nss_wrapper.git
5 years agonwrap: fix nwrap_module_getpwuid_r
Ralph Wuerthner [Fri, 19 Oct 2018 10:15:53 +0000 (12:15 +0200)]
nwrap: fix nwrap_module_getpwuid_r

On success *pwdstp must point to pwdst, on error return NULL instead.

Signed-off-by: Ralph Wuerthner <ralph.wuerthner@de.ibm.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
5 years agonwrap: fix nwrap_module_getpwnam_r
Ralph Wuerthner [Fri, 19 Oct 2018 09:27:04 +0000 (11:27 +0200)]
nwrap: fix nwrap_module_getpwnam_r

On success *pwdstp must point to pwdst, on error return NULL instead.

Signed-off-by: Ralph Wuerthner <ralph.wuerthner@de.ibm.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
5 years agoctest: Move to new dashboard
Andreas Schneider [Thu, 5 Jul 2018 08:15:11 +0000 (10:15 +0200)]
ctest: Move to new dashboard

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agonwrap: Update header
Andreas Schneider [Fri, 22 Jun 2018 06:46:06 +0000 (08:46 +0200)]
nwrap: Update header

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoUpdate LICENSE file
Andreas Schneider [Fri, 22 Jun 2018 06:34:27 +0000 (08:34 +0200)]
Update LICENSE file

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoRename COPYING to LICENSE
Andreas Schneider [Fri, 22 Jun 2018 06:32:43 +0000 (08:32 +0200)]
Rename COPYING to LICENSE

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agonwrap: Print errno when hsearch() returns NULL
Andreas Schneider [Mon, 22 Jan 2018 16:30:33 +0000 (17:30 +0100)]
nwrap: Print errno when hsearch() returns NULL

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agotests: Add musl-libc 1.1 compatibility (gethostent())
Dennis Schridde [Wed, 25 Jan 2017 21:25:24 +0000 (22:25 +0100)]
tests: Add musl-libc 1.1 compatibility (gethostent())

musl-libc stubs gethostent() and replies with NULL in any case. Thus we have to
 check the sensibility of the function before performing tests.

Tested with musl-libc 1.1.16-r13 on Alpine Linux 3.6. Also confirmed to not
 break with GNU libc 2.23-0ubuntu9 on Ubuntu 16.04.3 LTS.

Signed-Off-By: Dennis Schridde <dennis.schridde@uni-heidelberg.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agotests: Add musl-libc 1.1 compatibility (getaddrinfo(), EAI_SERVICE)
Dennis Schridde [Thu, 3 Aug 2017 09:34:07 +0000 (11:34 +0200)]
tests: Add musl-libc 1.1 compatibility (getaddrinfo(), EAI_SERVICE)

The tests of getaddrinfo() had to be adapted, because musl-libc, unlike glibc
 and others, returns EAI_SERVICE if the requested service is not available for
 the requested socket type.

Tested with musl-libc 1.1.16-r13 on Alpine Linux 3.6. Also confirmed to not
 break with GNU libc 2.23-0ubuntu9 on Ubuntu 16.04.3 LTS.

Signed-Off-By: Dennis Schridde <dennis.schridde@uni-heidelberg.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agotests: Add musl-libc 1.1 compatibility (getaddrinfo(), IP-addresses)
Dennis Schridde [Wed, 25 Jan 2017 21:25:24 +0000 (22:25 +0100)]
tests: Add musl-libc 1.1 compatibility (getaddrinfo(), IP-addresses)

The tests of getaddrinfo() had to be adapted, because musl-libc, unlike glibc
 and others, replies with the same canonical name that was used in the original
 request, if the requested "node" was an IP-address

Tested with musl-libc 1.1.16-r13 on Alpine Linux 3.6. Also confirmed to not
 break with GNU libc 2.23-0ubuntu9 on Ubuntu 16.04.3 LTS.

Signed-Off-By: Dennis Schridde <dennis.schridde@uni-heidelberg.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agocpack: Do not package build dirs in source tarball
Andreas Schneider [Fri, 22 Jun 2018 07:00:30 +0000 (09:00 +0200)]
cpack: Do not package build dirs in source tarball

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agocmake: Replace deprecated get_target_property()
Andreas Schneider [Fri, 22 Jun 2018 06:55:40 +0000 (08:55 +0200)]
cmake: Replace deprecated get_target_property()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agonwrap: Fix strotoul checks for NSS_WRAPPER_MAX_HOSTENTS
Douglas Bagnall [Tue, 15 Aug 2017 22:35:28 +0000 (10:35 +1200)]
nwrap: Fix strotoul checks for NSS_WRAPPER_MAX_HOSTENTS

