📄 open.c
字号:
CHECK_TIME(io.openx.out.write_time, write_time); CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED); CHECK_VAL(io.openx.out.unknown, 0); CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED); smbcli_close(cli->tree, fnum); /* now check the search attrib for hidden files - win2003 ignores this? */ SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN); CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib); io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); smbcli_close(cli->tree, io.openx.out.file.fnum); io.openx.in.search_attrs = 0; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); smbcli_close(cli->tree, io.openx.out.file.fnum); SET_ATTRIB(FILE_ATTRIBUTE_NORMAL); smbcli_unlink(cli->tree, fname); /* and check attrib on create */ io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE; io.openx.in.search_attrs = 0; io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); if (torture_setting_bool(tctx, "samba3", false)) { CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE, attrib & ~(FILE_ATTRIBUTE_NONINDEXED| FILE_ATTRIBUTE_SPARSE)); } else { CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE, attrib & ~(FILE_ATTRIBUTE_NONINDEXED)); } smbcli_close(cli->tree, io.openx.out.file.fnum); smbcli_unlink(cli->tree, fname); /* check timeout on create - win2003 ignores the timeout! */ io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE; io.openx.in.file_attrs = 0; io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); fnum = io.openx.out.file.fnum; io.openx.in.timeout = 20000; tv = timeval_current(); io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE; 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)); ret = false; } smbcli_close(cli->tree, fnum); smbcli_unlink(cli->tree, fname); /* now this is a really weird one - open for execute implies create?! */ io.openx.in.fname = fname; io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO; io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE; io.openx.in.search_attrs = 0; io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL; io.openx.in.file_attrs = 0; io.openx.in.write_time = 0; io.openx.in.size = 0; io.openx.in.timeout = 0; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); smbcli_close(cli->tree, io.openx.out.file.fnum); /* check the extended return flag */ io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN; io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL); smbcli_close(cli->tree, io.openx.out.file.fnum); io.openx.in.fname = "\\A.+,;=[].B"; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); /* Check the mapping for open exec. */ /* First create an .exe file. */ smbcli_unlink(cli->tree, fname_exe); fnum = create_complex_file(cli, tctx, fname_exe); smbcli_close(cli->tree, fnum); io.openx.level = RAW_OPEN_OPENX; io.openx.in.fname = fname_exe; io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO; io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE; io.openx.in.search_attrs = 0; io.openx.in.file_attrs = 0; io.openx.in.write_time = 0; io.openx.in.size = 0; io.openx.in.timeout = 0; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); /* Can we read and write ? */ CHECK_RDWR(io.openx.out.file.fnum, RDWR_RDONLY); smbcli_close(cli->tree, io.openx.out.file.fnum); smbcli_unlink(cli->tree, fname);done: smbcli_close(cli->tree, fnum); smbcli_unlink(cli->tree, fname_exe); smbcli_unlink(cli->tree, fname); return ret;}/* test RAW_OPEN_T2OPEN many thanks to kukks for a sniff showing how this works with os2->w2k*/static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx){ union smb_open io; union smb_fileinfo finfo; const char *fname1 = BASEDIR "\\torture_t2open_yes.txt"; const char *fname2 = BASEDIR "\\torture_t2open_no.txt"; const char *fname = BASEDIR "\\torture_t2open_3.txt"; NTSTATUS status; int fnum; bool ret = true; int i; struct { uint16_t open_func; bool with_file; NTSTATUS correct_status; } open_funcs[] = { { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK }, { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND }, { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK }, { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK }, { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_OBJECT_NAME_COLLISION }, { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_OBJECT_NAME_COLLISION }, { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION }, { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OBJECT_NAME_COLLISION }, { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK }, { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OK }, { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK }, { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK }, }; fnum = create_complex_file(cli, tctx, fname1); if (fnum == -1) { d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree)); ret = false; goto done; } smbcli_close(cli->tree, fnum); printf("Checking RAW_OPEN_T2OPEN\n"); io.t2open.level = RAW_OPEN_T2OPEN; io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO; io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR; io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE; io.t2open.in.search_attrs = 0; io.t2open.in.file_attrs = 0; io.t2open.in.write_time = 0; io.t2open.in.size = 0; io.t2open.in.timeout = 0; io.t2open.in.num_eas = 3; io.t2open.in.eas = talloc_array(tctx, struct ea_struct, io.t2open.in.num_eas); io.t2open.in.eas[0].flags = 0; io.t2open.in.eas[0].name.s = ".CLASSINFO"; io.t2open.in.eas[0].value = data_blob_talloc(tctx, "first value", 11); io.t2open.in.eas[1].flags = 0; io.t2open.in.eas[1].name.s = "EA TWO"; io.t2open.in.eas[1].value = data_blob_talloc(tctx, "foo", 3); io.t2open.in.eas[2].flags = 0; io.t2open.in.eas[2].name.s = "X THIRD"; io.t2open.in.eas[2].value = data_blob_talloc(tctx, "xy", 2); /* check all combinations of open_func */ for (i=0; i<ARRAY_SIZE(open_funcs); i++) { again: if (open_funcs[i].with_file) { io.t2open.in.fname = fname1; } else { io.t2open.in.fname = fname2; } io.t2open.in.open_func = open_funcs[i].open_func; status = smb_raw_open(cli->tree, tctx, &io); 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__); 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); ret = false; } if (NT_STATUS_IS_OK(status)) { smbcli_close(cli->tree, io.t2open.out.file.fnum); } } smbcli_unlink(cli->tree, fname1); smbcli_unlink(cli->tree, fname2); /* check the basic return fields */ io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE; io.t2open.in.write_time = 0; io.t2open.in.fname = fname; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); fnum = io.t2open.out.file.fnum; CHECK_ALL_INFO(io.t2open.out.size, size);#if 0 /* windows appears to leak uninitialised memory here */ CHECK_VAL(io.t2open.out.write_time, 0);#endif CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED); CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR); CHECK_VAL(io.t2open.out.ftype, 0); CHECK_VAL(io.t2open.out.devstate, 0); CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED); smbcli_close(cli->tree, fnum); status = torture_check_ea(cli, fname, ".CLASSINFO", "first value"); CHECK_STATUS(status, io.t2open.in.num_eas ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED); status = torture_check_ea(cli, fname, "EA TWO", "foo"); CHECK_STATUS(status, io.t2open.in.num_eas ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED); status = torture_check_ea(cli, fname, "X THIRD", "xy"); CHECK_STATUS(status, io.t2open.in.num_eas ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED); /* now check the search attrib for hidden files - win2003 ignores this? */ SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN); CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib); status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); smbcli_close(cli->tree, io.t2open.out.file.fnum); status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); smbcli_close(cli->tree, io.t2open.out.file.fnum); SET_ATTRIB(FILE_ATTRIBUTE_NORMAL); smbcli_unlink(cli->tree, fname); /* and check attrib on create */ io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE; io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); /* check timeout on create - win2003 ignores the timeout! */ io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE; io.t2open.in.file_attrs = 0; io.t2open.in.timeout = 20000; io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);done: smbcli_close(cli->tree, fnum); smbcli_unlink(cli->tree, fname); return ret;} /* test RAW_OPEN_NTCREATEX*/static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tctx){ union smb_open io; union smb_fileinfo finfo; const char *fname = BASEDIR "\\torture_ntcreatex.txt"; const char *dname = BASEDIR "\\torture_ntcreatex.dir"; NTSTATUS status; int fnum = -1; bool ret = true; int i; struct { uint32_t open_disp; bool with_file; NTSTATUS correct_status; } open_funcs[] = { { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK }, { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK }, { 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_OK }, { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND }, { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK }, { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK }, { 6, true, NT_STATUS_INVALID_PARAMETER }, { 6, false, NT_STATUS_INVALID_PARAMETER }, }; printf("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.access_mask = SEC_RIGHTS_FILE_ALL; io.ntcreatex.in.alloc_size = 1024*1024; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE; io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; io.ntcreatex.in.create_options = 0; io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; io.ntcreatex.in.security_flags = 0; io.ntcreatex.in.fname = fname; /* test the open disposition */ for (i=0; i<ARRAY_SIZE(open_funcs); i++) { 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)); ret = false; goto done; } smbcli_close(cli->tree, fnum); } 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); ret = false; } if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) { smbcli_close(cli->tree, io.ntcreatex.out.file.fnum); smbcli_unlink(cli->tree, fname); } } /* basic field testing */ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; status = smb_raw_open(cli->tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); fnum = io.ntcreatex.out.file.fnum; CHECK_VAL(io.ntcreatex.out.oplock_level, 0); CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -