r23792: convert Samba4 to GPLv3
[samba.git] / source4 / torture / basic / denytest.c
index 9b9be967b1a27c852a0a562380ee387f4a5d1087..98f4323ce63b9f9c81802053e86470d89c271017 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"
@@ -25,7 +24,6 @@
 #include "libcli/libcli.h"
 #include "torture/util.h"
 
-extern BOOL torture_showall;
 extern int torture_failures;
 
 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
@@ -1401,18 +1399,20 @@ static const struct {
 };
 
 
-static void progress_bar(uint_t i, uint_t total)
+static void progress_bar(struct torture_context *tctx, uint_t i, uint_t total)
 {
-       printf("%5d/%5d\r", i, total);
-       fflush(stdout);
+       if (torture_setting_bool(tctx, "progress", true)) {
+               torture_comment(tctx, "%5d/%5d\r", i, total);
+               fflush(stdout);
+       }
 }
 
 /*
   this produces a matrix of deny mode behaviour for 1 connection
  */
-BOOL torture_denytest1(struct torture_context *torture)
+BOOL torture_denytest1(struct torture_context *tctx, 
+                                          struct smbcli_state *cli1)
 {
-       static struct smbcli_state *cli1;
        int fnum1, fnum2;
        int i;
        BOOL correct = True;
@@ -1420,13 +1420,7 @@ BOOL torture_denytest1(struct torture_context *torture)
        const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"};
        int failures=0;
 
-       if (!torture_open_connection(&cli1)) {
-               return False;
-       }
-
-       printf("starting denytest1\n");
-
-       printf("Testing deny modes with 1 connection\n");
+       torture_comment(tctx, "Testing deny modes with 1 connection\n");
 
        for (i=0;i<2;i++) {
                smbcli_unlink(cli1->tree, fnames[i]);
@@ -1435,7 +1429,7 @@ BOOL torture_denytest1(struct torture_context *torture)
                smbcli_close(cli1->tree, fnum1);
        }
 
-       printf("testing %d entries\n", (int)ARRAY_SIZE(denytable1));
+       torture_comment(tctx, "testing %d entries\n", (int)ARRAY_SIZE(denytable1));
 
        GetTimeOfDay(&tv_start);
 
@@ -1443,7 +1437,7 @@ BOOL torture_denytest1(struct torture_context *torture)
                enum deny_result res;
                const char *fname = fnames[denytable1[i].isexe];
 
-               progress_bar(i, ARRAY_SIZE(denytable1));
+               progress_bar(tctx, i, ARRAY_SIZE(denytable1));
 
                fnum1 = smbcli_open(cli1->tree, fname, 
                                 denytable1[i].mode1,
@@ -1467,12 +1461,13 @@ BOOL torture_denytest1(struct torture_context *torture)
                        }
                }
 
