Path: blob/main/crypto/heimdal/lib/gssapi/spnego/cred_stubs.c
34907 views
/*1* Copyright (c) 2004, PADL Software Pty Ltd.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10*11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* 3. Neither the name of PADL Software nor the names of its contributors16* may be used to endorse or promote products derived from this software17* without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*/3132#include "spnego_locl.h"3334OM_uint32 GSSAPI_CALLCONV35_gss_spnego_release_cred(OM_uint32 *minor_status, gss_cred_id_t *cred_handle)36{37OM_uint32 ret;3839*minor_status = 0;4041if (cred_handle == NULL || *cred_handle == GSS_C_NO_CREDENTIAL)42return GSS_S_COMPLETE;4344ret = gss_release_cred(minor_status, cred_handle);4546*cred_handle = GSS_C_NO_CREDENTIAL;4748return ret;49}5051/*52* For now, just a simple wrapper that avoids recursion. When53* we support gss_{get,set}_neg_mechs() we will need to expose54* more functionality.55*/56OM_uint32 GSSAPI_CALLCONV _gss_spnego_acquire_cred57(OM_uint32 *minor_status,58const gss_name_t desired_name,59OM_uint32 time_req,60const gss_OID_set desired_mechs,61gss_cred_usage_t cred_usage,62gss_cred_id_t * output_cred_handle,63gss_OID_set * actual_mechs,64OM_uint32 * time_rec65)66{67const spnego_name dname = (const spnego_name)desired_name;68gss_name_t name = GSS_C_NO_NAME;69OM_uint32 ret, tmp;70gss_OID_set_desc actual_desired_mechs;71gss_OID_set mechs;72size_t i, j;7374*output_cred_handle = GSS_C_NO_CREDENTIAL;7576if (dname) {77ret = gss_import_name(minor_status, &dname->value, &dname->type, &name);78if (ret) {79return ret;80}81}8283ret = gss_indicate_mechs(minor_status, &mechs);84if (ret != GSS_S_COMPLETE) {85gss_release_name(minor_status, &name);86return ret;87}8889/* Remove ourselves from this list */90actual_desired_mechs.count = mechs->count;91actual_desired_mechs.elements = malloc(actual_desired_mechs.count *92sizeof(gss_OID_desc));93if (actual_desired_mechs.elements == NULL) {94*minor_status = ENOMEM;95ret = GSS_S_FAILURE;96goto out;97}9899for (i = 0, j = 0; i < mechs->count; i++) {100if (gss_oid_equal(&mechs->elements[i], GSS_SPNEGO_MECHANISM))101continue;102103actual_desired_mechs.elements[j] = mechs->elements[i];104j++;105}106actual_desired_mechs.count = j;107108ret = gss_acquire_cred(minor_status, name,109time_req, &actual_desired_mechs,110cred_usage,111output_cred_handle,112actual_mechs, time_rec);113if (ret != GSS_S_COMPLETE)114goto out;115116out:117gss_release_name(minor_status, &name);118gss_release_oid_set(&tmp, &mechs);119if (actual_desired_mechs.elements != NULL) {120free(actual_desired_mechs.elements);121}122if (ret != GSS_S_COMPLETE) {123_gss_spnego_release_cred(&tmp, output_cred_handle);124}125126return ret;127}128129OM_uint32 GSSAPI_CALLCONV _gss_spnego_inquire_cred130(OM_uint32 * minor_status,131const gss_cred_id_t cred_handle,132gss_name_t * name,133OM_uint32 * lifetime,134gss_cred_usage_t * cred_usage,135gss_OID_set * mechanisms136)137{138spnego_name sname = NULL;139OM_uint32 ret;140141if (cred_handle == GSS_C_NO_CREDENTIAL) {142*minor_status = 0;143return GSS_S_NO_CRED;144}145146if (name) {147sname = calloc(1, sizeof(*sname));148if (sname == NULL) {149*minor_status = ENOMEM;150return GSS_S_FAILURE;151}152}153154ret = gss_inquire_cred(minor_status,155cred_handle,156sname ? &sname->mech : NULL,157lifetime,158cred_usage,159mechanisms);160if (ret) {161if (sname)162free(sname);163return ret;164}165if (name)166*name = (gss_name_t)sname;167168return ret;169}170171OM_uint32 GSSAPI_CALLCONV _gss_spnego_inquire_cred_by_mech (172OM_uint32 * minor_status,173const gss_cred_id_t cred_handle,174const gss_OID mech_type,175gss_name_t * name,176OM_uint32 * initiator_lifetime,177OM_uint32 * acceptor_lifetime,178gss_cred_usage_t * cred_usage179)180{181spnego_name sname = NULL;182OM_uint32 ret;183184if (cred_handle == GSS_C_NO_CREDENTIAL) {185*minor_status = 0;186return GSS_S_NO_CRED;187}188189if (name) {190sname = calloc(1, sizeof(*sname));191if (sname == NULL) {192*minor_status = ENOMEM;193return GSS_S_FAILURE;194}195}196197ret = gss_inquire_cred_by_mech(minor_status,198cred_handle,199mech_type,200sname ? &sname->mech : NULL,201initiator_lifetime,202acceptor_lifetime,203cred_usage);204205if (ret) {206if (sname)207free(sname);208return ret;209}210if (name)211*name = (gss_name_t)sname;212213return GSS_S_COMPLETE;214}215216OM_uint32 GSSAPI_CALLCONV _gss_spnego_inquire_cred_by_oid217(OM_uint32 * minor_status,218const gss_cred_id_t cred_handle,219const gss_OID desired_object,220gss_buffer_set_t *data_set)221{222OM_uint32 ret;223224if (cred_handle == GSS_C_NO_CREDENTIAL) {225*minor_status = 0;226return GSS_S_NO_CRED;227}228229ret = gss_inquire_cred_by_oid(minor_status,230cred_handle,231desired_object,232data_set);233234return ret;235}236237OM_uint32 GSSAPI_CALLCONV238_gss_spnego_set_cred_option (OM_uint32 *minor_status,239gss_cred_id_t *cred_handle,240const gss_OID object,241const gss_buffer_t value)242{243if (cred_handle == NULL || *cred_handle == GSS_C_NO_CREDENTIAL) {244*minor_status = 0;245return GSS_S_NO_CRED;246}247248return gss_set_cred_option(minor_status,249cred_handle,250object,251value);252}253254#if 0255256OM_uint32 GSSAPI_CALLCONV257_gss_spnego_export_cred (OM_uint32 *minor_status,258gss_cred_id_t cred_handle,259gss_buffer_t value)260{261return gss_export_cred(minor_status, cred_handle, value);262}263264OM_uint32 GSSAPI_CALLCONV265_gss_spnego_import_cred (OM_uint32 *minor_status,266gss_buffer_t value,267gss_cred_id_t *cred_handle)268{269return gss_import_cred(minor_status, value, cred_handle);270}271272#endif273274275