s4:librpc: pass smbXcli_{conn,session,tcon} to dcerpc_pipe_open_smb_send()
authorStefan Metzmacher <metze@samba.org>
Thu, 19 Sep 2013 16:16:16 +0000 (18:16 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 7 Jan 2014 07:37:44 +0000 (08:37 +0100)
This will allow it to be used also for smb2 later.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source4/librpc/rpc/dcerpc.h
source4/librpc/rpc/dcerpc_connect.c
source4/librpc/rpc/dcerpc_smb.c

index 67059ac485bb5cdeee6fc5e655f3f33b2ac59705..a298be7fc406383621c715ca3c9b4a2de4bcbb3b 100644 (file)
@@ -153,6 +153,9 @@ struct epm_floor;
 
 struct smbcli_tree;
 struct smb2_tree;
+struct smbXcli_conn;
+struct smbXcli_session;
+struct smbXcli_tcon;
 struct socket_address;
 
 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
index 594e7f743200899ca6b82e952abe9943a6863dbc..089603d1b851f5d8ff29d7221e958f03d7328302 100644 (file)
@@ -29,6 +29,7 @@
 #include "lib/events/events.h"
 #include "libcli/smb2/smb2.h"
 #include "libcli/smb2/smb2_calls.h"
+#include "libcli/smb/smbXcli_base.h"
 #include "librpc/rpc/dcerpc.h"
 #include "librpc/rpc/dcerpc_proto.h"
 #include "auth/credentials/credentials.h"
@@ -38,7 +39,6 @@
 
 struct pipe_np_smb_state {
        struct smb_composite_connect conn;
-       struct smbcli_tree *tree;
        struct dcerpc_pipe_connect io;
 };
 
@@ -69,17 +69,44 @@ static void continue_smb_connect(struct composite_context *ctx)
                                                      struct composite_context);
        struct pipe_np_smb_state *s = talloc_get_type(c->private_data,
                                                      struct pipe_np_smb_state);
-       
+       struct smbcli_tree *t;
+       struct smbXcli_conn *conn;
+       struct smbXcli_session *session;
+       struct smbXcli_tcon *tcon;
+       uint32_t timeout_msec;
+
        /* receive result of smb connect request */
        c->status = smb_composite_connect_recv(ctx, s->io.pipe->conn);
        if (!composite_is_ok(c)) return;
 
        /* prepare named pipe open parameters */
-       s->tree         = s->conn.out.tree;
        s->io.pipe_name = s->io.binding->endpoint;
 
+       t = s->conn.out.tree;
+       conn = t->session->transport->conn;
+       session = t->session->smbXcli;
+       tcon = t->smbXcli;
+       smb1cli_tcon_set_id(tcon, t->tid);
+       timeout_msec = t->session->transport->options.request_timeout * 1000;
+
+       /* if we don't have a binding on this pipe yet, then create one */
+       if (s->io.pipe->binding == NULL) {
+               const char *r = smbXcli_conn_remote_name(conn);
+               char *str;
+               SMB_ASSERT(r != NULL);
+               str = talloc_asprintf(s, "ncacn_np:%s", r);
+               if (composite_nomem(str, c)) return;
+               c->status = dcerpc_parse_binding(s->io.pipe, str,
+                                                &s->io.pipe->binding);
+               talloc_free(str);
+               if (!composite_is_ok(c)) return;
+       }
+
        /* send named pipe open request */
-       open_ctx = dcerpc_pipe_open_smb_send(s->io.pipe, s->tree, s->io.pipe_name);
+       open_ctx = dcerpc_pipe_open_smb_send(s->io.pipe->conn,
+                                            conn, session,
+                                            tcon, timeout_msec,
+                                            s->io.pipe_name);
        if (composite_nomem(open_ctx, c)) return;
 
        composite_continue(c, open_ctx, continue_pipe_open_smb, c);
index 12a2407b28099dc4c545e8bd024e60897da233f2..8acc26f56f1bfa81dc60b1b36303ef3330906533 100644 (file)
@@ -37,12 +37,18 @@ struct smb_private {
        DATA_BLOB session_key;
        const char *server_name;
 
-       struct smbcli_tree *tree;
-
        struct tstream_context *stream;
        struct tevent_queue *write_queue;
        struct tevent_req *read_subreq;
        uint32_t pending_reads;
+
+       /*
+        * these are needed to open a secondary connection
+        */
+       struct smbXcli_conn *conn;
+       struct smbXcli_session *session;
+       struct smbXcli_tcon *tcon;
+       uint32_t timeout_msec;
 };
 
 
