2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 * @(#)rpcb_svc_4.c 1.8 93/07/05 SMI
30 * $NetBSD: rpcb_svc_4.c,v 1.1 2000/06/02 23:15:41 fvdl Exp $
31 * $FreeBSD: src/usr.sbin/rpcbind/rpcb_svc_4.c,v 1.5 2007/11/07 10:53:39 kevlo Exp $
34 * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
39 * The server procedure for the version 4 rpcbind.
43 #include <sys/types.h>
48 #include <netconfig.h>
54 static void *rpcbproc_getaddr_4_local(void *, struct svc_req
*, SVCXPRT
*,
56 static void *rpcbproc_getversaddr_4_local(void *, struct svc_req
*,
57 SVCXPRT
*, rpcvers_t
);
58 static void *rpcbproc_getaddrlist_4_local(void *, struct svc_req
*,
59 SVCXPRT
*, rpcvers_t
);
60 static void free_rpcb_entry_list(rpcb_entry_list_ptr
*);
61 static void *rpcbproc_dump_4_local(void *, struct svc_req
*, SVCXPRT
*,
65 * Called by svc_getreqset. There is a separate server handle for
66 * every transport that it waits on.
69 rpcb_service_4(struct svc_req
*rqstp
, SVCXPRT
*transp
)
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
;
79 xdrproc_t xdr_argument
, xdr_result
;
80 void *(*local
)(void *, struct svc_req
*, SVCXPRT
*, rpcvers_t
);
82 rpcbs_procinfo(RPCBVERS_4_STAT
, rqstp
->rq_proc
);
84 switch (rqstp
->rq_proc
) {
91 fprintf(stderr
, "RPCBPROC_NULL\n");
93 check_access(transp
, rqstp
->rq_proc
, NULL
, RPCBVERS4
);
94 svc_sendreply(transp
, (xdrproc_t
) xdr_void
, NULL
);
99 * Check to see whether the message came from
100 * loopback transports (for security reasons)
102 xdr_argument
= (xdrproc_t
)xdr_rpcb
;
103 xdr_result
= (xdrproc_t
)xdr_bool
;
104 local
= rpcbproc_set_com
;
109 * Check to see whether the message came from
110 * loopback transports (for security reasons)
112 xdr_argument
= (xdrproc_t
)xdr_rpcb
;
113 xdr_result
= (xdrproc_t
)xdr_bool
;
114 local
= rpcbproc_unset_com
;
117 case RPCBPROC_GETADDR
:
118 xdr_argument
= (xdrproc_t
)xdr_rpcb
;
119 xdr_result
= (xdrproc_t
)xdr_wrapstring
;
120 local
= rpcbproc_getaddr_4_local
;
123 case RPCBPROC_GETVERSADDR
:
126 fprintf(stderr
, "RPCBPROC_GETVERSADDR\n");
128 xdr_argument
= (xdrproc_t
)xdr_rpcb
;
129 xdr_result
= (xdrproc_t
)xdr_wrapstring
;
130 local
= rpcbproc_getversaddr_4_local
;
136 fprintf(stderr
, "RPCBPROC_DUMP\n");
138 xdr_argument
= (xdrproc_t
)xdr_void
;
139 xdr_result
= (xdrproc_t
)xdr_rpcblist_ptr
;
140 local
= rpcbproc_dump_4_local
;
143 case RPCBPROC_INDIRECT
:
146 fprintf(stderr
, "RPCBPROC_INDIRECT\n");
148 rpcbproc_callit_com(rqstp
, transp
, rqstp
->rq_proc
, RPCBVERS4
);
151 /* case RPCBPROC_CALLIT: */
155 fprintf(stderr
, "RPCBPROC_BCAST\n");
157 rpcbproc_callit_com(rqstp
, transp
, rqstp
->rq_proc
, RPCBVERS4
);
160 case RPCBPROC_GETTIME
:
163 fprintf(stderr
, "RPCBPROC_GETTIME\n");
165 xdr_argument
= (xdrproc_t
)xdr_void
;
166 xdr_result
= (xdrproc_t
)xdr_u_long
;
167 local
= rpcbproc_gettime_com
;
170 case RPCBPROC_UADDR2TADDR
:
173 fprintf(stderr
, "RPCBPROC_UADDR2TADDR\n");
175 xdr_argument
= (xdrproc_t
)xdr_wrapstring
;
176 xdr_result
= (xdrproc_t
)xdr_netbuf
;
177 local
= rpcbproc_uaddr2taddr_com
;
180 case RPCBPROC_TADDR2UADDR
:
183 fprintf(stderr
, "RPCBPROC_TADDR2UADDR\n");
185 xdr_argument
= (xdrproc_t
)xdr_netbuf
;
186 xdr_result
= (xdrproc_t
)xdr_wrapstring
;
187 local
= rpcbproc_taddr2uaddr_com
;
190 case RPCBPROC_GETADDRLIST
:
193 fprintf(stderr
, "RPCBPROC_GETADDRLIST\n");
195 xdr_argument
= (xdrproc_t
)xdr_rpcb
;
196 xdr_result
= (xdrproc_t
)xdr_rpcb_entry_list_ptr
;
197 local
= rpcbproc_getaddrlist_4_local
;
200 case RPCBPROC_GETSTAT
:
203 fprintf(stderr
, "RPCBPROC_GETSTAT\n");
205 xdr_argument
= (xdrproc_t
)xdr_void
;
206 xdr_result
= (xdrproc_t
)xdr_rpcb_stat_byvers
;
207 local
= rpcbproc_getstat
;
211 svcerr_noproc(transp
);
214 memset((char *)&argument
, 0, sizeof (argument
));
215 if (!svc_getargs(transp
, (xdrproc_t
) xdr_argument
,
216 (char *)&argument
)) {
217 svcerr_decode(transp
);
219 fprintf(stderr
, "rpcbind: could not decode\n");
222 if (!check_access(transp
, rqstp
->rq_proc
, &argument
, RPCBVERS4
)) {
223 svcerr_weakauth(transp
);
226 result
= (*local
)(&argument
, rqstp
, transp
, RPCBVERS4
);
227 if (result
!= NULL
&& !svc_sendreply(transp
, (xdrproc_t
) xdr_result
,
229 svcerr_systemerr(transp
);
231 fprintf(stderr
, "rpcbind: svc_sendreply\n");
238 if (!svc_freeargs(transp
, (xdrproc_t
) xdr_argument
,
239 (char *)&argument
)) {
241 fprintf(stderr
, "unable to free arguments\n");
251 * Lookup the mapping for a program, version and return its
252 * address. Assuming that the caller wants the address of the
253 * server running on the transport on which the request came.
254 * Even if a service with a different version number is available,
255 * it will return that address. The client should check with an
256 * clnt_call to verify whether the service is the one that is desired.
257 * We also try to resolve the universal address in terms of
258 * address of the caller.
262 rpcbproc_getaddr_4_local(void *arg
, struct svc_req
*rqstp
, SVCXPRT
*transp
,
263 rpcvers_t rpcbversnum __unused
)
265 RPCB
*regp
= (RPCB
*)arg
;
270 uaddr
= taddr2uaddr(rpcbind_get_conf(transp
->xp_netid
),
271 svc_getrpccaller(transp
));
272 fprintf(stderr
, "RPCB_GETADDR req for (%lu, %lu, %s) from %s: ",
273 (unsigned long)regp
->r_prog
, (unsigned long)regp
->r_vers
,
274 regp
->r_netid
, uaddr
);
278 return (rpcbproc_getaddr_com(regp
, rqstp
, transp
, RPCBVERS4
,
283 * Lookup the mapping for a program, version and return its
284 * address. Assuming that the caller wants the address of the
285 * server running on the transport on which the request came.
287 * We also try to resolve the universal address in terms of
288 * address of the caller.
292 rpcbproc_getversaddr_4_local(void *arg
, struct svc_req
*rqstp
, SVCXPRT
*transp
,
293 rpcvers_t versnum __unused
)
295 RPCB
*regp
= (RPCB
*)arg
;
300 uaddr
= taddr2uaddr(rpcbind_get_conf(transp
->xp_netid
),
301 svc_getrpccaller(transp
));
302 fprintf(stderr
, "RPCB_GETVERSADDR rqst for (%lu, %lu, %s)"
304 (unsigned long)regp
->r_prog
, (unsigned long)regp
->r_vers
,
305 regp
->r_netid
, uaddr
);
309 return (rpcbproc_getaddr_com(regp
, rqstp
, transp
, RPCBVERS4
,
314 * Lookup the mapping for a program, version and return the
315 * addresses for all transports in the current transport family.
316 * We return a merged address.
320 rpcbproc_getaddrlist_4_local(void *arg
, struct svc_req
*rqstp __unused
,
321 SVCXPRT
*transp
, rpcvers_t versnum __unused
)
323 RPCB
*regp
= (RPCB
*)arg
;
324 static rpcb_entry_list_ptr rlist
;
326 rpcb_entry_list_ptr rp
, tail
;
330 struct netconfig
*nconf
;
331 struct netconfig
*reg_nconf
;
332 char *saddr
, *maddr
= NULL
;
334 free_rpcb_entry_list(&rlist
);
338 reg_nconf
= rpcbind_get_conf(transp
->xp_netid
);
339 if (reg_nconf
== NULL
)
341 if (*(regp
->r_addr
) != '\0') {
342 saddr
= regp
->r_addr
;
348 fprintf(stderr
, "r_addr: %s r_netid: %s nc_protofmly: %s\n",
349 regp
->r_addr
, regp
->r_netid
, reg_nconf
->nc_protofmly
);
352 for (rbl
= list_rbl
; rbl
!= NULL
; rbl
= rbl
->rpcb_next
) {
353 if ((rbl
->rpcb_map
.r_prog
== prog
) &&
354 (rbl
->rpcb_map
.r_vers
== vers
)) {
355 nconf
= rpcbind_get_conf(rbl
->rpcb_map
.r_netid
);
358 if (strcmp(nconf
->nc_protofmly
, reg_nconf
->nc_protofmly
)
360 continue; /* not same proto family */
364 fprintf(stderr
, "\tmerge with: %s\n",
365 rbl
->rpcb_map
.r_addr
);
367 if ((maddr
= mergeaddr(transp
, rbl
->rpcb_map
.r_netid
,
368 rbl
->rpcb_map
.r_addr
, saddr
)) == NULL
) {
371 fprintf(stderr
, " FAILED\n");
374 } else if (!maddr
[0]) {
377 fprintf(stderr
, " SUCCEEDED, but port died - maddr: nullstring\n");
379 /* The server died. Unset this combination */
380 delete_prog(regp
->r_prog
);
385 fprintf(stderr
, " SUCCEEDED maddr: %s\n", maddr
);
390 rp
= malloc(sizeof (rpcb_entry_list
));
393 a
= &rp
->rpcb_entry_map
;
395 a
->r_nc_netid
= nconf
->nc_netid
;
396 a
->r_nc_semantics
= nconf
->nc_semantics
;
397 a
->r_nc_protofmly
= nconf
->nc_protofmly
;
398 a
->r_nc_proto
= nconf
->nc_proto
;
399 rp
->rpcb_entry_next
= NULL
;
404 tail
->rpcb_entry_next
= rp
;
412 for (rp
= rlist
; rp
; rp
= rp
->rpcb_entry_next
) {
413 fprintf(stderr
, "\t%s %s\n", rp
->rpcb_entry_map
.r_maddr
,
414 rp
->rpcb_entry_map
.r_nc_proto
);
419 * XXX: getaddrlist info is also being stuffed into getaddr.
420 * Perhaps wrong, but better than it not getting counted at all.
422 rpcbs_getaddr(RPCBVERS4
- 2, prog
, vers
, transp
->xp_netid
, maddr
);
423 return (void *)&rlist
;
425 fail
: free_rpcb_entry_list(&rlist
);
430 * Free only the allocated structure, rest is all a pointer to some
431 * other data somewhere else.
434 free_rpcb_entry_list(rpcb_entry_list_ptr
*rlistp
)
436 rpcb_entry_list_ptr rbl
, tmp
;
438 for (rbl
= *rlistp
; rbl
!= NULL
; ) {
440 rbl
= rbl
->rpcb_entry_next
;
441 free((char *)tmp
->rpcb_entry_map
.r_maddr
);
449 rpcbproc_dump_4_local(void *arg __unused
, struct svc_req
*req __unused
,
450 SVCXPRT
*xprt __unused
, rpcvers_t versnum __unused
)
452 return ((void *)&list_rbl
);