Makefile.am: change library ordering in TEST_LDADD

Since libsyslog-ng-test.a uses symbols from libsyslog-ng.so, the .a file
should come first. The only reason this didn't cause issues is that so
far all test programs directly referenced the .so file too. If that
doesn't happen, linking errors ensue.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
gsockaddr: constify ip address parameter for GSockAddrInet constructor

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
syslog-ng-ctl: make control_name const

To fix a warning and to indicate that syslog-ng-ctl doesn't own that value.
It's only a borrowed reference, its memory is managed by reloc.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg: free global LogTemplateOptions

This fixes a potential memory leak when global template specific
options were specified, such as local-time-zone(), send-time-zone() etc.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
hostname: factor out hostname related functions from misc
host-resolve: factor out resolver related functions from misc
hostname: refactor, cleanup and test coverage

This is a largish patch that contains multiple changes to the hostname
module.  The intentions of this patch are:

  * port new functionality from PE, which is essentially custom-domain() and
    a port to the Win32 API
  * make the code easier to follow and define clear semantics of all
    functions and test it via a unit test program
  * add the foundations of a custom-domain() option that can be used to
    override the local domain name
  * introduction of global_init/deinit function pairs
  * add two new functions that convert a hostname from fqdn to short and
    vice versa

Although it'd be better to split this patch along these lines, however
splitting it up is not really easy because of the internal dependencies, and
that the original was written as a single iteration. Essentially internal
steps would need to be rewritten from scratch.

Signed-off-by: Viktor Juhasz <jviktor@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
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>