svn rev #23565: trunk/src/lib/krb5/ ccache/ krb/

ghudson@MIT.EDU ghudson at MIT.EDU
Fri Jan 1 18:20:56 EST 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=23565
Commit By: ghudson
Log Message:
Factor out copying and counting of zero-terminated enctype lists into
a new file src/lib/krb5/krb/etype_list.c.



Changed Files:
U   trunk/src/lib/krb5/ccache/cc_retr.c
U   trunk/src/lib/krb5/krb/Makefile.in
U   trunk/src/lib/krb5/krb/auth_con.c
U   trunk/src/lib/krb5/krb/copy_ctx.c
A   trunk/src/lib/krb5/krb/etype_list.c
U   trunk/src/lib/krb5/krb/get_in_tkt.c
U   trunk/src/lib/krb5/krb/init_ctx.c
U   trunk/src/lib/krb5/krb/int-proto.h
U   trunk/src/lib/krb5/krb/ser_ctx.c
Modified: trunk/src/lib/krb5/ccache/cc_retr.c
===================================================================
--- trunk/src/lib/krb5/ccache/cc_retr.c	2010-01-01 22:34:29 UTC (rev 23564)
+++ trunk/src/lib/krb5/ccache/cc_retr.c	2010-01-01 23:20:56 UTC (rev 23565)
@@ -29,6 +29,7 @@
 
 #include "k5-int.h"
 #include "cc-int.h"
+#include "../krb/int-proto.h"
 
 #define KRB5_OK 0
 
@@ -279,9 +280,7 @@
         ret = krb5_get_tgs_ktypes (context, mcreds->server, &ktypes);
         if (ret)
             return ret;
-        nktypes = 0;
-        while (ktypes[nktypes])
-            nktypes++;
+        nktypes = krb5int_count_etypes (ktypes);
 
         ret = krb5_cc_retrieve_cred_seq (context, id, flags, mcreds, creds,
                                          nktypes, ktypes);

Modified: trunk/src/lib/krb5/krb/Makefile.in
===================================================================
--- trunk/src/lib/krb5/krb/Makefile.in	2010-01-01 22:34:29 UTC (rev 23564)
+++ trunk/src/lib/krb5/krb/Makefile.in	2010-01-01 23:20:56 UTC (rev 23565)
@@ -40,6 +40,7 @@
         enc_keyhelper.o	\
 	encode_kdc.o	\
 	encrypt_tk.o	\
+	etype_list.o	\
 	fast.o \
 	free_rtree.o	\
 	fwd_tgt.o	\
@@ -134,6 +135,7 @@
         $(OUTPRE)enc_keyhelper.$(OBJEXT)	\
 	$(OUTPRE)encode_kdc.$(OBJEXT)	\
 	$(OUTPRE)encrypt_tk.$(OBJEXT)	\
+	$(OUTPRE)etype_list.$(OBJEXT)	\
 	$(OUTPRE)fast.$(OBJEXT) \
 	$(OUTPRE)free_rtree.$(OBJEXT)	\
 	$(OUTPRE)fwd_tgt.$(OBJEXT)	\
@@ -229,6 +231,7 @@
 	$(srcdir)/enc_keyhelper.c	\
 	$(srcdir)/encode_kdc.c	\
 	$(srcdir)/encrypt_tk.c	\
+	$(srcdir)/etype_list.c	\
 	$(srcdir)/fast.c \
 	$(srcdir)/free_rtree.c	\
 	$(srcdir)/fwd_tgt.c	\
@@ -325,7 +328,8 @@
 T_KERB_OBJS= t_kerb.o conv_princ.o unparse.o set_realm.o str_conv.o
 
 T_SER_OBJS= t_ser.o ser_actx.o ser_adata.o ser_addr.o ser_auth.o ser_cksum.o \
-	ser_ctx.o ser_key.o ser_princ.o serialize.o authdata.o pac.o copy_data.o
+	ser_ctx.o ser_key.o ser_princ.o serialize.o authdata.o pac.o \
+	copy_data.o etype_list.o
 
 T_DELTAT_OBJS= t_deltat.o deltat.o
 
@@ -333,7 +337,7 @@
 
 T_PRINC_OBJS= t_princ.o parse.o unparse.o
 
