10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 53864Sraf * Common Development and Distribution License (the "License"). 63864Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 213864Sraf 220Sstevel@tonic-gate /* 23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 243864Sraf * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved. 290Sstevel@tonic-gate * 300Sstevel@tonic-gate * $Header: 310Sstevel@tonic-gate * /afs/gza.com/product/secure/rel-eng/src/1.1/rpc/RCS/auth_gssapi.c,v 320Sstevel@tonic-gate * 1.14 1995/03/22 22:07:55 jik Exp $ 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 35*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI" 36*6812Sraf 370Sstevel@tonic-gate #include <stdio.h> 380Sstevel@tonic-gate #include <stdlib.h> 390Sstevel@tonic-gate #include <strings.h> 400Sstevel@tonic-gate #include <errno.h> 410Sstevel@tonic-gate #include <pthread.h> 420Sstevel@tonic-gate #include <thread.h> 430Sstevel@tonic-gate #include <syslog.h> 440Sstevel@tonic-gate #include <gssapi/gssapi.h> 450Sstevel@tonic-gate #include <rpc/rpc.h> 460Sstevel@tonic-gate #include <rpc/rpcsec_defs.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate static void rpc_gss_nextverf(); 490Sstevel@tonic-gate static bool_t rpc_gss_marshall(); 500Sstevel@tonic-gate static bool_t rpc_gss_validate(); 510Sstevel@tonic-gate static bool_t rpc_gss_refresh(); 520Sstevel@tonic-gate static void rpc_gss_destroy(); 530Sstevel@tonic-gate static void rpc_gss_destroy_pvt(); 540Sstevel@tonic-gate static bool_t rpc_gss_seccreate_pvt(); 550Sstevel@tonic-gate static bool_t validate_seqwin(); 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * Globals that should have header files but don't. 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); 610Sstevel@tonic-gate 620Sstevel@tonic-gate 630Sstevel@tonic-gate static struct auth_ops rpc_gss_ops = { 640Sstevel@tonic-gate rpc_gss_nextverf, 650Sstevel@tonic-gate rpc_gss_marshall, 660Sstevel@tonic-gate rpc_gss_validate, 670Sstevel@tonic-gate rpc_gss_refresh, 680Sstevel@tonic-gate rpc_gss_destroy 690Sstevel@tonic-gate }; 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * Private data for RPCSEC_GSS. 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate typedef struct _rpc_gss_data { 750Sstevel@tonic-gate bool_t established; /* TRUE when established */ 760Sstevel@tonic-gate CLIENT *clnt; /* associated client handle */ 770Sstevel@tonic-gate uint_t version; /* RPCSEC version */ 780Sstevel@tonic-gate gss_ctx_id_t context; /* GSS context id */ 790Sstevel@tonic-gate gss_buffer_desc ctx_handle; /* RPCSEC context handle */ 800Sstevel@tonic-gate uint_t seq_num; /* last sequence number rcvd */ 810Sstevel@tonic-gate gss_cred_id_t my_cred; /* GSS credentials */ 820Sstevel@tonic-gate OM_uint32 qop; /* requested QOP */ 830Sstevel@tonic-gate rpc_gss_service_t service; /* requested service */ 840Sstevel@tonic-gate uint_t gss_proc; /* GSS control procedure */ 850Sstevel@tonic-gate gss_name_t target_name; /* target server */ 860Sstevel@tonic-gate int req_flags; /* GSS request bits */ 870Sstevel@tonic-gate gss_OID mech_type; /* GSS mechanism */ 880Sstevel@tonic-gate OM_uint32 time_req; /* requested cred lifetime */ 890Sstevel@tonic-gate bool_t invalid; /* can't use this any more */ 900Sstevel@tonic-gate OM_uint32 seq_window; /* server sequence window */ 910Sstevel@tonic-gate struct opaque_auth *verifier; /* rpc reply verifier saved for */ 920Sstevel@tonic-gate /* validating the sequence window */ 930Sstevel@tonic-gate gss_channel_bindings_t icb; 940Sstevel@tonic-gate } rpc_gss_data; 950Sstevel@tonic-gate #define AUTH_PRIVATE(auth) ((rpc_gss_data *)auth->ah_private) 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * Create a context. 990Sstevel@tonic-gate */ 1000Sstevel@tonic-gate AUTH * 1010Sstevel@tonic-gate __rpc_gss_seccreate(clnt, server_name, mech, service, qop, options_req, 1020Sstevel@tonic-gate options_ret) 1030Sstevel@tonic-gate CLIENT *clnt; /* associated client handle */ 1040Sstevel@tonic-gate char *server_name; /* target server */ 1050Sstevel@tonic-gate char *mech; /* security mechanism */ 1060Sstevel@tonic-gate rpc_gss_service_t service; /* security service */ 1070Sstevel@tonic-gate char *qop; /* requested QOP */ 1080Sstevel@tonic-gate rpc_gss_options_req_t *options_req; /* requested options */ 1090Sstevel@tonic-gate rpc_gss_options_ret_t *options_ret; /* returned options */ 1100Sstevel@tonic-gate { 1110Sstevel@tonic-gate OM_uint32 gssstat; 1120Sstevel@tonic-gate OM_uint32 minor_stat; 1130Sstevel@tonic-gate gss_name_t target_name; 1140Sstevel@tonic-gate gss_OID mech_type; 1150Sstevel@tonic-gate OM_uint32 ret_flags; 1160Sstevel@tonic-gate OM_uint32 time_rec; 1170Sstevel@tonic-gate gss_buffer_desc input_name; 1180Sstevel@tonic-gate AUTH *auth = NULL; 1190Sstevel@tonic-gate rpc_gss_data *ap = NULL; 1200Sstevel@tonic-gate OM_uint32 qop_num; 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * convert ascii strings to GSS values 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate if (!__rpc_gss_qop_to_num(qop, mech, &qop_num)) { 1260Sstevel@tonic-gate return (NULL); 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate if (!__rpc_gss_mech_to_oid(mech, &mech_type)) { 1300Sstevel@tonic-gate return (NULL); 1310Sstevel@tonic-gate } 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate /* 1340Sstevel@tonic-gate * convert name to GSS internal type 1350Sstevel@tonic-gate */ 1360Sstevel@tonic-gate input_name.value = server_name; 1370Sstevel@tonic-gate input_name.length = strlen(server_name); 1380Sstevel@tonic-gate gssstat = gss_import_name(&minor_stat, &input_name, 1390Sstevel@tonic-gate (gss_OID)GSS_C_NT_HOSTBASED_SERVICE, 1400Sstevel@tonic-gate &target_name); 1410Sstevel@tonic-gate if (gssstat != GSS_S_COMPLETE) { 1420Sstevel@tonic-gate rpc_gss_err.rpc_gss_error = RPC_GSS_ER_SYSTEMERROR; 1430Sstevel@tonic-gate rpc_gss_err.system_error = ENOMEM; 1440Sstevel@tonic-gate return (NULL); 1450Sstevel@tonic-gate } 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * Create AUTH handle. Save the necessary interface information 1490Sstevel@tonic-gate * so that the client can refresh the handle later if needed. 1500Sstevel@tonic-gate */ 1510Sstevel@tonic-gate if ((auth = (AUTH *) malloc(sizeof (*auth))) != NULL) 1520Sstevel@tonic-gate ap = (rpc_gss_data *) malloc(sizeof (*ap)); 1530Sstevel@tonic-gate if (auth == NULL || ap == NULL) { 1540Sstevel@tonic-gate rpc_gss_err.rpc_gss_error = RPC_GSS_ER_SYSTEMERROR; 1550Sstevel@tonic-gate rpc_gss_err.system_error = ENOMEM; 1560Sstevel@tonic-gate if (auth != NULL) 1570Sstevel@tonic-gate free((char *)auth); 1580Sstevel@tonic-gate (void) gss_release_name(&minor_stat, &target_name); 1590Sstevel@tonic-gate return (NULL); 1600Sstevel@tonic-gate } 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate memset((char *)ap, 0, sizeof (*ap)); 1630Sstevel@tonic-gate ap->clnt = clnt; 1640Sstevel@tonic-gate ap->version = RPCSEC_GSS_VERSION; 1650Sstevel@tonic-gate if (options_req != NULL) { 1660Sstevel@tonic-gate ap->my_cred = options_req->my_cred; 1670Sstevel@tonic-gate ap->req_flags = options_req->req_flags; 1680Sstevel@tonic-gate ap->time_req = options_req->time_req; 1690Sstevel@tonic-gate ap->icb = options_req->input_channel_bindings; 1700Sstevel@tonic-gate } else { 1710Sstevel@tonic-gate ap->my_cred = GSS_C_NO_CREDENTIAL; 1720Sstevel@tonic-gate ap->req_flags = GSS_C_MUTUAL_FLAG; 1730Sstevel@tonic-gate ap->time_req = 0; 1740Sstevel@tonic-gate ap->icb = NULL; 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate if ((ap->service = service) == rpc_gss_svc_default) 1770Sstevel@tonic-gate ap->service = rpc_gss_svc_integrity; 1780Sstevel@tonic-gate ap->qop = qop_num; 1790Sstevel@tonic-gate ap->target_name = target_name; 1800Sstevel@tonic-gate ap->mech_type = mech_type; 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate /* 1830Sstevel@tonic-gate * Now invoke the real interface that sets up the context from 1840Sstevel@tonic-gate * the information stashed away in the private data. 1850Sstevel@tonic-gate */ 1860Sstevel@tonic-gate if (!rpc_gss_seccreate_pvt(&gssstat, &minor_stat, auth, ap, 1870Sstevel@tonic-gate &mech_type, &ret_flags, &time_rec)) { 1880Sstevel@tonic-gate if (ap->target_name) 1890Sstevel@tonic-gate (void) gss_release_name(&minor_stat, &ap->target_name); 1900Sstevel@tonic-gate free((char *)ap); 1910Sstevel@tonic-gate free((char *)auth); 1920Sstevel@tonic-gate return (NULL); 1930Sstevel@tonic-gate } 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate /* 1960Sstevel@tonic-gate * Make sure that the requested service is supported. In all 1970Sstevel@tonic-gate * cases, integrity service must be available. 1980Sstevel@tonic-gate */ 1990Sstevel@tonic-gate if ((ap->service == rpc_gss_svc_privacy && 2000Sstevel@tonic-gate !(ret_flags & GSS_C_CONF_FLAG)) || 2010Sstevel@tonic-gate !(ret_flags & GSS_C_INTEG_FLAG)) { 2020Sstevel@tonic-gate rpc_gss_destroy(auth); 2030Sstevel@tonic-gate rpc_gss_err.rpc_gss_error = RPC_GSS_ER_SYSTEMERROR; 2040Sstevel@tonic-gate rpc_gss_err.system_error = EPROTONOSUPPORT; 2050Sstevel@tonic-gate return (NULL); 2060Sstevel@tonic-gate } 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* 2090Sstevel@tonic-gate * return option values if requested 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate if (options_ret != NULL) { 2120Sstevel@tonic-gate char *s; 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate options_ret->major_status = gssstat; 2150Sstevel@tonic-gate options_ret->minor_status = minor_stat; 2160Sstevel@tonic-gate options_ret->rpcsec_version = ap->version; 2170Sstevel@tonic-gate options_ret->ret_flags = ret_flags; 2180Sstevel@tonic-gate options_ret->time_ret = time_rec; 2190Sstevel@tonic-gate options_ret->gss_context = ap->context; 2200Sstevel@tonic-gate if ((s = __rpc_gss_oid_to_mech(mech_type)) != NULL) 2210Sstevel@tonic-gate strcpy(options_ret->actual_mechanism, s); 2220Sstevel@tonic-gate else 2230Sstevel@tonic-gate options_ret->actual_mechanism[0] = '\0'; 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate return (auth); 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /* 2290Sstevel@tonic-gate * Private interface to create a context. This is the interface 2300Sstevel@tonic-gate * that's invoked when the context has to be refreshed. 2310Sstevel@tonic-gate */ 2320Sstevel@tonic-gate static bool_t 2330Sstevel@tonic-gate rpc_gss_seccreate_pvt(gssstat, minor_stat, auth, ap, actual_mech_type, 2340Sstevel@tonic-gate ret_flags, time_rec) 2350Sstevel@tonic-gate OM_uint32 *gssstat; 2360Sstevel@tonic-gate OM_uint32 *minor_stat; 2370Sstevel@tonic-gate AUTH *auth; 2380Sstevel@tonic-gate rpc_gss_data *ap; 2390Sstevel@tonic-gate gss_OID *actual_mech_type; 2400Sstevel@tonic-gate OM_uint32 *ret_flags; 2410Sstevel@tonic-gate OM_uint32 *time_rec; 2420Sstevel@tonic-gate { 2430Sstevel@tonic-gate CLIENT *clnt = ap->clnt; 2440Sstevel@tonic-gate AUTH *save_auth; 2450Sstevel@tonic-gate enum clnt_stat callstat; 2460Sstevel@tonic-gate rpc_gss_init_arg call_arg; 2470Sstevel@tonic-gate rpc_gss_init_res call_res; 2480Sstevel@tonic-gate gss_buffer_desc *input_token_p, input_token; 2490Sstevel@tonic-gate bool_t free_results = FALSE; 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate /* 2520Sstevel@tonic-gate * initialize error 2530Sstevel@tonic-gate */ 2540Sstevel@tonic-gate memset(&rpc_createerr, 0, sizeof (rpc_createerr)); 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate /* 2570Sstevel@tonic-gate * (re)initialize AUTH handle and private data. 2580Sstevel@tonic-gate */ 2590Sstevel@tonic-gate memset((char *)auth, 0, sizeof (*auth)); 2600Sstevel@tonic-gate auth->ah_ops = &rpc_gss_ops; 2610Sstevel@tonic-gate auth->ah_private = (caddr_t)ap; 2620Sstevel@tonic-gate auth->ah_cred.oa_flavor = RPCSEC_GSS; 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate ap->established = FALSE; 2650Sstevel@tonic-gate ap->ctx_handle.length = 0; 2660Sstevel@tonic-gate ap->ctx_handle.value = NULL; 2670Sstevel@tonic-gate ap->context = GSS_C_NO_CONTEXT; 2680Sstevel@tonic-gate ap->seq_num = 0; 2690Sstevel@tonic-gate ap->gss_proc = RPCSEC_GSS_INIT; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * should not change clnt->cl_auth at this time, so save 2730Sstevel@tonic-gate * old handle 2740Sstevel@tonic-gate */ 2750Sstevel@tonic-gate save_auth = clnt->cl_auth; 2760Sstevel@tonic-gate clnt->cl_auth = auth; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate /* 2790Sstevel@tonic-gate * set state for starting context setup 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate input_token_p = GSS_C_NO_BUFFER; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate next_token: 2840Sstevel@tonic-gate *gssstat = gss_init_sec_context(minor_stat, 2850Sstevel@tonic-gate ap->my_cred, 2860Sstevel@tonic-gate &ap->context, 2870Sstevel@tonic-gate ap->target_name, 2880Sstevel@tonic-gate ap->mech_type, 2890Sstevel@tonic-gate ap->req_flags, 2900Sstevel@tonic-gate ap->time_req, 2910Sstevel@tonic-gate NULL, 2920Sstevel@tonic-gate input_token_p, 2930Sstevel@tonic-gate actual_mech_type, 2940Sstevel@tonic-gate &call_arg, 2950Sstevel@tonic-gate ret_flags, 2960Sstevel@tonic-gate time_rec); 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate if (input_token_p != GSS_C_NO_BUFFER) { 2990Sstevel@tonic-gate OM_uint32 minor_stat2; 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate (void) gss_release_buffer(&minor_stat2, input_token_p); 3020Sstevel@tonic-gate input_token_p = GSS_C_NO_BUFFER; 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate if (*gssstat != GSS_S_COMPLETE && *gssstat != GSS_S_CONTINUE_NEEDED) { 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate goto cleanup; 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate /* 3110Sstevel@tonic-gate * if we got a token, pass it on 3120Sstevel@tonic-gate */ 3130Sstevel@tonic-gate if (call_arg.length != 0) { 3140Sstevel@tonic-gate struct timeval timeout = {30, 0}; 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate memset((char *)&call_res, 0, sizeof (call_res)); 3170Sstevel@tonic-gate callstat = clnt_call(clnt, NULLPROC, 3180Sstevel@tonic-gate __xdr_rpc_gss_init_arg, (caddr_t)&call_arg, 3190Sstevel@tonic-gate __xdr_rpc_gss_init_res, (caddr_t)&call_res, 3200Sstevel@tonic-gate timeout); 3210Sstevel@tonic-gate (void) gss_release_buffer(minor_stat, &call_arg); 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate if (callstat != RPC_SUCCESS) { 3240Sstevel@tonic-gate goto cleanup; 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate /* 3270Sstevel@tonic-gate * we have results - note that these need to be freed 3280Sstevel@tonic-gate */ 3290Sstevel@tonic-gate free_results = TRUE; 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate if (call_res.gss_major != GSS_S_COMPLETE && 3320Sstevel@tonic-gate call_res.gss_major != GSS_S_CONTINUE_NEEDED) 3330Sstevel@tonic-gate goto cleanup; 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate ap->gss_proc = RPCSEC_GSS_CONTINUE_INIT; 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate /* 3380Sstevel@tonic-gate * check for ctx_handle 3390Sstevel@tonic-gate */ 3400Sstevel@tonic-gate if (ap->ctx_handle.length == 0) { 3410Sstevel@tonic-gate if (call_res.ctx_handle.length == 0) 3420Sstevel@tonic-gate goto cleanup; 3430Sstevel@tonic-gate GSS_DUP_BUFFER(ap->ctx_handle, 3440Sstevel@tonic-gate call_res.ctx_handle); 3450Sstevel@tonic-gate } else if (!GSS_BUFFERS_EQUAL(ap->ctx_handle, 3460Sstevel@tonic-gate call_res.ctx_handle)) 3470Sstevel@tonic-gate goto cleanup; 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate /* 3500Sstevel@tonic-gate * check for token 3510Sstevel@tonic-gate */ 3520Sstevel@tonic-gate if (call_res.token.length != 0) { 3530Sstevel@tonic-gate if (*gssstat == GSS_S_COMPLETE) 3540Sstevel@tonic-gate goto cleanup; 3550Sstevel@tonic-gate GSS_DUP_BUFFER(input_token, call_res.token); 3560Sstevel@tonic-gate input_token_p = &input_token; 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate } else if (*gssstat != GSS_S_COMPLETE) 3590Sstevel@tonic-gate goto cleanup; 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate /* save the sequence window value; validate later */ 3620Sstevel@tonic-gate ap->seq_window = call_res.seq_window; 3630Sstevel@tonic-gate xdr_free(__xdr_rpc_gss_init_res, (caddr_t)&call_res); 3640Sstevel@tonic-gate free_results = FALSE; 3650Sstevel@tonic-gate } 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate /* 3680Sstevel@tonic-gate * results were okay.. continue if necessary 3690Sstevel@tonic-gate */ 3700Sstevel@tonic-gate if (*gssstat == GSS_S_CONTINUE_NEEDED) 3710Sstevel@tonic-gate goto next_token; 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate /* 3740Sstevel@tonic-gate * Validate the sequence window - RFC 2203 section 5.2.3.1 3750Sstevel@tonic-gate */ 3760Sstevel@tonic-gate if (!validate_seqwin(ap)) { 3770Sstevel@tonic-gate goto cleanup; 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate /* 3810Sstevel@tonic-gate * Done! Security context creation is successful. 3820Sstevel@tonic-gate * Ready for exchanging data. 3830Sstevel@tonic-gate */ 3840Sstevel@tonic-gate ap->established = TRUE; 3850Sstevel@tonic-gate ap->seq_num = 1; 3860Sstevel@tonic-gate ap->gss_proc = RPCSEC_GSS_DATA; 3870Sstevel@tonic-gate ap->invalid = FALSE; 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate clnt->cl_auth = save_auth; /* restore cl_auth */ 3900Sstevel@tonic-gate return (TRUE); 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate cleanup: 3930Sstevel@tonic-gate if (ap->context != GSS_C_NO_CONTEXT) 3940Sstevel@tonic-gate rpc_gss_destroy_pvt(auth); 3950Sstevel@tonic-gate if (free_results) 3960Sstevel@tonic-gate xdr_free(__xdr_rpc_gss_init_res, (caddr_t)&call_res); 3970Sstevel@tonic-gate clnt->cl_auth = save_auth; /* restore cl_auth */ 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate /* 4000Sstevel@tonic-gate * if (rpc_createerr.cf_stat == 0) 4010Sstevel@tonic-gate * rpc_createerr.cf_stat = RPC_AUTHERROR; 4020Sstevel@tonic-gate */ 4030Sstevel@tonic-gate if (rpc_createerr.cf_stat == 0) { 4040Sstevel@tonic-gate rpc_gss_err.rpc_gss_error = RPC_GSS_ER_SYSTEMERROR; 4050Sstevel@tonic-gate rpc_gss_err.system_error = RPC_AUTHERROR; 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate return (FALSE); 4090Sstevel@tonic-gate } 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate /* 4120Sstevel@tonic-gate * Set service defaults. 4130Sstevel@tonic-gate */ 4140Sstevel@tonic-gate bool_t 4150Sstevel@tonic-gate __rpc_gss_set_defaults(auth, service, qop) 4160Sstevel@tonic-gate AUTH *auth; 4170Sstevel@tonic-gate rpc_gss_service_t service; 4180Sstevel@tonic-gate char *qop; 4190Sstevel@tonic-gate { 4200Sstevel@tonic-gate /*LINTED*/ 4210Sstevel@tonic-gate rpc_gss_data *ap = AUTH_PRIVATE(auth); 4220Sstevel@tonic-gate char *mech; 4230Sstevel@tonic-gate OM_uint32 qop_num; 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate switch (service) { 4260Sstevel@tonic-gate case rpc_gss_svc_integrity: 4270Sstevel@tonic-gate case rpc_gss_svc_privacy: 4280Sstevel@tonic-gate case rpc_gss_svc_none: 4290Sstevel@tonic-gate break; 4300Sstevel@tonic-gate case rpc_gss_svc_default: 4310Sstevel@tonic-gate service = rpc_gss_svc_integrity; 4320Sstevel@tonic-gate break; 4330Sstevel@tonic-gate default: 4340Sstevel@tonic-gate return (FALSE); 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate if ((mech = __rpc_gss_oid_to_mech(ap->mech_type)) == NULL) 4380Sstevel@tonic-gate return (FALSE); 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate if (!__rpc_gss_qop_to_num(qop, mech, &qop_num)) 4410Sstevel@tonic-gate return (FALSE); 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate ap->qop = qop_num; 4440Sstevel@tonic-gate ap->service = service; 4450Sstevel@tonic-gate return (TRUE); 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate /* 4490Sstevel@tonic-gate * Marshall credentials. 4500Sstevel@tonic-gate */ 4510Sstevel@tonic-gate static bool_t 4520Sstevel@tonic-gate marshall_creds(ap, xdrs) 4530Sstevel@tonic-gate rpc_gss_data *ap; 4540Sstevel@tonic-gate XDR *xdrs; 4550Sstevel@tonic-gate { 4560Sstevel@tonic-gate rpc_gss_creds ag_creds; 4570Sstevel@tonic-gate char cred_buf[MAX_AUTH_BYTES]; 4580Sstevel@tonic-gate struct opaque_auth creds; 4590Sstevel@tonic-gate XDR cred_xdrs; 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate ag_creds.version = ap->version; 4620Sstevel@tonic-gate ag_creds.gss_proc = ap->gss_proc; 4630Sstevel@tonic-gate ag_creds.seq_num = ap->seq_num; 4640Sstevel@tonic-gate ag_creds.service = ap->service; 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate /* 4670Sstevel@tonic-gate * If context has not been set up yet, use NULL handle. 4680Sstevel@tonic-gate */ 4690Sstevel@tonic-gate if (ap->ctx_handle.length > 0) 4700Sstevel@tonic-gate ag_creds.ctx_handle = ap->ctx_handle; 4710Sstevel@tonic-gate else { 4720Sstevel@tonic-gate ag_creds.ctx_handle.length = 0; 4730Sstevel@tonic-gate ag_creds.ctx_handle.value = NULL; 4740Sstevel@tonic-gate } 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate xdrmem_create(&cred_xdrs, (caddr_t)cred_buf, MAX_AUTH_BYTES, 4770Sstevel@tonic-gate XDR_ENCODE); 4780Sstevel@tonic-gate if (!__xdr_rpc_gss_creds(&cred_xdrs, &ag_creds)) { 4790Sstevel@tonic-gate XDR_DESTROY(&cred_xdrs); 4800Sstevel@tonic-gate return (FALSE); 4810Sstevel@tonic-gate } 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate creds.oa_flavor = RPCSEC_GSS; 4840Sstevel@tonic-gate creds.oa_base = cred_buf; 4850Sstevel@tonic-gate creds.oa_length = xdr_getpos(&cred_xdrs); 4860Sstevel@tonic-gate XDR_DESTROY(&cred_xdrs); 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate if (!xdr_opaque_auth(xdrs, &creds)) 4890Sstevel@tonic-gate return (FALSE); 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate return (TRUE); 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate /* 4950Sstevel@tonic-gate * Marshall verifier. The verifier is the checksum of the RPC header 4960Sstevel@tonic-gate * up to and including the credential field. The XDR handle that's 4970Sstevel@tonic-gate * passed in has the header up to and including the credential field 4980Sstevel@tonic-gate * encoded. A pointer to the transmit buffer is also passed in. 4990Sstevel@tonic-gate */ 5000Sstevel@tonic-gate static bool_t 5010Sstevel@tonic-gate marshall_verf(ap, xdrs, buf) 5020Sstevel@tonic-gate rpc_gss_data *ap; 5030Sstevel@tonic-gate XDR *xdrs; /* send XDR */ 5040Sstevel@tonic-gate char *buf; /* pointer of send buffer */ 5050Sstevel@tonic-gate { 5060Sstevel@tonic-gate struct opaque_auth verf; 5070Sstevel@tonic-gate OM_uint32 major, minor; 5080Sstevel@tonic-gate gss_buffer_desc in_buf, out_buf; 5090Sstevel@tonic-gate bool_t ret = FALSE; 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate /* 5120Sstevel@tonic-gate * If context is not established yet, use NULL verifier. 5130Sstevel@tonic-gate */ 5140Sstevel@tonic-gate if (!ap->established) { 5150Sstevel@tonic-gate verf.oa_flavor = AUTH_NONE; 5160Sstevel@tonic-gate verf.oa_base = NULL; 5170Sstevel@tonic-gate verf.oa_length = 0; 5180Sstevel@tonic-gate return (xdr_opaque_auth(xdrs, &verf)); 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate verf.oa_flavor = RPCSEC_GSS; 5220Sstevel@tonic-gate in_buf.length = xdr_getpos(xdrs); 5230Sstevel@tonic-gate in_buf.value = buf; 5240Sstevel@tonic-gate if ((major = gss_sign(&minor, ap->context, ap->qop, &in_buf, 5250Sstevel@tonic-gate &out_buf)) != GSS_S_COMPLETE) { 5260Sstevel@tonic-gate if (major == GSS_S_CONTEXT_EXPIRED) { 5270Sstevel@tonic-gate ap->invalid = TRUE; 5280Sstevel@tonic-gate } 5290Sstevel@tonic-gate return (FALSE); 5300Sstevel@tonic-gate } 5310Sstevel@tonic-gate verf.oa_base = out_buf.value; 5320Sstevel@tonic-gate verf.oa_length = out_buf.length; 5330Sstevel@tonic-gate ret = xdr_opaque_auth(xdrs, &verf); 5340Sstevel@tonic-gate (void) gss_release_buffer(&minor, &out_buf); 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate return (ret); 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate /* 5400Sstevel@tonic-gate * Function: rpc_gss_nextverf. Not used. 5410Sstevel@tonic-gate */ 5420Sstevel@tonic-gate static void 5430Sstevel@tonic-gate rpc_gss_nextverf() 5440Sstevel@tonic-gate { 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate /* 5480Sstevel@tonic-gate * Function: rpc_gss_marshall - not used. 5490Sstevel@tonic-gate */ 5500Sstevel@tonic-gate static bool_t 5510Sstevel@tonic-gate rpc_gss_marshall(auth, xdrs) 5520Sstevel@tonic-gate AUTH *auth; 5530Sstevel@tonic-gate XDR *xdrs; 5540Sstevel@tonic-gate { 5550Sstevel@tonic-gate if (!xdr_opaque_auth(xdrs, &auth->ah_cred) || 5560Sstevel@tonic-gate !xdr_opaque_auth(xdrs, &auth->ah_verf)) 5570Sstevel@tonic-gate return (FALSE); 5580Sstevel@tonic-gate return (TRUE); 5590Sstevel@tonic-gate } 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate /* 5620Sstevel@tonic-gate * Validate sequence window upon a successful RPCSEC_GSS INIT session. 5630Sstevel@tonic-gate * The sequence window sent back by the server should be verifiable by 5640Sstevel@tonic-gate * the verifier which is a checksum of the sequence window. 5650Sstevel@tonic-gate */ 5660Sstevel@tonic-gate static bool_t 5670Sstevel@tonic-gate validate_seqwin(rpc_gss_data *ap) 5680Sstevel@tonic-gate { 5690Sstevel@tonic-gate uint_t seq_win_net; 5700Sstevel@tonic-gate OM_uint32 major = 0, minor = 0; 5710Sstevel@tonic-gate gss_buffer_desc msg_buf, tok_buf; 5720Sstevel@tonic-gate int qop_state = 0; 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate seq_win_net = (uint_t)htonl(ap->seq_window); 5750Sstevel@tonic-gate msg_buf.length = sizeof (seq_win_net); 5760Sstevel@tonic-gate msg_buf.value = (char *)&seq_win_net; 5770Sstevel@tonic-gate tok_buf.length = ap->verifier->oa_length; 5780Sstevel@tonic-gate tok_buf.value = ap->verifier->oa_base; 5790Sstevel@tonic-gate major = gss_verify(&minor, ap->context, &msg_buf, &tok_buf, &qop_state); 5800Sstevel@tonic-gate if (major != GSS_S_COMPLETE) 581*6812Sraf return (FALSE); 5820Sstevel@tonic-gate return (TRUE); 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate /* 5860Sstevel@tonic-gate * Validate RPC response verifier from server. The response verifier 5870Sstevel@tonic-gate * is the checksum of the request sequence number. 5880Sstevel@tonic-gate */ 5890Sstevel@tonic-gate static bool_t 5900Sstevel@tonic-gate rpc_gss_validate(auth, verf) 5910Sstevel@tonic-gate AUTH *auth; 5920Sstevel@tonic-gate struct opaque_auth *verf; 5930Sstevel@tonic-gate { 5940Sstevel@tonic-gate /*LINTED*/ 5950Sstevel@tonic-gate rpc_gss_data *ap = AUTH_PRIVATE(auth); 5960Sstevel@tonic-gate uint_t seq_num_net; 5970Sstevel@tonic-gate OM_uint32 major, minor; 5980Sstevel@tonic-gate gss_buffer_desc msg_buf, tok_buf; 5990Sstevel@tonic-gate int qop_state; 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate /* 6020Sstevel@tonic-gate * If context is not established yet, save the verifier for 6030Sstevel@tonic-gate * validating the sequence window later at the end of context 6040Sstevel@tonic-gate * creation session. 6050Sstevel@tonic-gate */ 6060Sstevel@tonic-gate if (!ap->established) { 6070Sstevel@tonic-gate if (ap->verifier == NULL) { 6080Sstevel@tonic-gate ap->verifier = malloc(sizeof (struct opaque_auth)); 6090Sstevel@tonic-gate memset(ap->verifier, 0, sizeof (struct opaque_auth)); 6100Sstevel@tonic-gate if (verf->oa_length > 0) 6110Sstevel@tonic-gate ap->verifier->oa_base = malloc(verf->oa_length); 6120Sstevel@tonic-gate } else { 6130Sstevel@tonic-gate if (ap->verifier->oa_length > 0) 6140Sstevel@tonic-gate free(ap->verifier->oa_base); 6150Sstevel@tonic-gate if (verf->oa_length > 0) 6160Sstevel@tonic-gate ap->verifier->oa_base = malloc(verf->oa_length); 6170Sstevel@tonic-gate } 6180Sstevel@tonic-gate ap->verifier->oa_length = verf->oa_length; 6190Sstevel@tonic-gate bcopy(verf->oa_base, ap->verifier->oa_base, verf->oa_length); 6200Sstevel@tonic-gate return (TRUE); 6210Sstevel@tonic-gate } 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate seq_num_net = (uint_t)htonl(ap->seq_num); 6240Sstevel@tonic-gate msg_buf.length = sizeof (seq_num_net); 6250Sstevel@tonic-gate msg_buf.value = (char *)&seq_num_net; 6260Sstevel@tonic-gate tok_buf.length = verf->oa_length; 6270Sstevel@tonic-gate tok_buf.value = verf->oa_base; 6280Sstevel@tonic-gate major = gss_verify(&minor, ap->context, &msg_buf, &tok_buf, &qop_state); 6290Sstevel@tonic-gate if (major != GSS_S_COMPLETE) 6300Sstevel@tonic-gate return (FALSE); 6310Sstevel@tonic-gate return (TRUE); 6320Sstevel@tonic-gate } 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate /* 6350Sstevel@tonic-gate * Refresh client context. This is necessary sometimes because the 6360Sstevel@tonic-gate * server will ocassionally destroy contexts based on LRU method, or 6370Sstevel@tonic-gate * because of expired credentials. 6380Sstevel@tonic-gate */ 6390Sstevel@tonic-gate static bool_t 6400Sstevel@tonic-gate rpc_gss_refresh(auth, msg) 6410Sstevel@tonic-gate AUTH *auth; 6420Sstevel@tonic-gate struct rpc_msg *msg; 6430Sstevel@tonic-gate { 6440Sstevel@tonic-gate /*LINTED*/ 6450Sstevel@tonic-gate rpc_gss_data *ap = AUTH_PRIVATE(auth); 6460Sstevel@tonic-gate OM_uint32 gssstat, minor_stat; 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate /* 6490Sstevel@tonic-gate * The context needs to be recreated only when the error status 6500Sstevel@tonic-gate * returned from the server is one of the following: 6510Sstevel@tonic-gate * RPCSEC_GSS_NOCRED and RPCSEC_GSS_FAILED 6520Sstevel@tonic-gate * The existing context should not be destroyed unless the above 6530Sstevel@tonic-gate * error status codes are received or if the context has not 6540Sstevel@tonic-gate * been set up. 6550Sstevel@tonic-gate */ 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate if (msg->rjcted_rply.rj_why == RPCSEC_GSS_NOCRED || 6580Sstevel@tonic-gate msg->rjcted_rply.rj_why == RPCSEC_GSS_FAILED || 6590Sstevel@tonic-gate !ap->established) { 6600Sstevel@tonic-gate /* 6610Sstevel@tonic-gate * Destroy the context if necessary. Use the same memory 6620Sstevel@tonic-gate * for the new context since we've already passed a pointer 6630Sstevel@tonic-gate * to it to the user. 6640Sstevel@tonic-gate */ 6650Sstevel@tonic-gate if (ap->context != GSS_C_NO_CONTEXT) { 6660Sstevel@tonic-gate (void) gss_delete_sec_context(&minor_stat, &ap->context, 6670Sstevel@tonic-gate NULL); 6680Sstevel@tonic-gate ap->context = GSS_C_NO_CONTEXT; 6690Sstevel@tonic-gate } 6700Sstevel@tonic-gate if (ap->ctx_handle.length != 0) { 6710Sstevel@tonic-gate (void) gss_release_buffer(&minor_stat, 6720Sstevel@tonic-gate &ap->ctx_handle); 6730Sstevel@tonic-gate ap->ctx_handle.length = 0; 6740Sstevel@tonic-gate ap->ctx_handle.value = NULL; 6750Sstevel@tonic-gate } 6760Sstevel@tonic-gate 6770Sstevel@tonic-gate /* 6780Sstevel@tonic-gate * If the context was not already established, don't try to 6790Sstevel@tonic-gate * recreate it. 6800Sstevel@tonic-gate */ 6810Sstevel@tonic-gate if (!ap->established) { 6820Sstevel@tonic-gate ap->invalid = TRUE; 6830Sstevel@tonic-gate return (FALSE); 6840Sstevel@tonic-gate } 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate /* 6870Sstevel@tonic-gate * Recreate context. 6880Sstevel@tonic-gate */ 6890Sstevel@tonic-gate if (rpc_gss_seccreate_pvt(&gssstat, &minor_stat, auth, ap, 6900Sstevel@tonic-gate (gss_OID *)0, (OM_uint32 *)0, (OM_uint32 *)0)) 6910Sstevel@tonic-gate return (TRUE); 6920Sstevel@tonic-gate else { 6930Sstevel@tonic-gate ap->invalid = TRUE; 6940Sstevel@tonic-gate return (FALSE); 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate } 6970Sstevel@tonic-gate return (FALSE); 6980Sstevel@tonic-gate } 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate /* 7010Sstevel@tonic-gate * Destroy a context. 7020Sstevel@tonic-gate */ 7030Sstevel@tonic-gate static void 7040Sstevel@tonic-gate rpc_gss_destroy(auth) 7050Sstevel@tonic-gate AUTH *auth; 7060Sstevel@tonic-gate { 7070Sstevel@tonic-gate /*LINTED*/ 7080Sstevel@tonic-gate rpc_gss_data *ap = AUTH_PRIVATE(auth); 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate rpc_gss_destroy_pvt(auth); 7110Sstevel@tonic-gate free((char *)ap); 7120Sstevel@tonic-gate free(auth); 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate /* 7160Sstevel@tonic-gate * Private interface to destroy a context without freeing up 7170Sstevel@tonic-gate * the memory used by it. We need to do this when a refresh 7180Sstevel@tonic-gate * fails, for example, so the user will still have a handle. 7190Sstevel@tonic-gate */ 7200Sstevel@tonic-gate static void 7210Sstevel@tonic-gate rpc_gss_destroy_pvt(auth) 7220Sstevel@tonic-gate AUTH *auth; 7230Sstevel@tonic-gate { 7240Sstevel@tonic-gate struct timeval timeout; 7250Sstevel@tonic-gate OM_uint32 minor_stat; 7260Sstevel@tonic-gate /*LINTED*/ 7270Sstevel@tonic-gate rpc_gss_data *ap = AUTH_PRIVATE(auth); 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate /* 7300Sstevel@tonic-gate * If we have a server context id, inform server that we are 7310Sstevel@tonic-gate * destroying the context. 7320Sstevel@tonic-gate */ 7330Sstevel@tonic-gate if (ap->ctx_handle.length != 0) { 7340Sstevel@tonic-gate ap->gss_proc = RPCSEC_GSS_DESTROY; 7350Sstevel@tonic-gate timeout.tv_sec = 1; 7360Sstevel@tonic-gate timeout.tv_usec = 0; 7370Sstevel@tonic-gate (void) clnt_call(ap->clnt, NULLPROC, xdr_void, NULL, 7380Sstevel@tonic-gate xdr_void, NULL, timeout); 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate (void) gss_release_buffer(&minor_stat, &ap->ctx_handle); 7410Sstevel@tonic-gate ap->ctx_handle.length = 0; 7420Sstevel@tonic-gate ap->ctx_handle.value = NULL; 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate /* 7460Sstevel@tonic-gate * Destroy local GSS context. 7470Sstevel@tonic-gate */ 7480Sstevel@tonic-gate if (ap->context != GSS_C_NO_CONTEXT) { 7490Sstevel@tonic-gate (void) gss_delete_sec_context(&minor_stat, &ap->context, NULL); 7500Sstevel@tonic-gate ap->context = GSS_C_NO_CONTEXT; 7510Sstevel@tonic-gate } 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate /* 7540Sstevel@tonic-gate * Looks like we need to release default credentials if we use it. 7550Sstevel@tonic-gate * Non-default creds need to be released by user. 7560Sstevel@tonic-gate */ 7570Sstevel@tonic-gate if (ap->my_cred == GSS_C_NO_CREDENTIAL) 7580Sstevel@tonic-gate (void) gss_release_cred(&minor_stat, &ap->my_cred); 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate /* 7610Sstevel@tonic-gate * Release any internal name structures. 7620Sstevel@tonic-gate */ 7630Sstevel@tonic-gate if (ap->target_name != NULL) { 7640Sstevel@tonic-gate (void) gss_release_name(&minor_stat, &ap->target_name); 7650Sstevel@tonic-gate ap->target_name = NULL; 7660Sstevel@tonic-gate } 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate /* 7690Sstevel@tonic-gate * Free the verifier saved for sequence window checking. 7700Sstevel@tonic-gate */ 7710Sstevel@tonic-gate if (ap->verifier != NULL) { 7720Sstevel@tonic-gate if (ap->verifier->oa_length > 0) 7730Sstevel@tonic-gate free(ap->verifier->oa_base); 7740Sstevel@tonic-gate free(ap->verifier); 7750Sstevel@tonic-gate ap->verifier = NULL; 7760Sstevel@tonic-gate } 7770Sstevel@tonic-gate } 7780Sstevel@tonic-gate 7790Sstevel@tonic-gate /* 7800Sstevel@tonic-gate * Wrap client side data. The encoded header is passed in through 7810Sstevel@tonic-gate * buf and buflen. The header is up to but not including the 7820Sstevel@tonic-gate * credential field. 7830Sstevel@tonic-gate */ 7840Sstevel@tonic-gate bool_t 7850Sstevel@tonic-gate __rpc_gss_wrap(auth, buf, buflen, out_xdrs, xdr_func, xdr_ptr) 7860Sstevel@tonic-gate AUTH *auth; 7870Sstevel@tonic-gate char *buf; /* encoded header */ 7880Sstevel@tonic-gate uint_t buflen; /* encoded header length */ 7890Sstevel@tonic-gate XDR *out_xdrs; 7900Sstevel@tonic-gate bool_t (*xdr_func)(); 7910Sstevel@tonic-gate caddr_t xdr_ptr; 7920Sstevel@tonic-gate { 7930Sstevel@tonic-gate /*LINTED*/ 7940Sstevel@tonic-gate rpc_gss_data *ap = AUTH_PRIVATE(auth); 7950Sstevel@tonic-gate XDR xdrs; 7960Sstevel@tonic-gate char tmp_buf[512]; 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate /* 8000Sstevel@tonic-gate * Reject an invalid context. 8010Sstevel@tonic-gate */ 8020Sstevel@tonic-gate if (ap->invalid) 8030Sstevel@tonic-gate return (FALSE); 8040Sstevel@tonic-gate 8050Sstevel@tonic-gate /* 8060Sstevel@tonic-gate * If context is established, bump up sequence number. 8070Sstevel@tonic-gate */ 8080Sstevel@tonic-gate if (ap->established) 8090Sstevel@tonic-gate ap->seq_num++; 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate /* 8120Sstevel@tonic-gate * Create the header in a temporary XDR context and buffer 8130Sstevel@tonic-gate * before putting it out. 8140Sstevel@tonic-gate */ 8150Sstevel@tonic-gate xdrmem_create(&xdrs, tmp_buf, sizeof (tmp_buf), XDR_ENCODE); 8160Sstevel@tonic-gate if (!XDR_PUTBYTES(&xdrs, buf, buflen)) 8170Sstevel@tonic-gate return (FALSE); 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate /* 8200Sstevel@tonic-gate * create cred field 8210Sstevel@tonic-gate */ 8220Sstevel@tonic-gate if (!marshall_creds(ap, &xdrs)) 8230Sstevel@tonic-gate return (FALSE); 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate /* 8260Sstevel@tonic-gate * create verifier 8270Sstevel@tonic-gate */ 8280Sstevel@tonic-gate if (!marshall_verf(ap, &xdrs, tmp_buf)) 8290Sstevel@tonic-gate return (FALSE); 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate /* 8320Sstevel@tonic-gate * write out header and destroy temp structures 8330Sstevel@tonic-gate */ 8340Sstevel@tonic-gate if (!XDR_PUTBYTES(out_xdrs, tmp_buf, XDR_GETPOS(&xdrs))) 8350Sstevel@tonic-gate return (FALSE); 8360Sstevel@tonic-gate XDR_DESTROY(&xdrs); 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate /* 8390Sstevel@tonic-gate * If context is not established, or if neither integrity 8400Sstevel@tonic-gate * nor privacy is used, just XDR encode data. 8410Sstevel@tonic-gate */ 8420Sstevel@tonic-gate if (!ap->established || ap->service == rpc_gss_svc_none) 8430Sstevel@tonic-gate return ((*xdr_func)(out_xdrs, xdr_ptr)); 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate return (__rpc_gss_wrap_data(ap->service, ap->qop, ap->context, 8460Sstevel@tonic-gate ap->seq_num, out_xdrs, xdr_func, xdr_ptr)); 8470Sstevel@tonic-gate } 8480Sstevel@tonic-gate 8490Sstevel@tonic-gate /* 8500Sstevel@tonic-gate * Unwrap received data. 8510Sstevel@tonic-gate */ 8520Sstevel@tonic-gate bool_t 8530Sstevel@tonic-gate __rpc_gss_unwrap(auth, in_xdrs, xdr_func, xdr_ptr) 8540Sstevel@tonic-gate AUTH *auth; 8550Sstevel@tonic-gate XDR *in_xdrs; 8560Sstevel@tonic-gate bool_t (*xdr_func)(); 8570Sstevel@tonic-gate caddr_t xdr_ptr; 8580Sstevel@tonic-gate { 8590Sstevel@tonic-gate /*LINTED*/ 8600Sstevel@tonic-gate rpc_gss_data *ap = AUTH_PRIVATE(auth); 8610Sstevel@tonic-gate 8620Sstevel@tonic-gate /* 8630Sstevel@tonic-gate * If context is not established, of if neither integrity 8640Sstevel@tonic-gate * nor privacy is used, just XDR encode data. 8650Sstevel@tonic-gate */ 8660Sstevel@tonic-gate if (!ap->established || ap->service == rpc_gss_svc_none) 8670Sstevel@tonic-gate return ((*xdr_func)(in_xdrs, xdr_ptr)); 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate return (__rpc_gss_unwrap_data(ap->service, 8700Sstevel@tonic-gate ap->context, 8710Sstevel@tonic-gate ap->seq_num, 8720Sstevel@tonic-gate ap->qop, 8730Sstevel@tonic-gate in_xdrs, xdr_func, xdr_ptr)); 8740Sstevel@tonic-gate } 8750Sstevel@tonic-gate 8760Sstevel@tonic-gate int 8770Sstevel@tonic-gate __rpc_gss_max_data_length(auth, max_tp_unit_len) 8780Sstevel@tonic-gate AUTH *auth; 8790Sstevel@tonic-gate int max_tp_unit_len; 8800Sstevel@tonic-gate { 8810Sstevel@tonic-gate /*LINTED*/ 8820Sstevel@tonic-gate rpc_gss_data *ap = AUTH_PRIVATE(auth); 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate if (!ap->established || max_tp_unit_len <= 0) 8850Sstevel@tonic-gate return (0); 8860Sstevel@tonic-gate 8870Sstevel@tonic-gate return (__find_max_data_length(ap->service, 8880Sstevel@tonic-gate ap->context, 8890Sstevel@tonic-gate ap->qop, 8900Sstevel@tonic-gate max_tp_unit_len)); 8910Sstevel@tonic-gate } 8920Sstevel@tonic-gate 8933864Sraf void 8943864Sraf __rpc_gss_get_error(rpc_gss_error_t *error) 8953864Sraf { 8963864Sraf *error = rpc_gss_err; 8973864Sraf } 8983864Sraf 8990Sstevel@tonic-gate #undef rpc_gss_err 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate rpc_gss_error_t rpc_gss_err; 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate rpc_gss_error_t * 9040Sstevel@tonic-gate __rpc_gss_err() 9050Sstevel@tonic-gate { 9063864Sraf static thread_key_t rpc_gss_err_key = THR_ONCE_KEY; 9073864Sraf rpc_gss_error_t *tsd; 9080Sstevel@tonic-gate 909*6812Sraf if (thr_main()) 9100Sstevel@tonic-gate return (&rpc_gss_err); 911*6812Sraf if (thr_keycreate_once(&rpc_gss_err_key, free) != 0) 9123864Sraf return (&rpc_gss_err); 913*6812Sraf tsd = pthread_getspecific(rpc_gss_err_key); 9143864Sraf if (tsd == NULL) { 9153864Sraf tsd = (rpc_gss_error_t *)calloc(1, sizeof (rpc_gss_error_t)); 916*6812Sraf if (thr_setspecific(rpc_gss_err_key, tsd) != 0) { 9170Sstevel@tonic-gate if (tsd) 9180Sstevel@tonic-gate free(tsd); 9190Sstevel@tonic-gate return (&rpc_gss_err); 9200Sstevel@tonic-gate } 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate return (tsd); 9230Sstevel@tonic-gate } 924