17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5cb620785Sraf  * Common Development and Distribution License (the "License").
6cb620785Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21cb620785Sraf 
227c478bd9Sstevel@tonic-gate /*
237257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24cb620785Sraf  * Use is subject to license terms.
25*c5991125SMatt Barden  *
26*c5991125SMatt Barden  * Copyright 2021 Tintri by DDN, Inc. All rights reserved.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved.
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * $Header:
337c478bd9Sstevel@tonic-gate  * /afs/gza.com/product/secure/rel-eng/src/1.1/rpc/RCS/auth_gssapi.c,v
347c478bd9Sstevel@tonic-gate  * 1.14 1995/03/22 22:07:55 jik Exp $
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <stdio.h>
387c478bd9Sstevel@tonic-gate #include <stdlib.h>
397c478bd9Sstevel@tonic-gate #include <strings.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <pthread.h>
427c478bd9Sstevel@tonic-gate #include <thread.h>
437c478bd9Sstevel@tonic-gate #include <syslog.h>
447c478bd9Sstevel@tonic-gate #include <gssapi/gssapi.h>
457c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
467c478bd9Sstevel@tonic-gate #include <rpc/rpcsec_defs.h>
477c478bd9Sstevel@tonic-gate 
48*c5991125SMatt Barden static void	rpc_gss_nextverf();
49*c5991125SMatt Barden static bool_t	rpc_gss_marshall();
507c478bd9Sstevel@tonic-gate static bool_t	rpc_gss_validate();
517c478bd9Sstevel@tonic-gate static bool_t	rpc_gss_refresh();
527c478bd9Sstevel@tonic-gate static void	rpc_gss_destroy();
537c478bd9Sstevel@tonic-gate static void	rpc_gss_destroy_pvt();
547c478bd9Sstevel@tonic-gate static bool_t	rpc_gss_seccreate_pvt();
557c478bd9Sstevel@tonic-gate static bool_t	validate_seqwin();
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * Globals that should have header files but don't.
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate extern bool_t	xdr_opaque_auth(XDR *, struct opaque_auth *);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static struct auth_ops rpc_gss_ops = {
647c478bd9Sstevel@tonic-gate 	rpc_gss_nextverf,
657c478bd9Sstevel@tonic-gate 	rpc_gss_marshall,
667c478bd9Sstevel@tonic-gate 	rpc_gss_validate,
677c478bd9Sstevel@tonic-gate 	rpc_gss_refresh,
687c478bd9Sstevel@tonic-gate 	rpc_gss_destroy
697c478bd9Sstevel@tonic-gate };
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * Private data for RPCSEC_GSS.
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate typedef struct _rpc_gss_data {
757c478bd9Sstevel@tonic-gate 	bool_t			established;	/* TRUE when established */
767c478bd9Sstevel@tonic-gate 	CLIENT			*clnt;		/* associated client handle */
777c478bd9Sstevel@tonic-gate 	uint_t			version;	/* RPCSEC version */
787c478bd9Sstevel@tonic-gate 	gss_ctx_id_t		context;	/* GSS context id */
797c478bd9Sstevel@tonic-gate 	gss_buffer_desc		ctx_handle;	/* RPCSEC context handle */
807c478bd9Sstevel@tonic-gate 	uint_t			seq_num;	/* last sequence number rcvd */
817c478bd9Sstevel@tonic-gate 	gss_cred_id_t		my_cred;	/* GSS credentials */
827c478bd9Sstevel@tonic-gate 	OM_uint32		qop;		/* requested QOP */
837c478bd9Sstevel@tonic-gate 	rpc_gss_service_t	service;	/* requested service */
847c478bd9Sstevel@tonic-gate 	uint_t			gss_proc;	/* GSS control procedure */
857c478bd9Sstevel@tonic-gate 	gss_name_t		target_name;	/* target server */
867c478bd9Sstevel@tonic-gate 	int			req_flags;	/* GSS request bits */
877c478bd9Sstevel@tonic-gate 	gss_OID			mech_type;	/* GSS mechanism */
887c478bd9Sstevel@tonic-gate 	OM_uint32		time_req;	/* requested cred lifetime */
897c478bd9Sstevel@tonic-gate 	bool_t			invalid;	/* can't use this any more */
907c478bd9Sstevel@tonic-gate 	OM_uint32		seq_window;	/* server sequence window */
917c478bd9Sstevel@tonic-gate 	struct opaque_auth	*verifier;  /* rpc reply verifier saved for */
927c478bd9Sstevel@tonic-gate 					    /* validating the sequence window */
937c478bd9Sstevel@tonic-gate 	gss_channel_bindings_t	icb;
947c478bd9Sstevel@tonic-gate } rpc_gss_data;
957c478bd9Sstevel@tonic-gate #define	AUTH_PRIVATE(auth) ((rpc_gss_data *)auth->ah_private)
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Create a context.
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate AUTH *
__rpc_gss_seccreate(clnt,server_name,mech,service,qop,options_req,options_ret)1017c478bd9Sstevel@tonic-gate __rpc_gss_seccreate(clnt, server_name, mech, service, qop, options_req,
1027c478bd9Sstevel@tonic-gate 								options_ret)
1037c478bd9Sstevel@tonic-gate 	CLIENT			*clnt;		/* associated client handle */
1047c478bd9Sstevel@tonic-gate 	char			*server_name;	/* target server */
1057c478bd9Sstevel@tonic-gate 	char			*mech;		/* security mechanism */
1067c478bd9Sstevel@tonic-gate 	rpc_gss_service_t	service;	/* security service */
1077c478bd9Sstevel@tonic-gate 	char			*qop;		/* requested QOP */
1087c478bd9Sstevel@tonic-gate 	rpc_gss_options_req_t	*options_req;	/* requested options */
1097c478bd9Sstevel@tonic-gate 	rpc_gss_options_ret_t	*options_ret;	/* returned options */
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	OM_uint32		gssstat;
1127c478bd9Sstevel@tonic-gate 	OM_uint32		minor_stat;
1137c478bd9Sstevel@tonic-gate 	gss_name_t		target_name;
1147c478bd9Sstevel@tonic-gate 	gss_OID			mech_type;
1157c478bd9Sstevel@tonic-gate 	OM_uint32		ret_flags;
1167c478bd9Sstevel@tonic-gate 	OM_uint32		time_rec;
1177c478bd9Sstevel@tonic-gate 	gss_buffer_desc		input_name;
1187c478bd9Sstevel@tonic-gate 	AUTH			*auth = NULL;
1197c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap = NULL;
1207c478bd9Sstevel@tonic-gate 	OM_uint32		qop_num;
1217c478bd9Sstevel@tonic-gate 
122*c5991125SMatt Barden 	if (options_ret != NULL) {
123*c5991125SMatt Barden 		options_ret->major_status = 0;
124*c5991125SMatt Barden 		options_ret->minor_status = 0;
125*c5991125SMatt Barden 	}
126*c5991125SMatt Barden 
1277c478bd9Sstevel@tonic-gate 	/*
1287c478bd9Sstevel@tonic-gate 	 * convert ascii strings to GSS values
1297c478bd9Sstevel@tonic-gate 	 */
1307c478bd9Sstevel@tonic-gate 	if (!__rpc_gss_qop_to_num(qop, mech, &qop_num)) {
1317c478bd9Sstevel@tonic-gate 		return (NULL);
1327c478bd9Sstevel@tonic-gate 	}
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	if (!__rpc_gss_mech_to_oid(mech, &mech_type)) {
1357c478bd9Sstevel@tonic-gate 		return (NULL);
1367c478bd9Sstevel@tonic-gate 	}
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	/*
1397c478bd9Sstevel@tonic-gate 	 * convert name to GSS internal type
1407c478bd9Sstevel@tonic-gate 	 */
1417c478bd9Sstevel@tonic-gate 	input_name.value = server_name;
1427c478bd9Sstevel@tonic-gate 	input_name.length = strlen(server_name);
1437c478bd9Sstevel@tonic-gate 	gssstat = gss_import_name(&minor_stat, &input_name,
1447c478bd9Sstevel@tonic-gate 				(gss_OID)GSS_C_NT_HOSTBASED_SERVICE,
1457c478bd9Sstevel@tonic-gate 				&target_name);
1467c478bd9Sstevel@tonic-gate 	if (gssstat != GSS_S_COMPLETE) {
1477c478bd9Sstevel@tonic-gate 		rpc_gss_err.rpc_gss_error = RPC_GSS_ER_SYSTEMERROR;
1487c478bd9Sstevel@tonic-gate 		rpc_gss_err.system_error = ENOMEM;
149*c5991125SMatt Barden 		if (options_ret != NULL) {
150*c5991125SMatt Barden 			options_ret->major_status = gssstat;
151*c5991125SMatt Barden 			options_ret->minor_status = minor_stat;
152*c5991125SMatt Barden 		}
1537c478bd9Sstevel@tonic-gate 		return (NULL);
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	/*
1577c478bd9Sstevel@tonic-gate 	 * Create AUTH handle.  Save the necessary interface information
1587c478bd9Sstevel@tonic-gate 	 * so that the client can refresh the handle later if needed.
1597c478bd9Sstevel@tonic-gate 	 */
1607c478bd9Sstevel@tonic-gate 	if ((auth = (AUTH *) malloc(sizeof (*auth))) != NULL)
1617c478bd9Sstevel@tonic-gate 		ap = (rpc_gss_data *) malloc(sizeof (*ap));
1627c478bd9Sstevel@tonic-gate 	if (auth == NULL || ap == NULL) {
1637c478bd9Sstevel@tonic-gate 		rpc_gss_err.rpc_gss_error = RPC_GSS_ER_SYSTEMERROR;
1647c478bd9Sstevel@tonic-gate 		rpc_gss_err.system_error = ENOMEM;
1657c478bd9Sstevel@tonic-gate 		if (auth != NULL)
1667c478bd9Sstevel@tonic-gate 			free((char *)auth);
1677c478bd9Sstevel@tonic-gate 		(void) gss_release_name(&minor_stat, &target_name);
1687c478bd9Sstevel@tonic-gate 		return (NULL);
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	memset((char *)ap, 0, sizeof (*ap));
1727c478bd9Sstevel@tonic-gate 	ap->clnt = clnt;
1737c478bd9Sstevel@tonic-gate 	ap->version = RPCSEC_GSS_VERSION;
1747c478bd9Sstevel@tonic-gate 	if (options_req != NULL) {
1757c478bd9Sstevel@tonic-gate 		ap->my_cred = options_req->my_cred;
1767c478bd9Sstevel@tonic-gate 		ap->req_flags = options_req->req_flags;
1777c478bd9Sstevel@tonic-gate 		ap->time_req = options_req->time_req;
1787c478bd9Sstevel@tonic-gate 		ap->icb = options_req->input_channel_bindings;
1797c478bd9Sstevel@tonic-gate 	} else {
1807c478bd9Sstevel@tonic-gate 		ap->my_cred = GSS_C_NO_CREDENTIAL;
1817c478bd9Sstevel@tonic-gate 		ap->req_flags = GSS_C_MUTUAL_FLAG;
1827c478bd9Sstevel@tonic-gate 		ap->time_req = 0;
1837c478bd9Sstevel@tonic-gate 		ap->icb = NULL;
1847c478bd9Sstevel@tonic-gate 	}
1857c478bd9Sstevel@tonic-gate 	if ((ap->service = service) == rpc_gss_svc_default)
1867c478bd9Sstevel@tonic-gate 		ap->service = rpc_gss_svc_integrity;
1877c478bd9Sstevel@tonic-gate 	ap->qop = qop_num;
1887c478bd9Sstevel@tonic-gate 	ap->target_name = target_name;
1897c478bd9Sstevel@tonic-gate 	ap->mech_type = mech_type;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/*
1927c478bd9Sstevel@tonic-gate 	 * Now invoke the real interface that sets up the context from
1937c478bd9Sstevel@tonic-gate 	 * the information stashed away in the private data.
1947c478bd9Sstevel@tonic-gate 	 */
1957c478bd9Sstevel@tonic-gate 	if (!rpc_gss_seccreate_pvt(&gssstat, &minor_stat, auth, ap,
1967c478bd9Sstevel@tonic-gate 				&mech_type, &ret_flags, &time_rec)) {
197*c5991125SMatt Barden 		if (options_ret != NULL) {
198*c5991125SMatt Barden 			options_ret->major_status = gssstat;
199*c5991125SMatt Barden 			options_ret->minor_status = minor_stat;
200*c5991125SMatt Barden 		}
2017c478bd9Sstevel@tonic-gate 		if (ap->target_name)
2027c478bd9Sstevel@tonic-gate 			(void) gss_release_name(&minor_stat, &ap->target_name);
2037c478bd9Sstevel@tonic-gate 		free((char *)ap);
2047c478bd9Sstevel@tonic-gate 		free((char *)auth);
2057c478bd9Sstevel@tonic-gate 		return (NULL);
2067c478bd9Sstevel@tonic-gate 	}
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	/*
2097c478bd9Sstevel@tonic-gate 	 * Make sure that the requested service is supported.  In all
2107c478bd9Sstevel@tonic-gate 	 * cases, integrity service must be available.
2117c478bd9Sstevel@tonic-gate 	 */
2127c478bd9Sstevel@tonic-gate 	if ((ap->service == rpc_gss_svc_privacy &&
2137c478bd9Sstevel@tonic-gate 					!(ret_flags & GSS_C_CONF_FLAG)) ||
2147c478bd9Sstevel@tonic-gate 			!(ret_flags & GSS_C_INTEG_FLAG)) {
2157c478bd9Sstevel@tonic-gate 		rpc_gss_destroy(auth);
2167c478bd9Sstevel@tonic-gate 		rpc_gss_err.rpc_gss_error = RPC_GSS_ER_SYSTEMERROR;
2177c478bd9Sstevel@tonic-gate 		rpc_gss_err.system_error = EPROTONOSUPPORT;
2187c478bd9Sstevel@tonic-gate 		return (NULL);
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	/*
2227c478bd9Sstevel@tonic-gate 	 * return option values if requested
2237c478bd9Sstevel@tonic-gate 	 */
2247c478bd9Sstevel@tonic-gate 	if (options_ret != NULL) {
2257c478bd9Sstevel@tonic-gate 		char	*s;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 		options_ret->major_status = gssstat;
2287c478bd9Sstevel@tonic-gate 		options_ret->minor_status = minor_stat;
2297c478bd9Sstevel@tonic-gate 		options_ret->rpcsec_version = ap->version;
2307c478bd9Sstevel@tonic-gate 		options_ret->ret_flags = ret_flags;
2317c478bd9Sstevel@tonic-gate 		options_ret->time_ret = time_rec;
2327c478bd9Sstevel@tonic-gate 		options_ret->gss_context = ap->context;
2337c478bd9Sstevel@tonic-gate 		if ((s = __rpc_gss_oid_to_mech(mech_type)) != NULL)
2347c478bd9Sstevel@tonic-gate 			strcpy(options_ret->actual_mechanism, s);
2357c478bd9Sstevel@tonic-gate 		else
2367c478bd9Sstevel@tonic-gate 			options_ret->actual_mechanism[0] = '\0';
2377c478bd9Sstevel@tonic-gate 	}
2387c478bd9Sstevel@tonic-gate 	return (auth);
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate /*
2427c478bd9Sstevel@tonic-gate  * Private interface to create a context.  This is the interface
2437c478bd9Sstevel@tonic-gate  * that's invoked when the context has to be refreshed.
2447c478bd9Sstevel@tonic-gate  */
2457c478bd9Sstevel@tonic-gate static bool_t
rpc_gss_seccreate_pvt(gssstat,minor_stat,auth,ap,actual_mech_type,ret_flags,time_rec)2467c478bd9Sstevel@tonic-gate rpc_gss_seccreate_pvt(gssstat, minor_stat, auth, ap, actual_mech_type,
2477c478bd9Sstevel@tonic-gate 						ret_flags, time_rec)
2487c478bd9Sstevel@tonic-gate 	OM_uint32		*gssstat;
2497c478bd9Sstevel@tonic-gate 	OM_uint32		*minor_stat;
2507c478bd9Sstevel@tonic-gate 	AUTH			*auth;
2517c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap;
2527c478bd9Sstevel@tonic-gate 	gss_OID			*actual_mech_type;
2537c478bd9Sstevel@tonic-gate 	OM_uint32		*ret_flags;
2547c478bd9Sstevel@tonic-gate 	OM_uint32		*time_rec;
2557c478bd9Sstevel@tonic-gate {
2567c478bd9Sstevel@tonic-gate 	CLIENT			*clnt = ap->clnt;
2577c478bd9Sstevel@tonic-gate 	AUTH			*save_auth;
2587c478bd9Sstevel@tonic-gate 	enum clnt_stat		callstat;
2597c478bd9Sstevel@tonic-gate 	rpc_gss_init_arg	call_arg;
2607c478bd9Sstevel@tonic-gate 	rpc_gss_init_res	call_res;
2617c478bd9Sstevel@tonic-gate 	gss_buffer_desc		*input_token_p, input_token;
2627c478bd9Sstevel@tonic-gate 	bool_t			free_results = FALSE;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	/*
2657c478bd9Sstevel@tonic-gate 	 * initialize error
2667c478bd9Sstevel@tonic-gate 	 */
2677c478bd9Sstevel@tonic-gate 	memset(&rpc_createerr, 0, sizeof (rpc_createerr));
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	/*
2707c478bd9Sstevel@tonic-gate 	 * (re)initialize AUTH handle and private data.
2717c478bd9Sstevel@tonic-gate 	 */
2727c478bd9Sstevel@tonic-gate 	memset((char *)auth, 0, sizeof (*auth));
2737c478bd9Sstevel@tonic-gate 	auth->ah_ops = &rpc_gss_ops;
2747c478bd9Sstevel@tonic-gate 	auth->ah_private = (caddr_t)ap;
2757c478bd9Sstevel@tonic-gate 	auth->ah_cred.oa_flavor = RPCSEC_GSS;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	ap->established = FALSE;
2787c478bd9Sstevel@tonic-gate 	ap->ctx_handle.length = 0;
2797c478bd9Sstevel@tonic-gate 	ap->ctx_handle.value = NULL;
2807c478bd9Sstevel@tonic-gate 	ap->context = GSS_C_NO_CONTEXT;
2817c478bd9Sstevel@tonic-gate 	ap->seq_num = 0;
2827c478bd9Sstevel@tonic-gate 	ap->gss_proc = RPCSEC_GSS_INIT;
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	/*
2857c478bd9Sstevel@tonic-gate 	 * should not change clnt->cl_auth at this time, so save
2867c478bd9Sstevel@tonic-gate 	 * old handle
2877c478bd9Sstevel@tonic-gate 	 */
2887c478bd9Sstevel@tonic-gate 	save_auth = clnt->cl_auth;
2897c478bd9Sstevel@tonic-gate 	clnt->cl_auth = auth;
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	/*
2927c478bd9Sstevel@tonic-gate 	 * set state for starting context setup
2937c478bd9Sstevel@tonic-gate 	 */
2947c478bd9Sstevel@tonic-gate 	input_token_p = GSS_C_NO_BUFFER;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate next_token:
2977c478bd9Sstevel@tonic-gate 	*gssstat = gss_init_sec_context(minor_stat,
2987c478bd9Sstevel@tonic-gate 					ap->my_cred,
2997c478bd9Sstevel@tonic-gate 					&ap->context,
3007c478bd9Sstevel@tonic-gate 					ap->target_name,
3017c478bd9Sstevel@tonic-gate 					ap->mech_type,
3027c478bd9Sstevel@tonic-gate 					ap->req_flags,
3037c478bd9Sstevel@tonic-gate 					ap->time_req,
3047c478bd9Sstevel@tonic-gate 					NULL,
3057c478bd9Sstevel@tonic-gate 					input_token_p,
3067c478bd9Sstevel@tonic-gate 					actual_mech_type,
3077c478bd9Sstevel@tonic-gate 					&call_arg,
3087c478bd9Sstevel@tonic-gate 					ret_flags,
3097c478bd9Sstevel@tonic-gate 					time_rec);
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	if (input_token_p != GSS_C_NO_BUFFER) {
3127c478bd9Sstevel@tonic-gate 		OM_uint32 minor_stat2;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 		(void) gss_release_buffer(&minor_stat2, input_token_p);
3157c478bd9Sstevel@tonic-gate 		input_token_p = GSS_C_NO_BUFFER;
3167c478bd9Sstevel@tonic-gate 	}
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 	if (*gssstat != GSS_S_COMPLETE && *gssstat != GSS_S_CONTINUE_NEEDED) {
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 		goto cleanup;
3217c478bd9Sstevel@tonic-gate 	}
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	/*
3247c478bd9Sstevel@tonic-gate 	 * if we got a token, pass it on
3257c478bd9Sstevel@tonic-gate 	 */
3267c478bd9Sstevel@tonic-gate 	if (call_arg.length != 0) {
3277c478bd9Sstevel@tonic-gate 		struct timeval timeout = {30, 0};
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 		memset((char *)&call_res, 0, sizeof (call_res));
3307c478bd9Sstevel@tonic-gate 		callstat = clnt_call(clnt, NULLPROC,
3317c478bd9Sstevel@tonic-gate 				__xdr_rpc_gss_init_arg, (caddr_t)&call_arg,
3327c478bd9Sstevel@tonic-gate 				__xdr_rpc_gss_init_res, (caddr_t)&call_res,
3337c478bd9Sstevel@tonic-gate 				timeout);
3347c478bd9Sstevel@tonic-gate 		(void) gss_release_buffer(minor_stat, &call_arg);
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 		if (callstat != RPC_SUCCESS) {
3377c478bd9Sstevel@tonic-gate 			goto cleanup;
3387c478bd9Sstevel@tonic-gate 		}
3397c478bd9Sstevel@tonic-gate 		/*
3407c478bd9Sstevel@tonic-gate 		 * we have results - note that these need to be freed
3417c478bd9Sstevel@tonic-gate 		 */
3427c478bd9Sstevel@tonic-gate 		free_results = TRUE;
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 		if (call_res.gss_major != GSS_S_COMPLETE &&
3457c478bd9Sstevel@tonic-gate 			call_res.gss_major != GSS_S_CONTINUE_NEEDED)
3467c478bd9Sstevel@tonic-gate 			goto cleanup;
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 		ap->gss_proc = RPCSEC_GSS_CONTINUE_INIT;
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 		/*
3517c478bd9Sstevel@tonic-gate 		 * check for ctx_handle
3527c478bd9Sstevel@tonic-gate 		 */
3537c478bd9Sstevel@tonic-gate 		if (ap->ctx_handle.length == 0) {
3547c478bd9Sstevel@tonic-gate 			if (call_res.ctx_handle.length == 0)
3557c478bd9Sstevel@tonic-gate 				goto cleanup;
3567c478bd9Sstevel@tonic-gate 			GSS_DUP_BUFFER(ap->ctx_handle,
3577c478bd9Sstevel@tonic-gate 				call_res.ctx_handle);
3587c478bd9Sstevel@tonic-gate 		} else if (!GSS_BUFFERS_EQUAL(ap->ctx_handle,
3597c478bd9Sstevel@tonic-gate 						call_res.ctx_handle))
3607c478bd9Sstevel@tonic-gate 			goto cleanup;
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 		/*
3637c478bd9Sstevel@tonic-gate 		 * check for token
3647c478bd9Sstevel@tonic-gate 		 */
3657c478bd9Sstevel@tonic-gate 		if (call_res.token.length != 0) {
3667c478bd9Sstevel@tonic-gate 			if (*gssstat == GSS_S_COMPLETE)
3677c478bd9Sstevel@tonic-gate 				goto cleanup;
3687c478bd9Sstevel@tonic-gate 			GSS_DUP_BUFFER(input_token, call_res.token);
3697c478bd9Sstevel@tonic-gate 			input_token_p = &input_token;
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 		} else if (*gssstat != GSS_S_COMPLETE)
3727c478bd9Sstevel@tonic-gate 			goto cleanup;
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 		/* save the sequence window value; validate later */
3757c478bd9Sstevel@tonic-gate 		ap->seq_window = call_res.seq_window;
3767c478bd9Sstevel@tonic-gate 		xdr_free(__xdr_rpc_gss_init_res, (caddr_t)&call_res);
3777c478bd9Sstevel@tonic-gate 		free_results = FALSE;
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	/*
3817c478bd9Sstevel@tonic-gate 	 * results were okay.. continue if necessary
3827c478bd9Sstevel@tonic-gate 	 */
3837c478bd9Sstevel@tonic-gate 	if (*gssstat == GSS_S_CONTINUE_NEEDED)
3847c478bd9Sstevel@tonic-gate 		goto next_token;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	/*
3877c478bd9Sstevel@tonic-gate 	 * Validate the sequence window - RFC 2203 section 5.2.3.1
3887c478bd9Sstevel@tonic-gate 	 */
3897c478bd9Sstevel@tonic-gate 	if (!validate_seqwin(ap)) {
3907c478bd9Sstevel@tonic-gate 		goto cleanup;
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	/*
3947c478bd9Sstevel@tonic-gate 	 * Done!  Security context creation is successful.
3957c478bd9Sstevel@tonic-gate 	 * Ready for exchanging data.
3967c478bd9Sstevel@tonic-gate 	 */
3977c478bd9Sstevel@tonic-gate 	ap->established = TRUE;
3987c478bd9Sstevel@tonic-gate 	ap->seq_num = 1;
3997c478bd9Sstevel@tonic-gate 	ap->gss_proc = RPCSEC_GSS_DATA;
4007c478bd9Sstevel@tonic-gate 	ap->invalid = FALSE;
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	clnt->cl_auth = save_auth;	/* restore cl_auth */
4037c478bd9Sstevel@tonic-gate 	return (TRUE);
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate cleanup:
4067c478bd9Sstevel@tonic-gate 	if (ap->context != GSS_C_NO_CONTEXT)
4077c478bd9Sstevel@tonic-gate 		rpc_gss_destroy_pvt(auth);
4087c478bd9Sstevel@tonic-gate 	if (free_results)
4097c478bd9Sstevel@tonic-gate 		xdr_free(__xdr_rpc_gss_init_res, (caddr_t)&call_res);
4107c478bd9Sstevel@tonic-gate 	clnt->cl_auth = save_auth;	/* restore cl_auth */
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate /*
4137c478bd9Sstevel@tonic-gate  *	if (rpc_createerr.cf_stat == 0)
4147c478bd9Sstevel@tonic-gate  *		rpc_createerr.cf_stat = RPC_AUTHERROR;
4157c478bd9Sstevel@tonic-gate  */
4167c478bd9Sstevel@tonic-gate 	if (rpc_createerr.cf_stat == 0) {
4177c478bd9Sstevel@tonic-gate 		rpc_gss_err.rpc_gss_error = RPC_GSS_ER_SYSTEMERROR;
4187c478bd9Sstevel@tonic-gate 		rpc_gss_err.system_error = RPC_AUTHERROR;
4197c478bd9Sstevel@tonic-gate 	}
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 	return (FALSE);
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate /*
4257c478bd9Sstevel@tonic-gate  * Set service defaults.
4267c478bd9Sstevel@tonic-gate  */
4277c478bd9Sstevel@tonic-gate bool_t
__rpc_gss_set_defaults(auth,service,qop)4287c478bd9Sstevel@tonic-gate __rpc_gss_set_defaults(auth, service, qop)
4297c478bd9Sstevel@tonic-gate 	AUTH			*auth;
4307c478bd9Sstevel@tonic-gate 	rpc_gss_service_t	service;
4317c478bd9Sstevel@tonic-gate 	char			*qop;
4327c478bd9Sstevel@tonic-gate {
4337c478bd9Sstevel@tonic-gate 	/*LINTED*/
4347c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap = AUTH_PRIVATE(auth);
4357c478bd9Sstevel@tonic-gate 	char			*mech;
4367c478bd9Sstevel@tonic-gate 	OM_uint32		qop_num;
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 	switch (service) {
4397c478bd9Sstevel@tonic-gate 	case rpc_gss_svc_integrity:
4407c478bd9Sstevel@tonic-gate 	case rpc_gss_svc_privacy:
4417c478bd9Sstevel@tonic-gate 	case rpc_gss_svc_none:
4427c478bd9Sstevel@tonic-gate 		break;
4437c478bd9Sstevel@tonic-gate 	case rpc_gss_svc_default:
4447c478bd9Sstevel@tonic-gate 		service = rpc_gss_svc_integrity;
4457c478bd9Sstevel@tonic-gate 		break;
4467c478bd9Sstevel@tonic-gate 	default:
4477c478bd9Sstevel@tonic-gate 		return (FALSE);
4487c478bd9Sstevel@tonic-gate 	}
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	if ((mech = __rpc_gss_oid_to_mech(ap->mech_type)) == NULL)
4517c478bd9Sstevel@tonic-gate 		return (FALSE);
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	if (!__rpc_gss_qop_to_num(qop, mech, &qop_num))
4547c478bd9Sstevel@tonic-gate 		return (FALSE);
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	ap->qop = qop_num;
4577c478bd9Sstevel@tonic-gate 	ap->service = service;
4587c478bd9Sstevel@tonic-gate 	return (TRUE);
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate /*
4627c478bd9Sstevel@tonic-gate  * Marshall credentials.
4637c478bd9Sstevel@tonic-gate  */
4647c478bd9Sstevel@tonic-gate static bool_t
marshall_creds(ap,xdrs)4657c478bd9Sstevel@tonic-gate marshall_creds(ap, xdrs)
4667c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap;
4677c478bd9Sstevel@tonic-gate 	XDR			*xdrs;
4687c478bd9Sstevel@tonic-gate {
4697c478bd9Sstevel@tonic-gate 	rpc_gss_creds		ag_creds;
4707c478bd9Sstevel@tonic-gate 	char			cred_buf[MAX_AUTH_BYTES];
4717c478bd9Sstevel@tonic-gate 	struct opaque_auth	creds;
4727c478bd9Sstevel@tonic-gate 	XDR			cred_xdrs;
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	ag_creds.version = ap->version;
4757c478bd9Sstevel@tonic-gate 	ag_creds.gss_proc = ap->gss_proc;
4767c478bd9Sstevel@tonic-gate 	ag_creds.seq_num = ap->seq_num;
4777c478bd9Sstevel@tonic-gate 	ag_creds.service = ap->service;
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	/*
4807c478bd9Sstevel@tonic-gate 	 * If context has not been set up yet, use NULL handle.
4817c478bd9Sstevel@tonic-gate 	 */
4827c478bd9Sstevel@tonic-gate 	if (ap->ctx_handle.length > 0)
4837c478bd9Sstevel@tonic-gate 		ag_creds.ctx_handle = ap->ctx_handle;
4847c478bd9Sstevel@tonic-gate 	else {
4857c478bd9Sstevel@tonic-gate 		ag_creds.ctx_handle.length = 0;
4867c478bd9Sstevel@tonic-gate 		ag_creds.ctx_handle.value = NULL;
4877c478bd9Sstevel@tonic-gate 	}
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	xdrmem_create(&cred_xdrs, (caddr_t)cred_buf, MAX_AUTH_BYTES,
4907c478bd9Sstevel@tonic-gate 								XDR_ENCODE);
4917c478bd9Sstevel@tonic-gate 	if (!__xdr_rpc_gss_creds(&cred_xdrs, &ag_creds)) {
4927c478bd9Sstevel@tonic-gate 		XDR_DESTROY(&cred_xdrs);
4937c478bd9Sstevel@tonic-gate 		return (FALSE);
4947c478bd9Sstevel@tonic-gate 	}
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	creds.oa_flavor = RPCSEC_GSS;
4977c478bd9Sstevel@tonic-gate 	creds.oa_base = cred_buf;
4987c478bd9Sstevel@tonic-gate 	creds.oa_length = xdr_getpos(&cred_xdrs);
4997c478bd9Sstevel@tonic-gate 	XDR_DESTROY(&cred_xdrs);
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	if (!xdr_opaque_auth(xdrs, &creds))
5027c478bd9Sstevel@tonic-gate 		return (FALSE);
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 	return (TRUE);
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate  * Marshall verifier.  The verifier is the checksum of the RPC header
5097c478bd9Sstevel@tonic-gate  * up to and including the credential field.  The XDR handle that's
5107c478bd9Sstevel@tonic-gate  * passed in has the header up to and including the credential field
5117c478bd9Sstevel@tonic-gate  * encoded.  A pointer to the transmit buffer is also passed in.
5127c478bd9Sstevel@tonic-gate  */
5137c478bd9Sstevel@tonic-gate static bool_t
marshall_verf(ap,xdrs,buf)5147c478bd9Sstevel@tonic-gate marshall_verf(ap, xdrs, buf)
5157c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap;
5167c478bd9Sstevel@tonic-gate 	XDR			*xdrs;	/* send XDR */
5177c478bd9Sstevel@tonic-gate 	char			*buf;	/* pointer of send buffer */
5187c478bd9Sstevel@tonic-gate {
5197c478bd9Sstevel@tonic-gate 	struct opaque_auth	verf;
5207c478bd9Sstevel@tonic-gate 	OM_uint32		major, minor;
5217c478bd9Sstevel@tonic-gate 	gss_buffer_desc		in_buf, out_buf;
5227c478bd9Sstevel@tonic-gate 	bool_t			ret = FALSE;
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 	/*
5257c478bd9Sstevel@tonic-gate 	 * If context is not established yet, use NULL verifier.
5267c478bd9Sstevel@tonic-gate 	 */
5277c478bd9Sstevel@tonic-gate 	if (!ap->established) {
5287c478bd9Sstevel@tonic-gate 		verf.oa_flavor = AUTH_NONE;
5297c478bd9Sstevel@tonic-gate 		verf.oa_base = NULL;
5307c478bd9Sstevel@tonic-gate 		verf.oa_length = 0;
5317c478bd9Sstevel@tonic-gate 		return (xdr_opaque_auth(xdrs, &verf));
5327c478bd9Sstevel@tonic-gate 	}
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	verf.oa_flavor = RPCSEC_GSS;
5357c478bd9Sstevel@tonic-gate 	in_buf.length = xdr_getpos(xdrs);
5367c478bd9Sstevel@tonic-gate 	in_buf.value = buf;
5377c478bd9Sstevel@tonic-gate 	if ((major = gss_sign(&minor, ap->context, ap->qop, &in_buf,
5387c478bd9Sstevel@tonic-gate 					&out_buf)) != GSS_S_COMPLETE) {
5397c478bd9Sstevel@tonic-gate 		if (major == GSS_S_CONTEXT_EXPIRED) {
5407c478bd9Sstevel@tonic-gate 			ap->invalid = TRUE;
5417c478bd9Sstevel@tonic-gate 		}
5427c478bd9Sstevel@tonic-gate 		return (FALSE);
5437c478bd9Sstevel@tonic-gate 	}
5447c478bd9Sstevel@tonic-gate 	verf.oa_base = out_buf.value;
5457c478bd9Sstevel@tonic-gate 	verf.oa_length = out_buf.length;
5467c478bd9Sstevel@tonic-gate 	ret = xdr_opaque_auth(xdrs, &verf);
5477c478bd9Sstevel@tonic-gate 	(void) gss_release_buffer(&minor, &out_buf);
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	return (ret);
5507c478bd9Sstevel@tonic-gate }
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate /*
5537c478bd9Sstevel@tonic-gate  * Function: rpc_gss_nextverf.  Not used.
5547c478bd9Sstevel@tonic-gate  */
5557c478bd9Sstevel@tonic-gate static void
rpc_gss_nextverf()5567c478bd9Sstevel@tonic-gate rpc_gss_nextverf()
5577c478bd9Sstevel@tonic-gate {
5587c478bd9Sstevel@tonic-gate }
5597c478bd9Sstevel@tonic-gate 
5607c478bd9Sstevel@tonic-gate /*
5617c478bd9Sstevel@tonic-gate  * Function: rpc_gss_marshall - not used.
5627c478bd9Sstevel@tonic-gate  */
5637c478bd9Sstevel@tonic-gate static bool_t
rpc_gss_marshall(auth,xdrs)5647c478bd9Sstevel@tonic-gate rpc_gss_marshall(auth, xdrs)
5657c478bd9Sstevel@tonic-gate 	AUTH		*auth;
5667c478bd9Sstevel@tonic-gate 	XDR		*xdrs;
5677c478bd9Sstevel@tonic-gate {
5687c478bd9Sstevel@tonic-gate 	if (!xdr_opaque_auth(xdrs, &auth->ah_cred) ||
5697c478bd9Sstevel@tonic-gate 				!xdr_opaque_auth(xdrs, &auth->ah_verf))
5707c478bd9Sstevel@tonic-gate 		return (FALSE);
5717c478bd9Sstevel@tonic-gate 	return (TRUE);
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate /*
5757c478bd9Sstevel@tonic-gate  * Validate sequence window upon a successful RPCSEC_GSS INIT session.
5767c478bd9Sstevel@tonic-gate  * The sequence window sent back by the server should be verifiable by
5777c478bd9Sstevel@tonic-gate  * the verifier which is a checksum of the sequence window.
5787c478bd9Sstevel@tonic-gate  */
5797c478bd9Sstevel@tonic-gate static bool_t
validate_seqwin(rpc_gss_data * ap)5807c478bd9Sstevel@tonic-gate validate_seqwin(rpc_gss_data *ap)
5817c478bd9Sstevel@tonic-gate {
5827c478bd9Sstevel@tonic-gate 	uint_t			seq_win_net;
5837c478bd9Sstevel@tonic-gate 	OM_uint32		major = 0, minor = 0;
5847c478bd9Sstevel@tonic-gate 	gss_buffer_desc		msg_buf, tok_buf;
5857c478bd9Sstevel@tonic-gate 	int			qop_state = 0;
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate 	seq_win_net = (uint_t)htonl(ap->seq_window);
5887c478bd9Sstevel@tonic-gate 	msg_buf.length = sizeof (seq_win_net);
5897c478bd9Sstevel@tonic-gate 	msg_buf.value = (char *)&seq_win_net;
5907c478bd9Sstevel@tonic-gate 	tok_buf.length = ap->verifier->oa_length;
5917c478bd9Sstevel@tonic-gate 	tok_buf.value = ap->verifier->oa_base;
5927c478bd9Sstevel@tonic-gate 	major = gss_verify(&minor, ap->context, &msg_buf, &tok_buf, &qop_state);
5937c478bd9Sstevel@tonic-gate 	if (major != GSS_S_COMPLETE)
5947257d1b4Sraf 		return (FALSE);
5957c478bd9Sstevel@tonic-gate 	return (TRUE);
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate /*
5997c478bd9Sstevel@tonic-gate  * Validate RPC response verifier from server.  The response verifier
6007c478bd9Sstevel@tonic-gate  * is the checksum of the request sequence number.
6017c478bd9Sstevel@tonic-gate  */
6027c478bd9Sstevel@tonic-gate static bool_t
rpc_gss_validate(auth,verf)6037c478bd9Sstevel@tonic-gate rpc_gss_validate(auth, verf)
6047c478bd9Sstevel@tonic-gate 	AUTH			*auth;
6057c478bd9Sstevel@tonic-gate 	struct opaque_auth	*verf;
6067c478bd9Sstevel@tonic-gate {
6077c478bd9Sstevel@tonic-gate 	/*LINTED*/
6087c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap = AUTH_PRIVATE(auth);
6097c478bd9Sstevel@tonic-gate 	uint_t			seq_num_net;
6107c478bd9Sstevel@tonic-gate 	OM_uint32		major, minor;
6117c478bd9Sstevel@tonic-gate 	gss_buffer_desc		msg_buf, tok_buf;
6127c478bd9Sstevel@tonic-gate 	int			qop_state;
6137c478bd9Sstevel@tonic-gate 
6147c478bd9Sstevel@tonic-gate 	/*
6157c478bd9Sstevel@tonic-gate 	 * If context is not established yet, save the verifier for
6167c478bd9Sstevel@tonic-gate 	 * validating the sequence window later at the end of context
6177c478bd9Sstevel@tonic-gate 	 * creation session.
6187c478bd9Sstevel@tonic-gate 	 */
6197c478bd9Sstevel@tonic-gate 	if (!ap->established) {
6207c478bd9Sstevel@tonic-gate 	    if (ap->verifier == NULL) {
6217c478bd9Sstevel@tonic-gate 		ap->verifier = malloc(sizeof (struct opaque_auth));
6227c478bd9Sstevel@tonic-gate 		memset(ap->verifier, 0, sizeof (struct opaque_auth));
6237c478bd9Sstevel@tonic-gate 		if (verf->oa_length > 0)
6247c478bd9Sstevel@tonic-gate 		    ap->verifier->oa_base = malloc(verf->oa_length);
6257c478bd9Sstevel@tonic-gate 	    } else {
6267c478bd9Sstevel@tonic-gate 		if (ap->verifier->oa_length > 0)
6277c478bd9Sstevel@tonic-gate 		    free(ap->verifier->oa_base);
6287c478bd9Sstevel@tonic-gate 		if (verf->oa_length > 0)
6297c478bd9Sstevel@tonic-gate 		    ap->verifier->oa_base = malloc(verf->oa_length);
6307c478bd9Sstevel@tonic-gate 	    }
6317c478bd9Sstevel@tonic-gate 	    ap->verifier->oa_length = verf->oa_length;
6327c478bd9Sstevel@tonic-gate 	    bcopy(verf->oa_base, ap->verifier->oa_base, verf->oa_length);
6337c478bd9Sstevel@tonic-gate 	    return (TRUE);
6347c478bd9Sstevel@tonic-gate 	}
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate 	seq_num_net = (uint_t)htonl(ap->seq_num);
6377c478bd9Sstevel@tonic-gate 	msg_buf.length = sizeof (seq_num_net);
6387c478bd9Sstevel@tonic-gate 	msg_buf.value = (char *)&seq_num_net;
6397c478bd9Sstevel@tonic-gate 	tok_buf.length = verf->oa_length;
6407c478bd9Sstevel@tonic-gate 	tok_buf.value = verf->oa_base;
6417c478bd9Sstevel@tonic-gate 	major = gss_verify(&minor, ap->context, &msg_buf, &tok_buf, &qop_state);
6427c478bd9Sstevel@tonic-gate 	if (major != GSS_S_COMPLETE)
6437c478bd9Sstevel@tonic-gate 		return (FALSE);
6447c478bd9Sstevel@tonic-gate 	return (TRUE);
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate /*
6487c478bd9Sstevel@tonic-gate  * Refresh client context.  This is necessary sometimes because the
6497c478bd9Sstevel@tonic-gate  * server will ocassionally destroy contexts based on LRU method, or
6507c478bd9Sstevel@tonic-gate  * because of expired credentials.
6517c478bd9Sstevel@tonic-gate  */
6527c478bd9Sstevel@tonic-gate static bool_t
rpc_gss_refresh(auth,msg)6537c478bd9Sstevel@tonic-gate rpc_gss_refresh(auth, msg)
6547c478bd9Sstevel@tonic-gate 	AUTH		*auth;
6557c478bd9Sstevel@tonic-gate 	struct rpc_msg	*msg;
6567c478bd9Sstevel@tonic-gate {
6577c478bd9Sstevel@tonic-gate 	/*LINTED*/
6587c478bd9Sstevel@tonic-gate 	rpc_gss_data	*ap = AUTH_PRIVATE(auth);
6597c478bd9Sstevel@tonic-gate 	OM_uint32	gssstat, minor_stat;
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate 	/*
6627c478bd9Sstevel@tonic-gate 	 * The context needs to be recreated only when the error status
6637c478bd9Sstevel@tonic-gate 	 * returned from the server is one of the following:
6647c478bd9Sstevel@tonic-gate 	 *	RPCSEC_GSS_NOCRED and RPCSEC_GSS_FAILED
6657c478bd9Sstevel@tonic-gate 	 * The existing context should not be destroyed unless the above
6667c478bd9Sstevel@tonic-gate 	 * error status codes are received or if the context has not
6677c478bd9Sstevel@tonic-gate 	 * been set up.
6687c478bd9Sstevel@tonic-gate 	 */
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 	if (msg->rjcted_rply.rj_why == RPCSEC_GSS_NOCRED ||
6717c478bd9Sstevel@tonic-gate 			msg->rjcted_rply.rj_why == RPCSEC_GSS_FAILED ||
6727c478bd9Sstevel@tonic-gate 							!ap->established) {
6737c478bd9Sstevel@tonic-gate 		/*
6747c478bd9Sstevel@tonic-gate 		 * Destroy the context if necessary.  Use the same memory
6757c478bd9Sstevel@tonic-gate 		 * for the new context since we've already passed a pointer
6767c478bd9Sstevel@tonic-gate 		 * to it to the user.
6777c478bd9Sstevel@tonic-gate 		 */
6787c478bd9Sstevel@tonic-gate 		if (ap->context != GSS_C_NO_CONTEXT) {
6797c478bd9Sstevel@tonic-gate 			(void) gss_delete_sec_context(&minor_stat, &ap->context,
6807c478bd9Sstevel@tonic-gate 								NULL);
6817c478bd9Sstevel@tonic-gate 			ap->context = GSS_C_NO_CONTEXT;
6827c478bd9Sstevel@tonic-gate 		}
6837c478bd9Sstevel@tonic-gate 		if (ap->ctx_handle.length != 0) {
6847c478bd9Sstevel@tonic-gate 			(void) gss_release_buffer(&minor_stat,
6857c478bd9Sstevel@tonic-gate 							&ap->ctx_handle);
6867c478bd9Sstevel@tonic-gate 			ap->ctx_handle.length = 0;
6877c478bd9Sstevel@tonic-gate 			ap->ctx_handle.value = NULL;
6887c478bd9Sstevel@tonic-gate 		}
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 		/*
6917c478bd9Sstevel@tonic-gate 		 * If the context was not already established, don't try to
6927c478bd9Sstevel@tonic-gate 		 * recreate it.
6937c478bd9Sstevel@tonic-gate 		 */
6947c478bd9Sstevel@tonic-gate 		if (!ap->established) {
6957c478bd9Sstevel@tonic-gate 			ap->invalid = TRUE;
6967c478bd9Sstevel@tonic-gate 			return (FALSE);
6977c478bd9Sstevel@tonic-gate 		}
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate 		/*
7007c478bd9Sstevel@tonic-gate 		 * Recreate context.
7017c478bd9Sstevel@tonic-gate 		 */
7027c478bd9Sstevel@tonic-gate 		if (rpc_gss_seccreate_pvt(&gssstat, &minor_stat, auth, ap,
7037c478bd9Sstevel@tonic-gate 		    (gss_OID *)0, (OM_uint32 *)0, (OM_uint32 *)0))
7047c478bd9Sstevel@tonic-gate 			return (TRUE);
7057c478bd9Sstevel@tonic-gate 		else {
7067c478bd9Sstevel@tonic-gate 			ap->invalid = TRUE;
7077c478bd9Sstevel@tonic-gate 			return (FALSE);
7087c478bd9Sstevel@tonic-gate 		}
7097c478bd9Sstevel@tonic-gate 	}
7107c478bd9Sstevel@tonic-gate 	return (FALSE);
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate /*
7147c478bd9Sstevel@tonic-gate  * Destroy a context.
7157c478bd9Sstevel@tonic-gate  */
7167c478bd9Sstevel@tonic-gate static void
rpc_gss_destroy(auth)7177c478bd9Sstevel@tonic-gate rpc_gss_destroy(auth)
7187c478bd9Sstevel@tonic-gate 	AUTH		*auth;
7197c478bd9Sstevel@tonic-gate {
7207c478bd9Sstevel@tonic-gate 	/*LINTED*/
7217c478bd9Sstevel@tonic-gate 	rpc_gss_data	*ap = AUTH_PRIVATE(auth);
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	rpc_gss_destroy_pvt(auth);
7247c478bd9Sstevel@tonic-gate 	free((char *)ap);
7257c478bd9Sstevel@tonic-gate 	free(auth);
7267c478bd9Sstevel@tonic-gate }
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate /*
7297c478bd9Sstevel@tonic-gate  * Private interface to destroy a context without freeing up
7307c478bd9Sstevel@tonic-gate  * the memory used by it.  We need to do this when a refresh
7317c478bd9Sstevel@tonic-gate  * fails, for example, so the user will still have a handle.
7327c478bd9Sstevel@tonic-gate  */
7337c478bd9Sstevel@tonic-gate static void
rpc_gss_destroy_pvt(auth)7347c478bd9Sstevel@tonic-gate rpc_gss_destroy_pvt(auth)
7357c478bd9Sstevel@tonic-gate 	AUTH		*auth;
7367c478bd9Sstevel@tonic-gate {
7377c478bd9Sstevel@tonic-gate 	struct timeval	timeout;
7387c478bd9Sstevel@tonic-gate 	OM_uint32	minor_stat;
7397c478bd9Sstevel@tonic-gate 	/*LINTED*/
7407c478bd9Sstevel@tonic-gate 	rpc_gss_data	*ap = AUTH_PRIVATE(auth);
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 	/*
7437c478bd9Sstevel@tonic-gate 	 * If we have a server context id, inform server that we are
7447c478bd9Sstevel@tonic-gate 	 * destroying the context.
7457c478bd9Sstevel@tonic-gate 	 */
7467c478bd9Sstevel@tonic-gate 	if (ap->ctx_handle.length != 0) {
7477c478bd9Sstevel@tonic-gate 		ap->gss_proc = RPCSEC_GSS_DESTROY;
7487c478bd9Sstevel@tonic-gate 		timeout.tv_sec = 1;
7497c478bd9Sstevel@tonic-gate 		timeout.tv_usec = 0;
7507c478bd9Sstevel@tonic-gate 		(void) clnt_call(ap->clnt, NULLPROC, xdr_void, NULL,
7517c478bd9Sstevel@tonic-gate 						xdr_void, NULL, timeout);
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 		(void) gss_release_buffer(&minor_stat, &ap->ctx_handle);
7547c478bd9Sstevel@tonic-gate 		ap->ctx_handle.length = 0;
7557c478bd9Sstevel@tonic-gate 		ap->ctx_handle.value = NULL;
7567c478bd9Sstevel@tonic-gate 	}
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 	/*
7597c478bd9Sstevel@tonic-gate 	 * Destroy local GSS context.
7607c478bd9Sstevel@tonic-gate 	 */
7617c478bd9Sstevel@tonic-gate 	if (ap->context != GSS_C_NO_CONTEXT) {
7627c478bd9Sstevel@tonic-gate 		(void) gss_delete_sec_context(&minor_stat, &ap->context, NULL);
7637c478bd9Sstevel@tonic-gate 		ap->context = GSS_C_NO_CONTEXT;
7647c478bd9Sstevel@tonic-gate 	}
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 	/*
7677c478bd9Sstevel@tonic-gate 	 * Looks like we need to release default credentials if we use it.
7687c478bd9Sstevel@tonic-gate 	 * Non-default creds need to be released by user.
7697c478bd9Sstevel@tonic-gate 	 */
7707c478bd9Sstevel@tonic-gate 	if (ap->my_cred == GSS_C_NO_CREDENTIAL)
7717c478bd9Sstevel@tonic-gate 		(void) gss_release_cred(&minor_stat, &ap->my_cred);
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate 	/*
7747c478bd9Sstevel@tonic-gate 	 * Release any internal name structures.
7757c478bd9Sstevel@tonic-gate 	 */
7767c478bd9Sstevel@tonic-gate 	if (ap->target_name != NULL) {
7777c478bd9Sstevel@tonic-gate 		(void) gss_release_name(&minor_stat, &ap->target_name);
7787c478bd9Sstevel@tonic-gate 		ap->target_name = NULL;
7797c478bd9Sstevel@tonic-gate 	}
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 	/*
7827c478bd9Sstevel@tonic-gate 	 * Free the verifier saved for sequence window checking.
7837c478bd9Sstevel@tonic-gate 	 */
7847c478bd9Sstevel@tonic-gate 	if (ap->verifier != NULL) {
7857c478bd9Sstevel@tonic-gate 	    if (ap->verifier->oa_length > 0)
7867c478bd9Sstevel@tonic-gate 		free(ap->verifier->oa_base);
7877c478bd9Sstevel@tonic-gate 	    free(ap->verifier);
7887c478bd9Sstevel@tonic-gate 	    ap->verifier = NULL;
7897c478bd9Sstevel@tonic-gate 	}
7907c478bd9Sstevel@tonic-gate }
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate /*
7937c478bd9Sstevel@tonic-gate  * Wrap client side data.  The encoded header is passed in through
7947c478bd9Sstevel@tonic-gate  * buf and buflen.  The header is up to but not including the
7957c478bd9Sstevel@tonic-gate  * credential field.
7967c478bd9Sstevel@tonic-gate  */
7977c478bd9Sstevel@tonic-gate bool_t
__rpc_gss_wrap(auth,buf,buflen,out_xdrs,xdr_func,xdr_ptr)7987c478bd9Sstevel@tonic-gate __rpc_gss_wrap(auth, buf, buflen, out_xdrs, xdr_func, xdr_ptr)
7997c478bd9Sstevel@tonic-gate 	AUTH			*auth;
8007c478bd9Sstevel@tonic-gate 	char			*buf;		/* encoded header */
8017c478bd9Sstevel@tonic-gate 	uint_t			buflen;		/* encoded header length */
8027c478bd9Sstevel@tonic-gate 	XDR			*out_xdrs;
8037c478bd9Sstevel@tonic-gate 	bool_t			(*xdr_func)();
8047c478bd9Sstevel@tonic-gate 	caddr_t			xdr_ptr;
8057c478bd9Sstevel@tonic-gate {
8067c478bd9Sstevel@tonic-gate 	/*LINTED*/
8077c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap = AUTH_PRIVATE(auth);
8087c478bd9Sstevel@tonic-gate 	XDR			xdrs;
8097c478bd9Sstevel@tonic-gate 	char			tmp_buf[512];
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate 	/*
8137c478bd9Sstevel@tonic-gate 	 * Reject an invalid context.
8147c478bd9Sstevel@tonic-gate 	 */
8157c478bd9Sstevel@tonic-gate 	if (ap->invalid)
8167c478bd9Sstevel@tonic-gate 		return (FALSE);
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate 	/*
8197c478bd9Sstevel@tonic-gate 	 * If context is established, bump up sequence number.
8207c478bd9Sstevel@tonic-gate 	 */
8217c478bd9Sstevel@tonic-gate 	if (ap->established)
8227c478bd9Sstevel@tonic-gate 		ap->seq_num++;
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate 	/*
8257c478bd9Sstevel@tonic-gate 	 * Create the header in a temporary XDR context and buffer
8267c478bd9Sstevel@tonic-gate 	 * before putting it out.
8277c478bd9Sstevel@tonic-gate 	 */
8287c478bd9Sstevel@tonic-gate 	xdrmem_create(&xdrs, tmp_buf, sizeof (tmp_buf), XDR_ENCODE);
8297c478bd9Sstevel@tonic-gate 	if (!XDR_PUTBYTES(&xdrs, buf, buflen))
8307c478bd9Sstevel@tonic-gate 		return (FALSE);
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate 	/*
8337c478bd9Sstevel@tonic-gate 	 * create cred field
8347c478bd9Sstevel@tonic-gate 	 */
8357c478bd9Sstevel@tonic-gate 	if (!marshall_creds(ap, &xdrs))
8367c478bd9Sstevel@tonic-gate 		return (FALSE);
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate 	/*
8397c478bd9Sstevel@tonic-gate 	 * create verifier
8407c478bd9Sstevel@tonic-gate 	 */
8417c478bd9Sstevel@tonic-gate 	if (!marshall_verf(ap, &xdrs, tmp_buf))
8427c478bd9Sstevel@tonic-gate 		return (FALSE);
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 	/*
8457c478bd9Sstevel@tonic-gate 	 * write out header and destroy temp structures
8467c478bd9Sstevel@tonic-gate 	 */
8477c478bd9Sstevel@tonic-gate 	if (!XDR_PUTBYTES(out_xdrs, tmp_buf, XDR_GETPOS(&xdrs)))
8487c478bd9Sstevel@tonic-gate 		return (FALSE);
8497c478bd9Sstevel@tonic-gate 	XDR_DESTROY(&xdrs);
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 	/*
8527c478bd9Sstevel@tonic-gate 	 * If context is not established, or if neither integrity
8537c478bd9Sstevel@tonic-gate 	 * nor privacy is used, just XDR encode data.
8547c478bd9Sstevel@tonic-gate 	 */
8557c478bd9Sstevel@tonic-gate 	if (!ap->established || ap->service == rpc_gss_svc_none)
8567c478bd9Sstevel@tonic-gate 		return ((*xdr_func)(out_xdrs, xdr_ptr));
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 	return (__rpc_gss_wrap_data(ap->service, ap->qop, ap->context,
8597c478bd9Sstevel@tonic-gate 				ap->seq_num, out_xdrs, xdr_func, xdr_ptr));
8607c478bd9Sstevel@tonic-gate }
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate /*
8637c478bd9Sstevel@tonic-gate  * Unwrap received data.
8647c478bd9Sstevel@tonic-gate  */
8657c478bd9Sstevel@tonic-gate bool_t
__rpc_gss_unwrap(auth,in_xdrs,xdr_func,xdr_ptr)8667c478bd9Sstevel@tonic-gate __rpc_gss_unwrap(auth, in_xdrs, xdr_func, xdr_ptr)
8677c478bd9Sstevel@tonic-gate 	AUTH			*auth;
8687c478bd9Sstevel@tonic-gate 	XDR			*in_xdrs;
8697c478bd9Sstevel@tonic-gate 	bool_t			(*xdr_func)();
8707c478bd9Sstevel@tonic-gate 	caddr_t			xdr_ptr;
8717c478bd9Sstevel@tonic-gate {
8727c478bd9Sstevel@tonic-gate 	/*LINTED*/
8737c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap = AUTH_PRIVATE(auth);
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 	/*
8767c478bd9Sstevel@tonic-gate 	 * If context is not established, of if neither integrity
8777c478bd9Sstevel@tonic-gate 	 * nor privacy is used, just XDR encode data.
8787c478bd9Sstevel@tonic-gate 	 */
8797c478bd9Sstevel@tonic-gate 	if (!ap->established || ap->service == rpc_gss_svc_none)
8807c478bd9Sstevel@tonic-gate 		return ((*xdr_func)(in_xdrs, xdr_ptr));
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate 	return (__rpc_gss_unwrap_data(ap->service,
8837c478bd9Sstevel@tonic-gate 				ap->context,
8847c478bd9Sstevel@tonic-gate 				ap->seq_num,
8857c478bd9Sstevel@tonic-gate 				ap->qop,
8867c478bd9Sstevel@tonic-gate 				in_xdrs, xdr_func, xdr_ptr));
8877c478bd9Sstevel@tonic-gate }
8887c478bd9Sstevel@tonic-gate 
8897c478bd9Sstevel@tonic-gate int
__rpc_gss_max_data_length(auth,max_tp_unit_len)8907c478bd9Sstevel@tonic-gate __rpc_gss_max_data_length(auth, max_tp_unit_len)
8917c478bd9Sstevel@tonic-gate 	AUTH		*auth;
8927c478bd9Sstevel@tonic-gate 	int		max_tp_unit_len;
8937c478bd9Sstevel@tonic-gate {
8947c478bd9Sstevel@tonic-gate 	/*LINTED*/
8957c478bd9Sstevel@tonic-gate 	rpc_gss_data		*ap = AUTH_PRIVATE(auth);
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 	if (!ap->established || max_tp_unit_len <= 0)
8987c478bd9Sstevel@tonic-gate 		return (0);
8997c478bd9Sstevel@tonic-gate 
9007c478bd9Sstevel@tonic-gate 	return (__find_max_data_length(ap->service,
9017c478bd9Sstevel@tonic-gate 			ap->context,
9027c478bd9Sstevel@tonic-gate 			ap->qop,
9037c478bd9Sstevel@tonic-gate 			max_tp_unit_len));
9047c478bd9Sstevel@tonic-gate }
9057c478bd9Sstevel@tonic-gate 
906cb620785Sraf void
__rpc_gss_get_error(rpc_gss_error_t * error)907cb620785Sraf __rpc_gss_get_error(rpc_gss_error_t *error)
908cb620785Sraf {
909cb620785Sraf 	*error = rpc_gss_err;
910cb620785Sraf }
911cb620785Sraf 
9127c478bd9Sstevel@tonic-gate #undef  rpc_gss_err
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate rpc_gss_error_t	rpc_gss_err;
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate rpc_gss_error_t *
__rpc_gss_err()9177c478bd9Sstevel@tonic-gate __rpc_gss_err()
9187c478bd9Sstevel@tonic-gate {
919cb620785Sraf 	static thread_key_t rpc_gss_err_key = THR_ONCE_KEY;
920cb620785Sraf 	rpc_gss_error_t *tsd;
9217c478bd9Sstevel@tonic-gate 
9227257d1b4Sraf 	if (thr_main())
9237c478bd9Sstevel@tonic-gate 		return (&rpc_gss_err);
9247257d1b4Sraf 	if (thr_keycreate_once(&rpc_gss_err_key, free) != 0)
925cb620785Sraf 		return (&rpc_gss_err);
9267257d1b4Sraf 	tsd = pthread_getspecific(rpc_gss_err_key);
927cb620785Sraf 	if (tsd == NULL) {
928cb620785Sraf 		tsd = (rpc_gss_error_t *)calloc(1, sizeof (rpc_gss_error_t));
9297257d1b4Sraf 		if (thr_setspecific(rpc_gss_err_key, tsd) != 0) {
9307c478bd9Sstevel@tonic-gate 			if (tsd)
9317c478bd9Sstevel@tonic-gate 				free(tsd);
9327c478bd9Sstevel@tonic-gate 			return (&rpc_gss_err);
9337c478bd9Sstevel@tonic-gate 		}
9347c478bd9Sstevel@tonic-gate 	}
9357c478bd9Sstevel@tonic-gate 	return (tsd);
9367c478bd9Sstevel@tonic-gate }
937