1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /* lib/krb5/krb/copy_ctx.c */
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert * Copyright 1994,1999,2000, 2002, 2003, 2007, 2008, 2009 by the Massachusetts Institute of Technology.
5*7f2fe78bSCy Schubert * All Rights Reserved.
6*7f2fe78bSCy Schubert *
7*7f2fe78bSCy Schubert * Export of this software from the United States of America may
8*7f2fe78bSCy Schubert * require a specific license from the United States Government.
9*7f2fe78bSCy Schubert * It is the responsibility of any person or organization contemplating
10*7f2fe78bSCy Schubert * export to obtain such a license before exporting.
11*7f2fe78bSCy Schubert *
12*7f2fe78bSCy Schubert * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13*7f2fe78bSCy Schubert * distribute this software and its documentation for any purpose and
14*7f2fe78bSCy Schubert * without fee is hereby granted, provided that the above copyright
15*7f2fe78bSCy Schubert * notice appear in all copies and that both that copyright notice and
16*7f2fe78bSCy Schubert * this permission notice appear in supporting documentation, and that
17*7f2fe78bSCy Schubert * the name of M.I.T. not be used in advertising or publicity pertaining
18*7f2fe78bSCy Schubert * to distribution of the software without specific, written prior
19*7f2fe78bSCy Schubert * permission. Furthermore if you modify this software you must label
20*7f2fe78bSCy Schubert * your software as modified software and not distribute it in such a
21*7f2fe78bSCy Schubert * fashion that it might be confused with the original M.I.T. software.
22*7f2fe78bSCy Schubert * M.I.T. makes no representations about the suitability of
23*7f2fe78bSCy Schubert * this software for any purpose. It is provided "as is" without express
24*7f2fe78bSCy Schubert * or implied warranty.
25*7f2fe78bSCy Schubert */
26*7f2fe78bSCy Schubert /*
27*7f2fe78bSCy Schubert * Copyright (C) 1998 by the FundsXpress, INC.
28*7f2fe78bSCy Schubert *
29*7f2fe78bSCy Schubert * All rights reserved.
30*7f2fe78bSCy Schubert *
31*7f2fe78bSCy Schubert * Export of this software from the United States of America may require
32*7f2fe78bSCy Schubert * a specific license from the United States Government. It is the
33*7f2fe78bSCy Schubert * responsibility of any person or organization contemplating export to
34*7f2fe78bSCy Schubert * obtain such a license before exporting.
35*7f2fe78bSCy Schubert *
36*7f2fe78bSCy Schubert * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
37*7f2fe78bSCy Schubert * distribute this software and its documentation for any purpose and
38*7f2fe78bSCy Schubert * without fee is hereby granted, provided that the above copyright
39*7f2fe78bSCy Schubert * notice appear in all copies and that both that copyright notice and
40*7f2fe78bSCy Schubert * this permission notice appear in supporting documentation, and that
41*7f2fe78bSCy Schubert * the name of FundsXpress. not be used in advertising or publicity pertaining
42*7f2fe78bSCy Schubert * to distribution of the software without specific, written prior
43*7f2fe78bSCy Schubert * permission. FundsXpress makes no representations about the suitability of
44*7f2fe78bSCy Schubert * this software for any purpose. It is provided "as is" without express
45*7f2fe78bSCy Schubert * or implied warranty.
46*7f2fe78bSCy Schubert *
47*7f2fe78bSCy Schubert * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
48*7f2fe78bSCy Schubert * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
49*7f2fe78bSCy Schubert * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
50*7f2fe78bSCy Schubert */
51*7f2fe78bSCy Schubert
52*7f2fe78bSCy Schubert #include "k5-int.h"
53*7f2fe78bSCy Schubert #include "int-proto.h"
54*7f2fe78bSCy Schubert #include <ctype.h>
55*7f2fe78bSCy Schubert
56*7f2fe78bSCy Schubert krb5_error_code KRB5_CALLCONV
krb5_copy_context(krb5_context ctx,krb5_context * nctx_out)57*7f2fe78bSCy Schubert krb5_copy_context(krb5_context ctx, krb5_context *nctx_out)
58*7f2fe78bSCy Schubert {
59*7f2fe78bSCy Schubert krb5_error_code ret;
60*7f2fe78bSCy Schubert krb5_context nctx;
61*7f2fe78bSCy Schubert
62*7f2fe78bSCy Schubert *nctx_out = NULL;
63*7f2fe78bSCy Schubert if (ctx == NULL)
64*7f2fe78bSCy Schubert return EINVAL; /* XXX */
65*7f2fe78bSCy Schubert
66*7f2fe78bSCy Schubert nctx = malloc(sizeof(*nctx));
67*7f2fe78bSCy Schubert if (nctx == NULL)
68*7f2fe78bSCy Schubert return ENOMEM;
69*7f2fe78bSCy Schubert
70*7f2fe78bSCy Schubert *nctx = *ctx;
71*7f2fe78bSCy Schubert
72*7f2fe78bSCy Schubert nctx->tgs_etypes = NULL;
73*7f2fe78bSCy Schubert nctx->default_realm = NULL;
74*7f2fe78bSCy Schubert nctx->profile = NULL;
75*7f2fe78bSCy Schubert nctx->dal_handle = NULL;
76*7f2fe78bSCy Schubert nctx->prompt_types = NULL;
77*7f2fe78bSCy Schubert nctx->preauth_context = NULL;
78*7f2fe78bSCy Schubert nctx->ccselect_handles = NULL;
79*7f2fe78bSCy Schubert nctx->localauth_handles = NULL;
80*7f2fe78bSCy Schubert nctx->hostrealm_handles = NULL;
81*7f2fe78bSCy Schubert nctx->tls = NULL;
82*7f2fe78bSCy Schubert nctx->kdblog_context = NULL;
83*7f2fe78bSCy Schubert nctx->trace_callback = NULL;
84*7f2fe78bSCy Schubert nctx->trace_callback_data = NULL;
85*7f2fe78bSCy Schubert nctx->err_fmt = NULL;
86*7f2fe78bSCy Schubert if (ctx->err_fmt != NULL)
87*7f2fe78bSCy Schubert nctx->err_fmt = strdup(ctx->err_fmt); /* It's OK if this fails */
88*7f2fe78bSCy Schubert nctx->plugin_base_dir = NULL;
89*7f2fe78bSCy Schubert nctx->os_context.default_ccname = NULL;
90*7f2fe78bSCy Schubert
91*7f2fe78bSCy Schubert memset(&nctx->libkrb5_plugins, 0, sizeof(nctx->libkrb5_plugins));
92*7f2fe78bSCy Schubert memset(&nctx->err, 0, sizeof(nctx->err));
93*7f2fe78bSCy Schubert memset(&nctx->plugins, 0, sizeof(nctx->plugins));
94*7f2fe78bSCy Schubert
95*7f2fe78bSCy Schubert ret = k5_copy_etypes(ctx->tgs_etypes, &nctx->tgs_etypes);
96*7f2fe78bSCy Schubert if (ret)
97*7f2fe78bSCy Schubert goto errout;
98*7f2fe78bSCy Schubert
99*7f2fe78bSCy Schubert if (ctx->os_context.default_ccname != NULL) {
100*7f2fe78bSCy Schubert nctx->os_context.default_ccname =
101*7f2fe78bSCy Schubert strdup(ctx->os_context.default_ccname);
102*7f2fe78bSCy Schubert if (nctx->os_context.default_ccname == NULL) {
103*7f2fe78bSCy Schubert ret = ENOMEM;
104*7f2fe78bSCy Schubert goto errout;
105*7f2fe78bSCy Schubert }
106*7f2fe78bSCy Schubert }
107*7f2fe78bSCy Schubert ret = krb5_get_profile(ctx, &nctx->profile);
108*7f2fe78bSCy Schubert if (ret)
109*7f2fe78bSCy Schubert goto errout;
110*7f2fe78bSCy Schubert nctx->plugin_base_dir = strdup(ctx->plugin_base_dir);
111*7f2fe78bSCy Schubert if (nctx->plugin_base_dir == NULL) {
112*7f2fe78bSCy Schubert ret = ENOMEM;
113*7f2fe78bSCy Schubert goto errout;
114*7f2fe78bSCy Schubert }
115*7f2fe78bSCy Schubert
116*7f2fe78bSCy Schubert errout:
117*7f2fe78bSCy Schubert if (ret) {
118*7f2fe78bSCy Schubert krb5_free_context(nctx);
119*7f2fe78bSCy Schubert } else {
120*7f2fe78bSCy Schubert *nctx_out = nctx;
121*7f2fe78bSCy Schubert }
122*7f2fe78bSCy Schubert return ret;
123*7f2fe78bSCy Schubert }
124