2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2005 Doug Rabson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <gssapi/gssapi.h>
36 #include "mech_switch.h"
39 OM_uint32 gss_duplicate_name(OM_uint32 *minor_status,
40 const gss_name_t src_name,
41 gss_name_t *dest_name)
43 OM_uint32 major_status;
44 struct _gss_name *name = (struct _gss_name *) src_name;
45 struct _gss_name *new_name;
46 struct _gss_mechanism_name *mn;
49 *dest_name = GSS_C_NO_NAME;
52 * If this name has a value (i.e. it didn't come from
53 * gss_canonicalize_name(), we re-import the thing. Otherwise,
54 * we make a copy of the mechanism names.
56 if (name->gn_value.value) {
57 major_status = gss_import_name(minor_status,
58 &name->gn_value, &name->gn_type, dest_name);
59 if (major_status != GSS_S_COMPLETE)
60 return (major_status);
61 new_name = (struct _gss_name *) *dest_name;
63 SLIST_FOREACH(mn, &name->gn_mn, gmn_link) {
64 struct _gss_mechanism_name *mn2;
65 _gss_find_mn(minor_status, new_name,
66 mn->gmn_mech_oid, &mn2);
69 new_name = malloc(sizeof(struct _gss_name));
71 *minor_status = ENOMEM;
72 return (GSS_S_FAILURE);
74 memset(new_name, 0, sizeof(struct _gss_name));
75 SLIST_INIT(&new_name->gn_mn);
76 *dest_name = (gss_name_t) new_name;
78 SLIST_FOREACH(mn, &name->gn_mn, gmn_link) {
79 struct _gss_mechanism_name *new_mn;
81 new_mn = malloc(sizeof(*new_mn));
83 *minor_status = ENOMEM;
84 return (GSS_S_FAILURE);
86 new_mn->gmn_mech = mn->gmn_mech;
87 new_mn->gmn_mech_oid = mn->gmn_mech_oid;
90 mn->gmn_mech->gm_duplicate_name(minor_status,
91 mn->gmn_name, &new_mn->gmn_name);
92 if (major_status != GSS_S_COMPLETE) {
96 SLIST_INSERT_HEAD(&new_name->gn_mn, new_mn, gmn_link);
101 return (GSS_S_COMPLETE);