1 /* $NetBSD: gss_inquire_cred.c,v 1.1.1.1 2011/04/13 18:14:46 elric Exp $ */
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
28 * $FreeBSD: src/lib/libgssapi/gss_inquire_cred.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
31 #include "mech_locl.h"
37 updateusage(gss_cred_usage_t usage
, int *usagemask
)
39 if (usage
== GSS_C_BOTH
)
40 *usagemask
|= AUSAGE
| IUSAGE
;
41 else if (usage
== GSS_C_ACCEPT
)
43 else if (usage
== GSS_C_INITIATE
)
47 GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
48 gss_inquire_cred(OM_uint32
*minor_status
,
49 const gss_cred_id_t cred_handle
,
52 gss_cred_usage_t
*cred_usage
,
53 gss_OID_set
*mechanisms
)
55 OM_uint32 major_status
;
56 struct _gss_mech_switch
*m
;
57 struct _gss_cred
*cred
= (struct _gss_cred
*) cred_handle
;
58 struct _gss_name
*name
;
59 struct _gss_mechanism_name
*mn
;
60 OM_uint32 min_lifetime
;
63 gss_cred_usage_t usage
;
69 *name_ret
= GSS_C_NO_NAME
;
75 *mechanisms
= GSS_C_NO_OID_SET
;
78 name
= calloc(1, sizeof(*name
));
80 *minor_status
= ENOMEM
;
81 return (GSS_S_FAILURE
);
83 HEIM_SLIST_INIT(&name
->gn_mn
);
89 major_status
= gss_create_empty_oid_set(minor_status
,
93 return (major_status
);
97 min_lifetime
= GSS_C_INDEFINITE
;
99 struct _gss_mechanism_cred
*mc
;
101 HEIM_SLIST_FOREACH(mc
, &cred
->gc_mc
, gmc_link
) {
103 OM_uint32 mc_lifetime
;
105 major_status
= mc
->gmc_mech
->gm_inquire_cred(minor_status
,
106 mc
->gmc_cred
, &mc_name
, &mc_lifetime
, &usage
, NULL
);
110 updateusage(usage
, &usagemask
);
112 mn
= malloc(sizeof(struct _gss_mechanism_name
));
114 mc
->gmc_mech
->gm_release_name(minor_status
,
118 mn
->gmn_mech
= mc
->gmc_mech
;
119 mn
->gmn_mech_oid
= mc
->gmc_mech_oid
;
120 mn
->gmn_name
= mc_name
;
121 HEIM_SLIST_INSERT_HEAD(&name
->gn_mn
, mn
, gmn_link
);
123 mc
->gmc_mech
->gm_release_name(minor_status
,
127 if (mc_lifetime
< min_lifetime
)
128 min_lifetime
= mc_lifetime
;
131 gss_add_oid_set_member(minor_status
,
132 mc
->gmc_mech_oid
, mechanisms
);
136 HEIM_SLIST_FOREACH(m
, &_gss_mechs
, gm_link
) {
138 OM_uint32 mc_lifetime
;
140 major_status
= m
->gm_mech
.gm_inquire_cred(minor_status
,
141 GSS_C_NO_CREDENTIAL
, &mc_name
, &mc_lifetime
,
146 updateusage(usage
, &usagemask
);
147 if (name
&& mc_name
) {
149 sizeof(struct _gss_mechanism_name
));
151 m
->gm_mech
.gm_release_name(
152 minor_status
, &mc_name
);
155 mn
->gmn_mech
= &m
->gm_mech
;
156 mn
->gmn_mech_oid
= &m
->gm_mech_oid
;
157 mn
->gmn_name
= mc_name
;
158 HEIM_SLIST_INSERT_HEAD(&name
->gn_mn
, mn
, gmn_link
);
159 } else if (mc_name
) {
160 m
->gm_mech
.gm_release_name(minor_status
,
164 if (mc_lifetime
< min_lifetime
)
165 min_lifetime
= mc_lifetime
;
168 gss_add_oid_set_member(minor_status
,
169 &m
->gm_mech_oid
, mechanisms
);
175 gss_name_t n
= (gss_name_t
)name
;
177 gss_release_name(minor_status
, &n
);
178 gss_release_oid_set(minor_status
, mechanisms
);
180 return (GSS_S_NO_CRED
);
185 *name_ret
= (gss_name_t
) name
;
187 *lifetime
= min_lifetime
;
189 if ((usagemask
& (AUSAGE
|IUSAGE
)) == (AUSAGE
|IUSAGE
))
190 *cred_usage
= GSS_C_BOTH
;
191 else if (usagemask
& IUSAGE
)
192 *cred_usage
= GSS_C_INITIATE
;
193 else if (usagemask
& AUSAGE
)
194 *cred_usage
= GSS_C_ACCEPT
;
196 return (GSS_S_COMPLETE
);