const krb5_data *piece;
krb5_rcache *rcptr;
{
- krb5_rcache rcache;
- char *cachename;
+ krb5_rcache rcache = 0;
+ char *cachename = 0;
+ char tmp[4];
extern krb5_deltat krb5_clockskew;
krb5_error_code retval;
- int len = piece->length;
+ int len, p, i;
+
+ rcache = (krb5_rcache) malloc(sizeof(*rcache));
+ if (!rcache)
+ return ENOMEM;
+
+ retval = krb5_rc_resolve_type(&rcache, "dfl");
+ if (retval) goto cleanup;
- if (rcache = (krb5_rcache) malloc(sizeof(*rcache))) {
- if (!(retval = krb5_rc_resolve_type(&rcache, "dfl"))) {
+ len = piece->length + 3 + 1;
+ for (i = 0; i <= piece->length; i++) {
+ if (piece->data[i] == '\\')
+ len++;
+ else if (!isgraph(piece->data[i]))
+ len += 3;
+ }
+ cachename = malloc(len);
+ if (!cachename) {
+ retval = ENOMEM;
+ goto cleanup;
+ }
+ p = 3;
+ for (i = 0; i <= piece->length; i++) {
+ if (piece->data[i] == '\\') {
+ cachename[p++] = '\\';
+ cachename[p++] = '\\';
+ continue;
+ }
+ if (!isgraph(piece->data[i])) {
+ sprintf(tmp, "%03o", piece->data[i]);
+ cachename[p++] = '\\';
+ cachename[p++] = tmp[0];
+ cachename[p++] = tmp[1];
+ cachename[p++] = tmp[2];
+ }
+ cachename[p++] = piece->data[i];
+ }
- if (cachename = malloc(len+1+3)) {
- strcpy(cachename, "rc_");
- strncat(cachename, piece->data, len);
- cachename[len+3] = '\0';
+ if (retval = krb5_rc_resolve(rcache, cachename))
+ goto cleanup;
- if (!(retval = krb5_rc_resolve(rcache, cachename))) {
- if (!((retval = krb5_rc_recover(rcache)) &&
- (retval = krb5_rc_initialize(rcache,
- krb5_clockskew)))) {
- *rcptr = rcache;
- return 0;
- }
- }
- } else
- retval = ENOMEM;
- }
+ if (retval = krb5_rc_initialize(rcache, krb5_clockskew)) {
+ krb5_rc_close(rcache);
+ rcache = 0;
+ goto cleanup;
+ }
+
+ *rcptr = rcache;
+ return 0;
+
+cleanup:
+ if (rcache)
krb5_xfree(rcache);
- } else
- retval = ENOMEM;
+ if (cachename)
+ krb5_xfree(cachename);
return retval;
}