Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / source4 / torture / gentest.c
index fd6bd5cc0ade56c41bdfbc591238087c4f27d7cb..10a1370b9d860620003e4bb5777027c0f98c3829 100644 (file)
@@ -48,9 +48,9 @@ static struct gentest_options {
        int analyze;
        int analyze_always;
        int analyze_continuous;
-       uint_t max_open_handles;
-       uint_t seed;
-       uint_t numops;
+       unsigned int max_open_handles;
+       unsigned int seed;
+       unsigned int numops;
        int use_oplocks;
        char **ignore_patterns;
        const char *seeds_file;
@@ -67,12 +67,12 @@ static struct gentest_options {
 /* mapping between open handles on the server and local handles */
 static struct {
        bool active;
-       uint_t instance;
+       unsigned int instance;
        struct smb2_handle smb2_handle[NSERVERS]; /* SMB2 */
        uint16_t smb_handle[NSERVERS];            /* SMB */
        const char *name;
 } *open_handles;
-static uint_t num_open_handles;
+static unsigned int num_open_handles;
 
 /* state information for the servers. We open NINSTANCES connections to
    each server */
@@ -86,7 +86,7 @@ static struct {
 
 /* the seeds and flags for each operation */
 static struct {
-       uint_t seed;
+       unsigned int seed;
        bool disabled;
 } *op_parms;
 
@@ -111,9 +111,9 @@ static struct {
 /* info relevant to the current operation */
 static struct {
        const char *name;
-       uint_t seed;
+       unsigned int seed;
        NTSTATUS status;
-       uint_t opnum;
+       unsigned int opnum;
        TALLOC_CTX *mem_ctx;
        const char *mismatch;
 } current_op;
@@ -125,9 +125,9 @@ static struct smb2_handle bad_smb2_handle;
 
 static bool oplock_handler_smb2(struct smb2_transport *transport, const struct smb2_handle *handle,
                                uint8_t level, void *private_data);
-static void idle_func_smb2(struct smb2_transport *transport, void *private);
-static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
-static void idle_func_smb(struct smbcli_transport *transport, void *private);
+static void idle_func_smb2(struct smb2_transport *transport, void *private_data);
+static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private_data);
+static void idle_func_smb(struct smbcli_transport *transport, void *private_data);
 
 /*
   check if a string should be ignored. This is used as the basis
@@ -183,7 +183,7 @@ static bool connect_servers_fast(void)
 /***************************************************** 
 connect to the servers
 *******************************************************/
-static bool connect_servers(struct event_context *ev,
+static bool connect_servers(struct tevent_context *ev,
                            struct loadparm_context *lp_ctx)
 {
        int i, j;
@@ -213,6 +213,11 @@ static bool connect_servers(struct event_context *ev,
        for (i=0;i<NSERVERS;i++) {
                for (j=0;j<NINSTANCES;j++) {
                        NTSTATUS status;
+                       struct smbcli_options smb_options;
+                       struct smbcli_session_options smb_session_options;
+                       lp_smbcli_options(lp_ctx, &smb_options);
+                       lp_smbcli_session_options(lp_ctx, &smb_session_options);
+
                        printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
                               servers[i].server_name, servers[i].share_name, 
                               servers[i].credentials->username, j);
@@ -222,22 +227,27 @@ static bool connect_servers(struct event_context *ev,
 
                        if (options.smb2) {
                                status = smb2_connect(NULL, servers[i].server_name, 
+                                                                         lp_smb_ports(lp_ctx),
                                                      servers[i].share_name,
                                                      lp_resolve_context(lp_ctx),
                                                      servers[i].credentials,
                                                      &servers[i].smb2_tree[j],
-                                                     ev);
+                                                     ev, &smb_options,
+                                                         lp_socket_options(lp_ctx),
+                                                         lp_gensec_settings(lp_ctx, lp_ctx)
+                                                         );
                        } else {
-                               struct smbcli_options smb_options;
-                               lp_smbcli_options(lp_ctx, &smb_options);
                                status = smbcli_tree_full_connection(NULL,
                                                                     &servers[i].smb_tree[j], 
                                                                     servers[i].server_name, 
                                                                     lp_smb_ports(lp_ctx),
                                                                     servers[i].share_name, "A:",
+                                                                        lp_socket_options(lp_ctx),
                                                                     servers[i].credentials,
                                                                     lp_resolve_context(lp_ctx), ev,
-                                                                    &smb_options);
+                                                                    &smb_options,
+                                                                    &smb_session_options,
+                                                                        lp_gensec_settings(lp_ctx, lp_ctx));
                        }
                        if (!NT_STATUS_IS_OK(status)) {
                                printf("Failed to connect to \\\\%s\\%s - %s\n",
@@ -266,9 +276,9 @@ static bool connect_servers(struct event_context *ev,
 /*
   work out the time skew between the servers - be conservative
 */
-static uint_t time_skew(void)
+static unsigned int time_skew(void)
 {
-       uint_t ret;
+       unsigned int ret;
        if (options.smb2) {
                ret = labs(servers[0].smb2_tree[0]->session->transport->negotiate.system_time -
                           servers[1].smb2_tree[0]->session->transport->negotiate.system_time);
@@ -288,9 +298,9 @@ static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_ha
 /*
   turn a server handle into a local handle
 */
-static uint_t fnum_to_handle_smb2(int server, int instance, struct smb2_handle server_handle)
+static unsigned int fnum_to_handle_smb2(int server, int instance, struct smb2_handle server_handle)
 {
-       uint_t i;
+       unsigned int i;
        for (i=0;i<options.max_open_handles;i++) {
                if (!open_handles[i].active ||
                    instance != open_handles[i].instance) continue;
@@ -306,9 +316,9 @@ static uint_t fnum_to_handle_smb2(int server, int instance, struct smb2_handle s
 /*
   turn a server handle into a local handle
 */
-static uint_t fnum_to_handle_smb(int server, int instance, uint16_t server_handle)
+static unsigned int fnum_to_handle_smb(int server, int instance, uint16_t server_handle)
 {
-       uint_t i;
+       unsigned int i;
        for (i=0;i<options.max_open_handles;i++) {
                if (!open_handles[i].active ||
                    instance != open_handles[i].instance) continue;
@@ -439,7 +449,7 @@ static void gen_remove_handle_smb(int instance, uint16_t handles[NSERVERS])
 /*
   return true with 'chance' probability as a percentage
 */
-static bool gen_chance(uint_t chance)
+static bool gen_chance(unsigned int chance)
 {
        return ((random() % 100) <= chance);
 }
@@ -500,7 +510,7 @@ static uint16_t gen_fnum_close(int instance)
 */
 static int gen_int_range(uint64_t min, uint64_t max)
 {
-       uint_t r = random();
+       unsigned int r = random();
        return min + (r % (1+max-min));
 }
 
@@ -629,9 +639,9 @@ static uint32_t gen_bits_levels(int nlevels, ...)
 /*
   generate a bitmask
 */
-static uint32_t gen_bits_mask(uint_t mask)
+static uint32_t gen_bits_mask(unsigned int mask)
 {
-       uint_t ret = random();
+       unsigned int ret = random();
        return ret & mask;
 }
 
@@ -858,9 +868,9 @@ static NTTIME gen_timewarp(void)
 /*
   generate a file allocation size
 */
-static uint_t gen_alloc_size(void)
+static unsigned int gen_alloc_size(void)
 {
-       uint_t ret;
+       unsigned int ret;
 
        if (gen_chance(30)) return 0;
 
@@ -965,7 +975,7 @@ static void oplock_handler_close_recv_smb(struct smbcli_request *req)
 /*
   the oplock handler will either ack the break or close the file
 */
-static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
+static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private_data)
 {
        union smb_close io;
        int i, j;
@@ -1013,7 +1023,7 @@ static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid,
        }
 
        req->async.fn = oplock_handler_close_recv_smb;
-       req->async.private = NULL;
+       req->async.private_data = NULL;
 
        return true;
 }
@@ -1024,7 +1034,7 @@ static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid,
   an operation on another connection blocking until that break is acked
   we check for operations on all transports in the idle function
 */
-static void idle_func_smb(struct smbcli_transport *transport, void *private)
+static void idle_func_smb(struct smbcli_transport *transport, void *private_data)
 {
        int i, j;
        for (i=0;i<NSERVERS;i++) {
@@ -1144,7 +1154,7 @@ static bool oplock_handler_smb2(struct smb2_transport *transport, const struct s
   an operation on another connection blocking until that break is acked
   we check for operations on all transports in the idle function
 */
-static void idle_func_smb2(struct smb2_transport *transport, void *private)
+static void idle_func_smb2(struct smb2_transport *transport, void *private_data)
 {
        int i, j;
        for (i=0;i<NSERVERS;i++) {
@@ -1164,6 +1174,8 @@ static void idle_func_smb2(struct smb2_transport *transport, void *private)
 */
 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
 {
+       char *s;
+
        if (NT_STATUS_EQUAL(status1, status2)) return true;
 
        /* one code being an error and the other OK is always an error */
@@ -1177,6 +1189,17 @@ static bool compare_status(NTSTATUS status1, NTSTATUS status2)
            ignore_pattern(nt_errstr(status2))) {
                return true;
        }
+
+       /* also support ignore patterns of the form NT_STATUS_XX:NT_STATUS_YY
+          meaning that the first server returns NT_STATUS_XX and the 2nd
+          returns NT_STATUS_YY */
+       s = talloc_asprintf(current_op.mem_ctx, "%s:%s", 
+                           nt_errstr(status1), 
+                           nt_errstr(status2));
+       if (ignore_pattern(s)) {
+               return true;
+       }
+
        current_op.mismatch = nt_errstr(status1);
        return false;
 }
@@ -1347,7 +1370,7 @@ again:
        } \
        current_op.status = status[0]; \
        for (i=1;i<NSERVERS;i++) { \
-               if (!compare_status(status[i], status[0])) { \
+               if (!compare_status(status[0], status[1])) { \
                        printf("status different in %s - %s %s\n", #call, \
                               nt_errstr(status[0]), nt_errstr(status[i])); \
                        current_op.mismatch = nt_errstr(status[0]); \
@@ -1458,7 +1481,9 @@ again:
 } while(0)
 
 #define CHECK_BLOB_EQUAL(field) do { \
-       if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
+       if (((parm[0].field.data == NULL && parm[1].field.data != NULL) || \
+           (parm[1].field.data == NULL && parm[0].field.data != NULL) || \
+           (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0)) && !ignore_pattern(#field)) { \
                current_op.mismatch = #field; \
                printf("Mismatch in %s\n", #field); \
                return false; \
@@ -1793,7 +1818,7 @@ static bool handler_smb_ntcreatex(int instance)
 
        parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
        parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
-       parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
+       parm[0].ntcreatex.in.root_fid.fnum = gen_root_fid(instance);
        parm[0].ntcreatex.in.access_mask = gen_access_mask();
        parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
        parm[0].ntcreatex.in.file_attr = gen_attrib();
@@ -1811,8 +1836,8 @@ static bool handler_smb_ntcreatex(int instance)
        }
        
        GEN_COPY_PARM;
-       if (parm[0].ntcreatex.in.root_fid != 0) {
-               GEN_SET_FNUM_SMB(ntcreatex.in.root_fid);
+       if (parm[0].ntcreatex.in.root_fid.fnum != 0) {
+               GEN_SET_FNUM_SMB(ntcreatex.in.root_fid.fnum);
        }
        GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
 
@@ -2163,6 +2188,9 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
        case RAW_SFILEINFO_MODE_INFORMATION:
                info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
                break;
+       case RAW_SFILEINFO_FULL_EA_INFORMATION:
+               info->full_ea_information.in.eas = gen_ea_list();
+               break;
        case RAW_SFILEINFO_GENERIC:
        case RAW_SFILEINFO_SEC_DESC:
        case RAW_SFILEINFO_UNIX_BASIC:
@@ -2198,16 +2226,20 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
                LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO), 
                LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
                LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION), 
-               LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
+               LVL(POSITION_INFORMATION), LVL(FULL_EA_INFORMATION), LVL(MODE_INFORMATION),
                LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION), 
-               LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040),
+               LVL(PIPE_INFORMATION), LVL(VALID_DATA_INFORMATION), LVL(SHORT_NAME_INFORMATION), 
+               LVL(1025), LVL(1027), LVL(1029), LVL(1030), LVL(1031), LVL(1032), LVL(1036),
+               LVL(1041), LVL(1042), LVL(1043), LVL(1044),
        };
        struct levels smb2_levels[] = {
                LVL(BASIC_INFORMATION),
                LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION), 
-               LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
+               LVL(POSITION_INFORMATION), LVL(FULL_EA_INFORMATION), LVL(MODE_INFORMATION),
                LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION), 
-               LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
+               LVL(PIPE_INFORMATION), LVL(VALID_DATA_INFORMATION), LVL(SHORT_NAME_INFORMATION), 
+               LVL(1025), LVL(1027), LVL(1029), LVL(1030), LVL(1031), LVL(1032), LVL(1036),
+               LVL(1041), LVL(1042), LVL(1043), LVL(1044),
        };
        struct levels *levels = options.smb2?smb2_levels:smb_levels;
        uint32_t num_levels = options.smb2?ARRAY_SIZE(smb2_levels):ARRAY_SIZE(smb_levels);
@@ -2215,7 +2247,8 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
        do {
                i = gen_int_range(0, num_levels-1);
        } while (ignore_pattern(levels[i].name));
-       
+
+       ZERO_STRUCTP(info);
        info->generic.level = levels[i].level;
 
        switch (info->generic.level) {
@@ -2272,15 +2305,15 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
        case RAW_SFILEINFO_MODE_INFORMATION:
                info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
                break;
+       case RAW_SFILEINFO_FULL_EA_INFORMATION:
+               info->full_ea_information.in.eas = gen_ea_list();
+               break;
 
        case RAW_SFILEINFO_GENERIC:
        case RAW_SFILEINFO_SEC_DESC:
-       case RAW_SFILEINFO_1023:
        case RAW_SFILEINFO_1025:
        case RAW_SFILEINFO_1029:
        case RAW_SFILEINFO_1032:
-       case RAW_SFILEINFO_1039:
-       case RAW_SFILEINFO_1040:
        case RAW_SFILEINFO_UNIX_BASIC:
        case RAW_SFILEINFO_UNIX_INFO2:
        case RAW_SFILEINFO_UNIX_LINK:
@@ -2368,9 +2401,8 @@ static bool handler_smb_spathinfo(int instance)
        union smb_setfileinfo parm[NSERVERS];
        NTSTATUS status[NSERVERS];
 
-       parm[0].generic.in.file.path = gen_fname_open(instance);
-
        gen_setfileinfo(instance, &parm[0]);
+       parm[0].generic.in.file.path = gen_fname_open(instance);
 
        GEN_COPY_PARM;
 
@@ -2628,7 +2660,7 @@ static bool handler_smb2_lock(int instance)
        parm[0].level = RAW_LOCK_LOCKX;
        parm[0].in.file.handle.data[0] = gen_fnum(instance);
        parm[0].in.lock_count = gen_lock_count();
-       parm[0].in.reserved = gen_reserved32();
+       parm[0].in.lock_sequence = gen_reserved32();
        
        parm[0].in.locks = talloc_array(current_op.mem_ctx,
                                        struct smb2_lock_element,
@@ -2739,9 +2771,8 @@ static bool handler_smb2_sfileinfo(int instance)
        union smb_setfileinfo parm[NSERVERS];
        NTSTATUS status[NSERVERS];
 
-       parm[0].generic.in.file.fnum = gen_fnum(instance);
-
        gen_setfileinfo(instance, &parm[0]);
+       parm[0].generic.in.file.fnum = gen_fnum(instance);
 
        GEN_COPY_PARM;
        GEN_SET_FNUM_SMB2(generic.in.file.handle);
@@ -2857,7 +2888,7 @@ static struct {
   run the test with the current set of op_parms parameters
   return the number of operations that completed successfully
 */
-static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
+static int run_test(struct tevent_context *ev, struct loadparm_context *lp_ctx)
 {
        int op, i;
 
@@ -2903,12 +2934,11 @@ static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
                current_op.opnum = op;
                current_op.name = gen_ops[which_op].name;
                current_op.status = NT_STATUS_OK;
+               talloc_free(current_op.mem_ctx);
                current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
 
                ret = gen_ops[which_op].handler(instance);
 
-               talloc_free(current_op.mem_ctx);
-
                gen_ops[which_op].count++;
                if (NT_STATUS_IS_OK(current_op.status)) {
                        gen_ops[which_op].success_count++;                      
@@ -2939,7 +2969,7 @@ static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
    perform a backtracking analysis of the minimal set of operations
    to generate an error
 */
-static void backtrack_analyze(struct event_context *ev,
+static void backtrack_analyze(struct tevent_context *ev,
                              struct loadparm_context *lp_ctx)
 {
        int chunk, ret;
@@ -3007,7 +3037,7 @@ static void backtrack_analyze(struct event_context *ev,
 /* 
    start the main gentest process
 */
-static bool start_gentest(struct event_context *ev,
+static bool start_gentest(struct tevent_context *ev,
                          struct loadparm_context *lp_ctx)
 {
        int op;
@@ -3022,7 +3052,7 @@ static bool start_gentest(struct event_context *ev,
        /* generate the seeds - after this everything is deterministic */
        if (options.use_preset_seeds) {
                int numops;
-               char **preset = file_lines_load(options.seeds_file, &numops, NULL);
+               char **preset = file_lines_load(options.seeds_file, &numops, 0, NULL);
                if (!preset) {
                        printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
                        exit(1);
@@ -3099,7 +3129,7 @@ static bool split_unc_name(const char *unc, char **server, char **share)
        int i, username_count=0;
        bool ret;
        char *ignore_file=NULL;
-       struct event_context *ev;
+       struct tevent_context *ev;
        struct loadparm_context *lp_ctx;
        poptContext pc;
        int argc_new;
@@ -3169,7 +3199,7 @@ static bool split_unc_name(const char *unc, char **server, char **share)
        }
 
        if (ignore_file) {
-               options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
+               options.ignore_patterns = file_lines_load(ignore_file, NULL, 0, NULL);
        }
 
        argv_new = discard_const_p(char *, poptGetArgs(pc));
@@ -3215,7 +3245,7 @@ static bool split_unc_name(const char *unc, char **server, char **share)
 
        printf("seed=%u\n", options.seed);
 
-       ev = event_context_init(talloc_autofree_context());
+       ev = s4_event_context_init(talloc_autofree_context());
 
        gensec_init(lp_ctx);