obnox/cwrap/resolv_wrapper.git
4 years agotests: Use the right array size in tests.
Jakub Hrozek [Tue, 21 Oct 2014 16:42:44 +0000 (18:42 +0200)]
tests: Use the right array size in tests.

Several unit tests used the wrong array size, which might cause buffer
overflows. This patch unifies on using sizeof(array) since all the
arrays are allocated on stack.

CID #68270
CID #68269
CID #68267
CID #68265

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Don't use htons for bitfields.
Jakub Hrozek [Tue, 21 Oct 2014 15:23:30 +0000 (17:23 +0200)]
rwrap: Don't use htons for bitfields.

On FreeBSD, using htons to set the bitfield led to warnings such as:
resolv_wrapper.c:162:8: warning: implicit truncation from '__uint16_t'
(aka 'unsigned short') to bitfield changes value from 256 to 0
[-Wbitfield-constant-conversion]
        h->qr = htons(1);               /* response flag */
              ^ ~~~~~~~~

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Explicitly zero out sin_zero to silence gcc warnings.
Jakub Hrozek [Tue, 21 Oct 2014 13:34:28 +0000 (15:34 +0200)]
rwrap: Explicitly zero out sin_zero to silence gcc warnings.

On some platforms, failure to set the sin_zero structure lead to
warnings such as:

resolv_wrapper.c:969:5: warning: missing initializer for field ‘sin_zero’
        of ‘struct sockaddr_in’ [-Wmissing-field-initializers]

     };
     ^
In file included from /usr/include/arpa/inet.h:22:0,
                 from /.../source/src/resolv_wrapper.c:38:

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agotests: Call res_nclose() in test_res_query_search.c.
Jakub Hrozek [Tue, 21 Oct 2014 13:27:54 +0000 (15:27 +0200)]
tests: Call res_nclose() in test_res_query_search.c.

The res_query and res_nsearch unit tests didn't call res_nclose as
appropriate, leading to a resource leak.

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Close the resolv.conf file handle.
Jakub Hrozek [Tue, 21 Oct 2014 13:11:16 +0000 (15:11 +0200)]
rwrap: Close the resolv.conf file handle.

CID #68264

The file descriptor of resolv.conf wasn't closed properly.

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Free IPv6 name servers on close.
Jakub Hrozek [Tue, 21 Oct 2014 13:00:36 +0000 (15:00 +0200)]
rwrap: Free IPv6 name servers on close.

rwrap's res_ninit allocates IPv6 name servers, but res_nclose didn't
free them, leading to a resource leak detectable with valgrind.

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Move NEXT_KEY out of the NDEBUG ifdef.
Andreas Schneider [Tue, 21 Oct 2014 12:43:48 +0000 (14:43 +0200)]
rwrap: Move NEXT_KEY out of the NDEBUG ifdef.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agodoc: Add section for dns faking to manpage.
Andreas Schneider [Sun, 12 Oct 2014 18:04:11 +0000 (20:04 +0200)]
doc: Add section for dns faking to manpage.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agoresolv: Implement CNAME faking
Jakub Hrozek [Sat, 4 Oct 2014 16:10:42 +0000 (18:10 +0200)]
resolv: Implement CNAME faking

Signed-off-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agoresolv: Implement SOA faking
Jakub Hrozek [Sat, 4 Oct 2014 15:55:50 +0000 (17:55 +0200)]
resolv: Implement SOA faking

Signed-off-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agoresolv: Implement SRV faking
Jakub Hrozek [Sat, 4 Oct 2014 14:26:58 +0000 (16:26 +0200)]
resolv: Implement SRV faking

Signed-off-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agoresolv: Implement faking A and AAAA DNS replies
Jakub Hrozek [Sun, 14 Sep 2014 09:12:56 +0000 (11:12 +0200)]
resolv: Implement faking A and AAAA DNS replies

