1 | /* @(#)svc.c 2.4 88/08/11 4.0 RPCSRC; from 1.44 88/02/08 SMI */ |
---|
2 | /* |
---|
3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for |
---|
4 | * unrestricted use provided that this legend is included on all tape |
---|
5 | * media and as a part of the software program in whole or part. Users |
---|
6 | * may copy or modify Sun RPC without charge, but are not authorized |
---|
7 | * to license or distribute it to anyone else except as part of a product or |
---|
8 | * program developed by the user. |
---|
9 | * |
---|
10 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE |
---|
11 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR |
---|
12 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. |
---|
13 | * |
---|
14 | * Sun RPC is provided with no support and without any obligation on the |
---|
15 | * part of Sun Microsystems, Inc. to assist in its use, correction, |
---|
16 | * modification or enhancement. |
---|
17 | * |
---|
18 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE |
---|
19 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC |
---|
20 | * OR ANY PART THEREOF. |
---|
21 | * |
---|
22 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue |
---|
23 | * or profits or other special, indirect and consequential damages, even if |
---|
24 | * Sun has been advised of the possibility of such damages. |
---|
25 | * |
---|
26 | * Sun Microsystems, Inc. |
---|
27 | * 2550 Garcia Avenue |
---|
28 | * Mountain View, California 94043 |
---|
29 | */ |
---|
30 | #if !defined(lint) && defined(SCCSIDS) |
---|
31 | static char sccsid[] = "@(#)svc.c 1.41 87/10/13 Copyr 1984 Sun Micro"; |
---|
32 | #endif |
---|
33 | |
---|
34 | /* |
---|
35 | * svc.c, Server-side remote procedure call interface. |
---|
36 | * |
---|
37 | * There are two sets of procedures here. The xprt routines are |
---|
38 | * for handling transport handles. The svc routines handle the |
---|
39 | * list of service routines. |
---|
40 | * |
---|
41 | * Copyright (C) 1984, Sun Microsystems, Inc. |
---|
42 | */ |
---|
43 | |
---|
44 | #include <rpc/rpc.h> |
---|
45 | #include <stdio.h> |
---|
46 | #include <stdlib.h> |
---|
47 | |
---|
48 | #define RQCRED_SIZE 400 /* this size is excessive */ |
---|
49 | |
---|
50 | /* ******************* REPLY GENERATION ROUTINES ************ */ |
---|
51 | |
---|
52 | /* |
---|
53 | * Send a reply to an rpc request |
---|
54 | */ |
---|
55 | bool_t |
---|
56 | svc_sendreply(xprt, xdr_results, xdr_location) |
---|
57 | register SVCXPRT *xprt; |
---|
58 | xdrproc_t xdr_results; |
---|
59 | caddr_t xdr_location; |
---|
60 | { |
---|
61 | struct rpc_msg rply; |
---|
62 | |
---|
63 | rply.rm_direction = REPLY; |
---|
64 | rply.rm_reply.rp_stat = MSG_ACCEPTED; |
---|
65 | rply.acpted_rply.ar_verf = xprt->xp_verf; |
---|
66 | rply.acpted_rply.ar_stat = SUCCESS; |
---|
67 | rply.acpted_rply.ar_results.where = xdr_location; |
---|
68 | rply.acpted_rply.ar_results.proc = xdr_results; |
---|
69 | return (SVC_REPLY(xprt, &rply)); |
---|
70 | } |
---|
71 | |
---|
72 | /* |
---|
73 | * No procedure error reply |
---|
74 | */ |
---|
75 | void |
---|
76 | svcerr_noproc(xprt) |
---|
77 | register SVCXPRT *xprt; |
---|
78 | { |
---|
79 | struct rpc_msg rply; |
---|
80 | |
---|
81 | rply.rm_direction = REPLY; |
---|
82 | rply.rm_reply.rp_stat = MSG_ACCEPTED; |
---|
83 | rply.acpted_rply.ar_verf = xprt->xp_verf; |
---|
84 | rply.acpted_rply.ar_stat = PROC_UNAVAIL; |
---|
85 | SVC_REPLY(xprt, &rply); |
---|
86 | } |
---|
87 | |
---|
88 | /* |
---|
89 | * Can't decode args error reply |
---|
90 | */ |
---|
91 | void |
---|
92 | svcerr_decode(xprt) |
---|
93 | register SVCXPRT *xprt; |
---|
94 | { |
---|
95 | struct rpc_msg rply; |
---|
96 | |
---|
97 | rply.rm_direction = REPLY; |
---|
98 | rply.rm_reply.rp_stat = MSG_ACCEPTED; |
---|
99 | rply.acpted_rply.ar_verf = xprt->xp_verf; |
---|
100 | rply.acpted_rply.ar_stat = GARBAGE_ARGS; |
---|
101 | SVC_REPLY(xprt, &rply); |
---|
102 | } |
---|
103 | |
---|
104 | /* |
---|
105 | * Some system error |
---|
106 | */ |
---|
107 | void |
---|
108 | svcerr_systemerr(xprt) |
---|
109 | register SVCXPRT *xprt; |
---|
110 | { |
---|
111 | struct rpc_msg rply; |
---|
112 | |
---|
113 | rply.rm_direction = REPLY; |
---|
114 | rply.rm_reply.rp_stat = MSG_ACCEPTED; |
---|
115 | rply.acpted_rply.ar_verf = xprt->xp_verf; |
---|
116 | rply.acpted_rply.ar_stat = SYSTEM_ERR; |
---|
117 | SVC_REPLY(xprt, &rply); |
---|
118 | } |
---|
119 | |
---|
120 | /* |
---|
121 | * Authentication error reply |
---|
122 | */ |
---|
123 | void |
---|
124 | svcerr_auth(xprt, why) |
---|
125 | SVCXPRT *xprt; |
---|
126 | enum auth_stat why; |
---|
127 | { |
---|
128 | struct rpc_msg rply; |
---|
129 | |
---|
130 | rply.rm_direction = REPLY; |
---|
131 | rply.rm_reply.rp_stat = MSG_DENIED; |
---|
132 | rply.rjcted_rply.rj_stat = AUTH_ERROR; |
---|
133 | rply.rjcted_rply.rj_why = why; |
---|
134 | SVC_REPLY(xprt, &rply); |
---|
135 | } |
---|
136 | |
---|
137 | /* |
---|
138 | * Auth too weak error reply |
---|
139 | */ |
---|
140 | void |
---|
141 | svcerr_weakauth(xprt) |
---|
142 | SVCXPRT *xprt; |
---|
143 | { |
---|
144 | |
---|
145 | svcerr_auth(xprt, AUTH_TOOWEAK); |
---|
146 | } |
---|
147 | |
---|
148 | /* |
---|
149 | * Program unavailable error reply |
---|
150 | */ |
---|
151 | void |
---|
152 | svcerr_noprog(xprt) |
---|
153 | register SVCXPRT *xprt; |
---|
154 | { |
---|
155 | struct rpc_msg rply; |
---|
156 | |
---|
157 | rply.rm_direction = REPLY; |
---|
158 | rply.rm_reply.rp_stat = MSG_ACCEPTED; |
---|
159 | rply.acpted_rply.ar_verf = xprt->xp_verf; |
---|
160 | rply.acpted_rply.ar_stat = PROG_UNAVAIL; |
---|
161 | SVC_REPLY(xprt, &rply); |
---|
162 | } |
---|
163 | |
---|
164 | /* |
---|
165 | * Program version mismatch error reply |
---|
166 | */ |
---|
167 | void |
---|
168 | svcerr_progvers(xprt, low_vers, high_vers) |
---|
169 | register SVCXPRT *xprt; |
---|
170 | u_long low_vers; |
---|
171 | u_long high_vers; |
---|
172 | { |
---|
173 | struct rpc_msg rply; |
---|
174 | |
---|
175 | rply.rm_direction = REPLY; |
---|
176 | rply.rm_reply.rp_stat = MSG_ACCEPTED; |
---|
177 | rply.acpted_rply.ar_verf = xprt->xp_verf; |
---|
178 | rply.acpted_rply.ar_stat = PROG_MISMATCH; |
---|
179 | rply.acpted_rply.ar_vers.low = low_vers; |
---|
180 | rply.acpted_rply.ar_vers.high = high_vers; |
---|
181 | SVC_REPLY(xprt, &rply); |
---|
182 | } |
---|
183 | |
---|
184 | void |
---|
185 | svc_processrequest(xprt, prog, vers, dispatch) |
---|
186 | SVCXPRT *xprt; |
---|
187 | u_long prog; |
---|
188 | u_long vers; |
---|
189 | void (*dispatch)(); |
---|
190 | { |
---|
191 | struct rpc_msg msg; |
---|
192 | int prog_found = FALSE; |
---|
193 | u_long low_vers = 0; /* dummy init */ |
---|
194 | u_long high_vers = 0; /* dummy init */ |
---|
195 | struct svc_req r; |
---|
196 | /*static char cred_area[2*MAX_AUTH_BYTES + RQCRED_SIZE];*/ |
---|
197 | char *cred_area; |
---|
198 | |
---|
199 | cred_area = (char *)malloc(2*MAX_AUTH_BYTES + RQCRED_SIZE); |
---|
200 | msg.rm_call.cb_cred.oa_base = cred_area; |
---|
201 | msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]); |
---|
202 | r.rq_clntcred = &(cred_area[2*MAX_AUTH_BYTES]); |
---|
203 | |
---|
204 | if (SVC_RECV(xprt, &msg)) { |
---|
205 | |
---|
206 | /* now find the exported program and call it */ |
---|
207 | /* register struct svc_callout *s; */ |
---|
208 | enum auth_stat why; |
---|
209 | |
---|
210 | r.rq_xprt = xprt; |
---|
211 | r.rq_prog = msg.rm_call.cb_prog; |
---|
212 | r.rq_vers = msg.rm_call.cb_vers; |
---|
213 | r.rq_proc = msg.rm_call.cb_proc; |
---|
214 | r.rq_cred = msg.rm_call.cb_cred; |
---|
215 | |
---|
216 | /* first authenticate the message */ |
---|
217 | if ((why= _authenticate(&r, &msg)) != AUTH_OK) { |
---|
218 | svcerr_auth(xprt, why); |
---|
219 | free(cred_area); |
---|
220 | return; |
---|
221 | } |
---|
222 | |
---|
223 | /* now match message with a registered service*/ |
---|
224 | prog_found = FALSE; |
---|
225 | low_vers = 0 - 1; |
---|
226 | high_vers = 0; |
---|
227 | if (prog == r.rq_prog) { |
---|
228 | if (vers == r.rq_vers) { |
---|
229 | (*dispatch)(&r, xprt); |
---|
230 | free(cred_area); |
---|
231 | return; |
---|
232 | } /* found correct version */ |
---|
233 | prog_found = TRUE; |
---|
234 | if (vers < low_vers) |
---|
235 | low_vers = vers; |
---|
236 | if (vers > high_vers) |
---|
237 | high_vers = vers; |
---|
238 | } /* found correct program */ |
---|
239 | } |
---|
240 | /* |
---|
241 | * if we got here, the program or version |
---|
242 | * is not served ... |
---|
243 | */ |
---|
244 | if (prog_found) { |
---|
245 | svcerr_progvers(xprt, |
---|
246 | low_vers, high_vers); |
---|
247 | } else { |
---|
248 | svcerr_noprog(xprt); |
---|
249 | } |
---|
250 | |
---|
251 | free(cred_area); |
---|
252 | |
---|
253 | } |
---|
254 | |
---|
255 | /* stubs for solaris rpcgen */ |
---|
256 | /*int _rpcsvccount; |
---|
257 | int _rpcsvcstate; |
---|
258 | int _SERVED; |
---|
259 | */ |
---|