socket_wrapper.git
6 years agoBump version to 1.1.8 socket_wrapper-1.1.8
Andreas Schneider [Thu, 12 Oct 2017 14:47:49 +0000 (16:47 +0200)]
Bump version to 1.1.8

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
6 years agoswrap: Fix prototype of open[64] to prevent segfault on ppc64le
Andreas Schneider [Wed, 2 Aug 2017 11:21:59 +0000 (13:21 +0200)]
swrap: Fix prototype of open[64] to prevent segfault on ppc64le

The calling conventions for vaarg are different on ppc64le. The patch
fixes segfaults on that platform.

Thanks to Florian Weimer who helped debugging it!

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Improve argument handling for libc_vopen*()
Andreas Schneider [Tue, 1 Aug 2017 08:58:50 +0000 (10:58 +0200)]
swrap: Improve argument handling for libc_vopen*()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Improve argument handling for libc_vioctl()
Andreas Schneider [Tue, 1 Aug 2017 08:48:47 +0000 (10:48 +0200)]
swrap: Improve argument handling for libc_vioctl()

The ioctl() only takes one or no argument.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Improve argument handling for libc_fcntl()
Andreas Schneider [Tue, 1 Aug 2017 08:20:46 +0000 (10:20 +0200)]
swrap: Improve argument handling for libc_fcntl()

fcntl() has either one or no argument.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agotests: Add a simple fnctl() test
Andreas Schneider [Mon, 31 Jul 2017 17:25:41 +0000 (19:25 +0200)]
tests: Add a simple fnctl() test

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Simplify printing different log prefixes
Andreas Schneider [Mon, 31 Jul 2017 16:25:42 +0000 (18:25 +0200)]
swrap: Simplify printing different log prefixes

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Do an early return if log level doesn't match
Andreas Schneider [Mon, 31 Jul 2017 16:25:30 +0000 (18:25 +0200)]
swrap: Do an early return if log level doesn't match

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Always enable logging
Andreas Schneider [Mon, 31 Jul 2017 16:21:53 +0000 (18:21 +0200)]
swrap: Always enable logging

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Protect the FALL_THROUGH define
Andreas Schneider [Thu, 27 Jul 2017 11:18:12 +0000 (13:18 +0200)]
swrap: Protect the FALL_THROUGH define

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agocmake: Replace deprecated get_target_property()
Andreas Schneider [Thu, 27 Jul 2017 09:30:23 +0000 (11:30 +0200)]
cmake: Replace deprecated get_target_property()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agoswrap: Add common exit point to swrap_setsockopt
Anoop C S [Thu, 13 Jul 2017 00:43:47 +0000 (02:43 +0200)]
swrap: Add common exit point to swrap_setsockopt

In preparation of thread safety.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agoswrap: Add common exit point to swrap_getsockopt
Anoop C S [Thu, 13 Jul 2017 00:36:20 +0000 (02:36 +0200)]
swrap: Add common exit point to swrap_getsockopt

In preparation of thread safety.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agoswrap: Add common exit point to swrap_connect
Anoop C S [Thu, 13 Jul 2017 00:30:14 +0000 (02:30 +0200)]
swrap: Add common exit point to swrap_connect

In preparation of thread safety.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agoswrap: Add common exit point to swrap_auto_bind
Anoop C S [Thu, 13 Jul 2017 00:26:10 +0000 (02:26 +0200)]
swrap: Add common exit point to swrap_auto_bind

In preparation for thread safety.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agoswrap: Fix tab vs space in swrap_auto_bind
Michael Adam [Thu, 13 Jul 2017 00:22:14 +0000 (02:22 +0200)]
swrap: Fix tab vs space in swrap_auto_bind

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Suppress intentional fall through warning
Anoop C S [Sat, 15 Jul 2017 15:24:06 +0000 (20:54 +0530)]
swrap: Suppress intentional fall through warning

