libcli/smb: pass smbXcli_tcon to smb2cli_req_create/send()
authorStefan Metzmacher <metze@samba.org>
Wed, 25 Jul 2012 08:36:27 +0000 (10:36 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 25 Jul 2012 10:15:04 +0000 (12:15 +0200)
metze

14 files changed:
libcli/smb/smb2cli_close.c
libcli/smb/smb2cli_create.c
libcli/smb/smb2cli_flush.c
libcli/smb/smb2cli_ioctl.c
libcli/smb/smb2cli_query_directory.c
libcli/smb/smb2cli_query_info.c
libcli/smb/smb2cli_read.c
libcli/smb/smb2cli_session.c
libcli/smb/smb2cli_set_info.c
libcli/smb/smb2cli_write.c
libcli/smb/smbXcli_base.c
libcli/smb/smbXcli_base.h
source3/libsmb/smb2cli_tcon.c
source4/libcli/smb2/transport.c

index 42ed65a5de29c1edd6e1d6554096d767d9962df8..05877702baacff328f1efc1399a8cd60bed14d8f 100644 (file)
@@ -42,7 +42,6 @@ struct tevent_req *smb2cli_close_send(TALLOC_CTX *mem_ctx,
        struct tevent_req *req, *subreq;
        struct smb2cli_close_state *state;
        uint8_t *fixed;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_close_state);
@@ -55,15 +54,11 @@ struct tevent_req *smb2cli_close_send(TALLOC_CTX *mem_ctx,
        SBVAL(fixed, 8, fid_persistent);
        SBVAL(fixed, 16, fid_volatile);
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_CLOSE,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  NULL, 0);
index 33af378f90701856ff7c968b3c1a8cae938a92ec..350c2e508152d656352db7043fa987764ce826b6 100644 (file)
@@ -70,7 +70,6 @@ struct tevent_req *smb2cli_create_send(
        size_t blobs_offset;
        uint8_t *dyn;
        size_t dyn_len;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_create_state);
@@ -138,15 +137,11 @@ struct tevent_req *smb2cli_create_send(
                data_blob_free(&blob);
        }
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_CREATE,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  dyn, dyn_len);
index ca7a0fe8baba64a887c92c2e8bd82589b3026f82..60ae04da4019d71eafee5d4d35452ee6299bc77e 100644 (file)
@@ -41,7 +41,6 @@ struct tevent_req *smb2cli_flush_send(TALLOC_CTX *mem_ctx,
        struct tevent_req *req, *subreq;
        struct smb2cli_flush_state *state;
        uint8_t *fixed;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_flush_state);
@@ -53,15 +52,11 @@ struct tevent_req *smb2cli_flush_send(TALLOC_CTX *mem_ctx,
        SBVAL(fixed, 8, fid_persistent);
        SBVAL(fixed, 16, fid_volatile);
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_FLUSH,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  NULL, 0);
index 03296c69f62200768a40166fc0d0a9f3b9bb07fc..751f26dacff34951620d789ca49eaabdfd73e879 100644 (file)
@@ -61,7 +61,6 @@ struct tevent_req *smb2cli_ioctl_send(TALLOC_CTX *mem_ctx,
        uint32_t output_buffer_offset = 0;
        uint32_t output_buffer_length = 0;
        uint32_t pad_length = 0;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_ioctl_state);
@@ -134,15 +133,11 @@ struct tevent_req *smb2cli_ioctl_send(TALLOC_CTX *mem_ctx,
                dyn_len = sizeof(state->dyn_pad);
        }
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_IOCTL,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  dyn, dyn_len);
index 4ff93de68d0f3fd391e128fa1f70521eb1d77bab..781efbd06640dfce87c5cc5f3d02035fa95583c1 100644 (file)
@@ -52,7 +52,6 @@ struct tevent_req *smb2cli_query_directory_send(TALLOC_CTX *mem_ctx,
        uint8_t *fixed;
        uint8_t *dyn;
        size_t dyn_len;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_query_directory_state);
@@ -88,15 +87,11 @@ struct tevent_req *smb2cli_query_directory_send(TALLOC_CTX *mem_ctx,
                dyn_len = sizeof(state->dyn_pad);
        }
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_FIND,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  dyn, dyn_len);
index b5d9e791aa1abefb07bd2bccf58ca99648faf268..b1664c15854f8508b4edf691827dc3405867fb38 100644 (file)
@@ -55,7 +55,6 @@ struct tevent_req *smb2cli_query_info_send(TALLOC_CTX *mem_ctx,
        size_t dyn_len;
        uint16_t input_buffer_offset = 0;
        uint32_t input_buffer_length = 0;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_query_info_state);
