Get medieval on our ass about SMB1 file descriptors being 16 bits, not an int.
[nivanova/samba-autobuild/.git] / source3 / torture / scanner.c
index 87c82f8a737986d36a47e98405760c9ac3f0776a..e42e80abca46fe123e33af3897a2c8f6c8191121 100644 (file)
@@ -5,7 +5,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,
@@ -14,8 +14,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -24,6 +23,9 @@
 #define OP_MIN 0
 #define OP_MAX 20
 
+#define DATA_SIZE 1024
+#define PARAM_SIZE 1024
+
 /****************************************************************************
 look for a partial hit
 ****************************************************************************/
@@ -85,14 +87,14 @@ static NTSTATUS try_trans2_len(struct cli_state *cli,
        NTSTATUS ret=NT_STATUS_OK;
 
        ret = try_trans2(cli, op, param, data, param_len,
-                        sizeof(pstring), rparam_len, rdata_len);
+                        DATA_SIZE, rparam_len, rdata_len);
 #if VERBOSE 
        printf("op=%d level=%d ret=%s\n", op, level, nt_errstr(ret));
 #endif
        if (!NT_STATUS_IS_OK(ret)) return ret;
 
        *data_len = 0;
-       while (*data_len < sizeof(pstring)) {
+       while (*data_len < DATA_SIZE) {
                ret = try_trans2(cli, op, param, data, param_len,
                                 *data_len, rparam_len, rdata_len);
                if (NT_STATUS_IS_OK(ret)) break;
@@ -110,13 +112,13 @@ static NTSTATUS try_trans2_len(struct cli_state *cli,
 /****************************************************************************
 check for existance of a trans2 call
 ****************************************************************************/
-static BOOL scan_trans2(struct cli_state *cli, int op, int level, 
+static bool scan_trans2(struct cli_state *cli, int op, int level, 
                        int fnum, int dnum, const char *fname)
 {
        int data_len = 0;
        int param_len = 0;
        unsigned int rparam_len, rdata_len;
-       pstring param, data;
+       char param[PARAM_SIZE], data[DATA_SIZE];
        NTSTATUS status;
 
        memset(data, 0, sizeof(data));
@@ -168,7 +170,7 @@ static BOOL scan_trans2(struct cli_state *cli, int op, int level,
 
        status = try_trans2_len(cli, "newfile", op, level, param, data, param_len, &data_len, 
                                &rparam_len, &rdata_len);
-       cli_unlink(cli, "\\newfile.dat");
+       cli_unlink(cli, "\\newfile.dat", aSYSTEM | aHIDDEN);
        cli_rmdir(cli, "\\newfile.dat");
        if (NT_STATUS_IS_OK(status)) return True;
 
@@ -187,12 +189,12 @@ static BOOL scan_trans2(struct cli_state *cli, int op, int level,
 }
 
 
-BOOL torture_trans2_scan(int dummy)
+bool torture_trans2_scan(int dummy)
 {
        static struct cli_state *cli;
        int op, level;
        const char *fname = "\\scanner.dat";
-       int fnum, dnum;
+       uint16_t fnum, dnum;
 
        printf("starting trans2 scan test\n");
 
@@ -200,9 +202,15 @@ BOOL torture_trans2_scan(int dummy)
                return False;
        }
 
-       fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, 
-                        DENY_NONE);
-       dnum = cli_open(cli, "\\", O_RDONLY, DENY_NONE);
+       if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, 
+                        DENY_NONE, &fnum))) {
+               printf("open of %s failed\n", fname);
+               return false;
+       }
+       if (!NT_STATUS_IS_OK(cli_open(cli, "\\", O_RDONLY, DENY_NONE, &dnum))) {
+               printf("open of \\ failed\n");
+               return false;
+       }
 
        for (op=OP_MIN; op<=OP_MAX; op++) {
                printf("Scanning op=%d\n", op);
@@ -287,14 +295,14 @@ static NTSTATUS try_nttrans_len(struct cli_state *cli,
        NTSTATUS ret=NT_STATUS_OK;
 
        ret = try_nttrans(cli, op, param, data, param_len,
-                        sizeof(pstring), rparam_len, rdata_len);
+                        DATA_SIZE, rparam_len, rdata_len);
 #if VERBOSE 
        printf("op=%d level=%d ret=%s\n", op, level, nt_errstr(ret));
 #endif
        if (!NT_STATUS_IS_OK(ret)) return ret;
 
        *data_len = 0;
-       while (*data_len < sizeof(pstring)) {
+       while (*data_len < DATA_SIZE) {
                ret = try_nttrans(cli, op, param, data, param_len,
                                 *data_len, rparam_len, rdata_len);
                if (NT_STATUS_IS_OK(ret)) break;
@@ -312,13 +320,13 @@ static NTSTATUS try_nttrans_len(struct cli_state *cli,
 /****************************************************************************
 check for existance of a nttrans call
 ****************************************************************************/
-static BOOL scan_nttrans(struct cli_state *cli, int op, int level, 
+static bool scan_nttrans(struct cli_state *cli, int op, int level, 
                        int fnum, int dnum, const char *fname)
 {
        int data_len = 0;
        int param_len = 0;
        unsigned int rparam_len, rdata_len;
-       pstring param, data;
+       char param[PARAM_SIZE], data[DATA_SIZE];
        NTSTATUS status;
 
        memset(data, 0, sizeof(data));
@@ -370,7 +378,7 @@ static BOOL scan_nttrans(struct cli_state *cli, int op, int level,
 
        status = try_nttrans_len(cli, "newfile", op, level, param, data, param_len, &data_len, 
                                &rparam_len, &rdata_len);
-       cli_unlink(cli, "\\newfile.dat");
+       cli_unlink(cli, "\\newfile.dat", aSYSTEM | aHIDDEN);
        cli_rmdir(cli, "\\newfile.dat");
        if (NT_STATUS_IS_OK(status)) return True;
 
@@ -389,12 +397,12 @@ static BOOL scan_nttrans(struct cli_state *cli, int op, int level,
 }
 
 
-BOOL torture_nttrans_scan(int dummy)
+bool torture_nttrans_scan(int dummy)
 {
        static struct cli_state *cli;
        int op, level;
        const char *fname = "\\scanner.dat";
-       int fnum, dnum;
+       uint16_t fnum, dnum;
 
        printf("starting nttrans scan test\n");
 
@@ -402,9 +410,9 @@ BOOL torture_nttrans_scan(int dummy)
                return False;
        }
 
-       fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, 
-                        DENY_NONE);
-       dnum = cli_open(cli, "\\", O_RDONLY, DENY_NONE);
+       cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, 
+                        DENY_NONE, &fnum);
+       cli_open(cli, "\\", O_RDONLY, DENY_NONE, &dnum);
 
        for (op=OP_MIN; op<=OP_MAX; op++) {
                printf("Scanning op=%d\n", op);