18360efbdSAlfred Perlstein /* $NetBSD: rpcb_svc.c,v 1.1 2000/06/02 23:15:41 fvdl Exp $ */
28360efbdSAlfred Perlstein
3a7c51fa1SHiroki Sato /*-
48a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
58a16b7a1SPedro F. Giffuni *
6a7c51fa1SHiroki Sato * Copyright (c) 2009, Sun Microsystems, Inc.
7a7c51fa1SHiroki Sato * All rights reserved.
88360efbdSAlfred Perlstein *
9a7c51fa1SHiroki Sato * Redistribution and use in source and binary forms, with or without
10a7c51fa1SHiroki Sato * modification, are permitted provided that the following conditions are met:
11a7c51fa1SHiroki Sato * - Redistributions of source code must retain the above copyright notice,
12a7c51fa1SHiroki Sato * this list of conditions and the following disclaimer.
13a7c51fa1SHiroki Sato * - Redistributions in binary form must reproduce the above copyright notice,
14a7c51fa1SHiroki Sato * this list of conditions and the following disclaimer in the documentation
15a7c51fa1SHiroki Sato * and/or other materials provided with the distribution.
16a7c51fa1SHiroki Sato * - Neither the name of Sun Microsystems, Inc. nor the names of its
17a7c51fa1SHiroki Sato * contributors may be used to endorse or promote products derived
18a7c51fa1SHiroki Sato * from this software without specific prior written permission.
198360efbdSAlfred Perlstein *
20a7c51fa1SHiroki Sato * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21a7c51fa1SHiroki Sato * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22a7c51fa1SHiroki Sato * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23a7c51fa1SHiroki Sato * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24a7c51fa1SHiroki Sato * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25a7c51fa1SHiroki Sato * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26a7c51fa1SHiroki Sato * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27a7c51fa1SHiroki Sato * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28a7c51fa1SHiroki Sato * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29a7c51fa1SHiroki Sato * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30a7c51fa1SHiroki Sato * POSSIBILITY OF SUCH DAMAGE.
318360efbdSAlfred Perlstein */
328360efbdSAlfred Perlstein /*
338360efbdSAlfred Perlstein * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
348360efbdSAlfred Perlstein */
358360efbdSAlfred Perlstein
368360efbdSAlfred Perlstein /*
378360efbdSAlfred Perlstein * rpcb_svc.c
388360efbdSAlfred Perlstein * The server procedure for the version 3 rpcbind (TLI).
398360efbdSAlfred Perlstein *
408360efbdSAlfred Perlstein * It maintains a separate list of all the registered services with the
418360efbdSAlfred Perlstein * version 3 of rpcbind.
428360efbdSAlfred Perlstein */
438360efbdSAlfred Perlstein #include <sys/types.h>
448360efbdSAlfred Perlstein #include <rpc/rpc.h>
458360efbdSAlfred Perlstein #include <rpc/rpcb_prot.h>
468360efbdSAlfred Perlstein #include <netconfig.h>
478360efbdSAlfred Perlstein #include <stdio.h>
48*c5814cf6SHiroki Sato #ifdef RPCBIND_DEBUG
49*c5814cf6SHiroki Sato #include <stdlib.h>
50*c5814cf6SHiroki Sato #endif
518360efbdSAlfred Perlstein #include <string.h>
528360efbdSAlfred Perlstein
538360efbdSAlfred Perlstein #include "rpcbind.h"
548360efbdSAlfred Perlstein
55784bddbcSKevin Lo static void *rpcbproc_getaddr_3_local(void *, struct svc_req *, SVCXPRT *,
56784bddbcSKevin Lo rpcvers_t);
57784bddbcSKevin Lo static void *rpcbproc_dump_3_local(void *, struct svc_req *, SVCXPRT *,
58784bddbcSKevin Lo rpcvers_t);
598360efbdSAlfred Perlstein
608360efbdSAlfred Perlstein /*
618360efbdSAlfred Perlstein * Called by svc_getreqset. There is a separate server handle for
628360efbdSAlfred Perlstein * every transport that it waits on.
638360efbdSAlfred Perlstein */
648360efbdSAlfred Perlstein void
rpcb_service_3(struct svc_req * rqstp,SVCXPRT * transp)658360efbdSAlfred Perlstein rpcb_service_3(struct svc_req *rqstp, SVCXPRT *transp)
668360efbdSAlfred Perlstein {
678360efbdSAlfred Perlstein union {
688360efbdSAlfred Perlstein RPCB rpcbproc_set_3_arg;
698360efbdSAlfred Perlstein RPCB rpcbproc_unset_3_arg;
708360efbdSAlfred Perlstein RPCB rpcbproc_getaddr_3_local_arg;
718360efbdSAlfred Perlstein struct rpcb_rmtcallargs rpcbproc_callit_3_arg;
728360efbdSAlfred Perlstein char *rpcbproc_uaddr2taddr_3_arg;
738360efbdSAlfred Perlstein struct netbuf rpcbproc_taddr2uaddr_3_arg;
748360efbdSAlfred Perlstein } argument;
758360efbdSAlfred Perlstein char *result;
768360efbdSAlfred Perlstein xdrproc_t xdr_argument, xdr_result;
77784bddbcSKevin Lo void *(*local)(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
788360efbdSAlfred Perlstein
798360efbdSAlfred Perlstein rpcbs_procinfo(RPCBVERS_3_STAT, rqstp->rq_proc);
808360efbdSAlfred Perlstein
818360efbdSAlfred Perlstein switch (rqstp->rq_proc) {
828360efbdSAlfred Perlstein case NULLPROC:
838360efbdSAlfred Perlstein /*
848360efbdSAlfred Perlstein * Null proc call
858360efbdSAlfred Perlstein */
868360efbdSAlfred Perlstein #ifdef RPCBIND_DEBUG
878360efbdSAlfred Perlstein if (debugging)
888360efbdSAlfred Perlstein fprintf(stderr, "RPCBPROC_NULL\n");
898360efbdSAlfred Perlstein #endif
908360efbdSAlfred Perlstein /* This call just logs, no actual checks */
918360efbdSAlfred Perlstein check_access(transp, rqstp->rq_proc, NULL, RPCBVERS);
928360efbdSAlfred Perlstein (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
938360efbdSAlfred Perlstein return;
948360efbdSAlfred Perlstein
958360efbdSAlfred Perlstein case RPCBPROC_SET:
968360efbdSAlfred Perlstein xdr_argument = (xdrproc_t )xdr_rpcb;
978360efbdSAlfred Perlstein xdr_result = (xdrproc_t )xdr_bool;
988360efbdSAlfred Perlstein local = rpcbproc_set_com;
998360efbdSAlfred Perlstein break;
1008360efbdSAlfred Perlstein
1018360efbdSAlfred Perlstein case RPCBPROC_UNSET:
1028360efbdSAlfred Perlstein xdr_argument = (xdrproc_t)xdr_rpcb;
1038360efbdSAlfred Perlstein xdr_result = (xdrproc_t)xdr_bool;
1048360efbdSAlfred Perlstein local = rpcbproc_unset_com;
1058360efbdSAlfred Perlstein break;
1068360efbdSAlfred Perlstein
1078360efbdSAlfred Perlstein case RPCBPROC_GETADDR:
1088360efbdSAlfred Perlstein xdr_argument = (xdrproc_t)xdr_rpcb;
1098360efbdSAlfred Perlstein xdr_result = (xdrproc_t)xdr_wrapstring;
1108360efbdSAlfred Perlstein local = rpcbproc_getaddr_3_local;
1118360efbdSAlfred Perlstein break;
1128360efbdSAlfred Perlstein
1138360efbdSAlfred Perlstein case RPCBPROC_DUMP:
1148360efbdSAlfred Perlstein #ifdef RPCBIND_DEBUG
1158360efbdSAlfred Perlstein if (debugging)
1168360efbdSAlfred Perlstein fprintf(stderr, "RPCBPROC_DUMP\n");
1178360efbdSAlfred Perlstein #endif
1188360efbdSAlfred Perlstein xdr_argument = (xdrproc_t)xdr_void;
1198360efbdSAlfred Perlstein xdr_result = (xdrproc_t)xdr_rpcblist_ptr;
1208360efbdSAlfred Perlstein local = rpcbproc_dump_3_local;
1218360efbdSAlfred Perlstein break;
1228360efbdSAlfred Perlstein
1238360efbdSAlfred Perlstein case RPCBPROC_CALLIT:
1248360efbdSAlfred Perlstein rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS);
1258360efbdSAlfred Perlstein return;
1268360efbdSAlfred Perlstein
1278360efbdSAlfred Perlstein case RPCBPROC_GETTIME:
1288360efbdSAlfred Perlstein #ifdef RPCBIND_DEBUG
1298360efbdSAlfred Perlstein if (debugging)
1308360efbdSAlfred Perlstein fprintf(stderr, "RPCBPROC_GETTIME\n");
1318360efbdSAlfred Perlstein #endif
1328360efbdSAlfred Perlstein xdr_argument = (xdrproc_t)xdr_void;
1338360efbdSAlfred Perlstein xdr_result = (xdrproc_t)xdr_u_long;
1348360efbdSAlfred Perlstein local = rpcbproc_gettime_com;
1358360efbdSAlfred Perlstein break;
1368360efbdSAlfred Perlstein
1378360efbdSAlfred Perlstein case RPCBPROC_UADDR2TADDR:
1388360efbdSAlfred Perlstein #ifdef RPCBIND_DEBUG
1398360efbdSAlfred Perlstein if (debugging)
1408360efbdSAlfred Perlstein fprintf(stderr, "RPCBPROC_UADDR2TADDR\n");
1418360efbdSAlfred Perlstein #endif
1428360efbdSAlfred Perlstein xdr_argument = (xdrproc_t)xdr_wrapstring;
1438360efbdSAlfred Perlstein xdr_result = (xdrproc_t)xdr_netbuf;
1448360efbdSAlfred Perlstein local = rpcbproc_uaddr2taddr_com;
1458360efbdSAlfred Perlstein break;
1468360efbdSAlfred Perlstein
1478360efbdSAlfred Perlstein case RPCBPROC_TADDR2UADDR:
1488360efbdSAlfred Perlstein #ifdef RPCBIND_DEBUG
1498360efbdSAlfred Perlstein if (debugging)
1508360efbdSAlfred Perlstein fprintf(stderr, "RPCBPROC_TADDR2UADDR\n");
1518360efbdSAlfred Perlstein #endif
1528360efbdSAlfred Perlstein xdr_argument = (xdrproc_t)xdr_netbuf;
1538360efbdSAlfred Perlstein xdr_result = (xdrproc_t)xdr_wrapstring;
1548360efbdSAlfred Perlstein local = rpcbproc_taddr2uaddr_com;
1558360efbdSAlfred Perlstein break;
1568360efbdSAlfred Perlstein
1578360efbdSAlfred Perlstein default:
1588360efbdSAlfred Perlstein svcerr_noproc(transp);
1598360efbdSAlfred Perlstein return;
1608360efbdSAlfred Perlstein }
1618360efbdSAlfred Perlstein (void) memset((char *)&argument, 0, sizeof (argument));
1628360efbdSAlfred Perlstein if (!svc_getargs(transp, (xdrproc_t) xdr_argument,
1638360efbdSAlfred Perlstein (char *) &argument)) {
1648360efbdSAlfred Perlstein svcerr_decode(transp);
1658360efbdSAlfred Perlstein if (debugging)
1668360efbdSAlfred Perlstein (void) fprintf(stderr, "rpcbind: could not decode\n");
1678360efbdSAlfred Perlstein return;
1688360efbdSAlfred Perlstein }
1698360efbdSAlfred Perlstein if (!check_access(transp, rqstp->rq_proc, &argument, RPCBVERS)) {
1708360efbdSAlfred Perlstein svcerr_weakauth(transp);
1718360efbdSAlfred Perlstein goto done;
1728360efbdSAlfred Perlstein }
1738360efbdSAlfred Perlstein result = (*local)(&argument, rqstp, transp, RPCBVERS);
1748360efbdSAlfred Perlstein if (result != NULL && !svc_sendreply(transp, (xdrproc_t)xdr_result,
1758360efbdSAlfred Perlstein result)) {
1768360efbdSAlfred Perlstein svcerr_systemerr(transp);
1778360efbdSAlfred Perlstein if (debugging) {
1788360efbdSAlfred Perlstein (void) fprintf(stderr, "rpcbind: svc_sendreply\n");
1798360efbdSAlfred Perlstein if (doabort) {
1808360efbdSAlfred Perlstein rpcbind_abort();
1818360efbdSAlfred Perlstein }
1828360efbdSAlfred Perlstein }
1838360efbdSAlfred Perlstein }
1848360efbdSAlfred Perlstein done:
1858360efbdSAlfred Perlstein if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)
1868360efbdSAlfred Perlstein &argument)) {
1878360efbdSAlfred Perlstein if (debugging) {
1888360efbdSAlfred Perlstein (void) fprintf(stderr, "unable to free arguments\n");
1898360efbdSAlfred Perlstein if (doabort) {
1908360efbdSAlfred Perlstein rpcbind_abort();
1918360efbdSAlfred Perlstein }
1928360efbdSAlfred Perlstein }
1938360efbdSAlfred Perlstein }
1948360efbdSAlfred Perlstein }
1958360efbdSAlfred Perlstein
1968360efbdSAlfred Perlstein /*
1978360efbdSAlfred Perlstein * Lookup the mapping for a program, version and return its
1988360efbdSAlfred Perlstein * address. Assuming that the caller wants the address of the
1998360efbdSAlfred Perlstein * server running on the transport on which the request came.
2008360efbdSAlfred Perlstein *
2018360efbdSAlfred Perlstein * We also try to resolve the universal address in terms of
2028360efbdSAlfred Perlstein * address of the caller.
2038360efbdSAlfred Perlstein */
2048360efbdSAlfred Perlstein /* ARGSUSED */
2058360efbdSAlfred Perlstein static void *
rpcbproc_getaddr_3_local(void * arg,struct svc_req * rqstp __unused,SVCXPRT * transp __unused,rpcvers_t versnum __unused)2064180788fSAlfred Perlstein rpcbproc_getaddr_3_local(void *arg, struct svc_req *rqstp __unused,
2074180788fSAlfred Perlstein SVCXPRT *transp __unused, rpcvers_t versnum __unused)
2088360efbdSAlfred Perlstein {
2098360efbdSAlfred Perlstein RPCB *regp = (RPCB *)arg;
2108360efbdSAlfred Perlstein #ifdef RPCBIND_DEBUG
2118360efbdSAlfred Perlstein if (debugging) {
2128360efbdSAlfred Perlstein char *uaddr;
2138360efbdSAlfred Perlstein
2148360efbdSAlfred Perlstein uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
2158360efbdSAlfred Perlstein svc_getrpccaller(transp));
2168360efbdSAlfred Perlstein fprintf(stderr, "RPCB_GETADDR req for (%lu, %lu, %s) from %s: ",
2178360efbdSAlfred Perlstein (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
2188360efbdSAlfred Perlstein regp->r_netid, uaddr);
2198360efbdSAlfred Perlstein free(uaddr);
2208360efbdSAlfred Perlstein }
2218360efbdSAlfred Perlstein #endif
2228360efbdSAlfred Perlstein return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS,
2238360efbdSAlfred Perlstein RPCB_ALLVERS));
2248360efbdSAlfred Perlstein }
2258360efbdSAlfred Perlstein
2268360efbdSAlfred Perlstein /* ARGSUSED */
2278360efbdSAlfred Perlstein static void *
rpcbproc_dump_3_local(void * arg __unused,struct svc_req * rqstp __unused,SVCXPRT * transp __unused,rpcvers_t versnum __unused)2284180788fSAlfred Perlstein rpcbproc_dump_3_local(void *arg __unused, struct svc_req *rqstp __unused,
2294180788fSAlfred Perlstein SVCXPRT *transp __unused, rpcvers_t versnum __unused)
2308360efbdSAlfred Perlstein {
2318360efbdSAlfred Perlstein return ((void *)&list_rbl);
2328360efbdSAlfred Perlstein }
233