r15162: Patch for bug #3668. Windows has a bug with LARGE_READX
authorJeremy Allison <jra@samba.org>
Sat, 22 Apr 2006 02:33:11 +0000 (02:33 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:16:27 +0000 (11:16 -0500)
where if you ask for exactly 64k bytes it returns 0.
Jeremy.
(This used to be commit dcef65acb5bc08ea4b61ef490a518b7e668ff2ee)

source3/include/client.h
source3/libsmb/cliconnect.c
source3/libsmb/clireadwrite.c

index 30e0fae87441ad1f449ed5a2862f7b9c363a8dcf..c6d7b162fcd311c97f62801e37f3b7d8e352dbb2 100644 (file)
@@ -27,7 +27,8 @@
    overlap on the wire. This size gives us a nice read/write size, which
    will be a multiple of the page size on almost any system */
 #define CLI_BUFFER_SIZE (0xFFFF)
    overlap on the wire. This size gives us a nice read/write size, which
    will be a multiple of the page size on almost any system */
 #define CLI_BUFFER_SIZE (0xFFFF)
-#define CLI_MAX_LARGE_READX_SIZE (127*1024)
+#define CLI_SAMBA_MAX_LARGE_READX_SIZE (127*1024) /* Works for Samba servers */
+#define CLI_WINDOWS_MAX_LARGE_READX_SIZE ((64*1024)-2) /* Windows servers are broken.... */
 
 /*
  * These definitions depend on smb.h
 
 /*
  * These definitions depend on smb.h
@@ -143,6 +144,7 @@ struct cli_state {
        unsigned int bufsize;
        int initialised;
        int win95;
        unsigned int bufsize;
        int initialised;
        int win95;
+       BOOL is_samba;
        uint32 capabilities;
        BOOL dfsroot;
 
        uint32 capabilities;
        BOOL dfsroot;
 
index 48885f19d8413af26cbbc0422d9d067731677c6d..6b5de6d1439b6d29f1341cd274f43926c28c9436 100644 (file)
@@ -199,6 +199,10 @@ static BOOL cli_session_setup_guest(struct cli_state *cli)
        p += clistr_pull(cli, cli->server_type, p, sizeof(fstring), -1, STR_TERMINATE);
        p += clistr_pull(cli, cli->server_domain, p, sizeof(fstring), -1, STR_TERMINATE);
 
        p += clistr_pull(cli, cli->server_type, p, sizeof(fstring), -1, STR_TERMINATE);
        p += clistr_pull(cli, cli->server_domain, p, sizeof(fstring), -1, STR_TERMINATE);
 
+       if (strstr(cli->server_type, "Samba")) {
+               cli->is_samba = True;
+       }
+
        fstrcpy(cli->user_name, "");
 
        return True;
        fstrcpy(cli->user_name, "");
 
        return True;
@@ -263,6 +267,10 @@ static BOOL cli_session_setup_plaintext(struct cli_state *cli, const char *user,
        p += clistr_pull(cli, cli->server_domain, p, sizeof(fstring), -1, STR_TERMINATE);
        fstrcpy(cli->user_name, user);
 
        p += clistr_pull(cli, cli->server_domain, p, sizeof(fstring), -1, STR_TERMINATE);
        fstrcpy(cli->user_name, user);
 
+       if (strstr(cli->server_type, "Samba")) {
+               cli->is_samba = True;
+       }
+
        return True;
 }
 
        return True;
 }
 
@@ -408,6 +416,10 @@ static BOOL cli_session_setup_nt1(struct cli_state *cli, const char *user,
        p += clistr_pull(cli, cli->server_type, p, sizeof(fstring), -1, STR_TERMINATE);
        p += clistr_pull(cli, cli->server_domain, p, sizeof(fstring), -1, STR_TERMINATE);
 
        p += clistr_pull(cli, cli->server_type, p, sizeof(fstring), -1, STR_TERMINATE);
        p += clistr_pull(cli, cli->server_domain, p, sizeof(fstring), -1, STR_TERMINATE);
 
+       if (strstr(cli->server_type, "Samba")) {
+               cli->is_samba = True;
+       }
+
        fstrcpy(cli->user_name, user);
 
        if (session_key.data) {
        fstrcpy(cli->user_name, user);
 
        if (session_key.data) {
@@ -873,6 +885,10 @@ BOOL cli_session_setup(struct cli_state *cli,
                }
        }
 
                }
        }
 
+       if (strstr(cli->server_type, "Samba")) {
+               cli->is_samba = True;
+       }
+
        return True;
 
 }
        return True;
 
 }
@@ -1159,9 +1175,9 @@ BOOL cli_negprot(struct cli_state *cli)
                if (cli->capabilities & (CAP_LARGE_READX|CAP_LARGE_WRITEX)) {
                        SAFE_FREE(cli->outbuf);
                        SAFE_FREE(cli->inbuf);
                if (cli->capabilities & (CAP_LARGE_READX|CAP_LARGE_WRITEX)) {
                        SAFE_FREE(cli->outbuf);
                        SAFE_FREE(cli->inbuf);
-                       cli->outbuf = (char *)SMB_MALLOC(CLI_MAX_LARGE_READX_SIZE+SAFETY_MARGIN);
-                       cli->inbuf = (char *)SMB_MALLOC(CLI_MAX_LARGE_READX_SIZE+SAFETY_MARGIN);
-                       cli->bufsize = CLI_MAX_LARGE_READX_SIZE;
+                       cli->outbuf = (char *)SMB_MALLOC(CLI_SAMBA_MAX_LARGE_READX_SIZE+SAFETY_MARGIN);
+                       cli->inbuf = (char *)SMB_MALLOC(CLI_SAMBA_MAX_LARGE_READX_SIZE+SAFETY_MARGIN);
+                       cli->bufsize = CLI_SAMBA_MAX_LARGE_READX_SIZE;
                }
 
        } else if (cli->protocol >= PROTOCOL_LANMAN1) {
                }
 
        } else if (cli->protocol >= PROTOCOL_LANMAN1) {
index 650822bf8edbfaceab07331f439b20b0acffb918..883bc1260d6c492dcfb4efb5f1146ccbdfde0cd6 100644 (file)
@@ -76,7 +76,11 @@ ssize_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_
         */
 
        if (cli->capabilities & CAP_LARGE_READX) {
         */
 
        if (cli->capabilities & CAP_LARGE_READX) {
-               readsize = CLI_MAX_LARGE_READX_SIZE;
+               if (cli->is_samba) {
+                       readsize = CLI_SAMBA_MAX_LARGE_READX_SIZE;
+               } else {
+                       readsize = CLI_WINDOWS_MAX_LARGE_READX_SIZE;
+               }
        } else {
                readsize = (cli->max_xmit - (smb_size+32)) & ~1023;
        }
        } else {
                readsize = (cli->max_xmit - (smb_size+32)) & ~1023;
        }