[SCM] Socket Wrapper Repository - branch master updated

2023-06-29 Thread Andreas Schneider
The branch, master has been updated
   via  d07136e Bump version to 1.4.2
  from  81a8970 gitlab-ci: Add Ubuntu 32bit build

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit d07136e8a6934e128b8be6860b7d08966691f8c8
Author: Andreas Schneider 
Date:   Thu Jun 29 13:37:19 2023 +0200

Bump version to 1.4.2

Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CHANGELOG  | 3 +++
 CMakeLists.txt | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index 0e1d39c..48192d5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,9 @@
 CHANGELOG
 =
 
+version 1.4.2 (released 2023-06-29)
+  * Fixed LFS issues on 32bit platforms
+
 version 1.4.1 (released 2023-06-21)
   * Fixed issue with fnctl() on 32bit
   * Added openat64() to detect stale fds
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 02fe340..5b235d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.4.1 LANGUAGES C)
+project(socket_wrapper VERSION 1.4.2 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2023-06-29 Thread Andreas Schneider
The branch, master has been updated
   via  81a8970 gitlab-ci: Add Ubuntu 32bit build
   via  3d318d4 swrap: Provide a fcntl64()
   via  593ab18 swrap: Fix fnctl64()
   via  51fbe21 tests(cmake): Fix handling of LFS support
   via  72d3b3c tests: Implement test_fcntl_lock correctly
   via  bbe14cc swrap: Make sure we do not redirect (f)open(at)() or fcntl()
   via  70ecbaa tests: Do not build test_swrap_unit with LFS support
  from  d8b61a6 Bump version to 1.4.1

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 81a897096588acc658f3834f084ea92c3a8c1746
Author: Andreas Schneider 
Date:   Thu Jun 22 18:30:52 2023 +0200

gitlab-ci: Add Ubuntu 32bit build

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 3d318d40907964168cc0fdda9492b80f11c1dddf
Author: Andreas Schneider 
Date:   Fri Jun 23 11:10:45 2023 +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 
Reviewed-by: Stefan Metzmacher 

commit 593ab1862a1d076f30185f7fc03a1fdcf725be56
Author: Andreas Schneider 
Date:   Thu Jun 22 18:32:30 2023 +0200

swrap: Fix fnctl64()

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 51fbe21156fcb55db6dba3fb329daae24f0fba3d
Author: Andreas Schneider 
Date:   Tue Jun 27 12:02:30 2023 +0200

tests(cmake): Fix handling of LFS support

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 72d3b3c26a51024e35f82673f6d7ce734ccf54bf
Author: Andreas Schneider 
Date:   Fri Jun 23 13:50:03 2023 +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 
Reviewed-by: Stefan Metzmacher 

commit bbe14cc3200ca553b13ed49357e2e88ba487eeaa
Author: Andreas Schneider 
Date:   Tue Jun 27 12:18:53 2023 +0200

swrap: Make sure we do not redirect (f)open(at)() or fcntl()

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 70ecbaaac38dd47d1b3343ae828a3a7b9ab980c2
Author: Andreas Schneider 
Date:   Tue Jun 27 12:01:46 2023 +0200

tests: Do not build test_swrap_unit with LFS support

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 .gitlab-ci.yml  |  20 
 config.h.cmake  |   1 +
 src/socket_wrapper.c| 129 
 tests/CMakeLists.txt|  21 ++--
 tests/test_fcntl_lock.c |  46 -
 5 files changed, 182 insertions(+), 35 deletions(-)


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ef98aeb..3643167 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,6 +6,7 @@ variables:
   TUMBLEWEED_BUILD: buildenv-tumbleweed
   MINGW_BUILD: buildenv-mingw
   UBUNTU_BUILD: buildenv-ubuntu
+  UBUNTU32_BUILD: buildenv-ubuntu32
 
 stages:
   - build
@@ -307,3 +308,22 @@ ubuntu/x86_64:
 when: on_failure
 paths:
   - obj/
+
+ubuntu/x86:
+  stage: test
+  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$UBUNTU32_BUILD
+  script:
+- mkdir -p obj && cd obj && cmake
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo
+  -DPICKY_DEVELOPER=ON
+  -DUNIT_TESTING=ON .. &&
+  make -j$(nproc) && ctest --output-on-failure
+  tags:
+- shared
+  except:
+- tags
+  artifacts:
+expire_in: 1 week
+when: on_failure
+paths:
+  - obj/
diff --git a/config.h.cmake b/config.h.cmake
index 399013e..3a5843a 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -45,6 +45,7 @@
 #cmakedefine HAVE_OPEN64 1
 #cmakedefine HAVE_OPENAT64 1
 #cmakedefine HAVE_FOPEN64 1
+#cmakedefine HAVE_FCNTL64 1
 #cmakedefine HAVE_GETPROGNAME 1
 #cmakedefine HAVE_GETEXECNAME 1
 #cmakedefine HAVE_PLEDGE 1
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index dc07b53..c759d35 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -44,6 +44,12 @@
 
 #include "config.h"
 
+/*
+ * Make sure we do not redirect (f)open(at)() or fcntl() to their 64bit
+ * variants
+ */
+#undef _FILE_OFFSET_BITS
+
 #include 
 #include 
 #include 

[SCM] Socket Wrapper Repository - branch master updated

2023-06-21 Thread Andreas Schneider
The branch, master has been updated
   via  d8b61a6 Bump version to 1.4.1
  from  71a55a6 swrap: Add support for openat64()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit d8b61a6734e9dba718308ece5a66c751e3150c83
Author: Andreas Schneider 
Date:   Mon May 8 12:59:33 2023 +0200

Bump version to 1.4.1

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 CHANGELOG  | 4 
 CMakeLists.txt | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index 68e40f9..0e1d39c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,10 @@
 CHANGELOG
 =
 
+version 1.4.1 (released 2023-06-21)
+  * Fixed issue with fnctl() on 32bit
+  * Added openat64() to detect stale fds
+
 version 1.4.0 (released 2023-01-18)
   * Added support for sendmmsg()/recvmmsg()
   * Added support for handling close, recvmmsg and sendmmsg syscalls
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 47e9824..02fe340 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.4.0 LANGUAGES C)
+project(socket_wrapper VERSION 1.4.1 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -25,7 +25,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
 set(LIBRARY_VERSION_MINOR 4)
-set(LIBRARY_VERSION_PATCH 0)
+set(LIBRARY_VERSION_PATCH 1)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2023-06-20 Thread Andreas Schneider
The branch, master has been updated
   via  71a55a6 swrap: Add support for openat64()
   via  6bbf07e tests: Use F_(OFD)SETLK(64) in test_fcntl_lock
   via  cc80f53 cmake: Define large file support for tests
  from  cb5d579 gitlab-ci: Add a 32bit build

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 71a55a64d6b6dcba9582cbded86d321ce0318fc0
Author: Andreas Schneider 
Date:   Mon Jun 19 16:23:50 2023 +0200

swrap: Add support for openat64()

Signed-off-by: Andreas Schneider 
Reviewed-by: Andrew Bartlett 

commit 6bbf07e6c4475928de5a5005c1fb5804e3cebcde
Author: Andreas Schneider 
Date:   Tue May 9 09:19:07 2023 +0200

tests: Use F_(OFD)SETLK(64) in test_fcntl_lock

Signed-off-by: Andreas Schneider 
Reviewed-by: Andrew Bartlett 

commit cc80f531f439af77590b0f411ed3b38742d5ac08
Author: Andreas Schneider 
Date:   Tue May 9 09:09:01 2023 +0200

cmake: Define large file support for tests

Signed-off-by: Andreas Schneider 
Reviewed-by: Andrew Bartlett 

---

Summary of changes:
 ConfigureChecks.cmake   |  1 +
 config.h.cmake  |  1 +
 src/CMakeLists.txt  |  6 +
 src/socket_wrapper.c| 68 +
 tests/CMakeLists.txt|  7 -
 tests/test_fcntl_lock.c |  9 ++-
 6 files changed, 90 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index c99e2ae..daaee2b 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -70,6 +70,7 @@ check_function_exists(timerfd_create HAVE_TIMERFD_CREATE)
 check_function_exists(bindresvport HAVE_BINDRESVPORT)
 check_function_exists(accept4 HAVE_ACCEPT4)
 check_function_exists(open64 HAVE_OPEN64)
+check_function_exists(openat64 HAVE_OPENAT64)
 check_function_exists(fopen64 HAVE_FOPEN64)
 check_function_exists(getprogname HAVE_GETPROGNAME)
 check_function_exists(getexecname HAVE_GETEXECNAME)
diff --git a/config.h.cmake b/config.h.cmake
index a637a34..399013e 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -43,6 +43,7 @@
 #cmakedefine HAVE_BINDRESVPORT 1
 #cmakedefine HAVE_ACCEPT4 1
 #cmakedefine HAVE_OPEN64 1
+#cmakedefine HAVE_OPENAT64 1
 #cmakedefine HAVE_FOPEN64 1
 #cmakedefine HAVE_GETPROGNAME 1
 #cmakedefine HAVE_GETEXECNAME 1
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a1dbfaf..19e0d26 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,6 +8,12 @@ target_compile_options(socket_wrapper
PRIVATE
   ${DEFAULT_C_COMPILE_FLAGS}
   -D_GNU_SOURCE)
+if (CMAKE_SIZEOF_VOID_P EQUAL 4)
+target_compile_options(socket_wrapper
+   PRIVATE
+   -D_LARGEFILE64_SOURCE)
+endif()
+
 target_link_libraries(socket_wrapper
   PRIVATE ${SWRAP_REQUIRED_LIBRARIES} 
${CMAKE_THREAD_LIBS_INIT})
 
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index de2f732..dc07b53 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -531,6 +531,9 @@ typedef int (*__libc_open)(const char *pathname, int flags, 
...);
 #ifdef HAVE_OPEN64
 typedef int (*__libc_open64)(const char *pathname, int flags, ...);
 #endif /* HAVE_OPEN64 */
+#ifdef HAVE_OPENAT64
+typedef int (*__libc_openat64)(int dirfd, const char *pathname, int flags, 
...);
+#endif /* HAVE_OPENAT64 */
 typedef int (*__libc_openat)(int dirfd, const char *path, int flags, ...);
 typedef int (*__libc_pipe)(int pipefd[2]);
 typedef int (*__libc_read)(int fd, void *buf, size_t count);
@@ -631,6 +634,9 @@ struct swrap_libc_symbols {
SWRAP_SYMBOL_ENTRY(open);
 #ifdef HAVE_OPEN64
SWRAP_SYMBOL_ENTRY(open64);
+#endif
+#ifdef HAVE_OPENAT64
+   SWRAP_SYMBOL_ENTRY(openat64);
 #endif
SWRAP_SYMBOL_ENTRY(openat);
SWRAP_SYMBOL_ENTRY(pipe);
@@ -1136,6 +1142,29 @@ static int libc_vopen64(const char *pathname, int flags, 
va_list ap)
 }
 #endif /* HAVE_OPEN64 */
 
+#ifdef HAVE_OPENAT64
+static int
+libc_vopenat64(int dirfd, const char *pathname, int flags, va_list ap)
+{
+   int mode = 0;
+   int fd;
+
+   swrap_bind_symbol_all();
+
+   swrap_inject_o_largefile();
+
+   if (flags & O_CREAT) {
+   mode = va_arg(ap, int);
+   }
+   fd = swrap.libc.symbols._libc_openat64.f(dirfd,
+pathname,
+flags,
+(mode_t)mode);
+
+   return fd;
+}
+#endif /* HAVE_OPENAT64 */
+
 static int libc_vopenat(int dirfd, const char *path, int flags, va_list ap)
 {
int mode = 0;
@@ -1441,6 +1470,9 @@ static void __swrap_bind_symbol_all_once(void)
swrap_bind_symbol_libc(open);
 #ifdef HAVE_OPEN64

[SCM] Socket Wrapper Repository - branch master updated

2023-05-08 Thread Andreas Schneider
The branch, master has been updated
   via  cb5d579 gitlab-ci: Add a 32bit build
   via  df91870 Add fix for incorrect mapping of fcntl64() -> fcntl(), 
causing locking failures
   via  ceb139d Add test for F_SETLK as this is needs to be 64-bit aware on 
32-bit userspace
  from  b15c02f tests: New test with poll

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit cb5d5790fff30e3be5a9465a85b1ac0aaaebfed2
Author: Andreas Schneider 
Date:   Fri May 5 07:14:26 2023 +0200

gitlab-ci: Add a 32bit build

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

Signed-off-by: Andreas Schneider 
Reviewed-by: Andrew Bartlett 

commit df918708717c084ec9048be2864edcde81816108
Author: Andrew Bartlett 
Date:   Fri May 5 13:34:00 2023 +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 
Reviewed-by: Andreas Schneider 

commit ceb139dc42c50275a11ca974ef8800032cf24b6f
Author: Andrew Bartlett 
Date:   Fri May 5 13:15:51 2023 +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 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 .gitlab-ci.yml  | 20 ++
 ConfigureChecks.cmake   |  1 +
 cmake/Toolchain-cross-m32.cmake | 23 +++
 src/socket_wrapper.c| 25 
 tests/CMakeLists.txt|  1 +
 tests/test_fcntl_lock.c | 86 +
 6 files changed, 156 insertions(+)
 create mode 100644 cmake/Toolchain-cross-m32.cmake
 create mode 100644 tests/test_fcntl_lock.c


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d5dc461..ef98aeb 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -224,6 +224,26 @@ tumbleweed/x86_64/clang:
 paths:
   - obj/
 
+tumbleweed/x86/gcc:
+  stage: test
+  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD
+  script:
+- mkdir -p obj && cd obj && cmake
+  -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-m32.cmake
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo
+  -DPICKY_DEVELOPER=ON
+  -DUNIT_TESTING=ON .. &&
+  make -j$(nproc) && ctest --output-on-failure
+  tags:
+- shared
+  except:
+- tags
+  artifacts:
+expire_in: 1 week
+when: on_failure
+paths:
+  - obj/
+
 tumbleweed/static-analysis:
   stage: analysis
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index b820a65..c99e2ae 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -80,6 +80,7 @@ check_function_exists(__close_nocancel HAVE___CLOSE_NOCANCEL)
 check_function_exists(recvmmsg HAVE_RECVMMSG)
 check_function_exists(sendmmsg HAVE_SENDMMSG)
 check_function_exists(syscall HAVE_SYSCALL)
+check_function_exists(fcntl64 HAVE_FCNTL64)
 
 if (UNIX)
 find_library(DLFCN_LIBRARY dl)
diff --git a/cmake/Toolchain-cross-m32.cmake b/cmake/Toolchain-cross-m32.cmake
new file mode 100644
index 000..7918c60
--- /dev/null
+++ b/cmake/Toolchain-cross-m32.cmake
@@ -0,0 +1,23 @@
+set(CMAKE_C_FLAGS "-m32" CACHE STRING "C compiler flags"   FORCE)
+set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "C++ compiler flags" FORCE)
+
+set(LIB32 /usr/lib) # Fedora
+
+if(EXISTS /usr/lib32)
+set(LIB32 /usr/lib32) # Arch, Solus
+endif()
+
+set(CMAKE_SYSTEM_LIBRARY_PATH ${LIB32} CACHE STRING "system library search 
path" FORCE)
+set(CMAKE_LIBRARY_PATH${LIB32} CACHE STRING "library search path"  
  FORCE)
+
+# this is probably unlikely to be needed, but just in case
+set(CMAKE_EXE_LINKER_FLAGS"-m32 -L${LIB32}" CACHE STRING "executable 
linker flags" FORCE)
+set(CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library 
linker flags" FORCE)
+set(CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker 
flags" FORCE)
+
+# on Fedora and Arch and 

[SCM] Socket Wrapper Repository - branch master updated

2023-04-12 Thread Andreas Schneider
The branch, master has been updated
   via  b15c02f tests: New test with poll
   via  8b1b825 tests: Try larger writes and reads
  from  97fe09e cmake: Fix cmocka >= 1.1.6 find_package() in CONFIG mode

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit b15c02fc0187103ddad4c05adc0ff292f774c1ef
Author: Jakub Jelen 
Date:   Thu Mar 2 10:46:53 2023 +0100

tests: New test with poll

Signed-off-by: Jakub Jelen 
Reviewed-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 8b1b82567794470e829bd0a34e99eeec397c7e6d
Author: Jakub Jelen 
Date:   Thu Feb 23 14:55:02 2023 +0100

tests: Try larger writes and reads

Signed-off-by: Jakub Jelen 
Reviewed-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 tests/CMakeLists.txt |   1 +
 tests/test_echo_tcp_poll.c   | 226 +++
 tests/test_echo_tcp_write_read.c |  93 +++-
 3 files changed, 292 insertions(+), 28 deletions(-)
 create mode 100644 tests/test_echo_tcp_poll.c


Changeset truncated at 500 lines:

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3748461..b1a3c6c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -64,6 +64,7 @@ set(SWRAP_TESTS
 test_echo_tcp_sendmsg_recvmsg
 test_echo_tcp_sendmmsg_recvmmsg
 test_echo_tcp_write_read
+test_echo_tcp_poll
 test_echo_tcp_writev_readv
 test_echo_tcp_get_peer_sock_name
 test_echo_udp_sendto_recvfrom
diff --git a/tests/test_echo_tcp_poll.c b/tests/test_echo_tcp_poll.c
new file mode 100644
index 000..1632eae
--- /dev/null
+++ b/tests/test_echo_tcp_poll.c
@@ -0,0 +1,226 @@
+#include 
+#include 
+#include 
+#include 
+
+#include "config.h"
+#include "torture.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int setup_echo_srv_tcp_ipv4(void **state)
+{
+   torture_setup_echo_srv_tcp_ipv4(state);
+
+   return 0;
+}
+
+#ifdef HAVE_IPV6
+static int setup_echo_srv_tcp_ipv6(void **state)
+{
+   torture_setup_echo_srv_tcp_ipv6(state);
+
+   return 0;
+}
+#endif
+
+static int teardown(void **state)
+{
+   torture_teardown_echo_srv(state);
+
+   return 0;
+}
+
+static void handle_poll_loop(size_t size, int s)
+{
+   char send_buf[size];
+   char recv_buf[size];
+   int nfds, num_open_fds;
+   struct pollfd pfds[1];
+   size_t nread = 0, nwrote = 0;
+   ssize_t ret;
+   int i;
+
+   num_open_fds = nfds = 1;
+   pfds[0].fd = s;
+   pfds[0].events = POLLIN | POLLOUT;
+
+   i = 0;
+   memset(send_buf, 0, sizeof(send_buf));
+
+   while (num_open_fds > 0 && i < 10) {
+   int ready;
+
+   printf("About to poll()\n");
+   ready = poll(pfds, nfds, -1);
+   assert_int_not_equal(ready, -1);
+
+   printf("Ready: %d\n", ready);
+
+   /* Deal with array returned by poll(). */
+   for (int j = 0; j < nfds; j++) {
+   if (pfds[j].revents != 0) {
+   printf("  fd=%d; events: %s%s%s%s\n", 
pfds[j].fd,
+  (pfds[j].revents & POLLIN)  ? "POLLIN "  
: "",
+  (pfds[j].revents & POLLOUT) ? "POLLOUT " 
: "",
+  (pfds[j].revents & POLLHUP) ? "POLLHUP " 
: "",
+  (pfds[j].revents & POLLERR) ? "POLLERR " 
: "");
+   }
+
+   if (pfds[j].revents & POLLIN) {
+   ret = read(s,
+  recv_buf + nread,
+  sizeof(recv_buf) - nread);
+   printf("  fd=%d: read=%zd\n", pfds[j].fd, ret);
+   assert_int_not_equal(ret, -1);
+   nread += ret;
+   /* try to delay */
+   sleep(5);
+   }
+   if (pfds[j].revents & POLLOUT) {
+   snprintf(send_buf, sizeof(send_buf),
+"packet.%d", i);
+   ret = write(s,
+   send_buf + nwrote,
+   sizeof(send_buf) - nwrote);
+   printf("  fd=%d: wrote=%zd\n", pfds[j].fd, ret);
+   assert_int_not_equal(ret, -1);
+   nwrote += ret;
+   if (nwrote == sizeof(send_buf)) {
+   /* no more to write */
+   

[SCM] Socket Wrapper Repository - branch master updated

2023-02-23 Thread Andreas Schneider
The branch, master has been updated
   via  97fe09e cmake: Fix cmocka >= 1.1.6 find_package() in CONFIG mode
  from  3c945e0 Bump version to 1.4.0

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 97fe09e583f6e2ef94623c872e0c56bcd8817303
Author: Andreas Schneider 
Date:   Fri Feb 17 17:51:27 2023 +0100

cmake: Fix cmocka >= 1.1.6 find_package() in CONFIG mode

Signed-off-by: Andreas Schneider 
Reviewed-by: Pavel Filipenský 

---

Summary of changes:
 tests/CMakeLists.txt | 5 +
 1 file changed, 5 insertions(+)


Changeset truncated at 500 lines:

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6c3aae9..3748461 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -7,6 +7,11 @@ include_directories(
   ${CMOCKA_INCLUDE_DIR}
 )
 
+# Required for cmocka >= 1.1.6
+if (TARGET cmocka::cmocka)
+set(CMOCKA_LIBRARY cmocka::cmocka)
+endif()
+
 set(TORTURE_LIBRARY torture)
 
 # RFC862 echo server


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2023-01-18 Thread Andreas Schneider
The branch, master has been updated
   via  3c945e0 Bump version to 1.4.0
  from  5e4b246 tests: test uid_wrapper_syscall_{valid,va} interaction 
using swrap_fake_uid_wrapper.so

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 3c945e01a8b8d41a02f083af49b29e3143d06505
Author: Andreas Schneider 
Date:   Wed Jan 18 08:54:41 2023 +0100

Bump version to 1.4.0

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CHANGELOG  | 10 --
 CMakeLists.txt |  6 +++---
 2 files changed, 11 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index 31954d6..68e40f9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,11 @@
-ChangeLog
-==
+CHANGELOG
+=
+
+version 1.4.0 (released 2023-01-18)
+  * Added support for sendmmsg()/recvmmsg()
+  * Added support for handling close, recvmmsg and sendmmsg syscalls
+  * Added support to interact with uid_wrapper syscall()
+  * Improved IP address tracing output
 
 version 1.3.5 (released 2022-11-23)
   * Inject O_LARGEFILE as needed on 32bit
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a0c129..47e9824 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.3.5 LANGUAGES C)
+project(socket_wrapper VERSION 1.4.0 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -24,8 +24,8 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 #   If the source code was changed, but there were no interface changes:
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
-set(LIBRARY_VERSION_MINOR 3)
-set(LIBRARY_VERSION_PATCH 2)
+set(LIBRARY_VERSION_MINOR 4)
+set(LIBRARY_VERSION_PATCH 0)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2023-01-17 Thread Andreas Schneider
The branch, master has been updated
   via  5e4b246 tests: test uid_wrapper_syscall_{valid,va} interaction 
using swrap_fake_uid_wrapper.so
   via  a4e2437 src/socket_wrapper.c: make use of 
uid_wrapper_syscall_{valid,va}()
   via  1b8d5d8 src/socket_wrapper.c: export 
socket_wrapper_syscall_{valid,va}()
   via  79ce9b9 tests: let test_echo_tcp_sendmmsg_recvmmsg check raw 
SYS_close, SYS_recvmmsg and SYS_sendmmsg
   via  72da1a7 src/socket_wrapper.c: handle raw SYS_close, SYS_recvmmsg 
and SYS_sendmmsg syscall() invocations
   via  7fbf20d tests: add test_echo_tcp_sendmmsg_recvmmsg
   via  f9342dc src/socket_wrapper.c: implement recvmmsg and sendmmsg
   via  d04424e src/socket_wrapper.c: add some tracing for connected dgram 
sockets
   via  6af6c5e src/socket_wrapper.c: don't leak unlink() errno (most 
likely ENOENT) in swrap_bind()
   via  2f67c6b src/socket_wrapper.c: pretty print ip addresses in tracing 
output.
  from  f88fe92 Bump version to 1.3.5

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 5e4b2466d291f37a6deb1b4c7ae56d76b4402557
Author: Stefan Metzmacher 
Date:   Mon Jan 16 21:57:35 2023 +0100

tests: test uid_wrapper_syscall_{valid,va} interaction using 
swrap_fake_uid_wrapper.so

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit a4e2437d5f0a89880d45c2cf685f3e81654a23a7
Author: Stefan Metzmacher 
Date:   Mon Jan 16 19:51:05 2023 +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 
Reviewed-by: Andreas Schneider 

commit 1b8d5d8c6e0bd56ec4883e2b09f4f2cedd3aa1d7
Author: Stefan Metzmacher 
Date:   Mon Jan 16 19:48:57 2023 +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 
Reviewed-by: Andreas Schneider 

commit 79ce9b9b14ac83a33712d6af4eecdb63bba45742
Author: Stefan Metzmacher 
Date:   Mon Jan 16 20:14:26 2023 +0100

tests: let test_echo_tcp_sendmmsg_recvmmsg check raw SYS_close, 
SYS_recvmmsg and SYS_sendmmsg

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 72da1a76e78bcf9be733ec72cce7060a6e19606a
Author: Stefan Metzmacher 
Date:   Mon Jan 16 19:46:13 2023 +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 
Reviewed-by: Andreas Schneider 

commit 7fbf20da01e9cc2031e92111bc794048a13d5f50
Author: Stefan Metzmacher 
Date:   Mon Jan 16 19:27:12 2023 +0100

tests: add test_echo_tcp_sendmmsg_recvmmsg

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit f9342dcf3d9a163dd9f3aee324a14a3ac0d423ac
Author: Stefan Metzmacher 
Date:   Mon Jan 16 17:00:48 2023 +0100

src/socket_wrapper.c: implement recvmmsg and sendmmsg

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit d04424e0baddc969d06623e38a67937cb2c83587
Author: Stefan Metzmacher 
Date:   Mon Jan 16 16:58:04 2023 +0100

src/socket_wrapper.c: add some tracing for connected dgram sockets

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 6af6c5e59a9b522294c3a83a3efb0eccc1211087
Author: Stefan Metzmacher 
Date:   Sun Nov 6 16:07:21 2022 +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 
Reviewed-by: Andreas Schneider 

commit 2f67c6bef20e58676851df668f70fd261eea89ea
Author: Stefan Metzmacher 
Date:   Mon Jan 16 16:50:32 2023 +0100

src/socket_wrapper.c: pretty print ip addresses in tracing output.

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 


[SCM] Socket Wrapper Repository - branch master updated

2022-11-24 Thread Andreas Schneider
The branch, master has been updated
   via  f88fe92 Bump version to 1.3.5
   via  c562535 socket_wrapper: inject O_LARGEFILE to open[64|at]() if 
needed
   via  f0a511f Avoid dclose(RTLD_NEXT)
  from  6854835 pkgconfig: Fix path to libsocket_wrapper.so

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f88fe92249b156d90ecff78d3a5ef0e5bbcaa6b0
Author: Stefan Metzmacher 
Date:   Wed Nov 23 12:12:12 2022 +0100

Bump version to 1.3.5

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit c562535f1efef204f553ed793cfd9c7efada8b3f
Author: Stefan Metzmacher 
Date:   Wed Nov 23 11:46:45 2022 +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 
Reviewed-by: Andreas Schneider 

commit f0a511f6a4b60b63efcf0ddeec889672bd6d6a76
Author: Samuel Thibault 
Date:   Thu Nov 10 18:36:29 2022 +

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 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CHANGELOG|  6 ++
 CMakeLists.txt   |  4 ++--
 src/socket_wrapper.c | 31 +--
 3 files changed, 37 insertions(+), 4 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index 8c29ec1..31954d6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,12 @@
 ChangeLog
 ==
 
+version 1.3.5 (released 2022-11-23)
+  * Inject O_LARGEFILE as needed on 32bit
+  * pkgconfig: Fix path to libsocket_wrapper.so
+  * Fix -Wcast-qual warnings
+  * Fix dclose(RTLD_NEXT)
+
 version 1.3.4 (released 2022-07-21)
   * Fixed TOCTOU issue with udp auto binding
   * Fixed running on FreeBSD
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c6a34b0..8a0c129 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.3.4 LANGUAGES C)
+project(socket_wrapper VERSION 1.3.5 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -25,7 +25,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
 set(LIBRARY_VERSION_MINOR 3)
-set(LIBRARY_VERSION_PATCH 1)
+set(LIBRARY_VERSION_PATCH 2)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index ec8321f..bedda07 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -984,6 +984,19 @@ static FILE *libc_fopen64(const char *name, const char 
*mode)
 }
 #endif /* HAVE_FOPEN64 */
 
+static void swrap_inject_o_largefile(int *flags)
+{
+   (void)*flags; /* maybe unused */
+#if SIZE_MAX == 0xUL && defined(O_LARGEFILE)
+#ifdef O_PATH
+   if (((*flags) & O_PATH) == 0)
+#endif
+   {
+   *flags |= O_LARGEFILE;
+   }
+#endif
+}
+
 static int libc_vopen(const char *pathname, int flags, va_list ap)
 {
int mode = 0;
@@ -991,6 +1004,8 @@ static int libc_vopen(const char *pathname, int flags, 
va_list ap)
 
swrap_bind_symbol_all();
 
+   swrap_inject_o_largefile();
+
if (flags & O_CREAT) {
mode = va_arg(ap, int);
}
@@ -1019,6 +1034,8 @@ static int libc_vopen64(const char *pathname, int flags, 
va_list ap)
 
swrap_bind_symbol_all();
 
+   swrap_inject_o_largefile();
+
if (flags & O_CREAT) {
mode = va_arg(ap, int);
}
@@ -1035,6 +1052,8 @@ static int libc_vopenat(int dirfd, const char *path, int 
flags, va_list ap)
 
swrap_bind_symbol_all();
 
+   swrap_inject_o_largefile();
+
if (flags & O_CREAT) {
mode = va_arg(ap, int);
}
@@ -7831,10 +7850,18 @@ void swrap_destructor(void)
 
SAFE_FREE(sockets);
 
-   if (swrap.libc.handle != NULL) {
+   if (swrap.libc.handle != NULL
+#ifdef RTLD_NEXT
+   && swrap.libc.handle != RTLD_NEXT
+#endif
+   ) {
dlclose(swrap.libc.handle);
}
-   if (swrap.libc.socket_handle) {
+   if (swrap.libc.socket_handle

[SCM] Socket Wrapper Repository - branch master updated

2022-11-08 Thread Andreas Schneider
The branch, master has been updated
   via  6854835 pkgconfig: Fix path to libsocket_wrapper.so
  from  f5c3e25 Fix -Wcast-qual warnings

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 685483524bc15baa7f032c38d9084d8a5adfc7d5
Author: Andreas Schneider 
Date:   Mon Sep 12 11:25:17 2022 +0200

pkgconfig: Fix path to libsocket_wrapper.so

Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 socket_wrapper.pc.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/socket_wrapper.pc.cmake b/socket_wrapper.pc.cmake
index 80d205a..7312a6f 100644
--- a/socket_wrapper.pc.cmake
+++ b/socket_wrapper.pc.cmake
@@ -1,4 +1,4 @@
 Name: @PROJECT_NAME@
 Description: The socket_wrapper library
 Version: @PROJECT_VERSION@
-Libs: @CMAKE_INSTALL_LIBDIR@/@SOCKET_WRAPPER_LIB@
+Libs: @CMAKE_INSTALL_FULL_LIBDIR@/@SOCKET_WRAPPER_LIB@


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2022-09-08 Thread Andreas Schneider
The branch, master has been updated
   via  f5c3e25 Fix -Wcast-qual warnings
  from  cdc071a Bump version to 1.3.4

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f5c3e25c9910d305a26f267fcfa0bfe8d97834ec
Author: Alex Richardson 
Date:   Fri Oct 1 10:00:32 2021 +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 
Reviewed-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 CompilerChecks.cmake | 2 +-
 src/socket_wrapper.c | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CompilerChecks.cmake b/CompilerChecks.cmake
index 195d619..8d18fbf 100644
--- a/CompilerChecks.cmake
+++ b/CompilerChecks.cmake
@@ -22,7 +22,7 @@ if (UNIX)
 add_c_compiler_flag("-Wshadow" SUPPORTED_COMPILER_FLAGS)
 add_c_compiler_flag("-Wmissing-prototypes" SUPPORTED_COMPILER_FLAGS)
 add_c_compiler_flag("-Wcast-align" SUPPORTED_COMPILER_FLAGS)
-#add_c_compiler_flag("-Wcast-qual" SUPPORTED_COMPILER_FLAGS)
+add_c_compiler_flag("-Wcast-qual" SUPPORTED_COMPILER_FLAGS)
 add_c_compiler_flag("-Werror=address" SUPPORTED_COMPILER_FLAGS)
 add_c_compiler_flag("-Wstrict-prototypes" SUPPORTED_COMPILER_FLAGS)
 add_c_compiler_flag("-Werror=strict-prototypes" SUPPORTED_COMPILER_FLAGS)
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 5804e93..ec8321f 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5325,7 +5325,7 @@ union __swrap_cmsghdr {
struct cmsghdr *cmsg;
 };
 
-static int swrap_sendmsg_unix_scm_rights(const struct cmsghdr *cmsg,
+static int swrap_sendmsg_unix_scm_rights(struct cmsghdr *cmsg,
 uint8_t **cm_data,
 size_t *cm_data_space,
 int *scm_rights_pipe_fd)
@@ -5557,7 +5557,7 @@ static int swrap_sendmsg_unix_scm_rights(const struct 
cmsghdr *cmsg,
return 0;
 }
 
-static int swrap_sendmsg_unix_sol_socket(const struct cmsghdr *cmsg,
+static int swrap_sendmsg_unix_sol_socket(struct cmsghdr *cmsg,
 uint8_t **cm_data,
 size_t *cm_data_space,
 int *scm_rights_pipe_fd)
@@ -5581,7 +5581,7 @@ static int swrap_sendmsg_unix_sol_socket(const struct 
cmsghdr *cmsg,
return rc;
 }
 
-static int swrap_recvmsg_unix_scm_rights(const struct cmsghdr *cmsg,
+static int swrap_recvmsg_unix_scm_rights(struct cmsghdr *cmsg,
 uint8_t **cm_data,
 size_t *cm_data_space)
 {
@@ -5860,7 +5860,7 @@ static int swrap_recvmsg_unix_scm_rights(const struct 
cmsghdr *cmsg,
return 0;
 }
 
-static int swrap_recvmsg_unix_sol_socket(const struct cmsghdr *cmsg,
+static int swrap_recvmsg_unix_sol_socket(struct cmsghdr *cmsg,
 uint8_t **cm_data,
 size_t *cm_data_space)
 {


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2022-07-21 Thread Andreas Schneider
The branch, master has been updated
   via  cdc071a Bump version to 1.3.4
   via  ce05a82 swrap: Fix a TOCTOU issue in swrap_auto_bind()
  from  2e64ad0 gitlab-ci: Introduce stages

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit cdc071a1e7438143c6c75af123821b8672d05b8c
Author: Andreas Schneider 
Date:   Thu Jul 21 14:48:02 2022 +0200

Bump version to 1.3.4

Reviewed-by: Stefan Metzmacher 

commit ce05a8276792a02829c8a90d8b66a3edd1bf
Author: Andreas Schneider 
Date:   Thu Jul 21 07:22:08 2022 +0200

swrap: Fix a TOCTOU issue in swrap_auto_bind()

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CHANGELOG| 4 
 CMakeLists.txt   | 6 +++---
 src/socket_wrapper.c | 5 +++--
 3 files changed, 10 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index ed579e2..8c29ec1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,10 @@
 ChangeLog
 ==
 
+version 1.3.4 (released 2022-07-21)
+  * Fixed TOCTOU issue with udp auto binding
+  * Fixed running on FreeBSD
+
 version 1.3.3 (released 2021-03-17)
   * Added public libsocket_wrapper_noop library
   * Added wrapper for wrap __close_nocancel()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc6a786..c6a34b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@
 cmake_minimum_required(VERSION 3.5.0)
 cmake_policy(SET CMP0048 NEW)
 
-# Specify search path for CMake modules to be loaded by include() 
+# Specify search path for CMake modules to be loaded by include()
 # and find_package()
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.3.3 LANGUAGES C)
+project(socket_wrapper VERSION 1.3.4 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -25,7 +25,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
 set(LIBRARY_VERSION_MINOR 3)
-set(LIBRARY_VERSION_PATCH 0)
+set(LIBRARY_VERSION_PATCH 1)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index ef87519..5804e93 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -3815,7 +3815,6 @@ static int swrap_auto_bind(int fd, struct socket_info 
*si, int family)
char type;
int ret;
int port;
-   struct stat st;
char *swrap_dir = NULL;
 
swrap_mutex_lock(_start_mutex);
@@ -3916,10 +3915,12 @@ static int swrap_auto_bind(int fd, struct socket_info 
*si, int family)
  type,
  socket_wrapper_default_iface(),
  port);
-   if (stat(un_addr.sa.un.sun_path, ) == 0) continue;
 
ret = libc_bind(fd, _addr.sa.s, un_addr.sa_socklen);
if (ret == -1) {
+   if (errno == EALREADY || errno == EADDRINUSE) {
+   continue;
+   }
goto done;
}
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2022-07-21 Thread Andreas Schneider
The branch, master has been updated
   via  2e64ad0 gitlab-ci: Introduce stages
   via  ffa9e06 gitlab-ci: Fix formatting
   via  dfad2f7 Add editorconfig
   via  324c57a swrap: Remove _close symbol alias as this breaks 'make 
test' on FreeBSD
   via  9c3113d tests: Fix compiler warning that arrays might not be 
initialized
   via  04430cc cmake: Disable -Werror=strict-overflow till glibc is fixed
  from  088410e swrap: Don't pass NULL pointers to memcpy()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 2e64ad0aaf417ba22757634dd409e4ba93ddfbc7
Author: Andreas Schneider 
Date:   Thu Mar 3 09:24:09 2022 +0100

gitlab-ci: Introduce stages

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit ffa9e069202b71be737a05c9b7f30b4b6d3bc2c4
Author: Andreas Schneider 
Date:   Thu Mar 3 09:18:11 2022 +0100

gitlab-ci: Fix formatting

Complaints from yamllint.

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit dfad2f7574d5b62c1f03a6bb64631cde1aa350a9
Author: Andreas Schneider 
Date:   Thu Mar 3 09:22:01 2022 +0100

Add editorconfig

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 324c57ae5d086017f7c226c22eca80d27d71
Author: Andreas Schneider 
Date:   Thu Jul 21 08:59:32 2022 +0200

swrap: Remove _close symbol alias as this breaks 'make test' on FreeBSD

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 9c3113d2c30c65ac01f0a795e9e9b0df53abcce2
Author: Andreas Schneider 
Date:   Thu Jul 21 07:33:11 2022 +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: '' 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 
Reviewed-by: Stefan Metzmacher 

commit 04430ccf0f5ce4bbb48638c53cde66c9a7bb2e3e
Author: Andreas Schneider 
Date:   Thu Jul 21 07:50:27 2022 +0200

cmake: Disable -Werror=strict-overflow till glibc is fixed

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 .editorconfig|  23 +++
 .gitlab-ci.yml   | 238 +--
 CompilerChecks.cmake |   7 +-
 src/socket_wrapper.c |   5 +-
 tests/test_echo_tcp_sendmsg_recvmsg_fd.c |  11 +-
 5 files changed, 166 insertions(+), 118 deletions(-)
 create mode 100644 .editorconfig


Changeset truncated at 500 lines:

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 000..bbe1bd5
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,23 @@
+root = true
+
+[*]
+charset = utf-8
+max_line_length = 80
+end_of_line = lf
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.{c,h}]
+indent_style = tab
+indent_size = 8
+tab_width = 8
+
+[*.cmake]
+indent_style = space
+indent_size = 4
+tab_width = 4
+
+[CMake*]
+indent_style = space
+indent_size = 4
+tab_width = 4
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c4dd3ce..d5dc461 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,3 +1,4 @@
+---
 variables:
   BUILD_IMAGES_PROJECT: cmocka/gitlab-build-images
   FEDORA_BUILD: buildenv-fedora
@@ -6,18 +7,24 @@ variables:
   MINGW_BUILD: buildenv-mingw
   UBUNTU_BUILD: buildenv-ubuntu
 
+stages:
+  - build
+  - test
+  - analysis
+
 centos7/x86_64:
+  stage: test
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$CENTOS7_BUILD
   script:
-  - mkdir -p obj && cd obj && cmake3
--DCMAKE_BUILD_TYPE=RelWithDebInfo
--DPICKY_DEVELOPER=ON
--DUNIT_TESTING=ON .. &&
-make -j$(nproc) && ctest --output-on-failure
+- mkdir -p obj && cd obj && cmake3
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo
+  -DPICKY_DEVELOPER=ON
+  -DUNIT_TESTING=ON .. &&
+  make -j$(nproc) && ctest --output-on-failure
   tags:
-  - shared
+- shared
   except:
-  - tags
+- tags
   artifacts:
 expire_in: 1 week
 when: on_failure
@@ -25,17 +32,18 @@ centos7/x86_64:
   - obj/
 
 fedora/x86_64:
+  stage: test
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
   script:
-  - mkdir -p obj && cd obj && cmake
--DCMAKE_BUILD_TYPE=RelWithDebInfo
--DPICKY_DEVELOPER=ON

[SCM] Socket Wrapper Repository - branch master updated

2022-04-04 Thread Andreas Schneider
The branch, master has been updated
   via  088410e swrap: Don't pass NULL pointers to memcpy()
  from  12c6934 Bump version to 1.3.3

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 088410edfe5e1cd01bd5cfcd0b8f0016e8fade7d
Author: Joseph Sutton 
Date:   Fri Jul 30 11:12:12 2021 +1200

swrap: Don't pass NULL pointers to memcpy()

Doing so is undefined behaviour.

Signed-off-by: Joseph Sutton 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 44cfad8..8141b8b 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -6285,9 +6285,11 @@ static void swrap_sendmsg_after(int fd,
 
for (i = 0; i < (size_t)msg->msg_iovlen; i++) {
size_t this_time = MIN(remain, (size_t)msg->msg_iov[i].iov_len);
-   memcpy(buf + ofs,
-  msg->msg_iov[i].iov_base,
-  this_time);
+   if (this_time > 0) {
+   memcpy(buf + ofs,
+  msg->msg_iov[i].iov_base,
+  this_time);
+   }
ofs += this_time;
remain -= this_time;
}


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2021-03-17 Thread Andreas Schneider
The branch, master has been updated
   via  12c6934 Bump version to 1.3.3
   via  2a1fa0f cmake: Define a library version for the noop lib
   via  bb5dcee cmake: Export cmake config for socket_wrapper_noop
   via  12d4d02 cmake: Set public include dir for socket_wrapper_noop target
   via  176dff0 cmake: Set PRIVATE for linking libraries
  from  181a3fa swrap: wrap __close_nocancel() if available

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 12c6934ee23b387f9f8cfbb89d44a100d4d61b4f
Author: Andreas Schneider 
Date:   Mon Mar 15 08:24:57 2021 +0100

Bump version to 1.3.3

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 2a1fa0f36e4cc2bc9df07852967f8057cfec315a
Author: Andreas Schneider 
Date:   Mon Mar 15 08:22:33 2021 +0100

cmake: Define a library version for the noop lib

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit bb5dcee4c28b0c64cfe19ed7f218b9970693dc2d
Author: Andreas Schneider 
Date:   Mon Mar 15 08:18:15 2021 +0100

cmake: Export cmake config for socket_wrapper_noop

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 12d4d02399cce64eb0d7895b97b3faa169f04ed7
Author: Andreas Schneider 
Date:   Mon Mar 15 08:17:34 2021 +0100

cmake: Set public include dir for socket_wrapper_noop target

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 176dff0bd8c8e9fb3a409a4af634ec7d039955de
Author: Andreas Schneider 
Date:   Mon Mar 15 08:09:29 2021 +0100

cmake: Set PRIVATE for linking libraries

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CHANGELOG  |  6 ++
 CMakeLists.txt | 12 +---
 src/CMakeLists.txt | 19 ++-
 3 files changed, 29 insertions(+), 8 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index c2cbb23..ed579e2 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,12 @@
 ChangeLog
 ==
 
+version 1.3.3 (released 2021-03-17)
+  * Added public libsocket_wrapper_noop library
+  * Added wrapper for wrap __close_nocancel()
+  * Fixed possible deadlock in swrap_pcap_dump_packet()
+  * Fixed issue when writing pcap files
+
 version 1.3.2 (released 2021-02-10)
   * Fixed possible memory leak between swrap_recvmsg_{before,after}_unix()
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8927ebb..bc6a786 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.3.2 LANGUAGES C)
+project(socket_wrapper VERSION 1.3.3 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -24,11 +24,17 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 #   If the source code was changed, but there were no interface changes:
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
-set(LIBRARY_VERSION_MINOR 2)
-set(LIBRARY_VERSION_PATCH 2)
+set(LIBRARY_VERSION_MINOR 3)
+set(LIBRARY_VERSION_PATCH 0)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 
+set(NOOP_LIBRARY_VERSION_MAJOR 0)
+set(NOOP_LIBRARY_VERSION_MINOR 0)
+set(NOOP_LIBRARY_VERSION_PATCH 1)
+set(NOOP_LIBRARY_VERSION 
"${NOOP_LIBRARY_VERSION_MAJOR}.${NOOP_LIBRARY_VERSION_MINOR}.${NOOP_LIBRARY_VERSION_PATCH}")
+set(NOOP_LIBRARY_SOVERSION ${NOOP_LIBRARY_VERSION_MAJOR})
+
 # add definitions
 include(DefinePlatformDefaults)
 include(DefineOptions.cmake)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ac56c86..a1dbfaf 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,7 +8,8 @@ target_compile_options(socket_wrapper
PRIVATE
   ${DEFAULT_C_COMPILE_FLAGS}
   -D_GNU_SOURCE)
-target_link_libraries(socket_wrapper ${SWRAP_REQUIRED_LIBRARIES} 
${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(socket_wrapper
+  PRIVATE ${SWRAP_REQUIRED_LIBRARIES} 
${CMAKE_THREAD_LIBS_INIT})
 
 set_target_properties(socket_wrapper
   PROPERTIES
@@ -31,16 +32,20 @@ set(SOCKET_WRAPPER_LOCATION 
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_
 add_library(socket_wrapper_noop SHARED socket_wrapper_noop.c)
 target_include_directories(socket_wrapper_noop
PRIVATE
-   ${CMAKE_BINARY_DIR})
+   ${socket_wrapper_BINARY_DIR}
+   PUBLIC
+   $
+   $)
 target_compile_options(socket_wrapper_noop
PRIVATE
   

[SCM] Socket Wrapper Repository - branch master updated

2021-03-15 Thread Andreas Schneider
The branch, master has been updated
   via  181a3fa swrap: wrap __close_nocancel() if available
   via  ba970e5 swrap: export a public socket_wrapper_indicate_no_inet_fd() 
helper function
   via  efd2967 swrap: introduce a socket_wrapper_noop.so and 
socket_wrapper.h to provide noop stubs
   via  4ad5a5a swrap: split out swrap_remove_wrapper() to handle 
swrap_close() and swrap_remove_stale()
   via  d28fdbf swrap: remember the libc_close() errno in swrap_close()
   via  167009f swrap: call libc_write() directly for internal fds
   via  2cf4c54 swrap: warn about unreachable addresses
  from  85b51c2 Bump version to 1.3.2

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 181a3fa5e4c242d72d311f5baa771c680647eda7
Author: Stefan Metzmacher 
Date:   Wed Feb 17 10:58:29 2021 +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 
Reviewed-by: Andreas Schneider 

commit ba970e5d32cceb0750eaa71fb83da3e2eef881d5
Author: Stefan Metzmacher 
Date:   Wed Feb 17 12:29:27 2021 +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 
Reviewed-by: Andreas Schneider 

commit efd2967e060a3a7ca3de589a23511bb38151ed8b
Author: Stefan Metzmacher 
Date:   Wed Feb 24 12:45:26 2021 +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 
Reviewed-by: Andreas Schneider 

commit 4ad5a5af0bdf94497f068f10d6c09520702fd50f
Author: Stefan Metzmacher 
Date:   Wed Feb 17 12:14:06 2021 +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 
Reviewed-by: Andreas Schneider 

commit d28fdbf203976290e6ba97577e1979df8f99bb61
Author: Stefan Metzmacher 
Date:   Wed Feb 17 12:14:06 2021 +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 
Reviewed-by: Andreas Schneider 

commit 167009f6ac1186aeeabffc29368bd5b375d9861f
Author: Stefan Metzmacher 
Date:   Wed Feb 17 11:00:53 2021 +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 
Reviewed-by: Andreas Schneider 

commit 2cf4c543d614e3263fa261e4584716d5b7771f09
Author: Stefan Metzmacher 
Date:   Wed Feb 17 11:41:38 2021 +0100

swrap: warn about unreachable addresses

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

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 CMakeLists.txt |  10 ++
 ConfigureChecks.cmake  |   1 +
 config.h.cmake |   1 +
 doc/socket_wrapper.1   | 114 +--
 doc/socket_wrapper.1.adoc  |  48 +++
 socket_wrapper_noop.pc.cmake   |   8 ++
 src/CMakeLists.txt |  32 +
 src/socket_wrapper.c   | 157 ++---
 src/socket_wrapper.h   |  89 
 .../thread_deadlock.c => src/socket_wrapper_noop.c |  52 +++
 tests/CMakeLists.txt   |   3 +-
 tests/test_public_functions.c  | 109 ++
 tests/test_tcp_dup2.c  |  20 ++-
 13 files 

[SCM] Socket Wrapper Repository - branch master updated

2021-02-10 Thread Andreas Schneider
The branch, master has been updated
   via  85b51c2 Bump version to 1.3.2
   via  d610c8d swrap: don't read the callers msg_control buffer in 
swrap_recvmsg_before_unix()
  from  db594f1 swrap: don't touch msg_tmp in swrap_recvmsg_after_unix() on 
error

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 85b51c275dfef9318f9fe76190a09ddd3a02ddc5
Author: Andreas Schneider 
Date:   Wed Feb 10 10:49:30 2021 +0100

Bump version to 1.3.2

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit d610c8d5b32db5c3cc6e57b11d1d2e1505975832
Author: Stefan Metzmacher 
Date:   Wed Feb 10 10:45:11 2021 +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 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 CHANGELOG| 3 +++
 CMakeLists.txt   | 4 ++--
 src/socket_wrapper.c | 1 -
 3 files changed, 5 insertions(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index 1292599..c2cbb23 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,9 @@
 ChangeLog
 ==
 
+version 1.3.2 (released 2021-02-10)
+  * Fixed possible memory leak between swrap_recvmsg_{before,after}_unix()
+
 version 1.3.1 (released 2021-02-09)
   * Fixed copy on write leak of ~38M for every fork
   * Fixed issue with accept() on FreeBSD
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ac8c1fc..13be7fb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.3.1 LANGUAGES C)
+project(socket_wrapper VERSION 1.3.2 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -25,7 +25,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
 set(LIBRARY_VERSION_MINOR 2)
-set(LIBRARY_VERSION_PATCH 1)
+set(LIBRARY_VERSION_PATCH 2)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 59fb07d..a950a0a 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5993,7 +5993,6 @@ static int swrap_recvmsg_before_unix(struct msghdr 
*msg_in,
if (cm_data == NULL) {
return -1;
}
-   memcpy(cm_data, msg_in->msg_control, msg_in->msg_controllen);
 
msg_tmp->msg_controllen = cm_data_space;
msg_tmp->msg_control = cm_data;


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2021-02-09 Thread Andreas Schneider
The branch, master has been updated
   via  db594f1 swrap: don't touch msg_tmp in swrap_recvmsg_after_unix() on 
error
   via  2b8a9e3 swrap: fix possible memory leak between 
swrap_recvmsg_{before,after}_unix()
  from  3af2bf7 Bump version to 1.3.1

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit db594f106d9737e0415a268439fc9003bb636473
Author: Stefan Metzmacher 
Date:   Tue Feb 9 16:09:59 2021 +0100

swrap: don't touch msg_tmp in swrap_recvmsg_after_unix() on error

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 2b8a9e3255f2c9bf440cbae404ca8ac8f3f910f6
Author: Stefan Metzmacher 
Date:   Tue Feb 9 15:57:22 2021 +0100

swrap: fix possible memory leak between swrap_recvmsg_{before,after}_unix()

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c | 36 ++--
 1 file changed, 30 insertions(+), 6 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index ece3493..59fb07d 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5960,7 +5960,8 @@ static ssize_t swrap_sendmsg_after_unix(struct msghdr 
*msg_tmp,
 }
 
 static int swrap_recvmsg_before_unix(struct msghdr *msg_in,
-struct msghdr *msg_tmp)
+struct msghdr *msg_tmp,
+uint8_t **tmp_control)
 {
 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
const size_t cm_extra_space = CMSG_SPACE(sizeof(int));
@@ -5968,6 +5969,7 @@ static int swrap_recvmsg_before_unix(struct msghdr 
*msg_in,
size_t cm_data_space = 0;
 
*msg_tmp = *msg_in;
+   *tmp_control = NULL;
 
SWRAP_LOG(SWRAP_LOG_TRACE,
  "msg_in->msg_controllen=%zu",
@@ -5995,6 +5997,7 @@ static int swrap_recvmsg_before_unix(struct msghdr 
*msg_in,
 
msg_tmp->msg_controllen = cm_data_space;
msg_tmp->msg_control = cm_data;
+   *tmp_control = cm_data;
 
SWRAP_LOG(SWRAP_LOG_TRACE,
  "msg_tmp->msg_controllen=%zu",
@@ -6002,11 +6005,13 @@ static int swrap_recvmsg_before_unix(struct msghdr 
*msg_in,
return 0;
 #else /* HAVE_STRUCT_MSGHDR_MSG_CONTROL */
*msg_tmp = *msg_in;
+   *tmp_control = NULL;
return 0;
 #endif /* ! HAVE_STRUCT_MSGHDR_MSG_CONTROL */
 }
 
 static ssize_t swrap_recvmsg_after_unix(struct msghdr *msg_tmp,
+   uint8_t **tmp_control,
struct msghdr *msg_out,
ssize_t ret)
 {
@@ -6016,13 +6021,26 @@ static ssize_t swrap_recvmsg_after_unix(struct msghdr 
*msg_tmp,
size_t cm_data_space = 0;
int rc = -1;
 
+   if (ret < 0) {
+   int saved_errno = errno;
+   SWRAP_LOG(SWRAP_LOG_TRACE, "ret=%zd - %d - %s", ret,
+ saved_errno, strerror(saved_errno));
+   SAFE_FREE(*tmp_control);
+   /* msg_out should not be touched on error */
+   errno = saved_errno;
+   return ret;
+   }
+
SWRAP_LOG(SWRAP_LOG_TRACE,
  "msg_tmp->msg_controllen=%zu",
  (size_t)msg_tmp->msg_controllen);
 
/* Nothing to do */
if (msg_tmp->msg_controllen == 0 || msg_tmp->msg_control == NULL) {
+   int saved_errno = errno;
*msg_out = *msg_tmp;
+   SAFE_FREE(*tmp_control);
+   errno = saved_errno;
return ret;
}
 
@@ -6045,16 +6063,17 @@ static ssize_t swrap_recvmsg_after_unix(struct msghdr 
*msg_tmp,
if (rc < 0) {
int saved_errno = errno;
SAFE_FREE(cm_data);
+   SAFE_FREE(*tmp_control);
errno = saved_errno;
return rc;
}
}
 
/*
-* msg_tmp->msg_control was created by swrap_recvmsg_before_unix()
-* and msg_out->msg_control is still the buffer of the caller.
+* msg_tmp->msg_control (*tmp_control) was created by
+* swrap_recvmsg_before_unix() and msg_out->msg_control
+* is still the buffer of the caller.
 */
-   SAFE_FREE(msg_tmp->msg_control);
msg_tmp->msg_control = msg_out->msg_control;
msg_tmp->msg_controllen = msg_out->msg_controllen;
*msg_out = *msg_tmp;
@@ -6063,13 +6082,17 @@ static ssize_t swrap_recvmsg_after_unix(struct msghdr 
*msg_tmp,
memcpy(msg_out->msg_control, cm_data, cm_data_space);
msg_out->msg_controllen = cm_data_space;
SAFE_FREE(cm_data);
+   SAFE_FREE(*tmp_control);
 
SWRAP_LOG(SWRAP_LOG_TRACE,
 

[SCM] Socket Wrapper Repository - branch master updated

2021-02-08 Thread Andreas Schneider
The branch, master has been updated
   via  3af2bf7 Bump version to 1.3.1
  from  0422a95 test_echo_tcp_sendmsg_recvmsg_fd: add 
test_tcp_sendmsg_recvmsg_fd_mixed() tests

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 3af2bf79563b806e6406b719324ee3fa528d7c8d
Author: Andreas Schneider 
Date:   Fri Feb 5 15:55:49 2021 +0100

Bump version to 1.3.1

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CHANGELOG  | 6 ++
 CMakeLists.txt | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index e0f7dd4..1292599 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,12 @@
 ChangeLog
 ==
 
+version 1.3.1 (released 2021-02-09)
+  * Fixed copy on write leak of ~38M for every fork
+  * Fixed issue with accept() on FreeBSD
+  * Fixed fd-passing on 32bit platforms
+  * Fixed invalid read in swrap_sendmsg_unix_scm_rights()
+
 version 1.3.0 (released 2021-02-03)
   * Added support for fd-passing via unix sockets
   * Added (de)contructor support on AIX with pragma init/finish
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d924cf5..ac8c1fc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.3.0 LANGUAGES C)
+project(socket_wrapper VERSION 1.3.1 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -25,7 +25,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
 set(LIBRARY_VERSION_MINOR 2)
-set(LIBRARY_VERSION_PATCH 0)
+set(LIBRARY_VERSION_PATCH 1)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2021-02-08 Thread Andreas Schneider
The branch, master has been updated
   via  0422a95 test_echo_tcp_sendmsg_recvmsg_fd: add 
test_tcp_sendmsg_recvmsg_fd_mixed() tests
   via  b35e3ce test_echo_tcp_sendmsg_recvmsg_fd: add 
test_tcp_sendmsg_recvmsg_fd_different() tests
   via  2d93f75 test_echo_tcp_sendmsg_recvmsg_fd: also test passing the 
same socket up to 6 times
   via  5aa939f test_echo_tcp_sendmsg_recvmsg_fd: split out 
test_tcp_sendmsg_recvmsg_fd_same()
   via  cbd5910 test_echo_tcp_sendmsg_recvmsg_fd: split out 
test_tcp_sendmsg_recvmsg_fd_array()
   via  b2e366d tests/echo_srv: allow more than once tcp connection at a 
time
   via  e896cec swrap: fix fd-passing without 4 padding bytes
   via  3c7ef47 swrap: fix invalid read in swrap_sendmsg_unix_scm_rights()
  from  13a6aca swrap: fix copy on write leak of ~38M for every fork.

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 0422a957c1b8959c5b48d7188a524296dc9b778b
Author: Stefan Metzmacher 
Date:   Fri Feb 5 16:25:43 2021 +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 
Reviewed-by: Andreas Schneider 

commit b35e3ce2e2b78fb7a1ccf6d5e011239c14fe27a9
Author: Stefan Metzmacher 
Date:   Fri Feb 5 14:40:45 2021 +0100

test_echo_tcp_sendmsg_recvmsg_fd: add 
test_tcp_sendmsg_recvmsg_fd_different() tests

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 2d93f75669a432723c90e20c3f9b2e2abfa55545
Author: Stefan Metzmacher 
Date:   Fri Feb 5 14:20:16 2021 +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 
Reviewed-by: Andreas Schneider 

commit 5aa939f2eb3f3ab04b65fde031a0c1f151928121
Author: Stefan Metzmacher 
Date:   Fri Feb 5 14:10:03 2021 +0100

test_echo_tcp_sendmsg_recvmsg_fd: split out 
test_tcp_sendmsg_recvmsg_fd_same()

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit cbd5910b1814cad1f1c4e9c9e8515f217edcd4d2
Author: Stefan Metzmacher 
Date:   Thu Feb 4 17:04:30 2021 +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 
Reviewed-by: Andreas Schneider 

commit b2e366d87bf8b340fe5e0b0186369cda7a94d186
Author: Stefan Metzmacher 
Date:   Fri Feb 5 15:41:27 2021 +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 
Reviewed-by: Andreas Schneider 

commit e896cecf1fc08d091d09fa29f1cfbfc22dab89ff
Author: Stefan Metzmacher 
Date:   Thu Feb 4 16:20:13 2021 +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 
Reviewed-by: Andreas Schneider 

commit 3c7ef4751527bd8c93d5431d9f1e36c4fe648f3d
Author: Stefan Metzmacher 
Date:   Fri Feb 5 19:36:26 2021 +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 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c |  71 -
 tests/echo_srv.c |   2 +-
 tests/test_echo_tcp_sendmsg_recvmsg_fd.c | 510 +++
 3 files changed, 518 insertions(+), 65 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 43a5892..ece3493 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5450,7 +5450,7 @@ static int swrap_sendmsg_unix_scm_rights(const struct 
cmsghdr *cmsg,
*new_cmsg = *cmsg;
__fds_out.p = CMSG_DATA(new_cmsg);
fds_out = __fds_out.fds;
-   memcpy(fds_out, fds_in, size_fds_out);
+   memcpy(fds_out, fds_in, size_fds_in);
new_cmsg->cmsg_len = cmsg->cmsg_len;
 
for (i = 0; i < num_fds_in; i++) {
@@ 

[SCM] Socket Wrapper Repository - branch master updated

2021-02-05 Thread Andreas Schneider
The branch, master has been updated
   via  13a6aca swrap: fix copy on write leak of ~38M for every fork.
   via  92a4fce swrap: abort on mutex errors
   via  affaf42 swrap: fallback to libc_getpeername() when we get an empty 
sun_path from accept()
   via  e72898a swrap: make swrap_accept() more resilient against races 
related to already disconnected sockets
   via  c3f7465 swrap: add better logging to convert_un_in()
   via  fa7a9b7 tests/echo_srv: make the main server logic resilient to 
ECONNABORTED from accept()
  from  cd51d80 Bump version to 1.3.0

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 13a6aca342120383776251247c72170c142bf017
Author: Stefan Metzmacher 
Date:   Thu Feb 4 05:02:32 2021 +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 
Reviewed-by: Andreas Schneider 

commit 92a4fce9df55e4c1a3b75325baa0f4b0988eeb6c
Author: Stefan Metzmacher 
Date:   Fri Feb 5 11:50:17 2021 +0100

swrap: abort on mutex errors

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

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit affaf4248c0cc2056081f56199109e4a94348b82
Author: Stefan Metzmacher 
Date:   Fri Feb 5 13:13:44 2021 +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,0x7ffde158,0x7ffde150,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" 
},0x7ffde0c0) = 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,0x7ffde158,0x7ffde150,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,0x7ffde158,0x7ffde150) ERR#57 
'Socket is not connected'
 ECHO_SRV(parent): getsockname(5,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" 
},0x7ffde0c0) = 0 (0x0)
 ECHO_SRV(parent): getpeername(5,0x7ffde158,0x7ffde150) ERR#57 
'Socket is not connected'

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit e72898ad92a52a595d4733210483e9689cb5d390
Author: Stefan Metzmacher 
Date:   Fri Feb 5 12:13:12 2021 +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 

[SCM] Socket Wrapper Repository - branch master updated

2021-02-03 Thread Andreas Schneider
The branch, master has been updated
   via  cd51d80 Bump version to 1.3.0
   via  e89968d doc: Add website to manpage
   via  b1d4e2d doc: Define doctype for manpage
   via  2c3a0b5 doc: Rename socket_wrapper.1.txt to socket_wrapper.1.adoc
  from  f69ed59 swrap: add basic support for fd-passing via SCM_RIGHTS

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit cd51d80946cdc938cea905b2242144f08ef2fec7
Author: Andreas Schneider 
Date:   Tue Feb 2 10:33:37 2021 +0100

Bump version to 1.3.0

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit e89968d2bef7b142462262f43c2ea7024a9ef8ab
Author: Andreas Schneider 
Date:   Tue Feb 2 10:30:04 2021 +0100

doc: Add website to manpage

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit b1d4e2d3a0450faa574e0466aa56d2d4788089db
Author: Andreas Schneider 
Date:   Tue Feb 2 10:28:59 2021 +0100

doc: Define doctype for manpage

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 2c3a0b5273e987cd582c0620e3cf2555d9ab8734
Author: Andreas Schneider 
Date:   Tue Feb 2 10:26:07 2021 +0100

doc: Rename socket_wrapper.1.txt to socket_wrapper.1.adoc

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CHANGELOG  |   5 +
 CMakeLists.txt |   6 +-
 doc/README |   6 +-
 doc/socket_wrapper.1   | 266 -
 ...{socket_wrapper.1.txt => socket_wrapper.1.adoc} |   6 +
 5 files changed, 166 insertions(+), 123 deletions(-)
 rename doc/{socket_wrapper.1.txt => socket_wrapper.1.adoc} (98%)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index 3e89c08..e0f7dd4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
 ChangeLog
 ==
 
+version 1.3.0 (released 2021-02-03)
+  * Added support for fd-passing via unix sockets
+  * Added (de)contructor support on AIX with pragma init/finish
+  * Fixed mutex fork handling
+
 version 1.2.5 (released 2020-06-22)
   * Added basic support for TCP_INFO and SIOCOUTQ/TIOCOUTQ/FIONWRITE
   * Add SOCKET_WRAPPER_DIR_ALLOW_ORIG and abort() early if
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6b1643c..d924cf5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.2.5 LANGUAGES C)
+project(socket_wrapper VERSION 1.3.0 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -24,8 +24,8 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 #   If the source code was changed, but there were no interface changes:
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
-set(LIBRARY_VERSION_MINOR 1)
-set(LIBRARY_VERSION_PATCH 15)
+set(LIBRARY_VERSION_MINOR 2)
+set(LIBRARY_VERSION_PATCH 0)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 
diff --git a/doc/README b/doc/README
index dbe07f7..6f43236 100644
--- a/doc/README
+++ b/doc/README
@@ -1,3 +1,7 @@
 The manpage is written with asciidoc. To generate the manpage use:
 
-a2x --doctype manpage --format manpage doc/socket_wrapper.1.txt
+asciidoctor -b manpage doc/socket_wrapper.1.adoc
+
+or
+
+a2x --format manpage doc/socket_wrapper.1.adoc
diff --git a/doc/socket_wrapper.1 b/doc/socket_wrapper.1
index 3bd171e..0272c63 100644
--- a/doc/socket_wrapper.1
+++ b/doc/socket_wrapper.1
@@ -1,50 +1,53 @@
 '\" t
 .\" Title: socket_wrapper
 .\"Author: Samba Team
-.\" Generator: DocBook XSL Stylesheets v1.79.1 
-.\"  Date: 2021-02-01
+.\" Generator: Asciidoctor 2.0.12
+.\"  Date: 2021-02-02
 .\"Manual: \ \&
 .\"Source: \ \&
 .\"  Language: English
 .\"
-.TH "SOCKET_WRAPPER" "1" "2021\-02\-01" "\ \&" "\ \&"
-.\" -
-.\" * Define some portability stuff
-.\" -
-.\" ~
-.\" http://bugs.debian.org/507673
-.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
-.\" ~
+.TH "SOCKET_WRAPPER" "1" "2021-02-02" "\ \&" "\ \&"
 .ie \n(.g .ds Aq \(aq
 .el   .ds Aq '
-.\" -
-.\" * set default formatting
-.\" -
-.\" disable hyphenation
+.ss \n[.ss] 0
 .nh
-.\" disable 

[SCM] Socket Wrapper Repository - branch master updated

2021-02-02 Thread Andreas Schneider
The branch, master has been updated
   via  f69ed59 swrap: add basic support for fd-passing via SCM_RIGHTS
   via  66a5bef tests: Add test for socket_wrapper fd-passing support
   via  650115f swrap: always check new fd's against socket_fds_max and use 
libc_close() for cleanup
   via  a79dec9 swrap: add const to swrap_add_socket_info()
   via  c740bbe swrap: let swrap_sendmsg_before_unix() create a copy of 
msg_tmp.msg_control
   via  de81995 swrap: add stubs for 
swrap_{sendmsg,recvmsg}_{before,after}_unix()
   via  e030a18 swrap: filter out SCM_{RIGHTS,CREDENTIALS} on inet socket
   via  00f61ed swrap: add error checking/cleanup to 
swrap_sendmsg_filter_cmsghdr()
   via  00650ff swrap: Fix MSGHDR check in sendmsg()
   via  5b2a982 swrap: print out SOCKET_WRAPPER_PACKAGE and 
SOCKET_WRAPPER_VERSION on first use
  from  ef90a76 src/socket_wrapper.c: Improve checks and debug output of 
socket_wrapper_dir()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f69ed59e64acac52c1f8b3f8c7a76c5db0bc5877
Author: Stefan Metzmacher 
Date:   Mon Jun 29 14:10:54 2020 +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 
Reviewed-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit 66a5bef7f9aac4d70124bc8efec72dcd434c660a
Author: Anoop C S 
Date:   Thu Jul 23 15:59:29 2020 +0530

tests: Add test for socket_wrapper fd-passing support

Signed-off-by: Anoop C S 
Reviewed-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 650115f1b4ed2fd4aa7d65ce7578bc919e0601f4
Author: Stefan Metzmacher 
Date:   Tue Jun 30 17:53:20 2020 +0200

swrap: always check new fd's against socket_fds_max and use libc_close() 
for cleanup

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit a79dec9866a0c42ff60c72ba04483818d4575127
Author: Stefan Metzmacher 
Date:   Tue Jun 30 17:51:29 2020 +0200

swrap: add const to swrap_add_socket_info()

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit c740bbe30affb7b94c6cca5f65a4e9047a1119ec
Author: Stefan Metzmacher 
Date:   Mon Jun 29 09:39:22 2020 +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 
Reviewed-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit de819958b00b48f285a1f31bfee1f8bee8e16827
Author: Stefan Metzmacher 
Date:   Mon Jun 29 09:27:24 2020 +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 
Reviewed-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit e030a1897873f3cb24e7d5a35adab421a9d11b9f
Author: Stefan Metzmacher 
Date:   Mon Jun 29 13:07:26 2020 +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 
Reviewed-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit 00f61edc7363cd17435b559beb04b567200fb38f
Author: Stefan Metzmacher 
Date:   Mon Jun 29 10:12:07 2020 +0200

swrap: add error checking/cleanup to swrap_sendmsg_filter_cmsghdr()

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit 00650ffb0b913010aab7a004fa2d3eadf2f2f007
Author: Anoop C S 
Date:   Wed May 22 10:45:37 2019 +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 
Reviewed-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit 5b2a98203bbb0230785a65429338b52bd377971b
Author: 

[SCM] Socket Wrapper Repository - branch master updated

2021-01-29 Thread Andreas Schneider
The branch, master has been updated
   via  ef90a76 src/socket_wrapper.c: Improve checks and debug output of 
socket_wrapper_dir()
   via  0f8e90d src/socket_wrapper.c: fix mutex fork handling
   via  c0fb86a gitlab-ci: Add job for ThreadSanitizer
   via  06e423d cmake: Add ThreadSanitizer compile flags
   via  a9d93c0 src/socket_wrapper.c: always go through 
swrap_bind_symbol_all() protected by pthread_once()
   via  5a76d73 src/socket_wrapper.c: split out _swrap_bind_symbol_generic()
   via  8c524f7 src/socket_wrapper.c: remove unused 
swrap_bind_symbol_libnsl()
  from  e0af87f socket_wrapper.c/tests: fall back to pragma init/fini for 
constructor/destructor if possible

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit ef90a761df3532ee45a05eb2c930769d40f5f093
Author: Andreas Schneider 
Date:   Thu Jan 28 20:06:11 2021 +0100

src/socket_wrapper.c: Improve checks and debug output of 
socket_wrapper_dir()

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 0f8e90dd7e59c473be615dee08d445dca98fdab9
Author: Stefan Metzmacher 
Date:   Tue Jan 26 13:14:41 2021 +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 

Signed-off-by: Stefan Metzmacher 
Signed-off-by: Andreas Schneider 

commit c0fb86a71418dc8610089434fda4effbc99b4c12
Author: Andreas Schneider 
Date:   Wed Feb 12 10:56:13 2020 +0100

gitlab-ci: Add job for ThreadSanitizer

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 06e423d0647c4a3915f8600c8ec7c8825f8f1e97
Author: Andreas Schneider 
Date:   Wed Feb 12 10:56:13 2020 +0100

cmake: Add ThreadSanitizer compile flags

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit a9d93c078a80bb301df3f811da7442f6e99edc68
Author: Stefan Metzmacher 
Date:   Thu Jan 28 14:31:31 2021 +0100

src/socket_wrapper.c: always go through swrap_bind_symbol_all() protected 
by pthread_once()

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 5a76d7304ca655b668ee0df9f35a801121fb8d8e
Author: Stefan Metzmacher 
Date:   Thu Jan 28 13:11:51 2021 +0100

src/socket_wrapper.c: split out _swrap_bind_symbol_generic()

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 8c524f7d35b649451888932b86a7118e99b02716
Author: Stefan Metzmacher 
Date:   Thu Jan 28 13:11:16 2021 +0100

src/socket_wrapper.c: remove unused swrap_bind_symbol_libnsl()

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 .gitlab-ci.yml  |  24 +++
 cmake/Modules/DefineCompilerFlags.cmake |  12 ++
 src/socket_wrapper.c| 298 
 tests/CMakeLists.txt|   9 +
 4 files changed, 194 insertions(+), 149 deletions(-)


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a28377d..c4dd3ce 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -77,6 +77,27 @@ fedora/undefined-sanitizer:
 paths:
   - obj/
 
+# realpath() doesn't work with libtsan and returns EINVAL
+#
+# fedora/thread-sanitizer:
+tumbleweed/thread-sanitizer:
+  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD
+  script:
+  - mkdir -p obj && cd obj && cmake
+-DCMAKE_BUILD_TYPE=ThreadSanitizer
+-DPICKY_DEVELOPER=ON
+-DUNIT_TESTING=ON .. &&
+make -j$(nproc) && ctest --output-on-failure
+  tags:
+  - shared
+  except:
+  - tags
+  artifacts:
+expire_in: 1 week
+when: on_failure
+paths:
+  - obj/
+
 fedora/csbuild:
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
   script:
@@ -225,6 +246,9 @@ tumbleweed/helgrind:
 when: on_failure
 paths:
   - obj/
+  only:
+variables:
+  - $VALGRIND_SUPPORTS_FORKED_MUTEXES == "yes"
 
 ubuntu/x86_64:
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$UBUNTU_BUILD
diff --git a/cmake/Modules/DefineCompilerFlags.cmake 
b/cmake/Modules/DefineCompilerFlags.cmake
index 3277b99..c92182d 100644
--- a/cmake/Modules/DefineCompilerFlags.cmake
+++ b/cmake/Modules/DefineCompilerFlags.cmake
@@ -34,4 +34,16 @@ if (UNIX AND NOT WIN32)
 CACHE STRING "Flags used by the linker during the creation of shared 
libraries during UNDEFINEDSANITIZER builds.")
 set(CMAKE_EXEC_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined"
 CACHE STRING "Flags used by the linker during UNDEFINEDSANITIZER 
builds.")

[SCM] Socket Wrapper Repository - branch master updated

2020-11-04 Thread Andreas Schneider
The branch, master has been updated
   via  e0af87f socket_wrapper.c/tests: fall back to pragma init/fini for 
constructor/destructor if possible
   via  83a4c3c configure: check for pragma init/fini for 
constructors/destructors
  from  3b6e207 Bump version to 1.2.5

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit e0af87fff246887aacab8c94c3cf4dca2a28a94c
Author: Björn Jacke 
Date:   Fri Oct 30 15:44:53 2020 +0100

socket_wrapper.c/tests: fall back to pragma init/fini for 
constructor/destructor if possible

Signed-off-by: Bjoern Jacke 
Reviewed-by: Andreas Schneider 

commit 83a4c3c3c53c6ab171ee786ba7c9f509d73f36fd
Author: Björn Jacke 
Date:   Fri Oct 30 15:31:42 2020 +0100

configure: check for pragma init/fini for constructors/destructors

Signed-off-by: Bjoern Jacke 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 ConfigureChecks.cmake   | 26 ++
 config.h.cmake  |  2 ++
 src/socket_wrapper.c|  7 +++
 tests/thread_deadlock.c |  5 -
 4 files changed, 39 insertions(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 4a2f55e..3c8e615 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -216,6 +216,32 @@ int main(void) {
 return 0;
 }" HAVE_DESTRUCTOR_ATTRIBUTE)
 
+check_c_source_compiles("
+#pragma init (test_constructor)
+void test_constructor(void);
+
+void test_constructor(void)
+{
+return;
+}
+
+int main(void) {
+return 0;
+}" HAVE_PRAGMA_INIT)
+
+check_c_source_compiles("
+#pragma fini (test_destructor)
+void test_destructor(void);
+
+void test_destructor(void)
+{
+return;
+}
+
+int main(void) {
+return 0;
+}" HAVE_PRAGMA_FINI)
+
 check_c_source_compiles("
 #define FALL_THROUGH __attribute__((fallthrough))
 
diff --git a/config.h.cmake b/config.h.cmake
index d3ceb23..38166d2 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -66,6 +66,8 @@
 #cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
 #cmakedefine HAVE_CONSTRUCTOR_ATTRIBUTE 1
 #cmakedefine HAVE_DESTRUCTOR_ATTRIBUTE 1
+#cmakedefine HAVE_PRAGMA_INIT 1
+#cmakedefine HAVE_PRAGMA_FINI 1
 #cmakedefine HAVE_FALLTHROUGH_ATTRIBUTE 1
 #cmakedefine HAVE_ADDRESS_SANITIZER_ATTRIBUTE 1
 #cmakedefine HAVE_SOCKADDR_STORAGE 1
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index ffdd31a..35d61b5 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -334,7 +334,14 @@ static pthread_mutex_t mtu_update_mutex;
 
 bool socket_wrapper_enabled(void);
 
+#if ! defined(HAVE_CONSTRUCTOR_ATTRIBUTE) && defined(HAVE_PRAGMA_INIT)
+/* xlC and other oldschool compilers support (only) this */
+#pragma init (swrap_constructor)
+#endif
 void swrap_constructor(void) CONSTRUCTOR_ATTRIBUTE;
+#if ! defined(HAVE_DESTRUCTOR_ATTRIBUTE) && defined(HAVE_PRAGMA_FINI)
+#pragma fini (swrap_destructor)
+#endif
 void swrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
 
 #ifndef HAVE_GETPROGNAME
diff --git a/tests/thread_deadlock.c b/tests/thread_deadlock.c
index b72367f..6c58af3 100644
--- a/tests/thread_deadlock.c
+++ b/tests/thread_deadlock.c
@@ -43,7 +43,10 @@
 #else
 #define CONSTRUCTOR_ATTRIBUTE
 #endif /* HAVE_CONSTRUCTOR_ATTRIBUTE */
-
+#if ! defined(HAVE_CONSTRUCTOR_ATTRIBUTE) && defined(HAVE_PRAGMA_INIT)
+/* xlC and other oldschool compilers support (only) this */
+#pragma init (thread_deadlock_constructor)
+#endif
 void thread_deadlock_constructor(void) CONSTRUCTOR_ATTRIBUTE;
 
 static void thread_deadlock_prepare(void)


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2020-06-22 Thread Andreas Schneider
The branch, master has been updated
   via  3b6e207 Bump version to 1.2.5
  from  b94af54 socket_wrapper.c: let swrap_vioctl() handle 
SIOCOUTQ/TIOCOUTQ/FIONWRITE explicitly

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 3b6e2078e07cf379b5a65edb5e967d4f7c7b9e0a
Author: Andreas Schneider 
Date:   Mon Jun 22 16:53:36 2020 +0200

Bump version to 1.2.5

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CHANGELOG  | 5 +
 CMakeLists.txt | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CHANGELOG b/CHANGELOG
index bdb152d..3e89c08 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
 ChangeLog
 ==
 
+version 1.2.5 (released 2020-06-22)
+  * Added basic support for TCP_INFO and SIOCOUTQ/TIOCOUTQ/FIONWRITE
+  * Add SOCKET_WRAPPER_DIR_ALLOW_ORIG and abort() early if
+SOCKET_WRAPPER_DIR is unusable
+
 version 1.2.4 (released 2020-03-24)
   * Added support for 10.53.57.0 network
   * Added _{socket,close,connect,...} symbols on FreeBSD
diff --git a/CMakeLists.txt b/CMakeLists.txt
index db799ac..6b1643c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.2.4 LANGUAGES C)
+project(socket_wrapper VERSION 1.2.5 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -25,7 +25,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment PATCH.
 set(LIBRARY_VERSION_MAJOR 0)
 set(LIBRARY_VERSION_MINOR 1)
-set(LIBRARY_VERSION_PATCH 14)
+set(LIBRARY_VERSION_PATCH 15)
 set(LIBRARY_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
 set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR})
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2020-06-22 Thread Stefan Metzmacher
The branch, master has been updated
   via  b94af54 socket_wrapper.c: let swrap_vioctl() handle 
SIOCOUTQ/TIOCOUTQ/FIONWRITE explicitly
   via  64cee56 socket_wrapper.c: make FIONREAD handling more robust in 
swrap_vioctl()
   via  309103f test_echo_tcp_socket_options.c: add tests for TCP_INFO
   via  c73d8a4 socket_wrapper.c: implement getsockopt(TCP_INFO) if the 
platform supports it
   via  1c20b95 doc: Document SOCKET_WRAPPER_DIR_ALLOW_ORIG
   via  19c3e87 swrap: Add SOCKET_WRAPPER_DIR_ALLOW_ORIG to allow fall back
   via  dd42895 swrap: Abort if socket wrapper directory is too long to be 
usable
   via  fc1e98f swrap: Add abstractions to construct Unix domain socket 
paths
   via  80e0f42 swrap: Abort on failure to use SOCKET_WRAPPER_DIR
  from  49aeafa Revert "socket_wrapper.c: implement getsockopt(TCP_INFO) if 
the platform supports it"

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit b94af548f42e561207db7cacbe09c9e3286de2d3
Author: Stefan Metzmacher 
Date:   Mon Jun 8 14:21:25 2020 +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 
Reviewed-by: Andreas Schneider 
(cherry picked from commit f317ebcdcdd626ed9e06de2eb60031306994c803)

commit 64cee569a77e9d9d92e0dc0d2793536c9fb4a45e
Author: Stefan Metzmacher 
Date:   Mon Jun 8 14:18:44 2020 +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 
Reviewed-by: Andreas Schneider 
(cherry picked from commit c95b7cb1d7b9348472276edceff71889aa676d25)

commit 309103f464af19d6190f89de959c6dc41ba58c85
Author: Stefan Metzmacher 
Date:   Fri Jun 19 20:52:23 2020 +0200

test_echo_tcp_socket_options.c: add tests for TCP_INFO

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 
(cherry picked from commit a37c0175492fb1b35257b785c71dea4e4f6d4750)

commit c73d8a43c07ffbd9f4a7010b99363ffa53b4723c
Author: Stefan Metzmacher 
Date:   Mon Jun 8 10:32:28 2020 +0200

socket_wrapper.c: implement getsockopt(TCP_INFO) if the platform supports it

This just implements a few basics, which are required by Samba.

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

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 
(cherry picked from commit 300de6e099ea82ee5361918de8c3abb389e0782d)

commit 1c20b9596422c9cb92fc539493df45b03d91457b
Author: Martin Schwenke 
Date:   Thu May 14 09:57:24 2020 +1000

doc: Document SOCKET_WRAPPER_DIR_ALLOW_ORIG

Signed-off-by: Martin Schwenke 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 19c3e87570954cb7fb4f6c105cbec9eabf4539b0
Author: Martin Schwenke 
Date:   Thu May 14 10:01:54 2020 +1000

swrap: Add SOCKET_WRAPPER_DIR_ALLOW_ORIG to allow fall back

Instead of failing when the path returned by realpath(3) is too long,
if SOCKET_WRAPPER_DIR_ALLOW_ORIG is set then fall back to the
original value.  If this original path is too long or something else
fails then abort.

Signed-off-by: Martin Schwenke 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit dd428959713998d3f973bcf2762d489ef27d9f13
Author: Martin Schwenke 
Date:   Wed May 13 13:45:02 2020 +1000

swrap: Abort if socket wrapper directory is too long to be usable

If the socket wrapper directory path is too long to allow reliable
construction of the required Unix domain socket paths then
convert_in_un_alloc() can return ENFILE if paths are truncated in
unfortunate ways.  This can be very hard to debug since, for example,
bind(2) should never return ENFILE.

Instead, abort if the path returned by realpath(3) is unusable.

The code structure is slightly weird but this accommodates an
additional change.

Signed-off-by: Martin Schwenke 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit fc1e98f8ca51ca4de7551e61b6b9c6c99d183b10
Author: Martin Schwenke 
Date:   Wed May 13 13:23:21 2020 +1000

swrap: Add abstractions to construct Unix domain socket paths

These include overflow checks but the results of the checks are not
yet used.

Signed-off-by: Martin Schwenke 
Reviewed-by: Andreas Schneider 

[SCM] Socket Wrapper Repository - branch master updated

2020-06-19 Thread Stefan Metzmacher
The branch, master has been updated
   via  49aeafa Revert "socket_wrapper.c: implement getsockopt(TCP_INFO) if 
the platform supports it"
   via  a6f95ed Revert "test_echo_tcp_socket_options.c: add tests for 
TCP_INFO"
   via  f13db2b Revert "socket_wrapper.c: make FIONREAD handling more 
robust in swrap_vioctl()"
   via  22cfac3 Revert "socket_wrapper.c: let swrap_vioctl() handle 
SIOCOUTQ/TIOCOUTQ/FIONWRITE explicitly"
   via  f4fc52b Merge branch 'tcp_info' into 'master'
   via  f317ebc socket_wrapper.c: let swrap_vioctl() handle 
SIOCOUTQ/TIOCOUTQ/FIONWRITE explicitly
   via  c95b7cb socket_wrapper.c: make FIONREAD handling more robust in 
swrap_vioctl()
   via  a37c017 test_echo_tcp_socket_options.c: add tests for TCP_INFO
   via  300de6e socket_wrapper.c: implement getsockopt(TCP_INFO) if the 
platform supports it
  from  bbc1d65 tests: do not truncate pid to 16 bits

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 49aeafa2c530e35a43358977766899d45a0c8b28
Author: Stefan Metzmacher 
Date:   Fri Jun 19 23:26:28 2020 +0200

Revert "socket_wrapper.c: implement getsockopt(TCP_INFO) if the platform 
supports it"

This reverts commit 300de6e099ea82ee5361918de8c3abb389e0782d.

This got merged automatically by gitlab without review.

Signed-off-by: Stefan Metzmacher 

commit a6f95ed59e2bc5a5d732738be7046e1e8422fb26
Author: Stefan Metzmacher 
Date:   Fri Jun 19 23:26:25 2020 +0200

Revert "test_echo_tcp_socket_options.c: add tests for TCP_INFO"

This reverts commit a37c0175492fb1b35257b785c71dea4e4f6d4750.

This got merged automatically by gitlab without review.

Signed-off-by: Stefan Metzmacher 

commit f13db2b166dd9cc0ee31b5cdffdacb34945d615a
Author: Stefan Metzmacher 
Date:   Fri Jun 19 23:26:22 2020 +0200

Revert "socket_wrapper.c: make FIONREAD handling more robust in 
swrap_vioctl()"

This reverts commit c95b7cb1d7b9348472276edceff71889aa676d25.

This got merged automatically by gitlab without review.

Signed-off-by: Stefan Metzmacher 

commit 22cfac3bfca20eedbd0e3e428f085b24fb553047
Author: Stefan Metzmacher 
Date:   Fri Jun 19 23:25:40 2020 +0200

Revert "socket_wrapper.c: let swrap_vioctl() handle 
SIOCOUTQ/TIOCOUTQ/FIONWRITE explicitly"

This reverts commit f317ebcdcdd626ed9e06de2eb60031306994c803.

This got merged automatically by gitlab without review.

Signed-off-by: Stefan Metzmacher 

commit f4fc52be79edc74bd24b3ee968c5358af81b17bd
Merge: bbc1d65 f317ebc
Author: Stefan Metzmacher 
Date:   Fri Jun 19 21:07:09 2020 +

Merge branch 'tcp_info' into 'master'

Add support for TCP_INFO and SIOCOUTQ/TIOCOUTQ/FIONWRITE

See merge request cwrap/socket_wrapper!11

commit f317ebcdcdd626ed9e06de2eb60031306994c803
Author: Stefan Metzmacher 
Date:   Mon Jun 8 14:21:25 2020 +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 

commit c95b7cb1d7b9348472276edceff71889aa676d25
Author: Stefan Metzmacher 
Date:   Mon Jun 8 14:18:44 2020 +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 

commit a37c0175492fb1b35257b785c71dea4e4f6d4750
Author: Stefan Metzmacher 
Date:   Fri Jun 19 20:52:23 2020 +0200

test_echo_tcp_socket_options.c: add tests for TCP_INFO

Signed-off-by: Stefan Metzmacher 

commit 300de6e099ea82ee5361918de8c3abb389e0782d
Author: Stefan Metzmacher 
Date:   Mon Jun 8 10:32:28 2020 +0200

socket_wrapper.c: implement getsockopt(TCP_INFO) if the platform supports it

This just implements a few basics, which are required by Samba.

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

Signed-off-by: Stefan Metzmacher 

---

Summary of changes:


Changeset truncated at 500 lines:



-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2020-05-14 Thread Andreas Schneider
The branch, master has been updated
   via  bbc1d65 tests: do not truncate pid to 16 bits
  from  f6a10e2 swrap: Remove extra new line towards end of SWRAP_LOG()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit bbc1d654cae9197fa3782e8ea8e1aaa9fdf0cfb0
Author: Mike Gilbert 
Date:   Thu May 7 23:28:50 2020 -0400

tests: do not truncate pid to 16 bits

On Linux, pid_t is a 32-bit type, and the kernel permits pids up to 22
bits in length.

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

Signed-off-by: Mike Gilbert 
Reviewed-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 tests/torture.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)


Changeset truncated at 500 lines:

diff --git a/tests/torture.c b/tests/torture.c
index e55ebcf..595f504 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -255,8 +255,7 @@ void torture_teardown_socket_dir(void **state)
 void torture_teardown_echo_srv(void **state)
 {
struct torture_state *s = *state;
-   char buf[8] = {0};
-   long int tmp;
+   char buf[12] = {0}; /* -2147483648 + null byte */
ssize_t rc;
pid_t pid;
int fd;
@@ -277,13 +276,12 @@ void torture_teardown_echo_srv(void **state)
 
buf[sizeof(buf) - 1] = '\0';
 
-   tmp = strtol(buf, NULL, 10);
-   if (tmp == 0 || tmp > 0x || errno == ERANGE) {
+   errno = 0;
+   pid = strtol(buf, NULL, 10);
+   if (pid == 0 || errno != 0) {
goto done;
}
 
-   pid = (pid_t)(tmp & 0x);
-
for (count = 0; count < 10; count++) {
/* Make sure the daemon goes away! */
kill(pid, SIGTERM);


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2020-05-14 Thread Andreas Schneider
The branch, master has been updated
   via  f6a10e2 swrap: Remove extra new line towards end of SWRAP_LOG()
  from  6799f13 Bump version to 1.2.4

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f6a10e2a4a34662b11430aecf3eea7b6b3bf844f
Author: Anoop C S 
Date:   Tue Apr 7 14:23:09 2020 +0530

swrap: Remove extra new line towards end of SWRAP_LOG()

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 src/socket_wrapper.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index cee7c51..5b7c9ea 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -658,7 +658,7 @@ static void *swrap_load_lib_handle(enum swrap_lib lib)
handle = swrap.libc.handle = swrap.libc.socket_handle = 
RTLD_NEXT;
 #else
SWRAP_LOG(SWRAP_LOG_ERROR,
- "Failed to dlopen library: %s\n",
+ "Failed to dlopen library: %s",
  dlerror());
exit(-1);
 #endif
@@ -677,7 +677,7 @@ static void *_swrap_bind_symbol(enum swrap_lib lib, const 
char *fn_name)
func = dlsym(handle, fn_name);
if (func == NULL) {
SWRAP_LOG(SWRAP_LOG_ERROR,
- "Failed to find %s: %s\n",
+ "Failed to find %s: %s",
  fn_name,
  dlerror());
exit(-1);
@@ -1221,7 +1221,7 @@ static in_addr_t swrap_ipv4_net(void)
ret = inet_pton(AF_INET, net_str, );
if (ret <= 0) {
SWRAP_LOG(SWRAP_LOG_ERROR,
- "INVALID IPv4 Network [%s]\n",
+ "INVALID IPv4 Network [%s]",
  net_str);
abort();
}
@@ -1238,7 +1238,7 @@ static in_addr_t swrap_ipv4_net(void)
default:
SWRAP_LOG(SWRAP_LOG_ERROR,
  "INVALID IPv4 Network [%s][0x%x] should be "
- "127.0.0.0 or 10.53.57.0\n",
+ "127.0.0.0 or 10.53.57.0",
  net_str, (unsigned)hv);
abort();
}
@@ -1268,7 +1268,7 @@ static in_addr_t swrap_ipv4_iface(unsigned int iface)
 
if (iface == 0 || iface > MAX_WRAPPED_INTERFACES) {
SWRAP_LOG(SWRAP_LOG_ERROR,
- "swrap_ipv4_iface(%u) invalid!\n",
+ "swrap_ipv4_iface(%u) invalid!",
  iface);
abort();
return -1;
@@ -1376,7 +1376,7 @@ static char *socket_wrapper_dir(void)
char *s = getenv("SOCKET_WRAPPER_DIR");
 
if (s == NULL) {
-   SWRAP_LOG(SWRAP_LOG_WARN, "SOCKET_WRAPPER_DIR not set\n");
+   SWRAP_LOG(SWRAP_LOG_WARN, "SOCKET_WRAPPER_DIR not set");
return NULL;
}
 
@@ -1631,7 +1631,7 @@ static unsigned int socket_wrapper_default_iface(void)
 static void set_socket_info_index(int fd, int idx)
 {
SWRAP_LOG(SWRAP_LOG_TRACE,
- "fd=%d idx=%d\n",
+ "fd=%d idx=%d",
  fd, idx);
socket_fds_idx[fd] = idx;
/* This builtin issues a full memory barrier. */
@@ -1641,7 +1641,7 @@ static void set_socket_info_index(int fd, int idx)
 static void reset_socket_info_index(int fd)
 {
SWRAP_LOG(SWRAP_LOG_TRACE,
- "fd=%d idx=%d\n",
+ "fd=%d idx=%d",
  fd, -1);
set_socket_info_index(fd, -1);
 }
@@ -1844,7 +1844,7 @@ static int convert_in_un_remote(struct socket_info *si, 
const struct sockaddr *i
b_type = SOCKET_TYPE_CHAR_UDP;
break;
default:
-   SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n");
+   SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!");
errno = ESOCKTNOSUPPORT;
return -1;
}
@@ -1891,7 +1891,7 @@ static int convert_in_un_remote(struct socket_info *si, 
const struct sockaddr *i
type = SOCKET_TYPE_CHAR_UDP_V6;
break;
default:
-   SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n");
+   SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!");
errno = ESOCKTNOSUPPORT;
return -1;
}
@@ -1914,13 +1914,13 @@ static int convert_in_un_remote(struct socket_info *si, 
const struct sockaddr *i
}
 #endif
default:
-   SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown 

[SCM] Socket Wrapper Repository - branch master updated

2020-03-24 Thread Andreas Schneider
The branch, master has been updated
   via  6799f13 Bump version to 1.2.4
   via  a984d2e Rename CHANGELOG
   via  e7a70b8 gitlab-ci: Add ubuntu runner
   via  2e862a0 gitlab-ci: Remove debian cross mips build
   via  2ba55b1 tests: Fix a compile warning on Ubuntu
   via  43578b9 tests: Fix a coverty warning in echo_srv
  from  7bced01 swrap: add support for 
SOCKET_WRAPPER_IPV4_NETWORK=10.53.57.0

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 6799f13f5f34f6feabeb08573da8c4c04ccc70a8
Author: Andreas Schneider 
Date:   Mon Mar 23 09:47:32 2020 +0100

Bump version to 1.2.4

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit a984d2e5142b788aab8bf0dc158a063295eb8bcb
Author: Andreas Schneider 
Date:   Mon Mar 23 09:14:06 2020 +0100

Rename CHANGELOG

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit e7a70b862f497b262350e9e3eee8f458d1ead8fc
Author: Andreas Schneider 
Date:   Tue Mar 24 08:44:20 2020 +0100

gitlab-ci: Add ubuntu runner

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 2e862a0bddb19e84bec689929a72260213c2357c
Author: Andreas Schneider 
Date:   Tue Mar 24 08:54:59 2020 +0100

gitlab-ci: Remove debian cross mips build

This isn't supported by Debian anymore.

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 2ba55b1f7f4d476ef7ba85f3f171b6d0881096ab
Author: Andreas Schneider 
Date:   Tue Mar 24 08:53:55 2020 +0100

tests: Fix a compile warning on Ubuntu

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 43578b9a28184086cbdef4a257db808e2992b162
Author: Andreas Schneider 
Date:   Mon Mar 23 09:13:20 2020 +0100

tests: Fix a coverty warning in echo_srv

CID #288875

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 .gitlab-ci.yml| 44 +--
 ChangeLog => CHANGELOG|  5 +
 CMakeLists.txt| 17 ---
 tests/echo_srv.c  |  4 +++-
 tests/test_fork_thread_deadlock.c |  4 +++-
 5 files changed, 40 insertions(+), 34 deletions(-)
 rename ChangeLog => CHANGELOG (93%)


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 66855ca..a28377d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,7 +4,7 @@ variables:
   CENTOS7_BUILD: buildenv-centos7
   TUMBLEWEED_BUILD: buildenv-tumbleweed
   MINGW_BUILD: buildenv-mingw
-  DEBIAN_CROSS_BUILD: buildenv-debian-cross
+  UBUNTU_BUILD: buildenv-ubuntu
 
 centos7/x86_64:
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$CENTOS7_BUILD
@@ -130,30 +130,6 @@ freebsd/x86_64:
 paths:
   - obj/
 
-.Debian.cross.template: _cross_template
-  stage: test
-  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_CROSS_BUILD
-  script:
-  - build=$(dpkg-architecture -qDEB_HOST_GNU_TYPE)
-  - host="${CI_JOB_NAME#*.cross.}"
-  - mkdir -p obj && cd obj && cmake
--DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Debian-mips.cmake
--DCMAKE_BUILD_TYPE=RelWithDebInfo
--DUNIT_TESTING=ON .. && make -j$(nproc) &&
-ctest --output-on-failure
-  tags:
-  - shared
-  except:
-  - tags
-  artifacts:
-expire_in: 1 week
-when: on_failure
-paths:
-  - obj/
-
-Debian.cross.mips-linux-gnu:
-  <<: *Debian_cross_template
-
 tumbleweed/x86_64/gcc:
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD
   script:
@@ -249,3 +225,21 @@ tumbleweed/helgrind:
 when: on_failure
 paths:
   - obj/
+
+ubuntu/x86_64:
+  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$UBUNTU_BUILD
+  script:
+  - mkdir -p obj && cd obj && cmake
+-DCMAKE_BUILD_TYPE=RelWithDebInfo
+-DPICKY_DEVELOPER=ON
+-DUNIT_TESTING=ON .. &&
+make -j$(nproc) && ctest --output-on-failure
+  tags:
+  - shared
+  except:
+  - tags
+  artifacts:
+expire_in: 1 week
+when: on_failure
+paths:
+  - obj/
diff --git a/ChangeLog b/CHANGELOG
similarity index 93%
rename from ChangeLog
rename to CHANGELOG
index 04a4245..bdb152d 100644
--- a/ChangeLog
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
 ChangeLog
 ==
 
+version 1.2.4 (released 2020-03-24)
+  * Added support for 10.53.57.0 network
+  * Added _{socket,close,connect,...} symbols on FreeBSD
+  * Fixed interaction with resolv_wrapper on FreeBSD
+
 version 1.2.3 (released 2019-03-21)
   * Fixed missing NULL check for socket_wrapper_dir()
   * Fixes building in Samba source tree
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ef14e57..db799ac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,20 +11,23 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 

[SCM] Socket Wrapper Repository - branch master updated

2020-03-21 Thread Andreas Schneider
The branch, master has been updated
   via  7bced01 swrap: add support for 
SOCKET_WRAPPER_IPV4_NETWORK=10.53.57.0
   via  eb5bd0b swrap: implement swrap_ipv4_{net,bcast,iface}() helper 
functions
   via  6662fef doc/socket_wrapper.1: clarify the possible values for 
SOCKET_WRAPPER_DEFAULT_IFACE
   via  010e98c gitlab-ci: Whitelist metze to use the FreeBSD runner
  from  c212bf0 swrap: provide _{socket,close,connect,...} symbols on 
FreeBSD

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 7bced01e89a16e673794e83dc984967aaddb558c
Author: Stefan Metzmacher 
Date:   Wed Jan 23 19:41:36 2019 +0100

swrap: add support for SOCKET_WRAPPER_IPV4_NETWORK=10.53.57.0

With this 10.53.57.XX/8 addresses are used instead of
127.0.0.XX/8. Note the broadcast address is 127.255.255.255
or 10.255.255.255 (and not 10.53.57.255!).

Some applications, e.g. Samba have some special behavior for
loopback addresses.

This allows more realistic tests and triggers the more common
code paths.

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit eb5bd0bc2128cdea5f5ef0fc20fb0af28fb3f6c1
Author: Stefan Metzmacher 
Date:   Wed Jan 23 19:41:36 2019 +0100

swrap: implement swrap_ipv4_{net,bcast,iface}() helper functions

This makes it easier to implement SOCKET_WRAPPER_IPV4_NETWORK in
the next step.

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 6662fefad5104c8ccca16abf3bcc8afa96ccd0ca
Author: Stefan Metzmacher 
Date:   Fri Mar 20 10:28:04 2020 +0100

doc/socket_wrapper.1: clarify the possible values for 
SOCKET_WRAPPER_DEFAULT_IFACE

The valid range for  starts with 1 (the default) and ends with 64.

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 010e98c88890837de687f0dc4345375d4b800d4a
Author: Andreas Schneider 
Date:   Sat Mar 21 10:02:40 2020 +0100

gitlab-ci: Whitelist metze to use the FreeBSD runner

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 .gitlab-ci.yml   |   1 +
 doc/socket_wrapper.1 |   7 ++-
 doc/socket_wrapper.1.txt |  24 ++---
 src/socket_wrapper.c | 124 ++-
 4 files changed, 138 insertions(+), 18 deletions(-)


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 365d834..66855ca 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -123,6 +123,7 @@ freebsd/x86_64:
   only:
   - branches@cwrap/socket_wrapper
   - branches@cryptomilk/socket_wrapper
+  - branches@metze/socket_wrapper
   artifacts:
 expire_in: 1 week
 when: on_failure
diff --git a/doc/socket_wrapper.1 b/doc/socket_wrapper.1
index 9f3f75a..e244f10 100644
--- a/doc/socket_wrapper.1
+++ b/doc/socket_wrapper.1
@@ -75,9 +75,14 @@ Ability to capture network traffic in pcap format\&.
 The user defines a directory where to put all the unix sockets using the 
environment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir"\&. When a server 
opens a port or a client wants to connect, socket_wrapper will translate IP 
addresses to a special socket_wrapper name and look for the relevant Unix 
socket in the SOCKET_WRAPPER_DIR\&.
 .RE
 .PP
+\fBSOCKET_WRAPPER_IPV4_NETWORK\fR
+.RS 4
+By default the loopback IPv4 network "127\&.0\&.0\&.0/8" and the 
"127\&.0\&.0\&.x" can be used\&. In order to make more realistic testing 
possible it is possible to use the "10\&.0\&.0\&.0/8" IPv4 network instead\&. 
But note within "10\&.0\&.0\&.0/8" only "10\&.53\&.57\&." can be used, but 
the broadcast address is "10\&.255\&.255\&.255"\&. The following two value are 
allowed: SOCKET_WRAPPER_IPV4_NETWORK="127\&.0\&.0\&.0" (the default) and 
SOCKET_WRAPPER_IPV4_NETWORK="10\&.53\&.57\&.0"\&.
+.RE
+.PP
 \fBSOCKET_WRAPPER_DEFAULT_IFACE\fR
 .RS 4
-Additionally, the default interface to be used by an application is defined 
with "SOCKET_WRAPPER_DEFAULT_IFACE=" where  is between 2 and 254\&. 
This is analogous to use the IPv4 addresses "127\&.0\&.0\&." or IPv6 
addresses "fd00::5357:5f" (where  is a hexadecimal presentation of 
)\&. You should always set the default interface\&. If you listen on 
INADDR_ANY then it will use the default interface to listen on\&.
+Additionally, the default interface to be used by an application is defined 
with "SOCKET_WRAPPER_DEFAULT_IFACE=" where the valid range for  starts 
with 1 (the default) and ends with 64\&. This is analogous to use the IPv4 
addresses "127\&.0\&.0\&."/"10\&.53\&.57\&." or IPv6 addresses 
"fd00::5357:5f" (where  is a hexadecimal presentation of )\&. You 
should always set the default interface\&. If you listen on INADDR_ANY then it 
will use the default interface to listen on\&.
 .RE
 .PP
 

[SCM] Socket Wrapper Repository - branch master updated

2020-03-19 Thread Andreas Schneider
The branch, master has been updated
   via  c212bf0 swrap: provide _{socket,close,connect,...} symbols on 
FreeBSD
   via  7a9f807 swrap: detect stale fd for socket(PF_UNIX) and accept()
   via  d23452b swrap: trace the SOCKET_WRAPPER_PCAP_FILE location
  from  344801f swrap: Do not leak buf in swrap_sendmsg()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit c212bf0d976bcb70426a506c3e7d250644598b38
Author: Stefan Metzmacher 
Date:   Wed Mar 18 08:55:23 2020 +0100

swrap: provide _{socket,close,connect,...} symbols on FreeBSD

Maybe that's not FreeBSD only, but at least this fixes the interaction
of resolv_wrapper and socket_wrapper on FreeBSD 12.

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 7a9f807302e0ddb1579b5db2c3772bb23f44b04e
Author: Stefan Metzmacher 
Date:   Thu Feb 27 16:47:35 2020 +

swrap: detect stale fd for socket(PF_UNIX) and accept()

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit d23452ba4ec64c5be89864a8bd31d6ee2053be46
Author: Stefan Metzmacher 
Date:   Wed Mar 11 17:10:05 2020 +0100

swrap: trace the SOCKET_WRAPPER_PCAP_FILE location

Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 ConfigureChecks.cmake |  4 +--
 config.h.cmake|  2 ++
 src/socket_wrapper.c  | 75 ++-
 3 files changed, 78 insertions(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 81aaa1c..4d5adc4 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -70,9 +70,9 @@ check_function_exists(open64 HAVE_OPEN64)
 check_function_exists(fopen64 HAVE_FOPEN64)
 check_function_exists(getprogname HAVE_GETPROGNAME)
 check_function_exists(getexecname HAVE_GETEXECNAME)
-
 check_function_exists(pledge HAVE_PLEDGE)
-
+check_function_exists(_socket HAVE__SOCKET)
+check_function_exists(_close HAVE__CLOSE)
 
 if (UNIX)
 find_library(DLFCN_LIBRARY dl)
diff --git a/config.h.cmake b/config.h.cmake
index 3c0cf01..36050b5 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -44,6 +44,8 @@
 #cmakedefine HAVE_GETPROGNAME 1
 #cmakedefine HAVE_GETEXECNAME 1
 #cmakedefine HAVE_PLEDGE 1
+#cmakedefine HAVE__SOCKET 1
+#cmakedefine HAVE__CLOSE 1
 
 #cmakedefine HAVE_ACCEPT_PSOCKLEN_T 1
 #cmakedefine HAVE_IOCTL_INT 1
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a9e2a75..bd15793 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1536,6 +1536,9 @@ static unsigned int socket_wrapper_default_iface(void)
 
 static void set_socket_info_index(int fd, int idx)
 {
+   SWRAP_LOG(SWRAP_LOG_TRACE,
+ "fd=%d idx=%d\n",
+ fd, idx);
socket_fds_idx[fd] = idx;
/* This builtin issues a full memory barrier. */
__sync_synchronize();
@@ -1543,6 +1546,9 @@ static void set_socket_info_index(int fd, int idx)
 
 static void reset_socket_info_index(int fd)
 {
+   SWRAP_LOG(SWRAP_LOG_TRACE,
+ "fd=%d idx=%d\n",
+ fd, -1);
set_socket_info_index(fd, -1);
 }
 
@@ -2455,6 +2461,7 @@ static const char *swrap_pcap_init_file(void)
if (strncmp(s, "./", 2) == 0) {
s += 2;
}
+   SWRAP_LOG(SWRAP_LOG_TRACE, "SOCKET_WRAPPER_PCAP_FILE: %s", s);
return s;
 }
 
@@ -3140,7 +3147,15 @@ static int swrap_socket(int family, int type, int 
protocol)
case AF_PACKET:
 #endif /* AF_PACKET */
case AF_UNIX:
-   return libc_socket(family, type, protocol);
+   fd = libc_socket(family, type, protocol);
+   if (fd != -1) {
+   /* Check if we have a stale fd and remove it */
+   swrap_remove_stale(fd);
+   SWRAP_LOG(SWRAP_LOG_TRACE,
+ "Unix socket fd=%d",
+ fd);
+   }
+   return fd;
default:
errno = EAFNOSUPPORT;
return -1;
@@ -3384,6 +3399,9 @@ static int swrap_accept(int s,
 
fd = ret;
 
+   /* Check if we have a stale fd and remove it */
+   swrap_remove_stale(fd);
+
SWRAP_LOCK_SI(parent_si);
 
ret = sockaddr_convert_from_un(parent_si,
@@ -3666,6 +3684,9 @@ static int swrap_connect(int s, const struct sockaddr 
*serv_addr,
}
 
if (si->family != serv_addr->sa_family) {
+   SWRAP_LOG(SWRAP_LOG_ERROR,
+ "called for fd=%d (family=%d) called with invalid 
family=%d\n",
+ s, si->family, serv_addr->sa_family);
errno = EINVAL;
ret = -1;
goto done;
@@ -6076,6 +6097,7 @@ static 

[SCM] Socket Wrapper Repository - branch master updated

2019-03-21 Thread Andreas Schneider
The branch, master has been updated
   via  344801f swrap: Do not leak buf in swrap_sendmsg()
  from  44d9c59 Bump version to 1.2.3

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 344801fda7b2b50b1139056168b470ad656c20b5
Author: Andreas Schneider 
Date:   Thu Mar 21 14:59:30 2019 +0100

swrap: Do not leak buf in swrap_sendmsg()

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 src/socket_wrapper.c | 1 +
 1 file changed, 1 insertion(+)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 5b82e0c..a9e2a75 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5910,6 +5910,7 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr 
*omsg, int flags)
 
swrap_dir = socket_wrapper_dir();
if (swrap_dir == NULL) {
+   free(buf);
return -1;
}
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2019-03-21 Thread Andreas Schneider
The branch, master has been updated
   via  44d9c59 Bump version to 1.2.3
   via  51d8982 swrap: Add missing NULL checks to socket_wrapper_dir()
   via  b8dc4da swrap: Print a warning if SOCKET_WRAPPER_DIR is not set
  from  a3a3dca Bump version to 1.2.2

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 44d9c597963c49b739c40f6364b7882eb890f194
Author: Andreas Schneider 
Date:   Thu Mar 21 14:18:12 2019 +0100

Bump version to 1.2.3

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 51d8982627f0da1715d196fd75ec17d6579a57b0
Author: Andreas Schneider 
Date:   Thu Mar 21 14:09:37 2019 +0100

swrap: Add missing NULL checks to socket_wrapper_dir()

This return either malloc'ed memory or NULL. Make sure there is no
problem.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit b8dc4da6cb4903fce8f7b468c17caf12e3394c6b
Author: Andreas Schneider 
Date:   Thu Mar 21 14:09:19 2019 +0100

swrap: Print a warning if SOCKET_WRAPPER_DIR is not set

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 CMakeLists.txt   |  4 ++--
 ChangeLog|  4 
 src/socket_wrapper.c | 20 
 3 files changed, 26 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ab7254c..ef14e57 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.2.2 LANGUAGES C)
+project(socket_wrapper VERSION 1.2.3 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -23,7 +23,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION "0.1.12")
+set(LIBRARY_VERSION "0.1.13")
 set(LIBRARY_SOVERSION "0")
 
 # add definitions
diff --git a/ChangeLog b/ChangeLog
index d0a7285..04a4245 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
 ChangeLog
 ==
 
+version 1.2.3 (released 2019-03-21)
+  * Fixed missing NULL check for socket_wrapper_dir()
+  * Fixes building in Samba source tree
+
 version 1.2.2 (released 2019-03-21)
   * Added environment variable to disable deep binding
   * Fixed installation of socket_wrapper
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 7841c85..5b82e0c 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1288,6 +1288,7 @@ static char *socket_wrapper_dir(void)
char *s = getenv("SOCKET_WRAPPER_DIR");
 
if (s == NULL) {
+   SWRAP_LOG(SWRAP_LOG_WARN, "SOCKET_WRAPPER_DIR not set\n");
return NULL;
}
 
@@ -1818,6 +1819,10 @@ static int convert_in_un_remote(struct socket_info *si, 
const struct sockaddr *i
}
 
swrap_dir = socket_wrapper_dir();
+   if (swrap_dir == NULL) {
+   errno = EINVAL;
+   return -1;
+   }
 
if (is_bcast) {
snprintf(un->sun_path, sizeof(un->sun_path),
@@ -1988,6 +1993,10 @@ static int convert_in_un_alloc(struct socket_info *si, 
const struct sockaddr *in
}
 
swrap_dir = socket_wrapper_dir();
+   if (swrap_dir == NULL) {
+   errno = EINVAL;
+   return -1;
+   }
 
if (prt == 0) {
/* handle auto-allocation of ephemeral ports */
@@ -3582,6 +3591,11 @@ static int swrap_auto_bind(int fd, struct socket_info 
*si, int family)
}
 
swrap_dir = socket_wrapper_dir();
+   if (swrap_dir == NULL) {
+   errno = EINVAL;
+   ret = -1;
+   goto done;
+   }
 
for (i = 0; i < SOCKET_MAX_SOCKETS; i++) {
port = autobind_start + i;
@@ -5387,6 +5401,9 @@ static ssize_t swrap_sendto(int s, const void *buf, 
size_t len, int flags,
type = SOCKET_TYPE_CHAR_UDP;
 
swrap_dir = socket_wrapper_dir();
+   if (swrap_dir == NULL) {
+   return -1;
+   }
 
for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) {
snprintf(un_addr.sa.un.sun_path,
@@ -5892,6 +5909,9 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr 
*omsg, int flags)
type = SOCKET_TYPE_CHAR_UDP;
 
swrap_dir = socket_wrapper_dir();
+   if (swrap_dir == NULL) {
+   return -1;
+   }
 
for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) {
snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), 

[SCM] Socket Wrapper Repository - branch master updated

2019-03-21 Thread Andreas Schneider
The branch, master has been updated
   via  a3a3dca Bump version to 1.2.2
  from  bd951c1 swrap: Add paranoia NULL checks

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit a3a3dcac39fd9b477c497810f8c1512a2f449b8e
Author: Andreas Schneider 
Date:   Thu Mar 21 08:47:24 2019 +0100

Bump version to 1.2.2

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 CMakeLists.txt | 4 ++--
 ChangeLog  | 5 +
 2 files changed, 7 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1a161dc..ab7254c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.2.1 LANGUAGES C)
+project(socket_wrapper VERSION 1.2.2 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -23,7 +23,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION "0.1.11")
+set(LIBRARY_VERSION "0.1.12")
 set(LIBRARY_SOVERSION "0")
 
 # add definitions
diff --git a/ChangeLog b/ChangeLog
index c4831b9..d0a7285 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 ChangeLog
 ==
 
+version 1.2.2 (released 2019-03-21)
+  * Added environment variable to disable deep binding
+  * Fixed installation of socket_wrapper
+  * Fixed several small bugs
+
 version 1.2.1 (released 2018-11-14)
   * Removed error message to fix applications doing stupid things
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2019-03-21 Thread Andreas Schneider
The branch, master has been updated
   via  bd951c1 swrap: Add paranoia NULL checks
   via  6e1ed1d swrap: Fix strict aliasing issues in 
swrap_pcap_packet_init()
   via  2cfe068 swrap: Fix "Value stored never used" warning
   via  6f69593 tests: Fix typo in echo_srv help
   via  887ce58 doc: Fix some typos in the manpage
  from  2d53497 swrap: Do not use FALL_THROUGH for empty case statements

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit bd951c1f6944011bb5585cb58c92ca5cd5b78489
Author: Andreas Schneider 
Date:   Fri Mar 15 14:59:14 2019 +0100

swrap: Add paranoia NULL checks

csbuild complains about missing NULL checks here.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 6e1ed1da3f4372b7de69c5f8be227d85727b2b59
Author: Andreas Schneider 
Date:   Thu Feb 28 13:00:40 2019 +0100

swrap: Fix strict aliasing issues in swrap_pcap_packet_init()

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 2cfe0686137c61edd2ff9c6fa01e5499d210c0c5
Author: Anoop C S 
Date:   Fri Mar 15 18:48:40 2019 +0530

swrap: Fix "Value stored never used" warning

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 6f69593669b7d8424492da95a58d4d7cffa3c974
Author: Andreas Schneider 
Date:   Thu Feb 28 13:02:35 2019 +0100

tests: Fix typo in echo_srv help

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 887ce58dff7d8325e01738bd099e57dbace469f8
Author: Andreas Schneider 
Date:   Thu Feb 28 13:02:08 2019 +0100

doc: Fix some typos in the manpage

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 doc/socket_wrapper.1 |   6 +--
 doc/socket_wrapper.1.txt |   8 +--
 src/socket_wrapper.c | 123 +++
 tests/echo_srv.c |   2 +-
 4 files changed, 79 insertions(+), 60 deletions(-)


Changeset truncated at 500 lines:

diff --git a/doc/socket_wrapper.1 b/doc/socket_wrapper.1
index a064eed..9f3f75a 100644
--- a/doc/socket_wrapper.1
+++ b/doc/socket_wrapper.1
@@ -44,7 +44,7 @@ socket_wrapper aims to help client/server software 
development teams willing to
 .sp -1
 .IP \(bu 2.3
 .\}
-Redirects all network communication to happen over unix sockets\&.
+Redirects all network communication to happen over Unix sockets\&.
 .RE
 .sp
 .RS 4
@@ -66,13 +66,13 @@ Support for IPv4 and IPv6 socket and addressing emulation\&.
 .sp -1
 .IP \(bu 2.3
 .\}
-Ablility to capture network traffic in pcap format\&.
+Ability to capture network traffic in pcap format\&.
 .RE
 .SH "ENVIRONMENT VARIABLES"
 .PP
 \fBSOCKET_WRAPPER_DIR\fR
 .RS 4
-The user defines a directory where to put all the unix sockets using the 
envionment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir"\&. When a server 
opens a port or a client wants to connect, socket_wrapper will translate IP 
addresses to a special socket_wrapper name and look for the relevant unix 
socket in the SOCKET_WRAPPER_DIR\&.
+The user defines a directory where to put all the unix sockets using the 
environment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir"\&. When a server 
opens a port or a client wants to connect, socket_wrapper will translate IP 
addresses to a special socket_wrapper name and look for the relevant Unix 
socket in the SOCKET_WRAPPER_DIR\&.
 .RE
 .PP
 \fBSOCKET_WRAPPER_DEFAULT_IFACE\fR
diff --git a/doc/socket_wrapper.1.txt b/doc/socket_wrapper.1.txt
index da16c6d..b3ba96c 100644
--- a/doc/socket_wrapper.1.txt
+++ b/doc/socket_wrapper.1.txt
@@ -21,9 +21,9 @@ gain full functional test coverage. It makes possible to run 
several instances
 of the full software stack on the same machine and perform locally functional
 testing of complex network configurations.
 
-- Redirects all network communication to happen over unix sockets.
+- Redirects all network communication to happen over Unix sockets.
 - Support for IPv4 and IPv6 socket and addressing emulation.
-- Ablility to capture network traffic in pcap format.
+- Ability to capture network traffic in pcap format.
 
 ENVIRONMENT VARIABLES
 -
@@ -31,9 +31,9 @@ ENVIRONMENT VARIABLES
 *SOCKET_WRAPPER_DIR*::
 
 The user defines a directory where to put all the unix sockets using the
-envionment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir". When a server
+environment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir". When a server
 opens a port or a client wants to connect, socket_wrapper will translate IP
-addresses to a special socket_wrapper name and look for the relevant unix
+addresses to a special socket_wrapper name and look for the relevant Unix
 socket in the SOCKET_WRAPPER_DIR.
 
 *SOCKET_WRAPPER_DEFAULT_IFACE*::
diff --git a/src/socket_wrapper.c 

[SCM] Socket Wrapper Repository - branch master updated

2019-03-06 Thread Andreas Schneider
The branch, master has been updated
   via  2d53497 swrap: Do not use FALL_THROUGH for empty case statements
  from  70bc551 README: Create a markdown file

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 2d53497bb3610b4aa7c3f045b810d23d1f2e9daf
Author: Amitay Isaacs 
Date:   Thu Feb 21 14:04:21 2019 +1100

swrap: Do not use FALL_THROUGH for empty case statements

Signed-off-by: Amitay Isaacs 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c | 2 --
 1 file changed, 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index de5cc7a..a5037f7 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -610,7 +610,6 @@ static void *swrap_load_lib_handle(enum swrap_lib lib)
 
switch (lib) {
case SWRAP_LIBNSL:
-   FALL_THROUGH;
case SWRAP_LIBSOCKET:
 #ifdef HAVE_LIBSOCKET
handle = swrap.libc.socket_handle;
@@ -629,7 +628,6 @@ static void *swrap_load_lib_handle(enum swrap_lib lib)
}
break;
 #endif
-   FALL_THROUGH;
case SWRAP_LIBC:
handle = swrap.libc.handle;
 #ifdef LIBC_SO


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2019-02-20 Thread Andreas Schneider
The branch, master has been updated
   via  70bc551 README: Create a markdown file
   via  5cc0681 gitlab-ci: Check last 20 commits on force push
   via  066d850 cmake: Remove unused config.h variables
   via  9a9250a cmake: Use GNUInstallDirs
  from  24e5973 swrap: Fix a TODO

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 70bc551dca142a7a4d6ed082244966957ca2e070
Author: Andreas Schneider 
Date:   Tue Feb 19 16:18:10 2019 +0100

README: Create a markdown file

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 5cc06814060cd99245e7f072da077e5227d7698d
Author: Andreas Schneider 
Date:   Tue Feb 19 16:10:16 2019 +0100

gitlab-ci: Check last 20 commits on force push

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 066d850c2853095bf756e7f5e9aeb198f6775b23
Author: Andreas Schneider 
Date:   Wed Feb 20 10:34:04 2019 +0100

cmake: Remove unused config.h variables

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 9a9250a79143df88c3100e509e29c00536045b6b
Author: Andreas Schneider 
Date:   Fri Feb 15 13:09:28 2019 +0100

cmake: Use GNUInstallDirs

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 .gitlab-ci.yml  |   4 +-
 CMakeLists.txt  |   6 +-
 CPackConfig.cmake   |   2 +-
 ConfigureChecks.cmake   |   4 -
 README => README.md |   6 +-
 cmake/Modules/DefineInstallationPaths.cmake | 109 
 config.h.cmake  |   5 --
 doc/CMakeLists.txt  |   2 +-
 socket_wrapper-config.cmake.in  |   2 +-
 socket_wrapper.pc.cmake |   2 +-
 src/CMakeLists.txt  |  10 +--
 11 files changed, 16 insertions(+), 136 deletions(-)
 rename README => README.md (74%)
 delete mode 100644 cmake/Modules/DefineInstallationPaths.cmake


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a2bb099..365d834 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -82,12 +82,12 @@ fedora/csbuild:
   script:
   - |
 if [[ -z "$CI_COMMIT_BEFORE_SHA" ]]; then
-export CI_COMMIT_BEFORE_SHA=$(git rev-parse HEAD^)
+export CI_COMMIT_BEFORE_SHA=$(git rev-parse "${CI_COMMIT_SHA}~20")
 fi
 
 # Check if the commit exists in this branch
 # This is not the case for a force push
-git branch --contains $CI_COMMIT_BEFORE_SHA 2>/dev/null || export 
CI_COMMIT_BEFORE_SHA=$(git rev-parse HEAD^)
+git branch --contains $CI_COMMIT_BEFORE_SHA 2>/dev/null || export 
CI_COMMIT_BEFORE_SHA=$(git rev-parse "${CI_COMMIT_SHA}~20")
 
 export CI_COMMIT_RANGE="$CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA"
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 38b3e17..1a161dc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,10 +28,10 @@ set(LIBRARY_SOVERSION "0")
 
 # add definitions
 include(DefinePlatformDefaults)
-include(DefineInstallationPaths)
 include(DefineOptions.cmake)
 include(CPackConfig.cmake)
 include(CompilerChecks.cmake)
+include(GNUInstallDirs)
 
 # disallow in-source build
 include(MacroEnsureOutOfSourceBuild)
@@ -63,7 +63,7 @@ install(
   FILES
 ${CMAKE_CURRENT_BINARY_DIR}/socket_wrapper.pc
   DESTINATION
-${LIB_INSTALL_DIR}/pkgconfig
+  ${CMAKE_INSTALL_LIBDIR}/pkgconfig
   COMPONENT
 pkgconfig
 )
@@ -76,7 +76,7 @@ install(
 ${CMAKE_CURRENT_BINARY_DIR}/socket_wrapper-config-version.cmake
 ${CMAKE_CURRENT_BINARY_DIR}/socket_wrapper-config.cmake
 DESTINATION
-${CMAKE_INSTALL_DIR}/socket_wrapper
+${CMAKE_INSTALL_LIBDIR}/cmake/socket_wrapper
 COMPONENT
 devel
 )
diff --git a/CPackConfig.cmake b/CPackConfig.cmake
index 6cf14a6..11b0314 100644
--- a/CPackConfig.cmake
+++ b/CPackConfig.cmake
@@ -4,7 +4,7 @@
 ### general settings
 set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The SSH library")
-set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
 set(CPACK_PACKAGE_VENDOR "The SSH Library Development Team")
 set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 6cedb90..81aaa1c 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -9,10 +9,6 @@ include(TestBigEndian)
 
 set(PACKAGE ${PROJECT_NAME})
 set(VERSION ${PROJECT_VERSION})
-set(DATADIR ${DATA_INSTALL_DIR})
-set(LIBDIR ${LIB_INSTALL_DIR})
-set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
-set(SYSCONFDIR 

[SCM] Socket Wrapper Repository - branch master updated

2019-02-12 Thread Andreas Schneider
The branch, master has been updated
   via  24e5973 swrap: Fix a TODO
   via  74e9e13 Remove thread-safety task from TODO
   via  dd2f1b0 cmake: Disable deep binding for helgrind
   via  e7c9380 swrap: Add env variable to disable deep binding
  from  cf436b6 swrap: Use #ifdef instead of #if for config.h definitions

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 24e597330ec6fbbdc149d798e70d6ed48729bd84
Author: Anoop C S 
Date:   Thu Dec 6 11:16:15 2018 +0530

swrap: Fix a TODO

Use realpath(3) instead of strncmp(3)

Signed-off-by: Anoop C S 
Reviewed-by: Ralph Boehme 
Reviewed-by: Andreas Schneider 

commit 74e9e13c38eeda6b31a0bf971e03d2d79eb81681
Author: Anoop C S 
Date:   Thu Dec 6 11:15:46 2018 +0530

Remove thread-safety task from TODO

Signed-off-by: Anoop C S 
Reviewed-by: Ralph Boehme 
Reviewed-by: Andreas Schneider 

commit dd2f1b001de4a8e70f7c6fa52734b2a82bd2b566
Author: Andreas Schneider 
Date:   Wed Nov 28 09:23:52 2018 +0100

cmake: Disable deep binding for helgrind

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit e7c9380faf0f0557c202119f960026f8700667ee
Author: Andreas Schneider 
Date:   Wed Nov 28 09:20:58 2018 +0100

swrap: Add env variable to disable deep binding

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 TODO |  2 --
 doc/socket_wrapper.1 |  9 +++--
 doc/socket_wrapper.1.txt |  7 +++-
 src/socket_wrapper.c | 93 +++-
 tests/CMakeLists.txt |  2 +-
 5 files changed, 83 insertions(+), 30 deletions(-)


Changeset truncated at 500 lines:

diff --git a/TODO b/TODO
index 147c166..4a851e6 100644
--- a/TODO
+++ b/TODO
@@ -10,7 +10,6 @@ Library:
 -
 
 Goals:
-* Thread safety
 * The proposed way ==> - fd-passing for tcp sockets (for free)
   Approach:
   - tdb "in small". So a "db file".
@@ -30,4 +29,3 @@ Testing:
 * Add a test for sento() to broadcast 255.255.255.255.
 * Add a test to check that read/readv/send/ only work on connected sockets.
 * Add unit tests for conversion functions like convert_in_un_remote().
-* Add threaded tests.
diff --git a/doc/socket_wrapper.1 b/doc/socket_wrapper.1
index 7e10224..a064eed 100644
--- a/doc/socket_wrapper.1
+++ b/doc/socket_wrapper.1
@@ -2,12 +2,12 @@
 .\" Title: socket_wrapper
 .\"Author: Samba Team
 .\" Generator: DocBook XSL Stylesheets vsnapshot 
-.\"  Date: 2018-06-26
+.\"  Date: 2018-11-28
 .\"Manual: \ \&
 .\"Source: \ \&
 .\"  Language: English
 .\"
-.TH "SOCKET_WRAPPER" "1" "2018\-06\-26" "\ \&" "\ \&"
+.TH "SOCKET_WRAPPER" "1" "2018\-11\-28" "\ \&" "\ \&"
 .\" -
 .\" * Define some portability stuff
 .\" -
@@ -147,6 +147,11 @@ If you need to see what is going on in socket_wrapper 
itself or try to find a bu
 3 = TRACE
 .RE
 .RE
+.PP
+\fBSOCKET_WRAPPER_DISABLE_DEEPBIND\fR
+.RS 4
+This allows you to disable deep binding in socket_wrapper\&. This is useful 
for running valgrind tools or sanitizers like (address, undefined, thread)\&.
+.RE
 .SH "EXAMPLE"
 .sp
 .if n \{\
diff --git a/doc/socket_wrapper.1.txt b/doc/socket_wrapper.1.txt
index 583b50a..da16c6d 100644
--- a/doc/socket_wrapper.1.txt
+++ b/doc/socket_wrapper.1.txt
@@ -1,6 +1,6 @@
 socket_wrapper(1)
 =
-:revdate: 2018-06-26
+:revdate: 2018-11-28
 :author: Samba Team
 
 NAME
@@ -78,6 +78,11 @@ debug symbols.
 - 2 = DEBUG
 - 3 = TRACE
 
+*SOCKET_WRAPPER_DISABLE_DEEPBIND*::
+
+This allows you to disable deep binding in socket_wrapper. This is useful for
+running valgrind tools or sanitizers like (address, undefined, thread).
+
 EXAMPLE
 ---
 
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index ca0a833..de5cc7a 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -555,7 +555,7 @@ struct swrap {
 static struct swrap swrap;
 
 /* prototypes */
-static const char *socket_wrapper_dir(void);
+static char *socket_wrapper_dir(void);
 
 #define LIBC_NAME "libc.so"
 
@@ -587,15 +587,25 @@ static void *swrap_load_lib_handle(enum swrap_lib lib)
int i;
 
 #ifdef RTLD_DEEPBIND
-   const char *env = getenv("LD_PRELOAD");
+   const char *env_preload = getenv("LD_PRELOAD");
+   const char *env_deepbind = getenv("SOCKET_WRAPPER_DISABLE_DEEPBIND");
+   bool enable_deepbind = true;
 
/* Don't do a deepbind if we run with libasan */
-   if (env != NULL && strlen(env) < 1024) {
-   const char *p = strstr(env, "libasan.so");
-   if (p == NULL) {
-   flags |= RTLD_DEEPBIND;
+   if (env_preload != NULL && 

[SCM] Socket Wrapper Repository - branch master updated

2019-01-11 Thread Andreas Schneider
The branch, master has been updated
   via  cf436b6 swrap: Use #ifdef instead of #if for config.h definitions
  from  9413e43 swrap: Add an overflow check

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit cf436b6d3e1d2c85d47e76e19519e36672ac93b8
Author: Andreas Schneider 
Date:   Tue Nov 20 14:16:17 2018 +0100

swrap: Use #ifdef instead of #if for config.h definitions

Signed-off-by: Andreas Schneider 
Reviewed-by: Volker Lendecke 

---

Summary of changes:
 src/socket_wrapper.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a0e1df0..ca0a833 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -2012,7 +2012,7 @@ static bool check_addr_port_in_use(const struct sockaddr 
*sa, socklen_t len)
return false;
}
break;
-#if HAVE_IPV6
+#ifdef HAVE_IPV6
case AF_INET6:
if (len < sizeof(struct sockaddr_in6)) {
return false;
@@ -2059,7 +2059,7 @@ static bool check_addr_port_in_use(const struct sockaddr 
*sa, socklen_t len)
return true;
break;
}
-#if HAVE_IPV6
+#ifdef HAVE_IPV6
case AF_INET6: {
struct sockaddr_in6 *sin1, *sin2;
 
@@ -5303,7 +5303,7 @@ static ssize_t swrap_sendto(int s, const void *buf, 
size_t len, int flags,
msg.msg_namelen = tolen;   /* size of address */
msg.msg_iov = /* scatter/gather array */
msg.msg_iovlen = 1;/* # elements in msg_iov */
-#if HAVE_STRUCT_MSGHDR_MSG_CONTROL
+#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
msg.msg_control = NULL;/* ancillary data, see below */
msg.msg_controllen = 0;/* ancillary data buffer len */
msg.msg_flags = 0; /* flags on received message */
@@ -5534,7 +5534,7 @@ static ssize_t swrap_write(int s, const void *buf, size_t 
len)
msg.msg_namelen = 0;   /* size of address */
msg.msg_iov = /* scatter/gather array */
msg.msg_iovlen = 1;/* # elements in msg_iov */
-#if HAVE_STRUCT_MSGHDR_MSG_CONTROL
+#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
msg.msg_control = NULL;/* ancillary data, see below */
msg.msg_controllen = 0;/* ancillary data buffer len */
msg.msg_flags = 0; /* flags on received message */
@@ -5585,7 +5585,7 @@ static ssize_t swrap_send(int s, const void *buf, size_t 
len, int flags)
msg.msg_namelen = 0;   /* size of address */
msg.msg_iov = /* scatter/gather array */
msg.msg_iovlen = 1;/* # elements in msg_iov */
-#if HAVE_STRUCT_MSGHDR_MSG_CONTROL
+#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
msg.msg_control = NULL;/* ancillary data, see below */
msg.msg_controllen = 0;/* ancillary data buffer len */
msg.msg_flags = 0; /* flags on received message */
@@ -5949,7 +5949,7 @@ static ssize_t swrap_writev(int s, const struct iovec 
*vector, int count)
msg.msg_namelen = 0;   /* size of address */
msg.msg_iov = discard_const_p(struct iovec, vector); /* scatter/gather 
array */
msg.msg_iovlen = count;/* # elements in msg_iov */
-#if HAVE_STRUCT_MSGHDR_MSG_CONTROL
+#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
msg.msg_control = NULL;/* ancillary data, see below */
msg.msg_controllen = 0;/* ancillary data buffer len */
msg.msg_flags = 0; /* flags on received message */


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2019-01-11 Thread Andreas Schneider
The branch, master has been updated
   via  9413e43 swrap: Add an overflow check
  from  8ccac24 Bump version to 1.2.1

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 9413e433ea83095735ddb8dd080bceecde8a9b57
Author: Volker Lendecke 
Date:   Sat Dec 29 20:20:13 2018 +0100

swrap: Add an overflow check

Signed-off-by: Volker Lendecke 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c | 5 +
 1 file changed, 5 insertions(+)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index df70df5..a0e1df0 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -4752,6 +4752,11 @@ static ssize_t swrap_sendmsg_before(int fd,
for (i = 0; i < (size_t)msg->msg_iovlen; i++) {
size_t nlen;
nlen = len + msg->msg_iov[i].iov_len;
+   if (nlen < len) {
+   /* overflow */
+   errno = EMSGSIZE;
+   goto out;
+   }
if (nlen > mtu) {
break;
}


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-11-14 Thread Andreas Schneider
The branch, master has been updated
   via  8ccac24 Bump version to 1.2.1
  from  9731458 swrap: Do not log if we are over the limit in 
find_socket_info_index()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 8ccac24b78bc5aa758a02cdecf58bdd6b8d6da13
Author: Andreas Schneider 
Date:   Wed Nov 14 08:04:42 2018 +0100

Bump version to 1.2.1

Signed-off-by: Andreas Schneider 
Reviewed-by: Karolin Seeger 

---

Summary of changes:
 CMakeLists.txt | 4 ++--
 ChangeLog  | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f51bea..38b3e17 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.2.0 LANGUAGES C)
+project(socket_wrapper VERSION 1.2.1 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -23,7 +23,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION "0.1.10")
+set(LIBRARY_VERSION "0.1.11")
 set(LIBRARY_SOVERSION "0")
 
 # add definitions
diff --git a/ChangeLog b/ChangeLog
index 639044d..c4831b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 ChangeLog
 ==
 
+version 1.2.1 (released 2018-11-14)
+  * Removed error message to fix applications doing stupid things
+
 version 1.2.0 (released 2018-11-13)
   * Added threading support
   * Moved to modern cmake


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-11-13 Thread Andreas Schneider
The branch, master has been updated
   via  9731458 swrap: Do not log if we are over the limit in 
find_socket_info_index()
   via  9b01066 swrap: Also log the fd in swrap_socket()
  from  ce38138 swrap: Fix comparison of different signedness

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 97314589dec9feca4c10c2350dfbd7702ff44cb1
Author: Andreas Schneider 
Date:   Tue Nov 13 18:44:39 2018 +0100

swrap: Do not log if we are over the limit in find_socket_info_index()

There are applications which do:

for (fd = 0; fd <= getdtablesize(); fd++) {
close(fd)
};

This produced millions of error messsages.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 9b01066059a002d15996d797d911fdd693e29cb7
Author: Andreas Schneider 
Date:   Tue Nov 13 18:18:22 2018 +0100

swrap: Also log the fd in swrap_socket()

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 src/socket_wrapper.c | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index ae3b2b0..df70df5 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1540,11 +1540,23 @@ static int find_socket_info_index(int fd)
}
 
if ((size_t)fd >= socket_fds_max) {
+   /*
+* Do not add a log here as some applications do stupid things
+* like:
+*
+* for (fd = 0; fd <= getdtablesize(); fd++) {
+* close(fd)
+* };
+*
+* This would produce millions of lines of debug messages.
+*/
+#if 0
SWRAP_LOG(SWRAP_LOG_ERROR,
- "The max socket index limit of %zu has been reached, "
- "trying to add %d",
- socket_fds_max,
- fd);
+ "Looking for a socket info for the fd %d is over the "
+ "max socket index limit of %zu.",
+ fd,
+ socket_fds_max);
+#endif
return -1;
}
 
@@ -3161,9 +3173,10 @@ static int swrap_socket(int family, int type, int 
protocol)
}
 
SWRAP_LOG(SWRAP_LOG_TRACE,
- "Created %s socket for protocol %s",
+ "Created %s socket for protocol %s, fd=%d",
  family == AF_INET ? "IPv4" : "IPv6",
- real_type == SOCK_DGRAM ? "UDP" : "TCP");
+ real_type == SOCK_DGRAM ? "UDP" : "TCP",
+ fd);
 
return fd;
 }


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-11-13 Thread Andreas Schneider
The branch, master has been updated
   via  ce38138 swrap: Fix comparison of different signedness
  from  ac18c80 Bump version to 1.2.0

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit ce38138a9ac1b9e36b3338ee9ebcdc5686d541a4
Author: Andreas Schneider 
Date:   Tue Nov 13 14:28:17 2018 +0100

swrap: Fix comparison of different signedness

Found by csbuild.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 src/socket_wrapper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 2b77ceb..ae3b2b0 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1539,7 +1539,7 @@ static int find_socket_info_index(int fd)
return -1;
}
 
-   if (fd >= socket_fds_max) {
+   if ((size_t)fd >= socket_fds_max) {
SWRAP_LOG(SWRAP_LOG_ERROR,
  "The max socket index limit of %zu has been reached, "
  "trying to add %d",
@@ -1590,7 +1590,7 @@ static int swrap_create_socket(struct socket_info *si, 
int fd)
 {
int idx;
 
-   if (fd >= socket_fds_max) {
+   if ((size_t)fd >= socket_fds_max) {
SWRAP_LOG(SWRAP_LOG_ERROR,
  "The max socket index limit of %zu has been reached, "
  "trying to add %d",


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-11-13 Thread Andreas Schneider
The branch, master has been updated
   via  ac18c80 Bump version to 1.2.0
   via  aff61a7 swrap: Also log the process name
   via  d26ceb5 swrap: Better handling for default values in 
socket_wrapper_max_sockets()
   via  74c3a9a swrap: Always allocate the socket fd array to the maximum
   via  87cc3f8 swrap: Rename global variable for max sockets
  from  d788cef tests: Enable threaded test cases on FreeBSD

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit ac18c80e2096f0edc542273325fb2571d35cb796
Author: Andreas Schneider 
Date:   Mon Nov 12 11:14:20 2018 +0100

Bump version to 1.2.0

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit aff61a781700ce8c1e6f9d0cd74b4c484be354fa
Author: Andreas Schneider 
Date:   Mon Nov 12 15:22:35 2018 +0100

swrap: Also log the process name

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit d26ceb542342d6eef4a8df14f79ca2f81d1e550e
Author: Andreas Schneider 
Date:   Tue Nov 13 08:31:43 2018 +0100

swrap: Better handling for default values in socket_wrapper_max_sockets()

Pair-Programmed-With: Anoop C S 
Signed-off-by: Andreas Schneider 
Signed-off-by: Anoop C S 
Reviewed-by: Ralph Boehme 

commit 74c3a9a60e5cfb8d191876c24e88e5d3aa38ca58
Author: Andreas Schneider 
Date:   Mon Nov 12 17:34:08 2018 +0100

swrap: Always allocate the socket fd array to the maximum

This will allow that we can deal with duplicates if the default value is
used.

Pair-Programmed-With: Anoop C S 
Signed-off-by: Andreas Schneider 
Signed-off-by: Anoop C S 
Reviewed-by: Ralph Boehme 

commit 87cc3f8e5433471e986c3b50e351ae49289b4cbe
Author: Andreas Schneider 
Date:   Mon Nov 12 17:00:09 2018 +0100

swrap: Rename global variable for max sockets

We also need a mutex to protect access to it.

Pair-Programmed-With: Anoop C S 
Signed-off-by: Andreas Schneider 
Signed-off-by: Anoop C S 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 CMakeLists.txt|  4 +--
 ChangeLog |  5 +++
 ConfigureChecks.cmake |  9 ++
 config.h.cmake|  6 
 src/socket_wrapper.c  | 85 ++-
 5 files changed, 85 insertions(+), 24 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35527f1..2f51bea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.1.9 LANGUAGES C)
+project(socket_wrapper VERSION 1.2.0 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -23,7 +23,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION "0.1.9")
+set(LIBRARY_VERSION "0.1.10")
 set(LIBRARY_SOVERSION "0")
 
 # add definitions
diff --git a/ChangeLog b/ChangeLog
index 50911b6..639044d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 ChangeLog
 ==
 
+version 1.2.0 (released 2018-11-13)
+  * Added threading support
+  * Moved to modern cmake
+  * Several smaller bugfixes
+
 version 1.1.9 (released 2017-12-04)
   * Fixed thread - signal deadlock issue
 
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 94fed22..6cedb90 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -54,6 +54,13 @@ check_include_file(sys/timerfd.h HAVE_SYS_TIMERFD_H)
 check_include_file(gnu/lib-names.h HAVE_GNU_LIB_NAMES_H)
 check_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
 
+# SYMBOLS
+set(CMAKE_REQUIRED_FLAGS -D_GNU_SOURCE)
+check_symbol_exists(program_invocation_short_name
+"errno.h"
+HAVE_PROGRAM_INVOCATION_SHORT_NAME)
+unset(CMAKE_REQUIRED_FLAGS)
+
 # FUNCTIONS
 check_function_exists(strncpy HAVE_STRNCPY)
 check_function_exists(vsnprintf HAVE_VSNPRINTF)
@@ -65,6 +72,8 @@ check_function_exists(bindresvport HAVE_BINDRESVPORT)
 check_function_exists(accept4 HAVE_ACCEPT4)
 check_function_exists(open64 HAVE_OPEN64)
 check_function_exists(fopen64 HAVE_FOPEN64)
+check_function_exists(getprogname HAVE_GETPROGNAME)
+check_function_exists(getexecname HAVE_GETEXECNAME)
 
 check_function_exists(pledge HAVE_PLEDGE)
 
diff --git a/config.h.cmake b/config.h.cmake
index 5baa789..0207031 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -31,6 +31,10 @@
 #cmakedefine HAVE_STRUCT_SOCKADDR_SA_LEN 1
 #cmakedefine HAVE_STRUCT_MSGHDR_MSG_CONTROL 1
 
+/ SYMBOLS /
+
+#cmakedefine HAVE_PROGRAM_INVOCATION_SHORT_NAME 1
+
 

[SCM] Socket Wrapper Repository - branch master updated

2018-11-12 Thread Andreas Schneider
The branch, master has been updated
   via  d788cef tests: Enable threaded test cases on FreeBSD
   via  a2d7735 tests: Increase backlog count for listen() in echo_srv
  from  299af4a gitlab-ci: Add csbuild

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit d788cef44dc998ce51aeb9637145bf1d1cd58a9b
Author: Anoop C S 
Date:   Sat Nov 10 10:57:27 2018 +0530

tests: Enable threaded test cases on FreeBSD

It was previously judged as a bug which now turned to be due to
wrong backlog count set in echo_srv while listening on socket.

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit a2d7735ac7e8c3e9da15b6642c4f6e832ad7fa4d
Author: Anoop C S 
Date:   Sat Nov 10 10:56:24 2018 +0530

tests: Increase backlog count for listen() in echo_srv

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 tests/CMakeLists.txt | 12 
 tests/echo_srv.c |  2 +-
 2 files changed, 1 insertion(+), 13 deletions(-)


Changeset truncated at 500 lines:

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 829c243..1da839c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -107,18 +107,6 @@ foreach(_SWRAP_TEST ${SWRAP_TESTS})
 add_cmocka_test_environment(${_SWRAP_TEST})
 endforeach()
 
-# These test will fail on because there is a threading race condition in
-# FreeBSD.
-# See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848
-if (FREEBSD)
-set_tests_properties(test_thread_echo_tcp_connect
- PROPERTIES DISABLED TRUE)
-set_tests_properties(test_thread_echo_tcp_write_read
- PROPERTIES DISABLED TRUE)
-set_tests_properties(test_thread_echo_tcp_sendmsg_recvmsg
- PROPERTIES DISABLED TRUE)
-endif()
-
 if (HELGRIND_TESTING)
 find_program(VALGRIND_EXECUTABLE valgrind)
 if (VALGRIND_EXECUTABLE)
diff --git a/tests/echo_srv.c b/tests/echo_srv.c
index 957a3ad..fac4e8e 100644
--- a/tests/echo_srv.c
+++ b/tests/echo_srv.c
@@ -30,7 +30,7 @@
 #define ECHO_SRV_IPV6 "fd00::5357:5f0a"
 
 #define DFL_PORT7
-#define BACKLOG 5
+#define BACKLOG 16
 
 #ifndef BUFSIZE
 #define BUFSIZE 0x2 /* 128K */


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-11-07 Thread Andreas Schneider
The branch, master has been updated
   via  299af4a gitlab-ci: Add csbuild
   via  8609a8e tests: Protect IPv6 in st_echo_tcp_get_peer_sock_name
   via  28aeac8 cmake: SWRAP_REQUIRED_LIBRARIES should be a list
   via  dfeb05d cmake: Set LINK_FLAGS for echo_srv
   via  cdf557d cmake: Set LINK_FLAGS for socket_wrapper
   via  51fcd0a cmake: Only set default flags if they have been detected
   via  d9a6ecb cmake: Disable stack protector on Solaris
  from  efbb27d gitlab-ci: Enable freebsd runner

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 299af4a68ac51dd86143d3c4750b2571e98bcc58
Author: Andreas Schneider 
Date:   Wed Nov 7 08:31:50 2018 +0100

gitlab-ci: Add csbuild

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 8609a8eb39a097b47081f34fc9197b9a33d0c2c8
Author: Andreas Schneider 
Date:   Wed Nov 7 09:05:30 2018 +0100

tests: Protect IPv6 in st_echo_tcp_get_peer_sock_name

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 28aeac863cd829783aca1281ecde274266e40f09
Author: Andreas Schneider 
Date:   Wed Nov 7 09:02:35 2018 +0100

cmake: SWRAP_REQUIRED_LIBRARIES should be a list

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit dfeb05d87bac0d81f2676fbc22430bd0018eaa49
Author: Andreas Schneider 
Date:   Wed Nov 7 09:14:40 2018 +0100

cmake: Set LINK_FLAGS for echo_srv

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit cdf557dbca4df47301922c6304269f874236c759
Author: Andreas Schneider 
Date:   Wed Nov 7 09:13:26 2018 +0100

cmake: Set LINK_FLAGS for socket_wrapper

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 51fcd0af8a7017aea779b8516d7520df20bec454
Author: Andreas Schneider 
Date:   Wed Nov 7 09:25:54 2018 +0100

cmake: Only set default flags if they have been detected

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit d9a6ecb148ae6fe485e8b7416cd5b8265e22804f
Author: Andreas Schneider 
Date:   Wed Nov 7 09:27:38 2018 +0100

cmake: Disable stack protector on Solaris

They don't work.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 .gitlab-ci.yml   | 31 ++
 CompilerChecks.cmake | 44 ++--
 ConfigureChecks.cmake|  1 -
 src/CMakeLists.txt   | 19 +++---
 tests/CMakeLists.txt |  5 
 tests/test_echo_tcp_get_peer_sock_name.c | 15 +++
 6 files changed, 86 insertions(+), 29 deletions(-)


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 00b4576..a2bb099 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -77,6 +77,37 @@ fedora/undefined-sanitizer:
 paths:
   - obj/
 
+fedora/csbuild:
+  image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD
+  script:
+  - |
+if [[ -z "$CI_COMMIT_BEFORE_SHA" ]]; then
+export CI_COMMIT_BEFORE_SHA=$(git rev-parse HEAD^)
+fi
+
+# Check if the commit exists in this branch
+# This is not the case for a force push
+git branch --contains $CI_COMMIT_BEFORE_SHA 2>/dev/null || export 
CI_COMMIT_BEFORE_SHA=$(git rev-parse HEAD^)
+
+export CI_COMMIT_RANGE="$CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA"
+
+  - csbuild
+--build-dir=obj-csbuild
+--prep-cmd="cmake -DCMAKE_BUILD_TYPE=Debug -DPICKY_DEVELOPER=ON 
-DUNIT_TESTING=ON @SRCDIR@"
+--build-cmd "make clean && make -j$(nproc)"
+--git-commit-range $CI_COMMIT_RANGE
+--color
+--print-current --print-fixed
+  tags:
+  - shared
+  except:
+  - tags
+  artifacts:
+expire_in: 1 week
+when: on_failure
+paths:
+  - obj-csbuild/
+
 freebsd/x86_64:
   image:
   script:
diff --git a/CompilerChecks.cmake b/CompilerChecks.cmake
index f5a3c7f..4fa1a83 100644
--- a/CompilerChecks.cmake
+++ b/CompilerChecks.cmake
@@ -65,27 +65,29 @@ if (UNIX)
 endif()
 endif()
 
-check_c_compiler_flag_ssp("-fstack-protector-strong" 
WITH_STACK_PROTECTOR_STRONG)
-if (WITH_STACK_PROTECTOR_STRONG)
-list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector-strong")
-# This is needed as Solaris has a seperate libssp
-if (SOLARIS)
-list(APPEND SUPPORTED_LINKER_FLAGS "-fstack-protector-strong")
-endif()
-else (WITH_STACK_PROTECTOR_STRONG)
-check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR)
-if (WITH_STACK_PROTECTOR)
-list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector")
+if (NOT SOLARIS)
+check_c_compiler_flag_ssp("-fstack-protector-strong" 
WITH_STACK_PROTECTOR_STRONG)
+if (WITH_STACK_PROTECTOR_STRONG)
+   

[SCM] Socket Wrapper Repository - branch master updated

2018-11-06 Thread Andreas Schneider
The branch, master has been updated
   via  efbb27d gitlab-ci: Enable freebsd runner
   via  9c0931b tests: Disable failing tests as on FreeBSD
   via  38704a9 cmake: Create a list with required libraries
   via  db7070c tests: Protect IPv6 function in setup_echo_srv_tcp_ipv6
   via  f690f8c tests: Protect IPv6 case in echo_srv
   via  fb4df59 swrap: Protect IPv6 case in swrap_socket()
  from  916ce9c cmake: Don't use string PREPEND

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit efbb27d464afbf97e5f4b83d51f521028391a45b
Author: Andreas Schneider 
Date:   Tue Oct 30 13:01:27 2018 +0100

gitlab-ci: Enable freebsd runner

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 9c0931bf0ba7d3a08fe6428fa891d36d6c2130c7
Author: Andreas Schneider 
Date:   Tue Oct 30 13:00:51 2018 +0100

tests: Disable failing tests as on FreeBSD

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 38704a92f5ded6ac028f589632f4a305400a83ce
Author: Andreas Schneider 
Date:   Wed Oct 31 08:07:17 2018 +0100

cmake: Create a list with required libraries

This should fix the build on OmniOS.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit db7070c65a8732996a11ce05287a2380278ec6a8
Author: Andreas Schneider 
Date:   Mon Nov 5 08:29:25 2018 +0100

tests: Protect IPv6 function in setup_echo_srv_tcp_ipv6

Fixes the build on OmniOS.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit f690f8c0873d87359f9d3c11e46c8c4dc185af0e
Author: Andreas Schneider 
Date:   Wed Oct 31 08:04:03 2018 +0100

tests: Protect IPv6 case in echo_srv

This fixes the build on OmniOS.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit fb4df592a055669b8046e2d0a263b8cc49633fb0
Author: Andreas Schneider 
Date:   Wed Oct 31 08:02:25 2018 +0100

swrap: Protect IPv6 case in swrap_socket()

Fixes the build on OmniOS

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 .gitlab-ci.yml |  5 +
 ConfigureChecks.cmake  |  7 ---
 src/socket_wrapper.c   |  2 ++
 tests/CMakeLists.txt   | 12 
 tests/echo_srv.c   |  6 ++
 tests/test_echo_tcp_bind.c |  2 ++
 6 files changed, 27 insertions(+), 7 deletions(-)


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1f9dab3..00b4576 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -77,10 +77,7 @@ fedora/undefined-sanitizer:
 paths:
   - obj/
 
-# This runner is disabled because there is a threading race condition in
-# FreeBSD.
-# See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848
-.freebsd/x86_64:
+freebsd/x86_64:
   image:
   script:
   - mkdir -p obj && cd obj && cmake
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index cb5bf53..17fdd3e 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -72,7 +72,7 @@ check_function_exists(pledge HAVE_PLEDGE)
 if (UNIX)
 find_library(DLFCN_LIBRARY dl)
 if (DLFCN_LIBRARY)
-string(APPEND _REQUIRED_LIBRARIES ${DLFCN_LIBRARY})
+list(APPEND _REQUIRED_LIBRARIES ${DLFCN_LIBRARY})
 else()
 check_function_exists(dlopen HAVE_DLOPEN)
 if (NOT HAVE_DLOPEN)
@@ -84,13 +84,13 @@ if (UNIX)
 # libsocket (Solaris)
 check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET)
 if (HAVE_LIBSOCKET)
-string(APPEND _REQUIRED_LIBRARIES socket)
+list(APPEND _REQUIRED_LIBRARIES socket)
 endif (HAVE_LIBSOCKET)
 
 # libnsl/inet_pton (Solaris)
 check_library_exists(nsl inet_pton "" HAVE_LIBNSL)
 if (HAVE_LIBNSL)
-string(APPEND _REQUIRED_LIBRARIES nsl)
+list(APPEND _REQUIRED_LIBRARIES nsl)
 endif (HAVE_LIBNSL)
 endif (NOT LINUX)
 
@@ -269,4 +269,5 @@ endif (NOT WIN32)
 
 check_type_size(pid_t SIZEOF_PID_T)
 
+string(REPLACE ";" " " _REQUIRED_LIBRARIES "${_REQUIRED_LIBRARIES}")
 set(SWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL 
"socket_wrapper required system libraries")
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 5e3a47b..a107710 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -3098,6 +3098,7 @@ static int swrap_socket(int family, int type, int 
protocol)
memcpy(>myname.sa.in, , si->myname.sa_socklen);
break;
}
+#ifdef HAVE_IPV6
case AF_INET6: {
struct sockaddr_in6 sin6 = {
.sin6_family = AF_INET6,
@@ -3107,6 +3108,7 @@ static int swrap_socket(int family, int type, int 
protocol)
memcpy(>myname.sa.in6, , si->myname.sa_socklen);
break;
   

[SCM] Socket Wrapper Repository - branch master updated

2018-10-30 Thread Andreas Schneider
The branch, master has been updated
   via  916ce9c cmake: Don't use string PREPEND
  from  32df6eb swrap: Fix coverity issues

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 916ce9c66576f4de24dfe774fe9ab094187c1462
Author: Andreas Schneider 
Date:   Wed Oct 24 08:44:19 2018 +0200

cmake: Don't use string PREPEND

This is only supported in cmake >= 3.10.

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 tests/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3578f76..b43d03c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -83,8 +83,8 @@ function(ADD_CMOCKA_TEST_ENVIRONMENT _TEST_NAME)
 if (OSX)
 set(TORTURE_ENVIRONMENT 
"DYLD_FORCE_FLAT_NAMESPACE=1;DYLD_INSERT_LIBRARIES=${SOCKET_WRAPPER_LOCATION}")
 else ()
-string(REPLACE ";" ":" TORTURE_ENVIRONMENT "${PRELOAD_LIBRARIES}")
-string(PREPEND TORTURE_ENVIRONMENT "LD_PRELOAD=")
+string(REPLACE ";" ":" _TMP_ENV "${PRELOAD_LIBRARIES}")
+set(TORTURE_ENVIRONMENT "LD_PRELOAD=${_TMP_ENV}")
 endif()
 
 set_property(TEST


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-10-29 Thread Andreas Schneider
The branch, master has been updated
   via  32df6eb swrap: Fix coverity issues
  from  c26835a gitlab-ci: Disable the FreeBSD runner

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 32df6eb3c0d6ef19f561ff65e444b3ce3dff5a9e
Author: Anoop C S 
Date:   Fri Oct 26 15:44:53 2018 +0530

swrap: Fix coverity issues

CID 184220
CID 184221

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 src/socket_wrapper.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 0f19b95..5e3a47b 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -2055,8 +2055,6 @@ static void swrap_remove_stale(int fd)
 
reset_socket_info_index(fd);
 
-   swrap_mutex_unlock(_reset_mutex);
-
si = swrap_get_socket_info(si_index);
 
swrap_mutex_lock(_free_mutex);
@@ -2078,6 +2076,7 @@ static void swrap_remove_stale(int fd)
 out:
SWRAP_UNLOCK_SI(si);
swrap_mutex_unlock(_free_mutex);
+   swrap_mutex_unlock(_reset_mutex);
 }
 
 static int sockaddr_convert_to_un(struct socket_info *si,
@@ -5935,8 +5934,6 @@ static int swrap_close(int fd)
 
reset_socket_info_index(fd);
 
-   swrap_mutex_unlock(_reset_mutex);
-
si = swrap_get_socket_info(si_index);
 
swrap_mutex_lock(_free_mutex);
@@ -5970,6 +5967,7 @@ static int swrap_close(int fd)
 out:
SWRAP_UNLOCK_SI(si);
swrap_mutex_unlock(_free_mutex);
+   swrap_mutex_unlock(_reset_mutex);
 
return ret;
 }


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-10-23 Thread Andreas Schneider
The branch, master has been updated
   via  c26835a gitlab-ci: Disable the FreeBSD runner
   via  7628650 gitlab-ci: Add helgrind tests
   via  bee622b gitlab-ci: Add runners and toolchain files
   via  ab9cf16 tests: Init in_addr only once in test_tcp_socket_overwrite
   via  35174c8 tests: Return an error if setenv() fails in test_max_sockets
   via  b6f1a42 tests: Check the correct return code in 
test_thread_echo_tcp_write_read
   via  d588231 tests: Check return code of connect in 
test_thread_echo_tcp_sendmsg_recvmsg
   via  7232dee tests: Check the return code of connect in 
test_echo_udp_sendmsg_recvmsg
   via  6e65180 tests: Check return code of connnect in 
test_echo_tcp_sendmsg_recvmsg
   via  545d0b7 echo_srv: Check for a valid pidfile pointer
   via  04091a9 echo_srv: Only use 128K as buffer size instead of 4MB
   via  c49a629 torture: Wait longer for echo_srv startup
   via  9289145 echo_srv: Do not close bogus file descriptors
   via  326e9f8 swrap: Don't do a deep bind if we run with libasan
   via  370ece1 swrap: Add a mutex for resetting socket index
   via  0b1a43e swrap: Fix helgrind errors
   via  a2a8a80 tests: Use assert_return_code() to get errno
   via  0983cd2 tests: Avoid -Wcast-align warning
   via  3d340c3 tests: Fix -Wformat gcc warning
   via  702f2fb cmake: Fix checking for required system libraries
   via  62080ac cmake: Use target_include_directories()
   via  d3d419b cmake: Require modern cmake version
   via  b976977 cmake: Update AddCMockaTest
   via  b91dae5 cmake: Update cmocka requirement
   via  4adb5cf cmake: Support running the tests with AddressSanitizer
   via  da17de1 cmake: Add CFLAGS for AddressSanitizer and 
UndefinedSanitizer
   via  402f548 cmake: Move Compiler flags to new file
   via  013687b cmake: Remove obsolete DefineCompilerFlags.cmake
   via  aa9b0da cmake: Improve checks for compiler flags
   via  5672618 cmake: Update CMake defaults
   via  a5df8fc cmake: Suppress helgrind race condition warning we created 
on purpose
   via  da4b908 cmake: Create an error if helgrind finds a bug
   via  f465bf4 cmake: Write helgrind logs to stderr so we can see them
   via  1ef1728 cmake: Don't misuse CMAKE_REQUIRED_LIBRARIES
  from  5bbd6ad tests: Update valgrind suppression file

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit c26835ad5b0165efe51535b9e11c9d7282eca4b2
Author: Andreas Schneider 
Date:   Tue Oct 2 16:40:16 2018 +0200

gitlab-ci: Disable the FreeBSD runner

There is a threading race condition in FreeBSD.

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 76286508446f6c1b278021e1074b1c078ae0caf7
Author: Andreas Schneider 
Date:   Thu Sep 27 21:10:45 2018 +0200

gitlab-ci: Add helgrind tests

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit bee622ba59ae933f219a2efba1c3f1a1d53a9783
Author: Andreas Schneider 
Date:   Thu Sep 27 17:56:11 2018 +0200

gitlab-ci: Add runners and toolchain files

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit ab9cf16f48fd996e77117bd48eddecd869397ffa
Author: Andreas Schneider 
Date:   Mon Oct 1 21:34:44 2018 +0200

tests: Init in_addr only once in test_tcp_socket_overwrite

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 35174c856c0c464e13f72c5e4b82a976d1c84c2a
Author: Andreas Schneider 
Date:   Mon Oct 1 21:28:27 2018 +0200

tests: Return an error if setenv() fails in test_max_sockets

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit b6f1a42a7e88ff0376f92911813f3f0f56d8ccf9
Author: Andreas Schneider 
Date:   Mon Oct 1 21:28:06 2018 +0200

tests: Check the correct return code in test_thread_echo_tcp_write_read

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit d588231d05fa80bce1e860f9797d7a4a7624c670
Author: Andreas Schneider 
Date:   Mon Oct 1 21:27:40 2018 +0200

tests: Check return code of connect in test_thread_echo_tcp_sendmsg_recvmsg

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 7232dee952f4d4da4e670ff918589ec22a323631
Author: Andreas Schneider 
Date:   Mon Oct 1 21:31:19 2018 +0200

tests: Check the return code of connect in test_echo_udp_sendmsg_recvmsg

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 6e651805d42d808abb374f725dd5c5e25fe3ff1a
Author: Andreas Schneider 
Date:   Mon Oct 1 21:27:14 2018 +0200

tests: Check return code of connnect in test_echo_tcp_sendmsg_recvmsg

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 545d0b77d3308fde3de50c446b02ef1571b5cfa6
Author: Andreas Schneider 
Date:   Mon Oct 1 21:23:31 2018 +0200

echo_srv: Check 

[SCM] Socket Wrapper Repository - branch master updated

2018-08-17 Thread Andreas Schneider
The branch, master has been updated
   via  5bbd6ad tests: Update valgrind suppression file
   via  0053c60 cmake: Require at least cmake 3.2.0
  from  93d4387 ctest: Move to new dashboard

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 5bbd6ad51830daa0fa18b8d32fc591e1710cf222
Author: Andreas Schneider 
Date:   Tue Aug 14 11:42:38 2018 +0200

tests: Update valgrind suppression file

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 0053c607acb62f3c7ae66ba0d881d63a2d0bd03e
Author: Andreas Schneider 
Date:   Thu Aug 9 11:16:29 2018 +0200

cmake: Require at least cmake 3.2.0

This allows us to modernize the CMakeLists.txt

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CMakeLists.txt | 11 +++
 CPackConfig.cmake  | 11 ---
 ConfigureChecks.cmake  |  4 ++--
 config.h.cmake |  4 ++--
 socket_wrapper-config-version.cmake.in |  2 +-
 socket_wrapper.pc.cmake|  4 ++--
 tests/valgrind.supp| 10 +-
 7 files changed, 23 insertions(+), 23 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9de79b4..efb30d8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,17 +1,12 @@
-project(socket_wrapper C)
-
 # Required cmake version
 cmake_minimum_required(VERSION 2.8.5)
+cmake_policy(SET CMP0048 NEW)
+
+project(socket_wrapper VERSION 1.1.9 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
 
-set(APPLICATION_VERSION_MAJOR "1")
-set(APPLICATION_VERSION_MINOR "1")
-set(APPLICATION_VERSION_PATCH "9")
-
-set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
-
 # SOVERSION scheme: CURRENT.AGE.REVISION
 #   If there was an incompatible interface change:
 # Increment CURRENT. Set AGE and REVISION to 0
diff --git a/CPackConfig.cmake b/CPackConfig.cmake
index e1b83ac..6cf14a6 100644
--- a/CPackConfig.cmake
+++ b/CPackConfig.cmake
@@ -2,7 +2,7 @@
 # http://www.cmake.org/Wiki/CMake:CPackConfiguration
 
 ### general settings
-set(CPACK_PACKAGE_NAME ${APPLICATION_NAME})
+set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The SSH library")
 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
 set(CPACK_PACKAGE_VENDOR "The SSH Library Development Team")
@@ -11,10 +11,7 @@ set(CPACK_RESOURCE_FILE_LICENSE 
"${CMAKE_SOURCE_DIR}/LICENSE")
 
 
 ### versions
-set(CPACK_PACKAGE_VERSION_MAJOR "${APPLICATION_VERSION_MAJOR}")
-set(CPACK_PACKAGE_VERSION_MINOR "${APPLICATION_VERSION_MINOR}")
-set(CPACK_PACKAGE_VERSION_PATCH "${APPLICATION_VERSION_PATCH}")
-set(CPACK_PACKAGE_VERSION 
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
 
 
 ### source generator
@@ -37,7 +34,7 @@ endif (WIN32)
 
 set(CPACK_PACKAGE_INSTALL_DIRECTORY "libssh")
 
-set(CPACK_PACKAGE_FILE_NAME ${APPLICATION_NAME}-${CPACK_PACKAGE_VERSION})
+set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION})
 
 set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
 set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers")
@@ -46,7 +43,7 @@ set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
 set(CPACK_COMPONENT_HEADERS_DESCRIPTION
   "C/C++ header files for use with libssh")
 set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
-#set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
+#set(CPACK_COMPONENT_PROJECTS_GROUP "Runtime")
 set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
 set(CPACK_COMPONENT_HEADERS_GROUP "Development")
 
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 93010f4..8fdb7f4 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -7,8 +7,8 @@ include(CheckStructHasMember)
 include(CheckPrototypeDefinition)
 include(TestBigEndian)
 
-set(PACKAGE ${APPLICATION_NAME})
-set(VERSION ${APPLICATION_VERSION})
+set(PACKAGE ${PROJECT_NAME})
+set(VERSION ${PROJECT_VERSION})
 set(DATADIR ${DATA_INSTALL_DIR})
 set(LIBDIR ${LIB_INSTALL_DIR})
 set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
diff --git a/config.h.cmake b/config.h.cmake
index b98ceff..5baa789 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -1,8 +1,8 @@
 /* Name of package */
-#cmakedefine PACKAGE "${APPLICATION_NAME}"
+#cmakedefine PACKAGE "${PROJECT_NAME}"
 
 /* Version number of package */
-#cmakedefine VERSION "${APPLICATION_VERSION}"
+#cmakedefine VERSION "${PROJECT_VERSION}"
 
 #cmakedefine LOCALEDIR "${LOCALE_INSTALL_DIR}"
 #cmakedefine DATADIR "${DATADIR}"
diff --git a/socket_wrapper-config-version.cmake.in 
b/socket_wrapper-config-version.cmake.in
index 98f292c..4bff45e 

[SCM] Socket Wrapper Repository - branch master updated

2018-08-09 Thread Andreas Schneider
The branch, master has been updated
   via  93d4387 ctest: Move to new dashboard
   via  f0f8640 swrap: Add error check around pthread mutex locks
   via  1551444 tests: Prevent child process falling to defunct state
   via  326ae3b doc: Add SOCKET_WRAPPER_MAX_SOCKETS to manual page
   via  8ba0d9c swrap: Fix thread deadlock found by Coverity scan
   via  4d732f6 tests: Add missing header for IPPROTO_TCP
   via  32c1b58 swrap: Update header
   via  50fc189 Update LICENSE
   via  6c3e3b3 Rename COPYING to LICENSE
   via  f8b725a cpack: Do not package build dirs in source tarball
  from  5529ba0 swrap: Replace socket_fds linked list with an array

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 93d4387c27efb2b62bdc4240f66b2030f82c7705
Author: Andreas Schneider 
Date:   Thu Jul 5 10:14:14 2018 +0200

ctest: Move to new dashboard

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit f0f86400b6a9b9b8fc7ffddc24c64000f7b6866f
Author: Anoop C S 
Date:   Tue Jun 12 20:19:34 2018 +0530

swrap: Add error check around pthread mutex locks

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 1551444228d7e0a0b0e1028dabd23d92fb8f2834
Author: Anoop C S 
Date:   Wed Jun 27 23:35:28 2018 +0530

tests: Prevent child process falling to defunct state

Parent process does not wait for child process(which gets forked after
accepting a client connection) to exit inside echo server which in turn
puts child into defunct state. Even though those defunct childs are
cleaned up during parent exit it is better to wait from parent process
itself.

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 326ae3b98f766b95ccc83717896acb8651ec2ab2
Author: Anoop C S 
Date:   Mon Jun 25 19:15:44 2018 +0530

doc: Add SOCKET_WRAPPER_MAX_SOCKETS to manual page

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 8ba0d9cf9769579f3c68f78b33477c10aa133e8c
Author: Anoop C S 
Date:   Fri Jun 15 12:36:54 2018 +0530

swrap: Fix thread deadlock found by Coverity scan

CID 175897
CID 175898

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 4d732f6d037cfc2ca3c44c51081163b1d3e06b17
Author: Andreas Schneider 
Date:   Fri Jun 29 15:17:10 2018 +0200

tests: Add missing header for IPPROTO_TCP

This fixes the build on FreeBSD.

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 32c1b58590648becf179bea82eead158c324d7a7
Author: Andreas Schneider 
Date:   Fri Jun 22 08:47:08 2018 +0200

swrap: Update header

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 50fc18998e65be6012c59d69752978a21f5def49
Author: Andreas Schneider 
Date:   Fri Jun 22 08:42:06 2018 +0200

Update LICENSE

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 6c3e3b3c816c5530c5be55ed9739fb87c9573e2d
Author: Andreas Schneider 
Date:   Fri Jun 22 08:38:04 2018 +0200

Rename COPYING to LICENSE

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit f8b725a982653824dbe4a580e15b2104fd18af4d
Author: Andreas Schneider 
Date:   Fri Jun 22 09:01:19 2018 +0200

cpack: Do not package build dirs in source tarball

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 .gitignore  |   2 +-
 CPackConfig.cmake   |   4 +-
 CTestConfig.cmake   |   6 +-
 COPYING => LICENSE  |   9 ++-
 doc/socket_wrapper.1|  21 -
 doc/socket_wrapper.1.txt|  10 ++-
 src/socket_wrapper.c| 182 ++--
 tests/echo_srv.c|   2 +
 tests/test_thread_sockets.c |   1 +
 9 files changed, 165 insertions(+), 72 deletions(-)
 rename COPYING => LICENSE (82%)


Changeset truncated at 500 lines:

diff --git a/.gitignore b/.gitignore
index 5d8f581..21038a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,6 @@
 *.swp
 *~
 build
-obj
+obj*/
 cscope.*
 tags
diff --git a/CPackConfig.cmake b/CPackConfig.cmake
index dc74dfa..e1b83ac 100644
--- a/CPackConfig.cmake
+++ b/CPackConfig.cmake
@@ -7,7 +7,7 @@ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The SSH library")
 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
 set(CPACK_PACKAGE_VENDOR "The SSH Library Development Team")
 set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
-set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
 
 
 ### versions
@@ -19,7 

[SCM] Socket Wrapper Repository - branch master updated

2018-06-14 Thread Andreas Schneider
The branch, master has been updated
   via  5529ba0 swrap: Replace socket_fds linked list with an array
  from  321833e tests: Fix resouce leak in echo_srv tcp handling

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 5529ba060519017bb71de5de6e7b81e5b3d56ccf
Author: Anoop C S 
Date:   Sun Jun 10 13:19:14 2018 +0530

swrap: Replace socket_fds linked list with an array

This fixes the following bug:

As we are using a doubly linked list, we need a mutex which needs to be
locked when we are reading it that we do not end up with invalid
pointers.

The following can happen:

We are in swrap_close() which calls find_socket_info_fd() this locks the
mutex for the linked list. Now we get a singal SIGCHILD and the signal
handler is called. The signal handler calls swrap_write() and we try to
find out if the socket is managed by socket_wrapper calling
find_socket_info_fd() again -> DEADLOCK!

By moving to an array to handle the socket fds and using the fd as the
array access, we do not need a mutex for reading anymore. All we need is
a memory barrier.

This change also improves the performance as we move from the a linked
list to a hash table!

Pair-Programmed-With: Andreas Schneider 

Signed-off-by: Anoop C S 
Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 src/socket_wrapper.c | 314 ---
 1 file changed, 122 insertions(+), 192 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 6c9ec51..a22f7dc 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -142,6 +142,10 @@ enum swrap_dbglvl_e {
} while(0)
 #endif
 
+#ifndef SAFE_FREE
+#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
+#endif
+
 #ifndef discard_const
 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
 #endif
@@ -198,68 +202,6 @@ enum swrap_dbglvl_e {
pthread_mutex_unlock(>meta.mutex); \
 } while(0)
 
-#define DLIST_ADD(list, item) do { \
-   if (!(list)) { \
-   (item)->prev= NULL; \
-   (item)->next= NULL; \
-   (list)  = (item); \
-   } else { \
-   (item)->prev= NULL; \
-   (item)->next= (list); \
-   (list)->prev= (item); \
-   (list)  = (item); \
-   } \
-} while (0)
-
-#define SWRAP_DLIST_ADD(list, item) do { \
-   SWRAP_LOCK(list); \
-   DLIST_ADD(list, item); \
-   SWRAP_UNLOCK(list); \
-} while (0)
-
-#define DLIST_REMOVE(list, item) do { \
-   if ((list) == (item)) { \
-   (list)  = (item)->next; \
-   if (list) { \
-   (list)->prev= NULL; \
-   } \
-   } else { \
-   if ((item)->prev) { \
-   (item)->prev->next  = (item)->next; \
-   } \
-   if ((item)->next) { \
-   (item)->next->prev  = (item)->prev; \
-   } \
-   } \
-   (item)->prev= NULL; \
-   (item)->next= NULL; \
-} while (0)
-
-#define SWRAP_DLIST_REMOVE(list,item) do { \
-   SWRAP_LOCK(list); \
-   DLIST_REMOVE(list, item); \
-   SWRAP_UNLOCK(list); \
-} while (0)
-
-#define DLIST_ADD_AFTER(list, item, el) do { \
-   if ((list) == NULL || (el) == NULL) { \
-   DLIST_ADD(list, item); \
-   } else { \
-   (item)->prev = (el); \
-   (item)->next = (el)->next; \
-   (el)->next = (item); \
-   if ((item)->next != NULL) { \
-   (item)->next->prev = (item); \
-   } \
-   } \
-} while (0)
-
-#define SWRAP_DLIST_ADD_AFTER(list, item, el) do { \
-   SWRAP_LOCK(list); \
-   DLIST_ADD_AFTER(list, item, el); \
-   SWRAP_UNLOCK(list); \
-} while (0)
-
 #if defined(HAVE_GETTIMEOFDAY_TZ) || defined(HAVE_GETTIMEOFDAY_TZ_VOID)
 #define swrapGetTimeOfDay(tval) gettimeofday(tval,NULL)
 #else
@@ -288,7 +230,6 @@ enum swrap_dbglvl_e {
 
 #define SOCKET_MAX_SOCKETS 1024
 
-
 /*
  * Maximum number of socket_info structures that can
  * be used. Can be overriden by the environment variable
@@ -316,17 +257,6 @@ struct swrap_address {
} sa;
 };
 
-struct socket_info_fd {
-   struct socket_info_fd *prev, *next;
-   int fd;
-
-   /*
-* Points to corresponding index in array of
-* socket_info structures
-*/
-   int si_index;
-};
-
 int first_free;
 
 struct socket_info
@@ -376,7 +306,7 @@ static size_t max_sockets = 0;
  * numerical value gets changed. So its better to store it locally to each
  * process rather than including 

[SCM] Socket Wrapper Repository - branch master updated

2018-05-04 Thread Andreas Schneider
The branch, master has been updated
   via  321833e tests: Fix resouce leak in echo_srv tcp handling
  from  7b01e29 cmake: Run threaded tests with helgrind

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 321833e2696f1964eef6ff1bfa2455da735a372a
Author: Andreas Schneider 
Date:   Fri May 4 08:01:29 2018 +0200

tests: Fix resouce leak in echo_srv tcp handling

CID 175587

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 tests/echo_srv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/tests/echo_srv.c b/tests/echo_srv.c
index 2f877f4..771904a 100644
--- a/tests/echo_srv.c
+++ b/tests/echo_srv.c
@@ -534,9 +534,8 @@ static void echo_tcp(int sock)
 }
 close(s);
 exit(0);
-} else {
-close(s);
 }
+close(s);
 }
 
 done:


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-05-03 Thread Andreas Schneider
The branch, master has been updated
   via  7b01e29 cmake: Run threaded tests with helgrind
   via  1ff35b6 tests: Add test case to validate free-list indexes
   via  da1fe44 swrap: Update free-list only when refcount is zero
   via  7299ab3 swrap: Move metadata into socket_info_meta structure
   via  01ceb51 tests: New threaded test cases
   via  c48282b tests: Modify echo server to accept multiple connections
   via  a5c0851 tests: Add new test to check mutex lock contention
   via  b6909fc swrap: Implement thread safety using pthread mutexes
   via  501b5f3 swrap: Rearrange swrap_remove_stale
   via  64c8487 swrap: Rearrange swrap_close
   via  548f4d0 swrap: Remove swrap_first_free_index
   via  d0b13ef swrap: Use swrap_create_socket within swrap_accept
   via  e30b080 swrap: Use swrap_create_socket within swrap_socket
   via  9702a15 swrap: Add new routines to handle socket creation
   via  327cb50 swrap: Internal reorganization of core socket_info 
structures
   via  b1728e6 swrap: Reorder code inside swrap_socket
   via  203a279 swrap: Use swrap_get_socket_info inside 
socket_wrapper_first_free_index
   via  6661997 swrap: set errno to ENFILE if there is no more free 
socket_info
   via  aec1e12 swrap: New helper functions to treat next_free
   via  10b6cc0 swrap: Use helper functions to manage refcount
   via  f55c1be swrap: Use helper function swrap_get_socket_info
   via  a685112 swrap: Make early-libc-out more obvious by removing else
  from  f152f98 tests: Increase wait time for setup and teardown to 5ms

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 7b01e29d2c95216c842b56b89c88e900cfb4991b
Author: Andreas Schneider 
Date:   Wed May 2 17:05:21 2018 +0200

cmake: Run threaded tests with helgrind

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 1ff35b6bb9a2702c4b0785281f22018b05e549c8
Author: Anoop C S 
Date:   Wed Jan 31 22:43:21 2018 +0530

tests: Add test case to validate free-list indexes

Signed-off-by: Anoop C S 
Reviewed-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit da1fe44b27ce2dc66d795637c13bc13b2a657b79
Author: Anoop C S 
Date:   Wed Jan 31 22:46:23 2018 +0530

swrap: Update free-list only when refcount is zero

Signed-off-by: Anoop C S 
Reviewed-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit 7299ab3541c94f38ee62a9d39348bbeb438bfc1a
Author: Michael Adam 
Date:   Thu Jul 13 01:25:19 2017 +0200

swrap: Move metadata into socket_info_meta structure

Separating out the metadata related information to another
sub-structure to make it more clean and structured.

Pair-Programmed-With: Anoop C S 

Signed-off-by: Michael Adam 
Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit 01ceb512ccfb60431754fb40704c9fcfb46fc4ac
Author: Anoop C S 
Date:   Thu Mar 2 07:26:20 2017 +

tests: New threaded test cases

Signed-off-by: Anoop C S 
Reviewed-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit c48282b7920b6b0037d08b181403042731585d21
Author: Anoop C S 
Date:   Thu Mar 2 07:12:50 2017 +

tests: Modify echo server to accept multiple connections

In context of multiple threads, echo server must be capable of
accepting connections in a loop rather than be satisfied with
one incoming connection.

Signed-off-by: Anoop C S 
Reviewed-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit a5c08518e985bd3f0cb274c274c034be37fa5629
Author: Michael Adam 
Date:   Thu Sep 22 03:53:27 2016 +0200

tests: Add new test to check mutex lock contention

Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit b6909fc91d5d16ced108700cbd5cd8a13481a6c4
Author: Anoop C S 
Date:   Tue Mar 28 07:13:47 2017 +

swrap: Implement thread safety using pthread mutexes

Added a new mutex variable to socket_info structure along with
new macros for locking and unlocking mutex corresponding to
each socket_info entry. Apart from individual mutex defined in
socket_info structure, 4 new mutexes are added to protect the
concurrent access of globally used swrap parameters from different
threads.

All other individual wrappers and helper routines are also made

[SCM] Socket Wrapper Repository - branch master updated

2018-05-02 Thread Andreas Schneider
The branch, master has been updated
   via  f152f98 tests: Increase wait time for setup and teardown to 5ms
  from  142024a tests: Remove extra test by moving getsockname() to another

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f152f98a98d5b56b26386ae570f343253743289c
Author: Andreas Schneider 
Date:   Wed May 2 12:23:50 2018 +0200

tests: Increase wait time for setup and teardown to 5ms

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 tests/torture.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/tests/torture.c b/tests/torture.c
index 55c27c6..0579779 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -188,7 +188,7 @@ static void torture_setup_echo_srv_ip(void **state,
}
 
rc = stat(s->srv_pidfile, );
-   usleep(2000);
+   usleep(5000);
} while (rc != 0);
assert_int_equal(rc, 0);
 
@@ -288,7 +288,7 @@ void torture_teardown_echo_srv(void **state)
/* Make sure the daemon goes away! */
kill(pid, SIGTERM);
 
-   usleep(200);
+   usleep(5000);
 
rc = kill(pid, 0);
if (rc != 0) {


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-03-26 Thread Andreas Schneider
The branch, master has been updated
   via  142024a tests: Remove extra test by moving getsockname() to another
  from  33da03f cmake: Fix configure check for fall-through attribute

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 142024a641ca43f842584499b5694d26853dd3d9
Author: Anoop C S 
Date:   Fri Mar 23 17:12:49 2018 +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 
Reviewed-by: Andreas Schneider 
Reviewed-by: Andrew Bartlet 

---

Summary of changes:
 tests/CMakeLists.txt |  1 -
 tests/test_echo_tcp_socket.c | 69 
 tests/test_tcp_listen.c  |  2 ++
 3 files changed, 2 insertions(+), 70 deletions(-)
 delete mode 100644 tests/test_echo_tcp_socket.c


Changeset truncated at 500 lines:

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b86cc84..836a5e2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -24,7 +24,6 @@ set(SWRAP_TESTS
 test_tcp_listen
 test_tcp_dup2
 test_fcntl
-test_echo_tcp_socket
 test_echo_tcp_connect
 test_echo_tcp_bind
 test_echo_tcp_socket_options
diff --git a/tests/test_echo_tcp_socket.c b/tests/test_echo_tcp_socket.c
deleted file mode 100644
index 57b92de..000
--- a/tests/test_echo_tcp_socket.c
+++ /dev/null
@@ -1,69 +0,0 @@
-#include 
-#include 
-#include 
-#include 
-
-#include "config.h"
-#include "torture.h"
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-static void test_socket_getsockname(void **state)
-{
-   struct torture_address addr = {
-   .sa_socklen = sizeof(struct sockaddr_in),
-   };
-   int rc;
-   int s;
-
-   (void) state; /* unused */
-
-   s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-   assert_int_not_equal(s, -1);
-
-   rc = getsockname(s, , _socklen);
-   assert_return_code(rc, errno);
-   assert_int_equal(addr.sa.in.sin_family, AF_INET);
-}
-
-#ifdef HAVE_IPV6
-static void test_socket_getsockname6(void **state)
-{
-   struct torture_address addr = {
-   .sa_socklen = sizeof(struct sockaddr_in),
-   };
-   int rc;
-   int s;
-
-   (void) state; /* unused */
-
-   s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
-   assert_int_not_equal(s, -1);
-
-   rc = getsockname(s, , _socklen);
-   assert_return_code(rc, errno);
-   assert_int_equal(addr.sa.in6.sin6_family, AF_INET6);
-}
-#endif
-
-int main(void) {
-   int rc;
-
-   const struct CMUnitTest getsockname_tests[] = {
-   cmocka_unit_test(test_socket_getsockname),
-#ifdef HAVE_IPV6
-   cmocka_unit_test(test_socket_getsockname6),
-#endif
-   };
-
-   rc = cmocka_run_group_tests(getsockname_tests, NULL, NULL);
-
-   return rc;
-}
diff --git a/tests/test_tcp_listen.c b/tests/test_tcp_listen.c
index 5641c47..746620d 100644
--- a/tests/test_tcp_listen.c
+++ b/tests/test_tcp_listen.c
@@ -52,6 +52,7 @@ static void test_listen_unbound_ipv4(void **state)
 
rc = getsockname(s1, , _socklen);
assert_return_code(rc, errno);
+   assert_int_equal(addr.sa.in.sin_family, AF_INET);
assert_int_equal(addr.sa_socklen, sizeof(struct sockaddr_in));
assert_in_range(ntohs(addr.sa.in.sin_port), 1024, 65535);
 
@@ -85,6 +86,7 @@ static void test_listen_unbound_ipv6(void **state)
 
rc = getsockname(s1, , _socklen);
assert_return_code(rc, errno);
+   assert_int_equal(addr.sa.in6.sin6_family, AF_INET6);
assert_int_equal(addr.sa_socklen, sizeof(struct sockaddr_in6));
assert_in_range(ntohs(addr.sa.in6.sin6_port), 1024, 65535);
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-03-22 Thread Andreas Schneider
The branch, master has been updated
   via  33da03f cmake: Fix configure check for fall-through attribute
  from  f7fc3f5 cmake: Fix checks for attributes

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 33da03f478955daa04adca67fc012379bf0d2a39
Author: Andreas Schneider 
Date:   Wed Feb 28 07:36:58 2018 +0100

cmake: Fix configure check for fall-through attribute

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 ConfigureChecks.cmake | 17 -
 1 file changed, 4 insertions(+), 13 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index f06e780..93010f4 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -205,22 +205,13 @@ int main(void) {
 check_c_source_compiles("
 #define FALL_THROUGH __attribute__((fallthrough))
 
-enum direction_e {
-UP = 0,
-DOWN,
-};
-
 int main(void) {
-enum direction_e key = UP;
-int i = 10;
-int j = 0;
+int i = 2;
 
-switch (key) {
-case UP:
-i = 5;
+switch (i) {
+case 0:
 FALL_THROUGH;
-case DOWN:
-j = i * 2;
+case 1:
 break;
 default:
 break;


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-02-22 Thread Andreas Schneider
The branch, master has been updated
   via  f7fc3f5 cmake: Fix checks for attributes
  from  986684f swrap: Avoid double semicolons in the code

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f7fc3f5294fc4bfc917fe5827594b774be730f4b
Author: Andreas Schneider 
Date:   Thu Feb 22 09:37:40 2018 +0100

cmake: Fix checks for attributes

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 ConfigureChecks.cmake | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index cb2ea92..f06e780 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -42,7 +42,7 @@ if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
 "void __attribute__((visibility(\"default\"))) test() {}
 int main(void){ return 0; }
 " WITH_VISIBILITY_HIDDEN)
-set(CMAKE_REQUIRED_FLAGS "")
+unset(CMAKE_REQUIRED_FLAGS)
 endif (NOT GNUCC_VERSION EQUAL 34)
 endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
 
@@ -93,7 +93,7 @@ set(SWRAP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} 
CACHE INTERNAL "socket_
 check_struct_has_member("struct in_pktinfo" ipi_addr 
"sys/types.h;sys/socket.h;netinet/in.h" HAVE_STRUCT_IN_PKTINFO)
 set(CMAKE_REQUIRED_FLAGS -D_GNU_SOURCE)
 check_struct_has_member("struct in6_pktinfo" ipi6_addr 
"sys/types.h;sys/socket.h;netinet/in.h" HAVE_STRUCT_IN6_PKTINFO)
-set(CMAKE_REQUIRED_FLAGS)
+unset(CMAKE_REQUIRED_FLAGS)
 
 # STRUCT MEMBERS
 check_struct_has_member("struct sockaddr" sa_len 
"sys/types.h;sys/socket.h;netinet/in.h" HAVE_STRUCT_SOCKADDR_SA_LEN)
@@ -173,6 +173,11 @@ int main(void) {
 return 0;
 }" HAVE_SOCKADDR_STORAGE)
 
+###
+# For detecting attributes we need to treat warnings as
+# errors
+set(CMAKE_REQUIRED_FLAGS "-Werror")
+
 check_c_source_compiles("
 void test_constructor_attribute(void) __attribute__ ((constructor));
 
@@ -238,8 +243,6 @@ int main(void) {
 return 0;
 }" HAVE_FUNCTION_ATTRIBUTE_FORMAT)
 
-# If this produces a warning treat it as error!
-set(CMAKE_REQUIRED_FLAGS "-Werror")
 check_c_source_compiles("
 void test_address_sanitizer_attribute(void) 
__attribute__((no_sanitize_address));
 
@@ -251,7 +254,10 @@ void test_address_sanitizer_attribute(void)
 int main(void) {
 return 0;
 }" HAVE_ADDRESS_SANITIZER_ATTRIBUTE)
-set(CMAKE_REQUIRED_FLAGS)
+
+# Stop treating wanrings as errors
+unset(CMAKE_REQUIRED_FLAGS)
+###
 
 check_library_exists(dl dlopen "" HAVE_LIBDL)
 if (HAVE_LIBDL)


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2018-02-20 Thread Andreas Schneider
The branch, master has been updated
   via  986684f swrap: Avoid double semicolons in the code
  from  9a23836 Bump version to 1.1.9

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 986684ffa03f15f270c4deec2068ac3d2a450dea
Author: Andreas Schneider 
Date:   Tue Feb 20 17:52:00 2018 +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 

---

Summary of changes:
 src/socket_wrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 539d27d..02fe970 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -111,7 +111,7 @@ enum swrap_dbglvl_e {
 # ifdef HAVE_FALLTHROUGH_ATTRIBUTE
 #  define FALL_THROUGH __attribute__ ((fallthrough))
 # else /* HAVE_FALLTHROUGH_ATTRIBUTE */
-#  define FALL_THROUGH
+#  define FALL_THROUGH ((void)0)
 # endif /* HAVE_FALLTHROUGH_ATTRIBUTE */
 #endif /* FALL_THROUGH */
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2017-12-04 Thread Andreas Schneider
The branch, master has been updated
   via  9a23836 Bump version to 1.1.9
   via  3f80411 tests: Add a thread deadlock reproducer
   via  3547fdf swrap: Avoid symbol binding deadlocks during fork
   via  570930c swrap: Bind all symbols during prepare
   via  3d0f65f tests: Fix sa_socklen for sockaddr_in
   via  11bb41a swrap: Whitespace fixes
  from  230a8a0 Bump version to 1.1.8

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 9a23836b9789ae6405734e075fb440c3c06ad4ee
Author: Andreas Schneider 
Date:   Mon Dec 4 10:19:38 2017 +0100

Bump version to 1.1.9

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 3f804113608f0c2f04a8212fbacf569b67dd0a19
Author: Andreas Schneider 
Date:   Tue Nov 28 15:41:05 2017 +0100

tests: Add a thread deadlock reproducer

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 3547fdfc094f4588375cb7b1716461f8f328b643
Author: Andreas Schneider 
Date:   Mon Nov 27 11:00:54 2017 +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  0x7fe48837aef5 in __GI___pthread_mutex_lock (mutex=0x7fe4889a71c0 
) at ../nptl/pthread_mutex_lock.c:80
 2  0x7fe48879b2f1 in libc_write (fd=14, buf=0x7ffdad6436e8, count=8) 
at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:1070
 3  0x7fe4887a21cb in swrap_write (s=14, buf=0x7ffdad6436e8, len=8) at 
/home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:5137
 4  0x7fe4887a2359 in write (s=14, buf=0x7ffdad6436e8, len=8) at 
/home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:5171
 5  0x7fe48713e5f2 in tevent_common_wakeup_fd (fd=14) at 
../lib/tevent/tevent.c:959
 6  0x7fe48713e61f in tevent_common_wakeup (ev=ev@entry=0x55d04922e280) 
at ../lib/tevent/tevent.c:975
 7  0x7fe487141d38 in tevent_common_signal_handler (signum=) at ../lib/tevent/tevent_signal.c:109
 8  
 9  0x7fe4844de081 in __libc_fork () at ../sysdeps/nptl/fork.c:135
 10 0x55d047e8ddb3 in smbd_accept_connection (ev=0x55d04922e280, 
fde=, flags=, private_data=)
at ../source3/smbd/server.c:992

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 570930cff3511054a1a3e5e8155946b501ef
Author: Andreas Schneider 
Date:   Fri Dec 1 16:05:07 2017 +0100

swrap: Bind all symbols during prepare

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 3d0f65fcb183a0fb0e6ad122d929189ce5c0a2aa
Author: Andreas Schneider 
Date:   Tue Nov 28 10:15:07 2017 +0100

tests: Fix sa_socklen for sockaddr_in

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 11bb41a674a54cb0507b61270993902c0a5ff582
Author: Andreas Schneider 
Date:   Tue Nov 14 09:03:24 2017 +0100

swrap: Whitespace fixes

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CMakeLists.txt |   4 +-
 ChangeLog  |   3 +
 src/socket_wrapper.c   | 119 ++---
 tests/CMakeLists.txt   |   8 ++-
 tests/test_echo_tcp_bind.c |   4 +-
 tests/test_fork_thread_deadlock.c  |  98 +++
 tests/{torture.h => thread_deadlock.c} |  78 +
 7 files changed, 237 insertions(+), 77 deletions(-)
 create mode 100644 tests/test_fork_thread_deadlock.c
 copy tests/{torture.h => thread_deadlock.c} (56%)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f332cac..9de79b4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 
 set(APPLICATION_VERSION_MAJOR "1")
 set(APPLICATION_VERSION_MINOR "1")
-set(APPLICATION_VERSION_PATCH "8")
+set(APPLICATION_VERSION_PATCH "9")
 
 set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
 
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, 

[SCM] Socket Wrapper Repository - branch master updated

2017-10-13 Thread Andreas Schneider
The branch, master has been updated
   via  230a8a0 Bump version to 1.1.8
  from  c777417 swrap: Fix prototype of open[64] to prevent segfault on 
ppc64le

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 230a8a002b2017e76f5acb3c19ad919914e5d9fc
Author: Andreas Schneider 
Date:   Thu Oct 12 16:47:49 2017 +0200

Bump version to 1.1.8

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 CMakeLists.txt |  4 ++--
 ChangeLog  | 10 ++
 2 files changed, 12 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4d7c12e..f332cac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 
 set(APPLICATION_VERSION_MAJOR "1")
 set(APPLICATION_VERSION_MINOR "1")
-set(APPLICATION_VERSION_PATCH "7")
+set(APPLICATION_VERSION_PATCH "8")
 
 set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
 
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION "0.1.7")
+set(LIBRARY_VERSION "0.1.8")
 set(LIBRARY_SOVERSION "0")
 
 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is 
checked
diff --git a/ChangeLog b/ChangeLog
index dd03665..cfbcbe7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,16 @@
 ChangeLog
 ==
 
+version 1.1.8 (released 2017-10-13)
+  * Added support for openat()
+  * Added support for open64() and fopen64()
+  * Always enabled logging support
+  * Increased maximum for wrapped interfaces to 64
+  * Improved fd duplication code
+  * Fixed strict-aliasing issues
+  * Fixed some use after free issues
+  * Fixed issues on ppc64le
+
 version 1.1.7 (released 2016-05-20)
   * Added support for accept4()
   * Added support for OpenBSD


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2017-09-06 Thread Andreas Schneider
The branch, master has been updated
   via  c777417 swrap: Fix prototype of open[64] to prevent segfault on 
ppc64le
   via  753f387 swrap: Improve argument handling for libc_vopen*()
   via  03c0602 swrap: Improve argument handling for libc_vioctl()
   via  96c93cf swrap: Improve argument handling for libc_fcntl()
   via  a886815 tests: Add a simple fnctl() test
   via  b5a67f4 swrap: Simplify printing different log prefixes
   via  49d7a4e swrap: Do an early return if log level doesn't match
   via  d1bc679 swrap: Always enable logging
  from  fa9cc40 swrap: Protect the FALL_THROUGH define

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit c7774174beffe9a8d29dd4fb38bbed43ece1cecd
Author: Andreas Schneider 
Date:   Wed Aug 2 13:21:59 2017 +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 
Reviewed-by: Stefan Metzmacher 

commit 753f3872370a076628c272612da51963f4996ca4
Author: Andreas Schneider 
Date:   Tue Aug 1 10:58:50 2017 +0200

swrap: Improve argument handling for libc_vopen*()

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 03c06022e29e790938a1701a686ee2863677ff3c
Author: Andreas Schneider 
Date:   Tue Aug 1 10:48:47 2017 +0200

swrap: Improve argument handling for libc_vioctl()

The ioctl() only takes one or no argument.

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 96c93cf0ff3f06b99cdf84a3270e7686a4c7a0d3
Author: Andreas Schneider 
Date:   Tue Aug 1 10:20:46 2017 +0200

swrap: Improve argument handling for libc_fcntl()

fcntl() has either one or no argument.

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit a886815fc1408382a7bf0ac056e7c7d99f494345
Author: Andreas Schneider 
Date:   Mon Jul 31 19:25:41 2017 +0200

tests: Add a simple fnctl() test

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit b5a67f495620a38371cec166e05fa7010df8298a
Author: Andreas Schneider 
Date:   Mon Jul 31 18:25:42 2017 +0200

swrap: Simplify printing different log prefixes

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 49d7a4efd7a7de5a0962b358eb6e8c560a3f4711
Author: Andreas Schneider 
Date:   Mon Jul 31 18:25:30 2017 +0200

swrap: Do an early return if log level doesn't match

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit d1bc679f21155a19d5b691f695cf29c2a94b87cc
Author: Andreas Schneider 
Date:   Mon Jul 31 18:21:53 2017 +0200

swrap: Always enable logging

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 src/socket_wrapper.c | 110 +--
 tests/CMakeLists.txt |   1 +
 tests/test_fcntl.c   |  67 +++
 3 files changed, 114 insertions(+), 64 deletions(-)
 create mode 100644 tests/test_fcntl.c


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 280215e..ccbe67f 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -350,10 +350,6 @@ bool socket_wrapper_enabled(void);
 void swrap_constructor(void) CONSTRUCTOR_ATTRIBUTE;
 void swrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
 
-#ifdef NDEBUG
-# define SWRAP_LOG(...)
-#else
-
 static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *func, const char 
*format, ...) PRINTF_ATTRIBUTE(3, 4);
 # define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __func__, __VA_ARGS__)
 
@@ -365,42 +361,40 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl,
va_list va;
const char *d;
unsigned int lvl = 0;
+   const char *prefix = "SWRAP";
 
d = getenv("SOCKET_WRAPPER_DEBUGLEVEL");
if (d != NULL) {
lvl = atoi(d);
}
 
+   if (lvl < dbglvl) {
+   return;
+   }
+
va_start(va, format);
vsnprintf(buffer, sizeof(buffer), format, va);
va_end(va);
 
-   if (lvl >= dbglvl) {
-   switch (dbglvl) {
-   case SWRAP_LOG_ERROR:
-   fprintf(stderr,
-  

[SCM] Socket Wrapper Repository - branch master updated

2017-07-27 Thread Michael Adam
The branch, master has been updated
   via  fa9cc40 swrap: Protect the FALL_THROUGH define
  from  fafd5ed cmake: Replace deprecated get_target_property()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit fa9cc407f1a8bd17433835eedcc0135424d420a1
Author: Andreas Schneider 
Date:   Thu Jul 27 13:18:12 2017 +0200

swrap: Protect the FALL_THROUGH define

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 src/socket_wrapper.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 46fb683..280215e 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -107,11 +107,13 @@ enum swrap_dbglvl_e {
 #define DESTRUCTOR_ATTRIBUTE
 #endif
 
-#ifdef HAVE_FALLTHROUGH_ATTRIBUTE
-#define FALL_THROUGH __attribute__ ((fallthrough))
-#else
-#define FALL_THROUGH
-#endif
+#ifndef FALL_THROUGH
+# ifdef HAVE_FALLTHROUGH_ATTRIBUTE
+#  define FALL_THROUGH __attribute__ ((fallthrough))
+# else /* HAVE_FALLTHROUGH_ATTRIBUTE */
+#  define FALL_THROUGH
+# endif /* HAVE_FALLTHROUGH_ATTRIBUTE */
+#endif /* FALL_THROUGH */
 
 #ifdef HAVE_ADDRESS_SANITIZER_ATTRIBUTE
 #define DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE __attribute__((no_sanitize_address))


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2017-07-27 Thread Michael Adam
The branch, master has been updated
   via  fafd5ed cmake: Replace deprecated get_target_property()
   via  e961a1c swrap: Add common exit point to swrap_setsockopt
   via  070d84d swrap: Add common exit point to swrap_getsockopt
   via  b585bf0 swrap: Add common exit point to swrap_connect
   via  4c6082d swrap: Add common exit point to swrap_auto_bind
   via  d6253b3 swrap: Fix tab vs space in swrap_auto_bind
  from  ceb1767 swrap: Suppress intentional fall through warning

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit fafd5ed2dd89b7d951d70d0ac5585939cb2e4dcf
Author: Andreas Schneider 
Date:   Thu Jul 27 11:30:23 2017 +0200

cmake: Replace deprecated get_target_property()

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit e961a1c8b8e03d9e8f070a686207740b486340ea
Author: Anoop C S 
Date:   Thu Jul 13 02:43:47 2017 +0200

swrap: Add common exit point to swrap_setsockopt

In preparation of thread safety.

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit 070d84d733369a4de8f2b840a1f92065e2f3473d
Author: Anoop C S 
Date:   Thu Jul 13 02:36:20 2017 +0200

swrap: Add common exit point to swrap_getsockopt

In preparation of thread safety.

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit b585bf0a24d19e03f5a9fdc51b6b1bc90e60ddd6
Author: Anoop C S 
Date:   Thu Jul 13 02:30:14 2017 +0200

swrap: Add common exit point to swrap_connect

In preparation of thread safety.

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit 4c6082d88e1241fe678687fb0d19480e17e700e5
Author: Anoop C S 
Date:   Thu Jul 13 02:26:10 2017 +0200

swrap: Add common exit point to swrap_auto_bind

In preparation for thread safety.

Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit d6253b326ee53c4278458fc425335b64519d93dd
Author: Michael Adam 
Date:   Thu Jul 13 02:22:14 2017 +0200

swrap: Fix tab vs space in swrap_auto_bind

Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/CMakeLists.txt   |  7 +---
 src/socket_wrapper.c | 98 +++-
 2 files changed, 67 insertions(+), 38 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3b4d7d0..d96f773 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -23,9 +23,4 @@ set_target_properties(
 ${LIBRARY_SOVERSION}
 )
 
-# This needs to be at the end
-if (POLICY CMP0026)
-cmake_policy(SET CMP0026 OLD)
-endif()
-get_target_property(SWRAP_LOCATION socket_wrapper LOCATION)
-set(SOCKET_WRAPPER_LOCATION ${SWRAP_LOCATION} PARENT_SCOPE)
+set(SOCKET_WRAPPER_LOCATION 
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}socket_wrapper${CMAKE_SHARED_LIBRARY_SUFFIX}"
 PARENT_SCOPE)
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 29cd3f9..46fb683 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -3173,8 +3173,9 @@ static int swrap_auto_bind(int fd, struct socket_info 
*si, int family)
type = SOCKET_TYPE_CHAR_UDP;
break;
default:
-   errno = ESOCKTNOSUPPORT;
-   return -1;
+   errno = ESOCKTNOSUPPORT;
+   ret = -1;
+   goto done;
}
 
memset(, 0, sizeof(in));
@@ -3194,7 +3195,8 @@ static int swrap_auto_bind(int fd, struct socket_info 
*si, int family)
 
if (si->family != family) {
errno = ENETUNREACH;
-   return -1;
+   ret = -1;
+   goto done;
}
 
switch (si->type) {
@@ -3206,7 +3208,8 @@ static int swrap_auto_bind(int fd, struct socket_info 
*si, int family)
break;
default:
errno = ESOCKTNOSUPPORT;
-   return -1;
+   ret = -1;
+   goto done;
}
 
memset(, 0, sizeof(in6));
@@ -3223,7 +3226,8 @@ static int swrap_auto_bind(int fd, struct socket_info 
*si, int 

[SCM] Socket Wrapper Repository - branch master updated

2017-07-27 Thread Andreas Schneider
The branch, master has been updated
   via  ceb1767 swrap: Suppress intentional fall through warning
  from  9088344 swrap: Add fopen64() on systems which provide it

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit ceb17676cba178f56d00d21189c3f1765e5c2ae0
Author: Anoop C S 
Date:   Sat Jul 15 20:54:06 2017 +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 
Reviewed-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 ConfigureChecks.cmake | 27 +++
 config.h.cmake|  1 +
 src/socket_wrapper.c  | 16 +++-
 3 files changed, 39 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 0691c8a..cb2ea92 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -198,6 +198,33 @@ int main(void) {
 }" HAVE_DESTRUCTOR_ATTRIBUTE)
 
 check_c_source_compiles("
+#define FALL_THROUGH __attribute__((fallthrough))
+
+enum direction_e {
+UP = 0,
+DOWN,
+};
+
+int main(void) {
+enum direction_e key = UP;
+int i = 10;
+int j = 0;
+
+switch (key) {
+case UP:
+i = 5;
+FALL_THROUGH;
+case DOWN:
+j = i * 2;
+break;
+default:
+break;
+}
+
+return 0;
+}" HAVE_FALLTHROUGH_ATTRIBUTE)
+
+check_c_source_compiles("
 __thread int tls;
 
 int main(void) {
diff --git a/config.h.cmake b/config.h.cmake
index 2f494a4..b98ceff 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -62,6 +62,7 @@
 #cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
 #cmakedefine HAVE_CONSTRUCTOR_ATTRIBUTE 1
 #cmakedefine HAVE_DESTRUCTOR_ATTRIBUTE 1
+#cmakedefine HAVE_FALLTHROUGH_ATTRIBUTE 1
 #cmakedefine HAVE_ADDRESS_SANITIZER_ATTRIBUTE 1
 #cmakedefine HAVE_SOCKADDR_STORAGE 1
 #cmakedefine HAVE_IPV6 1
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 395d0d7..29cd3f9 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -107,6 +107,12 @@ enum swrap_dbglvl_e {
 #define DESTRUCTOR_ATTRIBUTE
 #endif
 
+#ifdef HAVE_FALLTHROUGH_ATTRIBUTE
+#define FALL_THROUGH __attribute__ ((fallthrough))
+#else
+#define FALL_THROUGH
+#endif
+
 #ifdef HAVE_ADDRESS_SANITIZER_ATTRIBUTE
 #define DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE __attribute__((no_sanitize_address))
 #else
@@ -587,7 +593,7 @@ static void *swrap_load_lib_handle(enum swrap_lib lib)
 
switch (lib) {
case SWRAP_LIBNSL:
-   /* FALL TROUGH */
+   FALL_THROUGH;
case SWRAP_LIBSOCKET:
 #ifdef HAVE_LIBSOCKET
handle = swrap.libc.socket_handle;
@@ -606,7 +612,7 @@ static void *swrap_load_lib_handle(enum swrap_lib lib)
}
break;
 #endif
-   /* FALL TROUGH */
+   FALL_THROUGH;
case SWRAP_LIBC:
handle = swrap.libc.handle;
 #ifdef LIBC_SO
@@ -1861,7 +1867,7 @@ static int sockaddr_convert_to_un(struct socket_info *si,
 * AF_UNSPEC is mapped to AF_INET and must be treated here.
 */
 
-   /* FALL THROUGH */
+   FALL_THROUGH;
}
case AF_INET:
 #ifdef HAVE_IPV6
@@ -2790,12 +2796,12 @@ static int swrap_socket(int family, int type, int 
protocol)
if (real_type == SOCK_STREAM) {
break;
}
-   /*fall through*/
+   FALL_THROUGH;
case 17:
if (real_type == SOCK_DGRAM) {
break;
}
-   /*fall through*/
+   FALL_THROUGH;
default:
   

[SCM] Socket Wrapper Repository - branch master updated

2017-04-06 Thread Andreas Schneider
The branch, master has been updated
   via  9088344 swrap: Add fopen64() on systems which provide it
   via  fb810a6 cmake: Check for fopen64() function
   via  b139b7c swrap: Add open64() on systems which provide it
   via  ef67998 cmake: Check for open64() function
   via  f64d6bd cmake: Do not check for LFS support
   via  502ab86 swrap: Increase max wrapped interfaces
  from  7ca7d61 tests: Fix test_close_failure test case

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 908834465e11736796e418dfdee6425f71959590
Author: Andreas Schneider 
Date:   Thu Apr 6 09:05:26 2017 +0200

swrap: Add fopen64() on systems which provide it

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit fb810a68eae6cb369d799805d3f0cd529f6d893c
Author: Andreas Schneider 
Date:   Thu Apr 6 09:02:21 2017 +0200

cmake: Check for fopen64() function

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit b139b7c2dae519a8fdd589b4bdff14b9a657fc4a
Author: Andreas Schneider 
Date:   Tue Mar 28 09:09:06 2017 +0200

swrap: Add open64() on systems which provide it

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

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit ef679984f4a85b4b75a85fc41df4d16a92f26721
Author: Andreas Schneider 
Date:   Tue Mar 28 09:03:02 2017 +0200

cmake: Check for open64() function

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

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit f64d6bd6526b046c350e8e421204461ee66cf9b8
Author: Andreas Schneider 
Date:   Tue Mar 28 08:58:14 2017 +0200

cmake: Do not check for LFS support

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

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 502ab86d4863802ef183cedbbf3283bf4bc07ab9
Author: Andreas Schneider 
Date:   Mon Mar 20 11:25:40 2017 +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 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 ConfigureChecks.cmake   |  2 +
 cmake/Modules/DefineCompilerFlags.cmake | 29 --
 config.h.cmake  |  2 +
 src/socket_wrapper.c| 99 -
 4 files changed, 102 insertions(+), 30 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 71b34ce..0691c8a 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -63,6 +63,8 @@ check_function_exists(eventfd HAVE_EVENTFD)
 check_function_exists(timerfd_create HAVE_TIMERFD_CREATE)
 check_function_exists(bindresvport HAVE_BINDRESVPORT)
 check_function_exists(accept4 HAVE_ACCEPT4)
+check_function_exists(open64 HAVE_OPEN64)
+check_function_exists(fopen64 HAVE_FOPEN64)
 
 check_function_exists(pledge HAVE_PLEDGE)
 
diff --git a/cmake/Modules/DefineCompilerFlags.cmake 
b/cmake/Modules/DefineCompilerFlags.cmake
index 53481c3..c60e586 100644
--- a/cmake/Modules/DefineCompilerFlags.cmake
+++ b/cmake/Modules/DefineCompilerFlags.cmake
@@ -53,35 +53,6 @@ if (UNIX AND NOT WIN32)
 endif()
 endif (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
 
-#
-# Check for large filesystem support
-#
-if (CMAKE_SIZEOF_VOID_P MATCHES "8")
-# with large file support
-execute_process(
-COMMAND
-getconf LFS64_CFLAGS
-OUTPUT_VARIABLE
-_lfs_CFLAGS
-ERROR_QUIET
-OUTPUT_STRIP_TRAILING_WHITESPACE
-)
-else (CMAKE_SIZEOF_VOID_P MATCHES "8")
-# with large file support
-execute_process(
-COMMAND
-getconf LFS_CFLAGS
-OUTPUT_VARIABLE
-_lfs_CFLAGS
-ERROR_QUIET
-OUTPUT_STRIP_TRAILING_WHITESPACE
-)
-endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
-if (_lfs_CFLAGS)
-string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_lfs_CFLAGS}")
-endif (_lfs_CFLAGS)
-
 endif (UNIX AND NOT WIN32)
 
 if (MSVC)
diff --git a/config.h.cmake b/config.h.cmake
index 6786b8a..2f494a4 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -40,6 +40,8 @@
 #cmakedefine HAVE_TIMERFD_CREATE 1
 #cmakedefine 

[SCM] Socket Wrapper Repository - branch master updated

2017-03-17 Thread Andreas Schneider
The branch, master has been updated
   via  7ca7d61 tests: Fix test_close_failure test case
  from  6e1a3b5 swrap: use proper blocks for early returns

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 7ca7d61c07d9dc884f06d2c77879694deac77b90
Author: Michael Adam 
Date:   Thu Mar 16 11:18:28 2017 +

tests: Fix test_close_failure test case

Found by valgrind.

Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 tests/test_close_failure.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/tests/test_close_failure.c b/tests/test_close_failure.c
index 0c9d6a7..8a6d40e 100644
--- a/tests/test_close_failure.c
+++ b/tests/test_close_failure.c
@@ -23,14 +23,12 @@ static int teardown(void **state)
 static void test_close_failure(void **state)
 {
int s;
-   int rc;
 
(void) state; /* unused */
-   (void) s; /*set but not used */
 
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 
-   assert_int_not_equal(rc, -1);
+   assert_int_not_equal(s, -1);
 
/* Do not close the socket here so that destructor
 * handles it and no hang should be observed.*/


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2017-03-02 Thread Andreas Schneider
The branch, master has been updated
   via  6e1a3b5 swrap: use proper blocks for early returns
   via  1de39d8 swrap: Add support for openat()
  from  68e1cbf Increase wait time during echo_server's pid-file check

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 6e1a3b50fb344107f7cfbcef35a4cf10c1e12113
Author: Michael Adam 
Date:   Fri Sep 23 16:33:52 2016 +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 
Reviewed-by: Andreas Schneider 

commit 1de39d82428fc6559ea5ea2d35187808020be9bf
Author: Andreas Schneider 
Date:   Thu Mar 2 09:56:29 2017 +0100

swrap: Add support for openat()

---

Summary of changes:
 src/socket_wrapper.c | 132 ---
 1 file changed, 115 insertions(+), 17 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 3d468c3..1d94a89 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -438,6 +438,7 @@ typedef int (*__libc_getsockopt)(int sockfd,
 typedef int (*__libc_ioctl)(int d, unsigned long int request, ...);
 typedef int (*__libc_listen)(int sockfd, int backlog);
 typedef int (*__libc_open)(const char *pathname, int flags, mode_t mode);
+typedef int (*__libc_openat)(int dirfd, const char *path, int flags, ...);
 typedef int (*__libc_pipe)(int pipefd[2]);
 typedef int (*__libc_read)(int fd, void *buf, size_t count);
 typedef ssize_t (*__libc_readv)(int fd, const struct iovec *iov, int iovcnt);
@@ -501,6 +502,7 @@ struct swrap_libc_symbols {
SWRAP_SYMBOL_ENTRY(ioctl);
SWRAP_SYMBOL_ENTRY(listen);
SWRAP_SYMBOL_ENTRY(open);
+   SWRAP_SYMBOL_ENTRY(openat);
SWRAP_SYMBOL_ENTRY(pipe);
SWRAP_SYMBOL_ENTRY(read);
SWRAP_SYMBOL_ENTRY(readv);
@@ -876,6 +878,34 @@ static int libc_open(const char *pathname, int flags, ...)
return fd;
 }
 
+static int libc_vopenat(int dirfd, const char *path, int flags, va_list ap)
+{
+   long int mode = 0;
+   int fd;
+
+   swrap_bind_symbol_libc(openat);
+
+   mode = va_arg(ap, long int);
+
+   fd = swrap.libc.symbols._libc_openat.f(dirfd, path, flags, 
(mode_t)mode);
+
+   return fd;
+}
+
+#if 0
+static int libc_openat(int dirfd, const char *path, int flags, ...)
+{
+   va_list ap;
+   int fd;
+
+   va_start(ap, flags);
+   fd = libc_vopenat(dirfd, path, flags, ap);
+   va_end(ap);
+
+   return fd;
+}
+#endif
+
 static int libc_pipe(int pipefd[2])
 {
swrap_bind_symbol_libsocket(pipe);
@@ -2279,7 +2309,9 @@ static int swrap_pcap_get_fd(const char *fname)
 {
static int fd = -1;
 
-   if (fd != -1) return fd;
+   if (fd != -1) {
+   return fd;
+   }
 
fd = libc_open(fname, O_WRONLY|O_CREAT|O_EXCL|O_APPEND, 0644);
if (fd != -1) {
@@ -2332,7 +2364,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct 
socket_info *si,
 
switch (type) {
case SWRAP_CONNECT_SEND:
-   if (si->type != SOCK_STREAM) return NULL;
+   if (si->type != SOCK_STREAM) {
+   return NULL;
+   }
 
src_addr  = >myname.sa.s;
dest_addr = addr;
@@ -2346,7 +2380,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct 
socket_info *si,
break;
 
case SWRAP_CONNECT_RECV:
-   if (si->type != SOCK_STREAM) return NULL;
+   if (si->type != SOCK_STREAM) {
+   return NULL;
+   }
 
dest_addr = >myname.sa.s;
src_addr = addr;
@@ -2360,7 +2396,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct 
socket_info *si,
break;
 
case SWRAP_CONNECT_UNREACH:
-   if (si->type != SOCK_STREAM) return NULL;
+   if (si->type != SOCK_STREAM) {
+   return NULL;
+   }
 
dest_addr = >myname.sa.s;
src_addr  = addr;
@@ -2374,7 +2412,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct 
socket_info *si,
break;
 
case SWRAP_CONNECT_ACK:
-   if (si->type != SOCK_STREAM) return NULL;
+   if (si->type != SOCK_STREAM) {
+   return NULL;
+   }
 
src_addr  = >myname.sa.s;
dest_addr = addr;
@@ -2386,7 +2426,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct 
socket_info *si,
break;
 
case SWRAP_ACCEPT_SEND:
-   if (si->type != SOCK_STREAM) return NULL;
+   if (si->type != SOCK_STREAM) {
+   return NULL;
+ 

[SCM] Socket Wrapper Repository - branch master updated

2017-02-27 Thread Andreas Schneider
The branch, master has been updated
   via  68e1cbf Increase wait time during echo_server's pid-file check
  from  5af1553 Avoid mutex lock wait in socket close failure

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 68e1cbf73e59954116fd0e7ef98c6e68c5aa0b9a
Author: Anoop C S 
Date:   Thu Feb 23 10:52:47 2017 +

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 
Reviewed-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 tests/torture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/tests/torture.c b/tests/torture.c
index d3ad84a..55c27c6 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -188,7 +188,7 @@ static void torture_setup_echo_srv_ip(void **state,
}
 
rc = stat(s->srv_pidfile, );
-   usleep(200);
+   usleep(2000);
} while (rc != 0);
assert_int_equal(rc, 0);
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2017-02-10 Thread Michael Adam
The branch, master has been updated
   via  5af1553 Avoid mutex lock wait in socket close failure
  from  888a62e swrap: Add sanity check in socket_wrapper_max_sockets()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 5af15532cefecb5665736f30e00960c17700d1b0
Author: Anoop C S 
Date:   Fri Feb 10 21:38:11 2017 +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 
Reviewed-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 src/socket_wrapper.c   |  4 
 tests/CMakeLists.txt   |  3 ++-
 tests/test_close_failure.c | 50 ++
 3 files changed, 52 insertions(+), 5 deletions(-)
 create mode 100644 tests/test_close_failure.c


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 186b696..3d468c3 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5656,8 +5656,6 @@ void swrap_destructor(void)
 {
struct socket_info_fd *s = socket_fds;
 
-   SWRAP_LOCK_ALL;
-
while (s != NULL) {
swrap_close(s->fd);
s = socket_fds;
@@ -5671,6 +5669,4 @@ void swrap_destructor(void)
if (swrap.libc.socket_handle) {
dlclose(swrap.libc.socket_handle);
}
-
-   SWRAP_UNLOCK_ALL;
 }
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9292b40..c2bd799 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -35,7 +35,8 @@ set(SWRAP_TESTS
 test_echo_udp_send_recv
 test_echo_udp_sendmsg_recvmsg
 test_swrap_unit
-test_max_sockets)
+test_max_sockets
+test_close_failure)
 
 if (HAVE_STRUCT_MSGHDR_MSG_CONTROL)
 set(SWRAP_TESTS ${SWRAP_TESTS} test_sendmsg_recvmsg_fd)
diff --git a/tests/test_close_failure.c b/tests/test_close_failure.c
new file mode 100644
index 000..0c9d6a7
--- /dev/null
+++ b/tests/test_close_failure.c
@@ -0,0 +1,50 @@
+#include "torture.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int setup(void **state)
+{
+   torture_setup_socket_dir(state);
+
+   return 0;
+}
+
+static int teardown(void **state)
+{
+   torture_teardown_socket_dir(state);
+
+   return 0;
+}
+
+static void test_close_failure(void **state)
+{
+   int s;
+   int rc;
+
+   (void) state; /* unused */
+   (void) s; /*set but not used */
+
+   s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+   assert_int_not_equal(rc, -1);
+
+   /* Do not close the socket here so that destructor
+* handles it and no hang should be observed.*/
+}
+
+int main(void) {
+   int rc;
+
+   const struct CMUnitTest close_failure_tests[] = {
+   cmocka_unit_test_setup_teardown(test_close_failure,
+   setup, teardown),
+   };
+
+   rc = cmocka_run_group_tests(close_failure_tests, NULL, NULL);
+
+   return rc;
+}


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-11-04 Thread Andreas Schneider
The branch, master has been updated
   via  888a62e swrap: Add sanity check in socket_wrapper_max_sockets()
  from  057a956 tests: Clean-up max_sockets test case

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 888a62e2c81370ab32e9bc790f12419148bd8972
Author: Andreas Schneider 
Date:   Fri Nov 4 09:44:04 2016 +0100

swrap: Add sanity check in socket_wrapper_max_sockets()

CID 153962

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 src/socket_wrapper.c | 7 +++
 1 file changed, 7 insertions(+)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index ece5a10..186b696 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -259,6 +259,8 @@ do { \
  */
 #define SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT 65535
 
+#define SOCKET_WRAPPER_MAX_SOCKETS_LIMIT 256000
+
 /* This limit is to avoid broadcast sendto() needing to stat too many
  * files.  It may be raised (with a performance cost) to up to 254
  * without changing the format above */
@@ -1141,6 +1143,11 @@ static size_t socket_wrapper_max_sockets(void)
if (s == endp) {
goto done;
}
+   if (tmp == 0 || tmp > SOCKET_WRAPPER_MAX_SOCKETS_LIMIT) {
+   SWRAP_LOG(SWRAP_LOG_ERROR,
+ "Invalid number of sockets specified, using 
default.");
+   goto done;
+   }
 
max_sockets = tmp;
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-10-27 Thread Michael Adam
The branch, master has been updated
   via  057a956 tests: Clean-up max_sockets test case
  from  63d83be swrap: Fix use-after-free

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 057a956ad4cfe2bc6e03ec9033a8a9b15e8c88a1
Author: Anoop C S 
Date:   Fri Sep 23 12:38:31 2016 +0530

tests: Clean-up max_sockets test case

Signed-off-by: Anoop C S 
Reviewed-by: Michael Adam 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 tests/test_max_sockets.c | 24 
 1 file changed, 4 insertions(+), 20 deletions(-)


Changeset truncated at 500 lines:

diff --git a/tests/test_max_sockets.c b/tests/test_max_sockets.c
index 0aac181..0bc694b 100644
--- a/tests/test_max_sockets.c
+++ b/tests/test_max_sockets.c
@@ -1,24 +1,10 @@
-#include 
-#include 
-#include 
-#include 
-
-#include "config.h"
 #include "torture.h"
 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
 #include 
+#include 
 #include 
-#ifdef HAVE_RPC_RPC_H
-#include 
-#endif
-
+#include 
 
 #define MAX_SOCKETS 4
 
@@ -52,14 +38,12 @@ static int _socket(int *_s)
 
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 
-   if (_s != NULL) {
-   *_s = s;
-   }
-
if (s < 0) {
return -1;
}
 
+   *_s = s;
+
return 0;
 }
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-10-25 Thread Michael Adam
The branch, master has been updated
   via  63d83be swrap: Fix use-after-free
  from  85c2d66 swrap: fix SWRAP_DLIST_ADD_AFTER

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 63d83be5925bcefc64275be5ccb2312596bf5ce8
Author: Anoop C S 
Date:   Tue Oct 25 22:33:10 2016 +0530

swrap: Fix use-after-free

This was introduced by commit 9ce583b6cd6f55d473e5b54794fb06450997ebc8

Signed-off-by: Anoop C S 
Reviewed-by: Michael Adam 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index d40f8b6..ece5a10 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1733,7 +1733,7 @@ static void swrap_remove_stale(int fd)
SWRAP_DLIST_REMOVE(socket_fds, fi);
free(fi);
 
-   si = [fi->si_index];
+   si = [si_index];
si->refcount--;
 
if (si->refcount > 0) {


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-10-25 Thread Michael Adam
The branch, master has been updated
   via  85c2d66 swrap: fix SWRAP_DLIST_ADD_AFTER
  from  9ce583b swrap: fix use-after-free in swrap_remove_stale()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 85c2d663ec4dc7dc0170df676721e9a63f18fe40
Author: Anoop C S 
Date:   Tue Oct 25 15:56:20 2016 +0200

swrap: fix SWRAP_DLIST_ADD_AFTER

Pair-Programmed-With: Michael Adam 

Signed-off-by: Anoop C S 
Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 40e2f04..d40f8b6 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -211,7 +211,7 @@ enum swrap_dbglvl_e {
 
 #define SWRAP_DLIST_ADD_AFTER(list, item, el) \
 do { \
-   if ((list) != NULL || (el) != NULL) { \
+   if ((list) == NULL || (el) == NULL) { \
SWRAP_DLIST_ADD(list, item); \
} else { \
(item)->prev = (el); \


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-10-25 Thread Michael Adam
The branch, master has been updated
   via  9ce583b swrap: fix use-after-free in swrap_remove_stale()
   via  ddba8cf swrap: slightly cleanup logic in swrap_close
   via  3b39c88 swrap: fix use-after-free in swrap_close
  from  d4cdce1 swrap: Fix build on Solaris

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 9ce583b6cd6f55d473e5b54794fb06450997ebc8
Author: Michael Adam 
Date:   Tue Oct 25 13:46:18 2016 +0200

swrap: fix use-after-free in swrap_remove_stale()

Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit ddba8cf2058d662d628fc62f5896b873754ba7c3
Author: Michael Adam 
Date:   Tue Oct 25 13:42:05 2016 +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 
Reviewed-by: Andreas Schneider 

commit 3b39c88b138f88bffc7d71572a9c6a83e54a03c9
Author: Michael Adam 
Date:   Tue Oct 25 13:41:29 2016 +0200

swrap: fix use-after-free in swrap_close

Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 82d27e5..40e2f04 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1721,17 +1721,19 @@ static void swrap_remove_stale(int fd)
 {
struct socket_info_fd *fi = find_socket_info_fd(fd);
struct socket_info *si;
+   int si_index;
 
if (fi == NULL) {
return;
}
 
-   si = [fi->si_index];
+   si_index = fi->si_index;
 
SWRAP_LOG(SWRAP_LOG_TRACE, "remove stale wrapper for %d", fd);
SWRAP_DLIST_REMOVE(socket_fds, fi);
free(fi);
 
+   si = [fi->si_index];
si->refcount--;
 
if (si->refcount > 0) {
@@ -1743,7 +1745,7 @@ static void swrap_remove_stale(int fd)
}
 
si->next_free = first_free;
-   first_free = fi->si_index;
+   first_free = si_index;
 }
 
 static int sockaddr_convert_to_un(struct socket_info *si,
@@ -5351,30 +5353,32 @@ static int swrap_close(int fd)
 {
struct socket_info_fd *fi = find_socket_info_fd(fd);
struct socket_info *si = NULL;
+   int si_index;
int ret;
 
if (fi == NULL) {
return libc_close(fd);
}
 
-   si = [fi->si_index];
+   si_index = fi->si_index;
 
SWRAP_DLIST_REMOVE(socket_fds, fi);
free(fi);
 
+   ret = libc_close(fd);
+
+   si = [si_index];
si->refcount--;
 
if (si->refcount > 0) {
/* there are still references left */
-   return libc_close(fd);
+   return ret;
}
 
if (si->myname.sa_socklen > 0 && si->peername.sa_socklen > 0) {
swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_SEND, NULL, 0);
}
 
-   ret = libc_close(fd);
-
if (si->myname.sa_socklen > 0 && si->peername.sa_socklen > 0) {
swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_RECV, NULL, 0);
swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_ACK, NULL, 0);
@@ -5385,7 +5389,7 @@ static int swrap_close(int fd)
}
 
si->next_free = first_free;
-   first_free = fi->si_index;
+   first_free = si_index;
 
return ret;
 }


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-10-21 Thread Michael Adam
The branch, master has been updated
   via  86fd744 swrap: Mark flags in swrap_accept4 as unused
   via  46615cd swrap: Fix the build on BSD and Solaris
  from  d8cf3b0 swrap: Handle threads that fork

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 86fd744333ddc74d32d301f316ce83e3a2d0c844
Author: Andreas Schneider 
Date:   Fri Oct 21 08:04:02 2016 +0200

swrap: Mark flags in swrap_accept4 as unused

This removes a compiler warning on non-Linux systems.

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit 46615cd9119e0e66175768e1757c9bc3e15b9cc8
Author: Andreas Schneider 
Date:   Fri Oct 21 07:56:24 2016 +0200

swrap: Fix the build on BSD and Solaris

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 src/socket_wrapper.c | 6 ++
 1 file changed, 6 insertions(+)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 6679d5c..fb92904 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -142,6 +142,8 @@ enum swrap_dbglvl_e {
 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
 #endif
 
+#define UNUSED(x) (void)(x)
+
 #ifdef IPV6_PKTINFO
 # ifndef IPV6_RECVPKTINFO
 #  define IPV6_RECVPKTINFO IPV6_PKTINFO
@@ -512,7 +514,9 @@ struct swrap_libc_symbols {
 #endif
SWRAP_SYMBOL_ENTRY(socket);
SWRAP_SYMBOL_ENTRY(socketpair);
+#ifdef HAVE_TIMERFD_CREATE
SWRAP_SYMBOL_ENTRY(timerfd_create);
+#endif
SWRAP_SYMBOL_ENTRY(write);
SWRAP_SYMBOL_ENTRY(writev);
 };
@@ -2882,6 +2886,7 @@ static int swrap_accept(int s,
 #ifdef HAVE_ACCEPT4
return libc_accept4(s, addr, addrlen, flags);
 #else
+   UNUSED(flags);
return libc_accept(s, addr, addrlen);
 #endif
}
@@ -2899,6 +2904,7 @@ static int swrap_accept(int s,
 #ifdef HAVE_ACCEPT4
ret = libc_accept4(s, _addr.sa.s, _addr.sa_socklen, flags);
 #else
+   UNUSED(flags);
ret = libc_accept(s, _addr.sa.s, _addr.sa_socklen);
 #endif
if (ret == -1) {


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-10-20 Thread Michael Adam
The branch, master has been updated
   via  d8cf3b0 swrap: Handle threads that fork
   via  c989bbc cmake: Check for constructor attribute
   via  f5cddcd swrap: Make symbol loading thread-safe
   via  201811d cmake: Link pthread library headers
   via  3507e18 swrap: Fix strict-aliasing issues while loading symbols
  from  b61f5df tests: Add a test for max_sockets

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit d8cf3b0ca8ce24aaf19e4692882dadffa921f763
Author: Andreas Schneider 
Date:   Thu Oct 20 10:37:18 2016 +0200

swrap: Handle threads that fork

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit c989bbc9f6afaad9e4b26501d57d7acb1297d1cb
Author: Andreas Schneider 
Date:   Thu Oct 20 10:35:50 2016 +0200

cmake: Check for constructor attribute

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit f5cddcd300b779131662519d56ae90fcebe459e1
Author: Andreas Schneider 
Date:   Thu Oct 20 10:22:40 2016 +0200

swrap: Make symbol loading thread-safe

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit 201811dc614a4787482c3bb2fa14f47112a05a34
Author: Michael Adam 
Date:   Sun Sep 18 20:28:06 2016 +0200

cmake: Link pthread library headers

Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit 3507e186d08fa8170a3499c9e69a49aa60ff9dcd
Author: Andreas Schneider 
Date:   Thu Oct 20 10:56:35 2016 +0200

swrap: Fix strict-aliasing issues while loading symbols

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 ConfigureChecks.cmake |  12 ++
 config.h.cmake|   1 +
 src/CMakeLists.txt|   2 +-
 src/socket_wrapper.c  | 434 +-
 tests/CMakeLists.txt  |   3 +-
 5 files changed, 306 insertions(+), 146 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 48455ef..71b34ce 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -172,6 +172,18 @@ int main(void) {
 }" HAVE_SOCKADDR_STORAGE)
 
 check_c_source_compiles("
+void test_constructor_attribute(void) __attribute__ ((constructor));
+
+void test_constructor_attribute(void)
+{
+return;
+}
+
+int main(void) {
+return 0;
+}" HAVE_CONSTRUCTOR_ATTRIBUTE)
+
+check_c_source_compiles("
 void test_destructor_attribute(void) __attribute__ ((destructor));
 
 void test_destructor_attribute(void)
diff --git a/config.h.cmake b/config.h.cmake
index a9b8ce8..6786b8a 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -58,6 +58,7 @@
 / OPTIONS /
 
 #cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
+#cmakedefine HAVE_CONSTRUCTOR_ATTRIBUTE 1
 #cmakedefine HAVE_DESTRUCTOR_ATTRIBUTE 1
 #cmakedefine HAVE_ADDRESS_SANITIZER_ATTRIBUTE 1
 #cmakedefine HAVE_SOCKADDR_STORAGE 1
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4b22d77..3b4d7d0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,7 +4,7 @@ include_directories(${CMAKE_BINARY_DIR})
 
 add_library(socket_wrapper SHARED socket_wrapper.c)
 
-target_link_libraries(socket_wrapper ${SWRAP_REQUIRED_LIBRARIES})
+target_link_libraries(socket_wrapper ${SWRAP_REQUIRED_LIBRARIES} 
${CMAKE_THREAD_LIBS_INIT})
 
 install(
   TARGETS
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 84dfc07..6679d5c 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -79,6 +79,7 @@
 #ifdef HAVE_RPC_RPC_H
 #include 
 #endif
+#include 
 
 enum swrap_dbglvl_e {
SWRAP_LOG_ERROR = 0,
@@ -94,6 +95,12 @@ enum swrap_dbglvl_e {
 #define PRINTF_ATTRIBUTE(a,b)
 #endif /* HAVE_FUNCTION_ATTRIBUTE_FORMAT */
 
+#ifdef HAVE_CONSTRUCTOR_ATTRIBUTE
+#define CONSTRUCTOR_ATTRIBUTE __attribute__ ((constructor))
+#else
+#define CONSTRUCTOR_ATTRIBUTE
+#endif /* HAVE_CONSTRUCTOR_ATTRIBUTE */
+
 #ifdef HAVE_DESTRUCTOR_ATTRIBUTE
 #define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor))
 #else
@@ -152,6 +159,22 @@ enum swrap_dbglvl_e {
 # endif
 #endif
 
+/* Macros for accessing mutexes */
+# define SWRAP_LOCK(m) do { \
+   pthread_mutex_lock(&(m ## _mutex)); \
+} while(0)
+
+# define SWRAP_UNLOCK(m) do { \
+   pthread_mutex_unlock(&(m ## _mutex)); \
+} while(0)
+
+/* Add new global locks here please */
+# define SWRAP_LOCK_ALL \
+   SWRAP_LOCK(libc_symbol_binding); \
+
+# define SWRAP_UNLOCK_ALL \
+   SWRAP_UNLOCK(libc_symbol_binding); \
+
 
 #define SWRAP_DLIST_ADD(list,item) do { \
if (!(list)) { \
@@ -305,9 +328,14 @@ static 

[SCM] Socket Wrapper Repository - branch master updated

2016-10-20 Thread Andreas Schneider
The branch, master has been updated
   via  b61f5df tests: Add a test for max_sockets
   via  f9fbda9 swrap: Introduce a freelist in the socket_info array
   via  69aee42 swrap: Replace linked list of socket_info with preallocated 
array of structures
   via  c3e5f78 swrap: Optimization in (commented out) 
check_addr_port_in_use()
   via  1e7528c swrap: Improve vfcntl to add the dup'd fd after the source 
fd
   via  d3d09e6 swrap: Improve dup2 to add the dup'd fd after the source fd
   via  ebe5f15 swrap: Improve dup to add the dup'd fd after the source fd
   via  97d2372 swrap: Add SWRAP_DLIST_ADD_AFTER macro
   via  087f9ae swrap: Untangle socket_info_fd from socket_info structure.
  from  f43d383 swrap: remove ununsed members from struct swrap.

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit b61f5df9f4a7c57cb9ad313a20d7dbe316f42072
Author: Michael Adam 
Date:   Thu Sep 22 02:13:20 2016 +0200

tests: Add a test for max_sockets

Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit f9fbda9ef0f7b279e8e618a3888ab2e50884da1b
Author: Michael Adam 
Date:   Wed Sep 14 13:24:47 2016 +0200

swrap: Introduce a freelist in the socket_info array

Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit 69aee42f1d4a0e563b9e85e899dc8b4f18303af0
Author: Anoop C S 
Date:   Thu Aug 25 11:41:12 2016 +0530

swrap: Replace linked list of socket_info with preallocated array of 
structures

Pair-Programmed-With: Michael Adam 

Signed-off-by: Anoop C S 
Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit c3e5f78016f4319fb22126163d0ddbcac0bdeed5
Author: Michael Adam 
Date:   Tue Aug 16 13:38:50 2016 +0200

swrap: Optimization in (commented out) check_addr_port_in_use()

Pair-Programmed-With: Stefan Metzmacher 

Signed-off-by: Michael Adam 
Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 1e7528c2b1a027538b54bd3576eba1206265ae8c
Author: Michael Adam 
Date:   Tue Aug 16 11:04:43 2016 +0200

swrap: Improve vfcntl to add the dup'd fd after the source fd

Pair-Programmed-With: Stefan Metzmacher 

Signed-off-by: Michael Adam 
Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit d3d09e631aa7f9b5ffe88a786ad21e7e51aee909
Author: Michael Adam 
Date:   Tue Aug 16 11:04:12 2016 +0200

swrap: Improve dup2 to add the dup'd fd after the source fd

Pair-Programmed-With: Stefan Metzmacher 

Signed-off-by: Michael Adam 
Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit ebe5f15854866c225febe73c952356873b958305
Author: Michael Adam 
Date:   Tue Aug 16 11:03:27 2016 +0200

swrap: Improve dup to add the dup'd fd after the source fd

Pair-Programmed-With: Stefan Metzmacher 

Signed-off-by: Michael Adam 
Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 97d23728cfc392fe5f2c33831f4c85aa31d083fc
Author: Michael Adam 
Date:   Tue Aug 16 11:00:50 2016 +0200

swrap: Add SWRAP_DLIST_ADD_AFTER macro

Pair-Programmed-With: Stefan Metzmacher 

Signed-off-by: Michael Adam 
Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

commit 087f9aea821cceffd3ced15b576106cace8a2c9d
Author: Anoop C S 
Date:   Wed Aug 10 16:32:19 2016 +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 
Signed-off-by: Anoop C S 
Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 


[SCM] Socket Wrapper Repository - branch master updated

2016-08-23 Thread Andreas Schneider
The branch, master has been updated
   via  f43d383 swrap: remove ununsed members from struct swrap.
   via  17cfdc6 swrap: Add test case to validate oldfd = newfd case in 
dup2()
   via  04dacf2 swrap: Treat the case of fd == newfd correctly in dup2()
  from  3eee8df swrap: Delay addition of child socket_info_fd into 
socket_info list

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f43d3835451a5271c4e5ec22f321a8120b40d1df
Author: Michael Adam 
Date:   Fri Aug 19 13:34:50 2016 +0200

swrap: remove ununsed members from struct swrap.

These were used in removed swrap_init().

Pair-Programmed-With: Anoop C S 

Signed-off-by: Michael Adam 
Signed-off-by: Anoop C S 
Reviewed-by: Andreas Schneider 

commit 17cfdc6a6568f0dbc34d863ad2d80acaed15a6ad
Author: Anoop C S 
Date:   Mon Aug 22 19:37:47 2016 +0530

swrap: Add test case to validate oldfd = newfd case in dup2()

Signed-off-by: Anoop C S 
Reviewed-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit 04dacf2d2e764eb9fd0791642893b4e1bc199ef0
Author: Michael Adam 
Date:   Tue Aug 16 10:59:40 2016 +0200

swrap: Treat the case of fd == newfd correctly in dup2()

Pair-Programmed-With: Stefan Metzmacher 

Signed-off-by: Michael Adam 
Signed-off-by: Stefan Metzmacher 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c  | 15 ++-
 tests/CMakeLists.txt  |  1 +
 tests/test_tcp_dup2.c | 50 ++
 3 files changed, 61 insertions(+), 5 deletions(-)
 create mode 100644 tests/test_tcp_dup2.c


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 00518c1..6c4ae3b 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -413,11 +413,6 @@ struct swrap {
void *libc_handle;
void *libsocket_handle;
 
-   bool initialised;
-   bool enabled;
-
-   char *socket_dir;
-
struct swrap_libc_fns fns;
 };
 
@@ -5186,6 +5181,16 @@ static int swrap_dup2(int fd, int newfd)
return libc_dup2(fd, newfd);
}
 
+   if (fd == newfd) {
+   /*
+* According to the manpage:
+*
+* "If oldfd is a valid file descriptor, and newfd has the same
+* value as oldfd, then dup2() does nothing, and returns newfd."
+*/
+   return newfd;
+   }
+
if (find_socket_info(newfd)) {
/* dup2() does an implicit close of newfd, which we
 * need to emulate */
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index aecf6b8..9b5c4bf 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -21,6 +21,7 @@ target_link_libraries(${TORTURE_LIBRARY}
 set(SWRAP_TESTS
 test_ioctl
 test_tcp_listen
+test_tcp_dup2
 test_echo_tcp_socket
 test_echo_tcp_connect
 test_echo_tcp_bind
diff --git a/tests/test_tcp_dup2.c b/tests/test_tcp_dup2.c
new file mode 100644
index 000..fd6adc2
--- /dev/null
+++ b/tests/test_tcp_dup2.c
@@ -0,0 +1,50 @@
+#include "torture.h"
+
+#include 
+#include 
+
+static int setup(void **state)
+{
+   torture_setup_socket_dir(state);
+
+   return 0;
+}
+
+static int teardown(void **state)
+{
+   torture_teardown_socket_dir(state);
+
+   return 0;
+}
+
+static void test_dup2_existing_open_fd(void **state)
+{
+   int s, dup_s;
+
+   (void) state; /* unused */
+
+   s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+   assert_int_not_equal(s, -1);
+
+   /*
+* Here we try to duplicate the existing socket fd to itself
+* and as per man page for dup2() it must return the already
+* open fd without any failure.
+*/
+   dup_s = dup2(s, s);
+   assert_int_equal(dup_s, s);
+
+   close(s);
+}
+
+int main(void) {
+   int rc;
+
+   const struct CMUnitTest tcp_dup2_tests[] = {
+   cmocka_unit_test(test_dup2_existing_open_fd),
+   };
+
+   rc = cmocka_run_group_tests(tcp_dup2_tests, setup, teardown);
+
+   return rc;
+}


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-08-12 Thread Andreas Schneider
The branch, master has been updated
   via  3eee8df swrap: Delay addition of child socket_info_fd into 
socket_info list
   via  9278886 swrap: Remove redunant check in swrap_socket
   via  69b89aa swrap: Simplify swrap_remove_stale by early return
  from  44f7e09 Bump version to 1.1.7

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 3eee8df6964fdca0d22967a5c8d65f934e935f34
Author: Anoop C S 
Date:   Thu Aug 11 20:24:54 2016 +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 
Reviewed-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit 92788865b636237f761ebd57d02fad0f3c9e03cd
Author: Anoop C S 
Date:   Thu Aug 11 20:20:17 2016 +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 
Signed-off-by: Anoop C S 
Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

commit 69b89aa9d0847ba7238963c0dafef41d691c52cd
Author: Anoop C S 
Date:   Thu Aug 11 19:27:17 2016 +0530

swrap: Simplify swrap_remove_stale by early return

Pair-programmed-with: Michael Adam 
Signed-off-by: Anoop C S 
Signed-off-by: Michael Adam 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c | 38 ++
 1 file changed, 18 insertions(+), 20 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index ba289e6..00518c1 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1469,23 +1469,25 @@ static void swrap_remove_stale(int fd)
struct socket_info *si = find_socket_info(fd);
struct socket_info_fd *fi;
 
-   if (si != NULL) {
-   for (fi = si->fds; fi; fi = fi->next) {
-   if (fi->fd == fd) {
-   SWRAP_LOG(SWRAP_LOG_TRACE, "remove stale 
wrapper for %d", fd);
-   SWRAP_DLIST_REMOVE(si->fds, fi);
-   free(fi);
-   break;
-   }
+   if (si == NULL) {
+   return;
+   }
+
+   for (fi = si->fds; fi; fi = fi->next) {
+   if (fi->fd == fd) {
+   SWRAP_LOG(SWRAP_LOG_TRACE, "remove stale wrapper for 
%d", fd);
+   SWRAP_DLIST_REMOVE(si->fds, fi);
+   free(fi);
+   break;
}
+   }
 
-   if (si->fds == NULL) {
-   SWRAP_DLIST_REMOVE(sockets, si);
-   if (si->un_addr.sun_path[0] != '\0') {
-   unlink(si->un_addr.sun_path);
-   }
-   free(si);
+   if (si->fds == NULL) {
+   SWRAP_DLIST_REMOVE(sockets, si);
+   if (si->un_addr.sun_path[0] != '\0') {
+   unlink(si->un_addr.sun_path);
}
+   free(si);
}
 }
 
@@ -2456,10 +2458,7 @@ static int swrap_socket(int family, int type, int 
protocol)
}
 
/* Check if we have a stale fd and remove it */
-   si = find_socket_info(fd);
-   if (si != NULL) {
-   swrap_remove_stale(fd);
-   }
+   swrap_remove_stale(fd);
 
si = (struct socket_info *)calloc(1, sizeof(struct socket_info));
if (si == NULL) {
@@ -2683,8 +2682,6 @@ static int swrap_accept(int s,
 
child_fi->fd = fd;
 
-   SWRAP_DLIST_ADD(child_si->fds, child_fi);
-
child_si->family = parent_si->family;
child_si->type = parent_si->type;
child_si->protocol = parent_si->protocol;
@@ -2737,6 +2734,7 @@ static int swrap_accept(int s,
};
memcpy(_si->myname.sa.ss, _my_addr.sa.ss, 
in_my_addr.sa_socklen);
 
+   SWRAP_DLIST_ADD(child_si->fds, child_fi);
SWRAP_DLIST_ADD(sockets, child_si);
 
if (addr != NULL) {


-- 
Socket Wrapper 

[SCM] Socket Wrapper Repository - branch master updated

2016-05-20 Thread Andreas Schneider
The branch, master has been updated
   via  44f7e09 Bump version to 1.1.7
  from  0c5a43a tests: Add test_connect_sendto_null_ipv4() test

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 44f7e09b5213a5ae91fb8e67262ac4a7e1bdf528
Author: Andreas Schneider 
Date:   Fri May 20 08:58:18 2016 +0200

Bump version to 1.1.7

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 CMakeLists.txt | 4 ++--
 ChangeLog  | 6 ++
 2 files changed, 8 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 420713c..4d7c12e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 
 set(APPLICATION_VERSION_MAJOR "1")
 set(APPLICATION_VERSION_MINOR "1")
-set(APPLICATION_VERSION_PATCH "6")
+set(APPLICATION_VERSION_PATCH "7")
 
 set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
 
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION "0.1.6")
+set(LIBRARY_VERSION "0.1.7")
 set(LIBRARY_SOVERSION "0")
 
 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is 
checked
diff --git a/ChangeLog b/ChangeLog
index 22bcd38..dd03665 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
 ChangeLog
 ==
 
+version 1.1.7 (released 2016-05-20)
+  * Added support for accept4()
+  * Added support for OpenBSD
+  * Fixed sendto() with UDP and a connected socket
+  * Fixed AF_RAWLINK sockets
+
 version 1.1.6 (released 2016-03-15)
   * Added a wrapper for write()
   * Added support for automatic binding of ephemeral ports


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-05-17 Thread Andreas Schneider
The branch, master has been updated
   via  0c5a43a tests: Add test_connect_sendto_null_ipv4() test
   via  e443d67 tests: Add a udp test case for sendto() after a connect()
   via  ec18c95 swrap: Fix sendto() with connected sockets
   via  395dc41 swrap: Allow to open RAW sockets when loaded
  from  d731d16 swrap: Add support for accept4()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 0c5a43a8a05d74de6c3ffa4f6c42429c2861d75f
Author: Andreas Schneider 
Date:   Tue May 17 10:01:38 2016 +0200

tests: Add test_connect_sendto_null_ipv4() test

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit e443d67914030e7f2e1126a82003e1bada5cbbac
Author: Richard Sharpe 
Date:   Wed May 11 17:10:54 2016 -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 
Reviewed-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit ec18c955e13ea2a294339e4c9ee977a769fbe903
Author: Richard Sharpe 
Date:   Wed May 11 17:03:46 2016 -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 
Signed-off-by: Richard Sharpe 
Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

commit 395dc418d996d343cfaeb03be5b720c9e52d1d46
Author: Andreas Schneider 
Date:   Tue Apr 26 18:10:52 2016 +0200

swrap: Allow to open RAW sockets when loaded

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 src/socket_wrapper.c  |  40 ++---
 tests/test_echo_udp_sendto_recvfrom.c | 104 ++
 2 files changed, 135 insertions(+), 9 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 6e65a7e..ba289e6 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -2407,6 +2407,9 @@ static int swrap_socket(int family, int type, int 
protocol)
 #ifdef AF_NETLINK
case AF_NETLINK:
 #endif /* AF_NETLINK */
+#ifdef AF_PACKET
+   case AF_PACKET:
+#endif /* AF_PACKET */
case AF_UNIX:
return libc_socket(family, type, protocol);
default:
@@ -3919,9 +3922,15 @@ static ssize_t swrap_sendmsg_before(int fd,
}
case SOCK_DGRAM:
if (si->connected) {
-   if (msg->msg_name) {
-   errno = EISCONN;
-   return -1;
+   if (msg->msg_name != NULL) {
+   /*
+* We are dealing with unix sockets and if we
+* are connected, we should only talk to the
+* connected unix path. Using the fd to send
+* to another server would be hard to achieve.
+*/
+   msg->msg_name = NULL;
+   msg->msg_namelen = 0;
}
} else {
const struct sockaddr *msg_name;
@@ -4468,12 +4477,25 @@ static ssize_t swrap_sendto(int s, const void *buf, 
size_t len, int flags,
return len;
}
 
-   ret = libc_sendto(s,
- buf,
- len,
- flags,
- (struct sockaddr *)msg.msg_name,
- msg.msg_namelen);
+   /*
+* If it is a dgram socket and we are connected, don't include the
+* 'to' address.
+*/
+   if (si->type == SOCK_DGRAM && si->connected) {
+   ret = libc_sendto(s,
+ buf,

[SCM] Socket Wrapper Repository - branch master updated

2016-05-03 Thread Andreas Schneider
The branch, master has been updated
   via  d731d16 swrap: Add support for accept4()
   via  09f3be7 swrap: Add support for running on OpenBSD
  from  feb9ee0 Bump version to 1.1.6

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit d731d16ac6b8f8c1edaf51794ed458cfe19c0040
Author: Andreas Schneider 
Date:   Tue May 3 14:59:34 2016 +0200

swrap: Add support for accept4()

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Böhme 

commit 09f3be725259c8ea9f51c84a96c4c03459ba72aa
Author: Andreas Schneider 
Date:   Tue May 3 14:43:21 2016 +0200

swrap: Add support for running on OpenBSD

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Böhme 

---

Summary of changes:
 ConfigureChecks.cmake |  3 +++
 config.h.cmake|  2 ++
 src/socket_wrapper.c  | 53 +--
 3 files changed, 56 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 71e5056..48455ef 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -62,6 +62,9 @@ check_function_exists(signalfd HAVE_SIGNALFD)
 check_function_exists(eventfd HAVE_EVENTFD)
 check_function_exists(timerfd_create HAVE_TIMERFD_CREATE)
 check_function_exists(bindresvport HAVE_BINDRESVPORT)
+check_function_exists(accept4 HAVE_ACCEPT4)
+
+check_function_exists(pledge HAVE_PLEDGE)
 
 
 if (UNIX)
diff --git a/config.h.cmake b/config.h.cmake
index 91e1206..a9b8ce8 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -39,6 +39,8 @@
 #cmakedefine HAVE_EVENTFD 1
 #cmakedefine HAVE_TIMERFD_CREATE 1
 #cmakedefine HAVE_BINDRESVPORT 1
+#cmakedefine HAVE_ACCEPT4 1
+#cmakedefine HAVE_PLEDGE 1
 
 #cmakedefine HAVE_ACCEPT_PSOCKLEN_T 1
 #cmakedefine HAVE_IOCTL_INT 1
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 3b0499d..6e65a7e 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -335,9 +335,16 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl,
 #include 
 
 struct swrap_libc_fns {
+#ifdef HAVE_ACCEPT4
+   int (*libc_accept4)(int sockfd,
+  struct sockaddr *addr,
+  socklen_t *addrlen,
+  int flags);
+#else
int (*libc_accept)(int sockfd,
   struct sockaddr *addr,
   socklen_t *addrlen);
+#endif
int (*libc_bind)(int sockfd,
 const struct sockaddr *addr,
 socklen_t addrlen);
@@ -552,12 +559,26 @@ static void *_swrap_load_lib_function(enum swrap_lib lib, 
const char *fn_name)
  * has probably something todo with with the linker.
  * So we need load each function at the point it is called the first time.
  */
+#ifdef HAVE_ACCEPT4
+static int libc_accept4(int sockfd,
+   struct sockaddr *addr,
+   socklen_t *addrlen,
+   int flags)
+{
+   swrap_load_lib_function(SWRAP_LIBSOCKET, accept4);
+
+   return swrap.fns.libc_accept4(sockfd, addr, addrlen, flags);
+}
+
+#else /* HAVE_ACCEPT4 */
+
 static int libc_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 {
swrap_load_lib_function(SWRAP_LIBSOCKET, accept);
 
return swrap.fns.libc_accept(sockfd, addr, addrlen);
 }
+#endif /* HAVE_ACCEPT4 */
 
 static int libc_bind(int sockfd,
 const struct sockaddr *addr,
@@ -2575,7 +2596,10 @@ int pipe(int pipefd[2])
  *   ACCEPT
  ***/
 
-static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
+static int swrap_accept(int s,
+   struct sockaddr *addr,
+   socklen_t *addrlen,
+   int flags)
 {
struct socket_info *parent_si, *child_si;
struct socket_info_fd *child_fi;
@@ -2596,7 +2620,11 @@ static int swrap_accept(int s, struct sockaddr *addr, 
socklen_t *addrlen)
 
parent_si = find_socket_info(s);
if (!parent_si) {
+#ifdef HAVE_ACCEPT4
+   return libc_accept4(s, addr, addrlen, flags);
+#else
return libc_accept(s, addr, addrlen);
+#endif
}
 
/*
@@ -2609,7 +2637,11 @@ static int swrap_accept(int s, struct sockaddr *addr, 
socklen_t *addrlen)
return -1;
}
 
+#ifdef HAVE_ACCEPT4
+   ret = libc_accept4(s, _addr.sa.s, _addr.sa_socklen, flags);
+#else
ret = libc_accept(s, _addr.sa.s, _addr.sa_socklen);
+#endif
if (ret == -1) {
if (errno == ENOTSOCK) {
/* Remove stale fds */
@@ -2713,13 +2745,20 @@ static int swrap_accept(int s, struct sockaddr *addr, 

[SCM] Socket Wrapper Repository - branch master updated

2016-03-15 Thread Andreas Schneider
The branch, master has been updated
   via  feb9ee0 Bump version to 1.1.6
  from  893a95a swrap: Fix buliding on unix systems without AF_NETLINK

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit feb9ee05b08eebbac21bab8ad9dd00beb96d4981
Author: Andreas Schneider 
Date:   Tue Mar 15 11:15:07 2016 +0100

Bump version to 1.1.6

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 CMakeLists.txt | 4 ++--
 ChangeLog  | 6 ++
 2 files changed, 8 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2924cd..420713c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 
 set(APPLICATION_VERSION_MAJOR "1")
 set(APPLICATION_VERSION_MINOR "1")
-set(APPLICATION_VERSION_PATCH "5")
+set(APPLICATION_VERSION_PATCH "6")
 
 set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
 
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION "0.1.5")
+set(LIBRARY_VERSION "0.1.6")
 set(LIBRARY_SOVERSION "0")
 
 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is 
checked
diff --git a/ChangeLog b/ChangeLog
index 3a665fc..22bcd38 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
 ChangeLog
 ==
 
+version 1.1.6 (released 2016-03-15)
+  * Added a wrapper for write()
+  * Added support for automatic binding of ephemeral ports
+  * Fixed recvmsg() with UDP
+  * Fixed AF_NETLINK sockets
+
 version 1.1.5 (released 2015-10-15)
   * Added support for TCP_NODELAY in setsockopt/getsockopt
   * Fixed cmsg space calculation


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-03-02 Thread Andreas Schneider
The branch, master has been updated
   via  893a95a swrap: Fix buliding on unix systems without AF_NETLINK
  from  1f9ea96 swrap: Use calloc() instead of malloc and memset

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 893a95a86485d27e64104e9ffd94f4ab4fa1fffc
Author: Andreas Schneider 
Date:   Thu Feb 25 18:01:49 2016 +0100

swrap: Fix buliding on unix systems without AF_NETLINK

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 src/socket_wrapper.c | 2 ++
 1 file changed, 2 insertions(+)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index fc9116b..3b0499d 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -2383,7 +2383,9 @@ static int swrap_socket(int family, int type, int 
protocol)
case AF_INET6:
 #endif
break;
+#ifdef AF_NETLINK
case AF_NETLINK:
+#endif /* AF_NETLINK */
case AF_UNIX:
return libc_socket(family, type, protocol);
default:


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2016-02-23 Thread Andreas Schneider
The branch, master has been updated
   via  1f9ea96 swrap: Use calloc() instead of malloc and memset
   via  ad9e56e swrap: Allow to open NETLINK sockets when loaded
  from  c7c45b0 tests: Add test for ephemeral port binding in listen()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 1f9ea967f81938a86fd120f59daaa01f055cdb48
Author: Andreas Schneider 
Date:   Tue Feb 23 11:22:58 2016 +0100

swrap: Use calloc() instead of malloc and memset

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit ad9e56e2b695cdba7000829c43d7c444a227fe4d
Author: Andreas Schneider 
Date:   Thu Nov 5 14:44:26 2015 +0100

swrap: Allow to open NETLINK sockets when loaded

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 src/socket_wrapper.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 9ba212b..fc9116b 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1855,11 +1855,10 @@ static uint8_t *swrap_pcap_packet_init(struct timeval 
*tval,
alloc_len = SWRAP_PACKET_MIN_ALLOC;
}
 
-   base = (uint8_t *)malloc(alloc_len);
+   base = (uint8_t *)calloc(1, alloc_len);
if (base == NULL) {
return NULL;
}
-   memset(base, 0x0, alloc_len);
 
buf = base;
 
@@ -2384,6 +2383,7 @@ static int swrap_socket(int family, int type, int 
protocol)
case AF_INET6:
 #endif
break;
+   case AF_NETLINK:
case AF_UNIX:
return libc_socket(family, type, protocol);
default:
@@ -2435,8 +2435,7 @@ static int swrap_socket(int family, int type, int 
protocol)
swrap_remove_stale(fd);
}
 
-   si = (struct socket_info *)malloc(sizeof(struct socket_info));
-   memset(si, 0, sizeof(struct socket_info));
+   si = (struct socket_info *)calloc(1, sizeof(struct socket_info));
if (si == NULL) {
errno = ENOMEM;
return -1;
@@ -2630,8 +2629,12 @@ static int swrap_accept(int s, struct sockaddr *addr, 
socklen_t *addrlen)
return ret;
}
 
-   child_si = (struct socket_info *)malloc(sizeof(struct socket_info));
-   memset(child_si, 0, sizeof(struct socket_info));
+   child_si = (struct socket_info *)calloc(1, sizeof(struct socket_info));
+   if (child_si == NULL) {
+   close(fd);
+   errno = ENOMEM;
+   return -1;
+   }
 
child_fi = (struct socket_info_fd *)calloc(1, sizeof(struct 
socket_info_fd));
if (child_fi == NULL) {


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2015-11-04 Thread Andreas Schneider
The branch, master has been updated
   via  c7c45b0 tests: Add test for ephemeral port binding in listen()
   via  1e2f53a swrap: Automatically bind an ephemeral port if needed
  from  f24f91e tests: Add valgrind suppression file for dlopen() issues

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit c7c45b0f2abf2fb278c7a63a24090fad3df28fee
Author: Andreas Schneider 
Date:   Wed Nov 4 11:22:25 2015 +0100

tests: Add test for ephemeral port binding in listen()

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit 1e2f53a6db5b9163ece72b0d75396b5816464460
Author: Andreas Schneider 
Date:   Wed Nov 4 11:21:23 2015 +0100

swrap: Automatically bind an ephemeral port if needed

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 src/socket_wrapper.c|   8 
 tests/CMakeLists.txt|   1 +
 tests/test_tcp_listen.c | 115 
 3 files changed, 124 insertions(+)
 create mode 100644 tests/test_tcp_listen.c


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index b43c877..9ba212b 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -3154,6 +3154,14 @@ static int swrap_listen(int s, int backlog)
return libc_listen(s, backlog);
}
 
+   if (si->bound == 0) {
+   ret = swrap_auto_bind(s, si, si->family);
+   if (ret == -1) {
+   errno = EADDRINUSE;
+   return ret;
+   }
+   }
+
ret = libc_listen(s, backlog);
 
return ret;
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9679177..aecf6b8 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -20,6 +20,7 @@ target_link_libraries(${TORTURE_LIBRARY}
 
 set(SWRAP_TESTS
 test_ioctl
+test_tcp_listen
 test_echo_tcp_socket
 test_echo_tcp_connect
 test_echo_tcp_bind
diff --git a/tests/test_tcp_listen.c b/tests/test_tcp_listen.c
new file mode 100644
index 000..5641c47
--- /dev/null
+++ b/tests/test_tcp_listen.c
@@ -0,0 +1,115 @@
+#include 
+#include 
+#include 
+#include 
+
+#include "config.h"
+#include "torture.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#ifdef HAVE_RPC_RPC_H
+#include 
+#endif
+
+static int setup(void **state)
+{
+   torture_setup_socket_dir(state);
+
+   return 0;
+}
+
+static int teardown(void **state)
+{
+   torture_teardown_socket_dir(state);
+
+   return 0;
+}
+
+static void test_listen_unbound_ipv4(void **state)
+{
+   struct torture_address addr = {
+   .sa_socklen = sizeof(struct sockaddr_storage),
+   };
+   int rc;
+   int s1;
+   int s2;
+
+   (void) state; /* unused */
+
+   s1 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+   assert_return_code(s1, errno);
+
+   rc = listen(s1, SOMAXCONN);
+   assert_return_code(rc, errno);
+
+   rc = getsockname(s1, , _socklen);
+   assert_return_code(rc, errno);
+   assert_int_equal(addr.sa_socklen, sizeof(struct sockaddr_in));
+   assert_in_range(ntohs(addr.sa.in.sin_port), 1024, 65535);
+
+   s2 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+   assert_return_code(s2, errno);
+
+   rc = connect(s2, , addr.sa_socklen);
+   assert_return_code(rc, errno);
+
+   close(s1);
+   close(s2);
+}
+
+#ifdef HAVE_IPV6
+static void test_listen_unbound_ipv6(void **state)
+{
+   struct torture_address addr = {
+   .sa_socklen = sizeof(struct sockaddr_storage),
+   };
+   int rc;
+   int s1;
+   int s2;
+
+   (void) state; /* unused */
+
+   s1 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
+   assert_return_code(s1, errno);
+
+   rc = listen(s1, SOMAXCONN);
+   assert_return_code(rc, errno);
+
+   rc = getsockname(s1, , _socklen);
+   assert_return_code(rc, errno);
+   assert_int_equal(addr.sa_socklen, sizeof(struct sockaddr_in6));
+   assert_in_range(ntohs(addr.sa.in6.sin6_port), 1024, 65535);
+
+   s2 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
+   assert_return_code(s2, errno);
+
+   rc = connect(s2, , addr.sa_socklen);
+   assert_return_code(rc, errno);
+
+   close(s1);
+   close(s2);
+}
+#endif /* HAVE_IPV6 */
+
+int main(void) {
+   int rc;
+
+   const struct CMUnitTest tcp_listen_tests[] = {
+   cmocka_unit_test(test_listen_unbound_ipv4),
+#ifdef HAVE_IPV6
+   cmocka_unit_test(test_listen_unbound_ipv6),
+#endif /* HAVE_IPV6 */
+   };
+
+   rc = cmocka_run_group_tests(tcp_listen_tests, setup, 

[SCM] Socket Wrapper Repository - branch master updated

2015-10-28 Thread Andreas Schneider
The branch, master has been updated
   via  f24f91e tests: Add valgrind suppression file for dlopen() issues
   via  f649d0c swrap: Add a wrapper for write()
  from  21cb6c8 torture: Use a short torture socket dir

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f24f91eb2064ab04f7f289f73a443aafc45649e4
Author: Andreas Schneider 
Date:   Wed Oct 28 09:52:25 2015 +0100

tests: Add valgrind suppression file for dlopen() issues

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit f649d0c5250867bf3d30d8f3059c3fbd75e17dd0
Author: Andreas Schneider 
Date:   Wed Oct 28 10:30:32 2015 +0100

swrap: Add a wrapper for write()

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 src/socket_wrapper.c | 60 
 tests/valgrind.supp  | 16 ++
 2 files changed, 76 insertions(+)
 create mode 100644 tests/valgrind.supp


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 3c0c279..b43c877 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -398,6 +398,7 @@ struct swrap_libc_fns {
 #ifdef HAVE_TIMERFD_CREATE
int (*libc_timerfd_create)(int clockid, int flags);
 #endif
+   ssize_t (*libc_write)(int fd, const void *buf, size_t count);
ssize_t (*libc_writev)(int fd, const struct iovec *iov, int iovcnt);
 };
 
@@ -837,6 +838,13 @@ static int libc_timerfd_create(int clockid, int flags)
 }
 #endif
 
+static ssize_t libc_write(int fd, const void *buf, size_t count)
+{
+   swrap_load_lib_function(SWRAP_LIBC, write);
+
+   return swrap.fns.libc_write(fd, buf, count);
+}
+
 static ssize_t libc_writev(int fd, const struct iovec *iov, int iovcnt)
 {
swrap_load_lib_function(SWRAP_LIBSOCKET, writev);
@@ -4544,6 +4552,58 @@ ssize_t read(int s, void *buf, size_t len)
 }
 
 /
+ *   WRITE
+ ***/
+
+static ssize_t swrap_write(int s, const void *buf, size_t len)
+{
+   struct msghdr msg;
+   struct iovec tmp;
+   struct sockaddr_un un_addr;
+   ssize_t ret;
+   int rc;
+   struct socket_info *si;
+
+   si = find_socket_info(s);
+   if (si == NULL) {
+   return libc_write(s, buf, len);
+   }
+
+   tmp.iov_base = discard_const_p(char, buf);
+   tmp.iov_len = len;
+
+   ZERO_STRUCT(msg);
+   msg.msg_name = NULL;   /* optional address */
+   msg.msg_namelen = 0;   /* size of address */
+   msg.msg_iov = /* scatter/gather array */
+   msg.msg_iovlen = 1;/* # elements in msg_iov */
+#if HAVE_STRUCT_MSGHDR_MSG_CONTROL
+   msg.msg_control = NULL;/* ancillary data, see below */
+   msg.msg_controllen = 0;/* ancillary data buffer len */
+   msg.msg_flags = 0; /* flags on received message */
+#endif
+
+   rc = swrap_sendmsg_before(s, si, , , _addr, NULL, NULL, 
NULL);
+   if (rc < 0) {
+   return -1;
+   }
+
+   buf = msg.msg_iov[0].iov_base;
+   len = msg.msg_iov[0].iov_len;
+
+   ret = libc_write(s, buf, len);
+
+   swrap_sendmsg_after(s, si, , NULL, ret);
+
+   return ret;
+}
+
+ssize_t write(int s, const void *buf, size_t len)
+{
+   return swrap_write(s, buf, len);
+}
+
+/
  *   SEND
  ***/
 
diff --git a/tests/valgrind.supp b/tests/valgrind.supp
new file mode 100644
index 000..9857825
--- /dev/null
+++ b/tests/valgrind.supp
@@ -0,0 +1,16 @@
+### GLIBC
+{
+   glibc_dlopen_alloc
+   Memcheck:Leak
+   fun:calloc
+   fun:_dlerror_run
+   fun:dlopen@@GLIBC_2.2.5
+}
+
+{
+   glibc_dlclose_alloc
+   Memcheck:Leak
+   fun:calloc
+   fun:_dlerror_run
+   fun:dlclose
+}


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2015-10-27 Thread Andreas Schneider
The branch, master has been updated
   via  21cb6c8 torture: Use a short torture socket dir
   via  be46c97 swrap: Fix recvmsg() with UDP
  from  73b2b4f swrap: Fix compare of signed and unsigned integer 
expressions

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 21cb6c86761c6a2db85a81d85395315d83f0cb52
Author: Andreas Schneider 
Date:   Tue Oct 27 10:03:06 2015 +0100

torture: Use a short torture socket dir

This makes sure we do not run into a regression.

Thanks to Grigorij Demidov 

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

commit be46c97142b9e79c45c8fdf078ac5245813738ba
Author: Andreas Schneider 
Date:   Tue Oct 27 09:26:40 2015 +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 

Signed-off-by: Andreas Schneider 
Reviewed-by: Stefan Metzmacher 

---

Summary of changes:
 src/socket_wrapper.c | 10 ++
 tests/torture.c  |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 6691738..3c0c279 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -4603,6 +4603,9 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, 
int flags)
struct swrap_address from_addr = {
.sa_socklen = sizeof(struct sockaddr_un),
};
+   struct swrap_address convert_addr = {
+   .sa_socklen = sizeof(struct sockaddr_storage),
+   };
struct socket_info *si;
struct msghdr msg;
struct iovec tmp;
@@ -4661,6 +4664,13 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, 
int flags)
}
 #endif
 
+   /*
+* We convert the unix address to a IP address so we need a buffer
+* which can store the address in case of SOCK_DGRAM, see below.
+*/
+   msg.msg_name = _addr.sa;
+   msg.msg_namelen = convert_addr.sa_socklen;
+
rc = swrap_recvmsg_after(s,
 si,
 ,
diff --git a/tests/torture.c b/tests/torture.c
index 821f0ab..d3ad84a 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -55,7 +55,7 @@
 #define TORTURE_ECHO_SRV_IPV6 "fd00::5357:5f0a"
 #define TORTURE_ECHO_SRV_PORT 7
 
-#define TORTURE_SOCKET_DIR "/tmp/test_socket_wrapper_XX"
+#define TORTURE_SOCKET_DIR "/tmp/w_XX"
 #define TORTURE_ECHO_SRV_PIDFILE "echo_srv.pid"
 #define TORTURE_PCAP_FILE "socket_trace.pcap"
 


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2015-10-19 Thread Andreas Schneider
The branch, master has been updated
   via  73b2b4f swrap: Fix compare of signed and unsigned integer 
expressions
   via  6c1f075 tests: Fix compile warning
  from  f635b31 Bump version to 1.1.5

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 73b2b4f16b4b5f51d4e13fba7444844e13a9f7cc
Author: Andreas Schneider 
Date:   Fri Oct 16 16:52:46 2015 +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 
Reviewed-by: Ralph Boehme 

commit 6c1f0750b122bacbf6bca126ce0e13ccd1e31fe3
Author: Andreas Schneider 
Date:   Fri Oct 16 16:50:00 2015 +0200

tests: Fix compile warning

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 src/socket_wrapper.c   | 6 --
 tests/test_echo_tcp_bind.c | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 353ad1d..6691738 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -3850,7 +3850,8 @@ static ssize_t swrap_sendmsg_before(int fd,
msg->msg_iovlen = i;
if (msg->msg_iovlen == 0) {
*tmp_iov = msg->msg_iov[0];
-   tmp_iov->iov_len = MIN(tmp_iov->iov_len, (size_t)mtu);
+   tmp_iov->iov_len = MIN((size_t)tmp_iov->iov_len,
+  (size_t)mtu);
msg->msg_iov = tmp_iov;
msg->msg_iovlen = 1;
}
@@ -4067,7 +4068,8 @@ static int swrap_recvmsg_before(int fd,
msg->msg_iovlen = i;
if (msg->msg_iovlen == 0) {
*tmp_iov = msg->msg_iov[0];
-   tmp_iov->iov_len = MIN(tmp_iov->iov_len, (size_t)mtu);
+   tmp_iov->iov_len = MIN((size_t)tmp_iov->iov_len,
+  (size_t)mtu);
msg->msg_iov = tmp_iov;
msg->msg_iovlen = 1;
}
diff --git a/tests/test_echo_tcp_bind.c b/tests/test_echo_tcp_bind.c
index 0baf0bd..cde7e3f 100644
--- a/tests/test_echo_tcp_bind.c
+++ b/tests/test_echo_tcp_bind.c
@@ -365,7 +365,7 @@ static void test_bindresvport_ipv4(void **state)
   _addr);
assert_int_equal(rc, 1);
 
-   rc = connect(s, , addr.sa_socklen);
+   rc = connect(s, , addr.sa_socklen);
assert_return_code(rc, errno);
 
close(s);


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2015-10-15 Thread Andreas Schneider
The branch, master has been updated
   via  f635b31 Bump version to 1.1.5
  from  f3489d5 swrap: Simplify cmspace calculation in 
swrap_sendmsg_copy_cmsg()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f635b312cd3cd166056dc02603c1f6b041f8d6e3
Author: Andreas Schneider 
Date:   Wed Oct 14 11:37:55 2015 +0200

Bump version to 1.1.5

Signed-off-by: Andreas Schneider 
Reviewed-by: Ralph Boehme 

---

Summary of changes:
 CMakeLists.txt | 4 ++--
 ChangeLog  | 4 
 2 files changed, 6 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5407410..a2924cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 
 set(APPLICATION_VERSION_MAJOR "1")
 set(APPLICATION_VERSION_MINOR "1")
-set(APPLICATION_VERSION_PATCH "4")
+set(APPLICATION_VERSION_PATCH "5")
 
 set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
 
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION 
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION "0.1.4")
+set(LIBRARY_VERSION "0.1.5")
 set(LIBRARY_SOVERSION "0")
 
 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is 
checked
diff --git a/ChangeLog b/ChangeLog
index b3509ab..3a665fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
 ChangeLog
 ==
 
+version 1.1.5 (released 2015-10-15)
+  * Added support for TCP_NODELAY in setsockopt/getsockopt
+  * Fixed cmsg space calculation
+
 version 1.1.4 (released 2015-08-25)
   * Fixed handling of msg_name in recvmsg()
   * Fixed sendmsg()/recvmsg() TCP support


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2015-10-14 Thread Andreas Schneider
The branch, master has been updated
   via  f3489d5 swrap: Simplify cmspace calculation in 
swrap_sendmsg_copy_cmsg()
   via  c5e809f tests: Add a unit test for wrap_sendmsg_filter_cmsghdr()
  from  84a4e23 tests: Add test for TCP_NODELAY setsockopt()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit f3489d5cb77a804891bdaff3d90449fa7f293dd6
Author: Ralph Boehme 
Date:   Thu Oct 8 03:25:53 2015 +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 
Reviewed-by: Andreas Schneider 

commit c5e809fed9a9e2cfce40312150322f28d3d338a6
Author: Ralph Boehme 
Date:   Tue Oct 13 16:38:26 2015 +0200

tests: Add a unit test for wrap_sendmsg_filter_cmsghdr()

Signed-off-by: Ralph Boehme 
Reviewed-by: Andreas Schneider 

---

Summary of changes:
 src/socket_wrapper.c|   4 +-
 tests/CMakeLists.txt|   3 +-
 tests/test_swrap_unit.c | 120 
 3 files changed, 123 insertions(+), 4 deletions(-)
 create mode 100644 tests/test_swrap_unit.c


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index aad5f3e..353ad1d 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -3739,9 +3739,7 @@ static int swrap_sendmsg_copy_cmsg(struct cmsghdr *cmsg,
size_t cmspace;
uint8_t *p;
 
-   cmspace =
-   (*cm_data_space) +
-   CMSG_SPACE(cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr)));
+   cmspace = *cm_data_space + CMSG_ALIGN(cmsg->cmsg_len);
 
p = realloc((*cm_data), cmspace);
if (p == NULL) {
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 0cb7f78..9679177 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -30,7 +30,8 @@ set(SWRAP_TESTS
 test_echo_tcp_get_peer_sock_name
 test_echo_udp_sendto_recvfrom
 test_echo_udp_send_recv
-test_echo_udp_sendmsg_recvmsg)
+test_echo_udp_sendmsg_recvmsg
+test_swrap_unit)
 
 if (HAVE_STRUCT_MSGHDR_MSG_CONTROL)
 set(SWRAP_TESTS ${SWRAP_TESTS} test_sendmsg_recvmsg_fd)
diff --git a/tests/test_swrap_unit.c b/tests/test_swrap_unit.c
new file mode 100644
index 000..469aa24
--- /dev/null
+++ b/tests/test_swrap_unit.c
@@ -0,0 +1,120 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "config.h"
+
+#include "socket_wrapper.c"
+
+#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
+
+/**
+ * test wrap_sendmsg_filter_cmsghdr()
+ *
+ * Prepare a message with two cmsg:
+ * - the first cmsg is a char buf with the string "Hello World"
+ * - the second cmsg is a char buf with the string "!\n"
+ *
+ * Both cmsgs will be copied without modification by
+ * wrap_sendmsg_filter_cmsghdr(), so we can check that the msg
+ * controllen, the cmsg sizes and the payload are the same.
+ *
+ * We use an not existing cmsg_type which triggers cmsg copying.
+ */
+static void test_sendmsg_cmsg(void **state)
+{
+   int rc = 0;
+   char byte = '!';
+   struct iovec iov;
+   struct msghdr msg = { 0 };
+   struct cmsghdr *cmsg;
+   char *cmsgbuf;
+   int cmsgbuf_size;
+   const char *s1 = "Hello World";
+   const int s1_len = strlen(s1);
+   const char *s2 = "!\n";
+   const int s2_len = strlen(s2);
+   uint8_t *cmbuf = NULL;
+   size_t cmlen = 0;
+
+   (void)state; /* unused */
+
+   iov.iov_base = 
+   iov.iov_len = 1;
+
+   /*
+* Prepare cmsgbuf and msg
+*/
+   msg.msg_iov = 
+   msg.msg_iovlen = 1;
+   cmsgbuf_size = CMSG_SPACE(s1_len) + CMSG_SPACE(s2_len);
+   cmsgbuf = calloc(cmsgbuf_size, sizeof(char));
+   assert_non_null(cmsgbuf);
+   msg.msg_control = cmsgbuf;
+   msg.msg_controllen = cmsgbuf_size;
+
+   /*
+* Prepare first cmsg with string "Hello World"
+*/
+   cmsg = CMSG_FIRSTHDR();
+   assert_non_null(cmsg);
+
+   cmsg->cmsg_level = SOL_SOCKET;
+   cmsg->cmsg_type = ~0 - 1;
+   cmsg->cmsg_len = CMSG_LEN(s1_len);
+   memcpy(CMSG_DATA(cmsg), s1, s1_len);
+
+   /*
+* Prepare second cmsg with string "!\n"
+*/
+   cmsg = CMSG_NXTHDR(, cmsg);
+  

[SCM] Socket Wrapper Repository - branch master updated

2015-10-14 Thread Michael Adam
The branch, master has been updated
   via  84a4e23 tests: Add test for TCP_NODELAY setsockopt()
   via  96dbeb7 tests: Add test for TCP_NODELAY getsockopt()
   via  1db6130 swrap: Add support for TCP_NODELAY in getsockopt()
   via  e9e0dac swrap: Add support for TCP_NODELAY in setsockopt()
  from  40b1926 Bump version to 1.1.4

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 84a4e23728a558984f449610b9e84933acfb0515
Author: Andreas Schneider 
Date:   Thu Oct 8 11:02:10 2015 +0200

tests: Add test for TCP_NODELAY setsockopt()

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit 96dbeb75f78665cf81a4ef8e3842e819043f8d51
Author: Andreas Schneider 
Date:   Mon Sep 14 22:07:09 2015 +0200

tests: Add test for TCP_NODELAY getsockopt()

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit 1db61302b6036bdfabf0e3a1507e0e5573a57368
Author: Andreas Schneider 
Date:   Mon Sep 14 22:06:52 2015 +0200

swrap: Add support for TCP_NODELAY in getsockopt()

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

commit e9e0dac6d719304af8174f4b9119709afe71f508
Author: Andreas Schneider 
Date:   Thu Oct 8 10:51:02 2015 +0200

swrap: Add support for TCP_NODELAY in setsockopt()

Signed-off-by: Andreas Schneider 
Reviewed-by: Michael Adam 

---

Summary of changes:
 src/socket_wrapper.c | 53 
 tests/test_echo_tcp_socket_options.c | 49 +
 2 files changed, 102 insertions(+)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 45282ed..aad5f3e 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -248,6 +248,7 @@ struct socket_info
int connected;
int defer_connect;
int pktinfo;
+   int tcp_nodelay;
 
/* The unix path so we can unlink it on close() */
struct sockaddr_un un_addr;
@@ -3350,6 +3351,29 @@ static int swrap_getsockopt(int s, int level, int 
optname,
   optval,
   optlen);
}
+   } else if (level == IPPROTO_TCP) {
+   switch (optname) {
+#ifdef TCP_NODELAY
+   case TCP_NODELAY:
+   /*
+* This enables sending packets directly out over TCP.
+* As a unix socket is doing that any way, report it as
+* enabled.
+*/
+   if (optval == NULL || optlen == NULL ||
+   *optlen < (socklen_t)sizeof(int)) {
+   errno = EINVAL;
+   return -1;
+   }
+
+   *optlen = sizeof(int);
+   *(int *)optval = si->tcp_nodelay;
+
+   return 0;
+#endif /* TCP_NODELAY */
+   default:
+   break;
+   }
}
 
errno = ENOPROTOOPT;
@@ -3388,6 +3412,35 @@ static int swrap_setsockopt(int s, int level, int 
optname,
   optname,
   optval,
   optlen);
+   } else if (level == IPPROTO_TCP) {
+   switch (optname) {
+#ifdef TCP_NODELAY
+   case TCP_NODELAY: {
+   int i;
+
+   /*
+* This enables sending packets directly out over TCP.
+* A unix socket is doing that any way.
+*/
+   if (optval == NULL || optlen == 0 ||
+   optlen < (socklen_t)sizeof(int)) {
+   errno = EINVAL;
+   return -1;
+   }
+
+   i = *discard_const_p(int, optval);
+   if (i != 0 && i != 1) {
+   errno = EINVAL;
+   return -1;
+   }
+   si->tcp_nodelay = i;
+
+   return 0;
+   }
+#endif /* TCP_NODELAY */
+   default:
+   break;
+   }
}
 
switch (si->family) {
diff --git a/tests/test_echo_tcp_socket_options.c 
b/tests/test_echo_tcp_socket_options.c
index f068fb8..dfa46fe 100644
--- a/tests/test_echo_tcp_socket_options.c
+++ b/tests/test_echo_tcp_socket_options.c
@@ -10,6 +10,7 @@
 

[SCM] Socket Wrapper Repository - branch master updated

2015-08-25 Thread Andreas Schneider
The branch, master has been updated
   via  40b1926 Bump version to 1.1.4
  from  c3c5f02 swrap: Call dlclose() in the destructor

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 40b1926e42896bb977705ed155c385b413ddd517
Author: Andreas Schneider a...@samba.org
Date:   Mon Aug 24 17:53:28 2015 +0200

Bump version to 1.1.4

Signed-off-by: Andreas Schneider a...@samba.org
Reviewed-by: Alexander Bokovoy a...@samba.org

---

Summary of changes:
 CMakeLists.txt | 4 ++--
 ChangeLog  | 6 ++
 2 files changed, 8 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ee6daa6..5407410 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 
 set(APPLICATION_VERSION_MAJOR 1)
 set(APPLICATION_VERSION_MINOR 1)
-set(APPLICATION_VERSION_PATCH 3)
+set(APPLICATION_VERSION_PATCH 4)
 
 set(APPLICATION_VERSION 
${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH})
 
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION 
${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
 # Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 # Increment REVISION.
-set(LIBRARY_VERSION 0.1.3)
+set(LIBRARY_VERSION 0.1.4)
 set(LIBRARY_SOVERSION 0)
 
 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is 
checked
diff --git a/ChangeLog b/ChangeLog
index c5b6019..b3509ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
 ChangeLog
 ==
 
+version 1.1.4 (released 2015-08-25)
+  * Fixed handling of msg_name in recvmsg()
+  * Fixed sendmsg()/recvmsg() TCP support
+  * Fixed several compile warnings
+  * Added environment variable to change MTU
+
 version 1.1.3 (released 2015-02-23)
   * Added support for address sanitizer.
   * Fixed leaking of memory and fds of stale sockets.


-- 
Socket Wrapper Repository



[SCM] Socket Wrapper Repository - branch master updated

2015-08-17 Thread Andreas Schneider
The branch, master has been updated
   via  c3c5f02 swrap: Call dlclose() in the destructor
   via  19fd43f tests: Rename s_addr to send_addr
   via  cf8fc6d tests: Fix memset() call in new tests
   via  94e6f3b tests: Fix passing pointer of incompatible type
   via  9434cdc swrap: Fix signed comparsion warnings
  from  6ece682 swrap: Add enviornment variable to specify mtu size

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit c3c5f02b0746958845eb825620765ac741920985
Author: Andreas Schneider a...@samba.org
Date:   Mon Aug 17 12:14:44 2015 +0200

swrap: Call dlclose() in the destructor

Signed-off-by: Andreas Schneider a...@samba.org

commit 19fd43f706cd73add4c7dd23613ceccf00fc0c84
Author: Andreas Schneider a...@samba.org
Date:   Mon Aug 17 12:06:30 2015 +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 a...@samba.org

commit cf8fc6d9572cf7800e46e68e3d01802345a7e54b
Author: Andreas Schneider a...@samba.org
Date:   Wed Aug 12 08:48:56 2015 +0200

tests: Fix memset() call in new tests

Signed-off-by: Andreas Schneider a...@samba.org

commit 94e6f3b24ad8e21857f3062a2a21429dea31b790
Author: Andreas Schneider a...@samba.org
Date:   Wed Aug 12 08:37:39 2015 +0200

tests: Fix passing pointer of incompatible type

Signed-off-by: Andreas Schneider a...@samba.org

commit 9434cdc6747b0837551bdd341d2f9b0f5479eb07
Author: Andreas Schneider a...@samba.org
Date:   Wed Aug 12 08:37:07 2015 +0200

swrap: Fix signed comparsion warnings

Signed-off-by: Andreas Schneider a...@samba.org

---

Summary of changes:
 src/socket_wrapper.c | 11 --
 tests/test_echo_tcp_connect.c|  2 +-
 tests/test_echo_tcp_get_peer_sock_name.c |  2 +-
 tests/test_echo_tcp_sendmsg_recvmsg.c| 12 +--
 tests/test_echo_tcp_socket.c |  2 +-
 tests/test_echo_udp_sendmsg_recvmsg.c| 36 
 6 files changed, 36 insertions(+), 29 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 01ab8d5..45282ed 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -3799,7 +3799,7 @@ static ssize_t swrap_sendmsg_before(int fd,
msg-msg_iovlen = i;
if (msg-msg_iovlen == 0) {
*tmp_iov = msg-msg_iov[0];
-   tmp_iov-iov_len = MIN(tmp_iov-iov_len, mtu);
+   tmp_iov-iov_len = MIN(tmp_iov-iov_len, (size_t)mtu);
msg-msg_iov = tmp_iov;
msg-msg_iovlen = 1;
}
@@ -4016,7 +4016,7 @@ static int swrap_recvmsg_before(int fd,
msg-msg_iovlen = i;
if (msg-msg_iovlen == 0) {
*tmp_iov = msg-msg_iov[0];
-   tmp_iov-iov_len = MIN(tmp_iov-iov_len, mtu);
+   tmp_iov-iov_len = MIN(tmp_iov-iov_len, (size_t)mtu);
msg-msg_iov = tmp_iov;
msg-msg_iovlen = 1;
}
@@ -5131,4 +5131,11 @@ void swrap_destructor(void)
}
s = sockets;
}
+
+   if (swrap.libc_handle != NULL) {
+   dlclose(swrap.libc_handle);
+   }
+   if (swrap.libsocket_handle) {
+   dlclose(swrap.libsocket_handle);
+   }
 }
diff --git a/tests/test_echo_tcp_connect.c b/tests/test_echo_tcp_connect.c
index f97b5ac..d2020c8 100644
--- a/tests/test_echo_tcp_connect.c
+++ b/tests/test_echo_tcp_connect.c
@@ -76,7 +76,7 @@ static void test_connect_downgrade_ipv6(void **state)
assert_int_equal(rc, 1);
 
/* Connect should downgrade to IPv4 and allow the connect */
-   rc = connect(s, addr.sa.in, addr.sa_socklen);
+   rc = connect(s, addr.sa.s, addr.sa_socklen);
assert_int_equal(rc, 0);
 
close(s);
diff --git a/tests/test_echo_tcp_get_peer_sock_name.c 
b/tests/test_echo_tcp_get_peer_sock_name.c
index 9a00255..ac369dd 100644
--- a/tests/test_echo_tcp_get_peer_sock_name.c
+++ b/tests/test_echo_tcp_get_peer_sock_name.c
@@ -413,7 +413,7 @@ static void test_connect_getsockname_getpeername_len(void 
**state)
assert_int_equal(rc, 1);
 
/* Connect */
-   rc = connect(s, addr.sa.in, addr.sa_socklen);
+   rc = connect(s, addr.sa.s, addr.sa_socklen);
assert_return_code(rc, errno);
 
/* Check with len=0 */
diff --git a/tests/test_echo_tcp_sendmsg_recvmsg.c 
b/tests/test_echo_tcp_sendmsg_recvmsg.c
index 2adaa75..4f7629e 100644
--- a/tests/test_echo_tcp_sendmsg_recvmsg.c
+++ b/tests/test_echo_tcp_sendmsg_recvmsg.c
@@ -193,7 +193,7 @@ static void test_sendmsg_recvmsg_ipv6(void **state)
 
 static void 

[SCM] Socket Wrapper Repository - branch master updated

2015-08-11 Thread Andreas Schneider
The branch, master has been updated
   via  6ece682 swrap: Add enviornment variable to specify mtu size
   via  c2d26a8 tests: Add tcp sendmsg/recvmsg test
   via  32f65ea swrap: Fix TCP support with sendmsg/recvmsg
   via  2e7cda5 tests: Tests for msg_name(len) in sendmsg/revcmsg
   via  73c2168 tests: Fix testname of sendmsg tests
   via  85b7f56 swrap: Correctly update the msg_name in recvmsg()
   via  055eb78 tests: Migrate to new cmocka API
  from  00eb315 Update TODO

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -
commit 6ece682ee36794aebd08503c60ecb1797c04849f
Author: Andreas Schneider a...@samba.org
Date:   Tue Aug 11 12:11:16 2015 +0200

swrap: Add enviornment variable to specify mtu size

Signed-off-by: Andreas Schneider a...@samba.org
Reviewed-by: Stefan Metzmacher me...@samba.org

commit c2d26a8dbd89d3db32461061e0b33df4f3eb87a1
Author: Andreas Schneider a...@samba.org
Date:   Tue Aug 11 11:40:30 2015 +0200

tests: Add tcp sendmsg/recvmsg test

Signed-off-by: Andreas Schneider a...@samba.org
Reviewed-by: Stefan Metzmacher me...@samba.org

commit 32f65eaa9ad699898fa274ea1f29655e6a344fb9
Author: Andreas Schneider a...@samba.org
Date:   Tue Aug 11 11:39:52 2015 +0200

swrap: Fix TCP support with sendmsg/recvmsg

Signed-off-by: Andreas Schneider a...@samba.org
Reviewed-by: Stefan Metzmacher me...@samba.org

commit 2e7cda5246b3b7565d376e9609b0e84b3cdff1d5
Author: Andreas Schneider a...@cryptomilk.org
Date:   Mon Aug 10 16:09:16 2015 +0200

tests: Tests for msg_name(len) in sendmsg/revcmsg

Signed-off-by: Andreas Schneider a...@cryptomilk.org
Reviewed-by: Stefan Metzmacher me...@samba.org

commit 73c2168291825fcbff4a4846a395793ceac46202
Author: Andreas Schneider a...@cryptomilk.org
Date:   Mon Aug 10 13:39:09 2015 +0200

tests: Fix testname of sendmsg tests

Signed-off-by: Andreas Schneider a...@cryptomilk.org
Reviewed-by: Stefan Metzmacher me...@samba.org

commit 85b7f564bd397e82cf847607f0bcee4e35f489ac
Author: Andreas Schneider a...@samba.org
Date:   Wed Aug 5 15:02:49 2015 +0200

swrap: Correctly update the msg_name in recvmsg()

This has been found while debugging nsupdate.

Signed-off-by: Andreas Schneider a...@samba.org
Reviewed-by: Stefan Metzmacher me...@samba.org

commit 055eb78f3690008021e17da8714da9db5247308c
Author: Andreas Schneider a...@samba.org
Date:   Thu Aug 6 16:08:32 2015 +0200

tests: Migrate to new cmocka API

Signed-off-by: Andreas Schneider a...@samba.org
Reviewed-by: Stefan Metzmacher me...@samba.org

---

Summary of changes:
 doc/socket_wrapper.1 |  11 +-
 doc/socket_wrapper.1.txt |   9 +-
 src/socket_wrapper.c | 114 ++---
 tests/CMakeLists.txt |   1 +
 tests/test_echo_tcp_bind.c   |  30 ++--
 tests/test_echo_tcp_connect.c|  18 +-
 tests/test_echo_tcp_get_peer_sock_name.c |  44 ++---
 tests/test_echo_tcp_sendmsg_recvmsg.c| 273 +++
 tests/test_echo_tcp_socket.c |   8 +-
 tests/test_echo_tcp_socket_options.c |  40 +++--
 tests/test_echo_tcp_write_read.c |  24 ++-
 tests/test_echo_tcp_writev_readv.c   |  24 ++-
 tests/test_echo_udp_send_recv.c  |  24 ++-
 tests/test_echo_udp_sendmsg_recvmsg.c| 224 -
 tests/test_echo_udp_sendto_recvfrom.c|  24 ++-
 tests/test_ioctl.c   |  18 +-
 tests/test_sendmsg_recvmsg_fd.c  |   6 +-
 17 files changed, 760 insertions(+), 132 deletions(-)
 create mode 100644 tests/test_echo_tcp_sendmsg_recvmsg.c


Changeset truncated at 500 lines:

diff --git a/doc/socket_wrapper.1 b/doc/socket_wrapper.1
index 4e0dd01..c3cf835 100644
--- a/doc/socket_wrapper.1
+++ b/doc/socket_wrapper.1
@@ -2,12 +2,12 @@
 .\ Title: socket_wrapper
 .\Author: [FIXME: author] [see http://docbook.sf.net/el/author]
 .\ Generator: DocBook XSL Stylesheets v1.78.1 http://docbook.sf.net/
-.\  Date: 2014-07-09
+.\  Date: 2015-08-11
 .\Manual: \ \
 .\Source: \ \
 .\  Language: English
 .\
-.TH SOCKET_WRAPPER 1 2014\-07\-09 \ \ \ \
+.TH SOCKET_WRAPPER 1 2015\-08\-11 \ \ \ \
 .\ -
 .\ * Define some portability stuff
 .\ -
@@ -85,6 +85,13 @@ Additionally, the default interface to be used by an 
application is defined with
 When debugging, it is often interesting to investigate the network traffic 
between the client and server within your application\. If you define 
SOCKET_WRAPPER_PCAP_FILE=/path/to/file\.pcap, socket_wrapper will dump all 
your network traffic to the specified file\. After the test has 

  1   2   >