1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * Kernel code to obtain client handle to gssd server 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <sys/types.h> 34*0Sstevel@tonic-gate #include <gssapi/gssapi.h> 35*0Sstevel@tonic-gate #include <gssapi/gssd_prot.h> 36*0Sstevel@tonic-gate #include <gssapi/kgssapi_defs.h> 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #include <sys/systm.h> 39*0Sstevel@tonic-gate #include <sys/vnode.h> 40*0Sstevel@tonic-gate #include <sys/uio.h> 41*0Sstevel@tonic-gate #include <sys/pathname.h> 42*0Sstevel@tonic-gate #include <sys/utsname.h> 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate #define GSSD_RETRY 5 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate kmutex_t gssrpcb_lock; 47*0Sstevel@tonic-gate zone_key_t gss_zone_key; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate struct gss_globals { 50*0Sstevel@tonic-gate enum clnt_stat gss_last_stat; 51*0Sstevel@tonic-gate struct netbuf gss_netaddr; 52*0Sstevel@tonic-gate struct knetconfig gss_config; 53*0Sstevel@tonic-gate }; 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate /* ARGSUSED */ 56*0Sstevel@tonic-gate void * 57*0Sstevel@tonic-gate gss_zone_init(zoneid_t zoneid) 58*0Sstevel@tonic-gate { 59*0Sstevel@tonic-gate struct gss_globals *gssg; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate gssg = kmem_zalloc(sizeof (*gssg), KM_SLEEP); 62*0Sstevel@tonic-gate return (gssg); 63*0Sstevel@tonic-gate } 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate /* ARGSUSED */ 66*0Sstevel@tonic-gate void 67*0Sstevel@tonic-gate gss_zone_fini(zoneid_t zoneid, void *data) 68*0Sstevel@tonic-gate { 69*0Sstevel@tonic-gate struct gss_globals *gssg = data; 70*0Sstevel@tonic-gate struct netbuf *netaddrp = &gssg->gss_netaddr; 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate if (netaddrp->len != 0) 73*0Sstevel@tonic-gate kmem_free(netaddrp->buf, netaddrp->maxlen); 74*0Sstevel@tonic-gate kmem_free(gssg, sizeof (*gssg)); 75*0Sstevel@tonic-gate } 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate void 78*0Sstevel@tonic-gate killgssd_handle(CLIENT *client) 79*0Sstevel@tonic-gate { 80*0Sstevel@tonic-gate struct rpc_err rpcerr; 81*0Sstevel@tonic-gate struct gss_globals *gssg; 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate gssg = zone_getspecific(gss_zone_key, curproc->p_zone); 84*0Sstevel@tonic-gate CLNT_GETERR(client, &rpcerr); 85*0Sstevel@tonic-gate gssg->gss_last_stat = rpcerr.re_status; 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate AUTH_DESTROY(client->cl_auth); 88*0Sstevel@tonic-gate CLNT_DESTROY(client); 89*0Sstevel@tonic-gate } 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate CLIENT * 92*0Sstevel@tonic-gate getgssd_handle(void) 93*0Sstevel@tonic-gate { 94*0Sstevel@tonic-gate struct vnode *vp; 95*0Sstevel@tonic-gate int error; 96*0Sstevel@tonic-gate CLIENT *clnt; 97*0Sstevel@tonic-gate char *gssname; 98*0Sstevel@tonic-gate enum clnt_stat stat; 99*0Sstevel@tonic-gate struct netbuf tmpaddr; 100*0Sstevel@tonic-gate struct gss_globals *gssg; 101*0Sstevel@tonic-gate struct netbuf *netaddrp; 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate gssg = zone_getspecific(gss_zone_key, curproc->p_zone); 104*0Sstevel@tonic-gate /* 105*0Sstevel@tonic-gate * Cribbed from kerb_krpc.c. Really should do the config set up 106*0Sstevel@tonic-gate * in the _init routine. 107*0Sstevel@tonic-gate */ 108*0Sstevel@tonic-gate if (gssg->gss_config.knc_rdev == 0) { 109*0Sstevel@tonic-gate if ((error = lookupname("/dev/ticotsord", UIO_SYSSPACE, 110*0Sstevel@tonic-gate FOLLOW, NULLVPP, &vp)) != 0) { 111*0Sstevel@tonic-gate GSSLOG(1, "getgssd_handle: lookupname: %d\n", error); 112*0Sstevel@tonic-gate return (NULL); 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate gssg->gss_config.knc_rdev = vp->v_rdev; 115*0Sstevel@tonic-gate gssg->gss_config.knc_protofmly = loopback_name; 116*0Sstevel@tonic-gate VN_RELE(vp); 117*0Sstevel@tonic-gate gssg->gss_config.knc_semantics = NC_TPI_COTS_ORD; 118*0Sstevel@tonic-gate } 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate /* 121*0Sstevel@tonic-gate * Contact rpcbind to get gssd's address only 122*0Sstevel@tonic-gate * once and re-use the address. 123*0Sstevel@tonic-gate */ 124*0Sstevel@tonic-gate mutex_enter(&gssrpcb_lock); 125*0Sstevel@tonic-gate netaddrp = &gssg->gss_netaddr; 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate if (netaddrp->len == 0 || gssg->gss_last_stat != RPC_SUCCESS) { 128*0Sstevel@tonic-gate char *nodename = uts_nodename(); 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate /* Set up netaddr to be <nodename>. */ 131*0Sstevel@tonic-gate netaddrp->len = strlen(nodename) + 1; 132*0Sstevel@tonic-gate if (netaddrp->buf != (char *)NULL) 133*0Sstevel@tonic-gate kmem_free(netaddrp->buf, netaddrp->maxlen); 134*0Sstevel@tonic-gate gssname = kmem_zalloc(netaddrp->len, KM_SLEEP); 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate (void) strncpy(gssname, nodename, netaddrp->len - 1); 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate /* Append "." to end of gssname */ 139*0Sstevel@tonic-gate (void) strncpy(gssname+(netaddrp->len-1), ".", 1); 140*0Sstevel@tonic-gate netaddrp->buf = gssname; 141*0Sstevel@tonic-gate netaddrp->maxlen = netaddrp->len; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate /* Get address of gssd from rpcbind */ 144*0Sstevel@tonic-gate stat = rpcbind_getaddr(&gssg->gss_config, GSSPROG, GSSVERS, 145*0Sstevel@tonic-gate netaddrp); 146*0Sstevel@tonic-gate if (stat != RPC_SUCCESS) { 147*0Sstevel@tonic-gate kmem_free(netaddrp->buf, netaddrp->maxlen); 148*0Sstevel@tonic-gate netaddrp->buf = (char *)NULL; 149*0Sstevel@tonic-gate netaddrp->len = netaddrp->maxlen = 0; 150*0Sstevel@tonic-gate mutex_exit(&gssrpcb_lock); 151*0Sstevel@tonic-gate return (NULL); 152*0Sstevel@tonic-gate } 153*0Sstevel@tonic-gate } 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate /* 156*0Sstevel@tonic-gate * Copy the netaddr information into a tmp location to 157*0Sstevel@tonic-gate * be used by clnt_tli_kcreate. The purpose of this 158*0Sstevel@tonic-gate * is for MT race condition (ie. netaddr being modified 159*0Sstevel@tonic-gate * while it is being used.) 160*0Sstevel@tonic-gate */ 161*0Sstevel@tonic-gate tmpaddr.buf = kmem_zalloc(netaddrp->maxlen, KM_SLEEP); 162*0Sstevel@tonic-gate bcopy(netaddrp->buf, tmpaddr.buf, netaddrp->maxlen); 163*0Sstevel@tonic-gate tmpaddr.maxlen = netaddrp->maxlen; 164*0Sstevel@tonic-gate tmpaddr.len = netaddrp->len; 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate mutex_exit(&gssrpcb_lock); 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate error = clnt_tli_kcreate(&gssg->gss_config, &tmpaddr, GSSPROG, 169*0Sstevel@tonic-gate GSSVERS, 0, GSSD_RETRY, kcred, &clnt); 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate kmem_free(tmpaddr.buf, tmpaddr.maxlen); 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate if (error != 0) { 174*0Sstevel@tonic-gate GSSLOG(1, 175*0Sstevel@tonic-gate "getgssd_handle: clnt_tli_kcreate: error %d\n", error); 176*0Sstevel@tonic-gate return (NULL); 177*0Sstevel@tonic-gate } 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate return (clnt); 180*0Sstevel@tonic-gate } 181