From: Theodore Tso Date: Thu, 2 Jun 1994 16:44:49 +0000 (+0000) Subject: Do appropriate quoting if the server name contains non-ascii characters X-Git-Tag: krb5-1.0-beta4~177 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2b76b925924cdfc9dc4494c4a5cafd15999ea6b6;p=krb5.git Do appropriate quoting if the server name contains non-ascii characters git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3674 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/krb/srv_rcache.c b/src/lib/krb5/krb/srv_rcache.c index 96778755b..c04e6249b 100644 --- a/src/lib/krb5/krb/srv_rcache.c +++ b/src/lib/krb5/krb/srv_rcache.c @@ -38,33 +38,65 @@ krb5_get_server_rcache(piece, rcptr) 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; }