obnox/cwrap/nss_wrapper.git
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>
8 years agotests: Added new test: test_nwrap_getaddrinfo_flags_ai_numericserv
Robin Hack [Tue, 13 Oct 2015 12:42:03 +0000 (14:42 +0200)]
tests: Added new test: test_nwrap_getaddrinfo_flags_ai_numericserv

Test checks if non-valid input is handled correctly.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agonwrap: Better check service string sanity.
Robin Hack [Tue, 13 Oct 2015 12:41:14 +0000 (14:41 +0200)]
nwrap: Better check service string sanity.

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

Patch use strtol() instead of atoi() to convert strings to numbers.
This helps better check sanity of service input string.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Fix memory leak in nwrap_gethostbyname_r()
Robin Hack [Mon, 12 Oct 2015 08:36:04 +0000 (10:36 +0200)]
nwrap: Fix memory leak in nwrap_gethostbyname_r()

Fix reimplements how memory is used.
Results from vector are copied to user provided buf.

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 agonwrap: Fix memory leak in nwrap_files_gethostbyname()
Robin Hack [Thu, 8 Oct 2015 13:27:47 +0000 (15:27 +0200)]
nwrap: Fix memory leak in nwrap_files_gethostbyname()

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Fix memory leak in nwrap_he_unload()
Robin Hack [Thu, 8 Oct 2015 13:00:33 +0000 (15:00 +0200)]
nwrap: Fix memory leak in nwrap_he_unload()

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Rename cont to vector in nwrap_vector_add_item()
Robin Hack [Thu, 8 Oct 2015 12:09:11 +0000 (14:09 +0200)]
nwrap: Rename cont to vector in nwrap_vector_add_item()

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Fix memory leak inside nwrap_getaddrinfo()
Robin Hack [Thu, 8 Oct 2015 12:02:56 +0000 (14:02 +0200)]
nwrap: Fix memory leak inside nwrap_getaddrinfo()

Memory leak was introduced by deep copy code.
Item ai_tmp->ai_addr should not have deep copy.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Use nwrap_vector_foreach instead of for loop
Robin Hack [Thu, 8 Oct 2015 12:00:38 +0000 (14:00 +0200)]
nwrap: Use nwrap_vector_foreach instead of for loop

Replace for loop by nwrap_vector_foreach in nwrap_lines_unload().

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Fix memory leak when getline() is used.
Robin Hack [Thu, 8 Oct 2015 09:36:33 +0000 (11:36 +0200)]
nwrap: Fix memory leak when getline() is used.

getline() allocates memory even if return code is < 0.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: add test for merging with empty vectors left and right.
Michael Adam [Fri, 9 Oct 2015 08:16:44 +0000 (10:16 +0200)]
tests: add test for merging with empty vectors left and right.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: improve nwrap_vector tests
Michael Adam [Fri, 9 Oct 2015 08:10:44 +0000 (10:10 +0200)]
tests: improve nwrap_vector tests

Improves ordering and adds some additional checks.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: Add missing include for crypt.h in test_shadow
Andreas Schneider [Thu, 8 Oct 2015 09:42:42 +0000 (11:42 +0200)]
tests: Add missing include for crypt.h in test_shadow

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Modify AUTHORS file. getaddrinfo-v2
Robin Hack [Mon, 30 Mar 2015 14:08:25 +0000 (16:08 +0200)]
nwrap: Modify AUTHORS file.

Assign emails to authors.
Also add me (Robin Hack) as a author.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoTESTS: Add new test which checks multithread support.
Robin Hack [Tue, 24 Mar 2015 15:45:19 +0000 (16:45 +0100)]
TESTS: Add new test which checks multithread support.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add basic locking for support multithreaded applications
Robin Hack [Tue, 24 Mar 2015 16:54:34 +0000 (17:54 +0100)]
nwrap: Add basic locking for support multithreaded applications

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoTESTS: Add test for getaddrinfo.
Robin Hack [Mon, 30 Mar 2015 12:36:29 +0000 (14:36 +0200)]
TESTS: Add test for getaddrinfo.

