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"
42 updateusage(gss_cred_usage_t usage, int *usagemask)
44 if (usage == GSS_C_BOTH)
45 *usagemask |= AUSAGE | IUSAGE;
46 else if (usage == GSS_C_ACCEPT)
48 else if (usage == GSS_C_INITIATE)
53 gss_inquire_cred(OM_uint32 *minor_status,
54 const gss_cred_id_t cred_handle,
57 gss_cred_usage_t *cred_usage,
58 gss_OID_set *mechanisms)
60 OM_uint32 major_status;
61 struct _gss_mech_switch *m;
62 struct _gss_cred *cred = (struct _gss_cred *) cred_handle;
63 struct _gss_name *name;
64 struct _gss_mechanism_name *mn;
65 OM_uint32 min_lifetime;
68 gss_cred_usage_t usage;
74 *name_ret = GSS_C_NO_NAME;
80 *mechanisms = GSS_C_NO_OID_SET;
83 name = malloc(sizeof(struct _gss_name));
85 *minor_status = ENOMEM;
86 return (GSS_S_FAILURE);
88 memset(name, 0, sizeof(struct _gss_name));
89 SLIST_INIT(&name->gn_mn);
95 major_status = gss_create_empty_oid_set(minor_status,
99 return (major_status);
103 min_lifetime = GSS_C_INDEFINITE;
105 struct _gss_mechanism_cred *mc;
107 SLIST_FOREACH(mc, &cred->gc_mc, gmc_link) {
109 OM_uint32 mc_lifetime;
111 major_status = mc->gmc_mech->gm_inquire_cred(minor_status,
112 mc->gmc_cred, &mc_name, &mc_lifetime, &usage, NULL);
116 updateusage(usage, &usagemask);
117 if (name && mc_name) {
118 mn = malloc(sizeof(struct _gss_mechanism_name));
120 mc->gmc_mech->gm_release_name(minor_status,
124 mn->gmn_mech = mc->gmc_mech;
125 mn->gmn_mech_oid = mc->gmc_mech_oid;
126 mn->gmn_name = mc_name;
127 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);
128 } else if (mc_name) {
129 mc->gmc_mech->gm_release_name(minor_status,
133 if (mc_lifetime < min_lifetime)
134 min_lifetime = mc_lifetime;
137 gss_add_oid_set_member(minor_status,
138 mc->gmc_mech_oid, mechanisms);
142 SLIST_FOREACH(m, &_gss_mechs, gm_link) {
144 OM_uint32 mc_lifetime;
146 major_status = m->gm_inquire_cred(minor_status,
147 GSS_C_NO_CREDENTIAL, &mc_name, &mc_lifetime,
152 updateusage(usage, &usagemask);
153 if (name && mc_name) {
155 sizeof(struct _gss_mechanism_name));
158 minor_status, &mc_name);
162 mn->gmn_mech_oid = &m->gm_mech_oid;
163 mn->gmn_name = mc_name;
164 SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link);
165 } else if (mc_name) {
166 m->gm_release_name(minor_status,
170 if (mc_lifetime < min_lifetime)
171 min_lifetime = mc_lifetime;
174 gss_add_oid_set_member(minor_status,
175 &m->gm_mech_oid, mechanisms);
181 gss_name_t n = (gss_name_t)name;
183 gss_release_name(minor_status, &n);
184 gss_release_oid_set(minor_status, mechanisms);
186 return (GSS_S_NO_CRED);
191 *name_ret = (gss_name_t) name;
193 *lifetime = min_lifetime;
195 if ((usagemask & (AUSAGE|IUSAGE)) == (AUSAGE|IUSAGE))
196 *cred_usage = GSS_C_BOTH;
197 else if (usagemask & IUSAGE)
198 *cred_usage = GSS_C_INITIATE;
199 else if (usagemask & AUSAGE)
200 *cred_usage = GSS_C_ACCEPT;
202 return (GSS_S_COMPLETE);