socket_wrapper.git
10 months agoBump version to 1.4.2 master socket_wrapper-1.4.2
Andreas Schneider [Thu, 29 Jun 2023 11:37:19 +0000 (13:37 +0200)]
Bump version to 1.4.2

Reviewed-by: Stefan Metzmacher <metze@samba.org>
10 months agogitlab-ci: Add Ubuntu 32bit build
Andreas Schneider [Thu, 22 Jun 2023 16:30:52 +0000 (18:30 +0200)]
gitlab-ci: Add Ubuntu 32bit build

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
10 months agoswrap: Provide a fcntl64()
Andreas Schneider [Fri, 23 Jun 2023 09:10:45 +0000 (11:10 +0200)]
swrap: Provide a fcntl64()

We want to run with and without large file support. It depends on if the
application is build with large file support so it will either choose fcntl or
fcntl64.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
10 months agoswrap: Fix fnctl64()
Andreas Schneider [Thu, 22 Jun 2023 16:32:30 +0000 (18:32 +0200)]
swrap: Fix fnctl64()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
10 months agotests(cmake): Fix handling of LFS support
Andreas Schneider [Tue, 27 Jun 2023 10:02:30 +0000 (12:02 +0200)]
tests(cmake): Fix handling of LFS support

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
10 months agotests: Implement test_fcntl_lock correctly
Andreas Schneider [Fri, 23 Jun 2023 11:50:03 +0000 (13:50 +0200)]
tests: Implement test_fcntl_lock correctly

This does:

openat(AT_FDCWD, "/tmp/test_socket_wrapper_Win6aA/file", O_RDWR|O_CREAT, 0600) = 3
fcntl(3, F_OFD_SETLK, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=0, l_len=1}) = 0
write(3, "fd=3\n", 5)                   = 5
fcntl(3, F_OFD_SETLK, {l_type=F_UNLCK, l_whence=SEEK_SET, l_start=0, l_len=1}) = 0
unlink("/tmp/test_socket_wrapper_Win6aA/file") = 0                                                                                                                                   close(3)
close(3)                                = 0

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
10 months agoswrap: Make sure we do not redirect (f)open(at)() or fcntl()
Andreas Schneider [Tue, 27 Jun 2023 10:18:53 +0000 (12:18 +0200)]
swrap: Make sure we do not redirect (f)open(at)() or fcntl()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
10 months agotests: Do not build test_swrap_unit with LFS support
Andreas Schneider [Tue, 27 Jun 2023 10:01:46 +0000 (12:01 +0200)]
tests: Do not build test_swrap_unit with LFS support

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
10 months agoBump version to 1.4.1
Andreas Schneider [Mon, 8 May 2023 10:59:33 +0000 (12:59 +0200)]
Bump version to 1.4.1

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
10 months agoswrap: Add support for openat64()
Andreas Schneider [Mon, 19 Jun 2023 14:23:50 +0000 (16:23 +0200)]
swrap: Add support for openat64()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
10 months agotests: Use F_(OFD)SETLK(64) in test_fcntl_lock
Andreas Schneider [Tue, 9 May 2023 07:19:07 +0000 (09:19 +0200)]
tests: Use F_(OFD)SETLK(64) in test_fcntl_lock

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
10 months agocmake: Define large file support for tests
Andreas Schneider [Tue, 9 May 2023 07:09:01 +0000 (09:09 +0200)]
cmake: Define large file support for tests

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
11 months agogitlab-ci: Add a 32bit build
Andreas Schneider [Fri, 5 May 2023 05:14:26 +0000 (07:14 +0200)]
gitlab-ci: Add a 32bit build

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

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
11 months agoAdd fix for incorrect mapping of fcntl64() -> fcntl(), causing locking failures
Andrew Bartlett [Fri, 5 May 2023 01:34:00 +0000 (13:34 +1200)]
Add fix for incorrect mapping of fcntl64() -> fcntl(), causing locking failures

We need to call fcntl64() if possible for 32-bit hosts

This is a strange case of socket_wrapper breaking normal file operation.

Newer glibc has introduced fcntl64 and symbol renaming but
the end function call was not caught by the automatic rename.

This means socket_wrapper would call fcntl(), not fcntl64 in libc
and this would do a "struct flock" -> "struct flock64" translation on the
supplied argument, despite this being already a flock64 from
the caller.

This in turn changed the lock offset values (eg to 0, 0).

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
11 months agoAdd test for F_SETLK as this is needs to be 64-bit aware on 32-bit userspace
Andrew Bartlett [Fri, 5 May 2023 01:15:51 +0000 (13:15 +1200)]
Add test for F_SETLK as this is needs to be 64-bit aware on 32-bit userspace

