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/composite/connect.c | 47 +++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'source4/libcli/composite') diff --git a/source4/libcli/composite/connect.c b/source4/libcli/composite/connect.c index 891d16b4e6..7e08aab0d5 100644 --- a/source4/libcli/composite/connect.c +++ b/source4/libcli/composite/connect.c @@ -26,7 +26,8 @@ #include "libcli/composite/composite.h" /* the stages of this call */ -enum connect_stage {CONNECT_SOCKET, +enum connect_stage {CONNECT_RESOLVE, + CONNECT_SOCKET, CONNECT_SESSION_REQUEST, CONNECT_NEGPROT, CONNECT_SESSION_SETUP, @@ -209,7 +210,7 @@ static NTSTATUS connect_socket(struct smbcli_composite *c, { struct connect_state *state = talloc_get_type(c->private, struct connect_state); NTSTATUS status; - struct nmb_name calling, called; + struct nbt_name calling, called; status = smbcli_sock_connect_recv(state->creq); NT_STATUS_NOT_OK_RETURN(status); @@ -225,8 +226,11 @@ static NTSTATUS connect_socket(struct smbcli_composite *c, return connect_send_negprot(c, io); } - make_nmb_name(&calling, io->in.calling_name, 0x0); - choose_called_name(&called, io->in.called_name, 0x20); + calling.name = io->in.calling_name; + calling.type = NBT_NAME_CLIENT; + calling.scope = NULL; + + nbt_choose_called_name(state, &called, io->in.called_name, NBT_NAME_SERVER); state->req = smbcli_transport_connect_send(state->transport, &calling, &called); NT_STATUS_HAVE_NO_MEMORY(state->req); @@ -239,6 +243,29 @@ static NTSTATUS connect_socket(struct smbcli_composite *c, } +/* + called when name resolution is finished +*/ +static NTSTATUS connect_resolve(struct smbcli_composite *c, + struct smb_composite_connect *io) +{ + struct connect_state *state = talloc_get_type(c->private, struct connect_state); + NTSTATUS status; + const char *address; + + status = resolve_name_recv(state->creq, state, &address); + NT_STATUS_NOT_OK_RETURN(status); + + state->creq = smbcli_sock_connect_send(state->sock, address, state->io->in.port); + NT_STATUS_HAVE_NO_MEMORY(state->creq); + + c->stage = CONNECT_SOCKET; + state->creq->async.private = c; + state->creq->async.fn = composite_handler; + + return NT_STATUS_OK; +} + /* handle and dispatch state transitions @@ -248,6 +275,9 @@ static void state_handler(struct smbcli_composite *c) struct connect_state *state = talloc_get_type(c->private, struct connect_state); switch (c->stage) { + case CONNECT_RESOLVE: + c->status = connect_resolve(c, state->io); + break; case CONNECT_SOCKET: c->status = connect_socket(c, state->io); break; @@ -301,6 +331,7 @@ struct smbcli_composite *smb_composite_connect_send(struct smb_composite_connect { struct smbcli_composite *c; struct connect_state *state; + struct nbt_name name; c = talloc_zero(NULL, struct smbcli_composite); if (c == NULL) goto failed; @@ -314,11 +345,15 @@ struct smbcli_composite *smb_composite_connect_send(struct smb_composite_connect state->io = io; c->state = SMBCLI_REQUEST_SEND; - c->stage = CONNECT_SOCKET; + c->stage = CONNECT_RESOLVE; c->event_ctx = state->sock->event.ctx; c->private = state; - state->creq = smbcli_sock_connect_send(state->sock, io->in.dest_host, io->in.port); + name.name = io->in.dest_host; + name.type = NBT_NAME_SERVER; + name.scope = NULL; + + state->creq = resolve_name_send(&name, c->event_ctx); if (state->creq == NULL) goto failed; state->creq->async.private = c; -- cgit