]> git.decadent.org.uk Git - nfs-utils.git/blob - support/gssapi/g_dup_name.c
Merge commit 'debian/1.0.7-2'
[nfs-utils.git] / support / gssapi / g_dup_name.c
1 /*
2                                  * Copyright 1996 by Sun Microsystems, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without fee,
6  * provided that the above copyright notice appears in all copies and
7  * that both that copyright notice and this permission notice appear in
8  * supporting documentation, and that the name of Sun Microsystems not be used
9  * in advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission. Sun Microsystems makes no
11  * representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  *
22  * created andros 2.24.01 from g_compare_name.c
23  */
24
25 /*
26  *  glue routine for gss_duplicate_name
27  *
28  */
29
30 #include <stdio.h>
31 #include "mglueP.h"
32 #ifdef HAVE_STDLIB_H
33 #include <stdlib.h>
34 #endif
35 #include <string.h>
36 #include <errno.h>
37
38 OM_uint32 KRB5_CALLCONV
39 gss_duplicate_name (minor_status,
40                     in_name,
41                     exp_name)
42 OM_uint32 *             minor_status;
43 const gss_name_t                in_name;
44 gss_name_t              *exp_name;
45 {
46     OM_uint32           tmp,major_status =  GSS_S_COMPLETE;
47     gss_union_name_t    union_in_name, union_exp_name;
48     gss_mechanism       mech;
49
50     gss_initialize();
51
52     /* if exp_name is NULL, simply return */
53     if (exp_name == NULL)
54         return (GSS_S_COMPLETE);
55
56     *exp_name = NULL;
57
58     if (in_name == 0)
59         return (GSS_S_BAD_NAME);
60
61     union_in_name = (gss_union_name_t) in_name;
62
63     /*
64      * Create the union name struct that will hold the exported
65      * name and the name type.
66      */
67
68     union_exp_name = (gss_union_name_t) malloc (sizeof(gss_union_name_desc));
69     if (!union_exp_name) {
70         *minor_status = ENOMEM;
71         goto allocation_failure;
72     }
73 #ifdef DEBUG
74     fprintf(stderr, "gss_duplicate_name: copying *oid %p\n",
75                 union_in_name->mech_type);
76 #endif
77     union_exp_name->gss_mech = union_in_name->gss_mech;
78     union_exp_name->mech_type = GSS_C_NO_OID;
79     if (union_in_name->mech_type != GSS_C_NO_OID &&
80         (generic_gss_copy_oid(&tmp, union_in_name->mech_type,
81                         &union_exp_name->mech_type) != GSS_S_COMPLETE)) {
82         *minor_status = ENOMEM;
83         goto allocation_failure;
84     }
85     union_exp_name->mech_name = NULL;
86     union_exp_name->name_type = GSS_C_NO_OID;
87     if (union_in_name->name_type != GSS_C_NO_OID &&
88         (generic_gss_copy_oid(&tmp, union_in_name->name_type,
89                         &union_exp_name->name_type) != GSS_S_COMPLETE)) {
90         *minor_status = ENOMEM;
91         goto allocation_failure;
92     }
93     union_exp_name->external_name = NULL;
94     union_exp_name->external_name =
95                         (gss_buffer_t) malloc(sizeof(gss_buffer_desc));
96     if (!union_exp_name->external_name) {
97         *minor_status = ENOMEM;
98         goto allocation_failure;
99     }
100     union_exp_name->external_name->length = union_in_name->external_name->length;
101     /*
102      * we malloc length+1 to stick a NULL on the end, just in case
103      * Note that this NULL is not included in ->length for a reason!
104      */
105
106     union_exp_name->external_name->value =
107     (void  *) malloc(union_in_name->external_name->length);
108     if (!union_exp_name->external_name->value) {
109         *minor_status = ENOMEM;
110         goto allocation_failure;
111     }
112     memcpy(union_exp_name->external_name->value,
113         union_in_name->external_name->value,
114         union_exp_name->external_name->length);
115
116     /*
117      * Mechanism specific name
118      */
119
120     if (union_in_name->mech_type != GSS_C_NO_OID) {
121         mech = __gss_get_mechanism (union_in_name->mech_type);
122         if (!mech)
123             return (GSS_S_BAD_MECH);
124         if (!mech->gss_duplicate_name)
125             return (GSS_S_BAD_BINDINGS);
126
127 #ifdef USE_MECH_CONTEXT
128         major_status = mech->gss_duplicate_name(mech->context, minor_status,
129 #else
130         major_status = mech->gss_duplicate_name(minor_status,
131 #endif
132             union_in_name->mech_name, &union_exp_name->mech_name);
133         if (major_status != GSS_S_COMPLETE)
134             return (major_status);
135     }
136 #ifdef DEBUG
137     fprintf(stderr, "gss_duplicate_name: returning union_exp_name %p\n",
138                 union_exp_name);
139 #endif
140     *exp_name = union_exp_name;
141     return (major_status);
142
143 allocation_failure:
144     if (union_exp_name) {
145         if (union_exp_name->external_name) {
146             if (union_exp_name->external_name->value)
147                 free(union_exp_name->external_name->value);
148                 free(union_exp_name->external_name);
149         }
150         if (union_exp_name->name_type)
151             generic_gss_release_oid(&tmp, &union_exp_name->name_type);
152         if (union_exp_name->mech_name)
153             __gss_release_internal_name(minor_status, union_exp_name->mech_type,
154                 &union_exp_name->mech_name);
155         if (union_exp_name->mech_type)
156             generic_gss_release_oid(&tmp, &union_exp_name->mech_type);
157             free(union_exp_name);
158     }
159 return (major_status);
160
161 }
162