r26238: Add a loadparm context parameter to torture_context, remove more uses of...
[gd/samba-autobuild/.git] / source4 / torture / raw / eas.c
index a636f8e1cd304930130f61713e47112098a6340d..53449a1505b675ac5a1fbcd86c11d32b234e8df6 100644 (file)
@@ -8,7 +8,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/libcli.h"
+#include "torture/util.h"
+#include "param/param.h"
 
 #define BASEDIR "\\testeas"
 
        if (!NT_STATUS_EQUAL(status, correct)) { \
                printf("(%s) Incorrect status %s - should be %s\n", \
                       __location__, nt_errstr(status), nt_errstr(correct)); \
-               ret = False; \
+               ret = false; \
                goto done; \
        }} while (0)
 
-static BOOL maxeadebug; /* need that here, to allow no file delete in debug case */
+static bool maxeadebug; /* need that here, to allow no file delete in debug case */
 
-static BOOL check_ea(struct smbcli_state *cli, 
+static bool check_ea(struct smbcli_state *cli, 
                     const char *fname, const char *eaname, const char *value)
 {
        NTSTATUS status = torture_check_ea(cli, fname, eaname, value);
        return NT_STATUS_IS_OK(status);
 }
 
-static BOOL test_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 {
        NTSTATUS status;
        union smb_setfileinfo setfile;
        union smb_open io;
        const char *fname = BASEDIR "\\ea.txt";
-       BOOL ret = True;
+       bool ret = true;
        int fnum = -1;
 
        printf("TESTING SETFILEINFO EA_SET\n");
@@ -207,7 +208,7 @@ static int test_one_eamax(struct smbcli_state *cli, const int fnum,
                        }
                        i -= (high - low + 1) / 2;
                }
-       } while (True);
+       } while (true);
 
        return low;
 }
@@ -221,21 +222,21 @@ static int test_one_eamax(struct smbcli_state *cli, const int fnum,
  * maxeasize    65536   limit the max. size for a single EA name
  * maxeanames     101   limit of the number of tested names
  * maxeastart       1   this EA size is used to test for the 1st EA (atm)
- * maxeadebug       0   if set True, further debug output is done - in addition
+ * maxeadebug       0   if set true, further debug output is done - in addition
  *                      the testfile is not deleted for further inspection!
  *
  * Set some/all of these options on the cmdline with:
  * --option torture:maxeasize=1024 --option torture:maxeadebug=1 ...
  *
  */
-static BOOL test_max_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_max_eas(struct smbcli_state *cli, struct torture_context *tctx)
 {
        NTSTATUS status;
        union smb_open io;
        const char *fname = BASEDIR "\\ea_max.txt";
        int fnum = -1;
-       BOOL ret = True;
-       BOOL err = False;
+       bool ret = true;
+       bool err = false;
 
        int       i, j, k, last, total;
        DATA_BLOB eablob;
@@ -246,27 +247,27 @@ static BOOL test_max_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("TESTING SETFILEINFO MAX. EA_SET\n");
 
-       maxeasize  = lp_parm_int(-1, "torture", "maxeasize", 65536);
-       maxeanames = lp_parm_int(-1, "torture", "maxeanames", 101);
-       maxeastart = lp_parm_int(-1, "torture", "maxeastart", 1);
-       maxeadebug = lp_parm_int(-1, "torture", "maxeadebug", 0);
+       maxeasize  = torture_setting_int(tctx, "maxeasize", 65536);
+       maxeanames = torture_setting_int(tctx, "maxeanames", 101);
+       maxeastart = torture_setting_int(tctx, "maxeastart", 1);
+       maxeadebug = torture_setting_int(tctx, "maxeadebug", 0);
 
        /* Do some sanity check on possibly passed parms */
        if (maxeasize <= 0) {
                printf("Invalid parameter 'maxeasize=%d'",maxeasize);
-               err = True;
+               err = true;
        }
        if (maxeanames <= 0) {
                printf("Invalid parameter 'maxeanames=%d'",maxeanames);
-               err = True;
+               err = true;
        }
        if (maxeastart <= 0) {
                printf("Invalid parameter 'maxeastart=%d'",maxeastart);
-               err = True;
+               err = true;
        }
        if (maxeadebug < 0) {
                printf("Invalid parameter 'maxeadebug=%d'",maxeadebug);
-               err = True;
+               err = true;
        }
        if (err) {
          printf("\n\n");
@@ -295,11 +296,11 @@ static BOOL test_max_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
        io.ntcreatex.in.security_flags = 0;
        io.ntcreatex.in.fname = fname;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.ntcreatex.out.file.fnum;
        
-       eablob = data_blob_talloc(mem_ctx, NULL, maxeasize);
+       eablob = data_blob_talloc(tctx, NULL, maxeasize);
        if (eablob.data == NULL) {
                goto done;
        }
@@ -335,7 +336,7 @@ static BOOL test_max_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
                if (eaname != NULL) {
                        talloc_free(eaname);
                }
-               eaname = talloc_asprintf(mem_ctx, "MAX%d", i);
+               eaname = talloc_asprintf(tctx, "MAX%d", i);
                if(eaname == NULL) {
                        goto done;
                }
@@ -352,7 +353,7 @@ static BOOL test_max_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
                printf ("NOTE: More EAs could be available!\n");
        } 
        if (total == 0) {
-               ret = False;
+               ret = false;
        }
 done:
        smbcli_close(cli->tree, fnum);
@@ -362,12 +363,12 @@ done:
 /*
   test using NTTRANS CREATE to create a file with an initial EA set
 */
-static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 {
        NTSTATUS status;
        union smb_open io;
        const char *fname = BASEDIR "\\ea2.txt";
-       BOOL ret = True;
+       bool ret = true;
        int fnum = -1;
        struct ea_struct eas[3];
        struct smb_ea_list ea_list;
@@ -444,52 +445,39 @@ done:
 /* 
    basic testing of EA calls
 */
-BOOL torture_raw_eas(void)
+bool torture_raw_eas(struct torture_context *torture, struct smbcli_state *cli)
 {
-       struct smbcli_state *cli;
-       BOOL ret = True;
-       TALLOC_CTX *mem_ctx;
-
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
-
-       mem_ctx = talloc_init("torture_raw_eas");
+       bool ret = true;
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
-       ret &= test_eas(cli, mem_ctx);
-       ret &= test_nttrans_create(cli, mem_ctx);
+       ret &= test_eas(cli, torture);
+       ret &= test_nttrans_create(cli, torture);
 
        smb_raw_exit(cli->session);
 
-       torture_close_connection(cli);
-       talloc_free(mem_ctx);
        return ret;
 }
 
 /* 
    test max EA size
 */
-BOOL torture_max_eas(void)
+bool torture_max_eas(struct torture_context *torture)
 {
        struct smbcli_state *cli;
-       BOOL ret = True;
-       TALLOC_CTX *mem_ctx;
+       bool ret = true;
 
-       if (!torture_open_connection(&cli)) {
-               return False;
+       if (!torture_open_connection(&cli, 0)) {
+               return false;
        }
 
-       mem_ctx = talloc_init("torture_raw_eas");
-
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
-       ret &= test_max_eas(cli, mem_ctx);
+       ret &= test_max_eas(cli, torture);
 
        smb_raw_exit(cli->session);
        if (!maxeadebug) {
@@ -498,6 +486,5 @@ BOOL torture_max_eas(void)
        }
 
        torture_close_connection(cli);
-       talloc_free(mem_ctx);
        return ret;
 }