17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5503a2b89SPeter Shoults * Common Development and Distribution License (the "License").
6503a2b89SPeter Shoults * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*5e01956fSGlenn Barry * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate * glue routine for gss_display_name()
277c478bd9Sstevel@tonic-gate *
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include <mechglueP.h>
31*5e01956fSGlenn Barry #include "gssapiP_generic.h"
327c478bd9Sstevel@tonic-gate #include <stdio.h>
337c478bd9Sstevel@tonic-gate #ifdef HAVE_STDLIB_H
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate
38503a2b89SPeter Shoults static OM_uint32
val_dsp_name_args(OM_uint32 * minor_status,gss_name_t input_name,gss_buffer_t output_name_buffer,gss_OID * output_name_type)39503a2b89SPeter Shoults val_dsp_name_args(
40503a2b89SPeter Shoults OM_uint32 *minor_status,
41503a2b89SPeter Shoults gss_name_t input_name,
42503a2b89SPeter Shoults gss_buffer_t output_name_buffer,
43503a2b89SPeter Shoults gss_OID *output_name_type)
44503a2b89SPeter Shoults {
45503a2b89SPeter Shoults
46503a2b89SPeter Shoults /* Initialize outputs. */
47503a2b89SPeter Shoults
48503a2b89SPeter Shoults if (minor_status != NULL)
49503a2b89SPeter Shoults *minor_status = 0;
50503a2b89SPeter Shoults
51503a2b89SPeter Shoults if (output_name_buffer != GSS_C_NO_BUFFER) {
52503a2b89SPeter Shoults output_name_buffer->length = 0;
53503a2b89SPeter Shoults output_name_buffer->value = NULL;
54503a2b89SPeter Shoults }
55503a2b89SPeter Shoults
56503a2b89SPeter Shoults if (output_name_type != NULL)
57503a2b89SPeter Shoults *output_name_type = GSS_C_NO_OID;
58503a2b89SPeter Shoults
59503a2b89SPeter Shoults /* Validate arguments. */
60503a2b89SPeter Shoults
61503a2b89SPeter Shoults if (minor_status == NULL)
62503a2b89SPeter Shoults return (GSS_S_CALL_INACCESSIBLE_WRITE);
63503a2b89SPeter Shoults
64503a2b89SPeter Shoults if (output_name_buffer == GSS_C_NO_BUFFER)
65503a2b89SPeter Shoults return (GSS_S_CALL_INACCESSIBLE_WRITE);
66503a2b89SPeter Shoults
67503a2b89SPeter Shoults if (input_name == GSS_C_NO_NAME)
68503a2b89SPeter Shoults return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
69503a2b89SPeter Shoults
70503a2b89SPeter Shoults return (GSS_S_COMPLETE);
71503a2b89SPeter Shoults }
72503a2b89SPeter Shoults
737c478bd9Sstevel@tonic-gate OM_uint32
gss_display_name(minor_status,input_name,output_name_buffer,output_name_type)747c478bd9Sstevel@tonic-gate gss_display_name(minor_status,
757c478bd9Sstevel@tonic-gate input_name,
767c478bd9Sstevel@tonic-gate output_name_buffer,
777c478bd9Sstevel@tonic-gate output_name_type)
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate OM_uint32 * minor_status;
807c478bd9Sstevel@tonic-gate const gss_name_t input_name;
817c478bd9Sstevel@tonic-gate gss_buffer_t output_name_buffer;
827c478bd9Sstevel@tonic-gate gss_OID * output_name_type;
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate OM_uint32 major_status;
867c478bd9Sstevel@tonic-gate gss_union_name_t union_name;
877c478bd9Sstevel@tonic-gate
88503a2b89SPeter Shoults major_status = val_dsp_name_args(minor_status, input_name,
89503a2b89SPeter Shoults output_name_buffer, output_name_type);
90503a2b89SPeter Shoults if (major_status != GSS_S_COMPLETE)
91503a2b89SPeter Shoults return (major_status);
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate union_name = (gss_union_name_t)input_name;
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate if (union_name->mech_type) {
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate * OK, we have a mechanism-specific name; let's use it!
987c478bd9Sstevel@tonic-gate */
997c478bd9Sstevel@tonic-gate return (__gss_display_internal_name(minor_status,
1007c478bd9Sstevel@tonic-gate union_name->mech_type,
1017c478bd9Sstevel@tonic-gate union_name->mech_name,
1027c478bd9Sstevel@tonic-gate output_name_buffer,
1037c478bd9Sstevel@tonic-gate output_name_type));
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate * copy the value of the external_name component of the union
1087c478bd9Sstevel@tonic-gate * name into the output_name_buffer and point the output_name_type
1097c478bd9Sstevel@tonic-gate * to the name_type component of union_name
1107c478bd9Sstevel@tonic-gate */
1117c478bd9Sstevel@tonic-gate if (output_name_type != NULL &&
1127c478bd9Sstevel@tonic-gate union_name->name_type != GSS_C_NULL_OID) {
1137c478bd9Sstevel@tonic-gate major_status = generic_gss_copy_oid(minor_status,
1147c478bd9Sstevel@tonic-gate union_name->name_type,
1157c478bd9Sstevel@tonic-gate output_name_type);
116*5e01956fSGlenn Barry if (major_status != GSS_S_COMPLETE) {
117*5e01956fSGlenn Barry map_errcode(minor_status);
1187c478bd9Sstevel@tonic-gate return (major_status);
1197c478bd9Sstevel@tonic-gate }
120*5e01956fSGlenn Barry }
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate if ((output_name_buffer->value =
1237c478bd9Sstevel@tonic-gate malloc(union_name->external_name->length + 1)) == NULL) {
1247c478bd9Sstevel@tonic-gate if (output_name_type && *output_name_type != GSS_C_NULL_OID) {
1257c478bd9Sstevel@tonic-gate (void) generic_gss_release_oid(minor_status,
1267c478bd9Sstevel@tonic-gate output_name_type);
1277c478bd9Sstevel@tonic-gate *output_name_type = NULL;
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate output_name_buffer->length = union_name->external_name->length;
1327c478bd9Sstevel@tonic-gate (void) memcpy(output_name_buffer->value,
1337c478bd9Sstevel@tonic-gate union_name->external_name->value,
1347c478bd9Sstevel@tonic-gate union_name->external_name->length);
1357c478bd9Sstevel@tonic-gate ((char *)output_name_buffer->value)[output_name_buffer->length] = '\0';
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE);
1387c478bd9Sstevel@tonic-gate }
139