nwrap: Fix resolving hostnames with a trailing dot.
authorAndreas Schneider <asn@samba.org>
Thu, 9 Oct 2014 07:14:57 +0000 (09:14 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 9 Oct 2014 10:24:03 +0000 (12:24 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/nss_wrapper/nss_wrapper.c

index e3943ee61b57c6594e4ce944bd5833cf9da2c142..57003bd612f56a95157b0b2c4f5456c0005472a4 100644 (file)
@@ -49,6 +49,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <limits.h>
 
 /*
  * Defining _POSIX_PTHREAD_SEMANTICS before including pwd.h and grp.h  gives us
@@ -2351,10 +2352,18 @@ static void nwrap_files_endgrent(struct nwrap_backend *b)
 static struct hostent *nwrap_files_gethostbyname(const char *name, int af)
 {
        struct hostent *he;
+       char canon_name[HOST_NAME_MAX] = { 0 };
+       size_t name_len;
        int i;
 
        nwrap_files_cache_reload(nwrap_he_global.cache);
 
+       name_len = strlen(name);
+       if (name_len < sizeof(canon_name) && name[name_len - 1] == '.') {
+               strncpy(canon_name, name, name_len - 1);
+               name = canon_name;
+       }
+
        for (i = 0; i < nwrap_he_global.num; i++) {
                int j;