gss_names.c revision 178828
1145256Sjkoshy/*- 2145256Sjkoshy * Copyright (c) 2005 Doug Rabson 3145256Sjkoshy * All rights reserved. 4145256Sjkoshy * 5145256Sjkoshy * Redistribution and use in source and binary forms, with or without 6145256Sjkoshy * modification, are permitted provided that the following conditions 7145256Sjkoshy * are met: 8145256Sjkoshy * 1. Redistributions of source code must retain the above copyright 9145256Sjkoshy * notice, this list of conditions and the following disclaimer. 10145256Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright 11145256Sjkoshy * notice, this list of conditions and the following disclaimer in the 12145256Sjkoshy * documentation and/or other materials provided with the distribution. 13145256Sjkoshy * 14145256Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15145256Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16145256Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17145256Sjkoshy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18145256Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19145256Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20145256Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21145256Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22145256Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23145256Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24145256Sjkoshy * SUCH DAMAGE. 25145256Sjkoshy * 26145256Sjkoshy * $FreeBSD: head/lib/libgssapi/gss_names.c 178828 2008-05-07 13:53:12Z dfr $ 27145256Sjkoshy */ 28145256Sjkoshy 29145256Sjkoshy#include <gssapi/gssapi.h> 30145256Sjkoshy#include <stdlib.h> 31145256Sjkoshy#include <string.h> 32190395Sfabient#include <errno.h> 33145256Sjkoshy 34145256Sjkoshy#include "mech_switch.h" 35145256Sjkoshy#include "name.h" 36147191Sjkoshy#include "utils.h" 37147191Sjkoshy 38147191Sjkoshy/* 39294046Sjtl * The implementation must reserve static storage for a 40294046Sjtl * gss_OID_desc object containing the value 41294046Sjtl * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" 42294046Sjtl * "\x01\x02\x01\x01"}, 43294046Sjtl * corresponding to an object-identifier value of 44294046Sjtl * {iso(1) member-body(2) United States(840) mit(113554) 45294046Sjtl * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant 46294046Sjtl * GSS_C_NT_USER_NAME should be initialized to point 47294046Sjtl * to that gss_OID_desc. 48147191Sjkoshy */ 49147191Sjkoshystatic gss_OID_desc GSS_C_NT_USER_NAME_storage = 50147191Sjkoshy {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01"}; 51147191Sjkoshygss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_storage; 52147191Sjkoshy 53147191Sjkoshy/* 54147191Sjkoshy * The implementation must reserve static storage for a 55147191Sjkoshy * gss_OID_desc object containing the value 56147191Sjkoshy * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" 57147191Sjkoshy * "\x01\x02\x01\x02"}, 58147191Sjkoshy * corresponding to an object-identifier value of 59147191Sjkoshy * {iso(1) member-body(2) United States(840) mit(113554) 60147191Sjkoshy * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}. 61147191Sjkoshy * The constant GSS_C_NT_MACHINE_UID_NAME should be 62147191Sjkoshy * initialized to point to that gss_OID_desc. 63147191Sjkoshy */ 64147191Sjkoshystatic gss_OID_desc GSS_C_NT_MACHINE_UID_NAME_storage = 65147191Sjkoshy {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"}; 66147191Sjkoshygss_OID GSS_C_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_storage; 67147191Sjkoshy 68147191Sjkoshy/* 69147191Sjkoshy * The implementation must reserve static storage for a 70145256Sjkoshy * gss_OID_desc object containing the value 71145256Sjkoshy * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" 72145256Sjkoshy * "\x01\x02\x01\x03"}, 73190395Sfabient * corresponding to an object-identifier value of 74145256Sjkoshy * {iso(1) member-body(2) United States(840) mit(113554) 75145256Sjkoshy * infosys(1) gssapi(2) generic(1) string_uid_name(3)}. 76145256Sjkoshy * The constant GSS_C_NT_STRING_UID_NAME should be 77145774Sjkoshy * initialized to point to that gss_OID_desc. 78145256Sjkoshy */ 79147191Sjkoshystatic gss_OID_desc GSS_C_NT_STRING_UID_NAME_storage = 80226514Sfabient {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03"}; 81145256Sjkoshygss_OID GSS_C_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_storage; 82145256Sjkoshy 83145256Sjkoshy/* 84147191Sjkoshy * The implementation must reserve static storage for a 85147191Sjkoshy * gss_OID_desc object containing the value 86145256Sjkoshy * {6, (void *)"\x2b\x06\x01\x05\x06\x02"}, 87145256Sjkoshy * corresponding to an object-identifier value of 88145256Sjkoshy * {iso(1) org(3) dod(6) internet(1) security(5) 89145256Sjkoshy * nametypes(6) gss-host-based-services(2)). The constant 90145256Sjkoshy * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point 91145256Sjkoshy * to that gss_OID_desc. This is a deprecated OID value, and 92145256Sjkoshy * implementations wishing to support hostbased-service names 93145774Sjkoshy * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID, 94145256Sjkoshy * defined below, to identify such names; 95147191Sjkoshy * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym 96145256Sjkoshy * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input 97145256Sjkoshy * parameter, but should not be emitted by GSS-API 98145256Sjkoshy * implementations 99147191Sjkoshy */ 100147191Sjkoshystatic gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_X_storage = 101145256Sjkoshy {6, (void *)(uintptr_t)"\x2b\x06\x01\x05\x06\x02"}; 102233321Sjkoshygss_OID GSS_C_NT_HOSTBASED_SERVICE_X = &GSS_C_NT_HOSTBASED_SERVICE_X_storage; 103145256Sjkoshy 104145256Sjkoshy/* 105145256Sjkoshy * The implementation must reserve static storage for a 106145256Sjkoshy * gss_OID_desc object containing the value 107145256Sjkoshy * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" 108145256Sjkoshy * "\x01\x02\x01\x04"}, corresponding to an 109145256Sjkoshy * object-identifier value of {iso(1) member-body(2) 110145256Sjkoshy * Unites States(840) mit(113554) infosys(1) gssapi(2) 111145256Sjkoshy * generic(1) service_name(4)}. The constant 112190395Sfabient * GSS_C_NT_HOSTBASED_SERVICE should be initialized 113145256Sjkoshy * to point to that gss_OID_desc. 114145256Sjkoshy */ 115static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_storage = 116 {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"}; 117gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVICE_storage; 118 119/* 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. 128 */ 129static gss_OID_desc GSS_C_NT_ANONYMOUS_storage = 130 {6, (void *)(uintptr_t)"\x2b\x06\01\x05\x06\x03"}; 131gss_OID GSS_C_NT_ANONYMOUS = &GSS_C_NT_ANONYMOUS_storage; 132 133/* 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. 142 */ 143static gss_OID_desc GSS_C_NT_EXPORT_NAME_storage = 144 {6, (void *)(uintptr_t)"\x2b\x06\x01\x05\x06\x04"}; 145gss_OID GSS_C_NT_EXPORT_NAME = &GSS_C_NT_EXPORT_NAME_storage; 146 147/* 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". 152 */ 153static gss_OID_desc GSS_KRB5_NT_PRINCIPAL_NAME_storage = 154 {10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x01"}; 155gss_OID GSS_KRB5_NT_PRINCIPAL_NAME = &GSS_KRB5_NT_PRINCIPAL_NAME_storage; 156 157/* 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". 162 */ 163gss_OID GSS_KRB5_NT_USER_NAME = &GSS_C_NT_USER_NAME_storage; 164 165/* 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". 170 */ 171gss_OID GSS_KRB5_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_storage; 172 173/* 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". 178 */ 179gss_OID GSS_KRB5_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_storage; 180 181OM_uint32 182_gss_find_mn(OM_uint32 *minor_status, struct _gss_name *name, gss_OID mech, 183 struct _gss_mechanism_name **output_mn) 184{ 185 OM_uint32 major_status; 186 struct _gss_mech_switch *m; 187 struct _gss_mechanism_name *mn; 188 189 *output_mn = NULL; 190 191 SLIST_FOREACH(mn, &name->gn_mn, gmn_link) { 192 if (gss_oid_equal(mech, mn->gmn_mech_oid)) 193 break; 194 } 195 196 if (!mn) { 197 /* 198 * If this name is canonical (i.e. there is only an 199 * MN but it is from a different mech), give up now. 200 */ 201 if (!name->gn_value.value) 202 return (GSS_S_BAD_NAME); 203 204 m = _gss_find_mech_switch(mech); 205 if (!m) 206 return (GSS_S_BAD_MECH); 207 208 mn = malloc(sizeof(struct _gss_mechanism_name)); 209 if (!mn) 210 return (GSS_S_FAILURE); 211 212 major_status = m->gm_import_name(minor_status, 213 &name->gn_value, 214 (name->gn_type.elements 215 ? &name->gn_type : GSS_C_NO_OID), 216 &mn->gmn_name); 217 if (major_status != GSS_S_COMPLETE) { 218 _gss_mg_error(m, major_status, *minor_status); 219 free(mn); 220 return (major_status); 221 } 222 223 mn->gmn_mech = m; 224 mn->gmn_mech_oid = &m->gm_mech_oid; 225 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link); 226 } 227 *output_mn = mn; 228 return (GSS_S_COMPLETE); 229} 230 231 232/* 233 * Make a name from an MN. 234 */ 235struct _gss_name * 236_gss_make_name(struct _gss_mech_switch *m, gss_name_t new_mn) 237{ 238 struct _gss_name *name; 239 struct _gss_mechanism_name *mn; 240 241 name = malloc(sizeof(struct _gss_name)); 242 if (!name) 243 return (0); 244 memset(name, 0, sizeof(struct _gss_name)); 245 246 mn = malloc(sizeof(struct _gss_mechanism_name)); 247 if (!mn) { 248 free(name); 249 return (0); 250 } 251 252 SLIST_INIT(&name->gn_mn); 253 mn->gmn_mech = m; 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); 257 258 return (name); 259} 260 261