xref: /illumos-gate/usr/src/lib/libgss/g_inquire_context.c (revision 503a2b89eaf04b96af9e457a7806f65ce3e0b723)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*503a2b89SPeter Shoults  * Common Development and Distribution License (the "License").
6*503a2b89SPeter Shoults  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*503a2b89SPeter Shoults  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  *  glue routine for gss_inquire_context
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <mechglueP.h>
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate 
33*503a2b89SPeter Shoults static OM_uint32
34*503a2b89SPeter Shoults val_inq_ctx_args(
35*503a2b89SPeter Shoults 	OM_uint32 *minor_status,
36*503a2b89SPeter Shoults 	gss_ctx_id_t context_handle,
37*503a2b89SPeter Shoults 	gss_name_t *src_name,
38*503a2b89SPeter Shoults 	gss_name_t *targ_name,
39*503a2b89SPeter Shoults 	gss_OID *mech_type)
40*503a2b89SPeter Shoults {
41*503a2b89SPeter Shoults 
42*503a2b89SPeter Shoults 	/* Initialize outputs. */
43*503a2b89SPeter Shoults 
44*503a2b89SPeter Shoults 	if (minor_status != NULL)
45*503a2b89SPeter Shoults 		*minor_status = 0;
46*503a2b89SPeter Shoults 
47*503a2b89SPeter Shoults 	if (src_name != NULL)
48*503a2b89SPeter Shoults 		*src_name = GSS_C_NO_NAME;
49*503a2b89SPeter Shoults 
50*503a2b89SPeter Shoults 	if (targ_name != NULL)
51*503a2b89SPeter Shoults 		*targ_name = GSS_C_NO_NAME;
52*503a2b89SPeter Shoults 
53*503a2b89SPeter Shoults 	if (mech_type != NULL)
54*503a2b89SPeter Shoults 		*mech_type = GSS_C_NO_OID;
55*503a2b89SPeter Shoults 
56*503a2b89SPeter Shoults 	/* Validate arguments. */
57*503a2b89SPeter Shoults 
58*503a2b89SPeter Shoults 	if (minor_status == NULL)
59*503a2b89SPeter Shoults 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
60*503a2b89SPeter Shoults 
61*503a2b89SPeter Shoults 	if (context_handle == GSS_C_NO_CONTEXT)
62*503a2b89SPeter Shoults 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
63*503a2b89SPeter Shoults 
64*503a2b89SPeter Shoults 	return (GSS_S_COMPLETE);
65*503a2b89SPeter Shoults }
66*503a2b89SPeter Shoults 
677c478bd9Sstevel@tonic-gate /* Last argument new for V2 */
687c478bd9Sstevel@tonic-gate OM_uint32
697c478bd9Sstevel@tonic-gate gss_inquire_context(
707c478bd9Sstevel@tonic-gate 		minor_status,
717c478bd9Sstevel@tonic-gate 		context_handle,
727c478bd9Sstevel@tonic-gate 		src_name,
737c478bd9Sstevel@tonic-gate 		targ_name,
747c478bd9Sstevel@tonic-gate 		lifetime_rec,
757c478bd9Sstevel@tonic-gate 		mech_type,
767c478bd9Sstevel@tonic-gate 		ctx_flags,
777c478bd9Sstevel@tonic-gate 		locally_initiated,
787c478bd9Sstevel@tonic-gate 		open)
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate OM_uint32 *minor_status;
817c478bd9Sstevel@tonic-gate const gss_ctx_id_t context_handle;
827c478bd9Sstevel@tonic-gate gss_name_t *src_name;
837c478bd9Sstevel@tonic-gate gss_name_t *targ_name;
847c478bd9Sstevel@tonic-gate OM_uint32 *lifetime_rec;
857c478bd9Sstevel@tonic-gate gss_OID *mech_type;
867c478bd9Sstevel@tonic-gate OM_uint32 *ctx_flags;
877c478bd9Sstevel@tonic-gate int *locally_initiated;
887c478bd9Sstevel@tonic-gate int *open;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate 	gss_union_ctx_id_t	ctx;
927c478bd9Sstevel@tonic-gate 	gss_mechanism		mech;
937c478bd9Sstevel@tonic-gate 	OM_uint32		status, temp_minor;
947c478bd9Sstevel@tonic-gate 	gss_name_t localTargName = NULL, localSourceName = NULL;
957c478bd9Sstevel@tonic-gate 
96*503a2b89SPeter Shoults 	status = val_inq_ctx_args(minor_status,
97*503a2b89SPeter Shoults 				context_handle,
98*503a2b89SPeter Shoults 				src_name,
99*503a2b89SPeter Shoults 				targ_name,
100*503a2b89SPeter Shoults 				mech_type);
101*503a2b89SPeter Shoults 	if (status != GSS_S_COMPLETE)
102*503a2b89SPeter Shoults 		return (status);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	/*
1057c478bd9Sstevel@tonic-gate 	 * select the approprate underlying mechanism routine and
1067c478bd9Sstevel@tonic-gate 	 * call it.
1077c478bd9Sstevel@tonic-gate 	 */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	ctx = (gss_union_ctx_id_t)context_handle;
1107c478bd9Sstevel@tonic-gate 	mech = __gss_get_mechanism(ctx->mech_type);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	if (!mech || !mech->gss_inquire_context || !mech->gss_display_name ||
1137c478bd9Sstevel@tonic-gate 		!mech->gss_release_name) {
1147c478bd9Sstevel@tonic-gate 		return (GSS_S_UNAVAILABLE);
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	status = mech->gss_inquire_context(
1187c478bd9Sstevel@tonic-gate 				mech->context,
1197c478bd9Sstevel@tonic-gate 				minor_status,
1207c478bd9Sstevel@tonic-gate 				ctx->internal_ctx_id,
1217c478bd9Sstevel@tonic-gate 				(src_name ? &localSourceName : NULL),
1227c478bd9Sstevel@tonic-gate 				(targ_name ? &localTargName : NULL),
1237c478bd9Sstevel@tonic-gate 				lifetime_rec,
1247c478bd9Sstevel@tonic-gate 				NULL,
1257c478bd9Sstevel@tonic-gate 				ctx_flags,
1267c478bd9Sstevel@tonic-gate 				locally_initiated,
1277c478bd9Sstevel@tonic-gate 				open);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	if (status != GSS_S_COMPLETE) {
1307c478bd9Sstevel@tonic-gate 		return (status);
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	/* need to convert names */
1347c478bd9Sstevel@tonic-gate 	if (src_name) {
1357c478bd9Sstevel@tonic-gate 		status = __gss_convert_name_to_union_name(minor_status, mech,
1367c478bd9Sstevel@tonic-gate 						localSourceName, src_name);
1377c478bd9Sstevel@tonic-gate 		if (status != GSS_S_COMPLETE) {
1387c478bd9Sstevel@tonic-gate 			if (localTargName)
1397c478bd9Sstevel@tonic-gate 				mech->gss_release_name(mech->context,
1407c478bd9Sstevel@tonic-gate 						&temp_minor, &localTargName);
1417c478bd9Sstevel@tonic-gate 			return (status);
1427c478bd9Sstevel@tonic-gate 		}
1437c478bd9Sstevel@tonic-gate 	}
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	if (targ_name) {
1467c478bd9Sstevel@tonic-gate 		status = __gss_convert_name_to_union_name(minor_status, mech,
1477c478bd9Sstevel@tonic-gate 						localTargName, targ_name);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 		if (status != GSS_S_COMPLETE) {
1507c478bd9Sstevel@tonic-gate 			if (src_name)
1517c478bd9Sstevel@tonic-gate 				(void) gss_release_name(&temp_minor, src_name);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 			return (status);
1547c478bd9Sstevel@tonic-gate 		}
1557c478bd9Sstevel@tonic-gate 	}
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	/* spec says mech type must point to static storage */
1587c478bd9Sstevel@tonic-gate 	if (mech_type)
1597c478bd9Sstevel@tonic-gate 		*mech_type = &mech->mech_type;
1607c478bd9Sstevel@tonic-gate 	return (GSS_S_COMPLETE);
1617c478bd9Sstevel@tonic-gate }
162