-T_ETYPES_OBJS= t_etypes.o init_ctx.o
+T_ETYPES_OBJS= t_etypes.o init_ctx.o etype_list.o
 
 t_walk_rtree: $(T_WALK_RTREE_OBJS) $(KRB5_BASE_DEPLIBS)
 	$(CC_LINK) -o t_walk_rtree $(T_WALK_RTREE_OBJS) $(KRB5_BASE_LIBS)

Modified: trunk/src/lib/krb5/krb/auth_con.c
===================================================================
--- trunk/src/lib/krb5/krb/auth_con.c	2010-01-01 22:34:29 UTC (rev 23564)
+++ trunk/src/lib/krb5/krb/auth_con.c	2010-01-01 23:20:56 UTC (rev 23565)
@@ -1,5 +1,6 @@
 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 #include "k5-int.h"
+#include "int-proto.h"
 #include "auth_con.h"
 
 static krb5_boolean chk_heimdal_seqnum(krb5_ui_4, krb5_ui_4);
@@ -355,53 +356,31 @@
 }
 
 krb5_error_code
-krb5_auth_con_setpermetypes(krb5_context context, krb5_auth_context auth_context, const krb5_enctype *permetypes)
+krb5_auth_con_setpermetypes(krb5_context context,
+                            krb5_auth_context auth_context,
+                            const krb5_enctype *permetypes)
 {
-    krb5_enctype        * newpe;
-    int i;
+    krb5_enctype *newpe;
+    krb5_error_code ret;
 
-    for (i=0; permetypes[i]; i++)
-        ;
-    i++; /* include the zero */
+    ret = krb5int_copy_etypes(permetypes, &newpe);
+    if (ret != 0)
+        return ret;
 
-    if ((newpe = (krb5_enctype *) malloc(i*sizeof(krb5_enctype)))
-        == NULL)
-        return(ENOMEM);
-
-    if (auth_context->permitted_etypes)
-        free(auth_context->permitted_etypes);
-
+    free(auth_context->permitted_etypes);
     auth_context->permitted_etypes = newpe;
-
-    memcpy(newpe, permetypes, i*sizeof(krb5_enctype));
-
     return 0;
 }
 
 krb5_error_code
-krb5_auth_con_getpermetypes(krb5_context context, krb5_auth_context auth_context, krb5_enctype **permetypes)
+krb5_auth_con_getpermetypes(krb5_context context,
+                            krb5_auth_context auth_context,
+                            krb5_enctype **permetypes)
 {
-    krb5_enctype        * newpe;
-    int i;
-
-    if (! auth_context->permitted_etypes) {
-        *permetypes = NULL;
-        return(0);
-    }
-
-    for (i=0; auth_context->permitted_etypes[i]; i++)
-        ;
-    i++; /* include the zero */
-
-    if ((newpe = (krb5_enctype *) malloc(i*sizeof(krb5_enctype)))
-        == NULL)
-        return(ENOMEM);
-
-    *permetypes = newpe;
-
-    memcpy(newpe, auth_context->permitted_etypes, i*sizeof(krb5_enctype));
-
-    return(0);
+    *permetypes = NULL;
+    if (auth_context->permitted_etypes == NULL)
+        return 0;
+    return krb5int_copy_etypes(auth_context->permitted_etypes, permetypes);
 }
 
 krb5_error_code KRB5_CALLCONV

Modified: trunk/src/lib/krb5/krb/copy_ctx.c
===================================================================
--- trunk/src/lib/krb5/krb/copy_ctx.c	2010-01-01 22:34:29 UTC (rev 23564)
+++ trunk/src/lib/krb5/krb/copy_ctx.c	2010-01-01 23:20:56 UTC (rev 23565)
@@ -54,26 +54,9 @@
  */
 
 #include "k5-int.h"
+#include "int-proto.h"
 #include <ctype.h>
 
