libcli/smb: pass max_dyn_len to smb2cli_req_send()
authorStefan Metzmacher <metze@samba.org>
Tue, 13 Aug 2013 08:25:52 +0000 (10:25 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 15 Aug 2013 07:07:06 +0000 (09:07 +0200)
This way we can calculate the correct credit charge
for requests with large output buffers.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
15 files changed:
libcli/smb/smb2cli_close.c
libcli/smb/smb2cli_create.c
libcli/smb/smb2cli_echo.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 ed15a203d846ce522b7a4a9f2f145b412f901383..5e3105618a34964a45b28f368340bab5e0e66325 100644 (file)
@@ -60,7 +60,8 @@ struct tevent_req *smb2cli_close_send(TALLOC_CTX *mem_ctx,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 NULL, 0);
+                                 NULL, 0, /* dyn* */
+                                 0); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 020a4685cbcc8ec57903a46c964ff55737ddc030..3f8d67250c149c48bcdb3a4066f491fcb1b34e3f 100644 (file)
@@ -62,6 +62,7 @@ struct tevent_req *smb2cli_create_send(
        size_t blobs_offset;
        uint8_t *dyn;
        size_t dyn_len;
+       size_t max_dyn_len;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_create_state);
@@ -129,13 +130,23 @@ struct tevent_req *smb2cli_create_send(
                data_blob_free(&blob);
        }
 
+       /*
+        * We use max_dyn_len = 0
+        * as we don't explicitly ask for any output length.
+        *
+        * But it's still possible for the server to return
+        * large create blobs.
+        */
+       max_dyn_len = 0;
+
        subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_CREATE,
                                  0, 0, /* flags */
                                  timeout_msec,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 dyn, dyn_len);
+                                 dyn, dyn_len,
+                                 max_dyn_len);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 29cbf26115fba95f221bcfcc423812225a8b7b1a..39c592cebb792c73caa6ac012e303d752d2fa115 100644 (file)
@@ -53,7 +53,8 @@ struct tevent_req *smb2cli_echo_send(TALLOC_CTX *mem_ctx,
                                  NULL, /* tcon */
                                  NULL, /* session */
                                  state->fixed, sizeof(state->fixed),
-                                 NULL, 0);
+                                 NULL, 0, /* dyn* */
+                                 0); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 0ca2699ce3983597e4e2b86e3f2855428100cd53..f014720ad0ef84c2a0ad772a84ced89c75b1fbe4 100644 (file)
@@ -58,7 +58,8 @@ struct tevent_req *smb2cli_flush_send(TALLOC_CTX *mem_ctx,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 NULL, 0);
+                                 NULL, 0, /* dyn* */
+                                 0); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 15a990c2560d00738feb9fa0c5abca9c58ec1057..8de76359a16608affe06ef19242962ddcd45220b 100644 (file)
@@ -61,6 +61,8 @@ 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;
+       uint64_t tmp64;
+       uint32_t max_dyn_len = 0;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smb2cli_ioctl_state);
@@ -70,6 +72,14 @@ struct tevent_req *smb2cli_ioctl_send(TALLOC_CTX *mem_ctx,
        state->max_input_length = in_max_input_length;
        state->max_output_length = in_max_output_length;
 
+       tmp64 = in_max_input_length;
+       tmp64 += in_max_output_length;
+       if (tmp64 > UINT32_MAX) {
+               max_dyn_len = UINT32_MAX;
+       } else {
+               max_dyn_len = tmp64;
+       }
+
        if (in_input_buffer) {
                input_buffer_offset = SMB2_HDR_BODY+0x38;
                input_buffer_length = in_input_buffer->length;
@@ -139,7 +149,8 @@ struct tevent_req *smb2cli_ioctl_send(TALLOC_CTX *mem_ctx,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 dyn, dyn_len);
+                                 dyn, dyn_len,
+                                 max_dyn_len);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 32f5bee0c58caad56050ba6fa3d5ee28f49541ed..bccc52945520c211a7bc5deebb7f6b62c6d656b0 100644 (file)
@@ -93,7 +93,8 @@ struct tevent_req *smb2cli_query_directory_send(TALLOC_CTX *mem_ctx,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 dyn, dyn_len);
+                                 dyn, dyn_len,
+                                 outbuf_len); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 9ec16b5c990b66c317dccc4675b5b2f9bb675790..454f25a1359de844d77d576d02478355b183003d 100644 (file)
@@ -96,7 +96,8 @@ struct tevent_req *smb2cli_query_info_send(TALLOC_CTX *mem_ctx,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 dyn, dyn_len);
+                                 dyn, dyn_len,
+                                 in_max_output_length); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 0adb4037944257d0f747caa9690c2cec4a0e84db..4a3162265f6afa0604b753637dee6a54836b4c2d 100644 (file)
@@ -72,7 +72,8 @@ struct tevent_req *smb2cli_read_send(TALLOC_CTX *mem_ctx,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 state->dyn_pad, sizeof(state->dyn_pad));
+                                 state->dyn_pad, sizeof(state->dyn_pad),
+                                 length); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 537c17111d53f9acbc83da3206095a38f40916b1..4418a0d68fa0cd9da20c6bdb645a122c980f5149 100644 (file)
@@ -102,7 +102,8 @@ struct tevent_req *smb2cli_session_setup_send(TALLOC_CTX *mem_ctx,
                                  NULL, /* tcon */
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 dyn, dyn_len);
+                                 dyn, dyn_len,
+                                 UINT16_MAX); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -258,7 +259,8 @@ struct tevent_req *smb2cli_logoff_send(TALLOC_CTX *mem_ctx,
                                  NULL, /* tcon */
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 NULL, 0);
+                                 NULL, 0, /* dyn* */
+                                 0); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index d5c7e583f1e7903a90aaaf8904f85d77b0619357..687137042839898ee618863fe581fa58b1b4c5e0 100644 (file)
@@ -88,7 +88,8 @@ struct tevent_req *smb2cli_set_info_send(TALLOC_CTX *mem_ctx,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 dyn, dyn_len);
+                                 dyn, dyn_len,
+                                 0); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 89137bd5baf4eab2caf935b86205c76ff75ca906..6d0a0aaaecb76d8bf41f8d3bdc3f90989a068bcc 100644 (file)
@@ -82,7 +82,8 @@ struct tevent_req *smb2cli_write_send(TALLOC_CTX *mem_ctx,
                                  tcon,
                                  session,
                                  state->fixed, sizeof(state->fixed),
-                                 dyn, dyn_len);
+                                 dyn, dyn_len,
+                                 0); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 02716914557ad9a771e8b6f37ae129a89a9579de..2562442f2842bddf56a52a808b438c4d02e75fbb 100644 (file)
@@ -2984,11 +2984,11 @@ struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
                                    const uint8_t *fixed,
                                    uint16_t fixed_len,
                                    const uint8_t *dyn,
