]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/statd/simu.c
statd: Replace note() with xlog() in rpc.statd
[nfs-utils.git] / utils / statd / simu.c
index 9d685adc3da3b268408954451e4298e9b2fec25b..7df04d9080abaf406c393a79f6dee7128e6c4b1a 100644 (file)
@@ -8,6 +8,9 @@
 #include <config.h>
 #endif
 
+#include <arpa/inet.h>
+
+#include "rpcmisc.h"
 #include "statd.h"
 #include "notlist.h"
 
@@ -20,13 +23,35 @@ extern void my_svc_exit (void);
 void *
 sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
 {
+  struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
   static char *result = NULL;
+  struct in_addr caller;
+
+  xlog(D_CALL, "Received SM_SIMU_CRASH");
+
+  if (sin->sin_family != AF_INET) {
+    xlog_warn("Call to statd from non-AF_INET address");
+    goto failure;
+  }
+
+  caller = sin->sin_addr;
+  if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
+    xlog_warn("Call to statd from non-local host %s",
+      inet_ntoa(caller));
+    goto failure;
+  }
+
+  if (ntohs(sin->sin_port) >= 1024) {
+    xlog_warn("Call to statd-simu-crash from unprivileged port");
+    goto failure;
+  }
 
-  note (N_WARNING, "*** SIMULATING CRASH! ***");
+  xlog_warn("*** SIMULATING CRASH! ***");
   my_svc_exit ();
 
   if (rtnl)
     nlist_kill (&rtnl);
 
+ failure:
   return ((void *)&result);
 }