From ef2e26c91b80556af033d3335e55f5dfa6fff31d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Aug 2003 01:53:07 +0000 Subject: first public release of samba4 code (This used to be commit b0510b5428b3461aeb9bbe3cc95f62fc73e2b97f) --- source4/libcli/raw/clisocket.c | 148 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 source4/libcli/raw/clisocket.c (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c new file mode 100644 index 0000000000..f0e05085c4 --- /dev/null +++ b/source4/libcli/raw/clisocket.c @@ -0,0 +1,148 @@ +/* + Unix SMB/CIFS implementation. + SMB client socket context management functions + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) James Myers 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +/* + create a cli_socket context +*/ +struct cli_socket *cli_sock_init(void) +{ + struct cli_socket *sock; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("cli_socket"); + if (!mem_ctx) return NULL; + + sock = talloc_zero(mem_ctx, sizeof(*sock)); + if (!sock) { + talloc_destroy(mem_ctx); + return NULL; + } + + sock->mem_ctx = mem_ctx; + sock->fd = -1; + sock->port = 445; + /* 20 second default timeout */ + sock->timeout = 20000; + + return sock; +} + +/* + connect a cli_socket context to an IP/port pair + if port is 0 then choose 445 then 139 +*/ +BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) +{ + if (getenv("LIBSMB_PROG")) { + sock->fd = sock_exec(getenv("LIBSMB_PROG")); + return sock->fd != -1; + } + + if (port == 0) { + return cli_sock_connect(sock, ip, 445) || + cli_sock_connect(sock, ip, 139); + } + + sock->dest_ip = *ip; + sock->port = port; + sock->fd = open_socket_out(SOCK_STREAM, + &sock->dest_ip, + sock->port, + LONG_CONNECT_TIMEOUT); + return (sock->fd != -1); +} + + +/**************************************************************************** + reduce socket reference count - if it becomes zero then close +****************************************************************************/ +void cli_sock_close(struct cli_socket *sock) +{ + sock->reference_count--; + if (sock->reference_count <= 0 && sock->fd != -1) { + close(sock->fd); + sock->fd = -1; + } +} + +/**************************************************************************** + Set socket options on a open connection. +****************************************************************************/ +void cli_sock_set_options(struct cli_socket *sock, const char *options) +{ + set_socket_options(sock->fd, options); +} + +/**************************************************************************** + Write to socket. Return amount written. +****************************************************************************/ +ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) +{ + return write_data(sock->fd, data, len); +} + + +/**************************************************************************** + Read from socket. return amount read +****************************************************************************/ +ssize_t cli_sock_read(struct cli_socket *sock, char *data, size_t len) +{ + return read_data(sock->fd, data, len); +} + +/**************************************************************************** +resolve a hostname and connect +****************************************************************************/ +BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port) +{ + int name_type = 0x20; + struct in_addr ip; + TALLOC_CTX *mem_ctx; + char *name, *p; + + if (getenv("LIBSMB_PROG")) { + sock->fd = sock_exec(getenv("LIBSMB_PROG")); + return sock->fd != -1; + } + + mem_ctx = talloc_init("cli_sock_connect_byname"); + if (!mem_ctx) return False; + + name = talloc_strdup(mem_ctx, host); + + /* allow hostnames of the form NAME#xx and do a netbios lookup */ + if ((p = strchr(name, '#'))) { + name_type = strtol(p+1, NULL, 16); + *p = 0; + } + + if (!resolve_name(mem_ctx, name, &ip, name_type)) { + talloc_destroy(mem_ctx); + return False; + } + + talloc_destroy(mem_ctx); + + return cli_sock_connect(sock, &ip, port); +} -- cgit From e1e98ab0496ae38b2d68d50133ec1da532f02757 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 19 Nov 2003 23:17:55 +0000 Subject: updated copyright year (This used to be commit 4dcc06d04c67c6e063c5b2a88f693423c77f342d) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index f0e05085c4..6ccdeef366 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. SMB client socket context management functions - Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Andrew Tridgell 1994-2003 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify -- cgit From 3e0501082cc5e5715dd315f890560a5759331df3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 26 Nov 2003 21:57:29 +0000 Subject: fixed default port handling pointed out by Tom Jansen (This used to be commit 8246e6ca0bd0eaa92de602db46a119d368e93391) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 6ccdeef366..f596cba854 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -41,7 +41,7 @@ struct cli_socket *cli_sock_init(void) sock->mem_ctx = mem_ctx; sock->fd = -1; - sock->port = 445; + sock->port = 0; /* 20 second default timeout */ sock->timeout = 20000; -- cgit From 493a37ba663686b7bee3f7093d6650a24250f101 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Apr 2004 04:21:22 +0000 Subject: r335: added much better handling of servers that die unexpectedly during a request (a dead socket). I discovered this when testing against Sun's PC-NetLink. cleaned up the naming of some of the samr requests add IDL and test code for samr_QueryGroupMember(), samr_SetMemberAttributesOfGroup() and samr_Shutdown(). (actually, I didn't leave the samr_Shutdown() test in, as its fatal to windows servers due to doing exactly what it says it does). (This used to be commit 925bc2622c105dee4ffff809c6c35cd209a839f8) --- source4/libcli/raw/clisocket.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index f596cba854..4dae7d517d 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -74,15 +74,25 @@ BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) } +/**************************************************************************** + mark the socket as dead +****************************************************************************/ +void cli_sock_dead(struct cli_socket *sock) +{ + if (sock->fd != -1) { + close(sock->fd); + sock->fd = -1; + } +} + /**************************************************************************** reduce socket reference count - if it becomes zero then close ****************************************************************************/ void cli_sock_close(struct cli_socket *sock) { sock->reference_count--; - if (sock->reference_count <= 0 && sock->fd != -1) { - close(sock->fd); - sock->fd = -1; + if (sock->reference_count <= 0) { + cli_sock_dead(sock); } } @@ -99,6 +109,11 @@ void cli_sock_set_options(struct cli_socket *sock, const char *options) ****************************************************************************/ ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) { + if (sock->fd == -1) { + errno = EIO; + return -1; + } + return write_data(sock->fd, data, len); } @@ -108,6 +123,11 @@ ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) ****************************************************************************/ ssize_t cli_sock_read(struct cli_socket *sock, char *data, size_t len) { + if (sock->fd == -1) { + errno = EIO; + return -1; + } + return read_data(sock->fd, data, len); } -- cgit From ed03516c915c4a4c8ae6f7decfa04d51049d9dd5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 13 Jul 2004 05:14:59 +0000 Subject: r1475: More kerberos work - We can now connect to hosts that follow the SPNEGO RFC, and *do not* give us their principal name in the mechListMIC. - The client code now remembers the hostname it connects to - We now kinit for a user, if there is not valid ticket already - Re-introduce clock skew compensation TODO: - See if the username in the ccache matches the username specified - Use a private ccache, rather then the global one, for a 'new' kinit - Determine 'default' usernames. - The default for Krb5 is the one in the ccache, then $USER - For NTLMSSP, it's just $USER Andrew Bartlett (This used to be commit de5da669397db4ac87c6da08d3533ca3030da2b0) --- source4/libcli/raw/clisocket.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 4dae7d517d..5cd6f33689 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -45,6 +45,8 @@ struct cli_socket *cli_sock_init(void) /* 20 second default timeout */ sock->timeout = 20000; + sock->hostname = NULL; + return sock; } @@ -140,6 +142,7 @@ BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port struct in_addr ip; TALLOC_CTX *mem_ctx; char *name, *p; + BOOL ret; if (getenv("LIBSMB_PROG")) { sock->fd = sock_exec(getenv("LIBSMB_PROG")); @@ -162,7 +165,13 @@ BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port return False; } + ret = cli_sock_connect(sock, &ip, port); + + if (ret) { + sock->hostname = talloc_steal(mem_ctx, sock->mem_ctx, name); + } + talloc_destroy(mem_ctx); - return cli_sock_connect(sock, &ip, port); + return ret; } -- cgit From 5ddf678e0113f81aa2b5f99134cda4fe8c01afb7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Jul 2004 06:40:49 +0000 Subject: r1578: the first stage of the async client rewrite. Up to now the client code has had an async API, and operated asynchronously at the packet level, but was not truly async in that it assumed that it could always write to the socket and when a partial packet came in that it could block waiting for the rest of the packet. This change makes the SMB client library full async, by adding a separate outgoing packet queue, using non-blocking socket IO and having a input buffer that can fill asynchonously until the full packet has arrived. The main complexity was in dealing with the events structure when using the CIFS proxy backend. In that case the same events structure needs to be used in both the client library and the main smbd server, so that when the client library is waiting for a reply that the main server keeps processing packets. This required some changes in the events library code. Next step is to make the generated rpc client code use these new capabilities. (This used to be commit 96bf4da3edc4d64b0f58ef520269f3b385b8da02) --- source4/libcli/raw/clisocket.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 5cd6f33689..eb5d3c0342 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -72,7 +72,13 @@ BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) &sock->dest_ip, sock->port, LONG_CONNECT_TIMEOUT); - return (sock->fd != -1); + if (sock->fd == -1) { + return False; + } + + set_blocking(sock->fd, False); + + return True; } -- cgit From c5fbb6f23c2d399c7510bc552cdb1a27b1ef66a8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 4 Aug 2004 13:23:35 +0000 Subject: r1654: rename cli_ -> smbcli_ rename CLI_ -> SMBCLI_ metze (This used to be commit 8441750fd9427dd6fe477f27e603821b4026f038) --- source4/libcli/raw/clisocket.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index eb5d3c0342..78d37b9be1 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -23,14 +23,14 @@ /* - create a cli_socket context + create a smbcli_socket context */ -struct cli_socket *cli_sock_init(void) +struct smbcli_socket *smbcli_sock_init(void) { - struct cli_socket *sock; + struct smbcli_socket *sock; TALLOC_CTX *mem_ctx; - mem_ctx = talloc_init("cli_socket"); + mem_ctx = talloc_init("smbcli_socket"); if (!mem_ctx) return NULL; sock = talloc_zero(mem_ctx, sizeof(*sock)); @@ -51,10 +51,10 @@ struct cli_socket *cli_sock_init(void) } /* - connect a cli_socket context to an IP/port pair + connect a smbcli_socket context to an IP/port pair if port is 0 then choose 445 then 139 */ -BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) +BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int port) { if (getenv("LIBSMB_PROG")) { sock->fd = sock_exec(getenv("LIBSMB_PROG")); @@ -62,8 +62,8 @@ BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) } if (port == 0) { - return cli_sock_connect(sock, ip, 445) || - cli_sock_connect(sock, ip, 139); + return smbcli_sock_connect(sock, ip, 445) || + smbcli_sock_connect(sock, ip, 139); } sock->dest_ip = *ip; @@ -85,7 +85,7 @@ BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) /**************************************************************************** mark the socket as dead ****************************************************************************/ -void cli_sock_dead(struct cli_socket *sock) +void smbcli_sock_dead(struct smbcli_socket *sock) { if (sock->fd != -1) { close(sock->fd); @@ -96,18 +96,18 @@ void cli_sock_dead(struct cli_socket *sock) /**************************************************************************** reduce socket reference count - if it becomes zero then close ****************************************************************************/ -void cli_sock_close(struct cli_socket *sock) +void smbcli_sock_close(struct smbcli_socket *sock) { sock->reference_count--; if (sock->reference_count <= 0) { - cli_sock_dead(sock); + smbcli_sock_dead(sock); } } /**************************************************************************** Set socket options on a open connection. ****************************************************************************/ -void cli_sock_set_options(struct cli_socket *sock, const char *options) +void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) { set_socket_options(sock->fd, options); } @@ -115,7 +115,7 @@ void cli_sock_set_options(struct cli_socket *sock, const char *options) /**************************************************************************** Write to socket. Return amount written. ****************************************************************************/ -ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) +ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t len) { if (sock->fd == -1) { errno = EIO; @@ -129,7 +129,7 @@ ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) /**************************************************************************** Read from socket. return amount read ****************************************************************************/ -ssize_t cli_sock_read(struct cli_socket *sock, char *data, size_t len) +ssize_t smbcli_sock_read(struct smbcli_socket *sock, char *data, size_t len) { if (sock->fd == -1) { errno = EIO; @@ -142,7 +142,7 @@ ssize_t cli_sock_read(struct cli_socket *sock, char *data, size_t len) /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port) +BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) { int name_type = 0x20; struct in_addr ip; @@ -155,7 +155,7 @@ BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port return sock->fd != -1; } - mem_ctx = talloc_init("cli_sock_connect_byname"); + mem_ctx = talloc_init("smbcli_sock_connect_byname"); if (!mem_ctx) return False; name = talloc_strdup(mem_ctx, host); @@ -171,7 +171,7 @@ BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port return False; } - ret = cli_sock_connect(sock, &ip, port); + ret = smbcli_sock_connect(sock, &ip, port); if (ret) { sock->hostname = talloc_steal(mem_ctx, sock->mem_ctx, name); -- cgit From 64082214337e2ab50f0a69ca7f9bcf56762129cc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Aug 2004 05:56:12 +0000 Subject: r1819: changed "smb ports" to be a LIST parameter type in loadparm (its a classic case for a list) (This used to be commit e53d32c65ab0751b3e01f4f699f5d0e1892369ae) --- source4/libcli/raw/clisocket.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 78d37b9be1..b09bebf133 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -62,8 +62,15 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por } if (port == 0) { - return smbcli_sock_connect(sock, ip, 445) || - smbcli_sock_connect(sock, ip, 139); + int i; + const char **ports = lp_smb_ports(); + for (i=0;ports[i];i++) { + int port = atoi(ports[i]); + if (port != 0 && smbcli_sock_connect(sock, ip, port)) { + return True; + } + } + return False; } sock->dest_ip = *ip; -- cgit From f42f0612364045702cea7e66cacd24aa20ecb54e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Aug 2004 11:37:36 +0000 Subject: r1910: this should not be a local var in this block metze (This used to be commit 0164cac6df46ca5996aae30b8c48a602999f7e0b) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index b09bebf133..343904999a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -65,7 +65,7 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por int i; const char **ports = lp_smb_ports(); for (i=0;ports[i];i++) { - int port = atoi(ports[i]); + port = atoi(ports[i]); if (port != 0 && smbcli_sock_connect(sock, ip, port)) { return True; } -- cgit From b83ba93eaeb2dcb0bf11615591d886fda84e4162 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Aug 2004 01:54:46 +0000 Subject: r1983: a completely new implementation of talloc This version does the following: 1) talloc_free(), talloc_realloc() and talloc_steal() lose their (redundent) first arguments 2) you can use _any_ talloc pointer as a talloc context to allocate more memory. This allows you to create complex data structures where the top level structure is the logical parent of the next level down, and those are the parents of the level below that. Then destroy either the lot with a single talloc_free() or destroy any sub-part with a talloc_free() of that part 3) you can name any pointer. Use talloc_named() which is just like talloc() but takes the printf style name argument as well as the parent context and the size. The whole thing ends up being a very simple piece of code, although some of the pointer walking gets hairy. So far, I'm just using the new talloc() like the old one. The next step is to actually take advantage of the new interface properly. Expect some new commits soon that simplify some common coding styles in samba4 by using the new talloc(). (This used to be commit e35bb094c52e550b3105dd1638d8d90de71d854f) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 343904999a..2bb50d200f 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -181,7 +181,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in ret = smbcli_sock_connect(sock, &ip, port); if (ret) { - sock->hostname = talloc_steal(mem_ctx, sock->mem_ctx, name); + sock->hostname = talloc_steal(sock->mem_ctx, name); } talloc_destroy(mem_ctx); -- cgit From b7e1ea20dc873a753ff64653987130f03897a4e9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Aug 2004 07:43:29 +0000 Subject: r1985: take advantage of the new talloc in a few more places (This used to be commit 6ffdfd779936ce8c5ca49c5f444e8da2bbeee0a8) --- source4/libcli/raw/clisocket.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 2bb50d200f..94bb447f47 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -28,18 +28,13 @@ struct smbcli_socket *smbcli_sock_init(void) { struct smbcli_socket *sock; - TALLOC_CTX *mem_ctx; - mem_ctx = talloc_init("smbcli_socket"); - if (!mem_ctx) return NULL; - - sock = talloc_zero(mem_ctx, sizeof(*sock)); + sock = talloc_named(NULL, sizeof(*sock), "smbcli_socket"); if (!sock) { - talloc_destroy(mem_ctx); return NULL; } - sock->mem_ctx = mem_ctx; + ZERO_STRUCTP(sock); sock->fd = -1; sock->port = 0; /* 20 second default timeout */ @@ -153,7 +148,6 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in { int name_type = 0x20; struct in_addr ip; - TALLOC_CTX *mem_ctx; char *name, *p; BOOL ret; @@ -162,10 +156,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in return sock->fd != -1; } - mem_ctx = talloc_init("smbcli_sock_connect_byname"); - if (!mem_ctx) return False; - - name = talloc_strdup(mem_ctx, host); + name = talloc_strdup(sock, host); /* allow hostnames of the form NAME#xx and do a netbios lookup */ if ((p = strchr(name, '#'))) { @@ -173,18 +164,18 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in *p = 0; } - if (!resolve_name(mem_ctx, name, &ip, name_type)) { - talloc_destroy(mem_ctx); + if (!resolve_name(name, name, &ip, name_type)) { + talloc_free(name); return False; } ret = smbcli_sock_connect(sock, &ip, port); if (ret) { - sock->hostname = talloc_steal(sock->mem_ctx, name); + sock->hostname = talloc_steal(sock, name); } - talloc_destroy(mem_ctx); + talloc_destroy(name); return ret; } -- cgit From b13a9a8f98469fffe0db4cce7e077390d35984a3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 25 Aug 2004 02:07:53 +0000 Subject: r2040: fixed a memory handling error in clisocket (caught with valgrind) (This used to be commit f6dc62bf119c294db060b0870b6ca80bc28bd4a5) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 94bb447f47..1004db4040 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -173,9 +173,9 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in if (ret) { sock->hostname = talloc_steal(sock, name); + } else { + talloc_free(name); } - talloc_destroy(name); - return ret; } -- cgit From b990e9a97b02cec9f012bacc6bb266a0403f6792 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Sep 2004 12:02:28 +0000 Subject: r2184: use the smb.conf socket options for client code too (This used to be commit 7256945b526a1ee68d18eb579e592f7389740c22) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 1004db4040..9aea8624d0 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -79,6 +79,7 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por } set_blocking(sock->fd, False); + set_socket_options(sock->fd, lp_socket_options()); return True; } -- cgit From 30381686c4874e4f9602a977a31399e49350e597 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 25 Sep 2004 11:15:18 +0000 Subject: r2621: - now that the client code is non-blocking, we no longer need write_data and read_data, which are inherently blocking operations - got rid of some old NBT keepalive routines that are not needed (This used to be commit e73b4ae4e500d3b7ee57e160e0f8b63c99b2542a) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9aea8624d0..654d8ee61b 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -125,7 +125,7 @@ ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t l return -1; } - return write_data(sock->fd, data, len); + return write(sock->fd, data, len); } @@ -139,7 +139,7 @@ ssize_t smbcli_sock_read(struct smbcli_socket *sock, char *data, size_t len) return -1; } - return read_data(sock->fd, data, len); + return read(sock->fd, data, len); } /**************************************************************************** -- cgit From 3ea916b2278c202c99c80c02e80e588bd7daedb8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 06:44:08 +0000 Subject: r2654: fixed some more server memory leaks. We are now down to a single leak of 16 bytes, caused by the 16 byte data_blob in the smb_signing code. (This used to be commit 2f1b788e09686e065d22f621f5c0c585192c6740) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 654d8ee61b..5663672333 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -29,7 +29,7 @@ struct smbcli_socket *smbcli_sock_init(void) { struct smbcli_socket *sock; - sock = talloc_named(NULL, sizeof(*sock), "smbcli_socket"); + sock = talloc_p(NULL, struct smbcli_socket); if (!sock) { return NULL; } -- cgit From 954869efdb8b0006fd4457a1c6d56a31c3825421 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 07:04:35 +0000 Subject: r2655: fixed an error in the shutdown of the sock->transport->session->tree smbcli raw context handling (This used to be commit d5fd6388751944f11c34e5124d403d57c8670e3b) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 5663672333..8481bc73e2 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -104,6 +104,7 @@ void smbcli_sock_close(struct smbcli_socket *sock) sock->reference_count--; if (sock->reference_count <= 0) { smbcli_sock_dead(sock); + talloc_free(sock); } } -- cgit From e3880fa759cfa03222262327854fe7bbe585fe01 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 11:30:20 +0000 Subject: r2660: - converted the libcli/raw/ library to use talloc_increase_ref_count() rather than manual reference counts - properly support SMBexit in the cifs and posix backends - added a logoff method to all backends With these changes the RAW-CONTEXT test now passes against the posix backend (This used to be commit c315d6ac1cc40546fde1474702a6d66d07ee13c8) --- source4/libcli/raw/clisocket.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 8481bc73e2..37188f4e77 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -21,6 +21,18 @@ #include "includes.h" +/* + destroy a socket + */ +static int sock_destructor(void *ptr) +{ + struct smbcli_socket *sock = ptr; + if (sock->fd != -1) { + close(sock->fd); + sock->fd = -1; + } + return 0; +} /* create a smbcli_socket context @@ -37,11 +49,13 @@ struct smbcli_socket *smbcli_sock_init(void) ZERO_STRUCTP(sock); sock->fd = -1; sock->port = 0; + /* 20 second default timeout */ sock->timeout = 20000; - sock->hostname = NULL; + talloc_set_destructor(sock, sock_destructor); + return sock; } @@ -96,18 +110,6 @@ void smbcli_sock_dead(struct smbcli_socket *sock) } } -/**************************************************************************** - reduce socket reference count - if it becomes zero then close -****************************************************************************/ -void smbcli_sock_close(struct smbcli_socket *sock) -{ - sock->reference_count--; - if (sock->reference_count <= 0) { - smbcli_sock_dead(sock); - talloc_free(sock); - } -} - /**************************************************************************** Set socket options on a open connection. ****************************************************************************/ -- cgit From b2f1a29e4348a5bc34a87d72d526e23e421ed9d5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 28 Sep 2004 05:44:59 +0000 Subject: r2710: continue with the new style of providing a parent context whenever possible to a structure creation routine. This makes for much easier global cleanup. (This used to be commit e14ee428ec357fab76a960387a9820a673786e27) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 37188f4e77..14862a39f0 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -37,11 +37,11 @@ static int sock_destructor(void *ptr) /* create a smbcli_socket context */ -struct smbcli_socket *smbcli_sock_init(void) +struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) { struct smbcli_socket *sock; - sock = talloc_p(NULL, struct smbcli_socket); + sock = talloc_p(mem_ctx, struct smbcli_socket); if (!sock) { return NULL; } -- cgit From c272e60955bff28ff6431fd50e94807aca1ea016 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 28 Oct 2004 08:15:12 +0000 Subject: r3315: converted the libcli/raw/ code to use the generic socket library. This allows me to test with the socket:testnonblock option. It passes. (This used to be commit 7cb4bf8662825d507d8246647ffb10aa08bad794) --- source4/libcli/raw/clisocket.c | 83 +++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 37 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 14862a39f0..907206a5e8 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -21,19 +21,6 @@ #include "includes.h" -/* - destroy a socket - */ -static int sock_destructor(void *ptr) -{ - struct smbcli_socket *sock = ptr; - if (sock->fd != -1) { - close(sock->fd); - sock->fd = -1; - } - return 0; -} - /* create a smbcli_socket context */ @@ -47,15 +34,13 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) } ZERO_STRUCTP(sock); - sock->fd = -1; + sock->sock = NULL; sock->port = 0; /* 20 second default timeout */ sock->timeout = 20000; sock->hostname = NULL; - talloc_set_destructor(sock, sock_destructor); - return sock; } @@ -65,10 +50,7 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) */ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int port) { - if (getenv("LIBSMB_PROG")) { - sock->fd = sock_exec(getenv("LIBSMB_PROG")); - return sock->fd != -1; - } + NTSTATUS status; if (port == 0) { int i; @@ -82,18 +64,23 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por return False; } - sock->dest_ip = *ip; - sock->port = port; - sock->fd = open_socket_out(SOCK_STREAM, - &sock->dest_ip, - sock->port, - LONG_CONNECT_TIMEOUT); - if (sock->fd == -1) { + status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); + if (!NT_STATUS_IS_OK(status)) { return False; } + talloc_steal(sock, sock->sock); - set_blocking(sock->fd, False); - set_socket_options(sock->fd, lp_socket_options()); + status = socket_connect(sock->sock, NULL, 0, inet_ntoa(*ip), port, 0); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(sock->sock); + sock->sock = NULL; + return False; + } + + sock->dest_ip = *ip; + sock->port = port; + + socket_set_option(sock->sock, lp_socket_options(), NULL); return True; } @@ -104,9 +91,9 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por ****************************************************************************/ void smbcli_sock_dead(struct smbcli_socket *sock) { - if (sock->fd != -1) { - close(sock->fd); - sock->fd = -1; + if (sock->sock != NULL) { + talloc_free(sock->sock); + sock->sock = NULL; } } @@ -115,7 +102,7 @@ void smbcli_sock_dead(struct smbcli_socket *sock) ****************************************************************************/ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) { - set_socket_options(sock->fd, options); + socket_set_option(sock->sock, options, NULL); } /**************************************************************************** @@ -123,12 +110,24 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) ****************************************************************************/ ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t len) { - if (sock->fd == -1) { + NTSTATUS status; + DATA_BLOB blob; + size_t nsent; + + if (sock->sock == NULL) { errno = EIO; return -1; } - return write(sock->fd, data, len); + blob.data = discard_const(data); + blob.length = len; + + status = socket_send(sock->sock, &blob, &nsent, 0); + if (NT_STATUS_IS_ERR(status)) { + return -1; + } + + return nsent; } @@ -137,12 +136,20 @@ ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t l ****************************************************************************/ ssize_t smbcli_sock_read(struct smbcli_socket *sock, char *data, size_t len) { - if (sock->fd == -1) { + NTSTATUS status; + size_t nread; + + if (sock->sock == NULL) { errno = EIO; return -1; } - return read(sock->fd, data, len); + status = socket_recv(sock->sock, data, len, &nread, 0); + if (NT_STATUS_IS_ERR(status)) { + return -1; + } + + return nread; } /**************************************************************************** @@ -155,10 +162,12 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in char *name, *p; BOOL ret; +#if 0 if (getenv("LIBSMB_PROG")) { sock->fd = sock_exec(getenv("LIBSMB_PROG")); return sock->fd != -1; } +#endif name = talloc_strdup(sock, host); -- cgit From 9f1210a243654fd6d94acdef83f468a33c1b3b3f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 01:03:22 +0000 Subject: r3419: moved the libcli/raw structures into libcli/raw/libcliraw.h and made them private (This used to be commit 386ac565c452ede1d74e06acb401ca9db99d3ff3) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 907206a5e8..c641f8bf12 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /* create a smbcli_socket context -- cgit From 284349482f5293a9a23d0f72d7c2aab46b55843b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 22:48:25 +0000 Subject: r3443: the next stage in the include files re-organisation. I have created the include/system/ directory, which will contain the wrappers for the system includes for logical subsystems. So far I have created include/system/kerberos.h and include/system/network.h, which contain all the system includes for kerberos code and networking code. These are the included in subsystems that need kerberos or networking respectively. Note that this method avoids the mess of #ifdef HAVE_XXX_H in every C file, instead each C module includes the include/system/XXX.h file for the logical system support it needs, and the details are kept isolated in include/system/ This patch also creates a "struct ipv4_addr" which replaces "struct in_addr" in our code. That avoids every C file needing to import all the system networking headers. (This used to be commit 2e25c71853f8996f73755277e448e7d670810349) --- source4/libcli/raw/clisocket.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index c641f8bf12..349b4b9a9c 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -49,7 +49,7 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) connect a smbcli_socket context to an IP/port pair if port is 0 then choose 445 then 139 */ -BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int port) +BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) { NTSTATUS status; @@ -71,7 +71,7 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por } talloc_steal(sock, sock->sock); - status = socket_connect(sock->sock, NULL, 0, inet_ntoa(*ip), port, 0); + status = socket_connect(sock->sock, NULL, 0, sys_inet_ntoa(*ip), port, 0); if (!NT_STATUS_IS_OK(status)) { talloc_free(sock->sock); sock->sock = NULL; @@ -159,7 +159,7 @@ resolve a hostname and connect BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) { int name_type = 0x20; - struct in_addr ip; + struct ipv4_addr ip; char *name, *p; BOOL ret; -- cgit From 9112a632f6791ffc3c3c1aadd214cbaba8fe816e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 4 Dec 2004 13:56:25 +0000 Subject: r4063: - change char * -> uint8_t in struct request_buffer - change smbcli_read/write to take void * for the buffers to match read(2)/write(2) all this fixes a lot of gcc-4 warnings metze (This used to be commit b94f92bc6637f748d6f7049f4f9a30b0b8d18a7a) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 349b4b9a9c..fb9afeab81 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -109,7 +109,7 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** Write to socket. Return amount written. ****************************************************************************/ -ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t len) +ssize_t smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, size_t len) { NTSTATUS status; DATA_BLOB blob; @@ -135,7 +135,7 @@ ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t l /**************************************************************************** Read from socket. return amount read ****************************************************************************/ -ssize_t smbcli_sock_read(struct smbcli_socket *sock, char *data, size_t len) +ssize_t smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, size_t len) { NTSTATUS status; size_t nread; -- cgit From e89fd49df7e63dcf37ee1aa7e2f50965851725c9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Jan 2005 10:38:12 +0000 Subject: r4757: added the ability of the clisocket level of libcli to handle async socket connections. This was complicated by a few factors: - it meant moving the event context from clitransport to clisocket, so lots of structures changed - we need to asynchronously handle connection to lists of port numbers, not just one port number. The code internally tries each port in the list in turn, without ever blocking - the man page on how connect() is supposed to work asynchronously doesn't work in practice (now why doesn't this surprise me?). The getsockopt() for SOL_ERROR is supposed to retrieve the error, but in fact the next (unrelated) connect() call on the same socket also gets an error, though not the right error. To work around this I need to tear down the whole socket between each attempted port. I hate posix. Note that clisocket.c still does a blocking name resolution call in smbcli_sock_connect_byname(). That will be fixed when we add the async NBT resolution code. Also note that I arranged things so that every SMB connection is now async internally, so using plain smbclient or smbtorture tests all the async features of this new code. (This used to be commit 468f8ebbfdbdf37c757fdc4863626aa9946a8870) --- source4/libcli/raw/clisocket.c | 244 +++++++++++++++++++++++++++++++++-------- 1 file changed, 197 insertions(+), 47 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index fb9afeab81..d20dc4bf25 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -1,7 +1,8 @@ /* Unix SMB/CIFS implementation. SMB client socket context management functions - Copyright (C) Andrew Tridgell 1994-2003 + + Copyright (C) Andrew Tridgell 1994-2005 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify @@ -20,7 +21,18 @@ */ #include "includes.h" +#include "events.h" #include "libcli/raw/libcliraw.h" +#include "libcli/composite/composite.h" + +/* + this private structure is used during async connection handling +*/ +struct clisocket_connect { + int *iports; + struct smbcli_socket *sock; + const char *dest_host; +}; /* create a smbcli_socket context @@ -29,61 +41,210 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) { struct smbcli_socket *sock; - sock = talloc_p(mem_ctx, struct smbcli_socket); + sock = talloc_zero(mem_ctx, struct smbcli_socket); if (!sock) { return NULL; } - ZERO_STRUCTP(sock); - sock->sock = NULL; - sock->port = 0; - - /* 20 second default timeout */ - sock->timeout = 20000; - sock->hostname = NULL; + sock->event.ctx = event_context_init(sock); + if (sock->event.ctx == NULL) { + talloc_free(sock); + return NULL; + } return sock; } +static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, + const char *hostaddr, int port); + /* - connect a smbcli_socket context to an IP/port pair - if port is 0 then choose 445 then 139 + handle socket write events during an async connect. These happen when the OS + has either completed the connect() or has returned an error */ -BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) +static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, + struct timeval t, uint16_t flags) { - NTSTATUS status; + struct smbcli_composite *c = fde->private; + struct clisocket_connect *conn = c->private; + int i; + + c->status = socket_connect_complete(conn->sock->sock, 0); + if (NT_STATUS_IS_OK(c->status)) { + socket_set_option(conn->sock->sock, lp_socket_options(), NULL); + c->state = SMBCLI_REQUEST_DONE; + if (c->async.fn) { + c->async.fn(c); + } + return; + } - if (port == 0) { - int i; - const char **ports = lp_smb_ports(); - for (i=0;ports[i];i++) { - port = atoi(ports[i]); - if (port != 0 && smbcli_sock_connect(sock, ip, port)) { - return True; + /* that port failed - try the next port */ + for (i=c->stage+1;conn->iports[i];i++) { + c->stage = i; + c->status = smbcli_sock_connect_one(conn->sock, + conn->dest_host, + conn->iports[i]); + if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + conn->sock->event.fde->private = c; + return; + } + if (NT_STATUS_IS_OK(c->status)) { + c->state = SMBCLI_REQUEST_DONE; + if (c->async.fn) { + c->async.fn(c); } + return; } - return False; } - status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); - if (!NT_STATUS_IS_OK(status)) { - return False; + c->state = SMBCLI_REQUEST_ERROR; + if (c->async.fn) { + c->async.fn(c); } - talloc_steal(sock, sock->sock); +} - status = socket_connect(sock->sock, NULL, 0, sys_inet_ntoa(*ip), port, 0); - if (!NT_STATUS_IS_OK(status)) { + +/* + try to connect to the given address/port +*/ +static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, + const char *hostaddr, int port) +{ + struct fd_event fde; + NTSTATUS status; + + if (sock->sock) { talloc_free(sock->sock); sock->sock = NULL; - return False; } - sock->dest_ip = *ip; + if (sock->event.fde) { + event_remove_fd(sock->event.ctx, sock->event.fde); + sock->event.fde = NULL; + } + + status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + talloc_steal(sock, sock->sock); + + /* we initially look for write - see the man page on + non-blocking connect */ + fde.fd = socket_get_fd(sock->sock); + fde.flags = EVENT_FD_WRITE; + fde.handler = smbcli_sock_connect_handler; + fde.private = sock; + + sock->event.fde = event_add_fd(sock->event.ctx, &fde); sock->port = port; + set_blocking(fde.fd, False); + + return socket_connect(sock->sock, NULL, 0, hostaddr, port, 0); +} + - socket_set_option(sock->sock, lp_socket_options(), NULL); +/* + connect a smbcli_socket context to an IP/port pair + if port is 0 then choose 445 then 139 + + this is the async send side of the interface +*/ +struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, + struct ipv4_addr *ip, int port) +{ + struct smbcli_composite *c; + struct clisocket_connect *conn; + int i; + + c = talloc_zero(sock, struct smbcli_composite); + if (c == NULL) return NULL; + + c->event_ctx = sock->event.ctx; + + conn = talloc(c, struct clisocket_connect); + if (conn == NULL) goto failed; + + conn->sock = sock; + + /* work out what ports we will try */ + if (port == 0) { + const char **ports = lp_smb_ports(); + for (i=0;ports[i];i++) /* noop */ ; + conn->iports = talloc_array(c, int, i+1); + if (conn->iports == NULL) goto failed; + for (i=0;ports[i];i++) { + conn->iports[i] = atoi(ports[i]); + } + conn->iports[i] = 0; + } else { + conn->iports = talloc_array(c, int, 2); + if (conn->iports == NULL) goto failed; + conn->iports[0] = port; + conn->iports[1] = 0; + } - return True; + conn->dest_host = talloc_strdup(c, sys_inet_ntoa(*ip)); + if (conn->dest_host == NULL) goto failed; + + c->private = conn; + c->state = SMBCLI_REQUEST_SEND; + + /* startup the connect process for each port in turn until one + succeeds or tells us that it is pending */ + for (i=0;conn->iports[i];i++) { + c->stage = i; + conn->sock->port = conn->iports[i]; + c->status = smbcli_sock_connect_one(sock, + conn->dest_host, + conn->iports[i]); + if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + sock->event.fde->private = c; + return c; + } + if (NT_STATUS_IS_OK(c->status)) { + c->state = SMBCLI_REQUEST_DONE; + return c; + } + } + + c->state = SMBCLI_REQUEST_ERROR; + return c; + +failed: + talloc_free(c); + return NULL; +} + +/* + finish a smbcli_sock_connect_send() operation +*/ +NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) +{ + NTSTATUS status; + status = smb_composite_wait(c); + talloc_free(c); + return status; +} + +/* + connect a smbcli_socket context to an IP/port pair + if port is 0 then choose the ports listed in smb.conf (normally 445 then 139) + + sync version of the function +*/ +NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) +{ + struct smbcli_composite *c; + + c = smbcli_sock_connect_send(sock, ip, port); + if (c == NULL) { + return NT_STATUS_NO_MEMORY; + } + + return smbcli_sock_connect_recv(c); } @@ -153,6 +314,7 @@ ssize_t smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, size_t len) return nread; } + /**************************************************************************** resolve a hostname and connect ****************************************************************************/ @@ -161,14 +323,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in int name_type = 0x20; struct ipv4_addr ip; char *name, *p; - BOOL ret; - -#if 0 - if (getenv("LIBSMB_PROG")) { - sock->fd = sock_exec(getenv("LIBSMB_PROG")); - return sock->fd != -1; - } -#endif + NTSTATUS status; name = talloc_strdup(sock, host); @@ -179,17 +334,12 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in } if (!resolve_name(name, name, &ip, name_type)) { - talloc_free(name); return False; } - ret = smbcli_sock_connect(sock, &ip, port); + sock->hostname = name; - if (ret) { - sock->hostname = talloc_steal(sock, name); - } else { - talloc_free(name); - } + status = smbcli_sock_connect(sock, &ip, port); - return ret; + return NT_STATUS_IS_OK(status); } -- cgit From 8ea26bf2fdad4440d65b020943e19128c34c4ed9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 01:21:18 +0000 Subject: r4765: simplify the async socket code to always go via the event handler rather than short-circuiting in the unlikely event the OS returns an immediate success on a non-blocking connect (This used to be commit db4380717041485e216f965103f9e803518b45c3) --- source4/libcli/raw/clisocket.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index d20dc4bf25..851cf67caa 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -85,17 +85,11 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even c->status = smbcli_sock_connect_one(conn->sock, conn->dest_host, conn->iports[i]); - if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + if (NT_STATUS_IS_OK(c->status) || + NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { conn->sock->event.fde->private = c; return; } - if (NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_DONE; - if (c->async.fn) { - c->async.fn(c); - } - return; - } } c->state = SMBCLI_REQUEST_ERROR; @@ -153,7 +147,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, this is the async send side of the interface */ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, - struct ipv4_addr *ip, int port) + const char *host_addr, int port) { struct smbcli_composite *c; struct clisocket_connect *conn; @@ -186,7 +180,7 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->iports[1] = 0; } - conn->dest_host = talloc_strdup(c, sys_inet_ntoa(*ip)); + conn->dest_host = talloc_strdup(c, host_addr); if (conn->dest_host == NULL) goto failed; c->private = conn; @@ -200,14 +194,11 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, c->status = smbcli_sock_connect_one(sock, conn->dest_host, conn->iports[i]); - if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + if (NT_STATUS_IS_OK(c->status) || + NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { sock->event.fde->private = c; return c; } - if (NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_DONE; - return c; - } } c->state = SMBCLI_REQUEST_ERROR; @@ -235,11 +226,11 @@ NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) sync version of the function */ -NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) +NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port) { struct smbcli_composite *c; - c = smbcli_sock_connect_send(sock, ip, port); + c = smbcli_sock_connect_send(sock, host_addr, port); if (c == NULL) { return NT_STATUS_NO_MEMORY; } @@ -339,7 +330,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in sock->hostname = name; - status = smbcli_sock_connect(sock, &ip, port); + status = smbcli_sock_connect(sock, sys_inet_ntoa(ip), port); return NT_STATUS_IS_OK(status); } -- cgit From 7cbc768376ed0a839afca64aeea99cd53d0fbc6f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 11:15:08 +0000 Subject: r4777: added a smb_composite_sesssetup() async composite function. This encapsulates all the different session setup methods, including the multi-pass spnego code. I have hooked this into all the places that previously used the RAW_SESSSETUP_GENERIC method, and have removed the old RAW_SESSSETUP_GENERIC code from clisession.c and clitree.c. A nice side effect is that these two modules are now very simple again, back to being "raw" session setup handling, which was what was originally intended. I have also used this to replace the session setup code in the smb_composite_connect() code, and used that to build a very simple replacement for smbcli_tree_full_connection(). As a result, smbclient, smbtorture and all our other SMB connection code now goes via these composite async functions. That should give them a good workout! (This used to be commit 080d0518bc7d6fd4bc3ef783e7d4d2e3275d0799) --- source4/libcli/raw/clisocket.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 851cf67caa..ad1c6a13b8 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -1,5 +1,6 @@ /* Unix SMB/CIFS implementation. + SMB client socket context management functions Copyright (C) Andrew Tridgell 1994-2005 @@ -72,6 +73,7 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even c->status = socket_connect_complete(conn->sock->sock, 0); if (NT_STATUS_IS_OK(c->status)) { socket_set_option(conn->sock->sock, lp_socket_options(), NULL); + conn->sock->hostname = talloc_strdup(conn->sock, conn->dest_host); c->state = SMBCLI_REQUEST_DONE; if (c->async.fn) { c->async.fn(c); -- cgit From 4a03172e66694b51a24f7b5566f361c1f1767e29 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 23:23:45 +0000 Subject: r4791: used the new talloc type safety macros to make the "void *private" pointers in the composite code type safe. This is a bit of an experiement, I'd be interested in comments on whether we should use this more widely. (This used to be commit 0e1da827b380998355f75f4ef4f424802059c278) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index ad1c6a13b8..66555695d3 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -66,8 +66,8 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, struct timeval t, uint16_t flags) { - struct smbcli_composite *c = fde->private; - struct clisocket_connect *conn = c->private; + struct smbcli_composite *c = talloc_get_type(fde->private, struct smbcli_composite); + struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); int i; c->status = socket_connect_complete(conn->sock->sock, 0); -- cgit From 196a5ec240c0386aff4f4442c9c44ac7cdd0a494 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Jan 2005 22:53:37 +0000 Subject: r4811: now that the event context is at the socket level, the event cleanup should be there too (This used to be commit 058ae5527e3daeb50eeea9e0ecee858c84e7e17d) --- source4/libcli/raw/clisocket.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 66555695d3..0edb95e1a1 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -35,6 +35,17 @@ struct clisocket_connect { const char *dest_host; }; + +static int smbcli_sock_destructor(void *ptr) +{ + struct smbcli_socket *sock = talloc_get_type(ptr, struct smbcli_socket); + + if (sock->event.fde && sock->event.ctx) { + event_remove_fd(sock->event.ctx, sock->event.fde); + } + return 0; +} + /* create a smbcli_socket context */ @@ -53,6 +64,8 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) return NULL; } + talloc_set_destructor(sock, smbcli_sock_destructor); + return sock; } -- cgit From 2383787f199c51cdc202a3cef5822a9fe6b8774c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Jan 2005 11:18:56 +0000 Subject: r4891: - added a generic resolve_name() async interface in libcli/resolve/, which will eventually try all resolution methods setup in smb.conf - only resolution backend at the moment is bcast, which does a parallel broadcast to all configured network interfaces, and takes the first reply that comes in (this nicely demonstrates how to do parallel requests using the async APIs) - converted all the existing code to use the new resolve_name() api - removed all the old nmb code (yay!) (This used to be commit 239c310f255e43dd2d1c2433f666c9faaacbdce3) --- source4/libcli/raw/clisocket.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 0edb95e1a1..e981049535 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -326,10 +326,11 @@ resolve a hostname and connect ****************************************************************************/ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) { - int name_type = 0x20; - struct ipv4_addr ip; - char *name, *p; + int name_type = NBT_NAME_SERVER; + const char *address; NTSTATUS status; + struct nbt_name nbt_name; + char *name, *p; name = talloc_strdup(sock, host); @@ -339,13 +340,18 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in *p = 0; } - if (!resolve_name(name, name, &ip, name_type)) { + nbt_name.name = name; + nbt_name.type = name_type; + nbt_name.scope = NULL; + + status = resolve_name(&nbt_name, sock, &address); + if (!NT_STATUS_IS_OK(status)) { return False; } sock->hostname = name; - status = smbcli_sock_connect(sock, sys_inet_ntoa(ip), port); + status = smbcli_sock_connect(sock, address, port); return NT_STATUS_IS_OK(status); } -- cgit From aefaa18554a55da5b5d9fdb9815eb246b539c8a2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 22 Jan 2005 02:51:39 +0000 Subject: r4924: continue the effort to simplify and generalise the composite interface. This patch removes the "stage" variable, which is really better suited to the backend state structures (This used to be commit 39da684ea8bc72d7a4a12c00eaad56b4f32890a9) --- source4/libcli/raw/clisocket.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index e981049535..cbbd6490bd 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -30,6 +30,7 @@ this private structure is used during async connection handling */ struct clisocket_connect { + int port_num; int *iports; struct smbcli_socket *sock; const char *dest_host; @@ -95,8 +96,8 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even } /* that port failed - try the next port */ - for (i=c->stage+1;conn->iports[i];i++) { - c->stage = i; + for (i=conn->port_num+1;conn->iports[i];i++) { + conn->port_num = i; c->status = smbcli_sock_connect_one(conn->sock, conn->dest_host, conn->iports[i]); @@ -204,7 +205,7 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, /* startup the connect process for each port in turn until one succeeds or tells us that it is pending */ for (i=0;conn->iports[i];i++) { - c->stage = i; + conn->port_num = i; conn->sock->port = conn->iports[i]; c->status = smbcli_sock_connect_one(sock, conn->dest_host, -- cgit From 9d6e923aab2036d6ce72e31aa4633d55b5991558 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Jan 2005 09:01:46 +0000 Subject: r4938: allow the caller to supply an existing event_context if they want to in smb_composite_connect_send(). This makes doing parallel calls much easier. (This used to be commit 442308970c123b9fb25615673049e1c1c234a0b9) --- source4/libcli/raw/clisocket.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index cbbd6490bd..9249f453e8 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -49,8 +49,10 @@ static int smbcli_sock_destructor(void *ptr) /* create a smbcli_socket context + The event_ctx is optional - if not supplied one will be created */ -struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) +struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, + struct event_context *event_ctx) { struct smbcli_socket *sock; @@ -59,7 +61,11 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) return NULL; } - sock->event.ctx = event_context_init(sock); + if (event_ctx) { + sock->event.ctx = talloc_reference(sock, event_ctx); + } else { + sock->event.ctx = event_context_init(sock); + } if (sock->event.ctx == NULL) { talloc_free(sock); return NULL; -- cgit From fd62df64188c0f992876c72fdda8a6da5dba3090 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Jan 2005 11:49:15 +0000 Subject: r4943: Smplified the events handling code a lot. The first source of complexity was that events didn't automatically cleanup themselves. This was because the events code was written before we had talloc destructors, so you needed to call event_remove_XX() to clean the event out of the event lists from every piece of code that used events. I have now added automatic event destructors, which in turn allowed me to simplify a lot of the calling code. The 2nd source of complexity was caused by the ref_count, which was needed to cope with event handlers destroying events while handling them, which meant the linked lists became invalid, so the ref_count ws used to mark events for later destruction. The new system is much simpler. I now have a ev->destruction_count, which is incremented in all event destructors. The event dispatch code checks for changes to this and handles it. (This used to be commit a3c7417cfeab429ffb22d5546b205818f531a7b4) --- source4/libcli/raw/clisocket.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9249f453e8..847f5c1b0a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -37,16 +37,6 @@ struct clisocket_connect { }; -static int smbcli_sock_destructor(void *ptr) -{ - struct smbcli_socket *sock = talloc_get_type(ptr, struct smbcli_socket); - - if (sock->event.fde && sock->event.ctx) { - event_remove_fd(sock->event.ctx, sock->event.fde); - } - return 0; -} - /* create a smbcli_socket context The event_ctx is optional - if not supplied one will be created @@ -71,8 +61,6 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, return NULL; } - talloc_set_destructor(sock, smbcli_sock_destructor); - return sock; } @@ -134,11 +122,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, talloc_free(sock->sock); sock->sock = NULL; } - - if (sock->event.fde) { - event_remove_fd(sock->event.ctx, sock->event.fde); - sock->event.fde = NULL; - } + talloc_free(sock->event.fde); status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); if (!NT_STATUS_IS_OK(status)) { @@ -155,6 +139,8 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, fde.private = sock; sock->event.fde = event_add_fd(sock->event.ctx, &fde); + talloc_steal(sock, sock->event.fde); + sock->port = port; set_blocking(fde.fd, False); -- cgit From 6c14b0133dede38294a812be7f5f5bd5ec3d498b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Jan 2005 12:17:45 +0000 Subject: r4944: every event_add_*() caller was having to call talloc_steal() to take control of the event, so instead build that into the function. If you pass NULL as mem_ctx then it leaves it as a child of the events structure. (This used to be commit 7f981b9ed96f39027cbfd500f41e0c2be64cbb50) --- source4/libcli/raw/clisocket.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 847f5c1b0a..c9934fa16d 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -138,8 +138,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, fde.handler = smbcli_sock_connect_handler; fde.private = sock; - sock->event.fde = event_add_fd(sock->event.ctx, &fde); - talloc_steal(sock, sock->event.fde); + sock->event.fde = event_add_fd(sock->event.ctx, &fde, sock); sock->port = port; set_blocking(fde.fd, False); -- cgit From 9a70f446fc4abc2bd1278772810c0e8132f4bea4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Jan 2005 08:30:44 +0000 Subject: r5126: the composite code is no longer client specific or smb specific, so rename the core structure to composite_context and the wait routine to composite_wait() (suggestion from metze) (This used to be commit cf11d05e35179c2c3e51c5ab370cd0a3fb15f24a) --- source4/libcli/raw/clisocket.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index c9934fa16d..78a096fb8f 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -74,7 +74,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, struct timeval t, uint16_t flags) { - struct smbcli_composite *c = talloc_get_type(fde->private, struct smbcli_composite); + struct composite_context *c = talloc_get_type(fde->private, struct composite_context); struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); int i; @@ -153,14 +153,14 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, this is the async send side of the interface */ -struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, +struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, const char *host_addr, int port) { - struct smbcli_composite *c; + struct composite_context *c; struct clisocket_connect *conn; int i; - c = talloc_zero(sock, struct smbcli_composite); + c = talloc_zero(sock, struct composite_context); if (c == NULL) return NULL; c->event_ctx = sock->event.ctx; @@ -219,10 +219,10 @@ failed: /* finish a smbcli_sock_connect_send() operation */ -NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) +NTSTATUS smbcli_sock_connect_recv(struct composite_context *c) { NTSTATUS status; - status = smb_composite_wait(c); + status = composite_wait(c); talloc_free(c); return status; } @@ -235,7 +235,7 @@ NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) */ NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port) { - struct smbcli_composite *c; + struct composite_context *c; c = smbcli_sock_connect_send(sock, host_addr, port); if (c == NULL) { -- cgit From 66170ef8b36b499aa5b44ef10c1bd362a50f2636 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 02:35:52 +0000 Subject: r5185: make all the events data structures private to events.c. This will make it possible to add optimisations to the events code such as keeping the next timed event in a sorted list, and using epoll for file descriptor events. I also removed the loop events code, as it wasn't being used anywhere, and changed timed events to always be one-shot (as adding a new timed event in the event handler is so easy to do if needed) (This used to be commit d7b4b6de51342a65bf46fce772d313f92f8d73d3) --- source4/libcli/raw/clisocket.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 78a096fb8f..f9e662714b 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -65,16 +65,17 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, } static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, - const char *hostaddr, int port); + const char *hostaddr, int port, + struct composite_context *c); /* handle socket write events during an async connect. These happen when the OS has either completed the connect() or has returned an error */ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, - struct timeval t, uint16_t flags) + struct timeval t, uint16_t flags, void *private) { - struct composite_context *c = talloc_get_type(fde->private, struct composite_context); + struct composite_context *c = talloc_get_type(private, struct composite_context); struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); int i; @@ -94,10 +95,9 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even conn->port_num = i; c->status = smbcli_sock_connect_one(conn->sock, conn->dest_host, - conn->iports[i]); + conn->iports[i], c); if (NT_STATUS_IS_OK(c->status) || NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - conn->sock->event.fde->private = c; return; } } @@ -113,9 +113,9 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even try to connect to the given address/port */ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, - const char *hostaddr, int port) + const char *hostaddr, int port, + struct composite_context *c) { - struct fd_event fde; NTSTATUS status; if (sock->sock) { @@ -133,15 +133,11 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, /* we initially look for write - see the man page on non-blocking connect */ - fde.fd = socket_get_fd(sock->sock); - fde.flags = EVENT_FD_WRITE; - fde.handler = smbcli_sock_connect_handler; - fde.private = sock; - - sock->event.fde = event_add_fd(sock->event.ctx, &fde, sock); + sock->event.fde = event_add_fd(sock->event.ctx, sock, socket_get_fd(sock->sock), + EVENT_FD_WRITE, smbcli_sock_connect_handler, c); sock->port = port; - set_blocking(fde.fd, False); + set_blocking(socket_get_fd(sock->sock), False); return socket_connect(sock->sock, NULL, 0, hostaddr, port, 0); } @@ -200,10 +196,9 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->sock->port = conn->iports[i]; c->status = smbcli_sock_connect_one(sock, conn->dest_host, - conn->iports[i]); + conn->iports[i], c); if (NT_STATUS_IS_OK(c->status) || NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - sock->event.fde->private = c; return c; } } -- cgit From 0798d54b4fc28be881e2c4012663b1461bc85ba7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 11:25:52 +0000 Subject: r5195: most events don't need the time of the event, so save a gettimeofday() call and just use timeval_current() when its actually needed (This used to be commit 236403cc4dc2924ed6a898acae0bb44cc1688dcc) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index f9e662714b..69de86088a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -73,7 +73,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, has either completed the connect() or has returned an error */ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, - struct timeval t, uint16_t flags, void *private) + uint16_t flags, void *private) { struct composite_context *c = talloc_get_type(private, struct composite_context); struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); -- cgit From 131dc76d56df40b3511c47e54f15412a25b491f8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 11:56:03 +0000 Subject: r5197: moved events code to lib/events/ (suggestion from metze) (This used to be commit 7f54c8a339f36aa43c9340be70ab7f0067593ef2) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 69de86088a..44c6a87e21 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -22,7 +22,7 @@ */ #include "includes.h" -#include "events.h" +#include "lib/events/events.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" -- cgit From bed7c9ec32b7d4083ba4ed2abbf3b6126bee7a25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 06:59:29 +0000 Subject: r5304: removed lib/socket/socket.h from includes.h (This used to be commit b902ea546d2d1327b23f40ddaeeaa8e7e3662454) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 44c6a87e21..cbb479ca1a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -25,6 +25,7 @@ #include "lib/events/events.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "lib/socket/socket.h" /* this private structure is used during async connection handling -- cgit From 2eb3d680625286431a3a60e37b75f47e0738f253 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 24 Mar 2005 04:14:06 +0000 Subject: r6028: A MAJOR update to intergrate the new credentails system fully with GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'. GENSEC now no longer has it's own handling of 'set username' etc, instead it uses cli_credentials calls. In order to link the credentails code right though Samba, a lot of interfaces have changed to remove 'username, domain, password' arguments, and these have been replaced with a single 'struct cli_credentials'. In the session setup code, a new parameter 'workgroup' contains the client/server current workgroup, which seems unrelated to the authentication exchange (it was being filled in from the auth info). This allows in particular kerberos to only call back for passwords when it actually needs to perform the kinit. The kerberos code has been modified not to use the SPNEGO provided 'principal name' (in the mechListMIC), but to instead use the name the host was connected to as. This better matches Microsoft behaviour, is more secure and allows better use of standard kerberos functions. To achieve this, I made changes to our socket code so that the hostname (before name resolution) is now recorded on the socket. In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now in libcli/auth/schannel.c, and it looks much more like a standard GENSEC module. The actual sign/seal code moved to libcli/auth/schannel_sign.c in a previous commit. The schannel credentails structure is now merged with the rest of the credentails, as many of the values (username, workstation, domain) where already present there. This makes handling this in a generic manner much easier, as there is no longer a custom entry-point. The auth_domain module continues to be developed, but is now just as functional as auth_winbind. The changes here are consequential to the schannel changes. The only removed function at this point is the RPC-LOGIN test (simulating the load of a WinXP login), which needs much more work to clean it up (it contains copies of too much code from all over the torture suite, and I havn't been able to penetrate its 'structure'). Andrew Bartlett (This used to be commit 2301a4b38a21aa60917973451687063d83d18d66) --- source4/libcli/raw/clisocket.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index cbb479ca1a..7cb7040131 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -34,7 +34,8 @@ struct clisocket_connect { int port_num; int *iports; struct smbcli_socket *sock; - const char *dest_host; + const char *dest_host_addr; + const char *dest_hostname; }; @@ -83,7 +84,7 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even c->status = socket_connect_complete(conn->sock->sock, 0); if (NT_STATUS_IS_OK(c->status)) { socket_set_option(conn->sock->sock, lp_socket_options(), NULL); - conn->sock->hostname = talloc_strdup(conn->sock, conn->dest_host); + conn->sock->hostname = talloc_strdup(conn->sock, conn->dest_hostname); c->state = SMBCLI_REQUEST_DONE; if (c->async.fn) { c->async.fn(c); @@ -95,7 +96,7 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even for (i=conn->port_num+1;conn->iports[i];i++) { conn->port_num = i; c->status = smbcli_sock_connect_one(conn->sock, - conn->dest_host, + conn->dest_host_addr, conn->iports[i], c); if (NT_STATUS_IS_OK(c->status) || NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { @@ -151,7 +152,8 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, this is the async send side of the interface */ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, - const char *host_addr, int port) + const char *host_addr, int port, + const char *host_name) { struct composite_context *c; struct clisocket_connect *conn; @@ -184,8 +186,11 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->iports[1] = 0; } - conn->dest_host = talloc_strdup(c, host_addr); - if (conn->dest_host == NULL) goto failed; + conn->dest_host_addr = talloc_strdup(c, host_addr); + if (conn->dest_host_addr == NULL) goto failed; + + conn->dest_hostname = talloc_strdup(c, host_name); + if (conn->dest_hostname == NULL) goto failed; c->private = conn; c->state = SMBCLI_REQUEST_SEND; @@ -196,7 +201,7 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->port_num = i; conn->sock->port = conn->iports[i]; c->status = smbcli_sock_connect_one(sock, - conn->dest_host, + conn->dest_host_addr, conn->iports[i], c); if (NT_STATUS_IS_OK(c->status) || NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { @@ -229,11 +234,12 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c) sync version of the function */ -NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port) +NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port, + const char *host_name) { struct composite_context *c; - c = smbcli_sock_connect_send(sock, host_addr, port); + c = smbcli_sock_connect_send(sock, host_addr, port, host_name); if (c == NULL) { return NT_STATUS_NO_MEMORY; } @@ -337,9 +343,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in return False; } - sock->hostname = name; - - status = smbcli_sock_connect(sock, address, port); + status = smbcli_sock_connect(sock, address, port, name); return NT_STATUS_IS_OK(status); } -- cgit From 777b4b021456f5bd8bbadfe97532efc13286e581 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 00:30:49 +0000 Subject: r7705: prevent SIGPIPE. this is what causes BASE-NEGNOWAIT to sometimes fail (This used to be commit 0163d7fe99caee54c6c2bd614e4f076fd00a6176) --- source4/libcli/raw/clisocket.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 7cb7040131..d6007ec8ba 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -63,6 +63,9 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, return NULL; } + /* ensure we don't get SIGPIPE */ + BlockSignals(True,SIGPIPE); + return sock; } -- cgit From 562498c5260108c17add1e1a392644d188ff5c79 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Jul 2005 03:01:26 +0000 Subject: r8407: fixed a bug left over from our old socket code. Thanks to lha for giving me a login on a netbsd machine to see this (This used to be commit 4e66f682e4f1c31bbe9441a13af2c245db31433d) --- source4/libcli/raw/clisocket.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index d6007ec8ba..b325fa473e 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -273,48 +273,33 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** Write to socket. Return amount written. ****************************************************************************/ -ssize_t smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, size_t len) +NTSTATUS smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, + size_t len, size_t *nsent) { - NTSTATUS status; DATA_BLOB blob; - size_t nsent; if (sock->sock == NULL) { - errno = EIO; - return -1; + return NT_STATUS_CONNECTION_DISCONNECTED; } blob.data = discard_const(data); blob.length = len; - status = socket_send(sock->sock, &blob, &nsent, 0); - if (NT_STATUS_IS_ERR(status)) { - return -1; - } - - return nsent; + return socket_send(sock->sock, &blob, nsent, 0); } /**************************************************************************** Read from socket. return amount read ****************************************************************************/ -ssize_t smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, size_t len) +NTSTATUS smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, + size_t len, size_t *nread) { - NTSTATUS status; - size_t nread; - if (sock->sock == NULL) { - errno = EIO; - return -1; - } - - status = socket_recv(sock->sock, data, len, &nread, 0); - if (NT_STATUS_IS_ERR(status)) { - return -1; + return NT_STATUS_CONNECTION_DISCONNECTED; } - return nread; + return socket_recv(sock->sock, data, len, nread, 0); } -- cgit From c98c6aa5611f26ab591c50fcded1fc55e81a0d07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 28 Aug 2005 02:37:14 +0000 Subject: r9702: r9680@blu: tridge | 2005-08-27 18:45:08 +1000 - fixed ncacn_ip_tcp to use the generic async name resolution methods, so NBT names now work (as requested several times by abartlet!) - changed resolve_name() to take an event_context, so it doesn't cause the whole process to block - cleaned up the talloc_find_parent_bytype() calls to go via a cleaner event_context_find() call (This used to be commit b3d491b210a8b889a25efcb273e70fefbd01b7f7) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index b325fa473e..90fb98603e 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -326,7 +326,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in nbt_name.type = name_type; nbt_name.scope = NULL; - status = resolve_name(&nbt_name, sock, &address); + status = resolve_name(&nbt_name, sock, &address, sock->event.ctx); if (!NT_STATUS_IS_OK(status)) { return False; } -- cgit From ab4d635b92b116b02b88843b4ec4f5b7517bab1a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 26 Sep 2005 11:47:55 +0000 Subject: r10504: - seperate implementation specific stuff, from the generic composite stuff. - don't use SMBCLI_REQUEST_* state's in the genreic composite stuff - move monitor_fn to libnet. NOTE: I have maybe found some bugs, in code that is dirrectly in DONE or ERROR state in the _send() function. I haven't fixed this bugs in this commit! We may need some composite_trigger_*() functions or so. And maybe some other generic helper functions... metze (This used to be commit 4527815a0a9b96e460f301cb1f0c0b3964c166fc) --- source4/libcli/raw/clisocket.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 90fb98603e..688ee8a78b 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -78,17 +78,17 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, has either completed the connect() or has returned an error */ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, - uint16_t flags, void *private) + uint16_t flags, void *private_data) { - struct composite_context *c = talloc_get_type(private, struct composite_context); - struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); + struct composite_context *c = talloc_get_type(private_data, struct composite_context); + struct clisocket_connect *conn = talloc_get_type(c->private_data, struct clisocket_connect); int i; c->status = socket_connect_complete(conn->sock->sock, 0); if (NT_STATUS_IS_OK(c->status)) { socket_set_option(conn->sock->sock, lp_socket_options(), NULL); conn->sock->hostname = talloc_strdup(conn->sock, conn->dest_hostname); - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; if (c->async.fn) { c->async.fn(c); } @@ -107,7 +107,7 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even } } - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; if (c->async.fn) { c->async.fn(c); } @@ -195,8 +195,8 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->dest_hostname = talloc_strdup(c, host_name); if (conn->dest_hostname == NULL) goto failed; - c->private = conn; - c->state = SMBCLI_REQUEST_SEND; + c->private_data = conn; + c->state = COMPOSITE_STATE_IN_PROGRESS; /* startup the connect process for each port in turn until one succeeds or tells us that it is pending */ @@ -212,7 +212,7 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, } } - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; return c; failed: -- cgit From 134b2488c82ae13392121f71e4960178a38f3e01 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 28 Oct 2005 11:02:42 +0000 Subject: r11369: Implement socket_connect_multi: Connect to multiple ipv4 tcp ports in sequence, with a 2-millisecond timeout between firing the syn packets. Build smbcli_sock_connect_send upon that. Volker (This used to be commit 5718df44d90d113304c5deed1e2e7f82ff9e928f) --- source4/libcli/raw/clisocket.c | 324 ++++++++++++++++++----------------------- 1 file changed, 140 insertions(+), 184 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 688ee8a78b..8b8a0b0faf 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -27,206 +27,130 @@ #include "libcli/composite/composite.h" #include "lib/socket/socket.h" -/* - this private structure is used during async connection handling -*/ -struct clisocket_connect { - int port_num; - int *iports; - struct smbcli_socket *sock; - const char *dest_host_addr; - const char *dest_hostname; +struct sock_connect_state { + struct composite_context *ctx; + const char *host_name; + int num_ports; + uint16_t *ports; + struct smbcli_socket *result; }; - /* - create a smbcli_socket context - The event_ctx is optional - if not supplied one will be created + connect a smbcli_socket context to an IP/port pair + if port is 0 then choose 445 then 139 */ -struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, - struct event_context *event_ctx) + +static void smbcli_sock_connect_recv_conn(struct composite_context *ctx); + +struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, + const char *host_addr, + int port, + const char *host_name, + struct event_context *event_ctx) { - struct smbcli_socket *sock; + struct composite_context *result, *ctx; + struct sock_connect_state *state; - sock = talloc_zero(mem_ctx, struct smbcli_socket); - if (!sock) { - return NULL; - } + result = talloc_zero(mem_ctx, struct composite_context); + if (result == NULL) goto failed; + result->state = COMPOSITE_STATE_IN_PROGRESS; - if (event_ctx) { - sock->event.ctx = talloc_reference(sock, event_ctx); + if (event_ctx != NULL) { + result->event_ctx = talloc_reference(result, event_ctx); } else { - sock->event.ctx = event_context_init(sock); - } - if (sock->event.ctx == NULL) { - talloc_free(sock); - return NULL; + result->event_ctx = event_context_init(result); } - /* ensure we don't get SIGPIPE */ - BlockSignals(True,SIGPIPE); + if (result->event_ctx == NULL) goto failed; - return sock; -} + state = talloc(result, struct sock_connect_state); + if (state == NULL) goto failed; + state->ctx = result; + result->private_data = state; -static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, - const char *hostaddr, int port, - struct composite_context *c); + state->host_name = talloc_strdup(state, host_name); + if (state->host_name == NULL) goto failed; -/* - handle socket write events during an async connect. These happen when the OS - has either completed the connect() or has returned an error -*/ -static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, - uint16_t flags, void *private_data) -{ - struct composite_context *c = talloc_get_type(private_data, struct composite_context); - struct clisocket_connect *conn = talloc_get_type(c->private_data, struct clisocket_connect); - int i; - - c->status = socket_connect_complete(conn->sock->sock, 0); - if (NT_STATUS_IS_OK(c->status)) { - socket_set_option(conn->sock->sock, lp_socket_options(), NULL); - conn->sock->hostname = talloc_strdup(conn->sock, conn->dest_hostname); - c->state = COMPOSITE_STATE_DONE; - if (c->async.fn) { - c->async.fn(c); - } - return; - } + if (port == 0) { + const char **ports = lp_smb_ports(); + int i; - /* that port failed - try the next port */ - for (i=conn->port_num+1;conn->iports[i];i++) { - conn->port_num = i; - c->status = smbcli_sock_connect_one(conn->sock, - conn->dest_host_addr, - conn->iports[i], c); - if (NT_STATUS_IS_OK(c->status) || - NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - return; + for (i=0;ports[i];i++) /* noop */ ; + if (i == 0) { + DEBUG(3, ("no smb ports defined\n")); + goto failed; } + state->num_ports = i; + state->ports = talloc_array(state, uint16_t, i); + if (state->ports == NULL) goto failed; + for (i=0;ports[i];i++) { + state->ports[i] = atoi(ports[i]); + } + } else { + state->ports = talloc_array(state, uint16_t, 1); + if (state->ports == NULL) goto failed; + state->num_ports = 1; + state->ports[0] = port; } - c->state = COMPOSITE_STATE_ERROR; - if (c->async.fn) { - c->async.fn(c); - } -} - - -/* - try to connect to the given address/port -*/ -static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, - const char *hostaddr, int port, - struct composite_context *c) -{ - NTSTATUS status; - - if (sock->sock) { - talloc_free(sock->sock); - sock->sock = NULL; - } - talloc_free(sock->event.fde); - - status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); - if (!NT_STATUS_IS_OK(status)) { - return status; - } - - talloc_steal(sock, sock->sock); - - /* we initially look for write - see the man page on - non-blocking connect */ - sock->event.fde = event_add_fd(sock->event.ctx, sock, socket_get_fd(sock->sock), - EVENT_FD_WRITE, smbcli_sock_connect_handler, c); + ctx = socket_connect_multi_send(state, host_addr, + state->num_ports, state->ports, + state->ctx->event_ctx); + if (ctx == NULL) goto failed; + ctx->async.fn = smbcli_sock_connect_recv_conn; + ctx->async.private_data = state; + return result; - sock->port = port; - set_blocking(socket_get_fd(sock->sock), False); - - return socket_connect(sock->sock, NULL, 0, hostaddr, port, 0); +failed: + talloc_free(result); + return NULL; } - -/* - connect a smbcli_socket context to an IP/port pair - if port is 0 then choose 445 then 139 - - this is the async send side of the interface -*/ -struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, - const char *host_addr, int port, - const char *host_name) +static void smbcli_sock_connect_recv_conn(struct composite_context *ctx) { - struct composite_context *c; - struct clisocket_connect *conn; - int i; + struct sock_connect_state *state = + talloc_get_type(ctx->async.private_data, + struct sock_connect_state); + struct socket_context *sock; + uint16_t port; - c = talloc_zero(sock, struct composite_context); - if (c == NULL) return NULL; + state->ctx->status = socket_connect_multi_recv(ctx, state, &sock, + &port); + if (!composite_is_ok(state->ctx)) return; - c->event_ctx = sock->event.ctx; + state->ctx->status = + socket_set_option(sock, lp_socket_options(), NULL); + if (!composite_is_ok(state->ctx)) return; - conn = talloc(c, struct clisocket_connect); - if (conn == NULL) goto failed; - conn->sock = sock; + state->result = talloc_zero(state, struct smbcli_socket); + if (composite_nomem(state->result, state->ctx)) return; - /* work out what ports we will try */ - if (port == 0) { - const char **ports = lp_smb_ports(); - for (i=0;ports[i];i++) /* noop */ ; - conn->iports = talloc_array(c, int, i+1); - if (conn->iports == NULL) goto failed; - for (i=0;ports[i];i++) { - conn->iports[i] = atoi(ports[i]); - } - conn->iports[i] = 0; - } else { - conn->iports = talloc_array(c, int, 2); - if (conn->iports == NULL) goto failed; - conn->iports[0] = port; - conn->iports[1] = 0; - } + state->result->sock = talloc_steal(state->result, sock); + state->result->port = port; + state->result->hostname = talloc_steal(sock, state->host_name); - conn->dest_host_addr = talloc_strdup(c, host_addr); - if (conn->dest_host_addr == NULL) goto failed; - - conn->dest_hostname = talloc_strdup(c, host_name); - if (conn->dest_hostname == NULL) goto failed; - - c->private_data = conn; - c->state = COMPOSITE_STATE_IN_PROGRESS; - - /* startup the connect process for each port in turn until one - succeeds or tells us that it is pending */ - for (i=0;conn->iports[i];i++) { - conn->port_num = i; - conn->sock->port = conn->iports[i]; - c->status = smbcli_sock_connect_one(sock, - conn->dest_host_addr, - conn->iports[i], c); - if (NT_STATUS_IS_OK(c->status) || - NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - return c; - } - } + state->result->event.ctx = + talloc_reference(state->result, state->ctx->event_ctx); + if (composite_nomem(state->result->event.ctx, state->ctx)) return; - c->state = COMPOSITE_STATE_ERROR; - return c; - -failed: - talloc_free(c); - return NULL; + composite_done(state->ctx); } /* finish a smbcli_sock_connect_send() operation */ -NTSTATUS smbcli_sock_connect_recv(struct composite_context *c) +NTSTATUS smbcli_sock_connect_recv(struct composite_context *c, + TALLOC_CTX *mem_ctx, + struct smbcli_socket **result) { - NTSTATUS status; - status = composite_wait(c); + NTSTATUS status = composite_wait(c); + if (NT_STATUS_IS_OK(status)) { + struct sock_connect_state *state = + talloc_get_type(c->private_data, + struct sock_connect_state); + *result = talloc_steal(mem_ctx, state->result); + } talloc_free(c); return status; } @@ -237,17 +161,16 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c) sync version of the function */ -NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port, - const char *host_name) +NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, + const char *host_addr, int port, + const char *host_name, + struct event_context *event_ctx, + struct smbcli_socket **result) { - struct composite_context *c; - - c = smbcli_sock_connect_send(sock, host_addr, port, host_name); - if (c == NULL) { - return NT_STATUS_NO_MEMORY; - } - - return smbcli_sock_connect_recv(c); + struct composite_context *c = + smbcli_sock_connect_send(mem_ctx, host_addr, port, host_name, + event_ctx); + return smbcli_sock_connect_recv(c, mem_ctx, result); } @@ -306,15 +229,39 @@ NTSTATUS smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) +struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, + TALLOC_CTX *mem_ctx, + struct event_context *event_ctx) { int name_type = NBT_NAME_SERVER; const char *address; NTSTATUS status; struct nbt_name nbt_name; char *name, *p; + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + struct smbcli_socket *result; + + if (tmp_ctx == NULL) { + DEBUG(0, ("talloc_new failed\n")); + return NULL; + } + + name = talloc_strdup(tmp_ctx, host); + if (name == NULL) { + DEBUG(0, ("talloc_strdup failed\n")); + talloc_free(tmp_ctx); + return NULL; + } + + if (event_ctx == NULL) { + event_ctx = event_context_init(mem_ctx); + } - name = talloc_strdup(sock, host); + if (event_ctx == NULL) { + DEBUG(0, ("event_context_init failed\n")); + talloc_free(tmp_ctx); + return NULL; + } /* allow hostnames of the form NAME#xx and do a netbios lookup */ if ((p = strchr(name, '#'))) { @@ -322,16 +269,25 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in *p = 0; } - nbt_name.name = name; - nbt_name.type = name_type; - nbt_name.scope = NULL; + make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, sock, &address, sock->event.ctx); + status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx); if (!NT_STATUS_IS_OK(status)) { + talloc_free(tmp_ctx); return False; } - status = smbcli_sock_connect(sock, address, port, name); + status = smbcli_sock_connect(mem_ctx, address, port, name, event_ctx, + &result); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(9, ("smbcli_sock_connect failed: %s\n", + nt_errstr(status))); + talloc_free(tmp_ctx); + return NULL; + } + + talloc_free(tmp_ctx); - return NT_STATUS_IS_OK(status); + return result; } -- cgit From 4c9ba2ffa13ebfe7e8a289ad3d27864fef7917d6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Nov 2005 05:26:53 +0000 Subject: r11632: removed 2 unused functions (This used to be commit fa904afed93a350dd0dcd3cddc1521a4a1ad6711) --- source4/libcli/raw/clisocket.c | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 8b8a0b0faf..be25b36007 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -193,39 +193,6 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) socket_set_option(sock->sock, options, NULL); } -/**************************************************************************** - Write to socket. Return amount written. -****************************************************************************/ -NTSTATUS smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, - size_t len, size_t *nsent) -{ - DATA_BLOB blob; - - if (sock->sock == NULL) { - return NT_STATUS_CONNECTION_DISCONNECTED; - } - - blob.data = discard_const(data); - blob.length = len; - - return socket_send(sock->sock, &blob, nsent, 0); -} - - -/**************************************************************************** - Read from socket. return amount read -****************************************************************************/ -NTSTATUS smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, - size_t len, size_t *nread) -{ - if (sock->sock == NULL) { - return NT_STATUS_CONNECTION_DISCONNECTED; - } - - return socket_recv(sock->sock, data, len, nread, 0); -} - - /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -- cgit From f5d4623ea5a755a9525b9ef4532420ee53729a3d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 1 Dec 2005 00:22:08 +0000 Subject: r11982: ensure the fde event gets freed before the socket itself, as otherwise we get a error from epoll about disabling events for a file descriptor that is closed (This used to be commit f32739307464a1f0c835cff886b8c4b960778900) --- source4/libcli/raw/clisocket.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index be25b36007..40d9d2784a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -179,10 +179,10 @@ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, ****************************************************************************/ void smbcli_sock_dead(struct smbcli_socket *sock) { - if (sock->sock != NULL) { - talloc_free(sock->sock); - sock->sock = NULL; - } + talloc_free(sock->event.fde); + sock->event.fde = NULL; + talloc_free(sock->sock); + sock->sock = NULL; } /**************************************************************************** -- cgit From 4ac2be99588b48b0652a524bf12fb1aa9c3f5fbb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 7 Mar 2006 11:07:23 +0000 Subject: r13924: Split more prototypes out of include/proto.h + initial work on header file dependencies (This used to be commit 122835876748a3eaf5e8d31ad1abddab9acb8781) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 40d9d2784a..4b1d70d8d2 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -26,6 +26,7 @@ #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" #include "lib/socket/socket.h" +#include "libcli/resolve/resolve.h" struct sock_connect_state { struct composite_context *ctx; -- cgit From add7ba54c1cbf0c2d3d6ef3230903a08522e8c33 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 14 Mar 2006 12:56:59 +0000 Subject: r14372: fix bug found by sparse metze (This used to be commit da1ac9b2243d0217c2d29879d885d62be9ddd290) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 4b1d70d8d2..0631d55a9c 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -242,7 +242,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); - return False; + return NULL; } status = smbcli_sock_connect(mem_ctx, address, port, name, event_ctx, -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/libcli/raw/clisocket.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 0631d55a9c..0aa6ec5616 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From ffeee68e4b72dd94fee57366bd8d38b8c284c3d4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 12:42:09 +0000 Subject: r25026: Move param/param.h out of includes.h (This used to be commit abe8349f9b4387961ff3665d8c589d61cd2edf31) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 0aa6ec5616..51f631eb67 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -26,6 +26,7 @@ #include "libcli/composite/composite.h" #include "lib/socket/socket.h" #include "libcli/resolve/resolve.h" +#include "param/param.h" struct sock_connect_state { struct composite_context *ctx; -- cgit From 37d53832a4623653f706e77985a79d84bd7c6694 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 28 Sep 2007 01:17:46 +0000 Subject: r25398: Parse loadparm context to all lp_*() functions. (This used to be commit 3fcc960839c6e5ca4de2c3c042f12f369ac5f238) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 51f631eb67..a748b40a32 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -73,7 +73,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, if (state->host_name == NULL) goto failed; if (port == 0) { - const char **ports = lp_smb_ports(); + const char **ports = lp_smb_ports(global_loadparm); int i; for (i=0;ports[i];i++) /* noop */ ; @@ -120,7 +120,7 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx) if (!composite_is_ok(state->ctx)) return; state->ctx->status = - socket_set_option(sock, lp_socket_options(), NULL); + socket_set_option(sock, lp_socket_options(global_loadparm), NULL); if (!composite_is_ok(state->ctx)) return; -- cgit From 1fbdd6ef1dfb8704de0524fc6f5c33e1418858cd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 18:47:35 +0100 Subject: r26264: pass name resolve order explicitly, use torture context for settings in dssync tests. (This used to be commit c7eae1c7842f9ff8b70cce9e5d6f3ebbbe78e83b) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index a748b40a32..e3420313c5 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -239,7 +239,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx); + status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, lp_name_resolve_order(global_loadparm)); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return NULL; -- cgit From 2f8dc4f48f1802baa3405e7803563f6840e0d1b3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 21:25:06 +0100 Subject: r26266: Remove more global_loadparm uses. (This used to be commit 99113075c4a96679bcec4f4d6bba4acb3dee4245) --- source4/libcli/raw/clisocket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index e3420313c5..6e12d8073d 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -199,6 +199,7 @@ resolve a hostname and connect ****************************************************************************/ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, TALLOC_CTX *mem_ctx, + const char **name_resolve_order, struct event_context *event_ctx) { int name_type = NBT_NAME_SERVER; @@ -239,7 +240,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, lp_name_resolve_order(global_loadparm)); + status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, name_resolve_order); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return NULL; -- cgit From 01d2acfdb4c4c0349a28a18c5c0da5b960b02791 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Dec 2007 16:04:17 +0100 Subject: r26335: Specify name_resolve_order to socket code. (This used to be commit b03e5d00110be3f1fe5809dad4eb6ca5cea7463d) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 6e12d8073d..9b744dcc18 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -96,6 +96,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, + lp_name_resolve_order(global_loadparm), state->ctx->event_ctx); if (ctx == NULL) goto failed; ctx->async.fn = smbcli_sock_connect_recv_conn; -- cgit From 5f4842cf65ce64bfdf577cd549565da20ca818cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 10 Dec 2007 18:41:19 +0100 Subject: r26376: Add context for libcli_resolve. (This used to be commit 459e1466a411d6f83b7372e248566e6e71c745fc) --- source4/libcli/raw/clisocket.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9b744dcc18..c09104e256 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -96,7 +96,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, - lp_name_resolve_order(global_loadparm), + lp_resolve_context(global_loadparm), state->ctx->event_ctx); if (ctx == NULL) goto failed; ctx->async.fn = smbcli_sock_connect_recv_conn; @@ -200,7 +200,7 @@ resolve a hostname and connect ****************************************************************************/ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, TALLOC_CTX *mem_ctx, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx) { int name_type = NBT_NAME_SERVER; @@ -241,7 +241,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, name_resolve_order); + status = resolve_name(resolve_ctx, &nbt_name, tmp_ctx, &address, event_ctx); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return NULL; -- cgit From 4b0199a5493ea2b88558cc40871e63c1dc8dbb56 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 12 Dec 2007 02:15:29 +0100 Subject: r26409: Pass smb ports along. (This used to be commit 2833f320de1f1fd39c710ad0a61c3fa1bb1df31f) --- source4/libcli/raw/clisocket.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index c09104e256..9732ab1638 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -45,12 +45,13 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx); struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, const char *host_addr, - int port, + const char **ports, const char *host_name, struct event_context *event_ctx) { struct composite_context *result, *ctx; struct sock_connect_state *state; + int i; result = talloc_zero(mem_ctx, struct composite_context); if (result == NULL) goto failed; @@ -72,26 +73,11 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, state->host_name = talloc_strdup(state, host_name); if (state->host_name == NULL) goto failed; - if (port == 0) { - const char **ports = lp_smb_ports(global_loadparm); - int i; - - for (i=0;ports[i];i++) /* noop */ ; - if (i == 0) { - DEBUG(3, ("no smb ports defined\n")); - goto failed; - } - state->num_ports = i; - state->ports = talloc_array(state, uint16_t, i); - if (state->ports == NULL) goto failed; - for (i=0;ports[i];i++) { - state->ports[i] = atoi(ports[i]); - } - } else { - state->ports = talloc_array(state, uint16_t, 1); - if (state->ports == NULL) goto failed; - state->num_ports = 1; - state->ports[0] = port; + state->num_ports = str_list_length(ports); + state->ports = talloc_array(state, uint16_t, state->num_ports); + if (state->ports == NULL) goto failed; + for (i=0;ports[i];i++) { + state->ports[i] = atoi(ports[i]); } ctx = socket_connect_multi_send(state, host_addr, @@ -164,13 +150,13 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c, sync version of the function */ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, - const char *host_addr, int port, + const char *host_addr, const char **ports, const char *host_name, struct event_context *event_ctx, struct smbcli_socket **result) { struct composite_context *c = - smbcli_sock_connect_send(mem_ctx, host_addr, port, host_name, + smbcli_sock_connect_send(mem_ctx, host_addr, ports, host_name, event_ctx); return smbcli_sock_connect_recv(c, mem_ctx, result); } @@ -198,7 +184,7 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, +struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports, TALLOC_CTX *mem_ctx, struct resolve_context *resolve_ctx, struct event_context *event_ctx) @@ -247,7 +233,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, return NULL; } - status = smbcli_sock_connect(mem_ctx, address, port, name, event_ctx, + status = smbcli_sock_connect(mem_ctx, address, ports, name, event_ctx, &result); if (!NT_STATUS_IS_OK(status)) { -- cgit From 771b347f9b185895390445be96081c781e28a26d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Jan 2008 18:39:01 -0600 Subject: r26644: Janitorial: Pass resolve_context explicitly to various SMB functions, should help fix the build for OpenChange. (This used to be commit 385ffe4f4cc9a21a760c0f00410f56e2592fd507) --- source4/libcli/raw/clisocket.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9732ab1638..8beaef3daa 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -47,6 +47,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, const char *host_addr, const char **ports, const char *host_name, + struct resolve_context *resolve_ctx, struct event_context *event_ctx) { struct composite_context *result, *ctx; @@ -152,11 +153,13 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c, NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, const char *host_addr, const char **ports, const char *host_name, + struct resolve_context *resolve_ctx, struct event_context *event_ctx, struct smbcli_socket **result) { struct composite_context *c = smbcli_sock_connect_send(mem_ctx, host_addr, ports, host_name, + resolve_ctx, event_ctx); return smbcli_sock_connect_recv(c, mem_ctx, result); } @@ -233,8 +236,8 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char ** return NULL; } - status = smbcli_sock_connect(mem_ctx, address, ports, name, event_ctx, - &result); + status = smbcli_sock_connect(mem_ctx, address, ports, name, resolve_ctx, + event_ctx, &result); if (!NT_STATUS_IS_OK(status)) { DEBUG(9, ("smbcli_sock_connect failed: %s\n", -- cgit From 2c8c9a535500e40084c4810da1890df8d9415659 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 Jan 2008 15:36:33 -0600 Subject: r26669: Janitorial: Remove uses of global_loadparm. (This used to be commit 50c46160d997e0448f51ae09e0f3c79e8519fa41) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 8beaef3daa..8fcb8bb48c 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -83,7 +83,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, - lp_resolve_context(global_loadparm), + resolve_ctx, state->ctx->event_ctx); if (ctx == NULL) goto failed; ctx->async.fn = smbcli_sock_connect_recv_conn; -- cgit From 3101cb888d5cbad785050b8491b138d683d444fb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 25 Feb 2008 12:51:55 +0100 Subject: Remove uses of global_loadparm. (This used to be commit a16c9a2129ce92e7e1a613b2badd168e42ead436) --- source4/libcli/raw/clisocket.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 8fcb8bb48c..eaa02e1047 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -33,6 +33,7 @@ struct sock_connect_state { const char *host_name; int num_ports; uint16_t *ports; + const char *socket_options; struct smbcli_socket *result; }; @@ -80,6 +81,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, for (i=0;ports[i];i++) { state->ports[i] = atoi(ports[i]); } + state->socket_options = lp_socket_options(global_loadparm); ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, @@ -108,7 +110,7 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx) if (!composite_is_ok(state->ctx)) return; state->ctx->status = - socket_set_option(sock, lp_socket_options(global_loadparm), NULL); + socket_set_option(sock, state->socket_options, NULL); if (!composite_is_ok(state->ctx)) return; -- cgit From afe3e8172ddaa5e4aa811faceecda4f943d6e2ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 04:53:27 +0200 Subject: Install public header files again and include required prototypes. (This used to be commit 47ffbbf67435904754469544390b67d34c958343) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index eaa02e1047..1dcf2d1c53 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -170,7 +170,7 @@ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, /**************************************************************************** mark the socket as dead ****************************************************************************/ -void smbcli_sock_dead(struct smbcli_socket *sock) +_PUBLIC_ void smbcli_sock_dead(struct smbcli_socket *sock) { talloc_free(sock->event.fde); sock->event.fde = NULL; @@ -189,7 +189,7 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports, +_PUBLIC_ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports, TALLOC_CTX *mem_ctx, struct resolve_context *resolve_ctx, struct event_context *event_ctx) -- cgit From 4e83011f72ba3df387512755a17760b42a7bf2f2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 21 Apr 2008 17:58:23 -0400 Subject: Remove more event_context_init() uses from function calls within deep down the code. Make sure we pass around the event_context where we need it instead. All test but a few python ones fail. Jelmer promised to fix them. (This used to be commit 3045d391626fba169aa26be52174883e18d323e9) --- source4/libcli/raw/clisocket.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'source4/libcli/raw/clisocket.c') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 1dcf2d1c53..49838e8a1c 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -59,12 +59,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, if (result == NULL) goto failed; result->state = COMPOSITE_STATE_IN_PROGRESS; - if (event_ctx != NULL) { - result->event_ctx = talloc_reference(result, event_ctx); - } else { - result->event_ctx = event_context_init(result); - } - + result->event_ctx = talloc_reference(result, event_ctx); if (result->event_ctx == NULL) goto failed; state = talloc(result, struct sock_connect_state); @@ -202,6 +197,11 @@ _PUBLIC_ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, cons TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); struct smbcli_socket *result; + if (event_ctx == NULL) { + DEBUG(0, ("Invalid NULL event context passed in as parameter\n")); + return NULL; + } + if (tmp_ctx == NULL) { DEBUG(0, ("talloc_new failed\n")); return NULL; @@ -214,16 +214,6 @@ _PUBLIC_ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, cons return NULL; } - if (event_ctx == NULL) { - event_ctx = event_context_init(mem_ctx); - } - - if (event_ctx == NULL) { - DEBUG(0, ("event_context_init failed\n")); - talloc_free(tmp_ctx); - return NULL; - } - /* allow hostnames of the form NAME#xx and do a netbios lookup */ if ((p = strchr(name, '#'))) { name_type = strtol(p+1, NULL, 16); -- cgit