Move code to initialise struct smb2_create into own functions
authorSachin Prabhu <sprabhu@redhat.com>
Wed, 14 Feb 2018 09:51:36 +0000 (15:21 +0530)
committerSachin Prabhu <sprabhu@redhat.com>
Tue, 17 Jul 2018 20:46:27 +0000 (21:46 +0100)
Avoid code duplication

Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
source4/torture/smb2/multichannel.c

index 680bcd611c74ef3a4187cd082f64f2150202f4e8..df74c35ef51ecf6c09cca06a6d310eab36efd727 100644 (file)
@@ -429,6 +429,16 @@ fail:
        return false;
 }
 
+static void test_multichannel_init_smb_create(struct smb2_create *io)
+{
+       io->in.durable_open = false;
+       io->in.durable_open_v2 = true;
+       io->in.persistent_open = false;
+       io->in.create_guid = GUID_random();
+       io->in.timeout = 0x493E0; /* 300000 */
+       /* windows 2016 returns 300000 0x493E0 */
+}
+
 /**
  * Test Oplock Break with Multi Channel
  */
@@ -449,9 +459,6 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
        struct smb2_handle h_client2_file2 = { 0 };
        struct smb2_handle h_client2_file3 = { 0 };
        struct smb2_create io1, io2, io3;
-       struct GUID create_guid1 = GUID_random();
-       struct GUID create_guid2 = GUID_random();
-       struct GUID create_guid3 = GUID_random();
        bool ret = true;
        int rval;
        const char *fname1 = BASEDIR "\\oplock_break_test1.dat";
@@ -492,33 +499,17 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
        smb2_oplock_create_share(&io1, fname1,
                        smb2_util_share_access("RWD"),
                        smb2_util_oplock_level("b"));
-       io1.in.durable_open = false;
-       io1.in.durable_open_v2 = true;
-       io1.in.persistent_open = false;
-       io1.in.create_guid = create_guid1;
-       io1.in.timeout = UINT32_MAX;
-       io1.in.timeout = 0x493E0; /* 300000 */
-       /* windows 2016 returns 300000 0x493E0 */
+       test_multichannel_init_smb_create(&io1);
 
        smb2_oplock_create_share(&io2, fname2,
                        smb2_util_share_access("RWD"),
                        smb2_util_oplock_level("b"));
-       io2.in.durable_open = false;
-       io2.in.durable_open_v2 = true;
-       io2.in.persistent_open = false;
-       io2.in.create_guid = create_guid2;
-       io2.in.timeout = UINT32_MAX;
-       io2.in.timeout = 0x493E0; /* 300000 */
+       test_multichannel_init_smb_create(&io2);
 
        smb2_oplock_create_share(&io3, fname3,
                        smb2_util_share_access("RWD"),
                        smb2_util_oplock_level("b"));
-       io3.in.durable_open = false;
-       io3.in.durable_open_v2 = true;
-       io3.in.persistent_open = false;
-       io3.in.create_guid = create_guid3;
-       io3.in.timeout = UINT32_MAX;
-       io3.in.timeout = 0x493E0; /* 300000 */
+       test_multichannel_init_smb_create(&io3);
 
        transport2_options = transport1->options;
        rval = test_multichannel_create_channels2(tctx, host, share,
@@ -855,9 +846,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        struct smb2_handle h_client2_file2 = { 0 };
        struct smb2_handle h_client2_file3 = { 0 };
        struct smb2_create io1, io2, io3;
-       struct GUID create_guid1 = GUID_random();
-       struct GUID create_guid2 = GUID_random();
-       struct GUID create_guid3 = GUID_random();
        bool ret = true;
        int rval;
        const char *fname1 = BASEDIR "\\lease_break_test1.dat";
@@ -888,7 +876,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        transport1->lease.handler = torture_lease_handler;
        transport1->lease.private_data = tree1;
        torture_comment(tctx, "transport1  [%p]\n", transport1);
-
        local_port = torture_get_local_port_from_transport(transport1);
        torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port);
 
@@ -902,27 +889,15 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
 
        smb2_lease_create(&io1, &ls1, false, fname1, LEASE2F1,
                          smb2_util_lease_state("RHW"));
-       io1.in.durable_open = false;
-       io1.in.durable_open_v2 = true;
-       io1.in.persistent_open = false;
-       io1.in.create_guid = create_guid1;
-       io1.in.timeout = 0x493E0;
+       test_multichannel_init_smb_create(&io1);
 
        smb2_lease_create(&io2, &ls2, false, fname2, LEASE2F2,
                          smb2_util_lease_state("RHW"));
-       io2.in.durable_open = false;
-       io2.in.durable_open_v2 = true;
-       io2.in.persistent_open = false;
-       io2.in.create_guid = create_guid2;
-       io2.in.timeout = 0x493E0;
+       test_multichannel_init_smb_create(&io2);
 
        smb2_lease_create(&io3, &ls3, false, fname3, LEASE2F3,
                          smb2_util_lease_state("RHW"));
-       io3.in.durable_open = false;
-       io3.in.durable_open_v2 = true;
-       io3.in.persistent_open = false;
-       io3.in.create_guid = create_guid3;
-       io3.in.timeout = 0x493E0;
+       test_multichannel_init_smb_create(&io3);
 
        transport2_options = transport1->options;