]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
avoid writing loopback addresses into CellServDB
authorMichael Meffie <mmeffie@sinenomine.net>
Tue, 4 Nov 2014 00:06:15 +0000 (19:06 -0500)
committerStephan Wiesand <stephan.wiesand@desy.de>
Wed, 18 Nov 2015 16:16:55 +0000 (11:16 -0500)
Do not use loopback addresses for the server side CellServDB file.  Use
getaddrinfo() instead of gethostbyname() to look up a list of IPv4
addresses for a given hostname, and take the first non-loopback address.

This avoids writing a loopback address into the CellServDB on systems
such as Debian, which map the address 127.0.1.1 to the hostname in the
/etc/hosts file.

Reviewed-on: http://gerrit.openafs.org/11585
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: D Brashear <shadow@your-file-system.com>
(cherry picked from commit e4a8a7a38dbf29e89bc1a7b6b017447a6aa0c764)

Change-Id: Ib53b924b49c4c959c2228f953227e37fb94030a9
Reviewed-on: http://gerrit.openafs.org/12083
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
src/auth/writeconfig.c

index 185bbc473b91169b11b44eeacdeb6084455f868b..6581841b849bc73b0d845c7de3a6f29d892b3cad 100644 (file)
@@ -51,14 +51,30 @@ VerifyEntries(struct afsconf_cell *aci)
        if (aci->hostAddr[i].sin_addr.s_addr == 0) {
            /* no address spec'd */
            if (*(aci->hostName[i]) != 0) {
-               th = gethostbyname(aci->hostName[i]);
-               if (!th) {
-                   printf("Host %s not found in host database...\n",
-                          aci->hostName[i]);
+               int code;
+               struct addrinfo hints;
+               struct addrinfo *result;
+               struct addrinfo *rp;
+
+               memset(&hints, 0, sizeof(struct addrinfo));
+               hints.ai_family = AF_INET;
+               hints.ai_socktype = SOCK_DGRAM;
+
+               code = getaddrinfo(aci->hostName[i], NULL, &hints, &result);
+               if (code) {
+                   return AFSCONF_FAILURE;
+               }
+               for (rp = result; rp != NULL; rp = rp->ai_next) {
+                   struct sockaddr_in *sa = (struct sockaddr_in *)rp->ai_addr;
+                   if (!rx_IsLoopbackAddr(ntohl(sa->sin_addr.s_addr))) {
+                       aci->hostAddr[i].sin_addr.s_addr = sa->sin_addr.s_addr;
+                       break;
+                   }
+               }
+               freeaddrinfo(result);
+               if (aci->hostAddr[i].sin_addr.s_addr == 0) {
                    return AFSCONF_FAILURE;
                }
-               memcpy(&aci->hostAddr[i].sin_addr, th->h_addr,
-                      sizeof(afs_int32));
            }
            /* otherwise we're deleting this entry */
        } else {