-Wimplicit-fallthrough compiler flag introduced with gcc v7
results in the following warning during compilation:

[  7%] Building C object src/CMakeFiles/socket_wrapper.dir/socket_wrapper.c.o
src/socket_wrapper.c: In function ‘sockaddr_convert_to_un’:
src/socket_wrapper.c:1846:18: warning: this statement may fall through [-Wimplicit-fallthrough=]
  case AF_UNSPEC: {
                  ^
/src/socket_wrapper.c:1866:2: note: here
  case AF_INET:
  ^~~~

Default level for -Wimplicit-fallthrough(which is 3) allows
us to get rid of the above warning using specific comments
made within switch cases matching the regular expressions
outlined in gcc docs[1].

But for us the presence of preprocessor directives in the
vicinity of such comments nullifies its effect[2]. So our
best bet would be to make use of the reliable fallthrough
attribute and supress such warnings in future.

[1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77817

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agoswrap: Add fopen64() on systems which provide it
Andreas Schneider [Thu, 6 Apr 2017 07:05:26 +0000 (09:05 +0200)]
swrap: Add fopen64() on systems which provide it

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
7 years agocmake: Check for fopen64() function
Andreas Schneider [Thu, 6 Apr 2017 07:02:21 +0000 (09:02 +0200)]
cmake: Check for fopen64() function

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
7 years agoswrap: Add open64() on systems which provide it
Andreas Schneider [Tue, 28 Mar 2017 07:09:06 +0000 (09:09 +0200)]
swrap: Add open64() on systems which provide it

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12694

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
7 years agocmake: Check for open64() function
Andreas Schneider [Tue, 28 Mar 2017 07:03:02 +0000 (09:03 +0200)]
cmake: Check for open64() function

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12694

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
7 years agocmake: Do not check for LFS support
Andreas Schneider [Tue, 28 Mar 2017 06:58:14 +0000 (08:58 +0200)]
cmake: Do not check for LFS support

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12694

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
7 years agoswrap: Increase max wrapped interfaces
Andreas Schneider [Mon, 20 Mar 2017 10:25:40 +0000 (11:25 +0100)]
swrap: Increase max wrapped interfaces

We are hitting the limit of 40 interfaces with Samba. So increase it to
64.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
7 years agotests: Fix test_close_failure test case
Michael Adam [Thu, 16 Mar 2017 11:18:28 +0000 (11:18 +0000)]
tests: Fix test_close_failure test case

Found by valgrind.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: use proper blocks for early returns
Michael Adam [Fri, 23 Sep 2016 14:33:52 +0000 (16:33 +0200)]
swrap: use proper blocks for early returns

This is better to read and might reduce the
diff of later patches.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Add support for openat()
Andreas Schneider [Thu, 2 Mar 2017 08:56:29 +0000 (09:56 +0100)]
swrap: Add support for openat()

7 years agoIncrease wait time during echo_server's pid-file check
Anoop C S [Thu, 23 Feb 2017 10:52:47 +0000 (10:52 +0000)]
Increase wait time during echo_server's pid-file check

We used to sleep for 200 microseconds in each iteration for checking
the existence of echo server's pid file which seems to be very short.
In order to avoid chances of failures to detect this pid file within
100 such iterations its better to increase this wait time to 2000
microseconds.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agoAvoid mutex lock wait in socket close failure
Anoop C S [Fri, 10 Feb 2017 16:08:11 +0000 (21:38 +0530)]
Avoid mutex lock wait in socket close failure

In case of absence to close a socket fd during an exit from
application we try to close the same by traversing the
socket_fds in swrap_destructor. But the early lock taken on
libc_symbol_binding_mutex inside the destructor blocks the
subsequent request for locking the same while loading
libc_close within swrap_close.

Also added a test case to verify this flaw in destructor.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agoswrap: Add sanity check in socket_wrapper_max_sockets()
Andreas Schneider [Fri, 4 Nov 2016 08:44:04 +0000 (09:44 +0100)]
swrap: Add sanity check in socket_wrapper_max_sockets()

CID 153962

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agotests: Clean-up max_sockets test case
Anoop C S [Fri, 23 Sep 2016 07:08:31 +0000 (12:38 +0530)]
tests: Clean-up max_sockets test case

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Fix use-after-free
Anoop C S [Tue, 25 Oct 2016 17:03:10 +0000 (22:33 +0530)]
swrap: Fix use-after-free

This was introduced by commit 9ce583b6cd6f55d473e5b54794fb06450997ebc8

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: fix SWRAP_DLIST_ADD_AFTER
Anoop C S [Tue, 25 Oct 2016 13:56:20 +0000 (15:56 +0200)]
swrap: fix SWRAP_DLIST_ADD_AFTER

Pair-Programmed-With: Michael Adam <obnox@samba.org>

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: fix use-after-free in swrap_remove_stale()
Michael Adam [Tue, 25 Oct 2016 11:46:18 +0000 (13:46 +0200)]
swrap: fix use-after-free in swrap_remove_stale()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: slightly cleanup logic in swrap_close
Michael Adam [Tue, 25 Oct 2016 11:42:05 +0000 (13:42 +0200)]
swrap: slightly cleanup logic in swrap_close

This moves the libc_close() to one central point, thereby
grouping the fd-related operations together and the the
socket-info related operations after that.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: fix use-after-free in swrap_close
Michael Adam [Tue, 25 Oct 2016 11:41:29 +0000 (13:41 +0200)]
swrap: fix use-after-free in swrap_close

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Fix build on Solaris
Andreas Schneider [Sat, 22 Oct 2016 11:42:41 +0000 (13:42 +0200)]
swrap: Fix build on Solaris

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agoswrap: Mark flags in swrap_accept4 as unused
Andreas Schneider [Fri, 21 Oct 2016 06:04:02 +0000 (08:04 +0200)]
swrap: Mark flags in swrap_accept4 as unused

This removes a compiler warning on non-Linux systems.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agoswrap: Fix the build on BSD and Solaris
Andreas Schneider [Fri, 21 Oct 2016 05:56:24 +0000 (07:56 +0200)]
swrap: Fix the build on BSD and Solaris

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agoswrap: Handle threads that fork
Andreas Schneider [Thu, 20 Oct 2016 08:37:18 +0000 (10:37 +0200)]
swrap: Handle threads that fork

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agocmake: Check for constructor attribute
Andreas Schneider [Thu, 20 Oct 2016 08:35:50 +0000 (10:35 +0200)]
cmake: Check for constructor attribute

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agoswrap: Make symbol loading thread-safe
Andreas Schneider [Thu, 20 Oct 2016 08:22:40 +0000 (10:22 +0200)]
swrap: Make symbol loading thread-safe

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agocmake: Link pthread library headers
Michael Adam [Sun, 18 Sep 2016 18:28:06 +0000 (20:28 +0200)]
cmake: Link pthread library headers

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Fix strict-aliasing issues while loading symbols
Andreas Schneider [Thu, 20 Oct 2016 08:56:35 +0000 (10:56 +0200)]
swrap: Fix strict-aliasing issues while loading symbols

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
7 years agotests: Add a test for max_sockets
Michael Adam [Thu, 22 Sep 2016 00:13:20 +0000 (02:13 +0200)]
tests: Add a test for max_sockets

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Introduce a freelist in the socket_info array
Michael Adam [Wed, 14 Sep 2016 11:24:47 +0000 (13:24 +0200)]
swrap: Introduce a freelist in the socket_info array

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Replace linked list of socket_info with preallocated array of structures
Anoop C S [Thu, 25 Aug 2016 06:11:12 +0000 (11:41 +0530)]
swrap: Replace linked list of socket_info with preallocated array of structures

Pair-Programmed-With: Michael Adam <obnox@samba.org>

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Optimization in (commented out) check_addr_port_in_use()
Michael Adam [Tue, 16 Aug 2016 11:38:50 +0000 (13:38 +0200)]
swrap: Optimization in (commented out) check_addr_port_in_use()

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Improve vfcntl to add the dup'd fd after the source fd
Michael Adam [Tue, 16 Aug 2016 09:04:43 +0000 (11:04 +0200)]
swrap: Improve vfcntl to add the dup'd fd after the source fd

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Improve dup2 to add the dup'd fd after the source fd
Michael Adam [Tue, 16 Aug 2016 09:04:12 +0000 (11:04 +0200)]
swrap: Improve dup2 to add the dup'd fd after the source fd

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Improve dup to add the dup'd fd after the source fd
Michael Adam [Tue, 16 Aug 2016 09:03:27 +0000 (11:03 +0200)]
swrap: Improve dup to add the dup'd fd after the source fd

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Add SWRAP_DLIST_ADD_AFTER macro
Michael Adam [Tue, 16 Aug 2016 09:00:50 +0000 (11:00 +0200)]
swrap: Add SWRAP_DLIST_ADD_AFTER macro

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Untangle socket_info_fd from socket_info structure.
Anoop C S [Wed, 10 Aug 2016 11:02:19 +0000 (16:32 +0530)]
swrap: Untangle socket_info_fd from socket_info structure.

This reverses the dependency of socket_info on socket_info_fd:
Instead of maintaining the list of socket_info structures,
and keeping a list of referencing fds (created by dup),
we now maintain the list of fds with pointers to the
corresponding socket_info structures, and count the
references in the socket_info.

This makes the treatment of the lists more obvious,
especially seen in the removing part.

This change is a preparatory step for implementing
fd-passing in socket-wrapper.

Pair-programmed-with: Michael Adam <obnox@samba.org>
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: remove ununsed members from struct swrap.
Michael Adam [Fri, 19 Aug 2016 11:34:50 +0000 (13:34 +0200)]
swrap: remove ununsed members from struct swrap.

These were used in removed swrap_init().

Pair-Programmed-With: Anoop C S <anoopcs@redhat.com>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Add test case to validate oldfd = newfd case in dup2()
Anoop C S [Mon, 22 Aug 2016 14:07:47 +0000 (19:37 +0530)]
swrap: Add test case to validate oldfd = newfd case in dup2()

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Treat the case of fd == newfd correctly in dup2()
Michael Adam [Tue, 16 Aug 2016 08:59:40 +0000 (10:59 +0200)]
swrap: Treat the case of fd == newfd correctly in dup2()

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Delay addition of child socket_info_fd into socket_info list
Anoop C S [Thu, 11 Aug 2016 14:54:54 +0000 (20:24 +0530)]
swrap: Delay addition of child socket_info_fd into socket_info list

In swrap_accept() we used to add new child socket_info_fd[child_fi]
into newly created child socket_info struture[child_si] without
considering the fact that we may return early in case of errors from
subsequent calls to libc_getsockname() and sockaddr_convert_from_un()
during which we free child_fi and child_si and return. So it is better
to delay the addition of child_fi into child_si->fds until child_si
is completely initialized.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Remove redunant check in swrap_socket
Anoop C S [Thu, 11 Aug 2016 14:50:17 +0000 (20:20 +0530)]
swrap: Remove redunant check in swrap_socket

The very same check is also being made inside swrap_remove_stale().
So we can get rid of this early if condition.

Pair-programmed-with: Michael Adam <obnox@samba.org>
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoswrap: Simplify swrap_remove_stale by early return
Anoop C S [Thu, 11 Aug 2016 13:57:17 +0000 (19:27 +0530)]
swrap: Simplify swrap_remove_stale by early return

Pair-programmed-with: Michael Adam <obnox@samba.org>
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
7 years agoBump version to 1.1.7 socket_wrapper-1.1.7
Andreas Schneider [Fri, 20 May 2016 06:58:18 +0000 (08:58 +0200)]
Bump version to 1.1.7

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agotests: Add test_connect_sendto_null_ipv4() test
Andreas Schneider [Tue, 17 May 2016 08:01:38 +0000 (10:01 +0200)]
tests: Add test_connect_sendto_null_ipv4() test

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agotests: Add a udp test case for sendto() after a connect()
Richard Sharpe [Thu, 12 May 2016 00:10:54 +0000 (17:10 -0700)]
tests: Add a udp test case for sendto() after a connect()

Here, we do the same as net ads dns gethostbyname. That is, we
connect on a UDP socket and then send a sendto with a dest address (the
same as the one we connected on.) and then a recvfrom etc.

Signed-of-by: Richard Sharpe <rsharpe@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agoswrap: Fix sendto() with connected sockets
Richard Sharpe [Thu, 12 May 2016 00:03:46 +0000 (17:03 -0700)]
swrap: Fix sendto() with connected sockets

Let the socket wrapper code work with the net ads dns gethostbyname etc
code (lib/addn/dnssock.c) which uses connect on a UDP socket before then
using sendto and recvfrom.

Here, we make sure we don't error out in that case.

Tested by creating a test case for this and then observing that:

1. The test case works when the socket wrapper lib is not being used
   ie, run the test directly after defining some SHELL variables.

2. That the test case fails when run with the un modified socket
   wrapper code.

3. Apply this fix and observe that it runs correctly.

Pair-Programmed-With: Andreas Schneider <asn@samba.org>
Signed-off-by: Richard Sharpe <rsharpe@samba.org>
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agoswrap: Allow to open RAW sockets when loaded
Andreas Schneider [Tue, 26 Apr 2016 16:10:52 +0000 (18:10 +0200)]
swrap: Allow to open RAW sockets when loaded

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agoswrap: Add support for accept4()
Andreas Schneider [Tue, 3 May 2016 12:59:34 +0000 (14:59 +0200)]
swrap: Add support for accept4()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
8 years agoswrap: Add support for running on OpenBSD
Andreas Schneider [Tue, 3 May 2016 12:43:21 +0000 (14:43 +0200)]
swrap: Add support for running on OpenBSD

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
8 years agoBump version to 1.1.6 socket_wrapper-1.1.6
Andreas Schneider [Tue, 15 Mar 2016 10:15:07 +0000 (11:15 +0100)]
Bump version to 1.1.6

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoswrap: Fix buliding on unix systems without AF_NETLINK
Andreas Schneider [Thu, 25 Feb 2016 17:01:49 +0000 (18:01 +0100)]
swrap: Fix buliding on unix systems without AF_NETLINK

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agoswrap: Use calloc() instead of malloc and memset
Andreas Schneider [Tue, 23 Feb 2016 10:22:58 +0000 (11:22 +0100)]
swrap: Use calloc() instead of malloc and memset

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoswrap: Allow to open NETLINK sockets when loaded
Andreas Schneider [Thu, 5 Nov 2015 13:44:26 +0000 (14:44 +0100)]
swrap: Allow to open NETLINK sockets when loaded

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agotests: Add test for ephemeral port binding in listen()
Andreas Schneider [Wed, 4 Nov 2015 10:22:25 +0000 (11:22 +0100)]
tests: Add test for ephemeral port binding in listen()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoswrap: Automatically bind an ephemeral port if needed
Andreas Schneider [Wed, 4 Nov 2015 10:21:23 +0000 (11:21 +0100)]
swrap: Automatically bind an ephemeral port if needed

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agotests: Add valgrind suppression file for dlopen() issues
Andreas Schneider [Wed, 28 Oct 2015 08:52:25 +0000 (09:52 +0100)]
tests: Add valgrind suppression file for dlopen() issues

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoswrap: Add a wrapper for write()
Andreas Schneider [Wed, 28 Oct 2015 09:30:32 +0000 (10:30 +0100)]
swrap: Add a wrapper for write()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agotorture: Use a short torture socket dir
Andreas Schneider [Tue, 27 Oct 2015 09:03:06 +0000 (10:03 +0100)]
torture: Use a short torture socket dir

This makes sure we do not run into a regression.

Thanks to Grigorij Demidov <grigorii.demidov@nic.cz>

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoswrap: Fix recvmsg() with UDP
Andreas Schneider [Tue, 27 Oct 2015 08:26:40 +0000 (09:26 +0100)]
swrap: Fix recvmsg() with UDP

This worked if the unix path was bigger than sizeof(struct sockaddr_in6).
With a short unix socket pathname the buffer was to small to store the
address and convert_un_in() failed.

Thanks to Grigorij Demidov <grigorii.demidov@nic.cz>

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoswrap: Fix compare of signed and unsigned integer expressions
Andreas Schneider [Fri, 16 Oct 2015 14:52:46 +0000 (16:52 +0200)]
swrap: Fix compare of signed and unsigned integer expressions

Make sure the values are compared as the same type. iov_len is size_t on
Linux and int on Solaris.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agotests: Fix compile warning
Andreas Schneider [Fri, 16 Oct 2015 14:50:00 +0000 (16:50 +0200)]
tests: Fix compile warning

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agoBump version to 1.1.5 socket_wrapper-1.1.5
Andreas Schneider [Wed, 14 Oct 2015 09:37:55 +0000 (11:37 +0200)]
Bump version to 1.1.5

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
8 years agoswrap: Simplify cmspace calculation in swrap_sendmsg_copy_cmsg()
Ralph Boehme [Thu, 8 Oct 2015 01:25:53 +0000 (03:25 +0200)]
swrap: Simplify cmspace calculation in swrap_sendmsg_copy_cmsg()

With cmsg->cmsg_len = CMSG_LEN(len) =>

CMSG_ALIGN(cmsg->cmsg_len) =

CMSG_ALIGN(CMSG_LEN(len)) =

CMSG_ALIGN(CMSG_ALIGN(sizeof(struct cmsghdr)) + len) =

CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len) =

CMSG_SPACE(len) =

CMSG_SPACE(CMSG_ALIGN(sizeof(struct cmsghdr)) + len - CMSG_ALIGN(sizeof(struct cmsghdr))) =

CMSG_SPACE(CMSG_LEN(len) - CMSG_ALIGN(sizeof(struct cmsghdr))) =

CMSG_SPACE(cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr)))

