xref: /titanic_51/usr/src/lib/rpcsec_gss/rpcsec_gss_misc.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1986-1995, 1997, 2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved.
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  * $Header:
33*7c478bd9Sstevel@tonic-gate  * /afs/gza.com/product/secure/rel-eng/src/1.1/rpc/RCS/auth_gssapi_misc.c,v
34*7c478bd9Sstevel@tonic-gate  * 1.10 1994/10/27 12:39:23 jik Exp $
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
38*7c478bd9Sstevel@tonic-gate #include <gssapi/gssapi.h>
39*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
40*7c478bd9Sstevel@tonic-gate #include <rpc/rpcsec_defs.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * Miscellaneous XDR routines.
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate bool_t
46*7c478bd9Sstevel@tonic-gate __xdr_gss_buf(xdrs, buf)
47*7c478bd9Sstevel@tonic-gate 	XDR		*xdrs;
48*7c478bd9Sstevel@tonic-gate 	gss_buffer_t	buf;
49*7c478bd9Sstevel@tonic-gate {
50*7c478bd9Sstevel@tonic-gate 	u_int cast_len, bound_len;
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate 	/*
53*7c478bd9Sstevel@tonic-gate 	 * We go through this contortion because size_t is a now a ulong,
54*7c478bd9Sstevel@tonic-gate 	 * GSS-API uses ulongs.
55*7c478bd9Sstevel@tonic-gate 	 */
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate 	if (xdrs->x_op != XDR_DECODE) {
58*7c478bd9Sstevel@tonic-gate 		bound_len = cast_len = (u_int) buf->length;
59*7c478bd9Sstevel@tonic-gate 	} else {
60*7c478bd9Sstevel@tonic-gate 		bound_len = (u_int)-1;
61*7c478bd9Sstevel@tonic-gate 	}
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	if (xdr_bytes(xdrs, (char **)&buf->value, &cast_len,
64*7c478bd9Sstevel@tonic-gate 	    bound_len) == TRUE) {
65*7c478bd9Sstevel@tonic-gate 		if (xdrs->x_op == XDR_DECODE)
66*7c478bd9Sstevel@tonic-gate 			buf->length = cast_len;
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 		return (TRUE);
69*7c478bd9Sstevel@tonic-gate 	}
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate 	return (FALSE);
72*7c478bd9Sstevel@tonic-gate }
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate bool_t
75*7c478bd9Sstevel@tonic-gate __xdr_rpc_gss_creds(xdrs, creds)
76*7c478bd9Sstevel@tonic-gate 	XDR			*xdrs;
77*7c478bd9Sstevel@tonic-gate 	rpc_gss_creds		*creds;
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &creds->version) ||
80*7c478bd9Sstevel@tonic-gate 				!xdr_u_int(xdrs, &creds->gss_proc) ||
81*7c478bd9Sstevel@tonic-gate 				!xdr_u_int(xdrs, &creds->seq_num) ||
82*7c478bd9Sstevel@tonic-gate 				!xdr_u_int(xdrs, (u_int *)&creds->service) ||
83*7c478bd9Sstevel@tonic-gate 				!__xdr_gss_buf(xdrs, &creds->ctx_handle))
84*7c478bd9Sstevel@tonic-gate 		return (FALSE);
85*7c478bd9Sstevel@tonic-gate 	return (TRUE);
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate bool_t
89*7c478bd9Sstevel@tonic-gate __xdr_rpc_gss_init_arg(xdrs, init_arg)
90*7c478bd9Sstevel@tonic-gate 	XDR			*xdrs;
91*7c478bd9Sstevel@tonic-gate 	rpc_gss_init_arg	*init_arg;
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate 	if (!__xdr_gss_buf(xdrs, init_arg))
94*7c478bd9Sstevel@tonic-gate 		return (FALSE);
95*7c478bd9Sstevel@tonic-gate 	return (TRUE);
96*7c478bd9Sstevel@tonic-gate }
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate bool_t
99*7c478bd9Sstevel@tonic-gate __xdr_rpc_gss_init_res(xdrs, init_res)
100*7c478bd9Sstevel@tonic-gate 	XDR			*xdrs;
101*7c478bd9Sstevel@tonic-gate 	rpc_gss_init_res	*init_res;
102*7c478bd9Sstevel@tonic-gate {
103*7c478bd9Sstevel@tonic-gate 	if (!__xdr_gss_buf(xdrs, &init_res->ctx_handle) ||
104*7c478bd9Sstevel@tonic-gate 			!xdr_u_int(xdrs, (u_int *)&init_res->gss_major) ||
105*7c478bd9Sstevel@tonic-gate 			!xdr_u_int(xdrs, (u_int *)&init_res->gss_minor) ||
106*7c478bd9Sstevel@tonic-gate 			!xdr_u_int(xdrs, (u_int *)&init_res->seq_window) ||
107*7c478bd9Sstevel@tonic-gate 			!__xdr_gss_buf(xdrs, &init_res->token))
108*7c478bd9Sstevel@tonic-gate 		return (FALSE);
109*7c478bd9Sstevel@tonic-gate 	return (TRUE);
110*7c478bd9Sstevel@tonic-gate }
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate /*
113*7c478bd9Sstevel@tonic-gate  * Generic routine to wrap data used by client and server sides.
114*7c478bd9Sstevel@tonic-gate  */
115*7c478bd9Sstevel@tonic-gate bool_t
116*7c478bd9Sstevel@tonic-gate __rpc_gss_wrap_data(service, qop, context, seq_num, out_xdrs, xdr_func,
117*7c478bd9Sstevel@tonic-gate 							xdr_ptr)
118*7c478bd9Sstevel@tonic-gate 	OM_uint32		qop;
119*7c478bd9Sstevel@tonic-gate 	rpc_gss_service_t	service;
120*7c478bd9Sstevel@tonic-gate 	gss_ctx_id_t		context;
121*7c478bd9Sstevel@tonic-gate 	u_int			seq_num;
122*7c478bd9Sstevel@tonic-gate 	XDR			*out_xdrs;
123*7c478bd9Sstevel@tonic-gate 	bool_t			(*xdr_func)();
124*7c478bd9Sstevel@tonic-gate 	caddr_t			xdr_ptr;
125*7c478bd9Sstevel@tonic-gate {
126*7c478bd9Sstevel@tonic-gate 	OM_uint32		minor;
127*7c478bd9Sstevel@tonic-gate 	gss_buffer_desc		in_buf, out_buf;
128*7c478bd9Sstevel@tonic-gate 	XDR			temp_xdrs;
129*7c478bd9Sstevel@tonic-gate 	bool_t			conf_state;
130*7c478bd9Sstevel@tonic-gate 	bool_t			ret = FALSE;
131*7c478bd9Sstevel@tonic-gate 	u_int			bufsiz;
132*7c478bd9Sstevel@tonic-gate 	char			*buf;
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 	/*
135*7c478bd9Sstevel@tonic-gate 	 * Create a temporary XDR/buffer to hold the data to be wrapped.
136*7c478bd9Sstevel@tonic-gate 	 */
137*7c478bd9Sstevel@tonic-gate 	out_buf.length = 0;
138*7c478bd9Sstevel@tonic-gate 	bufsiz = xdr_sizeof(xdr_func, xdr_ptr) +
139*7c478bd9Sstevel@tonic-gate 		xdr_sizeof(xdr_u_int, &seq_num);
140*7c478bd9Sstevel@tonic-gate 	if ((buf = (char *)malloc(bufsiz)) == NULL) {
141*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, dgettext(TEXT_DOMAIN, "malloc failed in "
142*7c478bd9Sstevel@tonic-gate 			"__rpc_gss_wrap_data\n"));
143*7c478bd9Sstevel@tonic-gate 		return (FALSE);
144*7c478bd9Sstevel@tonic-gate 	}
145*7c478bd9Sstevel@tonic-gate 	xdrmem_create(&temp_xdrs, buf, bufsiz, XDR_ENCODE);
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	/*
148*7c478bd9Sstevel@tonic-gate 	 * serialize the sequence number into tmp memory
149*7c478bd9Sstevel@tonic-gate 	 */
150*7c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(&temp_xdrs, &seq_num))
151*7c478bd9Sstevel@tonic-gate 		goto fail;
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 	/*
154*7c478bd9Sstevel@tonic-gate 	 * serialize the arguments into tmp memory
155*7c478bd9Sstevel@tonic-gate 	 */
156*7c478bd9Sstevel@tonic-gate 	if (!(*xdr_func)(&temp_xdrs, xdr_ptr))
157*7c478bd9Sstevel@tonic-gate 		goto fail;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 	/*
160*7c478bd9Sstevel@tonic-gate 	 * Data to be wrapped goes in in_buf.  If privacy is used,
161*7c478bd9Sstevel@tonic-gate 	 * out_buf will have wrapped data (in_buf will no longer be
162*7c478bd9Sstevel@tonic-gate 	 * needed).  If integrity is used, out_buf will have checksum
163*7c478bd9Sstevel@tonic-gate 	 * which will follow the data in in_buf.
164*7c478bd9Sstevel@tonic-gate 	 */
165*7c478bd9Sstevel@tonic-gate 	in_buf.length = xdr_getpos(&temp_xdrs);
166*7c478bd9Sstevel@tonic-gate 	in_buf.value = temp_xdrs.x_base;
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 	switch (service) {
169*7c478bd9Sstevel@tonic-gate 	case rpc_gss_svc_privacy:
170*7c478bd9Sstevel@tonic-gate 		if (gss_seal(&minor, context, TRUE, qop, &in_buf,
171*7c478bd9Sstevel@tonic-gate 				&conf_state, &out_buf) != GSS_S_COMPLETE)
172*7c478bd9Sstevel@tonic-gate 			goto fail;
173*7c478bd9Sstevel@tonic-gate 		in_buf.length = 0;	/* in_buf not needed */
174*7c478bd9Sstevel@tonic-gate 		if (!conf_state)
175*7c478bd9Sstevel@tonic-gate 			goto fail;
176*7c478bd9Sstevel@tonic-gate 		break;
177*7c478bd9Sstevel@tonic-gate 	case rpc_gss_svc_integrity:
178*7c478bd9Sstevel@tonic-gate 		if (gss_sign(&minor, context, qop, &in_buf,
179*7c478bd9Sstevel@tonic-gate 						&out_buf) != GSS_S_COMPLETE)
180*7c478bd9Sstevel@tonic-gate 			goto fail;
181*7c478bd9Sstevel@tonic-gate 		break;
182*7c478bd9Sstevel@tonic-gate 	default:
183*7c478bd9Sstevel@tonic-gate 		goto fail;
184*7c478bd9Sstevel@tonic-gate 	}
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate 	/*
187*7c478bd9Sstevel@tonic-gate 	 * write out in_buf and out_buf as needed
188*7c478bd9Sstevel@tonic-gate 	 */
189*7c478bd9Sstevel@tonic-gate 	if (in_buf.length != 0) {
190*7c478bd9Sstevel@tonic-gate 		if (!__xdr_gss_buf(out_xdrs, &in_buf))
191*7c478bd9Sstevel@tonic-gate 			goto fail;
192*7c478bd9Sstevel@tonic-gate 	}
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 	if (!__xdr_gss_buf(out_xdrs, &out_buf))
195*7c478bd9Sstevel@tonic-gate 		goto fail;
196*7c478bd9Sstevel@tonic-gate 	ret = TRUE;
197*7c478bd9Sstevel@tonic-gate fail:
198*7c478bd9Sstevel@tonic-gate 	XDR_DESTROY(&temp_xdrs);
199*7c478bd9Sstevel@tonic-gate 	if (buf)
200*7c478bd9Sstevel@tonic-gate 		(void) free(buf);
201*7c478bd9Sstevel@tonic-gate 	if (out_buf.length != 0)
202*7c478bd9Sstevel@tonic-gate 		(void) gss_release_buffer(&minor, &out_buf);
203*7c478bd9Sstevel@tonic-gate 	return (ret);
204*7c478bd9Sstevel@tonic-gate }
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate /*
207*7c478bd9Sstevel@tonic-gate  * Generic routine to unwrap data used by client and server sides.
208*7c478bd9Sstevel@tonic-gate  */
209*7c478bd9Sstevel@tonic-gate bool_t
210*7c478bd9Sstevel@tonic-gate __rpc_gss_unwrap_data(service, context, seq_num, qop_check, in_xdrs, xdr_func,
211*7c478bd9Sstevel@tonic-gate 								xdr_ptr)
212*7c478bd9Sstevel@tonic-gate 	rpc_gss_service_t	service;
213*7c478bd9Sstevel@tonic-gate 	gss_ctx_id_t		context;
214*7c478bd9Sstevel@tonic-gate 	u_int			seq_num;
215*7c478bd9Sstevel@tonic-gate 	OM_uint32		qop_check;
216*7c478bd9Sstevel@tonic-gate 	XDR			*in_xdrs;
217*7c478bd9Sstevel@tonic-gate 	bool_t			(*xdr_func)();
218*7c478bd9Sstevel@tonic-gate 	caddr_t			xdr_ptr;
219*7c478bd9Sstevel@tonic-gate {
220*7c478bd9Sstevel@tonic-gate 	gss_buffer_desc		in_buf, out_buf;
221*7c478bd9Sstevel@tonic-gate 	XDR			temp_xdrs;
222*7c478bd9Sstevel@tonic-gate 	u_int			seq_num2;
223*7c478bd9Sstevel@tonic-gate 	bool_t			conf;
224*7c478bd9Sstevel@tonic-gate 	OM_uint32		major = GSS_S_COMPLETE, minor = 0;
225*7c478bd9Sstevel@tonic-gate 	int			qop;
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate 	in_buf.value = NULL;
228*7c478bd9Sstevel@tonic-gate 	out_buf.value = NULL;
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 	/*
231*7c478bd9Sstevel@tonic-gate 	 * Pull out wrapped data.  For privacy service, this is the
232*7c478bd9Sstevel@tonic-gate 	 * encrypted data.  For integrity service, this is the data
233*7c478bd9Sstevel@tonic-gate 	 * followed by a checksum.
234*7c478bd9Sstevel@tonic-gate 	 */
235*7c478bd9Sstevel@tonic-gate 	if (!__xdr_gss_buf(in_xdrs, &in_buf))
236*7c478bd9Sstevel@tonic-gate 		return (FALSE);
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate 	if (service == rpc_gss_svc_privacy) {
239*7c478bd9Sstevel@tonic-gate 		major = gss_unseal(&minor, context, &in_buf, &out_buf, &conf,
240*7c478bd9Sstevel@tonic-gate 							&qop);
241*7c478bd9Sstevel@tonic-gate 		free(in_buf.value);
242*7c478bd9Sstevel@tonic-gate 		if (major != GSS_S_COMPLETE)
243*7c478bd9Sstevel@tonic-gate 			return (FALSE);
244*7c478bd9Sstevel@tonic-gate 		/*
245*7c478bd9Sstevel@tonic-gate 		 * Keep the returned token (unencrypted data) in in_buf.
246*7c478bd9Sstevel@tonic-gate 		 */
247*7c478bd9Sstevel@tonic-gate 		in_buf.length = out_buf.length;
248*7c478bd9Sstevel@tonic-gate 		in_buf.value = out_buf.value;
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate 		/*
251*7c478bd9Sstevel@tonic-gate 		 * If privacy was not used, or if QOP is not what we are
252*7c478bd9Sstevel@tonic-gate 		 * expecting, fail.
253*7c478bd9Sstevel@tonic-gate 		 */
254*7c478bd9Sstevel@tonic-gate 		if (!conf || qop != qop_check)
255*7c478bd9Sstevel@tonic-gate 			goto fail;
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate 	} else if (service == rpc_gss_svc_integrity) {
258*7c478bd9Sstevel@tonic-gate 		if (!__xdr_gss_buf(in_xdrs, &out_buf))
259*7c478bd9Sstevel@tonic-gate 			return (FALSE);
260*7c478bd9Sstevel@tonic-gate 		major = gss_verify(&minor, context, &in_buf, &out_buf, &qop);
261*7c478bd9Sstevel@tonic-gate 		free(out_buf.value);
262*7c478bd9Sstevel@tonic-gate 		if (major != GSS_S_COMPLETE) {
263*7c478bd9Sstevel@tonic-gate 			free(in_buf.value);
264*7c478bd9Sstevel@tonic-gate 			return (FALSE);
265*7c478bd9Sstevel@tonic-gate 		}
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 		/*
268*7c478bd9Sstevel@tonic-gate 		 * If QOP is not what we are expecting, fail.
269*7c478bd9Sstevel@tonic-gate 		 */
270*7c478bd9Sstevel@tonic-gate 		if (qop != qop_check)
271*7c478bd9Sstevel@tonic-gate 			goto fail;
272*7c478bd9Sstevel@tonic-gate 	}
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate 	xdrmem_create(&temp_xdrs, in_buf.value, in_buf.length, XDR_DECODE);
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate 	/*
277*7c478bd9Sstevel@tonic-gate 	 * The data consists of the sequence number followed by the
278*7c478bd9Sstevel@tonic-gate 	 * arguments.  Make sure sequence number is what we are
279*7c478bd9Sstevel@tonic-gate 	 * expecting (i.e., the value in the header).
280*7c478bd9Sstevel@tonic-gate 	 */
281*7c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(&temp_xdrs, &seq_num2))
282*7c478bd9Sstevel@tonic-gate 		goto fail;
283*7c478bd9Sstevel@tonic-gate 	if (seq_num2 != seq_num)
284*7c478bd9Sstevel@tonic-gate 		goto fail;
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate 	/*
287*7c478bd9Sstevel@tonic-gate 	 * Deserialize the arguments into xdr_ptr, and release in_buf.
288*7c478bd9Sstevel@tonic-gate 	 */
289*7c478bd9Sstevel@tonic-gate 	if (!(*xdr_func)(&temp_xdrs, xdr_ptr))
290*7c478bd9Sstevel@tonic-gate 		goto fail;
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate 	if (service == rpc_gss_svc_privacy)
293*7c478bd9Sstevel@tonic-gate 		(void) gss_release_buffer(&minor, &in_buf);
294*7c478bd9Sstevel@tonic-gate 	else
295*7c478bd9Sstevel@tonic-gate 		free(in_buf.value);
296*7c478bd9Sstevel@tonic-gate 	XDR_DESTROY(&temp_xdrs);
297*7c478bd9Sstevel@tonic-gate 	return (TRUE);
298*7c478bd9Sstevel@tonic-gate fail:
299*7c478bd9Sstevel@tonic-gate 	XDR_DESTROY(&temp_xdrs);
300*7c478bd9Sstevel@tonic-gate 	if (service == rpc_gss_svc_privacy)
301*7c478bd9Sstevel@tonic-gate 		(void) gss_release_buffer(&minor, &in_buf);
302*7c478bd9Sstevel@tonic-gate 	else
303*7c478bd9Sstevel@tonic-gate 		free(in_buf.value);
304*7c478bd9Sstevel@tonic-gate 	return (FALSE);
305*7c478bd9Sstevel@tonic-gate }
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
308*7c478bd9Sstevel@tonic-gate int
309*7c478bd9Sstevel@tonic-gate __find_max_data_length(service, context, qop, max_tp_unit_len)
310*7c478bd9Sstevel@tonic-gate 	rpc_gss_service_t service;
311*7c478bd9Sstevel@tonic-gate 	gss_ctx_id_t	context;
312*7c478bd9Sstevel@tonic-gate 	OM_uint32	qop;
313*7c478bd9Sstevel@tonic-gate 	int		max_tp_unit_len;
314*7c478bd9Sstevel@tonic-gate {
315*7c478bd9Sstevel@tonic-gate 	int		conf;
316*7c478bd9Sstevel@tonic-gate 	OM_uint32	maj_stat = GSS_S_COMPLETE, min_stat = 0;
317*7c478bd9Sstevel@tonic-gate 	OM_uint32	max_input_size;
318*7c478bd9Sstevel@tonic-gate 	int		ret_val = 0;
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate 	if (service == rpc_gss_svc_integrity || service == rpc_gss_svc_default)
321*7c478bd9Sstevel@tonic-gate 		conf = 0;
322*7c478bd9Sstevel@tonic-gate 	else if (service == rpc_gss_svc_privacy)
323*7c478bd9Sstevel@tonic-gate 		conf = 1;
324*7c478bd9Sstevel@tonic-gate 	else if (service == rpc_gss_svc_none)
325*7c478bd9Sstevel@tonic-gate 		return (max_tp_unit_len);
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate 	maj_stat = gss_wrap_size_limit(&min_stat,
328*7c478bd9Sstevel@tonic-gate 		context, conf, qop,
329*7c478bd9Sstevel@tonic-gate 		max_tp_unit_len, &max_input_size);
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 	/*
332*7c478bd9Sstevel@tonic-gate 	 * max_input_size may result in negative value
333*7c478bd9Sstevel@tonic-gate 	 */
334*7c478bd9Sstevel@tonic-gate 	if (maj_stat == GSS_S_COMPLETE) {
335*7c478bd9Sstevel@tonic-gate 		if ((int)max_input_size <= 0)
336*7c478bd9Sstevel@tonic-gate 			ret_val = 0;
337*7c478bd9Sstevel@tonic-gate 		else
338*7c478bd9Sstevel@tonic-gate 			ret_val = (int)(max_input_size);
339*7c478bd9Sstevel@tonic-gate 	} else {
340*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, dgettext(TEXT_DOMAIN,
341*7c478bd9Sstevel@tonic-gate 					"gss_wrap_size_limit failed in "
342*7c478bd9Sstevel@tonic-gate 					"__find_max_data_length\n"));
343*7c478bd9Sstevel@tonic-gate 	}
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate 	return (ret_val);
346*7c478bd9Sstevel@tonic-gate }
347