X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils%2Fstatd%2Fmonitor.c;h=a2c9e2b091c126d2d24b84a870f946f1f479ca68;hb=6b7ad21f8162ec85766fd1369ea13ab432e287f8;hp=5d4aa49644492c776d0d96310a58d0674fae4c12;hpb=4ac04d76dc0fffe48313d6a16b4ca9b44c135818;p=nfs-utils.git diff --git a/utils/statd/monitor.c b/utils/statd/monitor.c index 5d4aa49..a2c9e2b 100644 --- a/utils/statd/monitor.c +++ b/utils/statd/monitor.c @@ -20,6 +20,8 @@ #include #include #include + +#include "rpcmisc.h" #include "misc.h" #include "statd.h" #include "notlist.h" @@ -29,7 +31,6 @@ notify_list * rtnl = NULL; /* Run-time notify list. */ #define LINELEN (4*(8+1)+SM_PRIV_SIZE*2+1) -#ifdef RESTRICTED_STATD /* * Reject requests from non-loopback addresses in order * to prevent attack described in CERT CA-99.05. @@ -37,9 +38,10 @@ notify_list * rtnl = NULL; /* Run-time notify list. */ static int caller_is_localhost(struct svc_req *rqstp) { + struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt); struct in_addr caller; - caller = svc_getcaller(rqstp->rq_xprt)->sin_addr; + caller = sin->sin_addr; if (caller.s_addr != htonl(INADDR_LOOPBACK)) { note(N_WARNING, "Call to statd from non-local host %s", @@ -48,16 +50,6 @@ caller_is_localhost(struct svc_req *rqstp) } return 1; } -#else /* RESTRICTED_STATD */ -/* - * No restrictions for remote callers. - */ -static int -caller_is_localhost(struct svc_req *rqstp) -{ - return 1; -} -#endif /* RESTRICTED_STATD */ /* * Services SM_MON requests. @@ -81,7 +73,6 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) result.res_stat = STAT_FAIL; result.state = -1; /* State is undefined for STAT_FAIL. */ -#ifdef RESTRICTED_STATD /* 1. Reject any remote callers. * Ignore the my_name specified by the caller, and * use "127.0.0.1" instead. @@ -107,28 +98,6 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) goto failure; } -#if 0 - This is not usable anymore. Linux-kernel can be configured to use - host names with NSM so that multi-homed hosts are handled properly. - NeilBrown 15mar2007 - - /* 3. mon_name must be an address in dotted quad. - * Again, specific to the linux kernel lockd. - */ - if (!inet_aton(mon_name, &mon_addr)) { - note(N_WARNING, - "Attempt to register host %s (not a dotted quad)", - mon_name); - goto failure; - } -#endif -#else - if (!(hostinfo = gethostbyname(my_name))) { - note(N_WARNING, "gethostbyname error for %s", my_name); - goto failure; - } else - my_addr = *(struct in_addr *) hostinfo->h_addr; -#endif /* * Check hostnames. If I can't look them up, I won't monitor. This * might not be legal, but it adds a little bit of safety and sanity. @@ -235,7 +204,10 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) e += sprintf(e, "%02x", 0xff & (argp->priv[i])); if (e+1-buf != LINELEN) abort(); e += sprintf(e, " %s %s\n", mon_name, my_name); - write(fd, buf, e-buf); + if (write(fd, buf, e-buf) != (e-buf)) { + note(N_WARNING, "writing to %s failed: errno %d (%s)", + path, errno, strerror(errno)); + } } free(path); @@ -360,12 +332,13 @@ sm_unmon_1_svc(struct mon_id *argp, struct svc_req *rqstp) /* Check if we're monitoring anyone. */ - if (!(clnt = rtnl)) { + if (rtnl == NULL) { note(N_WARNING, "Received SM_UNMON request from %s for %s while not " "monitoring any hosts.", my_name, argp->mon_name); return (&result); } + clnt = rtnl; /* * OK, we are. Now look for appropriate entry in run-time list. @@ -385,7 +358,7 @@ sm_unmon_1_svc(struct mon_id *argp, struct svc_req *rqstp) /* PRC: do the HA callout: */ ha_callout("del-client", mon_name, my_name, -1); - xunlink(SM_DIR, clnt->dns_name, 1); + xunlink(SM_DIR, clnt->dns_name); nlist_free(&rtnl, clnt); return (&result); @@ -413,11 +386,12 @@ sm_unmon_all_1_svc(struct my_id *argp, struct svc_req *rqstp) result.state = MY_STATE; - if (!(clnt = rtnl)) { + if (rtnl == NULL) { note(N_WARNING, "Received SM_UNMON_ALL request from %s " "while not monitoring any hosts", my_name); return (&result); } + clnt = rtnl; while ((clnt = nlist_gethost(clnt, my_name, 1))) { if (NL_MY_PROC(clnt) == argp->my_proc && @@ -436,7 +410,7 @@ sm_unmon_all_1_svc(struct my_id *argp, struct svc_req *rqstp) temp = NL_NEXT(clnt); /* PRC: do the HA callout: */ ha_callout("del-client", mon_name, my_name, -1); - xunlink(SM_DIR, clnt->dns_name, 1); + xunlink(SM_DIR, clnt->dns_name); nlist_free(&rtnl, clnt); ++count; clnt = temp;