:)

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: Add a unit test for wrap_sendmsg_filter_cmsghdr()
Ralph Boehme [Tue, 13 Oct 2015 14:38:26 +0000 (16:38 +0200)]
tests: Add a unit test for wrap_sendmsg_filter_cmsghdr()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
8 years agotests: Add test for TCP_NODELAY setsockopt()
Andreas Schneider [Thu, 8 Oct 2015 09:02:10 +0000 (11:02 +0200)]
tests: Add test for TCP_NODELAY setsockopt()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agotests: Add test for TCP_NODELAY getsockopt()
Andreas Schneider [Mon, 14 Sep 2015 20:07:09 +0000 (22:07 +0200)]
tests: Add test for TCP_NODELAY getsockopt()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoswrap: Add support for TCP_NODELAY in getsockopt()
Andreas Schneider [Mon, 14 Sep 2015 20:06:52 +0000 (22:06 +0200)]
swrap: Add support for TCP_NODELAY in getsockopt()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoswrap: Add support for TCP_NODELAY in setsockopt()
Andreas Schneider [Thu, 8 Oct 2015 08:51:02 +0000 (10:51 +0200)]
swrap: Add support for TCP_NODELAY in setsockopt()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
8 years agoBump version to 1.1.4 socket_wrapper-1.1.4
Andreas Schneider [Mon, 24 Aug 2015 15:53:28 +0000 (17:53 +0200)]
Bump version to 1.1.4

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
8 years agoswrap: Call dlclose() in the destructor
Andreas Schneider [Mon, 17 Aug 2015 10:14:44 +0000 (12:14 +0200)]
swrap: Call dlclose() in the destructor

