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"
41 * The implementation must reserve static storage for a
42 * gss_OID_desc object containing the value
43 * {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
44 * "\x01\x02\x01\x01"},
45 * corresponding to an object-identifier value of
46 * {iso(1) member-body(2) United States(840) mit(113554)
47 * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant
48 * GSS_C_NT_USER_NAME should be initialized to point
49 * to that gss_OID_desc.
51 static gss_OID_desc GSS_C_NT_USER_NAME_storage =
52 {10, __DECONST(void *, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01")};
53 gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_storage;
56 * The implementation must reserve static storage for a
57 * gss_OID_desc object containing the value
58 * {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
59 * "\x01\x02\x01\x02"},
60 * corresponding to an object-identifier value of
61 * {iso(1) member-body(2) United States(840) mit(113554)
62 * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}.
63 * The constant GSS_C_NT_MACHINE_UID_NAME should be
64 * initialized to point to that gss_OID_desc.
66 static gss_OID_desc GSS_C_NT_MACHINE_UID_NAME_storage =
67 {10, __DECONST(void *, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02")};
68 gss_OID GSS_C_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_storage;
71 * The implementation must reserve static storage for a
72 * gss_OID_desc object containing the value
73 * {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
74 * "\x01\x02\x01\x03"},
75 * corresponding to an object-identifier value of
76 * {iso(1) member-body(2) United States(840) mit(113554)
77 * infosys(1) gssapi(2) generic(1) string_uid_name(3)}.
78 * The constant GSS_C_NT_STRING_UID_NAME should be
79 * initialized to point to that gss_OID_desc.
81 static gss_OID_desc GSS_C_NT_STRING_UID_NAME_storage =
82 {10, __DECONST(void *, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03")};
83 gss_OID GSS_C_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_storage;
86 * The implementation must reserve static storage for a
87 * gss_OID_desc object containing the value
88 * {6, (void *)"\x2b\x06\x01\x05\x06\x02"},
89 * corresponding to an object-identifier value of
90 * {iso(1) org(3) dod(6) internet(1) security(5)
91 * nametypes(6) gss-host-based-services(2)). The constant
92 * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point
93 * to that gss_OID_desc. This is a deprecated OID value, and
94 * implementations wishing to support hostbased-service names
95 * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID,
96 * defined below, to identify such names;
97 * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym
98 * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input
99 * parameter, but should not be emitted by GSS-API
102 static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_X_storage =
103 {6, __DECONST(void *, "\x2b\x06\x01\x05\x06\x02")};
104 gss_OID GSS_C_NT_HOSTBASED_SERVICE_X = &GSS_C_NT_HOSTBASED_SERVICE_X_storage;
107 * The implementation must reserve static storage for a
108 * gss_OID_desc object containing the value
109 * {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
110 * "\x01\x02\x01\x04"}, corresponding to an
111 * object-identifier value of {iso(1) member-body(2)
112 * Unites States(840) mit(113554) infosys(1) gssapi(2)
113 * generic(1) service_name(4)}. The constant
114 * GSS_C_NT_HOSTBASED_SERVICE should be initialized
115 * to point to that gss_OID_desc.
117 static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_storage =
118 {10, __DECONST(void *, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")};
119 gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVICE_storage;
122 * The implementation must reserve static storage for a
123 * gss_OID_desc object containing the value
124 * {6, (void *)"\x2b\x06\01\x05\x06\x03"},
125 * corresponding to an object identifier value of
126 * {1(iso), 3(org), 6(dod), 1(internet), 5(security),
127 * 6(nametypes), 3(gss-anonymous-name)}. The constant
128 * and GSS_C_NT_ANONYMOUS should be initialized to point
129 * to that gss_OID_desc.
131 static gss_OID_desc GSS_C_NT_ANONYMOUS_storage =
132 {6, __DECONST(void *, "\x2b\x06\01\x05\x06\x03")};
133 gss_OID GSS_C_NT_ANONYMOUS = &GSS_C_NT_ANONYMOUS_storage;
136 * The implementation must reserve static storage for a
137 * gss_OID_desc object containing the value
138 * {6, (void *)"\x2b\x06\x01\x05\x06\x04"},
139 * corresponding to an object-identifier value of
140 * {1(iso), 3(org), 6(dod), 1(internet), 5(security),
141 * 6(nametypes), 4(gss-api-exported-name)}. The constant
142 * GSS_C_NT_EXPORT_NAME should be initialized to point
143 * to that gss_OID_desc.
145 static gss_OID_desc GSS_C_NT_EXPORT_NAME_storage =
146 {6, __DECONST(void *, "\x2b\x06\x01\x05\x06\x04")};
147 gss_OID GSS_C_NT_EXPORT_NAME = &GSS_C_NT_EXPORT_NAME_storage;
150 * This name form shall be represented by the Object Identifier {iso(1)
151 * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
152 * krb5(2) krb5_name(1)}. The recommended symbolic name for this type
153 * is "GSS_KRB5_NT_PRINCIPAL_NAME".
155 static gss_OID_desc GSS_KRB5_NT_PRINCIPAL_NAME_storage =
156 {10, __DECONST(void *, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x01")};
157 gss_OID GSS_KRB5_NT_PRINCIPAL_NAME = &GSS_KRB5_NT_PRINCIPAL_NAME_storage;
160 * This name form shall be represented by the Object Identifier {iso(1)
161 * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
162 * generic(1) user_name(1)}. The recommended symbolic name for this
163 * type is "GSS_KRB5_NT_USER_NAME".
165 gss_OID GSS_KRB5_NT_USER_NAME = &GSS_C_NT_USER_NAME_storage;
168 * This name form shall be represented by the Object Identifier {iso(1)
169 * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
170 * generic(1) machine_uid_name(2)}. The recommended symbolic name for
171 * this type is "GSS_KRB5_NT_MACHINE_UID_NAME".
173 gss_OID GSS_KRB5_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_storage;
176 * This name form shall be represented by the Object Identifier {iso(1)
177 * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
178 * generic(1) string_uid_name(3)}. The recommended symbolic name for
179 * this type is "GSS_KRB5_NT_STRING_UID_NAME".
181 gss_OID GSS_KRB5_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_storage;
184 _gss_find_mn(OM_uint32 *minor_status, struct _gss_name *name, gss_OID mech,
185 struct _gss_mechanism_name **output_mn)
187 OM_uint32 major_status;
188 struct _gss_mech_switch *m;
189 struct _gss_mechanism_name *mn;
193 SLIST_FOREACH(mn, &name->gn_mn, gmn_link) {
194 if (gss_oid_equal(mech, mn->gmn_mech_oid))
200 * If this name is canonical (i.e. there is only an
201 * MN but it is from a different mech), give up now.
203 if (!name->gn_value.value)
204 return (GSS_S_BAD_NAME);
206 m = _gss_find_mech_switch(mech);
208 return (GSS_S_BAD_MECH);
210 mn = malloc(sizeof(struct _gss_mechanism_name));
212 return (GSS_S_FAILURE);
214 major_status = m->gm_import_name(minor_status,
216 (name->gn_type.elements
217 ? &name->gn_type : GSS_C_NO_OID),
219 if (major_status != GSS_S_COMPLETE) {
220 _gss_mg_error(m, major_status, *minor_status);
222 return (major_status);
226 mn->gmn_mech_oid = &m->gm_mech_oid;
227 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);
230 return (GSS_S_COMPLETE);
235 * Make a name from an MN.
238 _gss_make_name(struct _gss_mech_switch *m, gss_name_t new_mn)
240 struct _gss_name *name;
241 struct _gss_mechanism_name *mn;
243 name = malloc(sizeof(struct _gss_name));
246 memset(name, 0, sizeof(struct _gss_name));
248 mn = malloc(sizeof(struct _gss_mechanism_name));
254 SLIST_INIT(&name->gn_mn);
256 mn->gmn_mech_oid = &m->gm_mech_oid;
257 mn->gmn_name = new_mn;
258 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);