Adds the possibility of faking a DNS reply based on a hosts-like file.

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agocmake: Rely on the cmake config cmocka provides.
Andreas Schneider [Tue, 16 Sep 2014 13:37:38 +0000 (15:37 +0200)]
cmake: Rely on the cmake config cmocka provides.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agotests: Add a unit test for res_nquery and res_nsearch
Jakub Hrozek [Fri, 12 Sep 2014 13:49:01 +0000 (15:49 +0200)]
tests: Add a unit test for res_nquery and res_nsearch

Adds a test that connects to a test DNS server and searches it using
res_query and res_search.

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agotests: Add generating resolv.conf to torture
Jakub Hrozek [Sat, 13 Sep 2014 15:09:30 +0000 (17:09 +0200)]
tests: Add generating resolv.conf to torture

Adds a setup/teardown functions that allow a unit test to easily
generate a resolv.conf pointing to our test DNS server.

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agotests: Add torture library from socket_wrapper
Jakub Hrozek [Fri, 12 Sep 2014 12:49:16 +0000 (14:49 +0200)]
tests: Add torture library from socket_wrapper

Pretty much a blatant copy of the torture library from socket_wrapper,
just s/echo_srv/dns_srv/

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agotests: Add a simple DNS server
Jakub Hrozek [Mon, 8 Sep 2014 07:48:17 +0000 (09:48 +0200)]
tests: Add a simple DNS server

This DNS server will be usable for testing. Currently only supports A
records.

The server responds to any A query with the value of RWRAP_TEST_A_REC
environment variable. If undefined, the server always replies with
127.0.10.10.

Please note the server does *not* perform many security checks and is
completely unsuitable outside a test suite! Check out servers like
dnsmasq for anything more complex.

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agodoc: Update the manpage for resolv.conf.
Andreas Schneider [Thu, 4 Sep 2014 09:19:04 +0000 (11:19 +0200)]
doc: Update the manpage for resolv.conf.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agodoc: Add instructions how to point cmake to socket_wrapper
Michael Adam [Wed, 15 Oct 2014 09:52:08 +0000 (11:52 +0200)]
doc: Add instructions how to point cmake to socket_wrapper

This is needed for unit testing.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
4 years agotests: Add a test for parsing resolv.conf
Jakub Hrozek [Wed, 3 Sep 2014 15:32:27 +0000 (17:32 +0200)]
tests: Add a test for parsing resolv.conf

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Add support to read a resolv.conf.
Jakub Hrozek [Wed, 3 Sep 2014 12:34:15 +0000 (14:34 +0200)]
rwrap: Add support to read a resolv.conf.

For now, only "nameserver" entries are interpreted.

Pair-Programmed-With: Andreas Schneider <asn@samba.org>

Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com>
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Add support for res_[n]search().
Andreas Schneider [Tue, 2 Sep 2014 12:19:32 +0000 (14:19 +0200)]
rwrap: Add support for res_[n]search().

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Add support for res_[n]query().
Andreas Schneider [Tue, 2 Sep 2014 12:06:00 +0000 (14:06 +0200)]
rwrap: Add support for res_[n]query().

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Add support for res_nclose().
Andreas Schneider [Mon, 1 Sep 2014 15:23:13 +0000 (17:23 +0200)]
rwrap: Add support for res_nclose().

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Add initial support for res_[n]init().
Andreas Schneider [Mon, 1 Sep 2014 10:41:17 +0000 (12:41 +0200)]
rwrap: Add initial support for res_[n]init().

This first approach does not parse a resolv.conf file
but instead takes a nameserver address from the environment
variable RESOLV_WRAPPER_NAMESERVER.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Add .gitignore.
Andreas Schneider [Thu, 4 Sep 2014 05:57:11 +0000 (07:57 +0200)]
rwrap: Add .gitignore.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
4 years agorwrap: Big bang!
Andreas Schneider [Thu, 28 Aug 2014 15:47:06 +0000 (17:47 +0200)]
rwrap: Big bang!

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>