summaryrefslogtreecommitdiff
path: root/lib/async_req
AgeCommit message (Collapse)AuthorFilesLines
2023-10-24lib/async_req: let writev_send/recv use TEVENT_FD_ERRORStefan Metzmacher1-31/+18
Unless err_on_readability is true, we use TEVENT_FD_READ only to detect errors. Now that we have TEVENT_FD_ERROR we should use it. As a side effect it makes the code much simpler and clearer, as we can directly map TEVENT_FD_ERROR to EPIPE. In addition the err_on_readability=true case is now also clearer, where we just map TEVENT_FD_READ to EPIPE. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-10-24lib/async_req: let async_connect_send use TEVENT_FD_ERROR instead of ↵Stefan Metzmacher1-1/+2
TEVENT_FD_READ This mostly cosmetic, but now that we have TEVENT_FD_ERROR we should use it. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-03-16lib: Use FIONREAD in wait_for_read_send/recvVolker Lendecke1-14/+7
ENOTSOCK looks ugly in straces... Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-01-22lib: Make accept_recv() return the listening socketVolker Lendecke2-1/+9
This is helpful if you are in a listening loop with the same receiver for many sockets doing the same thing. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-01-22lib: Make accept_recv() return struct samba_sockaddrVolker Lendecke2-13/+15
Avoid casting problems by using the samba_sockaddr union Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2020-04-23lib: Fix a valgrind errorVolker Lendecke1-0/+9
I just came across this failure with a new test: ==16654== Invalid read of size 4 ==16654== at 0x4950947: tevent_req_is_in_progress (tevent_req.c:270) ==16654== by 0x5AEEE8F: writev_trigger (async_sock.c:375) ==16654== by 0x494F9E7: tevent_queue_immediate_trigger (tevent_queue.c:149) ==16654== by 0x494F53C: tevent_common_invoke_immediate_handler (tevent_immediate.c:166) ==16654== by 0x494F642: tevent_common_loop_immediate (tevent_immediate.c:203) ==16654== by 0x4959E5E: epoll_event_loop_once (tevent_epoll.c:918) ==16654== by 0x495665A: std_event_loop_once (tevent_standard.c:110) ==16654== by 0x494DFCE: _tevent_loop_once (tevent.c:772) ==16654== by 0x4950A6A: tevent_req_poll (tevent_req.c:300) ==16654== by 0x4D166C9: tevent_req_poll_ntstatus (tevent_ntstatus.c:109) ==16654== by 0x18C98B: run_readdir_timestamp (test_readdir_timestamp.c:489) ==16654== by 0x161BC5: run_test (torture.c:14896) ==16654== by 0x162726: main (torture.c:15136) ==16654== Address 0x91bb878 is 216 bytes inside a block of size 853 free'd ==16654== at 0x48369AB: free (vg_replace_malloc.c:530) ==16654== by 0x49B405E: _tc_free_internal (talloc.c:1221) ==16654== by 0x49B4116: _talloc_free_internal (talloc.c:1247) ==16654== by 0x49B547C: _talloc_free (talloc.c:1789) ==16654== by 0x50ECE3B: smb2cli_req_writev_done (smbXcli_base.c:3468) ==16654== by 0x4950648: _tevent_req_notify_callback (tevent_req.c:141) ==16654== by 0x49507A9: tevent_req_finish (tevent_req.c:193) ==16654== by 0x49507D6: _tevent_req_done (tevent_req.c:199) ==16654== by 0x5AEEE28: writev_do (async_sock.c:363) ==16654== by 0x5AEEE83: writev_trigger (async_sock.c:374) ==16654== by 0x494F9E7: tevent_queue_immediate_trigger (tevent_queue.c:149) ==16654== by 0x494F53C: tevent_common_invoke_immediate_handler (tevent_immediate.c:166) ==16654== by 0x494F642: tevent_common_loop_immediate (tevent_immediate.c:203) ==16654== by 0x4959E5E: epoll_event_loop_once (tevent_epoll.c:918) ==16654== by 0x495665A: std_event_loop_once (tevent_standard.c:110) ==16654== by 0x494DFCE: _tevent_loop_once (tevent.c:772) ==16654== by 0x4950A6A: tevent_req_poll (tevent_req.c:300) ==16654== by 0x4D166C9: tevent_req_poll_ntstatus (tevent_ntstatus.c:109) ==16654== by 0x18C98B: run_readdir_timestamp (test_readdir_timestamp.c:489) ==16654== by 0x161BC5: run_test (torture.c:14896) ==16654== by 0x162726: main (torture.c:15136) ==16654== Block was alloc'd at ==16654== at 0x483577F: malloc (vg_replace_malloc.c:299) ==16654== by 0x49B300F: __talloc_with_prefix (talloc.c:782) ==16654== by 0x49B31E6: _talloc_pool (talloc.c:837) ==16654== by 0x49B3394: _talloc_pooled_object (talloc.c:905) ==16654== by 0x49501A6: _tevent_req_create (tevent_req.c:79) ==16654== by 0x5AEE956: writev_send (async_sock.c:266) ==16654== by 0x50ECBCA: smb2cli_req_compound_submit (smbXcli_base.c:3396) ==16654== by 0x50ECD49: smb2cli_req_send (smbXcli_base.c:3447) ==16654== by 0x50FE34F: smb2cli_create_send (smb2cli_create.c:153) ==16654== by 0x490325E: cli_smb2_create_fnum_send (cli_smb2_fnum.c:273) ==16654== by 0x48D0146: cli_ntcreate_send (clifile.c:2504) ==16654== by 0x18B737: create_ts_send (test_readdir_timestamp.c:59) ==16654== by 0x18BF77: create_ts_files_send (test_readdir_timestamp.c:253) ==16654== by 0x18C35C: create_files_send (test_readdir_timestamp.c:336) ==16654== by 0x18C953: run_readdir_timestamp (test_readdir_timestamp.c:482) ==16654== by 0x161BC5: run_test (torture.c:14896) ==16654== by 0x162726: main (torture.c:15136) Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Thu Apr 23 21:53:38 UTC 2020 on sn-devel-184
2020-03-25lib: Try nonblocking writes in writev_send()Volker Lendecke1-27/+44
All callers now use nonblocking sockets, so that we can optimize by doing early writes Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Wed Mar 25 10:41:29 UTC 2020 on sn-devel-184
2020-03-25lib: Use optimize_empty in writev_send()Volker Lendecke1-2/+2
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2020-03-25lib: Simplify writev_cancel()Volker Lendecke1-12/+4
We can only reasonably cancel a writev request that is still queued. Once writing has started, cancel is pointless. Simplify the if-conditions. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2020-02-26lib/async_req: remove useless "reentrant" support from async_connect_send()Stefan Metzmacher1-5/+1
Now that open_socket_out*() doesn't do the strange reentrant calls, we can remove support for this in async_connect_send(), so that we'll never get any new users of this. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-26lib/async_req: make sure we return errors early from async_connect_send/recvStefan Metzmacher1-1/+8
While it is true that [e]poll() only needs POLLOUT and POLLERR/POLLHUP are added implicitly. For tevent we need TEVENT_FD_READ in order to see POLLERR/POLLHUP. The socket becomes only readable when we hit an error. Waiting for TEVENT_FD_WRITE is needed for getting success, while TEVENT_FD_READ is required to get failures. This matches what we have in tstream_bsd_connect_send(). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2019-11-22build: Do not build selftest binaries for builds without --enable-selftestAndrew Bartlett1-1/+1
Add new for_selftest option to SAMBA_BINARY() and SAMBA3_BINARY() This allows us to be much more consistent (at least in the core Samba) and documents clearly why the binary should not be installed. Not modified are - test_lp_load - notifyd-tests - gendrandperf - test* from examples/libsmbclient - dbwrap_torture - split_tokens - locktest2 - msgtest - msg_sink - msg_source - versiontest - rpc_open_tcp - test_headers As these are not tested in selftest so any change would also be untested. Of course they probably should be added in a different MR. Also not modified (because they are not tests, nor part of the build system) are: - smb2mount - notifydd - log2pacp - debug2html - smbfilter - destroy_netlogon_creds_cli - spotlight2* - tevent_glib_tracker These do however appear to be untested. For now, the source4 forked client tools are left unchanged: - smbclient4 - nmblookup4 Finally, the heimdal binaries are left as install=False as they are either part of the build system or end-user tools that we just don't want to install. These are however tested. The motivation is commit like c34ec003b7d45aa4196ff93a0ac29694b25e5309 and da87fa998ab71328f30bcdf5b41aee8675aee48a, which are both totally correct but are not needed if the selftest is not run on MacOS. There are likely other platforms or build environments where building our test binaries is more pain than valuable, see for example also https://lists.samba.org/archive/samba/2019-November/227137.html Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Isaac Boukris <iboukris@samba.org> Autobuild-User(master): Isaac Boukris <iboukris@samba.org> Autobuild-Date(master): Fri Nov 22 11:48:59 UTC 2019 on sn-devel-184
2017-12-18lib/async_req/async_sock.c set socket close on execGary Lockyer1-0/+1
Set SOCKET_CLOEXEC on the sockets returned by accept. This ensures that the socket is unavailable to any child process created by system(). Making it harder for malicious code to set up a command channel, as seen in the exploit for CVE-2015-0240 Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2017-08-16lib: tevent: Use system <tevent.h>, not internal header path (except in ↵Jeremy Allison1-1/+1
self-test). Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2016-10-26lib/async_req: add writev_cancel()Stefan Metzmacher1-2/+36
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2016-08-04async_req: make async_connect_send() "reentrant"Ralph Boehme1-3/+13
Allow callers to pass in socket fds that where already passed to an earlier call of async_connect_send(). Callers expect this behaviour and it was working until 05d4dbda8357712cb81008e0d611fdb0e7239587 broke it. The proper fix would be to change callers to close the fd and start from scratch with a fresh socket. Bug: https://bugzilla.samba.org/show_bug.cgi?id=12105 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Thu Aug 4 05:03:21 CEST 2016 on sn-devel-144
2016-06-13lib: Fix a signed/unsigned mixupVolker Lendecke1-1/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2016-06-07lib: Add accept_send/recvVolker Lendecke2-0/+88
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-12-01lib/async_req: do not install async_connect_send_test.Günther Deschner1-1/+2
Guenther Signed-off-by: Günther Deschner <gd@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2015-10-21selftest: Fix memset parameters in test for async_connect_send()Andrew Bartlett1-1/+1
This fixes: ../lib/async_req/async_connect_send_test.c: In function ‘main’: ../lib/async_req/async_connect_send_test.c:88:3: error: ‘memset’ used with constant zero length parameter; this could be due to transposed parameters [-Werror=memset-transposed-args] memset(&addr, sizeof(addr), 0); ^ Bug: https://bugzilla.samba.org/show_bug.cgi?id=11564 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Wed Oct 21 17:31:00 CEST 2015 on sn-devel-104
2015-10-20async_req: fix non-blocking connect()Ralph Boehme1-29/+27
According to Stevens UNIX Network Programming and various other sources, the correct handling for non-blocking connect() is: - when the initial connect() return -1/EINPROGRESS polling the socket for *writeability* - in the poll handler call getsocktopt() with SO_ERROR to get the finished connect() return value Simply calling connect() a second time without error checking is probably wrong and not portable. For a successfull connect() Linux returns 0, but Solaris will return EISCONN: 24254: 0.0336 0.0002 connect(4, 0xFEFFECAC, 16, SOV_DEFAULT) Err#150 EINPROGRESS 24254: AF_INET name = 10.10.10.143 port = 1024 24254: 0.0349 0.0001 port_associate(3, 4, 0x00000004, 0x0000001D,0x080648A8) = 0 24254: 0.0495 0.0146 port_getn(3, 0xFEFFEB50, 1, 1, 0xFEFFEB60) = 1 [0] 24254: 0.0497 0.0002 connect(4, 0x080646E4, 16, SOV_DEFAULT) Err#133 EISCONN 24254: AF_INET name = 10.10.10.143 port = 1024 Bug: https://bugzilla.samba.org/show_bug.cgi?id=11564 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-10-20selftest: add a test for async_connect_send()Ralph Boehme2-0/+134
Bug: https://bugzilla.samba.org/show_bug.cgi?id=11564 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-07-15async_req: check for errors when monitoring socket for readabilityUri Simchoni2-5/+44
Add an option to wait_for_read_send(), so that the request, upon calling back, report whether the socket actually contains data or is in EOF/error state. EOF is signalled via the EPIPE error. This is useful for clients which do not expect data to arrive but wait for readability to detect a closed socket (i.e. they do not intend to actually read the socket when it's readable). Actual data arrival would indicate a bug in this case, so the check can be used to print an error message. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11397 Signed-off-by: Uri Simchoni <urisimchoni@gmail.com> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-06-23lib: Fix CID 710685 Unchecked return value from libraryVolker Lendecke1-1/+6
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-06-16lib: Fix CID 1306765 Unchecked return value from libraryVolker Lendecke1-1/+7
This one might be a bit controversial. I don't see from man fcntl how this could fail. But if it does, we definitely do want to know about it. And here we don't have any good way to tell our caller, so abort. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Tue Jun 16 19:22:52 CEST 2015 on sn-devel-104
2015-06-16lib: Fix CID 1306764 Unchecked return valueVolker Lendecke1-1/+1
tevent_req_oom exists right for this case :-) Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org>
2015-06-12lib/async_req: remove the tevent_fd as early as possible via a ↵Stefan Metzmacher1-9/+21
wait_for_read_cleanup() hook BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-06-12lib/async_req: remove the tevent_fd as early as possible via a ↵Stefan Metzmacher1-4/+20
read_packet_cleanup() hook BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-06-12lib/async_req: use tevent_req_nomem/tevent_req_post in read_packet_send()Stefan Metzmacher1-7/+4
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-06-12lib/async_req: s/result/req/ in read_packet_send()Stefan Metzmacher1-6/+6
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-06-12lib/async_req: remove the tevent_fd as early as possible via a ↵Stefan Metzmacher1-14/+27
writev_cleanup() hook BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-06-12lib/async_req: simplify async_connect_* using a _cleanup() hookStefan Metzmacher1-35/+33
This makes sure we remove the tevent_fd as soon as possible and always reset the old_sockflags. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-06-12lib/async_req: s/result/req/ in async_connect_send()Stefan Metzmacher1-9/+8
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-06-12lib/async_req: remove unused sendto_{send,recv} and recvfrom_{send,recv}Stefan Metzmacher2-190/+0
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-02-24lib: Move "iov_buf.[ch]" to lib/utilVolker Lendecke1-1/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2014-12-30lib: Use iov_advance in writev_handlerVolker Lendecke2-26/+10
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2014-09-18lib: Make set_blocking() available independentlyVolker Lendecke1-1/+1
async_connect_send() needs this, and I don't want to pull in samba-util just for this Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2013-12-09CVE-2013-4408:async_sock: add some overflow detection to read_packet_handler()Stefan Metzmacher1-0/+5
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10185 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2013-05-17lib: Add before/after hooks to async_connectVolker Lendecke2-8/+37
This will facilitiate [un]become_root for smbd to connect safely to ctdbd. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Christian Ambach <ambi@samba.org>
2012-09-25lib: Make async_sock includable on its ownVolker Lendecke1-0/+1
Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Tue Sep 25 18:03:46 CEST 2012 on sn-devel-104
2012-03-23lib/async_req: Retry read_packet with read(2)Volker Lendecke1-0/+4
This way it will also work with pipes Autobuild-User: Volker Lendecke <vl@samba.org> Autobuild-Date: Fri Mar 23 17:31:24 CET 2012 on sn-devel-104
2011-09-23build: avoid util.h as a public header name due to conflict with MacOSAndrew Bartlett1-1/+1
2011-08-25s3: Fix bug 8385Volker Lendecke1-26/+14
Poll and select behave differently regarding error handling. When doing the connect(2), we can not rely on poll telling us both readability and writability upon error. Just always try a second connect(2). At least on Linux it returns 0 when it succeeded. Signed-off-by: Jeremy Allison <jra@samba.org> Autobuild-User: Jeremy Allison <jra@samba.org> Autobuild-Date: Thu Aug 25 19:39:12 CEST 2011 on sn-devel-104
2011-08-08build: provide tevent-util as a public libraryAndrew Bartlett1-1/+1
This is needed so that OpenChange can get at _tevent_req_nterr(), which is referenced by generated PIDL output. Andrew Bartlett
2011-07-28Add wait_for_read_send/recvVolker Lendecke2-0/+60
Wait for readability of a socket as a tevent_req
2011-06-06Fix bug #8197 - winbind does not properly detect when a DC connection is dead.Jeremy Allison1-6/+32
Only waiting for writability doesn't get fd errors back with poll. So always begin by selecting for readability, and if we get it then see if bytes were available to read or it really is an error condition. If bytes were available, remove the select on read as we know we will retrieve the error when we've finished writing and start reading the reply (or the write will timeout or fail). Metze and Volker please check. Autobuild-User: Jeremy Allison <jra@samba.org> Autobuild-Date: Mon Jun 6 21:53:16 CEST 2011 on sn-devel-104
2011-03-23async_rec/async_sock.c - add an additional "const"Matthias Dieter Wallnöfer1-1/+2
In order to suppress a build warning. Acked-by: Volker and Metze Autobuild-User: Matthias Dieter Wallnöfer <mdw@samba.org> Autobuild-Date: Wed Mar 23 10:26:23 CET 2011 on sn-devel-104
2011-02-14s3-waf: add UTIL_TEVENT subsystem (as in ../lib/util/wscript)Günther Deschner1-1/+2
Guenther
2010-12-29Use sockaddr_storage in async sendto/recvfromVolker Lendecke2-11/+28
2010-12-28async_send->sendto, async_recv->recvfromVolker Lendecke2-42/+53