If this is not correctly routed to fcntl64 (where that exists) then an
incorrect thunking could be applied breaking the functionality.

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
12 months agotests: New test with poll
Jakub Jelen [Thu, 2 Mar 2023 09:46:53 +0000 (10:46 +0100)]
tests: New test with poll

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
12 months agotests: Try larger writes and reads
Jakub Jelen [Thu, 23 Feb 2023 13:55:02 +0000 (14:55 +0100)]
tests: Try larger writes and reads

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
14 months agocmake: Fix cmocka >= 1.1.6 find_package() in CONFIG mode
Andreas Schneider [Fri, 17 Feb 2023 16:51:27 +0000 (17:51 +0100)]
cmake: Fix cmocka >= 1.1.6 find_package() in CONFIG mode

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
15 months agoBump version to 1.4.0 socket_wrapper-1.4.0
Andreas Schneider [Wed, 18 Jan 2023 07:54:41 +0000 (08:54 +0100)]
Bump version to 1.4.0

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
15 months agotests: test uid_wrapper_syscall_{valid,va} interaction using swrap_fake_uid_wrapper.so
Stefan Metzmacher [Mon, 16 Jan 2023 20:57:35 +0000 (21:57 +0100)]
tests: test uid_wrapper_syscall_{valid,va} interaction using swrap_fake_uid_wrapper.so

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agosrc/socket_wrapper.c: make use of uid_wrapper_syscall_{valid,va}()
Stefan Metzmacher [Mon, 16 Jan 2023 18:51:05 +0000 (19:51 +0100)]
src/socket_wrapper.c: make use of uid_wrapper_syscall_{valid,va}()

If we find uid_wrapper_syscall_{valid,va}() symbols in the already
loaded libraries, we'll try to hand over syscall() invocations to
uid_wrapper.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agosrc/socket_wrapper.c: export socket_wrapper_syscall_{valid,va}()
Stefan Metzmacher [Mon, 16 Jan 2023 18:48:57 +0000 (19:48 +0100)]
src/socket_wrapper.c: export socket_wrapper_syscall_{valid,va}()

We need to hook into syscall() from socket_wrapper as well as
from uid_wrapper() (and maybe others in future).
But the assumption is that only one wrapper will take care
of a single syscall number.

So we provide socket_wrapper_syscall_valid() in order to allow
external consumers (e.g. uid_wrapper.so) to check if
socket_wrapper wants to handle a specified syscall number.

And we provide socket_wrapper_syscall_va() in order to allow
calling into swrap_syscall().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agotests: let test_echo_tcp_sendmmsg_recvmmsg check raw SYS_close, SYS_recvmmsg and...
Stefan Metzmacher [Mon, 16 Jan 2023 19:14:26 +0000 (20:14 +0100)]
tests: let test_echo_tcp_sendmmsg_recvmmsg check raw SYS_close, SYS_recvmmsg and SYS_sendmmsg

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agosrc/socket_wrapper.c: handle raw SYS_close, SYS_recvmmsg and SYS_sendmmsg syscall...
Stefan Metzmacher [Mon, 16 Jan 2023 18:46:13 +0000 (19:46 +0100)]
src/socket_wrapper.c: handle raw SYS_close, SYS_recvmmsg and SYS_sendmmsg syscall() invocations

This fixes a problem hit by 'nsupdate -g' and bind9 (dnsutils). If bind is built
against libuv <= 1.44.2 it will not use sendmmsg/recvmmsg functions from libc
but use the corresponding syscalls directly. Newer version of libuv removed
the syscall wrappers and use sendmmsg/recvmmsg from libc.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agotests: add test_echo_tcp_sendmmsg_recvmmsg
Stefan Metzmacher [Mon, 16 Jan 2023 18:27:12 +0000 (19:27 +0100)]
tests: add test_echo_tcp_sendmmsg_recvmmsg

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agosrc/socket_wrapper.c: implement recvmmsg and sendmmsg
Stefan Metzmacher [Mon, 16 Jan 2023 16:00:48 +0000 (17:00 +0100)]
src/socket_wrapper.c: implement recvmmsg and sendmmsg

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agosrc/socket_wrapper.c: add some tracing for connected dgram sockets
Stefan Metzmacher [Mon, 16 Jan 2023 15:58:04 +0000 (16:58 +0100)]
src/socket_wrapper.c: add some tracing for connected dgram sockets

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agosrc/socket_wrapper.c: don't leak unlink() errno (most likely ENOENT) in swrap_bind()
Stefan Metzmacher [Sun, 6 Nov 2022 15:07:21 +0000 (16:07 +0100)]
src/socket_wrapper.c: don't leak unlink() errno (most likely ENOENT) in swrap_bind()

