xref: /titanic_50/usr/src/lib/libgss/g_inquire_context.c (revision 84ba300aaa958c8e8427c2ec66a932d86bee71c4)
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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 /*
26  *  glue routine for gss_inquire_context
27  */
28 
29 #include <mechglueP.h>
30 #include "gssapiP_generic.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           OM_uint32 *minor_status,
71           gss_ctx_id_t context_handle,
72           gss_name_t *src_name,
73           gss_name_t *targ_name,
74           OM_uint32 *lifetime_rec,
75           gss_OID *mech_type,
76           OM_uint32 *ctx_flags,
77           int *locally_initiated,
78           int *opened)
79 {
80 	gss_union_ctx_id_t	ctx;
81 	gss_mechanism		mech;
82 	OM_uint32		status, temp_minor;
83 	gss_name_t localTargName = NULL, localSourceName = NULL;
84 
85 	status = val_inq_ctx_args(minor_status,
86 				context_handle,
87 				src_name,
88 				targ_name,
89 				mech_type);
90 	if (status != GSS_S_COMPLETE)
91 		return (status);
92 
93 	/*
94 	 * select the approprate underlying mechanism routine and
95 	 * call it.
96 	 */
97 
98 	ctx = (gss_union_ctx_id_t)context_handle;
99 	mech = __gss_get_mechanism(ctx->mech_type);
100 
101 	if (!mech || !mech->gss_inquire_context || !mech->gss_display_name ||
102 		!mech->gss_release_name) {
103 		return (GSS_S_UNAVAILABLE);
104 	}
105 
106 	status = mech->gss_inquire_context(
107 				mech->context,
108 				minor_status,
109 				ctx->internal_ctx_id,
110 				(src_name ? &localSourceName : NULL),
111 				(targ_name ? &localTargName : NULL),
112 				lifetime_rec,
113 				NULL,
114 				ctx_flags,
115 				locally_initiated,
116 				opened);
117 
118 	if (status != GSS_S_COMPLETE) {
119 		map_error(minor_status, mech);
120 		return (status);
121 	}
122 
123 	/* need to convert names */
124 	if (src_name) {
125 		status = __gss_convert_name_to_union_name(minor_status, mech,
126 						localSourceName, src_name);
127 		if (status != GSS_S_COMPLETE) {
128 			if (localTargName)
129 				mech->gss_release_name(mech->context,
130 						&temp_minor, &localTargName);
131 			return (status);
132 		}
133 	}
134 
135 	if (targ_name) {
136 		status = __gss_convert_name_to_union_name(minor_status, mech,
137 						localTargName, targ_name);
138 
139 		if (status != GSS_S_COMPLETE) {
140 			if (src_name)
141 				(void) gss_release_name(&temp_minor, src_name);
142 
143 			return (status);
144 		}
145 	}
146 
147 	/* spec says mech type must point to static storage */
148 	if (mech_type)
149 		*mech_type = &mech->mech_type;
150 	return (GSS_S_COMPLETE);
151 }
152