diff options
Diffstat (limited to 'source4/torture/raw/open.c')
-rw-r--r-- | source4/torture/raw/open.c | 344 |
1 files changed, 279 insertions, 65 deletions
diff --git a/source4/torture/raw/open.c b/source4/torture/raw/open.c index 9f35aae4d0..73f9c3f839 100644 --- a/source4/torture/raw/open.c +++ b/source4/torture/raw/open.c @@ -65,7 +65,8 @@ static const char *rdwr_string(enum rdwr_mode m) #define CHECK_STATUS(status, correct) do { \ if (!NT_STATUS_EQUAL(status, correct)) { \ - printf("(%s) Incorrect status %s - should be %s\n", \ + torture_result(tctx, TORTURE_FAIL, \ + "(%s) Incorrect status %s - should be %s\n", \ __location__, nt_errstr(status), nt_errstr(correct)); \ ret = false; \ goto done; \ @@ -74,7 +75,9 @@ static const char *rdwr_string(enum rdwr_mode m) #define CREATE_FILE do { \ fnum = create_complex_file(cli, tctx, fname); \ if (fnum == -1) { \ - printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \ + torture_result(tctx, TORTURE_FAIL, \ + "(%s) Failed to create %s - %s\n", \ + __location__, fname, smbcli_errstr(cli->tree)); \ ret = false; \ goto done; \ }} while (0) @@ -82,7 +85,8 @@ static const char *rdwr_string(enum rdwr_mode m) #define CHECK_RDWR(fnum, correct) do { \ enum rdwr_mode m = check_rdwr(cli->tree, fnum); \ if (m != correct) { \ - printf("(%s) Incorrect readwrite mode %s - expected %s\n", \ + torture_result(tctx, TORTURE_FAIL, \ + "(%s) Incorrect readwrite mode %s - expected %s\n", \ __location__, rdwr_string(m), rdwr_string(correct)); \ ret = false; \ }} while (0) @@ -96,7 +100,8 @@ static const char *rdwr_string(enum rdwr_mode m) t1 = t & ~1; \ t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \ if (abs(t1-t2) > 2) { \ - printf("(%s) wrong time for field %s %s - %s\n", \ + torture_result(tctx, TORTURE_FAIL, \ + "(%s) wrong time for field %s %s - %s\n", \ __location__, #field, \ timestring(tctx, t1), \ timestring(tctx, t2)); \ @@ -112,7 +117,8 @@ static const char *rdwr_string(enum rdwr_mode m) CHECK_STATUS(status, NT_STATUS_OK); \ t2 = finfo.all_info.out.field; \ if (t != t2) { \ - printf("(%s) wrong time for field %s %s - %s\n", \ + torture_result(tctx, TORTURE_FAIL, \ + "(%s) wrong time for field %s %s - %s\n", \ __location__, #field, \ nt_time_string(tctx, t), \ nt_time_string(tctx, t2)); \ @@ -126,7 +132,8 @@ static const char *rdwr_string(enum rdwr_mode m) status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \ CHECK_STATUS(status, NT_STATUS_OK); \ if ((v) != (finfo.all_info.out.field)) { \ - printf("(%s) wrong value for field %s 0x%x - 0x%x\n", \ + torture_result(tctx, TORTURE_FAIL, \ + "(%s) wrong value for field %s 0x%x - 0x%x\n", \ __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \ dump_all_info(tctx, &finfo); \ ret = false; \ @@ -134,7 +141,8 @@ static const char *rdwr_string(enum rdwr_mode m) #define CHECK_VAL(v, correct) do { \ if ((v) != (correct)) { \ - printf("(%s) wrong value for %s 0x%x - should be 0x%x\n", \ + torture_result(tctx, TORTURE_FAIL, \ + "(%s) wrong value for %s 0x%x - should be 0x%x\n", \ __location__, #v, (int)(v), (int)correct); \ ret = false; \ }} while (0) @@ -147,7 +155,7 @@ static const char *rdwr_string(enum rdwr_mode m) sfinfo.basic_info.in.attrib = sattrib; \ status = smb_raw_setpathinfo(cli->tree, &sfinfo); \ if (!NT_STATUS_IS_OK(status)) { \ - printf("(%s) Failed to set attrib 0x%x on %s\n", \ + torture_warning(tctx, "(%s) Failed to set attrib 0x%x on %s\n", \ __location__, sattrib, fname); \ }} while (0) @@ -163,7 +171,7 @@ static bool test_open(struct smbcli_state *cli, struct torture_context *tctx) int fnum = -1, fnum2; bool ret = true; - printf("Checking RAW_OPEN_OPEN\n"); + torture_comment(tctx, "Checking RAW_OPEN_OPEN\n"); io.openold.level = RAW_OPEN_OPEN; io.openold.in.fname = fname; @@ -223,7 +231,7 @@ static bool test_open(struct smbcli_state *cli, struct torture_context *tctx) CHECK_RDWR(fnum, RDWR_RDWR); if (io.openold.in.open_mode != io.openold.out.rmode) { - printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n", + torture_warning(tctx, "(%s) rmode should equal open_mode - 0x%x 0x%x\n", __location__, io.openold.out.rmode, io.openold.in.open_mode); } @@ -295,7 +303,7 @@ static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx) { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK }, }; - printf("Checking RAW_OPEN_OPENX\n"); + torture_comment(tctx, "Checking RAW_OPEN_OPENX\n"); smbcli_unlink(cli->tree, fname); io.openx.level = RAW_OPEN_OPENX; @@ -313,7 +321,9 @@ static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx) if (open_funcs[i].with_file) { fnum = create_complex_file(cli, tctx, fname); if (fnum == -1) { - d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree)); + torture_result(tctx, TORTURE_FAIL, + "Failed to create file %s - %s\n", + fname, smbcli_errstr(cli->tree)); ret = false; goto done; } @@ -322,9 +332,13 @@ static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx) io.openx.in.open_func = open_funcs[i].open_func; status = smb_raw_open(cli->tree, tctx, &io); if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) { - printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n", - __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status), - i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func); + torture_result(tctx, TORTURE_FAIL, + "(%s) incorrect status %s should be %s " + "(i=%d with_file=%d open_func=0x%x)\n", + __location__, nt_errstr(status), + nt_errstr(open_funcs[i].correct_status), + i, (int)open_funcs[i].with_file, + (int)open_funcs[i].open_func); ret = false; } if (NT_STATUS_IS_OK(status)) { @@ -424,8 +438,10 @@ static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx) status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); if (timeval_elapsed(&tv) > 3.0) { - printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n", - __location__, timeval_elapsed(&tv)); + torture_result(tctx, TORTURE_FAIL, + "(%s) Incorrect timing in openx with timeout " + "- waited %.2f seconds\n", + __location__, timeval_elapsed(&tv)); ret = false; } smbcli_close(cli->tree, fnum); @@ -527,13 +543,15 @@ static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx) fnum = create_complex_file(cli, tctx, fname1); if (fnum == -1) { - d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree)); + torture_result(tctx, TORTURE_FAIL, + "(%s): Failed to create file %s - %s\n", + __location__, fname1, smbcli_errstr(cli->tree)); ret = false; goto done; } smbcli_close(cli->tree, fnum); - printf("Checking RAW_OPEN_T2OPEN\n"); + torture_comment(tctx, "Checking RAW_OPEN_T2OPEN\n"); io.t2open.level = RAW_OPEN_T2OPEN; io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO; @@ -570,16 +588,21 @@ static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx) if ((io.t2open.in.num_eas != 0) && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED) && torture_setting_bool(tctx, "samba3", false)) { - printf("(%s) EAs not supported, not treating as fatal " - "in Samba3 test\n", __location__); + torture_warning(tctx, "(%s) EAs not supported, not " + "treating as fatal in Samba3 test\n", + __location__); io.t2open.in.num_eas = 0; goto again; } if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) { - printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n", - __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status), - i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func); + torture_result(tctx, TORTURE_FAIL, + "(%s) incorrect status %s should be %s " + "(i=%d with_file=%d open_func=0x%x)\n", + __location__, nt_errstr(status), + nt_errstr(open_funcs[i].correct_status), + i, (int)open_funcs[i].with_file, + (int)open_funcs[i].open_func); ret = false; } if (NT_STATUS_IS_OK(status)) { @@ -691,12 +714,12 @@ static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tct { 6, false, NT_STATUS_INVALID_PARAMETER }, }; - printf("Checking RAW_OPEN_NTCREATEX\n"); + torture_comment(tctx, "Checking RAW_OPEN_NTCREATEX\n"); /* reasonable default parameters */ io.generic.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; - io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; io.ntcreatex.in.alloc_size = 1024*1024; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; @@ -712,7 +735,9 @@ static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tct if (open_funcs[i].with_file) { fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE); if (fnum == -1) { - d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree)); + torture_result(tctx, TORTURE_FAIL, + "Failed to create file %s - %s\n", + fname, smbcli_errstr(cli->tree)); ret = false; goto done; } @@ -721,9 +746,13 @@ static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tct io.ntcreatex.in.open_disposition = open_funcs[i].open_disp; status = smb_raw_open(cli->tree, tctx, &io); if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) { - printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n", - __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status), - i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp); + torture_result(tctx, TORTURE_FAIL, + "(%s) incorrect status %s should be %s " + "(i=%d with_file=%d open_disp=%d)\n", + __location__, nt_errstr(status), + nt_errstr(open_funcs[i].correct_status), + i, (int)open_funcs[i].with_file, + (int)open_funcs[i].open_disp); ret = false; } if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) { @@ -866,12 +895,12 @@ static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context { 6, false, NT_STATUS_INVALID_PARAMETER }, }; - printf("Checking RAW_OPEN_NTTRANS_CREATE\n"); + torture_comment(tctx, "Checking RAW_OPEN_NTTRANS_CREATE\n"); /* reasonable default parameters */ io.generic.level = RAW_OPEN_NTTRANS_CREATE; io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; - io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; io.ntcreatex.in.alloc_size = 1024*1024; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; @@ -889,7 +918,9 @@ static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context if (open_funcs[i].with_file) { fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE); if (fnum == -1) { - d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree)); + torture_result(tctx, TORTURE_FAIL, + "Failed to create file %s - %s\n", + fname, smbcli_errstr(cli->tree)); ret = false; goto done; } @@ -898,9 +929,13 @@ static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context io.ntcreatex.in.open_disposition = open_funcs[i].open_disp; status = smb_raw_open(cli->tree, tctx, &io); if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) { - printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n", - __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status), - i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp); + torture_result(tctx, TORTURE_FAIL, + "(%s) incorrect status %s should be %s " + "(i=%d with_file=%d open_disp=%d)\n", + __location__, nt_errstr(status), + nt_errstr(open_funcs[i].correct_status), + i, (int)open_funcs[i].with_file, + (int)open_funcs[i].open_disp); ret = false; } if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) { @@ -984,8 +1019,9 @@ static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context io.ntcreatex.in.create_options = create_option; status = smb_raw_open(cli->tree, tctx, &io); if (!NT_STATUS_IS_OK(status)) { - printf("ntcreatex create option 0x%08x gave %s - should give NT_STATUS_OK\n", - create_option, nt_errstr(status)); + torture_warning(tctx, "ntcreatex create option 0x%08x " + "gave %s - should give NT_STATUS_OK\n", + create_option, nt_errstr(status)); } CHECK_STATUS(status, NT_STATUS_OK); fnum = io.ntcreatex.out.file.fnum; @@ -1032,7 +1068,8 @@ static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context not_a_directory_mask |= 1<<i; } else { unexpected_mask |= 1<<i; - printf("create option 0x%08x returned %s\n", create_option, nt_errstr(status)); + torture_comment(tctx, "create option 0x%08x returned %s\n", + create_option, nt_errstr(status)); } } @@ -1110,11 +1147,11 @@ static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_con NTSTATUS status; bool ret = true; - printf("Testing ntcreatex with a byte range locked file\n"); + torture_comment(tctx, "Testing ntcreatex with a byte range locked file\n"); io.generic.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; - io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.access_mask = 0x2019f; io.ntcreatex.in.alloc_size = 0; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; @@ -1145,7 +1182,7 @@ static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_con io1.generic.level = RAW_OPEN_NTCREATEX; io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; - io1.ntcreatex.in.root_fid = 0; + io1.ntcreatex.in.root_fid.fnum = 0; io1.ntcreatex.in.access_mask = 0x20196; io1.ntcreatex.in.alloc_size = 0; io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; @@ -1181,7 +1218,7 @@ static bool test_mknew(struct smbcli_state *cli, struct torture_context *tctx) time_t basetime = (time(NULL) + 3600*24*3) & ~1; union smb_fileinfo finfo; - printf("Checking RAW_OPEN_MKNEW\n"); + torture_comment(tctx, "Checking RAW_OPEN_MKNEW\n"); io.mknew.level = RAW_OPEN_MKNEW; io.mknew.in.attrib = 0; @@ -1236,7 +1273,7 @@ static bool test_create(struct smbcli_state *cli, struct torture_context *tctx) time_t basetime = (time(NULL) + 3600*24*3) & ~1; union smb_fileinfo finfo; - printf("Checking RAW_OPEN_CREATE\n"); + torture_comment(tctx, "Checking RAW_OPEN_CREATE\n"); io.create.level = RAW_OPEN_CREATE; io.create.in.attrib = 0; @@ -1292,7 +1329,7 @@ static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx) union smb_fileinfo finfo; const char *name, *fname = NULL; - printf("Checking RAW_OPEN_CTEMP\n"); + torture_comment(tctx, "Checking RAW_OPEN_CTEMP\n"); io.ctemp.level = RAW_OPEN_CTEMP; io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN; @@ -1310,7 +1347,7 @@ static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx) CHECK_STATUS(status, NT_STATUS_OK); fname = finfo.name_info.out.fname.s; - d_printf("ctemp name=%s real name=%s\n", name, fname); + torture_comment(tctx, "ctemp name=%s real name=%s\n", name, fname); done: smbcli_close(cli->tree, fnum); @@ -1335,7 +1372,7 @@ static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx) const char *buf = "test"; char buf2[4]; - printf("Checking RAW_OPEN_OPENX chained with READX\n"); + torture_comment(tctx, "Checking RAW_OPEN_OPENX chained with READX\n"); smbcli_unlink(cli->tree, fname); fnum = create_complex_file(cli, tctx, fname); @@ -1366,7 +1403,8 @@ static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx) fnum = io.openxreadx.out.file.fnum; if (memcmp(buf, buf2, sizeof(buf)) != 0) { - d_printf("wrong data in reply buffer\n"); + torture_result(tctx, TORTURE_FAIL, + "wrong data in reply buffer\n"); ret = false; } @@ -1391,15 +1429,16 @@ static bool test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *tctx) bool ret = true; const char *buf = "test"; - printf("Checking RAW_OPEN_OPENX without leading slash on path\n"); + torture_comment(tctx, "Checking RAW_OPEN_OPENX without leading " + "slash on path\n"); smbcli_unlink(cli->tree, fname); - /* Create the file */ + /* Create the file */ fnum = create_complex_file(cli, tctx, fname); smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf)); smbcli_close(cli->tree, fnum); - /* Prepare to open the file using path without leading slash */ + /* Prepare to open the file using path without leading slash */ io.openx.level = RAW_OPEN_OPENX; io.openx.in.fname = fname + 1; io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO; @@ -1437,14 +1476,14 @@ static bool test_openx_over_dir(struct smbcli_state *cli, TALLOC_CTX *tctx) int fnum = -1; bool ret = true; - printf("Checking RAW_OPEN_OPENX over an existing directory\n"); + torture_comment(tctx, "Checking RAW_OPEN_OPENX over an existing directory\n"); smbcli_unlink(cli->tree, fname); - /* Create the Directory */ + /* Create the Directory */ status = create_directory_handle(cli->tree, fname, &d_fnum); smbcli_close(cli->tree, d_fnum); - /* Prepare to open the file over the directory. */ + /* Prepare to open the file over the directory. */ io.openx.level = RAW_OPEN_OPENX; io.openx.in.fname = fname; io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO; @@ -1492,7 +1531,8 @@ static bool test_raw_open_multi(struct torture_context *tctx) ios = talloc_array(mem_ctx, union smb_open, num_files); if ((tctx->ev == NULL) || (clients == NULL) || (requests == NULL) || (ios == NULL)) { - DEBUG(0, ("talloc failed\n")); + torture_result(tctx, TORTURE_FAIL, "(%s): talloc failed\n", + __location__); return false; } @@ -1505,7 +1545,9 @@ static bool test_raw_open_multi(struct torture_context *tctx) for (i=0; i<num_files; i++) { if (!torture_open_connection_share(mem_ctx, &(clients[i]), tctx, host, share, tctx->ev)) { - DEBUG(0, ("Could not open %d'th connection\n", i)); + torture_result(tctx, TORTURE_FAIL, + "(%s): Could not open %d'th connection\n", + __location__, i); return false; } clients[i]->tree->session->transport->options.request_timeout = 60; @@ -1518,7 +1560,7 @@ static bool test_raw_open_multi(struct torture_context *tctx) base ntcreatex parms */ io.generic.level = RAW_OPEN_NTCREATEX; - io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; io.ntcreatex.in.alloc_size = 0; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; @@ -1536,12 +1578,14 @@ static bool test_raw_open_multi(struct torture_context *tctx) ios[i] = io; requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]); if (requests[i] == NULL) { - DEBUG(0, ("could not send %d'th request\n", i)); + torture_result(tctx, TORTURE_FAIL, + "(%s): could not send %d'th request\n", + __location__, i); return false; } } - DEBUG(10, ("waiting for replies\n")); + torture_comment(tctx, "waiting for replies\n"); while (1) { bool unreplied = false; for (i=0; i<num_files; i++) { @@ -1555,8 +1599,8 @@ static bool test_raw_open_multi(struct torture_context *tctx) status = smb_raw_open_recv(requests[i], mem_ctx, &ios[i]); - DEBUG(0, ("File %d returned status %s\n", i, - nt_errstr(status))); + torture_comment(tctx, "File %d returned status %s\n", i, + nt_errstr(status)); if (NT_STATUS_IS_OK(status)) { num_ok += 1; @@ -1574,7 +1618,8 @@ static bool test_raw_open_multi(struct torture_context *tctx) } if (event_loop_once(tctx->ev) != 0) { - DEBUG(0, ("event_loop_once failed\n")); + torture_result(tctx, TORTURE_FAIL, + "(%s): event_loop_once failed\n", __location__); return false; } } @@ -1602,12 +1647,12 @@ static bool test_open_for_delete(struct smbcli_state *cli, struct torture_contex int fnum = -1; bool ret = true; - printf("Checking RAW_NTCREATEX for delete on a readonly file.\n"); + torture_comment(tctx, "Checking RAW_NTCREATEX for delete on a readonly file.\n"); /* reasonable default parameters */ io.generic.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; - io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.alloc_size = 0; io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_READONLY; @@ -1647,8 +1692,175 @@ done: return ret; } +/* + test chained RAW_OPEN_NTCREATEX_READX + Send chained NTCREATEX_READX on a file that doesn't exist, then create + the file and try again. +*/ +static bool test_chained_ntcreatex_readx(struct smbcli_state *cli, struct torture_context *tctx) +{ + TALLOC_CTX *mem_ctx = talloc_new(tctx); + union smb_open io; + const char *fname = BASEDIR "\\torture_chained.txt"; + NTSTATUS status; + int fnum = -1; + bool ret = true; + const char *buf = "test"; + char buf2[4]; + + torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on " + "non-existant file \n"); + smbcli_unlink(cli->tree, fname); + + /* ntcreatex parameters */ + io.generic.level = RAW_OPEN_NTCREATEX_READX; + io.ntcreatexreadx.in.flags = 0; + io.ntcreatexreadx.in.root_fid.fnum = 0; + io.ntcreatexreadx.in.access_mask = SEC_FILE_READ_DATA; + io.ntcreatexreadx.in.alloc_size = 0; + io.ntcreatexreadx.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatexreadx.in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE; + io.ntcreatexreadx.in.open_disposition = NTCREATEX_DISP_OPEN; + io.ntcreatexreadx.in.create_options = 0; + io.ntcreatexreadx.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION; + io.ntcreatexreadx.in.security_flags = 0; + io.ntcreatexreadx.in.fname = fname; + + /* readx parameters */ + io.ntcreatexreadx.in.offset = 0; + io.ntcreatexreadx.in.mincnt = sizeof(buf); + io.ntcreatexreadx.in.maxcnt = sizeof(buf); + io.ntcreatexreadx.in.remaining = 0; + io.ntcreatexreadx.out.data = (uint8_t *)buf2; + + /* try to open the non-existant file */ + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + fnum = io.ntcreatexreadx.out.file.fnum; + + smbcli_close(cli->tree, fnum); + smbcli_unlink(cli->tree, fname); + + torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on " + "existing file \n"); + + fnum = create_complex_file(cli, mem_ctx, fname); + smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf)); + smbcli_close(cli->tree, fnum); + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatexreadx.out.file.fnum; + + if (memcmp(buf, buf2, sizeof(buf)) != 0) { + torture_result(tctx, TORTURE_FAIL, + "(%s): wrong data in reply buffer\n", __location__); + ret = false; + } + +done: + smbcli_close(cli->tree, fnum); + smbcli_unlink(cli->tree, fname); + talloc_free(mem_ctx); + + return ret; +} + +#define FILL_NTCREATEX(_struct, _init...) \ + do { \ + (_struct)->generic.level = RAW_OPEN_NTCREATEX; \ + (_struct)->ntcreatex.in \ + = (typeof((_struct)->ntcreatex.in)) {_init};\ + } while (0) + +static bool test_ntcreatex_opendisp_dir(struct smbcli_state *cli, + struct torture_context *tctx) +{ + union smb_open io; + const char *dname = BASEDIR "\\torture_ntcreatex_opendisp_dir"; + NTSTATUS status; + bool ret = true; + int i; + struct { + uint32_t open_disp; + bool dir_exists; + NTSTATUS correct_status; + } open_funcs_dir[] = { + { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_INVALID_PARAMETER }, + { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_INVALID_PARAMETER }, + { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK }, + { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND }, + { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION }, + { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK }, + { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK }, + { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK }, + { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_INVALID_PARAMETER }, + { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_INVALID_PARAMETER }, + { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_INVALID_PARAMETER }, + { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_INVALID_PARAMETER }, + { 6, true, NT_STATUS_INVALID_PARAMETER }, + { 6, false, NT_STATUS_INVALID_PARAMETER }, + }; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + FILL_NTCREATEX(&io, + .flags = NTCREATEX_FLAGS_EXTENDED, + .access_mask = SEC_FLAG_MAXIMUM_ALLOWED, + .file_attr = FILE_ATTRIBUTE_DIRECTORY, + .share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE, + .create_options = NTCREATEX_OPTIONS_DIRECTORY, + .fname = dname, + ); + + smbcli_rmdir(cli->tree, dname); + smbcli_unlink(cli->tree, dname); + + /* test the open disposition for directories */ + torture_comment(tctx, "Testing open dispositions for directories...\n"); + + for (i=0; i<ARRAY_SIZE(open_funcs_dir); i++) { + if (open_funcs_dir[i].dir_exists) { + status = smbcli_mkdir(cli->tree, dname); + if (!NT_STATUS_IS_OK(status)) { + torture_result(tctx, TORTURE_FAIL, + "(%s): Failed to make directory " + "%s - %s\n", __location__, dname, + smbcli_errstr(cli->tree)); + ret = false; + goto done; + } + } + + io.ntcreatex.in.open_disposition = open_funcs_dir[i].open_disp; + status = smb_raw_open(cli->tree, tctx, &io); + if (!NT_STATUS_EQUAL(status, open_funcs_dir[i].correct_status)) { + torture_result(tctx, TORTURE_FAIL, + "(%s) incorrect status %s should be %s " + "(i=%d dir_exists=%d open_disp=%d)\n", + __location__, nt_errstr(status), + nt_errstr(open_funcs_dir[i].correct_status), + i, (int)open_funcs_dir[i].dir_exists, + (int)open_funcs_dir[i].open_disp); + ret = false; + } + if (NT_STATUS_IS_OK(status) || open_funcs_dir[i].dir_exists) { + smbcli_close(cli->tree, io.ntcreatex.out.file.fnum); + smbcli_rmdir(cli->tree, dname); + } + } + +done: + smbcli_rmdir(cli->tree, dname); + smbcli_deltree(cli->tree, BASEDIR); + return ret; +} + -/* basic testing of all RAW_OPEN_* calls +/* basic testing of all RAW_OPEN_* calls */ bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli) { @@ -1669,9 +1881,11 @@ bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli) ret &= test_create(cli, torture); ret &= test_ctemp(cli, torture); ret &= test_chained(cli, torture); + ret &= test_chained_ntcreatex_readx(cli, torture); ret &= test_no_leading_slash(cli, torture); ret &= test_openx_over_dir(cli, torture); ret &= test_open_for_delete(cli, torture); + ret &= test_ntcreatex_opendisp_dir(cli, torture); smb_raw_exit(cli->session); smbcli_deltree(cli->tree, BASEDIR); |