X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fstatd%2Fmonitor.c;h=325dfd3ac8bb3c12b7b6ab07b6b97923d46bd615;hp=fb321967759419c705c64a8cb6349f3cd6c8d1b6;hb=05f93b531d59df6e976d9b40c97b51546524040a;hpb=7f98c14d38badedd30d2d4a6b1d15e913967bf87 diff --git a/utils/statd/monitor.c b/utils/statd/monitor.c index fb32196..325dfd3 100644 --- a/utils/statd/monitor.c +++ b/utils/statd/monitor.c @@ -71,8 +71,7 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) .sin_family = AF_INET, .sin_addr.s_addr = htonl(INADDR_LOOPBACK), }; - char *dnsname; - struct hostent *hostinfo = NULL; + char *dnsname = NULL; xlog(D_CALL, "Received SM_MON for %s from %s", mon_name, my_name); @@ -114,9 +113,6 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) "or starting '.': %s", mon_name); xlog(L_ERROR, "POSSIBLE SPOOF/ATTACK ATTEMPT!"); goto failure; - } else if ((hostinfo = gethostbyname(mon_name)) == NULL) { - xlog_warn("gethostbyname error for %s", mon_name); - goto failure; } /* my_name must not have white space */ @@ -129,15 +125,13 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) * Now choose a hostname to use for matching. We cannot * really trust much in the incoming NOTIFY, so to make * sure that multi-homed hosts work nicely, we get an - * FQDN now, and use that for matching + * FQDN now, and use that for matching. */ - hostinfo = gethostbyaddr(hostinfo->h_addr, - hostinfo->h_length, - hostinfo->h_addrtype); - if (hostinfo) - dnsname = xstrdup(hostinfo->h_name); - else - dnsname = xstrdup(my_name); + dnsname = statd_canonical_name(mon_name); + if (dnsname == NULL) { + xlog(L_WARNING, "No canonical hostname found for %s", mon_name); + goto failure; + } /* Now check to see if this is a duplicate, and warn if so. * I will also return STAT_FAIL. (I *think* this is how I should @@ -163,6 +157,7 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) mon_name, my_name); /* But we'll let you pass anyway. */ + free(dnsname); goto success; } clnt = NL_NEXT(clnt); @@ -173,11 +168,11 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) * doesn't fail. (I should probably fix this assumption.) */ if (!(clnt = nlist_new(my_name, mon_name, 0))) { + free(dnsname); xlog_warn("out of memory"); goto failure; } - NL_ADDR(clnt) = my_addr.sin_addr; NL_MY_PROG(clnt) = id->my_prog; NL_MY_VERS(clnt) = id->my_vers; NL_MY_PROC(clnt) = id->my_proc; @@ -218,11 +213,11 @@ failure: } static unsigned int -load_one_host(const char *hostname, const struct sockaddr *sap, +load_one_host(const char *hostname, + __attribute__ ((unused)) const struct sockaddr *sap, const struct mon *m, __attribute__ ((unused)) const time_t timestamp) { - const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; notify_list *clnt; clnt = nlist_new(m->mon_id.my_id.my_name, @@ -239,7 +234,6 @@ load_one_host(const char *hostname, const struct sockaddr *sap, xlog(D_GENERAL, "Adding record for %s to the monitor list...", hostname); - NL_ADDR(clnt) = sin->sin_addr; NL_MY_PROG(clnt) = m->mon_id.my_id.my_prog; NL_MY_VERS(clnt) = m->mon_id.my_id.my_vers; NL_MY_PROC(clnt) = m->mon_id.my_id.my_proc;