[SCM] NSS Wrapper Repository - branch master updated
Andreas Schneider
asn at samba.org
Mon Mar 17 08:46:06 MDT 2014
The branch, master has been updated
via 19426f4 tests: Add test for gethostbyname2().
via 5034191 src: Add gethostbyname2() for getent.
via 89b1969 src: Add address family filter to nwrap_files_gethostbyname().
from 93db9fd README: Fix prefix env variable name.
http://gitweb.samba.org/?p=nss_wrapper.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 19426f4ed8e362bd5656fd0a5ec4c627f56a071e
Author: Andreas Schneider <asn at samba.org>
Date: Mon Mar 17 13:18:16 2014 +0100
tests: Add test for gethostbyname2().
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit 50341913140b4594f0b3a0a4774442c83e7a77b9
Author: Andreas Schneider <asn at samba.org>
Date: Mon Mar 17 10:34:42 2014 +0100
src: Add gethostbyname2() for getent.
This fixes 'getent hosts <fqdn>' with glibc.
Signed-Off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit 89b19692e44839545001244a20a2454dc971ecda
Author: Andreas Schneider <asn at samba.org>
Date: Mon Mar 17 13:19:03 2014 +0100
src: Add address family filter to nwrap_files_gethostbyname().
Signed-Off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
-----------------------------------------------------------------------
Summary of changes:
ConfigureChecks.cmake | 2 +
config.h.cmake | 3 ++
src/nss_wrapper.c | 42 ++++++++++++++++++++++++++++++++---
tests/hosts.in | 2 +
tests/test_gethostby_name_addr.c | 45 ++++++++++++++++++++++++++++++++++++++
5 files changed, 90 insertions(+), 4 deletions(-)
Changeset truncated at 500 lines:
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index afee1f8..b74ed8d 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -71,6 +71,8 @@ check_function_exists(getgrouplist HAVE_GETGROUPLIST)
check_function_exists(gethostbyaddr_r HAVE_GETHOSTBYADDR_R)
check_function_exists(gethostbyname_r HAVE_GETHOSTBYNAME_R)
+check_function_exists(gethostbyname2 HAVE_GETHOSTBYNAME2)
+
if (WIN32)
check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
check_function_exists(_vsnprintf HAVE__VSNPRINTF)
diff --git a/config.h.cmake b/config.h.cmake
index 06e5738..b94b621 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -49,6 +49,9 @@
/* Define to 1 if you have the `gethostbyname_r' function. */
#cmakedefine HAVE_GETHOSTBYNAME_R 1
+/* Define to 1 if you have the `gethostbyname2' function. */
+#cmakedefine HAVE_GETHOSTBYNAME2 1
+
#cmakedefine HAVE___POSIX_GETPWNAM_R 1
#cmakedefine HAVE___POSIX_GETPWUID_R 1
diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index 94df6ac..2706196 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -230,6 +230,9 @@ struct nwrap_libc_fns {
void (*_libc_endhostent)(void);
struct hostent *(*_libc_gethostbyname)(const char *name);
+#ifdef HAVE_GETHOSTBYNAME2 /* GNU extension */
+ struct hostent *(*_libc_gethostbyname2)(const char *name, int af);
+#endif
struct hostent *(*_libc_gethostbyaddr)(const void *addr, socklen_t len, int type);
int (*_libc_getaddrinfo)(const char *node, const char *service,
@@ -927,6 +930,15 @@ static struct hostent *libc_gethostbyname(const char *name)
return nwrap_main_global->libc->fns->_libc_gethostbyname(name);
}
+#ifdef HAVE_GETHOSTBYNAME2 /* GNU extension */
+static struct hostent *libc_gethostbyname2(const char *name, int af)
+{
+ nwrap_load_lib_function(NWRAP_LIBNSL, gethostbyname2);
+
+ return nwrap_main_global->libc->fns->_libc_gethostbyname2(name, af);
+}
+#endif
+
static struct hostent *libc_gethostbyaddr(const void *addr,
socklen_t len,
int type)
@@ -2328,7 +2340,7 @@ static void nwrap_files_endgrent(struct nwrap_backend *b)
}
/* hosts functions */
-static struct hostent *nwrap_files_gethostbyname(const char *name)
+static struct hostent *nwrap_files_gethostbyname(const char *name, int af)
{
struct hostent *he;
int i;
@@ -2340,6 +2352,11 @@ static struct hostent *nwrap_files_gethostbyname(const char *name)
he = &nwrap_he_global.list[i].ht;
+ /* Filter by address familiy if provided */
+ if (af != AF_UNSPEC && he->h_addrtype != af) {
+ continue;
+ }
+
if (strcasecmp(he->h_name, name) == 0) {
NWRAP_LOG(NWRAP_LOG_DEBUG, "name[%s] found", name);
return he;
@@ -2369,7 +2386,7 @@ static int nwrap_gethostbyname_r(const char *name,
char *buf, size_t buflen,
struct hostent **result, int *h_errnop)
{
- *result = nwrap_files_gethostbyname(name);
+ *result = nwrap_files_gethostbyname(name, AF_UNSPEC);
if (*result != NULL) {
memset(buf, '\0', buflen);
*ret = **result;
@@ -3668,7 +3685,7 @@ void endhostent(void)
static struct hostent *nwrap_gethostbyname(const char *name)
{
- return nwrap_files_gethostbyname(name);
+ return nwrap_files_gethostbyname(name, AF_UNSPEC);
}
struct hostent *gethostbyname(const char *name)
@@ -3680,6 +3697,23 @@ struct hostent *gethostbyname(const char *name)
return nwrap_gethostbyname(name);
}
+/* This is a GNU extension */
+#ifdef HAVE_GETHOSTBYNAME2
+static struct hostent *nwrap_gethostbyname2(const char *name, int af)
+{
+ return nwrap_files_gethostbyname(name, af);
+}
+
+struct hostent *gethostbyname2(const char *name, int af)
+{
+ if (!nwrap_hosts_enabled()) {
+ return libc_gethostbyname2(name, af);
+ }
+
+ return nwrap_gethostbyname2(name, af);
+}
+#endif
+
static struct hostent *nwrap_gethostbyaddr(const void *addr,
socklen_t len, int type)
{
@@ -3914,7 +3948,7 @@ static int nwrap_getaddrinfo(const char *node,
}
#endif
} else {
- he = nwrap_files_gethostbyname(node);
+ he = nwrap_files_gethostbyname(node, AF_UNSPEC);
if (he != NULL) {
rc = nwrap_convert_he_ai(he, port, hints, &ai);
eai = rc;
diff --git a/tests/hosts.in b/tests/hosts.in
index 5d5aef4..36f192b 100644
--- a/tests/hosts.in
+++ b/tests/hosts.in
@@ -1,3 +1,5 @@
127.0.0.11 magrathea.galaxy.site magrathea
127.0.0.12 maximegalon.galaxy.site
::13 beteigeuze.galaxy.site beteigeuze mail
+127.0.0.14 krikkit.galaxy.site
+::14 krikkit.galaxy.site
diff --git a/tests/test_gethostby_name_addr.c b/tests/test_gethostby_name_addr.c
index 8837075..bfc8437 100644
--- a/tests/test_gethostby_name_addr.c
+++ b/tests/test_gethostby_name_addr.c
@@ -69,6 +69,48 @@ static void test_nwrap_gethostbyname(void **state)
assert_string_equal(ip, "127.0.0.11");
}
+#ifdef HAVE_GETHOSTBYNAME2
+static void test_nwrap_gethostbyname2(void **state)
+{
+ char ip[INET6_ADDRSTRLEN];
+ struct hostent *he;
+ const char *a;
+
+ (void) state; /* unused */
+
+ he = gethostbyname2("magrathea.galaxy.site", AF_INET6);
+ assert_null(he);
+
+ he = gethostbyname2("magrathea.galaxy.site", AF_INET);
+ assert_non_null(he);
+
+
+ /* Check ipv6 he */
+ he = gethostbyname2("krikkit.galaxy.site", AF_INET6);
+ assert_non_null(he);
+
+ assert_string_equal(he->h_name, "krikkit.galaxy.site");
+ assert_int_equal(he->h_addrtype, AF_INET6);
+
+ a = inet_ntop(AF_INET6, he->h_addr_list[0], ip, sizeof(ip));
+ assert_non_null(a);
+
+ assert_string_equal(ip, "::14");
+
+ /* Check ipv4 he */
+ he = gethostbyname2("krikkit.galaxy.site", AF_INET);
+ assert_non_null(he);
+
+ assert_string_equal(he->h_name, "krikkit.galaxy.site");
+ assert_int_equal(he->h_addrtype, AF_INET);
+
+ a = inet_ntop(AF_INET, he->h_addr_list[0], ip, sizeof(ip));
+ assert_non_null(a);
+
+ assert_string_equal(ip, "127.0.0.14");
+}
+#endif /* HAVE_GETHOSTBYNAME2 */
+
static void test_nwrap_gethostbyaddr(void **state)
{
struct hostent *he;
@@ -153,6 +195,9 @@ int main(void) {
const UnitTest tests[] = {
unit_test(test_nwrap_gethostname),
unit_test(test_nwrap_gethostbyname),
+#ifdef HAVE_GETHOSTBYNAME2
+ unit_test(test_nwrap_gethostbyname2),
+#endif
unit_test(test_nwrap_gethostbyaddr),
#ifdef HAVE_GETHOSTBYNAME_R
unit_test(test_nwrap_gethostbyname_r),
--
NSS Wrapper Repository
More information about the samba-cvs
mailing list