Handle Windows pathnames properly in krb5_cc_resolve()
authorAsanka Herath <asanka@secure-endpoints.com>
Thu, 2 Sep 2010 21:15:01 +0000 (17:15 -0400)
committerAsanka C. Herath <asanka@secure-endpoints.com>
Tue, 14 Sep 2010 12:04:17 +0000 (08:04 -0400)
On Windows, a pathname can contain a drive letter and a colon.
krb5_cc_resolve() used to check whether there were any colons in the
ccache name string and assume it is a FILE: cache if there weren't.
In addition, on Windows, check for a drive specification.

lib/krb5/cache.c

index 09fbe1d9640f96cf0c0cb7419088132f8e3046f2..4c2cf3bce423b4dc9c1a5f9405ded6f45890212b 100644 (file)
@@ -217,6 +217,25 @@ allocate_ccache (krb5_context context,
     return ret;
 }
 
+static int
+is_possible_path_name(const char * name)
+{
+    const char * colon;
+
+    if ((colon = strchr(name, ':')) == NULL)
+        return TRUE;
+
+#ifdef _WIN32
+    /* <drive letter>:\path\to\cache ? */
+
+    if (colon == name + 1 &&
+        strchr(colon + 1, ':') == NULL)
+        return TRUE;
+#endif
+
+    return FALSE;
+}
+
 /**
  * Find and allocate a ccache in `id' from the specification in `residual'.
  * If the ccache name doesn't contain any colon, interpret it as a file name.
@@ -251,7 +270,7 @@ krb5_cc_resolve(krb5_context context,
                                    id);
        }
     }
-    if (strchr (name, ':') == NULL)
+    if (is_possible_path_name(name))
        return allocate_ccache (context, &krb5_fcc_ops, name, id);
     else {
        krb5_set_error_message(context, KRB5_CC_UNKNOWN_TYPE,
@@ -1413,7 +1432,7 @@ krb5_cccol_cursor_next(krb5_context context, krb5_cccol_cursor cursor,
        cursor->cursor = NULL;
        if (ret != KRB5_CC_END)
            break;
-       
+
        cursor->idx++;
     }
     if (cursor->idx >= context->num_cc_ops) {