2 * Copyright (c) 2010, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * 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 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include "gssapiP_eap.h"
36 gssEapAllocCred(OM_uint32 *minor, gss_cred_id_t *pCred)
41 *pCred = GSS_C_NO_CREDENTIAL;
43 cred = (gss_cred_id_t)GSSEAP_CALLOC(1, sizeof(*cred));
49 if (GSSEAP_MUTEX_INIT(&cred->mutex) != 0) {
51 gssEapReleaseCred(&tmpMinor, &cred);
58 return GSS_S_COMPLETE;
62 gssEapReleaseCred(OM_uint32 *minor, gss_cred_id_t *pCred)
65 gss_cred_id_t cred = *pCred;
67 if (cred == GSS_C_NO_CREDENTIAL) {
68 return GSS_S_COMPLETE;
71 gssEapReleaseName(&tmpMinor, &cred->name);
73 if (cred->password.value != NULL) {
74 memset(cred->password.value, 0, cred->password.length);
75 GSSEAP_FREE(cred->password.value);
78 GSSEAP_MUTEX_DESTROY(&cred->mutex);
79 memset(cred, 0, sizeof(*cred));
84 return GSS_S_COMPLETE;
88 gssEapAcquireCred(OM_uint32 *minor,
89 const gss_name_t desiredName,
90 const gss_buffer_t password,
92 const gss_OID_set desiredMechs,
95 gss_OID_set *pActualMechs,
98 OM_uint32 major, tmpMinor;
101 *pCred = GSS_C_NO_CREDENTIAL;
103 major = gssEapAllocCred(minor, &cred);
104 if (GSS_ERROR(major))
109 cred->flags |= CRED_FLAG_INITIATE | CRED_FLAG_ACCEPT;
112 cred->flags |= CRED_FLAG_INITIATE;
115 cred->flags |= CRED_FLAG_ACCEPT;
118 major = GSS_S_FAILURE;
123 if (desiredName != GSS_C_NO_NAME) {
124 major = gss_duplicate_name(minor, desiredName, &cred->name);
125 if (GSS_ERROR(major))
128 if (cred->flags & CRED_FLAG_INITIATE) {
131 buf.value = getlogin(); /* XXX */
132 buf.length = strlen((char *)buf.value);
134 major = gss_import_name(minor, &buf,
135 GSS_C_NT_USER_NAME, &cred->name);
136 if (GSS_ERROR(major))
140 cred->flags |= CRED_FLAG_DEFAULT_IDENTITY;
143 if (password != GSS_C_NO_BUFFER) {
144 major = duplicateBuffer(minor, password, &cred->password);
145 if (GSS_ERROR(major))
148 cred->flags |= CRED_FLAG_PASSWORD;
151 major = gssEapValidateMechs(minor, desiredMechs);
152 if (GSS_ERROR(major))
155 major = duplicateOidSet(minor, desiredMechs, &cred->mechanisms);
156 if (GSS_ERROR(major))
159 if (pActualMechs != NULL) {
160 major = duplicateOidSet(minor, cred->mechanisms, pActualMechs);
161 if (GSS_ERROR(major))
166 *timeRec = GSS_C_INDEFINITE;
169 major = GSS_S_COMPLETE;
172 if (GSS_ERROR(major))
173 gssEapReleaseCred(&tmpMinor, &cred);
179 gssEapCredAvailable(gss_cred_id_t cred, gss_OID mech)
184 assert(mech != GSS_C_NO_OID);
186 if (cred == GSS_C_NO_CREDENTIAL || cred->mechanisms == GSS_C_NO_OID_SET)
189 gss_test_oid_set_member(&minor, mech, cred->mechanisms, &present);