svn rev #23439: trunk/src/ kadmin/testing/scripts/ tests/resolve/

raeburn@MIT.EDU raeburn at MIT.EDU
Wed Dec 2 21:17:24 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=23439
Commit By: raeburn
Log Message:
ticket: 6590
subject: allow testing even if name->addr->name mapping doesn't work

Many of the tests are set up to fail if the local hostname can't be
mapped to an address and back to a name again.  If the name results in
an address, and we can get a fully-qualified name or something that
looks like it, though, we should be able to just go ahead and run some
tests.

This is also closer to the current behavior of sname_to_principal when
reverse DNS is enabled.


Changed Files:
U   trunk/src/kadmin/testing/scripts/make-host-keytab.plin
U   trunk/src/kadmin/testing/scripts/qualname.plin
U   trunk/src/tests/resolve/resolve.c
Modified: trunk/src/kadmin/testing/scripts/make-host-keytab.plin
===================================================================
--- trunk/src/kadmin/testing/scripts/make-host-keytab.plin	2009-12-03 02:17:20 UTC (rev 23438)
+++ trunk/src/kadmin/testing/scripts/make-host-keytab.plin	2009-12-03 02:17:24 UTC (rev 23439)
@@ -54,8 +54,8 @@
 
 ($canonhost,$aliases,$addrtype,$length, at addrs) = gethostbyname($canonhost);
 die "couldn't get canonical hostname\n" if !($canonhost && @addrs);
-($canonhost) = gethostbyaddr($addrs[0],$addrtype);
-die "couldn't get canonical hostname\n" if (!$canonhost);
+($canonhost2) = gethostbyaddr($addrs[0],$addrtype);
+if ($canonhost2) { $canonhost = $canonhost2; }
 
 for (@princs) {
     s/xCANONHOSTx/$canonhost/g;

Modified: trunk/src/kadmin/testing/scripts/qualname.plin
===================================================================
--- trunk/src/kadmin/testing/scripts/qualname.plin	2009-12-03 02:17:20 UTC (rev 23438)
+++ trunk/src/kadmin/testing/scripts/qualname.plin	2009-12-03 02:17:24 UTC (rev 23439)
@@ -6,13 +6,12 @@
     $hostname = $ARGV[0];
 }
 
-if (! (($type,$addr) = (gethostbyname($hostname))[2,4])) {
+if (! (($name,$type,$addr) = (gethostbyname($hostname))[0,2,4])) {
     print STDERR "No such host: $hostname\n";
     exit(1);
 }
 if (! ($qualname = (gethostbyaddr($addr,$type))[0])) {
-    print STDERR "No address information for host $hostname\n";
-    exit(1);
+    $qualname = $name;
 }
 
 $qualname =~ tr/A-Z/a-z/;	# lowercase our name for keytab use.

Modified: trunk/src/tests/resolve/resolve.c
===================================================================
--- trunk/src/tests/resolve/resolve.c	2009-12-03 02:17:20 UTC (rev 23438)
+++ trunk/src/tests/resolve/resolve.c	2009-12-03 02:17:24 UTC (rev 23439)
@@ -31,7 +31,7 @@
  * domain name, then the resolve library is broken.
  *
  * Warning: It is possible to fool this program into thinking everything is
- * alright byt a clever use of /etc/hosts - but this is better than nothing.
+ * alright by a clever use of /etc/hosts - but this is better than nothing.
  *
  * Usage:
  *   resolve [hostname]
@@ -79,7 +79,7 @@
     char **argv;
 {
     char myname[MAXHOSTNAMELEN+1];
-    char *ptr;
+    char *ptr, *fqdn;
     struct in_addr addrcopy;
     struct hostent *host;
     int quiet = 0;
@@ -120,6 +120,12 @@
         exit(2);
     }
 
+    fqdn = strdup(host->h_name);
+    if (fqdn == NULL) {
+        perror("strdup");
+        exit(2);
+    }
+
     ptr = host->h_addr_list[0];
 #define UC(a) (((int)a)&0xff)
     if (!quiet)
@@ -129,22 +135,29 @@
     memcpy(&addrcopy.s_addr, ptr, 4);
 
     /* Convert back to full name */
-    if((host = gethostbyaddr(&addrcopy.s_addr, 4, AF_INET)) == NULL) {
-        fprintf(stderr, "Error looking up IP address - fatal\n");
-        exit(2);
+    if ((host = gethostbyaddr(&addrcopy.s_addr, 4, AF_INET)) == NULL) {
+        if (!quiet)
+            fprintf(stderr, "Error looking up IP address\n");
+    } else {
+        free(fqdn);
+        fqdn = strdup(host->h_name);
+        if (fqdn == NULL) {
+            perror("strdup");
+            exit (2);
+        }
     }
 
     if (quiet)
-        printf("%s\n", host->h_name);
+        printf("%s\n", fqdn);
     else
-        printf("FQDN: %s\n", host->h_name);
+        printf("FQDN: %s\n", fqdn);
 
     /*
      * The host name must have at least one '.' in the name, and
      * if there is only one '.', it must not be at the end of the
      * string.  (i.e., "foo." is not a FQDN)
      */
-    ptr = strchr(host->h_name, '.');
+    ptr = strchr(fqdn, '.');
     if (ptr == NULL || ptr[1] == '\0') {
         fprintf(stderr,
                 "\nResolve library did not return a "




More information about the cvs-krb5 mailing list