640 number_to_scaled_string is duplicated in several commands
[unleashed.git] / usr / src / lib / libgss / g_dup_name.c
blob7ecaf1d45f5f739d7e1be73dfbaac4b00ad2e74b
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
26 * routine gss_duplicate_name
28 * This routine does not rely on mechanism implementation of this
29 * name, but instead uses mechanism specific gss_import_name routine.
32 #include <mechglueP.h>
33 #include "gssapiP_generic.h"
34 #ifdef HAVE_STDLIB_H
35 #include <stdlib.h>
36 #endif
37 #include <string.h>
38 #include <errno.h>
40 static OM_uint32
41 val_dup_name_args(
42 OM_uint32 *minor_status,
43 const gss_name_t src_name,
44 gss_name_t *dest_name)
47 /* Initialize outputs. */
49 if (minor_status != NULL)
50 *minor_status = 0;
52 if (dest_name != NULL)
53 *dest_name = GSS_C_NO_NAME;
55 /* Validate arguments. */
57 if (minor_status == NULL)
58 return (GSS_S_CALL_INACCESSIBLE_WRITE);
60 /* if output_name is NULL, simply return */
61 if (dest_name == NULL)
62 return (GSS_S_CALL_INACCESSIBLE_WRITE);
64 if (src_name == GSS_C_NO_NAME)
65 return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
67 return (GSS_S_COMPLETE);
70 OM_uint32
71 gss_duplicate_name(OM_uint32 *minor_status, const gss_name_t src_name,
72 gss_name_t *dest_name)
74 gss_union_name_t src_union, dest_union;
75 OM_uint32 major_status = GSS_S_FAILURE;
77 major_status = val_dup_name_args(minor_status, src_name, dest_name);
78 if (major_status != GSS_S_COMPLETE)
79 return (major_status);
81 major_status = GSS_S_FAILURE;
83 src_union = (gss_union_name_t)src_name;
86 * First create the union name struct that will hold the external
87 * name and the name type.
89 dest_union = (gss_union_name_t)malloc(sizeof (gss_union_name_desc));
90 if (!dest_union)
91 goto allocation_failure;
93 dest_union->mech_type = 0;
94 dest_union->mech_name = 0;
95 dest_union->name_type = 0;
96 dest_union->external_name = 0;
98 /* Now copy the external representaion */
99 if (gssint_create_copy_buffer(src_union->external_name,
100 &dest_union->external_name, 0))
101 goto allocation_failure;
103 if (src_union->name_type != GSS_C_NULL_OID) {
104 major_status = generic_gss_copy_oid(minor_status,
105 src_union->name_type, &dest_union->name_type);
106 if (major_status != GSS_S_COMPLETE) {
107 map_errcode(minor_status);
108 goto allocation_failure;
113 * See if source name is mechanim specific, if so then need to import it
115 if (src_union->mech_type) {
116 major_status = generic_gss_copy_oid(minor_status,
117 src_union->mech_type, &dest_union->mech_type);
118 if (major_status != GSS_S_COMPLETE) {
119 map_errcode(minor_status);
120 goto allocation_failure;
123 major_status = __gss_import_internal_name(minor_status,
124 dest_union->mech_type, dest_union, &dest_union->mech_name);
125 if (major_status != GSS_S_COMPLETE)
126 goto allocation_failure;
130 *dest_name = (gss_name_t)dest_union;
131 return (GSS_S_COMPLETE);
133 allocation_failure:
134 if (dest_union) {
135 if (dest_union->external_name) {
136 free(dest_union->external_name->value);
137 free(dest_union->external_name);
139 if (dest_union->name_type) {
140 (void) generic_gss_release_oid(minor_status,
141 &dest_union->name_type);
143 if (dest_union->mech_name) {
144 (void) __gss_release_internal_name(minor_status,
145 dest_union->mech_type, &dest_union->mech_name);
147 if (dest_union->mech_type) {
148 (void) generic_gss_release_oid(minor_status,
149 &dest_union->mech_type);
151 free(dest_union);
153 return (major_status);
154 } /* gss_duplicate_name */