svc.c revision 1.3.2.2 1 1.3.2.2 deraadt /*
2 1.3.2.2 deraadt * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 1.3.2.2 deraadt * unrestricted use provided that this legend is included on all tape
4 1.3.2.2 deraadt * media and as a part of the software program in whole or part. Users
5 1.3.2.2 deraadt * may copy or modify Sun RPC without charge, but are not authorized
6 1.3.2.2 deraadt * to license or distribute it to anyone else except as part of a product or
7 1.3.2.2 deraadt * program developed by the user.
8 1.3.2.2 deraadt *
9 1.3.2.2 deraadt * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 1.3.2.2 deraadt * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 1.3.2.2 deraadt * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 1.3.2.2 deraadt *
13 1.3.2.2 deraadt * Sun RPC is provided with no support and without any obligation on the
14 1.3.2.2 deraadt * part of Sun Microsystems, Inc. to assist in its use, correction,
15 1.3.2.2 deraadt * modification or enhancement.
16 1.3.2.2 deraadt *
17 1.3.2.2 deraadt * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 1.3.2.2 deraadt * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 1.3.2.2 deraadt * OR ANY PART THEREOF.
20 1.3.2.2 deraadt *
21 1.3.2.2 deraadt * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 1.3.2.2 deraadt * or profits or other special, indirect and consequential damages, even if
23 1.3.2.2 deraadt * Sun has been advised of the possibility of such damages.
24 1.3.2.2 deraadt *
25 1.3.2.2 deraadt * Sun Microsystems, Inc.
26 1.3.2.2 deraadt * 2550 Garcia Avenue
27 1.3.2.2 deraadt * Mountain View, California 94043
28 1.3.2.2 deraadt */
29 1.3.2.2 deraadt
30 1.3.2.2 deraadt #if defined(LIBC_SCCS) && !defined(lint)
31 1.3.2.2 deraadt /*static char *sccsid = "from: @(#)svc.c 1.44 88/02/08 Copyr 1984 Sun Micro";*/
32 1.3.2.2 deraadt /*static char *sccsid = "from: @(#)svc.c 2.4 88/08/11 4.0 RPCSRC";*/
33 1.3.2.2 deraadt static char *rcsid = "$Id: svc.c,v 1.3.2.2 1994/08/23 18:42:12 deraadt Exp $";
34 1.3.2.2 deraadt #endif
35 1.3.2.2 deraadt
36 1.3.2.2 deraadt /*
37 1.3.2.2 deraadt * svc.c, Server-side remote procedure call interface.
38 1.3.2.2 deraadt *
39 1.3.2.2 deraadt * There are two sets of procedures here. The xprt routines are
40 1.3.2.2 deraadt * for handling transport handles. The svc routines handle the
41 1.3.2.2 deraadt * list of service routines.
42 1.3.2.2 deraadt *
43 1.3.2.2 deraadt * Copyright (C) 1984, Sun Microsystems, Inc.
44 1.3.2.2 deraadt */
45 1.3.2.2 deraadt
46 1.3.2.2 deraadt #include <sys/errno.h>
47 1.3.2.2 deraadt #include <rpc/rpc.h>
48 1.3.2.2 deraadt #include <rpc/pmap_clnt.h>
49 1.3.2.2 deraadt
50 1.3.2.2 deraadt extern int errno;
51 1.3.2.2 deraadt
52 1.3.2.2 deraadt static SVCXPRT **xports;
53 1.3.2.2 deraadt
54 1.3.2.2 deraadt #define NULL_SVC ((struct svc_callout *)0)
55 1.3.2.2 deraadt #define RQCRED_SIZE 400 /* this size is excessive */
56 1.3.2.2 deraadt
57 1.3.2.2 deraadt #define max(a, b) (a > b ? a : b)
58 1.3.2.2 deraadt
59 1.3.2.2 deraadt /*
60 1.3.2.2 deraadt * The services list
61 1.3.2.2 deraadt * Each entry represents a set of procedures (an rpc program).
62 1.3.2.2 deraadt * The dispatch routine takes request structs and runs the
63 1.3.2.2 deraadt * apropriate procedure.
64 1.3.2.2 deraadt */
65 1.3.2.2 deraadt static struct svc_callout {
66 1.3.2.2 deraadt struct svc_callout *sc_next;
67 1.3.2.2 deraadt u_long sc_prog;
68 1.3.2.2 deraadt u_long sc_vers;
69 1.3.2.2 deraadt void (*sc_dispatch)();
70 1.3.2.2 deraadt } *svc_head;
71 1.3.2.2 deraadt
72 1.3.2.2 deraadt static struct svc_callout *svc_find();
73 1.3.2.2 deraadt
74 1.3.2.2 deraadt /* *************** SVCXPRT related stuff **************** */
75 1.3.2.2 deraadt
76 1.3.2.2 deraadt extern int svc_maxfd;
77 1.3.2.2 deraadt
78 1.3.2.2 deraadt /*
79 1.3.2.2 deraadt * Activate a transport handle.
80 1.3.2.2 deraadt */
81 1.3.2.2 deraadt void
82 1.3.2.2 deraadt xprt_register(xprt)
83 1.3.2.2 deraadt SVCXPRT *xprt;
84 1.3.2.2 deraadt {
85 1.3.2.2 deraadt register int sock = xprt->xp_sock;
86 1.3.2.2 deraadt
87 1.3.2.2 deraadt if (xports == NULL) {
88 1.3.2.2 deraadt xports = (SVCXPRT **)
89 1.3.2.2 deraadt mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *));
90 1.3.2.2 deraadt }
91 1.3.2.2 deraadt if (sock < FD_SETSIZE) {
92 1.3.2.2 deraadt xports[sock] = xprt;
93 1.3.2.2 deraadt FD_SET(sock, &svc_fdset);
94 1.3.2.2 deraadt svc_maxfd = max(svc_maxfd, sock);
95 1.3.2.2 deraadt }
96 1.3.2.2 deraadt }
97 1.3.2.2 deraadt
98 1.3.2.2 deraadt /*
99 1.3.2.2 deraadt * De-activate a transport handle.
100 1.3.2.2 deraadt */
101 1.3.2.2 deraadt void
102 1.3.2.2 deraadt xprt_unregister(xprt)
103 1.3.2.2 deraadt SVCXPRT *xprt;
104 1.3.2.2 deraadt {
105 1.3.2.2 deraadt register int sock = xprt->xp_sock;
106 1.3.2.2 deraadt
107 1.3.2.2 deraadt if ((sock < FD_SETSIZE) && (xports[sock] == xprt)) {
108 1.3.2.2 deraadt xports[sock] = (SVCXPRT *)0;
109 1.3.2.2 deraadt FD_CLR(sock, &svc_fdset);
110 1.3.2.2 deraadt if (sock == svc_maxfd) {
111 1.3.2.2 deraadt for (svc_maxfd--; svc_maxfd>=0; svc_maxfd--)
112 1.3.2.2 deraadt if (xports[svc_maxfd])
113 1.3.2.2 deraadt break;
114 1.3.2.2 deraadt }
115 1.3.2.2 deraadt }
116 1.3.2.2 deraadt }
117 1.3.2.2 deraadt
118 1.3.2.2 deraadt
119 1.3.2.2 deraadt /* ********************** CALLOUT list related stuff ************* */
120 1.3.2.2 deraadt
121 1.3.2.2 deraadt /*
122 1.3.2.2 deraadt * Add a service program to the callout list.
123 1.3.2.2 deraadt * The dispatch routine will be called when a rpc request for this
124 1.3.2.2 deraadt * program number comes in.
125 1.3.2.2 deraadt */
126 1.3.2.2 deraadt bool_t
127 1.3.2.2 deraadt svc_register(xprt, prog, vers, dispatch, protocol)
128 1.3.2.2 deraadt SVCXPRT *xprt;
129 1.3.2.2 deraadt u_long prog;
130 1.3.2.2 deraadt u_long vers;
131 1.3.2.2 deraadt void (*dispatch)();
132 1.3.2.2 deraadt int protocol;
133 1.3.2.2 deraadt {
134 1.3.2.2 deraadt struct svc_callout *prev;
135 1.3.2.2 deraadt register struct svc_callout *s;
136 1.3.2.2 deraadt
137 1.3.2.2 deraadt if ((s = svc_find(prog, vers, &prev)) != NULL_SVC) {
138 1.3.2.2 deraadt if (s->sc_dispatch == dispatch)
139 1.3.2.2 deraadt goto pmap_it; /* he is registering another xptr */
140 1.3.2.2 deraadt return (FALSE);
141 1.3.2.2 deraadt }
142 1.3.2.2 deraadt s = (struct svc_callout *)mem_alloc(sizeof(struct svc_callout));
143 1.3.2.2 deraadt if (s == (struct svc_callout *)0) {
144 1.3.2.2 deraadt return (FALSE);
145 1.3.2.2 deraadt }
146 1.3.2.2 deraadt s->sc_prog = prog;
147 1.3.2.2 deraadt s->sc_vers = vers;
148 1.3.2.2 deraadt s->sc_dispatch = dispatch;
149 1.3.2.2 deraadt s->sc_next = svc_head;
150 1.3.2.2 deraadt svc_head = s;
151 1.3.2.2 deraadt pmap_it:
152 1.3.2.2 deraadt /* now register the information with the local binder service */
153 1.3.2.2 deraadt if (protocol) {
154 1.3.2.2 deraadt return (pmap_set(prog, vers, protocol, xprt->xp_port));
155 1.3.2.2 deraadt }
156 1.3.2.2 deraadt return (TRUE);
157 1.3.2.2 deraadt }
158 1.3.2.2 deraadt
159 1.3.2.2 deraadt /*
160 1.3.2.2 deraadt * Remove a service program from the callout list.
161 1.3.2.2 deraadt */
162 1.3.2.2 deraadt void
163 1.3.2.2 deraadt svc_unregister(prog, vers)
164 1.3.2.2 deraadt u_long prog;
165 1.3.2.2 deraadt u_long vers;
166 1.3.2.2 deraadt {
167 1.3.2.2 deraadt struct svc_callout *prev;
168 1.3.2.2 deraadt register struct svc_callout *s;
169 1.3.2.2 deraadt
170 1.3.2.2 deraadt if ((s = svc_find(prog, vers, &prev)) == NULL_SVC)
171 1.3.2.2 deraadt return;
172 1.3.2.2 deraadt if (prev == NULL_SVC) {
173 1.3.2.2 deraadt svc_head = s->sc_next;
174 1.3.2.2 deraadt } else {
175 1.3.2.2 deraadt prev->sc_next = s->sc_next;
176 1.3.2.2 deraadt }
177 1.3.2.2 deraadt s->sc_next = NULL_SVC;
178 1.3.2.2 deraadt mem_free((char *) s, (u_int) sizeof(struct svc_callout));
179 1.3.2.2 deraadt /* now unregister the information with the local binder service */
180 1.3.2.2 deraadt (void)pmap_unset(prog, vers);
181 1.3.2.2 deraadt }
182 1.3.2.2 deraadt
183 1.3.2.2 deraadt /*
184 1.3.2.2 deraadt * Search the callout list for a program number, return the callout
185 1.3.2.2 deraadt * struct.
186 1.3.2.2 deraadt */
187 1.3.2.2 deraadt static struct svc_callout *
188 1.3.2.2 deraadt svc_find(prog, vers, prev)
189 1.3.2.2 deraadt u_long prog;
190 1.3.2.2 deraadt u_long vers;
191 1.3.2.2 deraadt struct svc_callout **prev;
192 1.3.2.2 deraadt {
193 1.3.2.2 deraadt register struct svc_callout *s, *p;
194 1.3.2.2 deraadt
195 1.3.2.2 deraadt p = NULL_SVC;
196 1.3.2.2 deraadt for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
197 1.3.2.2 deraadt if ((s->sc_prog == prog) && (s->sc_vers == vers))
198 1.3.2.2 deraadt goto done;
199 1.3.2.2 deraadt p = s;
200 1.3.2.2 deraadt }
201 1.3.2.2 deraadt done:
202 1.3.2.2 deraadt *prev = p;
203 1.3.2.2 deraadt return (s);
204 1.3.2.2 deraadt }
205 1.3.2.2 deraadt
206 1.3.2.2 deraadt /* ******************* REPLY GENERATION ROUTINES ************ */
207 1.3.2.2 deraadt
208 1.3.2.2 deraadt /*
209 1.3.2.2 deraadt * Send a reply to an rpc request
210 1.3.2.2 deraadt */
211 1.3.2.2 deraadt bool_t
212 1.3.2.2 deraadt svc_sendreply(xprt, xdr_results, xdr_location)
213 1.3.2.2 deraadt register SVCXPRT *xprt;
214 1.3.2.2 deraadt xdrproc_t xdr_results;
215 1.3.2.2 deraadt caddr_t xdr_location;
216 1.3.2.2 deraadt {
217 1.3.2.2 deraadt struct rpc_msg rply;
218 1.3.2.2 deraadt
219 1.3.2.2 deraadt rply.rm_direction = REPLY;
220 1.3.2.2 deraadt rply.rm_reply.rp_stat = MSG_ACCEPTED;
221 1.3.2.2 deraadt rply.acpted_rply.ar_verf = xprt->xp_verf;
222 1.3.2.2 deraadt rply.acpted_rply.ar_stat = SUCCESS;
223 1.3.2.2 deraadt rply.acpted_rply.ar_results.where = xdr_location;
224 1.3.2.2 deraadt rply.acpted_rply.ar_results.proc = xdr_results;
225 1.3.2.2 deraadt return (SVC_REPLY(xprt, &rply));
226 1.3.2.2 deraadt }
227 1.3.2.2 deraadt
228 1.3.2.2 deraadt /*
229 1.3.2.2 deraadt * No procedure error reply
230 1.3.2.2 deraadt */
231 1.3.2.2 deraadt void
232 1.3.2.2 deraadt svcerr_noproc(xprt)
233 1.3.2.2 deraadt register SVCXPRT *xprt;
234 1.3.2.2 deraadt {
235 1.3.2.2 deraadt struct rpc_msg rply;
236 1.3.2.2 deraadt
237 1.3.2.2 deraadt rply.rm_direction = REPLY;
238 1.3.2.2 deraadt rply.rm_reply.rp_stat = MSG_ACCEPTED;
239 1.3.2.2 deraadt rply.acpted_rply.ar_verf = xprt->xp_verf;
240 1.3.2.2 deraadt rply.acpted_rply.ar_stat = PROC_UNAVAIL;
241 1.3.2.2 deraadt SVC_REPLY(xprt, &rply);
242 1.3.2.2 deraadt }
243 1.3.2.2 deraadt
244 1.3.2.2 deraadt /*
245 1.3.2.2 deraadt * Can't decode args error reply
246 1.3.2.2 deraadt */
247 1.3.2.2 deraadt void
248 1.3.2.2 deraadt svcerr_decode(xprt)
249 1.3.2.2 deraadt register SVCXPRT *xprt;
250 1.3.2.2 deraadt {
251 1.3.2.2 deraadt struct rpc_msg rply;
252 1.3.2.2 deraadt
253 1.3.2.2 deraadt rply.rm_direction = REPLY;
254 1.3.2.2 deraadt rply.rm_reply.rp_stat = MSG_ACCEPTED;
255 1.3.2.2 deraadt rply.acpted_rply.ar_verf = xprt->xp_verf;
256 1.3.2.2 deraadt rply.acpted_rply.ar_stat = GARBAGE_ARGS;
257 1.3.2.2 deraadt SVC_REPLY(xprt, &rply);
258 1.3.2.2 deraadt }
259 1.3.2.2 deraadt
260 1.3.2.2 deraadt /*
261 1.3.2.2 deraadt * Some system error
262 1.3.2.2 deraadt */
263 1.3.2.2 deraadt void
264 1.3.2.2 deraadt svcerr_systemerr(xprt)
265 1.3.2.2 deraadt register SVCXPRT *xprt;
266 1.3.2.2 deraadt {
267 1.3.2.2 deraadt struct rpc_msg rply;
268 1.3.2.2 deraadt
269 1.3.2.2 deraadt rply.rm_direction = REPLY;
270 1.3.2.2 deraadt rply.rm_reply.rp_stat = MSG_ACCEPTED;
271 1.3.2.2 deraadt rply.acpted_rply.ar_verf = xprt->xp_verf;
272 1.3.2.2 deraadt rply.acpted_rply.ar_stat = SYSTEM_ERR;
273 1.3.2.2 deraadt SVC_REPLY(xprt, &rply);
274 1.3.2.2 deraadt }
275 1.3.2.2 deraadt
276 1.3.2.2 deraadt /*
277 1.3.2.2 deraadt * Authentication error reply
278 1.3.2.2 deraadt */
279 1.3.2.2 deraadt void
280 1.3.2.2 deraadt svcerr_auth(xprt, why)
281 1.3.2.2 deraadt SVCXPRT *xprt;
282 1.3.2.2 deraadt enum auth_stat why;
283 1.3.2.2 deraadt {
284 1.3.2.2 deraadt struct rpc_msg rply;
285 1.3.2.2 deraadt
286 1.3.2.2 deraadt rply.rm_direction = REPLY;
287 1.3.2.2 deraadt rply.rm_reply.rp_stat = MSG_DENIED;
288 1.3.2.2 deraadt rply.rjcted_rply.rj_stat = AUTH_ERROR;
289 1.3.2.2 deraadt rply.rjcted_rply.rj_why = why;
290 1.3.2.2 deraadt SVC_REPLY(xprt, &rply);
291 1.3.2.2 deraadt }
292 1.3.2.2 deraadt
293 1.3.2.2 deraadt /*
294 1.3.2.2 deraadt * Auth too weak error reply
295 1.3.2.2 deraadt */
296 1.3.2.2 deraadt void
297 1.3.2.2 deraadt svcerr_weakauth(xprt)
298 1.3.2.2 deraadt SVCXPRT *xprt;
299 1.3.2.2 deraadt {
300 1.3.2.2 deraadt
301 1.3.2.2 deraadt svcerr_auth(xprt, AUTH_TOOWEAK);
302 1.3.2.2 deraadt }
303 1.3.2.2 deraadt
304 1.3.2.2 deraadt /*
305 1.3.2.2 deraadt * Program unavailable error reply
306 1.3.2.2 deraadt */
307 1.3.2.2 deraadt void
308 1.3.2.2 deraadt svcerr_noprog(xprt)
309 1.3.2.2 deraadt register SVCXPRT *xprt;
310 1.3.2.2 deraadt {
311 1.3.2.2 deraadt struct rpc_msg rply;
312 1.3.2.2 deraadt
313 1.3.2.2 deraadt rply.rm_direction = REPLY;
314 1.3.2.2 deraadt rply.rm_reply.rp_stat = MSG_ACCEPTED;
315 1.3.2.2 deraadt rply.acpted_rply.ar_verf = xprt->xp_verf;
316 1.3.2.2 deraadt rply.acpted_rply.ar_stat = PROG_UNAVAIL;
317 1.3.2.2 deraadt SVC_REPLY(xprt, &rply);
318 1.3.2.2 deraadt }
319 1.3.2.2 deraadt
320 1.3.2.2 deraadt /*
321 1.3.2.2 deraadt * Program version mismatch error reply
322 1.3.2.2 deraadt */
323 1.3.2.2 deraadt void
324 1.3.2.2 deraadt svcerr_progvers(xprt, low_vers, high_vers)
325 1.3.2.2 deraadt register SVCXPRT *xprt;
326 1.3.2.2 deraadt u_long low_vers;
327 1.3.2.2 deraadt u_long high_vers;
328 1.3.2.2 deraadt {
329 1.3.2.2 deraadt struct rpc_msg rply;
330 1.3.2.2 deraadt
331 1.3.2.2 deraadt rply.rm_direction = REPLY;
332 1.3.2.2 deraadt rply.rm_reply.rp_stat = MSG_ACCEPTED;
333 1.3.2.2 deraadt rply.acpted_rply.ar_verf = xprt->xp_verf;
334 1.3.2.2 deraadt rply.acpted_rply.ar_stat = PROG_MISMATCH;
335 1.3.2.2 deraadt rply.acpted_rply.ar_vers.low = low_vers;
336 1.3.2.2 deraadt rply.acpted_rply.ar_vers.high = high_vers;
337 1.3.2.2 deraadt SVC_REPLY(xprt, &rply);
338 1.3.2.2 deraadt }
339 1.3.2.2 deraadt
340 1.3.2.2 deraadt /* ******************* SERVER INPUT STUFF ******************* */
341 1.3.2.2 deraadt
342 1.3.2.2 deraadt /*
343 1.3.2.2 deraadt * Get server side input from some transport.
344 1.3.2.2 deraadt *
345 1.3.2.2 deraadt * Statement of authentication parameters management:
346 1.3.2.2 deraadt * This function owns and manages all authentication parameters, specifically
347 1.3.2.2 deraadt * the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
348 1.3.2.2 deraadt * the "cooked" credentials (rqst->rq_clntcred).
349 1.3.2.2 deraadt * However, this function does not know the structure of the cooked
350 1.3.2.2 deraadt * credentials, so it make the following assumptions:
351 1.3.2.2 deraadt * a) the structure is contiguous (no pointers), and
352 1.3.2.2 deraadt * b) the cred structure size does not exceed RQCRED_SIZE bytes.
353 1.3.2.2 deraadt * In all events, all three parameters are freed upon exit from this routine.
354 1.3.2.2 deraadt * The storage is trivially management on the call stack in user land, but
355 1.3.2.2 deraadt * is mallocated in kernel land.
356 1.3.2.2 deraadt */
357 1.3.2.2 deraadt
358 1.3.2.2 deraadt void
359 1.3.2.2 deraadt svc_getreq(rdfds)
360 1.3.2.2 deraadt int rdfds;
361 1.3.2.2 deraadt {
362 1.3.2.2 deraadt fd_set readfds;
363 1.3.2.2 deraadt
364 1.3.2.2 deraadt FD_ZERO(&readfds);
365 1.3.2.2 deraadt readfds.fds_bits[0] = rdfds;
366 1.3.2.2 deraadt svc_getreqset(&readfds);
367 1.3.2.2 deraadt }
368 1.3.2.2 deraadt
369 1.3.2.2 deraadt void
370 1.3.2.2 deraadt svc_getreqset(readfds)
371 1.3.2.2 deraadt fd_set *readfds;
372 1.3.2.2 deraadt {
373 1.3.2.2 deraadt enum xprt_stat stat;
374 1.3.2.2 deraadt struct rpc_msg msg;
375 1.3.2.2 deraadt int prog_found;
376 1.3.2.2 deraadt u_long low_vers;
377 1.3.2.2 deraadt u_long high_vers;
378 1.3.2.2 deraadt struct svc_req r;
379 1.3.2.2 deraadt register SVCXPRT *xprt;
380 1.3.2.2 deraadt register u_long mask;
381 1.3.2.2 deraadt register int bit;
382 1.3.2.2 deraadt register u_long *maskp;
383 1.3.2.2 deraadt register int sock;
384 1.3.2.2 deraadt char cred_area[2*MAX_AUTH_BYTES + RQCRED_SIZE];
385 1.3.2.2 deraadt msg.rm_call.cb_cred.oa_base = cred_area;
386 1.3.2.2 deraadt msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
387 1.3.2.2 deraadt r.rq_clntcred = &(cred_area[2*MAX_AUTH_BYTES]);
388 1.3.2.2 deraadt
389 1.3.2.2 deraadt
390 1.3.2.2 deraadt maskp = (u_long *)readfds->fds_bits;
391 1.3.2.2 deraadt for (sock = 0; sock < FD_SETSIZE; sock += NFDBITS) {
392 1.3.2.2 deraadt for (mask = *maskp++; bit = ffs(mask); mask ^= (1 << (bit - 1))) {
393 1.3.2.2 deraadt /* sock has input waiting */
394 1.3.2.2 deraadt xprt = xports[sock + bit - 1];
395 1.3.2.2 deraadt /* now receive msgs from xprtprt (support batch calls) */
396 1.3.2.2 deraadt do {
397 1.3.2.2 deraadt if (SVC_RECV(xprt, &msg)) {
398 1.3.2.2 deraadt
399 1.3.2.2 deraadt /* now find the exported program and call it */
400 1.3.2.2 deraadt register struct svc_callout *s;
401 1.3.2.2 deraadt enum auth_stat why;
402 1.3.2.2 deraadt
403 1.3.2.2 deraadt r.rq_xprt = xprt;
404 1.3.2.2 deraadt r.rq_prog = msg.rm_call.cb_prog;
405 1.3.2.2 deraadt r.rq_vers = msg.rm_call.cb_vers;
406 1.3.2.2 deraadt r.rq_proc = msg.rm_call.cb_proc;
407 1.3.2.2 deraadt r.rq_cred = msg.rm_call.cb_cred;
408 1.3.2.2 deraadt /* first authenticate the message */
409 1.3.2.2 deraadt if ((why= _authenticate(&r, &msg)) != AUTH_OK) {
410 1.3.2.2 deraadt svcerr_auth(xprt, why);
411 1.3.2.2 deraadt goto call_done;
412 1.3.2.2 deraadt }
413 1.3.2.2 deraadt /* now match message with a registered service*/
414 1.3.2.2 deraadt prog_found = FALSE;
415 1.3.2.2 deraadt low_vers = 0 - 1;
416 1.3.2.2 deraadt high_vers = 0;
417 1.3.2.2 deraadt for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
418 1.3.2.2 deraadt if (s->sc_prog == r.rq_prog) {
419 1.3.2.2 deraadt if (s->sc_vers == r.rq_vers) {
420 1.3.2.2 deraadt (*s->sc_dispatch)(&r, xprt);
421 1.3.2.2 deraadt goto call_done;
422 1.3.2.2 deraadt } /* found correct version */
423 1.3.2.2 deraadt prog_found = TRUE;
424 1.3.2.2 deraadt if (s->sc_vers < low_vers)
425 1.3.2.2 deraadt low_vers = s->sc_vers;
426 1.3.2.2 deraadt if (s->sc_vers > high_vers)
427 1.3.2.2 deraadt high_vers = s->sc_vers;
428 1.3.2.2 deraadt } /* found correct program */
429 1.3.2.2 deraadt }
430 1.3.2.2 deraadt /*
431 1.3.2.2 deraadt * if we got here, the program or version
432 1.3.2.2 deraadt * is not served ...
433 1.3.2.2 deraadt */
434 1.3.2.2 deraadt if (prog_found)
435 1.3.2.2 deraadt svcerr_progvers(xprt,
436 1.3.2.2 deraadt low_vers, high_vers);
437 1.3.2.2 deraadt else
438 1.3.2.2 deraadt svcerr_noprog(xprt);
439 1.3.2.2 deraadt /* Fall through to ... */
440 1.3.2.2 deraadt }
441 1.3.2.2 deraadt call_done:
442 1.3.2.2 deraadt if ((stat = SVC_STAT(xprt)) == XPRT_DIED){
443 1.3.2.2 deraadt SVC_DESTROY(xprt);
444 1.3.2.2 deraadt break;
445 1.3.2.2 deraadt }
446 1.3.2.2 deraadt } while (stat == XPRT_MOREREQS);
447 1.3.2.2 deraadt }
448 1.3.2.2 deraadt }
449 1.3.2.2 deraadt }
450