libcli/smb: add max_credits arg to smbXcli_negprot_send()
authorRalph Boehme <slow@samba.org>
Mon, 27 Feb 2017 15:14:39 +0000 (16:14 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 3 Mar 2017 20:55:27 +0000 (21:55 +0100)
This allows source4/torture code to set the option for tests by
preparing a struct smbcli_options with max_credits set to some value and
pass that to a torture_smb2_connection_ext().

This will be used in subsequent smbtorture test for SMB2 creditting.

Behaviour of existing upper layers is unchanged, they simply pass the
wanted max credits value to smbXcli_negprot_send() instead of
retrofitting it with a call to smb2cli_conn_set_max_credits().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
libcli/smb/smbXcli_base.c
libcli/smb/smbXcli_base.h
source3/libsmb/cliconnect.c
source3/torture/torture.c
source4/libcli/raw/libcliraw.h
source4/libcli/raw/rawnegotiate.c
source4/libcli/smb2/connect.c
source4/param/loadparm.c

index a7b24f014977021fd9711ea8a3301624dc2f5264..70285e6317367937c3ffcb435241fd5acfacb272 100644 (file)
@@ -4092,7 +4092,8 @@ struct tevent_req *smbXcli_negprot_send(TALLOC_CTX *mem_ctx,
                                        struct smbXcli_conn *conn,
                                        uint32_t timeout_msec,
                                        enum protocol_types min_protocol,
-                                       enum protocol_types max_protocol)
+                                       enum protocol_types max_protocol,
+                                       uint16_t max_credits)
 {
        struct tevent_req *req, *subreq;
        struct smbXcli_negprot_state *state;
@@ -4125,6 +4126,10 @@ struct tevent_req *smbXcli_negprot_send(TALLOC_CTX *mem_ctx,
        conn->max_protocol = max_protocol;
        conn->protocol = PROTOCOL_NONE;
 
+       if (max_protocol >= PROTOCOL_SMB2_02) {
+               conn->smb2.max_credits = max_credits;
+       }
+
        if ((min_protocol < PROTOCOL_SMB2_02) &&
            (max_protocol < PROTOCOL_SMB2_02)) {
                /*
@@ -4147,16 +4152,6 @@ struct tevent_req *smbXcli_negprot_send(TALLOC_CTX *mem_ctx,
                 */
                conn->dispatch_incoming = smb2cli_conn_dispatch_incoming;
 
-               /*
-                * As we're starting with an SMB2 negprot, emulate Windows
-                * and ask for 31 credits in the initial SMB2 negprot.
-                * If we don't and leave requested credits at
-                * zero, MacOSX servers return zero credits on
-                * the negprot reply and we fail to connect.
-                */
-               smb2cli_conn_set_max_credits(conn,
-                       WINDOWS_CLIENT_PURE_SMB2_NEGPROT_INITIAL_CREDIT_ASK);
-
                subreq = smbXcli_negprot_smb2_subreq(state);
                if (tevent_req_nomem(subreq, req)) {
                        return tevent_req_post(req, ev);
@@ -5137,7 +5132,8 @@ NTSTATUS smbXcli_negprot(struct smbXcli_conn *conn,
                goto fail;
        }
        req = smbXcli_negprot_send(frame, ev, conn, timeout_msec,
-                                  min_protocol, max_protocol);
+                                  min_protocol, max_protocol,
+                                  WINDOWS_CLIENT_PURE_SMB2_NEGPROT_INITIAL_CREDIT_ASK);
        if (req == NULL) {
                goto fail;
        }
index 702eedf5dbae6f639e5d693a35af17cd5016c2be..6041ae53d078474af5b56b79a7fb14b90a83ea8a 100644 (file)
@@ -436,7 +436,8 @@ struct tevent_req *smbXcli_negprot_send(TALLOC_CTX *mem_ctx,
                                        struct smbXcli_conn *conn,
                                        uint32_t timeout_msec,
                                        enum protocol_types min_protocol,
-                                       enum protocol_types max_protocol);
+                                       enum protocol_types max_protocol,
+                                       uint16_t max_credits);
 NTSTATUS smbXcli_negprot_recv(struct tevent_req *req);
 NTSTATUS smbXcli_negprot(struct smbXcli_conn *conn,
                         uint32_t timeout_msec,
index a9451fbd57152faad6d0a7bf78127857f3cbca1a..029c3d4760ecf3756340b2c762af309a3303db34 100644 (file)
@@ -39,6 +39,7 @@
 #include "../libcli/smb/smbXcli_base.h"
 #include "../libcli/smb/smb_seal.h"
 #include "lib/param/param.h"
+#include "../libcli/smb/smb2_negotiate_context.h"
 
 #define STAR_SMBSERVER "*SMBSERVER"
 
@@ -2754,7 +2755,8 @@ static void cli_start_connection_connected(struct tevent_req *subreq)
        subreq = smbXcli_negprot_send(state, state->ev, state->cli->conn,
                                      state->cli->timeout,
                                      state->min_protocol,
-                                     state->max_protocol);
+                                     state->max_protocol,
+                                     WINDOWS_CLIENT_PURE_SMB2_NEGPROT_INITIAL_CREDIT_ASK);
        if (tevent_req_nomem(subreq, req)) {
                return;
        }
index 2c10ae87e8e3e4a8735dd2bec94e8f5bd4c9538e..dbbd072c679756389ca23184de481c82c224721f 100644 (file)
@@ -2990,7 +2990,7 @@ static bool run_negprot_nowait(int dummy)
                struct tevent_req *req;
 
                req = smbXcli_negprot_send(ev, ev, cli->conn, cli->timeout,
-                                          PROTOCOL_CORE, PROTOCOL_NT1);
+                                          PROTOCOL_CORE, PROTOCOL_NT1, 0);
                if (req == NULL) {
                        TALLOC_FREE(ev);
                        return false;
index 8220cd7c563513f05fb5c8a82c50e0f2b30d85b5..96dfcd4c76524592da147e9e7a74fddd13abc30c 100644 (file)
@@ -103,6 +103,7 @@ struct smbcli_options {
        enum smb_signing_setting signing;
        uint32_t smb2_capabilities;
        struct GUID client_guid;
+       uint64_t max_credits;
 };
 
 /* this is the context for the client transport layer */
index 4b42c2662a0ffd2453b65c7f25ae714022446c98..f6a189ff8d7157ad2b38c746fd8725d2ea289fb3 100644 (file)
@@ -60,7 +60,8 @@ struct tevent_req *smb_raw_negotiate_send(TALLOC_CTX *mem_ctx,
                                      transport->conn,
                                      timeout_msec,
                                      minprotocol,
-                                     maxprotocol);
+                                     maxprotocol,
+                                     transport->options.max_credits);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
index 1a6ae34d2cd9a98f3ba8bc69126add43e20cff57..8ff56c9ca8f81886690ea561c56f3019e80eba25 100644 (file)
@@ -155,7 +155,8 @@ static void smb2_connect_socket_done(struct composite_context *creq)
        subreq = smbXcli_negprot_send(state, state->ev,
                                      state->transport->conn, timeout_msec,
                                      min_protocol,
-                                     state->transport->options.max_protocol);
+                                     state->transport->options.max_protocol,
+                                     state->transport->options.max_credits);
        if (tevent_req_nomem(subreq, req)) {
                return;
        }
@@ -181,9 +182,6 @@ static void smb2_connect_negprot_done(struct tevent_req *subreq)
                return;
        }
 
-       /* This is a hack... */
-       smb2cli_conn_set_max_credits(transport->conn, 30);
-
        state->session = smb2_session_init(transport, state->gensec_settings, state);
        if (tevent_req_nomem(state->session, req)) {
                return;
index f53b2dd1807b2d325f9846ee62e828a8240d21dd..1044a07ee300b56e6bbda40592d0c7b1fe29c529 100644 (file)
@@ -30,6 +30,7 @@
 #include "lib/param/param.h"
 #include "libcli/raw/libcliraw.h"
 #include "librpc/ndr/libndr.h"
+#include "libcli/smb/smb2_negotiate_context.h"
 
 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
                         struct smbcli_options *options)
@@ -47,6 +48,7 @@ void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
        options->use_level2_oplocks = true;
        options->smb2_capabilities = SMB2_CAP_ALL;
        options->client_guid = GUID_random();
+       options->max_credits = WINDOWS_CLIENT_PURE_SMB2_NEGPROT_INITIAL_CREDIT_ASK;
 }
 
 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,