1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-27 03:21:53 +03:00
Commit Graph

5179 Commits

Author SHA1 Message Date
Michael Adam
159fdb0185 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>
2016-01-11 12:25:32 +01:00
Michael Adam
bf496153bc 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>
2016-01-11 12:25:32 +01:00
Michael Adam
736fa61a95 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>
2016-01-11 12:25:32 +01:00
Michael Adam
e94a7c5a56 nwrap: remove unused member list from struct nwrap_he
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2016-01-11 12:25:31 +01:00
Robin Hack
16b71aecab 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>
2016-01-11 12:25:31 +01:00
Andreas Schneider
db0ef5cc9e nwrap: Cast max_hostents to avoid warnings
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
2016-01-11 12:25:31 +01:00
Andreas Schneider
8fad97bc34 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>
2016-01-11 12:25:31 +01:00
Michael Adam
f1acb0e296 nwrap: remove ai_tail argument from 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
d198cdaefd 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>
2016-01-11 12:25:31 +01:00
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