[SCM] NSS Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Tue Sep 9 06:06:24 MDT 2014


The branch, master has been updated
       via  0e50956 nwrap: Don't overflow the in_addr if convert IPv6.
       via  379967b tests: Add test for hostnames with a trailing dot.
       via  b65c6d8 nwrap: Fix resolving hostnames with a trailing dot.
      from  3125e76 tests: use return code of copy_group() in test_nwrap_getgrgid()

http://gitweb.samba.org/?p=nss_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 0e509561b76fc1a0fadbcfddf9602569cb681f22
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Sep 9 11:03:24 2014 +0200

    nwrap: Don't overflow the in_addr if convert IPv6.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 379967b19b9c7327e0d8ffdf0cc693011abacced
Author: Andreas Schneider <asn at samba.org>
Date:   Wed Sep 3 13:08:03 2014 +0200

    tests: Add test for hostnames with a trailing dot.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit b65c6d8ed5b4122b69ecae94eac40bc7e9649710
Author: Andreas Schneider <asn at samba.org>
Date:   Wed Sep 3 13:07:31 2014 +0200

    nwrap: Fix resolving hostnames with a trailing dot.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 src/nss_wrapper.c        |   63 ++++++++++++++++++++++-----------------------
 tests/test_getaddrinfo.c |   29 +++++++++++++++++++++
 2 files changed, 60 insertions(+), 32 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index e3943ee..931aaa5 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -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;
 
@@ -3845,13 +3854,18 @@ static int nwrap_getaddrinfo(const char *node,
 	struct addrinfo *p = NULL;
 	unsigned short port = 0;
 	struct hostent *he;
-	struct in_addr in;
-	bool is_addr_ipv4 = false;
-	bool is_addr_ipv6 = false;
+	struct {
+		int family;
+		union {
+			struct in_addr v4;
+#ifdef HAVE_IPV6
+			struct in6_addr v6;
+		} in;
+#endif
+	} addr;
 	int eai = EAI_SYSTEM;
 	int ret;
 	int rc;
-	int af;
 
 	if (node == NULL && service == NULL) {
 		return EAI_NONAME;
@@ -3903,32 +3917,25 @@ static int nwrap_getaddrinfo(const char *node,
 		}
 	}
 
-	af = hints->ai_family;
-	if (af == AF_UNSPEC) {
-		af = AF_INET;
+	rc = 0;
+	if (hints->ai_family == AF_UNSPEC || hints->ai_family == AF_INET) {
+		rc = inet_pton(AF_INET, node, &addr.in.v4);
 	}
-
-	rc = inet_pton(af, node, &in);
 	if (rc == 1) {
-		is_addr_ipv4 = true;
-		if (af == AF_UNSPEC) {
-			af = AF_INET;
-		}
+		addr.family = AF_INET;
 #ifdef HAVE_IPV6
 	} else {
-		struct in6_addr in6;
-
-		af = AF_INET6;
-
-		rc = inet_pton(af, node, &in6);
+		rc = inet_pton(AF_INET6, node, &addr.in.v6);
 		if (rc == 1) {
-			is_addr_ipv6 = true;
+			addr.family = AF_INET6;
 		}
 #endif
 	}
 
-	if (is_addr_ipv4) {
-		he = nwrap_files_gethostbyaddr(&in, sizeof(struct in_addr), af);
+	if (addr.family == AF_INET) {
+		he = nwrap_files_gethostbyaddr(&addr.in.v4,
+					       sizeof(struct in_addr),
+					       addr.family);
 		if (he != NULL) {
 			rc = nwrap_convert_he_ai(he, port, hints, &ai);
 		} else {
@@ -3936,18 +3943,10 @@ static int nwrap_getaddrinfo(const char *node,
 			rc = -1;
 		}
 #ifdef HAVE_IPV6
-	} else if (is_addr_ipv6) {
-		struct in6_addr in6;
-
-		rc =  inet_pton(af, node, &in6);
-		if (rc <= 0) {
-			eai = EAI_ADDRFAMILY;
-			return ret == 0 ? 0 : eai;
-		}
-
-		he = nwrap_files_gethostbyaddr(&in6,
+	} else if (addr.family == AF_INET6) {
+		he = nwrap_files_gethostbyaddr(&addr.in.v6,
 					       sizeof(struct in6_addr),
-					       af);
+					       addr.family);
 		if (he != NULL) {
 			rc = nwrap_convert_he_ai(he, port, hints, &ai);
 			eai = rc;
diff --git a/tests/test_getaddrinfo.c b/tests/test_getaddrinfo.c
index a7714b1..492913b 100644
--- a/tests/test_getaddrinfo.c
+++ b/tests/test_getaddrinfo.c
@@ -311,6 +311,34 @@ static void test_nwrap_getaddrinfo_null(void **state)
 	freeaddrinfo(res);
 }
 
+static void test_nwrap_getaddrinfo_dot(void **state)
+{
+	struct addrinfo hints = {
+		.ai_family = AF_INET,
+	};
+	struct addrinfo *res = NULL;
+	struct sockaddr_in *sinp;
+	char ip[INET_ADDRSTRLEN];
+	int rc;
+
+	(void) state; /* unused */
+
+	/* Check with a dot at the end */
+	rc = getaddrinfo("magrathea.galaxy.site.", NULL, &hints, &res);
+	assert_int_equal(rc, 0);
+
+	assert_non_null(res->ai_next);
+	assert_int_equal(res->ai_family, AF_INET);
+
+	sinp = (struct sockaddr_in *)res->ai_addr;
+	assert_int_equal(sinp->sin_family, AF_INET);
+	inet_ntop(AF_INET, (void *)&sinp->sin_addr, ip, sizeof(ip));
+
+	assert_string_equal(ip, "127.0.0.11");
+
+	freeaddrinfo(res);
+}
+
 static void test_nwrap_getaddrinfo_ipv6(void **state)
 {
 	struct addrinfo hints;
@@ -353,6 +381,7 @@ int main(void) {
 		unit_test(test_nwrap_getaddrinfo_name),
 		unit_test(test_nwrap_getaddrinfo_service),
 		unit_test(test_nwrap_getaddrinfo_null),
+		unit_test(test_nwrap_getaddrinfo_dot),
 		unit_test(test_nwrap_getaddrinfo_ipv6),
 	};
 


-- 
NSS Wrapper Repository


More information about the samba-cvs mailing list