sq source4/torture/smb2/timestamps.c
authorStefan Metzmacher <metze@samba.org>
Wed, 15 Aug 2018 19:11:39 +0000 (21:11 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 15 Aug 2018 19:11:39 +0000 (21:11 +0200)
source4/torture/smb2/timestamps.c

index 55c6b1694226a0144de3742a00d4ac0a314d366c..259075ebc00acefafffe051870ac97669cd21ffa 100644 (file)
@@ -39,8 +39,6 @@
 #define CHECK_CREATED(__io, __created, __attribute)                    \
        do {                                                            \
                CHECK_VAL((__io)->out.create_action, NTCREATEX_ACTION_ ## __created); \
-               CHECK_VAL((__io)->out.alloc_size, 0);                   \
-               CHECK_VAL((__io)->out.size, 0);                         \
                CHECK_VAL((__io)->out.file_attr, (__attribute));        \
                CHECK_VAL((__io)->out.reserved2, 0);                    \
        } while(0)
        COMPARE_CREATE_TIME_EQUAL(given,correct); \
 } while (0)
 
+#define DEBUG_BASIC_INFO(finfo, comment) do { \
+       struct timeval atv; \
+       struct timeval wtv; \
+       struct timeval_buf atvb; \
+       struct timeval_buf wtvb; \
+       nttime_to_timeval(&atv, finfo.basic_info.out.access_time); \
+       nttime_to_timeval(&wtv, finfo.basic_info.out.write_time); \
+       torture_comment(tctx, "%s: Access(%s) Write(%s)\n", \
+                       comment, \
+                       timeval_str_buf(&atv, false, true, &atvb), \
+                       timeval_str_buf(&wtv, false, true, &wtvb)); \
+} while (0)
 #define GET_INFO_FILE(tree, finfo) do { \
-       struct timeval _atv; \
-       struct timeval _wtv; \
-       struct timeval_buf _atvb; \
-       struct timeval_buf _wtvb; \
        NTSTATUS _status; \
        _status = smb2_getinfo_file(tree, tctx, &finfo); \
        if (!NT_STATUS_IS_OK(_status)) { \
                               nt_errstr(_status)); \
                goto done; \
        } \
-       nttime_to_timeval(&_atv, finfo.basic_info.out.access_time); \
-       nttime_to_timeval(&_wtv, finfo.basic_info.out.write_time); \
-       torture_comment(tctx, "fileinfo(%s,%s): Access(%s) Write(%s)\n", \
-                       #tree, #finfo, \
-                       timeval_str_buf(&_atv, false, true, &_atvb), \
-                       timeval_str_buf(&_wtv, false, true, &_wtvb)); \
+       DEBUG_BASIC_INFO(finfo, "fileinfo(" #tree ")"); \
 } while (0)
 
 #define GET_INFO_BOTH(finfo1, finfo2) do { \
        COMPARE_ALL_TIMES_EQUAL(finfo1, finfo2); \
 } while (0)
 
