xref: /titanic_52/usr/src/lib/libgss/g_dup_name.c (revision 9113a79cf228b8f7bd509b1328adf88659dfe218)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  *  routine gss_duplicate_name
31  *
32  * This routine does not rely on mechanism implementation of this
33  * name, but instead uses mechanism specific gss_import_name routine.
34  */
35 
36 #include <mechglueP.h>
37 #ifdef HAVE_STDLIB_H
38 #include <stdlib.h>
39 #endif
40 #include <string.h>
41 #include <errno.h>
42 
43 OM_uint32
44 gss_duplicate_name(minor_status,
45 		src_name,
46 		dest_name)
47 OM_uint32 *minor_status;
48 const gss_name_t src_name;
49 gss_name_t *dest_name;
50 {
51 		gss_union_name_t src_union, dest_union;
52 		OM_uint32 major_status = GSS_S_FAILURE;
53 
54 
55 	if (!minor_status)
56 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
57 
58 	*minor_status = 0;
59 
60 	/* if output_name is NULL, simply return */
61 	if (dest_name == NULL)
62 		return (GSS_S_CALL_INACCESSIBLE_WRITE | GSS_S_BAD_NAME);
63 
64 	*dest_name = 0;
65 
66 	if (src_name == NULL)
67 		return (GSS_S_CALL_INACCESSIBLE_READ);
68 
69 	src_union = (gss_union_name_t)src_name;
70 
71 	/*
72 	 * First create the union name struct that will hold the external
73 	 * name and the name type.
74 	 */
75 	dest_union = (gss_union_name_t)malloc(sizeof (gss_union_name_desc));
76 	if (!dest_union)
77 		goto allocation_failure;
78 
79 	dest_union->mech_type = 0;
80 	dest_union->mech_name = 0;
81 	dest_union->name_type = 0;
82 	dest_union->external_name = 0;
83 
84 	/* Now copy the external representaion */
85 	if (__gss_create_copy_buffer(src_union->external_name,
86 				&dest_union->external_name, 0))
87 		goto allocation_failure;
88 
89 	if (src_union->name_type != GSS_C_NULL_OID) {
90 		major_status = generic_gss_copy_oid(minor_status,
91 						src_union->name_type,
92 						&dest_union->name_type);
93 		if (major_status != GSS_S_COMPLETE)
94 			goto allocation_failure;
95 	}
96 
97 	/*
98 	 * See if source name is mechanim specific, if so then need to import it
99 	 */
100 	if (src_union->mech_type) {
101 		major_status = generic_gss_copy_oid(minor_status,
102 							src_union->mech_type,
103 							&dest_union->mech_type);
104 		if (major_status != GSS_S_COMPLETE)
105 			goto allocation_failure;
106 
107 		major_status = __gss_import_internal_name(minor_status,
108 							dest_union->mech_type,
109 							dest_union,
110 							&dest_union->mech_name);
111 		if (major_status != GSS_S_COMPLETE)
112 			goto allocation_failure;
113 	}
114 
115 
116 	*dest_name = (gss_name_t)dest_union;
117 	return (GSS_S_COMPLETE);
118 
119 allocation_failure:
120 	if (dest_union) {
121 		if (dest_union->external_name) {
122 			if (dest_union->external_name->value)
123 				free(dest_union->external_name->value);
124 				free(dest_union->external_name);
125 		}
126 		if (dest_union->name_type)
127 			(void) generic_gss_release_oid(minor_status,
128 							&dest_union->name_type);
129 		if (dest_union->mech_name)
130 			(void) __gss_release_internal_name(minor_status,
131 						dest_union->mech_type,
132 						&dest_union->mech_name);
133 		if (dest_union->mech_type)
134 			(void) generic_gss_release_oid(minor_status,
135 							&dest_union->mech_type);
136 		free(dest_union);
137 	}
138 	return (major_status);
139 } /*	gss_duplicate_name	*/
140