This fixes a problem hit by 'nsupdate -g' from the
bind9-dnsutils 1:9.18.1-1ubuntu1.2 package.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
15 months agosrc/socket_wrapper.c: pretty print ip addresses in tracing output.
Stefan Metzmacher [Mon, 16 Jan 2023 15:50:32 +0000 (16:50 +0100)]
src/socket_wrapper.c: pretty print ip addresses in tracing output.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
17 months agoBump version to 1.3.5
Stefan Metzmacher [Wed, 23 Nov 2022 11:12:12 +0000 (12:12 +0100)]
Bump version to 1.3.5

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
17 months agosocket_wrapper: inject O_LARGEFILE to open[64|at]() if needed
Stefan Metzmacher [Wed, 23 Nov 2022 10:46:45 +0000 (11:46 +0100)]
socket_wrapper: inject O_LARGEFILE to open[64|at]() if needed

On 32bit systems this is normally done by glibc if _FILE_OFFSET_BITS is 64,
but with socket wrapper we don't want to define _FILE_OFFSET_BITS=64,
as we need to overload open64 explicitly. But we need to inject
O_LARGEFILE for being transparent to the application.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
17 months agoAvoid dclose(RTLD_NEXT)
Samuel Thibault [Thu, 10 Nov 2022 18:36:29 +0000 (18:36 +0000)]
Avoid dclose(RTLD_NEXT)

In case the libc was not found and RTLD_NEXT is used instead, we should not
dlclose it, otherwise mayhem happens.

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

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
17 months agopkgconfig: Fix path to libsocket_wrapper.so
Andreas Schneider [Mon, 12 Sep 2022 09:25:17 +0000 (11:25 +0200)]
pkgconfig: Fix path to libsocket_wrapper.so

Reviewed-by: Stefan Metzmacher <metze@samba.org>
19 months agoFix -Wcast-qual warnings
Alex Richardson [Fri, 1 Oct 2021 09:00:32 +0000 (10:00 +0100)]
Fix -Wcast-qual warnings

Without this change I get the following -Werror build failure when building
samba on macOS:
```
../../third_party/socket_wrapper/socket_wrapper.c:5420:15: error: cast from 'const struct cmsghdr *' to 'unsigned char *' drops const qualifier [-Werror,-Wcast-qual]
        __fds_in.p = CMSG_DATA(cmsg);
                     ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/socket.h:631:51: note: expanded from macro 'CMSG_DATA'
#define CMSG_DATA(cmsg)         ((unsigned char *)(cmsg) + \
                                                  ^
```

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
21 months agoBump version to 1.3.4 socket_wrapper-1.3.4
Andreas Schneider [Thu, 21 Jul 2022 12:48:02 +0000 (14:48 +0200)]
Bump version to 1.3.4

Reviewed-by: Stefan Metzmacher <metze@samba.org>
21 months agoswrap: Fix a TOCTOU issue in swrap_auto_bind()
Andreas Schneider [Thu, 21 Jul 2022 05:22:08 +0000 (07:22 +0200)]
swrap: Fix a TOCTOU issue in swrap_auto_bind()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
21 months agogitlab-ci: Introduce stages
Andreas Schneider [Thu, 3 Mar 2022 08:24:09 +0000 (09:24 +0100)]
gitlab-ci: Introduce stages

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
21 months agogitlab-ci: Fix formatting
Andreas Schneider [Thu, 3 Mar 2022 08:18:11 +0000 (09:18 +0100)]
gitlab-ci: Fix formatting

Complaints from yamllint.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
21 months agoAdd editorconfig
Andreas Schneider [Thu, 3 Mar 2022 08:22:01 +0000 (09:22 +0100)]
Add editorconfig

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
21 months agoswrap: Remove _close symbol alias as this breaks 'make test' on FreeBSD
Andreas Schneider [Thu, 21 Jul 2022 06:59:32 +0000 (08:59 +0200)]
swrap: Remove _close symbol alias as this breaks 'make test' on FreeBSD

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
21 months agotests: Fix compiler warning that arrays might not be initialized
Andreas Schneider [Thu, 21 Jul 2022 05:33:11 +0000 (07:33 +0200)]
tests: Fix compiler warning that arrays might not be initialized

tests/test_echo_tcp_sendmsg_recvmsg_fd.c: In function 'test_tcp_sendmsg_recvmsg_fd_mixed':
tests/test_echo_tcp_sendmsg_recvmsg_fd.c:477:9: error: '<unknown>' may be used uninitialized [-Werror=maybe-uninitialized]
  477 |         test_tcp_sendmsg_recvmsg_fd_array(fd_array, num_fds);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests/test_echo_tcp_sendmsg_recvmsg_fd.c:103:13: note: by argument 1 of type 'const int *' to 'test_tcp_sendmsg_recvmsg_fd_array' declared here
  103 | static void test_tcp_sendmsg_recvmsg_fd_array(const int *fds, size_t num_fds)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