Test tries to get multiple and mixed (ipv4 and ipv6) records.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoTESTS: Add test_nwrap_gethostbyname_multiple test
Robin Hack [Tue, 24 Mar 2015 11:03:14 +0000 (12:03 +0100)]
TESTS: Add test_nwrap_gethostbyname_multiple test

Test cover multiple records support.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add BSD libc support for gethost*_r functios.
Robin Hack [Fri, 27 Mar 2015 14:51:11 +0000 (15:51 +0100)]
nwrap: Add BSD libc support for gethost*_r functios.

BSD libc stores data in thread local storage.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Use nwrap vectors as memory backend for getaddrinfo() and gethostbyname()
Robin Hack [Thu, 16 Jul 2015 14:10:20 +0000 (16:10 +0200)]
nwrap: Use nwrap vectors as memory backend for getaddrinfo() and gethostbyname()

Previous patches introduced nwrap vectors and hash functions.
This patch will join all together.

Main purpose of this patch is:
- support more records per hostname.
  For example: hostname now can have associated IPv4 and IPv6 address.
- better handling of big number of hostname records

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add string manipulation functions.
Robin Hack [Tue, 24 Mar 2015 14:14:35 +0000 (15:14 +0100)]
nwrap: Add string manipulation functions.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add nwrap_add_hname() and nwrap_add_hname_alias().
Robin Hack [Wed, 15 Jul 2015 13:05:28 +0000 (15:05 +0200)]
nwrap: Add nwrap_add_hname() and nwrap_add_hname_alias().

Functions adds a hostname or an alias to the hash table.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add function nwrap_add_ai
Robin Hack [Wed, 15 Jul 2015 13:04:32 +0000 (15:04 +0200)]
nwrap: Add function nwrap_add_ai

This adds an ip to the hash table.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add a hash table to the nwrap structure
Robin Hack [Wed, 15 Jul 2015 13:01:48 +0000 (15:01 +0200)]
nwrap: Add a hash table to the nwrap structure

The hash table will hold hostnames and ips internally. The new
environment variable which is introduced is NSS_WRAPPER_MAX_HOSTENTS. It
sets the maximum count of hostent (hostnames and ips) structs which the
hash table can hold.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Simplify file loading.
Robin Hack [Mon, 23 Mar 2015 13:39:28 +0000 (14:39 +0100)]
nwrap: Simplify file loading.

Lines are stored into vectors now.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add nwrap vector memory management functions
Robin Hack [Mon, 23 Mar 2015 13:10:18 +0000 (14:10 +0100)]
nwrap: Add nwrap vector memory management functions

Nwrap vectors  are just more inteligent arrays.
They can look like very simple version of
vectors from C++.

TESTS: Add nwrap_vector tests.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Only run shadow test when shadow.h is available master-getspnam
Andreas Schneider [Tue, 6 Oct 2015 08:53:00 +0000 (10:53 +0200)]
tests: Only run shadow test when shadow.h is available

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Check for setspent and getspnam functions
Andreas Schneider [Tue, 6 Oct 2015 08:34:20 +0000 (10:34 +0200)]
nwrap: Check for setspent and getspnam functions

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agosrc: Add configure check for shadow.h
Andreas Schneider [Tue, 6 Oct 2015 08:19:48 +0000 (10:19 +0200)]
src: Add configure check for shadow.h

