Blame SOURCES/Don-t-include-all-MEMORY-ccaches-in-collection.patch

749169
From 7c50ae9787c2fbfb479fbc513a2aeb2aff039d43 Mon Sep 17 00:00:00 2001
d7027e
From: Greg Hudson <ghudson@mit.edu>
d7027e
Date: Wed, 1 Aug 2018 15:53:12 -0400
d7027e
Subject: [PATCH] Don't include all MEMORY ccaches in collection
d7027e
d7027e
In the MEMORY ccache implementation, only yield a cache in the
d7027e
per-type cursor if it is the context default cache, matching the
d7027e
behavior of FILE after commit 45360c9688ca963f75a2480f2cf818424fc3dc7b
d7027e
(ticket 6955).
d7027e
d7027e
ticket: 8720 (new)
d7027e
(cherry picked from commit 49bb627fed70c5258c151c5135ac3d95ed1ee55d)
d7027e
---
d7027e
 src/lib/krb5/ccache/cc_memory.c | 25 ++++++++++---------------
d7027e
 src/lib/krb5/ccache/t_cccol.py  |  7 ++++---
d7027e
 2 files changed, 14 insertions(+), 18 deletions(-)
d7027e
d7027e
diff --git a/src/lib/krb5/ccache/cc_memory.c b/src/lib/krb5/ccache/cc_memory.c
d7027e
index 8cdaff7fb..cfd5c6389 100644
d7027e
--- a/src/lib/krb5/ccache/cc_memory.c
d7027e
+++ b/src/lib/krb5/ccache/cc_memory.c
d7027e
@@ -132,7 +132,7 @@ struct mcc_cursor {
d7027e
 
d7027e
 /* Iterator over memory caches.  */
d7027e
 struct krb5_mcc_ptcursor_data {
d7027e
-    struct krb5_mcc_list_node *cur;
d7027e
+    krb5_boolean first;
d7027e
 };
d7027e
 
d7027e
 k5_cc_mutex krb5int_mcc_mutex = K5_CC_MUTEX_PARTIAL_INITIALIZER;
d7027e
@@ -693,9 +693,7 @@ krb5_mcc_ptcursor_new(
d7027e
         return ENOMEM;
d7027e
     }
d7027e
     n->data = cdata;
d7027e
-    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
d7027e
-    cdata->cur = mcc_head;
d7027e
-    k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
d7027e
+    cdata->first = TRUE;
d7027e
     *cursor = n;
d7027e
     return 0;
d7027e
 }
d7027e
@@ -707,22 +705,19 @@ krb5_mcc_ptcursor_next(
d7027e
     krb5_ccache *ccache)
d7027e
 {
d7027e
     struct krb5_mcc_ptcursor_data *cdata = NULL;
d7027e
+    const char *defname;
d7027e
 
d7027e
     *ccache = NULL;
d7027e
     cdata = cursor->data;
d7027e
-    if (cdata->cur == NULL)
d7027e
+    if (!cdata->first)
d7027e
+        return 0;
d7027e
+    cdata->first = FALSE;
d7027e
+
d7027e
+    defname = krb5_cc_default_name(context);
d7027e
+    if (defname == NULL || strncmp(defname, "MEMORY:", 7) != 0)
d7027e
         return 0;
d7027e
 
d7027e
-    *ccache = malloc(sizeof(**ccache));
d7027e
-    if (*ccache == NULL)
d7027e
-        return ENOMEM;
d7027e
-
d7027e
-    (*ccache)->ops = &krb5_mcc_ops;
d7027e
-    (*ccache)->data = cdata->cur->cache;
d7027e
-    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
d7027e
-    cdata->cur = cdata->cur->next;
d7027e
-    k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
d7027e
-    return 0;
d7027e
+    return krb5_cc_resolve(context, defname, ccache);
d7027e
 }
d7027e
 
d7027e
 static krb5_error_code KRB5_CALLCONV
d7027e
diff --git a/src/lib/krb5/ccache/t_cccol.py b/src/lib/krb5/ccache/t_cccol.py
d7027e
index f7f178564..c6d5f514d 100755
d7027e
--- a/src/lib/krb5/ccache/t_cccol.py
d7027e
+++ b/src/lib/krb5/ccache/t_cccol.py
d7027e
@@ -97,10 +97,11 @@ if test_keyring:
d7027e
 
d7027e
 mfoo = 'MEMORY:foo'
d7027e
 mbar = 'MEMORY:bar'
d7027e
-cursor_test('filemem', [fccname, mfoo, mbar], [fccname, mfoo, mbar])
d7027e
-cursor_test('dirmem', [dccname, mfoo], [duser, dalice, dbob, mfoo])
d7027e
+cursor_test('filemem', [fccname, mfoo], [fccname])
d7027e
+cursor_test('dirmem', [dccname, mfoo], [duser, dalice, dbob])
d7027e
+cursor_test('mem', [mfoo, mbar], [mfoo])
d7027e
 if test_keyring:
d7027e
-    cursor_test('keyringmem', [krccname, mfoo], [kruser, kralice, krbob, mfoo])
d7027e
+    cursor_test('keyringmem', [krccname, mfoo], [kruser, kralice, krbob])
d7027e
 
d7027e
 # Test krb5_cccol_have_content.
d7027e
 realm.run(['./t_cccursor', dccname, 'CONTENT'])