s4:torture: s/private/private_data
[samba.git] / source4 / torture / raw / lock.c
index 0a2ed5260be6a61c2fb5bd0f7dd764d3b0f30e7e..2d1eae3a696ed196b20a46c06821a2d5ddb3b566 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,
    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"
 #include "torture/torture.h"
 #include "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
 #include "system/time.h"
 #include "system/filesys.h"
 #include "libcli/libcli.h"
 #include "libcli/composite/composite.h"
 #include "libcli/smb_composite/smb_composite.h"
 #include "lib/cmdline/popt_common.h"
+#include "param/param.h"
 
 #define CHECK_STATUS(status, correct) do { \
        if (!NT_STATUS_EQUAL(status, correct)) { \
                printf("(%s) Incorrect status %s - should be %s\n", \
                       __location__, nt_errstr(status), nt_errstr(correct)); \
-               ret = False; \
-               goto done; \
-       }} while (0)
-
-#define CHECK_VALUE(v, correct) do { \
-       if ((v) != (correct)) { \
-               printf("(%s) Incorrect value %s=%d - should be %d\n", \
-                      __location__, #v, v, correct); \
-               ret = False; \
+               ret = false; \
                goto done; \
        }} while (0)
 
 /*
   test SMBlock and SMBunlock ops
 */
