2 * Copyright (c) 2005 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <gssapi/gssapi.h>
34 #include "mech_switch.h"
39 * The implementation must reserve static storage for a
40 * gss_OID_desc object containing the value
41 * {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
42 * "\x01\x02\x01\x01"},
43 * corresponding to an object-identifier value of
44 * {iso(1) member-body(2) United States(840) mit(113554)
45 * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant
46 * GSS_C_NT_USER_NAME should be initialized to point
47 * to that gss_OID_desc.
49 static gss_OID_desc GSS_C_NT_USER_NAME_storage =
50 {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01"};
51 gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_storage;
54 * The implementation must reserve static storage for a
55 * gss_OID_desc object containing the value
56 * {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
57 * "\x01\x02\x01\x02"},
58 * corresponding to an object-identifier value of
59 * {iso(1) member-body(2) United States(840) mit(113554)
60 * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}.
61 * The constant GSS_C_NT_MACHINE_UID_NAME should be
62 * initialized to point to that gss_OID_desc.
64 static gss_OID_desc GSS_C_NT_MACHINE_UID_NAME_storage =
65 {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
66 gss_OID GSS_C_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_storage;
69 * The implementation must reserve static storage for a
70 * gss_OID_desc object containing the value
71 * {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
72 * "\x01\x02\x01\x03"},
73 * corresponding to an object-identifier value of
74 * {iso(1) member-body(2) United States(840) mit(113554)
75 * infosys(1) gssapi(2) generic(1) string_uid_name(3)}.
76 * The constant GSS_C_NT_STRING_UID_NAME should be
77 * initialized to point to that gss_OID_desc.
79 static gss_OID_desc GSS_C_NT_STRING_UID_NAME_storage =
80 {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03"};
81 gss_OID GSS_C_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_storage;
84 * The implementation must reserve static storage for a
85 * gss_OID_desc object containing the value
86 * {6, (void *)"\x2b\x06\x01\x05\x06\x02"},
87 * corresponding to an object-identifier value of
88 * {iso(1) org(3) dod(6) internet(1) security(5)
89 * nametypes(6) gss-host-based-services(2)). The constant
90 * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point
91 * to that gss_OID_desc. This is a deprecated OID value, and
92 * implementations wishing to support hostbased-service names
93 * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID,
94 * defined below, to identify such names;
95 * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym
96 * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input
97 * parameter, but should not be emitted by GSS-API
100 static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_X_storage =
101 {6, (void *)(uintptr_t)"\x2b\x06\x01\x05\x06\x02"};
102 gss_OID GSS_C_NT_HOSTBASED_SERVICE_X = &GSS_C_NT_HOSTBASED_SERVICE_X_storage;
105 * The implementation must reserve static storage for a
106 * gss_OID_desc object containing the value
107 * {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
108 * "\x01\x02\x01\x04"}, corresponding to an
109 * object-identifier value of {iso(1) member-body(2)
110 * Unites States(840) mit(113554) infosys(1) gssapi(2)
111 * generic(1) service_name(4)}. The constant
112 * GSS_C_NT_HOSTBASED_SERVICE should be initialized
113 * to point to that gss_OID_desc.
115 static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_storage =
116 {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"};
117 gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVICE_storage;
120 * The implementation must reserve static storage for a
121 * gss_OID_desc object containing the value
122 * {6, (void *)"\x2b\x06\01\x05\x06\x03"},
123 * corresponding to an object identifier value of
124 * {1(iso), 3(org), 6(dod), 1(internet), 5(security),
125 * 6(nametypes), 3(gss-anonymous-name)}. The constant
126 * and GSS_C_NT_ANONYMOUS should be initialized to point
127 * to that gss_OID_desc.
129 static gss_OID_desc GSS_C_NT_ANONYMOUS_storage =
130 {6, (void *)(uintptr_t)"\x2b\x06\01\x05\x06\x03"};
131 gss_OID GSS_C_NT_ANONYMOUS = &GSS_C_NT_ANONYMOUS_storage;
134 * The implementation must reserve static storage for a
135 * gss_OID_desc object containing the value
136 * {6, (void *)"\x2b\x06\x01\x05\x06\x04"},
137 * corresponding to an object-identifier value of
138 * {1(iso), 3(org), 6(dod), 1(internet), 5(security),
139 * 6(nametypes), 4(gss-api-exported-name)}. The constant
140 * GSS_C_NT_EXPORT_NAME should be initialized to point
141 * to that gss_OID_desc.
143 static gss_OID_desc GSS_C_NT_EXPORT_NAME_storage =
144 {6, (void *)(uintptr_t)"\x2b\x06\x01\x05\x06\x04"};
145 gss_OID GSS_C_NT_EXPORT_NAME = &GSS_C_NT_EXPORT_NAME_storage;
148 * This name form shall be represented by the Object Identifier {iso(1)
149 * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
150 * krb5(2) krb5_name(1)}. The recommended symbolic name for this type
151 * is "GSS_KRB5_NT_PRINCIPAL_NAME".
153 static gss_OID_desc GSS_KRB5_NT_PRINCIPAL_NAME_storage =
154 {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x01"};
155 gss_OID GSS_KRB5_NT_PRINCIPAL_NAME = &GSS_KRB5_NT_PRINCIPAL_NAME_storage;
158 * This name form shall be represented by the Object Identifier {iso(1)
159 * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
160 * generic(1) user_name(1)}. The recommended symbolic name for this
161 * type is "GSS_KRB5_NT_USER_NAME".
163 gss_OID GSS_KRB5_NT_USER_NAME = &GSS_C_NT_USER_NAME_storage;
166 * This name form shall be represented by the Object Identifier {iso(1)
167 * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
168 * generic(1) machine_uid_name(2)}. The recommended symbolic name for
169 * this type is "GSS_KRB5_NT_MACHINE_UID_NAME".
171 gss_OID GSS_KRB5_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_storage;
174 * This name form shall be represented by the Object Identifier {iso(1)
175 * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
176 * generic(1) string_uid_name(3)}. The recommended symbolic name for
177 * this type is "GSS_KRB5_NT_STRING_UID_NAME".
179 gss_OID GSS_KRB5_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_storage;
182 _gss_find_mn(OM_uint32 *minor_status, struct _gss_name *name, gss_OID mech,
183 struct _gss_mechanism_name **output_mn)
185 OM_uint32 major_status;
186 struct _gss_mech_switch *m;
187 struct _gss_mechanism_name *mn;
191 SLIST_FOREACH(mn, &name->gn_mn, gmn_link) {
192 if (gss_oid_equal(mech, mn->gmn_mech_oid))
198 * If this name is canonical (i.e. there is only an
199 * MN but it is from a different mech), give up now.
201 if (!name->gn_value.value)
202 return (GSS_S_BAD_NAME);
204 m = _gss_find_mech_switch(mech);
206 return (GSS_S_BAD_MECH);
208 mn = malloc(sizeof(struct _gss_mechanism_name));
210 return (GSS_S_FAILURE);
212 major_status = m->gm_import_name(minor_status,
214 (name->gn_type.elements
215 ? &name->gn_type : GSS_C_NO_OID),
217 if (major_status != GSS_S_COMPLETE) {
218 _gss_mg_error(m, major_status, *minor_status);
220 return (major_status);
224 mn->gmn_mech_oid = &m->gm_mech_oid;
225 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);
228 return (GSS_S_COMPLETE);
233 * Make a name from an MN.
236 _gss_make_name(struct _gss_mech_switch *m, gss_name_t new_mn)
238 struct _gss_name *name;
239 struct _gss_mechanism_name *mn;
241 name = malloc(sizeof(struct _gss_name));
244 memset(name, 0, sizeof(struct _gss_name));
246 mn = malloc(sizeof(struct _gss_mechanism_name));
252 SLIST_INIT(&name->gn_mn);
254 mn->gmn_mech_oid = &m->gm_mech_oid;
255 mn->gmn_name = new_mn;
256 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);