1 /* #ident "@(#)g_imp_name.c 1.2 96/02/06 SMI" */
4 * Copyright 1996 by Sun Microsystems, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appears in all copies and
9 * that both that copyright notice and this permission notice appear in
10 * supporting documentation, and that the name of Sun Microsystems not be used
11 * in advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. Sun Microsystems makes no
13 * representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
16 * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
26 * glue routine gss_import_name
38 OM_uint32 KRB5_CALLCONV
39 gss_import_name(minor_status,
44 OM_uint32 * minor_status;
45 gss_buffer_t input_name_buffer;
46 gss_OID input_name_type;
47 gss_name_t * output_name;
50 gss_union_name_t union_name;
51 OM_uint32 tmp, major_status = GSS_S_FAILURE;
59 /* if output_name is NULL, simply return */
61 if(output_name == NULL)
62 return (GSS_S_COMPLETE);
66 if (input_name_buffer == GSS_C_NO_BUFFER)
67 return (GSS_S_BAD_NAME);
70 * First create the union name struct that will hold the external
71 * name and the name type.
74 union_name = (gss_union_name_t) malloc (sizeof(gss_union_name_desc));
76 *minor_status = ENOMEM;
77 goto allocation_failure;
79 union_name->mech_type = 0;
80 union_name->mech_name = 0;
81 union_name->name_type = 0;
82 union_name->external_name = 0;
83 union_name->gss_mech = NULL;
86 * All we do here is record the external name and name_type.
87 * When the name is actually used, the underlying gss_import_name()
88 * is called for the appropriate mechanism. Note that the name type
89 * is assumed to be constant, so only a pointer to it is stored in
92 union_name->external_name =
93 (gss_buffer_t) malloc(sizeof(gss_buffer_desc));
94 if (!union_name->external_name) {
95 *minor_status = ENOMEM;
96 goto allocation_failure;
99 union_name->external_name->length = input_name_buffer->length;
100 /* we malloc length+1 to stick a NULL on the end, just in case */
101 /* Note that this NULL is not included in ->length for a reason! */
102 union_name->external_name->value =
103 (void *) malloc(input_name_buffer->length+1);
104 if (!union_name->external_name->value) {
105 *minor_status = ENOMEM;
106 goto allocation_failure;
109 memcpy(union_name->external_name->value, input_name_buffer->value,
110 input_name_buffer->length);
112 /* add NULL to end of external_name->value, just in case... */
113 ((char *)union_name->external_name->value)
114 [input_name_buffer->length] = '\0';
116 major_status = generic_gss_copy_oid(minor_status, input_name_type,
117 &union_name->name_type);
118 if (major_status != GSS_S_COMPLETE)
119 goto allocation_failure;
122 * See if this is a mechanism-specific name. If so, let's import
123 * it now so we can get any error messages, and to avoid trouble
126 mech = gss_find_mechanism_from_name_type(input_name_type);
128 major_status = generic_gss_copy_oid(minor_status, mech,
129 &union_name->mech_type);
130 if (major_status != GSS_S_COMPLETE)
131 goto allocation_failure;
133 major_status = __gss_import_internal_name(minor_status, mech,
135 &union_name->mech_name);
137 goto allocation_failure;
140 *output_name = (gss_name_t) union_name;
142 return(GSS_S_COMPLETE);
146 if (union_name->external_name) {
147 if (union_name->external_name->value)
148 free(union_name->external_name->value);
149 free(union_name->external_name);
151 if (union_name->name_type)
152 generic_gss_release_oid(&tmp, &union_name->name_type);
153 if (union_name->mech_name)
154 __gss_release_internal_name(minor_status, union_name->mech_type,
155 &union_name->mech_name);
156 if (union_name->mech_type)
157 generic_gss_release_oid(&tmp, &union_name->mech_type);
160 return (major_status);