2 * $NetBSD: rpcb_svc_4.c,v 1.1 2000/06/02 23:15:41 fvdl Exp $
7 * SPDX-License-Identifier: BSD-3-Clause
9 * Copyright (c) 2009, Sun Microsystems, Inc.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of Sun Microsystems, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
36 * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
39 /* #ident "@(#)rpcb_svc_4.c 1.8 93/07/05 SMI" */
43 * The server procedure for the version 4 rpcbind.
47 #include <sys/types.h>
52 #include <netconfig.h>
58 static void *rpcbproc_getaddr_4_local(void *, struct svc_req *, SVCXPRT *,
60 static void *rpcbproc_getversaddr_4_local(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
61 static void *rpcbproc_getaddrlist_4_local
62 (void *, struct svc_req *, SVCXPRT *, rpcvers_t);
63 static void free_rpcb_entry_list(rpcb_entry_list_ptr *);
64 static void *rpcbproc_dump_4_local(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
67 * Called by svc_getreqset. There is a separate server handle for
68 * every transport that it waits on.
71 rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp)
74 rpcb rpcbproc_set_4_arg;
75 rpcb rpcbproc_unset_4_arg;
76 rpcb rpcbproc_getaddr_4_local_arg;
77 char *rpcbproc_uaddr2taddr_4_arg;
78 struct netbuf rpcbproc_taddr2uaddr_4_arg;
81 xdrproc_t xdr_argument, xdr_result;
82 void *(*local)(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
84 rpcbs_procinfo(RPCBVERS_4_STAT, rqstp->rq_proc);
86 switch (rqstp->rq_proc) {
93 fprintf(stderr, "RPCBPROC_NULL\n");
95 check_access(transp, rqstp->rq_proc, NULL, RPCBVERS4);
96 (void) svc_sendreply(transp, (xdrproc_t) xdr_void,
102 * Check to see whether the message came from
103 * loopback transports (for security reasons)
105 xdr_argument = (xdrproc_t)xdr_rpcb;
106 xdr_result = (xdrproc_t)xdr_bool;
107 local = rpcbproc_set_com;
112 * Check to see whether the message came from
113 * loopback transports (for security reasons)
115 xdr_argument = (xdrproc_t)xdr_rpcb;
116 xdr_result = (xdrproc_t)xdr_bool;
117 local = rpcbproc_unset_com;
120 case RPCBPROC_GETADDR:
121 xdr_argument = (xdrproc_t)xdr_rpcb;
122 xdr_result = (xdrproc_t)xdr_wrapstring;
123 local = rpcbproc_getaddr_4_local;
126 case RPCBPROC_GETVERSADDR:
129 fprintf(stderr, "RPCBPROC_GETVERSADDR\n");
131 xdr_argument = (xdrproc_t)xdr_rpcb;
132 xdr_result = (xdrproc_t)xdr_wrapstring;
133 local = rpcbproc_getversaddr_4_local;
139 fprintf(stderr, "RPCBPROC_DUMP\n");
141 xdr_argument = (xdrproc_t)xdr_void;
142 xdr_result = (xdrproc_t)xdr_rpcblist_ptr;
143 local = rpcbproc_dump_4_local;
146 case RPCBPROC_INDIRECT:
149 fprintf(stderr, "RPCBPROC_INDIRECT\n");
151 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
154 /* case RPCBPROC_CALLIT: */
158 fprintf(stderr, "RPCBPROC_BCAST\n");
160 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
163 case RPCBPROC_GETTIME:
166 fprintf(stderr, "RPCBPROC_GETTIME\n");
168 xdr_argument = (xdrproc_t)xdr_void;
169 xdr_result = (xdrproc_t)xdr_u_long;
170 local = rpcbproc_gettime_com;
173 case RPCBPROC_UADDR2TADDR:
176 fprintf(stderr, "RPCBPROC_UADDR2TADDR\n");
178 xdr_argument = (xdrproc_t)xdr_wrapstring;
179 xdr_result = (xdrproc_t)xdr_netbuf;
180 local = rpcbproc_uaddr2taddr_com;
183 case RPCBPROC_TADDR2UADDR:
186 fprintf(stderr, "RPCBPROC_TADDR2UADDR\n");
188 xdr_argument = (xdrproc_t)xdr_netbuf;
189 xdr_result = (xdrproc_t)xdr_wrapstring;
190 local = rpcbproc_taddr2uaddr_com;
193 case RPCBPROC_GETADDRLIST:
196 fprintf(stderr, "RPCBPROC_GETADDRLIST\n");
198 xdr_argument = (xdrproc_t)xdr_rpcb;
199 xdr_result = (xdrproc_t)xdr_rpcb_entry_list_ptr;
200 local = rpcbproc_getaddrlist_4_local;
203 case RPCBPROC_GETSTAT:
206 fprintf(stderr, "RPCBPROC_GETSTAT\n");
208 xdr_argument = (xdrproc_t)xdr_void;
209 xdr_result = (xdrproc_t)xdr_rpcb_stat_byvers;
210 local = rpcbproc_getstat;
214 svcerr_noproc(transp);
217 memset((char *)&argument, 0, sizeof (argument));
218 if (!svc_getargs(transp, (xdrproc_t) xdr_argument,
219 (char *)&argument)) {
220 svcerr_decode(transp);
222 (void) fprintf(stderr, "rpcbind: could not decode\n");
225 if (!check_access(transp, rqstp->rq_proc, &argument, RPCBVERS4)) {
226 svcerr_weakauth(transp);
229 result = (*local)(&argument, rqstp, transp, RPCBVERS4);
230 if (result != NULL && !svc_sendreply(transp, (xdrproc_t) xdr_result,
232 svcerr_systemerr(transp);
234 (void) fprintf(stderr, "rpcbind: svc_sendreply\n");
241 if (!svc_freeargs(transp, (xdrproc_t) xdr_argument,
242 (char *)&argument)) {
244 (void) fprintf(stderr, "unable to free arguments\n");
254 * Lookup the mapping for a program, version and return its
255 * address. Assuming that the caller wants the address of the
256 * server running on the transport on which the request came.
257 * Even if a service with a different version number is available,
258 * it will return that address. The client should check with an
259 * clnt_call to verify whether the service is the one that is desired.
260 * We also try to resolve the universal address in terms of
261 * address of the caller.
265 rpcbproc_getaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
266 rpcvers_t rpcbversnum __unused)
268 RPCB *regp = (RPCB *)arg;
273 uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
274 svc_getrpccaller(transp));
275 fprintf(stderr, "RPCB_GETADDR req for (%lu, %lu, %s) from %s: ",
276 (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
277 regp->r_netid, uaddr);
281 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS4,
286 * Lookup the mapping for a program, version and return its
287 * address. Assuming that the caller wants the address of the
288 * server running on the transport on which the request came.
290 * We also try to resolve the universal address in terms of
291 * address of the caller.
295 rpcbproc_getversaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
296 rpcvers_t versnum __unused)
298 RPCB *regp = (RPCB *)arg;
303 uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
304 svc_getrpccaller(transp));
305 fprintf(stderr, "RPCB_GETVERSADDR rqst for (%lu, %lu, %s)"
307 (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
308 regp->r_netid, uaddr);
312 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS4,
317 * Lookup the mapping for a program, version and return the
318 * addresses for all transports in the current transport family.
319 * We return a merged address.
323 rpcbproc_getaddrlist_4_local(void *arg, struct svc_req *rqstp __unused,
324 SVCXPRT *transp, rpcvers_t versnum __unused)
326 RPCB *regp = (RPCB *)arg;
327 static rpcb_entry_list_ptr rlist;
328 register rpcblist_ptr rbl;
329 rpcb_entry_list_ptr rp, tail;
333 struct netconfig *nconf;
334 struct netconfig *reg_nconf;
335 char *saddr, *maddr = NULL;
337 free_rpcb_entry_list(&rlist);
341 reg_nconf = rpcbind_get_conf(transp->xp_netid);
342 if (reg_nconf == NULL)
344 if (*(regp->r_addr) != '\0') {
345 saddr = regp->r_addr;
351 fprintf(stderr, "r_addr: %s r_netid: %s nc_protofmly: %s\n",
352 regp->r_addr, regp->r_netid, reg_nconf->nc_protofmly);
355 for (rbl = list_rbl; rbl != NULL; rbl = rbl->rpcb_next) {
356 if ((rbl->rpcb_map.r_prog == prog) &&
357 (rbl->rpcb_map.r_vers == vers)) {
358 nconf = rpcbind_get_conf(rbl->rpcb_map.r_netid);
361 if (strcmp(nconf->nc_protofmly, reg_nconf->nc_protofmly)
363 continue; /* not same proto family */
367 fprintf(stderr, "\tmerge with: %s\n",
368 rbl->rpcb_map.r_addr);
370 if ((maddr = mergeaddr(transp, rbl->rpcb_map.r_netid,
371 rbl->rpcb_map.r_addr, saddr)) == NULL) {
374 fprintf(stderr, " FAILED\n");
377 } else if (!maddr[0]) {
380 fprintf(stderr, " SUCCEEDED, but port died - maddr: nullstring\n");
382 /* The server died. Unset this combination */
383 delete_prog(regp->r_prog);
388 fprintf(stderr, " SUCCEEDED maddr: %s\n", maddr);
393 rp = malloc(sizeof (rpcb_entry_list));
396 a = &rp->rpcb_entry_map;
398 a->r_nc_netid = nconf->nc_netid;
399 a->r_nc_semantics = nconf->nc_semantics;
400 a->r_nc_protofmly = nconf->nc_protofmly;
401 a->r_nc_proto = nconf->nc_proto;
402 rp->rpcb_entry_next = NULL;
407 tail->rpcb_entry_next = rp;
415 for (rp = rlist; rp; rp = rp->rpcb_entry_next) {
416 fprintf(stderr, "\t%s %s\n", rp->rpcb_entry_map.r_maddr,
417 rp->rpcb_entry_map.r_nc_proto);
422 * XXX: getaddrlist info is also being stuffed into getaddr.
423 * Perhaps wrong, but better than it not getting counted at all.
425 rpcbs_getaddr(RPCBVERS4 - 2, prog, vers, transp->xp_netid, maddr);
426 return (void *)&rlist;
428 fail: free_rpcb_entry_list(&rlist);
433 * Free only the allocated structure, rest is all a pointer to some
434 * other data somewhere else.
437 free_rpcb_entry_list(rpcb_entry_list_ptr *rlistp)
439 register rpcb_entry_list_ptr rbl, tmp;
441 for (rbl = *rlistp; rbl != NULL; ) {
443 rbl = rbl->rpcb_entry_next;
444 free((char *)tmp->rpcb_entry_map.r_maddr);
452 rpcbproc_dump_4_local(void *arg __unused, struct svc_req *req __unused,
453 SVCXPRT *xprt __unused, rpcvers_t versnum __unused)
455 return ((void *)&list_rbl);