From: Tom Yu Date: Mon, 26 Jun 2006 21:03:04 +0000 (+0000) Subject: * src/include/krb5/krb5.hin: Add prototype for krb5_copy_context X-Git-Tag: krb5-1.6-alpha1~263 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a6d786ccf9d1b6dbfe2b86ee0d3dfc5c3951d37c;p=krb5.git * src/include/krb5/krb5.hin: Add prototype for krb5_copy_context * src/lib/krb5/krb/init_ctx.c (krb5_copy_context): New function to copy/clone an existing krb5 context. (copy_ktypes): Local helper function. ticket: 2856 tags: pullup git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18228 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/krb5/krb5.hin b/src/include/krb5/krb5.hin index d786e6770..9c8399847 100644 --- a/src/include/krb5/krb5.hin +++ b/src/include/krb5/krb5.hin @@ -1343,6 +1343,8 @@ krb5_error_code KRB5_CALLCONV krb5_init_secure_context (krb5_context *); void KRB5_CALLCONV krb5_free_context (krb5_context); +krb5_error_code KRB5_CALLCONV krb5_copy_context + (krb5_context, krb5_context *); #if KRB5_PRIVATE krb5_error_code krb5_set_default_in_tkt_ktypes diff --git a/src/lib/krb5/krb/init_ctx.c b/src/lib/krb5/krb/init_ctx.c index e1e1e755e..85a3d144a 100644 --- a/src/lib/krb5/krb/init_ctx.c +++ b/src/lib/krb5/krb/init_ctx.c @@ -485,3 +485,84 @@ krb5_is_permitted_enctype(krb5_context context, krb5_enctype etype) return(ret); } + +static krb5_error_code +copy_ktypes(krb5_context ctx, + unsigned int nktypes, + krb5_enctype *oldktypes, + krb5_enctype **newktypes) +{ + unsigned int i; + + *newktypes = NULL; + if (!nktypes) + return 0; + + *newktypes = malloc(nktypes * sizeof(krb5_enctype)); + if (*newktypes == NULL) + return ENOMEM; + for (i = 0; i < nktypes; i++) + (*newktypes)[i] = oldktypes[i]; + 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(krb5_context*)); + *nctx = *ctx; + + nctx->in_tkt_ktypes = NULL; + nctx->in_tkt_ktype_count = 0; + nctx->tgs_ktypes = NULL; + nctx->tgs_ktype_count = 0; + nctx->default_realm = NULL; + nctx->profile = NULL; + nctx->db_context = NULL; + nctx->ser_ctx_count = 0; + nctx->ser_ctx = NULL; + nctx->prompt_types = NULL; + nctx->os_context->default_ccname = 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_ktypes(nctx, ctx->in_tkt_ktype_count, + ctx->in_tkt_ktypes, &nctx->in_tkt_ktypes); + if (ret) + goto errout; + nctx->in_tkt_ktype_count = ctx->in_tkt_ktype_count; + + ret = copy_ktypes(nctx, ctx->tgs_ktype_count, + ctx->tgs_ktypes, &nctx->in_tkt_ktypes); + if (ret) + goto errout; + nctx->tgs_ktype_count = ctx->tgs_ktype_count; + + 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; +}