-#define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \
-       NTSTATUS _status; \
-       union smb_setfileinfo sfinfo; \
-       sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
-       sfinfo.basic_info.in.file.fnum = tfnum; \
-       sfinfo.basic_info.in.create_time = 0; \
-       sfinfo.basic_info.in.access_time = 0; \
-       unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
-       sfinfo.basic_info.in.change_time = 0; \
-       sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \
-       _status = smb_raw_setfileinfo(tree, &sfinfo); \
-       if (!NT_STATUS_IS_OK(_status)) { \
-               torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
-                              nt_errstr(_status)); \
-               ret = false; \
-               goto done; \
-       } \
-} while (0)
-#define SET_INFO_FILE(finfo, wrtime) \
-       SET_INFO_FILE_EX(finfo, wrtime, cli->tree, fnum1)
-
-#define SET_INFO_FILE_NS(finfo, wrtime, ns, tree, tfnum) do { \
-       NTSTATUS _status; \
-       union smb_setfileinfo sfinfo; \
-       sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
-       sfinfo.basic_info.in.file.fnum = tfnum; \
-       sfinfo.basic_info.in.create_time = 0; \
-       sfinfo.basic_info.in.access_time = 0; \
-       unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
-       sfinfo.basic_info.in.write_time += (ns); \
-       sfinfo.basic_info.in.change_time = 0; \
-       sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \
-       _status = smb_raw_setfileinfo(tree, &sfinfo); \
-       if (!NT_STATUS_IS_OK(_status)) { \
-               torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
-                              nt_errstr(_status)); \
-               ret = false; \
-               goto done; \
-       } \
-} while (0)
-
-struct test_durable_open_delaywrite1_state {
+struct test_timestamp_delaywrite1_state {
        struct torture_context *tctx;
        struct smb2_tree *tree1;
        struct smb2_tree *tree2;
@@ -185,11 +145,11 @@ struct test_durable_open_delaywrite1_state {
        struct smb2_handle *h2;
 };
 
-static bool test_durable_open_delaywrite1_get_info(void *private_data,
+static bool test_timestamp_delaywrite1_get_info(void *private_data,
                                                   union smb_fileinfo *finfo)
 {
-       struct test_durable_open_delaywrite1_state *state =
-               (struct test_durable_open_delaywrite1_state *)private_data;
+       struct test_timestamp_delaywrite1_state *state =
+               (struct test_timestamp_delaywrite1_state *)private_data;
        struct torture_context *tctx = state->tctx;
        union smb_fileinfo t1finfo;
        union smb_fileinfo t2finfo;
@@ -221,10 +181,10 @@ done:
        return ret;
 }
 
-static bool test_durable_open_delaywrite1_write_data(void *private_data)
+static bool test_timestamp_delaywrite1_write_data(void *private_data)
 {
-       struct test_durable_open_delaywrite1_state *state =
-               (struct test_durable_open_delaywrite1_state *)private_data;
+       struct test_timestamp_delaywrite1_state *state =
+               (struct test_timestamp_delaywrite1_state *)private_data;
        struct torture_context *tctx = state->tctx;
        struct smb2_write wr;
        NTSTATUS status;
@@ -243,11 +203,11 @@ done:
        return ret;
 }
 
-static bool test_durable_open_delaywrite1_close(void *private_data,
+static bool test_timestamp_delaywrite1_close(void *private_data,
                                                union smb_fileinfo *finfo)
 {
-       struct test_durable_open_delaywrite1_state *state =
-               (struct test_durable_open_delaywrite1_state *)private_data;
+       struct test_timestamp_delaywrite1_state *state =
+               (struct test_timestamp_delaywrite1_state *)private_data;
        struct torture_context *tctx = state->tctx;
        union smb_fileinfo t1finfoCL;
        union smb_fileinfo t2finfoCL;
@@ -299,11 +259,13 @@ done:
        return ret;
 }
 
-static bool test_durable_open_delaywrite1(struct torture_context *tctx,
-                                         struct smb2_tree *tree1,
-                                         struct smb2_tree *tree2)
+static bool test_timestamp_delaywrite1x(struct torture_context *tctx,
+                                       struct smb2_tree *tree1,
+                                       struct smb2_tree *tree2,
+                                       const char *description,
+                                       bool reconnect)
 {
-       struct test_durable_open_delaywrite1_state state = {
+       struct test_timestamp_delaywrite1_state state = {
                .tctx = tctx,
                .tree1 = tree1,
                .tree2 = tree2,
@@ -326,7 +288,7 @@ static bool test_durable_open_delaywrite1(struct torture_context *tctx,
                                         normal_delay);
 
        /* Choose a random name in case the state is left a little funky. */
-       snprintf(fname, 256, "durable_open_delaywrite1_%s.dat",
+       snprintf(fname, 256, "%s_%s.dat", description,
                 generate_random_str(tctx, 8));
 
        smb2_util_unlink(tree1, fname);
@@ -351,7 +313,7 @@ static bool test_durable_open_delaywrite1(struct torture_context *tctx,
        cr2.in.durable_open = false;
        cr2.in.oplock_level = 0;
        cr2.in.create_disposition = NTCREATEX_DISP_OPEN;
-       status = smb2_create(tree2, mem_ctx, &cr2);
+       status = smb2_create(state.tree2, mem_ctx, &cr2);
        CHECK_STATUS(status, NT_STATUS_OK);
        _h2 = cr2.out.file.handle;
        state.h2 = &_h2;
@@ -390,17 +352,17 @@ static bool test_durable_open_delaywrite1(struct torture_context *tctx,
 
        ok = test_smb_timestamp_writetime1(tctx, used_delay, normal_delay,
                        "run1",
-                       test_durable_open_delaywrite1_get_info,
-                       test_durable_open_delaywrite1_write_data,
+                       test_timestamp_delaywrite1_get_info,
+                       test_timestamp_delaywrite1_write_data,
                        NULL, /* close_cb */
                        &state);
        torture_assert_goto(tctx, ok, ret, done,
                            "test_smb_timestamp_writetime1(1)");
        ok = test_smb_timestamp_writetime1(tctx, used_delay, normal_delay,
                        "run2",
-                       test_durable_open_delaywrite1_get_info,
-                       test_durable_open_delaywrite1_write_data,
-                       test_durable_open_delaywrite1_close,
+                       test_timestamp_delaywrite1_get_info,
+                       test_timestamp_delaywrite1_write_data,
+                       test_timestamp_delaywrite1_close,
                        &state);
        torture_assert_goto(tctx, ok, ret, done,
                            "test_smb_timestamp_writetime1(2)");
@@ -413,10 +375,10 @@ done:
                smb2_util_close(tree2, *state.h2);
        }
 
-       smb2_util_unlink(tree1, fname);
+       smb2_util_unlink(tree2, fname);
 
-       talloc_free(tree1);
-       talloc_free(tree2);
+       TALLOC_FREE(tree1);
+       TALLOC_FREE(tree2);
 
        talloc_free(mem_ctx);
 
@@ -429,7 +391,7 @@ struct torture_suite *torture_smb2_timestamps_init(TALLOC_CTX *ctx)
            torture_suite_create(ctx, "timestamps");
 
        torture_suite_add_2smb2_test(suite, "delaywrite1",
-                                    test_durable_open_delaywrite1);
+                                    test_timestamp_delaywrite1);
 
        suite->description = talloc_strdup(suite, "SMB2-TIMESTAMPS tests");