Deleted Added
full compact
rpcb_svc_4.c (173412) rpcb_svc_4.c (258564)
1/*
2 * $NetBSD: rpcb_svc_4.c,v 1.1 2000/06/02 23:15:41 fvdl Exp $
1/*
2 * $NetBSD: rpcb_svc_4.c,v 1.1 2000/06/02 23:15:41 fvdl Exp $
3 * $FreeBSD: head/usr.sbin/rpcbind/rpcb_svc_4.c 173412 2007-11-07 10:53:41Z kevlo $
3 * $FreeBSD: head/usr.sbin/rpcbind/rpcb_svc_4.c 258564 2013-11-25 16:44:02Z hrs $
4 */
5
4 */
5
6/*
7 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
8 * unrestricted use provided that this legend is included on all tape
9 * media and as a part of the software program in whole or part. Users
10 * may copy or modify Sun RPC without charge, but are not authorized
11 * to license or distribute it to anyone else except as part of a product or
12 * program developed by the user.
13 *
14 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
15 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
17 *
18 * Sun RPC is provided with no support and without any obligation on the
19 * part of Sun Microsystems, Inc. to assist in its use, correction,
20 * modification or enhancement.
21 *
22 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
23 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
24 * OR ANY PART THEREOF.
25 *
26 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
27 * or profits or other special, indirect and consequential damages, even if
28 * Sun has been advised of the possibility of such damages.
29 *
30 * Sun Microsystems, Inc.
31 * 2550 Garcia Avenue
32 * Mountain View, California 94043
6/*-
7 * Copyright (c) 2009, Sun Microsystems, Inc.
8 * All rights reserved.
9 *
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.
20 *
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.
33 */
34/*
35 * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
36 */
37
38/* #ident "@(#)rpcb_svc_4.c 1.8 93/07/05 SMI" */
39
40/*
41 * rpcb_svc_4.c
42 * The server procedure for the version 4 rpcbind.
43 *
44 */
45
46#include <sys/types.h>
47#include <sys/stat.h>
48#include <rpc/rpc.h>
49#include <stdio.h>
50#include <unistd.h>
51#include <netconfig.h>
52#include <syslog.h>
53#include <string.h>
54#include <stdlib.h>
55#include "rpcbind.h"
56
57static void *rpcbproc_getaddr_4_local(void *, struct svc_req *, SVCXPRT *,
58 rpcvers_t);
59static void *rpcbproc_getversaddr_4_local(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
60static void *rpcbproc_getaddrlist_4_local
61 (void *, struct svc_req *, SVCXPRT *, rpcvers_t);
62static void free_rpcb_entry_list(rpcb_entry_list_ptr *);
63static void *rpcbproc_dump_4_local(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
64
65/*
66 * Called by svc_getreqset. There is a separate server handle for
67 * every transport that it waits on.
68 */
69void
70rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp)
71{
72 union {
73 rpcb rpcbproc_set_4_arg;
74 rpcb rpcbproc_unset_4_arg;
75 rpcb rpcbproc_getaddr_4_local_arg;
76 char *rpcbproc_uaddr2taddr_4_arg;
77 struct netbuf rpcbproc_taddr2uaddr_4_arg;
78 } argument;
79 char *result;
80 xdrproc_t xdr_argument, xdr_result;
81 void *(*local)(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
82
83 rpcbs_procinfo(RPCBVERS_4_STAT, rqstp->rq_proc);
84
85 switch (rqstp->rq_proc) {
86 case NULLPROC:
87 /*
88 * Null proc call
89 */
90#ifdef RPCBIND_DEBUG
91 if (debugging)
92 fprintf(stderr, "RPCBPROC_NULL\n");
93#endif
94 check_access(transp, rqstp->rq_proc, NULL, RPCBVERS4);
95 (void) svc_sendreply(transp, (xdrproc_t) xdr_void,
96 (char *)NULL);
97 return;
98
99 case RPCBPROC_SET:
100 /*
101 * Check to see whether the message came from
102 * loopback transports (for security reasons)
103 */
104 xdr_argument = (xdrproc_t)xdr_rpcb;
105 xdr_result = (xdrproc_t)xdr_bool;
106 local = rpcbproc_set_com;
107 break;
108
109 case RPCBPROC_UNSET:
110 /*
111 * Check to see whether the message came from
112 * loopback transports (for security reasons)
113 */
114 xdr_argument = (xdrproc_t)xdr_rpcb;
115 xdr_result = (xdrproc_t)xdr_bool;
116 local = rpcbproc_unset_com;
117 break;
118
119 case RPCBPROC_GETADDR:
120 xdr_argument = (xdrproc_t)xdr_rpcb;
121 xdr_result = (xdrproc_t)xdr_wrapstring;
122 local = rpcbproc_getaddr_4_local;
123 break;
124
125 case RPCBPROC_GETVERSADDR:
126#ifdef RPCBIND_DEBUG
127 if (debugging)
128 fprintf(stderr, "RPCBPROC_GETVERSADDR\n");
129#endif
130 xdr_argument = (xdrproc_t)xdr_rpcb;
131 xdr_result = (xdrproc_t)xdr_wrapstring;
132 local = rpcbproc_getversaddr_4_local;
133 break;
134
135 case RPCBPROC_DUMP:
136#ifdef RPCBIND_DEBUG
137 if (debugging)
138 fprintf(stderr, "RPCBPROC_DUMP\n");
139#endif
140 xdr_argument = (xdrproc_t)xdr_void;
141 xdr_result = (xdrproc_t)xdr_rpcblist_ptr;
142 local = rpcbproc_dump_4_local;
143 break;
144
145 case RPCBPROC_INDIRECT:
146#ifdef RPCBIND_DEBUG
147 if (debugging)
148 fprintf(stderr, "RPCBPROC_INDIRECT\n");
149#endif
150 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
151 return;
152
153/* case RPCBPROC_CALLIT: */
154 case RPCBPROC_BCAST:
155#ifdef RPCBIND_DEBUG
156 if (debugging)
157 fprintf(stderr, "RPCBPROC_BCAST\n");
158#endif
159 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
160 return;
161
162 case RPCBPROC_GETTIME:
163#ifdef RPCBIND_DEBUG
164 if (debugging)
165 fprintf(stderr, "RPCBPROC_GETTIME\n");
166#endif
167 xdr_argument = (xdrproc_t)xdr_void;
168 xdr_result = (xdrproc_t)xdr_u_long;
169 local = rpcbproc_gettime_com;
170 break;
171
172 case RPCBPROC_UADDR2TADDR:
173#ifdef RPCBIND_DEBUG
174 if (debugging)
175 fprintf(stderr, "RPCBPROC_UADDR2TADDR\n");
176#endif
177 xdr_argument = (xdrproc_t)xdr_wrapstring;
178 xdr_result = (xdrproc_t)xdr_netbuf;
179 local = rpcbproc_uaddr2taddr_com;
180 break;
181
182 case RPCBPROC_TADDR2UADDR:
183#ifdef RPCBIND_DEBUG
184 if (debugging)
185 fprintf(stderr, "RPCBPROC_TADDR2UADDR\n");
186#endif
187 xdr_argument = (xdrproc_t)xdr_netbuf;
188 xdr_result = (xdrproc_t)xdr_wrapstring;
189 local = rpcbproc_taddr2uaddr_com;
190 break;
191
192 case RPCBPROC_GETADDRLIST:
193#ifdef RPCBIND_DEBUG
194 if (debugging)
195 fprintf(stderr, "RPCBPROC_GETADDRLIST\n");
196#endif
197 xdr_argument = (xdrproc_t)xdr_rpcb;
198 xdr_result = (xdrproc_t)xdr_rpcb_entry_list_ptr;
199 local = rpcbproc_getaddrlist_4_local;
200 break;
201
202 case RPCBPROC_GETSTAT:
203#ifdef RPCBIND_DEBUG
204 if (debugging)
205 fprintf(stderr, "RPCBPROC_GETSTAT\n");
206#endif
207 xdr_argument = (xdrproc_t)xdr_void;
208 xdr_result = (xdrproc_t)xdr_rpcb_stat_byvers;
209 local = rpcbproc_getstat;
210 break;
211
212 default:
213 svcerr_noproc(transp);
214 return;
215 }
216 memset((char *)&argument, 0, sizeof (argument));
217 if (!svc_getargs(transp, (xdrproc_t) xdr_argument,
218 (char *)&argument)) {
219 svcerr_decode(transp);
220 if (debugging)
221 (void) fprintf(stderr, "rpcbind: could not decode\n");
222 return;
223 }
224 if (!check_access(transp, rqstp->rq_proc, &argument, RPCBVERS4)) {
225 svcerr_weakauth(transp);
226 goto done;
227 }
228 result = (*local)(&argument, rqstp, transp, RPCBVERS4);
229 if (result != NULL && !svc_sendreply(transp, (xdrproc_t) xdr_result,
230 result)) {
231 svcerr_systemerr(transp);
232 if (debugging) {
233 (void) fprintf(stderr, "rpcbind: svc_sendreply\n");
234 if (doabort) {
235 rpcbind_abort();
236 }
237 }
238 }
239done:
240 if (!svc_freeargs(transp, (xdrproc_t) xdr_argument,
241 (char *)&argument)) {
242 if (debugging) {
243 (void) fprintf(stderr, "unable to free arguments\n");
244 if (doabort) {
245 rpcbind_abort();
246 }
247 }
248 }
249 return;
250}
251
252/*
253 * Lookup the mapping for a program, version and return its
254 * address. Assuming that the caller wants the address of the
255 * server running on the transport on which the request came.
256 * Even if a service with a different version number is available,
257 * it will return that address. The client should check with an
258 * clnt_call to verify whether the service is the one that is desired.
259 * We also try to resolve the universal address in terms of
260 * address of the caller.
261 */
262/* ARGSUSED */
263static void *
264rpcbproc_getaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
265 rpcvers_t rpcbversnum __unused)
266{
267 RPCB *regp = (RPCB *)arg;
268#ifdef RPCBIND_DEBUG
269 if (debugging) {
270 char *uaddr;
271
272 uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
273 svc_getrpccaller(transp));
274 fprintf(stderr, "RPCB_GETADDR req for (%lu, %lu, %s) from %s: ",
275 (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
276 regp->r_netid, uaddr);
277 free(uaddr);
278 }
279#endif
280 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS4,
281 RPCB_ALLVERS));
282}
283
284/*
285 * Lookup the mapping for a program, version and return its
286 * address. Assuming that the caller wants the address of the
287 * server running on the transport on which the request came.
288 *
289 * We also try to resolve the universal address in terms of
290 * address of the caller.
291 */
292/* ARGSUSED */
293static void *
294rpcbproc_getversaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
295 rpcvers_t versnum __unused)
296{
297 RPCB *regp = (RPCB *)arg;
298#ifdef RPCBIND_DEBUG
299 if (debugging) {
300 char *uaddr;
301
302 uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
303 svc_getrpccaller(transp));
304 fprintf(stderr, "RPCB_GETVERSADDR rqst for (%lu, %lu, %s)"
305 " from %s : ",
306 (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
307 regp->r_netid, uaddr);
308 free(uaddr);
309 }
310#endif
311 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS4,
312 RPCB_ONEVERS));
313}
314
315/*
316 * Lookup the mapping for a program, version and return the
317 * addresses for all transports in the current transport family.
318 * We return a merged address.
319 */
320/* ARGSUSED */
321static void *
322rpcbproc_getaddrlist_4_local(void *arg, struct svc_req *rqstp __unused,
323 SVCXPRT *transp, rpcvers_t versnum __unused)
324{
325 RPCB *regp = (RPCB *)arg;
326 static rpcb_entry_list_ptr rlist;
327 register rpcblist_ptr rbl;
328 rpcb_entry_list_ptr rp, tail;
329 rpcprog_t prog;
330 rpcvers_t vers;
331 rpcb_entry *a;
332 struct netconfig *nconf;
333 struct netconfig *reg_nconf;
334 char *saddr, *maddr = NULL;
335
336 free_rpcb_entry_list(&rlist);
337 tail = NULL;
338 prog = regp->r_prog;
339 vers = regp->r_vers;
340 reg_nconf = rpcbind_get_conf(transp->xp_netid);
341 if (reg_nconf == NULL)
342 return (NULL);
343 if (*(regp->r_addr) != '\0') {
344 saddr = regp->r_addr;
345 } else {
346 saddr = NULL;
347 }
348#ifdef RPCBIND_DEBUG
349 if (debugging) {
350 fprintf(stderr, "r_addr: %s r_netid: %s nc_protofmly: %s\n",
351 regp->r_addr, regp->r_netid, reg_nconf->nc_protofmly);
352 }
353#endif
354 for (rbl = list_rbl; rbl != NULL; rbl = rbl->rpcb_next) {
355 if ((rbl->rpcb_map.r_prog == prog) &&
356 (rbl->rpcb_map.r_vers == vers)) {
357 nconf = rpcbind_get_conf(rbl->rpcb_map.r_netid);
358 if (nconf == NULL)
359 goto fail;
360 if (strcmp(nconf->nc_protofmly, reg_nconf->nc_protofmly)
361 != 0) {
362 continue; /* not same proto family */
363 }
364#ifdef RPCBIND_DEBUG
365 if (debugging)
366 fprintf(stderr, "\tmerge with: %s\n",
367 rbl->rpcb_map.r_addr);
368#endif
369 if ((maddr = mergeaddr(transp, rbl->rpcb_map.r_netid,
370 rbl->rpcb_map.r_addr, saddr)) == NULL) {
371#ifdef RPCBIND_DEBUG
372 if (debugging)
373 fprintf(stderr, " FAILED\n");
374#endif
375 continue;
376 } else if (!maddr[0]) {
377#ifdef RPCBIND_DEBUG
378 if (debugging)
379 fprintf(stderr, " SUCCEEDED, but port died - maddr: nullstring\n");
380#endif
381 /* The server died. Unset this combination */
382 delete_prog(regp->r_prog);
383 continue;
384 }
385#ifdef RPCBIND_DEBUG
386 if (debugging)
387 fprintf(stderr, " SUCCEEDED maddr: %s\n", maddr);
388#endif
389 /*
390 * Add it to rlist.
391 */
392 rp = malloc(sizeof (rpcb_entry_list));
393 if (rp == NULL)
394 goto fail;
395 a = &rp->rpcb_entry_map;
396 a->r_maddr = maddr;
397 a->r_nc_netid = nconf->nc_netid;
398 a->r_nc_semantics = nconf->nc_semantics;
399 a->r_nc_protofmly = nconf->nc_protofmly;
400 a->r_nc_proto = nconf->nc_proto;
401 rp->rpcb_entry_next = NULL;
402 if (rlist == NULL) {
403 rlist = rp;
404 tail = rp;
405 } else {
406 tail->rpcb_entry_next = rp;
407 tail = rp;
408 }
409 rp = NULL;
410 }
411 }
412#ifdef RPCBIND_DEBUG
413 if (debugging) {
414 for (rp = rlist; rp; rp = rp->rpcb_entry_next) {
415 fprintf(stderr, "\t%s %s\n", rp->rpcb_entry_map.r_maddr,
416 rp->rpcb_entry_map.r_nc_proto);
417 }
418 }
419#endif
420 /*
421 * XXX: getaddrlist info is also being stuffed into getaddr.
422 * Perhaps wrong, but better than it not getting counted at all.
423 */
424 rpcbs_getaddr(RPCBVERS4 - 2, prog, vers, transp->xp_netid, maddr);
425 return (void *)&rlist;
426
427fail: free_rpcb_entry_list(&rlist);
428 return (NULL);
429}
430
431/*
432 * Free only the allocated structure, rest is all a pointer to some
433 * other data somewhere else.
434 */
435static void
436free_rpcb_entry_list(rpcb_entry_list_ptr *rlistp)
437{
438 register rpcb_entry_list_ptr rbl, tmp;
439
440 for (rbl = *rlistp; rbl != NULL; ) {
441 tmp = rbl;
442 rbl = rbl->rpcb_entry_next;
443 free((char *)tmp->rpcb_entry_map.r_maddr);
444 free((char *)tmp);
445 }
446 *rlistp = NULL;
447}
448
449/* ARGSUSED */
450static void *
451rpcbproc_dump_4_local(void *arg __unused, struct svc_req *req __unused,
452 SVCXPRT *xprt __unused, rpcvers_t versnum __unused)
453{
454 return ((void *)&list_rbl);
455}
32 */
33/*
34 * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
35 */
36
37/* #ident "@(#)rpcb_svc_4.c 1.8 93/07/05 SMI" */
38
39/*
40 * rpcb_svc_4.c
41 * The server procedure for the version 4 rpcbind.
42 *
43 */
44
45#include <sys/types.h>
46#include <sys/stat.h>
47#include <rpc/rpc.h>
48#include <stdio.h>
49#include <unistd.h>
50#include <netconfig.h>
51#include <syslog.h>
52#include <string.h>
53#include <stdlib.h>
54#include "rpcbind.h"
55
56static void *rpcbproc_getaddr_4_local(void *, struct svc_req *, SVCXPRT *,
57 rpcvers_t);
58static void *rpcbproc_getversaddr_4_local(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
59static void *rpcbproc_getaddrlist_4_local
60 (void *, struct svc_req *, SVCXPRT *, rpcvers_t);
61static void free_rpcb_entry_list(rpcb_entry_list_ptr *);
62static void *rpcbproc_dump_4_local(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
63
64/*
65 * Called by svc_getreqset. There is a separate server handle for
66 * every transport that it waits on.
67 */
68void
69rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp)
70{
71 union {
72 rpcb rpcbproc_set_4_arg;
73 rpcb rpcbproc_unset_4_arg;
74 rpcb rpcbproc_getaddr_4_local_arg;
75 char *rpcbproc_uaddr2taddr_4_arg;
76 struct netbuf rpcbproc_taddr2uaddr_4_arg;
77 } argument;
78 char *result;
79 xdrproc_t xdr_argument, xdr_result;
80 void *(*local)(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
81
82 rpcbs_procinfo(RPCBVERS_4_STAT, rqstp->rq_proc);
83
84 switch (rqstp->rq_proc) {
85 case NULLPROC:
86 /*
87 * Null proc call
88 */
89#ifdef RPCBIND_DEBUG
90 if (debugging)
91 fprintf(stderr, "RPCBPROC_NULL\n");
92#endif
93 check_access(transp, rqstp->rq_proc, NULL, RPCBVERS4);
94 (void) svc_sendreply(transp, (xdrproc_t) xdr_void,
95 (char *)NULL);
96 return;
97
98 case RPCBPROC_SET:
99 /*
100 * Check to see whether the message came from
101 * loopback transports (for security reasons)
102 */
103 xdr_argument = (xdrproc_t)xdr_rpcb;
104 xdr_result = (xdrproc_t)xdr_bool;
105 local = rpcbproc_set_com;
106 break;
107
108 case RPCBPROC_UNSET:
109 /*
110 * Check to see whether the message came from
111 * loopback transports (for security reasons)
112 */
113 xdr_argument = (xdrproc_t)xdr_rpcb;
114 xdr_result = (xdrproc_t)xdr_bool;
115 local = rpcbproc_unset_com;
116 break;
117
118 case RPCBPROC_GETADDR:
119 xdr_argument = (xdrproc_t)xdr_rpcb;
120 xdr_result = (xdrproc_t)xdr_wrapstring;
121 local = rpcbproc_getaddr_4_local;
122 break;
123
124 case RPCBPROC_GETVERSADDR:
125#ifdef RPCBIND_DEBUG
126 if (debugging)
127 fprintf(stderr, "RPCBPROC_GETVERSADDR\n");
128#endif
129 xdr_argument = (xdrproc_t)xdr_rpcb;
130 xdr_result = (xdrproc_t)xdr_wrapstring;
131 local = rpcbproc_getversaddr_4_local;
132 break;
133
134 case RPCBPROC_DUMP:
135#ifdef RPCBIND_DEBUG
136 if (debugging)
137 fprintf(stderr, "RPCBPROC_DUMP\n");
138#endif
139 xdr_argument = (xdrproc_t)xdr_void;
140 xdr_result = (xdrproc_t)xdr_rpcblist_ptr;
141 local = rpcbproc_dump_4_local;
142 break;
143
144 case RPCBPROC_INDIRECT:
145#ifdef RPCBIND_DEBUG
146 if (debugging)
147 fprintf(stderr, "RPCBPROC_INDIRECT\n");
148#endif
149 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
150 return;
151
152/* case RPCBPROC_CALLIT: */
153 case RPCBPROC_BCAST:
154#ifdef RPCBIND_DEBUG
155 if (debugging)
156 fprintf(stderr, "RPCBPROC_BCAST\n");
157#endif
158 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
159 return;
160
161 case RPCBPROC_GETTIME:
162#ifdef RPCBIND_DEBUG
163 if (debugging)
164 fprintf(stderr, "RPCBPROC_GETTIME\n");
165#endif
166 xdr_argument = (xdrproc_t)xdr_void;
167 xdr_result = (xdrproc_t)xdr_u_long;
168 local = rpcbproc_gettime_com;
169 break;
170
171 case RPCBPROC_UADDR2TADDR:
172#ifdef RPCBIND_DEBUG
173 if (debugging)
174 fprintf(stderr, "RPCBPROC_UADDR2TADDR\n");
175#endif
176 xdr_argument = (xdrproc_t)xdr_wrapstring;
177 xdr_result = (xdrproc_t)xdr_netbuf;
178 local = rpcbproc_uaddr2taddr_com;
179 break;
180
181 case RPCBPROC_TADDR2UADDR:
182#ifdef RPCBIND_DEBUG
183 if (debugging)
184 fprintf(stderr, "RPCBPROC_TADDR2UADDR\n");
185#endif
186 xdr_argument = (xdrproc_t)xdr_netbuf;
187 xdr_result = (xdrproc_t)xdr_wrapstring;
188 local = rpcbproc_taddr2uaddr_com;
189 break;
190
191 case RPCBPROC_GETADDRLIST:
192#ifdef RPCBIND_DEBUG
193 if (debugging)
194 fprintf(stderr, "RPCBPROC_GETADDRLIST\n");
195#endif
196 xdr_argument = (xdrproc_t)xdr_rpcb;
197 xdr_result = (xdrproc_t)xdr_rpcb_entry_list_ptr;
198 local = rpcbproc_getaddrlist_4_local;
199 break;
200
201 case RPCBPROC_GETSTAT:
202#ifdef RPCBIND_DEBUG
203 if (debugging)
204 fprintf(stderr, "RPCBPROC_GETSTAT\n");
205#endif
206 xdr_argument = (xdrproc_t)xdr_void;
207 xdr_result = (xdrproc_t)xdr_rpcb_stat_byvers;
208 local = rpcbproc_getstat;
209 break;
210
211 default:
212 svcerr_noproc(transp);
213 return;
214 }
215 memset((char *)&argument, 0, sizeof (argument));
216 if (!svc_getargs(transp, (xdrproc_t) xdr_argument,
217 (char *)&argument)) {
218 svcerr_decode(transp);
219 if (debugging)
220 (void) fprintf(stderr, "rpcbind: could not decode\n");
221 return;
222 }
223 if (!check_access(transp, rqstp->rq_proc, &argument, RPCBVERS4)) {
224 svcerr_weakauth(transp);
225 goto done;
226 }
227 result = (*local)(&argument, rqstp, transp, RPCBVERS4);
228 if (result != NULL && !svc_sendreply(transp, (xdrproc_t) xdr_result,
229 result)) {
230 svcerr_systemerr(transp);
231 if (debugging) {
232 (void) fprintf(stderr, "rpcbind: svc_sendreply\n");
233 if (doabort) {
234 rpcbind_abort();
235 }
236 }
237 }
238done:
239 if (!svc_freeargs(transp, (xdrproc_t) xdr_argument,
240 (char *)&argument)) {
241 if (debugging) {
242 (void) fprintf(stderr, "unable to free arguments\n");
243 if (doabort) {
244 rpcbind_abort();
245 }
246 }
247 }
248 return;
249}
250
251/*
252 * Lookup the mapping for a program, version and return its
253 * address. Assuming that the caller wants the address of the
254 * server running on the transport on which the request came.
255 * Even if a service with a different version number is available,
256 * it will return that address. The client should check with an
257 * clnt_call to verify whether the service is the one that is desired.
258 * We also try to resolve the universal address in terms of
259 * address of the caller.
260 */
261/* ARGSUSED */
262static void *
263rpcbproc_getaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
264 rpcvers_t rpcbversnum __unused)
265{
266 RPCB *regp = (RPCB *)arg;
267#ifdef RPCBIND_DEBUG
268 if (debugging) {
269 char *uaddr;
270
271 uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
272 svc_getrpccaller(transp));
273 fprintf(stderr, "RPCB_GETADDR req for (%lu, %lu, %s) from %s: ",
274 (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
275 regp->r_netid, uaddr);
276 free(uaddr);
277 }
278#endif
279 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS4,
280 RPCB_ALLVERS));
281}
282
283/*
284 * Lookup the mapping for a program, version and return its
285 * address. Assuming that the caller wants the address of the
286 * server running on the transport on which the request came.
287 *
288 * We also try to resolve the universal address in terms of
289 * address of the caller.
290 */
291/* ARGSUSED */
292static void *
293rpcbproc_getversaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
294 rpcvers_t versnum __unused)
295{
296 RPCB *regp = (RPCB *)arg;
297#ifdef RPCBIND_DEBUG
298 if (debugging) {
299 char *uaddr;
300
301 uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
302 svc_getrpccaller(transp));
303 fprintf(stderr, "RPCB_GETVERSADDR rqst for (%lu, %lu, %s)"
304 " from %s : ",
305 (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
306 regp->r_netid, uaddr);
307 free(uaddr);
308 }
309#endif
310 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS4,
311 RPCB_ONEVERS));
312}
313
314/*
315 * Lookup the mapping for a program, version and return the
316 * addresses for all transports in the current transport family.
317 * We return a merged address.
318 */
319/* ARGSUSED */
320static void *
321rpcbproc_getaddrlist_4_local(void *arg, struct svc_req *rqstp __unused,
322 SVCXPRT *transp, rpcvers_t versnum __unused)
323{
324 RPCB *regp = (RPCB *)arg;
325 static rpcb_entry_list_ptr rlist;
326 register rpcblist_ptr rbl;
327 rpcb_entry_list_ptr rp, tail;
328 rpcprog_t prog;
329 rpcvers_t vers;
330 rpcb_entry *a;
331 struct netconfig *nconf;
332 struct netconfig *reg_nconf;
333 char *saddr, *maddr = NULL;
334
335 free_rpcb_entry_list(&rlist);
336 tail = NULL;
337 prog = regp->r_prog;
338 vers = regp->r_vers;
339 reg_nconf = rpcbind_get_conf(transp->xp_netid);
340 if (reg_nconf == NULL)
341 return (NULL);
342 if (*(regp->r_addr) != '\0') {
343 saddr = regp->r_addr;
344 } else {
345 saddr = NULL;
346 }
347#ifdef RPCBIND_DEBUG
348 if (debugging) {
349 fprintf(stderr, "r_addr: %s r_netid: %s nc_protofmly: %s\n",
350 regp->r_addr, regp->r_netid, reg_nconf->nc_protofmly);
351 }
352#endif
353 for (rbl = list_rbl; rbl != NULL; rbl = rbl->rpcb_next) {
354 if ((rbl->rpcb_map.r_prog == prog) &&
355 (rbl->rpcb_map.r_vers == vers)) {
356 nconf = rpcbind_get_conf(rbl->rpcb_map.r_netid);
357 if (nconf == NULL)
358 goto fail;
359 if (strcmp(nconf->nc_protofmly, reg_nconf->nc_protofmly)
360 != 0) {
361 continue; /* not same proto family */
362 }
363#ifdef RPCBIND_DEBUG
364 if (debugging)
365 fprintf(stderr, "\tmerge with: %s\n",
366 rbl->rpcb_map.r_addr);
367#endif
368 if ((maddr = mergeaddr(transp, rbl->rpcb_map.r_netid,
369 rbl->rpcb_map.r_addr, saddr)) == NULL) {
370#ifdef RPCBIND_DEBUG
371 if (debugging)
372 fprintf(stderr, " FAILED\n");
373#endif
374 continue;
375 } else if (!maddr[0]) {
376#ifdef RPCBIND_DEBUG
377 if (debugging)
378 fprintf(stderr, " SUCCEEDED, but port died - maddr: nullstring\n");
379#endif
380 /* The server died. Unset this combination */
381 delete_prog(regp->r_prog);
382 continue;
383 }
384#ifdef RPCBIND_DEBUG
385 if (debugging)
386 fprintf(stderr, " SUCCEEDED maddr: %s\n", maddr);
387#endif
388 /*
389 * Add it to rlist.
390 */
391 rp = malloc(sizeof (rpcb_entry_list));
392 if (rp == NULL)
393 goto fail;
394 a = &rp->rpcb_entry_map;
395 a->r_maddr = maddr;
396 a->r_nc_netid = nconf->nc_netid;
397 a->r_nc_semantics = nconf->nc_semantics;
398 a->r_nc_protofmly = nconf->nc_protofmly;
399 a->r_nc_proto = nconf->nc_proto;
400 rp->rpcb_entry_next = NULL;
401 if (rlist == NULL) {
402 rlist = rp;
403 tail = rp;
404 } else {
405 tail->rpcb_entry_next = rp;
406 tail = rp;
407 }
408 rp = NULL;
409 }
410 }
411#ifdef RPCBIND_DEBUG
412 if (debugging) {
413 for (rp = rlist; rp; rp = rp->rpcb_entry_next) {
414 fprintf(stderr, "\t%s %s\n", rp->rpcb_entry_map.r_maddr,
415 rp->rpcb_entry_map.r_nc_proto);
416 }
417 }
418#endif
419 /*
420 * XXX: getaddrlist info is also being stuffed into getaddr.
421 * Perhaps wrong, but better than it not getting counted at all.
422 */
423 rpcbs_getaddr(RPCBVERS4 - 2, prog, vers, transp->xp_netid, maddr);
424 return (void *)&rlist;
425
426fail: free_rpcb_entry_list(&rlist);
427 return (NULL);
428}
429
430/*
431 * Free only the allocated structure, rest is all a pointer to some
432 * other data somewhere else.
433 */
434static void
435free_rpcb_entry_list(rpcb_entry_list_ptr *rlistp)
436{
437 register rpcb_entry_list_ptr rbl, tmp;
438
439 for (rbl = *rlistp; rbl != NULL; ) {
440 tmp = rbl;
441 rbl = rbl->rpcb_entry_next;
442 free((char *)tmp->rpcb_entry_map.r_maddr);
443 free((char *)tmp);
444 }
445 *rlistp = NULL;
446}
447
448/* ARGSUSED */
449static void *
450rpcbproc_dump_4_local(void *arg __unused, struct svc_req *req __unused,
451 SVCXPRT *xprt __unused, rpcvers_t versnum __unused)
452{
453 return ((void *)&list_rbl);
454}