21 months agocmake: Disable -Werror=strict-overflow till glibc is fixed
Andreas Schneider [Thu, 21 Jul 2022 05:50:27 +0000 (07:50 +0200)]
cmake: Disable -Werror=strict-overflow till glibc is fixed

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agoswrap: Don't pass NULL pointers to memcpy()
Joseph Sutton [Thu, 29 Jul 2021 23:12:12 +0000 (11:12 +1200)]
swrap: Don't pass NULL pointers to memcpy()

Doing so is undefined behaviour.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoBump version to 1.3.3 socket_wrapper-1.3.3
Andreas Schneider [Mon, 15 Mar 2021 07:24:57 +0000 (08:24 +0100)]
Bump version to 1.3.3

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agocmake: Define a library version for the noop lib
Andreas Schneider [Mon, 15 Mar 2021 07:22:33 +0000 (08:22 +0100)]
cmake: Define a library version for the noop lib

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agocmake: Export cmake config for socket_wrapper_noop
Andreas Schneider [Mon, 15 Mar 2021 07:18:15 +0000 (08:18 +0100)]
cmake: Export cmake config for socket_wrapper_noop

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agocmake: Set public include dir for socket_wrapper_noop target
Andreas Schneider [Mon, 15 Mar 2021 07:17:34 +0000 (08:17 +0100)]
cmake: Set public include dir for socket_wrapper_noop target

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agocmake: Set PRIVATE for linking libraries
Andreas Schneider [Mon, 15 Mar 2021 07:09:29 +0000 (08:09 +0100)]
cmake: Set PRIVATE for linking libraries

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agoswrap: wrap __close_nocancel() if available
Stefan Metzmacher [Wed, 17 Feb 2021 09:58:29 +0000 (10:58 +0100)]
swrap: wrap __close_nocancel() if available

While it's no possible to inject swrap__close_nocancel() into
libc.so.6 directly, because it's no weak symbol, it seems to
be possible to inject it to other glibc libraries like
libpthread.so.0, which is better than nothing.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: export a public socket_wrapper_indicate_no_inet_fd() helper function
Stefan Metzmacher [Wed, 17 Feb 2021 11:29:27 +0000 (12:29 +0100)]
swrap: export a public socket_wrapper_indicate_no_inet_fd() helper function

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: introduce a socket_wrapper_noop.so and socket_wrapper.h to provide noop stubs
Stefan Metzmacher [Wed, 24 Feb 2021 11:45:26 +0000 (12:45 +0100)]
swrap: introduce a socket_wrapper_noop.so and socket_wrapper.h to provide noop stubs

Applications with the need to call socket_wrapper_enabled() should link
against -lsocket_wrapper_noop in order to resolve the symbol at
link time.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: split out swrap_remove_wrapper() to handle swrap_close() and swrap_remove_stale()
Stefan Metzmacher [Wed, 17 Feb 2021 11:14:06 +0000 (12:14 +0100)]
swrap: split out swrap_remove_wrapper() to handle swrap_close() and swrap_remove_stale()

Except of closing the fd, both should do the same, even indicating a TCP
close in the pcap file.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: remember the libc_close() errno in swrap_close()
Stefan Metzmacher [Wed, 17 Feb 2021 11:14:06 +0000 (12:14 +0100)]
swrap: remember the libc_close() errno in swrap_close()

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: call libc_write() directly for internal fds
Stefan Metzmacher [Wed, 17 Feb 2021 10:00:53 +0000 (11:00 +0100)]
swrap: call libc_write() directly for internal fds

Otherwise we may deadlock with a backtrace like this:

swrap_accept():
 ...
 SWRAP_LOCK_SI(si);
 swrap_pcap_dump_packet() ->
   write() ->
     swrap_write() ->
       SWRAP_LOCK_SI(si) -> abort()

This can happen if libc_open() called from swrap_pcap_get_fd()
return a stale fd. This may happen if glibc calls socket()
and closes it with __close_nocancel() instead of close().

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: warn about unreachable addresses
Stefan Metzmacher [Wed, 17 Feb 2021 10:41:38 +0000 (11:41 +0100)]
swrap: warn about unreachable addresses

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoBump version to 1.3.2 socket_wrapper-1.3.2
Andreas Schneider [Wed, 10 Feb 2021 09:49:30 +0000 (10:49 +0100)]
Bump version to 1.3.2

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agoswrap: don't read the callers msg_control buffer in swrap_recvmsg_before_unix()
Stefan Metzmacher [Wed, 10 Feb 2021 09:45:11 +0000 (10:45 +0100)]
swrap: don't read the callers msg_control buffer in swrap_recvmsg_before_unix()

