xref: /titanic_50/usr/src/lib/libgss/g_dsp_name.c (revision 753a6d457b330b1b29b2d3eefcd0831116ce950d)
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  *  glue routine for gss_display_name()
31  *
32  */
33 
34 #include <mechglueP.h>
35 #include <stdio.h>
36 #ifdef HAVE_STDLIB_H
37 #include <stdlib.h>
38 #endif
39 #include <string.h>
40 
41 OM_uint32
42 gss_display_name(minor_status,
43 			input_name,
44 			output_name_buffer,
45 			output_name_type)
46 
47 OM_uint32 *			minor_status;
48 const gss_name_t		input_name;
49 gss_buffer_t			output_name_buffer;
50 gss_OID *			output_name_type;
51 
52 {
53 	OM_uint32			major_status;
54 	gss_union_name_t		union_name;
55 
56 	if (minor_status == NULL)
57 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
58 	*minor_status = 0;
59 
60 	if (input_name == 0)
61 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
62 
63 	if (output_name_buffer == NULL)
64 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
65 
66 	if (output_name_type)
67 		*output_name_type = NULL;
68 
69 	union_name = (gss_union_name_t)input_name;
70 
71 	if (union_name->mech_type) {
72 		/*
73 		 * OK, we have a mechanism-specific name; let's use it!
74 		 */
75 		return (__gss_display_internal_name(minor_status,
76 							union_name->mech_type,
77 							union_name->mech_name,
78 							output_name_buffer,
79 							output_name_type));
80 	}
81 
82 	/*
83 	 * copy the value of the external_name component of the union
84 	 * name into the output_name_buffer and point the output_name_type
85 	 * to the name_type component of union_name
86 	 */
87 	if (output_name_type != NULL &&
88 	    union_name->name_type != GSS_C_NULL_OID) {
89 		major_status = generic_gss_copy_oid(minor_status,
90 						union_name->name_type,
91 						output_name_type);
92 		if (major_status != GSS_S_COMPLETE)
93 			return (major_status);
94 	}
95 
96 	if ((output_name_buffer->value =
97 		malloc(union_name->external_name->length + 1)) == NULL) {
98 		if (output_name_type && *output_name_type != GSS_C_NULL_OID) {
99 			(void) generic_gss_release_oid(minor_status,
100 						    output_name_type);
101 			*output_name_type = NULL;
102 		}
103 		return (GSS_S_FAILURE);
104 	}
105 	output_name_buffer->length = union_name->external_name->length;
106 	(void) memcpy(output_name_buffer->value,
107 		    union_name->external_name->value,
108 		union_name->external_name->length);
109 	((char *)output_name_buffer->value)[output_name_buffer->length] = '\0';
110 
111 	return (GSS_S_COMPLETE);
112 }
113