lock_proc.c revision 1.2 1 1.2 lukem /* $NetBSD: lock_proc.c,v 1.2 1997/10/18 04:01:15 lukem Exp $ */
2 1.1 scottr
3 1.1 scottr /*
4 1.1 scottr * Copyright (c) 1995
5 1.1 scottr * A.R. Gordon (andrew.gordon (at) net-tel.co.uk). All rights reserved.
6 1.1 scottr *
7 1.1 scottr * Redistribution and use in source and binary forms, with or without
8 1.1 scottr * modification, are permitted provided that the following conditions
9 1.1 scottr * are met:
10 1.1 scottr * 1. Redistributions of source code must retain the above copyright
11 1.1 scottr * notice, this list of conditions and the following disclaimer.
12 1.1 scottr * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 scottr * notice, this list of conditions and the following disclaimer in the
14 1.1 scottr * documentation and/or other materials provided with the distribution.
15 1.1 scottr * 3. All advertising materials mentioning features or use of this software
16 1.1 scottr * must display the following acknowledgement:
17 1.1 scottr * This product includes software developed for the FreeBSD project
18 1.1 scottr * 4. Neither the name of the author nor the names of any co-contributors
19 1.1 scottr * may be used to endorse or promote products derived from this software
20 1.1 scottr * without specific prior written permission.
21 1.1 scottr *
22 1.1 scottr * THIS SOFTWARE IS PROVIDED BY ANDREW GORDON AND CONTRIBUTORS ``AS IS'' AND
23 1.1 scottr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 scottr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 scottr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 1.1 scottr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 scottr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 scottr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 scottr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 scottr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 scottr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 scottr * SUCH DAMAGE.
33 1.1 scottr *
34 1.1 scottr */
35 1.1 scottr
36 1.2 lukem #include <sys/cdefs.h>
37 1.2 lukem #ifndef lint
38 1.2 lukem __RCSID("$NetBSD: lock_proc.c,v 1.2 1997/10/18 04:01:15 lukem Exp $");
39 1.2 lukem #endif
40 1.2 lukem
41 1.1 scottr #include <sys/param.h>
42 1.1 scottr #include <sys/socket.h>
43 1.1 scottr
44 1.1 scottr #include <netinet/in.h>
45 1.1 scottr #include <arpa/inet.h>
46 1.1 scottr
47 1.2 lukem #include <netdb.h>
48 1.2 lukem #include <stdio.h>
49 1.2 lukem #include <string.h>
50 1.2 lukem #include <syslog.h>
51 1.2 lukem
52 1.1 scottr #include <rpc/rpc.h>
53 1.1 scottr #include <rpcsvc/sm_inter.h>
54 1.1 scottr
55 1.1 scottr #include "lockd.h"
56 1.1 scottr #include "nlm_prot.h"
57 1.1 scottr
58 1.1 scottr
59 1.1 scottr #define CLIENT_CACHE_SIZE 64 /* No. of client sockets cached */
60 1.1 scottr #define CLIENT_CACHE_LIFETIME 120 /* In seconds */
61 1.1 scottr
62 1.2 lukem static CLIENT *get_client __P((struct sockaddr_in *));
63 1.2 lukem static void log_from_addr __P((char *, struct svc_req *));
64 1.2 lukem static void transmit_result __P((int, nlm_res *, struct svc_req *));
65 1.2 lukem
66 1.1 scottr /* log_from_addr ----------------------------------------------------------- */
67 1.1 scottr /*
68 1.1 scottr * Purpose: Log name of function called and source address
69 1.1 scottr * Returns: Nothing
70 1.1 scottr * Notes: Extracts the source address from the transport handle
71 1.1 scottr * passed in as part of the called procedure specification
72 1.1 scottr */
73 1.1 scottr static void
74 1.1 scottr log_from_addr(fun_name, req)
75 1.1 scottr char *fun_name;
76 1.1 scottr struct svc_req *req;
77 1.1 scottr {
78 1.1 scottr struct sockaddr_in *addr;
79 1.1 scottr struct hostent *host;
80 1.1 scottr char hostname_buf[40];
81 1.1 scottr
82 1.1 scottr addr = svc_getcaller(req->rq_xprt);
83 1.1 scottr host = gethostbyaddr((char *)&(addr->sin_addr), addr->sin_len, AF_INET);
84 1.1 scottr if (host) {
85 1.1 scottr strncpy(hostname_buf, host->h_name, sizeof(hostname_buf));
86 1.1 scottr hostname_buf[sizeof(hostname_buf) - 1] = '\0';
87 1.1 scottr } else /* No hostname available - print raw address */
88 1.1 scottr strcpy(hostname_buf, inet_ntoa(addr->sin_addr));
89 1.1 scottr
90 1.1 scottr syslog(LOG_DEBUG, "%s from %s", fun_name, hostname_buf);
91 1.1 scottr }
92 1.1 scottr
93 1.1 scottr /* get_client -------------------------------------------------------------- */
94 1.1 scottr /*
95 1.1 scottr * Purpose: Get a CLIENT* for making RPC calls to lockd on given host
96 1.1 scottr * Returns: CLIENT* pointer, from clnt_udp_create, or NULL if error
97 1.1 scottr * Notes: Creating a CLIENT* is quite expensive, involving a
98 1.1 scottr * conversation with the remote portmapper to get the
99 1.1 scottr * port number. Since a given client is quite likely
100 1.1 scottr * to make several locking requests in succession, it is
101 1.1 scottr * desirable to cache the created CLIENT*.
102 1.1 scottr *
103 1.1 scottr * Since we are using UDP rather than TCP, there is no cost
104 1.1 scottr * to the remote system in keeping these cached indefinitely.
105 1.1 scottr * Unfortunately there is a snag: if the remote system
106 1.1 scottr * reboots, the cached portmapper results will be invalid,
107 1.1 scottr * and we will never detect this since all of the xxx_msg()
108 1.1 scottr * calls return no result - we just fire off a udp packet
109 1.1 scottr * and hope for the best.
110 1.1 scottr *
111 1.1 scottr * We solve this by discarding cached values after two
112 1.1 scottr * minutes, regardless of whether they have been used
113 1.1 scottr * in the meanwhile (since a bad one might have been used
114 1.1 scottr * plenty of times, as the host keeps retrying the request
115 1.1 scottr * and we keep sending the reply back to the wrong port).
116 1.1 scottr *
117 1.1 scottr * Given that the entries will always expire in the order
118 1.1 scottr * that they were created, there is no point in a LRU
119 1.1 scottr * algorithm for when the cache gets full - entries are
120 1.1 scottr * always re-used in sequence.
121 1.1 scottr */
122 1.1 scottr static CLIENT *clnt_cache_ptr[CLIENT_CACHE_SIZE];
123 1.1 scottr static long clnt_cache_time[CLIENT_CACHE_SIZE]; /* time entry created */
124 1.1 scottr static struct in_addr clnt_cache_addr[CLIENT_CACHE_SIZE];
125 1.1 scottr static int clnt_cache_next_to_use = 0;
126 1.1 scottr
127 1.1 scottr static CLIENT *
128 1.1 scottr get_client(host_addr)
129 1.1 scottr struct sockaddr_in *host_addr;
130 1.1 scottr {
131 1.1 scottr CLIENT *client;
132 1.1 scottr struct timeval retry_time, time_now;
133 1.1 scottr int i, sock_no;
134 1.1 scottr
135 1.1 scottr gettimeofday(&time_now, NULL);
136 1.1 scottr
137 1.1 scottr /*
138 1.1 scottr * Search for the given client in the cache, zapping any expired
139 1.1 scottr * entries that we happen to notice in passing.
140 1.1 scottr */
141 1.1 scottr for (i = 0; i < CLIENT_CACHE_SIZE; i++) {
142 1.1 scottr client = clnt_cache_ptr[i];
143 1.1 scottr if (client && ((clnt_cache_time[i] + CLIENT_CACHE_LIFETIME)
144 1.1 scottr < time_now.tv_sec)) {
145 1.1 scottr /* Cache entry has expired. */
146 1.1 scottr if (debug_level > 3)
147 1.1 scottr syslog(LOG_DEBUG, "Expired CLIENT* in cache");
148 1.1 scottr clnt_cache_time[i] = 0L;
149 1.1 scottr clnt_destroy(client);
150 1.1 scottr clnt_cache_ptr[i] = NULL;
151 1.1 scottr client = NULL;
152 1.1 scottr }
153 1.1 scottr if (client && !memcmp(&clnt_cache_addr[i],
154 1.1 scottr &host_addr->sin_addr, sizeof(struct in_addr))) {
155 1.1 scottr /* Found it! */
156 1.1 scottr if (debug_level > 3)
157 1.1 scottr syslog(LOG_DEBUG, "Found CLIENT* in cache");
158 1.1 scottr return (client);
159 1.1 scottr }
160 1.1 scottr }
161 1.1 scottr
162 1.1 scottr /* Not found in cache. Free the next entry if it is in use. */
163 1.1 scottr if (clnt_cache_ptr[clnt_cache_next_to_use]) {
164 1.1 scottr clnt_destroy(clnt_cache_ptr[clnt_cache_next_to_use]);
165 1.1 scottr clnt_cache_ptr[clnt_cache_next_to_use] = NULL;
166 1.1 scottr }
167 1.1 scottr
168 1.1 scottr /* Create the new client handle */
169 1.1 scottr sock_no = RPC_ANYSOCK;
170 1.1 scottr retry_time.tv_sec = 5;
171 1.1 scottr retry_time.tv_usec = 0;
172 1.1 scottr host_addr->sin_port = 0; /* Force consultation with portmapper */
173 1.1 scottr client = clntudp_create(host_addr, NLM_PROG, NLM_VERS,
174 1.1 scottr retry_time, &sock_no);
175 1.1 scottr if (!client) {
176 1.1 scottr syslog(LOG_ERR, clnt_spcreateerror("clntudp_create"));
177 1.1 scottr syslog(LOG_ERR, "Unable to return result to %s",
178 1.1 scottr inet_ntoa(host_addr->sin_addr));
179 1.1 scottr return NULL;
180 1.1 scottr }
181 1.1 scottr
182 1.1 scottr /* Success - update the cache entry */
183 1.1 scottr clnt_cache_ptr[clnt_cache_next_to_use] = client;
184 1.1 scottr clnt_cache_addr[clnt_cache_next_to_use] = host_addr->sin_addr;
185 1.1 scottr clnt_cache_time[clnt_cache_next_to_use] = time_now.tv_sec;
186 1.1 scottr if (++clnt_cache_next_to_use > CLIENT_CACHE_SIZE)
187 1.1 scottr clnt_cache_next_to_use = 0;
188 1.1 scottr
189 1.1 scottr /*
190 1.1 scottr * Disable the default timeout, so we can specify our own in calls
191 1.1 scottr * to clnt_call(). (Note that the timeout is a different concept
192 1.1 scottr * from the retry period set in clnt_udp_create() above.)
193 1.1 scottr */
194 1.1 scottr retry_time.tv_sec = -1;
195 1.1 scottr retry_time.tv_usec = -1;
196 1.1 scottr clnt_control(client, CLSET_TIMEOUT, (char *)&retry_time);
197 1.1 scottr
198 1.1 scottr if (debug_level > 3)
199 1.1 scottr syslog(LOG_DEBUG, "Created CLIENT* for %s",
200 1.1 scottr inet_ntoa(host_addr->sin_addr));
201 1.1 scottr return client;
202 1.1 scottr }
203 1.1 scottr
204 1.1 scottr
205 1.1 scottr /* transmit_result --------------------------------------------------------- */
206 1.1 scottr /*
207 1.1 scottr * Purpose: Transmit result for nlm_xxx_msg pseudo-RPCs
208 1.1 scottr * Returns: Nothing - we have no idea if the datagram got there
209 1.1 scottr * Notes: clnt_call() will always fail (with timeout) as we are
210 1.1 scottr * calling it with timeout 0 as a hack to just issue a datagram
211 1.1 scottr * without expecting a result
212 1.1 scottr */
213 1.1 scottr static void
214 1.1 scottr transmit_result(opcode, result, req)
215 1.1 scottr int opcode;
216 1.1 scottr nlm_res *result;
217 1.1 scottr struct svc_req *req;
218 1.1 scottr {
219 1.1 scottr static char dummy;
220 1.1 scottr struct sockaddr_in *addr;
221 1.1 scottr CLIENT *cli;
222 1.1 scottr struct timeval timeo;
223 1.1 scottr int success;
224 1.1 scottr
225 1.1 scottr addr = svc_getcaller(req->rq_xprt);
226 1.2 lukem if ((cli = get_client(addr)) != NULL) {
227 1.1 scottr timeo.tv_sec = 0; /* No timeout - not expecting response */
228 1.1 scottr timeo.tv_usec = 0;
229 1.1 scottr
230 1.1 scottr success = clnt_call(cli, opcode, xdr_nlm_res, result, xdr_void,
231 1.1 scottr &dummy, timeo);
232 1.1 scottr
233 1.1 scottr if (debug_level > 2)
234 1.1 scottr syslog(LOG_DEBUG, "clnt_call returns %d\n", success);
235 1.1 scottr }
236 1.1 scottr }
237 1.1 scottr /* ------------------------------------------------------------------------- */
238 1.1 scottr /*
239 1.1 scottr * Functions for Unix<->Unix locking (ie. monitored locking, with rpc.statd
240 1.1 scottr * involved to ensure reclaim of locks after a crash of the "stateless"
241 1.1 scottr * server.
242 1.1 scottr *
243 1.1 scottr * These all come in two flavours - nlm_xxx() and nlm_xxx_msg().
244 1.1 scottr * The first are standard RPCs with argument and result.
245 1.1 scottr * The nlm_xxx_msg() calls implement exactly the same functions, but
246 1.1 scottr * use two pseudo-RPCs (one in each direction). These calls are NOT
247 1.1 scottr * standard use of the RPC protocol in that they do not return a result
248 1.1 scottr * at all (NB. this is quite different from returning a void result).
249 1.1 scottr * The effect of this is to make the nlm_xxx_msg() calls simple unacknowledged
250 1.1 scottr * datagrams, requiring higher-level code to perform retries.
251 1.1 scottr *
252 1.1 scottr * Despite the disadvantages of the nlm_xxx_msg() approach (some of which
253 1.1 scottr * are documented in the comments to get_client() above), this is the
254 1.1 scottr * interface used by all current commercial NFS implementations
255 1.1 scottr * [Solaris, SCO, AIX etc.]. This is presumed to be because these allow
256 1.1 scottr * implementations to continue using the standard RPC libraries, while
257 1.1 scottr * avoiding the block-until-result nature of the library interface.
258 1.1 scottr *
259 1.1 scottr * No client implementations have been identified so far that make use
260 1.1 scottr * of the true RPC version (early SunOS releases would be a likely candidate
261 1.1 scottr * for testing).
262 1.1 scottr */
263 1.1 scottr
264 1.1 scottr /* nlm_test ---------------------------------------------------------------- */
265 1.1 scottr /*
266 1.1 scottr * Purpose: Test whether a specified lock would be granted if requested
267 1.1 scottr * Returns: nlm_granted (or error code)
268 1.1 scottr * Notes:
269 1.1 scottr */
270 1.1 scottr nlm_testres *
271 1.1 scottr nlm_test_1_svc(arg, rqstp)
272 1.1 scottr nlm_testargs *arg;
273 1.1 scottr struct svc_req *rqstp;
274 1.1 scottr {
275 1.1 scottr static nlm_testres res;
276 1.1 scottr
277 1.1 scottr if (debug_level)
278 1.1 scottr log_from_addr("nlm_test", rqstp);
279 1.1 scottr
280 1.1 scottr /*
281 1.1 scottr * Copy the cookie from the argument into the result. Note that this
282 1.1 scottr * is slightly hazardous, as the structure contains a pointer to a
283 1.1 scottr * malloc()ed buffer that will get freed by the caller. However, the
284 1.1 scottr * main function transmits the result before freeing the argument
285 1.1 scottr * so it is in fact safe.
286 1.1 scottr */
287 1.1 scottr res.cookie = arg->cookie;
288 1.1 scottr res.stat.stat = nlm_granted;
289 1.1 scottr return (&res);
290 1.1 scottr }
291 1.1 scottr
292 1.1 scottr void *
293 1.1 scottr nlm_test_msg_1_svc(arg, rqstp)
294 1.1 scottr nlm_testargs *arg;
295 1.1 scottr struct svc_req *rqstp;
296 1.1 scottr {
297 1.1 scottr nlm_testres res;
298 1.1 scottr static char dummy;
299 1.1 scottr struct sockaddr_in *addr;
300 1.1 scottr CLIENT *cli;
301 1.1 scottr int success;
302 1.1 scottr struct timeval timeo;
303 1.1 scottr
304 1.1 scottr if (debug_level)
305 1.1 scottr log_from_addr("nlm_test_msg", rqstp);
306 1.1 scottr
307 1.1 scottr res.cookie = arg->cookie;
308 1.1 scottr res.stat.stat = nlm_granted;
309 1.1 scottr
310 1.1 scottr /*
311 1.1 scottr * nlm_test has different result type to the other operations, so
312 1.1 scottr * can't use transmit_result() in this case
313 1.1 scottr */
314 1.1 scottr addr = svc_getcaller(rqstp->rq_xprt);
315 1.2 lukem if ((cli = get_client(addr)) != NULL) {
316 1.1 scottr timeo.tv_sec = 0; /* No timeout - not expecting response */
317 1.1 scottr timeo.tv_usec = 0;
318 1.1 scottr
319 1.1 scottr success = clnt_call(cli, NLM_TEST_RES, xdr_nlm_testres,
320 1.1 scottr &res, xdr_void, &dummy, timeo);
321 1.1 scottr
322 1.1 scottr if (debug_level > 2)
323 1.1 scottr syslog(LOG_DEBUG, "clnt_call returns %d\n", success);
324 1.1 scottr }
325 1.1 scottr return (NULL);
326 1.1 scottr }
327 1.1 scottr
328 1.1 scottr /* nlm_lock ---------------------------------------------------------------- */
329 1.1 scottr /*
330 1.1 scottr * Purposes: Establish a lock
331 1.1 scottr * Returns: granted, denied or blocked
332 1.1 scottr * Notes: *** grace period support missing
333 1.1 scottr */
334 1.1 scottr nlm_res *
335 1.1 scottr nlm_lock_1_svc(arg, rqstp)
336 1.1 scottr nlm_lockargs *arg;
337 1.1 scottr struct svc_req *rqstp;
338 1.1 scottr {
339 1.1 scottr static nlm_res res;
340 1.1 scottr
341 1.1 scottr if (debug_level)
342 1.1 scottr log_from_addr("nlm_lock", rqstp);
343 1.1 scottr
344 1.1 scottr /* copy cookie from arg to result. See comment in nlm_test_1() */
345 1.1 scottr res.cookie = arg->cookie;
346 1.1 scottr
347 1.1 scottr res.stat.stat = nlm_granted;
348 1.1 scottr return (&res);
349 1.1 scottr }
350 1.1 scottr
351 1.1 scottr void *
352 1.1 scottr nlm_lock_msg_1_svc(arg, rqstp)
353 1.1 scottr nlm_lockargs *arg;
354 1.1 scottr struct svc_req *rqstp;
355 1.1 scottr {
356 1.1 scottr static nlm_res res;
357 1.1 scottr
358 1.1 scottr if (debug_level)
359 1.1 scottr log_from_addr("nlm_lock_msg", rqstp);
360 1.1 scottr
361 1.1 scottr res.cookie = arg->cookie;
362 1.1 scottr res.stat.stat = nlm_granted;
363 1.1 scottr transmit_result(NLM_LOCK_RES, &res, rqstp);
364 1.1 scottr
365 1.1 scottr return (NULL);
366 1.1 scottr }
367 1.1 scottr
368 1.1 scottr /* nlm_cancel -------------------------------------------------------------- */
369 1.1 scottr /*
370 1.1 scottr * Purpose: Cancel a blocked lock request
371 1.1 scottr * Returns: granted or denied
372 1.1 scottr * Notes:
373 1.1 scottr */
374 1.1 scottr nlm_res *
375 1.1 scottr nlm_cancel_1_svc(arg, rqstp)
376 1.1 scottr nlm_cancargs *arg;
377 1.1 scottr struct svc_req *rqstp;
378 1.1 scottr {
379 1.1 scottr static nlm_res res;
380 1.1 scottr
381 1.1 scottr if (debug_level)
382 1.1 scottr log_from_addr("nlm_cancel", rqstp);
383 1.1 scottr
384 1.1 scottr /* copy cookie from arg to result. See comment in nlm_test_1() */
385 1.1 scottr res.cookie = arg->cookie;
386 1.1 scottr
387 1.1 scottr /*
388 1.1 scottr * Since at present we never return 'nlm_blocked', there can never be
389 1.1 scottr * a lock to cancel, so this call always fails.
390 1.1 scottr */
391 1.1 scottr res.stat.stat = nlm_denied;
392 1.1 scottr return (&res);
393 1.1 scottr }
394 1.1 scottr
395 1.1 scottr void *
396 1.1 scottr nlm_cancel_msg_1_svc(arg, rqstp)
397 1.1 scottr nlm_cancargs *arg;
398 1.1 scottr struct svc_req *rqstp;
399 1.1 scottr {
400 1.1 scottr static nlm_res res;
401 1.1 scottr
402 1.1 scottr if (debug_level)
403 1.1 scottr log_from_addr("nlm_cancel_msg", rqstp);
404 1.1 scottr
405 1.1 scottr res.cookie = arg->cookie;
406 1.1 scottr /*
407 1.1 scottr * Since at present we never return 'nlm_blocked', there can never be
408 1.1 scottr * a lock to cancel, so this call always fails.
409 1.1 scottr */
410 1.1 scottr res.stat.stat = nlm_denied;
411 1.1 scottr transmit_result(NLM_CANCEL_RES, &res, rqstp);
412 1.1 scottr return (NULL);
413 1.1 scottr }
414 1.1 scottr
415 1.1 scottr /* nlm_unlock -------------------------------------------------------------- */
416 1.1 scottr /*
417 1.1 scottr * Purpose: Release an existing lock
418 1.1 scottr * Returns: Always granted, unless during grace period
419 1.1 scottr * Notes: "no such lock" error condition is ignored, as the
420 1.1 scottr * protocol uses unreliable UDP datagrams, and may well
421 1.1 scottr * re-try an unlock that has already succeeded.
422 1.1 scottr */
423 1.1 scottr nlm_res *
424 1.1 scottr nlm_unlock_1_svc(arg, rqstp)
425 1.1 scottr nlm_unlockargs *arg;
426 1.1 scottr struct svc_req *rqstp;
427 1.1 scottr {
428 1.1 scottr static nlm_res res;
429 1.1 scottr
430 1.1 scottr if (debug_level)
431 1.1 scottr log_from_addr("nlm_unlock", rqstp);
432 1.1 scottr
433 1.1 scottr res.stat.stat = nlm_granted;
434 1.1 scottr res.cookie = arg->cookie;
435 1.1 scottr
436 1.1 scottr return (&res);
437 1.1 scottr }
438 1.1 scottr
439 1.1 scottr void *
440 1.1 scottr nlm_unlock_msg_1_svc(arg, rqstp)
441 1.1 scottr nlm_unlockargs *arg;
442 1.1 scottr struct svc_req *rqstp;
443 1.1 scottr {
444 1.1 scottr static nlm_res res;
445 1.1 scottr
446 1.1 scottr if (debug_level)
447 1.1 scottr log_from_addr("nlm_unlock_msg", rqstp);
448 1.1 scottr
449 1.1 scottr res.stat.stat = nlm_granted;
450 1.1 scottr res.cookie = arg->cookie;
451 1.1 scottr
452 1.1 scottr transmit_result(NLM_UNLOCK_RES, &res, rqstp);
453 1.1 scottr return (NULL);
454 1.1 scottr }
455 1.1 scottr
456 1.1 scottr /* ------------------------------------------------------------------------- */
457 1.1 scottr /*
458 1.1 scottr * Client-side pseudo-RPCs for results. Note that for the client there
459 1.1 scottr * are only nlm_xxx_msg() versions of each call, since the 'real RPC'
460 1.1 scottr * version returns the results in the RPC result, and so the client
461 1.1 scottr * does not normally receive incoming RPCs.
462 1.1 scottr *
463 1.1 scottr * The exception to this is nlm_granted(), which is genuinely an RPC
464 1.1 scottr * call from the server to the client - a 'call-back' in normal procedure
465 1.1 scottr * call terms.
466 1.1 scottr */
467 1.1 scottr
468 1.1 scottr /* nlm_granted ------------------------------------------------------------- */
469 1.1 scottr /*
470 1.1 scottr * Purpose: Receive notification that formerly blocked lock now granted
471 1.1 scottr * Returns: always success ('granted')
472 1.1 scottr * Notes:
473 1.1 scottr */
474 1.1 scottr nlm_res *
475 1.1 scottr nlm_granted_1_svc(arg, rqstp)
476 1.1 scottr nlm_testargs *arg;
477 1.1 scottr struct svc_req *rqstp;
478 1.1 scottr {
479 1.1 scottr static nlm_res res;
480 1.1 scottr
481 1.1 scottr if (debug_level)
482 1.1 scottr log_from_addr("nlm_granted", rqstp);
483 1.1 scottr
484 1.1 scottr /* copy cookie from arg to result. See comment in nlm_test_1() */
485 1.1 scottr res.cookie = arg->cookie;
486 1.1 scottr
487 1.1 scottr res.stat.stat = nlm_granted;
488 1.1 scottr return (&res);
489 1.1 scottr }
490 1.1 scottr
491 1.1 scottr void *
492 1.1 scottr nlm_granted_msg_1_svc(arg, rqstp)
493 1.1 scottr nlm_testargs *arg;
494 1.1 scottr struct svc_req *rqstp;
495 1.1 scottr {
496 1.1 scottr static nlm_res res;
497 1.1 scottr
498 1.1 scottr if (debug_level)
499 1.1 scottr log_from_addr("nlm_granted_msg", rqstp);
500 1.1 scottr
501 1.1 scottr res.cookie = arg->cookie;
502 1.1 scottr res.stat.stat = nlm_granted;
503 1.1 scottr transmit_result(NLM_GRANTED_RES, &res, rqstp);
504 1.1 scottr return (NULL);
505 1.1 scottr }
506 1.1 scottr
507 1.1 scottr /* nlm_test_res ------------------------------------------------------------ */
508 1.1 scottr /*
509 1.1 scottr * Purpose: Accept result from earlier nlm_test_msg() call
510 1.1 scottr * Returns: Nothing
511 1.1 scottr */
512 1.1 scottr void *
513 1.1 scottr nlm_test_res_1_svc(arg, rqstp)
514 1.1 scottr nlm_testres *arg;
515 1.1 scottr struct svc_req *rqstp;
516 1.1 scottr {
517 1.1 scottr if (debug_level)
518 1.1 scottr log_from_addr("nlm_test_res", rqstp);
519 1.1 scottr return (NULL);
520 1.1 scottr }
521 1.1 scottr
522 1.1 scottr /* nlm_lock_res ------------------------------------------------------------ */
523 1.1 scottr /*
524 1.1 scottr * Purpose: Accept result from earlier nlm_lock_msg() call
525 1.1 scottr * Returns: Nothing
526 1.1 scottr */
527 1.1 scottr void *
528 1.1 scottr nlm_lock_res_1_svc(arg, rqstp)
529 1.1 scottr nlm_res *arg;
530 1.1 scottr struct svc_req *rqstp;
531 1.1 scottr {
532 1.1 scottr if (debug_level)
533 1.1 scottr log_from_addr("nlm_lock_res", rqstp);
534 1.1 scottr
535 1.1 scottr return (NULL);
536 1.1 scottr }
537 1.1 scottr
538 1.1 scottr /* nlm_cancel_res ---------------------------------------------------------- */
539 1.1 scottr /*
540 1.1 scottr * Purpose: Accept result from earlier nlm_cancel_msg() call
541 1.1 scottr * Returns: Nothing
542 1.1 scottr */
543 1.1 scottr void *
544 1.1 scottr nlm_cancel_res_1_svc(arg, rqstp)
545 1.1 scottr nlm_res *arg;
546 1.1 scottr struct svc_req *rqstp;
547 1.1 scottr {
548 1.1 scottr if (debug_level)
549 1.1 scottr log_from_addr("nlm_cancel_res", rqstp);
550 1.1 scottr return (NULL);
551 1.1 scottr }
552 1.1 scottr
553 1.1 scottr /* nlm_unlock_res ---------------------------------------------------------- */
554 1.1 scottr /*
555 1.1 scottr * Purpose: Accept result from earlier nlm_unlock_msg() call
556 1.1 scottr * Returns: Nothing
557 1.1 scottr */
558 1.1 scottr void *
559 1.1 scottr nlm_unlock_res_1_svc(arg, rqstp)
560 1.1 scottr nlm_res *arg;
561 1.1 scottr struct svc_req *rqstp;
562 1.1 scottr {
563 1.1 scottr if (debug_level)
564 1.1 scottr log_from_addr("nlm_unlock_res", rqstp);
565 1.1 scottr return (NULL);
566 1.1 scottr }
567 1.1 scottr
568 1.1 scottr /* nlm_granted_res --------------------------------------------------------- */
569 1.1 scottr /*
570 1.1 scottr * Purpose: Accept result from earlier nlm_granted_msg() call
571 1.1 scottr * Returns: Nothing
572 1.1 scottr */
573 1.1 scottr void *
574 1.1 scottr nlm_granted_res_1_svc(arg, rqstp)
575 1.1 scottr nlm_res *arg;
576 1.1 scottr struct svc_req *rqstp;
577 1.1 scottr {
578 1.1 scottr if (debug_level)
579 1.1 scottr log_from_addr("nlm_granted_res", rqstp);
580 1.1 scottr return (NULL);
581 1.1 scottr }
582 1.1 scottr
583 1.1 scottr /* ------------------------------------------------------------------------- */
584 1.1 scottr /*
585 1.1 scottr * Calls for PCNFS locking (aka non-monitored locking, no involvement
586 1.1 scottr * of rpc.statd).
587 1.1 scottr *
588 1.1 scottr * These are all genuine RPCs - no nlm_xxx_msg() nonsense here.
589 1.1 scottr */
590 1.1 scottr
591 1.1 scottr /* nlm_share --------------------------------------------------------------- */
592 1.1 scottr /*
593 1.1 scottr * Purpose: Establish a DOS-style lock
594 1.1 scottr * Returns: success or failure
595 1.1 scottr * Notes: Blocking locks are not supported - client is expected
596 1.1 scottr * to retry if required.
597 1.1 scottr */
598 1.1 scottr nlm_shareres *
599 1.1 scottr nlm_share_3_svc(arg, rqstp)
600 1.1 scottr nlm_shareargs *arg;
601 1.1 scottr struct svc_req *rqstp;
602 1.1 scottr {
603 1.1 scottr static nlm_shareres res;
604 1.1 scottr
605 1.1 scottr if (debug_level)
606 1.1 scottr log_from_addr("nlm_share", rqstp);
607 1.1 scottr
608 1.1 scottr res.cookie = arg->cookie;
609 1.1 scottr res.stat = nlm_granted;
610 1.1 scottr res.sequence = 1234356; /* X/Open says this field is ignored? */
611 1.1 scottr return (&res);
612 1.1 scottr }
613 1.1 scottr
614 1.1 scottr /* nlm_unshare ------------------------------------------------------------ */
615 1.1 scottr /*
616 1.1 scottr * Purpose: Release a DOS-style lock
617 1.1 scottr * Returns: nlm_granted, unless in grace period
618 1.1 scottr * Notes:
619 1.1 scottr */
620 1.1 scottr nlm_shareres *
621 1.1 scottr nlm_unshare_3_svc(arg, rqstp)
622 1.1 scottr nlm_shareargs *arg;
623 1.1 scottr struct svc_req *rqstp;
624 1.1 scottr {
625 1.1 scottr static nlm_shareres res;
626 1.1 scottr
627 1.1 scottr if (debug_level)
628 1.1 scottr log_from_addr("nlm_unshare", rqstp);
629 1.1 scottr
630 1.1 scottr res.cookie = arg->cookie;
631 1.1 scottr res.stat = nlm_granted;
632 1.1 scottr res.sequence = 1234356; /* X/Open says this field is ignored? */
633 1.1 scottr return (&res);
634 1.1 scottr }
635 1.1 scottr
636 1.1 scottr /* nlm_nm_lock ------------------------------------------------------------ */
637 1.1 scottr /*
638 1.1 scottr * Purpose: non-monitored version of nlm_lock()
639 1.1 scottr * Returns: as for nlm_lock()
640 1.1 scottr * Notes: These locks are in the same style as the standard nlm_lock,
641 1.1 scottr * but the rpc.statd should not be called to establish a
642 1.1 scottr * monitor for the client machine, since that machine is
643 1.1 scottr * declared not to be running a rpc.statd, and so would not
644 1.1 scottr * respond to the statd protocol.
645 1.1 scottr */
646 1.1 scottr nlm_res *
647 1.1 scottr nlm_nm_lock_3_svc(arg, rqstp)
648 1.1 scottr nlm_lockargs *arg;
649 1.1 scottr struct svc_req *rqstp;
650 1.1 scottr {
651 1.1 scottr static nlm_res res;
652 1.1 scottr
653 1.1 scottr if (debug_level)
654 1.1 scottr log_from_addr("nlm_nm_lock", rqstp);
655 1.1 scottr
656 1.1 scottr /* copy cookie from arg to result. See comment in nlm_test_1() */
657 1.1 scottr res.cookie = arg->cookie;
658 1.1 scottr res.stat.stat = nlm_granted;
659 1.1 scottr return (&res);
660 1.1 scottr }
661 1.1 scottr
662 1.1 scottr /* nlm_free_all ------------------------------------------------------------ */
663 1.1 scottr /*
664 1.1 scottr * Purpose: Release all locks held by a named client
665 1.1 scottr * Returns: Nothing
666 1.1 scottr * Notes: Potential denial of service security problem here - the
667 1.1 scottr * locks to be released are specified by a host name, independent
668 1.1 scottr * of the address from which the request has arrived.
669 1.1 scottr * Should probably be rejected if the named host has been
670 1.1 scottr * using monitored locks.
671 1.1 scottr */
672 1.1 scottr void *
673 1.1 scottr nlm_free_all_3_svc(arg, rqstp)
674 1.1 scottr nlm_notify *arg;
675 1.1 scottr struct svc_req *rqstp;
676 1.1 scottr {
677 1.1 scottr static char dummy;
678 1.1 scottr
679 1.1 scottr if (debug_level)
680 1.1 scottr log_from_addr("nlm_free_all", rqstp);
681 1.1 scottr return (&dummy);
682 1.1 scottr }
683