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 /*
2386632942Sssdevi * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
26*c6b31111SMarcel Telka /*
27*c6b31111SMarcel Telka * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
28*c6b31111SMarcel Telka */
297c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
307c478bd9Sstevel@tonic-gate /* All Rights Reserved */
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
337c478bd9Sstevel@tonic-gate * The Regents of the University of California
347c478bd9Sstevel@tonic-gate * All Rights Reserved
357c478bd9Sstevel@tonic-gate *
367c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
377c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
387c478bd9Sstevel@tonic-gate * contributors.
397c478bd9Sstevel@tonic-gate */
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate * rpcb_svc.c
437c478bd9Sstevel@tonic-gate * The server procedure for the version 3 rpcbind (TLI).
447c478bd9Sstevel@tonic-gate *
457c478bd9Sstevel@tonic-gate * It maintains a separate list of all the registered services with the
467c478bd9Sstevel@tonic-gate * version 3 of rpcbind.
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate #include <stdio.h>
497c478bd9Sstevel@tonic-gate #include <strings.h>
507c478bd9Sstevel@tonic-gate #include <sys/types.h>
517c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
527c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h>
537c478bd9Sstevel@tonic-gate #include <netconfig.h>
547c478bd9Sstevel@tonic-gate #include <syslog.h>
557c478bd9Sstevel@tonic-gate #include <netdir.h>
567c478bd9Sstevel@tonic-gate #include <stdlib.h>
577c478bd9Sstevel@tonic-gate #include "rpcbind.h"
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate * Called by svc_getreqset. There is a separate server handle for
617c478bd9Sstevel@tonic-gate * every transport that it waits on.
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate void
rpcb_service_3(struct svc_req * rqstp,SVCXPRT * transp)64*c6b31111SMarcel Telka rpcb_service_3(struct svc_req *rqstp, SVCXPRT *transp)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate union {
67*c6b31111SMarcel Telka rpcb rpcbproc_set_3_arg;
68*c6b31111SMarcel Telka rpcb rpcbproc_unset_3_arg;
69*c6b31111SMarcel Telka rpcb rpcbproc_getaddr_3_arg;
70*c6b31111SMarcel Telka rpcb_rmtcallargs rpcbproc_callit_3_arg;
717c478bd9Sstevel@tonic-gate char *rpcbproc_uaddr2taddr_3_arg;
727c478bd9Sstevel@tonic-gate struct netbuf rpcbproc_taddr2uaddr_3_arg;
737c478bd9Sstevel@tonic-gate } argument;
74*c6b31111SMarcel Telka union {
75*c6b31111SMarcel Telka bool_t rpcbproc_set_3_res;
76*c6b31111SMarcel Telka bool_t rpcbproc_unset_3_res;
77*c6b31111SMarcel Telka char *rpcbproc_getaddr_3_res;
78*c6b31111SMarcel Telka rpcblist_ptr *rpcbproc_dump_3_res;
79*c6b31111SMarcel Telka ulong_t rpcbproc_gettime_3_res;
80*c6b31111SMarcel Telka struct netbuf rpcbproc_uaddr2taddr_3_res;
81*c6b31111SMarcel Telka char *rpcbproc_taddr2uaddr_3_res;
82*c6b31111SMarcel Telka } result;
83*c6b31111SMarcel Telka bool_t retval;
84*c6b31111SMarcel Telka xdrproc_t xdr_argument, xdr_result;
85*c6b31111SMarcel Telka bool_t (*local)();
867c478bd9Sstevel@tonic-gate
87*c6b31111SMarcel Telka rpcbs_procinfo(RPCBVERS_3_STAT, rqstp->rq_proc);
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate RPCB_CHECK(transp, rqstp->rq_proc);
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate switch (rqstp->rq_proc) {
927c478bd9Sstevel@tonic-gate case NULLPROC:
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate * Null proc call
957c478bd9Sstevel@tonic-gate */
967c478bd9Sstevel@tonic-gate (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
977c478bd9Sstevel@tonic-gate return;
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate case RPCBPROC_SET:
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate * Check to see whether the message came from
1027c478bd9Sstevel@tonic-gate * loopback transports (for security reasons)
1037c478bd9Sstevel@tonic-gate */
1047c478bd9Sstevel@tonic-gate if (strcasecmp(transp->xp_netid, loopback_dg) &&
1057c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc) &&
1067c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc_ord)) {
1077c478bd9Sstevel@tonic-gate char *uaddr;
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
1107c478bd9Sstevel@tonic-gate svc_getrpccaller(transp));
1117c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "non-local attempt to set from %s",
112*c6b31111SMarcel Telka uaddr == NULL ? "<unknown>" : uaddr);
1137c478bd9Sstevel@tonic-gate free(uaddr);
1147c478bd9Sstevel@tonic-gate svcerr_weakauth(transp);
1157c478bd9Sstevel@tonic-gate return;
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb;
1187c478bd9Sstevel@tonic-gate xdr_result = xdr_bool;
119*c6b31111SMarcel Telka local = (bool_t (*)()) rpcbproc_set_com;
1207c478bd9Sstevel@tonic-gate break;
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate case RPCBPROC_UNSET:
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * Check to see whether the message came from
1257c478bd9Sstevel@tonic-gate * loopback transports (for security reasons)
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate if (strcasecmp(transp->xp_netid, loopback_dg) &&
1287c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc) &&
1297c478bd9Sstevel@tonic-gate strcasecmp(transp->xp_netid, loopback_vc_ord)) {
1307c478bd9Sstevel@tonic-gate char *uaddr;
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
1337c478bd9Sstevel@tonic-gate svc_getrpccaller(transp));
1347c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "non-local attempt to unset from %s",
135*c6b31111SMarcel Telka uaddr == NULL ? "<unknown>" : uaddr);
1367c478bd9Sstevel@tonic-gate free(uaddr);
1377c478bd9Sstevel@tonic-gate svcerr_weakauth(transp);
1387c478bd9Sstevel@tonic-gate return;
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb;
1417c478bd9Sstevel@tonic-gate xdr_result = xdr_bool;
142*c6b31111SMarcel Telka local = (bool_t (*)()) rpcbproc_unset_com;
1437c478bd9Sstevel@tonic-gate break;
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate case RPCBPROC_GETADDR:
1467c478bd9Sstevel@tonic-gate xdr_argument = xdr_rpcb;
1477c478bd9Sstevel@tonic-gate xdr_result = xdr_wrapstring;
148*c6b31111SMarcel Telka local = (bool_t (*)()) rpcbproc_getaddr_com;
1497c478bd9Sstevel@tonic-gate break;
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate case RPCBPROC_DUMP:
1527c478bd9Sstevel@tonic-gate xdr_argument = xdr_void;
153*c6b31111SMarcel Telka xdr_result = xdr_rpcblist_ptr_ptr;
154*c6b31111SMarcel Telka local = (bool_t (*)()) rpcbproc_dump_com;
1557c478bd9Sstevel@tonic-gate break;
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate case RPCBPROC_CALLIT:
1587c478bd9Sstevel@tonic-gate rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS);
1597c478bd9Sstevel@tonic-gate return;
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate case RPCBPROC_GETTIME:
1627c478bd9Sstevel@tonic-gate xdr_argument = xdr_void;
1637c478bd9Sstevel@tonic-gate xdr_result = xdr_u_long;
164*c6b31111SMarcel Telka local = (bool_t (*)()) rpcbproc_gettime_com;
1657c478bd9Sstevel@tonic-gate break;
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate case RPCBPROC_UADDR2TADDR:
1687c478bd9Sstevel@tonic-gate xdr_argument = xdr_wrapstring;
1697c478bd9Sstevel@tonic-gate xdr_result = xdr_netbuf;
170*c6b31111SMarcel Telka local = (bool_t (*)()) rpcbproc_uaddr2taddr_com;
1717c478bd9Sstevel@tonic-gate break;
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate case RPCBPROC_TADDR2UADDR:
1747c478bd9Sstevel@tonic-gate xdr_argument = xdr_netbuf;
1757c478bd9Sstevel@tonic-gate xdr_result = xdr_wrapstring;
176*c6b31111SMarcel Telka local = (bool_t (*)()) rpcbproc_taddr2uaddr_com;
1777c478bd9Sstevel@tonic-gate break;
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate default:
1807c478bd9Sstevel@tonic-gate svcerr_noproc(transp);
1817c478bd9Sstevel@tonic-gate return;
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate (void) memset((char *)&argument, 0, sizeof (argument));
184*c6b31111SMarcel Telka if (!svc_getargs(transp, xdr_argument, (char *)&argument)) {
1857c478bd9Sstevel@tonic-gate svcerr_decode(transp);
1867c478bd9Sstevel@tonic-gate if (debugging)
1877c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "rpcbind: could not decode\n");
1887c478bd9Sstevel@tonic-gate return;
1897c478bd9Sstevel@tonic-gate }
190*c6b31111SMarcel Telka retval = (*local)(&argument, &result, rqstp, RPCBVERS);
191*c6b31111SMarcel Telka if (retval > 0 && !svc_sendreply(transp, xdr_result, (char *)&result)) {
1927c478bd9Sstevel@tonic-gate svcerr_systemerr(transp);
1937c478bd9Sstevel@tonic-gate if (debugging) {
1947c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "rpcbind: svc_sendreply\n");
1957c478bd9Sstevel@tonic-gate if (doabort) {
1967c478bd9Sstevel@tonic-gate rpcbind_abort();
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate }
200*c6b31111SMarcel Telka if (!svc_freeargs(transp, xdr_argument, (char *)&argument)) {
2017c478bd9Sstevel@tonic-gate if (debugging) {
2027c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "unable to free arguments\n");
2037c478bd9Sstevel@tonic-gate if (doabort) {
2047c478bd9Sstevel@tonic-gate rpcbind_abort();
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate
209*c6b31111SMarcel Telka xdr_free(xdr_result, (char *)&result);
2107c478bd9Sstevel@tonic-gate }
211