6324 Add an `ndp' tool for manipulating the neighbors table
[illumos-gate.git] / usr / src / uts / common / gssapi / gss_import_name.c
blob78425191e4ebe89e342906a8e22156c1962301d3
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.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * glue routine gss_import_name
34 #include "mechglueP.h"
35 #include <sys/errno.h>
36 OM_uint32
37 gss_import_name(
38 OM_uint32 *minor_status,
39 const gss_buffer_t input_name_buffer,
40 const gss_OID input_name_type,
41 gss_name_t *output_name)
44 gss_union_name_t union_name;
45 OM_uint32 major_status = GSS_S_FAILURE;
47 if (minor_status)
48 *minor_status = 0;
50 /* if output_name is NULL, simply return */
52 if (output_name == NULL)
53 return (GSS_S_COMPLETE);
55 *output_name = 0;
57 if (input_name_buffer == GSS_C_NO_BUFFER || input_name_type == NULL)
58 return (GSS_S_BAD_NAME);
61 * First create the union name struct that will hold the external
62 * name and the name type.
65 union_name = (gss_union_name_t) MALLOC(sizeof (gss_union_name_desc));
67 if (!union_name) {
68 *minor_status = ENOMEM;
69 goto allocation_failure;
71 union_name->mech_type = 0;
72 union_name->mech_name = 0;
73 union_name->name_type = 0;
74 union_name->external_name = 0;
77 * All we do here is record the external name and name_type.
78 * When the name is actually used, the underlying gss_import_name()
79 * is called for the appropriate mechanism.
80 * Since the name type may be a constant or comming from the
81 * rpc resoults, we must make a copy.
83 union_name->external_name =
84 (gss_buffer_t) MALLOC(sizeof (gss_buffer_desc));
86 if (!union_name->external_name) {
87 *minor_status = ENOMEM;
88 goto allocation_failure;
91 union_name->external_name->length = input_name_buffer->length;
92 union_name->external_name->value =
93 (void *) MALLOC(input_name_buffer->length);
95 if (!union_name->external_name->value) {
96 *minor_status = ENOMEM;
97 goto allocation_failure;
100 (void) memcpy(union_name->external_name->value,
101 input_name_buffer->value, input_name_buffer->length);
104 * making a copy of the name_type structure and elements
105 * we now delete it when calling gss_release_name
107 union_name->name_type = (gss_OID) MALLOC(sizeof (gss_OID_desc));
109 if (!union_name->name_type) {
110 *minor_status = ENOMEM;
111 goto allocation_failure;
114 union_name->name_type->elements = (void *)
115 MALLOC(input_name_type->length);
117 if (!union_name->name_type->elements) {
118 *minor_status = ENOMEM;
119 goto allocation_failure;
122 (void) memcpy(union_name->name_type->elements,
123 input_name_type->elements, input_name_type->length);
124 union_name->name_type->length = input_name_type->length;
126 *output_name = (gss_name_t) union_name;
128 return (GSS_S_COMPLETE);
130 allocation_failure:
131 if (union_name) {
133 if (union_name->external_name) {
134 if (union_name->external_name->value)
135 FREE(union_name->external_name->value,
136 union_name->external_name->length);
137 FREE(union_name->external_name,
138 sizeof (gss_buffer_desc));
141 if (union_name->name_type) {
142 FREE(union_name->name_type, sizeof (gss_OID_desc));
144 FREE(union_name, sizeof (gss_union_name_desc));
146 return (major_status);