Path: blob/main/crypto/krb5/src/lib/gssapi/mechglue/g_inq_cred.c
39586 views
/* #pragma ident "@(#)g_inquire_cred.c 1.16 04/02/23 SMI" */12/*3* Copyright 1996 by Sun Microsystems, Inc.4*5* Permission to use, copy, modify, distribute, and sell this software6* and its documentation for any purpose is hereby granted without fee,7* provided that the above copyright notice appears in all copies and8* that both that copyright notice and this permission notice appear in9* supporting documentation, and that the name of Sun Microsystems not be used10* in advertising or publicity pertaining to distribution of the software11* without specific, written prior permission. Sun Microsystems makes no12* representations about the suitability of this software for any13* purpose. It is provided "as is" without express or implied warranty.14*15* SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,16* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO17* EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR18* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF19* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR20* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR21* PERFORMANCE OF THIS SOFTWARE.22*/2324/*25* glue routine for gss_inquire_cred26*/2728#include "mglueP.h"29#include <stdio.h>30#ifdef HAVE_STDLIB_H31#include <stdlib.h>32#endif33#include <string.h>34#include <time.h>3536OM_uint32 KRB5_CALLCONV37gss_inquire_cred(OM_uint32 *minor_status, gss_cred_id_t cred_handle,38gss_name_t *name, OM_uint32 *lifetime, int *cred_usage,39gss_OID_set *mechanisms)40{41OM_uint32 status, temp_minor_status;42gss_union_cred_t union_cred;43gss_mechanism mech;44gss_cred_id_t mech_cred;45gss_name_t mech_name;46gss_OID_set mechs = NULL;4748/* Initialize outputs. */4950if (minor_status != NULL)51*minor_status = 0;5253if (name != NULL)54*name = GSS_C_NO_NAME;5556if (mechanisms != NULL)57*mechanisms = GSS_C_NO_OID_SET;5859/* Validate arguments. */60if (minor_status == NULL)61return (GSS_S_CALL_INACCESSIBLE_WRITE);6263/*64* XXX We should iterate over all mechanisms in the credential and65* aggregate the results. This requires a union name structure containing66* multiple mechanism names, which we don't currently have. For now,67* inquire the first mechanism in the credential; this is consistent with68* our historical behavior.69*/7071/* Determine mechanism and mechanism credential. */72if (cred_handle != GSS_C_NO_CREDENTIAL) {73union_cred = (gss_union_cred_t) cred_handle;74if (union_cred->count <= 0)75return (GSS_S_DEFECTIVE_CREDENTIAL);76mech_cred = union_cred->cred_array[0];77mech = gssint_get_mechanism(&union_cred->mechs_array[0]);78} else {79union_cred = NULL;80mech_cred = GSS_C_NO_CREDENTIAL;81mech = gssint_get_mechanism(GSS_C_NULL_OID);82}8384/* Skip the call into the mech if the caller doesn't care about any of the85* values we would ask for. */86if (name != NULL || lifetime != NULL || cred_usage != NULL) {87if (mech == NULL)88return (GSS_S_DEFECTIVE_CREDENTIAL);89if (!mech->gss_inquire_cred)90return (GSS_S_UNAVAILABLE);9192status = mech->gss_inquire_cred(minor_status, mech_cred,93name ? &mech_name : NULL,94lifetime, cred_usage, NULL);95if (status != GSS_S_COMPLETE) {96map_error(minor_status, mech);97return(status);98}99100if (name) {101/* Convert mech_name into a union_name equivalent. */102status = gssint_convert_name_to_union_name(&temp_minor_status,103mech, mech_name, name);104if (status != GSS_S_COMPLETE) {105*minor_status = temp_minor_status;106map_error(minor_status, mech);107return (status);108}109}110}111112/*113* copy the mechanism set in union_cred into an OID set and return in114* the mechanisms parameter.115*/116117if(mechanisms != NULL) {118if (union_cred) {119status = gssint_make_public_oid_set(minor_status,120union_cred->mechs_array,121union_cred->count, &mechs);122if (GSS_ERROR(status))123goto error;124} else {125status = gss_create_empty_oid_set(minor_status, &mechs);126if (GSS_ERROR(status))127goto error;128129status = gss_add_oid_set_member(minor_status,130&mech->mech_type, &mechs);131if (GSS_ERROR(status))132goto error;133}134*mechanisms = mechs;135}136137return(GSS_S_COMPLETE);138139error:140if (mechs != NULL)141(void) gss_release_oid_set(&temp_minor_status, &mechs);142143if (name && *name != NULL)144(void) gss_release_name(&temp_minor_status, name);145146return (status);147}148149OM_uint32 KRB5_CALLCONV150gss_inquire_cred_by_mech(OM_uint32 *minor_status, gss_cred_id_t cred_handle,151gss_OID mech_type, gss_name_t *name,152OM_uint32 *initiator_lifetime,153OM_uint32 *acceptor_lifetime,154gss_cred_usage_t *cred_usage)155{156gss_union_cred_t union_cred;157gss_cred_id_t mech_cred;158gss_mechanism mech;159OM_uint32 status, temp_minor_status;160gss_name_t internal_name;161gss_OID selected_mech, public_mech;162163if (minor_status != NULL)164*minor_status = 0;165166if (name != NULL)167*name = GSS_C_NO_NAME;168169if (minor_status == NULL)170return (GSS_S_CALL_INACCESSIBLE_WRITE);171172status = gssint_select_mech_type(minor_status, mech_type, &selected_mech);173if (status != GSS_S_COMPLETE)174return (status);175176mech = gssint_get_mechanism(selected_mech);177if (!mech)178return (GSS_S_BAD_MECH);179if (!mech->gss_inquire_cred_by_mech)180return (GSS_S_BAD_BINDINGS);181182union_cred = (gss_union_cred_t) cred_handle;183mech_cred = gssint_get_mechanism_cred(union_cred, selected_mech);184if (cred_handle != GSS_C_NO_CREDENTIAL && mech_cred == GSS_C_NO_CREDENTIAL)185return (GSS_S_NO_CRED);186187public_mech = gssint_get_public_oid(selected_mech);188status = mech->gss_inquire_cred_by_mech(minor_status,189mech_cred, public_mech,190name ? &internal_name : NULL,191initiator_lifetime,192acceptor_lifetime, cred_usage);193194if (status != GSS_S_COMPLETE) {195map_error(minor_status, mech);196return (status);197}198199if (name) {200/*201* Convert internal_name into a union_name equivalent.202*/203status = gssint_convert_name_to_union_name(204&temp_minor_status, mech,205internal_name, name);206if (status != GSS_S_COMPLETE) {207*minor_status = temp_minor_status;208map_error(minor_status, mech);209return (status);210}211}212213return (GSS_S_COMPLETE);214}215216217