]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/statd/simu.c
rpc.statd: eliminate --secure_statd
[nfs-utils.git] / utils / statd / simu.c
index 78a6ee2e9d6cc059d233b11c4efa8ef9631ff2af..25e8badad160246f2efb600a51659deed8fb4d9e 100644 (file)
@@ -4,7 +4,11 @@
  * NSM for Linux.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <arpa/inet.h>
+
 #include "statd.h"
 #include "notlist.h"
 
@@ -18,6 +22,19 @@ void *
 sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
 {
   static char *result = NULL;
+  struct in_addr caller;
+
+  caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
+  if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
+    note(N_WARNING, "Call to statd from non-local host %s",
+      inet_ntoa(caller));
+    goto failure;
+  }
+
+  if (ntohs(svc_getcaller(rqstp->rq_xprt)->sin_port) >= 1024) {
+    note(N_WARNING, "Call to statd-simu-crash from unprivileged port");
+    goto failure;
+  }
 
   note (N_WARNING, "*** SIMULATING CRASH! ***");
   my_svc_exit ();
@@ -25,5 +42,6 @@ sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
   if (rtnl)
     nlist_kill (&rtnl);
 
+ failure:
   return ((void *)&result);
 }