]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/statd/simu.c
mountd: Use static buffer when constructing junction export options
[nfs-utils.git] / utils / statd / simu.c
index 25e8badad160246f2efb600a51659deed8fb4d9e..f1d0bf886f3dfb5caf87ebdeb38406a75db4b329 100644 (file)
@@ -7,8 +7,12 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+
+#include <netdb.h>
 #include <arpa/inet.h>
 
+#include "sockaddr.h"
+#include "rpcmisc.h"
 #include "statd.h"
 #include "notlist.h"
 
@@ -17,26 +21,28 @@ extern void my_svc_exit (void);
 
 /*
  * Services SM_SIMU_CRASH requests.
+ *
+ * Although the kernel contacts the statd service via only IPv4
+ * transports, the statd service can receive other requests, such
+ * as SM_NOTIFY, from remote peers via IPv6.
  */
 void *
-sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
+sm_simu_crash_1_svc (__attribute__ ((unused)) void *argp, struct svc_req *rqstp)
 {
+  struct sockaddr *sap = nfs_getrpccaller(rqstp->rq_xprt);
+  char buf[INET6_ADDRSTRLEN];
   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;
-  }
+  xlog(D_CALL, "Received SM_SIMU_CRASH");
+
+  if (!nfs_is_v4_loopback(sap))
+    goto out_nonlocal;
 
-  if (ntohs(svc_getcaller(rqstp->rq_xprt)->sin_port) >= 1024) {
-    note(N_WARNING, "Call to statd-simu-crash from unprivileged port");
+  if ((int)nfs_get_port(sap) >= IPPORT_RESERVED) {
+    xlog_warn("SM_SIMU_CRASH call from unprivileged port");
     goto failure;
   }
 
-  note (N_WARNING, "*** SIMULATING CRASH! ***");
   my_svc_exit ();
 
   if (rtnl)
@@ -44,4 +50,10 @@ sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
 
  failure:
   return ((void *)&result);
+
+ out_nonlocal:
+  if (!statd_present_address(sap, buf, sizeof(buf)))
+    buf[0] = '\0';
+  xlog_warn("SM_SIMU_CRASH call from non-local host %s", buf);
+  goto failure;
 }