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