@@ -91,15 +90,11 @@ struct tevent_req *smb2cli_query_info_send(TALLOC_CTX *mem_ctx,
                dyn_len = sizeof(state->dyn_pad);
        }
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_GETINFO,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  dyn, dyn_len);
index 5ff4b6443da97b76d0bb1deb7856a724e05c54d3..35298876bd4400c66855178baeb94decd97e7e36 100644 (file)
@@ -49,7 +49,6 @@ struct tevent_req *smb2cli_read_send(TALLOC_CTX *mem_ctx,
        struct tevent_req *req, *subreq;
        struct smb2cli_read_state *state;
        uint8_t *fixed;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_read_state);
@@ -67,15 +66,11 @@ struct tevent_req *smb2cli_read_send(TALLOC_CTX *mem_ctx,
        SBVAL(fixed, 32, minimum_count);
        SBVAL(fixed, 40, remaining_bytes);
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_READ,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  state->dyn_pad, sizeof(state->dyn_pad));
index 640eb95f0b33b96a8a7dc171a7df4f9ce0e7e55b..946e02cd4829074b7c7350b835fcc9bd670482a4 100644 (file)
@@ -100,7 +100,7 @@ struct tevent_req *smb2cli_session_setup_send(TALLOC_CTX *mem_ctx,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF,
-                                 0, /* tid */
+                                 NULL, /* tcon */
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  dyn, dyn_len);
@@ -257,7 +257,7 @@ struct tevent_req *smb2cli_logoff_send(TALLOC_CTX *mem_ctx,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 0, /* tid */
+                                 NULL, /* tcon */
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  NULL, 0);
index e33ba8367dba04cf40ca57f23252a20e78ef5b7e..e7464e65e8a9a883d914f9e46c20cfab16b4702d 100644 (file)
@@ -50,7 +50,6 @@ struct tevent_req *smb2cli_set_info_send(TALLOC_CTX *mem_ctx,
        size_t dyn_len;
        uint16_t input_buffer_offset = 0;
        uint32_t input_buffer_length = 0;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_set_info_state);
@@ -83,15 +82,11 @@ struct tevent_req *smb2cli_set_info_send(TALLOC_CTX *mem_ctx,
                dyn_len = sizeof(state->dyn_pad);
        }
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_SETINFO,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  dyn, dyn_len);
index cd98e5e723b3564114ee2c8083481fdcfdffde2c..60182c6c138b0f7fea8bb6059395f44a970e6343 100644 (file)
@@ -49,7 +49,6 @@ struct tevent_req *smb2cli_write_send(TALLOC_CTX *mem_ctx,
        uint8_t *fixed;
        const uint8_t *dyn;
        size_t dyn_len;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_write_state);
@@ -76,15 +75,11 @@ struct tevent_req *smb2cli_write_send(TALLOC_CTX *mem_ctx,
                dyn_len = sizeof(state->dyn_pad);
        }
 
-       if (tcon) {
-               tcon_id = smb2cli_tcon_current_id(tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_WRITE,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  0xFEFF, /* pid */
-                                 tcon_id,
+                                 tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
                                  dyn, dyn_len);
index 4c094ea87e4e9740870831bc4fc0d1e4ccd7597e..1b1b92aa0383290e78bc020895bdd121a67299e0 100644 (file)
@@ -2366,9 +2366,9 @@ static bool smb2cli_req_cancel(struct tevent_req *req)
                struct smbXcli_req_state);
        uint32_t flags = IVAL(state->smb2.hdr, SMB2_HDR_FLAGS);
        uint32_t pid = IVAL(state->smb2.hdr, SMB2_HDR_PID);
-       uint32_t tid = IVAL(state->smb2.hdr, SMB2_HDR_TID);
        uint64_t mid = BVAL(state->smb2.hdr, SMB2_HDR_MESSAGE_ID);
        uint64_t aid = BVAL(state->smb2.hdr, SMB2_HDR_ASYNC_ID);
+       struct smbXcli_tcon *tcon = state->tcon;
        struct smbXcli_session *session = state->session;
        uint8_t *fixed = state->smb2.pad;
        uint16_t fixed_len = 4;
