X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fstatd%2Fsimu.c;h=f1d0bf886f3dfb5caf87ebdeb38406a75db4b329;hp=82d794e1c2667a20198f0cb24a89bcf5e95f75ca;hb=05f93b531d59df6e976d9b40c97b51546524040a;hpb=dad50c0e589b5651242de50e81200b036d995b73 diff --git a/utils/statd/simu.c b/utils/statd/simu.c index 82d794e..f1d0bf8 100644 --- a/utils/statd/simu.c +++ b/utils/statd/simu.c @@ -7,8 +7,12 @@ #ifdef HAVE_CONFIG_H #include #endif + +#include #include +#include "sockaddr.h" +#include "rpcmisc.h" #include "statd.h" #include "notlist.h" @@ -17,40 +21,39 @@ 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; -#ifdef RESTRICTED_STATD - struct in_addr caller; - - /* 1. Reject anyone not calling from 127.0.0.1. - * Ignore the my_name specified by the caller, and - * use "127.0.0.1" instead. - */ - 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\n"); - goto failure; - } -#endif - note (N_WARNING, "*** SIMULATING CRASH! ***"); + xlog(D_CALL, "Received SM_SIMU_CRASH"); + + if (!nfs_is_v4_loopback(sap)) + goto out_nonlocal; + + if ((int)nfs_get_port(sap) >= IPPORT_RESERVED) { + xlog_warn("SM_SIMU_CRASH call from unprivileged port"); + goto failure; + } + my_svc_exit (); if (rtnl) nlist_kill (&rtnl); -#ifdef RESTRICTED_STATD failure: -#endif 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; }