Unify krb5_get_init_creds_keytab code paths
authorGreg Hudson <ghudson@mit.edu>
Thu, 19 Apr 2012 17:55:10 +0000 (17:55 +0000)
committerGreg Hudson <ghudson@mit.edu>
Thu, 19 Apr 2012 17:55:10 +0000 (17:55 +0000)
Use krb5_init_creds_set_keytab in krb5_get_init_creds_keytab, so that
processing added to the former will be used by the latter.  This is
slightly awkward because of the way we do the use_master fallback, in
that we have to duplicate some of krb5int_get_init_creds.

Based on a patch from Stef Walter.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25817 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/krb/deps
src/lib/krb5/krb/get_in_tkt.c
src/lib/krb5/krb/gic_keytab.c
src/lib/krb5/krb/int-proto.h

index fe2d54c579473dcc17c63ea13f7f2ec181e08c82..8c4db775f24918c22779c7a9279c2340242b8bd8 100644 (file)
@@ -473,7 +473,8 @@ gic_keytab.so gic_keytab.po $(OUTPRE)gic_keytab.$(OBJEXT): \
   $(top_srcdir)/include/k5-trace.h $(top_srcdir)/include/krb5.h \
   $(top_srcdir)/include/krb5/authdata_plugin.h $(top_srcdir)/include/krb5/plugin.h \
   $(top_srcdir)/include/krb5/preauth_plugin.h $(top_srcdir)/include/port-sockets.h \
-  $(top_srcdir)/include/socket-utils.h gic_keytab.c init_creds_ctx.h
+  $(top_srcdir)/include/socket-utils.h gic_keytab.c init_creds_ctx.h \
+  int-proto.h
 gic_opt.so gic_opt.po $(OUTPRE)gic_opt.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
   $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
   $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/k5-buf.h \
index aaabc4e2141f4ef5971a332e2caa17c9635f6054..681b648b1bcbdc50ebe462bad6546db645baaebe 100644 (file)
@@ -542,10 +542,9 @@ krb5_init_creds_free(krb5_context context,
     free(ctx);
 }
 
-static krb5_error_code
-init_creds_get(krb5_context context,
-               krb5_init_creds_context ctx,
-               int *use_master)
+krb5_error_code
+k5_init_creds_get(krb5_context context, krb5_init_creds_context ctx,
+                  int *use_master)
 {
     krb5_error_code code;
     krb5_data request;
@@ -599,7 +598,7 @@ krb5_init_creds_get(krb5_context context,
 {
     int use_master = 0;
 
-    return init_creds_get(context, ctx, &use_master);
+    return k5_init_creds_get(context, ctx, &use_master);
 }
 
 krb5_error_code KRB5_CALLCONV
@@ -1664,7 +1663,7 @@ krb5int_get_init_creds(krb5_context context,
             goto cleanup;
     }
 
-    code = init_creds_get(context, ctx, use_master);
+    code = k5_init_creds_get(context, ctx, use_master);
     if (code != 0)
         goto cleanup;
 
index 88de6a8feceed4b19bab0539c6a717210b7533a7..e59177fda8199fb10d193f910f4fb9bcbb67e3b4 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef LEAN_CLIENT
 
 #include "k5-int.h"
+#include "int-proto.h"
 #include "init_creds_ctx.h"
 
 static krb5_error_code
@@ -87,6 +88,44 @@ krb5_init_creds_set_keytab(krb5_context context,
     return 0;
 }
 
+static krb5_error_code
+get_init_creds_keytab(krb5_context context, krb5_creds *creds,
+                      krb5_principal client, krb5_keytab keytab,
+                      krb5_deltat start_time, char *in_tkt_service,
+                      krb5_get_init_creds_opt *options, int *use_master)
+{
+    krb5_error_code ret;
+    krb5_init_creds_context ctx = NULL;
+
+    ret = krb5_init_creds_init(context, client, NULL, NULL, start_time,
+                               options, &ctx);
+    if (ret != 0)
+        goto cleanup;
+
+    if (in_tkt_service) {
+        ret = krb5_init_creds_set_service(context, ctx, in_tkt_service);
+        if (ret != 0)
+            goto cleanup;
+    }
+
+    ret = krb5_init_creds_set_keytab(context, ctx, keytab);
+    if (ret != 0)
+        goto cleanup;
+
+    ret = k5_init_creds_get(context, ctx, use_master);
+    if (ret != 0)
+        goto cleanup;
+
+    ret = krb5_init_creds_get_creds(context, ctx, creds);
+    if (ret != 0)
+        goto cleanup;
+
+cleanup:
+    krb5_init_creds_free(context, ctx);
+
+    return ret;
+}
+
 krb5_error_code KRB5_CALLCONV
 krb5_get_init_creds_keytab(krb5_context context,
                            krb5_creds *creds,
@@ -111,10 +150,8 @@ krb5_get_init_creds_keytab(krb5_context context,
 
     /* first try: get the requested tkt from any kdc */
 
-    ret = krb5int_get_init_creds(context, creds, client, NULL, NULL,
-                                 start_time, in_tkt_service, options,
-                                 get_as_key_keytab, (void *) keytab,
-                                 &use_master,NULL);
+    ret = get_init_creds_keytab(context, creds, client, keytab, start_time,
+                                in_tkt_service, options, &use_master);
 
     /* check for success */
 
@@ -132,10 +169,9 @@ krb5_get_init_creds_keytab(krb5_context context,
     if (!use_master) {
         use_master = 1;
 
-        ret2 = krb5int_get_init_creds(context, creds, client, NULL, NULL,
-                                      start_time, in_tkt_service, options,
-                                      get_as_key_keytab, (void *) keytab,
-                                      &use_master, NULL);
+        ret2 = get_init_creds_keytab(context, creds, client, keytab,
+                                     start_time, in_tkt_service, options,
+                                     &use_master);
 
         if (ret2 == 0) {
             ret = 0;
index 6b160957eb6d925c3295239d1f17e9dfd971b3e6..899579f75677f60c07c4fea799c75c879461110c 100644 (file)
@@ -196,4 +196,8 @@ krb5int_mk_setpw_req(krb5_context context, krb5_auth_context auth_context,
 void
 k5_ccselect_free_context(krb5_context context);
 
+krb5_error_code
+k5_init_creds_get(krb5_context context, krb5_init_creds_context ctx,
+                  int *use_master);
+
 #endif /* KRB5_INT_FUNC_PROTO__ */