1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-27 03:21:53 +03:00
Commit Graph

63 Commits

Author SHA1 Message Date
Andreas Schneider
4524f5986c tsocket: Do not dereference a NULL pointer
Make sure the lrbsda pointer is not allocated and we will
not end up dereferencing a NULL pointer. In practice this
can't happen, but this change links the pointer with the
code that uses it.

Found by Coverity.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Jun 30 02:53:02 CEST 2016 on sn-devel-144
2016-06-30 02:53:01 +02:00
Ralph Boehme
574313a1e1 lib/tsocket: workaround sockets not supporting FIONREAD
Netlink sockets don't support querying pending bytes with ioctl(fd,
FIONREAD, ...) and would return EOPNOTSUPP, so use recvmsg() with
MSG_PEEK|MSG_TRUNC as a fallback.

The MSG_TRUNC flag to recvmsg() is Linux only, but netlink is as well,
so we're safe for now.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=11714

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Wed Feb 10 10:30:24 CET 2016 on sn-devel-144
2016-02-10 10:30:23 +01:00
Ralph Boehme
3e705adcab lib/tsocket: fix non-blockging connect() error handling
Non-blockging connect() either returns immediate success, or -1 with
errno EINPROGESS as indication that the connection is pending. All other
errnos indicate immediate failure.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2015-10-21 23:13:17 +02:00
Volker Lendecke
052b9a53b7 Fix a typo
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ira Cooper <ira@samba.org>

Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Fri Jun 19 01:05:17 CEST 2015 on sn-devel-104
2015-06-19 01:05:17 +02:00
Stefan Metzmacher
36b97d0bb9 lib/tsocket: add tdgram_inet_udp_broadcast_socket()
This is similar to tdgram_inet_udp_socket(), but it allows
the use of ipv4 broadcast traffic.

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>
Reviewed-by: Jeremy Allison <jra@samba.org>
2015-06-12 17:08:17 +02:00
Stefan Metzmacher
3a8b7b0518 lib/tsocket: add tdgram_bsd_existing_socket() helper function
This is similar to tstream_bsd_existing_socket().
Both help to migrate strange code path to using the tstream or tdgram
abstractions.

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>
Reviewed-by: Jeremy Allison <jra@samba.org>
2015-06-12 17:08:17 +02:00
Volker Lendecke
61dbe450b6 tsocket: Use common code in tsocket_bsd_common_prepare_fd
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org>
2015-06-05 14:33:19 +02:00
Volker Lendecke
d6f70d3346 tsocket: Use iov_advance
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2015-02-24 17:52:09 +01:00
Volker Lendecke
0a20ffb17d tsocket: Fix a typo
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2015-02-24 17:52:08 +01:00
Andreas Schneider
0b58eed335 tsocket: Pass the full port number to getaddrinfo().
The code stripped port numbers above 9999 down to 4 digits.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Mon Jul  1 21:10:53 CEST 2013 on sn-devel-104
2013-07-01 21:10:53 +02:00
Volker Lendecke
fffb70168d tsocket: Add some const
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2013-06-14 20:30:33 +02:00
Ira Cooper
ccb39a3fd2 tsocket: ENOMEM can be retried on illumos/Solaris.
The writev system call can return -1 and errno ENOMEM, as a
retriable condition.

Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Mar 13 23:50:05 CET 2013 on sn-devel-104
2013-03-13 23:50:04 +01:00
Andrew Bartlett
70e1b6185e tsocket_bsd: Attempt to increase the SO_SNDBUF if we get EMSGSIZE in sendto()
This matches what was done for lib/socket/socket_unix.c in
c692bb02b0.

(and is based on that patch by Landon Fuller <landonf@bikemonkey.org>)

Andrew Bartlett

Reviewed-by: Stefan Metzmacher <metze@samba.org>

Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Mon Mar  4 11:15:35 CET 2013 on sn-devel-104
2013-03-04 11:15:35 +01:00
Stefan Metzmacher
e42889f83f lib/tsocket: disable the syscall optimization for recvfrom/readv by default
We only do the optimization on recvfrom/readv if the caller asked for it.

