]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix test suite issues affecting Travis images 956/head
authorGreg Hudson <ghudson@mit.edu>
Fri, 26 Jul 2019 22:33:28 +0000 (18:33 -0400)
committerGreg Hudson <ghudson@mit.edu>
Mon, 29 Jul 2019 19:22:45 +0000 (15:22 -0400)
In the utilities used by the dejagnu test suites, use
getaddrinfo()/getnameinfo() instead of
gethostbyname()/gethostbyaddr(), as the results can vary when the
local hostname appears in multiple lines in /etc/hosts.

In t_ccselect.py, don't cause an error if the canonicalized local
hostname is "localhost".  The tests will continue to run in this case,
as long as we don't try to create duplicate principals.

In sim_server.c, bind to the wildcard address instead of the resolved
local hostname, to resolve a mysterious problem observed in Travis
where the second of three sim_client send() operations fails with
ECONNREFUSED.

src/appl/simple/server/sim_server.c
src/kadmin/testing/scripts/qualname.plin
src/tests/gssapi/t_ccselect.py
src/tests/resolve/Makefile.in
src/tests/resolve/resolve.c

index f09489c35d303aaf6a9e711a44e77da755a6b2f3..ed383a00bf30a8b98720e9f7bb8ad07bcad07934 100644 (file)
@@ -69,10 +69,8 @@ main(int argc, char *argv[])
     int flags = 0;                      /* for recvfrom() */
     int on = 1;
     struct servent *serv;
-    struct hostent *host;
     struct sockaddr_in s_sock;          /* server's address */
     struct sockaddr_in c_sock;          /* client's address */
-    char full_hname[MAXHOSTNAMELEN];
     char *cp;
     extern char * optarg;
     int ch;
@@ -133,6 +131,7 @@ main(int argc, char *argv[])
     /* Set up server address */
     memset(&s_sock, 0, sizeof(s_sock));
     s_sock.sin_family = AF_INET;
+    s_sock.sin_addr.s_addr = INADDR_ANY;
 
     if (port == 0) {
         /* Look up service */
@@ -145,17 +144,6 @@ main(int argc, char *argv[])
         s_sock.sin_port = htons(port);
     }
 
-    if (gethostname(full_hname, sizeof(full_hname)) < 0) {
-        perror("gethostname");
-        exit(1);
-    }
-
-    if ((host = gethostbyname(full_hname)) == (struct hostent *)0) {
-        fprintf(stderr, "%s: host unknown\n", full_hname);
-        exit(1);
-    }
-    memcpy(&s_sock.sin_addr, host->h_addr, sizeof(s_sock.sin_addr));
-
     /* Open socket */
     if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
         perror("opening datagram socket");
index b712d89738eb9f1ea056b57f2356ef3462fed8c5..ccc57e3a735ff4fc10daa4f23fa9b3f1fd2a4a4a 100755 (executable)
@@ -1,19 +1,20 @@
-#!/afs/athena/contrib/perl/p
+#!/usr/bin/perl
+use Socket qw(:addrinfo);
+use strict;
 
+my $hostname;
 if ($#ARGV == -1) {
     chop($hostname = `hostname`);
 } else {
     $hostname = $ARGV[0];
 }
 
-if (! (($name,$type,$addr) = (gethostbyname($hostname))[0,2,4])) {
-    print STDERR "No such host: $hostname\n";
-    exit(1);
-}
-if (! ($qualname = (gethostbyaddr($addr,$type))[0])) {
-    $qualname = $name;
-}
+my ($gaerr, @addrs) = getaddrinfo($hostname, "", {flags => AI_CANONNAME});
+die "No such host: $hostname ($gaerr)" if $gaerr;
+my ($canonname, $addr) = ($addrs[0]->{canonname}, $addrs[0]->{addr});
+
+my ($gnerr, $name, $servicename) = getnameinfo($addr, NI_NAMEREQD);
+my $qualname = $gnerr ? $name : $name;
 
 $qualname =~ tr/A-Z/a-z/;      # lowercase our name for keytab use.
 print "$qualname\n";
-
index 9ca66554fb231cc1f2301c7379e01342d93d91ae..423a00af2e3f31c2a36722a0482f4ceb1565c3bf 100755 (executable)
@@ -76,8 +76,9 @@ r1.addprinc(bob, password('bob'))
 r2.addprinc(zaphod, password('zaphod'))
 
 # Create host principals and keytabs for fallback realm tests.