-               if (torture_showall || res != denytable1[i].result) {
+               if (torture_setting_bool(tctx, "showall", False) || 
+                       res != denytable1[i].result) {
                        int64_t tdif;
                        GetTimeOfDay(&tv);
                        tdif = usec_time_diff(&tv, &tv_start);
                        tdif /= 1000;
-                       printf("%lld: %s %8s %10s    %8s %10s    %s (correct=%s)\n",
+                       torture_comment(tctx, "%lld: %s %8s %10s    %8s %10s    %s (correct=%s)\n",
                               (long long)tdif,
                               fname,
                               denystr(denytable1[i].deny1),
@@ -1497,11 +1492,7 @@ failed:
                smbcli_unlink(cli1->tree, fnames[i]);
        }
                
-       if (!torture_close_connection(cli1)) {
-               correct = False;
-       }
-       
-       printf("finshed denytest1 (%d failures)\n", failures);
+       torture_comment(tctx, "finshed denytest1 (%d failures)\n", failures);
        return correct;
 }
 
@@ -1509,9 +1500,10 @@ failed:
 /*
   this produces a matrix of deny mode behaviour with 2 connections
  */
-BOOL torture_denytest2(struct torture_context *torture)
+BOOL torture_denytest2(struct torture_context *tctx, 
+                                          struct smbcli_state *cli1, 
+                                          struct smbcli_state *cli2)
 {
-       static struct smbcli_state *cli1, *cli2;
        int fnum1, fnum2;
        int i;
        BOOL correct = True;
@@ -1519,14 +1511,6 @@ BOOL torture_denytest2(struct torture_context *torture)
        struct timeval tv, tv_start;
        int failures=0;
 
-       if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
-               return False;
-       }
-
-       printf("starting denytest2\n");
-
-       printf("Testing deny modes with 2 connections\n");
-
        for (i=0;i<2;i++) {
                smbcli_unlink(cli1->tree, fnames[i]);
                fnum1 = smbcli_open(cli1->tree, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
@@ -1540,7 +1524,7 @@ BOOL torture_denytest2(struct torture_context *torture)
                enum deny_result res;
                const char *fname = fnames[denytable2[i].isexe];
 
-               progress_bar(i, ARRAY_SIZE(denytable1));
+               progress_bar(tctx, i, ARRAY_SIZE(denytable1));
 
                fnum1 = smbcli_open(cli1->tree, fname, 
                                 denytable2[i].mode1,
@@ -1564,12 +1548,13 @@ BOOL torture_denytest2(struct torture_context *torture)
                        }
                }
 
-               if (torture_showall || res != denytable2[i].result) {
+               if (torture_setting_bool(tctx, "showall", False) || 
+                       res != denytable2[i].result) {
                        int64_t tdif;
                        GetTimeOfDay(&tv);
                        tdif = usec_time_diff(&tv, &tv_start);
                        tdif /= 1000;
-                       printf("%lld: %s %8s %10s    %8s %10s    %s (correct=%s)\n",
+                       torture_comment(tctx, "%lld: %s %8s %10s    %8s %10s    %s (correct=%s)\n",
                               (long long)tdif,
                               fname,
                               denystr(denytable2[i].deny1),
@@ -1594,14 +1579,7 @@ failed:
                smbcli_unlink(cli1->tree, fnames[i]);
        }
 
-       if (!torture_close_connection(cli1)) {
-               correct = False;
-       }
-       if (!torture_close_connection(cli2)) {
-               correct = False;
-       }
-       
-       printf("finshed denytest2 (%d failures)\n", failures);
+       torture_comment(tctx, "finshed denytest2 (%d failures)\n", failures);
        return correct;
 }
 
@@ -1610,23 +1588,13 @@ failed:
 /*
    simple test harness for playing with deny modes
  */
-BOOL torture_denytest3(struct torture_context *torture)
+BOOL torture_denytest3(struct torture_context *tctx, 
+                                          struct smbcli_state *cli1,
+                                          struct smbcli_state *cli2)
 {
-       struct smbcli_state *cli1, *cli2;
        int fnum1, fnum2;
        const char *fname;
 
-       printf("starting deny3 test\n");
-
-       printf("Testing simple deny modes\n");
-       
-       if (!torture_open_connection(&cli1)) {
-               return False;
-       }
-       if (!torture_open_connection(&cli2)) {
-               return False;
-       }
-
        fname = "\\deny_dos1.dat";
 
        smbcli_unlink(cli1->tree, fname);
@@ -1635,7 +1603,7 @@ BOOL torture_denytest3(struct torture_context *torture)
        if (fnum1 != -1) smbcli_close(cli1->tree, fnum1);
        if (fnum2 != -1) smbcli_close(cli1->tree, fnum2);
        smbcli_unlink(cli1->tree, fname);
-       printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
+       torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2);
 
 
        fname = "\\deny_dos2.dat";
@@ -1646,11 +1614,7 @@ BOOL torture_denytest3(struct torture_context *torture)
        if (fnum1 != -1) smbcli_close(cli1->tree, fnum1);
        if (fnum2 != -1) smbcli_close(cli2->tree, fnum2);
        smbcli_unlink(cli1->tree, fname);
-       printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
-
-
-       torture_close_connection(cli1);
-       torture_close_connection(cli2);
+       torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2);
 
        return True;
 }
@@ -1757,7 +1721,8 @@ static NTSTATUS predict_share_conflict(uint32_t sa1, uint32_t am1, uint32_t sa2,
 /*
   a denytest for ntcreatex
  */
-static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *cli2, int client)
+static BOOL torture_ntdenytest(struct torture_context *tctx, 
+                                                          struct smbcli_state *cli1, struct smbcli_state *cli2, int client)
 {
        const struct bit_value share_access_bits[] = {
                { NTCREATEX_SHARE_ACCESS_READ,   "S_R" },
@@ -1786,7 +1751,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
        int failures = 0;
        uint8_t buf[1];
 
-       printf("format: server correct\n");
+       torture_comment(tctx, "format: server correct\n");
 
        ZERO_STRUCT(buf);
 
@@ -1811,7 +1776,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
        io1.ntcreatex.in.fname = fname;
        io2 = io1;
 
-       printf("testing %d entries on %s\n", torture_numops, fname);
+       torture_comment(tctx, "testing %d entries on %s\n", torture_numops, fname);
 
        for (i=0;i<torture_numops;i++) {
                NTSTATUS status1, status2, status2_p;
@@ -1824,7 +1789,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
                int b_am2 = random() & ((1<<nbits2)-1);
                BOOL read_for_execute;
 
-               progress_bar(i, torture_numops);
+               progress_bar(tctx, i, torture_numops);
                
                io1.ntcreatex.in.share_access = map_bits(share_access_bits, b_sa1, nbits1);
                io1.ntcreatex.in.access_mask  = map_bits(access_mask_bits,  b_am1, nbits2);
@@ -1888,10 +1853,10 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
                GetTimeOfDay(&tv);
                tdif = usec_time_diff(&tv, &tv_start);
                tdif /= 1000;
-               if (torture_showall || 
+               if (torture_setting_bool(tctx, "showall", False) || 
                    !NT_STATUS_EQUAL(status2, status2_p) ||
                    res != res2) {
-                       printf("\n%-20s %-70s\n%-20s %-70s %4s %4s  %s/%s\n",
+                       torture_comment(tctx, "\n%-20s %-70s\n%-20s %-70s %4s %4s  %s/%s\n",
                               bit_string(mem_ctx, share_access_bits, b_sa1, nbits1),
                               bit_string(mem_ctx, access_mask_bits,  b_am1, nbits2),
                               bit_string(mem_ctx, share_access_bits, b_sa2, nbits1),
@@ -1915,7 +1880,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
 failed:
        smbcli_unlink(cli1->tree, fname);
        
-       printf("finshed ntdenytest (%d failures)\n", failures);
+       torture_comment(tctx, "finshed ntdenytest (%d failures)\n", failures);
        return correct;
 }
 
@@ -1924,47 +1889,31 @@ failed:
 /*
   a denytest for ntcreatex
  */
-BOOL torture_ntdenytest1(struct smbcli_state *cli, int client)
+BOOL torture_ntdenytest1(struct torture_context *tctx, struct smbcli_state *cli, int client)
 {
        extern int torture_seed;
 
        srandom(torture_seed + client);
 
-       printf("starting ntdenytest1 client %d\n", client);
+       torture_comment(tctx, "starting ntdenytest1 client %d\n", client);
 
-       return torture_ntdenytest(cli, cli, client);
+       return torture_ntdenytest(tctx, cli, cli, client);
 }
 
 /*
   a denytest for ntcreatex
  */
-BOOL torture_ntdenytest2(struct torture_context *torture)
+BOOL torture_ntdenytest2(struct torture_context *torture, 
+                                                struct smbcli_state *cli1,
+                                                struct smbcli_state *cli2)
 {
-       struct smbcli_state *cli1, *cli2;
-       BOOL ret;
-
-       if (!torture_open_connection(&cli1)) {
-               return False;
-       }
-
-       if (!torture_open_connection(&cli2)) {
-               return False;
-       }
-
-       printf("starting ntdenytest2\n");
-
-       ret = torture_ntdenytest(cli1, cli2, 0);
-
-       torture_close_connection(cli1);
-       torture_close_connection(cli2);
-
-       return ret;
+       return torture_ntdenytest(torture, cli1, cli2, 0);
 }
 
 
 #define CHECK_STATUS(status, correct) do { \
        if (!NT_STATUS_EQUAL(status, correct)) { \
-               printf("(%s) Incorrect status %s - should be %s\n", \
+               torture_comment(tctx, "(%s) Incorrect status %s - should be %s\n", \
                       __location__, nt_errstr(status), nt_errstr(correct)); \
                ret = False; \
                goto done; \
@@ -1972,7 +1921,7 @@ BOOL torture_ntdenytest2(struct torture_context *torture)
 
 #define CHECK_VAL(v, correct) do { \
        if ((v) != (correct)) { \
-               printf("(%s) wrong value for %s  0x%x - should be 0x%x\n", \
+               torture_comment(tctx, "(%s) wrong value for %s  0x%x - should be 0x%x\n", \
                       __location__, #v, (int)(v), (int)correct); \
                ret = False; \
        }} while (0)
@@ -1980,9 +1929,9 @@ BOOL torture_ntdenytest2(struct torture_context *torture)
 /*
   test sharing of handles with DENY_DOS on a single connection
 */
-BOOL torture_denydos_sharing(struct torture_context *torture)
+BOOL torture_denydos_sharing(struct torture_context *tctx, 
+                                                        struct smbcli_state *cli)
 {
-       struct smbcli_state *cli;
        union smb_open io;
        union smb_fileinfo finfo;
        const char *fname = "\\torture_denydos.txt";
@@ -1992,13 +1941,9 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
        union smb_setfileinfo sfinfo;
        TALLOC_CTX *mem_ctx;
 
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
-
        mem_ctx = talloc_new(cli);
 
-       printf("Checking DENY_DOS shared handle semantics\n");
+       torture_comment(tctx, "Checking DENY_DOS shared handle semantics\n");
        smbcli_unlink(cli->tree, fname);
 
        io.openx.level = RAW_OPEN_OPENX;
@@ -2012,7 +1957,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
        io.openx.in.size = 0;
        io.openx.in.timeout = 0;
 
-       printf("openx twice with RDWR/DENY_DOS\n");
+       torture_comment(tctx, "openx twice with RDWR/DENY_DOS\n");
        status = smb_raw_open(cli->tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum1 = io.openx.out.file.fnum;
@@ -2021,7 +1966,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum2 = io.openx.out.file.fnum;
 
-       printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
+       torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2);
 
        sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
        sfinfo.position_information.in.file.fnum = fnum1;
@@ -2029,7 +1974,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
        status = smb_raw_setfileinfo(cli->tree, &sfinfo);
        CHECK_STATUS(status, NT_STATUS_OK);
 
-       printf("two handles should be same file handle\n");
+       torture_comment(tctx, "two handles should be same file handle\n");
        finfo.position_information.level = RAW_FILEINFO_POSITION_INFORMATION;
        finfo.position_information.in.file.fnum = fnum1;
        status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
@@ -2045,7 +1990,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
        smbcli_close(cli->tree, fnum1);
        smbcli_close(cli->tree, fnum2);
 
-       printf("openx twice with RDWR/DENY_NONE\n");
+       torture_comment(tctx, "openx twice with RDWR/DENY_NONE\n");
        io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
        status = smb_raw_open(cli->tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -2056,9 +2001,9 @@ BOOL torture_denydos_sharing(struct torture_context *torture)
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum2 = io.openx.out.file.fnum;
 
-       printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
+       torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2);
 
-       printf("two handles should be separate\n");
+       torture_comment(tctx, "two handles should be separate\n");
        sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
        sfinfo.position_information.in.file.fnum = fnum1;
        sfinfo.position_information.in.position = 1000;