For recvmsg() msg_control is a write only buffer, that is filled by the
kernel, but the kernel won't read from that buffer. So we shouldn't
read from (copy) it either.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: don't touch msg_tmp in swrap_recvmsg_after_unix() on error
Stefan Metzmacher [Tue, 9 Feb 2021 15:09:59 +0000 (16:09 +0100)]
swrap: don't touch msg_tmp in swrap_recvmsg_after_unix() on error

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: fix possible memory leak between swrap_recvmsg_{before,after}_unix()
Stefan Metzmacher [Tue, 9 Feb 2021 14:57:22 +0000 (15:57 +0100)]
swrap: fix possible memory leak between swrap_recvmsg_{before,after}_unix()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoBump version to 1.3.1 socket_wrapper-1.3.1
Andreas Schneider [Fri, 5 Feb 2021 14:55:49 +0000 (15:55 +0100)]
Bump version to 1.3.1

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agotest_echo_tcp_sendmsg_recvmsg_fd: add test_tcp_sendmsg_recvmsg_fd_mixed() tests
Stefan Metzmacher [Fri, 5 Feb 2021 15:25:43 +0000 (16:25 +0100)]
test_echo_tcp_sendmsg_recvmsg_fd: add test_tcp_sendmsg_recvmsg_fd_mixed() tests

Here we mix sockets and other valid file descriptors.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agotest_echo_tcp_sendmsg_recvmsg_fd: add test_tcp_sendmsg_recvmsg_fd_different() tests
Stefan Metzmacher [Fri, 5 Feb 2021 13:40:45 +0000 (14:40 +0100)]
test_echo_tcp_sendmsg_recvmsg_fd: add test_tcp_sendmsg_recvmsg_fd_different() tests

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agotest_echo_tcp_sendmsg_recvmsg_fd: also test passing the same socket up to 6 times
Stefan Metzmacher [Fri, 5 Feb 2021 13:20:16 +0000 (14:20 +0100)]
test_echo_tcp_sendmsg_recvmsg_fd: also test passing the same socket up to 6 times

Note SWRAP_MAX_PASSED_FDS is currently 6.

This test demonstrates that even 64-bit systems required commit:
"swrap: fix fd-passing without 4 padding bytes"

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agotest_echo_tcp_sendmsg_recvmsg_fd: split out test_tcp_sendmsg_recvmsg_fd_same()
Stefan Metzmacher [Fri, 5 Feb 2021 13:10:03 +0000 (14:10 +0100)]
test_echo_tcp_sendmsg_recvmsg_fd: split out test_tcp_sendmsg_recvmsg_fd_same()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agotest_echo_tcp_sendmsg_recvmsg_fd: split out test_tcp_sendmsg_recvmsg_fd_array()
Stefan Metzmacher [Thu, 4 Feb 2021 16:04:30 +0000 (17:04 +0100)]
test_echo_tcp_sendmsg_recvmsg_fd: split out test_tcp_sendmsg_recvmsg_fd_array()

This will allow us to test more combinations in order to
get better coverage. For now we just test a single fd.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agotests/echo_srv: allow more than once tcp connection at a time
Stefan Metzmacher [Fri, 5 Feb 2021 14:41:27 +0000 (15:41 +0100)]
tests/echo_srv: allow more than once tcp connection at a time

We should not wait for the last connection to disconnect,
there would not be any reason to use fork at all.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: fix fd-passing without 4 padding bytes
Stefan Metzmacher [Thu, 4 Feb 2021 15:20:13 +0000 (16:20 +0100)]
swrap: fix fd-passing without 4 padding bytes

We noticed the problem on 32 bit platforms and sending a single
application fd, the hidden pipe-fd doesn't fit into the padding
bytes. This can also happen on 64 bit platforms and an even number
of application fds.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: fix invalid read in swrap_sendmsg_unix_scm_rights()
Stefan Metzmacher [Fri, 5 Feb 2021 18:36:26 +0000 (19:36 +0100)]
swrap: fix invalid read in swrap_sendmsg_unix_scm_rights()

Here the fds_out array is larger than the fds_in array, so we can
only copy the fds_in array using size_fds_in, leaving the last slot
of fds_out untouched, which is filled by fds_out[num_fds_in] = pipefd[0]
later.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: fix copy on write leak of ~38M for every fork.
Stefan Metzmacher [Thu, 4 Feb 2021 04:02:32 +0000 (05:02 +0100)]
swrap: fix copy on write leak of ~38M for every fork.

