Blame SOURCES/krb5-master-rcache-acquirecred-cleanup.patch

7d335d
commit ef8e19af863158e4c1abc15fc710aa8cfad38406
7d335d
Author: Greg Hudson <ghudson@mit.edu>
7d335d
Date:   Wed Jan 15 12:51:42 2014 -0500
7d335d
7d335d
    Clean up GSS krb5 acquire_accept_cred
7d335d
    
7d335d
    Use a cleanup handler instead of releasing kt in multiple error
7d335d
    clauses.  Wrap a long line and fix a comment with a missing word.
7d335d
    Rewrap the function arguments to use fewer lines.
7d335d
7d335d
diff --git a/src/lib/gssapi/krb5/acquire_cred.c b/src/lib/gssapi/krb5/acquire_cred.c
7d335d
index 9547207..37cc6b5 100644
7d335d
--- a/src/lib/gssapi/krb5/acquire_cred.c
7d335d
+++ b/src/lib/gssapi/krb5/acquire_cred.c
7d335d
@@ -179,13 +179,13 @@ cleanup:
7d335d
 */
7d335d
 
7d335d
 static OM_uint32
7d335d
-acquire_accept_cred(krb5_context context,
7d335d
-                    OM_uint32 *minor_status,
7d335d
-                    krb5_keytab req_keytab,
7d335d
-                    krb5_gss_cred_id_rec *cred)
7d335d
+acquire_accept_cred(krb5_context context, OM_uint32 *minor_status,
7d335d
+                    krb5_keytab req_keytab, krb5_gss_cred_id_rec *cred)
7d335d
 {
7d335d
+    OM_uint32 major;
7d335d
     krb5_error_code code;
7d335d
-    krb5_keytab kt;
7d335d
+    krb5_keytab kt = NULL;
7d335d
+    krb5_rcache rc = NULL;
7d335d
 
7d335d
     assert(cred->keytab == NULL);
7d335d
 
7d335d
@@ -202,46 +202,54 @@ acquire_accept_cred(krb5_context context,
7d335d
         }
7d335d
     }
7d335d
     if (code) {
7d335d
-        *minor_status = code;
7d335d
-        return GSS_S_CRED_UNAVAIL;
7d335d
+        major = GSS_S_CRED_UNAVAIL;
7d335d
+        goto cleanup;
7d335d
     }
7d335d
 
7d335d
     if (cred->name != NULL) {
7d335d
-        /* Make sure we keys matching the desired name in the keytab. */
7d335d
+        /* Make sure we have keys matching the desired name in the keytab. */
7d335d
         code = check_keytab(context, kt, cred->name);
7d335d
         if (code) {
7d335d
-            krb5_kt_close(context, kt);
7d335d
             if (code == KRB5_KT_NOTFOUND) {
7d335d
                 char *errstr = (char *)krb5_get_error_message(context, code);
7d335d
-                krb5_set_error_message(context, KG_KEYTAB_NOMATCH, "%s", errstr);
7d335d
+                krb5_set_error_message(context, KG_KEYTAB_NOMATCH, "%s",
7d335d
+                                       errstr);
7d335d
                 krb5_free_error_message(context, errstr);
7d335d
-                *minor_status = KG_KEYTAB_NOMATCH;
7d335d
-            } else
7d335d
-                *minor_status = code;
7d335d
-            return GSS_S_CRED_UNAVAIL;
7d335d
+                code = KG_KEYTAB_NOMATCH;
7d335d
+            }
7d335d
+            major = GSS_S_CRED_UNAVAIL;
7d335d
+            goto cleanup;
7d335d
         }
7d335d
 
7d335d
         /* Open the replay cache for this principal. */
7d335d
         code = krb5_get_server_rcache(context, &cred->name->princ->data[0],
7d335d
-                                      &cred->rcache);
7d335d
+                                      &rc);
7d335d
         if (code) {
7d335d
-            krb5_kt_close(context, kt);
7d335d
-            *minor_status = code;
7d335d
-            return GSS_S_FAILURE;
7d335d
+            major = GSS_S_FAILURE;
7d335d
+            goto cleanup;
7d335d
         }
7d335d
     } else {
7d335d
         /* Make sure we have a keytab with keys in it. */
7d335d
         code = krb5_kt_have_content(context, kt);
7d335d
         if (code) {
7d335d
-            krb5_kt_close(context, kt);
7d335d
-            *minor_status = code;
7d335d
-            return GSS_S_CRED_UNAVAIL;
7d335d
+            major = GSS_S_CRED_UNAVAIL;
7d335d
+            goto cleanup;
7d335d
         }
7d335d
     }
7d335d
 
7d335d
     cred->keytab = kt;
7d335d
+    kt = NULL;
7d335d
+    cred->rcache = rc;
7d335d
+    rc = NULL;
7d335d
+    major = GSS_S_COMPLETE;
7d335d
 
7d335d
-    return GSS_S_COMPLETE;
7d335d
+cleanup:
7d335d
+    if (kt != NULL)
7d335d
+        krb5_kt_close(context, kt);
7d335d
+    if (rc != NULL)
7d335d
+        krb5_rc_close(context, rc);
7d335d
+    *minor_status = code;
7d335d
+    return major;
7d335d
 }
7d335d
 #endif /* LEAN_CLIENT */
7d335d