r5963: Fix parameter passing for gentest and locktest
[samba.git] / source4 / torture / gentest.c
index cce831e6c66bad4cf50cce2ced0b87fcc5ccffd4..5f036910b60b477e7abbbd39746393be15b5c102 100644 (file)
 */
 
 #include "includes.h"
+#include "dynconfig.h"
 #include "system/time.h"
+#include "system/filesys.h"
+#include "request.h"
 #include "libcli/raw/libcliraw.h"
+#include "librpc/gen_ndr/ndr_security.h"
 
 #define NSERVERS 2
 #define NINSTANCES 2
@@ -56,8 +60,7 @@ static struct {
        struct smbcli_state *cli[NINSTANCES];
        char *server_name;
        char *share_name;
-       char *username;
-       char *password;
+       struct cli_credentials *credentials;
 } servers[NSERVERS];
 
 /* the seeds and flags for each operation */
@@ -172,13 +175,13 @@ static BOOL connect_servers(void)
                        NTSTATUS status;
                        printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
                               servers[i].server_name, servers[i].share_name, 
-                              servers[i].username, j);
+                              servers[i].credentials->username, j);
+
                        status = smbcli_full_connection(NULL, &servers[i].cli[j],
-                                                    "gentest",
-                                                    servers[i].server_name, NULL, 
-                                                    servers[i].share_name, "?????", 
-                                                    servers[i].username, lp_workgroup(),
-                                                    servers[i].password, 0, NULL);
+                                                       "gentest",
+                                                       servers[i].server_name, 
+                                                       servers[i].share_name, NULL, 
+                                                       servers[i].credentials);
                        if (!NT_STATUS_IS_OK(status)) {
                                printf("Failed to connect to \\\\%s\\%s - %s\n",
                                       servers[i].server_name, servers[i].share_name,
@@ -187,7 +190,7 @@ static BOOL connect_servers(void)
                        }
 
                        smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
-                       smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 1, NULL);
+                       smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
                }
        }
 
@@ -524,8 +527,8 @@ static uint32_t gen_ntcreatex_flags(void)
 */
 static uint32_t gen_access_mask(void)
 {
-       if (gen_chance(50)) return SEC_RIGHT_MAXIMUM_ALLOWED;
-       if (gen_chance(20)) return GENERIC_RIGHTS_FILE_ALL_ACCESS;
+       if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
+       if (gen_chance(20)) return SEC_FILE_ALL;
        return gen_bits_mask(0xFFFFFFFF);
 }
 
@@ -1086,14 +1089,14 @@ static BOOL handler_open(int instance)
        NTSTATUS status[NSERVERS];
 
        parm[0].openold.level = RAW_OPEN_OPEN;
-       parm[0].openold.in.flags = gen_bits_mask2(0xF, 0xFFFF);
+       parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
        parm[0].openold.in.search_attrs = gen_attrib();
        parm[0].openold.in.fname = gen_fname_open(instance);
 
        if (!options.use_oplocks) {
                /* mask out oplocks */
-               parm[0].openold.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
-                                          OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
+               parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
+                                                 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
        }
        
        GEN_COPY_PARM;
@@ -1327,8 +1330,8 @@ static BOOL handler_readx(int instance)
        parm[0].readx.in.mincnt = gen_io_count();
        parm[0].readx.in.maxcnt = gen_io_count();
        parm[0].readx.in.remaining = gen_io_count();
-       parm[0].readx.out.data = talloc(current_op.mem_ctx,
-                                       MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
+       parm[0].readx.out.data = talloc_size(current_op.mem_ctx,
+                                            MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
 
        GEN_COPY_PARM;
        GEN_SET_FNUM(readx.in.fnum);
@@ -1355,7 +1358,7 @@ static BOOL handler_writex(int instance)
        parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
        parm[0].writex.in.remaining = gen_io_count();
        parm[0].writex.in.count = gen_io_count();
-       parm[0].writex.in.data = talloc_zero(current_op.mem_ctx, parm[0].writex.in.count);
+       parm[0].writex.in.data = talloc_zero_size(current_op.mem_ctx, parm[0].writex.in.count);
 
        GEN_COPY_PARM;
        GEN_SET_FNUM(writex.in.fnum);
@@ -1389,8 +1392,9 @@ static BOOL handler_lockingx(int instance)
        } while (nlocks == 0);
 
        if (nlocks > 0) {
-               parm[0].lockx.in.locks = talloc(current_op.mem_ctx,
-                                               sizeof(parm[0].lockx.in.locks[0]) * nlocks);
+               parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
+                                                       struct smb_lock_entry,
+                                                       nlocks);
                for (n=0;n<nlocks;n++) {
                        parm[0].lockx.in.locks[n].pid = gen_pid();
                        parm[0].lockx.in.locks[n].offset = gen_offset();
@@ -1682,8 +1686,12 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
                info->standard.in.access_time = gen_timet();
                info->standard.in.write_time = gen_timet();
                break;
-       case RAW_SFILEINFO_EA_SET:
-               info->ea_set.in.ea = gen_ea_struct();
+       case RAW_SFILEINFO_EA_SET: {
+               static struct ea_struct ea;
+               info->ea_set.in.num_eas = 1;
+               info->ea_set.in.eas = &ea;
+               info->ea_set.in.eas[0] = gen_ea_struct();
+       }
                break;
        case RAW_SFILEINFO_BASIC_INFO:
        case RAW_SFILEINFO_BASIC_INFORMATION:
@@ -1919,7 +1927,7 @@ static int run_test(void)
 
                ret = gen_ops[which_op].handler(instance);
 
-               talloc_destroy(current_op.mem_ctx);
+               talloc_free(current_op.mem_ctx);
 
                gen_ops[which_op].count++;
                if (NT_STATUS_IS_OK(current_op.status)) {
@@ -2107,6 +2115,7 @@ static void usage(void)
 
        for (i=0;i<NSERVERS;i++) {
                const char *share = argv[1+i];
+               servers[i].credentials = cli_credentials_init(NULL);
                if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
                        printf("Invalid share name '%s'\n", share);
                        return -1;
@@ -2127,13 +2136,8 @@ static void usage(void)
        while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
                switch (opt) {
                case 'U':
-                       i = servers[0].username?1:0;
-                       if (!split_username(optarg, 
-                                           &servers[i].username, 
-                                           &servers[i].password)) {
-                               printf("Must supply USER%%PASS\n");
-                               return -1;
-                       }
+                       i = servers[0].credentials->username?1:0;
+                       cli_credentials_parse_string(servers[i].credentials, optarg, CRED_SPECIFIED);
                        break;
                case 'd':
                        DEBUGLEVEL = atoi(optarg);
@@ -2181,13 +2185,15 @@ static void usage(void)
                }
        }
 
-       if (!servers[0].username) {
+       gentest_init_subsystems;
+
+       if (!servers[0].credentials->username) {
                usage();
                return -1;
        }
-       if (!servers[1].username) {
-               servers[1].username = servers[0].username;
-               servers[1].password = servers[0].password;
+       if (!servers[1].credentials->username) {
+               servers[1].credentials->username = servers[0].credentials->username;
+               servers[1].credentials->password = servers[0].credentials->password;
        }
 
        printf("seed=%u\n", options.seed);