implement gss_acquire_cred_ex with password support

add missing SPIs to gss_mech_switch

s/acquire_cred_ex/acquire_cred_ext/g
This commit is contained in:
Luke Howard
2011-03-27 17:29:24 +11:00
parent fedd232ee4
commit 02cf28e20b
14 changed files with 460 additions and 59 deletions

View File

@@ -0,0 +1,151 @@
/*-
* Copyright (c) 2005 Doug Rabson
* All rights reserved.
*
* Portions Copyright (c) 2011 PADL Software Pty Ltd.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/lib/libgssapi/gss_acquire_cred.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
*/
#include "mech_locl.h"
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
gss_acquire_cred_ext(OM_uint32 *minor_status,
const gss_name_t desired_name,
const gss_OID credential_type,
const void *credential_data,
OM_uint32 time_req,
const gss_OID desired_mech,
gss_cred_usage_t cred_usage,
gss_cred_id_t *output_cred_handle)
{
OM_uint32 major_status;
struct _gss_name *name = (struct _gss_name *) desired_name;
gssapi_mech_interface m;
struct _gss_cred *cred;
struct _gss_mechanism_cred *mc;
gss_OID_set_desc set, *mechs;
size_t i;
*minor_status = 0;
if (output_cred_handle == NULL)
return GSS_S_CALL_INACCESSIBLE_READ;
_gss_load_mech();
if (desired_mech != GSS_C_NO_OID) {
int match = 0;
gss_test_oid_set_member(minor_status, desired_mech,
_gss_mech_oids, &match);
if (!match)
return GSS_S_BAD_MECH;
set.count = 1;
set.elements = desired_mech;
mechs = &set;
} else
mechs = _gss_mech_oids;
cred = calloc(1, sizeof(*cred));
if (cred == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
HEIM_SLIST_INIT(&cred->gc_mc);
for (i = 0; i < mechs->count; i++) {
struct _gss_mechanism_name *mn = NULL;
gss_name_t desired_mech_name = GSS_C_NO_NAME;
m = __gss_get_mechanism(&mechs->elements[i]);
if (!m)
continue;
if (desired_name != GSS_C_NO_NAME) {
major_status = _gss_find_mn(minor_status, name,
&mechs->elements[i], &mn);
if (major_status != GSS_S_COMPLETE)
continue;
desired_mech_name = mn->gmn_name;
}
mc = calloc(1, sizeof(struct _gss_mechanism_cred));
if (mc == NULL)
continue;
mc->gmc_mech = m;
mc->gmc_mech_oid = &m->gm_mech_oid;
if (m->gm_acquire_cred_ext) {
major_status = m->gm_acquire_cred_ext(minor_status,
desired_mech_name,
credential_type,
credential_data,
time_req,
mc->gmc_mech_oid,
cred_usage,
&mc->gmc_cred);
} else if (credential_type != GSS_C_NO_OID) {
gss_OID_set_desc set2;
set2.count = 1;
set2.elements = mc->gmc_mech_oid;
major_status = m->gm_acquire_cred(minor_status,
desired_name,
time_req,
&set2,
cred_usage,
&mc->gmc_cred,
NULL,
NULL);
} else {
major_status = GSS_S_UNAVAILABLE;
}
if (GSS_ERROR(major_status)) {
free(mc);
continue;
}
HEIM_SLIST_INSERT_HEAD(&cred->gc_mc, mc, gmc_link);
}
/*
* If we didn't manage to create a single credential, return
* an error.
*/
if (!HEIM_SLIST_FIRST(&cred->gc_mc)) {
free(cred);
*minor_status = 0;
return GSS_S_NO_CRED;
}
*output_cred_handle = (gss_cred_id_t) cred;
*minor_status = 0;
return GSS_S_COMPLETE;
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2011, PADL Software Pty Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of PADL Software nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "mech_locl.h"
OM_uint32
gss_acquire_cred_with_password(OM_uint32 *minor_status,
const gss_name_t desired_name,
const gss_buffer_t password,
OM_uint32 time_req,
const gss_OID_set desired_mechs,
gss_cred_usage_t cred_usage,
gss_cred_id_t *output_cred_handle,
gss_OID_set *actual_mechs,
OM_uint32 *time_rec)
{
OM_uint32 major_status, tmp_minor;
if (desired_mechs == GSS_C_NO_OID_SET) {
major_status = gss_acquire_cred_ext(minor_status,
desired_name,
GSS_C_CRED_PASSWORD,
password,
time_req,
GSS_C_NO_OID,
cred_usage,
output_cred_handle);
if (GSS_ERROR(major_status))
return major_status;
} else {
size_t i;
struct _gss_cred *new_cred;
new_cred = calloc(1, sizeof(*new_cred));
if (new_cred == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
HEIM_SLIST_INIT(&new_cred->gc_mc);
for (i = 0; i < desired_mechs->count; i++) {
struct _gss_cred *tmp_cred = NULL;
struct _gss_mechanism_cred *mc;
major_status = gss_acquire_cred_ext(minor_status,
desired_name,
GSS_C_CRED_PASSWORD,
password,
time_req,
&desired_mechs->elements[i],
cred_usage,
(gss_cred_id_t *)&tmp_cred);
if (GSS_ERROR(major_status))
continue;
mc = HEIM_SLIST_FIRST(&tmp_cred->gc_mc);
if (mc) {
HEIM_SLIST_REMOVE_HEAD(&tmp_cred->gc_mc, gmc_link);
HEIM_SLIST_INSERT_HEAD(&new_cred->gc_mc, mc, gmc_link);
}
gss_release_cred(&tmp_minor, &tmp_cred);
}
if (!HEIM_SLIST_FIRST(&new_cred->gc_mc)) {
free(new_cred);
*minor_status = 0;
return GSS_S_NO_CRED;
}
*output_cred_handle = (gss_cred_id_t)new_cred;
}
if (actual_mechs != NULL || time_rec != NULL) {
major_status = gss_inquire_cred(minor_status,
*output_cred_handle,
NULL,
time_rec,
NULL,
actual_mechs);
if (GSS_ERROR(major_status)) {
gss_release_cred(&tmp_minor, output_cred_handle);
return major_status;
}
}
*minor_status = 0;
return GSS_S_COMPLETE;
}

View File

@@ -28,7 +28,7 @@
#include "mech_locl.h"
static struct _gss_mechanism_cred *
struct _gss_mechanism_cred *
_gss_copy_cred(struct _gss_mechanism_cred *mc)
{
struct _gss_mechanism_cred *new_mc;

View File

@@ -343,6 +343,16 @@ _gss_load_mech(void)
OPTSYM(wrap_iov);
OPTSYM(unwrap_iov);
OPTSYM(wrap_iov_length);
OPTSYM(store_cred);
OPTSYM(export_cred);
OPTSYM(import_cred);
OPTSYM(acquire_cred_ext);
OPTSYM(iter_creds);
OPTSYM(destroy_cred);
OPTSYM(cred_hold);
OPTSYM(cred_unhold);
OPTSYM(cred_label_get);
OPTSYM(cred_label_set);
OPTSYM(display_name_ext);
OPTSYM(inquire_name);
OPTSYM(get_name_attribute);

View File

@@ -103,6 +103,12 @@ gss_OID_desc GSSAPI_LIB_VARIABLE __gss_c_ma_mech_name_oid_desc = { 6, "\x2a\x85\
/* GSS_C_MA_MECH_DESCRIPTION - 1.2.752.43.13.102 */
gss_OID_desc GSSAPI_LIB_VARIABLE __gss_c_ma_mech_description_oid_desc = { 6, "\x2a\x85\x70\x2b\x0d\x66" };
/* GSS_C_CRED_PASSWORD - 1.2.752.43.13.200 */
gss_OID_desc GSSAPI_LIB_VARIABLE __gss_c_cred_password_oid_desc = { 7, "\x2a\x85\x70\x2b\x0d\x81\x48" };
/* GSS_C_CRED_CERTIFICATE - 1.2.752.43.13.201 */
gss_OID_desc GSSAPI_LIB_VARIABLE __gss_c_cred_certificate_oid_desc = { 7, "\x2a\x85\x70\x2b\x0d\x81\x49" };
/* GSS_SASL_DIGEST_MD5_MECHANISM - 1.2.752.43.14.1 */
gss_OID_desc GSSAPI_LIB_VARIABLE __gss_sasl_digest_md5_mechanism_oid_desc = { 6, "\x2a\x85\x70\x2b\x0e\x01" };