socket_wrapper.git
6 years agoswrap: Rearrange swrap_remove_stale
Anoop C S [Thu, 13 Jul 2017 09:43:07 +0000 (15:13 +0530)]
swrap: Rearrange swrap_remove_stale

In preparation to implement thread safety, re-ordering lines
of code to properly align to lockign calls

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Rearrange swrap_close
Anoop C S [Thu, 13 Jul 2017 09:50:15 +0000 (15:20 +0530)]
swrap: Rearrange swrap_close

In preparation to implement thread safety, re-ordering lines
of code to properly align to locking calls.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Remove swrap_first_free_index
Anoop C S [Tue, 29 Aug 2017 08:59:16 +0000 (14:29 +0530)]
swrap: Remove swrap_first_free_index

swrap_first_free_index is no longer used as the whole logic now
implemented within swrap_create_socket.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use swrap_create_socket within swrap_accept
Anoop C S [Tue, 29 Aug 2017 09:04:58 +0000 (14:34 +0530)]
swrap: Use swrap_create_socket within swrap_accept

Replace the current logic of socket creation within swrap_accept
with more cleaner version using swrap_create_socket.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use swrap_create_socket within swrap_socket
Anoop C S [Tue, 29 Aug 2017 09:04:28 +0000 (14:34 +0530)]
swrap: Use swrap_create_socket within swrap_socket

Replace the current logic of socket creation within swrap_socket
with more cleaner version using swrap_create_socket.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Add new routines to handle socket creation
Anoop C S [Tue, 29 Aug 2017 07:10:35 +0000 (12:40 +0530)]
swrap: Add new routines to handle socket creation

A new function named swrap_create_socket is introduced which
cleanly performs all stuff related to creation of new socket
file descriptors and updation of relevant metadata including
the free-list and reference counter.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Internal reorganization of core socket_info structures
Michael Adam [Sat, 15 Jul 2017 09:10:07 +0000 (14:40 +0530)]
swrap: Internal reorganization of core socket_info structures

The change basically splits socket_info structure into
two structures, namely,
    - socket_info: to store the core information
      corresponding to a socket entry.
    - socket_info_container: wrapping structure to hold
      the socket_info data as well as metadata(currently
      refcount and next_free).

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>
6 years agoswrap: Reorder code inside swrap_socket
Michael Adam [Wed, 2 Aug 2017 11:56:09 +0000 (13:56 +0200)]
swrap: Reorder code inside swrap_socket

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use swrap_get_socket_info inside socket_wrapper_first_free_index
Michael Adam [Tue, 18 Jul 2017 10:53:03 +0000 (12:53 +0200)]
swrap: Use swrap_get_socket_info inside socket_wrapper_first_free_index

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: set errno to ENFILE if there is no more free socket_info
Michael Adam [Tue, 18 Jul 2017 10:50:15 +0000 (12:50 +0200)]
swrap: set errno to ENFILE if there is no more free socket_info

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: New helper functions to treat next_free
Michael Adam [Wed, 12 Jul 2017 23:01:57 +0000 (01:01 +0200)]
swrap: New helper functions to treat next_free

- swrap_get_next_free
- swrap_set_next_free

to avoid accessing socket_info.next_free directly

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use helper functions to manage refcount
Anoop C S [Thu, 1 Mar 2018 05:09:20 +0000 (10:39 +0530)]
swrap: Use helper functions to manage refcount

- swrap_get_refcount
- swrap_alter_refcount

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use helper function swrap_get_socket_info
Anoop C S [Thu, 1 Mar 2018 05:04:54 +0000 (10:34 +0530)]
swrap: Use helper function swrap_get_socket_info

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Make early-libc-out more obvious by removing else
Michael Adam [Thu, 13 Jul 2017 00:40:11 +0000 (02:40 +0200)]
swrap: Make early-libc-out more obvious by removing else

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agotests: Increase wait time for setup and teardown to 5ms
Andreas Schneider [Wed, 2 May 2018 10:23:50 +0000 (12:23 +0200)]
tests: Increase wait time for setup and teardown to 5ms

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agotests: Remove extra test by moving getsockname() to another
Anoop C S [Fri, 23 Mar 2018 11:42:49 +0000 (17:12 +0530)]
tests: Remove extra test by moving getsockname() to another

