Blame SOURCES/0003-Learn-to-destroy-the-ccache-we-re-copying-from.patch

7d335d
From bb1793f369fc486362d3d540eaa19799164d717f Mon Sep 17 00:00:00 2001
5af5b2
From: Nalin Dahyabhai <nalin@redhat.com>
5af5b2
Date: Thu, 31 Oct 2013 15:43:49 -0400
5af5b2
Subject: [PATCH 3/6] Learn to destroy the ccache we're copying from
5af5b2
5af5b2
Add a flag to krb5_ccache_copy() which will instruct it to destroy a
5af5b2
source ccache after reading its contents.  Using this when we copy the
5af5b2
creds from a MEMORY cache to somewhere else is necessary to avoid having
5af5b2
a subsequent call to krb5_cc_cache_match() select the MEMORY cache when
5af5b2
we're trying to have it search a different location by default.
5af5b2
---
5af5b2
 src/clients/ksu/ccache.c | 10 +++++++++-
5af5b2
 src/clients/ksu/ksu.h    |  2 +-
5af5b2
 src/clients/ksu/main.c   |  5 +++--
5af5b2
 3 files changed, 13 insertions(+), 4 deletions(-)
5af5b2
5af5b2
diff --git a/src/clients/ksu/ccache.c b/src/clients/ksu/ccache.c
5af5b2
index 7917af2..90ba2f2 100644
5af5b2
--- a/src/clients/ksu/ccache.c
5af5b2
+++ b/src/clients/ksu/ccache.c
5af5b2
@@ -47,12 +47,14 @@ void show_credential();
5af5b2
 */
5af5b2
 
5af5b2
 krb5_error_code krb5_ccache_copy (context, cc_def, cc_other_tag,
5af5b2
-                                  primary_principal, cc_out, stored, target_uid)
5af5b2
+                                  primary_principal, destroy_def,
5af5b2
+                                  cc_out, stored, target_uid)
5af5b2
 /* IN */
5af5b2
     krb5_context context;
5af5b2
     krb5_ccache cc_def;
5af5b2
     char *cc_other_tag;
5af5b2
     krb5_principal primary_principal;
5af5b2
+    krb5_boolean destroy_def;
5af5b2
     uid_t target_uid;
5af5b2
     /* OUT */
5af5b2
     krb5_ccache *cc_out;
5af5b2
@@ -80,6 +82,12 @@ krb5_error_code krb5_ccache_copy (context, cc_def, cc_other_tag,
5af5b2
         }
5af5b2
     }
5af5b2
 
5af5b2
+    if (destroy_def) {
5af5b2
+        retval = krb5_cc_destroy(context, cc_def);
5af5b2
+        if (retval)
5af5b2
+            return retval;
5af5b2
+    }
5af5b2
+
5af5b2
     *stored = krb5_find_princ_in_cred_list(context, cc_def_creds_arr,
5af5b2
                                            primary_principal);
5af5b2
 
5af5b2
diff --git a/src/clients/ksu/ksu.h b/src/clients/ksu/ksu.h
5af5b2
index 1d102a1..a889fb9 100644
5af5b2
--- a/src/clients/ksu/ksu.h
5af5b2
+++ b/src/clients/ksu/ksu.h
5af5b2
@@ -108,7 +108,7 @@ extern krb5_error_code get_best_principal
5af5b2
 /* ccache.c */
5af5b2
 extern krb5_error_code krb5_ccache_copy
5af5b2
 (krb5_context, krb5_ccache, char *, krb5_principal,
5af5b2
- krb5_ccache *, krb5_boolean *, uid_t);
5af5b2
+ krb5_boolean, krb5_ccache *, krb5_boolean *, uid_t);
5af5b2
 
5af5b2
 extern krb5_error_code krb5_store_all_creds
5af5b2
 (krb5_context, krb5_ccache, krb5_creds **, krb5_creds **);
5af5b2
diff --git a/src/clients/ksu/main.c b/src/clients/ksu/main.c
5af5b2
index fa86c78..7497a2b 100644
5af5b2
--- a/src/clients/ksu/main.c
5af5b2
+++ b/src/clients/ksu/main.c
5af5b2
@@ -28,6 +28,7 @@
5af5b2
 
5af5b2
 #include "ksu.h"
5af5b2
 #include "adm_proto.h"
5af5b2
+#include "../../lib/krb5/os/os-proto.h"
5af5b2
 #include <sys/types.h>
5af5b2
 #include <sys/wait.h>
5af5b2
 #include <signal.h>
5af5b2
@@ -481,7 +482,7 @@ main (argc, argv)
5af5b2
     } else {
5af5b2
 
5af5b2
         retval = krb5_ccache_copy(ksu_context, cc_source, KRB5_TEMPORARY_CACHE,
5af5b2
-                                  client, &cc_tmp, &stored, 0);
5af5b2
+                                  client, FALSE, &cc_tmp, &stored, 0);
5af5b2
         if (retval) {
5af5b2
             com_err(prog_name, retval, _("while copying cache %s to %s"),
5af5b2
                     krb5_cc_get_name(ksu_context, cc_source),
5af5b2
@@ -758,7 +759,7 @@ main (argc, argv)
5af5b2
     }
5af5b2
 
5af5b2
     retval = krb5_ccache_copy(ksu_context, cc_tmp, cc_target_tag,
5af5b2
-                              client, &cc_target, &stored,
5af5b2
+                              client, TRUE, &cc_target, &stored,
5af5b2
                               target_pwd->pw_uid);
5af5b2
     if (retval) {
5af5b2
         com_err(prog_name, retval, _("while copying cache %s to %s"),
5af5b2
-- 
5af5b2
1.8.4.2
5af5b2