-r1.addprinc('host/localhost')
-r2.addprinc('host/localhost')
+if hostname != 'localhost':
+    r1.addprinc('host/localhost')
+    r2.addprinc('host/localhost')
 r1.addprinc('host/' + foo)
 r2.addprinc('host/' + foo2)
 r1.addprinc('host/' + foobar)
index e6248f814b6aef4d9d44cd03fb7253a657df7f55..1f59540896bf730df768a7e49ea5379648bb4bcc 100644 (file)
@@ -8,7 +8,7 @@ SRCS=$(srcdir)/resolve.c $(srcdir)/addrinfo-test.c \
 all: resolve addrinfo-test fake-addrinfo-test
 
 resolve: resolve.o
-       $(CC_LINK) -o $@ resolve.o $(LIBS)
+       $(CC_LINK) -o $@ resolve.o $(SUPPORT_LIB) $(LIBS)
 
 addrinfo-test: addrinfo-test.o
        $(CC_LINK) -o $@ addrinfo-test.o $(SUPPORT_LIB) $(LIBS)
index 7339d21bd9ac6f6d37891f73e5394992573aaeae..ea0239113ab1c0d963fac0379efb1e45a4bcd3c7 100644 (file)
 
 /* This program tests the resolve library and sees if it is broken... */
 
-#include "autoconf.h"
-#include <stdio.h>
-
-#if STDC_HEADERS
-#include <string.h>
-#else
-#ifndef HAVE_STRCHR
-#define strchr index
-#endif
-char *strchr();
-#endif
-
+#include "k5-platform.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netdb.h>
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
 
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <netinet/in.h>
-#include <netdb.h>
-
 int
-main(argc, argv)
-    int argc;
-    char **argv;
+main(int argc, char **argv)
 {
-    char myname[MAXHOSTNAMELEN+1];
-    char *ptr, *fqdn;
-    struct in_addr addrcopy;
-    struct hostent *host;
-    int quiet = 0;
+    struct addrinfo *ai = NULL, hint;
+    char myname[MAXHOSTNAMELEN + 1], namebuf[NI_MAXHOST], abuf[256];
+    const char *addrstr;
+    int err, quiet = 0;
 
     argc--; argv++;
     while (argc) {
@@ -95,7 +70,7 @@ main(argc, argv)
     }
 
     if (argc >= 1) {
-        strncpy(myname, *argv, MAXHOSTNAMELEN);
+        strlcpy(myname, *argv, sizeof(myname));
     } else {
         if(gethostname(myname, MAXHOSTNAMELEN)) {
             perror("gethostname failure");
@@ -109,53 +84,32 @@ main(argc, argv)
     if (!quiet)
         printf("Hostname:  %s\n", myname);
 
-
-    /* Set the hosts db to close each time - effectively rewinding file */
-    sethostent(0);
-
-    if((host = gethostbyname (myname)) == NULL) {
+    memset(&hint, 0, sizeof(hint));
+    hint.ai_flags = AI_CANONNAME;
+    err = getaddrinfo(myname, 0, &hint, &ai);
+    if (err) {
         fprintf(stderr,
                 "Could not look up address for hostname '%s' - fatal\n",
                 myname);
         exit(2);
     }
 
-    fqdn = strdup(host->h_name);
-    if (fqdn == NULL) {
-        perror("strdup");
-        exit(2);
+    if (!quiet) {
+        addrstr = inet_ntop(ai->ai_family, ai->ai_addr, abuf, sizeof(abuf));
+        if (addrstr != NULL)
+            printf("Host address: %s\n", addrstr);
     }
 
-    ptr = host->h_addr_list[0];
-#define UC(a) (((int)a)&0xff)
-    if (!quiet)
-        printf("Host address: %d.%d.%d.%d\n",
-               UC(ptr[0]), UC(ptr[1]), UC(ptr[2]), UC(ptr[3]));
-
-    memcpy(&addrcopy.s_addr, ptr, 4);
-
-    /* Convert back to full name */
-    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);
-        }
-    }
+    err = getnameinfo(ai->ai_addr, ai->ai_addrlen, namebuf, sizeof(namebuf),
+                      NULL, 0, NI_NAMEREQD);
+    if (err && !quiet)
+        fprintf(stderr, "Error looking up IP address\n");
 
-    if (quiet)
-        printf("%s\n", fqdn);
-    else
-        printf("FQDN: %s\n", fqdn);
+    printf("%s%s\n", quiet ? "" : "FQDN: ", err ? ai->ai_canonname : namebuf);
 
     if (!quiet)
         printf("Resolve library appears to have passed the test\n");
 
-    /* All ok */
-    exit(0);
-
+    freeaddrinfo(ai);
+    return 0;
 }