Bob Proulx pointed out the README made mention of sudoers not a conffile
[debian/sudo] / interfaces.c
index b3dc14e91454a9475c1a5fa70e335b092dc31cb9..502cb94ae5e4afb39b399d1056fd2a6edfd6844a 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (c) 1996, 1998-2005 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1996, 1998-2005, 2007-2010
+ *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -19,7 +20,7 @@
  */
 
 /*
- * Supress a warning w/ gcc on Digital UN*X.
+ * Suppress a warning w/ gcc on Digital UN*X.
  * The system headers should really do this....
  */
 #if defined(__osf__) && !defined(__cplusplus)
@@ -51,19 +52,13 @@ struct rtentry;
 #  include <memory.h>
 # endif
 # include <string.h>
-#else
-# ifdef HAVE_STRINGS_H
-#  include <strings.h>
-# endif
 #endif /* HAVE_STRING_H */
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
-#ifdef HAVE_ERR_H
-# include <err.h>
-#else
-# include "emul/err.h"
-#endif /* HAVE_ERR_H */
 #include <netdb.h>
 #include <errno.h>
 #ifdef _ISC
@@ -88,10 +83,10 @@ struct rtentry;
 #include "sudo.h"
 #include "interfaces.h"
 
-#ifndef lint
-__unused static const char rcsid[] = "$Sudo: interfaces.c,v 1.72.2.6 2007/08/14 15:19:25 millert Exp $";
-#endif /* lint */
-
+/* Minix apparently lacks IFF_LOOPBACK */
+#ifndef IFF_LOOPBACK
+# define IFF_LOOPBACK  0
+#endif
 
 #ifdef HAVE_GETIFADDRS
 
@@ -104,7 +99,7 @@ load_interfaces()
 {
     struct ifaddrs *ifa, *ifaddrs;
     struct sockaddr_in *sin;
-#ifdef AF_INET6
+#ifdef HAVE_IN6_ADDR
     struct sockaddr_in6 *sin6;
 #endif
     int i;
@@ -121,7 +116,7 @@ load_interfaces()
 
        switch(ifa->ifa_addr->sa_family) {
            case AF_INET:
-#ifdef AF_INET6
+#ifdef HAVE_IN6_ADDR
            case AF_INET6:
 #endif
                num_interfaces++;
@@ -143,26 +138,34 @@ load_interfaces()
        switch(ifa->ifa_addr->sa_family) {
            case AF_INET:
                sin = (struct sockaddr_in *)ifa->ifa_addr;
+               if (sin == NULL)
+                   continue;
                memcpy(&interfaces[i].addr, &sin->sin_addr,
                    sizeof(struct in_addr));
                sin = (struct sockaddr_in *)ifa->ifa_netmask;
+               if (sin == NULL)
+                   continue;
                memcpy(&interfaces[i].netmask, &sin->sin_addr,
                    sizeof(struct in_addr));
                interfaces[i].family = AF_INET;
                i++;
                break;
-#ifdef AF_INET6
+#ifdef HAVE_IN6_ADDR
            case AF_INET6:
                sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
+               if (sin6 == NULL)
+                   continue;
                memcpy(&interfaces[i].addr, &sin6->sin6_addr,
                    sizeof(struct in6_addr));
                sin6 = (struct sockaddr_in6 *)ifa->ifa_netmask;
+               if (sin6 == NULL)
+                   continue;
                memcpy(&interfaces[i].netmask, &sin6->sin6_addr,
                    sizeof(struct in6_addr));
                interfaces[i].family = AF_INET6;
                i++;
                break;
-#endif /* AF_INET6 */
+#endif /* HAVE_IN6_ADDR */
        }
     }
 #ifdef HAVE_FREEIFADDRS
@@ -193,7 +196,7 @@ load_interfaces()
 
     sock = socket(AF_INET, SOCK_DGRAM, 0);
     if (sock < 0)
-       err(1, "cannot open socket");
+       error(1, "cannot open socket");
 
     /*
      * Get interface configuration or return (leaving num_interfaces == 0)
@@ -249,7 +252,7 @@ load_interfaces()
                continue;
 
 #ifdef SIOCGIFFLAGS
-       memset(&ifr_tmp, 0, sizeof(ifr_tmp));
+       zero_bytes(&ifr_tmp, sizeof(ifr_tmp));
        strncpy(ifr_tmp.ifr_name, ifr->ifr_name, sizeof(ifr_tmp.ifr_name) - 1);
        if (ioctl(sock, SIOCGIFFLAGS, (caddr_t) &ifr_tmp) < 0)
 #endif
@@ -267,7 +270,7 @@ load_interfaces()
        previfname = ifr->ifr_name;
 
        /* Get the netmask. */
-       (void) memset(&ifr_tmp, 0, sizeof(ifr_tmp));
+       zero_bytes(&ifr_tmp, sizeof(ifr_tmp));
        strncpy(ifr_tmp.ifr_name, ifr->ifr_name, sizeof(ifr_tmp.ifr_name) - 1);
 #ifdef SIOCGIFNETMASK
 #ifdef _ISC
@@ -325,7 +328,7 @@ void
 dump_interfaces()
 {
     int i;
-#ifdef AF_INET6
+#ifdef HAVE_IN6_ADDR
     char addrbuf[INET6_ADDRSTRLEN], maskbuf[INET6_ADDRSTRLEN];
 #endif
 
@@ -336,7 +339,7 @@ dump_interfaces()
                printf("\t%s / ", inet_ntoa(interfaces[i].addr.ip4));
                puts(inet_ntoa(interfaces[i].netmask.ip4));
                break;
-#ifdef AF_INET6
+#ifdef HAVE_IN6_ADDR
            case AF_INET6:
                inet_ntop(AF_INET6, &interfaces[i].addr.ip6,
                    addrbuf, sizeof(addrbuf));
@@ -344,7 +347,7 @@ dump_interfaces()
                    maskbuf, sizeof(maskbuf));
                printf("\t%s / %s\n", addrbuf, maskbuf);
                break;
-#endif /* AF_INET6 */
+#endif /* HAVE_IN6_ADDR */
        }
     }
 }