Do appropriate quoting if the server name contains non-ascii characters
authorTheodore Tso <tytso@mit.edu>
Thu, 2 Jun 1994 16:44:49 +0000 (16:44 +0000)
committerTheodore Tso <tytso@mit.edu>
Thu, 2 Jun 1994 16:44:49 +0000 (16:44 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3674 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/krb/srv_rcache.c

index 96778755b8133f985cbe7bf114ea08d0c8b12ab1..c04e6249baf078dc57da911068ef0d7387b83cce 100644 (file)
@@ -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;
 }