xref: /minix3/tests/fs/nfs/nfsservice/rpcbind/rpcb_svc.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: rpcb_svc.c,v 1.2 2011/09/16 16:13:18 plunky Exp $	*/
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*
4*11be35a1SLionel Sambuc  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5*11be35a1SLionel Sambuc  * unrestricted use provided that this legend is included on all tape
6*11be35a1SLionel Sambuc  * media and as a part of the software program in whole or part.  Users
7*11be35a1SLionel Sambuc  * may copy or modify Sun RPC without charge, but are not authorized
8*11be35a1SLionel Sambuc  * to license or distribute it to anyone else except as part of a product or
9*11be35a1SLionel Sambuc  * program developed by the user.
10*11be35a1SLionel Sambuc  *
11*11be35a1SLionel Sambuc  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12*11be35a1SLionel Sambuc  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13*11be35a1SLionel Sambuc  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14*11be35a1SLionel Sambuc  *
15*11be35a1SLionel Sambuc  * Sun RPC is provided with no support and without any obligation on the
16*11be35a1SLionel Sambuc  * part of Sun Microsystems, Inc. to assist in its use, correction,
17*11be35a1SLionel Sambuc  * modification or enhancement.
18*11be35a1SLionel Sambuc  *
19*11be35a1SLionel Sambuc  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20*11be35a1SLionel Sambuc  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21*11be35a1SLionel Sambuc  * OR ANY PART THEREOF.
22*11be35a1SLionel Sambuc  *
23*11be35a1SLionel Sambuc  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24*11be35a1SLionel Sambuc  * or profits or other special, indirect and consequential damages, even if
25*11be35a1SLionel Sambuc  * Sun has been advised of the possibility of such damages.
26*11be35a1SLionel Sambuc  *
27*11be35a1SLionel Sambuc  * Sun Microsystems, Inc.
28*11be35a1SLionel Sambuc  * 2550 Garcia Avenue
29*11be35a1SLionel Sambuc  * Mountain View, California  94043
30*11be35a1SLionel Sambuc  */
31*11be35a1SLionel Sambuc /*
32*11be35a1SLionel Sambuc  * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
33*11be35a1SLionel Sambuc  */
34*11be35a1SLionel Sambuc 
35*11be35a1SLionel Sambuc /* #ident	"@(#)rpcb_svc.c	1.16	93/07/05 SMI" */
36*11be35a1SLionel Sambuc 
37*11be35a1SLionel Sambuc /*
38*11be35a1SLionel Sambuc  * rpcb_svc.c
39*11be35a1SLionel Sambuc  * The server procedure for the version 3 rpcbind (TLI).
40*11be35a1SLionel Sambuc  *
41*11be35a1SLionel Sambuc  * It maintains a separate list of all the registered services with the
42*11be35a1SLionel Sambuc  * version 3 of rpcbind.
43*11be35a1SLionel Sambuc  */
44*11be35a1SLionel Sambuc #include <sys/types.h>
45*11be35a1SLionel Sambuc #include <rpc/rpc.h>
46*11be35a1SLionel Sambuc #include <rpc/rpcb_prot.h>
47*11be35a1SLionel Sambuc #include <netconfig.h>
48*11be35a1SLionel Sambuc #include <syslog.h>
49*11be35a1SLionel Sambuc #include <stdlib.h>
50*11be35a1SLionel Sambuc #include <stdio.h>
51*11be35a1SLionel Sambuc #include <string.h>
52*11be35a1SLionel Sambuc 
53*11be35a1SLionel Sambuc #include "rpcbind.h"
54*11be35a1SLionel Sambuc 
55*11be35a1SLionel Sambuc static void *rpcbproc_getaddr_3_local(void *, struct svc_req *, SVCXPRT *,
56*11be35a1SLionel Sambuc     rpcvers_t);
57*11be35a1SLionel Sambuc static void *rpcbproc_dump_3_local(void *, struct svc_req *, SVCXPRT *,
58*11be35a1SLionel Sambuc     rpcvers_t);
59*11be35a1SLionel Sambuc 
60*11be35a1SLionel Sambuc /*
61*11be35a1SLionel Sambuc  * Called by svc_getreqset. There is a separate server handle for
62*11be35a1SLionel Sambuc  * every transport that it waits on.
63*11be35a1SLionel Sambuc  */
64*11be35a1SLionel Sambuc void
rpcb_service_3(struct svc_req * rqstp,SVCXPRT * transp)65*11be35a1SLionel Sambuc rpcb_service_3(struct svc_req *rqstp, SVCXPRT *transp)
66*11be35a1SLionel Sambuc {
67*11be35a1SLionel Sambuc 	union {
68*11be35a1SLionel Sambuc 		RPCB rpcbproc_set_3_arg;
69*11be35a1SLionel Sambuc 		RPCB rpcbproc_unset_3_arg;
70*11be35a1SLionel Sambuc 		RPCB rpcbproc_getaddr_3_local_arg;
71*11be35a1SLionel Sambuc 		struct rpcb_rmtcallargs rpcbproc_callit_3_arg;
72*11be35a1SLionel Sambuc 		char *rpcbproc_uaddr2taddr_3_arg;
73*11be35a1SLionel Sambuc 		struct netbuf rpcbproc_taddr2uaddr_3_arg;
74*11be35a1SLionel Sambuc 	} argument;
75*11be35a1SLionel Sambuc 	char *result;
76*11be35a1SLionel Sambuc 	xdrproc_t xdr_argument, xdr_result;
77*11be35a1SLionel Sambuc 	void *(*local)(void *, struct svc_req *, SVCXPRT *, rpcvers_t);
78*11be35a1SLionel Sambuc 
79*11be35a1SLionel Sambuc 	rpcbs_procinfo(RPCBVERS_3_STAT, rqstp->rq_proc);
80*11be35a1SLionel Sambuc 
81*11be35a1SLionel Sambuc 	switch (rqstp->rq_proc) {
82*11be35a1SLionel Sambuc 	case NULLPROC:
83*11be35a1SLionel Sambuc 		/*
84*11be35a1SLionel Sambuc 		 * Null proc call
85*11be35a1SLionel Sambuc 		 */
86*11be35a1SLionel Sambuc #ifdef RPCBIND_DEBUG
87*11be35a1SLionel Sambuc 		if (debugging)
88*11be35a1SLionel Sambuc 			fprintf(stderr, "RPCBPROC_NULL\n");
89*11be35a1SLionel Sambuc #endif
90*11be35a1SLionel Sambuc 		/* This call just logs, no actual checks */
91*11be35a1SLionel Sambuc 		check_access(transp, rqstp->rq_proc, NULL, RPCBVERS);
92*11be35a1SLionel Sambuc 		(void) svc_sendreply(transp, (xdrproc_t)xdr_void, NULL);
93*11be35a1SLionel Sambuc 		return;
94*11be35a1SLionel Sambuc 
95*11be35a1SLionel Sambuc 	case RPCBPROC_SET:
96*11be35a1SLionel Sambuc 		xdr_argument = (xdrproc_t )xdr_rpcb;
97*11be35a1SLionel Sambuc 		xdr_result = (xdrproc_t )xdr_bool;
98*11be35a1SLionel Sambuc 		local = rpcbproc_set_com;
99*11be35a1SLionel Sambuc 		break;
100*11be35a1SLionel Sambuc 
101*11be35a1SLionel Sambuc 	case RPCBPROC_UNSET:
102*11be35a1SLionel Sambuc 		xdr_argument = (xdrproc_t)xdr_rpcb;
103*11be35a1SLionel Sambuc 		xdr_result = (xdrproc_t)xdr_bool;
104*11be35a1SLionel Sambuc 		local = rpcbproc_unset_com;
105*11be35a1SLionel Sambuc 		break;
106*11be35a1SLionel Sambuc 
107*11be35a1SLionel Sambuc 	case RPCBPROC_GETADDR:
108*11be35a1SLionel Sambuc 		xdr_argument = (xdrproc_t)xdr_rpcb;
109*11be35a1SLionel Sambuc 		xdr_result = (xdrproc_t)xdr_wrapstring;
110*11be35a1SLionel Sambuc 		local = rpcbproc_getaddr_3_local;
111*11be35a1SLionel Sambuc 		break;
112*11be35a1SLionel Sambuc 
113*11be35a1SLionel Sambuc 	case RPCBPROC_DUMP:
114*11be35a1SLionel Sambuc #ifdef RPCBIND_DEBUG
115*11be35a1SLionel Sambuc 		if (debugging)
116*11be35a1SLionel Sambuc 			fprintf(stderr, "RPCBPROC_DUMP\n");
117*11be35a1SLionel Sambuc #endif
118*11be35a1SLionel Sambuc 		xdr_argument = (xdrproc_t)xdr_void;
119*11be35a1SLionel Sambuc 		xdr_result = (xdrproc_t)xdr_rpcblist_ptr;
120*11be35a1SLionel Sambuc 		local = rpcbproc_dump_3_local;
121*11be35a1SLionel Sambuc 		break;
122*11be35a1SLionel Sambuc 
123*11be35a1SLionel Sambuc 	case RPCBPROC_CALLIT:
124*11be35a1SLionel Sambuc 		rpcbproc_callit_com(rqstp, transp, rqstp->rq_proc, RPCBVERS);
125*11be35a1SLionel Sambuc 		return;
126*11be35a1SLionel Sambuc 
127*11be35a1SLionel Sambuc 	case RPCBPROC_GETTIME:
128*11be35a1SLionel Sambuc #ifdef RPCBIND_DEBUG
129*11be35a1SLionel Sambuc 		if (debugging)
130*11be35a1SLionel Sambuc 			fprintf(stderr, "RPCBPROC_GETTIME\n");
131*11be35a1SLionel Sambuc #endif
132*11be35a1SLionel Sambuc 		xdr_argument = (xdrproc_t)xdr_void;
133*11be35a1SLionel Sambuc 		xdr_result = (xdrproc_t)xdr_u_long;
134*11be35a1SLionel Sambuc 		local = rpcbproc_gettime_com;
135*11be35a1SLionel Sambuc 		break;
136*11be35a1SLionel Sambuc 
137*11be35a1SLionel Sambuc 	case RPCBPROC_UADDR2TADDR:
138*11be35a1SLionel Sambuc #ifdef RPCBIND_DEBUG
139*11be35a1SLionel Sambuc 		if (debugging)
140*11be35a1SLionel Sambuc 			fprintf(stderr, "RPCBPROC_UADDR2TADDR\n");
141*11be35a1SLionel Sambuc #endif
142*11be35a1SLionel Sambuc 		xdr_argument = (xdrproc_t)xdr_wrapstring;
143*11be35a1SLionel Sambuc 		xdr_result = (xdrproc_t)xdr_netbuf;
144*11be35a1SLionel Sambuc 		local = rpcbproc_uaddr2taddr_com;
145*11be35a1SLionel Sambuc 		break;
146*11be35a1SLionel Sambuc 
147*11be35a1SLionel Sambuc 	case RPCBPROC_TADDR2UADDR:
148*11be35a1SLionel Sambuc #ifdef RPCBIND_DEBUG
149*11be35a1SLionel Sambuc 		if (debugging)
150*11be35a1SLionel Sambuc 			fprintf(stderr, "RPCBPROC_TADDR2UADDR\n");
151*11be35a1SLionel Sambuc #endif
152*11be35a1SLionel Sambuc 		xdr_argument = (xdrproc_t)xdr_netbuf;
153*11be35a1SLionel Sambuc 		xdr_result = (xdrproc_t)xdr_wrapstring;
154*11be35a1SLionel Sambuc 		local = rpcbproc_taddr2uaddr_com;
155*11be35a1SLionel Sambuc 		break;
156*11be35a1SLionel Sambuc 
157*11be35a1SLionel Sambuc 	default:
158*11be35a1SLionel Sambuc 		svcerr_noproc(transp);
159*11be35a1SLionel Sambuc 		return;
160*11be35a1SLionel Sambuc 	}
161*11be35a1SLionel Sambuc 	(void) memset((char *)&argument, 0, sizeof (argument));
162*11be35a1SLionel Sambuc 	if (!svc_getargs(transp, (xdrproc_t) xdr_argument,
163*11be35a1SLionel Sambuc 				(char *) &argument)) {
164*11be35a1SLionel Sambuc 		svcerr_decode(transp);
165*11be35a1SLionel Sambuc 		if (debugging)
166*11be35a1SLionel Sambuc 			(void) fprintf(stderr, "rpcbind: could not decode\n");
167*11be35a1SLionel Sambuc 		return;
168*11be35a1SLionel Sambuc 	}
169*11be35a1SLionel Sambuc 	if (!check_access(transp, rqstp->rq_proc, &argument, RPCBVERS)) {
170*11be35a1SLionel Sambuc 		svcerr_weakauth(transp);
171*11be35a1SLionel Sambuc 		goto done;
172*11be35a1SLionel Sambuc 	}
173*11be35a1SLionel Sambuc 	result = (*local)(&argument, rqstp, transp, RPCBVERS);
174*11be35a1SLionel Sambuc 	if (result != NULL && !svc_sendreply(transp, (xdrproc_t)xdr_result,
175*11be35a1SLionel Sambuc 						result)) {
176*11be35a1SLionel Sambuc 		svcerr_systemerr(transp);
177*11be35a1SLionel Sambuc 		if (debugging) {
178*11be35a1SLionel Sambuc 			(void) fprintf(stderr, "rpcbind: svc_sendreply\n");
179*11be35a1SLionel Sambuc 			if (doabort) {
180*11be35a1SLionel Sambuc 				rpcbind_abort();
181*11be35a1SLionel Sambuc 			}
182*11be35a1SLionel Sambuc 		}
183*11be35a1SLionel Sambuc 	}
184*11be35a1SLionel Sambuc done:
185*11be35a1SLionel Sambuc 	if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)
186*11be35a1SLionel Sambuc 				&argument)) {
187*11be35a1SLionel Sambuc 		if (debugging) {
188*11be35a1SLionel Sambuc 			(void) fprintf(stderr, "unable to free arguments\n");
189*11be35a1SLionel Sambuc 			if (doabort) {
190*11be35a1SLionel Sambuc 				rpcbind_abort();
191*11be35a1SLionel Sambuc 			}
192*11be35a1SLionel Sambuc 		}
193*11be35a1SLionel Sambuc 	}
194*11be35a1SLionel Sambuc }
195*11be35a1SLionel Sambuc 
196*11be35a1SLionel Sambuc /*
197*11be35a1SLionel Sambuc  * Lookup the mapping for a program, version and return its
198*11be35a1SLionel Sambuc  * address. Assuming that the caller wants the address of the
199*11be35a1SLionel Sambuc  * server running on the transport on which the request came.
200*11be35a1SLionel Sambuc  *
201*11be35a1SLionel Sambuc  * We also try to resolve the universal address in terms of
202*11be35a1SLionel Sambuc  * address of the caller.
203*11be35a1SLionel Sambuc  */
204*11be35a1SLionel Sambuc /* ARGSUSED */
205*11be35a1SLionel Sambuc static void *
rpcbproc_getaddr_3_local(void * arg,struct svc_req * rqstp,SVCXPRT * transp,rpcvers_t versnum)206*11be35a1SLionel Sambuc rpcbproc_getaddr_3_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
207*11be35a1SLionel Sambuc 			 rpcvers_t versnum)
208*11be35a1SLionel Sambuc {
209*11be35a1SLionel Sambuc 	RPCB *regp = (RPCB *)arg;
210*11be35a1SLionel Sambuc #ifdef RPCBIND_DEBUG
211*11be35a1SLionel Sambuc 	if (debugging) {
212*11be35a1SLionel Sambuc 		char *uaddr;
213*11be35a1SLionel Sambuc 
214*11be35a1SLionel Sambuc 		uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
215*11be35a1SLionel Sambuc 			    svc_getrpccaller(transp));
216*11be35a1SLionel Sambuc 		fprintf(stderr, "RPCB_GETADDR req for (%lu, %lu, %s) from %s: ",
217*11be35a1SLionel Sambuc 		    (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
218*11be35a1SLionel Sambuc 		    regp->r_netid, uaddr);
219*11be35a1SLionel Sambuc 		free(uaddr);
220*11be35a1SLionel Sambuc 	}
221*11be35a1SLionel Sambuc #endif
222*11be35a1SLionel Sambuc 	return (rpcbproc_getaddr_com(regp, rqstp, transp, RPCBVERS,
223*11be35a1SLionel Sambuc 	    RPCB_ALLVERS));
224*11be35a1SLionel Sambuc }
225*11be35a1SLionel Sambuc 
226*11be35a1SLionel Sambuc /* ARGSUSED */
227*11be35a1SLionel Sambuc static void *
rpcbproc_dump_3_local(void * arg,struct svc_req * rqstp,SVCXPRT * transp,rpcvers_t versnum)228*11be35a1SLionel Sambuc rpcbproc_dump_3_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
229*11be35a1SLionel Sambuc 		      rpcvers_t versnum)
230*11be35a1SLionel Sambuc {
231*11be35a1SLionel Sambuc 	return ((void *)&list_rbl);
232*11be35a1SLionel Sambuc }
233