Path: blob/main/crypto/krb5/src/lib/gssapi/mechglue/g_inq_context.c
39586 views
/* #pragma ident "@(#)g_inquire_context.c 1.15 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"29#ifdef HAVE_STDLIB_H30#include <stdlib.h>31#endif3233static OM_uint3234val_inq_ctx_args(35OM_uint32 *minor_status,36gss_ctx_id_t context_handle,37gss_name_t *src_name,38gss_name_t *targ_name,39OM_uint32 *lifetime_rec,40gss_OID *mech_type,41OM_uint32 *ctx_flags,42int *locally_initiated,43int *opened)44{4546/* Initialize outputs. */4748if (minor_status != NULL)49*minor_status = 0;5051if (src_name != NULL)52*src_name = GSS_C_NO_NAME;5354if (targ_name != NULL)55*targ_name = GSS_C_NO_NAME;5657if (mech_type != NULL)58*mech_type = GSS_C_NO_OID;5960/* Validate arguments. */6162if (minor_status == NULL)63return (GSS_S_CALL_INACCESSIBLE_WRITE);6465if (context_handle == GSS_C_NO_CONTEXT)66return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);6768return (GSS_S_COMPLETE);69}707172/* Last argument new for V2 */73OM_uint32 KRB5_CALLCONV74gss_inquire_context(75OM_uint32 *minor_status,76gss_ctx_id_t context_handle,77gss_name_t *src_name,78gss_name_t *targ_name,79OM_uint32 *lifetime_rec,80gss_OID *mech_type,81OM_uint32 *ctx_flags,82int *locally_initiated,83int *opened)84{85gss_union_ctx_id_t ctx;86gss_mechanism mech;87OM_uint32 status, temp_minor;88gss_OID actual_mech;89gss_name_t localTargName = NULL, localSourceName = NULL;9091status = val_inq_ctx_args(minor_status,92context_handle,93src_name, targ_name,94lifetime_rec,95mech_type, ctx_flags,96locally_initiated, opened);97if (status != GSS_S_COMPLETE)98return (status);99100/*101* select the approprate underlying mechanism routine and102* call it.103*/104105ctx = (gss_union_ctx_id_t) context_handle;106if (ctx->internal_ctx_id == GSS_C_NO_CONTEXT)107return (GSS_S_NO_CONTEXT);108mech = gssint_get_mechanism (ctx->mech_type);109110if (!mech || !mech->gss_inquire_context || !mech->gss_display_name ||111!mech->gss_release_name) {112return (GSS_S_UNAVAILABLE);113}114115status = mech->gss_inquire_context(116minor_status,117ctx->internal_ctx_id,118(src_name ? &localSourceName : NULL),119(targ_name ? &localTargName : NULL),120lifetime_rec,121&actual_mech,122ctx_flags,123locally_initiated,124opened);125126if (status != GSS_S_COMPLETE) {127map_error(minor_status, mech);128return status;129}130131/* need to convert names */132133if (src_name) {134if (localSourceName) {135status = gssint_convert_name_to_union_name(minor_status, mech,136localSourceName, src_name);137138if (status != GSS_S_COMPLETE) {139if (localTargName)140mech->gss_release_name(&temp_minor, &localTargName);141return (status);142}143} else {144*src_name = GSS_C_NO_NAME;145}146}147148if (targ_name) {149if (localTargName) {150status = gssint_convert_name_to_union_name(minor_status, mech,151localTargName, targ_name);152153if (status != GSS_S_COMPLETE) {154if (src_name)155(void) gss_release_name(&temp_minor, src_name);156157return (status);158}159}160else {161*targ_name = GSS_C_NO_NAME;162}163}164165if (mech_type)166*mech_type = gssint_get_public_oid(actual_mech);167168return(GSS_S_COMPLETE);169}170171172