xref: /titanic_50/usr/src/lib/libgss/g_inquire_context.c (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  *  glue routine for gss_inquire_context
31  */
32 
33 #include <mechglueP.h>
34 #include <stdlib.h>
35 
36 /* Last argument new for V2 */
37 OM_uint32
38 gss_inquire_context(
39 		minor_status,
40 		context_handle,
41 		src_name,
42 		targ_name,
43 		lifetime_rec,
44 		mech_type,
45 		ctx_flags,
46 		locally_initiated,
47 		open)
48 
49 OM_uint32 *minor_status;
50 const gss_ctx_id_t context_handle;
51 gss_name_t *src_name;
52 gss_name_t *targ_name;
53 OM_uint32 *lifetime_rec;
54 gss_OID *mech_type;
55 OM_uint32 *ctx_flags;
56 int *locally_initiated;
57 int *open;
58 
59 {
60 	gss_union_ctx_id_t	ctx;
61 	gss_mechanism		mech;
62 	OM_uint32		status, temp_minor;
63 	gss_name_t localTargName = NULL, localSourceName = NULL;
64 
65 	if (!minor_status)
66 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
67 
68 	*minor_status = 0;
69 
70 	/* if the context_handle is Null, return NO_CONTEXT error */
71 	if (context_handle == GSS_C_NO_CONTEXT)
72 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
73 
74 	/* set all output value to NULL */
75 	if (src_name)
76 		*src_name = NULL;
77 
78 	if (targ_name)
79 		*targ_name = NULL;
80 
81 	if (mech_type)
82 		*mech_type = NULL;
83 
84 	/*
85 	 * select the approprate underlying mechanism routine and
86 	 * call it.
87 	 */
88 
89 	ctx = (gss_union_ctx_id_t)context_handle;
90 	mech = __gss_get_mechanism(ctx->mech_type);
91 
92 	if (!mech || !mech->gss_inquire_context || !mech->gss_display_name ||
93 		!mech->gss_release_name) {
94 		return (GSS_S_UNAVAILABLE);
95 	}
96 
97 	status = mech->gss_inquire_context(
98 				mech->context,
99 				minor_status,
100 				ctx->internal_ctx_id,
101 				(src_name ? &localSourceName : NULL),
102 				(targ_name ? &localTargName : NULL),
103 				lifetime_rec,
104 				NULL,
105 				ctx_flags,
106 				locally_initiated,
107 				open);
108 
109 	if (status != GSS_S_COMPLETE) {
110 		return (status);
111 	}
112 
113 	/* need to convert names */
114 	if (src_name) {
115 		status = __gss_convert_name_to_union_name(minor_status, mech,
116 						localSourceName, src_name);
117 		if (status != GSS_S_COMPLETE) {
118 			if (localTargName)
119 				mech->gss_release_name(mech->context,
120 						&temp_minor, &localTargName);
121 			return (status);
122 		}
123 	}
124 
125 	if (targ_name) {
126 		status = __gss_convert_name_to_union_name(minor_status, mech,
127 						localTargName, targ_name);
128 
129 		if (status != GSS_S_COMPLETE) {
130 			if (src_name)
131 				(void) gss_release_name(&temp_minor, src_name);
132 
133 			return (status);
134 		}
135 	}
136 
137 	/* spec says mech type must point to static storage */
138 	if (mech_type)
139 		*mech_type = &mech->mech_type;
140 	return (GSS_S_COMPLETE);
141 }
142