1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 28*7c478bd9Sstevel@tonic-gate /* 29*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 30*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 31*7c478bd9Sstevel@tonic-gate * All Rights Reserved 32*7c478bd9Sstevel@tonic-gate * 33*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 34*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 35*7c478bd9Sstevel@tonic-gate * contributors. 36*7c478bd9Sstevel@tonic-gate */ 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * rpcb_svc.c 42*7c478bd9Sstevel@tonic-gate * The server procedure for the version 3 rpcbind (TLI). 43*7c478bd9Sstevel@tonic-gate * 44*7c478bd9Sstevel@tonic-gate * It maintains a separate list of all the registered services with the 45*7c478bd9Sstevel@tonic-gate * version 3 of rpcbind. 46*7c478bd9Sstevel@tonic-gate */ 47*7c478bd9Sstevel@tonic-gate #include <stdio.h> 48*7c478bd9Sstevel@tonic-gate #include <strings.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 50*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 51*7c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h> 52*7c478bd9Sstevel@tonic-gate #include <netconfig.h> 53*7c478bd9Sstevel@tonic-gate #include <syslog.h> 54*7c478bd9Sstevel@tonic-gate #include <netdir.h> 55*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 56*7c478bd9Sstevel@tonic-gate #include "rpcbind.h" 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * Called by svc_getreqset. There is a separate server handle for 60*7c478bd9Sstevel@tonic-gate * every transport that it waits on. 61*7c478bd9Sstevel@tonic-gate */ 62*7c478bd9Sstevel@tonic-gate void 63*7c478bd9Sstevel@tonic-gate rpcb_service_3(rqstp, transp) 64*7c478bd9Sstevel@tonic-gate register struct svc_req *rqstp; 65*7c478bd9Sstevel@tonic-gate register SVCXPRT *transp; 66*7c478bd9Sstevel@tonic-gate { 67*7c478bd9Sstevel@tonic-gate union { 68*7c478bd9Sstevel@tonic-gate RPCB rpcbproc_set_3_arg; 69*7c478bd9Sstevel@tonic-gate RPCB rpcbproc_unset_3_arg; 70*7c478bd9Sstevel@tonic-gate RPCB rpcbproc_getaddr_3_arg; 71*7c478bd9Sstevel@tonic-gate struct rpcb_rmtcallargs rpcbproc_callit_3_arg; 72*7c478bd9Sstevel@tonic-gate char *rpcbproc_uaddr2taddr_3_arg; 73*7c478bd9Sstevel@tonic-gate struct netbuf rpcbproc_taddr2uaddr_3_arg; 74*7c478bd9Sstevel@tonic-gate } argument; 75*7c478bd9Sstevel@tonic-gate char *result; 76*7c478bd9Sstevel@tonic-gate bool_t (*xdr_argument)(), (*xdr_result)(); 77*7c478bd9Sstevel@tonic-gate char *(*local)(); 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate rpcbs_procinfo((ulong_t)RPCBVERS_3_STAT, rqstp->rq_proc); 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate RPCB_CHECK(transp, rqstp->rq_proc); 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) { 84*7c478bd9Sstevel@tonic-gate case NULLPROC: 85*7c478bd9Sstevel@tonic-gate /* 86*7c478bd9Sstevel@tonic-gate * Null proc call 87*7c478bd9Sstevel@tonic-gate */ 88*7c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 89*7c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_NULL\n"); 90*7c478bd9Sstevel@tonic-gate #endif 91*7c478bd9Sstevel@tonic-gate (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL); 92*7c478bd9Sstevel@tonic-gate return; 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate case RPCBPROC_SET: 95*7c478bd9Sstevel@tonic-gate /* 96*7c478bd9Sstevel@tonic-gate * Check to see whether the message came from 97*7c478bd9Sstevel@tonic-gate * loopback transports (for security reasons) 98*7c478bd9Sstevel@tonic-gate */ 99*7c478bd9Sstevel@tonic-gate if (strcasecmp(transp->xp_netid, loopback_dg) && 100*7c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc) && 101*7c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc_ord)) { 102*7c478bd9Sstevel@tonic-gate char *uaddr; 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid), 105*7c478bd9Sstevel@tonic-gate svc_getrpccaller(transp)); 106*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "non-local attempt to set from %s", 107*7c478bd9Sstevel@tonic-gate uaddr); 108*7c478bd9Sstevel@tonic-gate free(uaddr); 109*7c478bd9Sstevel@tonic-gate svcerr_weakauth(transp); 110*7c478bd9Sstevel@tonic-gate return; 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 113*7c478bd9Sstevel@tonic-gate xdr_result = xdr_bool; 114*7c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_set_com; 115*7c478bd9Sstevel@tonic-gate break; 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate case RPCBPROC_UNSET: 118*7c478bd9Sstevel@tonic-gate /* 119*7c478bd9Sstevel@tonic-gate * Check to see whether the message came from 120*7c478bd9Sstevel@tonic-gate * loopback transports (for security reasons) 121*7c478bd9Sstevel@tonic-gate */ 122*7c478bd9Sstevel@tonic-gate if (strcasecmp(transp->xp_netid, loopback_dg) && 123*7c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc) && 124*7c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc_ord)) { 125*7c478bd9Sstevel@tonic-gate char *uaddr; 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid), 128*7c478bd9Sstevel@tonic-gate svc_getrpccaller(transp)); 129*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "non-local attempt to unset from %s", 130*7c478bd9Sstevel@tonic-gate uaddr); 131*7c478bd9Sstevel@tonic-gate free(uaddr); 132*7c478bd9Sstevel@tonic-gate svcerr_weakauth(transp); 133*7c478bd9Sstevel@tonic-gate return; 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 136*7c478bd9Sstevel@tonic-gate xdr_result = xdr_bool; 137*7c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_unset_com; 138*7c478bd9Sstevel@tonic-gate break; 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate case RPCBPROC_GETADDR: 141*7c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 142*7c478bd9Sstevel@tonic-gate xdr_result = xdr_wrapstring; 143*7c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_getaddr_3; 144*7c478bd9Sstevel@tonic-gate break; 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate case RPCBPROC_DUMP: 147*7c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 148*7c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_DUMP\n"); 149*7c478bd9Sstevel@tonic-gate #endif 150*7c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 151*7c478bd9Sstevel@tonic-gate xdr_result = xdr_rpcblist_ptr; 152*7c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_dump_3; 153*7c478bd9Sstevel@tonic-gate break; 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate case RPCBPROC_CALLIT: 156*7c478bd9Sstevel@tonic-gate rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS); 157*7c478bd9Sstevel@tonic-gate return; 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate case RPCBPROC_GETTIME: 160*7c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 161*7c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_GETTIME\n"); 162*7c478bd9Sstevel@tonic-gate #endif 163*7c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 164*7c478bd9Sstevel@tonic-gate xdr_result = xdr_u_long; 165*7c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_gettime_com; 166*7c478bd9Sstevel@tonic-gate break; 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate case RPCBPROC_UADDR2TADDR: 169*7c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 170*7c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_UADDR2TADDR\n"); 171*7c478bd9Sstevel@tonic-gate #endif 172*7c478bd9Sstevel@tonic-gate xdr_argument = xdr_wrapstring; 173*7c478bd9Sstevel@tonic-gate xdr_result = xdr_netbuf; 174*7c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_uaddr2taddr_com; 175*7c478bd9Sstevel@tonic-gate break; 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate case RPCBPROC_TADDR2UADDR: 178*7c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 179*7c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_TADDR2UADDR\n"); 180*7c478bd9Sstevel@tonic-gate #endif 181*7c478bd9Sstevel@tonic-gate xdr_argument = xdr_netbuf; 182*7c478bd9Sstevel@tonic-gate xdr_result = xdr_wrapstring; 183*7c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_taddr2uaddr_com; 184*7c478bd9Sstevel@tonic-gate break; 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate default: 187*7c478bd9Sstevel@tonic-gate svcerr_noproc(transp); 188*7c478bd9Sstevel@tonic-gate return; 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate (void) memset((char *)&argument, 0, sizeof (argument)); 191*7c478bd9Sstevel@tonic-gate if (!svc_getargs(transp, (xdrproc_t)xdr_argument, 192*7c478bd9Sstevel@tonic-gate (char *)&argument)) { 193*7c478bd9Sstevel@tonic-gate svcerr_decode(transp); 194*7c478bd9Sstevel@tonic-gate if (debugging) 195*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "rpcbind: could not decode\n"); 196*7c478bd9Sstevel@tonic-gate return; 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate result = (*local)(&argument, rqstp, transp, RPCBVERS); 199*7c478bd9Sstevel@tonic-gate if (result != NULL && !svc_sendreply(transp, (xdrproc_t)xdr_result, 200*7c478bd9Sstevel@tonic-gate result)) { 201*7c478bd9Sstevel@tonic-gate svcerr_systemerr(transp); 202*7c478bd9Sstevel@tonic-gate if (debugging) { 203*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "rpcbind: svc_sendreply\n"); 204*7c478bd9Sstevel@tonic-gate if (doabort) { 205*7c478bd9Sstevel@tonic-gate rpcbind_abort(); 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate } 208*7c478bd9Sstevel@tonic-gate } 209*7c478bd9Sstevel@tonic-gate if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *) 210*7c478bd9Sstevel@tonic-gate &argument)) { 211*7c478bd9Sstevel@tonic-gate if (debugging) { 212*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "unable to free arguments\n"); 213*7c478bd9Sstevel@tonic-gate if (doabort) { 214*7c478bd9Sstevel@tonic-gate rpcbind_abort(); 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate } 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate /* 221*7c478bd9Sstevel@tonic-gate * Lookup the mapping for a program, version and return its 222*7c478bd9Sstevel@tonic-gate * address. Assuming that the caller wants the address of the 223*7c478bd9Sstevel@tonic-gate * server running on the transport on which the request came. 224*7c478bd9Sstevel@tonic-gate * 225*7c478bd9Sstevel@tonic-gate * We also try to resolve the universal address in terms of 226*7c478bd9Sstevel@tonic-gate * address of the caller. 227*7c478bd9Sstevel@tonic-gate */ 228*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 229*7c478bd9Sstevel@tonic-gate static char ** 230*7c478bd9Sstevel@tonic-gate rpcbproc_getaddr_3(regp, rqstp, transp) 231*7c478bd9Sstevel@tonic-gate RPCB *regp; 232*7c478bd9Sstevel@tonic-gate struct svc_req *rqstp; /* Not used here */ 233*7c478bd9Sstevel@tonic-gate SVCXPRT *transp; 234*7c478bd9Sstevel@tonic-gate { 235*7c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 236*7c478bd9Sstevel@tonic-gate char *uaddr; 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid), 239*7c478bd9Sstevel@tonic-gate svc_getrpccaller(transp)); 240*7c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCB_GETADDR request for (%lu, %lu, %s) from %s : ", 241*7c478bd9Sstevel@tonic-gate regp->r_prog, regp->r_vers, transp->xp_netid, uaddr); 242*7c478bd9Sstevel@tonic-gate free(uaddr); 243*7c478bd9Sstevel@tonic-gate #endif 244*7c478bd9Sstevel@tonic-gate return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS, 245*7c478bd9Sstevel@tonic-gate (ulong_t)RPCB_ALLVERS)); 246*7c478bd9Sstevel@tonic-gate } 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 249*7c478bd9Sstevel@tonic-gate static rpcblist_ptr * 250*7c478bd9Sstevel@tonic-gate rpcbproc_dump_3() 251*7c478bd9Sstevel@tonic-gate { 252*7c478bd9Sstevel@tonic-gate return ((rpcblist_ptr *)&list_rbl); 253*7c478bd9Sstevel@tonic-gate } 254