s4:libcli: allow passing an already negotiated connection to smb_composite_connect()
authorStefan Metzmacher <metze@samba.org>
Wed, 18 Jul 2018 13:34:55 +0000 (15:34 +0200)
committerAlexander Bokovoy <ab@samba.org>
Tue, 24 Jul 2018 04:55:23 +0000 (06:55 +0200)
It will just do the session setup and tree connect steps.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13308

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
source4/libcli/raw/clitree.c
source4/libcli/smb_composite/connect.c
source4/libcli/smb_composite/smb_composite.h
source4/ntvfs/cifs/vfs_cifs.c

index 11be5485f2611e02182fcfca39d1b8e0b2a8cd79..b1b6159e75085989c2a25796636969c98d9571f9 100644 (file)
@@ -207,6 +207,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx,
        io.in.called_name = strupper_talloc(tmp_ctx, dest_host);
        io.in.service = service;
        io.in.service_type = service_type;
+       io.in.existing_conn = NULL;
        io.in.credentials = credentials;
        io.in.gensec_settings = gensec_settings;
        io.in.fallback_to_anonymous = false;
index fffa768ac977c2291dc44a0e0421e49849146f0d..582d43ef1730d4f29767f1b215537a2062400da9 100644 (file)
@@ -228,18 +228,10 @@ static NTSTATUS connect_session_setup(struct composite_context *c,
        return NT_STATUS_OK;
 }
 
-/*
-  a negprot request has completed
-*/
-static NTSTATUS connect_negprot(struct composite_context *c, 
-                               struct smb_composite_connect *io)
+static NTSTATUS connect_send_session(struct composite_context *c,
+                                    struct smb_composite_connect *io)
 {
        struct connect_state *state = talloc_get_type(c->private_data, struct connect_state);
-       NTSTATUS status;
-
-       status = smb_raw_negotiate_recv(state->subreq);
-       TALLOC_FREE(state->subreq);
-       NT_STATUS_NOT_OK_RETURN(status);
 
        /* next step is a session setup */
        state->session = smbcli_session_init(state->transport, state, true, io->in.session_options);
@@ -281,6 +273,22 @@ static NTSTATUS connect_negprot(struct composite_context *c,
        return NT_STATUS_OK;
 }
 
+/*
+  a negprot request has completed
+*/
+static NTSTATUS connect_negprot(struct composite_context *c,
+                               struct smb_composite_connect *io)
+{
+       struct connect_state *state = talloc_get_type(c->private_data, struct connect_state);
+       NTSTATUS status;
+
+       status = smb_raw_negotiate_recv(state->subreq);
+       TALLOC_FREE(state->subreq);
+       NT_STATUS_NOT_OK_RETURN(status);
+
+       return connect_send_session(c, io);
+}
+
 /*
   setup a negprot send 
 */
@@ -432,6 +440,26 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
        nbt_choose_called_name(state, &state->called,
                               io->in.called_name, NBT_NAME_SERVER);
 
+       if (io->in.existing_conn != NULL) {
+               NTSTATUS status;
+
+               status = smbcli_transport_raw_init(state,
+                                                  c->event_ctx,
+                                                  &io->in.existing_conn,
+                                                  &io->in.options,
+                                                  &state->transport);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto failed;
+               }
+
+               status = connect_send_session(c, io);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto failed;
+               }
+
+               return c;
+       }
+
        state->creq = smbcli_sock_connect_send(state, 
                                               NULL,
                                               io->in.dest_ports,
index a92c9612c6ac8854c54cecbadc446cc301184042..383946f1307ad60684c9bf7936c454a3e2ea2420 100644 (file)
@@ -118,6 +118,7 @@ struct smb_composite_connect {
                const char *called_name;
                const char *service;
                const char *service_type;
+               struct smbXcli_conn *existing_conn; /* optional */
                struct cli_credentials *credentials;
                bool fallback_to_anonymous;
                const char *workgroup;
index 478428e324651d14f00f86141b382f06693e3a2d..d88c034c6f2ad9e5e9256138d75ce954b409c39a 100644 (file)
@@ -296,6 +296,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
        io.in.dest_ports = lpcfg_smb_ports(ntvfs->ctx->lp_ctx);
        io.in.socket_options = lpcfg_socket_options(ntvfs->ctx->lp_ctx);
        io.in.called_name = host;
+       io.in.existing_conn = NULL;
        io.in.credentials = credentials;
        io.in.fallback_to_anonymous = false;
        io.in.workgroup = lpcfg_workgroup(ntvfs->ctx->lp_ctx);