pull up r18228:18229 from trunk
authorTom Yu <tlyu@mit.edu>
Mon, 26 Jun 2006 23:36:27 +0000 (23:36 +0000)
committerTom Yu <tlyu@mit.edu>
Mon, 26 Jun 2006 23:36:27 +0000 (23:36 +0000)
 r18228@cathode-dark-space:  tlyu | 2006-06-26 17:03:04 -0400
 ticket: 2856
 tags: pullup

  * 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.

 r18229@cathode-dark-space:  tlyu | 2006-06-26 18:04:51 -0400
 ticket: 2856

  * src/lib/krb5_32.def: Export krb5_copy_context.

  * src/lib/krb5/libkrb5.exports: Export krb5_copy_context.

  * src/lib/krb5/krb/init_ctx.c (krb5_copy_context): Fix malloc
  argument for nctx.  Handle null default_ccname case.

ticket: 2856
version_fixed: 1.5

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-5@18232 dc483132-0cff-0310-8789-dd5450dbe970

src/include/krb5/krb5.hin
src/lib/krb5/krb/init_ctx.c
src/lib/krb5/libkrb5.exports
src/lib/krb5_32.def

index d786e6770c3a7e1b23e445b4d7bd001b20d4b6dd..9c8399847d00244ce94e8466d8c9e410f06c13ff 100644 (file)
@@ -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
index e1e1e755e7d1e404cdd11b4ee675629d17667df3..8e4ce8c3b3a4fbc041a3c252bd2f4232bc46ec48 100644 (file)
@@ -485,3 +485,90 @@ 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(*nctx));
+    if (nctx == NULL)
+       return ENOMEM;
+
+    *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;
+
+    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;
+}
index b2fd14e575478641634bcdc46c1764d2312fed2b..94e94e45dbb9f9292eeadfe52b71931daebefd24 100644 (file)
@@ -323,6 +323,7 @@ krb5_copy_addresses
 krb5_copy_authdata
 krb5_copy_authenticator
 krb5_copy_checksum
+krb5_copy_context
 krb5_copy_creds
 krb5_copy_data
 krb5_copy_keyblock
index db0be8c617fa7e050b9061451b614cde39cbbd68..9785df56300e730c7a815ffbc4ff5e926e6b4da1 100644 (file)
@@ -100,6 +100,7 @@ krb5_c_string_to_key_with_params
        krb5_copy_authdata
        krb5_copy_authenticator
        krb5_copy_checksum
+       krb5_copy_context
        krb5_copy_creds
        krb5_copy_data
        krb5_copy_keyblock