The env and endptr pointers need to be dereferenced, but that is not
enough: we don't really want to regard an empty string (*env == '\0')
as a valid number.

Found by GCC 8.0.0 20170705 (experimental).

[2095/4103] Compiling lib/nss_wrapper/nss_wrapper.c
../lib/nss_wrapper/nss_wrapper.c: In function ‘nwrap_init’:
../lib/nss_wrapper/nss_wrapper.c:1571:13: warning: comparison between pointer and zero character constant [-Wpointer-compare]
   if (((env != '\0') && (endptr == '\0')) ||
                ^~
                ../lib/nss_wrapper/nss_wrapper.c:1571:9: note: did you mean to dereference the pointer?
   if (((env != '\0') && (endptr == '\0')) ||
            ^
            ../lib/nss_wrapper/nss_wrapper.c:1571:33: warning: comparison between pointer and zero character constant [-Wpointer-compare]
   if (((env != '\0') && (endptr == '\0')) ||
                                    ^~
                                    ../lib/nss_wrapper/nss_wrapper.c:1571:26: note: did you mean to dereference the pointer?
   if (((env != '\0') && (endptr == '\0')) ||

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
7 years agotestsuite: Add compatibility for musl-libc 1.1
Dennis Schridde [Wed, 25 Jan 2017 21:25:24 +0000 (22:25 +0100)]
testsuite: Add compatibility for musl-libc 1.1

The major difference is that getpwent_r and getgrent_r do not exist in
musl-libc. The testsuite was adapted to skip these tests if the
functions themselves are missing.

Signed-Off-By: Dennis Schridde <dennis.schridde@uni-heidelberg.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agonwrap: Add compatibility for musl-libc 1.1
Dennis Schridde [Mon, 27 Mar 2017 14:26:11 +0000 (16:26 +0200)]
nwrap: Add compatibility for musl-libc 1.1

The major difference is that getpwent_r and getgrent_r do not exist in
musl-libc. Hence it is sufficient to compile the wrappers for those only
conditionally.

Tested with musl-libc 1.1.15-r5 on Alpine Linux 3.5. Also confirmed to
not break with GNU libc 2.24-8 on Debian "Stretch" / 9.

Signed-Off-By: Dennis Schridde <dennis.schridde@uni-heidelberg.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agonwrap: Add a comment to the pthread_atfork() call
Andreas Schneider [Wed, 31 May 2017 13:25:30 +0000 (15:25 +0200)]
nwrap: Add a comment to the pthread_atfork() call

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agonwrap: Use a constructor to initialize pthread and nwrap
Andreas Schneider [Mon, 27 Mar 2017 14:23:08 +0000 (16:23 +0200)]
nwrap: Use a constructor to initialize pthread and nwrap

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agocmake: Check for contructor attribute support
Andreas Schneider [Mon, 27 Mar 2017 14:22:45 +0000 (16:22 +0200)]
cmake: Check for contructor attribute support

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agonwrap: Add NULL checks for destructor
Andreas Schneider [Mon, 27 Mar 2017 14:38:53 +0000 (16:38 +0200)]
nwrap: Add NULL checks for destructor

If we call init early and leave early they are not filled.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agonss_wrapper: Use perl via "env"
Volker Lendecke [Mon, 1 May 2017 17:52:07 +0000 (19:52 +0200)]
nss_wrapper: Use perl via "env"

FreeBSD has perl under /usr/local/bin

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agoBump version to 1.1.3 nss_wrapper-1.1.3
Andreas Schneider [Fri, 18 Mar 2016 10:58:13 +0000 (11:58 +0100)]
Bump version to 1.1.3

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agonwrap: Use snprintf() instead of strcpy()
Andreas Schneider [Wed, 16 Mar 2016 17:13:00 +0000 (18:13 +0100)]
nwrap: Use snprintf() instead of strcpy()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
8 years agotests: Add testing for BSD 'struct passwd' members
Andreas Schneider [Thu, 21 Jan 2016 12:51:08 +0000 (13:51 +0100)]
tests: Add testing for BSD 'struct passwd' members

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
8 years agonwrap: Support FreeBSD 'struct passwd' members
Andreas Schneider [Thu, 21 Jan 2016 12:47:27 +0000 (13:47 +0100)]
nwrap: Support FreeBSD 'struct passwd' members

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
8 years agoBump version to 1.1.2 nss_wrapper-1.1.2
Andreas Schneider [Thu, 17 Dec 2015 08:00:30 +0000 (09:00 +0100)]
Bump version to 1.1.2

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Add reload test for the hosts file
Andreas Schneider [Thu, 17 Dec 2015 07:56:05 +0000 (08:56 +0100)]
tests: Add reload test for the hosts file

With this valgrind should show issues if the hash table is not
recreated.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Fix segfaults while reloading hosts file
Andreas Schneider [Thu, 17 Dec 2015 07:46:33 +0000 (08:46 +0100)]
nwrap: Fix segfaults while reloading hosts file

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Add the same alias again
Andreas Schneider [Tue, 24 Nov 2015 16:33:49 +0000 (17:33 +0100)]
tests: Add the same alias again

We should be fault tolerant here.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Don't fail if we want to add an existing entry
Andreas Schneider [Tue, 24 Nov 2015 16:32:47 +0000 (17:32 +0100)]
nwrap: Don't fail if we want to add an existing entry

Pair-Programmed-With: Michael Adam <obnox@samba.org>
Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Michael Adam <obnox@samba.org>
8 years agoBump version to 1.1.1 nss_wrapper-1.1.1
Andreas Schneider [Mon, 23 Nov 2015 07:34:13 +0000 (08:34 +0100)]
Bump version to 1.1.1

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Fix the build on Solaris
Andreas Schneider [Mon, 23 Nov 2015 07:33:02 +0000 (08:33 +0100)]
nwrap: Fix the build on Solaris

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoBump version to 1.1.0 nss_wrapper-1.1.0
Andreas Schneider [Fri, 20 Nov 2015 09:13:09 +0000 (10:13 +0100)]
Bump version to 1.1.0

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: add __sha512_crypt to suppression file.
Michael Adam [Fri, 20 Nov 2015 09:51:11 +0000 (10:51 +0100)]
tests: add __sha512_crypt to suppression file.

While the manpage crypt(3) states that the function
returns a pointer to static memory, this does not
seem to be true for the __sha512 variant.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: Set the valgrind suppression file
Andreas Schneider [Fri, 20 Nov 2015 08:59:58 +0000 (09:59 +0100)]
tests: Set the valgrind suppression file

You can run 'make ExperimentalMemcheck' with valgrind suppression now.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Add valgrind suppression for glibc error
Andreas Schneider [Fri, 20 Nov 2015 08:22:36 +0000 (09:22 +0100)]
tests: Add valgrind suppression for glibc error

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Don't leak memory from gethostbyname*() functions
Andreas Schneider [Fri, 20 Nov 2015 08:38:16 +0000 (09:38 +0100)]
nwrap: Don't leak memory from gethostbyname*() functions

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Fix the build on FreeBSD
Andreas Schneider [Fri, 20 Nov 2015 07:51:49 +0000 (08:51 +0100)]
nwrap: Fix the build on FreeBSD

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: fix a copy and paste error in the destructor.
Michael Adam [Fri, 20 Nov 2015 08:01:01 +0000 (09:01 +0100)]
nwrap: fix a copy and paste error in the destructor.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: Cleanup shadow getspnam() memory
Andreas Schneider [Thu, 19 Nov 2015 08:02:46 +0000 (09:02 +0100)]
nwrap: Cleanup shadow  getspnam() memory

Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Michael Adam <obnox@samba.org>
8 years agonwrap: fix leaking the entlists
Michael Adam [Thu, 19 Nov 2015 00:00:16 +0000 (01:00 +0100)]
nwrap: fix leaking the entlists

Track the list heads in a vector in the newrap_he_global
struct and free the structures upon nwrap_he_unload.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: catch error to add item to vector in nwrap_he_parse_line()
Michael Adam [Wed, 18 Nov 2015 23:34:54 +0000 (00:34 +0100)]
nwrap: catch error to add item to vector in nwrap_he_parse_line()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: rename nwrap_he.entdata to nwrap_he.entries
Michael Adam [Wed, 18 Nov 2015 23:30:17 +0000 (00:30 +0100)]
nwrap: rename nwrap_he.entdata to nwrap_he.entries

That's what is is the list of entries. In the guise
nwrap_entdata structures but the code reads more
naturally this way.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: remove unused member list from struct nwrap_he
Michael Adam [Wed, 18 Nov 2015 23:24:14 +0000 (00:24 +0100)]
nwrap: remove unused member list from struct nwrap_he

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: Small code shift in nwrap_ed_inventarize_add_to_existing()
Robin Hack [Mon, 16 Nov 2015 22:38:51 +0000 (23:38 +0100)]
nwrap: Small code shift in nwrap_ed_inventarize_add_to_existing()

Allocate memory only when necessary.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: Fix memory leaks in getaddrinfo test
Andreas Schneider [Mon, 16 Nov 2015 19:43:00 +0000 (20:43 +0100)]
tests: Fix memory leaks in getaddrinfo test

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Cast max_hostents to avoid warnings
Andreas Schneider [Mon, 16 Nov 2015 09:19:27 +0000 (10:19 +0100)]
nwrap: Cast max_hostents to avoid warnings

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Fix initialization of e entry
Andreas Schneider [Mon, 16 Nov 2015 09:17:39 +0000 (10:17 +0100)]
nwrap: Fix initialization of e entry

This fixes a compiler warning.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Silence compiler warnings about uninitialized variables
Andreas Schneider [Mon, 16 Nov 2015 09:15:06 +0000 (10:15 +0100)]
tests: Silence compiler warnings about uninitialized variables

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Fix getaddrinfo test on BSD
Andreas Schneider [Mon, 16 Nov 2015 09:12:03 +0000 (10:12 +0100)]
tests: Fix getaddrinfo test on BSD

EAI_ADDRFAMILY is a GNU extension. EAI_FAMILY is the return value on
BSD.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoadd me to AUTHORS
Michael Adam [Thu, 12 Nov 2015 10:55:49 +0000 (11:55 +0100)]
add me to AUTHORS

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: Add test to exercise internal data structures
Robin Hack [Mon, 2 Nov 2015 12:48:47 +0000 (13:48 +0100)]
tests: Add test to exercise internal data structures

This uses a big hosts file from samba to avoid regressions in Samba.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotest: add test for AI_NUMERICHOST flag.
Michael Adam [Thu, 12 Nov 2015 10:40:25 +0000 (11:40 +0100)]
test: add test for AI_NUMERICHOST flag.

Based on first cut at a test by Robin Hack.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: remove ai_tail argument from nwrap_files_getaddrinfo()
Michael Adam [Thu, 12 Nov 2015 09:20:37 +0000 (10:20 +0100)]
nwrap: remove ai_tail argument from nwrap_files_getaddrinfo()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: rewrite the loop for duplication ai entries if socktype not given
Michael Adam [Thu, 12 Nov 2015 10:35:07 +0000 (11:35 +0100)]
nwrap: rewrite the loop for duplication ai entries if socktype not given

This loop reads much more naturally now. It inserts the
duplicated entry right after the entrie that is being
duplicated. It does not need a ai_tail any more.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: add an explaining comment for the ai duplicating loop
Michael Adam [Thu, 12 Nov 2015 10:17:21 +0000 (11:17 +0100)]
nwrap: add an explaining comment for the ai duplicating loop

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: move setting of ai_{flags|socktype|protocol} into nwrap_convert_he_ai
Michael Adam [Thu, 12 Nov 2015 10:15:03 +0000 (11:15 +0100)]
nwrap: move setting of ai_{flags|socktype|protocol} into nwrap_convert_he_ai

This makes the code in nwrap_getaddrinfo() more readable
and also treats all ai stuctures in the linked list, not
just the first one!

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: use symbols IPPROTO_TCP and IPPROTO_UDP
Michael Adam [Thu, 12 Nov 2015 10:08:47 +0000 (11:08 +0100)]
nwrap: use symbols IPPROTO_TCP and IPPROTO_UDP

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: rename _ai -> ai_new in nwrap_files_getaddrinfo()
Michael Adam [Thu, 12 Nov 2015 08:47:59 +0000 (09:47 +0100)]
nwrap: rename _ai -> ai_new in nwrap_files_getaddrinfo()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: fix a memleak in nwrap_files_getaddrinfo()
Michael Adam [Thu, 12 Nov 2015 08:46:29 +0000 (09:46 +0100)]
nwrap: fix a memleak in nwrap_files_getaddrinfo()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: rename ai_prev -> ai_cur in nwrap_files_getaddrinfo()
Michael Adam [Thu, 12 Nov 2015 08:45:50 +0000 (09:45 +0100)]
nwrap: rename ai_prev -> ai_cur in nwrap_files_getaddrinfo()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: Fix inventarization of IPs when loading hosts
Michael Adam [Thu, 12 Nov 2015 07:34:39 +0000 (08:34 +0100)]
nwrap: Fix inventarization of IPs when loading hosts

Use nwrap_ed_inventarize() instead of nwrap_add_ai().

This not only removes code duplication, but also
more correctly adds more than one line for a given
IP address in a list behind this address.

The original code would only have inventarized
the first line for an IP found.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: refactor nwrap_add_hname_* into one nwrap_ed_inventarize.
Michael Adam [Thu, 12 Nov 2015 07:29:57 +0000 (08:29 +0100)]
nwrap: refactor nwrap_add_hname_* into one nwrap_ed_inventarize.

This reduces code duplication and abstracts the logic out.
It was not special to hname or hname_alias.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: treat AI_NUMERICHOST correctly in getaddrinfo.
Michael Adam [Sun, 8 Nov 2015 23:29:23 +0000 (00:29 +0100)]
nwrap: treat AI_NUMERICHOST correctly in getaddrinfo.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11477

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: fix treatment of EAI_ADDRINFO in nwrap_files_getaddrinfo
Michael Adam [Thu, 12 Nov 2015 07:16:18 +0000 (08:16 +0100)]
nwrap: fix treatment of EAI_ADDRINFO in nwrap_files_getaddrinfo

Checking whether the passed in name (node) is a valid IPv6 or IPv4
address, we can do the checking for these two error conditions
properly up front.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: correctly track EAI_ADDRINFO in nwrap_files_getaddrinfo
Michael Adam [Thu, 12 Nov 2015 07:01:57 +0000 (08:01 +0100)]
nwrap: correctly track EAI_ADDRINFO in nwrap_files_getaddrinfo

When looping through the entry list and remember the
EAI_ADDRINFO case, so that we can differentiate
the cases
- no entry found at all
- an entry found buy wrong address type

Adapt return codes accordingly.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: in nwrap_files_getaddrinfo, treat failure of nwrap_convert_he_ai as error
Michael Adam [Wed, 11 Nov 2015 12:04:15 +0000 (13:04 +0100)]
nwrap: in nwrap_files_getaddrinfo, treat failure of nwrap_convert_he_ai as error

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: convert nwrap_files_getaddrinfo() to return EAI error codes
Michael Adam [Wed, 11 Nov 2015 12:02:59 +0000 (13:02 +0100)]
nwrap: convert nwrap_files_getaddrinfo() to return EAI error codes

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: use the error code from nwrap_files_cache_reload() in callers
Michael Adam [Wed, 11 Nov 2015 11:47:15 +0000 (12:47 +0100)]
nwrap: use the error code from nwrap_files_cache_reload() in callers

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: turn nwrap_files_cache_reload() into a bool function
Michael Adam [Wed, 11 Nov 2015 11:33:12 +0000 (12:33 +0100)]
nwrap: turn nwrap_files_cache_reload() into a bool function

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: better error propagation in nwrap_he_parse_line()
Michael Adam [Wed, 11 Nov 2015 11:30:36 +0000 (12:30 +0100)]
nwrap: better error propagation in nwrap_he_parse_line()

Use the return codes of nwrap_add_hname() and nwrap_add_ai().

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: log NULL alias name at ERROR level in nwrap_add_hname()
Michael Adam [Wed, 11 Nov 2015 11:29:55 +0000 (12:29 +0100)]
nwrap: log NULL alias name at ERROR level in nwrap_add_hname()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: better error propagation in nwrap_add_hname()
Michael Adam [Wed, 11 Nov 2015 11:28:58 +0000 (12:28 +0100)]
nwrap: better error propagation in nwrap_add_hname()

Use return codes from called functions.
Remove now unneeded asserts.
Make failure to add an entry for an alias an error.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: better error propagation in nwrap_add_hname_alias
Michael Adam [Wed, 11 Nov 2015 11:27:33 +0000 (12:27 +0100)]
nwrap: better error propagation in nwrap_add_hname_alias

use return codes from the called function.
Remove asserts becaus the cases are caught
by the called functions.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: catch NULL list in nwrap_add_hname_add_to_existing
Michael Adam [Wed, 11 Nov 2015 11:26:02 +0000 (12:26 +0100)]
nwrap: catch NULL list in nwrap_add_hname_add_to_existing

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: catch null h_name in nwrap_add_hname_add_new
Michael Adam [Wed, 11 Nov 2015 11:25:30 +0000 (12:25 +0100)]
nwrap: catch null h_name in nwrap_add_hname_add_new

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: catch NULL ip in nwrap_add_ai
Michael Adam [Wed, 11 Nov 2015 11:24:53 +0000 (12:24 +0100)]
nwrap: catch NULL ip in nwrap_add_ai

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: turn nwrap_add_hname_add_to_existing() into bool
Michael Adam [Wed, 11 Nov 2015 10:56:59 +0000 (11:56 +0100)]
nwrap: turn nwrap_add_hname_add_to_existing() into bool

for better error propagation.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: fix test_nwrap_gethostbyname2 - magrathea now has an IPv6 address
Michael Adam [Mon, 9 Nov 2015 12:40:08 +0000 (13:40 +0100)]
tests: fix test_nwrap_gethostbyname2 - magrathea now has an IPv6 address

This should have been caught before, but the failure of this test
seems to have been uncovered by a seemingly unrelated change to
the code. (Always set ed->ed_tail = ed when initializing a new ed).

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: simplify nwrap_file_getaddrinfo: remove a variable
Michael Adam [Wed, 11 Nov 2015 09:38:31 +0000 (10:38 +0100)]
nwrap: simplify nwrap_file_getaddrinfo: remove a variable

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: simplify nwrap_files_gethostbyname: remove a variable
Michael Adam [Wed, 11 Nov 2015 09:36:07 +0000 (10:36 +0100)]
nwrap: simplify nwrap_files_gethostbyname: remove a variable

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: log hash table full message at error level
Michael Adam [Wed, 11 Nov 2015 10:30:13 +0000 (11:30 +0100)]
nwrap: log hash table full message at error level

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: rewrite linked-list datastructures to be properly separated.
Michael Adam [Wed, 11 Nov 2015 09:27:50 +0000 (10:27 +0100)]
nwrap: rewrite linked-list datastructures to be properly separated.

The data structures were wrong:

- The nwrap_entdata structures reflects one line of the hosts
  file, with ip, fqdn and aliases.
  But they also had a linked list structure.

- Now the hash table was used to point each
  ip address, fqdn and alias name occurring in the hosts
  file to the list of lines (entdata structs) that contain
  this name/address.

The problem was that these list heads were pointing to the same
entdata structures, while the list should actually be individual
for each entity (ip, fqdn, alias). This lead to wrong assiciations
of lines to IP addresse and also endless loops in the list, when
one line was put into one list twice starting from two different
points.

This patch fixes this by lifting the linked list structure to
a layer nwrap_entlist above nwrap_entdata. The entlist
entries just contain pointers to the entdata, and hence
each line can be referenced independetly by several lists.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: remove superfluous comments from nwrap_add_hname()
Michael Adam [Wed, 11 Nov 2015 09:21:30 +0000 (10:21 +0100)]
nwrap: remove superfluous comments from nwrap_add_hname()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: remove superfluous comments from nwrap_add_hname_alias()
Michael Adam [Wed, 11 Nov 2015 09:21:10 +0000 (10:21 +0100)]
nwrap: remove superfluous comments from nwrap_add_hname_alias()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: remove a superfluous comment from nwrap_add_hname_add_new()
Michael Adam [Tue, 10 Nov 2015 11:32:20 +0000 (12:32 +0100)]
nwrap: remove a superfluous comment from nwrap_add_hname_add_new()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: move var into scope in nwrap_add_hname()
Michael Adam [Mon, 9 Nov 2015 16:41:43 +0000 (17:41 +0100)]
nwrap: move var into scope in nwrap_add_hname()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: simplify nwrap_add_hname
Michael Adam [Mon, 9 Nov 2015 16:36:37 +0000 (17:36 +0100)]
nwrap: simplify nwrap_add_hname

This is never given an alias name, so remove
the h_name_a argument.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: simplify nwrap_add_hname_alias
Michael Adam [Mon, 9 Nov 2015 16:36:07 +0000 (17:36 +0100)]
nwrap: simplify nwrap_add_hname_alias

This always uses the provided h_name_a alias name.
No need to fall back to the fqdn name from the entry.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: initialize some variables in nwrap_files_getaddrinfo
Michael Adam [Mon, 9 Nov 2015 16:35:29 +0000 (17:35 +0100)]
nwrap: initialize some variables in nwrap_files_getaddrinfo

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: slightly clean flow by removing an else branch in nwrap_getaddrinfo
Michael Adam [Sun, 8 Nov 2015 23:55:00 +0000 (00:55 +0100)]
nwrap: slightly clean flow by removing an else branch in nwrap_getaddrinfo

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: in nwrap_getaddrinfo, only call libc_getaddrinfo if we need it.
Michael Adam [Fri, 6 Nov 2015 10:43:04 +0000 (11:43 +0100)]
nwrap: in nwrap_getaddrinfo, only call libc_getaddrinfo if we need it.

Instead of calling libc_getaddrinfo on spec and throwing
away the result when we are certain that we don't need it,
call libc only if we really need it.

This fixes another memleak for the libc result.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: slightly simplify logic in nwrap_getaddrinfo()
Michael Adam [Fri, 6 Nov 2015 10:52:08 +0000 (11:52 +0100)]
nwrap: slightly simplify logic in nwrap_getaddrinfo()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: simplify logic in nwrap_getaddrinfo, calling nwrap_files_getaddrinfo
Michael Adam [Fri, 6 Nov 2015 10:48:40 +0000 (11:48 +0100)]
nwrap: simplify logic in nwrap_getaddrinfo, calling nwrap_files_getaddrinfo

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: improve code readability in nwrap_getaddrinfo()
Michael Adam [Fri, 6 Nov 2015 10:31:09 +0000 (11:31 +0100)]
nwrap: improve code readability in nwrap_getaddrinfo()

Untangle a (a ? b : c) statement and add an explanatory
comment, since the intention is not immediately obvious.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: remove code duplication in nwrap_getaddrinfo
Michael Adam [Fri, 6 Nov 2015 10:28:35 +0000 (11:28 +0100)]
nwrap: remove code duplication in nwrap_getaddrinfo

The three formerly distinct cases now are all the same.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: extend getaddrinfo_flags_ai_numericserv test to cover nwrap
Michael Adam [Fri, 6 Nov 2015 11:05:44 +0000 (12:05 +0100)]
tests: extend getaddrinfo_flags_ai_numericserv test to cover nwrap

If the handed in name is NULL, getaddrinfo calls are only
treated by libc even if nss_wrapper is enabled. Complement
the first tests with non-null name so that nwrap is covered.

Keep the NULL cases as they may be useful on their own.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: fix the getaddrinfo_service test.
Michael Adam [Fri, 6 Nov 2015 10:03:40 +0000 (11:03 +0100)]
tests: fix the getaddrinfo_service test.

When the specified service is neither a number
nor a name that can be resolved as a service,
the correct return code is EAI_NONAME instead
of EAI_SERVICE.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: fix return code for getaddrinfo in case service is not valid
Michael Adam [Fri, 6 Nov 2015 10:00:54 +0000 (11:00 +0100)]
nwrap: fix return code for getaddrinfo in case service is not valid

If the specified service is not a valid service name (or port number),
EAI_NONAME should be returned.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: fix return code of getaddrinfo for AI_NUMERICSERV in error case
Michael Adam [Fri, 6 Nov 2015 09:45:15 +0000 (10:45 +0100)]
nwrap: fix return code of getaddrinfo for AI_NUMERICSERV in error case

If the AI_NUMERICSERV flag is specified, the the port number
has to specified as a string representing a decimal number
or left NULL.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: fix numeric port detection in nwrap_getaddrinfo
Michael Adam [Fri, 6 Nov 2015 09:22:10 +0000 (10:22 +0100)]
nwrap: fix numeric port detection in nwrap_getaddrinfo

Only a string that can be converted to a number, is
allowed as a numeric port specification. Trailing
characters are not allowed.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>