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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*86632942Sssdevi * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 307c478bd9Sstevel@tonic-gate * The Regents of the University of California 317c478bd9Sstevel@tonic-gate * All Rights Reserved 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 347c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 357c478bd9Sstevel@tonic-gate * contributors. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * rpcb_svc.c 427c478bd9Sstevel@tonic-gate * The server procedure for the version 3 rpcbind (TLI). 437c478bd9Sstevel@tonic-gate * 447c478bd9Sstevel@tonic-gate * It maintains a separate list of all the registered services with the 457c478bd9Sstevel@tonic-gate * version 3 of rpcbind. 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate #include <stdio.h> 487c478bd9Sstevel@tonic-gate #include <strings.h> 497c478bd9Sstevel@tonic-gate #include <sys/types.h> 507c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 517c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h> 527c478bd9Sstevel@tonic-gate #include <netconfig.h> 537c478bd9Sstevel@tonic-gate #include <syslog.h> 547c478bd9Sstevel@tonic-gate #include <netdir.h> 557c478bd9Sstevel@tonic-gate #include <stdlib.h> 567c478bd9Sstevel@tonic-gate #include "rpcbind.h" 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * Called by svc_getreqset. There is a separate server handle for 607c478bd9Sstevel@tonic-gate * every transport that it waits on. 617c478bd9Sstevel@tonic-gate */ 627c478bd9Sstevel@tonic-gate void 637c478bd9Sstevel@tonic-gate rpcb_service_3(rqstp, transp) 647c478bd9Sstevel@tonic-gate register struct svc_req *rqstp; 657c478bd9Sstevel@tonic-gate register SVCXPRT *transp; 667c478bd9Sstevel@tonic-gate { 677c478bd9Sstevel@tonic-gate union { 687c478bd9Sstevel@tonic-gate RPCB rpcbproc_set_3_arg; 697c478bd9Sstevel@tonic-gate RPCB rpcbproc_unset_3_arg; 707c478bd9Sstevel@tonic-gate RPCB rpcbproc_getaddr_3_arg; 717c478bd9Sstevel@tonic-gate struct rpcb_rmtcallargs rpcbproc_callit_3_arg; 727c478bd9Sstevel@tonic-gate char *rpcbproc_uaddr2taddr_3_arg; 737c478bd9Sstevel@tonic-gate struct netbuf rpcbproc_taddr2uaddr_3_arg; 747c478bd9Sstevel@tonic-gate } argument; 757c478bd9Sstevel@tonic-gate char *result; 767c478bd9Sstevel@tonic-gate bool_t (*xdr_argument)(), (*xdr_result)(); 777c478bd9Sstevel@tonic-gate char *(*local)(); 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate rpcbs_procinfo((ulong_t)RPCBVERS_3_STAT, rqstp->rq_proc); 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate RPCB_CHECK(transp, rqstp->rq_proc); 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) { 847c478bd9Sstevel@tonic-gate case NULLPROC: 857c478bd9Sstevel@tonic-gate /* 867c478bd9Sstevel@tonic-gate * Null proc call 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 897c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_NULL\n"); 907c478bd9Sstevel@tonic-gate #endif 917c478bd9Sstevel@tonic-gate (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL); 927c478bd9Sstevel@tonic-gate return; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate case RPCBPROC_SET: 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * Check to see whether the message came from 977c478bd9Sstevel@tonic-gate * loopback transports (for security reasons) 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate if (strcasecmp(transp->xp_netid, loopback_dg) && 1007c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc) && 1017c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc_ord)) { 1027c478bd9Sstevel@tonic-gate char *uaddr; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid), 1057c478bd9Sstevel@tonic-gate svc_getrpccaller(transp)); 1067c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "non-local attempt to set from %s", 1077c478bd9Sstevel@tonic-gate uaddr); 1087c478bd9Sstevel@tonic-gate free(uaddr); 1097c478bd9Sstevel@tonic-gate svcerr_weakauth(transp); 1107c478bd9Sstevel@tonic-gate return; 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 1137c478bd9Sstevel@tonic-gate xdr_result = xdr_bool; 1147c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_set_com; 1157c478bd9Sstevel@tonic-gate break; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate case RPCBPROC_UNSET: 1187c478bd9Sstevel@tonic-gate /* 1197c478bd9Sstevel@tonic-gate * Check to see whether the message came from 1207c478bd9Sstevel@tonic-gate * loopback transports (for security reasons) 1217c478bd9Sstevel@tonic-gate */ 1227c478bd9Sstevel@tonic-gate if (strcasecmp(transp->xp_netid, loopback_dg) && 1237c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc) && 1247c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc_ord)) { 1257c478bd9Sstevel@tonic-gate char *uaddr; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid), 1287c478bd9Sstevel@tonic-gate svc_getrpccaller(transp)); 1297c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "non-local attempt to unset from %s", 1307c478bd9Sstevel@tonic-gate uaddr); 1317c478bd9Sstevel@tonic-gate free(uaddr); 1327c478bd9Sstevel@tonic-gate svcerr_weakauth(transp); 1337c478bd9Sstevel@tonic-gate return; 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 1367c478bd9Sstevel@tonic-gate xdr_result = xdr_bool; 1377c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_unset_com; 1387c478bd9Sstevel@tonic-gate break; 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate case RPCBPROC_GETADDR: 1417c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb; 1427c478bd9Sstevel@tonic-gate xdr_result = xdr_wrapstring; 1437c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_getaddr_3; 1447c478bd9Sstevel@tonic-gate break; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate case RPCBPROC_DUMP: 1477c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 1487c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_DUMP\n"); 1497c478bd9Sstevel@tonic-gate #endif 1507c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 1517c478bd9Sstevel@tonic-gate xdr_result = xdr_rpcblist_ptr; 1527c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_dump_3; 1537c478bd9Sstevel@tonic-gate break; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate case RPCBPROC_CALLIT: 1567c478bd9Sstevel@tonic-gate rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS); 1577c478bd9Sstevel@tonic-gate return; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate case RPCBPROC_GETTIME: 1607c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 1617c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_GETTIME\n"); 1627c478bd9Sstevel@tonic-gate #endif 1637c478bd9Sstevel@tonic-gate xdr_argument = xdr_void; 1647c478bd9Sstevel@tonic-gate xdr_result = xdr_u_long; 1657c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_gettime_com; 1667c478bd9Sstevel@tonic-gate break; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate case RPCBPROC_UADDR2TADDR: 1697c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 1707c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_UADDR2TADDR\n"); 1717c478bd9Sstevel@tonic-gate #endif 1727c478bd9Sstevel@tonic-gate xdr_argument = xdr_wrapstring; 1737c478bd9Sstevel@tonic-gate xdr_result = xdr_netbuf; 1747c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_uaddr2taddr_com; 1757c478bd9Sstevel@tonic-gate break; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate case RPCBPROC_TADDR2UADDR: 1787c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 1797c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCBPROC_TADDR2UADDR\n"); 1807c478bd9Sstevel@tonic-gate #endif 1817c478bd9Sstevel@tonic-gate xdr_argument = xdr_netbuf; 1827c478bd9Sstevel@tonic-gate xdr_result = xdr_wrapstring; 1837c478bd9Sstevel@tonic-gate local = (char *(*)()) rpcbproc_taddr2uaddr_com; 1847c478bd9Sstevel@tonic-gate break; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate default: 1877c478bd9Sstevel@tonic-gate svcerr_noproc(transp); 1887c478bd9Sstevel@tonic-gate return; 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate (void) memset((char *)&argument, 0, sizeof (argument)); 1917c478bd9Sstevel@tonic-gate if (!svc_getargs(transp, (xdrproc_t)xdr_argument, 1927c478bd9Sstevel@tonic-gate (char *)&argument)) { 1937c478bd9Sstevel@tonic-gate svcerr_decode(transp); 1947c478bd9Sstevel@tonic-gate if (debugging) 1957c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "rpcbind: could not decode\n"); 1967c478bd9Sstevel@tonic-gate return; 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate result = (*local)(&argument, rqstp, transp, RPCBVERS); 1997c478bd9Sstevel@tonic-gate if (result != NULL && !svc_sendreply(transp, (xdrproc_t)xdr_result, 2007c478bd9Sstevel@tonic-gate result)) { 2017c478bd9Sstevel@tonic-gate svcerr_systemerr(transp); 2027c478bd9Sstevel@tonic-gate if (debugging) { 2037c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "rpcbind: svc_sendreply\n"); 2047c478bd9Sstevel@tonic-gate if (doabort) { 2057c478bd9Sstevel@tonic-gate rpcbind_abort(); 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *) 2107c478bd9Sstevel@tonic-gate &argument)) { 2117c478bd9Sstevel@tonic-gate if (debugging) { 2127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "unable to free arguments\n"); 2137c478bd9Sstevel@tonic-gate if (doabort) { 2147c478bd9Sstevel@tonic-gate rpcbind_abort(); 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate /* 2217c478bd9Sstevel@tonic-gate * Lookup the mapping for a program, version and return its 2227c478bd9Sstevel@tonic-gate * address. Assuming that the caller wants the address of the 2237c478bd9Sstevel@tonic-gate * server running on the transport on which the request came. 2247c478bd9Sstevel@tonic-gate * 2257c478bd9Sstevel@tonic-gate * We also try to resolve the universal address in terms of 2267c478bd9Sstevel@tonic-gate * address of the caller. 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate /* ARGSUSED */ 229*86632942Sssdevi char ** 2307c478bd9Sstevel@tonic-gate rpcbproc_getaddr_3(regp, rqstp, transp) 2317c478bd9Sstevel@tonic-gate RPCB *regp; 2327c478bd9Sstevel@tonic-gate struct svc_req *rqstp; /* Not used here */ 2337c478bd9Sstevel@tonic-gate SVCXPRT *transp; 2347c478bd9Sstevel@tonic-gate { 2357c478bd9Sstevel@tonic-gate #ifdef RPCBIND_DEBUG 2367c478bd9Sstevel@tonic-gate char *uaddr; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid), 2397c478bd9Sstevel@tonic-gate svc_getrpccaller(transp)); 2407c478bd9Sstevel@tonic-gate fprintf(stderr, "RPCB_GETADDR request for (%lu, %lu, %s) from %s : ", 2417c478bd9Sstevel@tonic-gate regp->r_prog, regp->r_vers, transp->xp_netid, uaddr); 2427c478bd9Sstevel@tonic-gate free(uaddr); 2437c478bd9Sstevel@tonic-gate #endif 2447c478bd9Sstevel@tonic-gate return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS, 2457c478bd9Sstevel@tonic-gate (ulong_t)RPCB_ALLVERS)); 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /* ARGSUSED */ 249*86632942Sssdevi rpcblist_ptr * 2507c478bd9Sstevel@tonic-gate rpcbproc_dump_3() 2517c478bd9Sstevel@tonic-gate { 2527c478bd9Sstevel@tonic-gate return ((rpcblist_ptr *)&list_rbl); 2537c478bd9Sstevel@tonic-gate } 254