xref: /illumos-gate/usr/src/lib/libgss/g_dsp_name.c (revision 43449cdcd0600512dd862537f2cf014140dd0844)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 /*
26  *  glue routine for gss_display_name()
27  *
28  */
29 
30 #include <mechglueP.h>
31 #include "gssapiP_generic.h"
32 #include <stdio.h>
33 #ifdef HAVE_STDLIB_H
34 #include <stdlib.h>
35 #endif
36 #include <string.h>
37 
38 static OM_uint32
39 val_dsp_name_args(
40 	OM_uint32 *minor_status,
41 	gss_name_t input_name,
42 	gss_buffer_t output_name_buffer,
43 	gss_OID *output_name_type)
44 {
45 
46 	/* Initialize outputs. */
47 
48 	if (minor_status != NULL)
49 		*minor_status = 0;
50 
51 	if (output_name_buffer != GSS_C_NO_BUFFER) {
52 		output_name_buffer->length = 0;
53 		output_name_buffer->value = NULL;
54 	}
55 
56 	if (output_name_type != NULL)
57 		*output_name_type = GSS_C_NO_OID;
58 
59 	/* Validate arguments. */
60 
61 	if (minor_status == NULL)
62 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
63 
64 	if (output_name_buffer == GSS_C_NO_BUFFER)
65 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
66 
67 	if (input_name == GSS_C_NO_NAME)
68 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
69 
70 	return (GSS_S_COMPLETE);
71 }
72 
73 OM_uint32
74 gss_display_name(minor_status,
75 			input_name,
76 			output_name_buffer,
77 			output_name_type)
78 
79 OM_uint32 *			minor_status;
80 const gss_name_t		input_name;
81 gss_buffer_t			output_name_buffer;
82 gss_OID *			output_name_type;
83 
84 {
85 	OM_uint32			major_status;
86 	gss_union_name_t		union_name;
87 
88 	major_status = val_dsp_name_args(minor_status, input_name,
89 					output_name_buffer, output_name_type);
90 	if (major_status != GSS_S_COMPLETE)
91 		return (major_status);
92 
93 	union_name = (gss_union_name_t)input_name;
94 
95 	if (union_name->mech_type) {
96 		/*
97 		 * OK, we have a mechanism-specific name; let's use it!
98 		 */
99 		return (__gss_display_internal_name(minor_status,
100 							union_name->mech_type,
101 							union_name->mech_name,
102 							output_name_buffer,
103 							output_name_type));
104 	}
105 
106 	/*
107 	 * copy the value of the external_name component of the union
108 	 * name into the output_name_buffer and point the output_name_type
109 	 * to the name_type component of union_name
110 	 */
111 	if (output_name_type != NULL &&
112 	    union_name->name_type != GSS_C_NULL_OID) {
113 		major_status = generic_gss_copy_oid(minor_status,
114 						union_name->name_type,
115 						output_name_type);
116 		if (major_status != GSS_S_COMPLETE) {
117 			map_errcode(minor_status);
118 			return (major_status);
119 		}
120 	}
121 
122 	if ((output_name_buffer->value =
123 		malloc(union_name->external_name->length + 1)) == NULL) {
124 		if (output_name_type && *output_name_type != GSS_C_NULL_OID) {
125 			(void) generic_gss_release_oid(minor_status,
126 						    output_name_type);
127 			*output_name_type = NULL;
128 		}
129 		return (GSS_S_FAILURE);
130 	}
131 	output_name_buffer->length = union_name->external_name->length;
132 	(void) memcpy(output_name_buffer->value,
133 		    union_name->external_name->value,
134 		union_name->external_name->length);
135 	((char *)output_name_buffer->value)[output_name_buffer->length] = '\0';
136 
137 	return (GSS_S_COMPLETE);
138 }
139