1 /* $NetBSD: rpcb_svc.c,v 1.1 2000/06/02 23:15:41 fvdl Exp $ */
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (c) 2009, Sun Microsystems, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * - Neither the name of Sun Microsystems, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
37 /* #ident "@(#)rpcb_svc.c 1.16 93/07/05 SMI" */
41 * The server procedure for the version 3 rpcbind (TLI).
43 * It maintains a separate list of all the registered services with the
44 * version 3 of rpcbind.
46 #include <sys/types.h>
48 #include <rpc/rpcb_prot.h>
49 #include <netconfig.h>
58 static void *rpcbproc_getaddr_3_local(void *, struct svc_req *, SVCXPRT *,
60 static void *rpcbproc_dump_3_local(void *, struct svc_req *, SVCXPRT *,
64 * Called by svc_getreqset. There is a separate server handle for
65 * every transport that it waits on.
68 rpcb_service_3(struct svc_req *rqstp, SVCXPRT *transp)
71 RPCB rpcbproc_set_3_arg;
72 RPCB rpcbproc_unset_3_arg;
73 RPCB rpcbproc_getaddr_3_local_arg;
74 struct rpcb_rmtcallargs rpcbproc_callit_3_arg;
75 char *rpcbproc_uaddr2taddr_3_arg;
76 struct netbuf rpcbproc_taddr2uaddr_3_arg;
79 xdrproc_t xdr_argument, xdr_result;
80 void *(*local)(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
82 rpcbs_procinfo(RPCBVERS_3_STAT, rqstp->rq_proc);
84 switch (rqstp->rq_proc) {
91 fprintf(stderr, "RPCBPROC_NULL\n");
93 /* This call just logs, no actual checks */
94 check_access(transp, rqstp->rq_proc, NULL, RPCBVERS);
95 (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
99 xdr_argument = (xdrproc_t )xdr_rpcb;
100 xdr_result = (xdrproc_t )xdr_bool;
101 local = rpcbproc_set_com;
105 xdr_argument = (xdrproc_t)xdr_rpcb;
106 xdr_result = (xdrproc_t)xdr_bool;
107 local = rpcbproc_unset_com;
110 case RPCBPROC_GETADDR:
111 xdr_argument = (xdrproc_t)xdr_rpcb;
112 xdr_result = (xdrproc_t)xdr_wrapstring;
113 local = rpcbproc_getaddr_3_local;
119 fprintf(stderr, "RPCBPROC_DUMP\n");
121 xdr_argument = (xdrproc_t)xdr_void;
122 xdr_result = (xdrproc_t)xdr_rpcblist_ptr;
123 local = rpcbproc_dump_3_local;
126 case RPCBPROC_CALLIT:
127 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS);
130 case RPCBPROC_GETTIME:
133 fprintf(stderr, "RPCBPROC_GETTIME\n");
135 xdr_argument = (xdrproc_t)xdr_void;
136 xdr_result = (xdrproc_t)xdr_u_long;
137 local = rpcbproc_gettime_com;
140 case RPCBPROC_UADDR2TADDR:
143 fprintf(stderr, "RPCBPROC_UADDR2TADDR\n");
145 xdr_argument = (xdrproc_t)xdr_wrapstring;
146 xdr_result = (xdrproc_t)xdr_netbuf;
147 local = rpcbproc_uaddr2taddr_com;
150 case RPCBPROC_TADDR2UADDR:
153 fprintf(stderr, "RPCBPROC_TADDR2UADDR\n");
155 xdr_argument = (xdrproc_t)xdr_netbuf;
156 xdr_result = (xdrproc_t)xdr_wrapstring;
157 local = rpcbproc_taddr2uaddr_com;
161 svcerr_noproc(transp);
164 (void) memset((char *)&argument, 0, sizeof (argument));
165 if (!svc_getargs(transp, (xdrproc_t) xdr_argument,
166 (char *) &argument)) {
167 svcerr_decode(transp);
169 (void) fprintf(stderr, "rpcbind: could not decode\n");
172 if (!check_access(transp, rqstp->rq_proc, &argument, RPCBVERS)) {
173 svcerr_weakauth(transp);
176 result = (*local)(&argument, rqstp, transp, RPCBVERS);
177 if (result != NULL && !svc_sendreply(transp, (xdrproc_t)xdr_result,
179 svcerr_systemerr(transp);
181 (void) fprintf(stderr, "rpcbind: svc_sendreply\n");
188 if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)
191 (void) fprintf(stderr, "unable to free arguments\n");
200 * Lookup the mapping for a program, version and return its
201 * address. Assuming that the caller wants the address of the
202 * server running on the transport on which the request came.
204 * We also try to resolve the universal address in terms of
205 * address of the caller.
209 rpcbproc_getaddr_3_local(void *arg, struct svc_req *rqstp __unused,
210 SVCXPRT *transp __unused, rpcvers_t versnum __unused)
212 RPCB *regp = (RPCB *)arg;
217 uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
218 svc_getrpccaller(transp));
219 fprintf(stderr, "RPCB_GETADDR req for (%lu, %lu, %s) from %s: ",
220 (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
221 regp->r_netid, uaddr);
225 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS,
231 rpcbproc_dump_3_local(void *arg __unused, struct svc_req *rqstp __unused,
232 SVCXPRT *transp __unused, rpcvers_t versnum __unused)
234 return ((void *)&list_rbl);