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"
44 updateusage(gss_cred_usage_t usage, int *usagemask)
46 if (usage == GSS_C_BOTH)
47 *usagemask |= AUSAGE | IUSAGE;
48 else if (usage == GSS_C_ACCEPT)
50 else if (usage == GSS_C_INITIATE)
55 gss_inquire_cred(OM_uint32 *minor_status,
56 const gss_cred_id_t cred_handle,
59 gss_cred_usage_t *cred_usage,
60 gss_OID_set *mechanisms)
62 OM_uint32 major_status;
63 struct _gss_mech_switch *m;
64 struct _gss_cred *cred = (struct _gss_cred *) cred_handle;
65 struct _gss_name *name;
66 struct _gss_mechanism_name *mn;
67 OM_uint32 min_lifetime;
70 gss_cred_usage_t usage;
76 *name_ret = GSS_C_NO_NAME;
82 *mechanisms = GSS_C_NO_OID_SET;
85 name = malloc(sizeof(struct _gss_name));
87 *minor_status = ENOMEM;
88 return (GSS_S_FAILURE);
90 memset(name, 0, sizeof(struct _gss_name));
91 SLIST_INIT(&name->gn_mn);
97 major_status = gss_create_empty_oid_set(minor_status,
100 if (name) free(name);
101 return (major_status);
105 min_lifetime = GSS_C_INDEFINITE;
107 struct _gss_mechanism_cred *mc;
109 SLIST_FOREACH(mc, &cred->gc_mc, gmc_link) {
111 OM_uint32 mc_lifetime;
113 major_status = mc->gmc_mech->gm_inquire_cred(minor_status,
114 mc->gmc_cred, &mc_name, &mc_lifetime, &usage, NULL);
118 updateusage(usage, &usagemask);
119 if (name && mc_name) {
120 mn = malloc(sizeof(struct _gss_mechanism_name));
122 mc->gmc_mech->gm_release_name(minor_status,
126 mn->gmn_mech = mc->gmc_mech;
127 mn->gmn_mech_oid = mc->gmc_mech_oid;
128 mn->gmn_name = mc_name;
129 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);
130 } else if (mc_name) {
131 mc->gmc_mech->gm_release_name(minor_status,
135 if (mc_lifetime < min_lifetime)
136 min_lifetime = mc_lifetime;
139 gss_add_oid_set_member(minor_status,
140 mc->gmc_mech_oid, mechanisms);
144 SLIST_FOREACH(m, &_gss_mechs, gm_link) {
146 OM_uint32 mc_lifetime;
148 major_status = m->gm_inquire_cred(minor_status,
149 GSS_C_NO_CREDENTIAL, &mc_name, &mc_lifetime,
154 updateusage(usage, &usagemask);
155 if (name && mc_name) {
157 sizeof(struct _gss_mechanism_name));
160 minor_status, &mc_name);
164 mn->gmn_mech_oid = &m->gm_mech_oid;
165 mn->gmn_name = mc_name;
166 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);
167 } else if (mc_name) {
168 m->gm_release_name(minor_status,
172 if (mc_lifetime < min_lifetime)
173 min_lifetime = mc_lifetime;
176 gss_add_oid_set_member(minor_status,
177 &m->gm_mech_oid, mechanisms);
183 gss_name_t n = (gss_name_t)name;
185 gss_release_name(minor_status, &n);
186 gss_release_oid_set(minor_status, mechanisms);
188 return (GSS_S_NO_CRED);
193 *name_ret = (gss_name_t) name;
195 *lifetime = min_lifetime;
197 if ((usagemask & (AUSAGE|IUSAGE)) == (AUSAGE|IUSAGE))
198 *cred_usage = GSS_C_BOTH;
199 else if (usagemask & IUSAGE)
200 *cred_usage = GSS_C_INITIATE;
201 else if (usagemask & AUSAGE)
202 *cred_usage = GSS_C_ACCEPT;
204 return (GSS_S_COMPLETE);