961e5cc226
resolves: #1075932
172 lines
4.8 KiB
Diff
172 lines
4.8 KiB
Diff
commit 64c082a393013e3fc9a0cce0afa5e426f55b5ccd
|
|
Author: Andreas Schneider <asn@samba.org>
|
|
AuthorDate: Thu Mar 13 10:20:46 2014 +0100
|
|
Commit: Andreas Schneider <asn@samba.org>
|
|
CommitDate: Thu Mar 13 13:43:13 2014 +0100
|
|
|
|
src: Fix segfault in 'getent hosts' without aliases.
|
|
|
|
The glibc's 'getent' always dereferences he->h_aliases[i], so we need
|
|
to allocate it.
|
|
|
|
Signed-off-by: Andreas Schneider <asn@samba.org>
|
|
Reviewed-by: Stefan Metzmacher <metze@samba.org>
|
|
---
|
|
src/nss_wrapper.c | 7 ++++++-
|
|
1 file changed, 6 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
|
|
index 5685fc6..94df6ac 100644
|
|
--- a/src/nss_wrapper.c
|
|
+++ b/src/nss_wrapper.c
|
|
@@ -1950,7 +1950,12 @@ static bool nwrap_he_parse_line(struct nwrap_cache *nwrap, char *line)
|
|
|
|
ed->ht.h_name = n;
|
|
|
|
- ed->ht.h_aliases = NULL;
|
|
+ /* glib's getent always dereferences he->h_aliases */
|
|
+ ed->ht.h_aliases = malloc(sizeof(char *));
|
|
+ if (ed->ht.h_aliases == NULL) {
|
|
+ return false;
|
|
+ }
|
|
+ ed->ht.h_aliases[0] = NULL;
|
|
|
|
/*
|
|
* Aliases
|
|
commit b928fe9ff92a237ee4cffadfa517d76a4e07d80c
|
|
Author: Andreas Schneider <asn@samba.org>
|
|
AuthorDate: Thu Mar 13 10:35:47 2014 +0100
|
|
Commit: Andreas Schneider <asn@samba.org>
|
|
CommitDate: Thu Mar 13 13:43:32 2014 +0100
|
|
|
|
tests: Add test_gethostent.
|
|
|
|
Signed-off-by: Andreas Schneider <asn@samba.org>
|
|
Reviewed-by: Stefan Metzmacher <metze@samba.org>
|
|
---
|
|
tests/CMakeLists.txt | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
|
|
index 3b84829..5aab29e 100644
|
|
--- a/tests/CMakeLists.txt
|
|
+++ b/tests/CMakeLists.txt
|
|
@@ -23,7 +23,7 @@ list(APPEND TEST_ENVIRONMENT NSS_WRAPPER_HOSTS=${CMAKE_CURRENT_BINARY_DIR}/hosts
|
|
list(APPEND TEST_ENVIRONMENT NSS_WRAPPER_MODULE_SO_PATH=${CMAKE_CURRENT_BINARY_DIR}/libnss_nwrap.so)
|
|
list(APPEND TEST_ENVIRONMENT NSS_WRAPPER_MODULE_FN_PREFIX=nwrap)
|
|
|
|
-set(NWRAP_TESTS testsuite test_getaddrinfo test_getnameinfo test_gethostby_name_addr)
|
|
+set(NWRAP_TESTS testsuite test_getaddrinfo test_getnameinfo test_gethostby_name_addr test_gethostent)
|
|
|
|
foreach(_NWRAP_TEST ${NWRAP_TESTS})
|
|
add_cmocka_test(${_NWRAP_TEST} ${_NWRAP_TEST}.c ${TESTSUITE_LIBRARIES})
|
|
commit f24dbf643575c764eb74bbc08de2ececc35f1659
|
|
Author: Andreas Schneider <asn@samba.org>
|
|
AuthorDate: Thu Mar 13 13:46:22 2014 +0100
|
|
Commit: Andreas Schneider <asn@samba.org>
|
|
CommitDate: Fri Mar 14 11:01:04 2014 +0100
|
|
|
|
tests: Add test_gethostent.c
|
|
|
|
Signed-off-by: Andreas Schneider <asn@samba.org>
|
|
Reviewed-by: Stefan Metzmacher <metze@samba.org>
|
|
---
|
|
tests/test_gethostent.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
|
|
1 file changed, 61 insertions(+)
|
|
|
|
diff --git a/tests/test_gethostent.c b/tests/test_gethostent.c
|
|
new file mode 100644
|
|
index 0000000..e95195f
|
|
--- /dev/null
|
|
+++ b/tests/test_gethostent.c
|
|
@@ -0,0 +1,61 @@
|
|
+#include "config.h"
|
|
+
|
|
+#include <stdarg.h>
|
|
+#include <stddef.h>
|
|
+#include <setjmp.h>
|
|
+#include <cmocka.h>
|
|
+
|
|
+#include <stdio.h>
|
|
+#include <string.h>
|
|
+#include <unistd.h>
|
|
+
|
|
+#include <sys/socket.h>
|
|
+#include <netinet/in.h>
|
|
+#include <arpa/inet.h>
|
|
+#include <netdb.h>
|
|
+
|
|
+static void test_nwrap_gethostent(void **state)
|
|
+{
|
|
+ struct hostent *he;
|
|
+ uint32_t i;
|
|
+
|
|
+ (void)state; /* unused */
|
|
+
|
|
+ sethostent(0);
|
|
+
|
|
+ for (he = gethostent(); he != NULL; he = gethostent()) {
|
|
+ assert_non_null(he->h_addr_list);
|
|
+ assert_non_null(he->h_aliases);
|
|
+
|
|
+ for (i = 0; he->h_addr_list[i] != NULL; i++) {
|
|
+ char buf[INET6_ADDRSTRLEN];
|
|
+ uint32_t j;
|
|
+ const char *ip;
|
|
+
|
|
+ ip = inet_ntop(he->h_addrtype,
|
|
+ he->h_addr_list[i],
|
|
+ buf,
|
|
+ sizeof(buf));
|
|
+
|
|
+ printf("ip: %s\n", ip);
|
|
+
|
|
+ for (j = 0; he->h_aliases[j] != NULL; j++) {
|
|
+ printf("alias: %s\n", he->h_aliases[j]);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ endhostent();
|
|
+}
|
|
+
|
|
+int main(void) {
|
|
+ int rc;
|
|
+
|
|
+ const UnitTest tests[] = {
|
|
+ unit_test(test_nwrap_gethostent),
|
|
+ };
|
|
+
|
|
+ rc = run_tests(tests);
|
|
+
|
|
+ return rc;
|
|
+}
|
|
commit 93db9fd01cf556c49e4109c5901d4b4886bc1229
|
|
Author: Andreas Schneider <asn@samba.org>
|
|
AuthorDate: Thu Mar 13 14:58:23 2014 +0100
|
|
Commit: Andreas Schneider <asn@samba.org>
|
|
CommitDate: Fri Mar 14 11:01:10 2014 +0100
|
|
|
|
README: Fix prefix env variable name.
|
|
|
|
Signed-off-by: Andreas Schneider <asn@samba.org>
|
|
Reviewed-by: Stefan Metzmacher <metze@samba.org>
|
|
---
|
|
README | 6 +++++-
|
|
1 file changed, 5 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/README b/README
|
|
index 3edef91..2ffa564 100644
|
|
--- a/README
|
|
+++ b/README
|
|
@@ -47,4 +47,8 @@ NSS_WRAPPER_MODULE_SO_PATH=/path/to/libnss_yourmodule.so
|
|
As each nss module has a special prefix like _nss_winbind_getpwnam() you need
|
|
to set the prefix too so nss_wrapper can load the functions with:
|
|
|
|
-NSS_WRAPPER_MODULE_FN_NAME=<prefix>
|
|
+NSS_WRAPPER_MODULE_FN_PREFIX=<prefix>
|
|
+
|
|
+For _nss_winbind_getpwnam() this would be:
|
|
+
|
|
+NSS_WRAPPER_MODULE_FN_PREFIX=winbind
|