summaryrefslogtreecommitdiff
path: root/source4/libcli/smb_composite
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2005-10-28 11:02:42 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:45:27 -0500
commit134b2488c82ae13392121f71e4960178a38f3e01 (patch)
treef002f6d68b66654d18f53a46df5459fbfd241b1e /source4/libcli/smb_composite
parent3dc75cc84f92af9a72d52e7c9299b47c01368544 (diff)
downloadsamba-134b2488c82ae13392121f71e4960178a38f3e01.tar.gz
samba-134b2488c82ae13392121f71e4960178a38f3e01.tar.bz2
samba-134b2488c82ae13392121f71e4960178a38f3e01.zip
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)
Diffstat (limited to 'source4/libcli/smb_composite')
-rw-r--r--source4/libcli/smb_composite/connect.c42
-rw-r--r--source4/libcli/smb_composite/connect_multi.c188
2 files changed, 7 insertions, 223 deletions
diff --git a/source4/libcli/smb_composite/connect.c b/source4/libcli/smb_composite/connect.c
index 4e9ee48cb7..643871a8c4 100644
--- a/source4/libcli/smb_composite/connect.c
+++ b/source4/libcli/smb_composite/connect.c
@@ -41,7 +41,6 @@ struct connect_state {
struct smbcli_socket *sock;
struct smbcli_transport *transport;
struct smbcli_session *session;
- struct smb_composite_connectmulti *conn;
struct smb_composite_connect *io;
union smb_tcon *io_tcon;
struct smb_composite_sesssetup *io_setup;
@@ -73,7 +72,7 @@ static NTSTATUS connect_send_negprot(struct composite_context *c,
/*
- a tree connect request has competed
+ a tree connect request has completed
*/
static NTSTATUS connect_tcon(struct composite_context *c,
struct smb_composite_connect *io)
@@ -232,7 +231,7 @@ static NTSTATUS connect_session_setup(struct composite_context *c,
}
/*
- a negprot request has competed
+ a negprot request has completed
*/
static NTSTATUS connect_negprot(struct composite_context *c,
struct smb_composite_connect *io)
@@ -271,7 +270,7 @@ static NTSTATUS connect_negprot(struct composite_context *c,
/*
- a session request operation has competed
+ a session request operation has completed
*/
static NTSTATUS connect_session_request(struct composite_context *c,
struct smb_composite_connect *io)
@@ -287,7 +286,7 @@ static NTSTATUS connect_session_request(struct composite_context *c,
}
/*
- a socket connection operation has competed
+ a socket connection operation has completed
*/
static NTSTATUS connect_socket(struct composite_context *c,
struct smb_composite_connect *io)
@@ -296,11 +295,9 @@ static NTSTATUS connect_socket(struct composite_context *c,
NTSTATUS status;
struct nbt_name calling, called;
- status = smb_composite_connectmulti_recv(state->creq, state);
+ status = smbcli_sock_connect_recv(state->creq, state, &state->sock);
NT_STATUS_NOT_OK_RETURN(status);
- state->sock = state->conn->out.socket;
-
/* the socket is up - we can initialise the smbcli transport layer */
state->transport = smbcli_transport_init(state->sock, state, True);
NT_STATUS_HAVE_NO_MEMORY(state->transport);
@@ -339,37 +336,12 @@ static NTSTATUS connect_resolve(struct composite_context *c,
struct connect_state *state = talloc_get_type(c->private_data, struct connect_state);
NTSTATUS status;
const char *address;
- struct smb_composite_connectmulti *conn;
status = resolve_name_recv(state->creq, state, &address);
NT_STATUS_NOT_OK_RETURN(status);
- conn = talloc(state, struct smb_composite_connectmulti);
- NT_STATUS_HAVE_NO_MEMORY(conn);
- state->conn = conn;
- conn->in.num_dests = 1;
-
- conn->in.addresses = talloc_array(state->conn, const char *, 1);
- NT_STATUS_HAVE_NO_MEMORY(conn->in.addresses);
- conn->in.addresses[0] = address;
-
- conn->in.hostnames = talloc_array(state->conn, const char *, 1);
- NT_STATUS_HAVE_NO_MEMORY(conn->in.hostnames);
- if (state->io->in.called_name != NULL) {
- conn->in.hostnames[0] = state->io->in.called_name;
- } else {
- conn->in.hostnames[0] = state->io->in.dest_host;
- }
-
- conn->in.ports = NULL;
- if (state->io->in.port != 0) {
- conn->in.ports = talloc_array(state->conn, int, 1);
- NT_STATUS_HAVE_NO_MEMORY(conn->in.ports);
- conn->in.ports[0] = state->io->in.port;
- }
-
- state->creq = smb_composite_connectmulti_send(conn, state,
- c->event_ctx);
+ state->creq = smbcli_sock_connect_send(state, address, io->in.port,
+ io->in.dest_host, c->event_ctx);
NT_STATUS_HAVE_NO_MEMORY(state->creq);
state->stage = CONNECT_SOCKET;
diff --git a/source4/libcli/smb_composite/connect_multi.c b/source4/libcli/smb_composite/connect_multi.c
deleted file mode 100644
index a539ba4bc6..0000000000
--- a/source4/libcli/smb_composite/connect_multi.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- Copyright (C) Volker Lendecke
-
- 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.
-*/
-/*
- a composite API to fire connect calls to multiple targets, picking the first
- one.
-*/
-
-#include "includes.h"
-#include "libcli/raw/libcliraw.h"
-#include "libcli/composite/composite.h"
-#include "libcli/smb_composite/smb_composite.h"
-
-struct connectmulti_state {
- struct smb_composite_connectmulti *io;
- struct composite_context *creq;
- struct smbcli_socket *result;
- int num_socks, socks_left;
- struct smbcli_socket **socks;
- struct composite_context **creqs;
-};
-
-static void connect_receive(struct composite_context *c)
-
-{
- struct connectmulti_state *state =
- talloc_get_type(c->async.private_data,
- struct connectmulti_state);
- int i;
-
- for (i=0; i<state->num_socks; i++) {
- if (state->creqs[i] == c) {
- break;
- }
- }
-
- if (i == state->num_socks) {
- c->status = NT_STATUS_INTERNAL_ERROR;
- c->state = COMPOSITE_STATE_ERROR;
- if (state->creq->async.fn != NULL) {
- state->creq->async.fn(state->creq);
- }
- return;
- }
-
- state->creq->status = smbcli_sock_connect_recv(c);
- if (!NT_STATUS_IS_OK(state->creq->status)) {
- talloc_free(state->socks[i]);
- state->socks[i] = NULL;
- state->creqs[i] = NULL;
- state->socks_left -= 1;
- if (state->socks_left == 0) {
- state->creq->state = COMPOSITE_STATE_ERROR;
- if (state->creq->async.fn != NULL) {
- state->creq->async.fn(state->creq);
- }
- }
- return;
- }
-
- state->result = talloc_steal(state, state->socks[i]);
- talloc_free(state->socks);
-
- state->creq->state = COMPOSITE_STATE_DONE;
- if (state->creq->async.fn != NULL) {
- state->creq->async.fn(state->creq);
- }
-}
-
-struct composite_context *smb_composite_connectmulti_send(struct smb_composite_connectmulti *io,
- TALLOC_CTX *mem_ctx,
- struct event_context *event_ctx)
-{
- struct composite_context *c;
- struct connectmulti_state *state;
- int num_socks = io->in.num_dests;
- const char **hostnames = io->in.hostnames;
- const char **addresses = io->in.addresses;
- int *ports = io->in.ports;
- int i;
-
- c = talloc_zero(mem_ctx, struct composite_context);
- if (c == NULL) goto failed;
-
- state = talloc(c, struct connectmulti_state);
- if (state == NULL) goto failed;
-
- c->state = COMPOSITE_STATE_IN_PROGRESS;
- c->event_ctx = talloc_reference(c, event_ctx);
- c->private_data = state;
-
- if (ports == NULL) {
- int j, nports;
- const char **smb_ports = lp_smb_ports();
-
- for (nports=0; smb_ports[nports]; nports++) /* noop */;
-
- num_socks *= nports;
- hostnames = talloc_array(state, const char *, num_socks);
- if (hostnames == NULL) goto failed;
- addresses = talloc_array(state, const char *, num_socks);
- if (addresses == NULL) goto failed;
- ports = talloc_array(state, int, num_socks);
- if (ports == NULL) goto failed;
-
- for (i=0; i<io->in.num_dests; i++) {
- for (j=0; j<nports; j++) {
- hostnames[i*nports+j] = io->in.hostnames[i];
- addresses[i*nports+j] = io->in.addresses[i];
- ports[i*nports+j] = atoi(smb_ports[j]);
- }
- }
- }
-
- state->io = io;
- state->creq = c;
- state->num_socks = num_socks;
- state->socks_left = num_socks;
- state->socks = talloc_array(state, struct smbcli_socket *, num_socks);
- state->creqs = talloc_array(state, struct composite_context *,
- num_socks);
- if ((state->socks == NULL) || (state->creqs == NULL)) goto failed;
-
- for (i=0; i<num_socks; i++) {
- state->socks[i] = smbcli_sock_init(state->socks, event_ctx);
- if (state->socks[i] == NULL) goto failed;
-
- /* If the event_ctx we got given is NULL, the first socket
- * creates one and all others need to refer to it. */
- event_ctx = state->socks[i]->event.ctx;
-
- state->creqs[i] = smbcli_sock_connect_send(state->socks[i],
- addresses[i],
- ports[i],
- hostnames[i]);
- if (state->creqs[i] == NULL) goto failed;
- state->creqs[i]->async.fn = connect_receive;
- state->creqs[i]->async.private_data = state;
- }
-
- return c;
-
- failed:
- talloc_free(c);
- return NULL;
-}
-
-NTSTATUS smb_composite_connectmulti_recv(struct composite_context *c,
- TALLOC_CTX *mem_ctx)
-{
- NTSTATUS status;
- status = composite_wait(c);
-
- if (NT_STATUS_IS_OK(status)) {
- struct connectmulti_state *state =
- talloc_get_type(c->private_data,
- struct connectmulti_state);
- state->io->out.socket = talloc_steal(mem_ctx, state->result);
- }
-
- talloc_free(c);
- return status;
-}
-
-NTSTATUS smb_composite_connectmulti(struct smb_composite_connectmulti *io,
- TALLOC_CTX *mem_ctx,
- struct event_context *ev)
-{
- struct composite_context *c =
- smb_composite_connectmulti_send(io, mem_ctx, ev);
- return smb_composite_connectmulti_recv(c, mem_ctx);
-}