Blame SOURCES/Separate-cred-and-ccache-manipulation-in-gpp_store_r.patch

472fdf
From 1451b65fec69ff35e029b4770dcb4927ba57060a Mon Sep 17 00:00:00 2001
472fdf
From: Robbie Harwood <rharwood@redhat.com>
472fdf
Date: Fri, 17 Nov 2017 13:53:37 -0500
472fdf
Subject: [PATCH] Separate cred and ccache manipulation in
472fdf
 gpp_store_remote_creds()
472fdf
472fdf
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
472fdf
Reviewed-by: Simo Sorce <simo@redhat.com>
472fdf
(cherry picked from commit 221b553bfb4082085d05b40da9a04c1f7e4af533)
472fdf
---
472fdf
 proxy/src/mechglue/gpp_creds.c | 62 +++++++++++++++++++++-------------
472fdf
 1 file changed, 39 insertions(+), 23 deletions(-)
472fdf
472fdf
diff --git a/proxy/src/mechglue/gpp_creds.c b/proxy/src/mechglue/gpp_creds.c
472fdf
index 6bdff45..3ebd726 100644
472fdf
--- a/proxy/src/mechglue/gpp_creds.c
472fdf
+++ b/proxy/src/mechglue/gpp_creds.c
472fdf
@@ -136,6 +136,40 @@ bool gpp_creds_are_equal(gssx_cred *a, gssx_cred *b)
472fdf
     return true;
472fdf
 }
472fdf
 
472fdf
+static krb5_error_code gpp_construct_cred(gssx_cred *creds, krb5_context ctx,
472fdf
+                                          krb5_creds *cred, char *cred_name)
472fdf
+{
472fdf
+    XDR xdrctx;
472fdf
+    bool xdrok;
472fdf
+    krb5_error_code ret = 0;
472fdf
+
472fdf
+    memset(cred, 0, sizeof(*cred));
472fdf
+
472fdf
+    memcpy(cred_name, creds->desired_name.display_name.octet_string_val,
472fdf
+           creds->desired_name.display_name.octet_string_len);
472fdf
+    cred_name[creds->desired_name.display_name.octet_string_len] = '\0';
472fdf
+
472fdf
+    ret = krb5_parse_name(ctx, cred_name, &cred->client);
472fdf
+    if (ret) {
472fdf
+        return ret;
472fdf
+    }
472fdf
+
472fdf
+    ret = krb5_parse_name(ctx, GPKRB_SRV_NAME, &cred->server);
472fdf
+    if (ret) {
472fdf
+        return ret;
472fdf
+    }
472fdf
+
472fdf
+    cred->ticket.data = malloc(GPKRB_MAX_CRED_SIZE);
472fdf
+    xdrmem_create(&xdrctx, cred->ticket.data, GPKRB_MAX_CRED_SIZE,
472fdf
+                  XDR_ENCODE);
472fdf
+    xdrok = xdr_gssx_cred(&xdrctx, creds);
472fdf
+    if (!xdrok) {
472fdf
+        return ENOSPC;
472fdf
+    }
472fdf
+    cred->ticket.length = xdr_getpos(&xdrctx);
472fdf
+    return 0;
472fdf
+}
472fdf
+
472fdf
 uint32_t gpp_store_remote_creds(uint32_t *min, bool default_creds,
472fdf
                                 gss_const_key_value_set_t cred_store,
472fdf
                                 gssx_cred *creds)
472fdf
@@ -145,17 +179,18 @@ uint32_t gpp_store_remote_creds(uint32_t *min, bool default_creds,
472fdf
     krb5_creds cred;
472fdf
     krb5_error_code ret;
472fdf
     char cred_name[creds->desired_name.display_name.octet_string_len + 1];
472fdf
-    XDR xdrctx;
472fdf
-    bool xdrok;
472fdf
     const char *cc_type;
472fdf
 
472fdf
     *min = 0;
472fdf
 
472fdf
-    memset(&cred, 0, sizeof(cred));
472fdf
-
472fdf
     ret = krb5_init_context(&ctx;;
472fdf
     if (ret) return ret;
472fdf
 
472fdf
+    ret = gpp_construct_cred(creds, ctx, &cred, cred_name);
472fdf
+    if (ret) {
472fdf
+        goto done;
472fdf
+    }
472fdf
+
472fdf
     if (cred_store) {
472fdf
         for (unsigned i = 0; i < cred_store->count; i++) {
472fdf
             if (strcmp(cred_store->elements[i].key, "ccache") == 0) {
472fdf
@@ -175,25 +210,6 @@ uint32_t gpp_store_remote_creds(uint32_t *min, bool default_creds,
472fdf
         if (ret) goto done;
472fdf
     }
472fdf
 
472fdf
-    memcpy(cred_name, creds->desired_name.display_name.octet_string_val,
472fdf
-           creds->desired_name.display_name.octet_string_len);
472fdf
-    cred_name[creds->desired_name.display_name.octet_string_len] = '\0';
472fdf
-
472fdf
-    ret = krb5_parse_name(ctx, cred_name, &cred.client);
472fdf
-    if (ret) goto done;
472fdf
-
472fdf
-    ret = krb5_parse_name(ctx, GPKRB_SRV_NAME, &cred.server);
472fdf
-    if (ret) goto done;
472fdf
-
472fdf
-    cred.ticket.data = malloc(GPKRB_MAX_CRED_SIZE);
472fdf
-    xdrmem_create(&xdrctx, cred.ticket.data, GPKRB_MAX_CRED_SIZE, XDR_ENCODE);
472fdf
-    xdrok = xdr_gssx_cred(&xdrctx, creds);
472fdf
-    if (!xdrok) {
472fdf
-        ret = ENOSPC;
472fdf
-        goto done;
472fdf
-    }
472fdf
-    cred.ticket.length = xdr_getpos(&xdrctx);
472fdf
-
472fdf
     cc_type = krb5_cc_get_type(ctx, ccache);
472fdf
     if (strcmp(cc_type, "FILE") == 0) {
472fdf
         /* FILE ccaches don't handle updates properly: if they have the same