xref: /freebsd/crypto/krb5/src/lib/gssapi/mechglue/g_inq_context.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* #pragma ident	"@(#)g_inquire_context.c	1.15	04/02/23 SMI" */
2*7f2fe78bSCy Schubert 
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert  * Copyright 1996 by Sun Microsystems, Inc.
5*7f2fe78bSCy Schubert  *
6*7f2fe78bSCy Schubert  * Permission to use, copy, modify, distribute, and sell this software
7*7f2fe78bSCy Schubert  * and its documentation for any purpose is hereby granted without fee,
8*7f2fe78bSCy Schubert  * provided that the above copyright notice appears in all copies and
9*7f2fe78bSCy Schubert  * that both that copyright notice and this permission notice appear in
10*7f2fe78bSCy Schubert  * supporting documentation, and that the name of Sun Microsystems not be used
11*7f2fe78bSCy Schubert  * in advertising or publicity pertaining to distribution of the software
12*7f2fe78bSCy Schubert  * without specific, written prior permission. Sun Microsystems makes no
13*7f2fe78bSCy Schubert  * representations about the suitability of this software for any
14*7f2fe78bSCy Schubert  * purpose.  It is provided "as is" without express or implied warranty.
15*7f2fe78bSCy Schubert  *
16*7f2fe78bSCy Schubert  * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17*7f2fe78bSCy Schubert  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18*7f2fe78bSCy Schubert  * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19*7f2fe78bSCy Schubert  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20*7f2fe78bSCy Schubert  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21*7f2fe78bSCy Schubert  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22*7f2fe78bSCy Schubert  * PERFORMANCE OF THIS SOFTWARE.
23*7f2fe78bSCy Schubert  */
24*7f2fe78bSCy Schubert 
25*7f2fe78bSCy Schubert /*
26*7f2fe78bSCy Schubert  *  glue routine for gss_inquire_context
27*7f2fe78bSCy Schubert  */
28*7f2fe78bSCy Schubert 
29*7f2fe78bSCy Schubert #include "mglueP.h"
30*7f2fe78bSCy Schubert #ifdef HAVE_STDLIB_H
31*7f2fe78bSCy Schubert #include <stdlib.h>
32*7f2fe78bSCy Schubert #endif
33*7f2fe78bSCy Schubert 
34*7f2fe78bSCy Schubert static OM_uint32
val_inq_ctx_args(OM_uint32 * minor_status,gss_ctx_id_t context_handle,gss_name_t * src_name,gss_name_t * targ_name,OM_uint32 * lifetime_rec,gss_OID * mech_type,OM_uint32 * ctx_flags,int * locally_initiated,int * opened)35*7f2fe78bSCy Schubert val_inq_ctx_args(
36*7f2fe78bSCy Schubert     OM_uint32 *minor_status,
37*7f2fe78bSCy Schubert     gss_ctx_id_t context_handle,
38*7f2fe78bSCy Schubert     gss_name_t *src_name,
39*7f2fe78bSCy Schubert     gss_name_t *targ_name,
40*7f2fe78bSCy Schubert     OM_uint32 *lifetime_rec,
41*7f2fe78bSCy Schubert     gss_OID *mech_type,
42*7f2fe78bSCy Schubert     OM_uint32 *ctx_flags,
43*7f2fe78bSCy Schubert     int *locally_initiated,
44*7f2fe78bSCy Schubert     int *opened)
45*7f2fe78bSCy Schubert {
46*7f2fe78bSCy Schubert 
47*7f2fe78bSCy Schubert     /* Initialize outputs. */
48*7f2fe78bSCy Schubert 
49*7f2fe78bSCy Schubert     if (minor_status != NULL)
50*7f2fe78bSCy Schubert 	*minor_status = 0;
51*7f2fe78bSCy Schubert 
52*7f2fe78bSCy Schubert     if (src_name != NULL)
53*7f2fe78bSCy Schubert 	*src_name = GSS_C_NO_NAME;
54*7f2fe78bSCy Schubert 
55*7f2fe78bSCy Schubert     if (targ_name != NULL)
56*7f2fe78bSCy Schubert 	*targ_name = GSS_C_NO_NAME;
57*7f2fe78bSCy Schubert 
58*7f2fe78bSCy Schubert     if (mech_type != NULL)
59*7f2fe78bSCy Schubert 	*mech_type = GSS_C_NO_OID;
60*7f2fe78bSCy Schubert 
61*7f2fe78bSCy Schubert     /* Validate arguments. */
62*7f2fe78bSCy Schubert 
63*7f2fe78bSCy Schubert     if (minor_status == NULL)
64*7f2fe78bSCy Schubert 	return (GSS_S_CALL_INACCESSIBLE_WRITE);
65*7f2fe78bSCy Schubert 
66*7f2fe78bSCy Schubert     if (context_handle == GSS_C_NO_CONTEXT)
67*7f2fe78bSCy Schubert 	return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
68*7f2fe78bSCy Schubert 
69*7f2fe78bSCy Schubert     return (GSS_S_COMPLETE);
70*7f2fe78bSCy Schubert }
71*7f2fe78bSCy Schubert 
72*7f2fe78bSCy Schubert 
73*7f2fe78bSCy Schubert /* Last argument new for V2 */
74*7f2fe78bSCy Schubert OM_uint32 KRB5_CALLCONV
gss_inquire_context(OM_uint32 * minor_status,gss_ctx_id_t context_handle,gss_name_t * src_name,gss_name_t * targ_name,OM_uint32 * lifetime_rec,gss_OID * mech_type,OM_uint32 * ctx_flags,int * locally_initiated,int * opened)75*7f2fe78bSCy Schubert gss_inquire_context(
76*7f2fe78bSCy Schubert 	    OM_uint32 *minor_status,
77*7f2fe78bSCy Schubert 	    gss_ctx_id_t context_handle,
78*7f2fe78bSCy Schubert 	    gss_name_t *src_name,
79*7f2fe78bSCy Schubert 	    gss_name_t *targ_name,
80*7f2fe78bSCy Schubert 	    OM_uint32 *lifetime_rec,
81*7f2fe78bSCy Schubert 	    gss_OID *mech_type,
82*7f2fe78bSCy Schubert 	    OM_uint32 *ctx_flags,
83*7f2fe78bSCy Schubert 	    int *locally_initiated,
84*7f2fe78bSCy Schubert 	    int *opened)
85*7f2fe78bSCy Schubert {
86*7f2fe78bSCy Schubert     gss_union_ctx_id_t	ctx;
87*7f2fe78bSCy Schubert     gss_mechanism	mech;
88*7f2fe78bSCy Schubert     OM_uint32		status, temp_minor;
89*7f2fe78bSCy Schubert     gss_OID		actual_mech;
90*7f2fe78bSCy Schubert     gss_name_t localTargName = NULL, localSourceName = NULL;
91*7f2fe78bSCy Schubert 
92*7f2fe78bSCy Schubert     status = val_inq_ctx_args(minor_status,
93*7f2fe78bSCy Schubert 			      context_handle,
94*7f2fe78bSCy Schubert 			      src_name, targ_name,
95*7f2fe78bSCy Schubert 			      lifetime_rec,
96*7f2fe78bSCy Schubert 			      mech_type, ctx_flags,
97*7f2fe78bSCy Schubert 			      locally_initiated, opened);
98*7f2fe78bSCy Schubert     if (status != GSS_S_COMPLETE)
99*7f2fe78bSCy Schubert 	return (status);
100*7f2fe78bSCy Schubert 
101*7f2fe78bSCy Schubert     /*
102*7f2fe78bSCy Schubert      * select the approprate underlying mechanism routine and
103*7f2fe78bSCy Schubert      * call it.
104*7f2fe78bSCy Schubert      */
105*7f2fe78bSCy Schubert 
106*7f2fe78bSCy Schubert     ctx = (gss_union_ctx_id_t) context_handle;
107*7f2fe78bSCy Schubert     if (ctx->internal_ctx_id == GSS_C_NO_CONTEXT)
108*7f2fe78bSCy Schubert 	return (GSS_S_NO_CONTEXT);
109*7f2fe78bSCy Schubert     mech = gssint_get_mechanism (ctx->mech_type);
110*7f2fe78bSCy Schubert 
111*7f2fe78bSCy Schubert     if (!mech || !mech->gss_inquire_context || !mech->gss_display_name ||
112*7f2fe78bSCy Schubert 	!mech->gss_release_name) {
113*7f2fe78bSCy Schubert 	return (GSS_S_UNAVAILABLE);
114*7f2fe78bSCy Schubert     }
115*7f2fe78bSCy Schubert 
116*7f2fe78bSCy Schubert     status = mech->gss_inquire_context(
117*7f2fe78bSCy Schubert 			minor_status,
118*7f2fe78bSCy Schubert 			ctx->internal_ctx_id,
119*7f2fe78bSCy Schubert 			(src_name ? &localSourceName : NULL),
120*7f2fe78bSCy Schubert 			(targ_name ? &localTargName : NULL),
121*7f2fe78bSCy Schubert 			lifetime_rec,
122*7f2fe78bSCy Schubert 			&actual_mech,
123*7f2fe78bSCy Schubert 			ctx_flags,
124*7f2fe78bSCy Schubert 			locally_initiated,
125*7f2fe78bSCy Schubert 			opened);
126*7f2fe78bSCy Schubert 
127*7f2fe78bSCy Schubert     if (status != GSS_S_COMPLETE) {
128*7f2fe78bSCy Schubert 	map_error(minor_status, mech);
129*7f2fe78bSCy Schubert 	return status;
130*7f2fe78bSCy Schubert     }
131*7f2fe78bSCy Schubert 
132*7f2fe78bSCy Schubert     /* need to convert names */
133*7f2fe78bSCy Schubert 
134*7f2fe78bSCy Schubert     if (src_name) {
135*7f2fe78bSCy Schubert 	if (localSourceName) {
136*7f2fe78bSCy Schubert 	    status = gssint_convert_name_to_union_name(minor_status, mech,
137*7f2fe78bSCy Schubert 						      localSourceName, src_name);
138*7f2fe78bSCy Schubert 
139*7f2fe78bSCy Schubert 	    if (status != GSS_S_COMPLETE) {
140*7f2fe78bSCy Schubert 		if (localTargName)
141*7f2fe78bSCy Schubert 		    mech->gss_release_name(&temp_minor, &localTargName);
142*7f2fe78bSCy Schubert 		return (status);
143*7f2fe78bSCy Schubert 	    }
144*7f2fe78bSCy Schubert 	} else {
145*7f2fe78bSCy Schubert 	    *src_name = GSS_C_NO_NAME;
146*7f2fe78bSCy Schubert 	}
147*7f2fe78bSCy Schubert     }
148*7f2fe78bSCy Schubert 
149*7f2fe78bSCy Schubert     if (targ_name) {
150*7f2fe78bSCy Schubert         if (localTargName) {
151*7f2fe78bSCy Schubert 	    status = gssint_convert_name_to_union_name(minor_status, mech,
152*7f2fe78bSCy Schubert 						      localTargName, targ_name);
153*7f2fe78bSCy Schubert 
154*7f2fe78bSCy Schubert 	    if (status != GSS_S_COMPLETE) {
155*7f2fe78bSCy Schubert 		if (src_name)
156*7f2fe78bSCy Schubert 		    (void) gss_release_name(&temp_minor, src_name);
157*7f2fe78bSCy Schubert 
158*7f2fe78bSCy Schubert 		return (status);
159*7f2fe78bSCy Schubert 	    }
160*7f2fe78bSCy Schubert         }
161*7f2fe78bSCy Schubert         else {
162*7f2fe78bSCy Schubert             *targ_name = GSS_C_NO_NAME;
163*7f2fe78bSCy Schubert         }
164*7f2fe78bSCy Schubert     }
165*7f2fe78bSCy Schubert 
166*7f2fe78bSCy Schubert     if (mech_type)
167*7f2fe78bSCy Schubert 	*mech_type = gssint_get_public_oid(actual_mech);
168*7f2fe78bSCy Schubert 
169*7f2fe78bSCy Schubert     return(GSS_S_COMPLETE);
170*7f2fe78bSCy Schubert }
171