Added flag to disallow hostname -> IP lookups.
authorAlan T. DeKok <aland@freeradius.org>
Wed, 4 Dec 2013 14:17:17 +0000 (09:17 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 4 Dec 2013 14:17:17 +0000 (09:17 -0500)
Mainly for the tests .  It's still OK (and needed) for admins
to use "client.example.com" in the configs.  Requiring them to
use only IP addresses is annoying.

src/include/libradius.h
src/lib/misc.c
src/main/unittest.c

index 3be21d9..ba8f71c 100644 (file)
@@ -543,7 +543,8 @@ extern void _fr_exit_now(char const *file, int line, int status);
 #define fr_exit_now(_x) _fr_exit_now(__FILE__,  __LINE__, (_x))
 
 extern char const *fr_strerror(void);
-extern bool    fr_dns_lookups; /* 0 = no dns lookups */
+extern bool    fr_dns_lookups; /* do IP -> hostname lookups? */
+extern bool    fr_hostname_lookups; /* do hostname -> IP lookups? */
 extern int     fr_debug_flag;  /* 0 = no debugging information */
 extern int     fr_max_attributes; /* per incoming packet */
 #define        FR_MAX_PACKET_CODE (52)
index d50cba5..a1c5dc5 100644 (file)
@@ -37,7 +37,8 @@ RCSID("$Id$")
 
 static int     fr_debugger_present = -1;
 
-bool   fr_dns_lookups = false;
+bool   fr_dns_lookups = false;     /* IP -> hostname lookups? */
+bool    fr_hostname_lookups = true; /* hostname -> IP lookups? */
 int    fr_debug_flag = 0;
 
 static char const *months[] = {
@@ -466,6 +467,32 @@ int ip_hton(char const *src, int af, fr_ipaddr_t *dst)
        int rcode;
        struct addrinfo hints, *ai = NULL, *res = NULL;
 
+       if (!fr_hostname_lookups) {
+#ifdef HAVE_STRUCT_SOCKADDR_IN6
+               if (af == AF_UNSPEC) {
+                       char const *p;
+
+                       for (p = src; *p != '\0'; p++) {
+                               if ((*p == ':') ||
+                                   (*p == '[') ||
+                                   (*p == ']')) {
+                                       af = AF_INET6;
+                                       break;
+                               }
+                       }
+               }
+#endif
+
+               if (af == AF_UNSPEC) af = AF_INET;
+
+               if (!inet_pton(af, src, &(dst->ipaddr))) {
+                       return -1;
+               }
+               
+               dst->af = af;
+               return 0;
+       }
+
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = af;
 
index 892f5dc..e5ce177 100644 (file)
@@ -277,6 +277,11 @@ int main(int argc, char *argv[])
        mainconfig.name = "radiusd";
 
        /*
+        *      The tests should have only IPs, not host names.
+        */
+       fr_hostname_lookups = false;
+
+       /*
         *      We always log to stdout.
         */
        fr_log_fp = stdout;