@@ -422,37 +428,18 @@ struct dcerpc_pipe_open_smb_state {
 
 static void dcerpc_pipe_open_smb_done(struct tevent_req *subreq);
 
-struct composite_context *dcerpc_pipe_open_smb_send(struct dcerpc_pipe *p, 
-                                                   struct smbcli_tree *tree,
-                                                   const char *pipe_name)
+struct composite_context *dcerpc_pipe_open_smb_send(struct dcecli_connection *c,
+                                               struct smbXcli_conn *conn,
+                                               struct smbXcli_session *session,
+                                               struct smbXcli_tcon *tcon,
+                                               uint32_t timeout_msec,
+                                               const char *pipe_name)
 {
        struct composite_context *ctx;
        struct dcerpc_pipe_open_smb_state *state;
-       struct dcecli_connection *c = p->conn;
-       struct smbXcli_conn *conn = tree->session->transport->conn;
-       struct smbXcli_session *session = tree->session->smbXcli;
-       struct smbXcli_tcon *tcon = tree->smbXcli;
-       uint16_t pid = tree->session->pid;
-       uint32_t timeout_msec = tree->session->transport->options.request_timeout * 1000;
+       uint16_t pid = 0;
        struct tevent_req *subreq;
 
-       /* if we don't have a binding on this pipe yet, then create one */
-       if (p->binding == NULL) {
-               NTSTATUS status;
-               const char *r = smbXcli_conn_remote_name(conn);
-               char *s;
-               SMB_ASSERT(r != NULL);
-               s = talloc_asprintf(p, "ncacn_np:%s", r);
-               if (s == NULL) return NULL;
-               status = dcerpc_parse_binding(p, s, &p->binding);
-               talloc_free(s);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return NULL;
-               }
-       }
-
-       smb1cli_tcon_set_id(tree->smbXcli, tree->tid);
-
        ctx = composite_create(c, c->event_ctx);
        if (ctx == NULL) return NULL;
 
@@ -477,7 +464,10 @@ struct composite_context *dcerpc_pipe_open_smb_send(struct dcerpc_pipe *p,
        state->smb = talloc_zero(state, struct smb_private);
        if (composite_nomem(state->smb, ctx)) return ctx;
 
-       state->smb->tree = tree;
+       state->smb->conn = conn;
+       state->smb->session = session;
+       state->smb->tcon = tcon;
+       state->smb->timeout_msec = timeout_msec;
 
        state->smb->server_name = strupper_talloc(state->smb,
                smbXcli_conn_remote_name(conn));
@@ -556,11 +546,47 @@ NTSTATUS dcerpc_pipe_open_smb_recv(struct composite_context *c)
 }
 
 _PUBLIC_ NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p,
-                             struct smbcli_tree *tree,
+                             struct smbcli_tree *t,
                              const char *pipe_name)
 {
-       struct composite_context *ctx = dcerpc_pipe_open_smb_send(p, tree,
-                                                                 pipe_name);
+       struct smbXcli_conn *conn;
+       struct smbXcli_session *session;
+       struct smbXcli_tcon *tcon;
+       uint32_t timeout_msec;
+       struct composite_context *ctx;
+
+       conn = t->session->transport->conn;
+       session = t->session->smbXcli;
+       tcon = t->smbXcli;
+       smb1cli_tcon_set_id(tcon, t->tid);
+       timeout_msec = t->session->transport->options.request_timeout * 1000;
+
+       /* if we don't have a binding on this pipe yet, then create one */
+       if (p->binding == NULL) {
+               NTSTATUS status;
+               const char *r = smbXcli_conn_remote_name(conn);
+               char *str;
+               SMB_ASSERT(r != NULL);
+               str = talloc_asprintf(p, "ncacn_np:%s", r);
+               if (str == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+               status = dcerpc_parse_binding(p, str,
+                                             &p->binding);
+               talloc_free(str);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+       }
+
+       ctx = dcerpc_pipe_open_smb_send(p->conn,
+                                       conn, session,
+                                       tcon, timeout_msec,
+                                       pipe_name);
+       if (ctx == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
        return dcerpc_pipe_open_smb_recv(ctx);
 }
 
@@ -575,7 +601,12 @@ struct composite_context *dcerpc_secondary_smb_send(struct dcecli_connection *c1
        smb = talloc_get_type(c1->transport.private_data, struct smb_private);
        if (!smb) return NULL;
 
-       return dcerpc_pipe_open_smb_send(p2, smb->tree, pipe_name);
+       return dcerpc_pipe_open_smb_send(p2->conn,
+                                        smb->conn,
+                                        smb->session,
+                                        smb->tcon,
+                                        smb->timeout_msec,
+                                        pipe_name);
 }
 
 NTSTATUS dcerpc_secondary_smb_recv(struct composite_context *c)