@@ -2384,7 +2384,7 @@ static bool smb2cli_req_cancel(struct tevent_req *req)
                                    SMB2_OP_CANCEL,
                                    flags, 0,
                                    0, /* timeout */
-                                   pid, tid, session,
+                                   pid, tcon, session,
                                    fixed, fixed_len,
                                    NULL, 0);
        if (subreq == NULL) {
@@ -2398,7 +2398,6 @@ static bool smb2cli_req_cancel(struct tevent_req *req)
 
        SIVAL(substate->smb2.hdr, SMB2_HDR_FLAGS, flags);
        SIVAL(substate->smb2.hdr, SMB2_HDR_PID, pid);
-       SIVAL(substate->smb2.hdr, SMB2_HDR_TID, tid);
        SBVAL(substate->smb2.hdr, SMB2_HDR_MESSAGE_ID, mid);
        SBVAL(substate->smb2.hdr, SMB2_HDR_ASYNC_ID, aid);
 
@@ -2427,7 +2426,7 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
                                      uint32_t clear_flags,
                                      uint32_t timeout_msec,
                                      uint32_t pid,
-                                     uint32_t tid,
+                                     struct smbXcli_tcon *tcon,
                                      struct smbXcli_session *session,
                                      const uint8_t *fixed,
                                      uint16_t fixed_len,
@@ -2437,6 +2436,7 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
        struct tevent_req *req;
        struct smbXcli_req_state *state;
        uint32_t flags = 0;
+       uint32_t tid = 0;
        uint64_t uid = 0;
 
        req = tevent_req_create(mem_ctx, &state,
@@ -2448,6 +2448,7 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
        state->ev = ev;
        state->conn = conn;
        state->session = session;
+       state->tcon = tcon;
 
        if (session) {
                uid = session->smb2.session_id;
@@ -2455,8 +2456,6 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
                state->smb2.should_sign = session->smb2.should_sign;
                state->smb2.should_encrypt = session->smb2.should_encrypt;
 
-               /* TODO: turn on encryption based on the tree connect. */
-
                if (cmd == SMB2_OP_SESSSETUP &&
                    session->smb2.signing_key.length != 0) {
                        state->smb2.should_sign = true;
@@ -2466,10 +2465,16 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
                    session->smb2.channel_signing_key.length == 0) {
                        state->smb2.should_encrypt = false;
                }
+       }
 
-               if (state->smb2.should_encrypt) {
-                       state->smb2.should_sign = false;
-               }
+       if (tcon) {
+               tid = tcon->smb2.tcon_id;
+
+               /* TODO: turn on encryption based on the tree connect. */
+       }
+
+       if (state->smb2.should_encrypt) {
+               state->smb2.should_sign = false;
        }
 
        state->smb2.recv_iov = talloc_zero_array(state, struct iovec, 3);
@@ -2795,7 +2800,7 @@ struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
                                    uint32_t clear_flags,
                                    uint32_t timeout_msec,
                                    uint32_t pid,
-                                   uint32_t tid,
+                                   struct smbXcli_tcon *tcon,
                                    struct smbXcli_session *session,
                                    const uint8_t *fixed,
                                    uint16_t fixed_len,
@@ -2808,7 +2813,7 @@ struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
        req = smb2cli_req_create(mem_ctx, ev, conn, cmd,
                                 additional_flags, clear_flags,
                                 timeout_msec,
-                                pid, tid, session,
+                                pid, tcon, session,
                                 fixed, fixed_len, dyn, dyn_len);
        if (req == NULL) {
                return NULL;
@@ -3999,7 +4004,7 @@ static struct tevent_req *smbXcli_negprot_smb2_subreq(struct smbXcli_negprot_sta
                                state->conn, SMB2_OP_NEGPROT,
                                0, 0, /* flags */
                                state->timeout_msec,
-                               0xFEFF, 0, NULL, /* pid, tid, session */
+                               0xFEFF, NULL, NULL, /* pid, tcon, session */
                                state->smb2.fixed, sizeof(state->smb2.fixed),
                                state->smb2.dyn, dialect_count*2);
 }
index 665fb9c8ce489b8100c5666c10363b07fe8baed0..0260ab64a7a8a53e6bc67811a2876a4e9a99bbbb 100644 (file)
@@ -201,7 +201,7 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
                                      uint32_t clear_flags,
                                      uint32_t timeout_msec,
                                      uint32_t pid,
-                                     uint32_t tid,
+                                     struct smbXcli_tcon *tcon,
                                      struct smbXcli_session *session,
                                      const uint8_t *fixed,
                                      uint16_t fixed_len,
@@ -225,7 +225,7 @@ struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
                                    uint32_t clear_flags,
                                    uint32_t timeout_msec,
                                    uint32_t pid,
-                                   uint32_t tid,
+                                   struct smbXcli_tcon *tcon,
                                    struct smbXcli_session *session,
                                    const uint8_t *fixed,
                                    uint16_t fixed_len,
index 7271ddaa8e09c7eb4c2f3d74b9e3bb2ecd0cf36c..d2607824ff1327856edad4eb8b2a2ca141b7704a 100644 (file)
@@ -85,7 +85,7 @@ struct tevent_req *smb2cli_tcon_send(TALLOC_CTX *mem_ctx,
                                  0, 0, /* flags */
                                  cli->timeout,
                                  cli->smb2.pid,
-                                 0, /* tid */
+                                 NULL, /* tcon */
                                  cli->smb2.session,
                                  state->fixed, sizeof(state->fixed),
                                  dyn, dyn_len);
@@ -198,7 +198,6 @@ struct tevent_req *smb2cli_tdis_send(TALLOC_CTX *mem_ctx,
 {
        struct tevent_req *req, *subreq;
        struct smb2cli_tdis_state *state;
-       uint32_t tcon_id = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_tdis_state);
@@ -208,15 +207,11 @@ struct tevent_req *smb2cli_tdis_send(TALLOC_CTX *mem_ctx,
        state->cli = cli;
        SSVAL(state->fixed, 0, 4);
 
-       if (cli->smb2.tcon) {
-               tcon_id = smb2cli_tcon_current_id(cli->smb2.tcon);
-       }
-
        subreq = smb2cli_req_send(state, ev, cli->conn, SMB2_OP_TDIS,
                                  0, 0, /* flags */
                                  cli->timeout,
                                  cli->smb2.pid,
-                                 tcon_id,
+                                 cli->smb2.tcon,
                                  cli->smb2.session,
                                  state->fixed, sizeof(state->fixed),
                                  NULL, 0);
index a3845a60cbc255a3423e917a886e695fa5f733d4..423b634765971e0ff05c48dbda35f4d1410bfee8 100644 (file)
@@ -116,7 +116,7 @@ void smb2_transport_send(struct smb2_request *req)
        uint32_t additional_flags = IVAL(req->out.hdr, SMB2_HDR_FLAGS);
        uint32_t clear_flags = 0;
        uint32_t pid = IVAL(req->out.hdr, SMB2_HDR_PID);
-       uint32_t tid = IVAL(req->out.hdr, SMB2_HDR_TID);
+       struct smbXcli_tcon *tcon = NULL;
        struct smbXcli_session *session = NULL;
        bool need_pending_break = false;
        size_t hdr_ofs;
@@ -148,7 +148,7 @@ void smb2_transport_send(struct smb2_request *req)
                                            0, /*clear_flags */
                                            0, /* timeout_msec */
                                            0, /* pid */
-                                           0, /* tid */
+                                           NULL, /* tcon */
                                            NULL, /* session */
                                            NULL, /* body */
                                            0, /* body_fixed */
@@ -167,6 +167,10 @@ void smb2_transport_send(struct smb2_request *req)
                session = req->session->smbXcli;
        }
 
+       if (req->tree) {
+               tcon = req->tree->smbXcli;
+       }
+
        if (transport->compound.related) {
                additional_flags |= SMB2_HDR_FLAG_CHAINED;
        }
@@ -186,7 +190,7 @@ void smb2_transport_send(struct smb2_request *req)
                                         clear_flags,
                                         timeout_msec,
                                         pid,
-                                        tid,
+                                        tcon,
                                         session,
                                         body.data, body.length,
                                         dyn.data, dyn.length);
@@ -342,7 +346,7 @@ static void smb2_transport_break_handler(struct tevent_req *subreq)
                                    0, /*clear_flags */
                                    0, /* timeout_msec */
                                    0, /* pid */
-                                   0, /* tid */
+                                   NULL, /* tcon */
                                    NULL, /* session */
                                    NULL, /* body */
                                    0, /* body_fixed */