#include "k5-int.h"
#include "cc-int.h"
+#include "../krb/int-proto.h"
#define KRB5_OK 0
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);
enc_keyhelper.o \
encode_kdc.o \
encrypt_tk.o \
+ etype_list.o \
fast.o \
free_rtree.o \
fwd_tgt.o \
$(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) \
$(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 \
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
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)
/* -*- 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);
}
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;
-
- for (i=0; permetypes[i]; i++)
- ;
- i++; /* include the zero */
-
- if ((newpe = (krb5_enctype *) malloc(i*sizeof(krb5_enctype)))
- == NULL)
- return(ENOMEM);
+ krb5_enctype *newpe;
+ krb5_error_code ret;
- if (auth_context->permitted_etypes)
- free(auth_context->permitted_etypes);
+ ret = krb5int_copy_etypes(permetypes, &newpe);
+ if (ret != 0)
+ return ret;
+ 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
*/
#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)
{
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;
--- /dev/null
+/* -*- 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;
+}
+
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++) {
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;
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);
}
*/
#include "k5-int.h"
+#include "int-proto.h"
#include <ctype.h>
#include "brand.c"
/* There has to be a better way for windows... */
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.
*/
return KRB5_PROG_ETYPE_NOSUPP;
}
- code = copy_enctypes(context, etypes, &list);
+ code = krb5int_copy_etypes(etypes, &list);
if (code)
return code;
} else {
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 {
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__ */
* krb5_os_context structures.
*/
#include "k5-int.h"
+#include "int-proto.h"
/*
* Routines to deal with externalizing the krb5_context:
};
#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);
}
/*