commit 0f8e90dd7e59c473be615dee08d445dca98fdab9
(src/socket_wrapper.c: fix mutex fork handling)
let us touch the whole sockets array on every fork,
because each element in the array has it's own mutex.

max_sockets=65535 * sizeof(struct socket_info_container)=592 = 38796720

This was designed for the use of robust shared mutexes
when moving the sockets array into a shared memory file.

Until we really move to shared memory, we can use a single
global mutex in order to avoid the copy on write leaking.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: abort on mutex errors
Stefan Metzmacher [Fri, 5 Feb 2021 10:50:17 +0000 (11:50 +0100)]
swrap: abort on mutex errors

There's no way to continue in a reliable way...

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: fallback to libc_getpeername() when we get an empty sun_path from accept()
Stefan Metzmacher [Fri, 5 Feb 2021 12:13:44 +0000 (13:13 +0100)]
swrap: fallback to libc_getpeername() when we get an empty sun_path from accept()

This hopefully hides the strange behaviour of FreeBSD (at least 12.1)
for already disconnected AF_UNIX sockets.

The race is triggered when the following detects the usage of 'getpeername':

truss -o ./truss.out -f -H -a -e -D -s 160 ctest -V -R test_thread_echo_tcp_connect;
grep getpeername truss.out

In a simplified log the following is happening:

 ECHO_SRV(parent): socket(PF_LOCAL,SOCK_STREAM,0) = 4 (0x4)
 ECHO_SRV(parent): unlink("/tmp/w_E37bkf/T0A0007") ERR#2 'No such file or directory'
 ECHO_SRV(parent): bind(4,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" },106) = 0 (0x0)
 ECHO_SRV(parent): listen(4,16)  = 0 (0x0)
 ...
 ECHO_SRV(parent): write(2,"SWRAP_ERROR[echo_srv (9792)] - swrap_accept: before accept(sa_socklen=106)\n",75) = 75 (0x4b)
 ECHO_SRV(parent): accept4(0x4,0x7ffffffde158,0x7ffffffde150,0x0) = 5 (0x5)
 ECHO_SRV(parent): write(2,"SWRAP_ERROR[echo_srv (9792)] - swrap_accept: after accept(sa_socklen=106, family=1)\n",84) = 84 (0x54)
 ECHO_SRV(parent): getsockname(5,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" },0x7ffffffde0c0) = 0 (0x0)

 ECHO_SRV(parent): swrap_accept() returned a valid connection and a per connection child (pid=9793) handles it

 TEST_THREAD:      socket(PF_LOCAL,SOCK_STREAM,0) = 7 (0x7)
 TEST_THREAD:      bind(7,{ AF_UNIX "/tmp/w_E37bkf/T014D4F" },106) = 0 (0x0)
 TEST_THREAD:      connect(7,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" },106) = 0 (0x0)
 TEST_THREAD:      close(7)  = 0 (0x0)

 ECHO_SRV(parent): wait4(-1,0x0,0x0,0x0)  = 9793 (0x2641)
 ECHO_SRV(parent): close(5)  = 0 (0x0)
 ECHO_SRV(parent): write(2,"SWRAP_ERROR[echo_srv (9792)] - swrap_accept: before accept(sa_socklen=106)\n",75) = 75 (0x4b)
 ECHO_SRV(parent): accept4(0x4,0x7ffffffde158,0x7ffffffde150,0x0) = 5 (0x5)

 TEST_THREAD:      unlink("/tmp/w_E37bkf/T014D4F") = 0 (0x0)

 ECHO_SRV(parent): write(2,"SWRAP_ERROR[echo_srv (9792)] - swrap_accept: after accept(sa_socklen=16, family=1)\n",83) = 83 (0x53)
 ECHO_SRV(parent): getpeername(5,0x7ffffffde158,0x7ffffffde150) ERR#57 'Socket is not connected'
 ECHO_SRV(parent): getsockname(5,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" },0x7ffffffde0c0) = 0 (0x0)
 ECHO_SRV(parent): getpeername(5,0x7ffffffde158,0x7ffffffde150) ERR#57 'Socket is not connected'

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: make swrap_accept() more resilient against races related to already disconnect...
Stefan Metzmacher [Fri, 5 Feb 2021 11:13:12 +0000 (12:13 +0100)]
swrap: make swrap_accept() more resilient against races related to already disconnected sockets

Callers of accept() expect to get ECONNABORTED instead of a disconnected
socket.

Even on Linux we have a potential race calling libc_getsockname()
after accept(), so we map ENOTCONN to ECONNABORTED.

We should do all syscalls in order to have peer and sockname, before
doing in memory things like calling sockaddr_convert_from_un().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: add better logging to convert_un_in()
Stefan Metzmacher [Fri, 5 Feb 2021 12:13:07 +0000 (13:13 +0100)]
swrap: add better logging to convert_un_in()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agotests/echo_srv: make the main server logic resilient to ECONNABORTED from accept()
Stefan Metzmacher [Fri, 5 Feb 2021 11:22:47 +0000 (12:22 +0100)]
tests/echo_srv: make the main server logic resilient to ECONNABORTED from accept()

That should fix a race where the connect() directly followed by close()
in test_thread_echo_tcp_connect will cause the echo_srv to terminate
early, which results in connect() returning ECONNREFUSED in for other
threads.

This mainly happens on FreeBSD, but it can also happen on Linux.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoBump version to 1.3.0 socket_wrapper-1.3.0
Andreas Schneider [Tue, 2 Feb 2021 09:33:37 +0000 (10:33 +0100)]
Bump version to 1.3.0

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agodoc: Add website to manpage
Andreas Schneider [Tue, 2 Feb 2021 09:30:04 +0000 (10:30 +0100)]
doc: Add website to manpage

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agodoc: Define doctype for manpage
Andreas Schneider [Tue, 2 Feb 2021 09:28:59 +0000 (10:28 +0100)]
doc: Define doctype for manpage

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agodoc: Rename socket_wrapper.1.txt to socket_wrapper.1.adoc
Andreas Schneider [Tue, 2 Feb 2021 09:26:07 +0000 (10:26 +0100)]
doc: Rename socket_wrapper.1.txt to socket_wrapper.1.adoc

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agoswrap: add basic support for fd-passing via SCM_RIGHTS
Stefan Metzmacher [Mon, 29 Jun 2020 12:10:54 +0000 (14:10 +0200)]
swrap: add basic support for fd-passing via SCM_RIGHTS

We only allow passing up to 6 fds in a single sendmsg call,
in order to keep the logic simple.

That's more than enough for Samba's use of fd-passing,
there we only pass a single fd and the fd will be
closed in the sender on success. It means it's ok
to keep the socket_info.io.pck_{snd,rcv} fields per process
and the PCAP generation will still work as expected.

If these constraints turn out to be a problem for other applications,
we need to change to a more complex design and move the socket_info array
into a shared memory file and use shared robust mutexes.

But for now we just want to support multi-channel testing in Samba.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agotests: Add test for socket_wrapper fd-passing support
Anoop C S [Thu, 23 Jul 2020 10:29:29 +0000 (15:59 +0530)]
tests: Add test for socket_wrapper fd-passing support

Signed-off-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: always check new fd's against socket_fds_max and use libc_close() for cleanup
Stefan Metzmacher [Tue, 30 Jun 2020 15:53:20 +0000 (17:53 +0200)]
swrap: always check new fd's against socket_fds_max and use libc_close() for cleanup

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: add const to swrap_add_socket_info()
Stefan Metzmacher [Tue, 30 Jun 2020 15:51:29 +0000 (17:51 +0200)]
swrap: add const to swrap_add_socket_info()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: let swrap_sendmsg_before_unix() create a copy of msg_tmp.msg_control
Stefan Metzmacher [Mon, 29 Jun 2020 07:39:22 +0000 (09:39 +0200)]
swrap: let swrap_sendmsg_before_unix() create a copy of msg_tmp.msg_control

With fd-passing we'll have to modify the content of it.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: add stubs for swrap_{sendmsg,recvmsg}_{before,after}_unix()
Stefan Metzmacher [Mon, 29 Jun 2020 07:27:24 +0000 (09:27 +0200)]
swrap: add stubs for swrap_{sendmsg,recvmsg}_{before,after}_unix()

In order to implement fd-passing of socket_wrapper simulated sockets
we need to modify the msghdr structures from the callers.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: filter out SCM_{RIGHTS,CREDENTIALS} on inet socket
Stefan Metzmacher [Mon, 29 Jun 2020 11:07:26 +0000 (13:07 +0200)]
swrap: filter out SCM_{RIGHTS,CREDENTIALS} on inet socket

These are only valid on unix domain sockets and ignored otherwise (at
least on Linux).

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: add error checking/cleanup to swrap_sendmsg_filter_cmsghdr()
Stefan Metzmacher [Mon, 29 Jun 2020 08:12:07 +0000 (10:12 +0200)]
swrap: add error checking/cleanup to swrap_sendmsg_filter_cmsghdr()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: Fix MSGHDR check in sendmsg()
Anoop C S [Wed, 22 May 2019 05:15:37 +0000 (10:45 +0530)]
swrap: Fix MSGHDR check in sendmsg()

Check for msg_controllen and msg_control data members from msghdr
structure needs to be validated on the received omsg pointer rather
than on newly created msghdr struture inside the wrapper.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoswrap: print out SOCKET_WRAPPER_PACKAGE and SOCKET_WRAPPER_VERSION on first use
Stefan Metzmacher [Thu, 28 Jan 2021 11:40:14 +0000 (12:40 +0100)]
swrap: print out SOCKET_WRAPPER_PACKAGE and SOCKET_WRAPPER_VERSION on first use

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agosrc/socket_wrapper.c: Improve checks and debug output of socket_wrapper_dir()
Andreas Schneider [Thu, 28 Jan 2021 19:06:11 +0000 (20:06 +0100)]
src/socket_wrapper.c: Improve checks and debug output of socket_wrapper_dir()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agosrc/socket_wrapper.c: fix mutex fork handling
Stefan Metzmacher [Tue, 26 Jan 2021 12:14:41 +0000 (13:14 +0100)]
src/socket_wrapper.c: fix mutex fork handling

We need to use pthread_mutex_init in the child handler...
See https://sourceware.org/bugzilla/show_bug.cgi?id=2745

Valgrind tools like helgrind and drd don't understand this
(at least in 3.15.0), they require a pthread_mutex_unlock()
in the child in order work.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Andreas Schneider <asn@samba.org>
3 years agogitlab-ci: Add job for ThreadSanitizer
Andreas Schneider [Wed, 12 Feb 2020 09:56:13 +0000 (10:56 +0100)]
gitlab-ci: Add job for ThreadSanitizer

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agocmake: Add ThreadSanitizer compile flags
Andreas Schneider [Wed, 12 Feb 2020 09:56:13 +0000 (10:56 +0100)]
cmake: Add ThreadSanitizer compile flags

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agosrc/socket_wrapper.c: always go through swrap_bind_symbol_all() protected by pthread_...
Stefan Metzmacher [Thu, 28 Jan 2021 13:31:31 +0000 (14:31 +0100)]
src/socket_wrapper.c: always go through swrap_bind_symbol_all() protected by pthread_once()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agosrc/socket_wrapper.c: split out _swrap_bind_symbol_generic()
Stefan Metzmacher [Thu, 28 Jan 2021 12:11:51 +0000 (13:11 +0100)]
src/socket_wrapper.c: split out _swrap_bind_symbol_generic()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agosrc/socket_wrapper.c: remove unused swrap_bind_symbol_libnsl()
Stefan Metzmacher [Thu, 28 Jan 2021 12:11:16 +0000 (13:11 +0100)]
src/socket_wrapper.c: remove unused swrap_bind_symbol_libnsl()

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agosocket_wrapper.c/tests: fall back to pragma init/fini for constructor/destructor...
Björn Jacke [Fri, 30 Oct 2020 14:44:53 +0000 (15:44 +0100)]
socket_wrapper.c/tests: fall back to pragma init/fini for constructor/destructor if possible

Signed-off-by: Bjoern Jacke <bjacke@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoconfigure: check for pragma init/fini for constructors/destructors
Björn Jacke [Fri, 30 Oct 2020 14:31:42 +0000 (15:31 +0100)]
configure: check for pragma init/fini for constructors/destructors

Signed-off-by: Bjoern Jacke <bjacke@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoBump version to 1.2.5 socket_wrapper-1.2.5
Andreas Schneider [Mon, 22 Jun 2020 14:53:36 +0000 (16:53 +0200)]
Bump version to 1.2.5

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
3 years agosocket_wrapper.c: let swrap_vioctl() handle SIOCOUTQ/TIOCOUTQ/FIONWRITE explicitly
Stefan Metzmacher [Mon, 8 Jun 2020 12:21:25 +0000 (14:21 +0200)]
socket_wrapper.c: let swrap_vioctl() handle SIOCOUTQ/TIOCOUTQ/FIONWRITE explicitly

They are used to ask for the number of unacked bytes in the send queue,
with AF_UNIX sockets get strange result, on linux 5.3 I get more bytes
reported than I sent into the socket. All bytes reach the destination
directly, so we can just always report 0 unacked bytes.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
(cherry picked from commit f317ebcdcdd626ed9e06de2eb60031306994c803)

3 years agosocket_wrapper.c: make FIONREAD handling more robust in swrap_vioctl()
Stefan Metzmacher [Mon, 8 Jun 2020 12:18:44 +0000 (14:18 +0200)]
socket_wrapper.c: make FIONREAD handling more robust in swrap_vioctl()

We should only dereference the va args when the kernel already checked
they are valid.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
(cherry picked from commit c95b7cb1d7b9348472276edceff71889aa676d25)