gssapi: credential store extensions (#451)

Implement the GSS-API credential store API extensions defined by MIT here:

https://k5wiki.kerberos.org/wiki/Projects/Credential_Store_extensions

Note: we kill off gss_acquire_cred_ext() here. This was never a public API,
although mechanisms could have implemented it and I briefly used it in my
BrowserID prototype mechanism. gss_acquire_cred_ext_from() occupies the place
in the dispatch table where gss_acquire_cred_ext() used to, but this structure
was never visible outside Heimdal (i.e. it is only used by internal
mechanisms);

(Mechanisms that need to accept arbitrary key/value dictionaries from
applications should now implement gss_acquire_cred_from().)
This commit is contained in:
Luke Howard
2019-01-03 09:26:41 +11:00
committed by Nico Williams
parent a7d42cdf6b
commit e0bb9c10ca
39 changed files with 1289 additions and 1054 deletions

View File

@@ -39,19 +39,18 @@ struct _gss_cred {
struct _gss_mechanism_cred_list gc_mc;
};
struct _gss_mechanism_cred *
_gss_copy_cred(struct _gss_mechanism_cred *mc);
struct _gss_mechanism_name;
OM_uint32
_gss_acquire_mech_cred(OM_uint32 *minor_status,
gssapi_mech_interface m,
const struct _gss_mechanism_name *mn,
gss_const_OID credential_type,
const void *credential_data,
OM_uint32 time_req,
gss_const_OID desired_mech,
gss_cred_usage_t cred_usage,
struct _gss_mechanism_cred **output_cred_handle);
_gss_mg_add_mech_cred(OM_uint32 *minor_status,
gssapi_mech_interface m,
const struct _gss_mechanism_cred *mc,
const struct _gss_mechanism_name *mn,
gss_cred_usage_t cred_usage,
OM_uint32 initiator_time_req,
OM_uint32 acceptor_time_req,
gss_const_key_value_set_t cred_store,
struct _gss_mechanism_cred **output_cred_handle,
OM_uint32 *initiator_time_rec,
OM_uint32 *acceptor_time_rec);

View File

@@ -38,131 +38,13 @@ gss_acquire_cred(OM_uint32 *minor_status,
gss_OID_set *actual_mechs,
OM_uint32 *time_rec)
{
OM_uint32 major_status;
gss_OID_set mechs = desired_mechs;
gss_OID_set_desc set;
struct _gss_name *name = (struct _gss_name *) desired_name;
gssapi_mech_interface m;
struct _gss_cred *cred;
struct _gss_mechanism_cred *mc;
OM_uint32 min_time, cred_time;
size_t i;
*minor_status = 0;
if (output_cred_handle == NULL)
return GSS_S_CALL_INACCESSIBLE_READ;
if (actual_mechs)
*actual_mechs = GSS_C_NO_OID_SET;
if (time_rec)
*time_rec = 0;
_gss_load_mech();
/*
* First make sure that at least one of the requested
* mechanisms is one that we support.
*/
if (mechs) {
for (i = 0; i < mechs->count; i++) {
int t;
gss_test_oid_set_member(minor_status,
&mechs->elements[i], _gss_mech_oids, &t);
if (t)
break;
}
if (i == mechs->count) {
*minor_status = 0;
return (GSS_S_BAD_MECH);
}
}
if (actual_mechs) {
major_status = gss_create_empty_oid_set(minor_status,
actual_mechs);
if (major_status)
return (major_status);
}
cred = malloc(sizeof(struct _gss_cred));
if (!cred) {
if (actual_mechs)
gss_release_oid_set(minor_status, actual_mechs);
*minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
HEIM_SLIST_INIT(&cred->gc_mc);
if (mechs == GSS_C_NO_OID_SET)
mechs = _gss_mech_oids;
set.count = 1;
min_time = GSS_C_INDEFINITE;
for (i = 0; i < mechs->count; i++) {
struct _gss_mechanism_name *mn = NULL;
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;
}
mc = malloc(sizeof(struct _gss_mechanism_cred));
if (!mc) {
continue;
}
mc->gmc_mech = m;
mc->gmc_mech_oid = &m->gm_mech_oid;
/*
* XXX Probably need to do something with actual_mechs.
*/
set.elements = &mechs->elements[i];
major_status = m->gm_acquire_cred(minor_status,
(desired_name != GSS_C_NO_NAME
? mn->gmn_name : GSS_C_NO_NAME),
time_req, &set, cred_usage,
&mc->gmc_cred, NULL, &cred_time);
if (major_status) {
free(mc);
continue;
}
if (cred_time < min_time)
min_time = cred_time;
if (actual_mechs) {
major_status = gss_add_oid_set_member(minor_status,
mc->gmc_mech_oid, actual_mechs);
if (major_status) {
m->gm_release_cred(minor_status,
&mc->gmc_cred);
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);
if (actual_mechs)
gss_release_oid_set(minor_status, actual_mechs);
*minor_status = 0;
return (GSS_S_NO_CRED);
}
if (time_rec)
*time_rec = min_time;
*output_cred_handle = (gss_cred_id_t) cred;
*minor_status = 0;
return (GSS_S_COMPLETE);
return gss_acquire_cred_from(minor_status,
desired_name,
time_req,
desired_mechs,
cred_usage,
GSS_C_NO_CRED_STORE,
output_cred_handle,
actual_mechs,
time_rec);
}

View File

@@ -1,203 +0,0 @@
/*-
* 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"
OM_uint32
_gss_acquire_mech_cred(OM_uint32 *minor_status,
gssapi_mech_interface m,
const struct _gss_mechanism_name *mn,
gss_const_OID credential_type,
const void *credential_data,
OM_uint32 time_req,
gss_const_OID desired_mech,
gss_cred_usage_t cred_usage,
struct _gss_mechanism_cred **output_cred_handle)
{
OM_uint32 major_status;
struct _gss_mechanism_cred *mc;
gss_OID_set_desc set2;
*output_cred_handle = NULL;
mc = calloc(1, sizeof(struct _gss_mechanism_cred));
if (mc == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
mc->gmc_mech = m;
mc->gmc_mech_oid = &m->gm_mech_oid;
set2.count = 1;
set2.elements = mc->gmc_mech_oid;
if (m->gm_acquire_cred_ext) {
major_status = m->gm_acquire_cred_ext(minor_status,
mn->gmn_name,
credential_type,
credential_data,
time_req,
mc->gmc_mech_oid,
cred_usage,
&mc->gmc_cred);
} else if (gss_oid_equal(credential_type, GSS_C_CRED_PASSWORD) &&
m->gm_compat &&
m->gm_compat->gmc_acquire_cred_with_password) {
/*
* Shim for mechanisms that adhere to API-as-SPI and do not
* implement gss_acquire_cred_ext().
*/
major_status = m->gm_compat->gmc_acquire_cred_with_password(minor_status,
mn->gmn_name,
(const gss_buffer_t)credential_data,
time_req,
&set2,
cred_usage,
&mc->gmc_cred,
NULL,
NULL);
} else if (credential_type == GSS_C_NO_OID) {
major_status = m->gm_acquire_cred(minor_status,
mn->gmn_name,
time_req,
&set2,
cred_usage,
&mc->gmc_cred,
NULL,
NULL);
} else {
major_status = GSS_S_UNAVAILABLE;
free(mc);
mc= NULL;
}
if (major_status != GSS_S_COMPLETE)
free(mc);
else
*output_cred_handle = mc;
return major_status;
}
/**
* This function is not a public interface and is deprecated anyways, do
* not use. Use gss_acquire_cred_with_password() instead for now.
*
* @deprecated
*/
OM_uint32
_gss_acquire_cred_ext(OM_uint32 *minor_status,
gss_const_name_t desired_name,
gss_const_OID credential_type,
const void *credential_data,
OM_uint32 time_req,
gss_const_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;
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, (gss_OID)desired_mech,
_gss_mech_oids, &match);
if (!match)
return GSS_S_BAD_MECH;
set.count = 1;
set.elements = (gss_OID)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;
struct _gss_mechanism_cred *mc = NULL;
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;
}
major_status = _gss_acquire_mech_cred(minor_status, m, mn,
credential_type, credential_data,
time_req, desired_mech, cred_usage,
&mc);
if (GSS_ERROR(major_status)) {
if (mechs->count == 1)
_gss_mg_error(m, major_status, *minor_status);
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);
if (mechs->count > 1)
*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,265 @@
/*-
* Copyright (c) 2005 Doug Rabson
* All rights reserved.
*
* Portions Copyright (c) 2011, 2018 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"
/*
* Shim for gss_acquire_cred_with_password()
*/
static const char *
find_password_in_cred_store(gss_const_key_value_set_t cred_store)
{
size_t i;
if (cred_store == GSS_C_NO_CRED_STORE)
return NULL;
for (i = 0; i < cred_store->count; i++) {
if (strcmp(cred_store->elements[i].key, "password") == 0)
return cred_store->elements[i].value;
}
return NULL;
}
static OM_uint32
acquire_mech_cred(OM_uint32 *minor_status,
gssapi_mech_interface m,
const struct _gss_mechanism_name *mn,
OM_uint32 time_req,
gss_cred_usage_t cred_usage,
gss_const_key_value_set_t cred_store,
struct _gss_mechanism_cred **out,
OM_uint32 *time_rec)
{
OM_uint32 major_status;
struct _gss_mechanism_cred *mc;
gss_OID_set_desc mech;
const char *spassword;
*out = NULL;
if (time_rec)
*time_rec = 0;
mc = calloc(1, sizeof(struct _gss_mechanism_cred));
if (mc == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
mc->gmc_mech = m;
mc->gmc_mech_oid = &m->gm_mech_oid;
mech.count = 1;
mech.elements = mc->gmc_mech_oid;
if (m->gm_acquire_cred_from) {
major_status = m->gm_acquire_cred_from(minor_status,
mn ? mn->gmn_name : GSS_C_NO_NAME,
time_req,
&mech,
cred_usage,
cred_store,
&mc->gmc_cred,
NULL,
time_rec);
} else if (cred_store == GSS_C_NO_CRED_STORE && m->gm_acquire_cred) {
major_status = m->gm_acquire_cred(minor_status,
mn ? mn->gmn_name : GSS_C_NO_NAME,
time_req,
&mech,
cred_usage,
&mc->gmc_cred,
NULL,
time_rec);
} else if (m->gm_compat &&
m->gm_compat->gmc_acquire_cred_with_password &&
(spassword = find_password_in_cred_store(cred_store)) != NULL) {
gss_buffer_desc password;
password.length = strlen(spassword);
password.value = rk_UNCONST(spassword);
/* compat glue for loadable mechanisms that implement API-as-SPI */
major_status = m->gm_compat->gmc_acquire_cred_with_password(minor_status,
mn ? mn->gmn_name : GSS_C_NO_NAME,
&password,
time_req,
&mech,
cred_usage,
&mc->gmc_cred,
NULL,
time_rec);
} else
major_status = GSS_S_UNAVAILABLE;
heim_assert(major_status == GSS_S_COMPLETE || mc->gmc_cred == NULL,
"gss_acquire_cred_from: mech succeeded but did not return a credential");
if (major_status == GSS_S_COMPLETE)
*out = mc;
else
free(mc);
return major_status;
}
OM_uint32
gss_acquire_cred_from(OM_uint32 *minor_status,
gss_const_name_t desired_name,
OM_uint32 time_req,
const gss_OID_set desired_mechs,
gss_cred_usage_t cred_usage,
gss_const_key_value_set_t cred_store,
gss_cred_id_t *output_cred_handle,
gss_OID_set *actual_mechs,
OM_uint32 *time_rec)
{
OM_uint32 major_status, minor;
struct _gss_name *name = (struct _gss_name *)desired_name;
gssapi_mech_interface m;
struct _gss_cred *cred = NULL;
size_t i;
OM_uint32 min_time = GSS_C_INDEFINITE;
gss_OID_set mechs;
*minor_status = 0;
if (output_cred_handle == NULL)
return GSS_S_CALL_INACCESSIBLE_READ;
*output_cred_handle = GSS_C_NO_CREDENTIAL;
if (actual_mechs)
*actual_mechs = GSS_C_NO_OID_SET;
if (time_rec)
*time_rec = 0;
_gss_load_mech();
if (desired_mechs) {
int match = 0;
for (i = 0; i < desired_mechs->count; i++) {
gss_test_oid_set_member(minor_status, &desired_mechs->elements[i],
_gss_mech_oids, &match);
if (match)
break;
}
if (!match) {
*minor_status = 0;
major_status = GSS_S_BAD_MECH;
goto cleanup;
}
mechs = desired_mechs;
} 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);
if (actual_mechs) {
major_status = gss_create_empty_oid_set(minor_status, actual_mechs);
if (GSS_ERROR(major_status))
goto cleanup;
}
major_status = GSS_S_UNAVAILABLE; /* in case of no mechs */
for (i = 0; i < mechs->count; i++) {
struct _gss_mechanism_name *mn = NULL;
struct _gss_mechanism_cred *mc = NULL;
OM_uint32 cred_time;
m = __gss_get_mechanism(&mechs->elements[i]);
if (m == NULL)
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;
}
major_status = acquire_mech_cred(minor_status, m, mn,
time_req, cred_usage,
cred_store, &mc, &cred_time);
if (major_status != GSS_S_COMPLETE) {
if (mechs->count == 1)
_gss_mg_error(m, major_status, *minor_status);
continue;
}
HEIM_SLIST_INSERT_HEAD(&cred->gc_mc, mc, gmc_link);
if (cred_time < min_time)
min_time = cred_time;
if (actual_mechs != NULL) {
major_status = gss_add_oid_set_member(minor_status,
mc->gmc_mech_oid,
actual_mechs);
if (GSS_ERROR(major_status))
goto cleanup;
}
}
/*
* If we didn't manage to create a single credential, return
* an error.
*/
if (!HEIM_SLIST_FIRST(&cred->gc_mc)) {
if (mechs->count > 1) {
*minor_status = 0;
major_status = GSS_S_NO_CRED;
}
heim_assert(major_status != GSS_S_COMPLETE,
"lack of credentials must result in an error");
goto cleanup;
}
*minor_status = 0;
major_status = GSS_S_COMPLETE;
*output_cred_handle = (gss_cred_id_t)cred;
if (time_rec)
*time_rec = min_time;
cleanup:
if (major_status != GSS_S_COMPLETE) {
gss_release_cred(&minor, (gss_cred_id_t *)&cred);
if (actual_mechs)
gss_release_oid_set(&minor, actual_mechs);
}
return major_status;
}

