]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/statd/simu.c
nfs-utils: Provide type-checked version of svc_getcaller()
[nfs-utils.git] / utils / statd / simu.c
index fa4e3a63da246608bd11fd934639c9d2c55aa3cc..a7ecb85c275509e687c4351955c4c5b4d1e3c03d 100644 (file)
@@ -4,7 +4,13 @@
  * NSM for Linux.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <arpa/inet.h>
+
+#include "rpcmisc.h"
 #include "statd.h"
 #include "notlist.h"
 
@@ -17,13 +23,33 @@ 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;
+
+  if (sin->sin_family != AF_INET) {
+    note(N_WARNING, "Call to statd from non-AF_INET address");
+    goto failure;
+  }
+
+  caller = sin->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(sin->sin_port) >= 1024) {
+    note(N_WARNING, "Call to statd-simu-crash from unprivileged port");
+    goto failure;
+  }
 
-  log (L_WARNING, "*** SIMULATING CRASH! ***");
+  note (N_WARNING, "*** SIMULATING CRASH! ***");
   my_svc_exit ();
 
   if (rtnl)
     nlist_kill (&rtnl);
 
+ failure:
   return ((void *)&result);
 }