]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/statd/simu.c
a7ecb85c275509e687c4351955c4c5b4d1e3c03d
[nfs-utils.git] / utils / statd / simu.c
1 /*
2  * Copyright (C) 1995, 1997-1999 Jeffrey A. Uphoff
3  *
4  * NSM for Linux.
5  */
6
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10
11 #include <arpa/inet.h>
12
13 #include "rpcmisc.h"
14 #include "statd.h"
15 #include "notlist.h"
16
17 extern void my_svc_exit (void);
18
19
20 /*
21  * Services SM_SIMU_CRASH requests.
22  */
23 void *
24 sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
25 {
26   struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
27   static char *result = NULL;
28   struct in_addr caller;
29
30   if (sin->sin_family != AF_INET) {
31     note(N_WARNING, "Call to statd from non-AF_INET address");
32     goto failure;
33   }
34
35   caller = sin->sin_addr;
36   if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
37     note(N_WARNING, "Call to statd from non-local host %s",
38       inet_ntoa(caller));
39     goto failure;
40   }
41
42   if (ntohs(sin->sin_port) >= 1024) {
43     note(N_WARNING, "Call to statd-simu-crash from unprivileged port");
44     goto failure;
45   }
46
47   note (N_WARNING, "*** SIMULATING CRASH! ***");
48   my_svc_exit ();
49
50   if (rtnl)
51     nlist_kill (&rtnl);
52
53  failure:
54   return ((void *)&result);
55 }