View File

@@ -43,77 +43,43 @@ gss_acquire_cred_with_password(OM_uint32 *minor_status,
gss_OID_set *actual_mechs,
OM_uint32 *time_rec)
{
OM_uint32 major_status, tmp_minor;
OM_uint32 major_status;
gss_key_value_element_desc kv;
gss_key_value_set_desc store;
char *spassword = NULL;
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;
*output_cred_handle = GSS_C_NO_CREDENTIAL;
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);
if (password == GSS_C_NO_BUFFER || password->value == NULL)
return GSS_S_CALL_INACCESSIBLE_READ;
for (i = 0; i < desired_mechs->count; i++) {
struct _gss_cred *tmp_cred = NULL;
struct _gss_mechanism_cred *mc;
spassword = malloc(password->length + 1);
if (spassword == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
memcpy(spassword, password->value, password->length);
spassword[password->length] = '\0';
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;
kv.key = "password";
kv.value = spassword;
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);
}
store.count = 1;
store.elements = &kv;
gss_release_cred(&tmp_minor, (gss_cred_id_t *)&tmp_cred);
}
if (!HEIM_SLIST_FIRST(&new_cred->gc_mc)) {
free(new_cred);
if (desired_mechs->count > 1)
*minor_status = 0;
return GSS_S_NO_CRED;
}
*output_cred_handle = (gss_cred_id_t)new_cred;
major_status = gss_acquire_cred_from(minor_status,
desired_name,
time_req,
desired_mechs,
cred_usage,
&store,
output_cred_handle,
actual_mechs,
time_rec);
if (spassword) {
memset_s(spassword, password->length, 0, password->length);
free(spassword);
}
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;
return major_status;
}

