summaryrefslogtreecommitdiffstats
path: root/src/socket_wrapper.c
Commit message (Collapse)AuthorAgeFilesLines
...
* swrap: Fix prototype of open[64] to prevent segfault on ppc64leAndreas Schneider2017-09-071-2/+2
| | | | | | | | | | The calling conventions for vaarg are different on ppc64le. The patch fixes segfaults on that platform. Thanks to Florian Weimer who helped debugging it! Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Improve argument handling for libc_vopen*()Andreas Schneider2017-09-071-10/+16
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Improve argument handling for libc_vioctl()Andreas Schneider2017-09-071-11/+3
| | | | | | | The ioctl() only takes one or no argument. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Improve argument handling for libc_fcntl()Andreas Schneider2017-09-071-11/+3
| | | | | | | fcntl() has either one or no argument. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Simplify printing different log prefixesAndreas Schneider2017-09-071-23/+18
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Do an early return if log level doesn't matchAndreas Schneider2017-09-071-0/+4
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Always enable loggingAndreas Schneider2017-09-071-7/+0
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Protect the FALL_THROUGH defineAndreas Schneider2017-07-271-5/+7
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Add common exit point to swrap_setsockoptAnoop C S2017-07-271-6/+16
| | | | | | | | In preparation of thread safety. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Add common exit point to swrap_getsockoptAnoop C S2017-07-271-14/+27
| | | | | | | | In preparation of thread safety. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Add common exit point to swrap_connectAnoop C S2017-07-271-4/+7
| | | | | | | | In preparation of thread safety. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Add common exit point to swrap_auto_bindAnoop C S2017-07-271-7/+15
| | | | | | | | In preparation for thread safety. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Fix tab vs space in swrap_auto_bindMichael Adam2017-07-271-2/+2
| | | | | Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Suppress intentional fall through warningAnoop C S2017-07-271-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -Wimplicit-fallthrough compiler flag introduced with gcc v7 results in the following warning during compilation: [ 7%] Building C object src/CMakeFiles/socket_wrapper.dir/socket_wrapper.c.o src/socket_wrapper.c: In function ‘sockaddr_convert_to_un’: src/socket_wrapper.c:1846:18: warning: this statement may fall through [-Wimplicit-fallthrough=] case AF_UNSPEC: { ^ /src/socket_wrapper.c:1866:2: note: here case AF_INET: ^~~~ Default level for -Wimplicit-fallthrough(which is 3) allows us to get rid of the above warning using specific comments made within switch cases matching the regular expressions outlined in gcc docs[1]. But for us the presence of preprocessor directives in the vicinity of such comments nullifies its effect[2]. So our best bet would be to make use of the reliable fallthrough attribute and supress such warnings in future. [1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77817 Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Add fopen64() on systems which provide itAndreas Schneider2017-04-061-0/+40
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Add open64() on systems which provide itAndreas Schneider2017-04-061-0/+57
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=12694 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Increase max wrapped interfacesAndreas Schneider2017-04-061-1/+1
| | | | | | | | We are hitting the limit of 40 interfaces with Samba. So increase it to 64. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: use proper blocks for early returnsMichael Adam2017-03-021-17/+51
| | | | | | | | This is better to read and might reduce the diff of later patches. Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Add support for openat()Andreas Schneider2017-03-021-0/+64
|
* Avoid mutex lock wait in socket close failureAnoop C S2017-02-101-4/+0
| | | | | | | | | | | | | | | In case of absence to close a socket fd during an exit from application we try to close the same by traversing the socket_fds in swrap_destructor. But the early lock taken on libc_symbol_binding_mutex inside the destructor blocks the subsequent request for locking the same while loading libc_close within swrap_close. Also added a test case to verify this flaw in destructor. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Add sanity check in socket_wrapper_max_sockets()Andreas Schneider2016-11-041-0/+7
| | | | | | | CID 153962 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Fix use-after-freeAnoop C S2016-10-251-1/+1
| | | | | | | | This was introduced by commit 9ce583b6cd6f55d473e5b54794fb06450997ebc8 Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: fix SWRAP_DLIST_ADD_AFTERAnoop C S2016-10-251-1/+1
| | | | | | | | Pair-Programmed-With: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: fix use-after-free in swrap_remove_stale()Michael Adam2016-10-251-2/+4
| | | | | Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: slightly cleanup logic in swrap_closeMichael Adam2016-10-251-3/+3
| | | | | | | | | This moves the libc_close() to one central point, thereby grouping the fd-related operations together and the the socket-info related operations after that. Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: fix use-after-free in swrap_closeMichael Adam2016-10-251-2/+4
| | | | | Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Fix build on SolarisAndreas Schneider2016-10-251-1/+1
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Mark flags in swrap_accept4 as unusedAndreas Schneider2016-10-211-0/+4
| | | | | | | This removes a compiler warning on non-Linux systems. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Fix the build on BSD and SolarisAndreas Schneider2016-10-211-0/+2
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Handle threads that forkAndreas Schneider2016-10-201-0/+43
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* cmake: Check for constructor attributeAndreas Schneider2016-10-201-0/+6
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Make symbol loading thread-safeAndreas Schneider2016-10-201-3/+22
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Fix strict-aliasing issues while loading symbolsAndreas Schneider2016-10-201-143/+221
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* swrap: Introduce a freelist in the socket_info arrayMichael Adam2016-10-201-7/+37
| | | | | Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Replace linked list of socket_info with preallocated array of structuresAnoop C S2016-10-201-28/+120
| | | | | | | | Pair-Programmed-With: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Optimization in (commented out) check_addr_port_in_use()Michael Adam2016-10-201-0/+6
| | | | | | | | Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Improve vfcntl to add the dup'd fd after the source fdMichael Adam2016-10-201-7/+7
| | | | | | | | Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Improve dup2 to add the dup'd fd after the source fdMichael Adam2016-10-201-5/+6
| | | | | | | | Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Improve dup to add the dup'd fd after the source fdMichael Adam2016-10-201-5/+6
| | | | | | | | Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Add SWRAP_DLIST_ADD_AFTER macroMichael Adam2016-10-201-0/+14
| | | | | | | | Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Untangle socket_info_fd from socket_info structure.Anoop C S2016-10-201-58/+76
| | | | | | | | | | | | | | | | | | | | This reverses the dependency of socket_info on socket_info_fd: Instead of maintaining the list of socket_info structures, and keeping a list of referencing fds (created by dup), we now maintain the list of fds with pointers to the corresponding socket_info structures, and count the references in the socket_info. This makes the treatment of the lists more obvious, especially seen in the removing part. This change is a preparatory step for implementing fd-passing in socket-wrapper. Pair-programmed-with: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: remove ununsed members from struct swrap.Michael Adam2016-08-231-5/+0
| | | | | | | | | | These were used in removed swrap_init(). Pair-Programmed-With: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Treat the case of fd == newfd correctly in dup2()Michael Adam2016-08-231-0/+10
| | | | | | | | Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Delay addition of child socket_info_fd into socket_info listAnoop C S2016-08-121-2/+1
| | | | | | | | | | | | | | In swrap_accept() we used to add new child socket_info_fd[child_fi] into newly created child socket_info struture[child_si] without considering the fact that we may return early in case of errors from subsequent calls to libc_getsockname() and sockaddr_convert_from_un() during which we free child_fi and child_si and return. So it is better to delay the addition of child_fi into child_si->fds until child_si is completely initialized. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Remove redunant check in swrap_socketAnoop C S2016-08-121-4/+1
| | | | | | | | | | The very same check is also being made inside swrap_remove_stale(). So we can get rid of this early if condition. Pair-programmed-with: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Simplify swrap_remove_stale by early returnAnoop C S2016-08-121-14/+16
| | | | | | | Pair-programmed-with: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Fix sendto() with connected socketsRichard Sharpe2016-05-171-9/+28
| | | | | | | | | | | | | | | | | | | | | | | Let the socket wrapper code work with the net ads dns gethostbyname etc code (lib/addn/dnssock.c) which uses connect on a UDP socket before then using sendto and recvfrom. Here, we make sure we don't error out in that case. Tested by creating a test case for this and then observing that: 1. The test case works when the socket wrapper lib is not being used ie, run the test directly after defining some SHELL variables. 2. That the test case fails when run with the un modified socket wrapper code. 3. Apply this fix and observe that it runs correctly. Pair-Programmed-With: Andreas Schneider <asn@samba.org> Signed-off-by: Richard Sharpe <rsharpe@samba.org> Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Allow to open RAW sockets when loadedAndreas Schneider2016-05-171-0/+3
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Add support for accept4()Andreas Schneider2016-05-031-2/+41
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Böhme <slow@samba.org>
* swrap: Add support for running on OpenBSDAndreas Schneider2016-05-031-0/+10
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Böhme <slow@samba.org>