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