-static BOOL test_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_lock(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_lock io;
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing RAW_LOCK_LOCK\n");
@@ -69,7 +62,7 @@ static BOOL test_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -186,17 +179,17 @@ done:
 /*
   test locking&X ops
 */
-static BOOL test_lockx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_lockx(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_lock io;
        struct smb_lock_entry lock[1];
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing RAW_LOCK_LOCKX\n");
@@ -205,7 +198,7 @@ static BOOL test_lockx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -365,18 +358,19 @@ done:
 /*
   test high pid
 */
-static BOOL test_pidhigh(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_pidhigh(struct torture_context *tctx, 
+                                                struct smbcli_state *cli)
 {
        union smb_lock io;
        struct smb_lock_entry lock[1];
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
        uint8_t c = 1;
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing high pid\n");
@@ -387,13 +381,13 @@ static BOOL test_pidhigh(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
        if (smbcli_write(cli->tree, fnum, 0, &c, 0, 1) != 1) {
                printf("Failed to write 1 byte - %s\n", smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -412,7 +406,7 @@ static BOOL test_pidhigh(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
                printf("Failed to read 1 byte - %s\n", smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -422,7 +416,7 @@ static BOOL test_pidhigh(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (smbcli_read(cli->tree, fnum, &c, 0, 1) == 1) {
                printf("pid is incorrect handled for read with lock!\n");
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -430,7 +424,7 @@ static BOOL test_pidhigh(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
                printf("High pid is used on this server!\n");
-               ret = False;
+               ret = false;
        } else {
                printf("High pid is not used on this server (correct)\n");
        }
@@ -446,7 +440,8 @@ done:
 /*
   test locking&X async operation
 */
-static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_async(struct torture_context *tctx, 
+                                          struct smbcli_state *cli)
 {
        struct smbcli_session *session;
        struct smb_composite_sesssetup setup;
@@ -456,23 +451,26 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        union smb_lock io;
        struct smb_lock_entry lock[2];
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
        time_t t;
        struct smbcli_request *req;
+       struct smbcli_session_options options;
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
+       lp_smbcli_session_options(tctx->lp_ctx, &options);
+
        printf("Testing LOCKING_ANDX_CANCEL_LOCK\n");
        io.generic.level = RAW_LOCK_LOCKX;
 
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -498,7 +496,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        req = smb_raw_lock_send(cli->tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -529,7 +527,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (time(NULL) > t+2) {
                printf("lock cancel was not immediate (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -545,7 +543,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        req = smb_raw_lock_send(cli->tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -561,7 +559,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        if (time(NULL) > t+2) {
                printf("lock cancel by unlock was not immediate (%s) - took %d secs\n", 
                       __location__, (int)(time(NULL)-t));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -578,7 +576,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        req = smb_raw_lock_send(cli->tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -590,30 +588,31 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (time(NULL) > t+2) {
                printf("lock cancel by close was not immediate (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
        printf("create a new sessions\n");
-       session = smbcli_session_init(cli->transport, mem_ctx, False);
+       session = smbcli_session_init(cli->transport, tctx, false, options);
        setup.in.sesskey = cli->transport->negotiate.sesskey;
        setup.in.capabilities = cli->transport->negotiate.capabilities;
-       setup.in.workgroup = lp_workgroup();
+       setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
        setup.in.credentials = cmdline_credentials;
+       setup.in.gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
        status = smb_composite_sesssetup(session, &setup);
        CHECK_STATUS(status, NT_STATUS_OK);
        session->vuid = setup.out.vuid;
 
        printf("create new tree context\n");
-       share = lp_parm_string(-1, "torture", "share");
-       host  = lp_parm_string(-1, "torture", "host");
-       tree = smbcli_tree_init(session, mem_ctx, False);
+       share = torture_setting_string(tctx, "share", NULL);
+       host  = torture_setting_string(tctx, "host", NULL);
+       tree = smbcli_tree_init(session, tctx, false);
        tcon.generic.level = RAW_TCON_TCONX;
        tcon.tconx.in.flags = 0;
        tcon.tconx.in.password = data_blob(NULL, 0);
-       tcon.tconx.in.path = talloc_asprintf(mem_ctx, "\\\\%s\\%s", host, share);
+       tcon.tconx.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
        tcon.tconx.in.device = "A:";
-       status = smb_raw_tcon(tree, mem_ctx, &tcon);
+       status = smb_raw_tcon(tree, tctx, &tcon);
        CHECK_STATUS(status, NT_STATUS_OK);
        tree->tid = tcon.tconx.out.tid;
 
@@ -622,7 +621,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
-               ret = False;
+               ret = false;
                goto done;
        }
        io.lockx.level = RAW_LOCK_LOCKX;
@@ -650,7 +649,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        req = smb_raw_lock_send(tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -662,7 +661,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (time(NULL) > t+2) {
                printf("lock cancel by exit was not immediate (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -671,7 +670,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
-               ret = False;
+               ret = false;
                goto done;
        }
        io.lockx.level = RAW_LOCK_LOCKX;
@@ -699,7 +698,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        req = smb_raw_lock_send(tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -718,7 +717,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (time(NULL) > t+2) {
                printf("lock cancel by ulogoff was not immediate (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -729,7 +728,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
-               ret = False;
+               ret = false;
                goto done;
        }
        io.lockx.level = RAW_LOCK_LOCKX;
@@ -753,7 +752,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        req = smb_raw_lock_send(tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -765,7 +764,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (time(NULL) > t+2) {
                printf("lock cancel by tdis was not immediate (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -778,13 +777,14 @@ done:
 /*
   test NT_STATUS_LOCK_NOT_GRANTED vs. NT_STATUS_FILE_LOCK_CONFLICT
 */
-static BOOL test_errorcode(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_errorcode(struct torture_context *tctx, 
+                                                  struct smbcli_state *cli)
 {
        union smb_lock io;
        union smb_open op;
        struct smb_lock_entry lock[2];
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum, fnum2;
        const char *fname;
        struct smbcli_request *req;
@@ -792,7 +792,7 @@ static BOOL test_errorcode(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        int t;
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT\n");
@@ -821,11 +821,11 @@ next_run:
        op.openx.in.size = 0;
        op.openx.in.timeout = 0;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &op);
+       status = smb_raw_open(cli->tree, tctx, &op);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = op.openx.out.file.fnum;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &op);
+       status = smb_raw_open(cli->tree, tctx, &op);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum2 = op.openx.out.file.fnum;
 
@@ -1110,7 +1110,7 @@ next_run:
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
        io.lockx.level = RAW_LOCK_LOCKX;
@@ -1131,7 +1131,7 @@ next_run:
        req = smb_raw_lock_send(cli->tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1149,7 +1149,7 @@ next_run:
 
        if (time(NULL) < start+1) {
                printf("lock comes back to early (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1158,7 +1158,7 @@ next_run:
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
        io.lockx.level = RAW_LOCK_LOCKX;
@@ -1179,7 +1179,7 @@ next_run:
        req = smb_raw_lock_send(cli->tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1199,7 +1199,7 @@ next_run:
 
        if (time(NULL) < start+1) {
                printf("lock comes back to early (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1208,7 +1208,7 @@ next_run:
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
        io.lockx.level = RAW_LOCK_LOCKX;
@@ -1229,7 +1229,7 @@ next_run:
        req = smb_raw_lock_send(cli->tree, &io);
        if (req == NULL) {
                printf("Failed to setup timed lock (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1245,7 +1245,7 @@ next_run:
 
        if (time(NULL) < start+1) {
                printf("lock comes back to early (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1259,18 +1259,19 @@ done:
 /*
   test LOCKING_ANDX_CHANGE_LOCKTYPE
 */
-static BOOL test_changetype(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_changetype(struct torture_context *tctx, 
+                                                       struct smbcli_state *cli)
 {
        union smb_lock io;
        struct smb_lock_entry lock[2];
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        uint8_t c = 0;
        const char *fname = BASEDIR "\\test.txt";
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing LOCKING_ANDX_CHANGE_LOCKTYPE\n");
@@ -1279,7 +1280,7 @@ static BOOL test_changetype(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1298,7 +1299,7 @@ static BOOL test_changetype(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
                printf("allowed write on read locked region (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1309,7 +1310,7 @@ static BOOL test_changetype(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
                printf("allowed write after lock change (%s)\n", __location__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -1324,26 +1325,16 @@ done:
 /* 
    basic testing of lock calls
 */
-BOOL torture_raw_lock(struct torture_context *torture)
+struct torture_suite *torture_raw_lock(TALLOC_CTX *mem_ctx)
 {
-       struct smbcli_state *cli;
-       BOOL ret = True;
-       TALLOC_CTX *mem_ctx;
+       struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCK");
 
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
-
-       mem_ctx = talloc_init("torture_raw_lock");
+       torture_suite_add_1smb_test(suite, "lockx", test_lockx);
+       torture_suite_add_1smb_test(suite, "lock", test_lock);
+       torture_suite_add_1smb_test(suite, "pidhigh", test_pidhigh);
+       torture_suite_add_1smb_test(suite, "async", test_async);
+       torture_suite_add_1smb_test(suite, "errorcode", test_errorcode);
+       torture_suite_add_1smb_test(suite, "changetype", test_changetype);
 
-       ret &= test_lockx(cli, mem_ctx);
-       ret &= test_lock(cli, mem_ctx);
-       ret &= test_pidhigh(cli, mem_ctx);
-       ret &= test_async(cli, mem_ctx);
-       ret &= test_errorcode(cli, mem_ctx);
-       ret &= test_changetype(cli, mem_ctx);
-
-       torture_close_connection(cli);
-       talloc_free(mem_ctx);
-       return ret;
+       return suite;
 }