View File

@@ -30,49 +30,6 @@
#include "mech_locl.h"
struct _gss_mechanism_cred *
_gss_copy_cred(struct _gss_mechanism_cred *mc)
{
struct _gss_mechanism_cred *new_mc;
gssapi_mech_interface m = mc->gmc_mech;
OM_uint32 major_status, minor_status;
gss_name_t name;
gss_cred_id_t cred;
OM_uint32 initiator_lifetime, acceptor_lifetime;
gss_cred_usage_t cred_usage;
major_status = m->gm_inquire_cred_by_mech(&minor_status, mc->gmc_cred,
mc->gmc_mech_oid, &name,
&initiator_lifetime,
&acceptor_lifetime, &cred_usage);
if (major_status) {
_gss_mg_error(m, major_status, minor_status);
return 0;
}
major_status = m->gm_add_cred(&minor_status,
GSS_C_NO_CREDENTIAL, name, mc->gmc_mech_oid,
cred_usage, initiator_lifetime, acceptor_lifetime,
&cred, 0, 0, 0);
m->gm_release_name(&minor_status, &name);
if (major_status) {
_gss_mg_error(m, major_status, minor_status);
return 0;
}
new_mc = malloc(sizeof(struct _gss_mechanism_cred));
if (!new_mc) {
m->gm_release_cred(&minor_status, &cred);
return 0;
}
new_mc->gmc_mech = m;
new_mc->gmc_mech_oid = &m->gm_mech_oid;
new_mc->gmc_cred = cred;
return new_mc;
}
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
gss_add_cred(OM_uint32 *minor_status,
gss_const_cred_id_t input_cred_handle,
@@ -86,122 +43,16 @@ gss_add_cred(OM_uint32 *minor_status,
OM_uint32 *initiator_time_rec,
OM_uint32 *acceptor_time_rec)
{
OM_uint32 major_status;
gssapi_mech_interface m;
gss_cred_id_t release_cred = GSS_C_NO_CREDENTIAL;
struct _gss_cred *mut_cred;
struct _gss_mechanism_cred *mc;
struct _gss_mechanism_cred *new_mc = NULL;
struct _gss_mechanism_name *mn = NULL;
OM_uint32 junk;
*minor_status = 0;
/* Input validation */
if (output_cred_handle)
*output_cred_handle = GSS_C_NO_CREDENTIAL;
if (initiator_time_rec)
*initiator_time_rec = 0;
if (acceptor_time_rec)
*acceptor_time_rec = 0;
if (actual_mechs)
*actual_mechs = GSS_C_NO_OID_SET;
if ((m = __gss_get_mechanism(desired_mech)) == NULL)
return GSS_S_BAD_MECH;
if (input_cred_handle == GSS_C_NO_CREDENTIAL &&
output_cred_handle == NULL) {
return GSS_S_CALL_INACCESSIBLE_WRITE;
}
/* Setup mut_cred to be the credential we mutate */
if (input_cred_handle != GSS_C_NO_CREDENTIAL &&
output_cred_handle != NULL) {
gss_cred_id_t new_cred;
/* Duplicate the input credential */
major_status = gss_duplicate_cred(minor_status, input_cred_handle,
&new_cred);
if (major_status != GSS_S_COMPLETE)
return major_status;
mut_cred = (struct _gss_cred *)new_cred;
release_cred = (gss_cred_id_t)mut_cred;
} else if (input_cred_handle != GSS_C_NO_CREDENTIAL) {
/* Mutate the input credentials */
mut_cred = rk_UNCONST(input_cred_handle);
} else {
if ((mut_cred = malloc(sizeof(*mut_cred))) == NULL) {
*minor_status = ENOMEM;
return GSS_S_UNAVAILABLE;
}
HEIM_SLIST_INIT(&mut_cred->gc_mc);
release_cred = (gss_cred_id_t)mut_cred;
}
/* Find an MN, if any */
if (desired_name) {
major_status = _gss_find_mn(minor_status,
(struct _gss_name *)desired_name,
desired_mech, &mn);
if (major_status != GSS_S_COMPLETE)
goto done;
}
/*
* We go through all the mc attached to the input_cred_handle and check the
* mechanism. If it matches, we call gss_add_cred for that mechanism,
* otherwise we just add a new mc.
*/
HEIM_SLIST_FOREACH(mc, &mut_cred->gc_mc, gmc_link) {
if (!gss_oid_equal(mc->gmc_mech_oid, desired_mech))
continue;
major_status = m->gm_add_cred(minor_status,
(gss_const_cred_id_t)mc,
mn ? mn->gmn_name : GSS_C_NO_NAME,
desired_mech, cred_usage,
initiator_time_req, acceptor_time_req,
NULL, NULL, initiator_time_rec,
acceptor_time_rec);
if (major_status != GSS_S_COMPLETE)
_gss_mg_error(m, major_status, *minor_status);
goto done;
}
new_mc = malloc(sizeof(struct _gss_mechanism_cred));
if (!new_mc) {
*minor_status = ENOMEM;
major_status = GSS_S_FAILURE;
goto done;
}
new_mc->gmc_mech = m;
new_mc->gmc_mech_oid = &m->gm_mech_oid;
major_status = m->gm_add_cred(minor_status,
GSS_C_NO_CREDENTIAL, mn ? mn->gmn_name : GSS_C_NO_NAME,
desired_mech, cred_usage, initiator_time_req, acceptor_time_req,
&new_mc->gmc_cred, NULL, initiator_time_rec, acceptor_time_rec);
if (major_status != GSS_S_COMPLETE) {
_gss_mg_error(m, major_status, *minor_status);
goto done;
}
HEIM_SLIST_INSERT_HEAD(&mut_cred->gc_mc, new_mc, gmc_link);
new_mc = NULL;
done:
/* Lastly, we have to inquire the cred to get the actual_mechs */
if (major_status == GSS_S_COMPLETE && actual_mechs != NULL) {
major_status = gss_inquire_cred(minor_status,
(gss_const_cred_id_t)mut_cred, NULL,
NULL, NULL, actual_mechs);
if (major_status != GSS_S_COMPLETE)
_gss_mg_error(m, major_status, *minor_status);
}
if (major_status == GSS_S_COMPLETE) {
if (output_cred_handle != NULL)
*output_cred_handle = (gss_cred_id_t)mut_cred;
} else {
gss_release_cred(&junk, &release_cred);
}
free(new_mc);
return major_status;
return gss_add_cred_from(minor_status,
rk_UNCONST(input_cred_handle),
desired_name,
desired_mech,
cred_usage,
initiator_time_req,
acceptor_time_req,
GSS_C_NO_CRED_STORE,
output_cred_handle,
actual_mechs,
initiator_time_rec,
acceptor_time_rec);
}

View File

@@ -0,0 +1,229 @@
/*-
* Copyright (c) 2005 Doug Rabson
* Copyright (c) 2018 Kungliga Tekniska Högskolan
* Copyright (c) 2018 AuriStor, Inc.
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 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_add_cred.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
*/
#include "mech_locl.h"
OM_uint32
_gss_mg_add_mech_cred(OM_uint32 *minor_status,
gssapi_mech_interface m,
const struct _gss_mechanism_cred *mc,
const struct _gss_mechanism_name *mn,
gss_cred_usage_t cred_usage,
OM_uint32 initiator_time_req,
OM_uint32 acceptor_time_req,
gss_const_key_value_set_t cred_store,
struct _gss_mechanism_cred **out,
OM_uint32 *initiator_time_rec,
OM_uint32 *acceptor_time_rec)
{
OM_uint32 major_status;
struct _gss_mechanism_cred *new_mc = NULL;
if (out) {
*out = NULL;
new_mc = calloc(1, sizeof(struct _gss_mechanism_cred));
if (new_mc == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
new_mc->gmc_mech = m;
new_mc->gmc_mech_oid = &m->gm_mech_oid;
}
if (m->gm_add_cred_from) {
major_status = m->gm_add_cred_from(minor_status,
mc ? mc->gmc_cred : GSS_C_NO_CREDENTIAL,
mn ? mn->gmn_name : GSS_C_NO_NAME,
&m->gm_mech_oid,
cred_usage,
initiator_time_req,
acceptor_time_req,
cred_store,
new_mc ? &new_mc->gmc_cred : NULL,
NULL,
initiator_time_rec,
acceptor_time_rec);
} else if (cred_store == GSS_C_NO_CRED_STORE && m->gm_add_cred) {
major_status = m->gm_add_cred(minor_status,
mc ? mc->gmc_cred : GSS_C_NO_CREDENTIAL,
mn ? mn->gmn_name : GSS_C_NO_NAME,
&m->gm_mech_oid,
cred_usage,
initiator_time_req,
acceptor_time_req,
new_mc ? &new_mc->gmc_cred : NULL,
NULL,
initiator_time_rec,
acceptor_time_rec);
} else
major_status = GSS_S_UNAVAILABLE;
if (major_status == GSS_S_COMPLETE && out)
*out = new_mc;
else
free(new_mc);
return major_status;
}
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
gss_add_cred_from(OM_uint32 *minor_status,
gss_cred_id_t input_cred_handle,
gss_const_name_t desired_name,
const gss_OID desired_mech,
gss_cred_usage_t cred_usage,
OM_uint32 initiator_time_req,
OM_uint32 acceptor_time_req,
gss_const_key_value_set_t cred_store,
gss_cred_id_t *output_cred_handle,
gss_OID_set *actual_mechs,
OM_uint32 *initiator_time_rec,
OM_uint32 *acceptor_time_rec)
{
OM_uint32 major_status;
gssapi_mech_interface m;
gss_cred_id_t release_cred = GSS_C_NO_CREDENTIAL;
struct _gss_cred *mut_cred;
struct _gss_mechanism_cred *mc;
struct _gss_mechanism_cred *new_mc = NULL;
struct _gss_mechanism_name *mn = NULL;
OM_uint32 junk;
*minor_status = 0;
/* Input validation */
if (output_cred_handle)
*output_cred_handle = GSS_C_NO_CREDENTIAL;
if (initiator_time_rec)
*initiator_time_rec = 0;
if (acceptor_time_rec)
*acceptor_time_rec = 0;
if (actual_mechs)
*actual_mechs = GSS_C_NO_OID_SET;
if ((m = __gss_get_mechanism(desired_mech)) == NULL)
return GSS_S_BAD_MECH;
if (input_cred_handle == GSS_C_NO_CREDENTIAL &&
output_cred_handle == NULL) {
return GSS_S_CALL_INACCESSIBLE_WRITE;
}
/* Setup mut_cred to be the credential we mutate */
if (input_cred_handle != GSS_C_NO_CREDENTIAL &&
output_cred_handle != NULL) {
gss_cred_id_t new_cred;
/* Duplicate the input credential */
major_status = gss_duplicate_cred(minor_status, input_cred_handle,
&new_cred);
if (major_status != GSS_S_COMPLETE)
return major_status;
mut_cred = (struct _gss_cred *)new_cred;
release_cred = (gss_cred_id_t)mut_cred;
} else if (input_cred_handle != GSS_C_NO_CREDENTIAL) {
/* Mutate the input credentials */
mut_cred = rk_UNCONST(input_cred_handle);
} else {
if ((mut_cred = calloc(1, sizeof(*mut_cred))) == NULL) {
*minor_status = ENOMEM;
return GSS_S_UNAVAILABLE;
}
HEIM_SLIST_INIT(&mut_cred->gc_mc);
release_cred = (gss_cred_id_t)mut_cred;
}
/* Find an MN, if any */
if (desired_name) {
major_status = _gss_find_mn(minor_status,
(struct _gss_name *)desired_name,
desired_mech, &mn);
if (major_status != GSS_S_COMPLETE)
goto done;
}
/*
* We go through all the mc attached to the input_cred_handle and check the
* mechanism. If it matches, we call gss_add_cred for that mechanism,
* otherwise we just add a new mc.
*/
HEIM_SLIST_FOREACH(mc, &mut_cred->gc_mc, gmc_link) {
if (!gss_oid_equal(mc->gmc_mech_oid, desired_mech))
continue;
major_status = _gss_mg_add_mech_cred(minor_status, m,
mc, mn, cred_usage,
initiator_time_req, acceptor_time_req,
cred_store, NULL,
initiator_time_rec, acceptor_time_rec);
if (major_status != GSS_S_COMPLETE)
_gss_mg_error(m, major_status, *minor_status);
goto done;
}
new_mc = calloc(1, sizeof(struct _gss_mechanism_cred));
if (new_mc == NULL) {
*minor_status = ENOMEM;
major_status = GSS_S_FAILURE;
goto done;
}
new_mc->gmc_mech = m;
new_mc->gmc_mech_oid = &m->gm_mech_oid;
major_status = _gss_mg_add_mech_cred(minor_status, m, NULL, mn, cred_usage,
initiator_time_req, acceptor_time_req,
cred_store, &new_mc,
initiator_time_rec, acceptor_time_rec);
if (major_status != GSS_S_COMPLETE) {
_gss_mg_error(m, major_status, *minor_status);
goto done;
}
HEIM_SLIST_INSERT_HEAD(&mut_cred->gc_mc, new_mc, gmc_link);
new_mc = NULL;
done:
/* Lastly, we have to inquire the cred to get the actual_mechs */
if (major_status == GSS_S_COMPLETE && actual_mechs != NULL) {
major_status = gss_inquire_cred(minor_status,
(gss_const_cred_id_t)mut_cred, NULL,
NULL, NULL, actual_mechs);
if (major_status != GSS_S_COMPLETE)
_gss_mg_error(m, major_status, *minor_status);
}
if (major_status == GSS_S_COMPLETE) {
if (output_cred_handle != NULL)
*output_cred_handle = (gss_cred_id_t)mut_cred;
} else {
gss_release_cred(&junk, &release_cred);
}
free(new_mc);
return major_status;
}

View File

@@ -42,109 +42,47 @@ gss_add_cred_with_password(OM_uint32 *minor_status,
OM_uint32 *initiator_time_rec,
OM_uint32 *acceptor_time_rec)
{
OM_uint32 major_status;
gssapi_mech_interface m;
struct _gss_cred *cred = (struct _gss_cred *) input_cred_handle;
struct _gss_cred *new_cred;
struct _gss_mechanism_cred *mc;
struct _gss_mechanism_name *mn = NULL;
OM_uint32 junk, time_req;
OM_uint32 major_status;
gss_key_value_element_desc kv;
gss_key_value_set_desc store;
char *spassword = NULL;
*minor_status = 0;
*output_cred_handle = GSS_C_NO_CREDENTIAL;
if (initiator_time_rec)
*initiator_time_rec = 0;
if (acceptor_time_rec)
*acceptor_time_rec = 0;
if (actual_mechs)
*actual_mechs = GSS_C_NO_OID_SET;
*output_cred_handle = GSS_C_NO_CREDENTIAL;
m = __gss_get_mechanism(desired_mech);
if (m == NULL) {
*minor_status = 0;
return (GSS_S_BAD_MECH);
}
if (password == GSS_C_NO_BUFFER || password->value == NULL)
return GSS_S_CALL_INACCESSIBLE_READ;
new_cred = calloc(1, sizeof(struct _gss_cred));
if (new_cred == NULL) {
*minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
HEIM_SLIST_INIT(&new_cred->gc_mc);
spassword = malloc(password->length + 1);
if (spassword == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
memcpy(spassword, password->value, password->length);
spassword[password->length] = '\0';
/*
* Copy credentials from un-desired mechanisms to the new credential.
*/
if (cred) {
HEIM_SLIST_FOREACH(mc, &cred->gc_mc, gmc_link) {
struct _gss_mechanism_cred *copy_mc;
kv.key = "password";
kv.value = spassword;
if (gss_oid_equal(mc->gmc_mech_oid, desired_mech)) {
continue;
}
copy_mc = _gss_copy_cred(mc);
if (copy_mc == NULL) {
gss_release_cred(&junk, (gss_cred_id_t *)&new_cred);
*minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
HEIM_SLIST_INSERT_HEAD(&new_cred->gc_mc, copy_mc, gmc_link);
}
}
store.count = 1;
store.elements = &kv;
/*
* Figure out a suitable mn, if any.
*/
if (desired_name != GSS_C_NO_NAME) {
major_status = _gss_find_mn(minor_status,
(struct _gss_name *) desired_name,
desired_mech,
&mn);
if (major_status != GSS_S_COMPLETE) {
gss_release_cred(&junk, (gss_cred_id_t *)&new_cred);
return (major_status);
}
}
major_status = gss_add_cred_from(minor_status,
rk_UNCONST(input_cred_handle),
desired_name,
desired_mech,
cred_usage,
initiator_time_req,
acceptor_time_req,
&store,
output_cred_handle,
actual_mechs,
initiator_time_rec,
acceptor_time_rec);
if (cred_usage == GSS_C_BOTH)
time_req = initiator_time_req > acceptor_time_req ? acceptor_time_req : initiator_time_req;
else if (cred_usage == GSS_C_INITIATE)
time_req = initiator_time_req;
else
time_req = acceptor_time_req;
if (spassword) {
memset_s(spassword, password->length, 0, password->length);
free(spassword);
}
major_status = _gss_acquire_mech_cred(minor_status, m, mn,
GSS_C_CRED_PASSWORD, password,
time_req, desired_mech,
cred_usage, &mc);
if (major_status != GSS_S_COMPLETE) {
gss_release_cred(&junk, (gss_cred_id_t *)&new_cred);
return (major_status);
}
HEIM_SLIST_INSERT_HEAD(&new_cred->gc_mc, mc, gmc_link);
if (actual_mechs || initiator_time_rec || acceptor_time_rec) {
OM_uint32 time_rec;
major_status = gss_inquire_cred(minor_status,
(gss_cred_id_t)new_cred,
NULL,
&time_rec,
NULL,
actual_mechs);
if (GSS_ERROR(major_status)) {
gss_release_cred(&junk, (gss_cred_id_t *)&new_cred);
return (major_status);
}
if (initiator_time_rec &&
(cred_usage == GSS_C_INITIATE || cred_usage == GSS_C_BOTH))
*initiator_time_rec = time_rec;
if (acceptor_time_rec &&
(cred_usage == GSS_C_ACCEPT || cred_usage == GSS_C_BOTH))
*acceptor_time_rec = time_rec;
}
*output_cred_handle = (gss_cred_id_t) new_cred;
return (GSS_S_COMPLETE);
return major_status;
}

View File

@@ -223,3 +223,4 @@ gss_import_cred(OM_uint32 * minor_status,
return major;
}

View File

@@ -31,24 +31,58 @@
#include "mech_locl.h"
static OM_uint32
_gss_copy_cred_element(OM_uint32 *minor_status,
struct _gss_mechanism_cred *mc,
struct _gss_mechanism_cred **out)
copy_cred_element(OM_uint32 *minor_status,
struct _gss_mechanism_cred *mc,
struct _gss_mechanism_cred **out)
{
gssapi_mech_interface m = mc->gmc_mech;
OM_uint32 major_status;
gss_name_t name;
gss_cred_id_t cred;
OM_uint32 major_status, tmp;
struct _gss_mechanism_name mn;
struct _gss_mechanism_cred *new_mc;
OM_uint32 initiator_lifetime, acceptor_lifetime;
gss_cred_usage_t cred_usage;
gss_cred_id_t dup_cred = GSS_C_NO_CREDENTIAL;
if (m->gm_duplicate_cred)
return m->gm_duplicate_cred(minor_status, (gss_const_cred_id_t)mc,
(gss_cred_id_t *)out);
if (m->gm_duplicate_cred) {
major_status = m->gm_duplicate_cred(minor_status,
mc->gmc_cred, &dup_cred);
} else if (m->gm_import_cred && m->gm_export_cred) {
gss_buffer_desc export;
/* This path won't work for ephemeral creds */
major_status = m->gm_export_cred(minor_status, mc->gmc_cred, &export);
if (major_status == GSS_S_COMPLETE) {
major_status = m->gm_import_cred(minor_status, &export, &dup_cred);
gss_release_buffer(&tmp, &export);
}
} else
major_status = GSS_S_UNAVAILABLE;
if (major_status != GSS_S_UNAVAILABLE) {
if (dup_cred != GSS_C_NO_CREDENTIAL) {
new_mc = calloc(1, sizeof(*new_mc));
if (new_mc == NULL) {
*minor_status = ENOMEM;
m->gm_release_cred(&tmp, &dup_cred);
return GSS_S_FAILURE;
}
new_mc->gmc_mech = m;
new_mc->gmc_mech_oid = mc->gmc_mech_oid;
new_mc->gmc_cred = dup_cred;
*out = new_mc;
}
return major_status;
}
mn.gmn_mech = m;
mn.gmn_mech_oid = mc->gmc_mech_oid;
mn.gmn_name = GSS_C_NO_NAME;
/* This path won't work for ephemeral creds or cred stores */
major_status = m->gm_inquire_cred_by_mech(minor_status, mc->gmc_cred,
mc->gmc_mech_oid, &name,
mc->gmc_mech_oid, &mn.gmn_name,
&initiator_lifetime,
&acceptor_lifetime, &cred_usage);
if (major_status) {
@@ -56,27 +90,25 @@ _gss_copy_cred_element(OM_uint32 *minor_status,
return major_status;
}
major_status = m->gm_add_cred(minor_status,
GSS_C_NO_CREDENTIAL, name, mc->gmc_mech_oid,
cred_usage, initiator_lifetime, acceptor_lifetime,
&cred, 0, 0, 0);
m->gm_release_name(minor_status, &name);
if (major_status) {
major_status = _gss_mg_add_mech_cred(minor_status,
m,
NULL, /* mc */
&mn,
cred_usage,
initiator_lifetime,
acceptor_lifetime,
GSS_C_NO_CRED_STORE,
&new_mc,
NULL,
NULL);
if (major_status)
_gss_mg_error(m, major_status, *minor_status);
return major_status;
}
*out = malloc(sizeof(struct _gss_mechanism_cred));
if (!*out) {
*minor_status = ENOMEM;
m->gm_release_cred(minor_status, &cred);
return GSS_S_FAILURE;
}
(*out)->gmc_mech = m;
(*out)->gmc_mech_oid = &m->gm_mech_oid;
(*out)->gmc_cred = cred;
return GSS_S_COMPLETE;
m->gm_release_name(&tmp, &mn.gmn_name);
*out = new_mc;
return major_status;
}
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
@@ -111,7 +143,7 @@ gss_duplicate_cred(OM_uint32 *minor_status,
major_status = GSS_S_NO_CRED;
HEIM_SLIST_FOREACH(mc, &cred->gc_mc, gmc_link) {
major_status = _gss_copy_cred_element(minor_status, mc, &copy_mc);
major_status = copy_cred_element(minor_status, mc, &copy_mc);
if (major_status != GSS_S_COMPLETE) {
_gss_mg_error(mc->gmc_mech, major_status, *minor_status);
break;

View File

@@ -386,8 +386,8 @@ _gss_load_mech(void)
OPTSYM(store_cred);
OPTSYM(export_cred);
OPTSYM(import_cred);
OPTSYM(acquire_cred_from);
#if 0
OPTSYM(acquire_cred_ext);
OPTSYM(iter_creds);
OPTSYM(destroy_cred);
OPTSYM(cred_hold);
@@ -403,6 +403,8 @@ _gss_load_mech(void)
OPTSYM(export_name_composite);
OPTSYM(localname);
OPTSYM(duplicate_cred);
OPTSYM(add_cred_from);
OPTSYM(store_cred_into);
OPTSPISYM(authorize_localname);
mi = (_gss_mo_init *)dlsym(so, "gss_mo_init");

View File

@@ -103,12 +103,6 @@ gss_OID_desc GSSAPI_LIB_VARIABLE __gss_c_ma_mech_name_oid_desc = { 6, rk_UNCONST
/* 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, rk_UNCONST("\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, rk_UNCONST("\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, rk_UNCONST("\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, rk_UNCONST("\x2a\x85\x70\x2b\x0e\x01") };
@@ -299,8 +293,6 @@ gss_OID _gss_ot_internal[] = {
&__gss_c_ma_sasl_mech_name_oid_desc,
&__gss_c_ma_mech_name_oid_desc,
&__gss_c_ma_mech_description_oid_desc,
&__gss_c_cred_password_oid_desc,
&__gss_c_cred_certificate_oid_desc,
&__gss_sasl_digest_md5_mechanism_oid_desc,
&__gss_netlogon_mechanism_oid_desc,
&__gss_netlogon_set_session_key_x_oid_desc,

View File

@@ -43,58 +43,14 @@ gss_store_cred(OM_uint32 *minor_status,
gss_OID_set *elements_stored,
gss_cred_usage_t *cred_usage_stored)
{
struct _gss_cred *cred = (struct _gss_cred *) input_cred_handle;
struct _gss_mechanism_cred *mc;
OM_uint32 maj = GSS_S_FAILURE;
OM_uint32 junk;
size_t successes = 0;
if (minor_status == NULL)
return GSS_S_FAILURE;
if (elements_stored)
*elements_stored = NULL;
if (cred_usage_stored)
*cred_usage_stored = 0;
if (cred == NULL)
return GSS_S_NO_CONTEXT;
if (elements_stored) {
maj = gss_create_empty_oid_set(minor_status, elements_stored);
if (maj != GSS_S_COMPLETE)
return maj;
}
HEIM_SLIST_FOREACH(mc, &cred->gc_mc, gmc_link) {
gssapi_mech_interface m = mc->gmc_mech;
if (m == NULL || m->gm_store_cred == NULL)
continue;
if (desired_mech != GSS_C_NO_OID &&
!gss_oid_equal(&m->gm_mech_oid, desired_mech))
continue;
maj = (m->gm_store_cred)(minor_status, mc->gmc_cred,
cred_usage, desired_mech, overwrite_cred,
default_cred, NULL, cred_usage_stored);
if (maj == GSS_S_COMPLETE) {
if (elements_stored)
gss_add_oid_set_member(&junk, desired_mech, elements_stored);
successes++;
} else if (desired_mech != GSS_C_NO_OID) {
gss_release_oid_set(&junk, elements_stored);
return maj;
}
}
if (successes == 0) {
if (maj != GSS_S_COMPLETE)
return maj; /* last failure */
return GSS_S_FAILURE;
}
*minor_status = 0;
return GSS_S_COMPLETE;
return gss_store_cred_into(minor_status,
input_cred_handle,
cred_usage,
desired_mech,
overwrite_cred,
default_cred,
GSS_C_NO_CRED_STORE,
elements_stored,
cred_usage_stored);
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (c) 2009 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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 the Institute 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 THE INSTITUTE 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 INSTITUTE 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"
static OM_uint32
store_mech_cred(OM_uint32 *minor_status,
gssapi_mech_interface m,
const struct _gss_mechanism_cred *mc,
gss_cred_usage_t input_usage,
OM_uint32 overwrite_cred,
OM_uint32 default_cred,
gss_const_key_value_set_t cred_store,
gss_cred_usage_t *usage_stored)
{
OM_uint32 major_status;
if (m->gm_store_cred_into)
major_status = m->gm_store_cred_into(minor_status, mc->gmc_cred,
input_usage, &m->gm_mech_oid,
overwrite_cred, default_cred,
cred_store, NULL, usage_stored);
else if (cred_store == GSS_C_NO_CRED_STORE && m->gm_store_cred)
major_status = m->gm_store_cred(minor_status, mc->gmc_cred,
input_usage, &m->gm_mech_oid,
overwrite_cred, default_cred,
NULL, usage_stored);
else
major_status = GSS_S_UNAVAILABLE;
return major_status;
}
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
gss_store_cred_into(OM_uint32 *minor_status,
gss_const_cred_id_t input_cred_handle,
gss_cred_usage_t input_usage,
const gss_OID desired_mech,
OM_uint32 overwrite_cred,
OM_uint32 default_cred,
gss_const_key_value_set_t cred_store,
gss_OID_set *elements_stored,
gss_cred_usage_t *cred_usage_stored)
{
struct _gss_cred *cred = (struct _gss_cred *) input_cred_handle;
struct _gss_mechanism_cred *mc;
OM_uint32 maj = GSS_S_FAILURE;
OM_uint32 junk;
size_t successes = 0;
if (minor_status == NULL)
return GSS_S_FAILURE;
if (elements_stored)
*elements_stored = NULL;
if (cred_usage_stored)
*cred_usage_stored = 0;
if (cred == NULL)
return GSS_S_NO_CONTEXT;
if (elements_stored) {
maj = gss_create_empty_oid_set(minor_status, elements_stored);
if (maj != GSS_S_COMPLETE)
return maj;
}
HEIM_SLIST_FOREACH(mc, &cred->gc_mc, gmc_link) {
gssapi_mech_interface m = mc->gmc_mech;
if (m == NULL)
continue;
if (desired_mech != GSS_C_NO_OID &&
!gss_oid_equal(&m->gm_mech_oid, desired_mech))
continue;
maj = store_mech_cred(minor_status, m, mc,
input_usage, overwrite_cred,
default_cred, cred_store,
cred_usage_stored);
if (maj == GSS_S_COMPLETE) {
if (elements_stored)
gss_add_oid_set_member(&junk, desired_mech, elements_stored);
successes++;
} else if (desired_mech != GSS_C_NO_OID) {
gss_release_oid_set(&junk, elements_stored);
return maj;
}
}
if (successes == 0) {
if (maj != GSS_S_COMPLETE)
return maj; /* last failure */
return GSS_S_FAILURE;
}
*minor_status = 0;
return GSS_S_COMPLETE;
}