From e0e42ad8bb76955dd09d1f2076acaeb9ae38bb32 Mon Sep 17 00:00:00 2001 From: Zhanna Tsitkov Date: Tue, 29 Dec 2009 20:30:29 +0000 Subject: [PATCH] Create a separate file for krb5_copy_context for better code modularity git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23538 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/krb/Makefile.in | 3 + src/lib/krb5/krb/copy_ctx.c | 138 +++++++++++++++++++++++++++++++++++ src/lib/krb5/krb/init_ctx.c | 63 ---------------- 3 files changed, 141 insertions(+), 63 deletions(-) create mode 100644 src/lib/krb5/krb/copy_ctx.c diff --git a/src/lib/krb5/krb/Makefile.in b/src/lib/krb5/krb/Makefile.in index 2cdeb02ba..f8a92b1f9 100644 --- a/src/lib/krb5/krb/Makefile.in +++ b/src/lib/krb5/krb/Makefile.in @@ -55,6 +55,7 @@ STLIBOBJS= \ gic_pwd.o \ in_tkt_sky.o \ init_ctx.o \ + copy_ctx.o \ init_keyblock.o \ kdc_rep_dc.o \ kerrs.o \ @@ -148,6 +149,7 @@ OBJS= $(OUTPRE)addr_comp.$(OBJEXT) \ $(OUTPRE)gic_pwd.$(OBJEXT) \ $(OUTPRE)in_tkt_sky.$(OBJEXT) \ $(OUTPRE)init_ctx.$(OBJEXT) \ + $(OUTPRE)copy_ctx.$(OBJEXT) \ $(OUTPRE)init_keyblock.$(OBJEXT) \ $(OUTPRE)kdc_rep_dc.$(OBJEXT) \ $(OUTPRE)kerrs.$(OBJEXT) \ @@ -242,6 +244,7 @@ SRCS= $(srcdir)/addr_comp.c \ $(srcdir)/gic_pwd.c \ $(srcdir)/in_tkt_sky.c \ $(srcdir)/init_ctx.c \ + $(srcdir)/copy_ctx.c \ $(srcdir)/init_keyblock.c \ $(srcdir)/kdc_rep_dc.c \ $(srcdir)/kerrs.c \ diff --git a/src/lib/krb5/krb/copy_ctx.c b/src/lib/krb5/krb/copy_ctx.c new file mode 100644 index 000000000..a95891e4d --- /dev/null +++ b/src/lib/krb5/krb/copy_ctx.c @@ -0,0 +1,138 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * lib/krb5/krb/copy_ctx.c + * + * Copyright 1994,1999,2000, 2002, 2003, 2007, 2008, 2009 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. + * + * krb5_copy_contex() + */ + +/* + * Copyright (C) 1998 by the FundsXpress, INC. + * + * 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 FundsXpress. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. FundsXpress makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include "k5-int.h" +#include + +/* 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) +{ + krb5_error_code ret; + krb5_context nctx; + + *nctx_out = NULL; + if (ctx == NULL) + return EINVAL; /* XXX */ + + nctx = malloc(sizeof(*nctx)); + if (nctx == NULL) + return ENOMEM; + + *nctx = *ctx; + + nctx->in_tkt_etypes = NULL; + nctx->tgs_etypes = NULL; + nctx->default_realm = NULL; + nctx->profile = NULL; + nctx->dal_handle = NULL; + nctx->ser_ctx_count = 0; + nctx->ser_ctx = NULL; + nctx->prompt_types = NULL; + nctx->os_context.default_ccname = NULL; + + memset(&nctx->preauth_plugins, 0, sizeof(nctx->preauth_plugins)); + nctx->preauth_context = NULL; + + memset(&nctx->libkrb5_plugins, 0, sizeof(nctx->libkrb5_plugins)); + nctx->vtbl = NULL; + nctx->locate_fptrs = NULL; + + memset(&nctx->err, 0, sizeof(nctx->err)); + + ret = copy_enctypes(nctx, ctx->in_tkt_etypes, &nctx->in_tkt_etypes); + if (ret) + goto errout; + ret = copy_enctypes(nctx, ctx->tgs_etypes, &nctx->tgs_etypes); + if (ret) + goto errout; + + if (ctx->os_context.default_ccname != NULL) { + nctx->os_context.default_ccname = + strdup(ctx->os_context.default_ccname); + if (nctx->os_context.default_ccname == NULL) { + ret = ENOMEM; + goto errout; + } + } + ret = krb5_get_profile(ctx, &nctx->profile); + if (ret) + goto errout; + +errout: + if (ret) { + krb5_free_context(nctx); + } else { + *nctx_out = nctx; + } + return ret; +} diff --git a/src/lib/krb5/krb/init_ctx.c b/src/lib/krb5/krb/init_ctx.c index 6ffee90bb..4220c9be5 100644 --- a/src/lib/krb5/krb/init_ctx.c +++ b/src/lib/krb5/krb/init_ctx.c @@ -584,66 +584,3 @@ krb5_is_permitted_enctype_ext ( krb5_context context, return(ret); } - -krb5_error_code KRB5_CALLCONV -krb5_copy_context(krb5_context ctx, krb5_context *nctx_out) -{ - krb5_error_code ret; - krb5_context nctx; - - *nctx_out = NULL; - if (ctx == NULL) - return EINVAL; /* XXX */ - - nctx = malloc(sizeof(*nctx)); - if (nctx == NULL) - return ENOMEM; - - *nctx = *ctx; - - nctx->in_tkt_etypes = NULL; - nctx->tgs_etypes = NULL; - nctx->default_realm = NULL; - nctx->profile = NULL; - nctx->dal_handle = NULL; - nctx->ser_ctx_count = 0; - nctx->ser_ctx = NULL; - nctx->prompt_types = NULL; - nctx->os_context.default_ccname = NULL; - - memset(&nctx->preauth_plugins, 0, sizeof(nctx->preauth_plugins)); - nctx->preauth_context = NULL; - - memset(&nctx->libkrb5_plugins, 0, sizeof(nctx->libkrb5_plugins)); - nctx->vtbl = NULL; - nctx->locate_fptrs = NULL; - - memset(&nctx->err, 0, sizeof(nctx->err)); - - ret = copy_enctypes(nctx, ctx->in_tkt_etypes, &nctx->in_tkt_etypes); - if (ret) - goto errout; - ret = copy_enctypes(nctx, ctx->tgs_etypes, &nctx->tgs_etypes); - if (ret) - goto errout; - - if (ctx->os_context.default_ccname != NULL) { - nctx->os_context.default_ccname = - strdup(ctx->os_context.default_ccname); - if (nctx->os_context.default_ccname == NULL) { - ret = ENOMEM; - goto errout; - } - } - ret = krb5_get_profile(ctx, &nctx->profile); - if (ret) - goto errout; - -errout: - if (ret) { - krb5_free_context(nctx); - } else { - *nctx_out = nctx; - } - return ret; -} -- 2.26.2