test_echo_tcp_socket currently tests socket() and getsockname() network
calls. The test name was misleading as it does not require echo server
to be setup. Moreover it failed to create socket_wrapper directory which
is the pre-requisite for testing with libsocket_wrapper.

Therefore it is better to integrate getsockname() test into existing
test_tcp_listen test and remove useless test_echo_tcp_socket

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
6 years agocmake: Fix configure check for fall-through attribute
Andreas Schneider [Wed, 28 Feb 2018 06:36:58 +0000 (07:36 +0100)]
cmake: Fix configure check for fall-through attribute

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
6 years agocmake: Fix checks for attributes
Andreas Schneider [Thu, 22 Feb 2018 08:37:40 +0000 (09:37 +0100)]
cmake: Fix checks for attributes

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
6 years agoswrap: Avoid double semicolons in the code
Andreas Schneider [Tue, 20 Feb 2018 16:52:00 +0000 (17:52 +0100)]
swrap: Avoid double semicolons in the code

Compilers that don't support fallthrough will end up with an empty
FALL_THROUGH define and just see a semicolon. The probably will warn
that there are double semicolons in the code.

Signed-off-by: Andreas Schneider <asn@samba.org>
6 years agoBump version to 1.1.9 socket_wrapper-1.1.9
Andreas Schneider [Mon, 4 Dec 2017 09:19:38 +0000 (10:19 +0100)]
Bump version to 1.1.9

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agotests: Add a thread deadlock reproducer
Andreas Schneider [Tue, 28 Nov 2017 14:41:05 +0000 (15:41 +0100)]
tests: Add a thread deadlock reproducer

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Avoid symbol binding deadlocks during fork
Andreas Schneider [Mon, 27 Nov 2017 10:00:54 +0000 (11:00 +0100)]
swrap: Avoid symbol binding deadlocks during fork

If there is a signal handler defined, e.g. for SIGCHILD and this signal
handler is called during pthread_atfork() has just locked all mutexes
and we want to check if a symbol is bound, we end up in a deadlock.

(gdb) bt
 0  __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
 1  0x00007fe48837aef5 in __GI___pthread_mutex_lock (mutex=0x7fe4889a71c0 <libc_symbol_binding_mutex>) at ../nptl/pthread_mutex_lock.c:80
 2  0x00007fe48879b2f1 in libc_write (fd=14, buf=0x7ffdad6436e8, count=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:1070
 3  0x00007fe4887a21cb in swrap_write (s=14, buf=0x7ffdad6436e8, len=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:5137
 4  0x00007fe4887a2359 in write (s=14, buf=0x7ffdad6436e8, len=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:5171
 5  0x00007fe48713e5f2 in tevent_common_wakeup_fd (fd=14) at ../lib/tevent/tevent.c:959
 6  0x00007fe48713e61f in tevent_common_wakeup (ev=ev@entry=0x55d04922e280) at ../lib/tevent/tevent.c:975
 7  0x00007fe487141d38 in tevent_common_signal_handler (signum=<optimized out>) at ../lib/tevent/tevent_signal.c:109
 8  <signal handler called>
 9  0x00007fe4844de081 in __libc_fork () at ../sysdeps/nptl/fork.c:135
 10 0x000055d047e8ddb3 in smbd_accept_connection (ev=0x55d04922e280, fde=<optimized out>, flags=<optimized out>, private_data=<optimized out>)
    at ../source3/smbd/server.c:992

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Bind all symbols during prepare
Andreas Schneider [Fri, 1 Dec 2017 15:05:07 +0000 (16:05 +0100)]
swrap: Bind all symbols during prepare

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agotests: Fix sa_socklen for sockaddr_in
Andreas Schneider [Tue, 28 Nov 2017 09:15:07 +0000 (10:15 +0100)]
tests: Fix sa_socklen for sockaddr_in

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Whitespace fixes
Andreas Schneider [Tue, 14 Nov 2017 08:03:24 +0000 (09:03 +0100)]
swrap: Whitespace fixes

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
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>
8 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>