cfg: implement custom-domain() setting
host-resolve: use hostname provided functions instead of global variables directly
host-resolve: factor out normalize_hostname()
host-resolve: introduce HostResolveOptions

This patch adds HostResolveOptions to contain all resolver related
configuration options.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
host-resolve: reindent error messages
host-resolve: add resolve_hostname_to_hostname() function

This function can be used to reformat a hostname according to use-fqdn() &
normalize-hostnames() settings. Basically if we got a hostname without IP
address information, this is the best bet we can do to format a hostname
that best matches the one we would be generating if we created a message.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
host-resolve: added unit test program
host-resolve: avoid the use of input/output parameters

Instead of using a parameter that's input/output at the same time, separate
the two roles. Buffer size is a separate parameter from the returned
length.

Update testcases and add new tests to cover truncation due to small buffer
size.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
host-resolve: always return a new GSockAddr instance from resolve_hostname_to_sockaddr()

Instead of trying to _change_ an existing GSockAddr instance, always return
a new one. This makes the API easier to use, as well as makes
the implementation simpler. The original prototype probably dates back
to times when the afsocket driver stored ip/port parameters in an
existing GSockAddr instance and creating a new one was not good.

These times, we basically create the GSockAddr instance in the drivers
just to satisfy this requirement. So this patch simplifies call-sites
as well.

The only reason the input GSockAddr was used to determine the target address
family, but I introduced a new parameter for that.

Also the patch adds coverage for IPv6 in the testsuite.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
host-resolve: empty string in resolve_hostname_to_sockaddr() resolves to the wildcard address

As call-sites had to handle the default bind address on their own,
a better strategy is to handle a specific hostname to resolve to the
wildcard address that can be used to bind a service.

With IPv4, using the empty string or "0" literal works. With IPv6
unfortunately neither does. This patch adds this capability
to resolve_hostname_to_sockaddr(), either the empty string or a NULL
value returns the 0.0.0.0:0 or [::]:0 for IPv4 and IPv6 respectively.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
host-resolve: only declare resolve_lock if needed

This patch avoids the declaration of resolv_lock if not needed.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
host-resolve: refactor resolve_hostname_to_sockaddr() to smaller functions

This patch splits this huge function to smaller ones while keeping
its functionality and prototype.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
dnscache: store and return the length of the cached hostname

This is the fastest path in resolving a hostname, thus it makes sense
to also cache the length of the hostname for speed reasons.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
dnscache: add dns_cache_store() wrappers

Instead of two boolean arguments, use two wrappers for the two different
use-cases of the DNS cache.

1) dns_cache_store_persistent() can be used to add persistent entries
populated from /etc/hosts.

2) dns_cache_store_dynamic() can be used to add the normal, expiring
entries.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
dnscache: don't allow NULL hostname

In old times, hostname == NULL indicated a negative match, however this
was superseeded by an explicit "positive" argument to
dns_cache_store()/lookup() functions. Get rid of the remainder of this
old cruft, also updating the unit test in the process.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
hostname: add win32 implementation

This patch adds an implementation for supporting local hostname querying
on Windows platforms.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>