1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00
Commit Graph

110 Commits

Author SHA1 Message Date
Michael Adam
ab2f41bed6 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>
2016-01-11 12:25:31 +01:00
Michael Adam
062c97be19 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>
2016-01-11 12:25:31 +01:00
Michael Adam
a66606cd02 nwrap: use symbols IPPROTO_TCP and IPPROTO_UDP
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:31 +01:00
Michael Adam
bf65160ed2 nwrap: rename _ai -> ai_new in nwrap_files_getaddrinfo()
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:31 +01:00
Michael Adam
a42f6589c7 nwrap: fix a memleak in nwrap_files_getaddrinfo()
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:31 +01:00
Michael Adam
07b6925242 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>
2016-01-11 12:25:31 +01:00
Michael Adam
b996f0a60c 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>
2016-01-11 12:25:31 +01:00
Michael Adam
07f1bef632 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>
2016-01-11 12:25:31 +01:00
Michael Adam
55e9606e68 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>
2016-01-11 12:25:31 +01:00
Michael Adam
34cff9e729 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>
2016-01-11 12:25:31 +01:00
Michael Adam
154080ce85 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>
2016-01-11 12:25:30 +01:00
Michael Adam
0dc34ea56a 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>
2016-01-11 12:25:30 +01:00
Michael Adam
18be46d87c 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>
2016-01-11 12:25:30 +01:00
Michael Adam
6078126eb5 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>
2016-01-11 12:25:30 +01:00
Michael Adam
fe7e163515 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>
2016-01-11 12:25:30 +01:00
Michael Adam
4919f1cd21 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>
2016-01-11 12:25:30 +01:00
Michael Adam
ccb4076309 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>
2016-01-11 12:25:30 +01:00
Michael Adam
f6e4c58663 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>
2016-01-11 12:25:30 +01:00
Michael Adam
ddd0ca82bb 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>
2016-01-11 12:25:30 +01:00
Michael Adam
7ec5aaeb02 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>
2016-01-11 12:25:30 +01:00
Michael Adam
2974cef3d8 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>
2016-01-11 12:25:30 +01:00
Michael Adam
be8c7dc5af nwrap: catch NULL ip in nwrap_add_ai
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:30 +01:00
Michael Adam
a725bd7728 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>
2016-01-11 12:25:30 +01:00
Michael Adam
d681a084d9 nwrap: simplify nwrap_file_getaddrinfo: remove a variable
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:30 +01:00
Michael Adam
28f0a8b5a9 nwrap: simplify nwrap_files_gethostbyname: remove a variable
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:29 +01:00
Michael Adam
54c825b1cb nwrap: log hash table full message at error level
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:29 +01:00
Michael Adam
95025358d8 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>
2016-01-11 12:25:29 +01:00
Michael Adam
19d54157a4 nwrap: remove superfluous comments from nwrap_add_hname()
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:29 +01:00
Michael Adam
4ec47e739c nwrap: remove superfluous comments from nwrap_add_hname_alias()
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:29 +01:00
Michael Adam
69af963f8e 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>
2016-01-11 12:25:29 +01:00
Michael Adam
3cc12ec554 nwrap: move var into scope in nwrap_add_hname()
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:29 +01:00
Michael Adam
f7b28bd655 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>
2016-01-11 12:25:29 +01:00
Michael Adam
8f62cda726 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>
2016-01-11 12:25:29 +01:00
Michael Adam
067978d785 nwrap: initialize some variables in nwrap_files_getaddrinfo
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:29 +01:00
Michael Adam
be182bab2e 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>
2016-01-11 12:25:29 +01:00
Michael Adam
559ed74a5a 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>
2016-01-11 12:25:29 +01:00
Michael Adam
9927e499f2 nwrap: slightly simplify logic in nwrap_getaddrinfo()
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:29 +01:00
Michael Adam
b0569d40ce 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>
2016-01-11 12:25:29 +01:00
Michael Adam
53e633e401 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>
2016-01-11 12:25:29 +01:00
Michael Adam
8da2110a84 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>
2016-01-11 12:25:28 +01:00
Michael Adam
5bea2dc13f 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>
2016-01-11 12:25:28 +01:00
Michael Adam
40f9bf7835 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>
2016-01-11 12:25:28 +01:00
Michael Adam
522631b739 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>
2016-01-11 12:25:28 +01:00
Robin Hack
72764a6fd3 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>
2016-01-11 12:25:28 +01:00
Robin Hack
200f5bf138 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>
2016-01-11 12:25:28 +01:00
Robin Hack
43d470a06f 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>
2016-01-11 12:25:28 +01:00
Robin Hack
853b2ff08e 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>
2016-01-11 12:25:28 +01:00
Robin Hack
3cae3e55e7 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>
2016-01-11 12:25:28 +01:00
Robin Hack
e1bb0094d4 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>
2016-01-11 12:25:28 +01:00
Robin Hack
0f1ffb9b5b 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>
2016-01-11 12:25:28 +01:00