-/* Copy the zero-terminated enctype list old_list into *new_list. */
-static krb5_error_code
-copy_enctypes(krb5_context context, const krb5_enctype *old_list,
-              krb5_enctype **new_list)
-{
-    unsigned int count;
-    krb5_enctype *list;
-
-    *new_list = NULL;
-    for (count = 0; old_list[count]; count++);
-    list = malloc(sizeof(krb5_enctype) * (count + 1));
-    if (list == NULL)
-        return ENOMEM;
-    memcpy(list, old_list, sizeof(krb5_enctype) * (count + 1));
-    *new_list = list;
-    return 0;
-}
-
 krb5_error_code KRB5_CALLCONV
 krb5_copy_context(krb5_context ctx, krb5_context *nctx_out)
 {
@@ -109,10 +92,10 @@
 
     memset(&nctx->err, 0, sizeof(nctx->err));
 
-    ret = copy_enctypes(nctx, ctx->in_tkt_etypes, &nctx->in_tkt_etypes);
+    ret = krb5int_copy_etypes(ctx->in_tkt_etypes, &nctx->in_tkt_etypes);
     if (ret)
         goto errout;
-    ret = copy_enctypes(nctx, ctx->tgs_etypes, &nctx->tgs_etypes);
+    ret = krb5int_copy_etypes(ctx->tgs_etypes, &nctx->tgs_etypes);
     if (ret)
         goto errout;
 

Added: trunk/src/lib/krb5/krb/etype_list.c
===================================================================
--- trunk/src/lib/krb5/krb/etype_list.c	                        (rev 0)
+++ trunk/src/lib/krb5/krb/etype_list.c	2010-01-01 23:20:56 UTC (rev 23565)
@@ -0,0 +1,59 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ * lib/krb5/krb/etype_list.c
+ *
+ * Copyright (C) 2010 by the Massachusetts Institute of Technology.
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may
+ *   require a specific license from the United States Government.
+ *   It is the responsibility of any person or organization contemplating
+ *   export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission.  Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose.  It is provided "as is" without express
+ * or implied warranty.
+ *
+ *
+ * Helper functions related to zero-terminated lists of enctypes.
+ */
+
+#include "k5-int.h"
+#include "int-proto.h"
+
+size_t
+krb5int_count_etypes(const krb5_enctype *list)
+{
+    size_t count;
+
+    for (count = 0; list[count]; count++);
+    return count;
+}
+
+/* Copy the zero-terminated enctype list old_list into *new_list. */
+krb5_error_code
+krb5int_copy_etypes(const krb5_enctype *old_list, krb5_enctype **new_list)
+{
+    size_t count;
+    krb5_enctype *list;
+
+    *new_list = NULL;
+    count = krb5int_count_etypes(old_list);
+    list = malloc(sizeof(krb5_enctype) * (count + 1));
+    if (list == NULL)
+        return ENOMEM;
+    memcpy(list, old_list, sizeof(krb5_enctype) * (count + 1));
+    *new_list = list;
+    return 0;
+}
+

Modified: trunk/src/lib/krb5/krb/get_in_tkt.c
===================================================================
--- trunk/src/lib/krb5/krb/get_in_tkt.c	2010-01-01 22:34:29 UTC (rev 23564)
+++ trunk/src/lib/krb5/krb/get_in_tkt.c	2010-01-01 23:20:56 UTC (rev 23565)
@@ -720,13 +720,8 @@
     request.nonce = time_now;
 #endif /* APPLE_PKINIT */
 
-    request.ktype = malloc (sizeof(get_in_tkt_enctypes));
-    if (request.ktype == NULL) {
-        retval = ENOMEM;
-        goto cleanup;
-    }
-    memcpy(request.ktype, get_in_tkt_enctypes, sizeof(get_in_tkt_enctypes));
-    for (request.nktypes = 0;request.ktype[request.nktypes];request.nktypes++);
+    retval = krb5int_copy_etypes(get_in_tkt_enctypes, &request.ktype);
+    request.nktypes = krb5int_count_etypes(request.ktype);
     if (ktypes) {
         int i, req, next = 0;
         for (req = 0; ktypes[req]; req++) {
@@ -1433,10 +1428,7 @@
                ctx->request->nktypes * sizeof(krb5_enctype));
     } else if (krb5_get_default_in_tkt_ktypes(context,
                                               &ctx->request->ktype) == 0) {
-        for (ctx->request->nktypes = 0;
-             ctx->request->ktype[ctx->request->nktypes] != ENCTYPE_NULL;
-             ctx->request->nktypes++)
-            ;
+        ctx->request->nktypes = krb5int_count_etypes(ctx->request->ktype);
     } else {
         /* there isn't any useful default here. */
         code = KRB5_CONFIG_ETYPE_NOSUPP;
@@ -2134,7 +2126,7 @@
     if (addrs)
         krb5_get_init_creds_opt_set_address_list(opt, (krb5_address **) addrs);
     if (ktypes) {
-        for (i=0; ktypes[i]; i++);
+        i = krb5int_count_etypes(ktypes);
         if (i)
             krb5_get_init_creds_opt_set_etype_list(opt, ktypes, i);
     }

Modified: trunk/src/lib/krb5/krb/init_ctx.c
===================================================================
--- trunk/src/lib/krb5/krb/init_ctx.c	2010-01-01 22:34:29 UTC (rev 23564)
+++ trunk/src/lib/krb5/krb/init_ctx.c	2010-01-01 23:20:56 UTC (rev 23565)
@@ -54,6 +54,7 @@
  */
 
 #include "k5-int.h"
+#include "int-proto.h"
 #include <ctype.h>
 #include "brand.c"
 /* There has to be a better way for windows... */
@@ -267,24 +268,6 @@
     free(ctx);
 }
 
-/* Copy the zero-terminated enctype list old_list into *new_list. */
-static krb5_error_code
-copy_enctypes(krb5_context context, const krb5_enctype *old_list,
-              krb5_enctype **new_list)
-{
-    unsigned int count;
-    krb5_enctype *list;
-
-    *new_list = NULL;
-    for (count = 0; old_list[count]; count++);
-    list = malloc(sizeof(krb5_enctype) * (count + 1));
-    if (list == NULL)
-        return ENOMEM;
-    memcpy(list, old_list, sizeof(krb5_enctype) * (count + 1));
-    *new_list = list;
-    return 0;
-}
-
 /*
  * Set the desired default ktypes, making sure they are valid.
  */
@@ -304,7 +287,7 @@
                 return KRB5_PROG_ETYPE_NOSUPP;
         }
 
