s4-torture: removed more uses of typeof()
[ira/wip.git] / source4 / torture / basic / denytest.c
index 52b4d582e008a07add61302fa9371992ea3dd32e..8a5c24ca7949ed3affda114522d6aa390c7c2d33 100644 (file)
 */
 
 #include "includes.h"
-#include "torture/torture.h"
 #include "system/filesys.h"
-#include "libcli/raw/libcliraw.h"
 #include "libcli/libcli.h"
 #include "libcli/security/security.h"
 #include "torture/util.h"
-#include "torture/smbtorture.h"
-#include "libcli/util/clilsa.h"
 #include "cxd_known.h"
 
 extern int torture_failures;
@@ -1403,7 +1399,7 @@ static const struct {
 };
 
 
-static void progress_bar(struct torture_context *tctx, uint_t i, uint_t total)
+static void progress_bar(struct torture_context *tctx, unsigned int i, unsigned int total)
 {
        if (torture_setting_bool(tctx, "progress", true)) {
                torture_comment(tctx, "%5d/%5d\r", i, total);
@@ -1443,6 +1439,16 @@ bool torture_denytest1(struct torture_context *tctx,
 
                progress_bar(tctx, i, ARRAY_SIZE(denytable1));
 
+               if (!torture_setting_bool(tctx, "deny_fcb_support", true) &&
+                   (denytable1[i].deny1 == DENY_FCB ||
+                       denytable1[i].deny2 == DENY_FCB))
+                       continue;
+
+               if (!torture_setting_bool(tctx, "deny_dos_support", true) &&
+                   (denytable1[i].deny1 == DENY_DOS ||
+                       denytable1[i].deny2 == DENY_DOS))
+                       continue;
+
                fnum1 = smbcli_open(cli1->tree, fname, 
                                 denytable1[i].mode1,
                                 denytable1[i].deny1);
@@ -1530,6 +1536,16 @@ bool torture_denytest2(struct torture_context *tctx,
 
                progress_bar(tctx, i, ARRAY_SIZE(denytable1));
 
+               if (!torture_setting_bool(tctx, "deny_fcb_support", true) &&
+                   (denytable1[i].deny1 == DENY_FCB ||
+                       denytable1[i].deny2 == DENY_FCB))
+                       continue;
+
+               if (!torture_setting_bool(tctx, "deny_dos_support", true) &&
+                   (denytable1[i].deny1 == DENY_DOS ||
+                       denytable1[i].deny2 == DENY_DOS))
+                       continue;
+
                fnum1 = smbcli_open(cli1->tree, fname, 
                                 denytable2[i].mode1,
                                 denytable2[i].deny1);
@@ -1726,7 +1742,8 @@ static NTSTATUS predict_share_conflict(uint32_t sa1, uint32_t am1, uint32_t sa2,
   a denytest for ntcreatex
  */
 static bool torture_ntdenytest(struct torture_context *tctx, 
-                                                          struct smbcli_state *cli1, struct smbcli_state *cli2, int client)
+                              struct smbcli_state *cli1,
+                              struct smbcli_state *cli2, int client)
 {
        const struct bit_value share_access_bits[] = {
                { NTCREATEX_SHARE_ACCESS_READ,   "S_R" },
@@ -2078,13 +2095,6 @@ static int cxd_find_known(struct createx_data *cxd)
        return -1;
 }
 
-#define FILL_NTCREATEX(_struct, _init...)                       \
-       do {                                                    \
-               (_struct)->generic.level = RAW_OPEN_NTCREATEX;  \
-               (_struct)->ntcreatex.in                         \
-                   = (typeof((_struct)->ntcreatex.in)) {_init};\
-       } while (0)
-
 #define CREATEX_NAME "\\createx_dir"
 
 static bool createx_make_dir(struct torture_context *tctx,
@@ -2107,15 +2117,16 @@ static bool createx_make_file(struct torture_context *tctx,
        bool ret = true;
        NTSTATUS status;
 
-       FILL_NTCREATEX(&open_parms,
-           .flags = 0,
-           .access_mask = SEC_RIGHTS_FILE_ALL,
-           .file_attr = FILE_ATTRIBUTE_NORMAL,
-           .share_access = 0,
-           .open_disposition = NTCREATEX_DISP_CREATE,
-           .create_options = 0,
-           .fname = fname,
-       );
+       ZERO_STRUCT(open_parms);
+       open_parms.generic.level = RAW_OPEN_NTCREATEX;
+       open_parms.ntcreatex.in.flags = 0;
+       open_parms.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       open_parms.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       open_parms.ntcreatex.in.share_access = 0;
+       open_parms.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+       open_parms.ntcreatex.in.create_options = 0;
+       open_parms.ntcreatex.in.fname = fname;
+
        status = smb_raw_open(tree, mem_ctx, &open_parms);
        CHECK_STATUS(status, NT_STATUS_OK);
 
@@ -2129,30 +2140,30 @@ static bool createx_make_file(struct torture_context *tctx,
 static void createx_fill_dir(union smb_open *open_parms, int accessmode,
     int sharemode, const char *fname)
 {
-       FILL_NTCREATEX(open_parms,
-           .flags = 0,
-           .access_mask = accessmode,
-           .file_attr = FILE_ATTRIBUTE_DIRECTORY,
-           .share_access = sharemode,
-           .open_disposition = NTCREATEX_DISP_OPEN_IF,
-           .create_options = NTCREATEX_OPTIONS_DIRECTORY,
-           .fname = fname,
-       );
+       ZERO_STRUCTP(open_parms);
+       open_parms->generic.level = RAW_OPEN_NTCREATEX;
+       open_parms->ntcreatex.in.flags = 0;
+       open_parms->ntcreatex.in.access_mask = accessmode;
+       open_parms->ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
+       open_parms->ntcreatex.in.share_access = sharemode;
+       open_parms->ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+       open_parms->ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+       open_parms->ntcreatex.in.fname = fname;
 }
 
 static void createx_fill_file(union smb_open *open_parms, int accessmode,
     int sharemode, const char *fname)
 {
-       FILL_NTCREATEX(open_parms,
-           .flags = 0,
-           .access_mask = accessmode,
-           .file_attr = FILE_ATTRIBUTE_NORMAL,
-           .share_access = sharemode,
-           .open_disposition = NTCREATEX_DISP_OPEN_IF,
-           .create_options = 0,
-           .fname = fname,
-            .root_fid = { .fnum = 0 },
-       );
+       ZERO_STRUCTP(open_parms);
+       open_parms->generic.level = RAW_OPEN_NTCREATEX;
+       open_parms->ntcreatex.in.flags = 0;
+       open_parms->ntcreatex.in.access_mask = accessmode;
+       open_parms->ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       open_parms->ntcreatex.in.share_access = sharemode;
+       open_parms->ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+       open_parms->ntcreatex.in.create_options = 0;
+       open_parms->ntcreatex.in.fname = fname;
+       open_parms->ntcreatex.in.root_fid.fnum = 0;
 }
 
 static int data_file_fd = -1;
@@ -2167,15 +2178,16 @@ static bool createx_test_dir(struct torture_context *tctx,
        union smb_open open_parms;
 
        /* bypass original handle to guarantee creation */
-       FILL_NTCREATEX(&open_parms,
-           .flags = 0,
-           .access_mask = SEC_RIGHTS_FILE_ALL,
-           .file_attr = FILE_ATTRIBUTE_NORMAL,
-           .share_access = 0,
-           .open_disposition = NTCREATEX_DISP_CREATE,
-           .create_options = 0,
-           .fname = CREATEX_NAME "\\" KNOWN,
-       );
+       ZERO_STRUCT(open_parms);
+       open_parms.generic.level = RAW_OPEN_NTCREATEX;
+       open_parms.ntcreatex.in.flags = 0;
+       open_parms.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       open_parms.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       open_parms.ntcreatex.in.share_access = 0;
+       open_parms.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+       open_parms.ntcreatex.in.create_options = 0;
+       open_parms.ntcreatex.in.fname = CREATEX_NAME "\\" KNOWN;
+
        status = smb_raw_open(tree, mem_ctx, &open_parms);
        CHECK_STATUS(status, NT_STATUS_OK);
        smbcli_close(tree, open_parms.ntcreatex.out.file.fnum);
@@ -2183,32 +2195,32 @@ static bool createx_test_dir(struct torture_context *tctx,
        result[CXD_DIR_ENUMERATE] = NT_STATUS_OK;
 
        /* try to create a child */
-       FILL_NTCREATEX(&open_parms,
-           .flags = 0,
-           .access_mask = SEC_RIGHTS_FILE_ALL,
-           .file_attr = FILE_ATTRIBUTE_NORMAL,
-           .share_access = 0,
-           .open_disposition = NTCREATEX_DISP_CREATE,
-           .create_options = 0,
-           .fname = CHILD,
-           .root_fid = { .fnum = fnum },
-       );
+       ZERO_STRUCT(open_parms);
+       open_parms.generic.level = RAW_OPEN_NTCREATEX;
+       open_parms.ntcreatex.in.flags = 0;
+       open_parms.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       open_parms.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       open_parms.ntcreatex.in.share_access = 0;
+       open_parms.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+       open_parms.ntcreatex.in.create_options = 0;
+       open_parms.ntcreatex.in.fname = CHILD;
+       open_parms.ntcreatex.in.root_fid.fnum = fnum;
 
        result[CXD_DIR_CREATE_CHILD] =
            smb_raw_open(tree, mem_ctx, &open_parms);
        smbcli_close(tree, open_parms.ntcreatex.out.file.fnum);
 
        /* try to traverse dir to known good file */
-       FILL_NTCREATEX(&open_parms,
-           .flags = 0,
-           .access_mask = SEC_RIGHTS_FILE_ALL,
-           .file_attr = FILE_ATTRIBUTE_NORMAL,
-           .share_access = 0,
-           .open_disposition = NTCREATEX_DISP_OPEN,
-           .create_options = 0,
-           .fname = KNOWN,
-           .root_fid = {.fnum = fnum},
-       );
+       ZERO_STRUCT(open_parms);
+       open_parms.generic.level = RAW_OPEN_NTCREATEX;
+       open_parms.ntcreatex.in.flags = 0;
+       open_parms.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       open_parms.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       open_parms.ntcreatex.in.share_access = 0;
+       open_parms.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+       open_parms.ntcreatex.in.create_options = 0;
+       open_parms.ntcreatex.in.fname = KNOWN;
+       open_parms.ntcreatex.in.root_fid.fnum = fnum;
 
        result[CXD_DIR_TRAVERSE] =
            smb_raw_open(tree, mem_ctx, &open_parms);
@@ -2225,10 +2237,11 @@ static bool createx_test_dir(struct torture_context *tctx,
 static bool createx_test_file(struct torture_context *tctx,
     struct smbcli_tree *tree, int fnum, TALLOC_CTX *mem_ctx, NTSTATUS *result)
 {
-       union smb_read rd = {};
-       union smb_write wr = {};
+       union smb_read rd;
+       union smb_write wr;
        char buf[256] = "";
 
+       memset(&rd, 0, sizeof(rd));
        rd.readx.level = RAW_READ_READX;
        rd.readx.in.file.fnum = fnum;
        rd.readx.in.mincnt = sizeof(buf);
@@ -2237,6 +2250,7 @@ static bool createx_test_file(struct torture_context *tctx,
 
        result[CXD_FILE_READ] = smb_raw_read(tree, &rd);
 
+       memset(&wr, 0, sizeof(wr));
        wr.writex.level = RAW_WRITE_WRITEX;
        wr.writex.in.file.fnum = fnum;
        wr.writex.in.count = sizeof(buf);
@@ -2260,8 +2274,8 @@ static bool createx_test_file(struct torture_context *tctx,
 /* TODO When redirecting stdout to a file, the progress bar really screws up
  * the output. Could use a switch "--noprogress", or direct the progress bar to
  * stderr? No other solution? */
-static void createx_progress_bar(struct torture_context *tctx, uint_t i,
-    uint_t total, uint_t skipped)
+static void createx_progress_bar(struct torture_context *tctx, unsigned int i,
+    unsigned int total, unsigned int skipped)
 {
        if (torture_setting_bool(tctx, "progress", true)) {
                torture_comment(tctx, "%5d/%5d (%d skipped)\r", i, total,
@@ -2665,7 +2679,7 @@ bool torture_maximum_allowed(struct torture_context *tctx,
     struct smbcli_state *cli)
 {
        struct security_descriptor *sd, *sd_orig;
-       union smb_open io = {};
+       union smb_open io;
        static TALLOC_CTX *mem_ctx;
        int fnum, i;
        bool ret = true;
@@ -2690,6 +2704,7 @@ bool torture_maximum_allowed(struct torture_context *tctx,
        smbcli_unlink(cli->tree, MAXIMUM_ALLOWED_FILE);
 
        /* create initial file with restrictive SD */
+       memset(&io, 0, sizeof(io));
        io.generic.level = RAW_OPEN_NTTRANS_CREATE;
        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
@@ -2777,5 +2792,6 @@ bool torture_maximum_allowed(struct torture_context *tctx,
        }
 
  done:
+       smbcli_unlink(cli->tree, MAXIMUM_ALLOWED_FILE);
        return ret;
 }