r23779: Change from v2 or later to v3 or later.
[amitay/samba.git] / source3 / libsmb / clientgen.c
index 1a4b1f770f50a85040f4b0eebc7f5b6e3e1b447e..282ebb7cb99002dec648439fdbefcaae5ce43471 100644 (file)
@@ -6,7 +6,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -133,7 +133,7 @@ BOOL cli_receive_smb_internal(struct cli_state *cli, BOOL eat_keepalives)
        }
 
        /* If the server is not responding, note that now */
-       if (len <= 0) {
+       if (len < 0) {
                 DEBUG(0, ("Receiving SMB: Server stopped responding\n"));
                cli->smb_rw_error = smb_read_error;
                close(cli->fd);
@@ -234,7 +234,8 @@ BOOL cli_receive_smb_readX_header(struct cli_state *cli)
                        }
 
                        /* Read the rest of the data. */
-                       if (!cli_receive_smb_data(cli,cli->inbuf+len,total_len - len)) {
+                       if ((total_len - len > 0) &&
+                           !cli_receive_smb_data(cli,cli->inbuf+len,total_len - len)) {
                                goto read_err;
                        }
 
@@ -249,30 +250,34 @@ BOOL cli_receive_smb_readX_header(struct cli_state *cli)
                }
        }
 
-       /* Check it's a non-chained readX reply. */
-       if (!(CVAL(cli->inbuf, smb_flg) & FLAG_REPLY) ||
-               (CVAL(cli->inbuf,smb_vwv0) != 0xFF) ||
-               (CVAL(cli->inbuf,smb_com) != SMBreadX)) {
+       /* If it's not the above size it probably was an error packet. */
+
+       if ((len == (smb_size - 4) + 24) && !cli_is_error(cli)) {
+               /* Check it's a non-chained readX reply. */
+               if (!(CVAL(cli->inbuf, smb_flg) & FLAG_REPLY) ||
+                       (CVAL(cli->inbuf,smb_vwv0) != 0xFF) ||
+                       (CVAL(cli->inbuf,smb_com) != SMBreadX)) {
+                       /* 
+                        * We're not coping here with asnyc replies to
+                        * other calls. Punt here - we need async client
+                        * libs for this.
+                        */
+                       goto read_err;
+               }
+
                /* 
-                * We're not coping here with asnyc replies to
-                * other calls. Punt here - we need async client
-                * libs for this.
+                * We know it's a readX reply - ensure we've read the
+                * padding bytes also.
                 */
-               goto read_err;
-       }
 
-       /* 
-        * We know it's a readX reply - ensure we've read the
-        * padding bytes also.
-        */
-
-       offset = SVAL(cli->inbuf,smb_vwv6);
-       if (offset > len) {
-               ssize_t ret;
-               size_t padbytes = offset - len;
-               ret = cli_receive_smb_data(cli,smb_buf(cli->inbuf),padbytes);
-                if (ret != padbytes) {
-                       goto read_err;
+               offset = SVAL(cli->inbuf,smb_vwv6);
+               if (offset > len) {
+                       ssize_t ret;
+                       size_t padbytes = offset - len;
+                       ret = cli_receive_smb_data(cli,smb_buf(cli->inbuf),padbytes);
+                       if (ret != padbytes) {
+                               goto read_err;
+                       }
                }
        }