Signed-off-by: Andreas Schneider <asn@samba.org>
8 years agotests: Rename s_addr to send_addr
Andreas Schneider [Mon, 17 Aug 2015 10:06:30 +0000 (12:06 +0200)]
tests: Rename s_addr to send_addr

The preprocessor on Solaris replaces s_addr with S_un.S_addr.

Signed-off-by: Andreas Schneider <asn@samba.org>
8 years agotests: Fix memset() call in new tests
Andreas Schneider [Wed, 12 Aug 2015 06:48:56 +0000 (08:48 +0200)]
tests: Fix memset() call in new tests

Signed-off-by: Andreas Schneider <asn@samba.org>
8 years agotests: Fix passing pointer of incompatible type
Andreas Schneider [Wed, 12 Aug 2015 06:37:39 +0000 (08:37 +0200)]
tests: Fix passing pointer of incompatible type

Signed-off-by: Andreas Schneider <asn@samba.org>
8 years agoswrap: Fix signed comparsion warnings
Andreas Schneider [Wed, 12 Aug 2015 06:37:07 +0000 (08:37 +0200)]
swrap: Fix signed comparsion warnings

Signed-off-by: Andreas Schneider <asn@samba.org>
8 years agoswrap: Add enviornment variable to specify mtu size
Andreas Schneider [Tue, 11 Aug 2015 10:11:16 +0000 (12:11 +0200)]
swrap: Add enviornment variable to specify mtu size

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agotests: Add tcp sendmsg/recvmsg test
Andreas Schneider [Tue, 11 Aug 2015 09:40:30 +0000 (11:40 +0200)]
tests: Add tcp sendmsg/recvmsg test

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoswrap: Fix TCP support with sendmsg/recvmsg
Andreas Schneider [Tue, 11 Aug 2015 09:39:52 +0000 (11:39 +0200)]
swrap: Fix TCP support with sendmsg/recvmsg

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agotests: Tests for msg_name(len) in sendmsg/revcmsg
Andreas Schneider [Mon, 10 Aug 2015 14:09:16 +0000 (16:09 +0200)]
tests: Tests for msg_name(len) in sendmsg/revcmsg

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agotests: Fix testname of sendmsg tests
Andreas Schneider [Mon, 10 Aug 2015 11:39:09 +0000 (13:39 +0200)]
tests: Fix testname of sendmsg tests

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoswrap: Correctly update the msg_name in recvmsg()
Andreas Schneider [Wed, 5 Aug 2015 13:02:49 +0000 (15:02 +0200)]
swrap: Correctly update the msg_name in recvmsg()

This has been found while debugging nsupdate.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agotests: Migrate to new cmocka API
Andreas Schneider [Thu, 6 Aug 2015 14:08:32 +0000 (16:08 +0200)]
tests: Migrate to new cmocka API

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
8 years agoUpdate TODO
Andreas Schneider [Wed, 15 Jul 2015 13:18:08 +0000 (15:18 +0200)]
Update TODO

9 years agoRegenerate manpage.
Andreas Schneider [Mon, 20 Apr 2015 06:58:00 +0000 (08:58 +0200)]
Regenerate manpage.

Signed-off-by: Andreas Schneider <asn@samba.org>
9 years agodoc: Add a specific date to manpage
Jelmer Vernooij [Sat, 18 Apr 2015 23:58:15 +0000 (23:58 +0000)]
doc: Add a specific date to manpage

This makes builds for socket wrapper reproducible.

Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>