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