Path: blob/main/crypto/krb5/src/lib/gssapi/mechglue/g_inq_names.c
39586 views
/* #pragma ident "@(#)g_inquire_names.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_context26*/2728#include "mglueP.h"2930#define MAX_MECH_OID_PAIRS 323132/* Last argument new for V2 */33OM_uint32 KRB5_CALLCONV34gss_inquire_names_for_mech(OM_uint32 *minor_status, gss_OID mechanism,35gss_OID_set *name_types)36{37OM_uint32 status;38gss_OID selected_mech = GSS_C_NO_OID, public_mech;39gss_mechanism mech;4041/* Initialize outputs. */4243if (minor_status != NULL)44*minor_status = 0;4546if (name_types != NULL)47*name_types = GSS_C_NO_OID_SET;4849/* Validate arguments. */5051if (minor_status == NULL)52return (GSS_S_CALL_INACCESSIBLE_WRITE);5354if (name_types == NULL)55return (GSS_S_CALL_INACCESSIBLE_WRITE);5657/*58* select the approprate underlying mechanism routine and59* call it.60*/6162status = gssint_select_mech_type(minor_status, mechanism,63&selected_mech);64if (status != GSS_S_COMPLETE)65return (status);6667mech = gssint_get_mechanism(selected_mech);68if (mech == NULL)69return GSS_S_BAD_MECH;70else if (mech->gss_inquire_names_for_mech == NULL)71return GSS_S_UNAVAILABLE;72public_mech = gssint_get_public_oid(selected_mech);73status = mech->gss_inquire_names_for_mech(minor_status, public_mech,74name_types);75if (status != GSS_S_COMPLETE)76map_error(minor_status, mech);7778return status;79}8081static OM_uint3282val_inq_mechs4name_args(83OM_uint32 *minor_status,84const gss_name_t input_name,85gss_OID_set *mech_set)86{8788/* Initialize outputs. */89if (minor_status != NULL)90*minor_status = 0;9192if (mech_set != NULL)93*mech_set = GSS_C_NO_OID_SET;9495/* Validate arguments.e96*/97if (minor_status == NULL)98return (GSS_S_CALL_INACCESSIBLE_WRITE);99100if (input_name == GSS_C_NO_NAME)101return (GSS_S_BAD_NAME);102103return (GSS_S_COMPLETE);104}105106static int107mech_supports_nametype(gss_OID mech_oid, gss_OID name_type)108{109OM_uint32 status, minor;110gss_OID_set types = GSS_C_NO_OID_SET;111int present;112113status = gss_inquire_names_for_mech(&minor, mech_oid, &types);114if (status != GSS_S_COMPLETE)115return (0);116status = gss_test_oid_set_member(&minor, name_type, types, &present);117(void) gss_release_oid_set(&minor, &types);118return (status == GSS_S_COMPLETE && present);119}120121OM_uint32 KRB5_CALLCONV122gss_inquire_mechs_for_name(OM_uint32 *minor_status,123const gss_name_t input_name, gss_OID_set *mech_set)124{125OM_uint32 status, tmpmin;126gss_OID_set all_mechs = GSS_C_NO_OID_SET;127gss_OID_set mechs = GSS_C_NO_OID_SET;128gss_OID mech_oid, name_type;129gss_buffer_desc name_buffer = GSS_C_EMPTY_BUFFER;130size_t i;131132status = val_inq_mechs4name_args(minor_status, input_name, mech_set);133if (status != GSS_S_COMPLETE)134return (status);135136status = gss_display_name(minor_status, input_name, &name_buffer,137&name_type);138if (status != GSS_S_COMPLETE)139goto cleanup;140status = gss_indicate_mechs(minor_status, &all_mechs);141if (status != GSS_S_COMPLETE)142goto cleanup;143status = gss_create_empty_oid_set(minor_status, &mechs);144if (status != GSS_S_COMPLETE)145goto cleanup;146for (i = 0; i < all_mechs->count; i++) {147mech_oid = &all_mechs->elements[i];148if (mech_supports_nametype(mech_oid, name_type)) {149status = gss_add_oid_set_member(minor_status, mech_oid, &mechs);150if (status != GSS_S_COMPLETE)151goto cleanup;152}153}154155*mech_set = mechs;156mechs = GSS_C_NO_OID_SET;157158cleanup:159(void) gss_release_buffer(&tmpmin, &name_buffer);160(void) gss_release_oid_set(&tmpmin, &all_mechs);161(void) gss_release_oid_set(&tmpmin, &mechs);162return (status);163}164165166