Blame SOURCES/krb5-cccol-primary.patch

5af5b2
commit b874882dc93e5ece4f7218617ed7942656985471
5af5b2
Author: Greg Hudson <ghudson@mit.edu>
5af5b2
Date:   Mon Apr 22 17:00:35 2013 -0400
5af5b2
5af5b2
    Include default DIR::file ccache in collection
5af5b2
    
5af5b2
    If the context's default ccache name is a subsidiary file of a
5af5b2
    directory collection, include that single cache in the cursor walk
5af5b2
    over the DIR type.
5af5b2
    
5af5b2
    ticket: 7172
5af5b2
5af5b2
diff --git a/src/lib/krb5/ccache/cc_dir.c b/src/lib/krb5/ccache/cc_dir.c
5af5b2
index cee21ac..b8231ed 100644
5af5b2
--- a/src/lib/krb5/ccache/cc_dir.c
5af5b2
+++ b/src/lib/krb5/ccache/cc_dir.c
5af5b2
@@ -266,6 +266,28 @@ get_context_default_dir(krb5_context context, char **dirname_out)
5af5b2
     return 0;
5af5b2
 }
5af5b2
 
5af5b2
+/*
5af5b2
+ * If the default ccache name for context is a subsidiary file in a directory
5af5b2
+ * collection, set *subsidiary_out to the residual value.  Otherwise set
5af5b2
+ * *subsidiary_out to NULL.
5af5b2
+ */
5af5b2
+static krb5_error_code
5af5b2
+get_context_subsidiary_file(krb5_context context, char **subsidiary_out)
5af5b2
+{
5af5b2
+    const char *defname;
5af5b2
+    char *residual;
5af5b2
+
5af5b2
+    *subsidiary_out = NULL;
5af5b2
+    defname = krb5_cc_default_name(context);
5af5b2
+    if (defname == NULL || strncmp(defname, "DIR::", 5) != 0)
5af5b2
+        return 0;
5af5b2
+    residual = strdup(defname + 4);
5af5b2
+    if (residual == NULL)
5af5b2
+        return ENOMEM;
5af5b2
+    *subsidiary_out = residual;
5af5b2
+    return 0;
5af5b2
+}
5af5b2
+
5af5b2
 static const char * KRB5_CALLCONV
5af5b2
 dcc_get_name(krb5_context context, krb5_ccache cache)
5af5b2
 {
5af5b2
@@ -562,6 +584,18 @@ dcc_ptcursor_new(krb5_context context, krb5_cc_ptcursor *cursor_out)
5af5b2
 
5af5b2
     *cursor_out = NULL;
5af5b2
 
5af5b2
+    /* If the default cache is a subsidiary file, make a cursor with the
5af5b2
+     * specified file as the primary but with no directory collection. */
5af5b2
+    ret = get_context_subsidiary_file(context, &primary);
5af5b2
+    if (ret)
5af5b2
+        goto cleanup;
5af5b2
+    if (primary != NULL) {
5af5b2
+        ret = make_cursor(NULL, primary, NULL, cursor_out);
5af5b2
+        if (ret)
5af5b2
+            free(primary);
5af5b2
+        return ret;
5af5b2
+    }
5af5b2
+
5af5b2
     /* Open the directory for the context's default cache. */
5af5b2
     ret = get_context_default_dir(context, &dirname);
5af5b2
     if (ret || dirname == NULL)
5af5b2
@@ -607,16 +641,17 @@ dcc_ptcursor_next(krb5_context context, krb5_cc_ptcursor cursor,
5af5b2
     struct stat sb;
5af5b2
 
5af5b2
     *cache_out = NULL;
5af5b2
-    if (data->dir == NULL)      /* Empty cursor */
5af5b2
-        return 0;
5af5b2
 
5af5b2
-    /* Return the primary cache if we haven't yet. */
5af5b2
+    /* Return the primary or specified subsidiary cache if we haven't yet. */
5af5b2
     if (data->first) {
5af5b2
         data->first = FALSE;
5af5b2
         if (data->primary != NULL && stat(data->primary + 1, &sb) == 0)
5af5b2
             return dcc_resolve(context, cache_out, data->primary);
5af5b2
     }
5af5b2
 
5af5b2
+    if (data->dir == NULL)      /* No directory collection */
5af5b2
+        return 0;
5af5b2
+
5af5b2
     /* Look for the next filename of the correct form, without repeating the
5af5b2
      * primary cache. */
5af5b2
     while ((ent = readdir(data->dir)) != NULL) {