-        code = copy_enctypes(context, etypes, &list);
+        code = krb5int_copy_etypes(etypes, &list);
         if (code)
             return code;
     } else {
@@ -459,7 +442,7 @@
 
     if (ctx_list) {
         /* Use application defaults. */
-        code = copy_enctypes(context, ctx_list, &etypes);
+        code = krb5int_copy_etypes(ctx_list, &etypes);
         if (code)
             return code;
     } else {

Modified: trunk/src/lib/krb5/krb/int-proto.h
===================================================================
--- trunk/src/lib/krb5/krb/int-proto.h	2010-01-01 22:34:29 UTC (rev 23564)
+++ trunk/src/lib/krb5/krb/int-proto.h	2010-01-01 23:20:56 UTC (rev 23565)
@@ -164,4 +164,9 @@
                                        const krb5_keyblock *, krb5_keyusage,
                                        krb5_kdc_rep ** );
 
+/* Utility functions for zero-terminated enctype lists. */
+size_t krb5int_count_etypes(const krb5_enctype *list);
+krb5_error_code krb5int_copy_etypes(const krb5_enctype *old_list,
+                                    krb5_enctype **new_list);
+
 #endif /* KRB5_INT_FUNC_PROTO__ */

Modified: trunk/src/lib/krb5/krb/ser_ctx.c
===================================================================
--- trunk/src/lib/krb5/krb/ser_ctx.c	2010-01-01 22:34:29 UTC (rev 23564)
+++ trunk/src/lib/krb5/krb/ser_ctx.c	2010-01-01 23:20:56 UTC (rev 23565)
@@ -31,6 +31,7 @@
  *                krb5_os_context structures.
  */
 #include "k5-int.h"
+#include "int-proto.h"
 
 /*
  * Routines to deal with externalizing the krb5_context:
@@ -102,15 +103,10 @@
 };
 #endif /* LEAN_CLIENT */
 
-static unsigned int
+static inline unsigned int
 etypes_len(krb5_enctype *list)
 {
-    unsigned int i;
-
-    if (list == NULL)
-        return 0;
-    for (i = 0; list[i]; i++);
-    return i;
+    return (list == NULL) ? 0 : krb5int_count_etypes(list);
 }
 
 /*




More information about the cvs-krb5 mailing list