This is needed because in most cases we preferr to flush send
buffers before receiving incoming requests.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2012-11-05 17:13:39 +01:00
Stefan Metzmacher
d2aa785290 lib/tsocket: fix loop in tdgram_bsd_recvfrom() (bug #9184)
If the socket is not readable yet, we need to retry
if tsocket_bsd_pending() returns 0.

See also
https://lists.samba.org/archive/samba-technical/2012-October/087164.html

metze

Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Oct 23 14:44:21 CEST 2012 on sn-devel-104
2012-10-23 14:44:21 +02:00
Stefan Metzmacher
eacdd9f730 lib/tsocket: fix receiving of udp packets from 0 bytes (bug #9184)
It's possible for a client to send 0 bytes in a UDP packet,
we need still need to call recvfrom() and skip the invalid
packet at a higher level. Otherwise the kernel receive queue
is blocked.

metze
2012-09-22 04:31:06 +02:00
Stefan Metzmacher
c378835cb6 tsocket: fill in sa.sa_len if the system supports it
metze
2010-11-05 08:45:14 +00:00
Stefan Metzmacher
79c6572256 tsocket: let tstream_inet_tcp_connect_recv() optionally return the used local address
tstream_inet_tcp_connect_send() usually only gets no local port number
and it may use the wildcard address '0.0.0.0' or '::'.

tstream_inet_tcp_connect_recv() provides the used local address and port
which are used on the wire.

metze
2010-10-23 08:49:30 +02:00
Stefan Metzmacher
d2c653629c tsocket: ask the kernel for the specific local address after a tcp connect
metze
2010-10-23 08:49:29 +02:00
Stefan Metzmacher
4423aa59ab tsocket: make sure we delete the fd event before calling close()
We got random double free errors, when getting events from
epoll_wait() and try to dereference the private talloc pointer
attached to it.

Before doing the close() in the tstream_disconnect_send() function
we need to delete the fd event.

commit 38f505530b only fixed it for
tdgram sockets.

metze
2010-10-04 14:05:15 +00:00
Stefan Metzmacher
38f505530b tsocket: make sure we delete the fd event before calling close()
We got random double free errors, when getting events from
epoll_wait() and try to dereference the private talloc pointer
attached to it.

Before doing the close() in the tstream_disconnect_send() function
we need to delete the fd event.

metze

Autobuild-User: Stefan Metzmacher <metze@samba.org>
Autobuild-Date: Tue Sep 28 01:02:55 UTC 2010 on sn-devel-104
2010-09-28 01:02:55 +00:00
Andrew Tridgell
0212800de8 tsocket: we return -1 on error, not fd
the code used this pattent:

 if (fd < 0) {
   ...various cleanups...
   return fd;
 } 

it is much clearer to do this:

 if (fd < 0) {
   ...various cleanups...
   return -1;
 } 

as otherwise when reading the code you think this function may return
a fd.

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
2010-09-15 15:39:36 +10:00
Stefan Metzmacher
8494d09b89 Revert "lib/tsocket: sa_socklen is a macro on irix, so better use sasocklen"
This reverts commit 3d4fb698660381e650d7caeb5b7cff12847c0fb8.

This was wrong... The problem was in the caller, sa_len is a macro on irix

metze
2010-08-28 08:28:01 +02:00
Stefan Metzmacher
44b2a7941c lib/tsocket: sa_socklen is a macro on irix, so better use sasocklen
metze
2010-08-27 13:00:26 +02:00
Volker Lendecke
4b64555d75 tsocket: Fix some type-punned warnings 2010-06-21 15:03:59 +02:00
Stefan Metzmacher
2436ec2928 lib/tsocket: add tsocket_address_is_unix() function
metze
2010-04-27 13:00:24 +02:00
Stefan Metzmacher
e1596bbf27 lib/tsocket: add tsocket_address_is_inet() function
metze
2010-04-27 13:00:24 +02:00
Stefan Metzmacher
b29f3f497b Revert "tsocket: not all systems have IPV6_V6ONLY"
This reverts commit 63fc397808.

We now don't support IPv6 when IPV6_V6ONLY isn't available,
as we rely on the behavior.

metze
2010-04-24 20:30:25 +02:00
Andrew Bartlett
f1aa4c34bf tsocket_bsd: Always use a real length for the sa_socklen, and keep it around
The previous code assumed the OS would happily accept sizeof(struct
sockaddr_storage).  It seems some versions of Solaris do not like
this.

Andrew Bartlett
2010-04-08 08:34:40 +02:00
Andrew Tridgell
63fc397808 tsocket: not all systems have IPV6_V6ONLY 2010-03-26 16:50:48 +11:00
Stefan Metzmacher
c42d9c4ec4 tsocket/bsd: fix comment in tdgram_bsd_recvfrom_handler()
metze
2010-02-18 09:38:00 +01:00
Jeremy Allison
936828de71 Fix commit d07cd37b99
Which was:

    tsocket/bsd: fix bug #7115 FreeBSD includes the UDP header in FIONREAD

Metze, this has to have been wrong - you are throwing away the talloc_realloc
pointer returned. Also no error checking. Please review.

Thank goodness for gcc warnings :-).

Jeremy.
2010-02-17 09:24:34 -08:00
Stefan Metzmacher
d07cd37b99 tsocket/bsd: fix bug #7115 FreeBSD includes the UDP header in FIONREAD
metze
2010-02-17 14:46:39 +01:00
Stefan Metzmacher
1ffcb991a9 tsocket/bsd: set IPV6_V6ONLY on AF_INET6 sockets
Some system already have this as default. It's easier
to behave the same way on all systems and handle ipv6
and ipv4 sockets separate.

metze
2010-02-17 14:46:39 +01:00
Stefan Metzmacher
8a0949dfc8 tsocket/bsd: fix bug #7140 autodetect ipv4 and ipv6 based on the remote address if the local address is any
metze
2010-02-17 14:46:08 +01:00
Stefan Metzmacher
6637b2f4b0 tsocket/bsd: fix bug #7140 use calculated sa_socklen for bind() in tstream_bsd_connect_send()
This is needed because, we can't use sizeof(sockaddr_storage) for AF_UNIX
sockets. Also some platforms require exact values for AF_INET and AF_INET6.

metze
2010-02-17 14:45:34 +01:00
Stefan Metzmacher
135543b4c3 tsocket/bsd: fix do_bind logic for AF_INET
We want the explicit bind() when we don't use the any address.

metze
2010-02-17 14:13:57 +01:00
Stefan Metzmacher
17c804a675 tsocket: only copy the specific part of sockaddr*
This makes sure we fill the unspefic bytes with 0
and have zero termination for sockaddr_un.

metze
2009-12-24 17:38:29 +01:00
Stefan Metzmacher
4784c8c3be tsocket: allow AF_UNIX sockaddrs smaller than sizeof(sockaddr_un)
This is needed as getpeername() truncates the length to 2 if the
peer socket has no name.

metze
2009-12-24 17:38:04 +01:00
Andreas Schneider
ab04dd3be7 tsocket: Fixed typo in LGPL header. 2009-12-15 23:34:22 +01:00
Stefan Metzmacher
edbf2caa6f tsocket: add tsocket_address_bsd_sockaddr() and tsocket_address_bsd_from_sockaddr()
metze
2009-12-15 23:34:22 +01:00
Stefan Metzmacher
eb39f66940 tsocket_bsd: return -1 and set errno to ENAMETOOLONG if the unix path is too long
metze
2009-11-03 18:24:44 +01:00
Stefan Metzmacher
1f12dc4409 tsocket: rename sa_len => sa_socklen, because sa_len is a macro on some platforms
metze
2009-07-16 08:21:08 +02:00
Stefan Metzmacher
857ed9ca5a tsocket/bsd: also ask for TEVENT_FD_READ when we want to write into a stream socket
Otherwise we would not notice a broken connection.

metze
2009-06-29 16:03:57 +02:00
Stefan Metzmacher
b1d5e515b2 tsocket/bsd: more correctly check if the cached tevent_fd is still valid
I some cases the pointer value of tevent_context is the same again,
if we do something like:

	ev1 = tevent_context_init();
	...
	fde = tevent_add_fd(ev1, fd, TEVENT_FD_READ...);
	...
	talloc_free(ev1);
	...
	ev2 = tevent_context_init();

	if (ev1 == ev2) {
		/* this can happen! */
	}

	if (tevent_fd_get_flags(fde) == 0) {
		/* this is always true */
	}

But the "talloc_free(ev1)" will set fde->event_ctx to NULL
and tevent_fd_get_flags() will always return 0.

metze
2009-06-29 16:03:57 +02:00
Stefan Metzmacher
edd9bd9b16 tsocket: allow empty vectors at the end for tstream_writev()/readv()
metze
2009-05-22 14:01:22 +02:00
Volker Lendecke
ac65ae9b1d Set errno=ENOMEM if tevent_add_fd fails
tevent_add_fd does not properly set that. At least in epoll and select this is
the only error condition.

Metze, please check!
2009-05-19 23:51:22 +02:00
Volker Lendecke
f9d00fb58e Simplify the logic of tsocket_bsd_pending
Remove two indentation levels by returning early on error.

Metze, please check!
2009-05-19 23:35:16 +02:00
Stefan Metzmacher
ee6d796c19 tsocket: add tstream implementation for bsd sockets (inet and unix)
metze
2009-05-01 17:41:55 +02:00
Stefan Metzmacher
182a4b30de tsocket: rename tdgram_unix_dgram_socket() => tdgram_unix_socket()
metze
2009-05-01 17:41:38 +02:00