2 * $NetBSD: rpcb_svc_4.c,v 1.1 2000/06/02 23:15:41 fvdl Exp $
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.
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.
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.
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.
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.
30 * Sun Microsystems, Inc.
32 * Mountain View, California 94043
35 * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
38 /* #ident "@(#)rpcb_svc_4.c 1.8 93/07/05 SMI" */
42 * The server procedure for the version 4 rpcbind.
46 #include <sys/types.h>
51 #include <netconfig.h>
57 static void *rpcbproc_getaddr_4_local __P((void *, struct svc_req *, SVCXPRT *,
59 static void *rpcbproc_getversaddr_4_local __P((void *, struct svc_req *, SVCXPRT *, rpcvers_t));
60 static void *rpcbproc_getaddrlist_4_local
61 __P((void *, struct svc_req *, SVCXPRT *, rpcvers_t));
62 static void free_rpcb_entry_list __P((rpcb_entry_list_ptr *));
63 static void *rpcbproc_dump_4_local __P((void *, struct svc_req *, SVCXPRT *, rpcvers_t));
66 * Called by svc_getreqset. There is a separate server handle for
67 * every transport that it waits on.
70 rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp)
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;
80 xdrproc_t xdr_argument, xdr_result;
81 void *(*local) __P((void *, struct svc_req *, SVCXPRT *, rpcvers_t));
83 rpcbs_procinfo(RPCBVERS_4_STAT, rqstp->rq_proc);
85 switch (rqstp->rq_proc) {
92 fprintf(stderr, "RPCBPROC_NULL\n");
94 check_access(transp, rqstp->rq_proc, NULL, RPCBVERS4);
95 (void) svc_sendreply(transp, (xdrproc_t) xdr_void,
101 * Check to see whether the message came from
102 * loopback transports (for security reasons)
104 xdr_argument = (xdrproc_t)xdr_rpcb;
105 xdr_result = (xdrproc_t)xdr_bool;
106 local = rpcbproc_set_com;
111 * Check to see whether the message came from
112 * loopback transports (for security reasons)
114 xdr_argument = (xdrproc_t)xdr_rpcb;
115 xdr_result = (xdrproc_t)xdr_bool;
116 local = rpcbproc_unset_com;
119 case RPCBPROC_GETADDR:
120 xdr_argument = (xdrproc_t)xdr_rpcb;
121 xdr_result = (xdrproc_t)xdr_wrapstring;
122 local = rpcbproc_getaddr_4_local;
125 case RPCBPROC_GETVERSADDR:
128 fprintf(stderr, "RPCBPROC_GETVERSADDR\n");
130 xdr_argument = (xdrproc_t)xdr_rpcb;
131 xdr_result = (xdrproc_t)xdr_wrapstring;
132 local = rpcbproc_getversaddr_4_local;
138 fprintf(stderr, "RPCBPROC_DUMP\n");
140 xdr_argument = (xdrproc_t)xdr_void;
141 xdr_result = (xdrproc_t)xdr_rpcblist_ptr;
142 local = rpcbproc_dump_4_local;
145 case RPCBPROC_INDIRECT:
148 fprintf(stderr, "RPCBPROC_INDIRECT\n");
150 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
153 /* case RPCBPROC_CALLIT: */
157 fprintf(stderr, "RPCBPROC_BCAST\n");
159 rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS4);
162 case RPCBPROC_GETTIME:
165 fprintf(stderr, "RPCBPROC_GETTIME\n");
167 xdr_argument = (xdrproc_t)xdr_void;
168 xdr_result = (xdrproc_t)xdr_u_long;
169 local = rpcbproc_gettime_com;
172 case RPCBPROC_UADDR2TADDR:
175 fprintf(stderr, "RPCBPROC_UADDR2TADDR\n");
177 xdr_argument = (xdrproc_t)xdr_wrapstring;
178 xdr_result = (xdrproc_t)xdr_netbuf;
179 local = rpcbproc_uaddr2taddr_com;
182 case RPCBPROC_TADDR2UADDR:
185 fprintf(stderr, "RPCBPROC_TADDR2UADDR\n");
187 xdr_argument = (xdrproc_t)xdr_netbuf;
188 xdr_result = (xdrproc_t)xdr_wrapstring;
189 local = rpcbproc_taddr2uaddr_com;
192 case RPCBPROC_GETADDRLIST:
195 fprintf(stderr, "RPCBPROC_GETADDRLIST\n");
197 xdr_argument = (xdrproc_t)xdr_rpcb;
198 xdr_result = (xdrproc_t)xdr_rpcb_entry_list_ptr;
199 local = rpcbproc_getaddrlist_4_local;
202 case RPCBPROC_GETSTAT:
205 fprintf(stderr, "RPCBPROC_GETSTAT\n");
207 xdr_argument = (xdrproc_t)xdr_void;
208 xdr_result = (xdrproc_t)xdr_rpcb_stat_byvers;
209 local = rpcbproc_getstat;
213 svcerr_noproc(transp);
216 memset((char *)&argument, 0, sizeof (argument));
217 if (!svc_getargs(transp, (xdrproc_t) xdr_argument,
218 (char *)&argument)) {
219 svcerr_decode(transp);
221 (void) fprintf(stderr, "rpcbind: could not decode\n");
224 if (!check_access(transp, rqstp->rq_proc, &argument, RPCBVERS4)) {
225 svcerr_weakauth(transp);
228 result = (*local)(&argument, rqstp, transp, RPCBVERS4);
229 if (result != NULL && !svc_sendreply(transp, (xdrproc_t) xdr_result,
231 svcerr_systemerr(transp);
233 (void) fprintf(stderr, "rpcbind: svc_sendreply\n");
240 if (!svc_freeargs(transp, (xdrproc_t) xdr_argument,
241 (char *)&argument)) {
243 (void) fprintf(stderr, "unable to free arguments\n");
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.
264 rpcbproc_getaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
265 rpcvers_t rpcbversnum)
267 RPCB *regp = (RPCB *)arg;
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);
280 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS4,
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.
289 * We also try to resolve the universal address in terms of
290 * address of the caller.
294 rpcbproc_getversaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
297 RPCB *regp = (RPCB *)arg;
302 uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
303 svc_getrpccaller(transp));
304 fprintf(stderr, "RPCB_GETVERSADDR rqst for (%lu, %lu, %s)"
306 (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
307 regp->r_netid, uaddr);
311 return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS4,
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.
322 rpcbproc_getaddrlist_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
325 RPCB *regp = (RPCB *)arg;
326 static rpcb_entry_list_ptr rlist;
327 register rpcblist_ptr rbl;
328 rpcb_entry_list_ptr rp, tail;
332 struct netconfig *nconf;
333 struct netconfig *reg_nconf;
334 char *saddr, *maddr = NULL;
336 free_rpcb_entry_list(&rlist);
340 reg_nconf = rpcbind_get_conf(transp->xp_netid);
341 if (reg_nconf == NULL)
343 if (*(regp->r_addr) != '\0') {
344 saddr = regp->r_addr;
350 fprintf(stderr, "r_addr: %s r_netid: %s nc_protofmly: %s\n",
351 regp->r_addr, regp->r_netid, reg_nconf->nc_protofmly);
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);
360 if (strcmp(nconf->nc_protofmly, reg_nconf->nc_protofmly)
362 continue; /* not same proto family */
366 fprintf(stderr, "\tmerge with: %s\n",
367 rbl->rpcb_map.r_addr);
369 if ((maddr = mergeaddr(transp, rbl->rpcb_map.r_netid,
370 rbl->rpcb_map.r_addr, saddr)) == NULL) {
373 fprintf(stderr, " FAILED\n");
376 } else if (!maddr[0]) {
379 fprintf(stderr, " SUCCEEDED, but port died - maddr: nullstring\n");
381 /* The server died. Unset this combination */
382 delete_prog(regp->r_prog);
387 fprintf(stderr, " SUCCEEDED maddr: %s\n", maddr);
392 rp = (rpcb_entry_list_ptr)
393 malloc((u_int)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, struct svc_req *req, SVCXPRT *xprt,
455 return ((void *)&list_rbl);