summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mountd/mountd.c
diff options
context:
space:
mode:
authoriedowse <iedowse@FreeBSD.org>2001-04-23 10:12:31 +0000
committeriedowse <iedowse@FreeBSD.org>2001-04-23 10:12:31 +0000
commitba96b53461e2b4ea9034c2e532e2abbf478772bf (patch)
tree8c3ff1d7c719ac157eae339261f3148cc6de41a5 /usr.sbin/mountd/mountd.c
parentc22f3155bd89779380c9cea759931fe8a8ded233 (diff)
downloadFreeBSD-src-ba96b53461e2b4ea9034c2e532e2abbf478772bf.zip
FreeBSD-src-ba96b53461e2b4ea9034c2e532e2abbf478772bf.tar.gz
Reinstate one more old bugfix that got lost in the tirpc commit:
always look up -network and -mask addresses numerically before trying getnetbyname(). Without this, we may end up attempting DNS queries on silly names such as "127.0.0.0.my-domain.com". See the commit log from revisions 1.21 and 1.20 for further details.
Diffstat (limited to 'usr.sbin/mountd/mountd.c')
-rw-r--r--usr.sbin/mountd/mountd.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c
index 3726cba..cab8bc0 100644
--- a/usr.sbin/mountd/mountd.c
+++ b/usr.sbin/mountd/mountd.c
@@ -1866,10 +1866,10 @@ get_net(cp, net, maskflg)
struct netmsk *net;
int maskflg;
{
- struct netent *np;
+ struct netent *np = NULL;
char *name, *p, *prefp;
struct sockaddr_in sin;
- struct sockaddr *sa;
+ struct sockaddr *sa = NULL;
struct addrinfo hints, *ai = NULL;
char netname[NI_MAXHOST];
long preflen;
@@ -1881,13 +1881,11 @@ get_net(cp, net, maskflg)
prefp = p + 1;
}
- if ((np = getnetbyname(cp)) != NULL) {
- bzero(&sin, sizeof sin);
- sin.sin_family = AF_INET;
- sin.sin_len = sizeof sin;
- sin.sin_addr = inet_makeaddr(np->n_net, 0);
- sa = (struct sockaddr *)&sin;
- } else if (isxdigit(*cp) || *cp == ':') {
+ /*
+ * Check for a numeric address first. We wish to avoid
+ * possible DNS lookups in getnetbyname().
+ */
+ if (isxdigit(*cp) || *cp == ':') {
memset(&hints, 0, sizeof hints);
/* Ensure the mask and the network have the same family. */
if (maskflg && (opt_flags & OP_NET))
@@ -1897,9 +1895,9 @@ get_net(cp, net, maskflg)
else
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_NUMERICHOST;
- if (getaddrinfo(cp, NULL, &hints, &ai) != 0)
- goto fail;
- if (ai->ai_family == AF_INET) {
+ if (getaddrinfo(cp, NULL, &hints, &ai) == 0)
+ sa = ai->ai_addr;
+ if (sa != NULL && ai->ai_family == AF_INET) {
/*
* The address in `cp' is really a network address, so
* use inet_network() to re-interpret this correctly.
@@ -1913,9 +1911,16 @@ get_net(cp, net, maskflg)
fprintf(stderr, "get_net: v4 addr %s\n",
inet_ntoa(sin.sin_addr));
sa = (struct sockaddr *)&sin;
- } else
- sa = ai->ai_addr;
- } else
+ }
+ }
+ if (sa == NULL && (np = getnetbyname(cp)) != NULL) {
+ bzero(&sin, sizeof sin);
+ sin.sin_family = AF_INET;
+ sin.sin_len = sizeof sin;
+ sin.sin_addr = inet_makeaddr(np->n_net, 0);
+ sa = (struct sockaddr *)&sin;
+ }
+ if (sa == NULL)
goto fail;
if (maskflg) {
OpenPOWER on IntegriCloud