summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2006-06-26 21:03:04 +0000
committerTom Yu <tlyu@mit.edu>2006-06-26 21:03:04 +0000
commita6d786ccf9d1b6dbfe2b86ee0d3dfc5c3951d37c (patch)
tree56f25351e8e552fb62bb3f28c1bdf8cea3631107
parentbd7edfe0a67af34296baa530d2a2218ec4ddcb2d (diff)
downloadkrb5-a6d786ccf9d1b6dbfe2b86ee0d3dfc5c3951d37c.tar.gz
krb5-a6d786ccf9d1b6dbfe2b86ee0d3dfc5c3951d37c.tar.xz
krb5-a6d786ccf9d1b6dbfe2b86ee0d3dfc5c3951d37c.zip
* 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
-rw-r--r--src/include/krb5/krb5.hin2
-rw-r--r--src/lib/krb5/krb/init_ctx.c81
2 files changed, 83 insertions, 0 deletions
diff --git a/src/include/krb5/krb5.hin b/src/include/krb5/krb5.hin
index d786e6770c..9c8399847d 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 e1e1e755e7..85a3d144a0 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;
+}