16602 usba: unused label
[illumos-gate.git] / usr / src / uts / common / gssapi / gss_import_name.c
blobcd2f56083349bdbc921ea1cebe51a0a83e5c714f
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * glue routine gss_import_name
32 #include "mechglueP.h"
33 #include <sys/errno.h>
34 OM_uint32
35 gss_import_name(
36 OM_uint32 *minor_status,
37 const gss_buffer_t input_name_buffer,
38 const gss_OID input_name_type,
39 gss_name_t *output_name)
42 gss_union_name_t union_name;
43 OM_uint32 major_status = GSS_S_FAILURE;
45 if (minor_status)
46 *minor_status = 0;
48 /* if output_name is NULL, simply return */
50 if (output_name == NULL)
51 return (GSS_S_COMPLETE);
53 *output_name = 0;
55 if (input_name_buffer == GSS_C_NO_BUFFER || input_name_type == NULL)
56 return (GSS_S_BAD_NAME);
59 * First create the union name struct that will hold the external
60 * name and the name type.
63 union_name = (gss_union_name_t) MALLOC(sizeof (gss_union_name_desc));
65 if (!union_name) {
66 *minor_status = ENOMEM;
67 goto allocation_failure;
69 union_name->mech_type = 0;
70 union_name->mech_name = 0;
71 union_name->name_type = 0;
72 union_name->external_name = 0;
75 * All we do here is record the external name and name_type.
76 * When the name is actually used, the underlying gss_import_name()
77 * is called for the appropriate mechanism.
78 * Since the name type may be a constant or comming from the
79 * rpc resoults, we must make a copy.
81 union_name->external_name =
82 (gss_buffer_t) MALLOC(sizeof (gss_buffer_desc));
84 if (!union_name->external_name) {
85 *minor_status = ENOMEM;
86 goto allocation_failure;
89 union_name->external_name->length = input_name_buffer->length;
90 union_name->external_name->value =
91 (void *) MALLOC(input_name_buffer->length);
93 if (!union_name->external_name->value) {
94 *minor_status = ENOMEM;
95 goto allocation_failure;
98 (void) memcpy(union_name->external_name->value,
99 input_name_buffer->value, input_name_buffer->length);
102 * making a copy of the name_type structure and elements
103 * we now delete it when calling gss_release_name
105 union_name->name_type = (gss_OID) MALLOC(sizeof (gss_OID_desc));
107 if (!union_name->name_type) {
108 *minor_status = ENOMEM;
109 goto allocation_failure;
112 union_name->name_type->elements = (void *)
113 MALLOC(input_name_type->length);
115 if (!union_name->name_type->elements) {
116 *minor_status = ENOMEM;
117 goto allocation_failure;
120 (void) memcpy(union_name->name_type->elements,
121 input_name_type->elements, input_name_type->length);
122 union_name->name_type->length = input_name_type->length;
124 *output_name = (gss_name_t) union_name;
126 return (GSS_S_COMPLETE);
128 allocation_failure:
129 if (union_name) {
131 if (union_name->external_name) {
132 if (union_name->external_name->value)
133 FREE(union_name->external_name->value,
134 union_name->external_name->length);
135 FREE(union_name->external_name,
136 sizeof (gss_buffer_desc));
139 if (union_name->name_type) {
140 FREE(union_name->name_type, sizeof (gss_OID_desc));
142 FREE(union_name, sizeof (gss_union_name_desc));
144 return (major_status);