This is the first part to fix FreeBSD.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Add test for getspnam() function
Andreas Schneider [Mon, 14 Sep 2015 16:26:41 +0000 (18:26 +0200)]
tests: Add test for getspnam() function

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add support for getspnam()
Andreas Schneider [Thu, 17 Sep 2015 08:39:15 +0000 (10:39 +0200)]
nwrap: Add support for getspnam()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Add test for (set|get|end)spent functions
Andreas Schneider [Thu, 17 Sep 2015 08:44:30 +0000 (10:44 +0200)]
tests: Add test for (set|get|end)spent functions

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add (set|get|end)spent functions
Andreas Schneider [Thu, 17 Sep 2015 08:38:49 +0000 (10:38 +0200)]
nwrap: Add (set|get|end)spent functions

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add nss_wrapper_shadow_enabled() function
Andreas Schneider [Thu, 17 Sep 2015 08:37:50 +0000 (10:37 +0200)]
nwrap: Add nss_wrapper_shadow_enabled() function

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Add shadow file parser
Andreas Schneider [Thu, 17 Sep 2015 08:33:58 +0000 (10:33 +0200)]
nwrap: Add shadow file parser

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Remove unused struct member in nwrap_main
Andreas Schneider [Thu, 17 Sep 2015 08:32:46 +0000 (10:32 +0200)]
nwrap: Remove unused struct member in nwrap_main

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Implement nwrap_files_initgroups()
Andreas Schneider [Fri, 11 Sep 2015 11:37:57 +0000 (13:37 +0200)]
nwrap: Implement nwrap_files_initgroups()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Remove unneeded memcpy in getgrouplist()
Andreas Schneider [Mon, 14 Sep 2015 12:57:40 +0000 (14:57 +0200)]
nwrap: Remove unneeded memcpy in getgrouplist()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Avoid a string comparsion in getgrouplist()
Andreas Schneider [Mon, 14 Sep 2015 12:52:51 +0000 (14:52 +0200)]
nwrap: Avoid a string comparsion in getgrouplist()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoTESTS: Add assertions to tests.
Robin Hack [Tue, 24 Mar 2015 10:59:53 +0000 (11:59 +0100)]
TESTS: Add assertions to tests.

When function returns NULL then test raise assert fail istead of
SIGSEGV now.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoTESTS: Switch tests to new CMocka API.
Robin Hack [Wed, 25 Mar 2015 10:30:35 +0000 (11:30 +0100)]
TESTS: Switch tests to new CMocka API.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoTESTS: Fix some memory leaks in testsuite.
Robin Hack [Tue, 24 Mar 2015 11:02:24 +0000 (12:02 +0100)]
TESTS: Fix some memory leaks in testsuite.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Use ssize_t for aliases_count
Robin Hack [Wed, 15 Jul 2015 13:00:02 +0000 (15:00 +0200)]
nwrap: Use ssize_t for aliases_count

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Prevent compilation failure on machine without IPv4
Robin Hack [Wed, 25 Mar 2015 08:36:10 +0000 (09:36 +0100)]
nwrap: Prevent compilation failure on machine without IPv4

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agonwrap: Replace free() calls by SAFE_FREE macro where possible.
Robin Hack [Sat, 29 Nov 2014 12:22:46 +0000 (13:22 +0100)]
nwrap: Replace free() calls by SAFE_FREE macro where possible.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agocmake: Add compilation flags
Robin Hack [Wed, 25 Mar 2015 11:50:16 +0000 (12:50 +0100)]
cmake: Add compilation flags

Flags added:
    -Wbad-function-cast
    -fstrict-aliasing
    -Wstrict-aliasing=3

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agocmake: Add detection of -fstack-protector-strong compiler flag
Robin Hack [Wed, 25 Mar 2015 11:34:53 +0000 (12:34 +0100)]
cmake: Add detection of -fstack-protector-strong compiler flag

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
9 years agocmake: Drop test results via https.
Andreas Schneider [Wed, 25 Feb 2015 10:20:24 +0000 (11:20 +0100)]
cmake: Drop test results via https.

Signed-off-by: Andreas Schneider <asn@samba.org>
9 years agonwrap: Fix the handle loops for older gcc versions.
Andreas Schneider [Wed, 1 Oct 2014 15:15:35 +0000 (17:15 +0200)]
nwrap: Fix the handle loops for older gcc versions.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
9 years agoBump version to 1.0.3.
Andreas Schneider [Wed, 10 Sep 2014 11:53:13 +0000 (13:53 +0200)]
Bump version to 1.0.3.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
9 years agonwrap: Make sure addr is initialized.
Andreas Schneider [Wed, 10 Sep 2014 06:30:22 +0000 (08:30 +0200)]
nwrap: Make sure addr is initialized.

CID #72755

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>