-                                   uint32_t dyn_len)
+                                   uint32_t dyn_len,
+                                   uint32_t max_dyn_len)
 {
        struct tevent_req *req;
        NTSTATUS status;
-       uint32_t max_dyn_len = 0;
 
        req = smb2cli_req_create(mem_ctx, ev, conn, cmd,
                                 additional_flags, clear_flags,
@@ -4260,7 +4260,8 @@ static struct tevent_req *smbXcli_negprot_smb2_subreq(struct smbXcli_negprot_sta
                                state->timeout_msec,
                                NULL, NULL, /* tcon, session */
                                state->smb2.fixed, sizeof(state->smb2.fixed),
-                               state->smb2.dyn, dialect_count*2);
+                               state->smb2.dyn, dialect_count*2,
+                               UINT16_MAX); /* max_dyn_len */
 }
 
 static void smbXcli_negprot_smb2_done(struct tevent_req *subreq)
index 017c0f059d51d3bd70f8637678ec0f764cb03959..4ce39c0db14bf6bd7fb40548e48ae0c1a5c0c647 100644 (file)
@@ -242,7 +242,8 @@ struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
                                    const uint8_t *fixed,
                                    uint16_t fixed_len,
                                    const uint8_t *dyn,
-                                   uint32_t dyn_len);
+                                   uint32_t dyn_len,
+                                   uint32_t max_dyn_len);
 NTSTATUS smb2cli_req_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                          struct iovec **piov,
                          const struct smb2cli_req_expected_response *expected,
index ab97f8d0e16f05afcd765b208a19d6df9bc20d66..b3136fac91c2c0773b769a243041ffbdceb41651 100644 (file)
@@ -85,7 +85,8 @@ struct tevent_req *smb2cli_tcon_send(TALLOC_CTX *mem_ctx,
                                  NULL, /* tcon */
                                  cli->smb2.session,
                                  state->fixed, sizeof(state->fixed),
-                                 dyn, dyn_len);
+                                 dyn, dyn_len,
+                                 0); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -211,7 +212,8 @@ struct tevent_req *smb2cli_tdis_send(TALLOC_CTX *mem_ctx,
                                  cli->smb2.tcon,
                                  cli->smb2.session,
                                  state->fixed, sizeof(state->fixed),
-                                 NULL, 0);
+                                 NULL, 0, /* dyn* */
+                                 0); /* max_dyn_len */
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index bdab523f4fbe031f547ff5af51cdc4037ef88c8e..2ad16a912315869470fdf94e6aa54c5531281866 100644 (file)
@@ -151,7 +151,8 @@ void smb2_transport_send(struct smb2_request *req)
                                            NULL, /* body */
                                            0, /* body_fixed */
                                            NULL, /* dyn */
-                                           0); /* dyn_len */
+                                           0, /* dyn_len */
+                                           0); /* max_dyn_len */
                if (subreq != NULL) {
                        smbXcli_req_set_pending(subreq);
                        tevent_req_set_callback(subreq,
@@ -190,7 +191,8 @@ void smb2_transport_send(struct smb2_request *req)
                                         tcon,
                                         session,
                                         body.data, body.length,
-                                        dyn.data, dyn.length);
+                                        dyn.data, dyn.length,
+                                        0); /* max_dyn_len */
        if (req->subreq == NULL) {
                req->state = SMB2_REQUEST_ERROR;
                req->status = NT_STATUS_NO_MEMORY;
@@ -347,7 +349,8 @@ static void smb2_transport_break_handler(struct tevent_req *subreq)
                                    NULL, /* body */
                                    0, /* body_fixed */
                                    NULL, /* dyn */
-                                   0); /* dyn_len */
+                                   0, /* dyn_len */
+                                   0); /* max_dyn_len */
        if (subreq != NULL) {
                smbXcli_req_set_pending(subreq);
                tevent_req_set_callback(subreq,