diff options
Diffstat (limited to 'source4/torture')
51 files changed, 25143 insertions, 0 deletions
diff --git a/source4/torture/.cvsignore b/source4/torture/.cvsignore new file mode 100644 index 0000000000..06cac36e47 --- /dev/null +++ b/source4/torture/.cvsignore @@ -0,0 +1 @@ +torturebad.c diff --git a/source4/torture/aliases.c b/source4/torture/aliases.c new file mode 100644 index 0000000000..feb940eb42 --- /dev/null +++ b/source4/torture/aliases.c @@ -0,0 +1,403 @@ +/* + Unix SMB/CIFS implementation. + SMB trans2 alias scanner + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +int create_complex_file(struct cli_state *cli, TALLOC_CTX *mem_ctx, const char *fname); + +struct trans2_blobs { + struct trans2_blobs *next, *prev; + uint16 level; + DATA_BLOB params, data; +}; + +/* look for aliases for a query */ +static void gen_aliases(struct cli_state *cli, struct smb_trans2 *t2, int level_offset) +{ + TALLOC_CTX *mem_ctx; + uint16 level; + struct trans2_blobs *alias_blobs = NULL; + struct trans2_blobs *t2b, *t2b2; + int count=0, alias_count=0; + + mem_ctx = talloc_init("aliases"); + + for (level=0;level<2000;level++) { + NTSTATUS status; + + SSVAL(t2->in.params.data, level_offset, level); + + status = smb_raw_trans2(cli->tree, mem_ctx, t2); + if (!NT_STATUS_IS_OK(status)) continue; + + t2b = talloc(mem_ctx, sizeof(*t2b)); + t2b->level = level; + t2b->params = t2->out.params; + t2b->data = t2->out.data; + DLIST_ADD(alias_blobs, t2b); + d_printf("\tFound level %4u (0x%03x) of size %3d (0x%02x)\n", + level, level, + t2b->data.length, t2b->data.length); + count++; + } + + d_printf("Found %d levels with success status\n", count); + + for (t2b=alias_blobs; t2b; t2b=t2b->next) { + for (t2b2=alias_blobs; t2b2; t2b2=t2b2->next) { + if (t2b->level >= t2b2->level) continue; + if (data_blob_equal(&t2b->params, &t2b2->params) && + data_blob_equal(&t2b->data, &t2b2->data)) { + printf("\tLevel %u (0x%x) and level %u (0x%x) are possible aliases\n", + t2b->level, t2b->level, t2b2->level, t2b2->level); + alias_count++; + } + } + } + + d_printf("Found %d aliased levels\n", alias_count); + + talloc_destroy(mem_ctx); +} + +/* look for qfsinfo aliases */ +static void qfsinfo_aliases(struct cli_state *cli) +{ + struct smb_trans2 t2; + uint16 setup = TRANSACT2_QFSINFO; + + d_printf("\nChecking for QFSINFO aliases\n"); + + t2.in.max_param = 0; + t2.in.max_data = 0x8000; + t2.in.max_setup = 0; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params = data_blob(NULL, 2); + t2.in.data = data_blob(NULL, 0); + + gen_aliases(cli, &t2, 0); +} + +/* look for qfileinfo aliases */ +static void qfileinfo_aliases(struct cli_state *cli) +{ + struct smb_trans2 t2; + uint16 setup = TRANSACT2_QFILEINFO; + const char *fname = "\\qfileinfo_aliases.txt"; + int fnum; + + d_printf("\nChecking for QFILEINFO aliases\n"); + + t2.in.max_param = 2; + t2.in.max_data = 0x8000; + t2.in.max_setup = 0; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params = data_blob(NULL, 4); + t2.in.data = data_blob(NULL, 0); + + cli_unlink(cli, fname); + fnum = create_complex_file(cli, cli->mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + } + + cli_write(cli, fnum, 0, (char *)&t2, 0, sizeof(t2)); + + SSVAL(t2.in.params.data, 0, fnum); + + gen_aliases(cli, &t2, 2); + + cli_close(cli, fnum); + cli_unlink(cli, fname); +} + + +/* look for qpathinfo aliases */ +static void qpathinfo_aliases(struct cli_state *cli) +{ + struct smb_trans2 t2; + uint16 setup = TRANSACT2_QPATHINFO; + const char *fname = "\\qpathinfo_aliases.txt"; + int fnum; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("qpathinfo"); + + d_printf("\nChecking for QPATHINFO aliases\n"); + + t2.in.max_param = 2; + t2.in.max_data = 0x8000; + t2.in.max_setup = 0; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params = data_blob_talloc(mem_ctx, NULL, 6); + t2.in.data = data_blob(NULL, 0); + + cli_unlink(cli, fname); + fnum = create_complex_file(cli, cli->mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + } + + cli_write(cli, fnum, 0, (char *)&t2, 0, sizeof(t2)); + cli_close(cli, fnum); + + SIVAL(t2.in.params.data, 2, 0); + + cli_blob_append_string(cli->session, mem_ctx, &t2.in.params, + fname, STR_TERMINATE); + + gen_aliases(cli, &t2, 0); + + cli_unlink(cli, fname); + talloc_destroy(mem_ctx); +} + + +/* look for trans2 findfirst aliases */ +static void findfirst_aliases(struct cli_state *cli) +{ + struct smb_trans2 t2; + uint16 setup = TRANSACT2_FINDFIRST; + const char *fname = "\\findfirst_aliases.txt"; + int fnum; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("findfirst"); + + d_printf("\nChecking for FINDFIRST aliases\n"); + + t2.in.max_param = 16; + t2.in.max_data = 0x8000; + t2.in.max_setup = 0; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params = data_blob_talloc(mem_ctx, NULL, 12); + t2.in.data = data_blob(NULL, 0); + + cli_unlink(cli, fname); + fnum = create_complex_file(cli, cli->mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + } + + cli_write(cli, fnum, 0, (char *)&t2, 0, sizeof(t2)); + cli_close(cli, fnum); + + SSVAL(t2.in.params.data, 0, 0); + SSVAL(t2.in.params.data, 2, 1); + SSVAL(t2.in.params.data, 4, FLAG_TRANS2_FIND_CLOSE); + SSVAL(t2.in.params.data, 6, 0); + SIVAL(t2.in.params.data, 8, 0); + + cli_blob_append_string(cli->session, mem_ctx, &t2.in.params, + fname, STR_TERMINATE); + + gen_aliases(cli, &t2, 6); + + cli_unlink(cli, fname); + talloc_destroy(mem_ctx); +} + + + +/* look for aliases for a set function */ +static void gen_set_aliases(struct cli_state *cli, struct smb_trans2 *t2, int level_offset) +{ + TALLOC_CTX *mem_ctx; + uint16 level; + struct trans2_blobs *alias_blobs = NULL; + struct trans2_blobs *t2b; + int count=0, dsize; + + mem_ctx = talloc_init("aliases"); + + for (level=1;level<1100;level++) { + NTSTATUS status, status1; + SSVAL(t2->in.params.data, level_offset, level); + + status1 = NT_STATUS_OK; + + for (dsize=2; dsize<1024; dsize += 2) { + data_blob_free(&t2->in.data); + t2->in.data = data_blob(NULL, dsize); + data_blob_clear(&t2->in.data); + status = smb_raw_trans2(cli->tree, mem_ctx, t2); + /* some error codes mean that this whole level doesn't exist */ + if (NT_STATUS_EQUAL(NT_STATUS_INVALID_LEVEL, status) || + NT_STATUS_EQUAL(NT_STATUS_INVALID_INFO_CLASS, status) || + NT_STATUS_EQUAL(NT_STATUS_NOT_SUPPORTED, status)) { + break; + } + if (NT_STATUS_IS_OK(status)) break; + + /* invalid parameter means that the level exists at this + size, but the contents are wrong (not surprising with + all zeros!) */ + if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) break; + + /* this is the usual code for 'wrong size' */ + if (NT_STATUS_EQUAL(status, NT_STATUS_INFO_LENGTH_MISMATCH)) { + continue; + } + + if (!NT_STATUS_EQUAL(status, status1)) { + printf("level=%d size=%d %s\n", level, dsize, nt_errstr(status)); + } + status1 = status; + } + + if (!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) continue; + + t2b = talloc(mem_ctx, sizeof(*t2b)); + t2b->level = level; + t2b->params = t2->out.params; + t2b->data = t2->out.data; + DLIST_ADD(alias_blobs, t2b); + d_printf("\tFound level %4u (0x%03x) of size %3d (0x%02x)\n", + level, level, + t2->in.data.length, t2->in.data.length); + count++; + } + + d_printf("Found %d valid levels\n", count); + talloc_destroy(mem_ctx); +} + + + +/* look for setfileinfo aliases */ +static void setfileinfo_aliases(struct cli_state *cli) +{ + struct smb_trans2 t2; + uint16 setup = TRANSACT2_SETFILEINFO; + const char *fname = "\\setfileinfo_aliases.txt"; + int fnum; + + d_printf("\nChecking for SETFILEINFO aliases\n"); + + t2.in.max_param = 2; + t2.in.max_data = 0; + t2.in.max_setup = 0; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params = data_blob(NULL, 6); + t2.in.data = data_blob(NULL, 0); + + cli_unlink(cli, fname); + fnum = create_complex_file(cli, cli->mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + } + + cli_write(cli, fnum, 0, (char *)&t2, 0, sizeof(t2)); + + SSVAL(t2.in.params.data, 0, fnum); + SSVAL(t2.in.params.data, 4, 0); + + gen_set_aliases(cli, &t2, 2); + + cli_close(cli, fnum); + cli_unlink(cli, fname); +} + +/* look for setpathinfo aliases */ +static void setpathinfo_aliases(struct cli_state *cli) +{ + struct smb_trans2 t2; + uint16 setup = TRANSACT2_SETPATHINFO; + const char *fname = "\\setpathinfo_aliases.txt"; + int fnum; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("findfirst"); + + d_printf("\nChecking for SETPATHINFO aliases\n"); + + t2.in.max_param = 32; + t2.in.max_data = 0x8000; + t2.in.max_setup = 0; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params = data_blob_talloc(mem_ctx, NULL, 4); + t2.in.data = data_blob(NULL, 0); + + cli_unlink(cli, fname); + + fnum = create_complex_file(cli, cli->mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + } + + cli_write(cli, fnum, 0, (char *)&t2, 0, sizeof(t2)); + cli_close(cli, fnum); + + SSVAL(t2.in.params.data, 2, 0); + + cli_blob_append_string(cli->session, mem_ctx, &t2.in.params, + fname, STR_TERMINATE); + + gen_set_aliases(cli, &t2, 0); + + if (!cli_unlink(cli, fname)) { + printf("unlink: %s\n", cli_errstr(cli)); + } + talloc_destroy(mem_ctx); +} + + +/* look for aliased info levels in trans2 calls */ +BOOL torture_trans2_aliases(int dummy) +{ + struct cli_state *cli; + + if (!torture_open_connection(&cli)) { + return False; + } + + + qfsinfo_aliases(cli); + qfileinfo_aliases(cli); + qpathinfo_aliases(cli); + findfirst_aliases(cli); + setfileinfo_aliases(cli); + setpathinfo_aliases(cli); + + if (!torture_close_connection(cli)) { + return False; + } + + return True; +} diff --git a/source4/torture/cmd_sam.c b/source4/torture/cmd_sam.c new file mode 100644 index 0000000000..3f7f7dfe27 --- /dev/null +++ b/source4/torture/cmd_sam.c @@ -0,0 +1,514 @@ +/* + Unix SMB/CIFS implementation. + SAM module functions + + Copyright (C) Jelmer Vernooij 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "samtest.h" + +static void print_account(SAM_ACCOUNT_HANDLE *a) +{ + /* FIXME */ +} + +static NTSTATUS cmd_context(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + NTSTATUS status; + char **plugins; + int i; + + plugins = malloc(argc * sizeof(char *)); + + for(i = 1; i < argc; i++) + plugins[i-1] = argv[i]; + + plugins[argc-1] = NULL; + + if(!NT_STATUS_IS_OK(status = make_sam_context_list(&st->context, plugins))) { + printf("make_sam_context_list failed: %s\n", nt_errstr(status)); + SAFE_FREE(plugins); + return status; + } + + SAFE_FREE(plugins); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_load_module(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + char *plugin_arg[2]; + NTSTATUS status; + if (argc != 2 && argc != 3) { + printf("Usage: load <module path> [domain-name]\n"); + return NT_STATUS_OK; + } + + if (argc == 3) + asprintf(&plugin_arg[0], "plugin:%s|%s", argv[1], argv[2]); + else + asprintf(&plugin_arg[0], "plugin:%s", argv[1]); + + plugin_arg[1] = NULL; + + if(!NT_STATUS_IS_OK(status = make_sam_context_list(&st->context, plugin_arg))) { + free(plugin_arg[0]); + return status; + } + + free(plugin_arg[0]); + + printf("load: ok\n"); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_get_sec_desc(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_set_sec_desc(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_lookup_sid(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + char *name; + uint32 type; + NTSTATUS status; + DOM_SID sid; + if (argc != 2) { + printf("Usage: lookup_sid <sid>\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!string_to_sid(&sid, argv[1])){ + printf("Unparseable SID specified!\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!NT_STATUS_IS_OK(status = sam_lookup_sid(st->context, st->token, mem_ctx, &sid, &name, &type))) { + printf("sam_lookup_sid failed!\n"); + return status; + } + + printf("Name: %s\n", name); + printf("Type: %d\n", type); /* FIXME: What kind of an integer is type ? */ + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_lookup_name(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + DOM_SID sid; + uint32 type; + NTSTATUS status; + if (argc != 3) { + printf("Usage: lookup_name <domain> <name>\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!NT_STATUS_IS_OK(status = sam_lookup_name(st->context, st->token, argv[1], argv[2], &sid, &type))) { + printf("sam_lookup_name failed!\n"); + return status; + } + + printf("SID: %s\n", sid_string_static(&sid)); + printf("Type: %d\n", type); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_lookup_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_lookup_group(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_lookup_domain(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + DOM_SID *sid; + NTSTATUS status; + if (argc != 2) { + printf("Usage: lookup_domain <domain>\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!NT_STATUS_IS_OK(status = sam_lookup_domain(st->context, st->token, argv[1], &sid))) { + printf("sam_lookup_name failed!\n"); + return status; + } + + printf("SID: %s\n", sid_string_static(sid)); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_enum_domains(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int32 domain_count, i; + DOM_SID *domain_sids; + char **domain_names; + NTSTATUS status; + + if (!NT_STATUS_IS_OK(status = sam_enum_domains(st->context, st->token, &domain_count, &domain_sids, &domain_names))) { + printf("sam_enum_domains failed!\n"); + return status; + } + + if (domain_count == 0) { + printf("No domains found!\n"); + return NT_STATUS_OK; + } + + for (i = 0; i < domain_count; i++) { + printf("%s %s\n", domain_names[i], sid_string_static(&domain_sids[i])); + } + + SAFE_FREE(domain_sids); + SAFE_FREE(domain_names); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_update_domain(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_show_domain(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + NTSTATUS status; + DOM_SID sid; + SAM_DOMAIN_HANDLE *domain; + uint32 tmp_uint32; + uint16 tmp_uint16; + NTTIME tmp_nttime; + BOOL tmp_bool; + const char *tmp_string; + + if (argc != 2) { + printf("Usage: show_domain <sid>\n"); + return status; + } + + if (!string_to_sid(&sid, argv[1])){ + printf("Unparseable SID specified!\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_by_sid(st->context, st->token, GENERIC_RIGHTS_DOMAIN_ALL_ACCESS, &sid, &domain))) { + printf("sam_get_domain_by_sid failed\n"); + return status; + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_num_accounts(domain, &tmp_uint32))) { + printf("sam_get_domain_num_accounts failed: %s\n", nt_errstr(status)); + } else { + printf("Number of accounts: %d\n", tmp_uint32); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_num_groups(domain, &tmp_uint32))) { + printf("sam_get_domain_num_groups failed: %s\n", nt_errstr(status)); + } else { + printf("Number of groups: %u\n", tmp_uint32); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_num_aliases(domain, &tmp_uint32))) { + printf("sam_get_domain_num_aliases failed: %s\n", nt_errstr(status)); + } else { + printf("Number of aliases: %u\n", tmp_uint32); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_name(domain, &tmp_string))) { + printf("sam_get_domain_name failed: %s\n", nt_errstr(status)); + } else { + printf("Domain Name: %s\n", tmp_string); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_lockout_count(domain, &tmp_uint16))) { + printf("sam_get_domain_lockout_count failed: %s\n", nt_errstr(status)); + } else { + printf("Lockout Count: %u\n", tmp_uint16); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_force_logoff(domain, &tmp_bool))) { + printf("sam_get_domain_force_logoff failed: %s\n", nt_errstr(status)); + } else { + printf("Force Logoff: %s\n", (tmp_bool?"Yes":"No")); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_lockout_duration(domain, &tmp_nttime))) { + printf("sam_get_domain_lockout_duration failed: %s\n", nt_errstr(status)); + } else { + printf("Lockout duration: %u\n", tmp_nttime.low); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_login_pwdchange(domain, &tmp_bool))) { + printf("sam_get_domain_login_pwdchange failed: %s\n", nt_errstr(status)); + } else { + printf("Password changing allowed: %s\n", (tmp_bool?"Yes":"No")); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_max_pwdage(domain, &tmp_nttime))) { + printf("sam_get_domain_max_pwdage failed: %s\n", nt_errstr(status)); + } else { + printf("Maximum password age: %u\n", tmp_nttime.low); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_min_pwdage(domain, &tmp_nttime))) { + printf("sam_get_domain_min_pwdage failed: %s\n", nt_errstr(status)); + } else { + printf("Minimal password age: %u\n", tmp_nttime.low); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_min_pwdlength(domain, &tmp_uint16))) { + printf("sam_get_domain_min_pwdlength: %s\n", nt_errstr(status)); + } else { + printf("Minimal Password Length: %u\n", tmp_uint16); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_pwd_history(domain, &tmp_uint16))) { + printf("sam_get_domain_pwd_history failed: %s\n", nt_errstr(status)); + } else { + printf("Password history: %u\n", tmp_uint16); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_reset_count(domain, &tmp_nttime))) { + printf("sam_get_domain_reset_count failed: %s\n", nt_errstr(status)); + } else { + printf("Reset count: %u\n", tmp_nttime.low); + } + + if (!NT_STATUS_IS_OK(status = sam_get_domain_server(domain, &tmp_string))) { + printf("sam_get_domain_server failed: %s\n", nt_errstr(status)); + } else { + printf("Server: %s\n", tmp_string); + } + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_create_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_update_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_delete_account(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_enum_accounts(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + NTSTATUS status; + DOM_SID sid; + int32 account_count, i; + SAM_ACCOUNT_ENUM *accounts; + + if (argc != 2) { + printf("Usage: enum_accounts <domain-sid>\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!string_to_sid(&sid, argv[1])){ + printf("Unparseable SID specified!\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!NT_STATUS_IS_OK(status = sam_enum_accounts(st->context, st->token, &sid, 0, &account_count, &accounts))) { + printf("sam_enum_accounts failed: %s\n", nt_errstr(status)); + return status; + } + + if (account_count == 0) { + printf("No accounts found!\n"); + return NT_STATUS_OK; + } + + for (i = 0; i < account_count; i++) + printf("SID: %s\nName: %s\nFullname: %s\nDescription: %s\nACB_BITS: %08X\n\n", + sid_string_static(&accounts[i].sid), accounts[i].account_name, + accounts[i].full_name, accounts[i].account_desc, + accounts[i].acct_ctrl); + + SAFE_FREE(accounts); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_lookup_account_sid(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + NTSTATUS status; + DOM_SID sid; + SAM_ACCOUNT_HANDLE *account; + + if (argc != 2) { + printf("Usage: lookup_account_sid <account-sid>\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!string_to_sid(&sid, argv[1])){ + printf("Unparseable SID specified!\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + if (!NT_STATUS_IS_OK(status = sam_get_account_by_sid(st->context, st->token, GENERIC_RIGHTS_USER_ALL_ACCESS, &sid, &account))) { + printf("context_sam_get_account_by_sid failed: %s\n", nt_errstr(status)); + return status; + } + + print_account(account); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_lookup_account_name(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + NTSTATUS status; + SAM_ACCOUNT_HANDLE *account; + + if (argc != 3) { + printf("Usage: lookup_account_name <domain-name> <account-name>\n"); + return NT_STATUS_INVALID_PARAMETER; + } + + + if (!NT_STATUS_IS_OK(status = sam_get_account_by_name(st->context, st->token, GENERIC_RIGHTS_USER_ALL_ACCESS, argv[1], argv[2], &account))) { + printf("context_sam_get_account_by_sid failed: %s\n", nt_errstr(status)); + return status; + } + + print_account(account); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_create_group(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_update_group(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_delete_group(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_enum_groups(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_lookup_group_sid(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_lookup_group_name(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_group_add_member(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS cmd_group_del_member(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + + +static NTSTATUS cmd_group_enum(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + + +static NTSTATUS cmd_get_sid_groups(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +struct cmd_set sam_general_commands[] = { + + { "General SAM Commands" }, + + { "load", cmd_load_module, "Load a module", "load <module.so> [domain-sid]" }, + { "context", cmd_context, "Load specified context", "context [DOMAIN|]backend1[:options] [DOMAIN|]backend2[:options]" }, + { "get_sec_desc", cmd_get_sec_desc, "Get security descriptor info", "get_sec_desc <access-token> <sid>" }, + { "set_sec_desc", cmd_set_sec_desc, "Set security descriptor info", "set_sec_desc <access-token> <sid>" }, + { "lookup_sid", cmd_lookup_sid, "Lookup type of specified SID", "lookup_sid <sid>" }, + { "lookup_name", cmd_lookup_name, "Lookup type of specified name", "lookup_name <sid>" }, + { NULL } +}; + +struct cmd_set sam_domain_commands[] = { + { "Domain Commands" }, + { "update_domain", cmd_update_domain, "Update domain information", "update_domain [domain-options] domain-name | domain-sid" }, + { "show_domain", cmd_show_domain, "Show domain information", "show_domain domain-sid | domain-name" }, + { "enum_domains", cmd_enum_domains, "Enumerate all domains", "enum_domains <token> <acct-ctrl>" }, + { "lookup_domain", cmd_lookup_domain, "Lookup a domain by name", "lookup_domain domain-name" }, + { NULL } +}; + +struct cmd_set sam_account_commands[] = { + { "Account Commands" }, + { "create_account", cmd_create_account, "Create a new account with specified properties", "create_account [account-options]" }, + { "update_account", cmd_update_account, "Update an existing account", "update_account [account-options] account-sid | account-name" }, + { "delete_account", cmd_delete_account, "Delete an account", "delete_account account-sid | account-name" }, + { "enum_accounts", cmd_enum_accounts, "Enumerate all accounts", "enum_accounts <token> <acct-ctrl>" }, + { "lookup_account", cmd_lookup_account, "Lookup an account by either sid or name", "lookup_account account-sid | account-name" }, + { "lookup_account_sid", cmd_lookup_account_sid, "Lookup an account by sid", "lookup_account_sid account-sid" }, + { "lookup_account_name", cmd_lookup_account_name, "Lookup an account by name", "lookup_account_name account-name" }, + { NULL } +}; + +struct cmd_set sam_group_commands[] = { + { "Group Commands" }, + { "create_group", cmd_create_group, "Create a new group", "create_group [group-opts]" }, + { "update_group", cmd_update_group, "Update an existing group", "update_group [group-opts] group-name | group-sid" }, + { "delete_group", cmd_delete_group, "Delete an existing group", "delete_group group-name | group-sid" }, + { "enum_groups", cmd_enum_groups, "Enumerate all groups", "enum_groups <token> <group-ctrl>" }, + { "lookup_group", cmd_lookup_group, "Lookup a group by SID or name", "lookup_group group-sid | group-name" }, + { "lookup_group_sid", cmd_lookup_group_sid, "Lookup a group by SID", "lookup_group_sid <sid>" }, + { "lookup_group_name", cmd_lookup_group_name, "Lookup a group by name", "lookup_group_name <name>" }, + { "group_add_member", cmd_group_add_member, "Add group member to group", "group_add_member <group-name | group-sid> <member-name | member-sid>" }, + { "group_del_member", cmd_group_del_member, "Delete group member from group", "group_del_member <group-name | group-sid> <member-name | member-sid>" }, + { "group_enum", cmd_group_enum, "Enumerate all members of specified group", "group_enum group-sid | group-name" }, + + { "get_sid_groups", cmd_get_sid_groups, "Get a list of groups specified sid is a member of", "group_enum <group-sid | group-name>" }, + { NULL } +}; diff --git a/source4/torture/cmd_vfs.c b/source4/torture/cmd_vfs.c new file mode 100644 index 0000000000..b90c53e9fe --- /dev/null +++ b/source4/torture/cmd_vfs.c @@ -0,0 +1,1051 @@ +/* + Unix SMB/CIFS implementation. + VFS module functions + + Copyright (C) Simo Sorce 2002 + Copyright (C) Eric Lorimer 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "vfstest.h" + +static char *null_string = ""; + +static NTSTATUS cmd_load_module(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + struct smb_vfs_handle_struct *handle; + char *path = lp_vfs_path(0); + char name[PATH_MAX]; + + if (argc != 2) { + printf("Usage: load <module path>\n"); + return NT_STATUS_OK; + } + + if (path != NULL && *path != '\0') { + snprintf(name, PATH_MAX, "%s/%s", path, argv[1]); + } else { + snprintf(name, PATH_MAX, "%s", argv[1]); + } + vfs->conn->vfs_private = NULL; + handle = (struct smb_vfs_handle_struct *) smb_xmalloc(sizeof(smb_vfs_handle_struct)); + handle->handle = NULL; + DLIST_ADD(vfs->conn->vfs_private, handle) + if (!vfs_init_custom(vfs->conn, name)) { + DEBUG(0, ("load: error=-1 (vfs_init_custom failed for %s)\n", argv[1])); + return NT_STATUS_UNSUCCESSFUL; + } + printf("load: ok\n"); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_populate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + char c; + size_t size; + if (argc != 3) { + printf("Usage: populate <char> <size>\n"); + return NT_STATUS_OK; + } + c = argv[1][0]; + size = atoi(argv[2]); + vfs->data = (char *)talloc(mem_ctx, size); + if (vfs->data == NULL) { + printf("populate: error=-1 (not enough memory)"); + return NT_STATUS_UNSUCCESSFUL; + } + memset(vfs->data, c, size); + vfs->data_size = size; + return NT_STATUS_OK; +} + +static NTSTATUS cmd_show_data(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + size_t offset; + size_t len; + if (argc != 1 && argc != 3) { + printf("Usage: showdata [<offset> <len>]\n"); + return NT_STATUS_OK; + } + if (vfs->data == NULL || vfs->data_size == 0) { + printf("show_data: error=-1 (buffer empty)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + if (argc == 3) { + offset = atoi(argv[1]); + len = atoi(argv[2]); + } else { + offset = 0; + len = vfs->data_size; + } + if ((offset + len) > vfs->data_size) { + printf("show_data: error=-1 (not enough data in buffer)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + dump_data(0, (char *)(vfs->data) + offset, len); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_connect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + vfs->conn->vfs_ops.connect(vfs->conn, lp_servicename(vfs->conn->service), "vfstest"); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_disconnect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + vfs->conn->vfs_ops.disconnect(vfs->conn); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_disk_free(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + SMB_BIG_UINT diskfree, bsize, dfree, dsize; + if (argc != 2) { + printf("Usage: disk_free <path>\n"); + return NT_STATUS_OK; + } + + diskfree = vfs->conn->vfs_ops.disk_free(vfs->conn, argv[1], False, &bsize, &dfree, &dsize); + printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n", + (unsigned long)diskfree, + (unsigned long)bsize, + (unsigned long)dfree, + (unsigned long)dsize); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_opendir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + if (argc != 2) { + printf("Usage: opendir <fname>\n"); + return NT_STATUS_OK; + } + + vfs->currentdir = vfs->conn->vfs_ops.opendir(vfs->conn, argv[1]); + if (vfs->currentdir == NULL) { + printf("opendir error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("opendir: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_readdir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + struct dirent *dent; + + if (vfs->currentdir == NULL) { + printf("readdir: error=-1 (no open directory)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + dent = vfs->conn->vfs_ops.readdir(vfs->conn, vfs->currentdir); + if (dent == NULL) { + printf("readdir: NULL\n"); + return NT_STATUS_OK; + } + + printf("readdir: %s\n", dent->d_name); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_mkdir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + if (argc != 2) { + printf("Usage: mkdir <path>\n"); + return NT_STATUS_OK; + } + + if (vfs->conn->vfs_ops.mkdir(vfs->conn, argv[1], 00755) == -1) { + printf("mkdir error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("mkdir: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_closedir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int ret; + + if (vfs->currentdir == NULL) { + printf("closedir: failure (no directory open)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + ret = vfs->conn->vfs_ops.closedir(vfs->conn, vfs->currentdir); + if (ret == -1) { + printf("closedir failure: %s\n", strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("closedir: ok\n"); + vfs->currentdir = NULL; + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int flags, fd; + mode_t mode; + char *flagstr; + + mode = 00400; + + if (argc < 3 || argc > 5) { + printf("Usage: open <filename> <flags> <mode>\n"); + printf(" flags: O = O_RDONLY\n"); + printf(" R = O_RDWR\n"); + printf(" W = O_WRONLY\n"); + printf(" C = O_CREAT\n"); + printf(" E = O_EXCL\n"); + printf(" T = O_TRUNC\n"); + printf(" A = O_APPEND\n"); + printf(" N = O_NONBLOCK/O_NDELAY\n"); +#ifdef O_SYNC + printf(" S = O_SYNC\n"); +#endif +#ifdef O_NOFOLLOW + printf(" F = O_NOFOLLOW\n"); +#endif + printf(" mode: see open.2\n"); + printf(" mode is ignored if C flag not present\n"); + printf(" mode defaults to 00400\n"); + return NT_STATUS_OK; + } + flags = 0; + flagstr = argv[2]; + while (*flagstr) { + switch (*flagstr) { + case 'O': + flags |= O_RDONLY; + break; + case 'R': + flags |= O_RDWR; + break; + case 'W': + flags |= O_WRONLY; + break; + case 'C': + flags |= O_CREAT; + break; + case 'E': + flags |= O_EXCL; + break; + case 'T': + flags |= O_TRUNC; + break; + case 'A': + flags |= O_APPEND; + break; + case 'N': + flags |= O_NONBLOCK; + break; +#ifdef O_SYNC + case 'S': + flags |= O_SYNC; + break; +#endif +#ifdef O_NOFOLLOW + case 'F': + flags |= O_NOFOLLOW; + break; +#endif + default: + printf("open: error=-1 (invalid flag!)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + flagstr++; + } + if ((flags & O_CREAT) && argc == 4) { + if (sscanf(argv[3], "%o", &mode) == 0) { + printf("open: error=-1 (invalid mode!)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + } + + fd = vfs->conn->vfs_ops.open(vfs->conn, argv[1], flags, mode); + if (fd == -1) { + printf("open: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + vfs->files[fd] = (struct files_struct *)malloc(sizeof(struct files_struct)); + vfs->files[fd]->fsp_name = strdup(argv[1]); + vfs->files[fd]->fd = fd; + vfs->files[fd]->conn = vfs->conn; + printf("open: fd=%d\n", fd); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_pathfunc(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int ret = -1; + + if (argc != 2) { + printf("Usage: %s <path>\n", argv[0]); + return NT_STATUS_OK; + } + + if (strcmp("rmdir", argv[0]) == 0 ) { + ret = vfs->conn->vfs_ops.rmdir(vfs->conn, argv[1]); + } else if (strcmp("unlink", argv[0]) == 0 ) { + ret = vfs->conn->vfs_ops.unlink(vfs->conn, argv[1]); + } else if (strcmp("chdir", argv[0]) == 0 ) { + ret = vfs->conn->vfs_ops.chdir(vfs->conn, argv[1]); + } else { + printf("%s: error=%d (invalid function name!)\n", argv[0], errno); + return NT_STATUS_UNSUCCESSFUL; + } + + if (ret == -1) { + printf("%s: error=%d (%s)\n", argv[0], errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("%s: ok\n", argv[0]); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_close(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int fd, ret; + + if (argc != 2) { + printf("Usage: close <fd>\n"); + return NT_STATUS_OK; + } + + fd = atoi(argv[1]); + if (vfs->files[fd] == NULL) { + printf("close: error=-1 (invalid file descriptor)\n"); + return NT_STATUS_OK; + } + + ret = vfs->conn->vfs_ops.close(vfs->files[fd], fd); + if (ret == -1 ) + printf("close: error=%d (%s)\n", errno, strerror(errno)); + else + printf("close: ok\n"); + + SAFE_FREE(vfs->files[fd]->fsp_name); + SAFE_FREE(vfs->files[fd]); + vfs->files[fd] = NULL; + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_read(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int fd; + size_t size, rsize; + + if (argc != 3) { + printf("Usage: read <fd> <size>\n"); + return NT_STATUS_OK; + } + + /* do some error checking on these */ + fd = atoi(argv[1]); + size = atoi(argv[2]); + vfs->data = (char *)talloc(mem_ctx, size); + if (vfs->data == NULL) { + printf("read: error=-1 (not enough memory)"); + return NT_STATUS_UNSUCCESSFUL; + } + vfs->data_size = size; + + rsize = vfs->conn->vfs_ops.read(vfs->files[fd], fd, vfs->data, size); + if (rsize == -1) { + printf("read: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("read: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_write(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int fd, size, wsize; + + if (argc != 3) { + printf("Usage: write <fd> <size>\n"); + return NT_STATUS_OK; + } + + /* some error checking should go here */ + fd = atoi(argv[1]); + size = atoi(argv[2]); + if (vfs->data == NULL) { + printf("write: error=-1 (buffer empty, please populate it before writing)"); + return NT_STATUS_UNSUCCESSFUL; + } + + if (vfs->data_size < size) { + printf("write: error=-1 (buffer too small, please put some more data in)"); + return NT_STATUS_UNSUCCESSFUL; + } + + wsize = vfs->conn->vfs_ops.write(vfs->files[fd], fd, vfs->data, size); + + if (wsize == -1) { + printf("write: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("write: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_lseek(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int fd, offset, whence; + SMB_OFF_T pos; + + if (argc != 4) { + printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n"); + return NT_STATUS_OK; + } + + fd = atoi(argv[1]); + offset = atoi(argv[2]); + whence = atoi(argv[3]); + switch (whence) { + case 1: whence = SEEK_SET; break; + case 2: whence = SEEK_CUR; break; + default: whence = SEEK_END; + } + + pos = vfs->conn->vfs_ops.lseek(vfs->files[fd], fd, offset, whence); + if (pos == (SMB_OFF_T)-1) { + printf("lseek: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("lseek: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_rename(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int ret; + if (argc != 3) { + printf("Usage: rename <old> <new>\n"); + return NT_STATUS_OK; + } + + ret = vfs->conn->vfs_ops.rename(vfs->conn, argv[1], argv[2]); + if (ret == -1) { + printf("rename: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("rename: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_fsync(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int ret, fd; + if (argc != 2) { + printf("Usage: fsync <fd>\n"); + return NT_STATUS_OK; + } + + fd = atoi(argv[1]); + ret = vfs->conn->vfs_ops.fsync(vfs->files[fd], fd); + if (ret == -1) { + printf("fsync: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("fsync: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int ret; + char *user; + char *group; + struct passwd *pwd; + struct group *grp; + SMB_STRUCT_STAT st; + + if (argc != 2) { + printf("Usage: stat <fname>\n"); + return NT_STATUS_OK; + } + + ret = vfs->conn->vfs_ops.stat(vfs->conn, argv[1], &st); + if (ret == -1) { + printf("stat: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + pwd = sys_getpwuid(st.st_uid); + if (pwd != NULL) user = strdup(pwd->pw_name); + else user = null_string; + grp = sys_getgrgid(st.st_gid); + if (grp != NULL) group = strdup(grp->gr_name); + else group = null_string; + + printf("stat: ok\n"); + printf(" File: %s", argv[1]); + if (S_ISREG(st.st_mode)) printf(" Regular File\n"); + else if (S_ISDIR(st.st_mode)) printf(" Directory\n"); + else if (S_ISCHR(st.st_mode)) printf(" Character Device\n"); + else if (S_ISBLK(st.st_mode)) printf(" Block Device\n"); + else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n"); + else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n"); + else if (S_ISSOCK(st.st_mode)) printf(" Socket\n"); + printf(" Size: %10u", (unsigned int)st.st_size); + printf(" Blocks: %9u", (unsigned int)st.st_blocks); + printf(" IO Block: %u\n", (unsigned int)st.st_blksize); + printf(" Device: 0x%10x", (unsigned int)st.st_dev); + printf(" Inode: %10u", (unsigned int)st.st_ino); + printf(" Links: %10u\n", (unsigned int)st.st_nlink); + printf(" Access: %05o", (st.st_mode) & 007777); + printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group); + printf(" Access: %s", ctime(&(st.st_atime))); + printf(" Modify: %s", ctime(&(st.st_mtime))); + printf(" Change: %s", ctime(&(st.st_ctime))); + if (user != null_string) SAFE_FREE(user); + if (group!= null_string) SAFE_FREE(group); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int fd; + char *user; + char *group; + struct passwd *pwd; + struct group *grp; + SMB_STRUCT_STAT st; + + if (argc != 2) { + printf("Usage: fstat <fd>\n"); + return NT_STATUS_OK; + } + + fd = atoi(argv[1]); + if (fd < 0 || fd > 1024) { + printf("fstat: error=%d (file descriptor out of range)\n", EBADF); + return NT_STATUS_OK; + } + + if (vfs->files[fd] == NULL) { + printf("fstat: error=%d (invalid file descriptor)\n", EBADF); + return NT_STATUS_OK; + } + + if (vfs->conn->vfs_ops.fstat(vfs->files[fd], fd, &st) == -1) { + printf("fstat: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + pwd = sys_getpwuid(st.st_uid); + if (pwd != NULL) user = strdup(pwd->pw_name); + else user = null_string; + grp = sys_getgrgid(st.st_gid); + if (grp != NULL) group = strdup(grp->gr_name); + else group = null_string; + + printf("fstat: ok\n"); + if (S_ISREG(st.st_mode)) printf(" Regular File\n"); + else if (S_ISDIR(st.st_mode)) printf(" Directory\n"); + else if (S_ISCHR(st.st_mode)) printf(" Character Device\n"); + else if (S_ISBLK(st.st_mode)) printf(" Block Device\n"); + else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n"); + else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n"); + else if (S_ISSOCK(st.st_mode)) printf(" Socket\n"); + printf(" Size: %10u", (unsigned int)st.st_size); + printf(" Blocks: %9u", (unsigned int)st.st_blocks); + printf(" IO Block: %u\n", (unsigned int)st.st_blksize); + printf(" Device: 0x%10x", (unsigned int)st.st_dev); + printf(" Inode: %10u", (unsigned int)st.st_ino); + printf(" Links: %10u\n", (unsigned int)st.st_nlink); + printf(" Access: %05o", (st.st_mode) & 007777); + printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group); + printf(" Access: %s", ctime(&(st.st_atime))); + printf(" Modify: %s", ctime(&(st.st_mtime))); + printf(" Change: %s", ctime(&(st.st_ctime))); + if (user != null_string) SAFE_FREE(user); + if (group!= null_string) SAFE_FREE(group); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + char *user; + char *group; + struct passwd *pwd; + struct group *grp; + SMB_STRUCT_STAT st; + + if (argc != 2) { + printf("Usage: lstat <path>\n"); + return NT_STATUS_OK; + } + + if (vfs->conn->vfs_ops.lstat(vfs->conn, argv[1], &st) == -1) { + printf("lstat: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + pwd = sys_getpwuid(st.st_uid); + if (pwd != NULL) user = strdup(pwd->pw_name); + else user = null_string; + grp = sys_getgrgid(st.st_gid); + if (grp != NULL) group = strdup(grp->gr_name); + else group = null_string; + + printf("lstat: ok\n"); + if (S_ISREG(st.st_mode)) printf(" Regular File\n"); + else if (S_ISDIR(st.st_mode)) printf(" Directory\n"); + else if (S_ISCHR(st.st_mode)) printf(" Character Device\n"); + else if (S_ISBLK(st.st_mode)) printf(" Block Device\n"); + else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n"); + else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n"); + else if (S_ISSOCK(st.st_mode)) printf(" Socket\n"); + printf(" Size: %10u", (unsigned int)st.st_size); + printf(" Blocks: %9u", (unsigned int)st.st_blocks); + printf(" IO Block: %u\n", (unsigned int)st.st_blksize); + printf(" Device: 0x%10x", (unsigned int)st.st_dev); + printf(" Inode: %10u", (unsigned int)st.st_ino); + printf(" Links: %10u\n", (unsigned int)st.st_nlink); + printf(" Access: %05o", (st.st_mode) & 007777); + printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group); + printf(" Access: %s", ctime(&(st.st_atime))); + printf(" Modify: %s", ctime(&(st.st_mtime))); + printf(" Change: %s", ctime(&(st.st_ctime))); + if (user != null_string) SAFE_FREE(user); + if (group!= null_string) SAFE_FREE(group); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_chmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + mode_t mode; + if (argc != 3) { + printf("Usage: chmod <path> <mode>\n"); + return NT_STATUS_OK; + } + + mode = atoi(argv[2]); + if (vfs->conn->vfs_ops.chmod(vfs->conn, argv[1], mode) == -1) { + printf("chmod: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("chmod: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_fchmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int fd; + mode_t mode; + if (argc != 3) { + printf("Usage: fchmod <fd> <mode>\n"); + return NT_STATUS_OK; + } + + fd = atoi(argv[1]); + mode = atoi(argv[2]); + if (fd < 0 || fd > 1024) { + printf("fchmod: error=%d (file descriptor out of range)\n", EBADF); + return NT_STATUS_OK; + } + if (vfs->files[fd] == NULL) { + printf("fchmod: error=%d (invalid file descriptor)\n", EBADF); + return NT_STATUS_OK; + } + + if (vfs->conn->vfs_ops.fchmod(vfs->files[fd], fd, mode) == -1) { + printf("fchmod: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("fchmod: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_chown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + uid_t uid; + gid_t gid; + if (argc != 4) { + printf("Usage: chown <path> <uid> <gid>\n"); + return NT_STATUS_OK; + } + + uid = atoi(argv[2]); + gid = atoi(argv[3]); + if (vfs->conn->vfs_ops.chown(vfs->conn, argv[1], uid, gid) == -1) { + printf("chown: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("chown: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_fchown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + uid_t uid; + gid_t gid; + int fd; + if (argc != 4) { + printf("Usage: fchown <fd> <uid> <gid>\n"); + return NT_STATUS_OK; + } + + uid = atoi(argv[2]); + gid = atoi(argv[3]); + fd = atoi(argv[1]); + if (fd < 0 || fd > 1024) { + printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF); + return NT_STATUS_OK; + } + if (vfs->files[fd] == NULL) { + printf("fchown: error=%d (invalid file descriptor)\n", EBADF); + return NT_STATUS_OK; + } + if (vfs->conn->vfs_ops.fchown(vfs->files[fd], fd, uid, gid) == -1) { + printf("fchown error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("fchown: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_getwd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + char buf[PATH_MAX]; + if (vfs->conn->vfs_ops.getwd(vfs->conn, buf) == NULL) { + printf("getwd: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("getwd: %s\n", buf); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_utime(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + struct utimbuf times; + if (argc != 4) { + printf("Usage: utime <path> <access> <modify>\n"); + return NT_STATUS_OK; + } + times.actime = atoi(argv[2]); + times.modtime = atoi(argv[3]); + if (vfs->conn->vfs_ops.utime(vfs->conn, argv[1], ×) != 0) { + printf("utime: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("utime: ok\n"); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_ftruncate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + int fd; + SMB_OFF_T off; + if (argc != 3) { + printf("Usage: ftruncate <fd> <length>\n"); + return NT_STATUS_OK; + } + + fd = atoi(argv[1]); + off = atoi(argv[2]); + if (fd < 0 || fd > 1024) { + printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF); + return NT_STATUS_OK; + } + if (vfs->files[fd] == NULL) { + printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF); + return NT_STATUS_OK; + } + + if (vfs->conn->vfs_ops.ftruncate(vfs->files[fd], fd, off) == -1) { + printf("ftruncate: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("ftruncate: ok\n"); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_lock(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + BOOL ret; + int fd; + int op; + long offset; + long count; + int type; + char *typestr; + + if (argc != 6) { + printf("Usage: lock <fd> <op> <offset> <count> <type>\n"); + printf(" ops: G = F_GETLK\n"); + printf(" S = F_SETLK\n"); + printf(" W = F_SETLKW\n"); + printf(" type: R = F_RDLCK\n"); + printf(" W = F_WRLCK\n"); + printf(" U = F_UNLCK\n"); + return NT_STATUS_OK; + } + + if (sscanf(argv[1], "%d", &fd) == 0) { + printf("lock: error=-1 (error parsing fd)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + op = 0; + switch (*argv[2]) { + case 'G': + op = F_GETLK; + break; + case 'S': + op = F_SETLK; + break; + case 'W': + op = F_SETLKW; + break; + default: + printf("lock: error=-1 (invalid op flag!)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + if (sscanf(argv[3], "%ld", &offset) == 0) { + printf("lock: error=-1 (error parsing fd)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + if (sscanf(argv[4], "%ld", &count) == 0) { + printf("lock: error=-1 (error parsing fd)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + type = 0; + typestr = argv[5]; + while(*typestr) { + switch (*typestr) { + case 'R': + type |= F_RDLCK; + break; + case 'W': + type |= F_WRLCK; + break; + case 'U': + type |= F_UNLCK; + break; + default: + printf("lock: error=-1 (invalid type flag!)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + typestr++; + } + + printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd, op, offset, count, type); + + if ((ret = vfs->conn->vfs_ops.lock(vfs->files[fd], fd, op, offset, count, type)) == False) { + printf("lock: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("lock: ok\n"); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_symlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + if (argc != 3) { + printf("Usage: symlink <path> <link>\n"); + return NT_STATUS_OK; + } + + if (vfs->conn->vfs_ops.symlink(vfs->conn, argv[1], argv[2]) == -1) { + printf("symlink: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("symlink: ok\n"); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_readlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + char buffer[PATH_MAX]; + int size; + + if (argc != 2) { + printf("Usage: readlink <path>\n"); + return NT_STATUS_OK; + } + + if ((size = vfs->conn->vfs_ops.readlink(vfs->conn, argv[1], buffer, PATH_MAX)) == -1) { + printf("readlink: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + buffer[size] = '\0'; + printf("readlink: %s\n", buffer); + return NT_STATUS_OK; +} + + +static NTSTATUS cmd_link(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + if (argc != 3) { + printf("Usage: link <path> <link>\n"); + return NT_STATUS_OK; + } + + if (vfs->conn->vfs_ops.link(vfs->conn, argv[1], argv[2]) == -1) { + printf("link: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("link: ok\n"); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_mknod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + mode_t mode; + unsigned int dev_val; + SMB_DEV_T dev; + + if (argc != 4) { + printf("Usage: mknod <path> <mode> <dev>\n"); + printf(" mode is octal\n"); + printf(" dev is hex\n"); + return NT_STATUS_OK; + } + + if (sscanf(argv[2], "%o", &mode) == 0) { + printf("open: error=-1 (invalid mode!)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + if (sscanf(argv[3], "%x", &dev_val) == 0) { + printf("open: error=-1 (invalid dev!)\n"); + return NT_STATUS_UNSUCCESSFUL; + } + dev = (SMB_DEV_T)dev_val; + + if (vfs->conn->vfs_ops.mknod(vfs->conn, argv[1], mode, dev) == -1) { + printf("mknod: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("mknod: ok\n"); + return NT_STATUS_OK; +} + +static NTSTATUS cmd_realpath(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + char respath[PATH_MAX]; + + if (argc != 2) { + printf("Usage: realpath <path>\n"); + return NT_STATUS_OK; + } + + if (vfs->conn->vfs_ops.realpath(vfs->conn, argv[1], respath) == NULL) { + printf("realpath: error=%d (%s)\n", errno, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } + + printf("realpath: ok\n"); + return NT_STATUS_OK; +} + +struct cmd_set vfs_commands[] = { + + { "VFS Commands" }, + + { "load", cmd_load_module, "Load a module", "load <module.so>" }, + { "populate", cmd_populate, "Populate a data buffer", "populate <char> <size>" }, + { "showdata", cmd_show_data, "Show data currently in data buffer", "show_data [<offset> <len>]"}, + { "connect", cmd_connect, "VFS connect()", "connect" }, + { "disconnect", cmd_disconnect, "VFS disconnect()", "disconnect" }, + { "disk_free", cmd_disk_free, "VFS disk_free()", "disk_free <path>" }, + { "opendir", cmd_opendir, "VFS opendir()", "opendir <fname>" }, + { "readdir", cmd_readdir, "VFS readdir()", "readdir" }, + { "mkdir", cmd_mkdir, "VFS mkdir()", "mkdir <path>" }, + { "rmdir", cmd_pathfunc, "VFS rmdir()", "rmdir <path>" }, + { "closedir", cmd_closedir, "VFS closedir()", "closedir" }, + { "open", cmd_open, "VFS open()", "open <fname>" }, + { "close", cmd_close, "VFS close()", "close <fd>" }, + { "read", cmd_read, "VFS read()", "read <fd> <size>" }, + { "write", cmd_write, "VFS write()", "write <fd> <size>" }, + { "lseek", cmd_lseek, "VFS lseek()", "lseek <fd> <offset> <whence>" }, + { "rename", cmd_rename, "VFS rename()", "rename <old> <new>" }, + { "fsync", cmd_fsync, "VFS fsync()", "fsync <fd>" }, + { "stat", cmd_stat, "VFS stat()", "stat <fname>" }, + { "fstat", cmd_fstat, "VFS fstat()", "fstat <fd>" }, + { "lstat", cmd_lstat, "VFS lstat()", "lstat <fname>" }, + { "unlink", cmd_pathfunc, "VFS unlink()", "unlink <fname>" }, + { "chmod", cmd_chmod, "VFS chmod()", "chmod <path> <mode>" }, + { "fchmod", cmd_fchmod, "VFS fchmod()", "fchmod <fd> <mode>" }, + { "chown", cmd_chown, "VFS chown()", "chown <path> <uid> <gid>" }, + { "fchown", cmd_fchown, "VFS fchown()", "fchown <fd> <uid> <gid>" }, + { "chdir", cmd_pathfunc, "VFS chdir()", "chdir <path>" }, + { "getwd", cmd_getwd, "VFS getwd()", "getwd" }, + { "utime", cmd_utime, "VFS utime()", "utime <path> <access> <modify>" }, + { "ftruncate", cmd_ftruncate, "VFS ftruncate()", "ftruncate <fd> <length>" }, + { "lock", cmd_lock, "VFS lock()", "lock <f> <op> <offset> <count> <type>" }, + { "symlink", cmd_symlink, "VFS symlink()", "symlink <old> <new>" }, + { "readlink", cmd_readlink, "VFS readlink()", "readlink <path>" }, + { "link", cmd_link, "VFS link()", "link <oldpath> <newpath>" }, + { "mknod", cmd_mknod, "VFS mknod()", "mknod <path> <mode> <dev>" }, + { "realpath", cmd_realpath, "VFS realpath()", "realpath <path>" }, + { NULL } +}; diff --git a/source4/torture/denytest.c b/source4/torture/denytest.c new file mode 100644 index 0000000000..ea4b7e5735 --- /dev/null +++ b/source4/torture/denytest.c @@ -0,0 +1,1578 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester - deny mode scanning functions + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern BOOL torture_showall; + +enum deny_result {A_0=0, A_X=1, A_R=2, A_W=3, A_RW=5}; + +static const char *denystr(int denymode) +{ + struct { + int v; + const char *name; + } deny_modes[] = { + {DENY_DOS, "DENY_DOS"}, + {DENY_ALL, "DENY_ALL"}, + {DENY_WRITE, "DENY_WRITE"}, + {DENY_READ, "DENY_READ"}, + {DENY_NONE, "DENY_NONE"}, + {DENY_FCB, "DENY_FCB"}, + {-1, NULL}}; + int i; + for (i=0;deny_modes[i].name;i++) { + if (deny_modes[i].v == denymode) return deny_modes[i].name; + } + return "DENY_XXX"; +} + +static const char *openstr(int mode) +{ + struct { + int v; + const char *name; + } open_modes[] = { + {O_RDWR, "O_RDWR"}, + {O_RDONLY, "O_RDONLY"}, + {O_WRONLY, "O_WRONLY"}, + {-1, NULL}}; + int i; + for (i=0;open_modes[i].name;i++) { + if (open_modes[i].v == mode) return open_modes[i].name; + } + return "O_XXX"; +} + +static const char *resultstr(enum deny_result res) +{ + struct { + enum deny_result res; + const char *name; + } results[] = { + {A_X, "X"}, + {A_0, "-"}, + {A_R, "R"}, + {A_W, "W"}, + {A_RW,"RW"}}; + int i; + for (i=0;ARRAY_SIZE(results);i++) { + if (results[i].res == res) return results[i].name; + } + return "*"; +} + +static struct { + int isexe; + int mode1, deny1; + int mode2, deny2; + enum deny_result result; +} denytable2[] = { +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_NONE, A_RW}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_WRITE, A_RW}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_WRITE, A_R}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_WRITE, A_W}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_NONE, A_RW}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_DOS, A_RW}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_DOS, A_W}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_READ, A_RW}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_READ, A_R}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_READ, A_W}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_NONE, A_RW}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_NONE, A_R}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_NONE, A_W}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_WRITE, A_R}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_DOS, A_R}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_READ, A_R}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_WRITE, A_W}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_DOS, A_W}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_READ, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_READ, A_W}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_WRITE, A_RW}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_WRITE, A_R}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_WRITE, A_W}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_DOS, A_RW}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_DOS, A_R}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_DOS, A_W}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_READ, A_RW}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_READ, A_R}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_READ, A_W}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_DOS, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_WRITE, A_R}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_WRITE, A_R}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_READ, A_R}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_WRITE, A_W}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_READ, A_W}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_WRITE, A_RW}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_WRITE, A_R}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_WRITE, A_W}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_READ, A_RW}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_READ, A_R}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_READ, A_W}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_FCB, A_0} +}; + + +static struct { + int isexe; + int mode1, deny1; + int mode2, deny2; + enum deny_result result; +} denytable1[] = { +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_NONE, A_RW}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDWR, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_WRITE, A_RW}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_WRITE, A_R}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_WRITE, A_W}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_NONE, A_RW}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDONLY, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_DOS, A_RW}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_DOS, A_W}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_READ, A_RW}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_READ, A_R}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_READ, A_W}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_NONE, A_RW}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_NONE, A_R}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_NONE, A_W}, +{1, O_WRONLY, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_WRITE, A_R}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_DOS, A_R}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_READ, A_R}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDWR, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_WRITE, A_W}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDONLY, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_DOS, A_W}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_READ, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_READ, A_W}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{1, O_WRONLY, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDWR, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{1, O_RDWR, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_WRITE, A_RW}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_WRITE, A_R}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_WRITE, A_W}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{1, O_RDONLY, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{1, O_RDONLY, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_DOS, A_RW}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_DOS, A_R}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_DOS, A_W}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_READ, A_RW}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_READ, A_R}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_READ, A_W}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{1, O_WRONLY, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{1, O_WRONLY, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDWR, DENY_FCB, O_RDWR, DENY_FCB, A_RW}, +{1, O_RDWR, DENY_FCB, O_RDONLY, DENY_FCB, A_RW}, +{1, O_RDWR, DENY_FCB, O_WRONLY, DENY_FCB, A_RW}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_DOS, A_RW}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_DOS, A_R}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_DOS, A_W}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{1, O_RDONLY, DENY_FCB, O_RDWR, DENY_FCB, A_RW}, +{1, O_RDONLY, DENY_FCB, O_RDONLY, DENY_FCB, A_RW}, +{1, O_RDONLY, DENY_FCB, O_WRONLY, DENY_FCB, A_RW}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_DOS, A_RW}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_DOS, A_R}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_DOS, A_W}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{1, O_WRONLY, DENY_FCB, O_RDWR, DENY_FCB, A_RW}, +{1, O_WRONLY, DENY_FCB, O_RDONLY, DENY_FCB, A_RW}, +{1, O_WRONLY, DENY_FCB, O_WRONLY, DENY_FCB, A_RW}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_DOS, A_RW}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_DOS, A_W}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_DOS, O_RDWR, DENY_FCB, A_RW}, +{0, O_RDWR, DENY_DOS, O_RDONLY, DENY_FCB, A_RW}, +{0, O_RDWR, DENY_DOS, O_WRONLY, DENY_FCB, A_RW}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_WRITE, A_R}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_DOS, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_DOS, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_DOS, A_RW}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_DOS, A_R}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_DOS, A_W}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_DOS, O_RDWR, DENY_FCB, A_RW}, +{0, O_WRONLY, DENY_DOS, O_RDONLY, DENY_FCB, A_RW}, +{0, O_WRONLY, DENY_DOS, O_WRONLY, DENY_FCB, A_RW}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_ALL, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_ALL, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_WRITE, A_R}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_READ, A_R}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_NONE, A_R}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_WRITE, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_WRITE, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{0, O_RDWR, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_WRITE, A_W}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{0, O_RDONLY, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_READ, A_W}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_NONE, A_W}, +{0, O_WRONLY, DENY_READ, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_READ, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_READ, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_DOS, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{0, O_RDWR, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{0, O_RDWR, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_DOS, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_WRITE, A_RW}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_WRITE, A_R}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_WRITE, A_W}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{0, O_RDONLY, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{0, O_RDONLY, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_DOS, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_READ, A_RW}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_READ, A_R}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_READ, A_W}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_NONE, A_RW}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_NONE, A_R}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_NONE, A_W}, +{0, O_WRONLY, DENY_NONE, O_RDWR, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_NONE, O_RDONLY, DENY_FCB, A_0}, +{0, O_WRONLY, DENY_NONE, O_WRONLY, DENY_FCB, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_DOS, A_RW}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_DOS, A_W}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDWR, DENY_FCB, O_RDWR, DENY_FCB, A_RW}, +{0, O_RDWR, DENY_FCB, O_RDONLY, DENY_FCB, A_RW}, +{0, O_RDWR, DENY_FCB, O_WRONLY, DENY_FCB, A_RW}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_DOS, A_RW}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_DOS, A_R}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_DOS, A_W}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{0, O_RDONLY, DENY_FCB, O_RDWR, DENY_FCB, A_RW}, +{0, O_RDONLY, DENY_FCB, O_RDONLY, DENY_FCB, A_RW}, +{0, O_RDONLY, DENY_FCB, O_WRONLY, DENY_FCB, A_RW}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_DOS, A_RW}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_DOS, A_R}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_DOS, A_W}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_ALL, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_WRITE, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_READ, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_READ, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_NONE, A_0}, +{0, O_WRONLY, DENY_FCB, O_RDWR, DENY_FCB, A_RW}, +{0, O_WRONLY, DENY_FCB, O_RDONLY, DENY_FCB, A_RW}, +{0, O_WRONLY, DENY_FCB, O_WRONLY, DENY_FCB, A_RW} +}; + + +static void progress_bar(unsigned i, unsigned total) +{ + if (i % 10 != 0) return; + printf("%5d/%5d\r", i, total); + fflush(stdout); +} + +/* + this produces a matrix of deny mode behaviour for 1 connection + */ +BOOL torture_denytest1(int dummy) +{ + static struct cli_state *cli1; + int fnum1, fnum2; + int i; + BOOL correct = True; + const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"}; + + if (!torture_open_connection(&cli1)) { + return False; + } + + printf("starting denytest1\n"); + + printf("Testing deny modes with 1 connection\n"); + + for (i=0;i<2;i++) { + cli_unlink(cli1, fnames[i]); + fnum1 = cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE); + cli_write(cli1, fnum1, 0, fnames[i], 0, strlen(fnames[i])); + cli_close(cli1, fnum1); + } + + printf("testing %d entries\n", ARRAY_SIZE(denytable1)); + + for (i=0; i<ARRAY_SIZE(denytable1); i++) { + enum deny_result res; + const char *fname = fnames[denytable1[i].isexe]; + + progress_bar(i, ARRAY_SIZE(denytable1)); + + fnum1 = cli_open(cli1, fname, + denytable1[i].mode1, + denytable1[i].deny1); + fnum2 = cli_open(cli1, fname, + denytable1[i].mode2, + denytable1[i].deny2); + + if (fnum1 == -1) { + res = A_X; + } else if (fnum2 == -1) { + res = A_0; + } else { + char x = 1; + res = A_0; + if (cli_read(cli1, fnum2, (void *)&x, 0, 1) == 1) { + res += A_R; + } + if (cli_write(cli1, fnum2, 0, (void *)&x, 0, 1) == 1) { + res += A_W; + } + } + + if (res != denytable1[i].result) { + correct = False; + } + + if (torture_showall || res != denytable1[i].result) { + printf("%s %8s %10s %8s %10s %s (correct=%s)\n", + fname, + denystr(denytable1[i].deny1), + openstr(denytable1[i].mode1), + denystr(denytable1[i].deny2), + openstr(denytable1[i].mode2), + resultstr(res), + resultstr(denytable1[i].result)); + } + + cli_close(cli1, fnum1); + cli_close(cli1, fnum2); + } + + for (i=0;i<2;i++) { + cli_unlink(cli1, fnames[i]); + } + + if (!torture_close_connection(cli1)) { + correct = False; + } + + printf("finshed denytest1\n"); + return correct; +} + + +/* + this produces a matrix of deny mode behaviour with 2 connections + */ +BOOL torture_denytest2(int dummy) +{ + static struct cli_state *cli1, *cli2; + int fnum1, fnum2; + int i; + BOOL correct = True; + const char *fnames[2] = {"\\denytest2.dat", "\\denytest2.exe"}; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting denytest2\n"); + + printf("Testing deny modes with 2 connections\n"); + + for (i=0;i<2;i++) { + cli_unlink(cli1, fnames[i]); + fnum1 = cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE); + cli_write(cli1, fnum1, 0, fnames[i], 0, strlen(fnames[i])); + cli_close(cli1, fnum1); + } + + for (i=0; i<ARRAY_SIZE(denytable2); i++) { + enum deny_result res; + const char *fname = fnames[denytable2[i].isexe]; + + progress_bar(i, ARRAY_SIZE(denytable1)); + + fnum1 = cli_open(cli1, fname, + denytable2[i].mode1, + denytable2[i].deny1); + fnum2 = cli_open(cli2, fname, + denytable2[i].mode2, + denytable2[i].deny2); + + if (fnum1 == -1) { + res = A_X; + } else if (fnum2 == -1) { + res = A_0; + } else { + char x = 1; + res = A_0; + if (cli_read(cli2, fnum2, (void *)&x, 0, 1) == 1) { + res += A_R; + } + if (cli_write(cli2, fnum2, 0, (void *)&x, 0, 1) == 1) { + res += A_W; + } + } + + if (res != denytable2[i].result) { + correct = False; + } + + if (torture_showall || res != denytable2[i].result) { + printf("%s %8s %10s %8s %10s %s (correct=%s)\n", + fname, + denystr(denytable2[i].deny1), + openstr(denytable2[i].mode1), + denystr(denytable2[i].deny2), + openstr(denytable2[i].mode2), + resultstr(res), + resultstr(denytable2[i].result)); + } + + cli_close(cli1, fnum1); + cli_close(cli2, fnum2); + } + + for (i=0;i<2;i++) { + cli_unlink(cli1, fnames[i]); + } + + if (!torture_close_connection(cli1)) { + correct = False; + } + if (!torture_close_connection(cli2)) { + correct = False; + } + + printf("finshed denytest2\n"); + return correct; +} + diff --git a/source4/torture/dfstest.c b/source4/torture/dfstest.c new file mode 100644 index 0000000000..79d49aded3 --- /dev/null +++ b/source4/torture/dfstest.c @@ -0,0 +1,459 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester - DFS tests + Copyright (C) James J Myers 2003 <myersjj@samba.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define DFS_SERVER_COUNT 6 +#define DFS_FILE_COUNT 8 +extern char *host, *share, *password, *username; +static struct cli_client context; +static const char *sockops="TCP_NODELAY"; + +/* + checks for correct DFS cluster support + */ +BOOL torture_dfs_basic(int dummy) +{ + int current_server = 0; + char *fname[DFS_FILE_COUNT]; + int file_server[DFS_FILE_COUNT]; + int fnum[DFS_FILE_COUNT]; + int i; + const char *template = "\\\\%s\\%s\\dfstest%d.tmp"; + char *filedata; + int server_count = 0; + int connection_flags = CLI_FULL_CONNECTION_USE_KERBEROS + | CLI_FULL_CONNECTION_USE_DFS + ; + + printf("starting dfs_basic_test\n"); + cli_client_initialize(&context, sockops, username, password, lp_workgroup(), connection_flags); + + if ((current_server = cli_dfs_open_connection(&context, host, share, connection_flags) < 0)) + return False; + + for (i=0; i < DFS_FILE_COUNT ; i++) { + file_server[i] = 0; + DEBUG(4,("host=%s share=%s cli host=%s cli share=%s\n", + host, share, cli_state_get_host(context.cli[file_server[i]]), + cli_state_get_share(context.cli[file_server[i]]))); + host = cli_state_get_host(context.cli[file_server[i]]); + share = cli_state_get_share(context.cli[file_server[i]]); + asprintf(&fname[i], template, host, share, i); + DEBUG(3,("unlinking %s\n", fname[i])); + cli_nt_unlink(&context, &file_server[i], fname[i], 0); + } + + for (i=0; i < DFS_FILE_COUNT ; i++) { + host = cli_state_get_host(context.cli[file_server[i]]); + share = cli_state_get_share(context.cli[file_server[i]]); + asprintf(&fname[i], template, host, share, i); + DEBUG(3,("open %s on server %s(%d)\n", + fname[i], host, file_server[i])); + fnum[i] = cli_dfs_open(&context, &file_server[i], fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum[i] == -1) + { + printf("open of %s failed (%s)\n", fname[i], cli_errstr(context.cli[file_server[i]])); + return False; + } + asprintf(&filedata, "%s %d", fname[i], fnum[i]); + DEBUG(3,("write %d bytes (%s) to %s (fid %d) on server %s(%d)\n", + strlen(filedata), filedata, fname[i], fnum[i], + host, file_server[i])); + if (cli_write(context.cli[file_server[i]], fnum[i], 0, filedata, 0, strlen(filedata)) != strlen(filedata)) + { + printf("write failed (%s)\n", cli_errstr(context.cli[file_server[i]])); + return False; + } + + if (!cli_close(context.cli[file_server[i]], fnum[i])) { + printf("close of %s failed (%s)\n", fname[i], cli_errstr(context.cli[file_server[i]])); + return False; + } + } + DEBUG(3,("used Dfs servers:")); + for (i=0; i < DFS_SERVER_COUNT ; i++) { + server_count++; + DEBUG(3,(" %s(%d)", cli_state_get_host(context.cli[file_server[i]]), i)); + if (!torture_close_connection(context.cli[i])) + return False; + } + DEBUG(3,("\n")); + + printf("Passed dfstest, found and used %d Dfs servers\n", server_count); + return True; +} + +/* + Check for correct DFS rename support. + First test is simple rename, a la command line, explorer. + Second test is simulation of MS Word edit/save file. + */ +BOOL torture_dfs_rename(int dummy) +{ + int current_server = -1; + char *fname[DFS_FILE_COUNT]; + int file_server[DFS_FILE_COUNT]; + int fnum[DFS_FILE_COUNT]; + int i; + const char *template = "\\\\%s\\%s\\dfstest%d.tmp"; + const char *template2orig = "\\\\%s\\%s\\dfstestorig.txt"; + const char *template2old = "\\\\%s\\%s\\~dfstestold.txt"; + const char *template2new = "\\\\%s\\%s\\~dfstestnew.txt"; + char *filedata, *newdata; + int server_count = 0; + int connection_flags = CLI_FULL_CONNECTION_USE_KERBEROS + | CLI_FULL_CONNECTION_USE_DFS + ; + + printf("starting dfs_rename_test\n"); + cli_client_initialize(&context, sockops, username, password, + lp_workgroup(), connection_flags); + + if ((current_server = cli_dfs_open_connection(&context, host, share, connection_flags)) < 0) + return False; + + for (i=0; i < DFS_FILE_COUNT ; i++) { + file_server[i] = 0; + slprintf(fname[i],sizeof(fstring)-1,template, host, share, i); + DEBUG(3,("unlinking %s\n", fname[i])); + cli_nt_unlink(&context, &file_server[i], fname[i], 0); + } + /* Simple rename test */ + for (i=0; i < 1 ; i++) { + slprintf(fname[i],sizeof(fstring)-1,template, + cli_state_get_host(context.cli[file_server[i]]), + cli_state_get_share(context.cli[file_server[i]]), i); + DEBUG(3,("open %s on server %s(%d)\n", + fname[i], cli_state_get_host(context.cli[file_server[i]]), file_server[i])); + + fnum[i] = cli_dfs_open(&context, &file_server[i], fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum[i] == -1) { + printf("open of %s failed (%s)\n", fname[i], cli_errstr(context.cli[file_server[i]])); + return False; + } + asprintf(&filedata, "%s %d", fname[i], (int)getpid()); + DEBUG(3,("write %d bytes (%s) to %s (fid %d) on server %s(%d)\n", + strlen(filedata), filedata, fname[i], fnum[i], + cli_state_get_host(context.cli[file_server[i]]), file_server[i])); + if (cli_write(context.cli[file_server[i]], fnum[i], 0, filedata, 0, strlen(filedata)) != strlen(filedata)) + { + printf("write failed (%s)\n", cli_errstr(context.cli[file_server[i]])); + return False; + } + + if (!cli_close(context.cli[file_server[i]], fnum[i])) { + printf("close of %s failed (%s)\n", fname[i], cli_errstr(context.cli[file_server[i]])); + return False; + } + } + // now attempt to rename the file + DEBUG(3,("rename %s to %s on server %s(%d)\n", + fname[0], fname[1], cli_state_get_host(context.cli[file_server[i]]), file_server[0])); + if (!cli_dfs_rename(&context, &file_server[0], fname[0], fname[1])) { + printf("rename of %s to %s failed (%s)\n", fname[0], fname[1], cli_errstr(context.cli[file_server[0]])); + return False; + } + // clean up + DEBUG(3,("used Dfs servers:")); + for (i=0; i < DFS_SERVER_COUNT ; i++) { + server_count++; + DEBUG(3,(" %s(%d)", cli_state_get_host(context.cli[file_server[i]]), i)); + if (!torture_close_connection(context.cli[i])) + return False; + } + DEBUG(3,("\n")); + printf("Dfstest: passed simple rename test\n"); + + /* Now try more complicated test, a la MS Word. + * Open existing file (x) and read file and close. + * Then open, write to new temp name file (~x.new), close. + * Then rename old file name to old temp name file (~x.old). + * Then rename new temp name file to oroginal name (x). */ + cli_client_initialize(&context, sockops, username, password, + lp_workgroup(), connection_flags); + + if ((current_server = cli_dfs_open_connection(&context, host, share, connection_flags)) < 0) + return False; + slprintf(fname[0],sizeof(fname[0])-1,template2orig, host, share); + slprintf(fname[1],sizeof(fname[1])-1,template2old, host, share); + slprintf(fname[2],sizeof(fname[2])-1,template2new, host, share); + for (i=0; i < DFS_FILE_COUNT ; i++) { + file_server[i] = 0; + fnum[i] = 0; + DEBUG(3,("unlinking %s\n", fname[i])); + cli_nt_unlink(&context, &file_server[i], fname[i], 0); + } + asprintf(&fname[0],template2orig, + cli_state_get_host(context.cli[0]), + cli_state_get_share(context.cli[0]), 0); + asprintf(&fname[1],template2old, + cli_state_get_host(context.cli[1]), + cli_state_get_share(context.cli[1]), 1); + asprintf(&fname[2],template2new, + cli_state_get_host(context.cli[2]), + cli_state_get_share(context.cli[2]), 2); + DEBUG(3,("edit(MS Word) %s on server %s(%d)\n", + fname[0], cli_state_get_host(context.cli[0]), file_server[0])); + DEBUG(3,("open %s on server %s(%d)\n", + fname[0], cli_state_get_host(context.cli[0]), file_server[0])); + + fnum[0] = cli_dfs_open(&context, &file_server[0], fname[0], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum[0] == -1) + { + printf("open of %s failed (%s)\n", fname[0], cli_errstr(context.cli[file_server[0]])); + return False; + } + slprintf(filedata, sizeof(fstring)-1, "%s %d", fname[0], (int)getpid()); + DEBUG(3,("write %d bytes (%s) to %s (fid %d) on server %s(%d)\n", + strlen(filedata), filedata, fname[0], fnum[0], + cli_state_get_host(context.cli[0]), file_server[0])); + if (cli_write(context.cli[file_server[0]], fnum[0], 0, filedata, 0, strlen(filedata)) != strlen(filedata)) + { + printf("write failed (%s)\n", cli_errstr(context.cli[file_server[0]])); + return False; + } + // read data from original file + DEBUG(3,("read %s (fid %d) on server %s(%d)\n", + fname[0], fnum[0], cli_state_get_host(context.cli[0]), file_server[0])); + if (cli_read(context.cli[file_server[0]], fnum[0], filedata, 0, strlen(filedata)) != strlen(filedata)) + { + printf("read failed (%s)", cli_errstr(context.cli[file_server[0]])); + return False; + } + DEBUG(3,("close %s on server %s(%d)\n", + fname[0], cli_state_get_host(context.cli[0]), file_server[0])); + if (!cli_close(context.cli[file_server[0]], fnum[0])) { + printf("close of %s failed (%s)\n", fname[0], cli_errstr(context.cli[file_server[0]])); + return False; + } + // open new temp file, write data + DEBUG(3,("open %s on server %s(%d)\n", + fname[2], cli_state_get_host(context.cli[2]), file_server[2])); + fnum[2] = cli_dfs_open(&context, &file_server[2], fname[2], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum[2] == -1) + { + printf("open of %s failed (%s)\n", fname[2], cli_errstr(context.cli[file_server[2]])); + return False; + } + DEBUG(3,("write %d bytes (%s) to %s (fid %d) on server %s(%d)\n", + strlen(filedata), filedata, fname[2], fnum[2], + cli_state_get_host(context.cli[2]), file_server[2])); + if (cli_write(context.cli[file_server[2]], fnum[2], 0, filedata, 0, strlen(filedata)) != strlen(filedata)) + { + printf("write failed (%s)\n", cli_errstr(context.cli[file_server[2]])); + return False; + } + slprintf(newdata, sizeof(fstring)-1, "new data: %s %d", fname[0], (int)getpid()); + DEBUG(3,("write new data %d bytes (%s) to %s (fid %d) on server %s(%d)\n", + strlen(newdata), newdata, fname[2], fnum[2], + cli_state_get_host(context.cli[2]), file_server[2])); + if (cli_write(context.cli[file_server[2]], fnum[2], 0, newdata, strlen(filedata), strlen(newdata)) != strlen(newdata)) + { + printf("write failed (%s)\n", cli_errstr(context.cli[file_server[2]])); + return False; + } + DEBUG(3,("close %s on server %s(%d)\n", + fname[2], cli_state_get_host(context.cli[2]), file_server[2])); + if (!cli_close(context.cli[file_server[2]], fnum[2])) { + printf("close of %s failed (%s)\n", fname[2], cli_errstr(context.cli[file_server[2]])); + return False; + } + DEBUG(3,("close successful %s on server %s(%d)\n", + fname[2], cli_state_get_host(context.cli[2]), file_server[2])); + // rename original file to temp + DEBUG(4,("file_server[0]=%d\n", file_server[0])); + DEBUG(4,("context.cli[file_server[0]].desthost=%s\n", cli_state_get_host(context.cli[0]))); + DEBUG(3,("rename %s to %s on server %s(%d)\n", + fname[0], fname[1], cli_state_get_host(context.cli[0]), file_server[0])); + if (!cli_dfs_rename(&context, &file_server[0], fname[0], fname[1])) { + printf("rename of %s to %s failed (%s)\n", fname[0], fname[1], cli_errstr(context.cli[file_server[0]])); + return False; + } + // name new temp file to original + DEBUG(3,("rename %s to %s on server %s(%d)\n", + fname[2], fname[0], cli_state_get_host(context.cli[2]), file_server[2])); + if (!cli_dfs_rename(&context, &file_server[2], fname[2], fname[0])) { + printf("rename of %s to %s failed (%s)\n", fname[2], fname[0], cli_errstr(context.cli[file_server[2]])); + return False; + } + printf("Dfstest: passed MS Word rename test\n"); + // clean up + DEBUG(3,("used Dfs servers:")); + for (i=0; i < DFS_SERVER_COUNT ; i++) { + server_count++; + DEBUG(3,(" %s(%d)", cli_state_get_host(context.cli[i]), i)); + if (!torture_close_connection(context.cli[i])) + return False; + } + DEBUG(3,("\n")); + + printf("Passed dfs_rename_test\n"); + return True; +} +struct list_fn_parms { + struct cli_client *context; + char* rname; +} list_fn_parms; + +void dfs_list_fn(file_info *finfo, const char *rname, void* parmsp); +void delete_file(file_info *finfo, const char *rname) +{ + int server = 0; + char *fname; + + DEBUG(3,("deleting file %s in %s\n", finfo->name, rname)); + asprintf(&fname, "%s\\%s", rname, finfo->name); + cli_nt_unlink(&context, &server, fname, 0); +} +void delete_directory(file_info *finfo, const char *rname) +{ + int server = 0; + char *dname, *rname2; + + DEBUG(3,("deleting directory %s in %s\n", finfo->name, rname)); + asprintf(&dname, "%s%s\\*", rname, finfo->name); + cli_nt_unlink(&context, &server, dname, 0); + asprintf(&dname, "%s%s\\*", rname, finfo->name); + asprintf(&rname2, "%s%s", rname, finfo->name); + cli_search(context.cli[0], dname, FILE_ATTRIBUTE_DIRECTORY, + dfs_list_fn, (void*)rname2); + cli_dfs_rmdir(&context, &server, rname2); +} + +void dfs_list_fn(file_info *finfo, const char *name, void* parmsp) +{ + struct list_fn_parms *parms = (struct list_fn_parms*)parmsp; + + DEBUG(4,("processing %s in %s\n", finfo->name, parms->rname)); + if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) { + delete_directory(finfo, parms->rname); + } + else { + delete_file(finfo, parms->rname); + } +} + +/* + checks for correct DFS cluster support creating random dirs/files. + */ +#define DFS_RANDOM_FILE_COUNT 10 +#define DFS_RANDOM_DIR_COUNT 3 +#define DFS_RANDOM_DIR_LEVELS 2 +BOOL torture_dfs_random(int dummy) +{ + char *fname[DFS_RANDOM_FILE_COUNT]; + int file_server[DFS_RANDOM_FILE_COUNT]; + char *dname[DFS_RANDOM_DIR_COUNT]; + int dir_server[DFS_RANDOM_DIR_COUNT]; + char *rname; + int fnum[DFS_FILE_COUNT]; + int i; + const char *ftemplate = "%s\\dfsfile%d.tmp"; + const char *alltemplate = "\\\\%s\\%s\\dfs*.tmp"; + char *filedata; + int server_count = 0; + int file_count; + int connection_flags = CLI_FULL_CONNECTION_USE_KERBEROS + | CLI_FULL_CONNECTION_USE_DFS + ; + + printf("starting dfs_random_test\n"); + cli_client_initialize(&context, sockops, username, password, + lp_workgroup(), connection_flags); + + if ((dir_server[0] = cli_dfs_open_connection(&context, host, share, connection_flags)) < 0) + return False; + + // get list of directories named dfsdir*. + // delete all files in these directories using wild card, + // then delete directory. + asprintf(&rname, "\\\\%s\\%s\\", + cli_state_get_host(context.cli[0]), + cli_state_get_share(context.cli[0])); + asprintf(&fname[0], alltemplate, + cli_state_get_host(context.cli[0]), + cli_state_get_share(context.cli[0])); + DEBUG(3,("deleting files %s in %s on server %s(%d)\n", + fname[0], rname, cli_state_get_host(context.cli[0]), dir_server[0])); + file_count = cli_search(context.cli[0], fname[0], FILE_ATTRIBUTE_DIRECTORY, dfs_list_fn, (void*)rname); + + // create random directory names with 0-n levels + asprintf(&dname[0], "\\\\%s\\%s\\", + cli_state_get_host(context.cli[0]), + cli_state_get_share(context.cli[0])); + DEBUG(3,("creating directories in %s on server %s(%d)\n", + rname, cli_state_get_host(context.cli[0]), dir_server[0])); + for (i=1; i < DFS_RANDOM_DIR_COUNT; i++) { + dir_server[i] = 0; + asprintf(&dname[i], + "\\\\%s\\%s\\dfsdir%d.tmp", + cli_state_get_host(context.cli[dir_server[i]]), + cli_state_get_share(context.cli[dir_server[i]]), + (int)sys_random()%10000); + DEBUG(3,("mkdir %s on server %s(%d)\n", + dname[i], cli_state_get_host(context.cli[dir_server[i]]), dir_server[i])); + if (!cli_dfs_mkdir(&context, &dir_server[i], dname[i])) { + printf("mkdir of %s failed (%s)\n", dname[i], cli_errstr(context.cli[dir_server[i]])); + return False; + } + } + + for (i=0; i < DFS_RANDOM_FILE_COUNT ; i++) { + // select a directory randomly, create a file in it. + int dn = (int)sys_random()%DFS_RANDOM_DIR_COUNT; + file_server[i] = dir_server[dn]; + asprintf(&fname[i], ftemplate, dname[dn], i); + DEBUG(3,("open %s on server %s(%d)\n", + fname[i], cli_state_get_host(context.cli[dir_server[i]]), file_server[i])); + fnum[i] = cli_dfs_open(&context, &file_server[i], fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum[i] == -1) + { + printf("open of %s failed (%s)\n", fname[i], cli_errstr(context.cli[file_server[i]])); + return False; + } + + asprintf(&filedata, "%s %d", fname[i], fnum[i]); + DEBUG(3,("write %d bytes (%s) to %s (fid %d) on server %s(%d)\n", + strlen(filedata), filedata, fname[i], fnum[i], + cli_state_get_host(context.cli[dir_server[i]]), file_server[i])); + if (cli_write(context.cli[file_server[i]], fnum[i], 0, filedata, 0, strlen(filedata)) != strlen(filedata)) + { + printf("write failed (%s)\n", cli_errstr(context.cli[file_server[i]])); + return False; + } + + if (!cli_close(context.cli[file_server[i]], fnum[i])) { + printf("close of %s failed (%s)\n", fname[i], cli_errstr(context.cli[file_server[i]])); + return False; + } + } + DEBUG(3,("used Dfs servers:")); + for (i=0; i < DFS_SERVER_COUNT ; i++) { + server_count++; + DEBUG(3,(" %s(%d)", cli_state_get_host(context.cli[i]), i)); + if (!torture_close_connection(context.cli[i])) + return False; + } + DEBUG(3,("\n")); + + printf("Passed dfs_random_test\n"); + return True; +} diff --git a/source4/torture/genbit.c b/source4/torture/genbit.c new file mode 100644 index 0000000000..6afde37706 --- /dev/null +++ b/source4/torture/genbit.c @@ -0,0 +1,83 @@ +/* + Unix SMB/CIFS implementation. + Gentest test definitions + + Copyright (C) James Myers 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +get_field_function test_field_get_file_attr; +get_field_function test_field_get_fid; +get_field_function test_field_get_filename; +get_field_function test_field_get_mtime; +get_field_function test_field_get_trans2; +get_field_function test_field_get_fsinfo_level; + +static struct unlink_test_parms_t gen_unlink_test_parms; +static struct close_test_parms_t gen_close_test_parms; +static struct qfsi_test_parms_t gen_qfsi_test_parms; + +static struct trans2_parms trans2_qfsi_parms = { + testFieldTypeTrans2, 1, 2, 0, 0, TRANSACT2_QFSINFO +}; + +static struct field_test_spec gen_unlink_test_spec[] = { + {"FATTR", testFieldTypeFileAttr, NULL, + 1, test_field_get_file_attr}, + {"FNAME", testFieldTypeFilename, NULL, + -1, test_field_get_filename}, + {"", -1, NULL, -1, NULL} +}; + +static struct field_test_spec gen_close_test_spec[] = { + {"FID", testFieldTypeFid, NULL, 1, + test_field_get_fid}, + {"MTIME", testFieldTypeMtime, NULL, 2, + test_field_get_mtime}, + {"", -1, NULL, -1, NULL} +}; + +static struct field_test_spec gen_qfsi_test_spec[] = { + {"TRANS2", testFieldTypeTrans2, + (void*)&trans2_qfsi_parms, 15, + test_field_get_trans2}, + {"INFO_LEVEL", 0, NULL, 1, test_field_get_fsinfo_level}, + {"", -1, NULL, -1, NULL} +}; + +static struct enum_test gen_enum_tests[] = { + {SMBunlink, "UNLINK", TEST_COND_TCON, + testTypeFilename, + TEST_OPTION_FILE_EXISTS | + TEST_OPTION_FILE_SYSTEM | + TEST_OPTION_FILE_HIDDEN | + TEST_OPTION_FILE_INVISIBLE | + TEST_OPTION_FILE_WILDCARD | + TEST_OPTION_FILE_NOT_EXIST, + 1, gen_unlink_test_spec, (void*)&gen_unlink_test_parms, + gen_execute_unlink, gen_verify_unlink}, + {SMBclose, "CLOSE", TEST_COND_TCON, + testTypeFid, + TEST_OPTION_FID_VALID | TEST_OPTION_FID_INVALID, + 3, gen_close_test_spec, (void*)&gen_close_test_parms, + gen_execute_close, gen_verify_close}, + {SMBtrans2, "QUERY_FS_INFO", TEST_COND_TCON, + testTypeConnected, + 1, + 16, gen_qfsi_test_spec, (void*)&gen_qfsi_test_parms, + gen_execute_qfsi, gen_verify_qfsi}, + {-1, NULL, 0, 0, 0, -1, NULL, NULL, NULL} +}; diff --git a/source4/torture/gendefs.h b/source4/torture/gendefs.h new file mode 100644 index 0000000000..6afde37706 --- /dev/null +++ b/source4/torture/gendefs.h @@ -0,0 +1,83 @@ +/* + Unix SMB/CIFS implementation. + Gentest test definitions + + Copyright (C) James Myers 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +get_field_function test_field_get_file_attr; +get_field_function test_field_get_fid; +get_field_function test_field_get_filename; +get_field_function test_field_get_mtime; +get_field_function test_field_get_trans2; +get_field_function test_field_get_fsinfo_level; + +static struct unlink_test_parms_t gen_unlink_test_parms; +static struct close_test_parms_t gen_close_test_parms; +static struct qfsi_test_parms_t gen_qfsi_test_parms; + +static struct trans2_parms trans2_qfsi_parms = { + testFieldTypeTrans2, 1, 2, 0, 0, TRANSACT2_QFSINFO +}; + +static struct field_test_spec gen_unlink_test_spec[] = { + {"FATTR", testFieldTypeFileAttr, NULL, + 1, test_field_get_file_attr}, + {"FNAME", testFieldTypeFilename, NULL, + -1, test_field_get_filename}, + {"", -1, NULL, -1, NULL} +}; + +static struct field_test_spec gen_close_test_spec[] = { + {"FID", testFieldTypeFid, NULL, 1, + test_field_get_fid}, + {"MTIME", testFieldTypeMtime, NULL, 2, + test_field_get_mtime}, + {"", -1, NULL, -1, NULL} +}; + +static struct field_test_spec gen_qfsi_test_spec[] = { + {"TRANS2", testFieldTypeTrans2, + (void*)&trans2_qfsi_parms, 15, + test_field_get_trans2}, + {"INFO_LEVEL", 0, NULL, 1, test_field_get_fsinfo_level}, + {"", -1, NULL, -1, NULL} +}; + +static struct enum_test gen_enum_tests[] = { + {SMBunlink, "UNLINK", TEST_COND_TCON, + testTypeFilename, + TEST_OPTION_FILE_EXISTS | + TEST_OPTION_FILE_SYSTEM | + TEST_OPTION_FILE_HIDDEN | + TEST_OPTION_FILE_INVISIBLE | + TEST_OPTION_FILE_WILDCARD | + TEST_OPTION_FILE_NOT_EXIST, + 1, gen_unlink_test_spec, (void*)&gen_unlink_test_parms, + gen_execute_unlink, gen_verify_unlink}, + {SMBclose, "CLOSE", TEST_COND_TCON, + testTypeFid, + TEST_OPTION_FID_VALID | TEST_OPTION_FID_INVALID, + 3, gen_close_test_spec, (void*)&gen_close_test_parms, + gen_execute_close, gen_verify_close}, + {SMBtrans2, "QUERY_FS_INFO", TEST_COND_TCON, + testTypeConnected, + 1, + 16, gen_qfsi_test_spec, (void*)&gen_qfsi_test_parms, + gen_execute_qfsi, gen_verify_qfsi}, + {-1, NULL, 0, 0, 0, -1, NULL, NULL, NULL} +}; diff --git a/source4/torture/genparm.c b/source4/torture/genparm.c new file mode 100644 index 0000000000..4d968ba6c3 --- /dev/null +++ b/source4/torture/genparm.c @@ -0,0 +1,732 @@ +/* + Unix SMB/CIFS implementation. + SMB test generator - load and parse test config + Copyright (C) James Myers 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "gentest.h" + +static struct gentest_context_t *contextP; + +#define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct)) + +static BOOL do_parameter(const char *pszParmName, const char *pszParmValue); +static BOOL do_section(const char *pszSectionName); + +/* prototypes for the special type handlers */ +static BOOL handle_tests(const char *pszParmValue, char **ptr); + +static BOOL handle_options(const char *pszParmValue, char **ptr); +static BOOL handle_fields(const char *pszParmValue, char **ptr); + +static struct enum_list enum_command[] = { + { + SMBunlink, "SMBunlink" + }, + {SMBclose, "SMBclosex"}, + {-1, NULL} + }; +static struct enum_list enum_condition[] = { + { + TEST_COND_NEGPROT, "TEST_COND_NEGPROT" + }, + {TEST_COND_SESSION, "TEST_COND_SESSION"}, + {TEST_COND_TCON, "TEST_COND_TCON"}, + {TEST_COND_FID, "TEST_COND_FID"}, + {-1, NULL} + }; +static struct enum_list enum_test_type[] = { + { + testTypeConnected, "Connected" + }, + {testTypeFilename, "Filename"}, + {testTypeFid, "FID"}, + {-1, NULL} + }; +static struct enum_list enum_options[] = { + {TEST_OPTION_FILE_EXISTS, "FILE_EXISTS"}, + {TEST_OPTION_FILE_NOT_EXIST, "FILE_NOT_EXIST"}, + {TEST_OPTION_FILE_HIDDEN, "FILE_HIDDEN"}, + {TEST_OPTION_FILE_SYSTEM, "FILE_SYSTEM"}, + {TEST_OPTION_FILE_INVISIBLE, "FILE_INVISIBLE"}, + {TEST_OPTION_FILE_WILDCARD, "FILE_WILDCARD"}, + {TEST_OPTION_FID_INVALID, "FID_INVALID"}, + {TEST_OPTION_FID_VALID, "FID_VALID"}, + {-1, NULL} + }; +static struct enum_list enum_execute[] = { + {(int)gen_execute_unlink, "gen_execute_unlink"}, + {(int)gen_execute_close, "gen_execute_close"}, + {-1, NULL} + }; +static struct enum_list enum_verify[] = { + { + (int)gen_verify_unlink, "gen_verify_unlink" + }, + {(int)gen_verify_close, "gen_verify_close"}, + {-1, NULL} + }; +static struct enum_list enum_field_type[] = { + { + testFieldTypeFilename, "Filename" + }, + {testFieldTypeFileAttr, "FileAttr"}, + {testFieldTypeFid, "FID"}, + {testFieldTypeMtime, "Mtime"}, + {testFieldTypeTrans2, "Trans2"}, + {-1, NULL} + }; +static struct enum_list enum_function[] = { + { + (int)test_field_get_filename, "test_field_get_filename" + }, + {(int)test_field_get_file_attr, "test_field_get_file_attr"}, + {-1, NULL} + }; + +/* Note: We do not initialise the defaults union - it is not allowed in ANSI C + */ +#define GEN_FLAG_GLOBAL 0x0001 /* fundamental options */ +#define GEN_FLAG_TEST 0x0002 /* test options */ +#define GEN_FLAG_FIELD 0x0004 /* field options */ + +static struct { + int command; + char *name; + int debug; + int condition; + int type; + int options; + int words; + struct field_test_spec* fields; + int field_count; + void* execute; + void* verify; +} +test_section; + +static struct { + char *name; + int type; + BOOL random; + int words; + void * function; +} +field_section; + +static struct parm_struct parm_table[] = { + {"Base Options", P_SEP, P_SEPARATOR + }, + /* global section parameters */ + {"tests", P_LIST, P_GLOBAL, NULL, handle_tests, NULL, GEN_FLAG_GLOBAL}, + + /* test section parameters */ + {"Test section", P_SEP, P_SEPARATOR}, + {"command", P_ENUM, P_LOCAL, &test_section.command, NULL, enum_command, GEN_FLAG_TEST}, + {"name", P_STRING, P_LOCAL, &test_section.name, NULL, NULL, GEN_FLAG_TEST}, + {"debug", P_INTEGER, P_LOCAL, &test_section.debug, NULL, NULL, GEN_FLAG_TEST}, + {"condition", P_ENUM, P_LOCAL, &test_section.condition, NULL, enum_condition, GEN_FLAG_TEST}, + {"type", P_ENUM, P_LOCAL, &test_section.type, NULL, enum_test_type, GEN_FLAG_TEST}, + {"options", P_LIST, P_LOCAL, &test_section.options, handle_options, NULL, GEN_FLAG_TEST}, + {"word count", P_INTEGER, P_LOCAL, &test_section.words, NULL, NULL, GEN_FLAG_TEST}, + {"fields", P_LIST, P_LOCAL, NULL, handle_fields, NULL, GEN_FLAG_TEST}, + {"execute", P_ENUM, P_LOCAL, &test_section.execute, NULL, enum_execute, GEN_FLAG_TEST}, + {"verify", P_ENUM, P_LOCAL, &test_section.verify, NULL, enum_verify, GEN_FLAG_TEST}, + + /* field section parameters */ + {"Field section", P_SEP, P_SEPARATOR}, + {"type", P_ENUM, P_LOCAL, &field_section.type, NULL, enum_field_type, GEN_FLAG_FIELD}, + {"random", P_BOOL, P_LOCAL, &field_section.random, NULL, NULL, GEN_FLAG_FIELD}, + {"word count", P_INTEGER, P_LOCAL, &field_section.words, NULL, NULL, GEN_FLAG_FIELD}, + {"function", P_ENUM, P_LOCAL, &field_section.function, NULL, enum_function, GEN_FLAG_FIELD}, + + {NULL, P_BOOL, P_NONE, NULL, NULL, NULL, 0} + }; + +static BOOL handle_tests(const char *pszParmValue, char **ptr) { + contextP->testNames = str_list_make(pszParmValue, NULL); + return True; +} +static BOOL handle_options(const char *pszParmValue, char **ptr) { + /* convert option names (in enum_options) to flags */ + char **str_array; + + str_array = str_list_make(pszParmValue, NULL); + + if (str_array) { + size_t i, j; + for ( j = 0; str_array[j] != NULL; j++) { + BOOL optionValid = False; + for (i = 0; enum_options[i].name; i++) { + if (strequal(str_array[j], + enum_options[i].name)) { + *(int *)ptr |= enum_options[i].value; + optionValid = True; + break; + } + } + if (!optionValid) + DEBUG(0,("handle_options: '%s' invalid option\n", + str_array[j])); + } + } + DEBUG(9,("handle_options: %s -> %p\n", pszParmValue, *ptr)); + + return True; +} + +static BOOL handle_fields(const char *pszParmValue, char **ptr) { + /* create initialized field structures for each name */ + char **str_array; + + str_array = str_list_make(pszParmValue, NULL); + + if (str_array) { + size_t i; + for ( i = 0; str_array[i] != NULL; i++) + test_section.field_count++; + /* allocate new field array */ + test_section.fields = talloc(contextP->mem_ctx, + test_section.field_count * sizeof(struct field_test_spec)); + for ( i = 0; str_array[i] != NULL; i++) + test_section.fields[i].name = str_array[i]; + } + return True; +} + +/*************************************************************************** + Map a parameter's string representation to something we can use. + Returns False if the parameter string is not recognised, else TRUE. +***************************************************************************/ + +static int map_parameter(const char *pszParmName, int section) { + int iIndex; + unsigned validFlags = 0; + + if (*pszParmName == '-') + return (-1); + + /* Check for section-specific parameters. + * This allows the same parameter name to be used in + * different sections with different meanings. + */ + if (section == GEN_SECTION_GLOBAL) + validFlags |= GEN_FLAG_GLOBAL; + if (section == GEN_SECTION_TEST) + validFlags |= GEN_FLAG_TEST; + if (section == GEN_SECTION_FIELD) + validFlags |= GEN_FLAG_FIELD; + for (iIndex = 0; parm_table[iIndex].label; iIndex++) + if ((parm_table[iIndex].flags & validFlags) && + strwicmp(parm_table[iIndex].label, pszParmName) == 0) + return (iIndex); + + /* Warn only if it isn't parametric option */ + if (strchr(pszParmName, ':') == NULL) + DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName)); + /* We do return 'fail' for parametric options as well because they are + stored in different storage + */ + return (-1); +} + +/*************************************************************************** + Set a boolean variable from the text value stored in the passed string. + Returns True in success, False if the passed string does not correctly + represent a boolean. +***************************************************************************/ + +static BOOL set_boolean(BOOL *pb, const char *pszParmValue) { + BOOL bRetval; + + bRetval = True; + if (strwicmp(pszParmValue, "yes") == 0 || + strwicmp(pszParmValue, "true") == 0 || + strwicmp(pszParmValue, "1") == 0) { + *pb = True; + } else if (strwicmp(pszParmValue, "no") == 0 || + strwicmp(pszParmValue, "False") == 0 || + strwicmp(pszParmValue, "0") == 0) { + *pb = False; + } else { + DEBUG(0, + ("ERROR: Badly formed boolean in configuration file: \"%s\".\n", + pszParmValue)); + bRetval = False; + } + return (bRetval); +} + +/*************************************************************************** + Process a parameter +***************************************************************************/ + +static BOOL gen_do_parm(struct gentest_context_t *context, + const char *pszParmName, const char *pszParmValue) { + int parmnum, i; + void *parm_ptr = NULL; /* where we are going to store the result */ + void *def_ptr = NULL; + + parmnum = map_parameter(pszParmName, context->iCurrentSectionType); + + if (parmnum < 0) { + DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName)); + return (True); + } + DEBUG(19,("gen_do_parm: parm %s is valid\n", pszParmName)); + def_ptr = parm_table[parmnum].ptr; + + /* we might point at a test, a field or a global */ + if (context->iCurrentSectionType == GEN_SECTION_GLOBAL) { + parm_ptr = def_ptr; + } else { + if (parm_table[parmnum].class == P_GLOBAL) { + DEBUG(0, + ("Global parameter %s found in service section!\n", + pszParmName)); + return (True); + } + parm_ptr = def_ptr; + } + + /* if it is a special case then go ahead */ + if (parm_table[parmnum].special) { + parm_table[parmnum].special(pszParmValue, (char **)parm_ptr); + return (True); + } + DEBUG(19,("gen_do_parm: parm %s type=%d\n", pszParmName, + parm_table[parmnum].type)); + + /* now switch on the type of variable it is */ + switch (parm_table[parmnum].type) { + case P_BOOL: + set_boolean(parm_ptr, pszParmValue); + break; + + case P_INTEGER: + *(int *)parm_ptr = atoi(pszParmValue); + break; + + case P_LIST: + *(char ***)parm_ptr = str_list_make(pszParmValue, NULL); + break; + + case P_STRING: + parm_ptr = talloc_strdup(context->mem_ctx, pszParmValue); + break; + + case P_ENUM: + for (i = 0; parm_table[parmnum].enum_list[i].name; i++) { + if (strequal + (pszParmValue, + parm_table[parmnum].enum_list[i].name)) { + *(int *)parm_ptr = + parm_table[parmnum]. + enum_list[i].value; + break; + } + } + break; + case P_SEP: + break; + default: + break; + } + + return (True); +} +/*************************************************************************** + Process a parameter. +***************************************************************************/ + +static BOOL do_parameter(const char *pszParmName, const char *pszParmValue) { + BOOL bRetval; + + DEBUG(4, ("doing parameter %s = %s\n", pszParmName, pszParmValue)); + bRetval = gen_do_parm(contextP, pszParmName, pszParmValue); + + return bRetval; +} + +/*************************************************************************** +Check a test for consistency. Return False if the test is in any way +incomplete or faulty, else True. +***************************************************************************/ + +static BOOL test_ok(struct gentest_context_t *context,int iTest) { + BOOL bRetval = True; + + DEBUG(9,("test_ok: index=%d, tests@%p\n", iTest, + context->tests)); + /* initialize new test section */ + DEBUG(9,("test_ok: name=%s\n", test_section.name)); + context->tests[iTest].name = test_section.name; + context->tests[iTest].debug = test_section.debug; + context->tests[iTest].type = test_section.type; + context->tests[iTest].command = test_section.command; + context->tests[iTest].initial_conditions = test_section.condition; + context->tests[iTest].options = test_section.options; + context->tests[iTest].word_count = test_section.words; + context->tests[iTest].fields = test_section.fields; + context->tests[iTest].field_count = test_section.field_count; + context->tests[iTest].execute = test_section.execute; + context->tests[iTest].verify = test_section.verify; + + /* validate test entry */ + DEBUG(9,("test_ok: validate name=%s\n", test_section.name)); + if (context->tests[iTest].name[0] == '\0') { + DEBUG(0, ("The following message indicates an internal error:\n")); + DEBUG(0, ("No test name in test entry.\n")); + bRetval = False; + } + if (bRetval) { + context->tests[iTest].valid = True; + DEBUG(9,("added valid test %s\n",test_section.name)); + } + + return (bRetval); +} +/*************************************************************************** +Check a field for consistency. Return False if the field is in any way +incomplete or faulty, else True. +***************************************************************************/ + +static BOOL field_ok(struct gentest_context_t *context,int iField) { + BOOL bRetval = True; + + /* setup new field entry */ + DEBUG(9,("field_ok: index=%d, fields@%p\n", iField, + context->fields)); + context->fields[iField].name = field_section.name; + context->fields[iField].type = field_section.type; + context->fields[iField].random = field_section.random; + context->fields[iField].word_count = field_section.words; + context->fields[iField].function = field_section.function; + + /* validate field */ + if (context->fields[iField].name[0] == '\0') { + DEBUG(0, ("The following message indicates an internal error:\n")); + DEBUG(0, ("No field name in field entry.\n")); + bRetval = False; + } + if (bRetval) { + context->fields[iField].valid = True; + DEBUG(9,("added valid field %s\n",field_section.name)); + } + + return (bRetval); +} +/*************************************************************************** +Find a test by name. Otherwise works like get_test. +***************************************************************************/ + +static int gettestbyname(struct gentest_context_t *context, + const char *pszTestName) { + int iTest; + + for (iTest = context->iNumTests - 1; iTest >= 0; iTest--) + if (context->tests[iTest].valid && + strwicmp(context->tests[iTest].name, pszTestName) == 0) { + break; + } + + return (iTest); +} +/*************************************************************************** +Find a field by name. Otherwise works like get_field. +***************************************************************************/ + +static int getfieldbyname(struct gentest_context_t *context, + const char *pszFieldName) { + int iField; + + for (iField = context->iNumFields - 1; iField >= 0; iField--) + if (context->fields[iField].valid && + strwicmp(context->fields[iField].name, pszFieldName) == 0) { + break; + } + + return (iField); +} +/*************************************************************************** + Add a new test to the tests array initialising it with the given + test. +***************************************************************************/ + +static int add_a_test(struct gentest_context_t *context, + const char *name) { + int i; + int num_to_alloc = context->iNumTests + 1; + + DEBUG(3, ("add_a_test: %s at index %d\n", name, num_to_alloc-1)); + /* it might already exist */ + if (name) { + i = gettestbyname(context, name); + if (i >= 0) + return (i); + } + + /* find an invalid one */ + for (i = 0; i < context->iNumTests; i++) + if (!context->tests[i].valid) + break; + + /* if not, then create one */ + DEBUG(3, ("add_a_test: add %s at index %d\n", name, i)); + if (i == context->iNumTests) { + struct enum_test *tsp; + + tsp = talloc_realloc(context->mem_ctx, context->tests, + sizeof(struct enum_test) * + num_to_alloc); + + if (!tsp) { + DEBUG(0,("add_a_test: failed to enlarge TestPtrs!\n")); + return (-1); + } else { + context->tests = tsp; + } + + context->iNumTests++; + DEBUG(3, ("add_a_test: tests@%p\n", tsp)); + } //else + //free_test(context->tests[i]); + /* reinitialize test section fields */ + test_section.command = 0; + test_section.name = talloc_strdup(context->mem_ctx, name); + test_section.debug = 0; + test_section.condition = 0; + test_section.type = 0; + test_section.options = 0; + test_section.words = 0; + test_section.fields = NULL; + test_section.field_count = 0; + test_section.execute = NULL; + test_section.verify = NULL; + context->tests[i].valid = False; + + if (name) + context->tests[i].name = test_section.name; + DEBUG(3, ("add_a_test: added %s at index %d\n", name, i)); + return (i); +} +/*************************************************************************** + Add a new field to the fields array initialising it with the given + field. +***************************************************************************/ + +static int add_a_field(struct gentest_context_t *context, + const char *name) { + int i; + int num_to_alloc = context->iNumFields + 1; + + DEBUG(3, ("add_a_field: %s at index %d\n", name, num_to_alloc-1)); + /* it might already exist */ + if (name) { + i = getfieldbyname(context, name); + if (i >= 0) + return (i); + } + + /* find an invalid one */ + for (i = 0; i < context->iNumFields; i++) + if (!context->fields[i].valid) + break; + + /* if not, then create one */ + DEBUG(3, ("add_a_field: add %s at index %d\n", name, i)); + if (i == context->iNumFields) { + field_test_spec *tsp; + + tsp = talloc_realloc(context->mem_ctx, context->fields, + sizeof(field_test_spec) * + num_to_alloc); + + if (!tsp) { + DEBUG(0,("add_a_field: failed to enlarge FieldPtrs!\n")); + return (-1); + } else { + context->fields = tsp; + } + + context->iNumFields++; + DEBUG(3, ("add_a_field: fields@%p\n", tsp)); + } + + /* reinitialize field section fields */ + field_section.name = NULL; + field_section.type = 0; + field_section.random = False; + field_section.words = 0; + field_section.function = NULL; + context->fields[i].valid = False; + + if (name) + field_section.name = talloc_strdup(context->mem_ctx, name); + DEBUG(3, ("add_a_field: added %s at index %d\n", name, i)); + return (i); +} +/*************************************************************************** + Process a new section (test or field). + Returns True on success, False on failure. +***************************************************************************/ + +static BOOL do_section(const char *pszSectionName) { + BOOL bRetval; + BOOL isglobal = (strwicmp(pszSectionName, GLOBAL_NAME) == 0); + char *sectionType, *sectionName, *p; + + bRetval = False; + DEBUG(4, ("doing section %s\n", pszSectionName)); + /* if we've just struck a global section, note the fact. */ + contextP->bInGlobalSection = isglobal; + + /* check for multiple global sections */ + if (contextP->bInGlobalSection) { + DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName)); + contextP->iCurrentSectionType = GEN_SECTION_GLOBAL; + return (True); + } else if (contextP->iCurrentSectionType == GEN_SECTION_GLOBAL) { + /* just finished global section */ + ; + } + + /* parse section name (form <type:name> */ + sectionType = talloc_strdup(contextP->mem_ctx, pszSectionName); + p = strchr_m(sectionType,':'); + if (p) { + *p = 0; + sectionName = talloc_strdup(contextP->mem_ctx, p+1); + } else { + DEBUG(0, ("Invalid section name %s\n", pszSectionName)); + return False; + } + + /* if we have a current test or field, tidy it up before moving on */ + bRetval = True; + + if (contextP->iTestIndex >= 0 && contextP->iCurrentSectionType == GEN_SECTION_TEST) + bRetval = test_ok(contextP, contextP->iTestIndex); + if (contextP->iFieldIndex >= 0 && contextP->iCurrentSectionType == GEN_SECTION_FIELD) + bRetval = field_ok(contextP, contextP->iFieldIndex); + + /* determine type of this section */ + contextP->iCurrentSectionType = GEN_SECTION_INVALID; + if (strequal(sectionType, "test")) + contextP->iCurrentSectionType = GEN_SECTION_TEST; + if (strequal(sectionType, "field")) + contextP->iCurrentSectionType = GEN_SECTION_FIELD; + if (contextP->iCurrentSectionType == GEN_SECTION_INVALID) { + DEBUG(0, ("Invalid section type %s\n", sectionType)); + return False; + } + + /* if all is still well, move to the next record in the tests array */ + if (bRetval) { + /* We put this here to avoid an odd message order if messages are */ + /* issued by the post-processing of a previous section. */ + DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName)); + + if (contextP->iCurrentSectionType == GEN_SECTION_TEST) { + if ((contextP->iTestIndex = add_a_test(contextP, sectionName)) + < 0) { + DEBUG(0, ("Failed to add a new test\n")); + return (False); + } + } + if (contextP->iCurrentSectionType == GEN_SECTION_FIELD) { + if ((contextP->iFieldIndex = add_a_field(contextP, sectionName)) + < 0) { + DEBUG(0, ("Failed to add a new field\n")); + return (False); + } + } + } + + return (bRetval); +} + +/*************************************************************************** + Load the test configuration from the test config file. Return True on success, + False on failure. +***************************************************************************/ + +BOOL gen_load_config(struct gentest_context_t *contextPTR) { + char *n2; + BOOL bRetval; + + contextP = contextPTR; + contextP->param_opt = NULL; + + n2 = talloc_strdup(contextP->mem_ctx, contextP->config_filename); + + /* We get sections first, so have to start 'behind' to make up */ + contextP->iTestIndex = -1; + bRetval = pm_process(n2, do_section, do_parameter); + + /* finish up the last section */ + DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval))); + + /* if we have a current test or field, tidy it up before moving on */ + if (contextP->iTestIndex >= 0 && contextP->iCurrentSectionType == GEN_SECTION_TEST) + bRetval = test_ok(contextP, contextP->iTestIndex); + if (contextP->iFieldIndex >= 0 && contextP->iCurrentSectionType == GEN_SECTION_FIELD) + bRetval = field_ok(contextP, contextP->iFieldIndex); + + /* OK, we've parsed the configuration, now we need to match + * the field sections to fields required by tests */ + if (bRetval) { + int i,j,k; + BOOL fieldValid; + for (i=0; i<contextP->iNumTests; i++) { + DEBUG(19,("gen_load_config: process test %d %s\n", + i, contextP->tests[i].name)); + for (j=0; j<contextP->tests[i].field_count; j++) { + fieldValid = False; + DEBUG(19,("gen_load_config: look for field %s\n", + contextP->tests[i].fields[j].name)); + for (k=0; k<contextP->iNumFields; k++) { + DEBUG(19,("gen_load_config: compare field %s\n", + contextP->fields[k].name)); + if (strequal(contextP->tests[i].fields[j].name, + contextP->fields[k].name)) { + /* matching field found */ + fieldValid = True; + contextP->tests[i].fields[j].type = contextP->fields[k].type; + contextP->tests[i].fields[j].word_count = contextP->fields[k].word_count; + contextP->tests[i].fields[j].function = contextP->fields[k].function; + contextP->tests[i].fields[j].valid = contextP->fields[k].valid; + contextP->tests[i].fields[j].random = contextP->fields[k].random; + contextP->tests[i].fields[j].parms = contextP->fields[k].parms; + break; + } + if (fieldValid) + break; + } + if (!fieldValid) { + contextP->tests[i].fields[j].valid = False; + contextP->tests[i].fields[j].function = test_field_get_null; + DEBUG(0,("missing field section: %s\n", + contextP->tests[i].fields[j].name)); + } + } + } + } + + return (bRetval); +} diff --git a/source4/torture/gentest.c b/source4/torture/gentest.c new file mode 100644 index 0000000000..abe6d057c3 --- /dev/null +++ b/source4/torture/gentest.c @@ -0,0 +1,2113 @@ +/* + Unix SMB/CIFS implementation. + generic testing tool + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define NSERVERS 2 +#define NINSTANCES 2 + +/* global options */ +static struct gentest_options { + BOOL showall; + BOOL analyze; + BOOL analyze_always; + BOOL analyze_continuous; + uint_t max_open_handles; + uint_t seed; + uint_t numops; + BOOL use_oplocks; + char **ignore_patterns; + const char *seeds_file; + BOOL use_preset_seeds; + BOOL fast_reconnect; +} options; + +/* mapping between open handles on the server and local handles */ +static struct { + BOOL active; + uint_t instance; + uint_t server_fnum[NSERVERS]; + const char *name; +} *open_handles; +static uint_t num_open_handles; + +/* state information for the servers. We open NINSTANCES connections to + each server */ +static struct { + struct cli_state *cli[NINSTANCES]; + char *server_name; + char *share_name; + char *username; + char *password; +} servers[NSERVERS]; + +/* the seeds and flags for each operation */ +static struct { + uint_t seed; + BOOL disabled; +} *op_parms; + + +/* oplock break info */ +static struct { + BOOL got_break; + uint16 fnum; + uint16 handle; + uint8 level; + BOOL do_close; +} oplocks[NSERVERS][NINSTANCES]; + +/* change notify reply info */ +static struct { + int notify_count; + NTSTATUS status; + struct smb_notify notify; +} notifies[NSERVERS][NINSTANCES]; + +/* info relevant to the current operation */ +static struct { + const char *name; + uint_t seed; + NTSTATUS status; + uint_t opnum; + TALLOC_CTX *mem_ctx; +} current_op; + + + +#define BAD_HANDLE 0xFFFE + +static BOOL oplock_handler(struct cli_transport *transport, uint16 tid, uint16 fnum, uint8 level, void *private); +static void idle_func(struct cli_transport *transport, void *private); + +/* + check if a string should be ignored. This is used as the basis + for all error ignore settings +*/ +static BOOL ignore_pattern(const char *str) +{ + int i; + if (!options.ignore_patterns) return False; + + for (i=0;options.ignore_patterns[i];i++) { + if (strcmp(options.ignore_patterns[i], str) == 0 || + gen_fnmatch(options.ignore_patterns[i], str) == 0) { + DEBUG(2,("Ignoring '%s'\n", str)); + return True; + } + } + return False; +} + +/***************************************************** +connect to the servers +*******************************************************/ +static BOOL connect_servers_fast(void) +{ + int h, i; + + /* close all open files */ + for (h=0;h<options.max_open_handles;h++) { + if (!open_handles[h].active) continue; + for (i=0;i<NSERVERS;i++) { + if (!cli_close(servers[i].cli[open_handles[h].instance], + open_handles[h].server_fnum[i])) { + return False; + } + open_handles[h].active = False; + } + } + + return True; +} + + + + +/***************************************************** +connect to the servers +*******************************************************/ +static BOOL connect_servers(void) +{ + int i, j; + + if (options.fast_reconnect && servers[0].cli[0]) { + if (connect_servers_fast()) { + return True; + } + } + + /* close any existing connections */ + for (i=0;i<NSERVERS;i++) { + for (j=0;j<NINSTANCES;j++) { + if (servers[i].cli[j]) { + cli_tdis(servers[i].cli[j]); + cli_shutdown(servers[i].cli[j]); + servers[i].cli[j] = NULL; + } + } + } + + for (i=0;i<NSERVERS;i++) { + for (j=0;j<NINSTANCES;j++) { + NTSTATUS status; + printf("Connecting to \\\\%s\\%s as %s - instance %d\n", + servers[i].server_name, servers[i].share_name, + servers[i].username, j); + status = cli_full_connection(&servers[i].cli[j], + "gentest", + servers[i].server_name, NULL, + servers[i].share_name, "?????", + servers[i].username, "", + servers[i].password, 0, NULL); + if (!NT_STATUS_IS_OK(status)) { + printf("Failed to connect to \\\\%s\\%s - %s\n", + servers[i].server_name, servers[i].share_name, + nt_errstr(status)); + return False; + } + + cli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL); + cli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 10, NULL); + } + } + + return True; +} + +/* + work out the time skew between the servers - be conservative +*/ +static uint_t time_skew(void) +{ + uint_t ret; + ret = ABS(servers[0].cli[0]->transport->negotiate.server_time - + servers[1].cli[0]->transport->negotiate.server_time); + return ret + 300; +} + +/* + turn an fnum for an instance into a handle +*/ +static uint_t fnum_to_handle(int server, int instance, uint16 fnum) +{ + uint_t i; + for (i=0;i<options.max_open_handles;i++) { + if (!open_handles[i].active || + instance != open_handles[i].instance) continue; + if (open_handles[i].server_fnum[server] == fnum) { + return i; + } + } + printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n", + fnum, server, instance); + return BAD_HANDLE; +} + +/* + add some newly opened handles +*/ +static void gen_add_handle(int instance, const char *name, uint16 fnums[NSERVERS]) +{ + int i, h; + for (h=0;h<options.max_open_handles;h++) { + if (!open_handles[h].active) break; + } + if (h == options.max_open_handles) { + /* we have to force close a random handle */ + h = random() % options.max_open_handles; + for (i=0;i<NSERVERS;i++) { + if (!cli_close(servers[i].cli[open_handles[h].instance], + open_handles[h].server_fnum[i])) { + printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n", + cli_errstr(servers[i].cli[open_handles[h].instance])); + } + } + printf("Recovered handle %d\n", h); + num_open_handles--; + } + for (i=0;i<NSERVERS;i++) { + open_handles[h].server_fnum[i] = fnums[i]; + open_handles[h].instance = instance; + open_handles[h].active = True; + open_handles[h].name = name; + } + num_open_handles++; + + printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n", + num_open_handles, h, + open_handles[h].server_fnum[0], open_handles[h].server_fnum[1], + name); +} + +/* + remove a closed handle +*/ +static void gen_remove_handle(int instance, uint16 fnums[NSERVERS]) +{ + int h; + for (h=0;h<options.max_open_handles;h++) { + if (instance == open_handles[h].instance && + open_handles[h].server_fnum[0] == fnums[0]) { + open_handles[h].active = False; + num_open_handles--; + printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n", + num_open_handles, h, + open_handles[h].server_fnum[0], open_handles[h].server_fnum[1], + open_handles[h].name); + return; + } + } + printf("Removing invalid handle!?\n"); + exit(1); +} + +/* + return True with 'chance' probability as a percentage +*/ +static BOOL gen_chance(uint_t chance) +{ + return ((random() % 100) <= chance); +} + +/* + map an internal handle number to a server fnum +*/ +static uint16 gen_lookup_fnum(int server, uint16 handle) +{ + if (handle == BAD_HANDLE) return handle; + return open_handles[handle].server_fnum[server]; +} + +/* + return a file handle +*/ +static uint16 gen_fnum(int instance) +{ + uint16 h; + int count = 0; + + if (gen_chance(20)) return BAD_HANDLE; + + while (num_open_handles > 0 && count++ < 10*options.max_open_handles) { + h = random() % options.max_open_handles; + if (open_handles[h].active && + open_handles[h].instance == instance) { + return h; + } + } + return BAD_HANDLE; +} + +/* + return a file handle, but skewed so we don't close the last + couple of handles too readily +*/ +static uint16 gen_fnum_close(int instance) +{ + if (num_open_handles < 3) { + if (gen_chance(80)) return BAD_HANDLE; + } + + return gen_fnum(instance); +} + +/* + generate an integer in a specified range +*/ +static int gen_int_range(uint_t min, uint_t max) +{ + uint_t r = random(); + return min + (r % (1+max-min)); +} + +/* + return a fnum for use as a root fid + be careful to call GEN_SET_FNUM() when you use this! +*/ +static uint16 gen_root_fid(int instance) +{ + if (gen_chance(5)) return gen_fnum(instance); + return 0; +} + +/* + generate a file offset +*/ +static int gen_offset(void) +{ + if (gen_chance(20)) return 0; + return gen_int_range(0, 1024*1024); +} + +/* + generate a io count +*/ +static int gen_io_count(void) +{ + if (gen_chance(20)) return 0; + return gen_int_range(0, 4096); +} + +/* + generate a filename +*/ +static const char *gen_fname(void) +{ + const char *names[] = {"\\gentest\\gentest.dat", + "\\gentest\\foo", + "\\gentest\\foo2.sym", + "\\gentest\\foo3.dll", + "\\gentest\\foo4", + "\\gentest\\foo4:teststream1", + "\\gentest\\foo4:teststream2", + "\\gentest\\foo5.exe", + "\\gentest\\foo5.exe:teststream3", + "\\gentest\\foo5.exe:teststream4", + "\\gentest\\foo6.com", + "\\gentest\\blah", + "\\gentest\\blah\\blergh.txt", + "\\gentest\\blah\\blergh2", + "\\gentest\\blah\\blergh3.txt", + "\\gentest\\blah\\blergh4", + "\\gentest\\blah\\blergh5.txt", + "\\gentest\\blah\\blergh5", + "\\gentest\\blah\\.", +#if 0 + /* this causes problem with w2k3 */ + "\\gentest\\blah\\..", +#endif + "\\gentest\\a_very_long_name.bin", + "\\gentest\\x.y", + "\\gentest\\blah"}; + int i; + + do { + i = gen_int_range(0, ARRAY_SIZE(names)-1); + } while (ignore_pattern(names[i])); + + return names[i]; +} + +/* + generate a filename with a higher chance of choosing an already + open file +*/ +static const char *gen_fname_open(int instance) +{ + uint16 h; + h = gen_fnum(instance); + if (h == BAD_HANDLE) { + return gen_fname(); + } + return open_handles[h].name; +} + +/* + generate a wildcard pattern +*/ +static const char *gen_pattern(void) +{ + int i; + const char *names[] = {"\\gentest\\*.dat", + "\\gentest\\*", + "\\gentest\\*.*", + "\\gentest\\blah\\*.*", + "\\gentest\\blah\\*", + "\\gentest\\?"}; + + if (gen_chance(50)) return gen_fname(); + + do { + i = gen_int_range(0, ARRAY_SIZE(names)-1); + } while (ignore_pattern(names[i])); + + return names[i]; +} + +/* + generate a bitmask +*/ +static uint32 gen_bits_mask(uint_t mask) +{ + uint_t ret = random(); + return ret & mask; +} + +/* + generate a bitmask with high probability of the first mask + and low of the second +*/ +static uint32 gen_bits_mask2(uint32 mask1, uint32 mask2) +{ + if (gen_chance(10)) return gen_bits_mask(mask2); + return gen_bits_mask(mask1); +} + +/* + generate a boolean +*/ +static BOOL gen_bool(void) +{ + return gen_bits_mask2(0x1, 0xFF); +} + +/* + return a lockingx lock mode +*/ +static uint16 gen_lock_mode(void) +{ + if (gen_chance(5)) return gen_bits_mask(0xFFFF); + if (gen_chance(20)) return gen_bits_mask(0x1F); + return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES); +} + +/* + generate a pid +*/ +static uint16 gen_pid(void) +{ + if (gen_chance(10)) return gen_bits_mask(0xFFFF); + return getpid(); +} + +/* + generate a lock count +*/ +static SMB_OFF_T gen_lock_count(void) +{ + return gen_int_range(0, 3); +} + +/* + generate a ntcreatex flags field +*/ +static uint32 gen_ntcreatex_flags(void) +{ + if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED; + return gen_bits_mask2(0x1F, 0xFFFFFFFF); +} + +/* + generate a NT access mask +*/ +static uint32 gen_access_mask(void) +{ + if (gen_chance(50)) return SEC_RIGHT_MAXIMUM_ALLOWED; + if (gen_chance(20)) return GENERIC_RIGHTS_FILE_ALL_ACCESS; + return gen_bits_mask(0xFFFFFFFF); +} + +/* + generate a ntcreatex create options bitfield +*/ +static uint32 gen_create_options(void) +{ + if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF); + if (gen_chance(50)) return 0; + return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY); +} + +/* + generate a ntcreatex open disposition +*/ +static uint32 gen_open_disp(void) +{ + if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF); + return gen_int_range(0, 5); +} + +/* + generate an openx open mode +*/ +static uint16 gen_openx_mode(void) +{ + if (gen_chance(20)) return gen_bits_mask(0xFFFF); + if (gen_chance(20)) return gen_bits_mask(0xFF); + return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3); +} + +/* + generate an openx flags field +*/ +static uint16 gen_openx_flags(void) +{ + if (gen_chance(20)) return gen_bits_mask(0xFFFF); + return gen_bits_mask(0x7); +} + +/* + generate an openx open function +*/ +static uint16 gen_openx_func(void) +{ + if (gen_chance(20)) return gen_bits_mask(0xFFFF); + return gen_bits_mask(0x13); +} + +/* + generate a file attrib combination +*/ +static uint32 gen_attrib(void) +{ + if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF); + return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); +} + +/* + generate a unix timestamp +*/ +static time_t gen_timet(void) +{ + if (gen_chance(30)) return 0; + return (time_t)random(); +} + +/* + generate a unix timestamp +*/ +static NTTIME gen_nttime(void) +{ + NTTIME ret; + unix_to_nt_time(&ret, gen_timet()); + return ret; +} + +/* + generate a milliseconds protocol timeout +*/ +static uint32 gen_timeout(void) +{ + if (gen_chance(98)) return 0; + return random() % 50; +} + +/* + generate a file allocation size +*/ +static uint_t gen_alloc_size(void) +{ + uint_t ret; + + if (gen_chance(30)) return 0; + + ret = random() % 4*1024*1024; + /* give a high chance of a round number */ + if (gen_chance(60)) { + ret &= ~(1024*1024 - 1); + } + return ret; +} + +/* + generate an ea_struct +*/ +struct ea_struct gen_ea_struct(void) +{ + struct ea_struct ea; + const char *names[] = {"EAONE", + "", + "FOO!", + " WITH SPACES ", + ".", + "AVERYLONGATTRIBUTENAME"}; + const char *values[] = {"VALUE1", + "", + "NOT MUCH FOO", + " LEADING SPACES ", + ":", + "ASOMEWHATLONGERATTRIBUTEVALUE"}; + int i; + + do { + i = gen_int_range(0, ARRAY_SIZE(names)-1); + } while (ignore_pattern(names[i])); + + ea.name.s = names[i]; + + do { + i = gen_int_range(0, ARRAY_SIZE(values)-1); + } while (ignore_pattern(values[i])); + + ea.value = data_blob(values[i], strlen(values[i])); + + if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF); + ea.flags = 0; + + return ea; +} + + +/* + this is called when a change notify reply comes in +*/ +static void async_notify(struct cli_request *req) +{ + struct smb_notify notify; + NTSTATUS status; + int i, j; + uint16 tid; + struct cli_transport *transport = req->transport; + + tid = SVAL(req->in.hdr, HDR_TID); + + status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify); + if (NT_STATUS_IS_OK(status)) { + printf("notify tid=%d num_changes=%d action=%d name=%s\n", + tid, + notify.out.num_changes, + notify.out.changes[0].action, + notify.out.changes[0].name.s); + } + + for (i=0;i<NSERVERS;i++) { + for (j=0;j<NINSTANCES;j++) { + if (transport == servers[i].cli[j]->transport && + tid == servers[i].cli[j]->tree->tid) { + notifies[i][j].notify_count++; + notifies[i][j].status = status; + notifies[i][j].notify = notify; + } + } + } +} + +/* + the oplock handler will either ack the break or close the file +*/ +static BOOL oplock_handler(struct cli_transport *transport, uint16 tid, uint16 fnum, uint8 level, void *private) +{ + union smb_close io; + NTSTATUS status; + int i, j; + BOOL do_close; + struct cli_tree *tree = NULL; + + srandom(current_op.seed); + do_close = gen_chance(50); + + for (i=0;i<NSERVERS;i++) { + for (j=0;j<NINSTANCES;j++) { + if (transport == servers[i].cli[j]->transport && + tid == servers[i].cli[j]->tree->tid) { + oplocks[i][j].got_break = True; + oplocks[i][j].fnum = fnum; + oplocks[i][j].handle = fnum_to_handle(i, j, fnum); + oplocks[i][j].level = level; + oplocks[i][j].do_close = do_close; + tree = servers[i].cli[j]->tree; + } + } + } + + if (!tree) { + printf("Oplock break not for one of our trees!?\n"); + return False; + } + + if (!do_close) { + printf("oplock ack fnum=%d\n", fnum); + return cli_oplock_ack(tree, fnum, level == 1? 0x102 : 2); + } + + printf("oplock close fnum=%d\n", fnum); + + io.close.level = RAW_CLOSE_CLOSE; + io.close.in.fnum = fnum; + io.close.in.write_time = 0; + status = smb_raw_close(tree, &io); + + if (!NT_STATUS_IS_OK(status)) { + printf("WARNING: close failed in oplock_handler_close - %s\n", nt_errstr(status)); + } + return True; +} + + +/* + the idle function tries to cope with getting an oplock break on a connection, and + an operation on another connection blocking until that break is acked + we check for operations on all transports in the idle function +*/ +static void idle_func(struct cli_transport *transport, void *private) +{ + int i, j; + for (i=0;i<NSERVERS;i++) { + for (j=0;j<NINSTANCES;j++) { + if (servers[i].cli[j] && + transport != servers[i].cli[j]->transport && + cli_transport_pending(servers[i].cli[j]->transport)) { + if (!cli_request_receive_next(servers[i].cli[j]->transport)) { + printf("Connection to server %d instance %d died!\n", + i, j); + exit(1); + } + } + } + } + +} + + +/* + compare NTSTATUS, using checking ignored patterns +*/ +static BOOL compare_status(NTSTATUS status1, NTSTATUS status2) +{ + if (NT_STATUS_EQUAL(status1, status2)) return True; + + /* one code being an error and the other OK is always an error */ + if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return False; + + /* if we are ignoring one of the status codes then consider this a match */ + if (ignore_pattern(nt_errstr(status1)) || + ignore_pattern(nt_errstr(status2))) { + return True; + } + return False; +} + + +/* + check for pending packets on all connections +*/ +static void check_pending(void) +{ + int i, j; + + msleep(20); + + for (j=0;j<NINSTANCES;j++) { + for (i=0;i<NSERVERS;i++) { + if (cli_transport_pending(servers[i].cli[j]->transport)) { + if (!cli_request_receive_next(servers[i].cli[j]->transport)) { + printf("Connection to server %d instance %d died!\n", + i, j); + exit(1); + } + } + } + } +} + +/* + check that the same oplock breaks have been received by all instances +*/ +static BOOL check_oplocks(const char *call) +{ + int i, j; + int tries = 0; + +again: + check_pending(); + + for (j=0;j<NINSTANCES;j++) { + for (i=1;i<NSERVERS;i++) { + if (oplocks[0][j].got_break != oplocks[i][j].got_break || + oplocks[0][j].handle != oplocks[i][j].handle || + oplocks[0][j].level != oplocks[i][j].level) { + if (tries++ < 10) goto again; + printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n", + oplocks[0][j].got_break, + oplocks[0][j].handle, + oplocks[0][j].level, + oplocks[i][j].got_break, + oplocks[i][j].handle, + oplocks[i][j].level); + return False; + } + } + } + + /* if we got a break and closed then remove the handle */ + for (j=0;j<NINSTANCES;j++) { + if (oplocks[0][j].got_break && + oplocks[0][j].do_close) { + uint16 fnums[NSERVERS]; + for (i=0;i<NSERVERS;i++) { + fnums[i] = oplocks[i][j].fnum; + } + gen_remove_handle(j, fnums); + break; + } + } + return True; +} + + +/* + check that the same change notify info has been received by all instances +*/ +static BOOL check_notifies(const char *call) +{ + int i, j; + int tries = 0; + +again: + check_pending(); + + for (j=0;j<NINSTANCES;j++) { + for (i=1;i<NSERVERS;i++) { + int n; + struct smb_notify not1, not2; + + if (notifies[0][j].notify_count != notifies[i][j].notify_count) { + if (tries++ < 10) goto again; + printf("Notify count inconsistent %d %d\n", + notifies[0][j].notify_count, + notifies[i][j].notify_count); + return False; + } + + if (notifies[0][j].notify_count == 0) continue; + + if (!NT_STATUS_EQUAL(notifies[0][j].status, + notifies[i][j].status)) { + printf("Notify status mismatch - %s - %s\n", + nt_errstr(notifies[0][j].status), + nt_errstr(notifies[i][j].status)); + return False; + } + + if (!NT_STATUS_IS_OK(notifies[0][j].status)) { + continue; + } + + not1 = notifies[0][j].notify; + not2 = notifies[i][j].notify; + + for (n=0;n<not1.out.num_changes;n++) { + if (not1.out.changes[n].action != + not2.out.changes[n].action) { + printf("Notify action %d inconsistent %d %d\n", n, + not1.out.changes[n].action, + not2.out.changes[n].action); + return False; + } + if (strcmp(not1.out.changes[n].name.s, + not2.out.changes[n].name.s)) { + printf("Notify name %d inconsistent %s %s\n", n, + not1.out.changes[n].name.s, + not2.out.changes[n].name.s); + return False; + } + if (not1.out.changes[n].name.private_length != + not2.out.changes[n].name.private_length) { + printf("Notify name length %d inconsistent %d %d\n", n, + not1.out.changes[n].name.private_length, + not2.out.changes[n].name.private_length); + return False; + } + } + } + } + + ZERO_STRUCT(notifies); + + return True; +} + + +#define GEN_COPY_PARM do { \ + int i; \ + for (i=1;i<NSERVERS;i++) { \ + parm[i] = parm[0]; \ + } \ +} while (0) + +#define GEN_CALL(call) do { \ + int i; \ + ZERO_STRUCT(oplocks); \ + ZERO_STRUCT(notifies); \ + for (i=0;i<NSERVERS;i++) { \ + struct cli_tree *tree = servers[i].cli[instance]->tree; \ + status[i] = call; \ + } \ + current_op.status = status[0]; \ + for (i=1;i<NSERVERS;i++) { \ + if (!compare_status(status[i], status[0])) { \ + printf("status different in %s - %s %s\n", #call, \ + nt_errstr(status[0]), nt_errstr(status[i])); \ + return False; \ + } \ + } \ + if (!check_oplocks(#call)) return False; \ + if (!check_notifies(#call)) return False; \ + if (!NT_STATUS_IS_OK(status[0])) { \ + return True; \ + } \ +} while(0) + +#define ADD_HANDLE(name, field) do { \ + uint16 fnums[NSERVERS]; \ + int i; \ + for (i=0;i<NSERVERS;i++) { \ + fnums[i] = parm[i].field; \ + } \ + gen_add_handle(instance, name, fnums); \ +} while(0) + +#define REMOVE_HANDLE(field) do { \ + uint16 fnums[NSERVERS]; \ + int i; \ + for (i=0;i<NSERVERS;i++) { \ + fnums[i] = parm[i].field; \ + } \ + gen_remove_handle(instance, fnums); \ +} while(0) + +#define GEN_SET_FNUM(field) do { \ + int i; \ + for (i=0;i<NSERVERS;i++) { \ + parm[i].field = gen_lookup_fnum(i, parm[i].field); \ + } \ +} while(0) + +#define CHECK_EQUAL(field) do { \ + if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \ + printf("Mismatch in %s - 0x%x 0x%x\n", #field, \ + (int)parm[0].field, (int)parm[1].field); \ + return False; \ + } \ +} while(0) + +#define CHECK_WSTR_EQUAL(field) do { \ + if (strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \ + printf("Mismatch in %s - %s %s\n", #field, \ + parm[0].field.s, parm[1].field.s); \ + return False; \ + } \ + CHECK_EQUAL(field.private_length); \ +} while(0) + +#define CHECK_BLOB_EQUAL(field) do { \ + if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \ + printf("Mismatch in %s\n", #field); \ + return False; \ + } \ + CHECK_EQUAL(field.length); \ +} while(0) + +#define CHECK_TIMES_EQUAL(field) do { \ + if (ABS(parm[0].field - parm[1].field) > time_skew() && \ + !ignore_pattern(#field)) { \ + printf("Mismatch in %s - 0x%x 0x%x\n", #field, \ + (int)parm[0].field, (int)parm[1].field); \ + return False; \ + } \ +} while(0) + +#define CHECK_NTTIMES_EQUAL(field) do { \ + if (ABS(nt_time_to_unix(&parm[0].field) - \ + nt_time_to_unix(&parm[1].field)) > time_skew() && \ + !ignore_pattern(#field)) { \ + printf("Mismatch in %s - 0x%x 0x%x\n", #field, \ + (int)nt_time_to_unix(&parm[0].field), \ + (int)nt_time_to_unix(&parm[1].field)); \ + return False; \ + } \ +} while(0) + +/* + generate openx operations +*/ +static BOOL handler_openx(int instance) +{ + union smb_open parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].openx.level = RAW_OPEN_OPENX; + parm[0].openx.in.flags = gen_openx_flags(); + parm[0].openx.in.open_mode = gen_openx_mode(); + parm[0].openx.in.search_attrs = gen_attrib(); + parm[0].openx.in.file_attrs = gen_attrib(); + parm[0].openx.in.write_time = gen_timet(); + parm[0].openx.in.open_func = gen_openx_func(); + parm[0].openx.in.size = gen_io_count(); + parm[0].openx.in.timeout = gen_timeout(); + parm[0].openx.in.fname = gen_fname_open(instance); + + if (!options.use_oplocks) { + /* mask out oplocks */ + parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK| + OPENX_FLAGS_REQUEST_BATCH_OPLOCK); + } + + GEN_COPY_PARM; + GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i])); + + CHECK_EQUAL(openx.out.attrib); + CHECK_EQUAL(openx.out.size); + CHECK_EQUAL(openx.out.access); + CHECK_EQUAL(openx.out.ftype); + CHECK_EQUAL(openx.out.devstate); + CHECK_EQUAL(openx.out.action); + CHECK_EQUAL(openx.out.access_mask); + CHECK_EQUAL(openx.out.unknown); + CHECK_TIMES_EQUAL(openx.out.write_time); + + /* open creates a new file handle */ + ADD_HANDLE(parm[0].openx.in.fname, openx.out.fnum); + + return True; +} + + +/* + generate ntcreatex operations +*/ +static BOOL handler_ntcreatex(int instance) +{ + union smb_open parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX; + parm[0].ntcreatex.in.flags = gen_ntcreatex_flags(); + parm[0].ntcreatex.in.root_fid = gen_root_fid(instance); + parm[0].ntcreatex.in.access_mask = gen_access_mask(); + parm[0].ntcreatex.in.alloc_size = gen_alloc_size(); + parm[0].ntcreatex.in.file_attr = gen_attrib(); + parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF); + parm[0].ntcreatex.in.open_disposition = gen_open_disp(); + parm[0].ntcreatex.in.create_options = gen_create_options(); + parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF); + parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF); + parm[0].ntcreatex.in.fname = gen_fname_open(instance); + + if (!options.use_oplocks) { + /* mask out oplocks */ + parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK| + NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK); + } + + GEN_COPY_PARM; + if (parm[0].ntcreatex.in.root_fid != 0) { + GEN_SET_FNUM(ntcreatex.in.root_fid); + } + GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i])); + + CHECK_EQUAL(ntcreatex.out.oplock_level); + CHECK_EQUAL(ntcreatex.out.create_action); + CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time); + CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time); + CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time); + CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time); + CHECK_EQUAL(ntcreatex.out.attrib); + CHECK_EQUAL(ntcreatex.out.alloc_size); + CHECK_EQUAL(ntcreatex.out.size); + CHECK_EQUAL(ntcreatex.out.file_type); + CHECK_EQUAL(ntcreatex.out.ipc_state); + CHECK_EQUAL(ntcreatex.out.is_directory); + + /* ntcreatex creates a new file handle */ + ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.fnum); + + return True; +} + +/* + generate close operations +*/ +static BOOL handler_close(int instance) +{ + union smb_close parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].close.level = RAW_CLOSE_CLOSE; + parm[0].close.in.fnum = gen_fnum_close(instance); + parm[0].close.in.write_time = gen_timet(); + + GEN_COPY_PARM; + GEN_SET_FNUM(close.in.fnum); + GEN_CALL(smb_raw_close(tree, &parm[i])); + + REMOVE_HANDLE(close.in.fnum); + + return True; +} + +/* + generate unlink operations +*/ +static BOOL handler_unlink(int instance) +{ + struct smb_unlink parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].in.pattern = gen_pattern(); + parm[0].in.attrib = gen_attrib(); + + GEN_COPY_PARM; + GEN_CALL(smb_raw_unlink(tree, &parm[i])); + + return True; +} + +/* + generate chkpath operations +*/ +static BOOL handler_chkpath(int instance) +{ + struct smb_chkpath parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].in.path = gen_fname_open(instance); + + GEN_COPY_PARM; + GEN_CALL(smb_raw_chkpath(tree, &parm[i])); + + return True; +} + +/* + generate mkdir operations +*/ +static BOOL handler_mkdir(int instance) +{ + union smb_mkdir parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].mkdir.level = RAW_MKDIR_MKDIR; + parm[0].mkdir.in.path = gen_fname_open(instance); + + GEN_COPY_PARM; + GEN_CALL(smb_raw_mkdir(tree, &parm[i])); + + return True; +} + +/* + generate rmdir operations +*/ +static BOOL handler_rmdir(int instance) +{ + struct smb_rmdir parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].in.path = gen_fname_open(instance); + + GEN_COPY_PARM; + GEN_CALL(smb_raw_rmdir(tree, &parm[i])); + + return True; +} + +/* + generate rename operations +*/ +static BOOL handler_rename(int instance) +{ + struct smb_rename parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].in.pattern1 = gen_pattern(); + parm[0].in.pattern2 = gen_pattern(); + parm[0].in.attrib = gen_attrib(); + + GEN_COPY_PARM; + GEN_CALL(smb_raw_rename(tree, &parm[i])); + + return True; +} + + +/* + generate readx operations +*/ +static BOOL handler_readx(int instance) +{ + union smb_read parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].readx.level = RAW_READ_READX; + parm[0].readx.in.fnum = gen_fnum(instance); + parm[0].readx.in.offset = gen_offset(); + parm[0].readx.in.mincnt = gen_io_count(); + parm[0].readx.in.maxcnt = gen_io_count(); + parm[0].readx.in.remaining = gen_io_count(); + parm[0].readx.out.data = talloc(current_op.mem_ctx, + MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt)); + + GEN_COPY_PARM; + GEN_SET_FNUM(readx.in.fnum); + GEN_CALL(smb_raw_read(tree, &parm[i])); + + CHECK_EQUAL(readx.out.remaining); + CHECK_EQUAL(readx.out.compaction_mode); + CHECK_EQUAL(readx.out.nread); + + return True; +} + +/* + generate writex operations +*/ +static BOOL handler_writex(int instance) +{ + union smb_write parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].writex.level = RAW_WRITE_WRITEX; + parm[0].writex.in.fnum = gen_fnum(instance); + parm[0].writex.in.offset = gen_offset(); + parm[0].writex.in.wmode = gen_bits_mask(0xFFFF); + parm[0].writex.in.remaining = gen_io_count(); + parm[0].writex.in.count = gen_io_count(); + parm[0].writex.in.data = talloc_zero(current_op.mem_ctx, parm[0].writex.in.count); + + GEN_COPY_PARM; + GEN_SET_FNUM(writex.in.fnum); + GEN_CALL(smb_raw_write(tree, &parm[i])); + + CHECK_EQUAL(writex.out.nwritten); + CHECK_EQUAL(writex.out.remaining); + + return True; +} + +/* + generate lockingx operations +*/ +static BOOL handler_lockingx(int instance) +{ + union smb_lock parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + int n, nlocks; + + parm[0].lockx.level = RAW_LOCK_LOCKX; + parm[0].lockx.in.fnum = gen_fnum(instance); + parm[0].lockx.in.mode = gen_lock_mode(); + parm[0].lockx.in.timeout = gen_timeout(); + do { + /* make sure we don't accidentially generate an oplock + break ack - otherwise the server can just block forever */ + parm[0].lockx.in.ulock_cnt = gen_lock_count(); + parm[0].lockx.in.lock_cnt = gen_lock_count(); + nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt; + } while (nlocks == 0); + + if (nlocks > 0) { + parm[0].lockx.in.locks = talloc(current_op.mem_ctx, + sizeof(parm[0].lockx.in.locks[0]) * nlocks); + for (n=0;n<nlocks;n++) { + parm[0].lockx.in.locks[n].pid = gen_pid(); + parm[0].lockx.in.locks[n].offset = gen_offset(); + parm[0].lockx.in.locks[n].count = gen_io_count(); + } + } + + GEN_COPY_PARM; + GEN_SET_FNUM(lockx.in.fnum); + GEN_CALL(smb_raw_lock(tree, &parm[i])); + + return True; +} + +/* + generate a fileinfo query structure +*/ +static void gen_fileinfo(int instance, union smb_fileinfo *info) +{ + int i; + #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v} + struct { + enum fileinfo_level level; + const char *name; + } levels[] = { + LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD), + LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID), + LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO), + LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO), + LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION), + LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION), + LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION), + LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION), + LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION), + LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION) + }; + do { + i = gen_int_range(0, ARRAY_SIZE(levels)-1); + } while (ignore_pattern(levels[i].name)); + + info->generic.level = levels[i].level; +} + +/* + compare returned fileinfo structures +*/ +static BOOL cmp_fileinfo(int instance, + union smb_fileinfo parm[NSERVERS], + NTSTATUS status[NSERVERS]) +{ + int i; + + switch (parm[0].generic.level) { + case RAW_FILEINFO_GENERIC: + return False; + + case RAW_FILEINFO_GETATTR: + CHECK_EQUAL(getattr.out.attrib); + CHECK_EQUAL(getattr.out.size); + CHECK_TIMES_EQUAL(getattr.out.write_time); + break; + + case RAW_FILEINFO_GETATTRE: + CHECK_TIMES_EQUAL(getattre.out.create_time); + CHECK_TIMES_EQUAL(getattre.out.access_time); + CHECK_TIMES_EQUAL(getattre.out.write_time); + CHECK_EQUAL(getattre.out.size); + CHECK_EQUAL(getattre.out.alloc_size); + CHECK_EQUAL(getattre.out.attrib); + break; + + case RAW_FILEINFO_STANDARD: + CHECK_TIMES_EQUAL(standard.out.create_time); + CHECK_TIMES_EQUAL(standard.out.access_time); + CHECK_TIMES_EQUAL(standard.out.write_time); + CHECK_EQUAL(standard.out.size); + CHECK_EQUAL(standard.out.alloc_size); + CHECK_EQUAL(standard.out.attrib); + break; + + case RAW_FILEINFO_EA_SIZE: + CHECK_TIMES_EQUAL(ea_size.out.create_time); + CHECK_TIMES_EQUAL(ea_size.out.access_time); + CHECK_TIMES_EQUAL(ea_size.out.write_time); + CHECK_EQUAL(ea_size.out.size); + CHECK_EQUAL(ea_size.out.alloc_size); + CHECK_EQUAL(ea_size.out.attrib); + CHECK_EQUAL(ea_size.out.ea_size); + break; + + case RAW_FILEINFO_ALL_EAS: + CHECK_EQUAL(all_eas.out.num_eas); + for (i=0;i<parm[0].all_eas.out.num_eas;i++) { + CHECK_EQUAL(all_eas.out.eas[i].flags); + CHECK_WSTR_EQUAL(all_eas.out.eas[i].name); + CHECK_BLOB_EQUAL(all_eas.out.eas[i].value); + } + break; + + case RAW_FILEINFO_IS_NAME_VALID: + break; + + case RAW_FILEINFO_BASIC_INFO: + case RAW_FILEINFO_BASIC_INFORMATION: + CHECK_NTTIMES_EQUAL(basic_info.out.create_time); + CHECK_NTTIMES_EQUAL(basic_info.out.access_time); + CHECK_NTTIMES_EQUAL(basic_info.out.write_time); + CHECK_NTTIMES_EQUAL(basic_info.out.change_time); + CHECK_EQUAL(basic_info.out.attrib); + break; + + case RAW_FILEINFO_STANDARD_INFO: + case RAW_FILEINFO_STANDARD_INFORMATION: + CHECK_EQUAL(standard_info.out.alloc_size); + CHECK_EQUAL(standard_info.out.size); + CHECK_EQUAL(standard_info.out.nlink); + CHECK_EQUAL(standard_info.out.delete_pending); + CHECK_EQUAL(standard_info.out.directory); + break; + + case RAW_FILEINFO_EA_INFO: + case RAW_FILEINFO_EA_INFORMATION: + CHECK_EQUAL(ea_info.out.ea_size); + break; + + case RAW_FILEINFO_NAME_INFO: + case RAW_FILEINFO_NAME_INFORMATION: + CHECK_WSTR_EQUAL(name_info.out.fname); + break; + + case RAW_FILEINFO_ALL_INFO: + case RAW_FILEINFO_ALL_INFORMATION: + CHECK_NTTIMES_EQUAL(all_info.out.create_time); + CHECK_NTTIMES_EQUAL(all_info.out.access_time); + CHECK_NTTIMES_EQUAL(all_info.out.write_time); + CHECK_NTTIMES_EQUAL(all_info.out.change_time); + CHECK_EQUAL(all_info.out.attrib); + CHECK_EQUAL(all_info.out.alloc_size); + CHECK_EQUAL(all_info.out.size); + CHECK_EQUAL(all_info.out.nlink); + CHECK_EQUAL(all_info.out.delete_pending); + CHECK_EQUAL(all_info.out.directory); + CHECK_EQUAL(all_info.out.ea_size); + CHECK_WSTR_EQUAL(all_info.out.fname); + break; + + case RAW_FILEINFO_ALT_NAME_INFO: + case RAW_FILEINFO_ALT_NAME_INFORMATION: + CHECK_WSTR_EQUAL(alt_name_info.out.fname); + break; + + case RAW_FILEINFO_STREAM_INFO: + case RAW_FILEINFO_STREAM_INFORMATION: + CHECK_EQUAL(stream_info.out.num_streams); + for (i=0;i<parm[0].stream_info.out.num_streams;i++) { + CHECK_EQUAL(stream_info.out.streams[i].size); + CHECK_EQUAL(stream_info.out.streams[i].alloc_size); + CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name); + } + break; + + case RAW_FILEINFO_COMPRESSION_INFO: + case RAW_FILEINFO_COMPRESSION_INFORMATION: + CHECK_EQUAL(compression_info.out.compressed_size); + CHECK_EQUAL(compression_info.out.format); + CHECK_EQUAL(compression_info.out.unit_shift); + CHECK_EQUAL(compression_info.out.chunk_shift); + CHECK_EQUAL(compression_info.out.cluster_shift); + break; + + case RAW_FILEINFO_INTERNAL_INFORMATION: + CHECK_EQUAL(internal_information.out.device); + CHECK_EQUAL(internal_information.out.inode); + break; + + case RAW_FILEINFO_ACCESS_INFORMATION: + CHECK_EQUAL(access_information.out.access_flags); + break; + + case RAW_FILEINFO_POSITION_INFORMATION: + CHECK_EQUAL(position_information.out.position); + break; + + case RAW_FILEINFO_MODE_INFORMATION: + CHECK_EQUAL(mode_information.out.mode); + break; + + case RAW_FILEINFO_ALIGNMENT_INFORMATION: + CHECK_EQUAL(alignment_information.out.alignment_requirement); + break; + + case RAW_FILEINFO_NETWORK_OPEN_INFORMATION: + CHECK_NTTIMES_EQUAL(network_open_information.out.create_time); + CHECK_NTTIMES_EQUAL(network_open_information.out.access_time); + CHECK_NTTIMES_EQUAL(network_open_information.out.write_time); + CHECK_NTTIMES_EQUAL(network_open_information.out.change_time); + CHECK_EQUAL(network_open_information.out.alloc_size); + CHECK_EQUAL(network_open_information.out.size); + CHECK_EQUAL(network_open_information.out.attrib); + break; + + case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION: + CHECK_EQUAL(attribute_tag_information.out.attrib); + CHECK_EQUAL(attribute_tag_information.out.reparse_tag); + break; + } + + return True; +} + +/* + generate qpathinfo operations +*/ +static BOOL handler_qpathinfo(int instance) +{ + union smb_fileinfo parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].generic.in.fname = gen_fname_open(instance); + + gen_fileinfo(instance, &parm[0]); + + GEN_COPY_PARM; + GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i])); + + return cmp_fileinfo(instance, parm, status); +} + +/* + generate qfileinfo operations +*/ +static BOOL handler_qfileinfo(int instance) +{ + union smb_fileinfo parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].generic.in.fnum = gen_fnum(instance); + + gen_fileinfo(instance, &parm[0]); + + GEN_COPY_PARM; + GEN_SET_FNUM(generic.in.fnum); + GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i])); + + return cmp_fileinfo(instance, parm, status); +} + + +/* + generate a fileinfo query structure +*/ +static void gen_setfileinfo(int instance, union smb_setfileinfo *info) +{ + int i; + #undef LVL + #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v} + struct { + enum setfileinfo_level level; + const char *name; + } levels[] = { +#if 0 + /* disabled until win2003 can handle them ... */ + LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO), + LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO), +#endif + LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION), + LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION), + LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION), + LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION), + LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040) + }; + do { + i = gen_int_range(0, ARRAY_SIZE(levels)-1); + } while (ignore_pattern(levels[i].name)); + + info->generic.level = levels[i].level; + + switch (info->generic.level) { + case RAW_SFILEINFO_SETATTR: + info->setattr.in.attrib = gen_attrib(); + info->setattr.in.write_time = gen_timet(); + break; + case RAW_SFILEINFO_SETATTRE: + info->setattre.in.create_time = gen_timet(); + info->setattre.in.access_time = gen_timet(); + info->setattre.in.write_time = gen_timet(); + break; + case RAW_SFILEINFO_STANDARD: + info->standard.in.create_time = gen_timet(); + info->standard.in.access_time = gen_timet(); + info->standard.in.write_time = gen_timet(); + break; + case RAW_SFILEINFO_EA_SET: + info->ea_set.in.ea = gen_ea_struct(); + break; + case RAW_SFILEINFO_BASIC_INFO: + case RAW_SFILEINFO_BASIC_INFORMATION: + info->basic_info.in.create_time = gen_nttime(); + info->basic_info.in.access_time = gen_nttime(); + info->basic_info.in.write_time = gen_nttime(); + info->basic_info.in.change_time = gen_nttime(); + info->basic_info.in.attrib = gen_attrib(); + break; + case RAW_SFILEINFO_DISPOSITION_INFO: + case RAW_SFILEINFO_DISPOSITION_INFORMATION: + info->disposition_info.in.delete_on_close = gen_bool(); + break; + case RAW_SFILEINFO_ALLOCATION_INFO: + case RAW_SFILEINFO_ALLOCATION_INFORMATION: + info->allocation_info.in.alloc_size = gen_alloc_size(); + break; + case RAW_SFILEINFO_END_OF_FILE_INFO: + case RAW_SFILEINFO_END_OF_FILE_INFORMATION: + info->end_of_file_info.in.size = gen_offset(); + break; + case RAW_SFILEINFO_RENAME_INFORMATION: + info->rename_information.in.overwrite = gen_bool(); + info->rename_information.in.root_fid = gen_root_fid(instance); + info->rename_information.in.new_name = gen_fname_open(instance); + break; + case RAW_SFILEINFO_POSITION_INFORMATION: + info->position_information.in.position = gen_offset(); + break; + case RAW_SFILEINFO_MODE_INFORMATION: + info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF); + break; + } +} + +/* + generate setpathinfo operations +*/ +static BOOL handler_spathinfo(int instance) +{ + union smb_setfileinfo parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].generic.file.fname = gen_fname_open(instance); + + gen_setfileinfo(instance, &parm[0]); + + GEN_COPY_PARM; + + /* a special case for the fid in a RENAME */ + if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION && + parm[0].rename_information.in.root_fid != 0) { + GEN_SET_FNUM(rename_information.in.root_fid); + } + + GEN_CALL(smb_raw_setpathinfo(tree, &parm[i])); + + return True; +} + + +/* + generate setfileinfo operations +*/ +static BOOL handler_sfileinfo(int instance) +{ + union smb_setfileinfo parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].generic.file.fnum = gen_fnum(instance); + + gen_setfileinfo(instance, &parm[0]); + + GEN_COPY_PARM; + GEN_SET_FNUM(generic.file.fnum); + GEN_CALL(smb_raw_setfileinfo(tree, &parm[i])); + + return True; +} + + +/* + generate change notify operations +*/ +static BOOL handler_notify(int instance) +{ + struct smb_notify parm[NSERVERS]; + int n; + + parm[0].in.buffer_size = gen_io_count(); + parm[0].in.completion_filter = gen_bits_mask(0xFF); + parm[0].in.fnum = gen_fnum(instance); + parm[0].in.recursive = gen_bool(); + + GEN_COPY_PARM; + GEN_SET_FNUM(in.fnum); + + for (n=0;n<NSERVERS;n++) { + struct cli_request *req; + req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]); + req->async.fn = async_notify; + } + + return True; +} + +/* + wipe any relevant files +*/ +static void wipe_files(void) +{ + int i; + for (i=0;i<NSERVERS;i++) { + int n = cli_deltree(servers[i].cli[0], "\\gentest"); + if (n == -1) { + printf("Failed to wipe tree on server %d\n", i); + exit(1); + } + if (!cli_mkdir(servers[i].cli[0], "\\gentest")) { + printf("Failed to create \\gentest - %s\n", + cli_errstr(servers[i].cli[0])); + exit(1); + } + if (n > 0) { + printf("Deleted %d files on server %d\n", n, i); + } + } +} + +/* + dump the current seeds - useful for continuing a backtrack +*/ +static void dump_seeds(void) +{ + int i; + FILE *f; + + if (!options.seeds_file) { + return; + } + f = fopen("seeds.tmp", "w"); + if (!f) return; + + for (i=0;i<options.numops;i++) { + fprintf(f, "%u\n", op_parms[i].seed); + } + fclose(f); + rename("seeds.tmp", options.seeds_file); +} + + + +/* + the list of top-level operations that we will generate +*/ +static struct { + const char *name; + BOOL (*handler)(int instance); + int count, success_count; +} gen_ops[] = { + {"OPENX", handler_openx}, + {"NTCREATEX", handler_ntcreatex}, + {"CLOSE", handler_close}, + {"UNLINK", handler_unlink}, + {"MKDIR", handler_mkdir}, + {"RMDIR", handler_rmdir}, + {"RENAME", handler_rename}, + {"READX", handler_readx}, + {"WRITEX", handler_writex}, + {"CHKPATH", handler_chkpath}, + {"LOCKINGX", handler_lockingx}, + {"QPATHINFO", handler_qpathinfo}, + {"QFILEINFO", handler_qfileinfo}, + {"SPATHINFO", handler_spathinfo}, + {"SFILEINFO", handler_sfileinfo}, + {"NOTIFY", handler_notify}, +}; + + +/* + run the test with the current set of op_parms parameters + return the number of operations that completed successfully +*/ +static int run_test(void) +{ + int op, i; + + if (!connect_servers()) { + printf("Failed to connect to servers\n"); + exit(1); + } + + dump_seeds(); + + /* wipe any leftover files from old runs */ + wipe_files(); + + /* reset the open handles array */ + memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0])); + num_open_handles = 0; + + for (i=0;i<ARRAY_SIZE(gen_ops);i++) { + gen_ops[i].count = 0; + gen_ops[i].success_count = 0; + } + + for (op=0; op<options.numops; op++) { + int instance, which_op; + BOOL ret; + + if (op_parms[op].disabled) continue; + + srandom(op_parms[op].seed); + + instance = gen_int_range(0, NINSTANCES-1); + + /* generate a non-ignored operation */ + do { + which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1); + } while (ignore_pattern(gen_ops[which_op].name)); + + DEBUG(3,("Generating op %s on instance %d\n", + gen_ops[which_op].name, instance)); + + current_op.seed = op_parms[op].seed; + current_op.opnum = op; + current_op.name = gen_ops[which_op].name; + current_op.status = NT_STATUS_OK; + current_op.mem_ctx = talloc_init(current_op.name); + + ret = gen_ops[which_op].handler(instance); + + talloc_destroy(current_op.mem_ctx); + + gen_ops[which_op].count++; + if (NT_STATUS_IS_OK(current_op.status)) { + gen_ops[which_op].success_count++; + } + + if (!ret) { + printf("Failed at operation %d - %s\n", + op, gen_ops[which_op].name); + return op; + } + + if (op % 100 == 0) { + printf("%d\n", op); + } + } + + for (i=0;i<ARRAY_SIZE(gen_ops);i++) { + printf("Op %-10s got %d/%d success\n", + gen_ops[i].name, + gen_ops[i].success_count, + gen_ops[i].count); + } + + return op; +} + +/* + perform a backtracking analysis of the minimal set of operations + to generate an error +*/ +static void backtrack_analyze(void) +{ + int chunk, ret; + + chunk = options.numops / 2; + + do { + int base; + for (base=0; + chunk > 0 && base+chunk < options.numops && options.numops > 1; ) { + int i, max; + + chunk = MIN(chunk, options.numops / 2); + + /* mark this range as disabled */ + max = MIN(options.numops, base+chunk); + for (i=base;i<max; i++) { + op_parms[i].disabled = True; + } + printf("Testing %d ops with %d-%d disabled\n", + options.numops, base, max-1); + ret = run_test(); + printf("Completed %d of %d ops\n", ret, options.numops); + for (i=base;i<max; i++) { + op_parms[i].disabled = False; + } + if (ret == options.numops) { + /* this chunk is needed */ + base += chunk; + } else if (ret < base) { + printf("damn - inconsistent errors! found early error\n"); + options.numops = ret+1; + base = 0; + } else { + /* it failed - this chunk isn't needed for a failure */ + memmove(&op_parms[base], &op_parms[max], + sizeof(op_parms[0]) * (options.numops - max)); + options.numops = (ret+1) - (max - base); + } + } + + if (chunk == 2) { + chunk = 1; + } else { + chunk *= 0.4; + } + + if (options.analyze_continuous && chunk == 0 && options.numops != 1) { + chunk = 1; + } + } while (chunk > 0); + + printf("Reduced to %d ops\n", options.numops); + ret = run_test(); + if (ret != options.numops - 1) { + printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops); + } +} + +/* + start the main gentest process +*/ +static BOOL start_gentest(void) +{ + int op; + int ret; + + /* allocate the open_handles array */ + open_handles = calloc(options.max_open_handles, sizeof(open_handles[0])); + + srandom(options.seed); + op_parms = calloc(options.numops, sizeof(op_parms[0])); + + /* generate the seeds - after this everything is deterministic */ + if (options.use_preset_seeds) { + int numops; + char **preset = file_lines_load(options.seeds_file, &numops); + if (!preset) { + printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno)); + exit(1); + } + if (numops < options.numops) { + options.numops = numops; + } + for (op=0;op<options.numops;op++) { + if (!preset[op]) { + printf("Not enough seeds in %s\n", options.seeds_file); + exit(1); + } + op_parms[op].seed = atoi(preset[op]); + } + printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file); + } else { + for (op=0; op<options.numops; op++) { + op_parms[op].seed = random(); + } + } + + ret = run_test(); + + if (ret != options.numops && options.analyze) { + options.numops = ret+1; + backtrack_analyze(); + } else if (options.analyze_always) { + backtrack_analyze(); + } else if (options.analyze_continuous) { + while (run_test() == options.numops) ; + } + + return ret == options.numops; +} + + +static void usage(void) +{ + printf( +"Usage:\n\ + gentest2 //server1/share1 //server2/share2 [options..]\n\ + options:\n\ + -U user%%pass (must be specified twice)\n\ + -s seed\n\ + -o numops\n\ + -a (show all ops)\n\ + -A backtrack to find minimal ops\n\ + -i FILE add a list of wildcard exclusions\n\ + -O enable oplocks\n\ + -S FILE set preset seeds file\n\ + -L use preset seeds\n\ + -F fast reconnect (just close files)\n\ + -C continuous analysis mode\n\ + -X analyse even when test OK\n\ +"); +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc, char *argv[]) +{ + int opt; + int i; + BOOL ret; + + setlinebuf(stdout); + + setup_logging("gentest", DEBUG_STDOUT); + + if (argc < 3 || argv[1][0] == '-') { + usage(); + exit(1); + } + + setup_logging(argv[0],True); + + for (i=0;i<NSERVERS;i++) { + const char *share = argv[1+i]; + if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) { + printf("Invalid share name '%s'\n", share); + return -1; + } + } + + argc -= NSERVERS; + argv += NSERVERS; + + lp_load(dyn_CONFIGFILE,True,False,False); + load_interfaces(); + + options.seed = time(NULL); + options.numops = 1000; + options.max_open_handles = 20; + options.seeds_file = "gentest_seeds.dat"; + + while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) { + switch (opt) { + case 'U': + i = servers[0].username?1:0; + if (!split_username(optarg, + &servers[i].username, + &servers[i].password)) { + printf("Must supply USER%%PASS\n"); + return -1; + } + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + setup_logging(NULL,True); + break; + case 's': + options.seed = atoi(optarg); + break; + case 'S': + options.seeds_file = optarg; + break; + case 'L': + options.use_preset_seeds = True; + break; + case 'F': + options.fast_reconnect = True; + break; + case 'o': + options.numops = atoi(optarg); + break; + case 'O': + options.use_oplocks = True; + break; + case 'a': + options.showall = True; + break; + case 'A': + options.analyze = True; + break; + case 'X': + options.analyze_always = True; + break; + case 'C': + options.analyze_continuous = True; + break; + case 'i': + options.ignore_patterns = file_lines_load(optarg, NULL); + break; + case 'h': + usage(); + exit(1); + default: + printf("Unknown option %c (%d)\n", (char)opt, opt); + exit(1); + } + } + + if (!servers[0].username || !servers[1].username) { + usage(); + return -1; + } + + printf("seed=%u\n", options.seed); + + ret = start_gentest(); + + if (ret) { + printf("gentest completed - no errors\n"); + } else { + printf("gentest failed\n"); + } + + return ret?0:-1; +} diff --git a/source4/torture/locktest.c b/source4/torture/locktest.c new file mode 100644 index 0000000000..26bf6d62dd --- /dev/null +++ b/source4/torture/locktest.c @@ -0,0 +1,566 @@ +/* + Unix SMB/CIFS implementation. + randomised byte range lock tester + Copyright (C) Andrew Tridgell 1999 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static fstring password[2]; +static fstring username[2]; +static int got_user; +static int got_pass; +static BOOL use_kerberos; +static int numops = 1000; +static BOOL showall; +static BOOL analyze; +static BOOL hide_unlock_fails; +static BOOL use_oplocks; +static unsigned lock_range = 100; +static unsigned lock_base = 0; +static unsigned min_length = 0; +static BOOL exact_error_codes; +static BOOL zero_zero; + +#define FILENAME "\\locktest.dat" + +#define READ_PCT 50 +#define LOCK_PCT 45 +#define UNLOCK_PCT 70 +#define RANGE_MULTIPLE 1 +#define NSERVERS 2 +#define NCONNECTIONS 2 +#define NFILES 2 +#define LOCK_TIMEOUT 0 + +#define NASTY_POSIX_LOCK_HACK 0 + +enum lock_op {OP_LOCK, OP_UNLOCK, OP_REOPEN}; + +struct record { + enum lock_op lock_op; + enum brl_type lock_type; + char conn, f; + SMB_BIG_UINT start, len; + char needed; +}; + +#define PRESETS 0 + +#if PRESETS +static struct record preset[] = { +{OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 3, 0, 1}, +{OP_UNLOCK, 0 , 0, 0, 2, 0, 1}, +{OP_REOPEN, 0, 0, 0, 0, 0, 1}, + +{OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1}, +{OP_LOCK, READ_LOCK, 0, 0, 1, 1, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1}, +{OP_REOPEN, 0, 0, 0, 0, 0, 1}, + +{OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 3, 1, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1}, +{OP_REOPEN, 0, 0, 0, 0, 0, 1}, + +{OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 1, 1, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1}, +{OP_REOPEN, 0, 0, 0, 0, 0, 1}, + +{OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1}, +{OP_LOCK, READ_LOCK, 0, 0, 1, 1, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1}, +{OP_REOPEN, 0, 0, 0, 0, 0, 1}, + +{OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1}, +{OP_LOCK, READ_LOCK, 0, 0, 3, 1, 1}, +{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1}, +{OP_REOPEN, 0, 0, 0, 0, 0, 1}, + +}; +#endif + +static struct record *recorded; + +/***************************************************** +return a connection to a server +*******************************************************/ +static struct cli_state *connect_one(char *share, int snum) +{ + struct cli_state *c; + fstring server, myname; + uint_t flags = 0; + NTSTATUS status; + + fstrcpy(server,share+2); + share = strchr_m(server,'\\'); + if (!share) return NULL; + *share = 0; + share++; + + slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), snum); + + if (use_kerberos) + flags |= CLI_FULL_CONNECTION_USE_KERBEROS; + + status = cli_full_connection(&c, myname, + server, NULL, + share, "?????", + username[snum], lp_workgroup(), + password[snum], flags, NULL); + + if (!NT_STATUS_IS_OK(status)) { + return NULL; + } + + return c; +} + + +static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES], + char *share[NSERVERS]) +{ + int server, conn, f; + + for (server=0;server<NSERVERS;server++) + for (conn=0;conn<NCONNECTIONS;conn++) { + if (cli[server][conn]) { + for (f=0;f<NFILES;f++) { + if (fnum[server][conn][f] != -1) { + cli_close(cli[server][conn], fnum[server][conn][f]); + fnum[server][conn][f] = -1; + } + } + cli_shutdown(cli[server][conn]); + } + cli[server][conn] = connect_one(share[server], server); + if (!cli[server][conn]) { + DEBUG(0,("Failed to connect to %s\n", share[server])); + exit(1); + } + } +} + + + +static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], + int fnum[NSERVERS][NCONNECTIONS][NFILES], + struct record *rec) +{ + unsigned conn = rec->conn; + unsigned f = rec->f; + SMB_BIG_UINT start = rec->start; + SMB_BIG_UINT len = rec->len; + enum brl_type op = rec->lock_type; + int server; + BOOL ret[NSERVERS]; + NTSTATUS status[NSERVERS]; + + switch (rec->lock_op) { + case OP_LOCK: + /* set a lock */ + for (server=0;server<NSERVERS;server++) { + ret[server] = cli_lock64(cli[server][conn], + fnum[server][conn][f], + start, len, LOCK_TIMEOUT, op); + status[server] = cli_nt_error(cli[server][conn]); + if (!exact_error_codes && + NT_STATUS_EQUAL(status[server], + NT_STATUS_FILE_LOCK_CONFLICT)) { + status[server] = NT_STATUS_LOCK_NOT_GRANTED; + } + } + if (showall || !NT_STATUS_EQUAL(status[0],status[1])) { + printf("lock conn=%u f=%u range=%.0f(%.0f) op=%s -> %s:%s\n", + conn, f, + (double)start, (double)len, + op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", + nt_errstr(status[0]), nt_errstr(status[1])); + } + if (!NT_STATUS_EQUAL(status[0],status[1])) return False; + break; + + case OP_UNLOCK: + /* unset a lock */ + for (server=0;server<NSERVERS;server++) { + ret[server] = cli_unlock64(cli[server][conn], + fnum[server][conn][f], + start, len); + status[server] = cli_nt_error(cli[server][conn]); + } + if (showall || + (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1]))) { + printf("unlock conn=%u f=%u range=%.0f(%.0f) -> %s:%s\n", + conn, f, + (double)start, (double)len, + nt_errstr(status[0]), nt_errstr(status[1])); + } + if (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1])) + return False; + break; + + case OP_REOPEN: + /* reopen the file */ + for (server=0;server<NSERVERS;server++) { + cli_close(cli[server][conn], fnum[server][conn][f]); + fnum[server][conn][f] = -1; + } + for (server=0;server<NSERVERS;server++) { + fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME, + O_RDWR|O_CREAT, + DENY_NONE); + if (fnum[server][conn][f] == -1) { + printf("failed to reopen on share%d\n", server); + return False; + } + } + if (showall) { + printf("reopen conn=%u f=%u\n", + conn, f); + } + break; + } + + return True; +} + +static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], + int fnum[NSERVERS][NCONNECTIONS][NFILES]) +{ + int server, conn, f; + + for (server=0;server<NSERVERS;server++) + for (conn=0;conn<NCONNECTIONS;conn++) + for (f=0;f<NFILES;f++) { + if (fnum[server][conn][f] != -1) { + cli_close(cli[server][conn], fnum[server][conn][f]); + fnum[server][conn][f] = -1; + } + } + for (server=0;server<NSERVERS;server++) { + cli_unlink(cli[server][0], FILENAME); + } +} + +static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], + int fnum[NSERVERS][NCONNECTIONS][NFILES]) +{ + int server, conn, f; + + for (server=0;server<NSERVERS;server++) + for (conn=0;conn<NCONNECTIONS;conn++) + for (f=0;f<NFILES;f++) { + fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME, + O_RDWR|O_CREAT, + DENY_NONE); + if (fnum[server][conn][f] == -1) { + fprintf(stderr,"Failed to open fnum[%u][%u][%u]\n", + server, conn, f); + exit(1); + } + } +} + + +static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS], + int fnum[NSERVERS][NCONNECTIONS][NFILES], + int n) +{ + int i; + printf("testing %u ...\n", n); + for (i=0; i<n; i++) { + if (i && i % 100 == 0) { + printf("%u\n", i); + } + + if (recorded[i].needed && + !test_one(cli, fnum, &recorded[i])) return i; + } + return n; +} + + +/* each server has two connections open to it. Each connection has two file + descriptors open on the file - 8 file descriptors in total + + we then do random locking ops in tamdem on the 4 fnums from each + server and ensure that the results match + */ +static void test_locks(char *share[NSERVERS]) +{ + struct cli_state *cli[NSERVERS][NCONNECTIONS]; + int fnum[NSERVERS][NCONNECTIONS][NFILES]; + int n, i, n1, skip, r1, r2; + + ZERO_STRUCT(fnum); + ZERO_STRUCT(cli); + + recorded = (struct record *)malloc(sizeof(*recorded) * numops); + + for (n=0; n<numops; n++) { +#if PRESETS + if (n < sizeof(preset) / sizeof(preset[0])) { + recorded[n] = preset[n]; + } else { +#endif + recorded[n].conn = random() % NCONNECTIONS; + recorded[n].f = random() % NFILES; + recorded[n].start = lock_base + ((unsigned)random() % (lock_range-1)); + recorded[n].len = min_length + + random() % (lock_range-(recorded[n].start-lock_base)); + recorded[n].start *= RANGE_MULTIPLE; + recorded[n].len *= RANGE_MULTIPLE; + r1 = random() % 100; + r2 = random() % 100; + if (r1 < READ_PCT) { + recorded[n].lock_type = READ_LOCK; + } else { + recorded[n].lock_type = WRITE_LOCK; + } + if (r2 < LOCK_PCT) { + recorded[n].lock_op = OP_LOCK; + } else if (r2 < UNLOCK_PCT) { + recorded[n].lock_op = OP_UNLOCK; + } else { + recorded[n].lock_op = OP_REOPEN; + } + recorded[n].needed = True; + if (!zero_zero && recorded[n].start==0 && recorded[n].len==0) { + recorded[n].len = 1; + } +#if PRESETS + } +#endif + } + + reconnect(cli, fnum, share); + open_files(cli, fnum); + n = retest(cli, fnum, numops); + + if (n == numops || !analyze) return; + n++; + + skip = n/2; + + while (1) { + n1 = n; + + close_files(cli, fnum); + reconnect(cli, fnum, share); + open_files(cli, fnum); + + for (i=0;i<n-skip;i+=skip) { + int m, j; + printf("excluding %d-%d\n", i, i+skip-1); + for (j=i;j<i+skip;j++) { + recorded[j].needed = False; + } + + close_files(cli, fnum); + open_files(cli, fnum); + + m = retest(cli, fnum, n); + if (m == n) { + for (j=i;j<i+skip;j++) { + recorded[j].needed = True; + } + } else { + if (i+(skip-1) < m) { + memmove(&recorded[i], &recorded[i+skip], + (m-(i+skip-1))*sizeof(recorded[0])); + } + n = m-(skip-1); + i--; + } + } + + if (skip > 1) { + skip = skip/2; + printf("skip=%d\n", skip); + continue; + } + + if (n1 == n) break; + } + + close_files(cli, fnum); + reconnect(cli, fnum, share); + open_files(cli, fnum); + showall = True; + n1 = retest(cli, fnum, n); + if (n1 != n-1) { + printf("ERROR - inconsistent result (%u %u)\n", n1, n); + } + close_files(cli, fnum); + + for (i=0;i<n;i++) { + printf("{%d, %d, %u, %u, %.0f, %.0f, %u},\n", + recorded[i].lock_op, + recorded[i].lock_type, + recorded[i].conn, + recorded[i].f, + (double)recorded[i].start, + (double)recorded[i].len, + recorded[i].needed); + } +} + + + +static void usage(void) +{ + printf( +"Usage:\n\ + locktest //server1/share1 //server2/share2 [options..]\n\ + options:\n\ + -U user%%pass (may be specified twice)\n\ + -k use kerberos\n\ + -s seed\n\ + -o numops\n\ + -u hide unlock fails\n\ + -a (show all ops)\n\ + -A analyse for minimal ops\n\ + -O use oplocks\n\ + -E enable exact error code checking\n\ + -Z enable the zero/zero lock\n\ + -R range set lock range\n\ + -B base set lock base\n\ + -M min set min lock length\n\ +"); +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + char *share[NSERVERS]; + int opt; + char *p; + int seed, server; + + setlinebuf(stdout); + + setup_logging("locktest", DEBUG_STDOUT); + + if (argc < 3 || argv[1][0] == '-') { + usage(); + exit(1); + } + + setup_logging(argv[0],True); + + for (server=0;server<NSERVERS;server++) { + share[server] = argv[1+server]; + all_string_sub(share[server],"/","\\",0); + } + + argc -= NSERVERS; + argv += NSERVERS; + + lp_load(dyn_CONFIGFILE,True,False,False); + load_interfaces(); + + if (getenv("USER")) { + fstrcpy(username[0],getenv("USER")); + fstrcpy(username[1],getenv("USER")); + } + + seed = time(NULL); + + while ((opt = getopt(argc, argv, "U:s:ho:aAW:OkR:B:M:EZ")) != EOF) { + switch (opt) { + case 'k': +#ifdef HAVE_KRB5 + use_kerberos = True; +#else + d_printf("No kerberos support compiled in\n"); + exit(1); +#endif + break; + case 'U': + got_user = 1; + if (got_pass == 2) { + d_printf("Max of 2 usernames\n"); + exit(1); + } + fstrcpy(username[got_pass],optarg); + p = strchr_m(username[got_pass],'%'); + if (p) { + *p = 0; + fstrcpy(password[got_pass], p+1); + got_pass++; + } + break; + case 'R': + lock_range = strtol(optarg, NULL, 0); + break; + case 'B': + lock_base = strtol(optarg, NULL, 0); + break; + case 'M': + min_length = strtol(optarg, NULL, 0); + break; + case 's': + seed = atoi(optarg); + break; + case 'u': + hide_unlock_fails = True; + break; + case 'o': + numops = atoi(optarg); + break; + case 'O': + use_oplocks = True; + break; + case 'a': + showall = True; + break; + case 'A': + analyze = True; + break; + case 'Z': + zero_zero = True; + break; + case 'E': + exact_error_codes = True; + break; + case 'h': + usage(); + exit(1); + default: + printf("Unknown option %c (%d)\n", (char)opt, opt); + exit(1); + } + } + + if(use_kerberos && !got_user) got_pass = True; + + argc -= optind; + argv += optind; + + DEBUG(0,("seed=%u base=%d range=%d min_length=%d\n", + seed, lock_base, lock_range, min_length)); + srandom(seed); + + test_locks(share); + + return(0); +} diff --git a/source4/torture/locktest2.c b/source4/torture/locktest2.c new file mode 100644 index 0000000000..17435afb4c --- /dev/null +++ b/source4/torture/locktest2.c @@ -0,0 +1,558 @@ +/* + Unix SMB/CIFS implementation. + byte range lock tester - with local filesystem support + Copyright (C) Andrew Tridgell 1999 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static fstring password; +static fstring username; +static int got_pass; +static int numops = 1000; +static BOOL showall; +static BOOL analyze; +static BOOL hide_unlock_fails; +static BOOL use_oplocks; + +#define FILENAME "\\locktest.dat" +#define LOCKRANGE 100 +#define LOCKBASE 0 + +/* +#define LOCKBASE (0x40000000 - 50) +*/ + +#define READ_PCT 50 +#define LOCK_PCT 25 +#define UNLOCK_PCT 65 +#define RANGE_MULTIPLE 1 + +#define NSERVERS 2 +#define NCONNECTIONS 2 +#define NUMFSTYPES 2 +#define NFILES 2 +#define LOCK_TIMEOUT 0 + +#define FSTYPE_SMB 0 +#define FSTYPE_NFS 1 + +struct record { + char r1, r2; + char conn, f, fstype; + unsigned start, len; + char needed; +}; + +static struct record *recorded; + +static int try_open(struct cli_state *c, char *nfs, int fstype, const char *fname, int flags) +{ + pstring path; + + switch (fstype) { + case FSTYPE_SMB: + return cli_open(c, fname, flags, DENY_NONE); + + case FSTYPE_NFS: + slprintf(path, sizeof(path), "%s%s", nfs, fname); + pstring_sub(path,"\\", "/"); + return open(path, flags, 0666); + } + + return -1; +} + +static BOOL try_close(struct cli_state *c, int fstype, int fd) +{ + switch (fstype) { + case FSTYPE_SMB: + return cli_close(c, fd); + + case FSTYPE_NFS: + return close(fd) == 0; + } + + return False; +} + +static BOOL try_lock(struct cli_state *c, int fstype, + int fd, unsigned start, unsigned len, + enum brl_type op) +{ + struct flock lock; + + switch (fstype) { + case FSTYPE_SMB: + return cli_lock(c, fd, start, len, LOCK_TIMEOUT, op); + + case FSTYPE_NFS: + lock.l_type = (op==READ_LOCK) ? F_RDLCK:F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = start; + lock.l_len = len; + lock.l_pid = getpid(); + return fcntl(fd,F_SETLK,&lock) == 0; + } + + return False; +} + +static BOOL try_unlock(struct cli_state *c, int fstype, + int fd, unsigned start, unsigned len) +{ + struct flock lock; + + switch (fstype) { + case FSTYPE_SMB: + return cli_unlock(c, fd, start, len); + + case FSTYPE_NFS: + lock.l_type = F_UNLCK; + lock.l_whence = SEEK_SET; + lock.l_start = start; + lock.l_len = len; + lock.l_pid = getpid(); + return fcntl(fd,F_SETLK,&lock) == 0; + } + + return False; +} + +static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, + enum brl_type lock_type, + br_off start, br_off size) +{ + printf("%6d %05x:%05x %s %.0f:%.0f(%.0f)\n", + (int)pid, (int)dev, (int)ino, + lock_type==READ_LOCK?"R":"W", + (double)start, (double)start+size-1,(double)size); + +} + +/***************************************************** +return a connection to a server +*******************************************************/ +static struct cli_state *connect_one(char *share) +{ + struct cli_state *c; + char *server_n; + fstring server; + fstring myname; + static int count; + NTSTATUS nt_status; + + fstrcpy(server,share+2); + share = strchr_m(server,'\\'); + if (!share) return NULL; + *share = 0; + share++; + + server_n = server; + + if (!got_pass) { + char *pass = getpass("Password: "); + if (pass) { + fstrcpy(password, pass); + } + } + + slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++); + + nt_status = cli_full_connection(&c, myname, server_n, NULL, 0, share, "?????", + username, lp_workgroup(), password, 0, + NULL); + + if (!NT_STATUS_IS_OK(nt_status)) { + DEBUG(0, ("cli_full_connection failed with error %s\n", nt_errstr(nt_status))); + return NULL; + } + + c->use_oplocks = use_oplocks; + + return c; +} + + +static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], + char *nfs[NSERVERS], + int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], + char *share1, char *share2) +{ + int server, conn, f, fstype; + char *share[2]; + share[0] = share1; + share[1] = share2; + + fstype = FSTYPE_SMB; + + for (server=0;server<NSERVERS;server++) + for (conn=0;conn<NCONNECTIONS;conn++) { + if (cli[server][conn]) { + for (f=0;f<NFILES;f++) { + cli_close(cli[server][conn], fnum[server][fstype][conn][f]); + } + cli_ulogoff(cli[server][conn]); + cli_shutdown(cli[server][conn]); + } + cli[server][conn] = connect_one(share[server]); + if (!cli[server][conn]) { + DEBUG(0,("Failed to connect to %s\n", share[server])); + exit(1); + } + } +} + + + +static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], + char *nfs[NSERVERS], + int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], + struct record *rec) +{ + unsigned conn = rec->conn; + unsigned f = rec->f; + unsigned fstype = rec->fstype; + unsigned start = rec->start; + unsigned len = rec->len; + unsigned r1 = rec->r1; + unsigned r2 = rec->r2; + enum brl_type op; + int server; + BOOL ret[NSERVERS]; + + if (r1 < READ_PCT) { + op = READ_LOCK; + } else { + op = WRITE_LOCK; + } + + if (r2 < LOCK_PCT) { + /* set a lock */ + for (server=0;server<NSERVERS;server++) { + ret[server] = try_lock(cli[server][conn], fstype, + fnum[server][fstype][conn][f], + start, len, op); + } + if (showall || ret[0] != ret[1]) { + printf("lock conn=%u fstype=%u f=%u range=%u:%u(%u) op=%s -> %u:%u\n", + conn, fstype, f, + start, start+len-1, len, + op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", + ret[0], ret[1]); + } + if (showall) brl_forall(print_brl); + if (ret[0] != ret[1]) return False; + } else if (r2 < LOCK_PCT+UNLOCK_PCT) { + /* unset a lock */ + for (server=0;server<NSERVERS;server++) { + ret[server] = try_unlock(cli[server][conn], fstype, + fnum[server][fstype][conn][f], + start, len); + } + if (showall || (!hide_unlock_fails && (ret[0] != ret[1]))) { + printf("unlock conn=%u fstype=%u f=%u range=%u:%u(%u) -> %u:%u\n", + conn, fstype, f, + start, start+len-1, len, + ret[0], ret[1]); + } + if (showall) brl_forall(print_brl); + if (!hide_unlock_fails && ret[0] != ret[1]) return False; + } else { + /* reopen the file */ + for (server=0;server<NSERVERS;server++) { + try_close(cli[server][conn], fstype, fnum[server][fstype][conn][f]); + fnum[server][fstype][conn][f] = try_open(cli[server][conn], nfs[server], fstype, FILENAME, + O_RDWR|O_CREAT); + if (fnum[server][fstype][conn][f] == -1) { + printf("failed to reopen on share1\n"); + return False; + } + } + if (showall) { + printf("reopen conn=%u fstype=%u f=%u\n", + conn, fstype, f); + brl_forall(print_brl); + } + } + return True; +} + +static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], + char *nfs[NSERVERS], + int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES]) +{ + int server, conn, f, fstype; + + for (server=0;server<NSERVERS;server++) + for (fstype=0;fstype<NUMFSTYPES;fstype++) + for (conn=0;conn<NCONNECTIONS;conn++) + for (f=0;f<NFILES;f++) { + if (fnum[server][fstype][conn][f] != -1) { + try_close(cli[server][conn], fstype, fnum[server][fstype][conn][f]); + fnum[server][fstype][conn][f] = -1; + } + } + for (server=0;server<NSERVERS;server++) { + cli_unlink(cli[server][0], FILENAME); + } +} + +static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], + char *nfs[NSERVERS], + int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES]) +{ + int server, fstype, conn, f; + + for (server=0;server<NSERVERS;server++) + for (fstype=0;fstype<NUMFSTYPES;fstype++) + for (conn=0;conn<NCONNECTIONS;conn++) + for (f=0;f<NFILES;f++) { + fnum[server][fstype][conn][f] = try_open(cli[server][conn], nfs[server], fstype, FILENAME, + O_RDWR|O_CREAT); + if (fnum[server][fstype][conn][f] == -1) { + fprintf(stderr,"Failed to open fnum[%u][%u][%u][%u]\n", + server, fstype, conn, f); + exit(1); + } + } +} + + +static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS], + char *nfs[NSERVERS], + int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], + int n) +{ + int i; + printf("testing %u ...\n", n); + for (i=0; i<n; i++) { + if (i && i % 100 == 0) { + printf("%u\n", i); + } + + if (recorded[i].needed && + !test_one(cli, nfs, fnum, &recorded[i])) return i; + } + return n; +} + + +/* each server has two connections open to it. Each connection has two file + descriptors open on the file - 8 file descriptors in total + + we then do random locking ops in tamdem on the 4 fnums from each + server and ensure that the results match + */ +static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath2) +{ + struct cli_state *cli[NSERVERS][NCONNECTIONS]; + char *nfs[NSERVERS]; + int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES]; + int n, i, n1; + + nfs[0] = nfspath1; + nfs[1] = nfspath2; + + ZERO_STRUCT(fnum); + ZERO_STRUCT(cli); + + recorded = (struct record *)malloc(sizeof(*recorded) * numops); + + for (n=0; n<numops; n++) { + recorded[n].conn = random() % NCONNECTIONS; + recorded[n].fstype = random() % NUMFSTYPES; + recorded[n].f = random() % NFILES; + recorded[n].start = LOCKBASE + ((unsigned)random() % (LOCKRANGE-1)); + recorded[n].len = 1 + + random() % (LOCKRANGE-(recorded[n].start-LOCKBASE)); + recorded[n].start *= RANGE_MULTIPLE; + recorded[n].len *= RANGE_MULTIPLE; + recorded[n].r1 = random() % 100; + recorded[n].r2 = random() % 100; + recorded[n].needed = True; + } + + reconnect(cli, nfs, fnum, share1, share2); + open_files(cli, nfs, fnum); + n = retest(cli, nfs, fnum, numops); + + if (n == numops || !analyze) return; + n++; + + while (1) { + n1 = n; + + close_files(cli, nfs, fnum); + reconnect(cli, nfs, fnum, share1, share2); + open_files(cli, nfs, fnum); + + for (i=0;i<n-1;i++) { + int m; + recorded[i].needed = False; + + close_files(cli, nfs, fnum); + open_files(cli, nfs, fnum); + + m = retest(cli, nfs, fnum, n); + if (m == n) { + recorded[i].needed = True; + } else { + if (i < m) { + memmove(&recorded[i], &recorded[i+1], + (m-i)*sizeof(recorded[0])); + } + n = m; + i--; + } + } + + if (n1 == n) break; + } + + close_files(cli, nfs, fnum); + reconnect(cli, nfs, fnum, share1, share2); + open_files(cli, nfs, fnum); + showall = True; + n1 = retest(cli, nfs, fnum, n); + if (n1 != n-1) { + printf("ERROR - inconsistent result (%u %u)\n", n1, n); + } + close_files(cli, nfs, fnum); + + for (i=0;i<n;i++) { + printf("{%u, %u, %u, %u, %u, %u, %u, %u},\n", + recorded[i].r1, + recorded[i].r2, + recorded[i].conn, + recorded[i].fstype, + recorded[i].f, + recorded[i].start, + recorded[i].len, + recorded[i].needed); + } +} + + + +static void usage(void) +{ + printf( +"Usage:\n\ + locktest //server1/share1 //server2/share2 /path1 /path2 [options..]\n\ + options:\n\ + -U user%%pass\n\ + -s seed\n\ + -o numops\n\ + -u hide unlock fails\n\ + -a (show all ops)\n\ + -O use oplocks\n\ +"); +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + char *share1, *share2, *nfspath1, *nfspath2; + extern char *optarg; + extern int optind; + int opt; + char *p; + int seed; + + setlinebuf(stdout); + + dbf = x_stderr; + + if (argc < 5 || argv[1][0] == '-') { + usage(); + exit(1); + } + + share1 = argv[1]; + share2 = argv[2]; + nfspath1 = argv[3]; + nfspath2 = argv[4]; + + all_string_sub(share1,"/","\\",0); + all_string_sub(share2,"/","\\",0); + + setup_logging(argv[0],True); + + argc -= 4; + argv += 4; + + lp_load(dyn_CONFIGFILE,True,False,False); + load_interfaces(); + + if (getenv("USER")) { + fstrcpy(username,getenv("USER")); + } + + seed = time(NULL); + + while ((opt = getopt(argc, argv, "U:s:ho:aAW:O")) != EOF) { + switch (opt) { + case 'U': + fstrcpy(username,optarg); + p = strchr_m(username,'%'); + if (p) { + *p = 0; + fstrcpy(password, p+1); + got_pass = 1; + } + break; + case 's': + seed = atoi(optarg); + break; + case 'u': + hide_unlock_fails = True; + break; + case 'o': + numops = atoi(optarg); + break; + case 'O': + use_oplocks = True; + break; + case 'a': + showall = True; + break; + case 'A': + analyze = True; + break; + case 'h': + usage(); + exit(1); + default: + printf("Unknown option %c (%d)\n", (char)opt, opt); + exit(1); + } + } + + argc -= optind; + argv += optind; + + DEBUG(0,("seed=%u\n", seed)); + srandom(seed); + + locking_init(1); + test_locks(share1, share2, nfspath1, nfspath2); + + return(0); +} diff --git a/source4/torture/mangle_test.c b/source4/torture/mangle_test.c new file mode 100644 index 0000000000..fadd884061 --- /dev/null +++ b/source4/torture/mangle_test.c @@ -0,0 +1,205 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester - mangling test + Copyright (C) Andrew Tridgell 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static TDB_CONTEXT *tdb; + +#define NAME_LENGTH 20 + +static unsigned total, collisions, failures; + +static BOOL test_one(struct cli_state *cli, const char *name) +{ + int fnum; + char *shortname; + fstring name2; + NTSTATUS status; + TDB_DATA data; + + total++; + + fnum = cli_open(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum == -1) { + printf("open of %s failed (%s)\n", name, cli_errstr(cli)); + return False; + } + + if (!cli_close(cli, fnum)) { + printf("close of %s failed (%s)\n", name, cli_errstr(cli)); + return False; + } + + /* get the short name */ + status = cli_qpathinfo_alt_name(cli, name, &shortname); + if (!NT_STATUS_IS_OK(status)) { + printf("query altname of %s failed (%s)\n", name, cli_errstr(cli)); + return False; + } + + snprintf(name2, sizeof(name2), "\\mangle_test\\%s", shortname); + if (!cli_unlink(cli, name2)) { + printf("unlink of %s (%s) failed (%s)\n", + name2, name, cli_errstr(cli)); + return False; + } + + /* recreate by short name */ + fnum = cli_open(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum == -1) { + printf("open2 of %s failed (%s)\n", name2, cli_errstr(cli)); + return False; + } + if (!cli_close(cli, fnum)) { + printf("close of %s failed (%s)\n", name, cli_errstr(cli)); + return False; + } + + /* and unlink by long name */ + if (!cli_unlink(cli, name)) { + printf("unlink2 of %s (%s) failed (%s)\n", + name, name2, cli_errstr(cli)); + failures++; + cli_unlink(cli, name2); + return True; + } + + /* see if the short name is already in the tdb */ + data = tdb_fetch_by_string(tdb, shortname); + if (data.dptr) { + /* maybe its a duplicate long name? */ + if (strcasecmp(name, data.dptr) != 0) { + /* we have a collision */ + collisions++; + printf("Collision between %s and %s -> %s " + " (coll/tot: %u/%u)\n", + name, data.dptr, shortname, collisions, total); + } + free(data.dptr); + } else { + TDB_DATA namedata; + /* store it for later */ + namedata.dptr = name; + namedata.dsize = strlen(name)+1; + tdb_store_by_string(tdb, shortname, namedata, TDB_REPLACE); + } + + return True; +} + + +static void gen_name(char *name) +{ + const char *chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-$~..."; + unsigned max_idx = strlen(chars); + unsigned len; + int i; + char *p; + + fstrcpy(name, "\\mangle_test\\"); + p = name + strlen(name); + + len = 1 + random() % NAME_LENGTH; + + for (i=0;i<len;i++) { + p[i] = chars[random() % max_idx]; + } + + p[i] = 0; + + if (strcmp(p, ".") == 0 || strcmp(p, "..") == 0) { + p[0] = '_'; + } + + /* have a high probability of a common lead char */ + if (random() % 2 == 0) { + p[0] = 'A'; + } + + /* and a medium probability of a common lead string */ + if (random() % 10 == 0) { + strncpy(p, "ABCDE", 5); + } + + /* and a high probability of a good extension length */ + if (random() % 2 == 0) { + char *s = strrchr(p, '.'); + if (s) { + s[4] = 0; + } + } +} + + +BOOL torture_mangle(int dummy) +{ + extern int torture_numops; + static struct cli_state *cli; + int i; + + printf("starting mangle test\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + /* we will use an internal tdb to store the names we have used */ + tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0); + if (!tdb) { + printf("ERROR: Failed to open tdb\n"); + return False; + } + + cli_unlink(cli, "\\mangle_test\\*"); + cli_rmdir(cli, "\\mangle_test"); + + if (!cli_mkdir(cli, "\\mangle_test")) { + printf("ERROR: Failed to make directory\n"); + return False; + } + + for (i=0;i<torture_numops;i++) { + fstring name; + + gen_name(name); + + if (!test_one(cli, name)) { + break; + } + if (total && total % 100 == 0) { + printf("collisions %u/%u - %.2f%% (%u failures)\r", + collisions, total, (100.0*collisions) / total, failures); + } + } + + cli_unlink(cli, "\\mangle_test\\*"); + if (!cli_rmdir(cli, "\\mangle_test")) { + printf("ERROR: Failed to remove directory\n"); + return False; + } + + printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n", + collisions, total, (100.0*collisions) / total, failures); + + torture_close_connection(cli); + + printf("mangle test finished\n"); + return (failures == 0); +} diff --git a/source4/torture/masktest.c b/source4/torture/masktest.c new file mode 100644 index 0000000000..15bc080893 --- /dev/null +++ b/source4/torture/masktest.c @@ -0,0 +1,464 @@ +/* + Unix SMB/CIFS implementation. + mask_match tester + Copyright (C) Andrew Tridgell 1999 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static fstring password; +static fstring username; +static int got_pass; +static int max_protocol = PROTOCOL_NT1; +static BOOL showall = False; +static BOOL old_list = False; +static const char *maskchars = "<>\"?*abc."; +static const char *filechars = "abcdefghijklm."; +static int verbose; +static int die_on_error; +static int NumLoops = 0; + +/* a test fn for LANMAN mask support */ +static int ms_fnmatch_lanman_core(const char *pattern, const char *string) +{ + const char *p = pattern, *n = string; + char c; + + if (strcmp(p,"?")==0 && strcmp(n,".")==0) goto match; + + while ((c = *p++)) { + switch (c) { + case '.': + /* if (! *n && ! *p) goto match; */ + if (*n != '.') goto nomatch; + n++; + break; + + case '?': + if ((*n == '.' && n[1] != '.') || ! *n) goto next; + n++; + break; + + case '>': + if (n[0] == '.') { + if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) goto match; + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; + goto nomatch; + } + if (! *n) goto next; + n++; + break; + + case '*': + if (! *p) goto match; + for (; *n; n++) { + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; + } + break; + + case '<': + for (; *n; n++) { + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; + if (*n == '.' && !strchr_m(n+1,'.')) { + n++; + break; + } + } + break; + + case '"': + if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) goto match; + if (*n != '.') goto nomatch; + n++; + break; + + default: + if (c != *n) goto nomatch; + n++; + } + } + + if (! *n) goto match; + + nomatch: + if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string); + return -1; + +next: + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; + goto nomatch; + + match: + if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string); + return 0; +} + +static int ms_fnmatch_lanman(const char *pattern, const char *string) +{ + if (!strpbrk(pattern, "?*<>\"")) { + if (strcmp(string,"..") == 0) + string = "."; + + return strcmp(pattern, string); + } + + if (strcmp(string,"..") == 0 || strcmp(string,".") == 0) { + return ms_fnmatch_lanman_core(pattern, "..") && + ms_fnmatch_lanman_core(pattern, "."); + } + + return ms_fnmatch_lanman_core(pattern, string); +} + +static BOOL reg_match_one(struct cli_state *cli, const char *pattern, const char *file) +{ + /* oh what a weird world this is */ + if (old_list && strcmp(pattern, "*.*") == 0) return True; + + if (strcmp(pattern,".") == 0) return False; + + if (max_protocol <= PROTOCOL_LANMAN2) { + return ms_fnmatch_lanman(pattern, file)==0; + } + + if (strcmp(file,"..") == 0) file = "."; + + return ms_fnmatch(pattern, file, cli->transport->negotiate.protocol)==0; +} + +static char *reg_test(struct cli_state *cli, char *pattern, char *long_name, char *short_name) +{ + static fstring ret; + fstrcpy(ret, "---"); + + pattern = 1+strrchr_m(pattern,'\\'); + + if (reg_match_one(cli, pattern, ".")) ret[0] = '+'; + if (reg_match_one(cli, pattern, "..")) ret[1] = '+'; + if (reg_match_one(cli, pattern, long_name) || + (*short_name && reg_match_one(cli, pattern, short_name))) ret[2] = '+'; + return ret; +} + + +/***************************************************** +return a connection to a server +*******************************************************/ +static struct cli_state *connect_one(char *share) +{ + struct cli_state *c; + fstring server; + uint_t flags = 0; + NTSTATUS status; + + fstrcpy(server,share+2); + share = strchr_m(server,'\\'); + if (!share) return NULL; + *share = 0; + share++; + + status = cli_full_connection(&c, "masktest", + server, NULL, + share, "?????", + username, lp_workgroup(), + password, flags, NULL); + + if (!NT_STATUS_IS_OK(status)) { + return NULL; + } + + return c; +} + +static char *resultp; +static struct { + pstring long_name; + pstring short_name; +} last_hit; +static BOOL f_info_hit; + +static void listfn(file_info *f, const char *s, void *state) +{ + if (strcmp(f->name,".") == 0) { + resultp[0] = '+'; + } else if (strcmp(f->name,"..") == 0) { + resultp[1] = '+'; + } else { + resultp[2] = '+'; + } + pstrcpy(last_hit.long_name, f->name); + pstrcpy(last_hit.short_name, f->short_name); + f_info_hit = True; +} + +static void get_real_name(struct cli_state *cli, + pstring long_name, fstring short_name) +{ + const char *mask; + if (max_protocol <= PROTOCOL_LANMAN1) { + mask = "\\masktest\\*.*"; + } else { + mask = "\\masktest\\*"; + } + + f_info_hit = False; + + cli_list_new(cli, mask, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY, + listfn, NULL); + + if (f_info_hit) { + fstrcpy(short_name, last_hit.short_name); + strlower(short_name); + pstrcpy(long_name, last_hit.long_name); + strlower(long_name); + } + + if (*short_name == 0) { + fstrcpy(short_name, long_name); + } +} + +static void testpair(struct cli_state *cli, char *mask, char *file) +{ + int fnum; + fstring res1; + char *res2; + static int count; + fstring short_name; + pstring long_name; + + count++; + + fstrcpy(res1, "---"); + + fnum = cli_open(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0); + if (fnum == -1) { + DEBUG(0,("Can't create %s\n", file)); + return; + } + cli_close(cli, fnum); + + resultp = res1; + fstrcpy(short_name, ""); + get_real_name(cli, long_name, short_name); + fstrcpy(res1, "---"); + cli_list(cli, mask, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY, + listfn, NULL); + + res2 = reg_test(cli, mask, long_name, short_name); + + if (showall || strcmp(res1, res2)) { + d_printf("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n", + res1, res2, count, mask, file, long_name, short_name); + if (die_on_error) exit(1); + } + + cli_unlink(cli, file); + + if (count % 100 == 0) DEBUG(0,("%d\n", count)); +} + +static void test_mask(int argc, char *argv[], + struct cli_state *cli) +{ + pstring mask, file; + int l1, l2, i, l; + int mc_len = strlen(maskchars); + int fc_len = strlen(filechars); + + cli_mkdir(cli, "\\masktest"); + + cli_unlink(cli, "\\masktest\\*"); + + if (argc >= 2) { + while (argc >= 2) { + pstrcpy(mask,"\\masktest\\"); + pstrcpy(file,"\\masktest\\"); + pstrcat(mask, argv[0]); + pstrcat(file, argv[1]); + testpair(cli, mask, file); + argv += 2; + argc -= 2; + } + goto finished; + } + + while (1) { + l1 = 1 + random() % 20; + l2 = 1 + random() % 20; + pstrcpy(mask,"\\masktest\\"); + pstrcpy(file,"\\masktest\\"); + l = strlen(mask); + for (i=0;i<l1;i++) { + mask[i+l] = maskchars[random() % mc_len]; + } + mask[l+l1] = 0; + + for (i=0;i<l2;i++) { + file[i+l] = filechars[random() % fc_len]; + } + file[l+l2] = 0; + + if (strcmp(file+l,".") == 0 || + strcmp(file+l,"..") == 0 || + strcmp(mask+l,"..") == 0) continue; + + if (strspn(file+l, ".") == strlen(file+l)) continue; + + testpair(cli, mask, file); + if (NumLoops && (--NumLoops == 0)) + break; + } + + finished: + cli_rmdir(cli, "\\masktest"); +} + + +static void usage(void) +{ + printf( +"Usage:\n\ + masktest //server/share [options..]\n\ + options:\n\ + -d debuglevel\n\ + -n numloops\n\ + -W workgroup\n\ + -U user%%pass\n\ + -s seed\n\ + -M max protocol\n\ + -f filechars (default %s)\n\ + -m maskchars (default %s)\n\ + -v verbose mode\n\ + -E die on error\n\ + -a show all tests\n\ +\n\ + This program tests wildcard matching between two servers. It generates\n\ + random pairs of filenames/masks and tests that they match in the same\n\ + way on the servers and internally\n\ +", + filechars, maskchars); +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + char *share; + struct cli_state *cli; + int opt; + char *p; + int seed; + + setlinebuf(stdout); + + setup_logging("masktest", DEBUG_STDOUT); + + lp_set_cmdline("log level", "0"); + + if (argc < 2 || argv[1][0] == '-') { + usage(); + exit(1); + } + + share = argv[1]; + + all_string_sub(share,"/","\\",0); + + setup_logging(argv[0],True); + + argc -= 1; + argv += 1; + + lp_load(dyn_CONFIGFILE,True,False,False); + load_interfaces(); + + if (getenv("USER")) { + fstrcpy(username,getenv("USER")); + } + + seed = time(NULL); + + while ((opt = getopt(argc, argv, "n:d:U:s:hm:f:aoW:M:vE")) != EOF) { + switch (opt) { + case 'n': + NumLoops = atoi(optarg); + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + case 'E': + die_on_error = 1; + break; + case 'v': + verbose++; + break; + case 'M': + max_protocol = interpret_protocol(optarg, max_protocol); + break; + case 'U': + fstrcpy(username,optarg); + p = strchr_m(username,'%'); + if (p) { + *p = 0; + fstrcpy(password, p+1); + got_pass = 1; + } + break; + case 's': + seed = atoi(optarg); + break; + case 'h': + usage(); + exit(1); + case 'm': + maskchars = optarg; + break; + case 'f': + filechars = optarg; + break; + case 'a': + showall = 1; + break; + case 'o': + old_list = True; + break; + default: + printf("Unknown option %c (%d)\n", (char)opt, opt); + exit(1); + } + } + + argc -= optind; + argv += optind; + + + cli = connect_one(share); + if (!cli) { + DEBUG(0,("Failed to connect to %s\n", share)); + exit(1); + } + + /* need to init seed after connect as clientgen uses random numbers */ + DEBUG(0,("seed=%d\n", seed)); + srandom(seed); + + test_mask(argc, argv, cli); + + return(0); +} diff --git a/source4/torture/msgtest.c b/source4/torture/msgtest.c new file mode 100644 index 0000000000..952aa46bfe --- /dev/null +++ b/source4/torture/msgtest.c @@ -0,0 +1,89 @@ +/* + Unix SMB/CIFS implementation. + Copyright (C) Andrew Tridgell 2000 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + test code for internal messaging + */ + +#include "includes.h" + +static int pong_count; + +/**************************************************************************** +a useful function for testing the message system +****************************************************************************/ +void pong_message(int msg_type, pid_t src, void *buf, size_t len) +{ + pong_count++; +} + + int main(int argc, char *argv[]) +{ + pid_t pid; + int i, n; + char buf[12]; + + setup_logging(argv[0],True); + + lp_load(dyn_CONFIGFILE,False,False,False); + + message_init(); + + if (argc != 3) { + fprintf(stderr, "%s: Usage - %s pid count\n", argv[0], argv[0]); + exit(1); + } + + pid = atoi(argv[1]); + n = atoi(argv[2]); + + message_register(MSG_PONG, pong_message); + + for (i=0;i<n;i++) { + message_send_pid(pid, MSG_PING, NULL, 0, True); + } + + while (pong_count < i) { + message_dispatch(); + msleep(1); + } + + /* Now test that the duplicate filtering code works. */ + pong_count = 0; + + safe_strcpy(buf, "1234567890", sizeof(buf)-1); + + for (i=0;i<n;i++) { + message_send_pid(getpid(), MSG_PING, NULL, 0, False); + message_send_pid(getpid(), MSG_PING, buf, 11, False); + } + + for (i=0;i<n;i++) { + message_dispatch(); + msleep(1); + } + + if (pong_count != 2) { + fprintf(stderr, "Duplicate filter failed (%d).\n", pong_count); + exit(1); + } + + return (0); +} + diff --git a/source4/torture/nbio.c b/source4/torture/nbio.c new file mode 100644 index 0000000000..ef231478d0 --- /dev/null +++ b/source4/torture/nbio.c @@ -0,0 +1,285 @@ +#define NBDEBUG 0 + +/* + Unix SMB/CIFS implementation. + SMB torture tester + Copyright (C) Andrew Tridgell 1997-1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define MAX_FILES 1000 + +static char buf[70000]; +extern int line_count; +extern int nbio_id; +static int nprocs; +static BOOL bypass_io; + +static struct { + int fd; + int handle; +} ftable[MAX_FILES]; + +static struct { + double bytes_in, bytes_out; + int line; + int done; +} *children; + +double nbio_total(void) +{ + int i; + double total = 0; + for (i=0;i<nprocs;i++) { + total += children[i].bytes_out + children[i].bytes_in; + } + return total; +} + +void nb_alarm(void) +{ + int i; + int lines=0, num_clients=0; + if (nbio_id != -1) return; + + for (i=0;i<nprocs;i++) { + lines += children[i].line; + if (!children[i].done) num_clients++; + } + + printf("%4d %8d %.2f MB/sec\r", num_clients, lines/nprocs, 1.0e-6 * nbio_total() / end_timer()); + + signal(SIGALRM, nb_alarm); + alarm(1); +} + +void nbio_shmem(int n) +{ + nprocs = n; + children = shm_setup(sizeof(*children) * nprocs); + if (!children) { + printf("Failed to setup shared memory!\n"); + exit(1); + } +} + +static int find_handle(int handle) +{ + int i; + children[nbio_id].line = line_count; + for (i=0;i<MAX_FILES;i++) { + if (ftable[i].handle == handle) return i; + } + printf("(%d) ERROR: handle %d was not found\n", + line_count, handle); + exit(1); + + return -1; /* Not reached */ +} + + +static struct cli_state *c; + +static void sigsegv(int sig) +{ + char line[200]; + printf("segv at line %d\n", line_count); + slprintf(line, sizeof(line), "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d", + (int)getpid(), (int)getpid()); + system(line); + exit(1); +} + +void nb_setup(struct cli_state *cli) +{ + signal(SIGSEGV, sigsegv); + c = cli; + start_timer(); + children[nbio_id].done = 0; + if (bypass_io) + printf("skipping I/O\n"); +} + + +void nb_unlink(const char *fname) +{ + if (!cli_unlink(c, fname)) { +#if NBDEBUG + printf("(%d) unlink %s failed (%s)\n", + line_count, fname, cli_errstr(c)); +#endif + } +} + + +void nb_createx(const char *fname, + unsigned create_options, unsigned create_disposition, int handle) +{ + int fd, i; + uint32 desired_access; + + if (create_options & NTCREATEX_OPTIONS_DIRECTORY) { + desired_access = SA_RIGHT_FILE_READ_DATA; + } else { + desired_access = SA_RIGHT_FILE_READ_DATA | SA_RIGHT_FILE_WRITE_DATA; + } + + fd = cli_nt_create_full(c, fname, 0, + desired_access, + 0x0, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, + create_disposition, + create_options, 0); + if (fd == -1 && handle != -1) { + printf("ERROR: cli_nt_create_full failed for %s - %s\n", + fname, cli_errstr(c)); + exit(1); + } + if (fd != -1 && handle == -1) { + printf("ERROR: cli_nt_create_full succeeded for %s\n", fname); + exit(1); + } + if (fd == -1) return; + + for (i=0;i<MAX_FILES;i++) { + if (ftable[i].handle == 0) break; + } + if (i == MAX_FILES) { + printf("(%d) file table full for %s\n", line_count, + fname); + exit(1); + } + ftable[i].handle = handle; + ftable[i].fd = fd; +} + +void nb_writex(int handle, int offset, int size, int ret_size) +{ + int i; + + if (buf[0] == 0) memset(buf, 1, sizeof(buf)); + + i = find_handle(handle); + if (!bypass_io && cli_write(c, ftable[i].fd, 0, buf, offset, size) != ret_size) { + printf("(%d) ERROR: write failed on handle %d, fd %d \ +errno %d (%s)\n", line_count, handle, ftable[i].fd, errno, strerror(errno)); + exit(1); + } + + children[nbio_id].bytes_out += ret_size; +} + +void nb_readx(int handle, int offset, int size, int ret_size) +{ + int i, ret; + + i = find_handle(handle); + if (!bypass_io && (ret=cli_read(c, ftable[i].fd, buf, offset, size)) != ret_size) { + printf("(%d) ERROR: read failed on handle %d ofs=%d size=%d res=%d fd %d errno %d (%s)\n", + line_count, handle, offset, size, ret, ftable[i].fd, errno, strerror(errno)); + exit(1); + } + children[nbio_id].bytes_in += ret_size; +} + +void nb_close(int handle) +{ + int i; + i = find_handle(handle); + if (!cli_close(c, ftable[i].fd)) { + printf("(%d) close failed on handle %d\n", line_count, handle); + exit(1); + } + ftable[i].handle = 0; +} + +void nb_rmdir(const char *fname) +{ + if (!cli_rmdir(c, fname)) { + printf("ERROR: rmdir %s failed (%s)\n", + fname, cli_errstr(c)); + exit(1); + } +} + +void nb_rename(const char *old, const char *new) +{ + if (!cli_rename(c, old, new)) { + printf("ERROR: rename %s %s failed (%s)\n", + old, new, cli_errstr(c)); + exit(1); + } +} + + +void nb_qpathinfo(const char *fname) +{ + cli_qpathinfo(c, fname, NULL, NULL, NULL, NULL, NULL); +} + +void nb_qfileinfo(int fnum) +{ + int i; + i = find_handle(fnum); + cli_qfileinfo(c, ftable[i].fd, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +} + +void nb_qfsinfo(int level) +{ + int bsize, total, avail; + /* this is not the right call - we need cli_qfsinfo() */ + cli_dskattr(c, &bsize, &total, &avail); +} + +static void find_fn(file_info *finfo, const char *name, void *state) +{ + /* noop */ +} + +void nb_findfirst(const char *mask) +{ + cli_list(c, mask, 0, find_fn, NULL); +} + +void nb_flush(int fnum) +{ + int i; + i = find_handle(fnum); + /* hmmm, we don't have cli_flush() yet */ +} + +void nb_deltree(const char *dname) +{ + int total_deleted; + + total_deleted = cli_deltree(c, dname); + + if (total_deleted == -1) { + printf("Failed to cleanup tree %s - exiting\n", dname); + exit(1); + } + + if (total_deleted > 0) printf("WARNING: Cleaned up %d files\n", total_deleted); +} + + +void nb_cleanup(void) +{ + cli_rmdir(c, "clients"); + children[nbio_id].done = 1; +} diff --git a/source4/torture/nsstest.c b/source4/torture/nsstest.c new file mode 100644 index 0000000000..a82fa05203 --- /dev/null +++ b/source4/torture/nsstest.c @@ -0,0 +1,410 @@ +/* + Unix SMB/CIFS implementation. + nss tester for winbindd + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static const char *so_path = "/lib/libnss_winbind.so"; +static const char *nss_name = "winbind"; +static int nss_errno; +static NSS_STATUS last_error; +static int total_errors; + +static void *find_fn(const char *name) +{ + char s[1024]; + static void *h; + void *res; + + snprintf(s,sizeof(s), "_nss_%s_%s", nss_name, name); + + if (!h) { + h = sys_dlopen(so_path, RTLD_LAZY); + } + if (!h) { + printf("Can't open shared library %s\n", so_path); + exit(1); + } + res = sys_dlsym(h, s); + if (!res) { + printf("Can't find function %s\n", s); + return NULL; + } + return res; +} + +static void report_nss_error(const char *who, NSS_STATUS status) +{ + last_error = status; + total_errors++; + printf("ERROR %s: NSS_STATUS=%d %d (nss_errno=%d)\n", + who, status, NSS_STATUS_SUCCESS, nss_errno); +} + +static struct passwd *nss_getpwent(void) +{ + NSS_STATUS (*_nss_getpwent_r)(struct passwd *, char *, + size_t , int *) = find_fn("getpwent_r"); + static struct passwd pwd; + static char buf[1000]; + NSS_STATUS status; + + status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno); + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getpwent", status); + return NULL; + } + return &pwd; +} + +static struct passwd *nss_getpwnam(const char *name) +{ + NSS_STATUS (*_nss_getpwnam_r)(const char *, struct passwd *, char *, + size_t , int *) = find_fn("getpwnam_r"); + static struct passwd pwd; + static char buf[1000]; + NSS_STATUS status; + + status = _nss_getpwnam_r(name, &pwd, buf, sizeof(buf), &nss_errno); + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getpwnam", status); + return NULL; + } + return &pwd; +} + +static struct passwd *nss_getpwuid(uid_t uid) +{ + NSS_STATUS (*_nss_getpwuid_r)(uid_t , struct passwd *, char *, + size_t , int *) = find_fn("getpwuid_r"); + static struct passwd pwd; + static char buf[1000]; + NSS_STATUS status; + + status = _nss_getpwuid_r(uid, &pwd, buf, sizeof(buf), &nss_errno); + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getpwuid", status); + return NULL; + } + return &pwd; +} + +static void nss_setpwent(void) +{ + NSS_STATUS (*_nss_setpwent)(void) = find_fn("setpwent"); + NSS_STATUS status; + status = _nss_setpwent(); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("setpwent", status); + } +} + +static void nss_endpwent(void) +{ + NSS_STATUS (*_nss_endpwent)(void) = find_fn("endpwent"); + NSS_STATUS status; + status = _nss_endpwent(); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("endpwent", status); + } +} + + +static struct group *nss_getgrent(void) +{ + NSS_STATUS (*_nss_getgrent_r)(struct group *, char *, + size_t , int *) = find_fn("getgrent_r"); + static struct group grp; + static char *buf; + static int buflen = 1024; + NSS_STATUS status; + + if (!buf) buf = malloc(buflen); + +again: + status = _nss_getgrent_r(&grp, buf, buflen, &nss_errno); + if (status == NSS_STATUS_TRYAGAIN) { + buflen *= 2; + buf = realloc(buf, buflen); + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getgrent", status); + return NULL; + } + return &grp; +} + +static struct group *nss_getgrnam(const char *name) +{ + NSS_STATUS (*_nss_getgrnam_r)(const char *, struct group *, char *, + size_t , int *) = find_fn("getgrnam_r"); + static struct group grp; + static char *buf; + static int buflen = 1000; + NSS_STATUS status; + + if (!buf) buf = malloc(buflen); +again: + status = _nss_getgrnam_r(name, &grp, buf, buflen, &nss_errno); + if (status == NSS_STATUS_TRYAGAIN) { + buflen *= 2; + buf = realloc(buf, buflen); + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getgrnam", status); + return NULL; + } + return &grp; +} + +static struct group *nss_getgrgid(gid_t gid) +{ + NSS_STATUS (*_nss_getgrgid_r)(gid_t , struct group *, char *, + size_t , int *) = find_fn("getgrgid_r"); + static struct group grp; + static char *buf; + static int buflen = 1000; + NSS_STATUS status; + + if (!buf) buf = malloc(buflen); +again: + status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno); + if (status == NSS_STATUS_TRYAGAIN) { + buflen *= 2; + buf = realloc(buf, buflen); + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getgrgid", status); + return NULL; + } + return &grp; +} + +static void nss_setgrent(void) +{ + NSS_STATUS (*_nss_setgrent)(void) = find_fn("setgrent"); + NSS_STATUS status; + status = _nss_setgrent(); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("setgrent", status); + } +} + +static void nss_endgrent(void) +{ + NSS_STATUS (*_nss_endgrent)(void) = find_fn("endgrent"); + NSS_STATUS status; + status = _nss_endgrent(); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("endgrent", status); + } +} + +static int nss_initgroups(char *user, gid_t group, gid_t **groups, long int *start, long int *size) +{ + NSS_STATUS (*_nss_initgroups)(char *, gid_t , long int *, + long int *, gid_t **, long int , int *) = + find_fn("initgroups_dyn"); + NSS_STATUS status; + + if (!_nss_initgroups) return NSS_STATUS_UNAVAIL; + + status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("initgroups", status); + } + return status; +} + +static void print_passwd(struct passwd *pwd) +{ + printf("%s:%s:%d:%d:%s:%s:%s\n", + pwd->pw_name, + pwd->pw_passwd, + pwd->pw_uid, + pwd->pw_gid, + pwd->pw_gecos, + pwd->pw_dir, + pwd->pw_shell); +} + +static void print_group(struct group *grp) +{ + int i; + printf("%s:%s:%d: ", + grp->gr_name, + grp->gr_passwd, + grp->gr_gid); + + if (!grp->gr_mem[0]) { + printf("\n"); + return; + } + + for (i=0; grp->gr_mem[i+1]; i++) { + printf("%s, ", grp->gr_mem[i]); + } + printf("%s\n", grp->gr_mem[i]); +} + +static void nss_test_initgroups(char *name, gid_t gid) +{ + long int size = 16; + long int start = 1; + gid_t *groups = NULL; + int i; + NSS_STATUS status; + + groups = (gid_t *)malloc(size * sizeof(gid_t)); + groups[0] = gid; + + status = nss_initgroups(name, gid, &groups, &start, &size); + if (status == NSS_STATUS_UNAVAIL) { + printf("No initgroups fn\n"); + return; + } + + for (i=0; i<start-1; i++) { + printf("%d, ", groups[i]); + } + printf("%d\n", groups[i]); +} + + +static void nss_test_users(void) +{ + struct passwd *pwd; + + nss_setpwent(); + /* loop over all users */ + while ((pwd = nss_getpwent())) { + printf("Testing user %s\n", pwd->pw_name); + printf("getpwent: "); print_passwd(pwd); + pwd = nss_getpwuid(pwd->pw_uid); + if (!pwd) { + total_errors++; + printf("ERROR: can't getpwuid\n"); + continue; + } + printf("getpwuid: "); print_passwd(pwd); + pwd = nss_getpwnam(pwd->pw_name); + if (!pwd) { + total_errors++; + printf("ERROR: can't getpwnam\n"); + continue; + } + printf("getpwnam: "); print_passwd(pwd); + printf("initgroups: "); nss_test_initgroups(pwd->pw_name, pwd->pw_gid); + printf("\n"); + } + nss_endpwent(); +} + +static void nss_test_groups(void) +{ + struct group *grp; + + nss_setgrent(); + /* loop over all groups */ + while ((grp = nss_getgrent())) { + printf("Testing group %s\n", grp->gr_name); + printf("getgrent: "); print_group(grp); + grp = nss_getgrnam(grp->gr_name); + if (!grp) { + total_errors++; + printf("ERROR: can't getgrnam\n"); + continue; + } + printf("getgrnam: "); print_group(grp); + grp = nss_getgrgid(grp->gr_gid); + if (!grp) { + total_errors++; + printf("ERROR: can't getgrgid\n"); + continue; + } + printf("getgrgid: "); print_group(grp); + printf("\n"); + } + nss_endgrent(); +} + +static void nss_test_errors(void) +{ + struct passwd *pwd; + struct group *grp; + + pwd = getpwnam("nosuchname"); + if (pwd || last_error != NSS_STATUS_NOTFOUND) { + total_errors++; + printf("ERROR Non existant user gave error %d\n", last_error); + } + + pwd = getpwuid(0xFFF0); + if (pwd || last_error != NSS_STATUS_NOTFOUND) { + total_errors++; + printf("ERROR Non existant uid gave error %d\n", last_error); + } + + grp = getgrnam("nosuchgroup"); + if (grp || last_error != NSS_STATUS_NOTFOUND) { + total_errors++; + printf("ERROR Non existant group gave error %d\n", last_error); + } + + grp = getgrgid(0xFFF0); + if (grp || last_error != NSS_STATUS_NOTFOUND) { + total_errors++; + printf("ERROR Non existant gid gave error %d\n", last_error); + } +} + + int main(int argc, char *argv[]) +{ + if (argc > 1) so_path = argv[1]; + if (argc > 2) nss_name = argv[2]; + + nss_test_users(); + nss_test_groups(); + nss_test_errors(); + + printf("total_errors=%d\n", total_errors); + + return total_errors; +} diff --git a/source4/torture/qfileinfo.c b/source4/torture/qfileinfo.c new file mode 100644 index 0000000000..d7136cf22a --- /dev/null +++ b/source4/torture/qfileinfo.c @@ -0,0 +1,640 @@ +/* + Unix SMB/CIFS implementation. + RAW_FILEINFO_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static struct { + const char *name; + enum fileinfo_level level; + unsigned only_paths:1; + unsigned only_handles:1; + NTSTATUS fnum_status, fname_status; + union smb_fileinfo fnum_finfo, fname_finfo; +} levels[] = { + { "GETATTR", RAW_FILEINFO_GETATTR, 1, 0, }, + { "GETATTRE", RAW_FILEINFO_GETATTRE, 0, 1, }, + { "STANDARD", RAW_FILEINFO_STANDARD, }, + { "EA_SIZE", RAW_FILEINFO_EA_SIZE, }, + { "ALL_EAS", RAW_FILEINFO_ALL_EAS, }, + { "IS_NAME_VALID", RAW_FILEINFO_IS_NAME_VALID, 1, 0, }, + { "BASIC_INFO", RAW_FILEINFO_BASIC_INFO, }, + { "STANDARD_INFO", RAW_FILEINFO_STANDARD_INFO, }, + { "EA_INFO", RAW_FILEINFO_EA_INFO, }, + { "NAME_INFO", RAW_FILEINFO_NAME_INFO, }, + { "ALL_INFO", RAW_FILEINFO_ALL_INFO, }, + { "ALT_NAME_INFO", RAW_FILEINFO_ALT_NAME_INFO, }, + { "STREAM_INFO", RAW_FILEINFO_STREAM_INFO, }, + { "COMPRESSION_INFO", RAW_FILEINFO_COMPRESSION_INFO, }, + { "BASIC_INFORMATION", RAW_FILEINFO_BASIC_INFORMATION, }, + { "STANDARD_INFORMATION", RAW_FILEINFO_STANDARD_INFORMATION, }, + { "INTERNAL_INFORMATION", RAW_FILEINFO_INTERNAL_INFORMATION, }, + { "EA_INFORMATION", RAW_FILEINFO_EA_INFORMATION, }, + { "ACCESS_INFORMATION", RAW_FILEINFO_ACCESS_INFORMATION, }, + { "NAME_INFORMATION", RAW_FILEINFO_NAME_INFORMATION, }, + { "POSITION_INFORMATION", RAW_FILEINFO_POSITION_INFORMATION, }, + { "MODE_INFORMATION", RAW_FILEINFO_MODE_INFORMATION, }, + { "ALIGNMENT_INFORMATION", RAW_FILEINFO_ALIGNMENT_INFORMATION, }, + { "ALL_INFORMATION", RAW_FILEINFO_ALL_INFORMATION, }, + { "ALT_NAME_INFORMATION", RAW_FILEINFO_ALT_NAME_INFORMATION, }, + { "STREAM_INFORMATION", RAW_FILEINFO_STREAM_INFORMATION, }, + { "COMPRESSION_INFORMATION", RAW_FILEINFO_COMPRESSION_INFORMATION, }, + { "NETWORK_OPEN_INFORMATION", RAW_FILEINFO_NETWORK_OPEN_INFORMATION, }, + { "ATTRIBUTE_TAG_INFORMATION", RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION, }, + { NULL, } +}; + +/* + compare a dos time (2 second resolution) to a nt time +*/ +static int dos_nt_time_cmp(time_t t, const NTTIME *nt) +{ + time_t t2 = nt_time_to_unix(nt); + if (ABS(t2 - t) <= 2) return 0; + return t2 - t; +} + + +/* + find a level in the levels[] table +*/ +static union smb_fileinfo *fnum_find(const char *name) +{ + int i; + for (i=0; levels[i].name; i++) { + if (NT_STATUS_IS_OK(levels[i].fnum_status) && + strcmp(name, levels[i].name) == 0 && + !levels[i].only_paths) { + return &levels[i].fnum_finfo; + } + } + return NULL; +} + +/* + find a level in the levels[] table +*/ +static union smb_fileinfo *fname_find(const char *name) +{ + int i; + for (i=0; levels[i].name; i++) { + if (NT_STATUS_IS_OK(levels[i].fname_status) && + strcmp(name, levels[i].name) == 0 && + !levels[i].only_handles) { + return &levels[i].fname_finfo; + } + } + return NULL; +} + +/* local macros to make the code below more readable */ +#define VAL_EQUAL(n1, v1, n2, v2) do {if (s1->n1.out.v1 != s2->n2.out.v2) { \ + printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \ + #n1, #v1, (uint_t)s1->n1.out.v1, \ + #n2, #v2, (uint_t)s2->n2.out.v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +#define STR_EQUAL(n1, v1, n2, v2) do {if (strcmp(s1->n1.out.v1.s, s2->n2.out.v2.s) || \ + s1->n1.out.v1.private_length != s2->n2.out.v2.private_length) { \ + printf("%s/%s [%s/%d] != %s/%s [%s/%d] at %s(%d)\n", \ + #n1, #v1, s1->n1.out.v1.s, s1->n1.out.v1.private_length, \ + #n2, #v2, s2->n2.out.v2.s, s2->n2.out.v2.private_length, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +#define STRUCT_EQUAL(n1, v1, n2, v2) do {if (memcmp(&s1->n1.out.v1,&s2->n2.out.v2,sizeof(s1->n1.out.v1))) { \ + printf("%s/%s != %s/%s at %s(%d)\n", \ + #n1, #v1, \ + #n2, #v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +/* used to find hints on unknown values - and to make sure + we zero-fill */ +#define VAL_UNKNOWN(n1, v1) do {if (s1->n1.out.v1 != 0) { \ + printf("%s/%s non-zero unknown - %u (0x%x) at %s(%d)\n", \ + #n1, #v1, \ + (uint_t)s1->n1.out.v1, \ + (uint_t)s1->n1.out.v1, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +/* basic testing of all RAW_FILEINFO_* calls + for each call we test that it succeeds, and where possible test + for consistency between the calls. +*/ +BOOL torture_qfileinfo(int dummy) +{ + struct cli_state *cli; + int i; + BOOL ret = True; + int count; + union smb_fileinfo *s1, *s2; + TALLOC_CTX *mem_ctx; + int fnum; + const char *fname = "\\torture_qfileinfo.txt"; + NTTIME correct_time; + large_t correct_size; + uint32 correct_attrib; + const char *correct_name; + BOOL skip_streams = False; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_qfileinfo"); + + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + + /* scan all the fileinfo and pathinfo levels */ + for (i=0; levels[i].name; i++) { + if (!levels[i].only_paths) { + levels[i].fnum_finfo.generic.level = levels[i].level; + levels[i].fnum_finfo.generic.in.fnum = fnum; + levels[i].fnum_status = smb_raw_fileinfo(cli->tree, mem_ctx, + &levels[i].fnum_finfo); + } + + if (!levels[i].only_handles) { + levels[i].fname_finfo.generic.level = levels[i].level; + levels[i].fname_finfo.generic.in.fname = talloc_strdup(mem_ctx, fname); + levels[i].fname_status = smb_raw_pathinfo(cli->tree, mem_ctx, + &levels[i].fname_finfo); + } + } + + /* check for completely broken levels */ + for (count=i=0; levels[i].name; i++) { + if (!levels[i].only_paths && !NT_STATUS_IS_OK(levels[i].fnum_status)) { + printf("ERROR: level %s failed - %s\n", + levels[i].name, nt_errstr(levels[i].fnum_status)); + count++; + } + if (!levels[i].only_handles && !NT_STATUS_IS_OK(levels[i].fname_status)) { + printf("ERROR: level %s failed - %s\n", + levels[i].name, nt_errstr(levels[i].fname_status)); + count++; + } + } + + if (count != 0) { + ret = False; + printf("%d levels failed\n", count); + if (count > 32) { + printf("too many level failures - giving up\n"); + goto done; + } + } + + /* see if we can do streams */ + s1 = fnum_find("STREAM_INFO"); + if (!s1 || s1->stream_info.out.num_streams == 0) { + printf("STREAM_INFO broken (%d) - skipping streams checks\n", + s1 ? s1->stream_info.out.num_streams : -1); + skip_streams = True; + } + + + /* this code is incredibly repititive but doesn't lend itself to loops, so + we use lots of macros to make it less painful */ + + /* first off we check the levels that are supposed to be aliases. It will be quite rare for + this code to fail, but we need to check it for completeness */ + + + +#define ALIAS_CHECK(sname1, sname2) \ + do { \ + s1 = fnum_find(sname1); s2 = fnum_find(sname2); \ + if (s1 && s2) { INFO_CHECK } \ + s1 = fname_find(sname1); s2 = fname_find(sname2); \ + if (s1 && s2) { INFO_CHECK } \ + s1 = fnum_find(sname1); s2 = fname_find(sname2); \ + if (s1 && s2) { INFO_CHECK } \ + } while (0) + +#define INFO_CHECK \ + STRUCT_EQUAL(basic_info, create_time, basic_info, create_time); \ + STRUCT_EQUAL(basic_info, access_time, basic_info, access_time); \ + STRUCT_EQUAL(basic_info, write_time, basic_info, write_time); \ + STRUCT_EQUAL(basic_info, change_time, basic_info, change_time); \ + VAL_EQUAL (basic_info, attrib, basic_info, attrib); + + ALIAS_CHECK("BASIC_INFO", "BASIC_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + VAL_EQUAL(standard_info, alloc_size, standard_info, alloc_size); \ + VAL_EQUAL(standard_info, size, standard_info, size); \ + VAL_EQUAL(standard_info, nlink, standard_info, nlink); \ + VAL_EQUAL(standard_info, delete_pending, standard_info, delete_pending); \ + VAL_EQUAL(standard_info, directory, standard_info, directory); + + ALIAS_CHECK("STANDARD_INFO", "STANDARD_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + VAL_EQUAL(ea_info, ea_size, ea_info, ea_size); + + ALIAS_CHECK("EA_INFO", "EA_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + STR_EQUAL(name_info, fname, name_info, fname); + + ALIAS_CHECK("NAME_INFO", "NAME_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + STRUCT_EQUAL(all_info, create_time, all_info, create_time); \ + STRUCT_EQUAL(all_info, access_time, all_info, access_time); \ + STRUCT_EQUAL(all_info, write_time, all_info, write_time); \ + STRUCT_EQUAL(all_info, change_time, all_info, change_time); \ + VAL_EQUAL(all_info, attrib, all_info, attrib); \ + VAL_EQUAL(all_info, alloc_size, all_info, alloc_size); \ + VAL_EQUAL(all_info, size, all_info, size); \ + VAL_EQUAL(all_info, nlink, all_info, nlink); \ + VAL_EQUAL(all_info, delete_pending, all_info, delete_pending); \ + VAL_EQUAL(all_info, directory, all_info, directory); \ + VAL_EQUAL(all_info, ea_size, all_info, ea_size); \ + STR_EQUAL(all_info, fname, all_info, fname); + + ALIAS_CHECK("ALL_INFO", "ALL_INFORMATION"); + + +#undef INFO_CHECK +#define INFO_CHECK \ + STR_EQUAL(alt_name_info, fname, alt_name_info, fname); + + ALIAS_CHECK("ALT_NAME_INFO", "ALT_NAME_INFORMATION"); + +#define TIME_CHECK_NT(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && memcmp(&s1->stype.out.tfield, &correct_time, sizeof(correct_time)) != 0) { \ + printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + nt_time_string(mem_ctx, &s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && memcmp(&s1->stype.out.tfield, &correct_time, sizeof(correct_time)) != 0) { \ + printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + nt_time_string(mem_ctx, &s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + }} while (0) + +#define TIME_CHECK_DOS(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && dos_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ + printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + time_string(mem_ctx, s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && dos_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ + printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + time_string(mem_ctx, s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + }} while (0) + +#define TIME_CHECK_UNX(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && unx_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ + printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + time_string(mem_ctx, s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && unx_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ + printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + time_string(mem_ctx, s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + }} while (0) + + /* now check that all the times that are supposed to be equal are correct */ + s1 = fnum_find("BASIC_INFO"); + correct_time = s1->basic_info.out.create_time; + printf("create_time: %s\n", nt_time_string(mem_ctx, &correct_time)); + + TIME_CHECK_NT ("BASIC_INFO", basic_info, create_time); + TIME_CHECK_NT ("BASIC_INFORMATION", basic_info, create_time); + TIME_CHECK_DOS("GETATTRE", getattre, create_time); + TIME_CHECK_DOS("STANDARD", standard, create_time); + TIME_CHECK_DOS("EA_SIZE", ea_size, create_time); + TIME_CHECK_NT ("ALL_INFO", all_info, create_time); + TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, create_time); + + s1 = fnum_find("BASIC_INFO"); + correct_time = s1->basic_info.out.access_time; + printf("access_time: %s\n", nt_time_string(mem_ctx, &correct_time)); + + TIME_CHECK_NT ("BASIC_INFO", basic_info, access_time); + TIME_CHECK_NT ("BASIC_INFORMATION", basic_info, access_time); + TIME_CHECK_DOS("GETATTRE", getattre, access_time); + TIME_CHECK_DOS("STANDARD", standard, access_time); + TIME_CHECK_DOS("EA_SIZE", ea_size, access_time); + TIME_CHECK_NT ("ALL_INFO", all_info, access_time); + TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, access_time); + + s1 = fnum_find("BASIC_INFO"); + correct_time = s1->basic_info.out.write_time; + printf("write_time : %s\n", nt_time_string(mem_ctx, &correct_time)); + + TIME_CHECK_NT ("BASIC_INFO", basic_info, write_time); + TIME_CHECK_NT ("BASIC_INFORMATION", basic_info, write_time); + TIME_CHECK_DOS("GETATTRE", getattre, write_time); + TIME_CHECK_DOS("STANDARD", standard, write_time); + TIME_CHECK_DOS("EA_SIZE", ea_size, write_time); + TIME_CHECK_NT ("ALL_INFO", all_info, write_time); + TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, write_time); + + s1 = fnum_find("BASIC_INFO"); + correct_time = s1->basic_info.out.change_time; + printf("change_time: %s\n", nt_time_string(mem_ctx, &correct_time)); + + TIME_CHECK_NT ("BASIC_INFO", basic_info, change_time); + TIME_CHECK_NT ("BASIC_INFORMATION", basic_info, change_time); + TIME_CHECK_NT ("ALL_INFO", all_info, change_time); + TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, change_time); + + +#define SIZE_CHECK(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && s1->stype.out.tfield != correct_size) { \ + printf("(%d) handle %s/%s incorrect - %u should be %u\n", __LINE__, #stype, #tfield, \ + (unsigned)s1->stype.out.tfield, \ + (unsigned)correct_size); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && s1->stype.out.tfield != correct_size) { \ + printf("(%d) path %s/%s incorrect - %u should be %u\n", __LINE__, #stype, #tfield, \ + (unsigned)s1->stype.out.tfield, \ + (unsigned)correct_size); \ + ret = False; \ + }} while (0) + + s1 = fnum_find("STANDARD_INFO"); + correct_size = s1->standard_info.out.size; + printf("size: %u\n", (unsigned)correct_size); + + SIZE_CHECK("GETATTR", getattr, size); + SIZE_CHECK("GETATTRE", getattre, size); + SIZE_CHECK("STANDARD", standard, size); + SIZE_CHECK("EA_SIZE", ea_size, size); + SIZE_CHECK("STANDARD_INFO", standard_info, size); + SIZE_CHECK("STANDARD_INFORMATION", standard_info, size); + SIZE_CHECK("ALL_INFO", all_info, size); + SIZE_CHECK("ALL_INFORMATION", all_info, size); + SIZE_CHECK("COMPRESSION_INFO", compression_info, compressed_size); + SIZE_CHECK("COMPRESSION_INFORMATION", compression_info, compressed_size); + SIZE_CHECK("NETWORK_OPEN_INFORMATION", network_open_information, size); + if (!skip_streams) { + SIZE_CHECK("STREAM_INFO", stream_info, streams[0].size); + SIZE_CHECK("STREAM_INFORMATION", stream_info, streams[0].size); + } + + + s1 = fnum_find("STANDARD_INFO"); + correct_size = s1->standard_info.out.alloc_size; + printf("alloc_size: %u\n", (unsigned)correct_size); + + SIZE_CHECK("GETATTRE", getattre, alloc_size); + SIZE_CHECK("STANDARD", standard, alloc_size); + SIZE_CHECK("EA_SIZE", ea_size, alloc_size); + SIZE_CHECK("STANDARD_INFO", standard_info, alloc_size); + SIZE_CHECK("STANDARD_INFORMATION", standard_info, alloc_size); + SIZE_CHECK("ALL_INFO", all_info, alloc_size); + SIZE_CHECK("ALL_INFORMATION", all_info, alloc_size); + SIZE_CHECK("NETWORK_OPEN_INFORMATION", network_open_information, alloc_size); + if (!skip_streams) { + SIZE_CHECK("STREAM_INFO", stream_info, streams[0].alloc_size); + SIZE_CHECK("STREAM_INFORMATION", stream_info, streams[0].alloc_size); + } + +#define ATTRIB_CHECK(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && s1->stype.out.tfield != correct_attrib) { \ + printf("(%d) handle %s/%s incorrect - 0x%x should be 0x%x\n", __LINE__, #stype, #tfield, \ + (unsigned)s1->stype.out.tfield, \ + (unsigned)correct_attrib); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && s1->stype.out.tfield != correct_attrib) { \ + printf("(%d) path %s/%s incorrect - 0x%x should be 0x%x\n", __LINE__, #stype, #tfield, \ + (unsigned)s1->stype.out.tfield, \ + (unsigned)correct_attrib); \ + ret = False; \ + }} while (0) + + s1 = fnum_find("BASIC_INFO"); + correct_attrib = s1->basic_info.out.attrib; + printf("attrib: 0x%x\n", (unsigned)correct_attrib); + + ATTRIB_CHECK("GETATTR", getattr, attrib); + ATTRIB_CHECK("GETATTRE", getattre, attrib); + ATTRIB_CHECK("STANDARD", standard, attrib); + ATTRIB_CHECK("BASIC_INFO", basic_info, attrib); + ATTRIB_CHECK("BASIC_INFORMATION", basic_info, attrib); + ATTRIB_CHECK("EA_SIZE", ea_size, attrib); + ATTRIB_CHECK("ALL_INFO", all_info, attrib); + ATTRIB_CHECK("ALL_INFORMATION", all_info, attrib); + ATTRIB_CHECK("NETWORK_OPEN_INFORMATION", network_open_information, attrib); + ATTRIB_CHECK("ATTRIBUTE_TAG_INFORMATION", attribute_tag_information, attrib); + + correct_name = fname; + printf("name: %s\n", correct_name); + +#define NAME_CHECK(sname, stype, tfield, flags) do { \ + s1 = fnum_find(sname); \ + if ((s1 && strcmp(s1->stype.out.tfield.s, correct_name) != 0) || \ + wire_bad_flags(&s1->stype.out.tfield, flags)) { \ + printf("(%d) handle %s/%s incorrect - '%s/%d'\n", __LINE__, #stype, #tfield, \ + s1->stype.out.tfield.s, s1->stype.out.tfield.private_length); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if ((s1 && strcmp(s1->stype.out.tfield.s, correct_name)) != 0 || \ + wire_bad_flags(&s1->stype.out.tfield, flags)) { \ + printf("(%d) path %s/%s incorrect - '%s/%d'\n", __LINE__, #stype, #tfield, \ + s1->stype.out.tfield.s, s1->stype.out.tfield.private_length); \ + ret = False; \ + }} while (0) + + NAME_CHECK("NAME_INFO", name_info, fname, STR_UNICODE); + NAME_CHECK("NAME_INFORMATION", name_info, fname, STR_UNICODE); + + /* the ALL_INFO file name is the full path on the filesystem */ + s1 = fnum_find("ALL_INFO"); + if (s1 && !s1->all_info.out.fname.s) { + printf("ALL_INFO didn't give a filename\n"); + ret = False; + } + if (s1 && s1->all_info.out.fname.s) { + char *p = strrchr(s1->all_info.out.fname.s, '\\'); + if (!p) { + printf("Not a full path in all_info/fname? - '%s'\n", + s1->all_info.out.fname.s); + ret = False; + } else { + if (strcmp(correct_name, p) != 0) { + printf("incorrect basename in all_info/fname - '%s'\n", + s1->all_info.out.fname.s); + ret = False; + } + } + if (wire_bad_flags(&s1->all_info.out.fname, STR_UNICODE)) { + printf("Should not null terminate all_info/fname\n"); + ret = False; + } + } + + s1 = fnum_find("ALT_NAME_INFO"); + correct_name = s1->alt_name_info.out.fname.s; + printf("alt_name: %s\n", correct_name); + + NAME_CHECK("ALT_NAME_INFO", alt_name_info, fname, STR_UNICODE); + NAME_CHECK("ALT_NAME_INFORMATION", alt_name_info, fname, STR_UNICODE); + + /* and make sure we can open by alternate name */ + cli_close(cli, fnum); + fnum = cli_nt_create_full(cli, correct_name, 0, NT_ACCESS_GENERIC_ALL_ACCESS, + FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_DELETE| + NTCREATEX_SHARE_ACCESS_READ| + NTCREATEX_SHARE_ACCESS_WRITE, + FILE_OVERWRITE_IF, + 0, 0); + if (fnum == -1) { + printf("Unable to open by alt_name - %s\n", cli_errstr(cli)); + ret = False; + } + + if (!skip_streams) { + correct_name = "::$DATA"; + printf("stream_name: %s\n", correct_name); + + NAME_CHECK("STREAM_INFO", stream_info, streams[0].stream_name, STR_UNICODE); + NAME_CHECK("STREAM_INFORMATION", stream_info, streams[0].stream_name, STR_UNICODE); + } + + /* make sure the EAs look right */ + s1 = fnum_find("ALL_EAS"); + if (s1) { + printf("ea_size: %d\n", s1->all_eas.out.ea_size); + for (i=0;i<s1->all_eas.out.num_eas;i++) { + printf(" flags=%d %s=%*.*s\n", + s1->all_eas.out.eas[i].flags, + s1->all_eas.out.eas[i].name.s, + s1->all_eas.out.eas[i].value.length, + s1->all_eas.out.eas[i].value.length, + s1->all_eas.out.eas[i].value.data); + } + } + + +#define VAL_CHECK(sname1, stype1, tfield1, sname2, stype2, tfield2) do { \ + s1 = fnum_find(sname1); s2 = fnum_find(sname2); \ + if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \ + printf("(%d) handle %s/%s != %s/%s - 0x%x vs 0x%x\n", __LINE__, \ + #stype1, #tfield1, #stype2, #tfield2, \ + s1->stype1.out.tfield1, s2->stype2.out.tfield2); \ + ret = False; \ + } \ + s1 = fname_find(sname1); s2 = fname_find(sname2); \ + if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \ + printf("(%d) path %s/%s != %s/%s - 0x%x vs 0x%x\n", __LINE__, \ + #stype1, #tfield1, #stype2, #tfield2, \ + s1->stype1.out.tfield1, s2->stype2.out.tfield2); \ + ret = False; \ + } \ + s1 = fnum_find(sname1); s2 = fname_find(sname2); \ + if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \ + printf("(%d) handle %s/%s != path %s/%s - 0x%x vs 0x%x\n", __LINE__, \ + #stype1, #tfield1, #stype2, #tfield2, \ + s1->stype1.out.tfield1, s2->stype2.out.tfield2); \ + ret = False; \ + } \ + s1 = fname_find(sname1); s2 = fnum_find(sname2); \ + if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \ + printf("(%d) path %s/%s != handle %s/%s - 0x%x vs 0x%x\n", __LINE__, \ + #stype1, #tfield1, #stype2, #tfield2, \ + s1->stype1.out.tfield1, s2->stype2.out.tfield2); \ + ret = False; \ + }} while (0) + + VAL_CHECK("STANDARD_INFO", standard_info, delete_pending, + "ALL_INFO", all_info, delete_pending); + VAL_CHECK("STANDARD_INFO", standard_info, directory, + "ALL_INFO", all_info, directory); + VAL_CHECK("STANDARD_INFO", standard_info, nlink, + "ALL_INFO", all_info, nlink); + VAL_CHECK("EA_INFO", ea_info, ea_size, + "ALL_INFO", all_info, ea_size); + VAL_CHECK("ALL_EAS", all_eas, ea_size, + "ALL_INFO", all_info, ea_size); + VAL_CHECK("EA_SIZE", ea_size, ea_size, + "ALL_INFO", all_info, ea_size); + +#define UNKNOWN_CHECK(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && s1->stype.out.tfield != 0) { \ + printf("(%d) handle %s/%s unknown != 0 (0x%x)\n", __LINE__, \ + #stype, #tfield, \ + (unsigned)s1->stype.out.tfield); \ + } \ + s1 = fname_find(sname); \ + if (s1 && s1->stype.out.tfield != 0) { \ + printf("(%d) path %s/%s unknown != 0 (0x%x)\n", __LINE__, \ + #stype, #tfield, \ + (unsigned)s1->stype.out.tfield); \ + }} while (0) + + /* now get a bit fancier .... */ + + /* when we set the delete disposition then the link count should drop + to 0 and delete_pending should be 1 */ + + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/qfsinfo.c b/source4/torture/qfsinfo.c new file mode 100644 index 0000000000..fc4947e158 --- /dev/null +++ b/source4/torture/qfsinfo.c @@ -0,0 +1,286 @@ +/* + Unix SMB/CIFS implementation. + RAW_QFS_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +static struct { + const char *name; + enum fsinfo_level level; + NTSTATUS status; + union smb_fsinfo fsinfo; +} levels[] = { + {"DSKATTR", RAW_QFS_DSKATTR, }, + {"ALLOCATION", RAW_QFS_ALLOCATION, }, + {"VOLUME", RAW_QFS_VOLUME, }, + {"VOLUME_INFO", RAW_QFS_VOLUME_INFO, }, + {"SIZE_INFO", RAW_QFS_SIZE_INFO, }, + {"DEVICE_INFO", RAW_QFS_DEVICE_INFO, }, + {"ATTRIBUTE_INFO", RAW_QFS_ATTRIBUTE_INFO, }, + {"VOLUME_INFORMATION", RAW_QFS_VOLUME_INFORMATION, }, + {"SIZE_INFORMATION", RAW_QFS_SIZE_INFORMATION, }, + {"DEVICE_INFORMATION", RAW_QFS_DEVICE_INFORMATION, }, + {"ATTRIBUTE_INFORMATION", RAW_QFS_ATTRIBUTE_INFORMATION, }, + {"QUOTA_INFORMATION", RAW_QFS_QUOTA_INFORMATION, }, + {"FULL_SIZE_INFORMATION", RAW_QFS_FULL_SIZE_INFORMATION, }, + {"OBJECTID_INFORMATION", RAW_QFS_OBJECTID_INFORMATION, }, + { NULL, } +}; + + +/* + find a level in the levels[] table +*/ +static union smb_fsinfo *find(const char *name) +{ + int i; + for (i=0; levels[i].name; i++) { + if (strcmp(name, levels[i].name) == 0) { + return &levels[i].fsinfo; + } + } + return NULL; +} + +/* local macros to make the code below more readable */ +#define VAL_EQUAL(n1, v1, n2, v2) do {if (s1->n1.out.v1 != s2->n2.out.v2) { \ + printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \ + #n1, #v1, (uint_t)s1->n1.out.v1, \ + #n2, #v2, (uint_t)s2->n2.out.v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +#define STR_EQUAL(n1, v1, n2, v2) do {if (!s1->n1.out.v1 && !s2->n2.out.v2) return True; \ + if (!s1->n1.out.v1 || !s2->n2.out.v2) return False; \ + if (strcmp(s1->n1.out.v1, s2->n2.out.v2)) { \ + printf("%s/%s [%s] != %s/%s [%s] at %s(%d)\n", \ + #n1, #v1, s1->n1.out.v1, \ + #n2, #v2, s2->n2.out.v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +#define STRUCT_EQUAL(n1, v1, n2, v2) do {if (memcmp(&s1->n1.out.v1,&s2->n2.out.v2,sizeof(s1->n1.out.v1))) { \ + printf("%s/%s != %s/%s at %s(%d)\n", \ + #n1, #v1, \ + #n2, #v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +/* used to find hints on unknown values - and to make sure + we zero-fill */ +#define VAL_UNKNOWN(n1, v1) do {if (s1->n1.out.v1 != 0) { \ + printf("%s/%s non-zero unknown - %u (0x%x) at %s(%d)\n", \ + #n1, #v1, \ + (uint_t)s1->n1.out.v1, \ + (uint_t)s1->n1.out.v1, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +/* basic testing of all RAW_QFS_* calls + for each call we test that it succeeds, and where possible test + for consistency between the calls. + + Some of the consistency tests assume that the target filesystem is + quiescent, which is sometimes hard to achieve +*/ +BOOL torture_qfsinfo(int dummy) +{ + struct cli_state *cli; + int i; + BOOL ret = True; + int count; + union smb_fsinfo *s1, *s2; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_qfsinfo"); + + /* scan all the levels, pulling the results */ + for (i=0; levels[i].name; i++) { + levels[i].fsinfo.generic.level = levels[i].level; + levels[i].status = smb_raw_fsinfo(cli->tree, mem_ctx, &levels[i].fsinfo); + } + + /* check for completely broken levels */ + for (count=i=0; levels[i].name; i++) { + if (!NT_STATUS_IS_OK(levels[i].status)) { + printf("ERROR: level %s failed - %s\n", levels[i].name, nt_errstr(levels[i].status)); + count++; + } + } + + if (count != 0) { + ret = False; + printf("%d levels failed\n", count); + if (count > 10) { + printf("too many level failures - giving up\n"); + goto done; + } + } + + /* check for correct aliases */ + s1 = find("SIZE_INFO"); + s2 = find("SIZE_INFORMATION"); + if (s1 && s2) { + VAL_EQUAL(size_info, total_alloc_units, size_info, total_alloc_units); + VAL_EQUAL(size_info, avail_alloc_units, size_info, avail_alloc_units); + VAL_EQUAL(size_info, sectors_per_unit, size_info, sectors_per_unit); + VAL_EQUAL(size_info, bytes_per_sector, size_info, bytes_per_sector); + } + + s1 = find("DEVICE_INFO"); + s2 = find("DEVICE_INFORMATION"); + if (s1 && s2) { + VAL_EQUAL(device_info, device_type, device_info, device_type); + VAL_EQUAL(device_info, characteristics, device_info, characteristics); + } + + s1 = find("VOLUME_INFO"); + s2 = find("VOLUME_INFORMATION"); + if (s1 && s2) { + STRUCT_EQUAL(volume_info, create_time, volume_info, create_time); + VAL_EQUAL (volume_info, serial_number, volume_info, serial_number); + STR_EQUAL (volume_info, volume_name.s, volume_info, volume_name.s); + printf("volume_info.volume_name = '%s'\n", s1->volume_info.out.volume_name.s); + } + + s1 = find("ATTRIBUTE_INFO"); + s2 = find("ATTRIBUTE_INFORMATION"); + if (s1 && s2) { + VAL_EQUAL(attribute_info, fs_attr, + attribute_info, fs_attr); + VAL_EQUAL(attribute_info, max_file_component_length, + attribute_info, max_file_component_length); + STR_EQUAL(attribute_info, fs_type.s, attribute_info, fs_type.s); + printf("attribute_info.fs_type = '%s'\n", s1->attribute_info.out.fs_type.s); + } + + /* check for consistent disk sizes */ + s1 = find("DSKATTR"); + s2 = find("ALLOCATION"); + if (s1 && s2) { + double size1, size2; + double scale = s1->dskattr.out.blocks_per_unit * s1->dskattr.out.block_size; + size1 = 1.0 * + s1->dskattr.out.units_total * + s1->dskattr.out.blocks_per_unit * + s1->dskattr.out.block_size / scale; + size2 = 1.0 * + s2->allocation.out.sectors_per_unit * + s2->allocation.out.total_alloc_units * + s2->allocation.out.bytes_per_sector / scale; + if (ABS(size1 - size2) > 1) { + printf("Inconsistent total size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", + size1, size2); + ret = False; + } + printf("total disk = %.0f MB\n", size1*scale/1.0e6); + } + + /* and for consistent free disk space */ + s1 = find("DSKATTR"); + s2 = find("ALLOCATION"); + if (s1 && s2) { + double size1, size2; + double scale = s1->dskattr.out.blocks_per_unit * s1->dskattr.out.block_size; + size1 = 1.0 * + s1->dskattr.out.units_free * + s1->dskattr.out.blocks_per_unit * + s1->dskattr.out.block_size / scale; + size2 = 1.0 * + s2->allocation.out.sectors_per_unit * + s2->allocation.out.avail_alloc_units * + s2->allocation.out.bytes_per_sector / scale; + if (ABS(size1 - size2) > 1) { + printf("Inconsistent avail size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", + size1, size2); + ret = False; + } + printf("free disk = %.0f MB\n", size1*scale/1.0e6); + } + + /* volume info consistency */ + s1 = find("VOLUME"); + s2 = find("VOLUME_INFO"); + if (s1 && s2) { + VAL_EQUAL(volume, serial_number, volume_info, serial_number); + STR_EQUAL(volume, volume_name.s, volume_info, volume_name.s); + } + + /* disk size consistency - notice that 'avail_alloc_units' maps to the caller + available allocation units, not the total */ + s1 = find("SIZE_INFO"); + s2 = find("FULL_SIZE_INFORMATION"); + if (s1 && s2) { + VAL_EQUAL(size_info, total_alloc_units, full_size_information, total_alloc_units); + VAL_EQUAL(size_info, avail_alloc_units, full_size_information, call_avail_alloc_units); + VAL_EQUAL(size_info, sectors_per_unit, full_size_information, sectors_per_unit); + VAL_EQUAL(size_info, bytes_per_sector, full_size_information, bytes_per_sector); + } + + /* check for non-zero unknown fields - if we find them + they might give us some hints */ + s1 = find("QUOTA_INFORMATION"); + if (s1) { + VAL_UNKNOWN(quota_information, unknown[0]); + VAL_UNKNOWN(quota_information, unknown[1]); + VAL_UNKNOWN(quota_information, unknown[2]); + } + + s1 = find("OBJECTID_INFORMATION"); + if (s1) { + VAL_UNKNOWN(objectid_information, unknown[0]); + VAL_UNKNOWN(objectid_information, unknown[1]); + VAL_UNKNOWN(objectid_information, unknown[2]); + VAL_UNKNOWN(objectid_information, unknown[3]); + VAL_UNKNOWN(objectid_information, unknown[4]); + VAL_UNKNOWN(objectid_information, unknown[5]); + } + + +#define STR_CHECK(sname, stype, field, flags) do { \ + s1 = find(sname); \ + if (s1) { \ + if (wire_bad_flags(&s1->stype.out.field, flags)) { \ + printf("(%d) incorrect string termination in %s/%s\n", \ + __LINE__, #stype, #field); \ + ret = False; \ + } \ + }} while (0) + + /* check for correct termination */ + STR_CHECK("VOLUME", volume, volume_name, 0); + STR_CHECK("VOLUME_INFO", volume_info, volume_name, STR_UNICODE); + STR_CHECK("VOLUME_INFORMATION", volume_info, volume_name, STR_UNICODE); + STR_CHECK("ATTRIBUTE_INFO", attribute_info, fs_type, STR_UNICODE); + STR_CHECK("ATTRIBUTE_INFORMATION", attribute_info, fs_type, STR_UNICODE); + +done: + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/chkpath.c b/source4/torture/raw/chkpath.c new file mode 100644 index 0000000000..3364c39a73 --- /dev/null +++ b/source4/torture/raw/chkpath.c @@ -0,0 +1,142 @@ +/* + Unix SMB/CIFS implementation. + chkpath individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define BASEDIR "\\rawchkpath" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + + +static BOOL test_chkpath(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + struct smb_chkpath io; + NTSTATUS status; + BOOL ret = True; + int fnum = -1; + + io.in.path = BASEDIR; + + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + io.in.path = BASEDIR "\\nodir"; + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + + fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\test.txt"); + if (fnum == -1) { + printf("failed to open test.txt - %s\n", cli_errstr(cli)); + ret = False; + goto done; + } + + io.in.path = BASEDIR "\\test.txt"; + printf("testing %s\n", io.in.path); + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY); + + if (!torture_set_file_attribute(cli->tree, BASEDIR, FILE_ATTRIBUTE_HIDDEN)) { + printf("failed to set basedir hidden\n"); + ret = False; + goto done; + } + + io.in.path = BASEDIR; + printf("testing %s\n", io.in.path); + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + io.in.path = ""; + printf("testing %s\n", io.in.path); + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + io.in.path = "."; + printf("testing %s\n", io.in.path); + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID); + + io.in.path = "\\"; + printf("testing %s\n", io.in.path); + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + io.in.path = "\\."; + printf("testing %s\n", io.in.path); + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID); + + io.in.path = "\\.."; + printf("testing %s\n", io.in.path); + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD); + + io.in.path = BASEDIR "\\.."; + printf("testing %s\n", io.in.path); + status = smb_raw_chkpath(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + +done: + cli_close(cli, fnum); + return ret; +} + +/* + basic testing of chkpath calls +*/ +BOOL torture_raw_chkpath(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_chkpath"); + + if (cli_deltree(cli, BASEDIR) == -1) { + printf("Failed to clean " BASEDIR "\n"); + return False; + } + if (!cli_mkdir(cli, BASEDIR)) { + printf("Failed to create " BASEDIR " - %s\n", cli_errstr(cli)); + return False; + } + + if (!test_chkpath(cli, mem_ctx)) { + ret = False; + } + + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/close.c b/source4/torture/raw/close.c new file mode 100644 index 0000000000..40bb57f303 --- /dev/null +++ b/source4/torture/raw/close.c @@ -0,0 +1,170 @@ +/* + Unix SMB/CIFS implementation. + RAW_CLOSE_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +/* basic testing of all RAW_CLOSE_* calls +*/ +BOOL torture_raw_close(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + union smb_close io; + struct smb_flush io_flush; + int fnum; + const char *fname = "\\torture_close.txt"; + time_t basetime = (time(NULL) + 3*86400) & ~1; + union smb_fileinfo finfo, finfo2; + NTSTATUS status; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_close"); + +#define REOPEN do { \ + fnum = create_complex_file(cli, mem_ctx, fname); \ + if (fnum == -1) { \ + printf("(%d) Failed to create %s\n", __LINE__, fname); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + + REOPEN; + + io.close.level = RAW_CLOSE_CLOSE; + io.close.in.fnum = fnum; + io.close.in.write_time = basetime; + status = smb_raw_close(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb_raw_close(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("testing close.in.write_time\n"); + + /* the file should have the write time set */ + finfo.generic.in.fname = fname; + finfo.generic.level = RAW_FILEINFO_ALL_INFO; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); + CHECK_STATUS(status, NT_STATUS_OK); + + if (basetime != nt_time_to_unix(&finfo.all_info.out.write_time)) { + printf("Incorrect write time on file - %s - %s\n", + time_string(mem_ctx, basetime), + nt_time_string(mem_ctx, &finfo.all_info.out.write_time)); + dump_all_info(mem_ctx, &finfo); + ret = False; + } + + printf("testing other times\n"); + + /* none of the other times should be set to that time */ + if (nt_time_equal(&finfo.all_info.out.write_time, + &finfo.all_info.out.access_time) || + nt_time_equal(&finfo.all_info.out.write_time, + &finfo.all_info.out.create_time) || + nt_time_equal(&finfo.all_info.out.write_time, + &finfo.all_info.out.change_time)) { + printf("Incorrect times after close - only write time should be set\n"); + dump_all_info(mem_ctx, &finfo); + ret = False; + } + + + cli_unlink(cli, fname); + REOPEN; + + finfo2.generic.in.fname = fname; + finfo2.generic.level = RAW_FILEINFO_ALL_INFO; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); + CHECK_STATUS(status, NT_STATUS_OK); + + io.close.level = RAW_CLOSE_CLOSE; + io.close.in.fnum = fnum; + io.close.in.write_time = 0; + status = smb_raw_close(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + /* the file should have the write time set equal to access time */ + finfo.generic.in.fname = fname; + finfo.generic.level = RAW_FILEINFO_ALL_INFO; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); + CHECK_STATUS(status, NT_STATUS_OK); + + if (!nt_time_equal(&finfo.all_info.out.write_time, + &finfo2.all_info.out.write_time)) { + printf("Incorrect write time on file - 0 time should be ignored\n"); + dump_all_info(mem_ctx, &finfo); + ret = False; + } + + printf("testing splclose\n"); + + /* check splclose on a file */ + REOPEN; + io.splclose.level = RAW_CLOSE_SPLCLOSE; + io.splclose.in.fnum = fnum; + status = smb_raw_close(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL); + + printf("testing flush\n"); + cli_close(cli, fnum); + + io_flush.in.fnum = fnum; + status = smb_raw_flush(cli->tree, &io_flush); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + io_flush.in.fnum = 0xffff; + status = smb_raw_flush(cli->tree, &io_flush); + CHECK_STATUS(status, NT_STATUS_OK); + + REOPEN; + + io_flush.in.fnum = fnum; + status = smb_raw_flush(cli->tree, &io_flush); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Testing SMBexit\n"); + smb_raw_exit(cli->session); + + io_flush.in.fnum = fnum; + status = smb_raw_flush(cli->tree, &io_flush); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/context.c b/source4/torture/raw/context.c new file mode 100644 index 0000000000..c19fea458d --- /dev/null +++ b/source4/torture/raw/context.c @@ -0,0 +1,388 @@ +/* + Unix SMB/CIFS implementation. + test suite for session setup operations + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define BASEDIR "\\rawcontext" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_VALUE(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) Incorrect value %s=%d - should be %d\n", \ + __LINE__, #v, v, correct); \ + ret = False; \ + goto done; \ + }} while (0) + + +/* + test session ops +*/ +static BOOL test_session(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + NTSTATUS status; + BOOL ret = True; + char *username, *domain, *password; + struct cli_session *session; + struct cli_tree *tree; + union smb_sesssetup setup; + union smb_open io; + union smb_write wr; + union smb_close cl; + int fnum; + const char *fname = BASEDIR "\\test.txt"; + char c = 1; + + printf("TESTING SESSION HANDLING\n"); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + username = lp_parm_string(-1, "torture", "username"); + password = lp_parm_string(-1, "torture", "password"); + domain = lp_workgroup(); + + printf("create a second security context on the same transport\n"); + session = cli_session_init(cli->transport); + setup.generic.level = RAW_SESSSETUP_GENERIC; + setup.generic.in.sesskey = cli->transport->negotiate.sesskey; + setup.generic.in.capabilities = 0; /* ignored in secondary session setup */ + setup.generic.in.password = password; + setup.generic.in.user = username; + setup.generic.in.domain = domain; + + status = smb_raw_session_setup(session, mem_ctx, &setup); + CHECK_STATUS(status, NT_STATUS_OK); + + session->vuid = setup.generic.out.vuid; + + printf("use the same tree as the existing connection\n"); + tree = cli_tree_init(session); + tree->tid = cli->tree->tid; + cli->tree->reference_count++; + + printf("vuid1=%d vuid2=%d\n", cli->session->vuid, session->vuid); + + printf("create a file using the new vuid\n"); + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED; + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = fname; + status = smb_raw_open(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + printf("write using the old vuid\n"); + wr.generic.level = RAW_WRITE_WRITEX; + wr.writex.in.fnum = fnum; + wr.writex.in.offset = 0; + wr.writex.in.wmode = 0; + wr.writex.in.remaining = 0; + wr.writex.in.count = 1; + wr.writex.in.data = &c; + + status = smb_raw_write(cli->tree, &wr); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("write with the new vuid\n"); + status = smb_raw_write(tree, &wr); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(wr.writex.out.nwritten, 1); + + printf("logoff the new vuid\n"); + status = smb_raw_ulogoff(session); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("the new vuid should not now be accessible\n"); + status = smb_raw_write(tree, &wr); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("the fnum should have been auto-closed\n"); + cl.close.level = RAW_CLOSE_CLOSE; + cl.close.in.fnum = fnum; + cl.close.in.write_time = 0; + status = smb_raw_close(cli->tree, &cl); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + /* close down the new tree, which will also close the session + as the reference count will be 0 */ + cli_tree_close(tree); + +done: + return ret; +} + + +/* + test tree ops +*/ +static BOOL test_tree(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + NTSTATUS status; + BOOL ret = True; + char *share; + struct cli_tree *tree; + union smb_tcon tcon; + union smb_open io; + union smb_write wr; + union smb_close cl; + int fnum; + const char *fname = BASEDIR "\\test.txt"; + char c = 1; + + printf("TESTING TREE HANDLING\n"); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + share = lp_parm_string(-1, "torture", "share"); + + printf("create a second tree context on the same session\n"); + tree = cli_tree_init(cli->session); + + tcon.generic.level = RAW_TCON_TCONX; + tcon.tconx.in.flags = 0; + tcon.tconx.in.password = data_blob(NULL, 0); + tcon.tconx.in.path = share; + tcon.tconx.in.device = "A:"; + status = smb_tree_connect(tree, mem_ctx, &tcon); + CHECK_STATUS(status, NT_STATUS_OK); + + tree->tid = tcon.tconx.out.cnum; + printf("tid1=%d tid2=%d\n", cli->tree->tid, tree->tid); + + printf("try a tconx with a bad device type\n"); + tcon.tconx.in.device = "FOO"; + status = smb_tree_connect(tree, mem_ctx, &tcon); + CHECK_STATUS(status, NT_STATUS_BAD_DEVICE_TYPE); + + + printf("create a file using the new tid\n"); + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED; + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = fname; + status = smb_raw_open(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + printf("write using the old tid\n"); + wr.generic.level = RAW_WRITE_WRITEX; + wr.writex.in.fnum = fnum; + wr.writex.in.offset = 0; + wr.writex.in.wmode = 0; + wr.writex.in.remaining = 0; + wr.writex.in.count = 1; + wr.writex.in.data = &c; + + status = smb_raw_write(cli->tree, &wr); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("write with the new tid\n"); + status = smb_raw_write(tree, &wr); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(wr.writex.out.nwritten, 1); + + printf("disconnect the new tid\n"); + status = smb_tree_disconnect(tree); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("the new tid should not now be accessible\n"); + status = smb_raw_write(tree, &wr); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("the fnum should have been auto-closed\n"); + cl.close.level = RAW_CLOSE_CLOSE; + cl.close.in.fnum = fnum; + cl.close.in.write_time = 0; + status = smb_raw_close(cli->tree, &cl); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + /* close down the new tree */ + cli_tree_close(tree); + +done: + return ret; +} + + +/* + test pid ops +*/ +static BOOL test_pid(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + NTSTATUS status; + BOOL ret = True; + union smb_open io; + union smb_write wr; + union smb_close cl; + int fnum; + const char *fname = BASEDIR "\\test.txt"; + char c = 1; + uint16 pid1, pid2; + + printf("TESTING PID HANDLING\n"); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("create a second pid\n"); + pid1 = cli->session->pid; + pid2 = pid1+1; + + printf("pid1=%d pid2=%d\n", pid1, pid2); + + printf("create a file using the new pid\n"); + cli->session->pid = pid2; + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED; + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = fname; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + printf("write using the old pid\n"); + cli->session->pid = pid1; + wr.generic.level = RAW_WRITE_WRITEX; + wr.writex.in.fnum = fnum; + wr.writex.in.offset = 0; + wr.writex.in.wmode = 0; + wr.writex.in.remaining = 0; + wr.writex.in.count = 1; + wr.writex.in.data = &c; + + status = smb_raw_write(cli->tree, &wr); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(wr.writex.out.nwritten, 1); + + printf("write with the new pid\n"); + cli->session->pid = pid2; + status = smb_raw_write(cli->tree, &wr); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(wr.writex.out.nwritten, 1); + + printf("exit the old pid\n"); + cli->session->pid = pid1; + status = smb_raw_exit(cli->session); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("the fnum should still be accessible\n"); + cli->session->pid = pid1; + status = smb_raw_write(cli->tree, &wr); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(wr.writex.out.nwritten, 1); + + printf("exit the new pid\n"); + cli->session->pid = pid2; + status = smb_raw_exit(cli->session); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("the fnum should not now be accessible\n"); + cli->session->pid = pid1; + status = smb_raw_write(cli->tree, &wr); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("the fnum should have been auto-closed\n"); + cl.close.level = RAW_CLOSE_CLOSE; + cl.close.in.fnum = fnum; + cl.close.in.write_time = 0; + status = smb_raw_close(cli->tree, &cl); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + +done: + return ret; +} + + +/* + basic testing of session/tree context calls +*/ +BOOL torture_raw_context(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_context"); + + if (!test_session(cli, mem_ctx)) { + ret = False; + } + + if (!test_tree(cli, mem_ctx)) { + ret = False; + } + + if (!test_pid(cli, mem_ctx)) { + ret = False; + } + + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/ioctl.c b/source4/torture/raw/ioctl.c new file mode 100644 index 0000000000..d55db4c1e6 --- /dev/null +++ b/source4/torture/raw/ioctl.c @@ -0,0 +1,156 @@ +/* + Unix SMB/CIFS implementation. + ioctl individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define BASEDIR "\\rawioctl" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + + +/* test some ioctls */ +static BOOL test_ioctl(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + struct smb_ioctl ctl; + int fnum; + NTSTATUS status; + BOOL ret = True; + const char *fname = BASEDIR "\\test.dat"; + + printf("TESTING IOCTL FUNCTIONS\n"); + + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + printf("Failed to create test.dat - %s\n", cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying QUERY_JOB_INFO\n"); + ctl.in.fnum = fnum; + ctl.in.request = IOCTL_QUERY_JOB_INFO; + + status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl); + CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL); + + printf("Trying bad handle\n"); + ctl.in.fnum = fnum+1; + status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl); + CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL); + +done: + cli_close(cli, fnum); + return ret; +} + +/* test some filesystem control functions */ +static BOOL test_fsctl(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + int fnum; + NTSTATUS status; + BOOL ret = True; + const char *fname = BASEDIR "\\test.dat"; + struct smb_ntioctl nt; + + printf("\nTESTING FSCTL FUNCTIONS\n"); + + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + printf("Failed to create test.dat - %s\n", cli_errstr(cli)); + ret = False; + goto done; + } + + printf("trying sparse file\n"); + nt.in.function = FSCTL_SET_SPARSE; + nt.in.fnum = fnum; + nt.in.fsctl = True; + nt.in.filter = 0; + + status = smb_raw_ntioctl(cli->tree, &nt); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying bad handle\n"); + nt.in.fnum = fnum+1; + status = smb_raw_ntioctl(cli->tree, &nt); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + +#if 0 + nt.in.fnum = fnum; + for (i=0;i<100;i++) { + nt.in.function = FSCTL_FILESYSTEM + (i<<2); + status = smb_raw_ntioctl(cli->tree, &nt); + if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) { + printf("filesystem fsctl 0x%x - %s\n", + i, nt_errstr(status)); + } + } +#endif + +done: + cli_close(cli, fnum); + return ret; +} + +/* + basic testing of some ioctl calls +*/ +BOOL torture_raw_ioctl(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_ioctl"); + + if (cli_deltree(cli, BASEDIR) == -1) { + printf("Failed to clean " BASEDIR "\n"); + return False; + } + if (!cli_mkdir(cli, BASEDIR)) { + printf("Failed to create " BASEDIR " - %s\n", cli_errstr(cli)); + return False; + } + + if (!test_ioctl(cli, mem_ctx)) { + ret = False; + } + + if (!test_fsctl(cli, mem_ctx)) { + ret = False; + } + + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/lock.c b/source4/torture/raw/lock.c new file mode 100644 index 0000000000..b0b0b56451 --- /dev/null +++ b/source4/torture/raw/lock.c @@ -0,0 +1,216 @@ +/* + Unix SMB/CIFS implementation. + test suite for various lock operations + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_VALUE(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) Incorrect value %s=%d - should be %d\n", \ + __LINE__, #v, v, correct); \ + ret = False; \ + goto done; \ + }} while (0) + +#define BASEDIR "\\testlock" + + +/* + test SMBlock and SMBunlock ops +*/ +static BOOL test_lock(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_lock io; + NTSTATUS status; + BOOL ret = True; + int fnum; + const char *fname = BASEDIR "\\test.txt"; + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_LOCK_LOCK\n"); + io.generic.level = RAW_LOCK_LOCK; + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying 0/0 lock\n"); + io.lock.level = RAW_LOCK_LOCK; + io.lock.in.fnum = fnum; + io.lock.in.count = 0; + io.lock.in.offset = 0; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli->session->pid++; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli->session->pid--; + io.lock.level = RAW_LOCK_UNLOCK; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying 0/1 lock\n"); + io.lock.level = RAW_LOCK_LOCK; + io.lock.in.fnum = fnum; + io.lock.in.count = 1; + io.lock.in.offset = 0; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli->session->pid++; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED); + cli->session->pid--; + io.lock.level = RAW_LOCK_UNLOCK; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + io.lock.level = RAW_LOCK_UNLOCK; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + + printf("Trying max lock\n"); + io.lock.level = RAW_LOCK_LOCK; + io.lock.in.fnum = fnum; + io.lock.in.count = 4000; + io.lock.in.offset = ~0; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli->session->pid++; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + cli->session->pid--; + io.lock.level = RAW_LOCK_UNLOCK; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + io.lock.level = RAW_LOCK_UNLOCK; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + + printf("Trying wrong pid unlock\n"); + io.lock.level = RAW_LOCK_LOCK; + io.lock.in.fnum = fnum; + io.lock.in.count = 4002; + io.lock.in.offset = 10001; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli->session->pid++; + io.lock.level = RAW_LOCK_UNLOCK; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + cli->session->pid--; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + test locking&X ops +*/ +static BOOL test_lockx(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_lock io; + struct smb_lock_entry lock[1]; + NTSTATUS status; + BOOL ret = True; + int fnum; + const char *fname = BASEDIR "\\test.txt"; + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_LOCK_LOCKX\n"); + io.generic.level = RAW_LOCK_LOCKX; + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + io.lockx.level = RAW_LOCK_LOCKX; + io.lockx.in.fnum = fnum; + io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES; + io.lockx.in.timeout = 0; + io.lockx.in.ulock_cnt = 0; + io.lockx.in.lock_cnt = 1; + lock[0].pid = cli->session->pid; + lock[0].offset = 0; + lock[0].count = 0xFFFFFFFF; + io.lockx.in.locks = &lock[0]; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + basic testing of lock calls +*/ +BOOL torture_raw_lock(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_lock"); + + if (!test_lockx(cli, mem_ctx)) { + ret = False; + } + + if (!test_lock(cli, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/missing.txt b/source4/torture/raw/missing.txt new file mode 100644 index 0000000000..8e026b78ff --- /dev/null +++ b/source4/torture/raw/missing.txt @@ -0,0 +1,157 @@ +- all messaging commands + +- writebraw + +- writebmpx + +- acl ops + +- readbmpx + +- rap commands + +- rpc commands + +- SMBcopy + +- SMBtcon + +- SMBecho + +- SMBfunique + +- SMBsearch vs SMBffirst? + +- SMBfclose + +- SMBkeepalive + +- secondary trans2 and nttrans + +- trans2 ioctl + +- trans2 session setup + +- trans2 DFS ops + +- unix ops + +-------------- +done: + +mkdir +rmdir +open +create +close +flush +unlink +mv +getatr +setatr +read +write +lock +unlock +ctemp +mknew +chkpath +exit +lseek +tconX +tdis +negprot +dskattr +search +lockread +writeunlock +readbraw +setattrE +getattrE +lockingX +ioctl +openX +readX +writeX +sesssetupX +trans2 +findclose +ulogoffX +nttrans +ntcreateX +ntcancel +trans2_open +trans2_findfirst +trans2_findnext? +trans2_qfsinfo +trans2_setfsinfo +trans2_qpathinfo +trans2_setpathinfo +trans2_qfileinfo +trans2_setfileinfo +trans2_fsctl +trans2_mkdir +trans2_findnext +SMB_QFS_ALLOCATION +SMB_QFS_VOLUME +SMB_QFS_VOLUME_INFO +SMB_QFS_SIZE_INFO +SMB_QFS_DEVICE_INFO +SMB_QFS_ATTRIBUTE_INFO +SMB_QFS_VOLUME_INFORMATION +SMB_QFS_SIZE_INFORMATION +SMB_QFS_DEVICE_INFORMATION +SMB_QFS_ATTRIBUTE_INFORMATION +SMB_QFS_QUOTA_INFORMATION +SMB_QFS_FULL_SIZE_INFORMATION +SMB_QFS_OBJECTID_INFORMATION +SMB_QFILEINFO_STANDARD +SMB_QFILEINFO_EA_SIZE +SMB_QFILEINFO_ALL_EAS +SMB_QFILEINFO_IS_NAME_VALID +SMB_QFILEINFO_BASIC_INFO +SMB_QFILEINFO_STANDARD_INFO +SMB_QFILEINFO_EA_INFO +SMB_QFILEINFO_NAME_INFO +SMB_QFILEINFO_ALL_INFO +SMB_QFILEINFO_ALT_NAME_INFO +SMB_QFILEINFO_STREAM_INFO +SMB_QFILEINFO_COMPRESSION_INFO +SMB_QFILEINFO_BASIC_INFORMATION +SMB_QFILEINFO_STANDARD_INFORMATION +SMB_QFILEINFO_INTERNAL_INFORMATION +SMB_QFILEINFO_EA_INFORMATION +SMB_QFILEINFO_ACCESS_INFORMATION +SMB_QFILEINFO_NAME_INFORMATION +SMB_QFILEINFO_POSITION_INFORMATION +SMB_QFILEINFO_MODE_INFORMATION +SMB_QFILEINFO_ALIGNMENT_INFORMATION +SMB_QFILEINFO_ALL_INFORMATION +SMB_QFILEINFO_ALT_NAME_INFORMATION +SMB_QFILEINFO_STREAM_INFORMATION +SMB_QFILEINFO_COMPRESSION_INFORMATION +SMB_QFILEINFO_NETWORK_OPEN_INFORMATION +SMB_QFILEINFO_ATTRIBUTE_TAG_INFORMATION +SMB_SFILEINFO_STANDARD +SMB_SFILEINFO_EA_SET +SMB_SFILEINFO_BASIC_INFO +SMB_SFILEINFO_DISPOSITION_INFO +SMB_SFILEINFO_ALLOCATION_INFO +SMB_SFILEINFO_END_OF_FILE_INFO +SMB_SFILEINFO_UNIX_BASIC +SMB_SFILEINFO_UNIX_LINK +SMB_SFILEINFO_BASIC_INFORMATION +SMB_SFILEINFO_RENAME_INFORMATION +SMB_SFILEINFO_DISPOSITION_INFORMATION +SMB_SFILEINFO_POSITION_INFORMATION +SMB_SFILEINFO_MODE_INFORMATION +SMB_SFILEINFO_ALLOCATION_INFORMATION +SMB_SFILEINFO_END_OF_FILE_INFORMATION +SMB_FIND_STANDARD +SMB_FIND_EA_SIZE +SMB_FIND_DIRECTORY_INFO +SMB_FIND_FULL_DIRECTORY_INFO +SMB_FIND_NAME_INFO +SMB_FIND_BOTH_DIRECTORY_INFO +SMB_FIND_261 +SMB_FIND_262 diff --git a/source4/torture/raw/mkdir.c b/source4/torture/raw/mkdir.c new file mode 100644 index 0000000000..52120f0542 --- /dev/null +++ b/source4/torture/raw/mkdir.c @@ -0,0 +1,141 @@ +/* + Unix SMB/CIFS implementation. + RAW_MKDIR_* and RAW_RMDIR_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +/* + test mkdir ops +*/ +static BOOL test_mkdir(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_mkdir md; + struct smb_rmdir rd; + const char *path = "\\test_mkdir.dir"; + NTSTATUS status; + BOOL ret = True; + + /* cleanup */ + cli_rmdir(cli, path); + cli_unlink(cli, path); + + /* + basic mkdir + */ + md.mkdir.level = RAW_MKDIR_MKDIR; + md.mkdir.in.path = path; + + status = smb_raw_mkdir(cli->tree, &md); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("testing mkdir collision\n"); + + /* 2nd create */ + status = smb_raw_mkdir(cli->tree, &md); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION); + + /* basic rmdir */ + rd.in.path = path; + status = smb_raw_rmdir(cli->tree, &rd); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb_raw_rmdir(cli->tree, &rd); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + + printf("testing mkdir collision with file\n"); + + /* name collision with a file */ + cli_close(cli, create_complex_file(cli, mem_ctx, path)); + status = smb_raw_mkdir(cli->tree, &md); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION); + + printf("testing rmdir with file\n"); + + /* delete a file with rmdir */ + status = smb_raw_rmdir(cli->tree, &rd); + CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY); + + cli_unlink(cli, path); + + printf("testing invalid dir\n"); + + /* create an invalid dir */ + md.mkdir.in.path = "..\\..\\.."; + status = smb_raw_mkdir(cli->tree, &md); + CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD); + + printf("testing t2mkdir\n"); + + /* try a t2mkdir - need to work out why this fails! */ + md.t2mkdir.level = RAW_MKDIR_T2MKDIR; + md.t2mkdir.in.path = path; + md.t2mkdir.in.num_eas = 0; + status = smb_raw_mkdir(cli->tree, &md); + CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL); + + printf("testing t2mkdir with EAs\n"); + + /* with EAs */ + md.t2mkdir.in.num_eas = 1; + md.t2mkdir.in.eas = talloc(mem_ctx, sizeof(md.t2mkdir.in.eas[0])); + md.t2mkdir.in.eas[0].flags = 0; + md.t2mkdir.in.eas[0].name.s = "EAONE"; + md.t2mkdir.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1); + status = smb_raw_mkdir(cli->tree, &md); + CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL); + + +done: + cli_rmdir(cli, path); + cli_unlink(cli, path); + return ret; +} + + +/* + basic testing of all RAW_MKDIR_* calls +*/ +BOOL torture_raw_mkdir(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_mkdir"); + + if (!test_mkdir(cli, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/mux.c b/source4/torture/raw/mux.c new file mode 100644 index 0000000000..05c5e3de09 --- /dev/null +++ b/source4/torture/raw/mux.c @@ -0,0 +1,298 @@ +/* + Unix SMB/CIFS implementation. + basic raw test suite for multiplexing + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define BASEDIR "\\test_mux" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + + +/* + test the delayed reply to a open that leads to a sharing violation +*/ +static BOOL test_mux_open(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_open io; + NTSTATUS status; + int fnum; + BOOL ret = True; + struct cli_request *req; + + printf("testing multiplexed open/open/close\n"); + + /* + file open with no share access + */ + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED; + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = 0; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = BASEDIR "\\open.dat"; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + /* send an open that will conflict */ + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); + + /* + same request, but async + */ + req = smb_raw_open_send(cli->tree, &io); + + /* and close the file */ + cli_close(cli, fnum); + + /* see if the async open succeeded */ + status = smb_raw_open_recv(req, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + cli_close(cli, io.ntcreatex.out.fnum); + +done: + return ret; +} + + +/* + test a write that hits a byte range lock and send the close after the write +*/ +static BOOL test_mux_write(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_write io; + NTSTATUS status; + int fnum; + BOOL ret = True; + struct cli_request *req; + + printf("testing multiplexed lock/write/close\n"); + + fnum = cli_open(cli, BASEDIR "\\write.dat", O_RDWR | O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("open failed in mux_write - %s\n", cli_errstr(cli)); + ret = False; + goto done; + } + + cli->session->pid = 1; + + /* lock a range */ + if (!cli_lock(cli, fnum, 0, 4, 0, WRITE_LOCK)) { + printf("lock failed in mux_write - %s\n", cli_errstr(cli)); + ret = False; + goto done; + } + + cli->session->pid = 2; + + /* send an async write */ + io.generic.level = RAW_WRITE_WRITEX; + io.writex.in.fnum = fnum; + io.writex.in.offset = 0; + io.writex.in.wmode = 0; + io.writex.in.remaining = 0; + io.writex.in.count = 4; + io.writex.in.data = (void *)&fnum; + req = smb_raw_write_send(cli->tree, &io); + + /* unlock the range */ + cli->session->pid = 1; + cli_unlock(cli, fnum, 0, 4); + + /* and recv the async write reply */ + status = smb_raw_write_recv(req, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + cli_close(cli, fnum); + +done: + return ret; +} + + +/* + test a lock that conflicts with an existing lock +*/ +static BOOL test_mux_lock(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_lock io; + NTSTATUS status; + int fnum; + BOOL ret = True; + struct cli_request *req; + struct smb_lock_entry lock[1]; + + printf("TESTING MULTIPLEXED LOCK/LOCK/UNLOCK\n"); + + fnum = cli_open(cli, BASEDIR "\\write.dat", O_RDWR | O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("open failed in mux_write - %s\n", cli_errstr(cli)); + ret = False; + goto done; + } + + printf("establishing a lock\n"); + io.lockx.level = RAW_LOCK_LOCKX; + io.lockx.in.fnum = fnum; + io.lockx.in.mode = 0; + io.lockx.in.timeout = 0; + io.lockx.in.lock_cnt = 1; + io.lockx.in.ulock_cnt = 0; + lock[0].pid = 1; + lock[0].offset = 0; + lock[0].count = 4; + io.lockx.in.locks = &lock[0]; + + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("the second lock will conflict with the first\n"); + lock[0].pid = 2; + io.lockx.in.timeout = 1000; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + printf("this will too, but we'll unlock while waiting\n"); + req = smb_raw_lock_send(cli->tree, &io); + + printf("unlock the first range\n"); + lock[0].pid = 1; + io.lockx.in.ulock_cnt = 1; + io.lockx.in.lock_cnt = 0; + io.lockx.in.timeout = 0; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("recv the async reply\n"); + status = cli_request_simple_recv(req); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("reopening with an exit\n"); + smb_raw_exit(cli->session); + fnum = cli_open(cli, BASEDIR "\\write.dat", O_RDWR | O_CREAT, DENY_NONE); + + printf("Now trying with a cancel\n"); + + io.lockx.level = RAW_LOCK_LOCKX; + io.lockx.in.fnum = fnum; + io.lockx.in.mode = 0; + io.lockx.in.timeout = 0; + io.lockx.in.lock_cnt = 1; + io.lockx.in.ulock_cnt = 0; + lock[0].pid = 1; + lock[0].offset = 0; + lock[0].count = 4; + io.lockx.in.locks = &lock[0]; + + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + lock[0].pid = 2; + io.lockx.in.timeout = 1000; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + req = smb_raw_lock_send(cli->tree, &io); + + /* cancel the blocking lock */ + smb_raw_ntcancel(req); + + lock[0].pid = 1; + io.lockx.in.ulock_cnt = 1; + io.lockx.in.lock_cnt = 0; + io.lockx.in.timeout = 0; + status = smb_raw_lock(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + status = cli_request_simple_recv(req); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + cli_close(cli, fnum); + +done: + return ret; +} + + + +/* + basic testing of multiplexing notify +*/ +BOOL torture_raw_mux(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_mux"); + + /* cleanup */ + if (cli_deltree(cli, BASEDIR) == -1) { + printf("Failed to cleanup " BASEDIR "\n"); + ret = False; + goto done; + } + + + if (!cli_mkdir(cli, BASEDIR)) { + printf("Failed to create %s\n", BASEDIR); + ret = False; + goto done; + } + + if (!test_mux_open(cli, mem_ctx)) { + ret = False; + } + + if (!test_mux_write(cli, mem_ctx)) { + ret = False; + } + + if (!test_mux_lock(cli, mem_ctx)) { + ret = False; + } + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/notify.c b/source4/torture/raw/notify.c new file mode 100644 index 0000000000..a123dc6702 --- /dev/null +++ b/source4/torture/raw/notify.c @@ -0,0 +1,140 @@ +/* + Unix SMB/CIFS implementation. + basic raw test suite for change notify + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define BASEDIR "\\test_notify" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + + +#define CHECK_VAL(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) wrong value for %s 0x%x - 0x%x\n", \ + __LINE__, #v, (int)v, (int)correct); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_WSTR(field, value, flags) do { \ + if (!field.s || strcmp(field.s, value) || wire_bad_flags(&field, flags)) { \ + printf("(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \ + ret = False; \ + goto done; \ + }} while (0) + + +/* + basic testing of change notify +*/ +BOOL torture_raw_notify(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + NTSTATUS status; + struct smb_notify notify; + union smb_open io; + int fnum = -1; + struct cli_request *req; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_notify"); + + /* cleanup */ + if (cli_deltree(cli, BASEDIR) == -1) { + printf("Failed to cleanup " BASEDIR "\n"); + ret = False; + goto done; + } + + /* + get a handle on the directory + */ + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SA_RIGHT_FILE_ALL_ACCESS; + io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = BASEDIR; + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + /* ask for a change notify */ + notify.in.buffer_size = 4096; + notify.in.completion_filter = 0xFF; + notify.in.fnum = fnum; + notify.in.recursive = True; + + printf("testing notify mkdir\n"); + + req = smb_raw_changenotify_send(cli->tree, ¬ify); + cli_mkdir(cli, BASEDIR "\\subdir-name"); + + status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify); + CHECK_STATUS(status, NT_STATUS_OK); + + CHECK_VAL(notify.out.num_changes, 1); + CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_ADDED); + CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE); + + printf("testing notify rmdir\n"); + + req = smb_raw_changenotify_send(cli->tree, ¬ify); + cli_rmdir(cli, BASEDIR "\\subdir-name"); + + status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(notify.out.num_changes, 1); + CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED); + CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE); + + printf("testing notify cancel\n"); + + req = smb_raw_changenotify_send(cli->tree, ¬ify); + smb_raw_ntcancel(req); + cli_mkdir(cli, BASEDIR "\\subdir-name"); + status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify); + CHECK_STATUS(status, NT_STATUS_CANCELLED); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/open.c b/source4/torture/raw/open.c new file mode 100644 index 0000000000..9f77eb3f8e --- /dev/null +++ b/source4/torture/raw/open.c @@ -0,0 +1,895 @@ +/* + Unix SMB/CIFS implementation. + RAW_OPEN_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* enum for whether reads/writes are possible on a file */ +enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR}; + +#define BASEDIR "\\rawopen" + +/* + check if a open file can be read/written +*/ +static enum rdwr_mode check_rdwr(struct cli_state *cli, int fnum) +{ + char c = 1; + BOOL can_read = (cli_read(cli, fnum, &c, 0, 1) == 1); + BOOL can_write = (cli_write(cli, fnum, 0, &c, 0, 1) == 1); + if ( can_read && can_write) return RDWR_RDWR; + if ( can_read && !can_write) return RDWR_RDONLY; + if (!can_read && can_write) return RDWR_WRONLY; + return RDWR_NONE; +} + +/* + describe a RDWR mode as a string +*/ +static const char *rdwr_string(enum rdwr_mode m) +{ + switch (m) { + case RDWR_NONE: return "NONE"; + case RDWR_RDONLY: return "RDONLY"; + case RDWR_WRONLY: return "WRONLY"; + case RDWR_RDWR: return "RDWR"; + } + return "-"; +} + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CREATE_FILE do { \ + fnum = create_complex_file(cli, mem_ctx, fname); \ + if (fnum == -1) { \ + printf("(%d) Failed to create %s - %s\n", __LINE__, fname, cli_errstr(cli)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_RDWR(fnum, correct) do { \ + enum rdwr_mode m = check_rdwr(cli, fnum); \ + if (m != correct) { \ + printf("(%d) Incorrect readwrite mode %s - expected %s\n", \ + __LINE__, rdwr_string(m), rdwr_string(correct)); \ + ret = False; \ + }} while (0) + +#define CHECK_TIME(t, field) do { \ + time_t t1, t2; \ + finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \ + finfo.all_info.in.fname = fname; \ + status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \ + CHECK_STATUS(status, NT_STATUS_OK); \ + t1 = t & ~1; \ + t2 = nt_time_to_unix(&finfo.all_info.out.field) & ~1; \ + if (ABS(t1-t2) > 2) { \ + printf("(%d) wrong time for field %s %s - %s\n", \ + __LINE__, #field, \ + time_string(mem_ctx, t1), \ + time_string(mem_ctx, t2)); \ + dump_all_info(mem_ctx, &finfo); \ + ret = False; \ + }} while (0) + +#define CHECK_NTTIME(t, field) do { \ + NTTIME t2; \ + finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \ + finfo.all_info.in.fname = fname; \ + status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \ + CHECK_STATUS(status, NT_STATUS_OK); \ + t2 = finfo.all_info.out.field; \ + if (!nt_time_equal(&t, &t2)) { \ + printf("(%d) wrong time for field %s %s - %s\n", \ + __LINE__, #field, \ + nt_time_string(mem_ctx, &t), \ + nt_time_string(mem_ctx, &t2)); \ + dump_all_info(mem_ctx, &finfo); \ + ret = False; \ + }} while (0) + +#define CHECK_ALL_INFO(v, field) do { \ + finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \ + finfo.all_info.in.fname = fname; \ + status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \ + CHECK_STATUS(status, NT_STATUS_OK); \ + if ((v) != finfo.all_info.out.field) { \ + printf("(%d) wrong value for field %s 0x%x - 0x%x\n", \ + __LINE__, #field, (int)v, (int)finfo.all_info.out.field); \ + dump_all_info(mem_ctx, &finfo); \ + ret = False; \ + }} while (0) + +#define CHECK_VAL(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) wrong value for %s 0x%x - 0x%x\n", \ + __LINE__, #v, (int)v, (int)correct); \ + ret = False; \ + }} while (0) + +#define SET_ATTRIB(sattrib) do { \ + union smb_setfileinfo sfinfo; \ + sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION; \ + sfinfo.generic.file.fname = fname; \ + ZERO_STRUCT(sfinfo.basic_info.in); \ + sfinfo.basic_info.in.attrib = sattrib; \ + status = smb_raw_setpathinfo(cli->tree, &sfinfo); \ + if (!NT_STATUS_IS_OK(status)) { \ + printf("(%d) Failed to set attrib 0x%x on %s\n", \ + __LINE__, sattrib, fname); \ + }} while (0) + +/* + test RAW_OPEN_OPEN +*/ +static BOOL test_open(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_open io; + union smb_fileinfo finfo; + const char *fname = BASEDIR "\\torture_open.txt"; + NTSTATUS status; + int fnum, fnum2; + BOOL ret = True; + + printf("Checking RAW_OPEN_OPEN\n"); + + io.open.level = RAW_OPEN_OPEN; + io.open.in.fname = fname; + io.open.in.flags = OPEN_FLAGS_FCB; + io.open.in.search_attrs = 0; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + fnum = io.open.out.fnum; + + cli_unlink(cli, fname); + CREATE_FILE; + cli_close(cli, fnum); + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.open.out.fnum; + CHECK_RDWR(fnum, RDWR_RDWR); + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum2 = io.open.out.fnum; + CHECK_RDWR(fnum2, RDWR_RDWR); + cli_close(cli, fnum2); + cli_close(cli, fnum); + + /* check the read/write modes */ + io.open.level = RAW_OPEN_OPEN; + io.open.in.fname = fname; + io.open.in.search_attrs = 0; + + io.open.in.flags = OPEN_FLAGS_OPEN_READ; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.open.out.fnum; + CHECK_RDWR(fnum, RDWR_RDONLY); + cli_close(cli, fnum); + + io.open.in.flags = OPEN_FLAGS_OPEN_WRITE; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.open.out.fnum; + CHECK_RDWR(fnum, RDWR_WRONLY); + cli_close(cli, fnum); + + io.open.in.flags = OPEN_FLAGS_OPEN_RDWR; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.open.out.fnum; + CHECK_RDWR(fnum, RDWR_RDWR); + cli_close(cli, fnum); + + /* check the share modes roughly - not a complete matrix */ + io.open.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.open.out.fnum; + CHECK_RDWR(fnum, RDWR_RDWR); + + if (io.open.in.flags != io.open.out.rmode) { + printf("(%d) rmode should equal flags - 0x%x 0x%x\n", + __LINE__, io.open.out.rmode, io.open.in.flags); + } + + io.open.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); + + io.open.in.flags = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum2 = io.open.out.fnum; + CHECK_RDWR(fnum2, RDWR_RDONLY); + cli_close(cli, fnum); + cli_close(cli, fnum2); + + + /* check the returned write time */ + io.open.level = RAW_OPEN_OPEN; + io.open.in.fname = fname; + io.open.in.search_attrs = 0; + io.open.in.flags = OPEN_FLAGS_OPEN_READ; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.open.out.fnum; + + /* check other reply fields */ + CHECK_TIME(io.open.out.write_time, write_time); + CHECK_ALL_INFO(io.open.out.size, size); + CHECK_ALL_INFO(io.open.out.attrib, attrib); + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + + return ret; +} + + +/* + test RAW_OPEN_OPENX +*/ +static BOOL test_openx(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_open io; + union smb_fileinfo finfo; + const char *fname = BASEDIR "\\torture_openx.txt"; + NTSTATUS status; + int fnum, fnum2; + BOOL ret = True; + int i; + struct { + uint16 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_INVALID_LOCK_SEQUENCE }, + { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_INVALID_LOCK_SEQUENCE }, + { 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_OK }, + { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK }, + { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND }, + { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK }, + { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK }, + }; + + printf("Checking RAW_OPEN_OPENX\n"); + cli_unlink(cli, fname); + + io.openx.level = RAW_OPEN_OPENX; + io.openx.in.fname = fname; + io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO; + io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR; + io.openx.in.search_attrs = 0; + io.openx.in.file_attrs = 0; + io.openx.in.write_time = 0; + io.openx.in.size = 1024*1024; + io.openx.in.timeout = 0; + + /* check all combinations of open_func */ + for (i=0; i<ARRAY_SIZE(open_funcs); i++) { + if (open_funcs[i].with_file) { + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + d_printf("Failed to create file %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + cli_close(cli, fnum); + } + io.openx.in.open_func = open_funcs[i].open_func; + status = smb_raw_open(cli->tree, mem_ctx, &io); + if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) { + printf("(%d) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n", + __LINE__, 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) || open_funcs[i].with_file) { + cli_close(cli, io.openx.out.fnum); + cli_unlink(cli, fname); + } + } + + /* check the basic return fields */ + io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.openx.out.fnum; + + CHECK_ALL_INFO(io.openx.out.size, size); + CHECK_VAL(io.openx.out.size, 1024*1024); + CHECK_ALL_INFO(io.openx.in.size, size); + CHECK_TIME(io.openx.out.write_time, write_time); + CHECK_ALL_INFO(io.openx.out.attrib, attrib); + CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR); + CHECK_VAL(io.openx.out.ftype, 0); + CHECK_VAL(io.openx.out.devstate, 0); + CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED); + cli_close(cli, fnum); + cli_unlink(cli, fname); + + /* check the fields when the file already existed */ + fnum2 = create_complex_file(cli, mem_ctx, fname); + if (fnum2 == -1) { + ret = False; + goto done; + } + cli_close(cli, fnum2); + + io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.openx.out.fnum; + + CHECK_ALL_INFO(io.openx.out.size, size); + 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); + cli_close(cli, 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, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli_close(cli, io.openx.out.fnum); + + io.openx.in.search_attrs = 0; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli_close(cli, io.openx.out.fnum); + + SET_ATTRIB(FILE_ATTRIBUTE_NORMAL); + cli_unlink(cli, 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, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE, attrib); + cli_close(cli, io.openx.out.fnum); + cli_unlink(cli, 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, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.openx.out.fnum; + + io.openx.in.timeout = 20000; + start_timer(); + io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); + if (end_timer() > 3) { + printf("(%d) Incorrect timing in openx with timeout - waited %d seconds\n", + __LINE__, (int)end_timer()); + ret = False; + } + cli_close(cli, fnum); + cli_unlink(cli, 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, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli_close(cli, io.openx.out.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, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(io.openx.out.access_mask, STD_RIGHT_ALL_ACCESS); + cli_close(cli, io.openx.out.fnum); + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + + return ret; +} + + +/* + test RAW_OPEN_T2OPEN + + I can't work out how to get win2003 to accept a create file via TRANS2_OPEN, which + is why you see all the ACCESS_DENIED results below. When we finally work this out then this + test will make more sense +*/ +static BOOL test_t2open(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_open io; + union smb_fileinfo finfo; + const char *fname = BASEDIR "\\torture_t2open.txt"; + NTSTATUS status; + int fnum; + BOOL ret = True; + int i; + struct { + uint16 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_ACCESS_DENIED }, + { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_OBJECT_NAME_COLLISION }, + { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_ACCESS_DENIED }, + { 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_ACCESS_DENIED }, + { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_ACCESS_DENIED }, + { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND }, + { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_ACCESS_DENIED }, + { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED }, + }; + + printf("Checking RAW_OPEN_T2OPEN\n"); + + io.t2open.level = RAW_OPEN_T2OPEN; + io.t2open.in.fname = fname; + io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | + OPENX_FLAGS_EA_LEN | OPENX_FLAGS_EXTENDED_RETURN; + 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.file_attrs = 0; + io.t2open.in.write_time = 0; + io.t2open.in.size = 0; + io.t2open.in.timeout = 0; + + io.t2open.in.eas = talloc(mem_ctx, sizeof(io.t2open.in.eas[0])); + io.t2open.in.num_eas = 1; + io.t2open.in.eas[0].flags = 0; + io.t2open.in.eas[0].name.s = "EAONE"; + io.t2open.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1); + + /* check all combinations of open_func */ + for (i=0; i<ARRAY_SIZE(open_funcs); i++) { + if (open_funcs[i].with_file) { + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + d_printf("Failed to create file %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + cli_close(cli, fnum); + } + io.t2open.in.open_func = open_funcs[i].open_func; + status = smb_raw_open(cli->tree, mem_ctx, &io); + if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) { + printf("(%d) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n", + __LINE__, 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) || open_funcs[i].with_file) { + cli_close(cli, io.t2open.out.fnum); + cli_unlink(cli, fname); + } + } + + /* check the basic return fields */ + fnum = create_complex_file(cli, mem_ctx, fname); + cli_close(cli, fnum); + io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.t2open.out.fnum; + + CHECK_ALL_INFO(io.t2open.out.size, size); + CHECK_VAL(io.t2open.out.write_time, 0); + CHECK_ALL_INFO(io.t2open.out.attrib, attrib); + 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_EXISTED); + cli_close(cli, fnum); + + /* 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, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli_close(cli, io.t2open.out.fnum); + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + cli_close(cli, io.t2open.out.fnum); + + SET_ATTRIB(FILE_ATTRIBUTE_NORMAL); + cli_unlink(cli, 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, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); + + /* 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.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + + return ret; +} + + +/* + test RAW_OPEN_NTCREATEX +*/ +static BOOL test_ntcreatex(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + 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; + BOOL ret = True; + int i; + struct { + uint32 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 = GENERIC_RIGHTS_FILE_ALL_ACCESS; + 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 = cli_open(cli, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE); + if (fnum == -1) { + d_printf("Failed to create file %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + cli_close(cli, fnum); + } + io.ntcreatex.in.open_disposition = open_funcs[i].open_disp; + status = smb_raw_open(cli->tree, mem_ctx, &io); + if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) { + printf("(%d) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n", + __LINE__, 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) { + cli_close(cli, io.ntcreatex.out.fnum); + cli_unlink(cli, fname); + } + } + + /* basic field testing */ + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + CHECK_VAL(io.ntcreatex.out.oplock_level, 0); + CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED); + CHECK_NTTIME(io.ntcreatex.out.create_time, create_time); + CHECK_NTTIME(io.ntcreatex.out.access_time, access_time); + CHECK_NTTIME(io.ntcreatex.out.write_time, write_time); + CHECK_NTTIME(io.ntcreatex.out.change_time, change_time); + CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib); + CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size); + CHECK_ALL_INFO(io.ntcreatex.out.size, size); + CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory); + CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK); + + /* check fields when the file already existed */ + cli_close(cli, fnum); + cli_unlink(cli, fname); + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + ret = False; + goto done; + } + cli_close(cli, fnum); + + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + CHECK_VAL(io.ntcreatex.out.oplock_level, 0); + CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED); + CHECK_NTTIME(io.ntcreatex.out.create_time, create_time); + CHECK_NTTIME(io.ntcreatex.out.access_time, access_time); + CHECK_NTTIME(io.ntcreatex.out.write_time, write_time); + CHECK_NTTIME(io.ntcreatex.out.change_time, change_time); + CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib); + CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size); + CHECK_ALL_INFO(io.ntcreatex.out.size, size); + CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory); + CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK); + cli_close(cli, fnum); + cli_unlink(cli, fname); + + + /* create a directory */ + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY; + 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.fname = dname; + fname = dname; + + cli_rmdir(cli, fname); + cli_unlink(cli, fname); + + io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED; + io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + CHECK_VAL(io.ntcreatex.out.oplock_level, 0); + CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED); + CHECK_NTTIME(io.ntcreatex.out.create_time, create_time); + CHECK_NTTIME(io.ntcreatex.out.access_time, access_time); + CHECK_NTTIME(io.ntcreatex.out.write_time, write_time); + CHECK_NTTIME(io.ntcreatex.out.change_time, change_time); + CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib); + CHECK_VAL(io.ntcreatex.out.attrib, FILE_ATTRIBUTE_DIRECTORY); + CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size); + CHECK_ALL_INFO(io.ntcreatex.out.size, size); + CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory); + CHECK_VAL(io.ntcreatex.out.is_directory, 1); + CHECK_VAL(io.ntcreatex.out.size, 0); + CHECK_VAL(io.ntcreatex.out.alloc_size, 0); + CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK); + cli_unlink(cli, fname); + + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + + return ret; +} + + +/* + test RAW_OPEN_MKNEW +*/ +static BOOL test_mknew(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_open io; + const char *fname = BASEDIR "\\torture_mknew.txt"; + NTSTATUS status; + int fnum; + BOOL ret = True; + time_t basetime = (time(NULL) + 3600*24*3) & ~1; + union smb_fileinfo finfo; + + printf("Checking RAW_OPEN_MKNEW\n"); + + io.mknew.level = RAW_OPEN_MKNEW; + io.mknew.in.attrib = 0; + io.mknew.in.write_time = 0; + io.mknew.in.fname = fname; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.mknew.out.fnum; + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION); + + cli_close(cli, fnum); + cli_unlink(cli, fname); + + /* make sure write_time works */ + io.mknew.in.write_time = basetime; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.mknew.out.fnum; + CHECK_TIME(basetime, write_time); + + cli_close(cli, fnum); + cli_unlink(cli, fname); + + /* make sure file_attrs works */ + io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.mknew.out.fnum; + CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE, attrib); + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + + return ret; +} + + +/* + test RAW_OPEN_CTEMP +*/ +static BOOL test_ctemp(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_open io; + NTSTATUS status; + int fnum; + BOOL ret = True; + time_t basetime = (time(NULL) + 3600*24*3) & ~1; + union smb_fileinfo finfo; + const char *name, *fname = NULL; + + printf("Checking RAW_OPEN_CTEMP\n"); + + io.ctemp.level = RAW_OPEN_CTEMP; + io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN; + io.ctemp.in.write_time = basetime; + io.ctemp.in.directory = BASEDIR; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ctemp.out.fnum; + + name = io.ctemp.out.name; + + finfo.generic.level = RAW_FILEINFO_NAME_INFO; + finfo.generic.in.fnum = fnum; + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo); + CHECK_STATUS(status, NT_STATUS_OK); + + fname = finfo.name_info.out.fname.s; + d_printf("ctemp name=%s real name=%s\n", name, fname); + + CHECK_TIME(basetime, write_time); + +done: + cli_close(cli, fnum); + if (fname) { + cli_unlink(cli, fname); + } + + return ret; +} + +/* basic testing of all RAW_OPEN_* calls +*/ +BOOL torture_raw_open(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_open"); + + if (cli_deltree(cli, BASEDIR) == -1) { + printf("Failed to clean " BASEDIR "\n"); + return False; + } + if (!cli_mkdir(cli, BASEDIR)) { + printf("Failed to create " BASEDIR " - %s\n", cli_errstr(cli)); + return False; + } + + if (!test_open(cli, mem_ctx)) { + ret = False; + } + + if (!test_openx(cli, mem_ctx)) { + ret = False; + } + + if (!test_ntcreatex(cli, mem_ctx)) { + ret = False; + } + + if (!test_t2open(cli, mem_ctx)) { + ret = False; + } + + if (!test_mknew(cli, mem_ctx)) { + ret = False; + } + + if (!test_ctemp(cli, mem_ctx)) { + ret = False; + } + + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/oplock.c b/source4/torture/raw/oplock.c new file mode 100644 index 0000000000..888fcbdc13 --- /dev/null +++ b/source4/torture/raw/oplock.c @@ -0,0 +1,288 @@ +/* + Unix SMB/CIFS implementation. + basic raw test suite for oplocks + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define CHECK_VAL(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) wrong value for %s 0x%x - 0x%x\n", \ + __LINE__, #v, (int)v, (int)correct); \ + ret = False; \ + }} while (0) + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + + +static struct { + int fnum; + unsigned char level; + int count; +} break_info; + +/* + a handler function for oplock break requests +*/ +static BOOL oplock_handler_ack(struct cli_transport *transport, uint16 tid, uint16 fnum, uint8 level, void *private) +{ + struct cli_tree *tree = private; + break_info.fnum = fnum; + break_info.level = level; + break_info.count++; + + printf("Acking in oplock handler\n"); + + return cli_oplock_ack(tree, fnum, level == 1? 0x102 : 2); +} + +/* + a handler function for oplock break requests - close the file +*/ +static BOOL oplock_handler_close(struct cli_transport *transport, uint16 tid, uint16 fnum, uint8 level, void *private) +{ + union smb_close io; + NTSTATUS status; + struct cli_tree *tree = private; + + break_info.fnum = fnum; + break_info.level = level; + break_info.count++; + + io.close.level = RAW_CLOSE_CLOSE; + io.close.in.fnum = fnum; + io.close.in.write_time = 0; + status = smb_raw_close(tree, &io); + + printf("Closing in oplock handler\n"); + + if (!NT_STATUS_IS_OK(status)) { + printf("close failed in oplock_handler_close\n"); + return False; + } + return True; +} + +/* + test oplock ops +*/ +static BOOL test_oplock(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + const char *fname = "\\test_oplock.dat"; + NTSTATUS status; + BOOL ret = True; + union smb_open io; + struct smb_unlink unl; + union smb_read rd; + uint16 fnum, fnum2; + + /* cleanup */ + cli_unlink(cli, fname); + + cli_oplock_handler(cli->transport, oplock_handler_ack, cli->tree); + + /* + base ntcreatex parms + */ + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF; + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = fname; + + printf("open a file with a normal oplock\n"); + ZERO_STRUCT(break_info); + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK; + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN); + + printf("unlink it - should be no break\n"); + unl.in.pattern = fname; + unl.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &unl); + CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); + CHECK_VAL(break_info.count, 0); + + cli_close(cli, fnum); + + /* + with a batch oplock we get a break + */ + printf("open with batch oplock\n"); + ZERO_STRUCT(break_info); + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | + NTCREATEX_FLAGS_REQUEST_OPLOCK | + NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN); + + printf("unlink should generate a break\n"); + unl.in.pattern = fname; + unl.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &unl); + CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); + + CHECK_VAL(break_info.fnum, fnum); + CHECK_VAL(break_info.level, 2); + CHECK_VAL(break_info.count, 1); + + + cli_close(cli, fnum); + + printf("if we close on break then the unlink can succeed\n"); + ZERO_STRUCT(break_info); + cli_oplock_handler(cli->transport, oplock_handler_close, cli->tree); + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | + NTCREATEX_FLAGS_REQUEST_OPLOCK | + NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN); + + unl.in.pattern = fname; + unl.in.attrib = 0; + ZERO_STRUCT(break_info); + status = smb_raw_unlink(cli->tree, &unl); + CHECK_STATUS(status, NT_STATUS_OK); + + CHECK_VAL(break_info.fnum, fnum); + CHECK_VAL(break_info.level, 2); + CHECK_VAL(break_info.count, 1); + + printf("a self read should not cause a break\n"); + ZERO_STRUCT(break_info); + cli_close(cli, fnum); + cli_oplock_handler(cli->transport, oplock_handler_ack, cli->tree); + + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | + NTCREATEX_FLAGS_REQUEST_OPLOCK | + NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN); + + rd.read.level = RAW_READ_READ; + rd.read.in.fnum = fnum; + rd.read.in.count = 1; + rd.read.in.offset = 0; + rd.read.in.remaining = 0; + status = smb_raw_read(cli->tree, &rd); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(break_info.count, 0); + + + printf("a 2nd open should give a break\n"); + ZERO_STRUCT(break_info); + cli_close(cli, fnum); + cli_oplock_handler(cli->transport, oplock_handler_ack, cli->tree); + + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | + NTCREATEX_FLAGS_REQUEST_OPLOCK | + NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN); + + ZERO_STRUCT(break_info); + + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); + + CHECK_VAL(break_info.count, 1); + CHECK_VAL(break_info.fnum, fnum); + CHECK_VAL(break_info.level, 2); + + printf("a 2nd open should get an oplock when we close instead of ack\n"); + ZERO_STRUCT(break_info); + cli_close(cli, fnum); + cli_oplock_handler(cli->transport, oplock_handler_close, cli->tree); + + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | + NTCREATEX_FLAGS_REQUEST_OPLOCK | + NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum2 = io.ntcreatex.out.fnum; + CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN); + + ZERO_STRUCT(break_info); + + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | + NTCREATEX_FLAGS_REQUEST_OPLOCK | + NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN); + + CHECK_VAL(break_info.count, 1); + CHECK_VAL(break_info.fnum, fnum2); + CHECK_VAL(break_info.level, 2); + + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + return ret; +} + + +/* + basic testing of oplocks +*/ +BOOL torture_raw_oplock(int dummy) +{ + struct cli_state *cli1; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli1)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_oplock"); + + if (!test_oplock(cli1, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli1); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/qfileinfo.c b/source4/torture/raw/qfileinfo.c new file mode 100644 index 0000000000..b1f508cae8 --- /dev/null +++ b/source4/torture/raw/qfileinfo.c @@ -0,0 +1,701 @@ +/* + Unix SMB/CIFS implementation. + RAW_FILEINFO_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static struct { + const char *name; + enum fileinfo_level level; + unsigned only_paths:1; + unsigned only_handles:1; + uint32 capability_mask; + NTSTATUS fnum_status, fname_status; + union smb_fileinfo fnum_finfo, fname_finfo; +} levels[] = { + { "GETATTR", RAW_FILEINFO_GETATTR, 1, 0, }, + { "GETATTRE", RAW_FILEINFO_GETATTRE, 0, 1, }, + { "STANDARD", RAW_FILEINFO_STANDARD, }, + { "EA_SIZE", RAW_FILEINFO_EA_SIZE, }, + { "ALL_EAS", RAW_FILEINFO_ALL_EAS, }, + { "IS_NAME_VALID", RAW_FILEINFO_IS_NAME_VALID, 1, 0, }, + { "BASIC_INFO", RAW_FILEINFO_BASIC_INFO, }, + { "STANDARD_INFO", RAW_FILEINFO_STANDARD_INFO, }, + { "EA_INFO", RAW_FILEINFO_EA_INFO, }, + { "NAME_INFO", RAW_FILEINFO_NAME_INFO, }, + { "ALL_INFO", RAW_FILEINFO_ALL_INFO, }, + { "ALT_NAME_INFO", RAW_FILEINFO_ALT_NAME_INFO, }, + { "STREAM_INFO", RAW_FILEINFO_STREAM_INFO, }, + { "COMPRESSION_INFO", RAW_FILEINFO_COMPRESSION_INFO, }, + { "UNIX_BASIC_INFO", RAW_FILEINFO_UNIX_BASIC, 0, 0, CAP_UNIX}, + { "UNIX_LINK_INFO", RAW_FILEINFO_UNIX_LINK, 0, 0, CAP_UNIX}, + { "BASIC_INFORMATION", RAW_FILEINFO_BASIC_INFORMATION, }, + { "STANDARD_INFORMATION", RAW_FILEINFO_STANDARD_INFORMATION, }, + { "INTERNAL_INFORMATION", RAW_FILEINFO_INTERNAL_INFORMATION, }, + { "EA_INFORMATION", RAW_FILEINFO_EA_INFORMATION, }, + { "ACCESS_INFORMATION", RAW_FILEINFO_ACCESS_INFORMATION, }, + { "NAME_INFORMATION", RAW_FILEINFO_NAME_INFORMATION, }, + { "POSITION_INFORMATION", RAW_FILEINFO_POSITION_INFORMATION, }, + { "MODE_INFORMATION", RAW_FILEINFO_MODE_INFORMATION, }, + { "ALIGNMENT_INFORMATION", RAW_FILEINFO_ALIGNMENT_INFORMATION, }, + { "ALL_INFORMATION", RAW_FILEINFO_ALL_INFORMATION, }, + { "ALT_NAME_INFORMATION", RAW_FILEINFO_ALT_NAME_INFORMATION, }, + { "STREAM_INFORMATION", RAW_FILEINFO_STREAM_INFORMATION, }, + { "COMPRESSION_INFORMATION", RAW_FILEINFO_COMPRESSION_INFORMATION, }, + { "NETWORK_OPEN_INFORMATION", RAW_FILEINFO_NETWORK_OPEN_INFORMATION, }, + { "ATTRIBUTE_TAG_INFORMATION", RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION, }, + { NULL, } +}; + +/* + compare a dos time (2 second resolution) to a nt time +*/ +static int dos_nt_time_cmp(time_t t, const NTTIME *nt) +{ + time_t t2 = nt_time_to_unix(nt); + if (ABS(t2 - t) <= 2) return 0; + return t2 - t; +} + + +/* + find a level in the levels[] table +*/ +static union smb_fileinfo *fnum_find(const char *name) +{ + int i; + for (i=0; levels[i].name; i++) { + if (NT_STATUS_IS_OK(levels[i].fnum_status) && + strcmp(name, levels[i].name) == 0 && + !levels[i].only_paths) { + return &levels[i].fnum_finfo; + } + } + return NULL; +} + +/* + find a level in the levels[] table +*/ +static union smb_fileinfo *fname_find(const char *name) +{ + int i; + for (i=0; levels[i].name; i++) { + if (NT_STATUS_IS_OK(levels[i].fname_status) && + strcmp(name, levels[i].name) == 0 && + !levels[i].only_handles) { + return &levels[i].fname_finfo; + } + } + return NULL; +} + +/* local macros to make the code below more readable */ +#define VAL_EQUAL(n1, v1, n2, v2) do {if (s1->n1.out.v1 != s2->n2.out.v2) { \ + printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \ + #n1, #v1, (uint_t)s1->n1.out.v1, \ + #n2, #v2, (uint_t)s2->n2.out.v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +#define STR_EQUAL(n1, v1, n2, v2) do {if (strcmp(s1->n1.out.v1.s, s2->n2.out.v2.s) || \ + s1->n1.out.v1.private_length != s2->n2.out.v2.private_length) { \ + printf("%s/%s [%s/%d] != %s/%s [%s/%d] at %s(%d)\n", \ + #n1, #v1, s1->n1.out.v1.s, s1->n1.out.v1.private_length, \ + #n2, #v2, s2->n2.out.v2.s, s2->n2.out.v2.private_length, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +#define STRUCT_EQUAL(n1, v1, n2, v2) do {if (memcmp(&s1->n1.out.v1,&s2->n2.out.v2,sizeof(s1->n1.out.v1))) { \ + printf("%s/%s != %s/%s at %s(%d)\n", \ + #n1, #v1, \ + #n2, #v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +/* used to find hints on unknown values - and to make sure + we zero-fill */ +#define VAL_UNKNOWN(n1, v1) do {if (s1->n1.out.v1 != 0) { \ + printf("%s/%s non-zero unknown - %u (0x%x) at %s(%d)\n", \ + #n1, #v1, \ + (uint_t)s1->n1.out.v1, \ + (uint_t)s1->n1.out.v1, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +/* basic testing of all RAW_FILEINFO_* calls + for each call we test that it succeeds, and where possible test + for consistency between the calls. +*/ +BOOL torture_raw_qfileinfo(int dummy) +{ + struct cli_state *cli; + int i; + BOOL ret = True; + int count; + union smb_fileinfo *s1, *s2; + TALLOC_CTX *mem_ctx; + int fnum; + const char *fname = "\\torture_qfileinfo.txt"; + NTTIME correct_time; + large_t correct_size; + uint32 correct_attrib; + const char *correct_name; + BOOL skip_streams = False; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_qfileinfo"); + + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + + /* scan all the fileinfo and pathinfo levels */ + for (i=0; levels[i].name; i++) { + if (!levels[i].only_paths) { + levels[i].fnum_finfo.generic.level = levels[i].level; + levels[i].fnum_finfo.generic.in.fnum = fnum; + levels[i].fnum_status = smb_raw_fileinfo(cli->tree, mem_ctx, + &levels[i].fnum_finfo); + } + + if (!levels[i].only_handles) { + levels[i].fname_finfo.generic.level = levels[i].level; + levels[i].fname_finfo.generic.in.fname = talloc_strdup(mem_ctx, fname); + levels[i].fname_status = smb_raw_pathinfo(cli->tree, mem_ctx, + &levels[i].fname_finfo); + } + } + + /* check for completely broken levels */ + for (count=i=0; levels[i].name; i++) { + uint32 cap = cli->transport->negotiate.capabilities; + /* see if this server claims to support this level */ + if ((cap & levels[i].capability_mask) != levels[i].capability_mask) { + continue; + } + + if (!levels[i].only_paths && !NT_STATUS_IS_OK(levels[i].fnum_status)) { + printf("ERROR: level %s failed - %s\n", + levels[i].name, nt_errstr(levels[i].fnum_status)); + count++; + } + if (!levels[i].only_handles && !NT_STATUS_IS_OK(levels[i].fname_status)) { + printf("ERROR: level %s failed - %s\n", + levels[i].name, nt_errstr(levels[i].fname_status)); + count++; + } + } + + if (count != 0) { + ret = False; + printf("%d levels failed\n", count); + if (count > 32) { + printf("too many level failures - giving up\n"); + goto done; + } + } + + /* see if we can do streams */ + s1 = fnum_find("STREAM_INFO"); + if (!s1 || s1->stream_info.out.num_streams == 0) { + printf("STREAM_INFO broken (%d) - skipping streams checks\n", + s1 ? s1->stream_info.out.num_streams : -1); + skip_streams = True; + } + + + /* this code is incredibly repititive but doesn't lend itself to loops, so + we use lots of macros to make it less painful */ + + /* first off we check the levels that are supposed to be aliases. It will be quite rare for + this code to fail, but we need to check it for completeness */ + + + +#define ALIAS_CHECK(sname1, sname2) \ + do { \ + s1 = fnum_find(sname1); s2 = fnum_find(sname2); \ + if (s1 && s2) { INFO_CHECK } \ + s1 = fname_find(sname1); s2 = fname_find(sname2); \ + if (s1 && s2) { INFO_CHECK } \ + s1 = fnum_find(sname1); s2 = fname_find(sname2); \ + if (s1 && s2) { INFO_CHECK } \ + } while (0) + +#define INFO_CHECK \ + STRUCT_EQUAL(basic_info, create_time, basic_info, create_time); \ + STRUCT_EQUAL(basic_info, access_time, basic_info, access_time); \ + STRUCT_EQUAL(basic_info, write_time, basic_info, write_time); \ + STRUCT_EQUAL(basic_info, change_time, basic_info, change_time); \ + VAL_EQUAL (basic_info, attrib, basic_info, attrib); + + ALIAS_CHECK("BASIC_INFO", "BASIC_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + VAL_EQUAL(standard_info, alloc_size, standard_info, alloc_size); \ + VAL_EQUAL(standard_info, size, standard_info, size); \ + VAL_EQUAL(standard_info, nlink, standard_info, nlink); \ + VAL_EQUAL(standard_info, delete_pending, standard_info, delete_pending); \ + VAL_EQUAL(standard_info, directory, standard_info, directory); + + ALIAS_CHECK("STANDARD_INFO", "STANDARD_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + VAL_EQUAL(ea_info, ea_size, ea_info, ea_size); + + ALIAS_CHECK("EA_INFO", "EA_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + STR_EQUAL(name_info, fname, name_info, fname); + + ALIAS_CHECK("NAME_INFO", "NAME_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + STRUCT_EQUAL(all_info, create_time, all_info, create_time); \ + STRUCT_EQUAL(all_info, access_time, all_info, access_time); \ + STRUCT_EQUAL(all_info, write_time, all_info, write_time); \ + STRUCT_EQUAL(all_info, change_time, all_info, change_time); \ + VAL_EQUAL(all_info, attrib, all_info, attrib); \ + VAL_EQUAL(all_info, alloc_size, all_info, alloc_size); \ + VAL_EQUAL(all_info, size, all_info, size); \ + VAL_EQUAL(all_info, nlink, all_info, nlink); \ + VAL_EQUAL(all_info, delete_pending, all_info, delete_pending); \ + VAL_EQUAL(all_info, directory, all_info, directory); \ + VAL_EQUAL(all_info, ea_size, all_info, ea_size); \ + STR_EQUAL(all_info, fname, all_info, fname); + + ALIAS_CHECK("ALL_INFO", "ALL_INFORMATION"); + +#undef INFO_CHECK +#define INFO_CHECK \ + VAL_EQUAL(compression_info, compressed_size,compression_info, compressed_size); \ + VAL_EQUAL(compression_info, format, compression_info, format); \ + VAL_EQUAL(compression_info, unit_shift, compression_info, unit_shift); \ + VAL_EQUAL(compression_info, chunk_shift, compression_info, chunk_shift); \ + VAL_EQUAL(compression_info, cluster_shift, compression_info, cluster_shift); + + ALIAS_CHECK("COMPRESSION_INFO", "COMPRESSION_INFORMATION"); + + +#undef INFO_CHECK +#define INFO_CHECK \ + STR_EQUAL(alt_name_info, fname, alt_name_info, fname); + + ALIAS_CHECK("ALT_NAME_INFO", "ALT_NAME_INFORMATION"); + + +#define TIME_CHECK_NT(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && memcmp(&s1->stype.out.tfield, &correct_time, sizeof(correct_time)) != 0) { \ + printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + nt_time_string(mem_ctx, &s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && memcmp(&s1->stype.out.tfield, &correct_time, sizeof(correct_time)) != 0) { \ + printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + nt_time_string(mem_ctx, &s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + }} while (0) + +#define TIME_CHECK_DOS(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && dos_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ + printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + time_string(mem_ctx, s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && dos_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ + printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + time_string(mem_ctx, s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + }} while (0) + +#define TIME_CHECK_UNX(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && unx_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ + printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + time_string(mem_ctx, s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && unx_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ + printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ + time_string(mem_ctx, s1->stype.out.tfield), \ + nt_time_string(mem_ctx, &correct_time)); \ + ret = False; \ + }} while (0) + + /* now check that all the times that are supposed to be equal are correct */ + s1 = fnum_find("BASIC_INFO"); + correct_time = s1->basic_info.out.create_time; + printf("create_time: %s\n", nt_time_string(mem_ctx, &correct_time)); + + TIME_CHECK_NT ("BASIC_INFO", basic_info, create_time); + TIME_CHECK_NT ("BASIC_INFORMATION", basic_info, create_time); + TIME_CHECK_DOS("GETATTRE", getattre, create_time); + TIME_CHECK_DOS("STANDARD", standard, create_time); + TIME_CHECK_DOS("EA_SIZE", ea_size, create_time); + TIME_CHECK_NT ("ALL_INFO", all_info, create_time); + TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, create_time); + + s1 = fnum_find("BASIC_INFO"); + correct_time = s1->basic_info.out.access_time; + printf("access_time: %s\n", nt_time_string(mem_ctx, &correct_time)); + + TIME_CHECK_NT ("BASIC_INFO", basic_info, access_time); + TIME_CHECK_NT ("BASIC_INFORMATION", basic_info, access_time); + TIME_CHECK_DOS("GETATTRE", getattre, access_time); + TIME_CHECK_DOS("STANDARD", standard, access_time); + TIME_CHECK_DOS("EA_SIZE", ea_size, access_time); + TIME_CHECK_NT ("ALL_INFO", all_info, access_time); + TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, access_time); + + s1 = fnum_find("BASIC_INFO"); + correct_time = s1->basic_info.out.write_time; + printf("write_time : %s\n", nt_time_string(mem_ctx, &correct_time)); + + TIME_CHECK_NT ("BASIC_INFO", basic_info, write_time); + TIME_CHECK_NT ("BASIC_INFORMATION", basic_info, write_time); + TIME_CHECK_DOS("GETATTR", getattr, write_time); + TIME_CHECK_DOS("GETATTRE", getattre, write_time); + TIME_CHECK_DOS("STANDARD", standard, write_time); + TIME_CHECK_DOS("EA_SIZE", ea_size, write_time); + TIME_CHECK_NT ("ALL_INFO", all_info, write_time); + TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, write_time); + + s1 = fnum_find("BASIC_INFO"); + correct_time = s1->basic_info.out.change_time; + printf("change_time: %s\n", nt_time_string(mem_ctx, &correct_time)); + + TIME_CHECK_NT ("BASIC_INFO", basic_info, change_time); + TIME_CHECK_NT ("BASIC_INFORMATION", basic_info, change_time); + TIME_CHECK_NT ("ALL_INFO", all_info, change_time); + TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, change_time); + + +#define SIZE_CHECK(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && s1->stype.out.tfield != correct_size) { \ + printf("(%d) handle %s/%s incorrect - %u should be %u\n", __LINE__, #stype, #tfield, \ + (unsigned)s1->stype.out.tfield, \ + (unsigned)correct_size); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && s1->stype.out.tfield != correct_size) { \ + printf("(%d) path %s/%s incorrect - %u should be %u\n", __LINE__, #stype, #tfield, \ + (unsigned)s1->stype.out.tfield, \ + (unsigned)correct_size); \ + ret = False; \ + }} while (0) + + s1 = fnum_find("STANDARD_INFO"); + correct_size = s1->standard_info.out.size; + printf("size: %u\n", (unsigned)correct_size); + + SIZE_CHECK("GETATTR", getattr, size); + SIZE_CHECK("GETATTRE", getattre, size); + SIZE_CHECK("STANDARD", standard, size); + SIZE_CHECK("EA_SIZE", ea_size, size); + SIZE_CHECK("STANDARD_INFO", standard_info, size); + SIZE_CHECK("STANDARD_INFORMATION", standard_info, size); + SIZE_CHECK("ALL_INFO", all_info, size); + SIZE_CHECK("ALL_INFORMATION", all_info, size); + SIZE_CHECK("COMPRESSION_INFO", compression_info, compressed_size); + SIZE_CHECK("COMPRESSION_INFORMATION", compression_info, compressed_size); + SIZE_CHECK("NETWORK_OPEN_INFORMATION", network_open_information, size); + if (!skip_streams) { + SIZE_CHECK("STREAM_INFO", stream_info, streams[0].size); + SIZE_CHECK("STREAM_INFORMATION", stream_info, streams[0].size); + } + + + s1 = fnum_find("STANDARD_INFO"); + correct_size = s1->standard_info.out.alloc_size; + printf("alloc_size: %u\n", (unsigned)correct_size); + + SIZE_CHECK("GETATTRE", getattre, alloc_size); + SIZE_CHECK("STANDARD", standard, alloc_size); + SIZE_CHECK("EA_SIZE", ea_size, alloc_size); + SIZE_CHECK("STANDARD_INFO", standard_info, alloc_size); + SIZE_CHECK("STANDARD_INFORMATION", standard_info, alloc_size); + SIZE_CHECK("ALL_INFO", all_info, alloc_size); + SIZE_CHECK("ALL_INFORMATION", all_info, alloc_size); + SIZE_CHECK("NETWORK_OPEN_INFORMATION", network_open_information, alloc_size); + if (!skip_streams) { + SIZE_CHECK("STREAM_INFO", stream_info, streams[0].alloc_size); + SIZE_CHECK("STREAM_INFORMATION", stream_info, streams[0].alloc_size); + } + +#define ATTRIB_CHECK(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && s1->stype.out.tfield != correct_attrib) { \ + printf("(%d) handle %s/%s incorrect - 0x%x should be 0x%x\n", __LINE__, #stype, #tfield, \ + (unsigned)s1->stype.out.tfield, \ + (unsigned)correct_attrib); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if (s1 && s1->stype.out.tfield != correct_attrib) { \ + printf("(%d) path %s/%s incorrect - 0x%x should be 0x%x\n", __LINE__, #stype, #tfield, \ + (unsigned)s1->stype.out.tfield, \ + (unsigned)correct_attrib); \ + ret = False; \ + }} while (0) + + s1 = fnum_find("BASIC_INFO"); + correct_attrib = s1->basic_info.out.attrib; + printf("attrib: 0x%x\n", (unsigned)correct_attrib); + + ATTRIB_CHECK("GETATTR", getattr, attrib); + ATTRIB_CHECK("GETATTRE", getattre, attrib); + ATTRIB_CHECK("STANDARD", standard, attrib); + ATTRIB_CHECK("BASIC_INFO", basic_info, attrib); + ATTRIB_CHECK("BASIC_INFORMATION", basic_info, attrib); + ATTRIB_CHECK("EA_SIZE", ea_size, attrib); + ATTRIB_CHECK("ALL_INFO", all_info, attrib); + ATTRIB_CHECK("ALL_INFORMATION", all_info, attrib); + ATTRIB_CHECK("NETWORK_OPEN_INFORMATION", network_open_information, attrib); + ATTRIB_CHECK("ATTRIBUTE_TAG_INFORMATION", attribute_tag_information, attrib); + + correct_name = fname; + printf("name: %s\n", correct_name); + +#define NAME_CHECK(sname, stype, tfield, flags) do { \ + s1 = fnum_find(sname); \ + if ((s1 && strcmp(s1->stype.out.tfield.s, correct_name) != 0) || \ + wire_bad_flags(&s1->stype.out.tfield, flags)) { \ + printf("(%d) handle %s/%s incorrect - '%s/%d'\n", __LINE__, #stype, #tfield, \ + s1->stype.out.tfield.s, s1->stype.out.tfield.private_length); \ + ret = False; \ + } \ + s1 = fname_find(sname); \ + if ((s1 && strcmp(s1->stype.out.tfield.s, correct_name)) != 0 || \ + wire_bad_flags(&s1->stype.out.tfield, flags)) { \ + printf("(%d) path %s/%s incorrect - '%s/%d'\n", __LINE__, #stype, #tfield, \ + s1->stype.out.tfield.s, s1->stype.out.tfield.private_length); \ + ret = False; \ + }} while (0) + + NAME_CHECK("NAME_INFO", name_info, fname, STR_UNICODE); + NAME_CHECK("NAME_INFORMATION", name_info, fname, STR_UNICODE); + + /* the ALL_INFO file name is the full path on the filesystem */ + s1 = fnum_find("ALL_INFO"); + if (s1 && !s1->all_info.out.fname.s) { + printf("ALL_INFO didn't give a filename\n"); + ret = False; + } + if (s1 && s1->all_info.out.fname.s) { + char *p = strrchr(s1->all_info.out.fname.s, '\\'); + if (!p) { + printf("Not a full path in all_info/fname? - '%s'\n", + s1->all_info.out.fname.s); + ret = False; + } else { + if (strcmp(correct_name, p) != 0) { + printf("incorrect basename in all_info/fname - '%s'\n", + s1->all_info.out.fname.s); + ret = False; + } + } + if (wire_bad_flags(&s1->all_info.out.fname, STR_UNICODE)) { + printf("Should not null terminate all_info/fname\n"); + ret = False; + } + } + + s1 = fnum_find("ALT_NAME_INFO"); + correct_name = s1->alt_name_info.out.fname.s; + printf("alt_name: %s\n", correct_name); + + NAME_CHECK("ALT_NAME_INFO", alt_name_info, fname, STR_UNICODE); + NAME_CHECK("ALT_NAME_INFORMATION", alt_name_info, fname, STR_UNICODE); + + /* and make sure we can open by alternate name */ + cli_close(cli, fnum); + fnum = cli_nt_create_full(cli, correct_name, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, + FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_DELETE| + NTCREATEX_SHARE_ACCESS_READ| + NTCREATEX_SHARE_ACCESS_WRITE, + NTCREATEX_DISP_OVERWRITE_IF, + 0, 0); + if (fnum == -1) { + printf("Unable to open by alt_name - %s\n", cli_errstr(cli)); + ret = False; + } + + if (!skip_streams) { + correct_name = "::$DATA"; + printf("stream_name: %s\n", correct_name); + + NAME_CHECK("STREAM_INFO", stream_info, streams[0].stream_name, STR_UNICODE); + NAME_CHECK("STREAM_INFORMATION", stream_info, streams[0].stream_name, STR_UNICODE); + } + + /* make sure the EAs look right */ + s1 = fnum_find("ALL_EAS"); + s2 = fnum_find("ALL_INFO"); + if (s1) { + for (i=0;i<s1->all_eas.out.num_eas;i++) { + printf(" flags=%d %s=%*.*s\n", + s1->all_eas.out.eas[i].flags, + s1->all_eas.out.eas[i].name.s, + s1->all_eas.out.eas[i].value.length, + s1->all_eas.out.eas[i].value.length, + s1->all_eas.out.eas[i].value.data); + } + } + if (s1 && s2) { + if (s1->all_eas.out.num_eas == 0) { + if (s2->all_info.out.ea_size != 0) { + printf("ERROR: num_eas==0 but fnum all_info.out.ea_size == %d\n", + s2->all_info.out.ea_size); + } + } else { + if (s2->all_info.out.ea_size != + ea_list_size(s1->all_eas.out.num_eas, s1->all_eas.out.eas)) { + printf("ERROR: ea_list_size=%d != fnum all_info.out.ea_size=%d\n", + ea_list_size(s1->all_eas.out.num_eas, s1->all_eas.out.eas), + s2->all_info.out.ea_size); + } + } + } + s2 = fname_find("ALL_EAS"); + if (s2) { + VAL_EQUAL(all_eas, num_eas, all_eas, num_eas); + for (i=0;i<s1->all_eas.out.num_eas;i++) { + VAL_EQUAL(all_eas, eas[i].flags, all_eas, eas[i].flags); + STR_EQUAL(all_eas, eas[i].name, all_eas, eas[i].name); + VAL_EQUAL(all_eas, eas[i].value.length, all_eas, eas[i].value.length); + } + } + +#define VAL_CHECK(sname1, stype1, tfield1, sname2, stype2, tfield2) do { \ + s1 = fnum_find(sname1); s2 = fnum_find(sname2); \ + if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \ + printf("(%d) handle %s/%s != %s/%s - 0x%x vs 0x%x\n", __LINE__, \ + #stype1, #tfield1, #stype2, #tfield2, \ + s1->stype1.out.tfield1, s2->stype2.out.tfield2); \ + ret = False; \ + } \ + s1 = fname_find(sname1); s2 = fname_find(sname2); \ + if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \ + printf("(%d) path %s/%s != %s/%s - 0x%x vs 0x%x\n", __LINE__, \ + #stype1, #tfield1, #stype2, #tfield2, \ + s1->stype1.out.tfield1, s2->stype2.out.tfield2); \ + ret = False; \ + } \ + s1 = fnum_find(sname1); s2 = fname_find(sname2); \ + if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \ + printf("(%d) handle %s/%s != path %s/%s - 0x%x vs 0x%x\n", __LINE__, \ + #stype1, #tfield1, #stype2, #tfield2, \ + s1->stype1.out.tfield1, s2->stype2.out.tfield2); \ + ret = False; \ + } \ + s1 = fname_find(sname1); s2 = fnum_find(sname2); \ + if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \ + printf("(%d) path %s/%s != handle %s/%s - 0x%x vs 0x%x\n", __LINE__, \ + #stype1, #tfield1, #stype2, #tfield2, \ + s1->stype1.out.tfield1, s2->stype2.out.tfield2); \ + ret = False; \ + }} while (0) + + VAL_CHECK("STANDARD_INFO", standard_info, delete_pending, + "ALL_INFO", all_info, delete_pending); + VAL_CHECK("STANDARD_INFO", standard_info, directory, + "ALL_INFO", all_info, directory); + VAL_CHECK("STANDARD_INFO", standard_info, nlink, + "ALL_INFO", all_info, nlink); + VAL_CHECK("EA_INFO", ea_info, ea_size, + "ALL_INFO", all_info, ea_size); + VAL_CHECK("EA_SIZE", ea_size, ea_size, + "ALL_INFO", all_info, ea_size); + + +#define NAME_PATH_CHECK(sname, stype, field) do { \ + s1 = fname_find(sname); s2 = fnum_find(sname); \ + VAL_EQUAL(stype, field, stype, field); \ +} while (0) + + NAME_PATH_CHECK("INTERNAL_INFORMATION", internal_information, device); + NAME_PATH_CHECK("INTERNAL_INFORMATION", internal_information, inode); + NAME_PATH_CHECK("POSITION_INFORMATION", position_information, position); + NAME_PATH_CHECK("MODE_INFORMATION", mode_information, mode); + NAME_PATH_CHECK("ALIGNMENT_INFORMATION", alignment_information, alignment_requirement); + NAME_PATH_CHECK("ATTRIBUTE_TAG_INFORMATION", attribute_tag_information, attrib); + NAME_PATH_CHECK("ATTRIBUTE_TAG_INFORMATION", attribute_tag_information, reparse_tag); + +#if 0 + /* these are expected to differ */ + NAME_PATH_CHECK("ACCESS_INFORMATION", access_information, access_flags); +#endif + +#define UNKNOWN_CHECK(sname, stype, tfield) do { \ + s1 = fnum_find(sname); \ + if (s1 && s1->stype.out.tfield != 0) { \ + printf("(%d) handle %s/%s unknown != 0 (0x%x)\n", __LINE__, \ + #stype, #tfield, \ + (unsigned)s1->stype.out.tfield); \ + } \ + s1 = fname_find(sname); \ + if (s1 && s1->stype.out.tfield != 0) { \ + printf("(%d) path %s/%s unknown != 0 (0x%x)\n", __LINE__, \ + #stype, #tfield, \ + (unsigned)s1->stype.out.tfield); \ + }} while (0) + + /* now get a bit fancier .... */ + + /* when we set the delete disposition then the link count should drop + to 0 and delete_pending should be 1 */ + + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/qfsinfo.c b/source4/torture/raw/qfsinfo.c new file mode 100644 index 0000000000..274d1073af --- /dev/null +++ b/source4/torture/raw/qfsinfo.c @@ -0,0 +1,295 @@ +/* + Unix SMB/CIFS implementation. + RAW_QFS_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +static struct { + const char *name; + enum fsinfo_level level; + uint32 capability_mask; + NTSTATUS status; + union smb_fsinfo fsinfo; +} levels[] = { + {"DSKATTR", RAW_QFS_DSKATTR, }, + {"ALLOCATION", RAW_QFS_ALLOCATION, }, + {"VOLUME", RAW_QFS_VOLUME, }, + {"VOLUME_INFO", RAW_QFS_VOLUME_INFO, }, + {"SIZE_INFO", RAW_QFS_SIZE_INFO, }, + {"DEVICE_INFO", RAW_QFS_DEVICE_INFO, }, + {"ATTRIBUTE_INFO", RAW_QFS_ATTRIBUTE_INFO, }, + {"UNIX_INFO", RAW_QFS_UNIX_INFO, CAP_UNIX}, + {"VOLUME_INFORMATION", RAW_QFS_VOLUME_INFORMATION, }, + {"SIZE_INFORMATION", RAW_QFS_SIZE_INFORMATION, }, + {"DEVICE_INFORMATION", RAW_QFS_DEVICE_INFORMATION, }, + {"ATTRIBUTE_INFORMATION", RAW_QFS_ATTRIBUTE_INFORMATION, }, + {"QUOTA_INFORMATION", RAW_QFS_QUOTA_INFORMATION, }, + {"FULL_SIZE_INFORMATION", RAW_QFS_FULL_SIZE_INFORMATION, }, + {"OBJECTID_INFORMATION", RAW_QFS_OBJECTID_INFORMATION, }, + { NULL, } +}; + + +/* + find a level in the levels[] table +*/ +static union smb_fsinfo *find(const char *name) +{ + int i; + for (i=0; levels[i].name; i++) { + if (strcmp(name, levels[i].name) == 0) { + return &levels[i].fsinfo; + } + } + return NULL; +} + +/* local macros to make the code below more readable */ +#define VAL_EQUAL(n1, v1, n2, v2) do {if (s1->n1.out.v1 != s2->n2.out.v2) { \ + printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \ + #n1, #v1, (uint_t)s1->n1.out.v1, \ + #n2, #v2, (uint_t)s2->n2.out.v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +#define STR_EQUAL(n1, v1, n2, v2) do {if (!s1->n1.out.v1 && !s2->n2.out.v2) return True; \ + if (!s1->n1.out.v1 || !s2->n2.out.v2) return False; \ + if (strcmp(s1->n1.out.v1, s2->n2.out.v2)) { \ + printf("%s/%s [%s] != %s/%s [%s] at %s(%d)\n", \ + #n1, #v1, s1->n1.out.v1, \ + #n2, #v2, s2->n2.out.v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +#define STRUCT_EQUAL(n1, v1, n2, v2) do {if (memcmp(&s1->n1.out.v1,&s2->n2.out.v2,sizeof(s1->n1.out.v1))) { \ + printf("%s/%s != %s/%s at %s(%d)\n", \ + #n1, #v1, \ + #n2, #v2, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +/* used to find hints on unknown values - and to make sure + we zero-fill */ +#define VAL_UNKNOWN(n1, v1) do {if (s1->n1.out.v1 != 0) { \ + printf("%s/%s non-zero unknown - %u (0x%x) at %s(%d)\n", \ + #n1, #v1, \ + (uint_t)s1->n1.out.v1, \ + (uint_t)s1->n1.out.v1, \ + __FILE__, __LINE__); \ + ret = False; \ +}} while(0) + +/* basic testing of all RAW_QFS_* calls + for each call we test that it succeeds, and where possible test + for consistency between the calls. + + Some of the consistency tests assume that the target filesystem is + quiescent, which is sometimes hard to achieve +*/ +BOOL torture_raw_qfsinfo(int dummy) +{ + struct cli_state *cli; + int i; + BOOL ret = True; + int count; + union smb_fsinfo *s1, *s2; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_qfsinfo"); + + /* scan all the levels, pulling the results */ + for (i=0; levels[i].name; i++) { + printf("Running level %s\n", levels[i].name); + levels[i].fsinfo.generic.level = levels[i].level; + levels[i].status = smb_raw_fsinfo(cli->tree, mem_ctx, &levels[i].fsinfo); + } + + /* check for completely broken levels */ + for (count=i=0; levels[i].name; i++) { + uint32 cap = cli->transport->negotiate.capabilities; + /* see if this server claims to support this level */ + if ((cap & levels[i].capability_mask) != levels[i].capability_mask) { + continue; + } + + if (!NT_STATUS_IS_OK(levels[i].status)) { + printf("ERROR: level %s failed - %s\n", + levels[i].name, nt_errstr(levels[i].status)); + count++; + } + } + + if (count != 0) { + ret = False; + printf("%d levels failed\n", count); + if (count > 10) { + printf("too many level failures - giving up\n"); + goto done; + } + } + + printf("check for correct aliases\n"); + s1 = find("SIZE_INFO"); + s2 = find("SIZE_INFORMATION"); + if (s1 && s2) { + VAL_EQUAL(size_info, total_alloc_units, size_info, total_alloc_units); + VAL_EQUAL(size_info, avail_alloc_units, size_info, avail_alloc_units); + VAL_EQUAL(size_info, sectors_per_unit, size_info, sectors_per_unit); + VAL_EQUAL(size_info, bytes_per_sector, size_info, bytes_per_sector); + } + + s1 = find("DEVICE_INFO"); + s2 = find("DEVICE_INFORMATION"); + if (s1 && s2) { + VAL_EQUAL(device_info, device_type, device_info, device_type); + VAL_EQUAL(device_info, characteristics, device_info, characteristics); + } + + s1 = find("VOLUME_INFO"); + s2 = find("VOLUME_INFORMATION"); + if (s1 && s2) { + STRUCT_EQUAL(volume_info, create_time, volume_info, create_time); + VAL_EQUAL (volume_info, serial_number, volume_info, serial_number); + STR_EQUAL (volume_info, volume_name.s, volume_info, volume_name.s); + printf("volume_info.volume_name = '%s'\n", s1->volume_info.out.volume_name.s); + } + + s1 = find("ATTRIBUTE_INFO"); + s2 = find("ATTRIBUTE_INFORMATION"); + if (s1 && s2) { + VAL_EQUAL(attribute_info, fs_attr, + attribute_info, fs_attr); + VAL_EQUAL(attribute_info, max_file_component_length, + attribute_info, max_file_component_length); + STR_EQUAL(attribute_info, fs_type.s, attribute_info, fs_type.s); + printf("attribute_info.fs_type = '%s'\n", s1->attribute_info.out.fs_type.s); + } + + printf("check for consistent disk sizes\n"); + s1 = find("DSKATTR"); + s2 = find("ALLOCATION"); + if (s1 && s2) { + double size1, size2; + double scale = s1->dskattr.out.blocks_per_unit * s1->dskattr.out.block_size; + size1 = 1.0 * + s1->dskattr.out.units_total * + s1->dskattr.out.blocks_per_unit * + s1->dskattr.out.block_size / scale; + size2 = 1.0 * + s2->allocation.out.sectors_per_unit * + s2->allocation.out.total_alloc_units * + s2->allocation.out.bytes_per_sector / scale; + if (ABS(size1 - size2) > 1) { + printf("Inconsistent total size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", + size1, size2); + ret = False; + } + printf("total disk = %.0f MB\n", size1*scale/1.0e6); + } + + printf("check consistent free disk space\n"); + s1 = find("DSKATTR"); + s2 = find("ALLOCATION"); + if (s1 && s2) { + double size1, size2; + double scale = s1->dskattr.out.blocks_per_unit * s1->dskattr.out.block_size; + size1 = 1.0 * + s1->dskattr.out.units_free * + s1->dskattr.out.blocks_per_unit * + s1->dskattr.out.block_size / scale; + size2 = 1.0 * + s2->allocation.out.sectors_per_unit * + s2->allocation.out.avail_alloc_units * + s2->allocation.out.bytes_per_sector / scale; + if (ABS(size1 - size2) > 1) { + printf("Inconsistent avail size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", + size1, size2); + ret = False; + } + printf("free disk = %.0f MB\n", size1*scale/1.0e6); + } + + printf("volume info consistency\n"); + s1 = find("VOLUME"); + s2 = find("VOLUME_INFO"); + if (s1 && s2) { + VAL_EQUAL(volume, serial_number, volume_info, serial_number); + STR_EQUAL(volume, volume_name.s, volume_info, volume_name.s); + } + + /* disk size consistency - notice that 'avail_alloc_units' maps to the caller + available allocation units, not the total */ + s1 = find("SIZE_INFO"); + s2 = find("FULL_SIZE_INFORMATION"); + if (s1 && s2) { + VAL_EQUAL(size_info, total_alloc_units, full_size_information, total_alloc_units); + VAL_EQUAL(size_info, avail_alloc_units, full_size_information, call_avail_alloc_units); + VAL_EQUAL(size_info, sectors_per_unit, full_size_information, sectors_per_unit); + VAL_EQUAL(size_info, bytes_per_sector, full_size_information, bytes_per_sector); + } + + printf("check for non-zero unknown fields\n"); + s1 = find("QUOTA_INFORMATION"); + if (s1) { + VAL_UNKNOWN(quota_information, unknown[0]); + VAL_UNKNOWN(quota_information, unknown[1]); + VAL_UNKNOWN(quota_information, unknown[2]); + } + + s1 = find("OBJECTID_INFORMATION"); + if (s1) { + VAL_UNKNOWN(objectid_information, unknown[0]); + VAL_UNKNOWN(objectid_information, unknown[1]); + VAL_UNKNOWN(objectid_information, unknown[2]); + VAL_UNKNOWN(objectid_information, unknown[3]); + VAL_UNKNOWN(objectid_information, unknown[4]); + VAL_UNKNOWN(objectid_information, unknown[5]); + } + + +#define STR_CHECK(sname, stype, field, flags) do { \ + s1 = find(sname); \ + if (s1) { \ + if (wire_bad_flags(&s1->stype.out.field, flags)) { \ + printf("(%d) incorrect string termination in %s/%s\n", \ + __LINE__, #stype, #field); \ + ret = False; \ + } \ + }} while (0) + + printf("check for correct termination\n"); + STR_CHECK("VOLUME", volume, volume_name, 0); + STR_CHECK("VOLUME_INFO", volume_info, volume_name, STR_UNICODE); + STR_CHECK("VOLUME_INFORMATION", volume_info, volume_name, STR_UNICODE); + STR_CHECK("ATTRIBUTE_INFO", attribute_info, fs_type, STR_UNICODE); + STR_CHECK("ATTRIBUTE_INFORMATION", attribute_info, fs_type, STR_UNICODE); + +done: + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/read.c b/source4/torture/raw/read.c new file mode 100644 index 0000000000..c231f52c9d --- /dev/null +++ b/source4/torture/raw/read.c @@ -0,0 +1,732 @@ +/* + Unix SMB/CIFS implementation. + test suite for various read operations + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_VALUE(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) Incorrect value %s=%d - should be %d\n", \ + __LINE__, #v, v, correct); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_BUFFER(buf, seed, len) do { \ + if (!check_buffer(buf, seed, len, __LINE__)) { \ + ret = False; \ + goto done; \ + }} while (0) + +#define BASEDIR "\\testread" + + +/* + setup a random buffer based on a seed +*/ +static void setup_buffer(char *buf, unsigned seed, int len) +{ + int i; + srandom(seed); + for (i=0;i<len;i++) buf[i] = random(); +} + +/* + check a random buffer based on a seed +*/ +static BOOL check_buffer(char *buf, unsigned seed, int len, int line) +{ + int i; + srandom(seed); + for (i=0;i<len;i++) { + char v = random(); + if (buf[i] != v) { + printf("Buffer incorrect at line %d! ofs=%d v1=0x%x v2=0x%x\n", + line, i, buf[i], v); + return False; + } + } + return True; +} + +/* + test read ops +*/ +static BOOL test_read(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_read io; + NTSTATUS status; + BOOL ret = True; + int fnum; + char *buf; + const int maxsize = 90000; + const char *fname = BASEDIR "\\test.txt"; + const char *test_data = "TEST DATA"; + unsigned seed = time(NULL); + + buf = talloc_zero(mem_ctx, maxsize); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_READ_READ\n"); + io.generic.level = RAW_READ_READ; + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying empty file read\n"); + io.read.in.fnum = fnum; + io.read.in.count = 1; + io.read.in.offset = 0; + io.read.in.remaining = 0; + io.read.out.data = buf; + status = smb_raw_read(cli->tree, &io); + + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.read.out.nread, 0); + + printf("Trying zero file read\n"); + io.read.in.count = 0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.read.out.nread, 0); + + printf("Trying bad fnum\n"); + io.read.in.fnum = fnum+1; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + io.read.in.fnum = fnum; + + cli_write(cli, fnum, 0, test_data, 0, strlen(test_data)); + + printf("Trying small read\n"); + io.read.in.fnum = fnum; + io.read.in.offset = 0; + io.read.in.remaining = 0; + io.read.in.count = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.read.out.nread, strlen(test_data)); + if (memcmp(buf, test_data, strlen(test_data)) != 0) { + ret = False; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf); + goto done; + } + + printf("Trying short read\n"); + io.read.in.offset = 1; + io.read.in.count = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.read.out.nread, strlen(test_data)-1); + if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) { + ret = False; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf); + goto done; + } + + printf("Trying max offset\n"); + io.read.in.offset = ~0; + io.read.in.count = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.read.out.nread, 0); + + setup_buffer(buf, seed, maxsize); + cli_write(cli, fnum, 0, buf, 0, maxsize); + memset(buf, 0, maxsize); + + printf("Trying large read\n"); + io.read.in.offset = 0; + io.read.in.count = ~0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_BUFFER(buf, seed, io.read.out.nread); + + + printf("Trying locked region\n"); + cli->session->pid++; + if (!cli_lock(cli, fnum, 103, 1, 0, WRITE_LOCK)) { + printf("Failed to lock file at %d\n", __LINE__); + ret = False; + goto done; + } + cli->session->pid--; + memset(buf, 0, maxsize); + io.read.in.offset = 0; + io.read.in.count = ~0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + test lockread ops +*/ +static BOOL test_lockread(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_read io; + NTSTATUS status; + BOOL ret = True; + int fnum; + char *buf; + const int maxsize = 90000; + const char *fname = BASEDIR "\\test.txt"; + const char *test_data = "TEST DATA"; + unsigned seed = time(NULL); + + buf = talloc_zero(mem_ctx, maxsize); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_READ_LOCKREAD\n"); + io.generic.level = RAW_READ_LOCKREAD; + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying empty file read\n"); + io.lockread.in.fnum = fnum; + io.lockread.in.count = 1; + io.lockread.in.offset = 0; + io.lockread.in.remaining = 0; + io.lockread.out.data = buf; + status = smb_raw_read(cli->tree, &io); + + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.lockread.out.nread, 0); + + printf("Trying zero file read\n"); + io.lockread.in.count = 0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED); + + printf("Trying bad fnum\n"); + io.lockread.in.fnum = fnum+1; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + io.lockread.in.fnum = fnum; + + cli_write(cli, fnum, 0, test_data, 0, strlen(test_data)); + + printf("Trying small read\n"); + io.lockread.in.fnum = fnum; + io.lockread.in.offset = 0; + io.lockread.in.remaining = 0; + io.lockread.in.count = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + cli_unlock(cli, fnum, 0, 1); + + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.lockread.out.nread, strlen(test_data)); + if (memcmp(buf, test_data, strlen(test_data)) != 0) { + ret = False; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf); + goto done; + } + + printf("Trying short read\n"); + io.lockread.in.offset = 1; + io.lockread.in.count = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED); + cli_unlock(cli, fnum, 0, strlen(test_data)); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + CHECK_VALUE(io.lockread.out.nread, strlen(test_data)-1); + if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) { + ret = False; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf); + goto done; + } + + printf("Trying max offset\n"); + io.lockread.in.offset = ~0; + io.lockread.in.count = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.lockread.out.nread, 0); + + setup_buffer(buf, seed, maxsize); + cli_write(cli, fnum, 0, buf, 0, maxsize); + memset(buf, 0, maxsize); + + printf("Trying large read\n"); + io.lockread.in.offset = 0; + io.lockread.in.count = ~0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED); + cli_unlock(cli, fnum, 1, strlen(test_data)); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_BUFFER(buf, seed, io.lockread.out.nread); + cli_unlock(cli, fnum, 0, 0xFFFF); + + + printf("Trying locked region\n"); + cli->session->pid++; + if (!cli_lock(cli, fnum, 103, 1, 0, WRITE_LOCK)) { + printf("Failed to lock file at %d\n", __LINE__); + ret = False; + goto done; + } + cli->session->pid--; + memset(buf, 0, maxsize); + io.lockread.in.offset = 0; + io.lockread.in.count = ~0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + +done: + cli_close(cli, fnum); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + test readx ops +*/ +static BOOL test_readx(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_read io; + NTSTATUS status; + BOOL ret = True; + int fnum; + char *buf; + const int maxsize = 90000; + const char *fname = BASEDIR "\\test.txt"; + const char *test_data = "TEST DATA"; + unsigned seed = time(NULL); + + buf = talloc_zero(mem_ctx, maxsize); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_READ_READX\n"); + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying empty file read\n"); + io.generic.level = RAW_READ_READX; + io.readx.in.fnum = fnum; + io.readx.in.mincnt = 1; + io.readx.in.maxcnt = 1; + io.readx.in.offset = 0; + io.readx.in.remaining = 0; + io.readx.out.data = buf; + status = smb_raw_read(cli->tree, &io); + + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.nread, 0); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + + printf("Trying zero file read\n"); + io.readx.in.mincnt = 0; + io.readx.in.maxcnt = 0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.nread, 0); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + + printf("Trying bad fnum\n"); + io.readx.in.fnum = fnum+1; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + io.readx.in.fnum = fnum; + + cli_write(cli, fnum, 0, test_data, 0, strlen(test_data)); + + printf("Trying small read\n"); + io.readx.in.fnum = fnum; + io.readx.in.offset = 0; + io.readx.in.remaining = 0; + io.readx.in.mincnt = strlen(test_data); + io.readx.in.maxcnt = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.nread, strlen(test_data)); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + if (memcmp(buf, test_data, strlen(test_data)) != 0) { + ret = False; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf); + goto done; + } + + printf("Trying short read\n"); + io.readx.in.offset = 1; + io.readx.in.mincnt = strlen(test_data); + io.readx.in.maxcnt = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.nread, strlen(test_data)-1); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) { + ret = False; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf); + goto done; + } + + printf("Trying max offset\n"); + io.readx.in.offset = 0xffffffff; + io.readx.in.mincnt = strlen(test_data); + io.readx.in.maxcnt = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.nread, 0); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + + setup_buffer(buf, seed, maxsize); + cli_write(cli, fnum, 0, buf, 0, maxsize); + memset(buf, 0, maxsize); + + printf("Trying large read\n"); + io.readx.in.offset = 0; + io.readx.in.mincnt = ~0; + io.readx.in.maxcnt = ~0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt); + CHECK_BUFFER(buf, seed, io.readx.out.nread); + + printf("Trying mincnt > maxcnt\n"); + memset(buf, 0, maxsize); + io.readx.in.offset = 0; + io.readx.in.mincnt = 30000; + io.readx.in.maxcnt = 20000; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt); + CHECK_BUFFER(buf, seed, io.readx.out.nread); + + printf("Trying mincnt < maxcnt\n"); + memset(buf, 0, maxsize); + io.readx.in.offset = 0; + io.readx.in.mincnt = 20000; + io.readx.in.maxcnt = 30000; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt); + CHECK_BUFFER(buf, seed, io.readx.out.nread); + + printf("Trying locked region\n"); + cli->session->pid++; + if (!cli_lock(cli, fnum, 103, 1, 0, WRITE_LOCK)) { + printf("Failed to lock file at %d\n", __LINE__); + ret = False; + goto done; + } + cli->session->pid--; + memset(buf, 0, maxsize); + io.readx.in.offset = 0; + io.readx.in.mincnt = 100; + io.readx.in.maxcnt = 200; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + +#ifdef LARGE_SMB_OFF_T + printf("Trying large offset read\n"); + io.readx.in.offset = ((SMB_BIG_UINT)0x2) << 32; + io.readx.in.mincnt = 10; + io.readx.in.maxcnt = 10; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.nread, 0); + + if (!cli_lock64(cli, fnum, io.readx.in.offset, 1, 0, WRITE_LOCK)) { + printf("Failed to lock file at %d\n", __LINE__); + ret = False; + goto done; + } + + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.nread, 0); +#endif + +done: + cli_close(cli, fnum); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + test readbraw ops +*/ +static BOOL test_readbraw(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_read io; + NTSTATUS status; + BOOL ret = True; + int fnum; + char *buf; + const int maxsize = 90000; + const char *fname = BASEDIR "\\test.txt"; + const char *test_data = "TEST DATA"; + unsigned seed = time(NULL); + + buf = talloc_zero(mem_ctx, maxsize); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_READ_READBRAW\n"); + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying empty file read\n"); + io.generic.level = RAW_READ_READBRAW; + io.readbraw.in.fnum = fnum; + io.readbraw.in.mincnt = 1; + io.readbraw.in.maxcnt = 1; + io.readbraw.in.offset = 0; + io.readbraw.in.timeout = 0; + io.readbraw.out.data = buf; + status = smb_raw_read(cli->tree, &io); + + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, 0); + + printf("Trying zero file read\n"); + io.readbraw.in.mincnt = 0; + io.readbraw.in.maxcnt = 0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, 0); + + printf("Trying bad fnum\n"); + io.readbraw.in.fnum = fnum+1; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, 0); + io.readbraw.in.fnum = fnum; + + cli_write(cli, fnum, 0, test_data, 0, strlen(test_data)); + + printf("Trying small read\n"); + io.readbraw.in.fnum = fnum; + io.readbraw.in.offset = 0; + io.readbraw.in.mincnt = strlen(test_data); + io.readbraw.in.maxcnt = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, strlen(test_data)); + if (memcmp(buf, test_data, strlen(test_data)) != 0) { + ret = False; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf); + goto done; + } + + printf("Trying short read\n"); + io.readbraw.in.offset = 1; + io.readbraw.in.mincnt = strlen(test_data); + io.readbraw.in.maxcnt = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, strlen(test_data)-1); + if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) { + ret = False; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf); + goto done; + } + + printf("Trying max offset\n"); + io.readbraw.in.offset = ~0; + io.readbraw.in.mincnt = strlen(test_data); + io.readbraw.in.maxcnt = strlen(test_data); + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, 0); + + setup_buffer(buf, seed, maxsize); + cli_write(cli, fnum, 0, buf, 0, maxsize); + memset(buf, 0, maxsize); + + printf("Trying large read\n"); + io.readbraw.in.offset = 0; + io.readbraw.in.mincnt = ~0; + io.readbraw.in.maxcnt = ~0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, 0xFFFF); + CHECK_BUFFER(buf, seed, io.readbraw.out.nread); + + printf("Trying mincnt > maxcnt\n"); + memset(buf, 0, maxsize); + io.readbraw.in.offset = 0; + io.readbraw.in.mincnt = 30000; + io.readbraw.in.maxcnt = 20000; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt); + CHECK_BUFFER(buf, seed, io.readbraw.out.nread); + + printf("Trying mincnt < maxcnt\n"); + memset(buf, 0, maxsize); + io.readbraw.in.offset = 0; + io.readbraw.in.mincnt = 20000; + io.readbraw.in.maxcnt = 30000; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt); + CHECK_BUFFER(buf, seed, io.readbraw.out.nread); + + printf("Trying locked region\n"); + cli->session->pid++; + if (!cli_lock(cli, fnum, 103, 1, 0, WRITE_LOCK)) { + printf("Failed to lock file at %d\n", __LINE__); + ret = False; + goto done; + } + cli->session->pid--; + memset(buf, 0, maxsize); + io.readbraw.in.offset = 0; + io.readbraw.in.mincnt = 100; + io.readbraw.in.maxcnt = 200; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, 0); + + printf("Trying locked region with timeout\n"); + memset(buf, 0, maxsize); + io.readbraw.in.offset = 0; + io.readbraw.in.mincnt = 100; + io.readbraw.in.maxcnt = 200; + io.readbraw.in.timeout = 10000; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, 0); + +#ifdef LARGE_SMB_OFF_T + printf("Trying large offset read\n"); + io.readbraw.in.offset = ((SMB_BIG_UINT)0x2) << 32; + io.readbraw.in.mincnt = 10; + io.readbraw.in.maxcnt = 10; + io.readbraw.in.timeout = 0; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readbraw.out.nread, 0); +#endif + +done: + cli_close(cli, fnum); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + basic testing of read calls +*/ +BOOL torture_raw_read(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_read"); + + if (!test_read(cli, mem_ctx)) { + ret = False; + } + + if (!test_readx(cli, mem_ctx)) { + ret = False; + } + + if (!test_lockread(cli, mem_ctx)) { + ret = False; + } + + if (!test_readbraw(cli, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/rename.c b/source4/torture/raw/rename.c new file mode 100644 index 0000000000..4cfa1c95c2 --- /dev/null +++ b/source4/torture/raw/rename.c @@ -0,0 +1,128 @@ +/* + Unix SMB/CIFS implementation. + rename test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define BASEDIR "\\testrename" + +/* + test SMBmv ops +*/ +static BOOL test_mv(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + struct smb_rename io; + NTSTATUS status; + BOOL ret = True; + int fnum; + const char *fname1 = BASEDIR "\\test1.txt"; + const char *fname2 = BASEDIR "\\test2.txt"; + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Trying simple rename\n"); + + fnum = create_complex_file(cli, mem_ctx, fname1); + + io.in.pattern1 = fname1; + io.in.pattern2 = fname2; + io.in.attrib = 0; + + status = smb_raw_rename(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); + + smb_raw_exit(cli->session); + status = smb_raw_rename(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + + printf("trying wildcard rename\n"); + io.in.pattern1 = BASEDIR "\\*.txt"; + io.in.pattern2 = fname1; + + status = smb_raw_rename(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("and again\n"); + status = smb_raw_rename(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying extension change\n"); + io.in.pattern1 = BASEDIR "\\*.txt"; + io.in.pattern2 = BASEDIR "\\*.bak"; + status = smb_raw_rename(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb_raw_rename(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE); + + printf("Checking attrib handling\n"); + torture_set_file_attribute(cli->tree, BASEDIR "\\test1.bak", FILE_ATTRIBUTE_HIDDEN); + io.in.pattern1 = BASEDIR "\\test1.bak"; + io.in.pattern2 = BASEDIR "\\*.txt"; + io.in.attrib = 0; + status = smb_raw_rename(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE); + + io.in.attrib = FILE_ATTRIBUTE_HIDDEN; + status = smb_raw_rename(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + basic testing of rename calls +*/ +BOOL torture_raw_rename(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_rename"); + + if (!test_mv(cli, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/search.c b/source4/torture/raw/search.c new file mode 100644 index 0000000000..6cfdd2b3ff --- /dev/null +++ b/source4/torture/raw/search.c @@ -0,0 +1,610 @@ +/* + Unix SMB/CIFS implementation. + RAW_SEARCH_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +#define BASEDIR "\\testsearch" + +/* + callback function for single_search +*/ +static BOOL single_search_callback(void *private, union smb_search_data *file) +{ + union smb_search_data *data = private; + + *data = *file; + + return True; +} + +/* + do a single file (non-wildcard) search +*/ +static NTSTATUS single_search(struct cli_state *cli, + TALLOC_CTX *mem_ctx, + const char *pattern, + enum search_level level, + union smb_search_data *data) +{ + union smb_search_first io; + NTSTATUS status; + + io.generic.level = level; + if (level == RAW_SEARCH_SEARCH) { + io.search_first.in.max_count = 1; + io.search_first.in.search_attrib = 0; + io.search_first.in.pattern = pattern; + } else { + io.t2ffirst.in.search_attrib = 0; + io.t2ffirst.in.max_count = 1; + io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE; + io.t2ffirst.in.storage_type = 0; + io.t2ffirst.in.pattern = pattern; + } + + status = smb_raw_search_first(cli->tree, mem_ctx, + &io, (void *)data, single_search_callback); + + return status; +} + + +static struct { + const char *name; + enum search_level level; + uint32 capability_mask; + NTSTATUS status; + union smb_search_data data; +} levels[] = { + {"SEARCH", RAW_SEARCH_SEARCH, }, + {"STANDARD", RAW_SEARCH_STANDARD, }, + {"EA_SIZE", RAW_SEARCH_EA_SIZE, }, + {"DIRECTORY_INFO", RAW_SEARCH_DIRECTORY_INFO, }, + {"FULL_DIRECTORY_INFO", RAW_SEARCH_FULL_DIRECTORY_INFO, }, + {"NAME_INFO", RAW_SEARCH_NAME_INFO, }, + {"BOTH_DIRECTORY_INFO", RAW_SEARCH_BOTH_DIRECTORY_INFO, }, + {"LEVEL_261", RAW_SEARCH_261, }, + {"LEVEL_262", RAW_SEARCH_262, }, + {"UNIX_INFO", RAW_SEARCH_UNIX_INFO, CAP_UNIX} +}; + +/* find a level in the table by name */ +static union smb_search_data *find(const char *name) +{ + int i; + for (i=0;i<ARRAY_SIZE(levels);i++) { + if (NT_STATUS_IS_OK(levels[i].status) && + strcmp(levels[i].name, name) == 0) { + return &levels[i].data; + } + } + return NULL; +} + +/* + basic testing of all RAW_SEARCH_* calls using a single file +*/ +static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + BOOL ret = True; + int fnum; + const char *fname = "\\torture_search.txt"; + NTSTATUS status; + int i; + union smb_fileinfo all_info, alt_info, name_info; + union smb_search_data *s; + + printf("Testing one file searches\n"); + + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + /* call all the levels */ + for (i=0;i<ARRAY_SIZE(levels);i++) { + uint32 cap = cli->transport->negotiate.capabilities; + + levels[i].status = single_search(cli, mem_ctx, fname, + levels[i].level, &levels[i].data); + + /* see if this server claims to support this level */ + if ((cap & levels[i].capability_mask) != levels[i].capability_mask) { + continue; + } + + printf("testing %s\n", levels[i].name); + + if (!NT_STATUS_IS_OK(levels[i].status)) { + printf("search level %s(%d) failed - %s\n", + levels[i].name, (int)levels[i].level, + nt_errstr(levels[i].status)); + ret = False; + } + } + + /* get the all_info file into to check against */ + all_info.generic.level = RAW_FILEINFO_ALL_INFO; + all_info.generic.in.fname = fname; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &all_info); + if (!NT_STATUS_IS_OK(status)) { + printf("RAW_FILEINFO_ALL_INFO failed - %s\n", nt_errstr(status)); + ret = False; + goto done; + } + + alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO; + alt_info.generic.in.fname = fname; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &alt_info); + if (!NT_STATUS_IS_OK(status)) { + printf("RAW_FILEINFO_ALT_NAME_INFO failed - %s\n", nt_errstr(status)); + ret = False; + goto done; + } + + name_info.generic.level = RAW_FILEINFO_NAME_INFO; + name_info.generic.in.fname = fname; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &name_info); + if (!NT_STATUS_IS_OK(status)) { + printf("RAW_FILEINFO_NAME_INFO failed - %s\n", nt_errstr(status)); + ret = False; + goto done; + } + +#define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \ + s = find(name); \ + if (s) { \ + if (s->sname1.field1 != v.sname2.out.field2) { \ + printf("(%d) %s/%s [%d] != %s/%s [%d]\n", \ + __LINE__, \ + #sname1, #field1, (int)s->sname1.field1, \ + #sname2, #field2, (int)v.sname2.out.field2); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \ + s = find(name); \ + if (s) { \ + if (s->sname1.field1 != (~1 & nt_time_to_unix(&v.sname2.out.field2))) { \ + printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ + __LINE__, \ + #sname1, #field1, time_string(mem_ctx, s->sname1.field1), \ + #sname2, #field2, nt_time_string(mem_ctx, &v.sname2.out.field2)); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \ + s = find(name); \ + if (s) { \ + if (memcmp(&s->sname1.field1, &v.sname2.out.field2, sizeof(NTTIME))) { \ + printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ + __LINE__, \ + #sname1, #field1, nt_time_string(mem_ctx, &s->sname1.field1), \ + #sname2, #field2, nt_time_string(mem_ctx, &v.sname2.out.field2)); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \ + s = find(name); \ + if (s) { \ + if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \ + printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ + __LINE__, \ + #sname1, #field1, s->sname1.field1, \ + #sname2, #field2, v.sname2.out.field2.s); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \ + s = find(name); \ + if (s) { \ + if (!s->sname1.field1.s || \ + strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \ + wire_bad_flags(&s->sname1.field1, flags)) { \ + printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ + __LINE__, \ + #sname1, #field1, s->sname1.field1.s, \ + #sname2, #field2, v.sname2.out.field2.s); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_NAME(name, sname1, field1, fname, flags) do { \ + s = find(name); \ + if (s) { \ + if (!s->sname1.field1.s || \ + strcmp(s->sname1.field1.s, fname) || \ + wire_bad_flags(&s->sname1.field1, flags)) { \ + printf("(%d) %s/%s [%s] != %s\n", \ + __LINE__, \ + #sname1, #field1, s->sname1.field1.s, \ + fname); \ + ret = False; \ + } \ + }} while (0) + + /* check that all the results are as expected */ + CHECK_VAL("SEARCH", search, attrib, all_info, all_info, attrib); + CHECK_VAL("STANDARD", standard, attrib, all_info, all_info, attrib); + CHECK_VAL("EA_SIZE", ea_size, attrib, all_info, all_info, attrib); + CHECK_VAL("DIRECTORY_INFO", directory_info, attrib, all_info, all_info, attrib); + CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, attrib, all_info, all_info, attrib); + CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, attrib, all_info, all_info, attrib); + CHECK_VAL("LEVEL_261", level_261, attrib, all_info, all_info, attrib); + CHECK_VAL("LEVEL_262", level_262, attrib, all_info, all_info, attrib); + + CHECK_TIME("SEARCH", search, write_time, all_info, all_info, write_time); + CHECK_TIME("STANDARD", standard, write_time, all_info, all_info, write_time); + CHECK_TIME("EA_SIZE", ea_size, write_time, all_info, all_info, write_time); + CHECK_TIME("STANDARD", standard, create_time, all_info, all_info, create_time); + CHECK_TIME("EA_SIZE", ea_size, create_time, all_info, all_info, create_time); + CHECK_TIME("STANDARD", standard, access_time, all_info, all_info, access_time); + CHECK_TIME("EA_SIZE", ea_size, access_time, all_info, all_info, access_time); + + CHECK_NTTIME("DIRECTORY_INFO", directory_info, write_time, all_info, all_info, write_time); + CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, write_time, all_info, all_info, write_time); + CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, write_time, all_info, all_info, write_time); + CHECK_NTTIME("LEVEL_261", level_261, write_time, all_info, all_info, write_time); + CHECK_NTTIME("LEVEL_262", level_262, write_time, all_info, all_info, write_time); + + CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("LEVEL_261", level_261, create_time, all_info, all_info, create_time); + CHECK_NTTIME("LEVEL_262", level_262, create_time, all_info, all_info, create_time); + + CHECK_NTTIME("DIRECTORY_INFO", directory_info, access_time, all_info, all_info, access_time); + CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, access_time, all_info, all_info, access_time); + CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, access_time, all_info, all_info, access_time); + CHECK_NTTIME("LEVEL_261", level_261, access_time, all_info, all_info, access_time); + CHECK_NTTIME("LEVEL_262", level_262, access_time, all_info, all_info, access_time); + + CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("LEVEL_261", level_261, create_time, all_info, all_info, create_time); + CHECK_NTTIME("LEVEL_262", level_262, create_time, all_info, all_info, create_time); + + CHECK_VAL("SEARCH", search, size, all_info, all_info, size); + CHECK_VAL("STANDARD", standard, size, all_info, all_info, size); + CHECK_VAL("EA_SIZE", ea_size, size, all_info, all_info, size); + CHECK_VAL("DIRECTORY_INFO", directory_info, size, all_info, all_info, size); + CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, size, all_info, all_info, size); + CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, size, all_info, all_info, size); + CHECK_VAL("LEVEL_261", level_261, size, all_info, all_info, size); + CHECK_VAL("LEVEL_262", level_262, size, all_info, all_info, size); + + CHECK_VAL("STANDARD", standard, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("EA_SIZE", ea_size, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("DIRECTORY_INFO", directory_info, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("LEVEL_261", level_261, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("LEVEL_262", level_262, alloc_size, all_info, all_info, alloc_size); + + CHECK_VAL("EA_SIZE", ea_size, ea_size, all_info, all_info, ea_size); + CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, ea_size, all_info, all_info, ea_size); + CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, ea_size, all_info, all_info, ea_size); + CHECK_VAL("LEVEL_261", level_261, ea_size, all_info, all_info, ea_size); + CHECK_VAL("LEVEL_262", level_262, ea_size, all_info, all_info, ea_size); + + CHECK_STR("SEARCH", search, name, alt_info, alt_name_info, fname); + CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info, short_name, alt_info, alt_name_info, fname, STR_UNICODE); + + CHECK_NAME("STANDARD", standard, name, fname+1, 0); + CHECK_NAME("EA_SIZE", ea_size, name, fname+1, 0); + CHECK_NAME("DIRECTORY_INFO", directory_info, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("NAME_INFO", name_info, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("LEVEL_261", level_261, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("LEVEL_262", level_262, name, fname+1, STR_TERMINATE_ASCII); + +done: + smb_raw_exit(cli->session); + cli_unlink(cli, fname); + + return ret; +} + + +struct multiple_result { + TALLOC_CTX *mem_ctx; + int count; + union smb_search_data *list; +}; + +/* + callback function for multiple_search +*/ +static BOOL multiple_search_callback(void *private, union smb_search_data *file) +{ + struct multiple_result *data = private; + + + data->count++; + data->list = talloc_realloc(data->mem_ctx, + data->list, + data->count * (sizeof(data->list[0]))); + + data->list[data->count-1] = *file; + + return True; +} + +enum continue_type {CONT_FLAGS, CONT_NAME, CONT_RESUME_KEY}; + +/* + do a single file (non-wildcard) search +*/ +static NTSTATUS multiple_search(struct cli_state *cli, + TALLOC_CTX *mem_ctx, + const char *pattern, + enum search_level level, + enum continue_type cont_type, + void *data) +{ + union smb_search_first io; + union smb_search_next io2; + NTSTATUS status; + const int per_search = 300; + struct multiple_result *result = data; + + io.generic.level = level; + if (level == RAW_SEARCH_SEARCH) { + io.search_first.in.max_count = per_search; + io.search_first.in.search_attrib = 0; + io.search_first.in.pattern = pattern; + } else { + io.t2ffirst.in.search_attrib = 0; + io.t2ffirst.in.max_count = per_search; + io.t2ffirst.in.flags = 0; + io.t2ffirst.in.storage_type = 0; + io.t2ffirst.in.pattern = pattern; + if (cont_type == CONT_RESUME_KEY) { + io.t2ffirst.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME | + FLAG_TRANS2_FIND_BACKUP_INTENT; + } + } + + status = smb_raw_search_first(cli->tree, mem_ctx, + &io, data, multiple_search_callback); + + + while (NT_STATUS_IS_OK(status)) { + io2.generic.level = level; + if (level == RAW_SEARCH_SEARCH) { + io2.search_next.in.max_count = per_search; + io2.search_next.in.search_attrib = 0; + io2.search_next.in.search_id = result->list[result->count-1].search.search_id; + } else { + io2.t2fnext.in.handle = io.t2ffirst.out.handle; + io2.t2fnext.in.max_count = per_search; + io2.t2fnext.in.resume_key = 0; + io2.t2fnext.in.flags = 0; + io2.t2fnext.in.last_name = ""; + switch (cont_type) { + case CONT_RESUME_KEY: + if (level == RAW_SEARCH_STANDARD) { + io2.t2fnext.in.resume_key = + result->list[result->count-1].standard.resume_key; + } else { + io2.t2fnext.in.resume_key = + result->list[result->count-1].both_directory_info.file_index; + } + io2.t2fnext.in.flags = FLAG_TRANS2_FIND_REQUIRE_RESUME | + FLAG_TRANS2_FIND_BACKUP_INTENT; + break; + case CONT_NAME: + if (level == RAW_SEARCH_STANDARD) { + io2.t2fnext.in.last_name = + result->list[result->count-1].standard.name.s; + } else { + io2.t2fnext.in.last_name = + result->list[result->count-1].both_directory_info.name.s; + } + break; + case CONT_FLAGS: + io2.t2fnext.in.flags = FLAG_TRANS2_FIND_CONTINUE; + break; + } + } + + status = smb_raw_search_next(cli->tree, mem_ctx, + &io2, data, multiple_search_callback); + if (!NT_STATUS_IS_OK(status)) { + break; + } + if (level == RAW_SEARCH_SEARCH) { + if (io2.search_next.out.count == 0) { + break; + } + } else if (io2.t2fnext.out.count == 0 || + io2.t2fnext.out.end_of_search) { + break; + } + } + + return status; +} + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_VALUE(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) Incorrect value %s=%d - should be %d\n", \ + __LINE__, #v, v, correct); \ + ret = False; \ + }} while (0) + + +static int search_both_compare(union smb_search_data *d1, union smb_search_data *d2) +{ + return strcmp(d1->both_directory_info.name.s, d2->both_directory_info.name.s); +} + +static int search_standard_compare(union smb_search_data *d1, union smb_search_data *d2) +{ + return strcmp(d1->standard.name.s, d2->standard.name.s); +} + +static int search_old_compare(union smb_search_data *d1, union smb_search_data *d2) +{ + return strcmp(d1->search.name, d2->search.name); +} + + +/* + basic testing of search calls using many files +*/ +static BOOL test_many_files(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + const int num_files = 700; + int i, fnum, t; + char *fname; + BOOL ret = True; + NTSTATUS status; + struct multiple_result result; + struct { + const char *name; + const char *cont_name; + enum search_level level; + enum continue_type cont_type; + } search_types[] = { + {"BOTH_DIRECTORY_INFO", "FLAGS", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_FLAGS}, + {"BOTH_DIRECTORY_INFO", "KEY", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_RESUME_KEY}, + {"BOTH_DIRECTORY_INFO", "NAME", RAW_SEARCH_BOTH_DIRECTORY_INFO, CONT_NAME}, + {"STANDARD", "FLAGS", RAW_SEARCH_STANDARD, CONT_FLAGS}, + {"STANDARD", "KEY", RAW_SEARCH_STANDARD, CONT_RESUME_KEY}, + {"STANDARD", "NAME", RAW_SEARCH_STANDARD, CONT_NAME}, + {"SEARCH", "ID", RAW_SEARCH_SEARCH, CONT_RESUME_KEY} + }; + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Failed to create " BASEDIR " - %s\n", cli_errstr(cli)); + return False; + } + + printf("Creating %d files\n", num_files); + + for (i=0;i<num_files;i++) { + asprintf(&fname, BASEDIR "\\test%03d.txt", i); + fnum = cli_open(cli, fname, O_CREAT|O_RDWR, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + free(fname); + cli_close(cli, fnum); + } + + + for (t=0;t<ARRAY_SIZE(search_types);t++) { + ZERO_STRUCT(result); + result.mem_ctx = mem_ctx; + + printf("Continue %s via %s\n", search_types[t].name, search_types[t].cont_name); + + status = multiple_search(cli, mem_ctx, BASEDIR "\\*.*", + search_types[t].level, + search_types[t].cont_type, + &result); + + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(result.count, num_files); + + if (search_types[t].level == RAW_SEARCH_BOTH_DIRECTORY_INFO) { + qsort(result.list, result.count, sizeof(result.list[0]), search_both_compare); + } else if (search_types[t].level == RAW_SEARCH_STANDARD) { + qsort(result.list, result.count, sizeof(result.list[0]), search_standard_compare); + } else { + qsort(result.list, result.count, sizeof(result.list[0]), search_old_compare); + } + + for (i=0;i<num_files;i++) { + const char *s; + if (search_types[t].level == RAW_SEARCH_BOTH_DIRECTORY_INFO) { + s = result.list[i].both_directory_info.name.s; + } else if (search_types[t].level == RAW_SEARCH_STANDARD) { + s = result.list[i].standard.name.s; + } else { + s = result.list[i].search.name; + } + asprintf(&fname, "test%03d.txt", i); + if (strcmp(fname, s)) { + printf("Incorrect name %s at entry %d\n", s, i); + ret = False; + break; + } + free(fname); + } + } + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + + return ret; +} + + +/* + basic testing of all RAW_SEARCH_* calls using a single file +*/ +BOOL torture_raw_search(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_search"); + + if (!test_one_file(cli, mem_ctx)) { + ret = False; + } + + if (!test_many_files(cli, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + + return ret; +} diff --git a/source4/torture/raw/seek.c b/source4/torture/raw/seek.c new file mode 100644 index 0000000000..9379b676ab --- /dev/null +++ b/source4/torture/raw/seek.c @@ -0,0 +1,152 @@ +/* + Unix SMB/CIFS implementation. + seek test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_VALUE(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) Incorrect value %s=%d - should be %d\n", \ + __LINE__, #v, v, correct); \ + ret = False; \ + goto done; \ + }} while (0) + +#define BASEDIR "\\testseek" + +/* + test seek ops +*/ +static BOOL test_seek(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + struct smb_seek io; + union smb_fileinfo finfo; + NTSTATUS status; + BOOL ret = True; + int fnum; + const char *fname = BASEDIR "\\test.txt"; + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + printf("Failed to open test.txt - %s\n", cli_errstr(cli)); + ret = False; + goto done; + } + + finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; + finfo.position_information.in.fnum = fnum; + + printf("Trying bad handle\n"); + io.in.fnum = fnum+1; + io.in.mode = SEEK_MODE_START; + io.in.offset = 0; + status = smb_raw_seek(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("Trying simple seek\n"); + io.in.fnum = fnum; + io.in.mode = SEEK_MODE_START; + io.in.offset = 17; + status = smb_raw_seek(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.out.offset, 17); + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(finfo.position_information.out.position, 0); + + printf("Trying relative seek\n"); + io.in.fnum = fnum; + io.in.mode = SEEK_MODE_CURRENT; + io.in.offset = -3; + status = smb_raw_seek(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.out.offset, 14); + + printf("Trying end seek\n"); + io.in.fnum = fnum; + io.in.mode = SEEK_MODE_END; + io.in.offset = 0; + status = smb_raw_seek(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + finfo.generic.level = RAW_FILEINFO_ALL_INFO; + finfo.all_info.in.fnum = fnum; + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.out.offset, finfo.all_info.out.size); + + printf("Trying max seek\n"); + io.in.fnum = fnum; + io.in.mode = SEEK_MODE_START; + io.in.offset = -1; + status = smb_raw_seek(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.out.offset, 0xffffffff); + + printf("Trying max overflow\n"); + io.in.fnum = fnum; + io.in.mode = SEEK_MODE_CURRENT; + io.in.offset = 1000; + status = smb_raw_seek(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.out.offset, 999); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + basic testing of seek calls +*/ +BOOL torture_raw_seek(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_seek"); + + if (!test_seek(cli, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/setfileinfo.c b/source4/torture/raw/setfileinfo.c new file mode 100644 index 0000000000..c169895020 --- /dev/null +++ b/source4/torture/raw/setfileinfo.c @@ -0,0 +1,498 @@ +/* + Unix SMB/CIFS implementation. + RAW_SFILEINFO_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define BASEDIR "\\testsfileinfo" + +/* basic testing of all RAW_SFILEINFO_* calls + for each call we test that it succeeds, and where possible test + for consistency between the calls. +*/ +BOOL torture_raw_sfileinfo(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + int fnum = -1; + char *fnum_fname; + char *fnum_fname_new; + char *path_fname; + char *path_fname_new; + union smb_fileinfo finfo1, finfo2; + union smb_setfileinfo sfinfo; + NTSTATUS status, status2; + const char *call_name; + time_t basetime = (time(NULL) - 86400) & ~1; + BOOL check_fnum; + int n = time(NULL) % 100; + + asprintf(&path_fname, BASEDIR "\\fname_test_%d.txt", n); + asprintf(&path_fname_new, BASEDIR "\\fname_test_new_%d.txt", n); + asprintf(&fnum_fname, BASEDIR "\\fnum_test_%d.txt", n); + asprintf(&fnum_fname_new, BASEDIR "\\fnum_test_new_%d.txt", n); + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_sfileinfo"); + + cli_deltree(cli, BASEDIR); + cli_mkdir(cli, BASEDIR); + +#define RECREATE_FILE(fname) do { \ + if (fnum != -1) cli_close(cli, fnum); \ + fnum = create_complex_file(cli, mem_ctx, fname); \ + if (fnum == -1) { \ + printf("(%d) ERROR: open of %s failed (%s)\n", \ + __LINE__, fname, cli_errstr(cli)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define RECREATE_BOTH do { \ + RECREATE_FILE(path_fname); \ + cli_close(cli, fnum); \ + RECREATE_FILE(fnum_fname); \ + } while (0) + + RECREATE_BOTH; + +#define CHECK_CALL_FNUM(call, rightstatus) do { \ + check_fnum = True; \ + call_name = #call; \ + sfinfo.generic.level = RAW_SFILEINFO_ ## call; \ + sfinfo.generic.file.fnum = fnum; \ + status = smb_raw_setfileinfo(cli->tree, &sfinfo); \ + if (!NT_STATUS_EQUAL(status, rightstatus)) { \ + printf("(%d) %s - %s (should be %s)\n", __LINE__, #call, \ + nt_errstr(status), nt_errstr(rightstatus)); \ + ret = False; \ + } \ + finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \ + finfo1.generic.in.fnum = fnum; \ + status2 = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); \ + if (!NT_STATUS_IS_OK(status2)) { \ + printf("(%d) %s pathinfo - %s\n", __LINE__, #call, nt_errstr(status)); \ + ret = False; \ + }} while (0) + +#define CHECK_CALL_PATH(call, rightstatus) do { \ + check_fnum = False; \ + call_name = #call; \ + sfinfo.generic.level = RAW_SFILEINFO_ ## call; \ + sfinfo.generic.file.fname = path_fname; \ + status = smb_raw_setpathinfo(cli->tree, &sfinfo); \ + if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \ + sfinfo.generic.file.fname = path_fname_new; \ + status = smb_raw_setpathinfo(cli->tree, &sfinfo); \ + } \ + if (!NT_STATUS_EQUAL(status, rightstatus)) { \ + printf("(%d) %s - %s (should be %s)\n", __LINE__, #call, \ + nt_errstr(status), nt_errstr(rightstatus)); \ + ret = False; \ + } \ + finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \ + finfo1.generic.in.fname = path_fname; \ + status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo1); \ + if (NT_STATUS_EQUAL(status2, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \ + finfo1.generic.in.fname = path_fname_new; \ + status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo1); \ + } \ + if (!NT_STATUS_IS_OK(status2)) { \ + printf("(%d) %s pathinfo - %s\n", __LINE__, #call, nt_errstr(status2)); \ + ret = False; \ + }} while (0) + +#define CHECK1(call) \ + do { if (NT_STATUS_IS_OK(status)) { \ + finfo2.generic.level = RAW_FILEINFO_ ## call; \ + if (check_fnum) { \ + finfo2.generic.in.fnum = fnum; \ + status2 = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); \ + } else { \ + finfo2.generic.in.fname = path_fname; \ + status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); \ + if (NT_STATUS_EQUAL(status2, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \ + finfo2.generic.in.fname = path_fname_new; \ + status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); \ + } \ + } \ + if (!NT_STATUS_IS_OK(status2)) { \ + printf("%s - %s\n", #call, nt_errstr(status2)); \ + } \ + }} while (0) + +#define CHECK_VALUE(call, stype, field, value) do { \ + CHECK1(call); \ + if (NT_STATUS_IS_OK(status) && finfo2.stype.out.field != value) { \ + printf("(%d) %s - %s/%s should be 0x%x - 0x%x\n", __LINE__, \ + call_name, #stype, #field, \ + (uint_t)value, (uint_t)finfo2.stype.out.field); \ + dump_all_info(mem_ctx, &finfo1); \ + }} while (0) + +#define CHECK_TIME(call, stype, field, value) do { \ + CHECK1(call); \ + if (NT_STATUS_IS_OK(status) && nt_time_to_unix(&finfo2.stype.out.field) != value) { \ + printf("(%d) %s - %s/%s should be 0x%x - 0x%x\n", __LINE__, \ + call_name, #stype, #field, \ + (uint_t)value, \ + (uint_t)nt_time_to_unix(&finfo2.stype.out.field)); \ + printf("\t%s", http_timestring(mem_ctx, value)); \ + printf("\t%s\n", nt_time_string(mem_ctx, &finfo2.stype.out.field)); \ + dump_all_info(mem_ctx, &finfo1); \ + }} while (0) + +#define CHECK_STR(call, stype, field, value) do { \ + CHECK1(call); \ + if (NT_STATUS_IS_OK(status) && strcmp(finfo2.stype.out.field, value) != 0) { \ + printf("(%d) %s - %s/%s should be '%s' - '%s'\n", __LINE__, \ + call_name, #stype, #field, \ + value, \ + finfo2.stype.out.field); \ + dump_all_info(mem_ctx, &finfo1); \ + }} while (0) + + + printf("test setattr\n"); + sfinfo.setattr.in.attrib = FILE_ATTRIBUTE_READONLY; + sfinfo.setattr.in.write_time = basetime; + CHECK_CALL_PATH(SETATTR, NT_STATUS_OK); + CHECK_VALUE (ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + CHECK_TIME (ALL_INFO, all_info, write_time, basetime); + + printf("setting to NORMAL doesn't do anything\n"); + sfinfo.setattr.in.attrib = FILE_ATTRIBUTE_NORMAL; + sfinfo.setattr.in.write_time = 0; + CHECK_CALL_PATH(SETATTR, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + CHECK_TIME (ALL_INFO, all_info, write_time, basetime); + + printf("a zero write_time means don't change\n"); + sfinfo.setattr.in.attrib = 0; + sfinfo.setattr.in.write_time = 0; + CHECK_CALL_PATH(SETATTR, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL); + CHECK_TIME (ALL_INFO, all_info, write_time, basetime); + + printf("test setattre\n"); + sfinfo.setattre.in.create_time = basetime + 20; + sfinfo.setattre.in.access_time = basetime + 30; + sfinfo.setattre.in.write_time = basetime + 40; + CHECK_CALL_FNUM(SETATTRE, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 20); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 30); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 40); + + sfinfo.setattre.in.create_time = 0; + sfinfo.setattre.in.access_time = 0; + sfinfo.setattre.in.write_time = 0; + CHECK_CALL_FNUM(SETATTRE, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 20); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 30); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 40); + + printf("test standard level\n"); + sfinfo.standard.in.create_time = basetime + 100; + sfinfo.standard.in.access_time = basetime + 200; + sfinfo.standard.in.write_time = basetime + 300; + CHECK_CALL_FNUM(STANDARD, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + + printf("test basic_info level\n"); + basetime += 86400; + unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100); + unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200); + unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300); + unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400); + sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY; + CHECK_CALL_FNUM(BASIC_INFO, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + + printf("a zero time means don't change\n"); + unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0); + sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL; + CHECK_CALL_FNUM(BASIC_INFO, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL); + + printf("test basic_information level\n"); + basetime += 86400; + unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100); + unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200); + unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300); + unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400); + sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY; + CHECK_CALL_FNUM(BASIC_INFORMATION, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + + CHECK_CALL_PATH(BASIC_INFORMATION, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + + printf("a zero time means don't change\n"); + unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0); + sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL; + CHECK_CALL_FNUM(BASIC_INFORMATION, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL); + + CHECK_CALL_PATH(BASIC_INFORMATION, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + + /* interesting - w2k3 leaves change_time as current time for 0 change time + in setpathinfo + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + */ + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL); + + printf("test disposition_info level\n"); + sfinfo.disposition_info.in.delete_on_close = 1; + CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1); + CHECK_VALUE(ALL_INFO, all_info, nlink, 0); + + sfinfo.disposition_info.in.delete_on_close = 0; + CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0); + CHECK_VALUE(ALL_INFO, all_info, nlink, 1); + + printf("test disposition_information level\n"); + sfinfo.disposition_info.in.delete_on_close = 1; + CHECK_CALL_FNUM(DISPOSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1); + CHECK_VALUE(ALL_INFO, all_info, nlink, 0); + + /* this would delete the file! */ + /* + CHECK_CALL_PATH(DISPOSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1); + CHECK_VALUE(ALL_INFO, all_info, nlink, 0); + */ + + sfinfo.disposition_info.in.delete_on_close = 0; + CHECK_CALL_FNUM(DISPOSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0); + CHECK_VALUE(ALL_INFO, all_info, nlink, 1); + + CHECK_CALL_PATH(DISPOSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0); + CHECK_VALUE(ALL_INFO, all_info, nlink, 1); + + printf("test allocation_info level\n"); + sfinfo.allocation_info.in.alloc_size = 0; + CHECK_CALL_FNUM(ALLOCATION_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0); + + sfinfo.allocation_info.in.alloc_size = 4096; + CHECK_CALL_FNUM(ALLOCATION_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 4096); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + + RECREATE_BOTH; + sfinfo.allocation_info.in.alloc_size = 0; + CHECK_CALL_FNUM(ALLOCATION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0); + + CHECK_CALL_PATH(ALLOCATION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0); + + sfinfo.allocation_info.in.alloc_size = 4096; + CHECK_CALL_FNUM(ALLOCATION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 4096); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + + /* setting the allocation size up via setpathinfo seems + to be broken in w2k3 */ + CHECK_CALL_PATH(ALLOCATION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + + printf("test end_of_file_info level\n"); + sfinfo.end_of_file_info.in.size = 37; + CHECK_CALL_FNUM(END_OF_FILE_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 37); + + sfinfo.end_of_file_info.in.size = 7; + CHECK_CALL_FNUM(END_OF_FILE_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 7); + + sfinfo.end_of_file_info.in.size = 37; + CHECK_CALL_FNUM(END_OF_FILE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 37); + + CHECK_CALL_PATH(END_OF_FILE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 37); + + sfinfo.end_of_file_info.in.size = 7; + CHECK_CALL_FNUM(END_OF_FILE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 7); + + CHECK_CALL_PATH(END_OF_FILE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 7); + + printf("test position_information level\n"); + sfinfo.position_information.in.position = 123456; + CHECK_CALL_FNUM(POSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(POSITION_INFORMATION, position_information, position, 123456); + + CHECK_CALL_PATH(POSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(POSITION_INFORMATION, position_information, position, 0); + + printf("test mode_information level\n"); + sfinfo.mode_information.in.mode = 2; + CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 2); + + CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0); + + sfinfo.mode_information.in.mode = 1; + CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER); + CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER); + + sfinfo.mode_information.in.mode = 0; + CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0); + + CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0); + + printf("finally the rename_information level\n"); + cli_close(cli, create_complex_file(cli, mem_ctx, fnum_fname_new)); + cli_close(cli, create_complex_file(cli, mem_ctx, path_fname_new)); + + sfinfo.rename_information.in.overwrite = 0; + sfinfo.rename_information.in.root_fid = 0; + sfinfo.rename_information.in.new_name = fnum_fname_new+strlen(BASEDIR)+1; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OBJECT_NAME_COLLISION); + + sfinfo.rename_information.in.new_name = path_fname_new+strlen(BASEDIR)+1; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OBJECT_NAME_COLLISION); + + sfinfo.rename_information.in.new_name = fnum_fname_new+strlen(BASEDIR)+1; + sfinfo.rename_information.in.overwrite = 1; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new); + + sfinfo.rename_information.in.new_name = path_fname_new+strlen(BASEDIR)+1; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_fname_new); + + sfinfo.rename_information.in.new_name = fnum_fname+strlen(BASEDIR)+1; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname); + + sfinfo.rename_information.in.new_name = path_fname+strlen(BASEDIR)+1; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_fname); + +#if 0 + printf("test unix_basic level\n"); + CHECK_CALL_FNUM(UNIX_BASIC, NT_STATUS_OK); + CHECK_CALL_PATH(UNIX_BASIC, NT_STATUS_OK); + + printf("test unix_link level\n"); + CHECK_CALL_FNUM(UNIX_LINK, NT_STATUS_OK); + CHECK_CALL_PATH(UNIX_LINK, NT_STATUS_OK); +#endif + +done: + cli_close(cli, fnum); + if (!cli_unlink(cli, fnum_fname)) { + printf("Failed to delete %s - %s\n", fnum_fname, cli_errstr(cli)); + } + if (!cli_unlink(cli, path_fname)) { + printf("Failed to delete %s - %s\n", path_fname, cli_errstr(cli)); + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} + + +/* + look for the w2k3 setpathinfo STANDARD bug +*/ +BOOL torture_raw_sfileinfo_bug(int dummy) +{ + struct cli_state *cli; + TALLOC_CTX *mem_ctx; + const char *fname = "\\bug3.txt"; + union smb_setfileinfo sfinfo; + NTSTATUS status; + int fnum; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_sfileinfo"); + + fnum = create_complex_file(cli, mem_ctx, fname); + cli_close(cli, fnum); + + sfinfo.generic.level = RAW_SFILEINFO_STANDARD; + sfinfo.generic.file.fname = fname; + + sfinfo.standard.in.create_time = 0; + sfinfo.standard.in.access_time = 0; + sfinfo.standard.in.write_time = 0; + + status = smb_raw_setpathinfo(cli->tree, &sfinfo); + printf("%s - %s\n", fname, nt_errstr(status)); + + printf("now try and delete %s\n", fname); + + return True; +} diff --git a/source4/torture/raw/unlink.c b/source4/torture/raw/unlink.c new file mode 100644 index 0000000000..9cae91fe41 --- /dev/null +++ b/source4/torture/raw/unlink.c @@ -0,0 +1,148 @@ +/* + Unix SMB/CIFS implementation. + unlink test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define BASEDIR "\\testunlink" + +/* + test unlink ops +*/ +static BOOL test_unlink(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + struct smb_unlink io; + NTSTATUS status; + BOOL ret = True; + const char *fname = BASEDIR "\\test.txt"; + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Trying non-existant file\n"); + io.in.pattern = fname; + io.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + + cli_close(cli, cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE)); + + io.in.pattern = fname; + io.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying a hidden file\n"); + cli_close(cli, cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE)); + torture_set_file_attribute(cli->tree, fname, FILE_ATTRIBUTE_HIDDEN); + + io.in.pattern = fname; + io.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE); + + io.in.pattern = fname; + io.in.attrib = FILE_ATTRIBUTE_HIDDEN; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying a directory\n"); + io.in.pattern = BASEDIR; + io.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY); + + io.in.pattern = BASEDIR; + io.in.attrib = FILE_ATTRIBUTE_DIRECTORY; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY); + + printf("Trying a bad path\n"); + io.in.pattern = ".."; + io.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD); + + printf("Trying wildcards\n"); + cli_close(cli, cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE)); + io.in.pattern = BASEDIR "\\t*.t"; + io.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE); + + io.in.pattern = BASEDIR "\\*"; + io.in.attrib = FILE_ATTRIBUTE_DIRECTORY; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID); + + io.in.pattern = BASEDIR "\\*.dat"; + io.in.attrib = FILE_ATTRIBUTE_DIRECTORY; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE); + + io.in.pattern = BASEDIR "\\*.tx?"; + io.in.attrib = 0; + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb_raw_unlink(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE); + + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + basic testing of unlink calls +*/ +BOOL torture_raw_unlink(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_unlink"); + + if (!test_unlink(cli, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/write.c b/source4/torture/raw/write.c new file mode 100644 index 0000000000..117b322530 --- /dev/null +++ b/source4/torture/raw/write.c @@ -0,0 +1,702 @@ +/* + Unix SMB/CIFS implementation. + test suite for various write operations + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%d) Incorrect status %s - should be %s\n", \ + __LINE__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_VALUE(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%d) Incorrect value %s=%d - should be %d\n", \ + __LINE__, #v, v, correct); \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_BUFFER(buf, seed, len) do { \ + if (!check_buffer(buf, seed, len, __LINE__)) { \ + ret = False; \ + goto done; \ + }} while (0) + +#define CHECK_ALL_INFO(v, field) do { \ + finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \ + finfo.all_info.in.fname = fname; \ + status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \ + CHECK_STATUS(status, NT_STATUS_OK); \ + if ((v) != finfo.all_info.out.field) { \ + printf("(%d) wrong value for field %s %.0f - %.0f\n", \ + __LINE__, #field, (double)v, (double)finfo.all_info.out.field); \ + dump_all_info(mem_ctx, &finfo); \ + ret = False; \ + }} while (0) + + +#define BASEDIR "\\testwrite" + + +/* + setup a random buffer based on a seed +*/ +static void setup_buffer(char *buf, unsigned seed, int len) +{ + int i; + srandom(seed); + for (i=0;i<len;i++) buf[i] = random(); +} + +/* + check a random buffer based on a seed +*/ +static BOOL check_buffer(char *buf, unsigned seed, int len, int line) +{ + int i; + srandom(seed); + for (i=0;i<len;i++) { + char v = random(); + if (buf[i] != v) { + printf("Buffer incorrect at line %d! ofs=%d buf=0x%x correct=0x%x\n", + line, i, buf[i], v); + return False; + } + } + return True; +} + +/* + test write ops +*/ +static BOOL test_write(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_write io; + NTSTATUS status; + BOOL ret = True; + int fnum; + char *buf; + const int maxsize = 90000; + const char *fname = BASEDIR "\\test.txt"; + unsigned seed = time(NULL); + union smb_fileinfo finfo; + + buf = talloc_zero(mem_ctx, maxsize); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_WRITE_WRITE\n"); + io.generic.level = RAW_WRITE_WRITE; + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying zero write\n"); + io.write.in.fnum = fnum; + io.write.in.count = 0; + io.write.in.offset = 0; + io.write.in.remaining = 0; + io.write.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.write.out.nwritten, 0); + + setup_buffer(buf, seed, maxsize); + + printf("Trying small write\n"); + io.write.in.count = 9; + io.write.in.offset = 4; + io.write.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.write.out.nwritten, io.write.in.count); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, 0, 13) != 13) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf+4, seed, 9); + CHECK_VALUE(IVAL(buf,0), 0); + + setup_buffer(buf, seed, maxsize); + + printf("Trying large write\n"); + io.write.in.count = 4000; + io.write.in.offset = 0; + io.write.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.write.out.nwritten, 4000); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, 0, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed, 4000); + + printf("Trying bad fnum\n"); + io.write.in.fnum = fnum+1; + io.write.in.count = 4000; + io.write.in.offset = 0; + io.write.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("Setting file as sparse\n"); + status = torture_set_sparse(cli->tree, fnum); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying 2^32 offset\n"); + setup_buffer(buf, seed, maxsize); + io.write.in.fnum = fnum; + io.write.in.count = 4000; + io.write.in.offset = 0xFFFFFFFF - 2000; + io.write.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.write.out.nwritten, 4000); + CHECK_ALL_INFO(io.write.in.count + (SMB_BIG_UINT)io.write.in.offset, size); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, io.write.in.offset, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed, 4000); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + test writex ops +*/ +static BOOL test_writex(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_write io; + NTSTATUS status; + BOOL ret = True; + int fnum; + char *buf; + const int maxsize = 90000; + const char *fname = BASEDIR "\\test.txt"; + unsigned seed = time(NULL); + union smb_fileinfo finfo; + + buf = talloc_zero(mem_ctx, maxsize); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_WRITE_WRITEX\n"); + io.generic.level = RAW_WRITE_WRITEX; + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying zero write\n"); + io.writex.in.fnum = fnum; + io.writex.in.offset = 0; + io.writex.in.wmode = 0; + io.writex.in.remaining = 0; + io.writex.in.count = 0; + io.writex.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writex.out.nwritten, 0); + + setup_buffer(buf, seed, maxsize); + + printf("Trying small write\n"); + io.writex.in.count = 9; + io.writex.in.offset = 4; + io.writex.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writex.out.nwritten, io.writex.in.count); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, 0, 13) != 13) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf+4, seed, 9); + CHECK_VALUE(IVAL(buf,0), 0); + + setup_buffer(buf, seed, maxsize); + + printf("Trying large write\n"); + io.writex.in.count = 4000; + io.writex.in.offset = 0; + io.writex.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writex.out.nwritten, 4000); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, 0, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed, 4000); + + printf("Trying bad fnum\n"); + io.writex.in.fnum = fnum+1; + io.writex.in.count = 4000; + io.writex.in.offset = 0; + io.writex.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("Testing wmode\n"); + io.writex.in.fnum = fnum; + io.writex.in.count = 1; + io.writex.in.offset = 0; + io.writex.in.wmode = 1; + io.writex.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writex.out.nwritten, io.writex.in.count); + + io.writex.in.wmode = 2; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writex.out.nwritten, io.writex.in.count); + + + printf("Trying locked region\n"); + cli->session->pid++; + if (!cli_lock(cli, fnum, 3, 1, 0, WRITE_LOCK)) { + printf("Failed to lock file at %d\n", __LINE__); + ret = False; + goto done; + } + cli->session->pid--; + io.writex.in.wmode = 0; + io.writex.in.count = 4; + io.writex.in.offset = 0; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + printf("Setting file as sparse\n"); + status = torture_set_sparse(cli->tree, fnum); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying 2^32 offset\n"); + setup_buffer(buf, seed, maxsize); + io.writex.in.fnum = fnum; + io.writex.in.count = 4000; + io.writex.in.offset = 0xFFFFFFFF - 2000; + io.writex.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writex.out.nwritten, 4000); + CHECK_ALL_INFO(io.writex.in.count + (SMB_BIG_UINT)io.writex.in.offset, size); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, io.writex.in.offset, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed, 4000); + + printf("Trying 2^43 offset\n"); + setup_buffer(buf, seed+1, maxsize); + io.writex.in.fnum = fnum; + io.writex.in.count = 4000; + io.writex.in.offset = ((SMB_BIG_UINT)1) << 43; + io.writex.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writex.out.nwritten, 4000); + CHECK_ALL_INFO(io.writex.in.count + (SMB_BIG_UINT)io.writex.in.offset, size); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, io.writex.in.offset, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed+1, 4000); + + + setup_buffer(buf, seed, maxsize); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + test write unlock ops +*/ +static BOOL test_writeunlock(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_write io; + NTSTATUS status; + BOOL ret = True; + int fnum; + char *buf; + const int maxsize = 90000; + const char *fname = BASEDIR "\\test.txt"; + unsigned seed = time(NULL); + union smb_fileinfo finfo; + + buf = talloc_zero(mem_ctx, maxsize); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_WRITE_WRITEUNLOCK\n"); + io.generic.level = RAW_WRITE_WRITEUNLOCK; + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying zero write\n"); + io.writeunlock.in.fnum = fnum; + io.writeunlock.in.count = 0; + io.writeunlock.in.offset = 0; + io.writeunlock.in.remaining = 0; + io.writeunlock.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeunlock.out.nwritten, io.writeunlock.in.count); + + setup_buffer(buf, seed, maxsize); + + printf("Trying small write\n"); + io.writeunlock.in.count = 9; + io.writeunlock.in.offset = 4; + io.writeunlock.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + if (cli_read(cli, fnum, buf, 0, 13) != 13) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf+4, seed, 9); + CHECK_VALUE(IVAL(buf,0), 0); + + setup_buffer(buf, seed, maxsize); + cli_lock(cli, fnum, io.writeunlock.in.offset, io.writeunlock.in.count, + 0, WRITE_LOCK); + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeunlock.out.nwritten, io.writeunlock.in.count); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, 0, 13) != 13) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf+4, seed, 9); + CHECK_VALUE(IVAL(buf,0), 0); + + setup_buffer(buf, seed, maxsize); + + printf("Trying large write\n"); + io.writeunlock.in.count = 4000; + io.writeunlock.in.offset = 0; + io.writeunlock.in.data = buf; + cli_lock(cli, fnum, io.writeunlock.in.offset, io.writeunlock.in.count, + 0, WRITE_LOCK); + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeunlock.out.nwritten, 4000); + + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, 0, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed, 4000); + + printf("Trying bad fnum\n"); + io.writeunlock.in.fnum = fnum+1; + io.writeunlock.in.count = 4000; + io.writeunlock.in.offset = 0; + io.writeunlock.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("Setting file as sparse\n"); + status = torture_set_sparse(cli->tree, fnum); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying 2^32 offset\n"); + setup_buffer(buf, seed, maxsize); + io.writeunlock.in.fnum = fnum; + io.writeunlock.in.count = 4000; + io.writeunlock.in.offset = 0xFFFFFFFF - 2000; + io.writeunlock.in.data = buf; + cli_lock(cli, fnum, io.writeunlock.in.offset, io.writeunlock.in.count, + 0, WRITE_LOCK); + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeunlock.out.nwritten, 4000); + CHECK_ALL_INFO(io.writeunlock.in.count + (SMB_BIG_UINT)io.writeunlock.in.offset, size); + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, io.writeunlock.in.offset, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed, 4000); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + test write close ops +*/ +static BOOL test_writeclose(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_write io; + NTSTATUS status; + BOOL ret = True; + int fnum; + char *buf; + const int maxsize = 90000; + const char *fname = BASEDIR "\\test.txt"; + unsigned seed = time(NULL); + union smb_fileinfo finfo; + + buf = talloc_zero(mem_ctx, maxsize); + + if (cli_deltree(cli, BASEDIR) == -1 || + !cli_mkdir(cli, BASEDIR)) { + printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli)); + return False; + } + + printf("Testing RAW_WRITE_WRITECLOSE\n"); + io.generic.level = RAW_WRITE_WRITECLOSE; + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + printf("Failed to create %s - %s\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + printf("Trying zero write\n"); + io.writeclose.in.fnum = fnum; + io.writeclose.in.count = 0; + io.writeclose.in.offset = 0; + io.writeclose.in.mtime = 0; + io.writeclose.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeclose.out.nwritten, io.writeclose.in.count); + + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeclose.out.nwritten, io.writeclose.in.count); + + setup_buffer(buf, seed, maxsize); + + printf("Trying small write\n"); + io.writeclose.in.count = 9; + io.writeclose.in.offset = 4; + io.writeclose.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + fnum = cli_open(cli, fname, O_RDWR, DENY_NONE); + io.writeclose.in.fnum = fnum; + + if (cli_read(cli, fnum, buf, 0, 13) != 13) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf+4, seed, 9); + CHECK_VALUE(IVAL(buf,0), 0); + + setup_buffer(buf, seed, maxsize); + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeclose.out.nwritten, io.writeclose.in.count); + + fnum = cli_open(cli, fname, O_RDWR, DENY_NONE); + io.writeclose.in.fnum = fnum; + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, 0, 13) != 13) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf+4, seed, 9); + CHECK_VALUE(IVAL(buf,0), 0); + + setup_buffer(buf, seed, maxsize); + + printf("Trying large write\n"); + io.writeclose.in.count = 4000; + io.writeclose.in.offset = 0; + io.writeclose.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeclose.out.nwritten, 4000); + + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + fnum = cli_open(cli, fname, O_RDWR, DENY_NONE); + io.writeclose.in.fnum = fnum; + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, 0, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed, 4000); + + printf("Trying bad fnum\n"); + io.writeclose.in.fnum = fnum+1; + io.writeclose.in.count = 4000; + io.writeclose.in.offset = 0; + io.writeclose.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE); + + printf("Setting file as sparse\n"); + status = torture_set_sparse(cli->tree, fnum); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("Trying 2^32 offset\n"); + setup_buffer(buf, seed, maxsize); + io.writeclose.in.fnum = fnum; + io.writeclose.in.count = 4000; + io.writeclose.in.offset = 0xFFFFFFFF - 2000; + io.writeclose.in.data = buf; + status = smb_raw_write(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.writeclose.out.nwritten, 4000); + CHECK_ALL_INFO(io.writeclose.in.count + (SMB_BIG_UINT)io.writeclose.in.offset, size); + + fnum = cli_open(cli, fname, O_RDWR, DENY_NONE); + io.writeclose.in.fnum = fnum; + + memset(buf, 0, maxsize); + if (cli_read(cli, fnum, buf, io.writeclose.in.offset, 4000) != 4000) { + printf("read failed at %d\n", __LINE__); + ret = False; + goto done; + } + CHECK_BUFFER(buf, seed, 4000); + +done: + smb_raw_exit(cli->session); + cli_deltree(cli, BASEDIR); + return ret; +} + + +/* + basic testing of write calls +*/ +BOOL torture_raw_write(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_write"); + + if (!test_write(cli, mem_ctx)) { + ret = False; + } + + if (!test_writeunlock(cli, mem_ctx)) { + ret = False; + } + + if (!test_writeclose(cli, mem_ctx)) { + ret = False; + } + + if (!test_writex(cli, mem_ctx)) { + ret = False; + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/rpctorture.c b/source4/torture/rpctorture.c new file mode 100644 index 0000000000..04656e71d1 --- /dev/null +++ b/source4/torture/rpctorture.c @@ -0,0 +1,526 @@ +/* + Unix SMB/CIFS implementation. + SMB client + Copyright (C) Andrew Tridgell 1994-1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#ifndef REGISTER +#define REGISTER 0 +#endif + +extern file_info def_finfo; + +#define CNV_LANG(s) dos2unix_format(s,False) +#define CNV_INPUT(s) unix2dos_format(s,True) + +static struct cli_state smbcli; +struct cli_state *smb_cli = &smbcli; + +FILE *out_hnd; + +static pstring password; /* local copy only, if one is entered */ + +/**************************************************************************** +initialise smb client structure +****************************************************************************/ +void rpcclient_init(void) +{ + memset((char *)smb_cli, '\0', sizeof(smb_cli)); + cli_initialise(smb_cli); + smb_cli->capabilities |= CAP_NT_SMBS; +} + +/**************************************************************************** +make smb client connection +****************************************************************************/ +static BOOL rpcclient_connect(struct client_info *info) +{ + struct nmb_name calling; + struct nmb_name called; + + make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type); + make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0); + + if (!cli_establish_connection(smb_cli, + info->dest_host, &info->dest_ip, + &calling, &called, + info->share, info->svc_type, + False, True)) + { + DEBUG(0,("rpcclient_connect: connection failed\n")); + cli_shutdown(smb_cli); + return False; + } + + return True; +} + +/**************************************************************************** +stop the smb connection(s?) +****************************************************************************/ +static void rpcclient_stop(void) +{ + cli_shutdown(smb_cli); +} + +/**************************************************************************** + log in as an nt user, log out again. +****************************************************************************/ +void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) +{ + pstring cmd; + int i; + + /* establish connections. nothing to stop these being re-established. */ + rpcclient_connect(cli_info); + + DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); + if (cli->fd <= 0) + { + fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", + cli_info->dest_host, cli_info->name_type); + return; + } + + for (i = 0; i < num_ops; i++) + { + set_first_token(""); + cmd_srv_enum_sess(cli_info); + set_first_token(""); + cmd_srv_enum_shares(cli_info); + set_first_token(""); + cmd_srv_enum_files(cli_info); + + if (password[0] != 0) + { + slprintf(cmd, sizeof(cmd)-1, "1"); + set_first_token(cmd); + } + else + { + set_first_token(""); + } + cmd_srv_enum_conn(cli_info); + } + + rpcclient_stop(); + +} + +/**************************************************************************** + log in as an nt user, log out again. +****************************************************************************/ +void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) +{ + pstring cmd; + int i; + + /* establish connections. nothing to stop these being re-established. */ + rpcclient_connect(cli_info); + + DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); + if (cli->fd <= 0) + { + fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", + cli_info->dest_host, cli_info->name_type); + return; + } + + for (i = 0; i < num_ops; i++) + { + slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password); + set_first_token(cmd); + + cmd_netlogon_login_test(cli_info); + } + + rpcclient_stop(); + +} + +/**************************************************************************** + runs n simultaneous functions. +****************************************************************************/ +static void create_procs(int nprocs, int numops, + struct client_info *cli_info, struct cli_state *cli, + void (*fn)(int, struct client_info *, struct cli_state *)) +{ + int i, status; + + for (i=0;i<nprocs;i++) + { + if (fork() == 0) + { + pid_t mypid = getpid(); + sys_srandom(mypid ^ time(NULL)); + fn(numops, cli_info, cli); + fflush(out_hnd); + _exit(0); + } + } + + for (i=0;i<nprocs;i++) + { + waitpid(0, &status, 0); + } +} +/**************************************************************************** +usage on the program - OUT OF DATE! +****************************************************************************/ +static void usage(char *pname) +{ + fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ", + pname); + + fprintf(out_hnd, "\nVersion %s\n",VERSION); + fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n"); + fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n"); + fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n"); + fprintf(out_hnd, "\t-m max protocol set the max protocol level\n"); + fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n"); + fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n"); + fprintf(out_hnd, "\t-U username set the network username\n"); + fprintf(out_hnd, "\t-W workgroup set the workgroup name\n"); + fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"); + fprintf(out_hnd, "\n"); +} + +enum client_action +{ + CLIENT_NONE, + CLIENT_IPC, + CLIENT_SVC +}; + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + char *pname = argv[0]; + int opt; + extern char *optarg; + extern int optind; + pstring term_code; + BOOL got_pass = False; + char *cmd_str=""; + enum client_action cli_action = CLIENT_NONE; + int nprocs = 1; + int numops = 100; + pstring logfile; + + struct client_info cli_info; + + out_hnd = stdout; + + rpcclient_init(); + +#ifdef KANJI + pstrcpy(term_code, KANJI); +#else /* KANJI */ + *term_code = 0; +#endif /* KANJI */ + + if (!lp_load(dyn_CONFIGFILE,True, False, False)) + { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); + } + + DEBUGLEVEL = 0; + + cli_info.put_total_size = 0; + cli_info.put_total_time_ms = 0; + cli_info.get_total_size = 0; + cli_info.get_total_time_ms = 0; + + cli_info.dir_total = 0; + cli_info.newer_than = 0; + cli_info.archive_level = 0; + cli_info.print_mode = 1; + + cli_info.translation = False; + cli_info.recurse_dir = False; + cli_info.lowercase = False; + cli_info.prompt = True; + cli_info.abort_mget = True; + + cli_info.dest_ip.s_addr = 0; + cli_info.name_type = 0x20; + + pstrcpy(cli_info.cur_dir , "\\"); + pstrcpy(cli_info.file_sel, ""); + pstrcpy(cli_info.base_dir, ""); + pstrcpy(smb_cli->domain, ""); + pstrcpy(smb_cli->user_name, ""); + pstrcpy(cli_info.myhostname, ""); + pstrcpy(cli_info.dest_host, ""); + + pstrcpy(cli_info.svc_type, "A:"); + pstrcpy(cli_info.share, ""); + pstrcpy(cli_info.service, ""); + + ZERO_STRUCT(cli_info.dom.level3_sid); + pstrcpy(cli_info.dom.level3_dom, ""); + ZERO_STRUCT(cli_info.dom.level5_sid); + pstrcpy(cli_info.dom.level5_dom, ""); + + smb_cli->nt_pipe_fnum = 0xffff; + + setup_logging(pname, True); + + password[0] = 0; + + if (argc < 2) + { + usage(pname); + exit(1); + } + + if (*argv[1] != '-') + { + pstrcpy(cli_info.service, argv[1]); + /* Convert any '/' characters in the service name to '\' characters */ + string_replace( cli_info.service, '/','\\'); + argc--; + argv++; + + DEBUG(1,("service: %s\n", cli_info.service)); + + if (count_chars(cli_info.service,'\\') < 3) + { + usage(pname); + printf("\n%s: Not enough '\\' characters in service\n", cli_info.service); + exit(1); + } + + /* + if (count_chars(cli_info.service,'\\') > 3) + { + usage(pname); + printf("\n%s: Too many '\\' characters in service\n", cli_info.service); + exit(1); + } + */ + + if (argc > 1 && (*argv[1] != '-')) + { + got_pass = True; + pstrcpy(password,argv[1]); + memset(argv[1],'X',strlen(argv[1])); + argc--; + argv++; + } + + cli_action = CLIENT_SVC; + } + + while ((opt = getopt(argc, argv,"s:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) + { + switch (opt) + { + case 'm': + { + /* FIXME ... max_protocol seems to be funny here */ + + int max_protocol = 0; + max_protocol = interpret_protocol(optarg,max_protocol); + fprintf(stderr, "max protocol not currently supported\n"); + break; + } + + case 'O': + lp_set_cmdline("socket options", optarg); + break; + + case 'S': + { + pstrcpy(cli_info.dest_host,optarg); + strupper(cli_info.dest_host); + cli_action = CLIENT_IPC; + break; + } + + case 'i': + { + pstrcpy(scope, optarg); + break; + } + + case 'U': + { + char *lp; + pstrcpy(smb_cli->user_name,optarg); + if ((lp=strchr_m(smb_cli->user_name,'%'))) + { + *lp = 0; + pstrcpy(password,lp+1); + got_pass = True; + memset(strchr_m(optarg,'%')+1,'X',strlen(password)); + } + break; + } + + case 'W': + { + pstrcpy(smb_cli->domain,optarg); + break; + } + + case 'E': + { + dbf = x_stderr; + break; + } + + case 'I': + { + cli_info.dest_ip = *interpret_addr2(optarg); + if (is_zero_ip(cli_info.dest_ip)) + { + exit(1); + } + break; + } + + case 'N': + { + nprocs = atoi(optarg); + break; + } + + case 'o': + { + numops = atoi(optarg); + break; + } + + case 'n': + lp_set_cmdline("netbios name", optarg); + break; + + case 'd': + { + if (*optarg == 'A') + DEBUGLEVEL = 10000; + else + DEBUGLEVEL = atoi(optarg); + break; + } + + case 'l': + { + slprintf(logfile, sizeof(logfile)-1, + "%s.client",optarg); + lp_set_logfile(logfile); + break; + } + + case 'c': + { + cmd_str = optarg; + got_pass = True; + break; + } + + case 'h': + { + usage(pname); + exit(0); + break; + } + + case 's': + { + pstrcpy(dyn_CONFIGFILE, optarg); + break; + } + + case 't': + { + pstrcpy(term_code, optarg); + break; + } + + default: + { + usage(pname); + exit(1); + break; + } + } + } + + if (cli_action == CLIENT_NONE) + { + usage(pname); + exit(1); + } + + fstrcpy(cli_info.myhostname, lp_netbios_name()); + + DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION)); + + if (*smb_cli->domain == 0) + { + pstrcpy(smb_cli->domain,lp_workgroup()); + } + strupper(smb_cli->domain); + + load_interfaces(); + + if (cli_action == CLIENT_IPC) + { + pstrcpy(cli_info.share, "IPC$"); + pstrcpy(cli_info.svc_type, "IPC"); + } + + fstrcpy(cli_info.mach_acct, cli_info.myhostname); + strupper(cli_info.mach_acct); + fstrcat(cli_info.mach_acct, "$"); + + /* set the password cache info */ + if (got_pass) + { + if (password[0] == 0) + { + pwd_set_nullpwd(&(smb_cli->pwd)); + } + else + { + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + } + } + else + { + char *pwd = getpass("Enter Password:"); + safe_strcpy(password, pwd, sizeof(password)); + pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ + } + + create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test); + + if (password[0] != 0) + { + create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); + } + + fflush(out_hnd); + + return(0); +} diff --git a/source4/torture/samtest.c b/source4/torture/samtest.c new file mode 100644 index 0000000000..832f3ecea5 --- /dev/null +++ b/source4/torture/samtest.c @@ -0,0 +1,451 @@ +/* + Unix SMB/CIFS implementation. + SAM module tester + + Copyright (C) 2002 Jelmer Vernooij + + Parts of the code stolen from vfstest by Simo Sorce and Eric Lorimer + Parts of the code stolen from rpcclient by Tim Potter + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "samtest.h" + +struct func_entry { + char *name; + int (*fn)(struct tcon_context *conn, const char *path); +}; + +/* List to hold groups of commands */ +static struct cmd_list { + struct cmd_list *prev, *next; + struct cmd_set *cmd_set; +} *cmd_list; + +static char* next_command (char** cmdstr) +{ + static pstring command; + char *p; + + if (!cmdstr || !(*cmdstr)) + return NULL; + + p = strchr_m(*cmdstr, ';'); + if (p) + *p = '\0'; + pstrcpy(command, *cmdstr); + *cmdstr = p; + + return command; +} + +/* Load specified configuration file */ +static NTSTATUS cmd_conf(struct samtest_state *sam, TALLOC_CTX *mem_ctx, + int argc, char **argv) +{ + if (argc != 2) { + printf("Usage: %s <smb.conf>\n", argv[0]); + return NT_STATUS_OK; + } + + if (!lp_load(argv[1], False, True, False)) { + printf("Error loading \"%s\"\n", argv[1]); + return NT_STATUS_OK; + } + + printf("\"%s\" successfully loaded\n", argv[1]); + return NT_STATUS_OK; +} + +/* Display help on commands */ +static NTSTATUS cmd_help(struct samtest_state *st, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + struct cmd_list *tmp; + struct cmd_set *tmp_set; + + /* Usage */ + if (argc > 2) { + printf("Usage: %s [command]\n", argv[0]); + return NT_STATUS_OK; + } + + /* Help on one command */ + + if (argc == 2) { + for (tmp = cmd_list; tmp; tmp = tmp->next) { + + tmp_set = tmp->cmd_set; + + while(tmp_set->name) { + if (strequal(argv[1], tmp_set->name)) { + if (tmp_set->usage && + tmp_set->usage[0]) + printf("%s\n", tmp_set->usage); + else + printf("No help for %s\n", tmp_set->name); + + return NT_STATUS_OK; + } + + tmp_set++; + } + } + + printf("No such command: %s\n", argv[1]); + return NT_STATUS_OK; + } + + /* List all commands */ + + for (tmp = cmd_list; tmp; tmp = tmp->next) { + + tmp_set = tmp->cmd_set; + + while(tmp_set->name) { + + printf("%20s\t%s\n", tmp_set->name, + tmp_set->description ? tmp_set->description: + ""); + + tmp_set++; + } + } + + return NT_STATUS_OK; +} + +/* Change the debug level */ +static NTSTATUS cmd_debuglevel(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + if (argc > 2) { + printf("Usage: %s [debuglevel]\n", argv[0]); + return NT_STATUS_OK; + } + + if (argc == 2) { + DEBUGLEVEL = atoi(argv[1]); + } + + printf("debuglevel is %d\n", DEBUGLEVEL); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_quit(struct samtest_state *st, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + /* Cleanup */ + talloc_destroy(mem_ctx); + + exit(0); + return NT_STATUS_OK; /* NOTREACHED */ +} + +static struct cmd_set samtest_commands[] = { + + { "GENERAL OPTIONS" }, + + { "help", cmd_help, "Get help on commands", "" }, + { "?", cmd_help, "Get help on commands", "" }, + { "conf", cmd_conf, "Load smb configuration file", "conf <smb.conf>" }, + { "debuglevel", cmd_debuglevel, "Set debug level", "" }, + { "exit", cmd_quit, "Exit program", "" }, + { "quit", cmd_quit, "Exit program", "" }, + + { NULL } +}; + +static struct cmd_set separator_command[] = { + { "---------------", NULL, "----------------------" }, + { NULL } +}; + + +/*extern struct cmd_set sam_commands[];*/ +extern struct cmd_set sam_general_commands[]; +extern struct cmd_set sam_domain_commands[]; +extern struct cmd_set sam_account_commands[]; +extern struct cmd_set sam_group_commands[]; +static struct cmd_set *samtest_command_list[] = { + samtest_commands, + sam_general_commands, + sam_domain_commands, + sam_account_commands, + sam_group_commands, + NULL +}; + +static void add_command_set(struct cmd_set *cmd_set) +{ + struct cmd_list *entry; + + if (!(entry = (struct cmd_list *)malloc(sizeof(struct cmd_list)))) { + DEBUG(0, ("out of memory\n")); + return; + } + + ZERO_STRUCTP(entry); + + entry->cmd_set = cmd_set; + DLIST_ADD(cmd_list, entry); +} + +static NTSTATUS do_cmd(struct samtest_state *st, struct cmd_set *cmd_entry, char *cmd) +{ + char *p = cmd, **argv = NULL; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + TALLOC_CTX *mem_ctx = NULL; + pstring buf; + int argc = 0, i; + + /* Count number of arguments first time through the loop then + allocate memory and strdup them. */ + + again: + while(next_token(&p, buf, " ", sizeof(buf))) { + if (argv) { + argv[argc] = strdup(buf); + } + + argc++; + } + + if (!argv) { + + /* Create argument list */ + + argv = (char **)malloc(sizeof(char *) * argc); + memset(argv, 0, sizeof(char *) * argc); + + if (!argv) { + fprintf(stderr, "out of memory\n"); + result = NT_STATUS_NO_MEMORY; + goto done; + } + + p = cmd; + argc = 0; + + goto again; + } + + /* Call the function */ + + if (cmd_entry->fn) { + + if (mem_ctx == NULL) { + /* Create mem_ctx */ + if (!(mem_ctx = talloc_init("do_cmd"))) { + DEBUG(0, ("talloc_init() failed\n")); + goto done; + } + } + + /* Run command */ + result = cmd_entry->fn(st, mem_ctx, argc, argv); + + } else { + fprintf (stderr, "Invalid command\n"); + goto done; + } + + done: + + /* Cleanup */ + + if (argv) { + for (i = 0; i < argc; i++) + SAFE_FREE(argv[i]); + + SAFE_FREE(argv); + } + + return result; +} + +/* Process a command entered at the prompt or as part of -c */ +static NTSTATUS process_cmd(struct samtest_state *st, char *cmd) +{ + struct cmd_list *temp_list; + BOOL found = False; + pstring buf; + char *p = cmd; + NTSTATUS result = NT_STATUS_OK; + int len = 0; + + if (cmd[strlen(cmd) - 1] == '\n') + cmd[strlen(cmd) - 1] = '\0'; + + if (!next_token(&p, buf, " ", sizeof(buf))) { + return NT_STATUS_OK; + } + + /* strip the trainly \n if it exsists */ + len = strlen(buf); + if (buf[len-1] == '\n') + buf[len-1] = '\0'; + + /* Search for matching commands */ + + for (temp_list = cmd_list; temp_list; temp_list = temp_list->next) { + struct cmd_set *temp_set = temp_list->cmd_set; + + while(temp_set->name) { + if (strequal(buf, temp_set->name)) { + found = True; + result = do_cmd(st, temp_set, cmd); + + goto done; + } + temp_set++; + } + } + + done: + if (!found && buf[0]) { + printf("command not found: %s\n", buf); + return NT_STATUS_OK; + } + + if (!NT_STATUS_IS_OK(result)) { + printf("result was %s\n", nt_errstr(result)); + } + + return result; +} + +void exit_server(char *reason) +{ + DEBUG(3,("Server exit (%s)\n", (reason ? reason : ""))); + exit(0); +} + +static int server_fd = -1; +int last_message = -1; + +int smbd_server_fd(void) +{ + return server_fd; +} + +BOOL reload_services(BOOL test) +{ + return True; +} + +/* Main function */ + +int main(int argc, char *argv[]) +{ + BOOL interactive = True; + int opt; + static char *cmdstr = ""; + static char *opt_logfile=NULL; + static char *config_file = dyn_CONFIGFILE; + pstring logfile; + struct cmd_set **cmd_set; + struct samtest_state st; + + /* make sure the vars that get altered (4th field) are in + a fixed location or certain compilers complain */ + poptContext pc; + struct poptOption long_options[] = { + POPT_AUTOHELP + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, + {"command", 'e', POPT_ARG_STRING, &cmdstr, 'e', "Execute semicolon seperated cmds"}, + {"logfile", 'l', POPT_ARG_STRING, &opt_logfile, 'l', "Logfile to use instead of stdout"}, + {"configfile", 'c', POPT_ARG_STRING, &config_file, 0,"use different configuration file",NULL}, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, + { 0, 0, 0, 0} + }; + + ZERO_STRUCT(st); + + st.token = get_system_token(); + + setlinebuf(stdout); + + DEBUGLEVEL = 1; + + pc = poptGetContext("samtest", argc, (const char **) argv, + long_options, 0); + + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'l': + slprintf(logfile, sizeof(logfile) - 1, "%s.client", + opt_logfile); + lp_set_logfile(logfile); + interactive = False; + break; + } + } + + if (!lp_load(config_file,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", config_file); + exit(1); + } + + poptFreeContext(pc); + + /* the following functions are part of the Samba debugging + facilities. See lib/debug.c */ + setup_logging("samtest", interactive); + if (!interactive) + reopen_logs(); + + /* Load command lists */ + + cmd_set = samtest_command_list; + + while(*cmd_set) { + add_command_set(*cmd_set); + add_command_set(separator_command); + cmd_set++; + } + + /* Do anything specified with -c */ + if (cmdstr[0]) { + char *cmd; + char *p = cmdstr; + + while((cmd=next_command(&p)) != NULL) { + process_cmd(&st, cmd); + } + + return 0; + } + + /* Loop around accepting commands */ + + while(1) { + pstring prompt; + char *line; + + slprintf(prompt, sizeof(prompt) - 1, "samtest $> "); + + line = smb_readline(prompt, NULL, NULL); + + if (line == NULL) + break; + + if (line[0] != '\n') + process_cmd(&st, line); + } + + return 0; +} diff --git a/source4/torture/samtest.h b/source4/torture/samtest.h new file mode 100644 index 0000000000..a136ab191e --- /dev/null +++ b/source4/torture/samtest.h @@ -0,0 +1,38 @@ +/* + Unix SMB/CIFS implementation. + SAM module tester + + Copyright (C) Jelmer Vernooij 2002 + + Most of this code was ripped off of rpcclient. + Copyright (C) Tim Potter 2000-2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +struct samtest_state { + SAM_CONTEXT *context; + NT_USER_TOKEN *token; +}; + +struct cmd_set { + char *name; + NTSTATUS (*fn)(struct samtest_state *sam, TALLOC_CTX *mem_ctx, int argc, + char **argv); + char *description; + char *usage; +}; + + diff --git a/source4/torture/scanner.c b/source4/torture/scanner.c new file mode 100644 index 0000000000..0a92db9a4b --- /dev/null +++ b/source4/torture/scanner.c @@ -0,0 +1,514 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester - scanning functions + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#define VERBOSE 0 +#define OP_MIN 0 +#define OP_MAX 100 + +/**************************************************************************** +look for a partial hit +****************************************************************************/ +static void trans2_check_hit(const char *format, int op, int level, NTSTATUS status) +{ + if (NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_INVALID_LEVEL) || + NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_NOT_IMPLEMENTED) || + NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_NOT_SUPPORTED) || + NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_UNSUCCESSFUL) || + NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_INVALID_INFO_CLASS)) { + return; + } +#if VERBOSE + printf("possible %s hit op=%3d level=%5d status=%s\n", + format, op, level, nt_errstr(status)); +#endif +} + +/**************************************************************************** +check for existance of a trans2 call +****************************************************************************/ +static NTSTATUS try_trans2(struct cli_state *cli, + int op, + char *param, char *data, + int param_len, int data_len, + int *rparam_len, int *rdata_len) +{ + NTSTATUS status; + struct smb_trans2 t2; + uint16 setup = op; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("try_trans2"); + + t2.in.max_param = 1024; + t2.in.max_data = 0x8000; + t2.in.max_setup = 10; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params.data = param; + t2.in.params.length = param_len; + t2.in.data.data = data; + t2.in.data.length = data_len; + + status = smb_raw_trans2(cli->tree, mem_ctx, &t2); + + *rparam_len = t2.out.params.length; + *rdata_len = t2.out.data.length; + + talloc_destroy(mem_ctx); + + return status; +} + + +static NTSTATUS try_trans2_len(struct cli_state *cli, + const char *format, + int op, int level, + char *param, char *data, + int param_len, int *data_len, + int *rparam_len, int *rdata_len) +{ + NTSTATUS ret=NT_STATUS_OK; + + ret = try_trans2(cli, op, param, data, param_len, + sizeof(pstring), rparam_len, rdata_len); +#if VERBOSE + printf("op=%d level=%d ret=%s\n", op, level, nt_errstr(ret)); +#endif + if (!NT_STATUS_IS_OK(ret)) return ret; + + *data_len = 0; + while (*data_len < sizeof(pstring)) { + ret = try_trans2(cli, op, param, data, param_len, + *data_len, rparam_len, rdata_len); + if (NT_STATUS_IS_OK(ret)) break; + *data_len += 2; + } + if (NT_STATUS_IS_OK(ret)) { + printf("found %s level=%d data_len=%d rparam_len=%d rdata_len=%d\n", + format, level, *data_len, *rparam_len, *rdata_len); + } else { + trans2_check_hit(format, op, level, ret); + } + return ret; +} + + +/**************************************************************************** +check whether a trans2 opnum exists at all +****************************************************************************/ +static BOOL trans2_op_exists(struct cli_state *cli, int op) +{ + int data_len = 0; + int param_len = 0; + int rparam_len, rdata_len; + pstring param, data; + NTSTATUS status1, status2; + + memset(data, 0, sizeof(data)); + data_len = 4; + + /* try with a info level only */ + param_len = sizeof(param); + data_len = sizeof(data); + + memset(param, 0xFF, sizeof(param)); + memset(data, 0xFF, sizeof(data)); + + status1 = try_trans2(cli, 0xFFFF, param, data, param_len, data_len, + &rparam_len, &rdata_len); + + status2 = try_trans2(cli, op, param, data, param_len, data_len, + &rparam_len, &rdata_len); + + if (NT_STATUS_EQUAL(status1, status2)) return False; + + printf("Found op %d (status=%s)\n", op, nt_errstr(status2)); + + return True; +} + +/**************************************************************************** +check for existance of a trans2 call +****************************************************************************/ +static BOOL scan_trans2(struct cli_state *cli, int op, int level, + int fnum, int dnum, int qfnum, const char *fname) +{ + int data_len = 0; + int param_len = 0; + int rparam_len, rdata_len; + pstring param, data; + NTSTATUS status; + + memset(data, 0, sizeof(data)); + data_len = 4; + + /* try with a info level only */ + param_len = 2; + SSVAL(param, 0, level); + status = try_trans2_len(cli, "void", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + /* try with a file descriptor */ + param_len = 6; + SSVAL(param, 0, fnum); + SSVAL(param, 2, level); + SSVAL(param, 4, 0); + status = try_trans2_len(cli, "fnum", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + /* try with a quota file descriptor */ + param_len = 6; + SSVAL(param, 0, qfnum); + SSVAL(param, 2, level); + SSVAL(param, 4, 0); + status = try_trans2_len(cli, "qfnum", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + /* try with a notify style */ + param_len = 6; + SSVAL(param, 0, dnum); + SSVAL(param, 2, dnum); + SSVAL(param, 4, level); + status = try_trans2_len(cli, "notify", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + /* try with a file name */ + param_len = 6; + SSVAL(param, 0, level); + SSVAL(param, 2, 0); + SSVAL(param, 4, 0); + param_len += push_string(NULL, ¶m[6], fname, sizeof(pstring)-7, STR_TERMINATE|STR_UNICODE); + + status = try_trans2_len(cli, "fname", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + /* try with a new file name */ + param_len = 6; + SSVAL(param, 0, level); + SSVAL(param, 2, 0); + SSVAL(param, 4, 0); + param_len += push_string(NULL, ¶m[6], "\\newfile.dat", sizeof(pstring)-7, STR_TERMINATE|STR_UNICODE); + + status = try_trans2_len(cli, "newfile", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + cli_unlink(cli, "\\newfile.dat"); + cli_rmdir(cli, "\\newfile.dat"); + if (NT_STATUS_IS_OK(status)) return True; + + /* try dfs style */ + cli_mkdir(cli, "\\testdir"); + param_len = 2; + SSVAL(param, 0, level); + param_len += push_string(NULL, ¶m[2], "\\testdir", sizeof(pstring)-3, STR_TERMINATE|STR_UNICODE); + + status = try_trans2_len(cli, "dfs", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + cli_rmdir(cli, "\\testdir"); + if (NT_STATUS_IS_OK(status)) return True; + + return False; +} + + +BOOL torture_trans2_scan(int dummy) +{ + static struct cli_state *cli; + int op, level; + const char *fname = "\\scanner.dat"; + int fnum, dnum, qfnum; + + printf("starting trans2 scan test\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + if (fnum == -1) { + printf("file open failed - %s\n", cli_errstr(cli)); + } + dnum = cli_nt_create_full(cli, "\\", + 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE, + NTCREATEX_DISP_OPEN, + NTCREATEX_OPTIONS_DIRECTORY, 0); + if (dnum == -1) { + printf("directory open failed - %s\n", cli_errstr(cli)); + } + qfnum = cli_nt_create_full(cli, "\\$Extend\\$Quota:$Q:$INDEX_ALLOCATION", + NTCREATEX_FLAGS_EXTENDED, + SEC_RIGHTS_MAXIMUM_ALLOWED, + 0, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, + NTCREATEX_DISP_OPEN, + 0, 0); + if (qfnum == -1) { + printf("quota open failed - %s\n", cli_errstr(cli)); + } + + for (op=OP_MIN; op<=OP_MAX; op++) { + + if (!trans2_op_exists(cli, op)) { + continue; + } + + for (level = 0; level <= 50; level++) { + scan_trans2(cli, op, level, fnum, dnum, qfnum, fname); + } + + for (level = 0x100; level <= 0x130; level++) { + scan_trans2(cli, op, level, fnum, dnum, qfnum, fname); + } + + for (level = 1000; level < 1050; level++) { + scan_trans2(cli, op, level, fnum, dnum, qfnum, fname); + } + } + + torture_close_connection(cli); + + printf("trans2 scan finished\n"); + return True; +} + + + + +/**************************************************************************** +look for a partial hit +****************************************************************************/ +static void nttrans_check_hit(const char *format, int op, int level, NTSTATUS status) +{ + if (NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_INVALID_LEVEL) || + NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_NOT_IMPLEMENTED) || + NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_NOT_SUPPORTED) || + NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_UNSUCCESSFUL) || + NT_STATUS_V(status) == NT_STATUS_V(NT_STATUS_INVALID_INFO_CLASS)) { + return; + } +#if VERBOSE + printf("possible %s hit op=%3d level=%5d status=%s\n", + format, op, level, nt_errstr(status)); +#endif +} + +/**************************************************************************** +check for existence of a nttrans call +****************************************************************************/ +static NTSTATUS try_nttrans(struct cli_state *cli, + int op, + char *param, char *data, + int param_len, int data_len, + int *rparam_len, int *rdata_len) +{ + struct smb_nttrans parms; + DATA_BLOB ntparam_blob, ntdata_blob; + TALLOC_CTX *mem_ctx; + NTSTATUS status; + + mem_ctx = talloc_init("try_nttrans"); + + ntparam_blob.length = param_len; + ntparam_blob.data = param; + ntdata_blob.length = data_len; + ntdata_blob.data = data; + + parms.in.max_param = 1024; + parms.in.max_data = 1024; + parms.in.max_setup = 0; + parms.in.setup_count = 0; + parms.in.function = op; + parms.in.params = ntparam_blob; + parms.in.data = ntdata_blob; + + status = smb_raw_nttrans(cli->tree, mem_ctx, &parms); + + if (NT_STATUS_IS_ERR(status)) { + DEBUG(1,("Failed to send NT_TRANS\n")); + talloc_destroy(mem_ctx); + return status; + } + *rparam_len = parms.out.params.length; + *rdata_len = parms.out.data.length; + + talloc_destroy(mem_ctx); + + return status; +} + + +static NTSTATUS try_nttrans_len(struct cli_state *cli, + const char *format, + int op, int level, + char *param, char *data, + int param_len, int *data_len, + int *rparam_len, int *rdata_len) +{ + NTSTATUS ret=NT_STATUS_OK; + + ret = try_nttrans(cli, op, param, data, param_len, + sizeof(pstring), rparam_len, rdata_len); +#if VERBOSE + printf("op=%d level=%d ret=%s\n", op, level, nt_errstr(ret)); +#endif + if (!NT_STATUS_IS_OK(ret)) return ret; + + *data_len = 0; + while (*data_len < sizeof(pstring)) { + ret = try_nttrans(cli, op, param, data, param_len, + *data_len, rparam_len, rdata_len); + if (NT_STATUS_IS_OK(ret)) break; + *data_len += 2; + } + if (NT_STATUS_IS_OK(ret)) { + printf("found %s level=%d data_len=%d rparam_len=%d rdata_len=%d\n", + format, level, *data_len, *rparam_len, *rdata_len); + } else { + nttrans_check_hit(format, op, level, ret); + } + return ret; +} + +/**************************************************************************** +check for existance of a nttrans call +****************************************************************************/ +static BOOL scan_nttrans(struct cli_state *cli, int op, int level, + int fnum, int dnum, const char *fname) +{ + int data_len = 0; + int param_len = 0; + int rparam_len, rdata_len; + pstring param, data; + NTSTATUS status; + + memset(data, 0, sizeof(data)); + data_len = 4; + + /* try with a info level only */ + param_len = 2; + SSVAL(param, 0, level); + status = try_nttrans_len(cli, "void", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + /* try with a file descriptor */ + param_len = 6; + SSVAL(param, 0, fnum); + SSVAL(param, 2, level); + SSVAL(param, 4, 0); + status = try_nttrans_len(cli, "fnum", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + + /* try with a notify style */ + param_len = 6; + SSVAL(param, 0, dnum); + SSVAL(param, 2, dnum); + SSVAL(param, 4, level); + status = try_nttrans_len(cli, "notify", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + /* try with a file name */ + param_len = 6; + SSVAL(param, 0, level); + SSVAL(param, 2, 0); + SSVAL(param, 4, 0); + param_len += push_string(NULL, ¶m[6], fname, -1, STR_TERMINATE | STR_UNICODE); + + status = try_nttrans_len(cli, "fname", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + if (NT_STATUS_IS_OK(status)) return True; + + /* try with a new file name */ + param_len = 6; + SSVAL(param, 0, level); + SSVAL(param, 2, 0); + SSVAL(param, 4, 0); + param_len += push_string(NULL, ¶m[6], "\\newfile.dat", -1, STR_TERMINATE | STR_UNICODE); + + status = try_nttrans_len(cli, "newfile", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + cli_unlink(cli, "\\newfile.dat"); + cli_rmdir(cli, "\\newfile.dat"); + if (NT_STATUS_IS_OK(status)) return True; + + /* try dfs style */ + cli_mkdir(cli, "\\testdir"); + param_len = 2; + SSVAL(param, 0, level); + param_len += push_string(NULL, ¶m[2], "\\testdir", -1, STR_TERMINATE | STR_UNICODE); + + status = try_nttrans_len(cli, "dfs", op, level, param, data, param_len, &data_len, + &rparam_len, &rdata_len); + cli_rmdir(cli, "\\testdir"); + if (NT_STATUS_IS_OK(status)) return True; + + return False; +} + + +BOOL torture_nttrans_scan(int dummy) +{ + static struct cli_state *cli; + int op, level; + const char *fname = "\\scanner.dat"; + int fnum, dnum; + + printf("starting nttrans scan test\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, + DENY_NONE); + dnum = cli_open(cli, "\\", O_RDONLY, DENY_NONE); + + for (op=OP_MIN; op<=OP_MAX; op++) { + printf("Scanning op=%d\n", op); + for (level = 0; level <= 50; level++) { + scan_nttrans(cli, op, level, fnum, dnum, fname); + } + + for (level = 0x100; level <= 0x130; level++) { + scan_nttrans(cli, op, level, fnum, dnum, fname); + } + + for (level = 1000; level < 1050; level++) { + scan_nttrans(cli, op, level, fnum, dnum, fname); + } + } + + torture_close_connection(cli); + + printf("nttrans scan finished\n"); + return True; +} diff --git a/source4/torture/search.c b/source4/torture/search.c new file mode 100644 index 0000000000..cf9e28b0fd --- /dev/null +++ b/source4/torture/search.c @@ -0,0 +1,325 @@ +/* + Unix SMB/CIFS implementation. + RAW_SEARCH_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +/* + callback function for single_search +*/ +static BOOL single_search_callback(void *private, union smb_search_data *file) +{ + union smb_search_data *data = private; + + *data = *file; + + return True; +} + +/* + do a single file (non-wildcard) search +*/ +static NTSTATUS single_search(struct cli_state *cli, + TALLOC_CTX *mem_ctx, + const char *pattern, + enum search_level level, + union smb_search_data *data) +{ + union smb_search_first io; + NTSTATUS status; + + io.generic.level = level; + if (level == RAW_SEARCH_SEARCH) { + io.search_first.in.max_count = 1; + io.search_first.in.search_attrib = 0; + io.search_first.in.pattern = pattern; + } else { + io.t2ffirst.in.search_attrib = 0; + io.t2ffirst.in.max_count = 1; + io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE; + io.t2ffirst.in.storage_type = 0; + io.t2ffirst.in.pattern = pattern; + } + + status = smb_raw_search_first(cli->tree, mem_ctx, + &io, (void *)data, single_search_callback); + + return status; +} + + +static struct { + const char *name; + enum search_level level; + NTSTATUS status; + union smb_search_data data; +} levels[] = { + {"SEARCH", RAW_SEARCH_SEARCH, }, + {"STANDARD", RAW_SEARCH_STANDARD, }, + {"EA_SIZE", RAW_SEARCH_EA_SIZE, }, + {"DIRECTORY_INFO", RAW_SEARCH_DIRECTORY_INFO, }, + {"FULL_DIRECTORY_INFO", RAW_SEARCH_FULL_DIRECTORY_INFO, }, + {"NAME_INFO", RAW_SEARCH_NAME_INFO, }, + {"BOTH_DIRECTORY_INFO", RAW_SEARCH_BOTH_DIRECTORY_INFO, }, + {"LEVEL_261", RAW_SEARCH_261, }, + {"LEVEL_262", RAW_SEARCH_262, } +}; + +/* find a level in the table by name */ +static union smb_search_data *find(const char *name) +{ + int i; + for (i=0;levels[i].name;i++) { + if (NT_STATUS_IS_OK(levels[i].status) && + strcmp(levels[i].name, name) == 0) { + return &levels[i].data; + } + } + return NULL; +} + +/* + basic testing of all RAW_SEARCH_* calls +*/ +BOOL torture_search(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + int fnum; + const char *fname = "\\torture_search.txt"; + NTSTATUS status; + int i; + union smb_fileinfo all_info, alt_info, name_info; + union smb_search_data *s; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_search"); + + fnum = create_complex_file(cli, mem_ctx, fname); + if (fnum == -1) { + printf("ERROR: open of %s failed (%s)\n", fname, cli_errstr(cli)); + ret = False; + goto done; + } + + /* call all the levels */ + for (i=0;levels[i].name;i++) { + levels[i].status = single_search(cli, mem_ctx, fname, + levels[i].level, &levels[i].data); + if (!NT_STATUS_IS_OK(levels[i].status)) { + printf("search level %s(%d) failed - %s\n", + levels[i].name, (int)levels[i].level, + nt_errstr(levels[i].status)); + ret = False; + } + } + + /* get the all_info file into to check against */ + all_info.generic.level = RAW_FILEINFO_ALL_INFO; + all_info.generic.in.fname = fname; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &all_info); + if (!NT_STATUS_IS_OK(status)) { + printf("RAW_FILEINFO_ALL_INFO failed - %s\n", nt_errstr(status)); + ret = False; + goto done; + } + + alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO; + alt_info.generic.in.fname = fname; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &alt_info); + if (!NT_STATUS_IS_OK(status)) { + printf("RAW_FILEINFO_ALT_NAME_INFO failed - %s\n", nt_errstr(status)); + ret = False; + goto done; + } + + name_info.generic.level = RAW_FILEINFO_NAME_INFO; + name_info.generic.in.fname = fname; + status = smb_raw_pathinfo(cli->tree, mem_ctx, &name_info); + if (!NT_STATUS_IS_OK(status)) { + printf("RAW_FILEINFO_NAME_INFO failed - %s\n", nt_errstr(status)); + ret = False; + goto done; + } + +#define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \ + s = find(name); \ + if (s) { \ + if (s->sname1.field1 != v.sname2.out.field2) { \ + printf("(%d) %s/%s [%d] != %s/%s [%d]\n", \ + __LINE__, \ + #sname1, #field1, (int)s->sname1.field1, \ + #sname2, #field2, (int)v.sname2.out.field2); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_TIME(name, sname1, field1, v, sname2, field2) do { \ + s = find(name); \ + if (s) { \ + if (s->sname1.field1 != (~1 & nt_time_to_unix(&v.sname2.out.field2))) { \ + printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ + __LINE__, \ + #sname1, #field1, time_string(mem_ctx, s->sname1.field1), \ + #sname2, #field2, nt_time_string(mem_ctx, &v.sname2.out.field2)); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_NTTIME(name, sname1, field1, v, sname2, field2) do { \ + s = find(name); \ + if (s) { \ + if (memcmp(&s->sname1.field1, &v.sname2.out.field2, sizeof(NTTIME))) { \ + printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ + __LINE__, \ + #sname1, #field1, nt_time_string(mem_ctx, &s->sname1.field1), \ + #sname2, #field2, nt_time_string(mem_ctx, &v.sname2.out.field2)); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_STR(name, sname1, field1, v, sname2, field2) do { \ + s = find(name); \ + if (s) { \ + if (!s->sname1.field1 || strcmp(s->sname1.field1, v.sname2.out.field2.s)) { \ + printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ + __LINE__, \ + #sname1, #field1, s->sname1.field1, \ + #sname2, #field2, v.sname2.out.field2.s); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_WSTR(name, sname1, field1, v, sname2, field2, flags) do { \ + s = find(name); \ + if (s) { \ + if (!s->sname1.field1.s || \ + strcmp(s->sname1.field1.s, v.sname2.out.field2.s) || \ + wire_bad_flags(&s->sname1.field1, flags)) { \ + printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ + __LINE__, \ + #sname1, #field1, s->sname1.field1.s, \ + #sname2, #field2, v.sname2.out.field2.s); \ + ret = False; \ + } \ + }} while (0) + +#define CHECK_NAME(name, sname1, field1, fname, flags) do { \ + s = find(name); \ + if (s) { \ + if (!s->sname1.field1.s || \ + strcmp(s->sname1.field1.s, fname) || \ + wire_bad_flags(&s->sname1.field1, flags)) { \ + printf("(%d) %s/%s [%s] != %s\n", \ + __LINE__, \ + #sname1, #field1, s->sname1.field1.s, \ + fname); \ + ret = False; \ + } \ + }} while (0) + + /* check that all the results are as expected */ + CHECK_VAL("SEARCH", search, attrib, all_info, all_info, attrib); + CHECK_VAL("STANDARD", standard, attrib, all_info, all_info, attrib); + CHECK_VAL("EA_SIZE", ea_size, attrib, all_info, all_info, attrib); + CHECK_VAL("DIRECTORY_INFO", directory_info, attrib, all_info, all_info, attrib); + CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, attrib, all_info, all_info, attrib); + CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, attrib, all_info, all_info, attrib); + CHECK_VAL("LEVEL_261", level_261, attrib, all_info, all_info, attrib); + CHECK_VAL("LEVEL_262", level_262, attrib, all_info, all_info, attrib); + + CHECK_TIME("SEARCH", search, write_time, all_info, all_info, write_time); + CHECK_TIME("STANDARD", standard, write_time, all_info, all_info, write_time); + CHECK_TIME("EA_SIZE", ea_size, write_time, all_info, all_info, write_time); + CHECK_TIME("STANDARD", standard, create_time, all_info, all_info, create_time); + CHECK_TIME("EA_SIZE", ea_size, create_time, all_info, all_info, create_time); + CHECK_TIME("STANDARD", standard, access_time, all_info, all_info, access_time); + CHECK_TIME("EA_SIZE", ea_size, access_time, all_info, all_info, access_time); + + CHECK_NTTIME("DIRECTORY_INFO", directory_info, write_time, all_info, all_info, write_time); + CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, write_time, all_info, all_info, write_time); + CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, write_time, all_info, all_info, write_time); + CHECK_NTTIME("LEVEL_261", level_261, write_time, all_info, all_info, write_time); + CHECK_NTTIME("LEVEL_262", level_262, write_time, all_info, all_info, write_time); + + CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("LEVEL_261", level_261, create_time, all_info, all_info, create_time); + CHECK_NTTIME("LEVEL_262", level_262, create_time, all_info, all_info, create_time); + + CHECK_NTTIME("DIRECTORY_INFO", directory_info, access_time, all_info, all_info, access_time); + CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, access_time, all_info, all_info, access_time); + CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, access_time, all_info, all_info, access_time); + CHECK_NTTIME("LEVEL_261", level_261, access_time, all_info, all_info, access_time); + CHECK_NTTIME("LEVEL_262", level_262, access_time, all_info, all_info, access_time); + + CHECK_NTTIME("DIRECTORY_INFO", directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("FULL_DIRECTORY_INFO", full_directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("BOTH_DIRECTORY_INFO", both_directory_info, create_time, all_info, all_info, create_time); + CHECK_NTTIME("LEVEL_261", level_261, create_time, all_info, all_info, create_time); + CHECK_NTTIME("LEVEL_262", level_262, create_time, all_info, all_info, create_time); + + CHECK_VAL("SEARCH", search, size, all_info, all_info, size); + CHECK_VAL("STANDARD", standard, size, all_info, all_info, size); + CHECK_VAL("EA_SIZE", ea_size, size, all_info, all_info, size); + CHECK_VAL("DIRECTORY_INFO", directory_info, size, all_info, all_info, size); + CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, size, all_info, all_info, size); + CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, size, all_info, all_info, size); + CHECK_VAL("LEVEL_261", level_261, size, all_info, all_info, size); + CHECK_VAL("LEVEL_262", level_262, size, all_info, all_info, size); + + CHECK_VAL("STANDARD", standard, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("EA_SIZE", ea_size, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("DIRECTORY_INFO", directory_info, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("BOTH_DIRECTORY_INFO", both_directory_info, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("LEVEL_261", level_261, alloc_size, all_info, all_info, alloc_size); + CHECK_VAL("LEVEL_262", level_262, alloc_size, all_info, all_info, alloc_size); + + CHECK_VAL("EA_SIZE", ea_size, ea_size, all_info, all_info, ea_size); + CHECK_VAL("FULL_DIRECTORY_INFO", full_directory_info, ea_size, all_info, all_info, ea_size); + CHECK_VAL("LEVEL_261", level_261, ea_size, all_info, all_info, ea_size); + CHECK_VAL("LEVEL_262", level_262, ea_size, all_info, all_info, ea_size); + + CHECK_STR("SEARCH", search, name, alt_info, alt_name_info, fname); + CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info, short_name, alt_info, alt_name_info, fname, STR_UNICODE); + + CHECK_NAME("STANDARD", standard, name, fname+1, 0); + CHECK_NAME("EA_SIZE", ea_size, name, fname+1, 0); + CHECK_NAME("DIRECTORY_INFO", directory_info, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("NAME_INFO", name_info, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("LEVEL_261", level_261, name, fname+1, STR_TERMINATE_ASCII); + CHECK_NAME("LEVEL_262", level_262, name, fname+1, STR_TERMINATE_ASCII); + +done: + cli_close(cli, fnum); + cli_unlink(cli, fname); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/setfileinfo.c b/source4/torture/setfileinfo.c new file mode 100644 index 0000000000..b49ac187ca --- /dev/null +++ b/source4/torture/setfileinfo.c @@ -0,0 +1,471 @@ +/* + Unix SMB/CIFS implementation. + RAW_SFILEINFO_* individual test suite + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* basic testing of all RAW_SFILEINFO_* calls + for each call we test that it succeeds, and where possible test + for consistency between the calls. +*/ +BOOL torture_sfileinfo(int dummy) +{ + struct cli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + int fnum = -1; + const char *fnum_fname = "\\torture_sfileinfo.txt"; + const char *fnum_fname_new = "\\torture_sfileinfo-new.txt"; + const char *path_fname = "\\torture_spathinfo13.txt"; + const char *path_fname_new = "\\torture_spathinfo-new.txt"; + union smb_fileinfo finfo1, finfo2; + union smb_setfileinfo sfinfo; + NTSTATUS status, status2; + const char *call_name; + time_t basetime = (time(NULL) - 86400) & ~1; + BOOL check_fnum; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_sfileinfo"); + +#define RECREATE_FILE(fname) do { \ + if (fnum != -1) cli_close(cli, fnum); \ + fnum = create_complex_file(cli, mem_ctx, fname); \ + if (fnum == -1) { \ + printf("(%d) ERROR: open of %s failed (%s)\n", \ + __LINE__, fname, cli_errstr(cli)); \ + ret = False; \ + goto done; \ + }} while (0) + +#define RECREATE_BOTH do { \ + RECREATE_FILE(path_fname); \ + cli_close(cli, fnum); \ + RECREATE_FILE(fnum_fname); \ + } while (0) + + RECREATE_BOTH; + +#define CHECK_CALL_FNUM(call, rightstatus) do { \ + check_fnum = True; \ + call_name = #call; \ + sfinfo.generic.level = RAW_SFILEINFO_ ## call; \ + sfinfo.generic.file.fnum = fnum; \ + status = smb_raw_setfileinfo(cli->tree, &sfinfo); \ + if (!NT_STATUS_EQUAL(status, rightstatus)) { \ + printf("(%d) %s - %s (should be %s)\n", __LINE__, #call, \ + nt_errstr(status), nt_errstr(rightstatus)); \ + ret = False; \ + } \ + finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \ + finfo1.generic.in.fnum = fnum; \ + status2 = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); \ + if (!NT_STATUS_IS_OK(status2)) { \ + printf("(%d) %s pathinfo - %s\n", __LINE__, #call, nt_errstr(status)); \ + ret = False; \ + }} while (0) + +#define CHECK_CALL_PATH(call, rightstatus) do { \ + check_fnum = False; \ + call_name = #call; \ + sfinfo.generic.level = RAW_SFILEINFO_ ## call; \ + sfinfo.generic.file.fname = path_fname; \ + status = smb_raw_setpathinfo(cli->tree, &sfinfo); \ + if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \ + sfinfo.generic.file.fname = path_fname_new; \ + status = smb_raw_setpathinfo(cli->tree, &sfinfo); \ + } \ + if (!NT_STATUS_EQUAL(status, rightstatus)) { \ + printf("(%d) %s - %s (should be %s)\n", __LINE__, #call, \ + nt_errstr(status), nt_errstr(rightstatus)); \ + ret = False; \ + } \ + finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \ + finfo1.generic.in.fname = path_fname; \ + status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo1); \ + if (NT_STATUS_EQUAL(status2, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \ + finfo1.generic.in.fname = path_fname_new; \ + status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo1); \ + } \ + if (!NT_STATUS_IS_OK(status2)) { \ + printf("(%d) %s pathinfo - %s\n", __LINE__, #call, nt_errstr(status2)); \ + ret = False; \ + }} while (0) + +#define CHECK1(call) \ + do { if (NT_STATUS_IS_OK(status)) { \ + finfo2.generic.level = RAW_FILEINFO_ ## call; \ + if (check_fnum) { \ + finfo2.generic.in.fnum = fnum; \ + status2 = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); \ + } else { \ + finfo2.generic.in.fname = path_fname; \ + status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); \ + if (NT_STATUS_EQUAL(status2, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \ + finfo2.generic.in.fname = path_fname_new; \ + status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); \ + } \ + } \ + if (!NT_STATUS_IS_OK(status2)) { \ + printf("%s - %s\n", #call, nt_errstr(status2)); \ + } \ + }} while (0) + +#define CHECK_VALUE(call, stype, field, value) do { \ + CHECK1(call); \ + if (NT_STATUS_IS_OK(status) && finfo2.stype.out.field != value) { \ + printf("(%d) %s - %s/%s should be 0x%x - 0x%x\n", __LINE__, \ + call_name, #stype, #field, \ + (uint_t)value, (uint_t)finfo2.stype.out.field); \ + dump_all_info(mem_ctx, &finfo1); \ + }} while (0) + +#define CHECK_TIME(call, stype, field, value) do { \ + CHECK1(call); \ + if (NT_STATUS_IS_OK(status) && nt_time_to_unix(&finfo2.stype.out.field) != value) { \ + printf("(%d) %s - %s/%s should be 0x%x - 0x%x\n", __LINE__, \ + call_name, #stype, #field, \ + (uint_t)value, \ + (uint_t)nt_time_to_unix(&finfo2.stype.out.field)); \ + printf("\t%s", http_timestring(value)); \ + printf("\t%s\n", nt_time_string(mem_ctx, &finfo2.stype.out.field)); \ + dump_all_info(mem_ctx, &finfo1); \ + }} while (0) + +#define CHECK_STR(call, stype, field, value) do { \ + CHECK1(call); \ + if (NT_STATUS_IS_OK(status) && strcmp(finfo2.stype.out.field, value) != 0) { \ + printf("(%d) %s - %s/%s should be '%s' - '%s'\n", __LINE__, \ + call_name, #stype, #field, \ + value, \ + finfo2.stype.out.field); \ + dump_all_info(mem_ctx, &finfo1); \ + }} while (0) + + /* test setattr */ + sfinfo.setattr.in.attrib = FILE_ATTRIBUTE_READONLY; + sfinfo.setattr.in.write_time = basetime; + CHECK_CALL_PATH(SETATTR, NT_STATUS_OK); + CHECK_VALUE (ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + CHECK_TIME (ALL_INFO, all_info, write_time, basetime); + + /* a zero write_time means don't change */ + sfinfo.setattr.in.attrib = 0; + sfinfo.setattr.in.write_time = 0; + CHECK_CALL_PATH(SETATTR, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL); + CHECK_TIME (ALL_INFO, all_info, write_time, basetime); + + /* test setattre */ + sfinfo.setattre.in.create_time = basetime + 20; + sfinfo.setattre.in.access_time = basetime + 30; + sfinfo.setattre.in.write_time = basetime + 40; + CHECK_CALL_FNUM(SETATTRE, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 20); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 30); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 40); + + sfinfo.setattre.in.create_time = 0; + sfinfo.setattre.in.access_time = 0; + sfinfo.setattre.in.write_time = 0; + CHECK_CALL_FNUM(SETATTRE, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 20); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 30); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 40); + + /* test standard level */ + sfinfo.standard.in.create_time = basetime + 100; + sfinfo.standard.in.access_time = basetime + 200; + sfinfo.standard.in.write_time = basetime + 300; + CHECK_CALL_FNUM(STANDARD, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + + /* test basic_info level */ + basetime += 86400; + unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100); + unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200); + unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300); + unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400); + sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY; + CHECK_CALL_FNUM(BASIC_INFO, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + + /* a zero time means don't change */ + unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0); + sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL; + CHECK_CALL_FNUM(BASIC_INFO, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL); + + /* test basic_information level */ + basetime += 86400; + unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100); + unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200); + unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300); + unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400); + sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY; + CHECK_CALL_FNUM(BASIC_INFORMATION, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + + CHECK_CALL_PATH(BASIC_INFORMATION, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY); + + /* a zero time means don't change */ + unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0); + unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0); + sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL; + CHECK_CALL_FNUM(BASIC_INFORMATION, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL); + + CHECK_CALL_PATH(BASIC_INFORMATION, NT_STATUS_OK); + CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100); + CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200); + CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300); + /* interesting - w2k3 leaves change_time as current time for 0 change time + in setpathinfo + CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400); + */ + CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL); + + /* test disposition_info level */ + sfinfo.disposition_info.in.delete_on_close = 1; + CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1); + CHECK_VALUE(ALL_INFO, all_info, nlink, 0); + + sfinfo.disposition_info.in.delete_on_close = 0; + CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0); + CHECK_VALUE(ALL_INFO, all_info, nlink, 1); + + /* test disposition_information level */ + sfinfo.disposition_info.in.delete_on_close = 1; + CHECK_CALL_FNUM(DISPOSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1); + CHECK_VALUE(ALL_INFO, all_info, nlink, 0); + + /* this would delete the file! */ + /* + CHECK_CALL_PATH(DISPOSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1); + CHECK_VALUE(ALL_INFO, all_info, nlink, 0); + */ + + sfinfo.disposition_info.in.delete_on_close = 0; + CHECK_CALL_FNUM(DISPOSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0); + CHECK_VALUE(ALL_INFO, all_info, nlink, 1); + + CHECK_CALL_PATH(DISPOSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0); + CHECK_VALUE(ALL_INFO, all_info, nlink, 1); + + /* test allocation_info level - this can truncate the file + to the rounded up size */ + sfinfo.allocation_info.in.alloc_size = 0; + CHECK_CALL_FNUM(ALLOCATION_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0); + + sfinfo.allocation_info.in.alloc_size = 4096; + CHECK_CALL_FNUM(ALLOCATION_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 4096); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + + RECREATE_BOTH; + sfinfo.allocation_info.in.alloc_size = 0; + CHECK_CALL_FNUM(ALLOCATION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0); + + CHECK_CALL_PATH(ALLOCATION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0); + + sfinfo.allocation_info.in.alloc_size = 4096; + CHECK_CALL_FNUM(ALLOCATION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 4096); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + + /* setting the allocation size up via setpathinfo seems + to be broken in w2k3 */ + CHECK_CALL_PATH(ALLOCATION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0); + CHECK_VALUE(ALL_INFO, all_info, size, 0); + + /* test end_of_file_info level */ + sfinfo.end_of_file_info.in.size = 37; + CHECK_CALL_FNUM(END_OF_FILE_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 37); + + sfinfo.end_of_file_info.in.size = 7; + CHECK_CALL_FNUM(END_OF_FILE_INFO, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 7); + + sfinfo.end_of_file_info.in.size = 37; + CHECK_CALL_FNUM(END_OF_FILE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 37); + + CHECK_CALL_PATH(END_OF_FILE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 37); + + sfinfo.end_of_file_info.in.size = 7; + CHECK_CALL_FNUM(END_OF_FILE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 7); + + CHECK_CALL_PATH(END_OF_FILE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(ALL_INFO, all_info, size, 7); + + + /* test position_information level */ + sfinfo.position_information.in.position = 123456; + CHECK_CALL_FNUM(POSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(POSITION_INFORMATION, position_information, position, 123456); + + CHECK_CALL_PATH(POSITION_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(POSITION_INFORMATION, position_information, position, 0); + + /* test mode_information level */ + sfinfo.mode_information.in.mode = 2; + CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 2); + + CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0); + + sfinfo.mode_information.in.mode = 1; + CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER); + CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER); + + sfinfo.mode_information.in.mode = 0; + CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0); + + CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_OK); + CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0); + + /* finally the rename_information level */ + cli_close(cli, create_complex_file(cli, mem_ctx, fnum_fname_new)); + cli_close(cli, create_complex_file(cli, mem_ctx, path_fname_new)); + + sfinfo.rename_information.in.overwrite = 0; + sfinfo.rename_information.in.root_fid = 0; + sfinfo.rename_information.in.new_name = fnum_fname_new+1; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OBJECT_NAME_COLLISION); + + sfinfo.rename_information.in.new_name = path_fname_new+1; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OBJECT_NAME_COLLISION); + + sfinfo.rename_information.in.new_name = fnum_fname_new+1; + sfinfo.rename_information.in.overwrite = 1; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new); + + sfinfo.rename_information.in.new_name = path_fname_new+1; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_fname_new); + + sfinfo.rename_information.in.new_name = fnum_fname+1; + CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname); + + sfinfo.rename_information.in.new_name = path_fname+1; + CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK); + CHECK_STR(NAME_INFO, name_info, fname.s, path_fname); + + +done: + cli_close(cli, fnum); + if (!cli_unlink(cli, fnum_fname)) { + printf("Failed to delete %s - %s\n", fnum_fname, cli_errstr(cli)); + } + if (!cli_unlink(cli, path_fname)) { + printf("Failed to delete %s - %s\n", path_fname, cli_errstr(cli)); + } + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} + + +/* + look for the w2k3 setpathinfo STANDARD bug +*/ +BOOL torture_sfileinfo_bug(int dummy) +{ + struct cli_state *cli; + TALLOC_CTX *mem_ctx; + const char *fname = "\\bug3.txt"; + union smb_setfileinfo sfinfo; + NTSTATUS status; + int fnum; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_sfileinfo"); + + fnum = create_complex_file(cli, mem_ctx, fname); + cli_close(cli, fnum); + + sfinfo.generic.level = RAW_SFILEINFO_STANDARD; + sfinfo.generic.file.fname = fname; + + sfinfo.standard.in.create_time = 0; + sfinfo.standard.in.access_time = 0; + sfinfo.standard.in.write_time = 0; + + status = smb_raw_setpathinfo(cli->tree, &sfinfo); + printf("%s - %s\n", fname, nt_errstr(status)); + + printf("now try and delete %s\n", fname); + + return True; +} diff --git a/source4/torture/t_strcmp.c b/source4/torture/t_strcmp.c new file mode 100644 index 0000000000..622769001b --- /dev/null +++ b/source4/torture/t_strcmp.c @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2003 by Martin Pool + * + * Test harness for StrCaseCmp + */ + +#include "includes.h" + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + fprintf(stderr, "usage: %s STRING1 STRING2\nCompares two strings\n", + argv[0]); + return 2; + } + + printf("%d\n", StrCaseCmp(argv[1], argv[2])); + + return 0; +} diff --git a/source4/torture/torture.c b/source4/torture/torture.c new file mode 100644 index 0000000000..05a2979dd1 --- /dev/null +++ b/source4/torture/torture.c @@ -0,0 +1,4183 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester + Copyright (C) Andrew Tridgell 1997-2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +static int nprocs=4; +int torture_numops=100; +int torture_entries=1000; +int torture_failures=1; +static int procnum; /* records process count number when forking */ +static struct cli_state *current_cli; +static char *randomfname; +static BOOL use_oplocks; +static BOOL use_level_II_oplocks; +static const char *client_txt = "client_oplocks.txt"; +static BOOL use_kerberos; +static BOOL bypass_io; + +BOOL torture_showall = False; + +static double create_procs(BOOL (*fn)(int), BOOL *result); + +#define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0) + +static struct cli_state *open_nbt_connection(void) +{ + struct nmb_name called, calling; + struct in_addr ip; + struct cli_state *cli; + char *host = lp_parm_string(-1, "torture", "host"); + + make_nmb_name(&calling, lp_netbios_name(), 0x0); + make_nmb_name(&called , host, 0x20); + + zero_ip(&ip); + + cli = cli_state_init(); + if (!cli) { + printf("Failed initialize cli_struct to connect with %s\n", host); + return NULL; + } + + if (!cli_socket_connect(cli, host, &ip)) { + printf("Failed to connect with %s\n", host); + return cli; + } + + cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */ + + if (!cli_transport_establish(cli, &calling, &called)) { + /* + * Well, that failed, try *SMBSERVER ... + * However, we must reconnect as well ... + */ + if (!cli_socket_connect(cli, host, &ip)) { + printf("Failed to connect with %s\n", host); + return False; + } + + make_nmb_name(&called, "*SMBSERVER", 0x20); + if (!cli_transport_establish(cli, &calling, &called)) { + printf("%s rejected the session\n",host); + printf("We tried with a called name of %s & %s\n", + host, "*SMBSERVER"); + cli_shutdown(cli); + return NULL; + } + } + + return cli; +} + +BOOL torture_open_connection(struct cli_state **c) +{ + BOOL retry; + int flags = 0; + NTSTATUS status; + char *host = lp_parm_string(-1, "torture", "host"); + char *share = lp_parm_string(-1, "torture", "share"); + char *username = lp_parm_string(-1, "torture", "username"); + char *password = lp_parm_string(-1, "torture", "password"); + + if (use_kerberos) + flags |= CLI_FULL_CONNECTION_USE_KERBEROS; + + status = cli_full_connection(c, lp_netbios_name(), + host, NULL, + share, "?????", + username, lp_workgroup(), + password, flags, &retry); + if (!NT_STATUS_IS_OK(status)) { + return False; + } + + (*c)->transport->options.use_oplocks = use_oplocks; + (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks; + (*c)->transport->socket->timeout = 120000; + + return True; +} + +BOOL torture_close_connection(struct cli_state *c) +{ + BOOL ret = True; + DEBUG(9,("torture_close_connection: cli_state@%p\n", c)); + if (!c) return True; + if (!cli_tdis(c)) { + printf("tdis failed (%s)\n", cli_errstr(c)); + ret = False; + } + DEBUG(9,("torture_close_connection: call cli_shutdown\n")); + cli_shutdown(c); + DEBUG(9,("torture_close_connection: exit\n")); + return ret; +} + + +/* check if the server produced the expected error code */ +static BOOL check_error(int line, struct cli_state *c, + uint8 eclass, uint32 ecode, NTSTATUS nterr) +{ + if (cli_is_dos_error(c)) { + uint8 class; + uint32 num; + + /* Check DOS error */ + + cli_dos_error(c, &class, &num); + + if (eclass != class || ecode != num) { + printf("unexpected error code class=%d code=%d\n", + (int)class, (int)num); + printf(" expected %d/%d %s (line=%d)\n", + (int)eclass, (int)ecode, nt_errstr(nterr), line); + return False; + } + + } else { + NTSTATUS status; + + /* Check NT error */ + + status = cli_nt_error(c); + + if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) { + printf("unexpected error code %s\n", nt_errstr(status)); + printf(" expected %s (line=%d)\n", nt_errstr(nterr), line); + return False; + } + } + + return True; +} + + +static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) +{ + while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) { + if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + return True; +} + + +static BOOL rw_torture(struct cli_state *c) +{ + const char *lockfname = "\\torture.lck"; + char *fname; + int fnum; + int fnum2; + pid_t pid2, pid = getpid(); + int i, j; + char buf[1024]; + BOOL correct = True; + + fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, + DENY_NONE); + if (fnum2 == -1) + fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open of %s failed (%s)\n", lockfname, cli_errstr(c)); + return False; + } + + + for (i=0;i<torture_numops;i++) { + unsigned n = (unsigned)sys_random()%10; + if (i % 10 == 0) { + printf("%d\r", i); fflush(stdout); + } + asprintf(&fname, "\\torture.%u", n); + + if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) { + return False; + } + + fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL); + if (fnum == -1) { + printf("open failed (%s)\n", cli_errstr(c)); + correct = False; + break; + } + + if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) { + printf("write failed (%s)\n", cli_errstr(c)); + correct = False; + } + + for (j=0;j<50;j++) { + if (cli_write(c, fnum, 0, (char *)buf, + sizeof(pid)+(j*sizeof(buf)), + sizeof(buf)) != sizeof(buf)) { + printf("write failed (%s)\n", cli_errstr(c)); + correct = False; + } + } + + pid2 = 0; + + if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) { + printf("read failed (%s)\n", cli_errstr(c)); + correct = False; + } + + if (pid2 != pid) { + printf("data corruption!\n"); + correct = False; + } + + if (!cli_close(c, fnum)) { + printf("close failed (%s)\n", cli_errstr(c)); + correct = False; + } + + if (!cli_unlink(c, fname)) { + printf("unlink failed (%s)\n", cli_errstr(c)); + correct = False; + } + + if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) { + printf("unlock failed (%s)\n", cli_errstr(c)); + correct = False; + } + free(fname); + } + + cli_close(c, fnum2); + cli_unlink(c, lockfname); + + printf("%d\n", i); + + return correct; +} + +static BOOL run_torture(int dummy) +{ + struct cli_state *cli; + BOOL ret; + + cli = current_cli; + + ret = rw_torture(cli); + + if (!torture_close_connection(cli)) { + ret = False; + } + + return ret; +} + +static BOOL rw_torture3(struct cli_state *c, char *lockfname) +{ + int fnum = -1; + unsigned int i = 0; + char buf[131072]; + char buf_rd[131072]; + unsigned count; + unsigned countprev = 0; + ssize_t sent = 0; + BOOL correct = True; + + srandom(1); + for (i = 0; i < sizeof(buf); i += sizeof(uint32)) + { + SIVAL(buf, i, sys_random()); + } + + if (procnum == 0) + { + fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, + DENY_NONE); + if (fnum == -1) { + printf("first open read/write of %s failed (%s)\n", + lockfname, cli_errstr(c)); + return False; + } + } + else + { + for (i = 0; i < 500 && fnum == -1; i++) + { + fnum = cli_open(c, lockfname, O_RDONLY, + DENY_NONE); + msleep(10); + } + if (fnum == -1) { + printf("second open read-only of %s failed (%s)\n", + lockfname, cli_errstr(c)); + return False; + } + } + + i = 0; + for (count = 0; count < sizeof(buf); count += sent) + { + if (count >= countprev) { + printf("%d %8d\r", i, count); + fflush(stdout); + i++; + countprev += (sizeof(buf) / 20); + } + + if (procnum == 0) + { + sent = ((unsigned)sys_random()%(20))+ 1; + if (sent > sizeof(buf) - count) + { + sent = sizeof(buf) - count; + } + + if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) { + printf("write failed (%s)\n", cli_errstr(c)); + correct = False; + } + } + else + { + sent = cli_read(c, fnum, buf_rd+count, count, + sizeof(buf)-count); + if (sent < 0) + { + printf("read failed offset:%d size:%d (%s)\n", + count, sizeof(buf)-count, + cli_errstr(c)); + correct = False; + sent = 0; + } + if (sent > 0) + { + if (memcmp(buf_rd+count, buf+count, sent) != 0) + { + printf("read/write compare failed\n"); + printf("offset: %d req %d recvd %d\n", + count, sizeof(buf)-count, sent); + correct = False; + break; + } + } + } + + } + + if (!cli_close(c, fnum)) { + printf("close failed (%s)\n", cli_errstr(c)); + correct = False; + } + + return correct; +} + +static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2) +{ + const char *lockfname = "\\torture2.lck"; + int fnum1; + int fnum2; + int i; + uchar buf[131072]; + uchar buf_rd[131072]; + BOOL correct = True; + ssize_t bytes_read, bytes_written; + + if (cli_deltree(c1, lockfname) == -1) { + printf("unlink failed (%s)\n", cli_errstr(c1)); + } + + fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL, + DENY_NONE); + if (fnum1 == -1) { + printf("first open read/write of %s failed (%s)\n", + lockfname, cli_errstr(c1)); + return False; + } + fnum2 = cli_open(c2, lockfname, O_RDONLY, + DENY_NONE); + if (fnum2 == -1) { + printf("second open read-only of %s failed (%s)\n", + lockfname, cli_errstr(c2)); + cli_close(c1, fnum1); + return False; + } + + printf("Checking data integrity over %d ops\n", torture_numops); + + for (i=0;i<torture_numops;i++) + { + size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1; + if (i % 10 == 0) { + printf("%d\r", i); fflush(stdout); + } + + generate_random_buffer(buf, buf_size, False); + + if ((bytes_written = cli_write(c1, fnum1, 0, buf, 0, buf_size)) != buf_size) { + printf("write failed (%s)\n", cli_errstr(c1)); + printf("wrote %d, expected %d\n", bytes_written, buf_size); + correct = False; + break; + } + + if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) { + printf("read failed (%s)\n", cli_errstr(c2)); + printf("read %d, expected %d\n", bytes_read, buf_size); + correct = False; + break; + } + + if (memcmp(buf_rd, buf, buf_size) != 0) + { + printf("read/write compare failed\n"); + correct = False; + break; + } + } + + if (!cli_close(c2, fnum2)) { + printf("close failed (%s)\n", cli_errstr(c2)); + correct = False; + } + if (!cli_close(c1, fnum1)) { + printf("close failed (%s)\n", cli_errstr(c1)); + correct = False; + } + + if (!cli_unlink(c1, lockfname)) { + printf("unlink failed (%s)\n", cli_errstr(c1)); + correct = False; + } + + return correct; +} + +static BOOL run_readwritetest(int dummy) +{ + struct cli_state *cli1, *cli2; + BOOL test1, test2 = True; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting readwritetest\n"); + + test1 = rw_torture2(cli1, cli2); + printf("Passed readwritetest v1: %s\n", BOOLSTR(test1)); + + if (test1) { + test2 = rw_torture2(cli1, cli1); + printf("Passed readwritetest v2: %s\n", BOOLSTR(test2)); + } + + if (!torture_close_connection(cli1)) { + test1 = False; + } + + if (!torture_close_connection(cli2)) { + test2 = False; + } + + return (test1 && test2); +} + +static BOOL run_readwritemulti(int dummy) +{ + struct cli_state *cli; + BOOL test; + + cli = current_cli; + + printf("run_readwritemulti: fname %s\n", randomfname); + test = rw_torture3(cli, randomfname); + + if (!torture_close_connection(cli)) { + test = False; + } + + return test; +} + + +int line_count = 0; +int nbio_id; + +#define ival(s) strtol(s, NULL, 0) + +/* run a test that simulates an approximate netbench client load */ +static BOOL run_netbench(int client) +{ + struct cli_state *cli; + int i; + pstring line; + char *cname; + FILE *f; + const char *params[20]; + BOOL correct = True; + + cli = current_cli; + + nbio_id = client; + + nb_setup(cli); + + asprintf(&cname, "client%d", client); + + f = fopen(client_txt, "r"); + + if (!f) { + perror(client_txt); + return False; + } + + while (fgets(line, sizeof(line)-1, f)) { + line_count++; + + line[strlen(line)-1] = 0; + + /* printf("[%d] %s\n", line_count, line); */ + + all_string_sub(line,"client1", cname, sizeof(line)); + + /* parse the command parameters */ + params[0] = strtok(line," "); + i = 0; + while (params[i]) params[++i] = strtok(NULL," "); + + params[i] = ""; + + if (i < 2) continue; + + if (!strncmp(params[0],"SMB", 3)) { + printf("ERROR: You are using a dbench 1 load file\n"); + exit(1); + } + DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1])); + + if (!strcmp(params[0],"NTCreateX")) { + nb_createx(params[1], ival(params[2]), ival(params[3]), + ival(params[4])); + } else if (!strcmp(params[0],"Close")) { + nb_close(ival(params[1])); + } else if (!strcmp(params[0],"Rename")) { + nb_rename(params[1], params[2]); + } else if (!strcmp(params[0],"Unlink")) { + nb_unlink(params[1]); + } else if (!strcmp(params[0],"Deltree")) { + nb_deltree(params[1]); + } else if (!strcmp(params[0],"Rmdir")) { + nb_rmdir(params[1]); + } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) { + nb_qpathinfo(params[1]); + } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) { + nb_qfileinfo(ival(params[1])); + } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) { + nb_qfsinfo(ival(params[1])); + } else if (!strcmp(params[0],"FIND_FIRST")) { + nb_findfirst(params[1]); + } else if (!strcmp(params[0],"WriteX")) { + nb_writex(ival(params[1]), + ival(params[2]), ival(params[3]), ival(params[4])); + } else if (!strcmp(params[0],"ReadX")) { + nb_readx(ival(params[1]), + ival(params[2]), ival(params[3]), ival(params[4])); + } else if (!strcmp(params[0],"Flush")) { + nb_flush(ival(params[1])); + } else { + printf("Unknown operation %s\n", params[0]); + exit(1); + } + } + fclose(f); + + nb_cleanup(); + + if (!torture_close_connection(cli)) { + correct = False; + } + + return correct; +} + + +/* run a test that simulates an approximate netbench client load */ +static BOOL run_nbench(int dummy) +{ + double t; + BOOL correct = True; + + nbio_shmem(nprocs); + + nbio_id = -1; + + signal(SIGALRM, SIGNAL_CAST nb_alarm); + alarm(1); + t = create_procs(run_netbench, &correct); + alarm(0); + + printf("\nThroughput %g MB/sec\n", + 1.0e-6 * nbio_total() / t); + return correct; +} + + +/* + This test checks for two things: + + 1) correct support for retaining locks over a close (ie. the server + must not use posix semantics) + 2) support for lock timeouts + */ +static BOOL run_locktest1(int dummy) +{ + struct cli_state *cli1, *cli2; + const char *fname = "\\lockt1.lck"; + int fnum1, fnum2, fnum3; + time_t t1, t2; + unsigned lock_timeout; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting locktest1\n"); + + cli_unlink(cli1, fname); + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE); + if (fnum3 == -1) { + printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2)); + return False; + } + + if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) { + printf("lock1 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + + if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) { + printf("lock2 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + + lock_timeout = (6 + (random() % 20)); + printf("Testing lock timeout with timeout=%u\n", lock_timeout); + t1 = time(NULL); + if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) { + printf("lock3 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + } + t2 = time(NULL); + + if (t2 - t1 < 5) { + printf("error: This server appears not to support timed lock requests\n"); + } + printf("server slept for %u seconds for a %u second timeout\n", + (unsigned int)(t2-t1), lock_timeout); + + if (!cli_close(cli1, fnum2)) { + printf("close1 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) { + printf("lock4 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + if (!cli_close(cli2, fnum3)) { + printf("close3 failed (%s)\n", cli_errstr(cli2)); + return False; + } + + if (!cli_unlink(cli1, fname)) { + printf("unlink failed (%s)\n", cli_errstr(cli1)); + return False; + } + + + if (!torture_close_connection(cli1)) { + return False; + } + + if (!torture_close_connection(cli2)) { + return False; + } + + printf("Passed locktest1\n"); + return True; +} + +/* + this checks to see if a secondary tconx can use open files from an + earlier tconx + */ +static BOOL run_tcon_test(int dummy) +{ + struct cli_state *cli; + const char *fname = "\\tcontest.tmp"; + int fnum1; + uint16 cnum1, cnum2, cnum3; + uint16 vuid1, vuid2; + char buf[4]; + BOOL ret = True; + struct cli_tree *tree1; + char *host = lp_parm_string(-1, "torture", "host"); + char *share = lp_parm_string(-1, "torture", "share"); + char *password = lp_parm_string(-1, "torture", "password"); + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("starting tcontest\n"); + + if (cli_deltree(cli, fname) == -1) { + printf("unlink of %s failed (%s)\n", fname, cli_errstr(cli)); + } + + fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); + return False; + } + + cnum1 = cli->tree->tid; + vuid1 = cli->session->vuid; + + memset(&buf, 0, 4); /* init buf so valgrind won't complain */ + if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) { + printf("initial write failed (%s)\n", cli_errstr(cli)); + return False; + } + + tree1 = cli->tree; /* save old tree connection */ + if (!cli_send_tconX(cli, share, "?????", + password)) { + printf("%s refused 2nd tree connect (%s)\n", host, + cli_errstr(cli)); + cli_shutdown(cli); + return False; + } + + cnum2 = cli->tree->tid; + cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */ + vuid2 = cli->session->vuid + 1; + + /* try a write with the wrong tid */ + cli->tree->tid = cnum2; + + if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) { + printf("* server allows write with wrong TID\n"); + ret = False; + } else { + printf("server fails write with wrong TID : %s\n", cli_errstr(cli)); + } + + + /* try a write with an invalid tid */ + cli->tree->tid = cnum3; + + if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) { + printf("* server allows write with invalid TID\n"); + ret = False; + } else { + printf("server fails write with invalid TID : %s\n", cli_errstr(cli)); + } + + /* try a write with an invalid vuid */ + cli->session->vuid = vuid2; + cli->tree->tid = cnum1; + + if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) { + printf("* server allows write with invalid VUID\n"); + ret = False; + } else { + printf("server fails write with invalid VUID : %s\n", cli_errstr(cli)); + } + + cli->session->vuid = vuid1; + cli->tree->tid = cnum1; + + if (!cli_close(cli, fnum1)) { + printf("close failed (%s)\n", cli_errstr(cli)); + return False; + } + + cli->tree->tid = cnum2; + + if (!cli_tdis(cli)) { + printf("secondary tdis failed (%s)\n", cli_errstr(cli)); + return False; + } + + cli->tree = tree1; /* restore initial tree */ + cli->tree->tid = cnum1; + + if (!torture_close_connection(cli)) { + return False; + } + + return ret; +} + + + +static BOOL tcon_devtest(struct cli_state *cli, + const char *myshare, const char *devtype, + NTSTATUS expected_error) +{ + BOOL status; + BOOL ret; + char *password = lp_parm_string(-1, "torture", "password"); + + status = cli_send_tconX(cli, myshare, devtype, + password); + + printf("Trying share %s with devtype %s\n", myshare, devtype); + + if (NT_STATUS_IS_OK(expected_error)) { + if (status) { + ret = True; + } else { + printf("tconX to share %s with type %s " + "should have succeeded but failed\n", + myshare, devtype); + ret = False; + } + cli_tdis(cli); + } else { + if (status) { + printf("tconx to share %s with type %s " + "should have failed but succeeded\n", + myshare, devtype); + ret = False; + } else { + if (NT_STATUS_EQUAL(cli_nt_error(cli), + expected_error)) { + ret = True; + } else { + printf("Returned unexpected error\n"); + ret = False; + } + } + } + return ret; +} + +/* + checks for correct tconX support + */ +static BOOL run_tcon_devtype_test(int dummy) +{ + struct cli_state *cli1 = NULL; + BOOL retry; + int flags = 0; + NTSTATUS status; + BOOL ret = True; + char *host = lp_parm_string(-1, "torture", "host"); + char *share = lp_parm_string(-1, "torture", "share"); + char *username = lp_parm_string(-1, "torture", "username"); + char *password = lp_parm_string(-1, "torture", "password"); + + status = cli_full_connection(&cli1, lp_netbios_name(), + host, NULL, + share, "?????", + username, lp_workgroup(), + password, flags, &retry); + + if (!NT_STATUS_IS_OK(status)) { + printf("could not open connection\n"); + return False; + } + + if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE)) + ret = False; + + if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK)) + ret = False; + + if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE)) + ret = False; + + if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK)) + ret = False; + + if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE)) + ret = False; + + if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK)) + ret = False; + + if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK)) + ret = False; + + if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE)) + ret = False; + + if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE)) + ret = False; + + if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE)) + ret = False; + + cli_shutdown(cli1); + + if (ret) + printf("Passed tcondevtest\n"); + + return ret; +} + + +/* + This test checks that + + 1) the server supports multiple locking contexts on the one SMB + connection, distinguished by PID. + + 2) the server correctly fails overlapping locks made by the same PID (this + goes against POSIX behaviour, which is why it is tricky to implement) + + 3) the server denies unlock requests by an incorrect client PID +*/ +static BOOL run_locktest2(int dummy) +{ + struct cli_state *cli; + const char *fname = "\\lockt2.lck"; + int fnum1, fnum2, fnum3; + BOOL correct = True; + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("starting locktest2\n"); + + cli_unlink(cli, fname); + + printf("Testing pid context\n"); + + cli->session->pid = 1; + + fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); + return False; + } + + fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli)); + return False; + } + + cli->session->pid = 2; + + fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE); + if (fnum3 == -1) { + printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli)); + return False; + } + + cli->session->pid = 1; + + if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) { + printf("lock1 failed (%s)\n", cli_errstr(cli)); + return False; + } + + if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) { + printf("WRITE lock1 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__LINE__, cli, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) { + printf("WRITE lock2 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__LINE__, cli, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) { + printf("READ lock2 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__LINE__, cli, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + } + + if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) { + printf("lock at 100 failed (%s)\n", cli_errstr(cli)); + } + + cli->session->pid = 2; + + if (cli_unlock(cli, fnum1, 100, 4)) { + printf("unlock at 100 succeeded! This is a locking bug\n"); + correct = False; + } + + if (cli_unlock(cli, fnum1, 0, 4)) { + printf("unlock1 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__LINE__, cli, + ERRDOS, ERRlock, + NT_STATUS_RANGE_NOT_LOCKED)) return False; + } + + if (cli_unlock(cli, fnum1, 0, 8)) { + printf("unlock2 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__LINE__, cli, + ERRDOS, ERRlock, + NT_STATUS_RANGE_NOT_LOCKED)) return False; + } + + if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) { + printf("lock3 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + cli->session->pid = 1; + + if (!cli_close(cli, fnum1)) { + printf("close1 failed (%s)\n", cli_errstr(cli)); + return False; + } + + if (!cli_close(cli, fnum2)) { + printf("close2 failed (%s)\n", cli_errstr(cli)); + return False; + } + + if (!cli_close(cli, fnum3)) { + printf("close3 failed (%s)\n", cli_errstr(cli)); + return False; + } + + if (!torture_close_connection(cli)) { + correct = False; + } + + printf("locktest2 finished\n"); + + return correct; +} + + +/* + This test checks that + + 1) the server supports the full offset range in lock requests +*/ +static BOOL run_locktest3(int dummy) +{ + struct cli_state *cli1, *cli2; + const char *fname = "\\lockt3.lck"; + int fnum1, fnum2, i; + uint32 offset; + BOOL correct = True; + +#define NEXT_OFFSET offset += (~(uint32)0) / torture_numops + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting locktest3\n"); + + printf("Testing 32 bit offset ranges\n"); + + cli_unlink(cli1, fname); + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + return False; + } + + printf("Establishing %d locks\n", torture_numops); + + for (offset=i=0;i<torture_numops;i++) { + NEXT_OFFSET; + if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) { + printf("lock1 %d failed (%s)\n", + i, + cli_errstr(cli1)); + return False; + } + + if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) { + printf("lock2 %d failed (%s)\n", + i, + cli_errstr(cli1)); + return False; + } + } + + printf("Testing %d locks\n", torture_numops); + + for (offset=i=0;i<torture_numops;i++) { + NEXT_OFFSET; + + if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) { + printf("error: lock1 %d succeeded!\n", i); + return False; + } + + if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) { + printf("error: lock2 %d succeeded!\n", i); + return False; + } + + if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) { + printf("error: lock3 %d succeeded!\n", i); + return False; + } + + if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) { + printf("error: lock4 %d succeeded!\n", i); + return False; + } + } + + printf("Removing %d locks\n", torture_numops); + + for (offset=i=0;i<torture_numops;i++) { + NEXT_OFFSET; + + if (!cli_unlock(cli1, fnum1, offset-1, 1)) { + printf("unlock1 %d failed (%s)\n", + i, + cli_errstr(cli1)); + return False; + } + + if (!cli_unlock(cli2, fnum2, offset-2, 1)) { + printf("unlock2 %d failed (%s)\n", + i, + cli_errstr(cli1)); + return False; + } + } + + if (!cli_close(cli1, fnum1)) { + printf("close1 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + if (!cli_close(cli2, fnum2)) { + printf("close2 failed (%s)\n", cli_errstr(cli2)); + return False; + } + + if (!cli_unlink(cli1, fname)) { + printf("unlink failed (%s)\n", cli_errstr(cli1)); + return False; + } + + if (!torture_close_connection(cli1)) { + correct = False; + } + + if (!torture_close_connection(cli2)) { + correct = False; + } + + printf("finished locktest3\n"); + + return correct; +} + +#define EXPECTED(ret, v) if ((ret) != (v)) { \ + printf("** "); correct = False; \ + } + +/* + looks at overlapping locks +*/ +static BOOL run_locktest4(int dummy) +{ + struct cli_state *cli1, *cli2; + const char *fname = "\\lockt4.lck"; + int fnum1, fnum2, f; + BOOL ret; + char buf[1000]; + BOOL correct = True; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting locktest4\n"); + + cli_unlink(cli1, fname); + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE); + + memset(buf, 0, sizeof(buf)); + + if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { + printf("Failed to create file\n"); + correct = False; + goto fail; + } + + ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) && + cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK); + EXPECTED(ret, False); + printf("the same process %s set overlapping write locks\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) && + cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK); + EXPECTED(ret, True); + printf("the same process %s set overlapping read locks\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) && + cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK); + EXPECTED(ret, False); + printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) && + cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK); + EXPECTED(ret, True); + printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot"); + + ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) && + (cli1->session->pid = 2, cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK)); + EXPECTED(ret, False); + printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot"); + + ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) && + (cli1->session->pid = 2, cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK)); + EXPECTED(ret, True); + printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) && + cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK); + EXPECTED(ret, True); + printf("the same process %s set the same read lock twice\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) && + cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK); + EXPECTED(ret, False); + printf("the same process %s set the same write lock twice\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) && + cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK); + EXPECTED(ret, False); + printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) && + cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK); + EXPECTED(ret, True); + printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot"); + + ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) && + (cli1->session->pid = 2, cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK)); + EXPECTED(ret, False); + printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) && + cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) && + cli_unlock(cli1, fnum1, 110, 6); + EXPECTED(ret, False); + printf("the same process %s coalesce read locks\n", ret?"can":"cannot"); + + + ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) && + (cli_read(cli2, fnum2, buf, 120, 4) == 4); + EXPECTED(ret, False); + printf("this server %s strict write locking\n", ret?"doesn't do":"does"); + + ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) && + (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4); + EXPECTED(ret, False); + printf("this server %s strict read locking\n", ret?"doesn't do":"does"); + + + ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) && + cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) && + cli_unlock(cli1, fnum1, 140, 4) && + cli_unlock(cli1, fnum1, 140, 4); + EXPECTED(ret, True); + printf("this server %s do recursive read locking\n", ret?"does":"doesn't"); + + + ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) && + cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) && + cli_unlock(cli1, fnum1, 150, 4) && + (cli_read(cli2, fnum2, buf, 150, 4) == 4) && + !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) && + cli_unlock(cli1, fnum1, 150, 4); + EXPECTED(ret, True); + printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't"); + + ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) && + cli_unlock(cli1, fnum1, 160, 4) && + (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) && + (cli_read(cli2, fnum2, buf, 160, 4) == 4); + EXPECTED(ret, True); + printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) && + cli_unlock(cli1, fnum1, 170, 4) && + (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) && + (cli_read(cli2, fnum2, buf, 170, 4) == 4); + EXPECTED(ret, True); + printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot"); + + ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) && + cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) && + cli_unlock(cli1, fnum1, 190, 4) && + !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) && + (cli_read(cli2, fnum2, buf, 190, 4) == 4); + EXPECTED(ret, True); + printf("the same process %s remove the first lock first\n", ret?"does":"doesn't"); + + cli_close(cli1, fnum1); + cli_close(cli2, fnum2); + fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE); + f = cli_open(cli1, fname, O_RDWR, DENY_NONE); + ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) && + cli_lock(cli1, f, 0, 1, 0, READ_LOCK) && + cli_close(cli1, fnum1) && + ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) && + cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK); + cli_close(cli1, f); + cli_close(cli1, fnum1); + EXPECTED(ret, True); + printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); + + fail: + cli_close(cli1, fnum1); + cli_close(cli2, fnum2); + cli_unlink(cli1, fname); + torture_close_connection(cli1); + torture_close_connection(cli2); + + printf("finished locktest4\n"); + return correct; +} + +/* + looks at lock upgrade/downgrade. +*/ +static BOOL run_locktest5(int dummy) +{ + struct cli_state *cli1, *cli2; + const char *fname = "\\lockt5.lck"; + int fnum1, fnum2, fnum3; + BOOL ret; + char buf[1000]; + BOOL correct = True; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting locktest5\n"); + + cli_unlink(cli1, fname); + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE); + fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE); + + memset(buf, 0, sizeof(buf)); + + if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { + printf("Failed to create file\n"); + correct = False; + goto fail; + } + + /* Check for NT bug... */ + ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) && + cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK); + cli_close(cli1, fnum1); + fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE); + ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK); + EXPECTED(ret, True); + printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); + cli_close(cli1, fnum1); + fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE); + cli_unlock(cli1, fnum3, 0, 1); + + ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) && + cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK); + EXPECTED(ret, True); + printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); + + ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK); + EXPECTED(ret, False); + + printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot"); + + /* Unlock the process 2 lock. */ + cli_unlock(cli2, fnum2, 0, 4); + + ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK); + EXPECTED(ret, False); + + printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot"); + + /* Unlock the process 1 fnum3 lock. */ + cli_unlock(cli1, fnum3, 0, 4); + + /* Stack 2 more locks here. */ + ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) && + cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK); + + EXPECTED(ret, True); + printf("the same process %s stack read locks\n", ret?"can":"cannot"); + + /* Unlock the first process lock, then check this was the WRITE lock that was + removed. */ + + ret = cli_unlock(cli1, fnum1, 0, 4) && + cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK); + + EXPECTED(ret, True); + printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ"); + + /* Unlock the process 2 lock. */ + cli_unlock(cli2, fnum2, 0, 4); + + /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */ + + ret = cli_unlock(cli1, fnum1, 1, 1) && + cli_unlock(cli1, fnum1, 0, 4) && + cli_unlock(cli1, fnum1, 0, 4); + + EXPECTED(ret, True); + printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot"); + + /* Ensure the next unlock fails. */ + ret = cli_unlock(cli1, fnum1, 0, 4); + EXPECTED(ret, False); + printf("the same process %s count the lock stack\n", !ret?"can":"cannot"); + + /* Ensure connection 2 can get a write lock. */ + ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK); + EXPECTED(ret, True); + + printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot"); + + + fail: + cli_close(cli1, fnum1); + cli_close(cli2, fnum2); + cli_unlink(cli1, fname); + if (!torture_close_connection(cli1)) { + correct = False; + } + if (!torture_close_connection(cli2)) { + correct = False; + } + + printf("finished locktest5\n"); + + return correct; +} + +/* + tries the unusual lockingX locktype bits +*/ +static BOOL run_locktest6(int dummy) +{ + struct cli_state *cli; + const char *fname[1] = { "\\lock6.txt" }; + int i; + int fnum; + NTSTATUS status; + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("starting locktest6\n"); + + for (i=0;i<1;i++) { + printf("Testing %s\n", fname[i]); + + cli_unlink(cli, fname[i]); + + fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE); + cli_close(cli, fnum); + printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status)); + + fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE); + status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK); + cli_close(cli, fnum); + printf("CANCEL_LOCK gave %s\n", nt_errstr(status)); + + cli_unlink(cli, fname[i]); + } + + torture_close_connection(cli); + + printf("finished locktest6\n"); + return True; +} + +static BOOL run_locktest7(int dummy) +{ + struct cli_state *cli1; + const char *fname = "\\lockt7.lck"; + int fnum1; + char buf[200]; + BOOL correct = False; + + if (!torture_open_connection(&cli1)) { + return False; + } + + printf("starting locktest7\n"); + + cli_unlink(cli1, fname); + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + + memset(buf, 0, sizeof(buf)); + + if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { + printf("Failed to create file\n"); + goto fail; + } + + cli1->session->pid = 1; + + if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) { + printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1)); + goto fail; + } else { + printf("pid1 successfully locked range 130:4 for READ\n"); + } + + if (cli_read(cli1, fnum1, buf, 130, 4) != 4) { + printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1)); + goto fail; + } else { + printf("pid1 successfully read the range 130:4\n"); + } + + if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) { + printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1)); + if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid1 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + cli1->session->pid = 2; + + if (cli_read(cli1, fnum1, buf, 130, 4) != 4) { + printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1)); + } else { + printf("pid2 successfully read the range 130:4\n"); + } + + if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) { + printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1)); + if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + cli1->session->pid = 1; + cli_unlock(cli1, fnum1, 130, 4); + + if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) { + printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1)); + goto fail; + } else { + printf("pid1 successfully locked range 130:4 for WRITE\n"); + } + + if (cli_read(cli1, fnum1, buf, 130, 4) != 4) { + printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1)); + goto fail; + } else { + printf("pid1 successfully read the range 130:4\n"); + } + + if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) { + printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1)); + goto fail; + } else { + printf("pid1 successfully wrote to the range 130:4\n"); + } + + cli1->session->pid = 2; + + if (cli_read(cli1, fnum1, buf, 130, 4) != 4) { + printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1)); + if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully read the range 130:4 (should be denied)\n"); + goto fail; + } + + if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) { + printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1)); + if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + cli_unlock(cli1, fnum1, 130, 0); + correct = True; + +fail: + cli_close(cli1, fnum1); + cli_unlink(cli1, fname); + torture_close_connection(cli1); + + printf("finished locktest7\n"); + return correct; +} + +/* +test whether fnums and tids open on one VC are available on another (a major +security hole) +*/ +static BOOL run_fdpasstest(int dummy) +{ + struct cli_state *cli1, *cli2; + const char *fname = "\\fdpass.tst"; + int fnum1, oldtid; + pstring buf; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting fdpasstest\n"); + + cli_unlink(cli1, fname); + + printf("Opening a file on connection 1\n"); + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + printf("writing to file on connection 1\n"); + + if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) { + printf("write failed (%s)\n", cli_errstr(cli1)); + return False; + } + + oldtid = cli2->tree->tid; + cli2->session->vuid = cli1->session->vuid; + cli2->tree->tid = cli1->tree->tid; + cli2->session->pid = cli1->session->pid; + + printf("reading from file on connection 2\n"); + + if (cli_read(cli2, fnum1, buf, 0, 13) == 13) { + printf("read succeeded! nasty security hole [%s]\n", + buf); + return False; + } + + cli_close(cli1, fnum1); + cli_unlink(cli1, fname); + + cli2->tree->tid = oldtid; + + torture_close_connection(cli1); + torture_close_connection(cli2); + + printf("finished fdpasstest\n"); + return True; +} + + +/* + This test checks that + + 1) the server does not allow an unlink on a file that is open +*/ +static BOOL run_unlinktest(int dummy) +{ + struct cli_state *cli; + const char *fname = "\\unlink.tst"; + int fnum; + BOOL correct = True; + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("starting unlink test\n"); + + cli_unlink(cli, fname); + + cli->session->pid = 1; + + printf("Opening a file\n"); + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); + return False; + } + + printf("Unlinking a open file\n"); + + if (cli_unlink(cli, fname)) { + printf("error: server allowed unlink on an open file\n"); + correct = False; + } else { + correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare, + NT_STATUS_SHARING_VIOLATION); + } + + cli_close(cli, fnum); + cli_unlink(cli, fname); + + if (!torture_close_connection(cli)) { + correct = False; + } + + printf("unlink test finished\n"); + + return correct; +} + + +/* +test how many open files this server supports on the one socket +*/ +static BOOL run_maxfidtest(int dummy) +{ + struct cli_state *cli; + const char *template = "\\maxfid.%d.%d"; + char *fname; + int fnums[0x11000], i; + int retries=4; + BOOL correct = True; + + cli = current_cli; + + if (retries <= 0) { + printf("failed to connect\n"); + return False; + } + + printf("Testing maximum number of open files\n"); + + for (i=0; i<0x11000; i++) { + asprintf(&fname, template, i,(int)getpid()); + if ((fnums[i] = cli_open(cli, fname, + O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == + -1) { + printf("open of %s failed (%s)\n", + fname, cli_errstr(cli)); + printf("maximum fnum is %d\n", i); + break; + } + free(fname); + printf("%6d\r", i); + } + printf("%6d\n", i); + i--; + + printf("cleaning up\n"); + for (;i>=0;i--) { + asprintf(&fname, template, i,(int)getpid()); + if (!cli_close(cli, fnums[i])) { + printf("Close of fnum %d failed - %s\n", fnums[i], cli_errstr(cli)); + } + if (!cli_unlink(cli, fname)) { + printf("unlink of %s failed (%s)\n", + fname, cli_errstr(cli)); + correct = False; + } + free(fname); + printf("%6d\r", i); + } + printf("%6d\n", 0); + + printf("maxfid test finished\n"); + if (!torture_close_connection(cli)) { + correct = False; + } + return correct; +} + +/* send smb negprot commands, not reading the response */ +static BOOL run_negprot_nowait(int dummy) +{ + int i; + struct cli_state *cli; + BOOL correct = True; + + printf("starting negprot nowait test\n"); + + cli = open_nbt_connection(); + if (!cli) { + return False; + } + + printf("Establishing protocol negotiations - connect with another client\n"); + + for (i=0;i<50000;i++) { + smb_negprot_send(cli->transport, PROTOCOL_NT1); + } + + if (!torture_close_connection(cli)) { + correct = False; + } + + printf("finished negprot nowait test\n"); + + return correct; +} + + +/* + This checks how the getatr calls works +*/ +static BOOL run_attrtest(int dummy) +{ + struct cli_state *cli; + int fnum; + time_t t, t2; + const char *fname = "\\attrib123456789.tst"; + BOOL correct = True; + + printf("starting attrib test\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + cli_unlink(cli, fname); + fnum = cli_open(cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_close(cli, fnum); + + if (!cli_getatr(cli, fname, NULL, NULL, &t)) { + printf("getatr failed (%s)\n", cli_errstr(cli)); + correct = False; + } + + printf("New file time is %s", ctime(&t)); + + if (abs(t - time(NULL)) > 60*60*24*10) { + printf("ERROR: SMBgetatr bug. time is %s", + ctime(&t)); + t = time(NULL); + correct = False; + } + + t2 = t-60*60*24; /* 1 day ago */ + + printf("Setting file time to %s", ctime(&t2)); + + if (!cli_setatr(cli, fname, 0, t2)) { + printf("setatr failed (%s)\n", cli_errstr(cli)); + correct = True; + } + + if (!cli_getatr(cli, fname, NULL, NULL, &t)) { + printf("getatr failed (%s)\n", cli_errstr(cli)); + correct = True; + } + + printf("Retrieved file time as %s", ctime(&t)); + + if (t != t2) { + printf("ERROR: getatr/setatr bug. times are\n%s", + ctime(&t)); + printf("%s", ctime(&t2)); + correct = True; + } + + cli_unlink(cli, fname); + + if (!torture_close_connection(cli)) { + correct = False; + } + + printf("attrib test finished\n"); + + return correct; +} + + +/* + This checks a couple of trans2 calls +*/ +static BOOL run_trans2test(int dummy) +{ + struct cli_state *cli; + int fnum; + size_t size; + time_t c_time, a_time, m_time, w_time, m_time2; + const char *fname = "\\trans2.tst"; + const char *dname = "\\trans2"; + const char *fname2 = "\\trans2\\trans2.tst"; + const char *pname; + BOOL correct = True; + + printf("starting trans2 test\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + cli_unlink(cli, fname); + + printf("Testing qfileinfo\n"); + + fnum = cli_open(cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time, + NULL, NULL)) { + printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli)); + correct = False; + } + + printf("Testing NAME_INFO\n"); + + if (!cli_qfilename(cli, fnum, &pname)) { + printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli)); + correct = False; + } + + if (!pname || strcmp(pname, fname)) { + printf("qfilename gave different name? [%s] [%s]\n", + fname, pname); + correct = False; + } + + cli_close(cli, fnum); + cli_unlink(cli, fname); + + fnum = cli_open(cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + if (fnum == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); + return False; + } + cli_close(cli, fnum); + + printf("Checking for sticky create times\n"); + + if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) { + printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli)); + correct = False; + } else { + if (c_time != m_time) { + printf("create time=%s", ctime(&c_time)); + printf("modify time=%s", ctime(&m_time)); + printf("This system appears to have sticky create times\n"); + } + if (a_time % (60*60) == 0) { + printf("access time=%s", ctime(&a_time)); + printf("This system appears to set a midnight access time\n"); + correct = False; + } + + if (abs(m_time - time(NULL)) > 60*60*24*7) { + printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time)); + correct = False; + } + } + + + cli_unlink(cli, fname); + fnum = cli_open(cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_close(cli, fnum); + if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time, + &w_time, &size, NULL, NULL)) { + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli)); + correct = False; + } else { + if (w_time < 60*60*24*2) { + printf("write time=%s", ctime(&w_time)); + printf("This system appears to set a initial 0 write time\n"); + correct = False; + } + } + + cli_unlink(cli, fname); + + + /* check if the server updates the directory modification time + when creating a new file */ + if (!cli_mkdir(cli, dname)) { + printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli)); + correct = False; + } + sleep(3); + if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time, + &w_time, &size, NULL, NULL)) { + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli)); + correct = False; + } + + fnum = cli_open(cli, fname2, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum)); + cli_close(cli, fnum); + if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2, + &w_time, &size, NULL, NULL)) { + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli)); + correct = False; + } else { + if (m_time2 == m_time) { + printf("This system does not update directory modification times\n"); + correct = False; + } + } + cli_unlink(cli, fname2); + cli_rmdir(cli, dname); + + if (!torture_close_connection(cli)) { + correct = False; + } + + printf("trans2 test finished\n"); + + return correct; +} + +/* + Test delete on close semantics. + */ +static BOOL run_deletetest(int dummy) +{ + struct cli_state *cli1; + struct cli_state *cli2 = NULL; + const char *fname = "\\delete.file"; + int fnum1 = -1; + int fnum2 = -1; + BOOL correct = True; + + printf("starting delete test\n"); + + if (!torture_open_connection(&cli1)) { + return False; + } + + /* Test 1 - this should delete the file on close. */ + + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, + NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); + + if (fnum1 == -1) { + printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum1)) { + printf("[1] close failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE); + if (fnum1 != -1) { + printf("[1] open of %s succeeded (should fail)\n", fname); + correct = False; + goto fail; + } + + printf("first delete on close test succeeded.\n"); + + /* Test 2 - this should delete the file on close. */ + + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, + FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, + NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_nt_delete_on_close(cli1, fnum1, True)) { + printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum1)) { + printf("[2] close failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 != -1) { + printf("[2] open of %s succeeded should have been deleted on close !\n", fname); + if (!cli_close(cli1, fnum1)) { + printf("[2] close failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + cli_unlink(cli1, fname); + } else + printf("second delete on close test succeeded.\n"); + + /* Test 3 - ... */ + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This should fail with a sharing violation - open for delete is only compatible + with SHARE_DELETE. */ + + fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, + NTCREATEX_DISP_OPEN, 0, 0); + + if (fnum2 != -1) { + printf("[3] open - 2 of %s succeeded - should have failed.\n", fname); + correct = False; + goto fail; + } + + /* This should succeed. */ + + fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0); + + if (fnum2 == -1) { + printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_nt_delete_on_close(cli1, fnum1, True)) { + printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum1)) { + printf("[3] close 1 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum2)) { + printf("[3] close 2 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This should fail - file should no longer be there. */ + + fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 != -1) { + printf("[3] open of %s succeeded should have been deleted on close !\n", fname); + if (!cli_close(cli1, fnum1)) { + printf("[3] close failed (%s)\n", cli_errstr(cli1)); + } + cli_unlink(cli1, fname); + correct = False; + goto fail; + } else + printf("third delete on close test succeeded.\n"); + + /* Test 4 ... */ + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + fnum1 = cli_nt_create_full(cli1, fname, 0, + SA_RIGHT_FILE_READ_DATA | + SA_RIGHT_FILE_WRITE_DATA | + STD_RIGHT_DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, + NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This should succeed. */ + fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, + FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE | + NTCREATEX_SHARE_ACCESS_DELETE, + NTCREATEX_DISP_OPEN, 0, 0); + if (fnum2 == -1) { + printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum2)) { + printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_nt_delete_on_close(cli1, fnum1, True)) { + printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This should fail - no more opens once delete on close set. */ + fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, + FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, + NTCREATEX_DISP_OPEN, 0, 0); + if (fnum2 != -1) { + printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname ); + correct = False; + goto fail; + } else + printf("fourth delete on close test succeeded.\n"); + + if (!cli_close(cli1, fnum1)) { + printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* Test 5 ... */ + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This should fail - only allowed on NT opens with DELETE access. */ + + if (cli_nt_delete_on_close(cli1, fnum1, True)) { + printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n"); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum1)) { + printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + printf("fifth delete on close test succeeded.\n"); + + /* Test 6 ... */ + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + fnum1 = cli_nt_create_full(cli1, fname, 0, + SA_RIGHT_FILE_READ_DATA | SA_RIGHT_FILE_WRITE_DATA, + FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE | + NTCREATEX_SHARE_ACCESS_DELETE, + NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This should fail - only allowed on NT opens with DELETE access. */ + + if (cli_nt_delete_on_close(cli1, fnum1, True)) { + printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n"); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum1)) { + printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + printf("sixth delete on close test succeeded.\n"); + + /* Test 7 ... */ + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + fnum1 = cli_nt_create_full(cli1, fname, 0, + SA_RIGHT_FILE_READ_DATA | + SA_RIGHT_FILE_WRITE_DATA | + STD_RIGHT_DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, 0, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_nt_delete_on_close(cli1, fnum1, True)) { + printf("[7] setting delete_on_close on file failed !\n"); + correct = False; + goto fail; + } + + if (!cli_nt_delete_on_close(cli1, fnum1, False)) { + printf("[7] unsetting delete_on_close on file failed !\n"); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum1)) { + printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This next open should succeed - we reset the flag. */ + + fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 == -1) { + printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum1)) { + printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + printf("seventh delete on close test succeeded.\n"); + + /* Test 7 ... */ + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + if (!torture_open_connection(&cli2)) { + printf("[8] failed to open second connection.\n"); + correct = False; + goto fail; + } + + fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, + NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, + NTCREATEX_DISP_OPEN, 0, 0); + + if (fnum2 == -1) { + printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_nt_delete_on_close(cli1, fnum1, True)) { + printf("[8] setting delete_on_close on file failed !\n"); + correct = False; + goto fail; + } + + if (!cli_close(cli1, fnum1)) { + printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + if (!cli_close(cli2, fnum2)) { + printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2)); + correct = False; + goto fail; + } + + /* This should fail.. */ + fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 != -1) { + printf("[8] open of %s succeeded should have been deleted on close !\n", fname); + goto fail; + correct = False; + } else + printf("eighth delete on close test succeeded.\n"); + + /* This should fail - we need to set DELETE_ACCESS. */ + fnum1 = cli_nt_create_full(cli1, fname, 0,SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA, + FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); + + if (fnum1 != -1) { + printf("[9] open of %s succeeded should have failed!\n", fname); + correct = False; + goto fail; + } + + printf("ninth delete on close test succeeded.\n"); + + fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS, + FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); + if (fnum1 == -1) { + printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This should delete the file. */ + if (!cli_close(cli1, fnum1)) { + printf("[10] close failed (%s)\n", cli_errstr(cli1)); + correct = False; + goto fail; + } + + /* This should fail.. */ + fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE); + if (fnum1 != -1) { + printf("[10] open of %s succeeded should have been deleted on close !\n", fname); + goto fail; + correct = False; + } else + printf("tenth delete on close test succeeded.\n"); + printf("finished delete test\n"); + + fail: + /* FIXME: This will crash if we aborted before cli2 got + * intialized, because these functions don't handle + * uninitialized connections. */ + + cli_close(cli1, fnum1); + cli_close(cli1, fnum2); + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + if (!torture_close_connection(cli1)) { + correct = False; + } + if (!torture_close_connection(cli2)) { + correct = False; + } + return correct; +} + + +/* + print out server properties + */ +static BOOL run_properties(int dummy) +{ + struct cli_state *cli; + BOOL correct = True; + + printf("starting properties test\n"); + + ZERO_STRUCT(cli); + + if (!torture_open_connection(&cli)) { + return False; + } + + d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities); + + if (!torture_close_connection(cli)) { + correct = False; + } + + return correct; +} + + + +/* FIRST_DESIRED_ACCESS 0xf019f */ +#define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\ + SA_RIGHT_FILE_READ_EA| /* 0xf */ \ + SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \ + SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \ + STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\ + STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */ +/* SECOND_DESIRED_ACCESS 0xe0080 */ +#define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \ + STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\ + STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */ + +#if 0 +#define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \ + READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\ + SA_RIGHT_FILE_READ_DATA|\ + WRITE_OWNER_ACCESS /* */ +#endif + +/* + Test ntcreate calls made by xcopy + */ +static BOOL run_xcopy(int dummy) +{ + struct cli_state *cli1; + const char *fname = "\\test.txt"; + BOOL correct = True; + int fnum1, fnum2; + + printf("starting xcopy test\n"); + + if (!torture_open_connection(&cli1)) { + return False; + } + + fnum1 = cli_nt_create_full(cli1, fname, 0, + FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, + 0x4044, 0); + + if (fnum1 == -1) { + printf("First open failed - %s\n", cli_errstr(cli1)); + return False; + } + + fnum2 = cli_nt_create_full(cli1, fname, 0, + SECOND_DESIRED_ACCESS, 0, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, + 0x200000, 0); + if (fnum2 == -1) { + printf("second open failed - %s\n", cli_errstr(cli1)); + return False; + } + + if (!torture_close_connection(cli1)) { + correct = False; + } + + return correct; +} + +/* + Test rename on files open with share delete and no share delete. + */ +static BOOL run_rename(int dummy) +{ + struct cli_state *cli1; + const char *fname = "\\test.txt"; + const char *fname1 = "\\test1.txt"; + BOOL correct = True; + int fnum1; + + printf("starting rename test\n"); + + if (!torture_open_connection(&cli1)) { + return False; + } + + cli_unlink(cli1, fname); + cli_unlink(cli1, fname1); + fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("First open failed - %s\n", cli_errstr(cli1)); + return False; + } + + if (!cli_rename(cli1, fname, fname1)) { + printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1)); + } else { + printf("First rename succeeded - this should have failed !\n"); + correct = False; + } + + if (!cli_close(cli1, fnum1)) { + printf("close - 1 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + cli_unlink(cli1, fname); + cli_unlink(cli1, fname1); + fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL, +#if 0 + NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); +#else + NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); +#endif + + if (fnum1 == -1) { + printf("Second open failed - %s\n", cli_errstr(cli1)); + return False; + } + + if (!cli_rename(cli1, fname, fname1)) { + printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1)); + correct = False; + } else { + printf("Second rename succeeded\n"); + } + + if (!cli_close(cli1, fnum1)) { + printf("close - 2 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + cli_unlink(cli1, fname); + cli_unlink(cli1, fname1); + + fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("Third open failed - %s\n", cli_errstr(cli1)); + return False; + } + + +#if 0 + { + int fnum2; + + fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum2 == -1) { + printf("Fourth open failed - %s\n", cli_errstr(cli1)); + return False; + } + if (!cli_nt_delete_on_close(cli1, fnum2, True)) { + printf("[8] setting delete_on_close on file failed !\n"); + return False; + } + + if (!cli_close(cli1, fnum2)) { + printf("close - 4 failed (%s)\n", cli_errstr(cli1)); + return False; + } + } +#endif + + if (!cli_rename(cli1, fname, fname1)) { + printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1)); + correct = False; + } else { + printf("Third rename succeeded\n"); + } + + if (!cli_close(cli1, fnum1)) { + printf("close - 3 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + cli_unlink(cli1, fname); + cli_unlink(cli1, fname1); + + if (!torture_close_connection(cli1)) { + correct = False; + } + + return correct; +} + +static BOOL run_pipe_number(int dummy) +{ + struct cli_state *cli1; + const char *pipe_name = "\\SPOOLSS"; + int fnum; + int num_pipes = 0; + + printf("starting pipenumber test\n"); + if (!torture_open_connection(&cli1)) { + return False; + } + + while(1) { + fnum = cli_nt_create_full(cli1, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum == -1) { + printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1)); + break; + } + num_pipes++; + } + + printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name ); + torture_close_connection(cli1); + return True; +} + + +/* + Test open mode returns on read-only files. + */ + static BOOL run_opentest(int dummy) +{ + static struct cli_state *cli1; + static struct cli_state *cli2; + const char *fname = "\\readonly.file"; + int fnum1, fnum2; + char buf[20]; + size_t fsize; + BOOL correct = True; + char *tmp_path; + int failures = 0; + + printf("starting open test\n"); + + if (!torture_open_connection(&cli1)) { + return False; + } + + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + if (!cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0)) { + printf("cli_setatr failed (%s)\n", cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test1); + return False; + } + + fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test1); + return False; + } + + /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */ + fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL); + + if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess, + NT_STATUS_ACCESS_DENIED)) { + printf("correct error code ERRDOS/ERRnoaccess returned\n"); + } + + printf("finished open test 1\n"); +error_test1: + cli_close(cli1, fnum1); + + /* Now try not readonly and ensure ERRbadshare is returned. */ + + cli_setatr(cli1, fname, 0, 0); + + fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + /* This will fail - but the error should be ERRshare. */ + fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL); + + if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare, + NT_STATUS_SHARING_VIOLATION)) { + printf("correct error code ERRDOS/ERRbadshare returned\n"); + } + + if (!cli_close(cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + cli_unlink(cli1, fname); + + printf("finished open test 2\n"); + + /* Test truncate open disposition on file opened for read. */ + + fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + /* write 20 bytes. */ + + memset(buf, '\0', 20); + + if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) { + printf("write failed (%s)\n", cli_errstr(cli1)); + correct = False; + } + + if (!cli_close(cli1, fnum1)) { + printf("(3) close1 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + /* Ensure size == 20. */ + if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) { + printf("(3) getatr failed (%s)\n", cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test3); + return False; + } + + if (fsize != 20) { + printf("(3) file size != 20\n"); + CHECK_MAX_FAILURES(error_test3); + return False; + } + + /* Now test if we can truncate a file opened for readonly. */ + + fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE); + if (fnum1 == -1) { + printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test3); + return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(cli1)); + return False; + } + + /* Ensure size == 0. */ + if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) { + printf("(3) getatr failed (%s)\n", cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test3); + return False; + } + + if (fsize != 0) { + printf("(3) file size != 0\n"); + CHECK_MAX_FAILURES(error_test3); + return False; + } + printf("finished open test 3\n"); +error_test3: + cli_unlink(cli1, fname); + + + printf("testing ctemp\n"); + fnum1 = cli_ctemp(cli1, "\\", &tmp_path); + if (fnum1 == -1) { + printf("ctemp failed (%s)\n", cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test4); + return False; + } + printf("ctemp gave path %s\n", tmp_path); + if (!cli_close(cli1, fnum1)) { + printf("close of temp failed (%s)\n", cli_errstr(cli1)); + } + if (!cli_unlink(cli1, tmp_path)) { + printf("unlink of temp failed (%s)\n", cli_errstr(cli1)); + } +error_test4: + /* Test the non-io opens... */ + + if (!torture_open_connection(&cli2)) { + return False; + } + + cli_setatr(cli2, fname, 0, 0); + cli_unlink(cli2, fname); + + printf("TEST #1 testing 2 non-io opens (no delete)\n"); + + fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test10); + return False; + } + + fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); + if (fnum2 == -1) { + printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + CHECK_MAX_FAILURES(error_test10); + return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + if (!cli_close(cli2, fnum2)) { + printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + return False; + } + + printf("non-io open test #1 passed.\n"); +error_test10: + cli_unlink(cli1, fname); + + printf("TEST #2 testing 2 non-io opens (first with delete)\n"); + + fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test20); + return False; + } + + fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum2 == -1) { + printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + CHECK_MAX_FAILURES(error_test20); + return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + if (!cli_close(cli2, fnum2)) { + printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + printf("non-io open test #2 passed.\n"); +error_test20: + cli_unlink(cli1, fname); + + printf("TEST #3 testing 2 non-io opens (second with delete)\n"); + + fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test30); + return False; + } + + fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum2 == -1) { + printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + CHECK_MAX_FAILURES(error_test30); + return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + if (!cli_close(cli2, fnum2)) { + printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + return False; + } + + printf("non-io open test #3 passed.\n"); +error_test30: + cli_unlink(cli1, fname); + + printf("TEST #4 testing 2 non-io opens (both with delete)\n"); + + fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test40); + return False; + } + + fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum2 != -1) { + printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2)); + CHECK_MAX_FAILURES(error_test40); + return False; + } + + printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation"); + + if (!cli_close(cli1, fnum1)) { + printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + printf("non-io open test #4 passed.\n"); +error_test40: + cli_unlink(cli1, fname); + + printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n"); + + fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test50); + return False; + } + + fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum2 == -1) { + printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + CHECK_MAX_FAILURES(error_test50); + return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + if (!cli_close(cli2, fnum2)) { + printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + return False; + } + + printf("non-io open test #5 passed.\n"); +error_test50: + printf("TEST #6 testing 1 non-io open, one io open\n"); + + cli_unlink(cli1, fname); + + fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test60); + return False; + } + + fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum2 == -1) { + printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + CHECK_MAX_FAILURES(error_test60); + return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + if (!cli_close(cli2, fnum2)) { + printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); + return False; + } + + printf("non-io open test #6 passed.\n"); +error_test60: + printf("TEST #7 testing 1 non-io open, one io open with delete\n"); + + cli_unlink(cli1, fname); + + fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + CHECK_MAX_FAILURES(error_test70); + return False; + } + + fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum2 != -1) { + printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2)); + CHECK_MAX_FAILURES(error_test70); + return False; + } + + printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation"); + + if (!cli_close(cli1, fnum1)) { + printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); + return False; + } + + printf("non-io open test #7 passed.\n"); +error_test70: + cli_unlink(cli1, fname); + + if (!torture_close_connection(cli1)) { + correct = False; + } + if (!torture_close_connection(cli2)) { + correct = False; + } + + return correct; +} + + +static uint32 open_attrs_table[] = { + FILE_ATTRIBUTE_NORMAL, + FILE_ATTRIBUTE_ARCHIVE, + FILE_ATTRIBUTE_READONLY, + FILE_ATTRIBUTE_HIDDEN, + FILE_ATTRIBUTE_SYSTEM, + + FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, + FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, + FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, + FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, + FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, + FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, + + FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, + FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, + FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, + FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM, +}; + +struct trunc_open_results { + unsigned int num; + uint32 init_attr; + uint32 trunc_attr; + uint32 result_attr; +}; + +static struct trunc_open_results attr_results[] = { + { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE }, + { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE }, + { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY }, + { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE }, + { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE }, + { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY }, + { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, + { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, + { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN }, + { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, + { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, + { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }, + { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, + { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, + { 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN }, + { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, + { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, + { 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }, + { 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN }, + { 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM }, + { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, + { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN }, + { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN }, + { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, + { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM }, + { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM } +}; + +static BOOL run_openattrtest(int dummy) +{ + struct cli_state *cli1; + const char *fname = "\\openattr.file"; + int fnum1; + BOOL correct = True; + uint16 attr; + unsigned int i, j, k, l; + int failures = 0; + + printf("starting open attr test\n"); + + if (!torture_open_connection(&cli1)) { + return False; + } + + for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) { + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_WRITE_DATA, open_attrs_table[i], + NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + + if (fnum1 == -1) { + printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1)); + return False; + } + + if (!cli_close(cli1, fnum1)) { + printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1)); + return False; + } + + for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) { + fnum1 = cli_nt_create_full(cli1, fname, 0, + SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA, + open_attrs_table[j], + NTCREATEX_SHARE_ACCESS_NONE, + NTCREATEX_DISP_OVERWRITE, 0, 0); + + if (fnum1 == -1) { + for (l = 0; l < ARRAY_SIZE(attr_results); l++) { + if (attr_results[l].num == k) { + printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n", + k, open_attrs_table[i], + open_attrs_table[j], + fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1)); + correct = False; + CHECK_MAX_FAILURES(error_exit); + } + } + if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) { + printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n", + k, open_attrs_table[i], open_attrs_table[j], + cli_errstr(cli1)); + correct = False; + CHECK_MAX_FAILURES(error_exit); + } +#if 0 + printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]); +#endif + k++; + continue; + } + + if (!cli_close(cli1, fnum1)) { + printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1)); + return False; + } + + if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) { + printf("getatr(2) failed (%s)\n", cli_errstr(cli1)); + return False; + } + +#if 0 + printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n", + k, open_attrs_table[i], open_attrs_table[j], attr ); +#endif + + for (l = 0; l < ARRAY_SIZE(attr_results); l++) { + if (attr_results[l].num == k) { + if (attr != attr_results[l].result_attr || + open_attrs_table[i] != attr_results[l].init_attr || + open_attrs_table[j] != attr_results[l].trunc_attr) { + printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n", + k, open_attrs_table[i], + open_attrs_table[j], + (unsigned int)attr, + attr_results[l].result_attr); + correct = False; + CHECK_MAX_FAILURES(error_exit); + } + break; + } + } + k++; + } + } +error_exit: + cli_setatr(cli1, fname, 0, 0); + cli_unlink(cli1, fname); + + printf("open attr test %s.\n", correct ? "passed" : "failed"); + + if (!torture_close_connection(cli1)) { + correct = False; + } + return correct; +} + +static void list_fn(file_info *finfo, const char *name, void *state) +{ + +} + +/* + test directory listing speed + */ +static BOOL run_dirtest(int dummy) +{ + int i; + struct cli_state *cli; + int fnum; + double t1; + BOOL correct = True; + + printf("starting directory test\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("Creating %d random filenames\n", torture_numops); + + srandom(0); + for (i=0;i<torture_numops;i++) { + char *fname; + asprintf(&fname, "\\%x", (int)random()); + fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum == -1) { + fprintf(stderr,"Failed to open %s\n", fname); + return False; + } + cli_close(cli, fnum); + free(fname); + } + + t1 = end_timer(); + + printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL)); + printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL)); + printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL)); + + printf("dirtest core %g seconds\n", end_timer() - t1); + + srandom(0); + for (i=0;i<torture_numops;i++) { + char *fname; + asprintf(&fname, "\\%x", (int)random()); + cli_unlink(cli, fname); + free(fname); + } + + if (!torture_close_connection(cli)) { + correct = False; + } + + printf("finished dirtest\n"); + + return correct; +} + +static void del_fn(file_info *finfo, const char *mask, void *state) +{ + struct cli_state *pcli = (struct cli_state *)state; + char *fname; + asprintf(&fname, "\\LISTDIR\\%s", finfo->name); + + if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0) + return; + + if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) { + if (!cli_rmdir(pcli, fname)) + printf("del_fn: failed to rmdir %s, error=%s\n", fname, cli_errstr(pcli) ); + } else { + if (!cli_unlink(pcli, fname)) + printf("del_fn: failed to unlink %s, error=%s\n", fname, cli_errstr(pcli) ); + } + free(fname); +} + + +/* + sees what IOCTLs are supported + */ +BOOL torture_ioctl_test(int dummy) +{ + struct cli_state *cli; + uint16 device, function; + int fnum; + const char *fname = "\\ioctl.dat"; + DATA_BLOB blob; + NTSTATUS status; + struct smb_ioctl parms; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("ioctl_test"); + + printf("starting ioctl test\n"); + + cli_unlink(cli, fname); + + fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); + return False; + } + + parms.in.request = IOCTL_QUERY_JOB_INFO; + status = smb_raw_ioctl(cli->tree, mem_ctx, &parms); + printf("ioctl job info: %s\n", cli_errstr(cli)); + + for (device=0;device<0x100;device++) { + printf("testing device=0x%x\n", device); + for (function=0;function<0x100;function++) { + parms.in.request = (device << 16) | function; + status = smb_raw_ioctl(cli->tree, mem_ctx, &parms); + + if (NT_STATUS_IS_OK(status)) { + printf("ioctl device=0x%x function=0x%x OK : %d bytes\n", + device, function, blob.length); + data_blob_free(&parms.out.blob); + } + } + } + + if (!torture_close_connection(cli)) { + return False; + } + + return True; +} + + +/* + tries variants of chkpath + */ +BOOL torture_chkpath_test(int dummy) +{ + struct cli_state *cli; + int fnum; + BOOL ret; + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("starting chkpath test\n"); + + printf("Testing valid and invalid paths\n"); + + /* cleanup from an old run */ + cli_rmdir(cli, "\\chkpath.dir\\dir2"); + cli_unlink(cli, "\\chkpath.dir\\*"); + cli_rmdir(cli, "\\chkpath.dir"); + + if (!cli_mkdir(cli, "\\chkpath.dir")) { + printf("mkdir1 failed : %s\n", cli_errstr(cli)); + return False; + } + + if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) { + printf("mkdir2 failed : %s\n", cli_errstr(cli)); + return False; + } + + fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum == -1) { + printf("open1 failed (%s)\n", cli_errstr(cli)); + return False; + } + cli_close(cli, fnum); + + if (!cli_chkpath(cli, "\\chkpath.dir")) { + printf("chkpath1 failed: %s\n", cli_errstr(cli)); + ret = False; + } + + if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) { + printf("chkpath2 failed: %s\n", cli_errstr(cli)); + ret = False; + } + + if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) { + ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, + NT_STATUS_NOT_A_DIRECTORY); + } else { + printf("* chkpath on a file should fail\n"); + ret = False; + } + + if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) { + ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile, + NT_STATUS_OBJECT_NAME_NOT_FOUND); + } else { + printf("* chkpath on a non existent file should fail\n"); + ret = False; + } + + if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) { + ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, + NT_STATUS_OBJECT_PATH_NOT_FOUND); + } else { + printf("* chkpath on a non existent component should fail\n"); + ret = False; + } + + cli_rmdir(cli, "\\chkpath.dir\\dir2"); + cli_unlink(cli, "\\chkpath.dir\\*"); + cli_rmdir(cli, "\\chkpath.dir"); + + if (!torture_close_connection(cli)) { + return False; + } + + return ret; +} + + + + +static BOOL run_dirtest1(int dummy) +{ + int i; + struct cli_state *cli; + int fnum, num_seen; + BOOL correct = True; + + printf("starting directory test\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli); + cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli); + if (cli_deltree(cli, "\\LISTDIR") == -1) { + fprintf(stderr,"Failed to deltree %s, error=%s\n", "\\LISTDIR", cli_errstr(cli)); + return False; + } + if (!cli_mkdir(cli, "\\LISTDIR")) { + fprintf(stderr,"Failed to mkdir %s, error=%s\n", "\\LISTDIR", cli_errstr(cli)); + return False; + } + + printf("Creating %d files\n", torture_entries); + + /* Create torture_entries files and torture_entries directories. */ + for (i=0;i<torture_entries;i++) { + char *fname; + asprintf(&fname, "\\LISTDIR\\f%d", i); + fnum = cli_nt_create_full(cli, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); + if (fnum == -1) { + fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli)); + return False; + } + free(fname); + cli_close(cli, fnum); + } + for (i=0;i<torture_entries;i++) { + char *fname; + asprintf(&fname, "\\LISTDIR\\d%d", i); + if (!cli_mkdir(cli, fname)) { + fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli)); + return False; + } + free(fname); + } + + /* Now ensure that doing an old list sees both files and directories. */ + num_seen = cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); + printf("num_seen = %d\n", num_seen ); + /* We should see (torture_entries) each of files & directories + . and .. */ + if (num_seen != (2*torture_entries)+2) { + correct = False; + fprintf(stderr,"entry count mismatch, should be %d, was %d\n", + (2*torture_entries)+2, num_seen); + } + + + /* Ensure if we have the "must have" bits we only see the + * relevant entries. + */ + num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); + printf("num_seen = %d\n", num_seen ); + if (num_seen != torture_entries+2) { + correct = False; + fprintf(stderr,"entry count mismatch, should be %d, was %d\n", + torture_entries+2, num_seen); + } + + num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); + printf("num_seen = %d\n", num_seen ); + if (num_seen != torture_entries) { + correct = False; + fprintf(stderr,"entry count mismatch, should be %d, was %d\n", + torture_entries, num_seen); + } + + /* Delete everything. */ + cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli); + cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli); + cli_rmdir(cli, "\\LISTDIR"); + +#if 0 + printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL)); + printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL)); + printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL)); +#endif + + if (!torture_close_connection(cli)) { + correct = False; + } + + printf("finished dirtest1\n"); + + return correct; +} + + +/* + simple test harness for playing with deny modes + */ +static BOOL run_deny3test(int dummy) +{ + struct cli_state *cli1, *cli2; + int fnum1, fnum2; + const char *fname; + + printf("starting deny3 test\n"); + + printf("Testing simple deny modes\n"); + + if (!torture_open_connection(&cli1)) { + return False; + } + if (!torture_open_connection(&cli2)) { + return False; + } + + fname = "\\deny_dos1.dat"; + + cli_unlink(cli1, fname); + fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS); + fnum2 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS); + if (fnum1 != -1) cli_close(cli1, fnum1); + if (fnum2 != -1) cli_close(cli1, fnum2); + cli_unlink(cli1, fname); + printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); + + + fname = "\\deny_dos2.dat"; + + cli_unlink(cli1, fname); + fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS); + fnum2 = cli_open(cli2, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS); + if (fnum1 != -1) cli_close(cli1, fnum1); + if (fnum2 != -1) cli_close(cli2, fnum2); + cli_unlink(cli1, fname); + printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); + + + torture_close_connection(cli1); + torture_close_connection(cli2); + + return True; +} + + +static double create_procs(BOOL (*fn)(int), BOOL *result) +{ + int i, status; + volatile pid_t *child_status; + volatile BOOL *child_status_out; + int synccount; + int tries = 8; + + synccount = 0; + + child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs); + if (!child_status) { + printf("Failed to setup shared memory\n"); + return -1; + } + + child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs); + if (!child_status_out) { + printf("Failed to setup result status shared memory\n"); + return -1; + } + + for (i = 0; i < nprocs; i++) { + child_status[i] = 0; + child_status_out[i] = True; + } + + start_timer(); + + for (i=0;i<nprocs;i++) { + procnum = i; + if (fork() == 0) { + char *myname; + pid_t mypid = getpid(); + sys_srandom(((int)mypid) ^ ((int)time(NULL))); + + asprintf(&myname, "CLIENT%d", i); + lp_set_cmdline("netbios name", myname); + free(myname); + + while (1) { + if (torture_open_connection(¤t_cli)) break; + if (tries-- == 0) { + printf("pid %d failed to start\n", (int)getpid()); + _exit(1); + } + msleep(10); + } + + child_status[i] = getpid(); + + while (child_status[i] && end_timer() < 5) msleep(2); + + child_status_out[i] = fn(i); + _exit(0); + } + } + + do { + synccount = 0; + for (i=0;i<nprocs;i++) { + if (child_status[i]) synccount++; + } + if (synccount == nprocs) break; + msleep(10); + } while (end_timer() < 30); + + if (synccount != nprocs) { + printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount); + *result = False; + return end_timer(); + } + + /* start the client load */ + start_timer(); + + for (i=0;i<nprocs;i++) { + child_status[i] = 0; + } + + printf("%d clients started\n", nprocs); + + for (i=0;i<nprocs;i++) { + while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ; + } + + printf("\n"); + + for (i=0;i<nprocs;i++) { + if (!child_status_out[i]) { + *result = False; + } + } + return end_timer(); +} + +#define FLAG_MULTIPROC 1 + +static struct { + const char *name; + BOOL (*fn)(int); + unsigned flags; +} torture_ops[] = { + {"FDPASS", run_fdpasstest, 0}, + {"LOCK1", run_locktest1, 0}, + {"LOCK2", run_locktest2, 0}, + {"LOCK3", run_locktest3, 0}, + {"LOCK4", run_locktest4, 0}, + {"LOCK5", run_locktest5, 0}, + {"LOCK6", run_locktest6, 0}, + {"LOCK7", run_locktest7, 0}, + {"UNLINK", run_unlinktest, 0}, + {"ATTR", run_attrtest, 0}, + {"TRANS2", run_trans2test, 0}, + {"MAXFID", run_maxfidtest, FLAG_MULTIPROC}, + {"TORTURE",run_torture, FLAG_MULTIPROC}, + {"NEGNOWAIT", run_negprot_nowait, 0}, + {"NBENCH", run_nbench, 0}, + {"DIR", run_dirtest, 0}, + {"DIR1", run_dirtest1, 0}, + {"DENY1", torture_denytest1, 0}, + {"DENY2", torture_denytest2, 0}, + {"TCON", run_tcon_test, 0}, + {"TCONDEV", run_tcon_devtype_test, 0}, +#if 0 + {"DFSBASIC", torture_dfs_basic, 0}, + {"DFSRENAME", torture_dfs_rename, 0}, + {"DFSRANDOM", torture_dfs_random, 0}, +#endif + {"RW1", run_readwritetest, 0}, + {"RW2", run_readwritemulti, FLAG_MULTIPROC}, + {"OPEN", run_opentest, 0}, + {"DENY3", run_deny3test, 0}, +#if 1 + {"OPENATTR", run_openattrtest, 0}, +#endif + {"XCOPY", run_xcopy, 0}, + {"RENAME", run_rename, 0}, + {"DELETE", run_deletetest, 0}, + {"PROPERTIES", run_properties, 0}, + {"MANGLE", torture_mangle, 0}, + {"UTABLE", torture_utable, 0}, + {"CASETABLE", torture_casetable, 0}, + {"PIPE_NUMBER", run_pipe_number, 0}, + {"IOCTL", torture_ioctl_test, 0}, + {"CHKPATH", torture_chkpath_test, 0}, + {"RAW-QFSINFO", torture_raw_qfsinfo, 0}, + {"RAW-QFILEINFO", torture_raw_qfileinfo, 0}, + {"RAW-SFILEINFO", torture_raw_sfileinfo, 0}, + {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0}, + {"RAW-SEARCH", torture_raw_search, 0}, + {"RAW-CLOSE", torture_raw_close, 0}, + {"RAW-OPEN", torture_raw_open, 0}, + {"RAW-MKDIR", torture_raw_mkdir, 0}, + {"RAW-OPLOCK", torture_raw_oplock, 0}, + {"RAW-NOTIFY", torture_raw_notify, 0}, + {"RAW-MUX", torture_raw_mux, 0}, + {"RAW-IOCTL", torture_raw_ioctl, 0}, + {"RAW-CHKPATH", torture_raw_chkpath, 0}, + {"RAW-UNLINK", torture_raw_unlink, 0}, + {"RAW-READ", torture_raw_read, 0}, + {"RAW-WRITE", torture_raw_write, 0}, + {"RAW-LOCK", torture_raw_lock, 0}, + {"RAW-CONTEXT", torture_raw_context, 0}, + {"RAW-RENAME", torture_raw_rename, 0}, + {"RAW-SEEK", torture_raw_seek, 0}, + {"SCAN-TRANS2", torture_trans2_scan, 0}, + {"SCAN-NTTRANS", torture_nttrans_scan, 0}, + {"SCAN-ALIASES", torture_trans2_aliases, 0}, + {NULL, NULL, 0}}; + + + +/**************************************************************************** +run a specified test or "ALL" +****************************************************************************/ +static BOOL run_test(const char *name) +{ + BOOL ret = True; + int i; + BOOL matched = False; + + if (strequal(name,"ALL")) { + for (i=0;torture_ops[i].name;i++) { + if (!run_test(torture_ops[i].name)) { + ret = False; + } + } + return ret; + } + + for (i=0;torture_ops[i].name;i++) { + asprintf(&randomfname, "\\XX%x", + (unsigned)random()); + + if (gen_fnmatch(name, torture_ops[i].name) == 0) { + double t; + matched = True; + printf("Running %s\n", torture_ops[i].name); + if (torture_ops[i].flags & FLAG_MULTIPROC) { + BOOL result; + t = create_procs(torture_ops[i].fn, &result); + if (!result) { + ret = False; + printf("TEST %s FAILED!\n", torture_ops[i].name); + } + + } else { + start_timer(); + if (!torture_ops[i].fn(0)) { + ret = False; + printf("TEST %s FAILED!\n", torture_ops[i].name); + } + t = end_timer(); + } + printf("%s took %g secs\n\n", torture_ops[i].name, t); + } + } + + if (!matched) { + printf("Unknown torture operation '%s'\n", name); + } + + return ret; +} + + +static void usage(void) +{ + int i; + + printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n"); + + printf("\t-d debuglevel\n"); + printf("\t-U user%%pass\n"); + printf("\t-k use kerberos\n"); + printf("\t-N numprocs\n"); + printf("\t-n my_netbios_name\n"); + printf("\t-W workgroup\n"); + printf("\t-o num_operations\n"); + printf("\t-e num files(entries)\n"); + printf("\t-O socket_options\n"); + printf("\t-m maximum protocol\n"); + printf("\t-L use oplocks\n"); + printf("\t-c CLIENT.TXT specify client load file for NBENCH\n"); + printf("\t-A showall\n"); + printf("\t-p port\n"); + printf("\t-s seed\n"); + printf("\t-f max failures\n"); + printf("\t-b bypass I/O (NBENCH)\n"); + printf("\n\n"); + + printf("tests are:"); + for (i=0;torture_ops[i].name;i++) { + printf(" %s", torture_ops[i].name); + } + printf("\n"); + + printf("default test is ALL\n"); + + exit(1); +} + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc,char *argv[]) +{ + int opt, i; + char *p; + int gotuser = 0; + int gotpass = 0; + BOOL correct = True; + char *host, *share, *username, *password; + + setup_logging("smbtorture", DEBUG_STDOUT); + +#ifdef HAVE_SETBUFFER + setbuffer(stdout, NULL, 0); +#endif + + lp_load(dyn_CONFIGFILE,True,False,False); + load_interfaces(); + + if (argc < 2) { + usage(); + } + + for(p = argv[1]; *p; p++) + if(*p == '\\') + *p = '/'; + + if (strncmp(argv[1], "//", 2)) { + usage(); + } + + host = strdup(&argv[1][2]); + p = strchr_m(&host[2],'/'); + if (!p) { + usage(); + } + *p = 0; + share = strdup(p+1); + + if (getenv("LOGNAME")) { + username = strdup(getenv("LOGNAME")); + } + + lp_set_cmdline("torture:host", host); + lp_set_cmdline("torture:share", share); + lp_set_cmdline("torture:username", username); + lp_set_cmdline("torture:password", ""); + + argc--; + argv++; + + srandom(time(NULL)); + + while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:e:m:Ld:Ac:ks:f:bs:")) != EOF) { + switch (opt) { + case 'p': + lp_set_cmdline("smb ports", optarg); + break; + case 'W': + lp_set_cmdline("workgroup", optarg); + break; + case 'm': + lp_set_cmdline("protocol", optarg); + break; + case 'n': + lp_set_cmdline("netbios name", optarg); + break; + case 'd': + lp_set_cmdline("debug level", optarg); + setup_logging(NULL,True); + break; + case 'O': + lp_set_cmdline("socket options", optarg); + break; + case 's': + srandom(atoi(optarg)); + break; + case 'N': + nprocs = atoi(optarg); + break; + case 'o': + torture_numops = atoi(optarg); + break; + case 'e': + torture_entries = atoi(optarg); + break; + case 'L': + use_oplocks = True; + break; + case 'A': + torture_showall = True; + break; + case 'c': + client_txt = optarg; + break; + case 'k': +#ifdef HAVE_KRB5 + use_kerberos = True; +#else + d_printf("No kerberos support compiled in\n"); + exit(1); +#endif + break; + case 'U': + gotuser = 1; + username = strdup(optarg); + p = strchr_m(username,'%'); + if (p) { + *p = 0; + password = strdup(p+1); + gotpass = 1; + } + lp_set_cmdline("torture:username", username); + lp_set_cmdline("torture:password", password); + break; + case 'f': + torture_failures = atoi(optarg); + break; + case 'b': + bypass_io = True; + break; + + default: + printf("Unknown option %c (%d)\n", (char)opt, opt); + usage(); + } + } + + if(use_kerberos && !gotuser) gotpass = True; + + while (!gotpass) { + p = getpass("Password:"); + if (p) { + lp_set_cmdline("torture:password", p); + gotpass = 1; + } + } + + printf("host=%s share=%s user=%s myname=%s\n", + host, share, username, lp_netbios_name()); + + if (argc == optind) { + printf("You must specify a test to run, or 'ALL'\n"); + } else { + for (i=optind;i<argc;i++) { + if (!run_test(argv[i])) { + correct = False; + } + } + } + + if (correct) { + return(0); + } else { + return(1); + } +} diff --git a/source4/torture/torture_util.c b/source4/torture/torture_util.c new file mode 100644 index 0000000000..c8fb8a84b2 --- /dev/null +++ b/source4/torture/torture_util.c @@ -0,0 +1,306 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester utility functions + Copyright (C) Andrew Tridgell 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +static struct timeval tp1,tp2; + +void start_timer(void) +{ + gettimeofday(&tp1,NULL); +} + +double end_timer(void) +{ + gettimeofday(&tp2,NULL); + return((tp2.tv_sec - tp1.tv_sec) + + (tp2.tv_usec - tp1.tv_usec)*1.0e-6); +} + +/* + sometimes we need a fairly complex file to work with, so we can test + all possible attributes. +*/ +int create_complex_file(struct cli_state *cli, TALLOC_CTX *mem_ctx, const char *fname) +{ + int fnum; + char buf[7] = "abc"; + union smb_setfileinfo setfile; + union smb_fileinfo fileinfo; + time_t t = (time(NULL) & ~1); + NTSTATUS status; + + cli_unlink(cli, fname); + fnum = cli_nt_create_full(cli, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, + FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_DELETE| + NTCREATEX_SHARE_ACCESS_READ| + NTCREATEX_SHARE_ACCESS_WRITE, + NTCREATEX_DISP_OVERWRITE_IF, + 0, 0); + if (fnum == -1) return -1; + + cli_write(cli, fnum, 0, buf, 0, sizeof(buf)); + + /* setup some EAs */ + setfile.generic.level = RAW_SFILEINFO_EA_SET; + setfile.generic.file.fnum = fnum; + setfile.ea_set.in.ea.flags = 0; + setfile.ea_set.in.ea.name.s = "EAONE"; + setfile.ea_set.in.ea.value = data_blob_talloc(mem_ctx, "VALUE1", 6); + + status = smb_raw_setfileinfo(cli->tree, &setfile); + if (!NT_STATUS_IS_OK(status)) { + printf("Failed to setup EAs\n"); + } + + setfile.ea_set.in.ea.name.s = "SECONDEA"; + setfile.ea_set.in.ea.value = data_blob_talloc(mem_ctx, "ValueTwo", 8); + status = smb_raw_setfileinfo(cli->tree, &setfile); + if (!NT_STATUS_IS_OK(status)) { + printf("Failed to setup EAs\n"); + } + + /* make sure all the timestamps aren't the same */ + setfile.generic.level = RAW_SFILEINFO_SETATTRE; + setfile.generic.file.fnum = fnum; + + setfile.setattre.in.create_time = t + 60; + setfile.setattre.in.access_time = t + 120; + setfile.setattre.in.write_time = t + 180; + + status = smb_raw_setfileinfo(cli->tree, &setfile); + if (!NT_STATUS_IS_OK(status)) { + printf("Failed to setup file times - %s\n", nt_errstr(status)); + } + + /* make sure all the timestamps aren't the same */ + fileinfo.generic.level = RAW_FILEINFO_GETATTRE; + fileinfo.generic.in.fnum = fnum; + + status = smb_raw_fileinfo(cli->tree, mem_ctx, &fileinfo); + if (!NT_STATUS_IS_OK(status)) { + printf("Failed to query file times - %s\n", nt_errstr(status)); + } + + if (setfile.setattre.in.create_time != fileinfo.getattre.out.create_time) { + printf("create_time not setup correctly\n"); + } + if (setfile.setattre.in.access_time != fileinfo.getattre.out.access_time) { + printf("access_time not setup correctly\n"); + } + if (setfile.setattre.in.write_time != fileinfo.getattre.out.write_time) { + printf("write_time not setup correctly\n"); + } + + return fnum; +} + + + +/* return a pointer to a anonymous shared memory segment of size "size" + which will persist across fork() but will disappear when all processes + exit + + The memory is not zeroed + + This function uses system5 shared memory. It takes advantage of a property + that the memory is not destroyed if it is attached when the id is removed + */ +void *shm_setup(int size) +{ + int shmid; + void *ret; + + shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W); + if (shmid == -1) { + printf("can't get shared memory\n"); + exit(1); + } + ret = (void *)shmat(shmid, 0, 0); + if (!ret || ret == (void *)-1) { + printf("can't attach to shared memory\n"); + return NULL; + } + /* the following releases the ipc, but note that this process + and all its children will still have access to the memory, its + just that the shmid is no longer valid for other shm calls. This + means we don't leave behind lots of shm segments after we exit + + See Stevens "advanced programming in unix env" for details + */ + shmctl(shmid, IPC_RMID, 0); + + return ret; +} + + +/* + check that a wire string matches the flags specified + not 100% accurate, but close enough for testing +*/ +BOOL wire_bad_flags(WIRE_STRING *str, int flags) +{ + int len; + len = strlen(str->s); + if (flags & STR_TERMINATE) len++; + if ((flags & STR_UNICODE) || !getenv("CLI_FORCE_ASCII")) { + len *= 2; + } else if (flags & STR_TERMINATE_ASCII) { + len++; + } + if (str->private_length != len) { + printf("Expected wire_length %d but got %d for '%s'\n", + len, str->private_length, str->s); + return True; + } + return False; +} + +/* + return a talloced string representing a time_t for human consumption +*/ +const char *time_string(TALLOC_CTX *mem_ctx, time_t t) +{ + return talloc_strdup(mem_ctx, http_timestring(mem_ctx, t)); +} + +/* + check if 2 NTTIMEs are equal +*/ +BOOL nt_time_equal(NTTIME *t1, NTTIME *t2) +{ + return t1->low == t2->low && t1->high == t2->high; +} + +/* + dump a all_info QFILEINFO structure +*/ +void dump_all_info(TALLOC_CTX *mem_ctx, union smb_fileinfo *finfo) +{ + d_printf("\tcreate_time: %s\n", nt_time_string(mem_ctx, &finfo->all_info.out.create_time)); + d_printf("\taccess_time: %s\n", nt_time_string(mem_ctx, &finfo->all_info.out.access_time)); + d_printf("\twrite_time: %s\n", nt_time_string(mem_ctx, &finfo->all_info.out.write_time)); + d_printf("\tchange_time: %s\n", nt_time_string(mem_ctx, &finfo->all_info.out.change_time)); + d_printf("\tattrib: 0x%x\n", finfo->all_info.out.attrib); + d_printf("\talloc_size: %llu\n", (unsigned long long)finfo->all_info.out.alloc_size); + d_printf("\tsize: %llu\n", (unsigned long long)finfo->all_info.out.size); + d_printf("\tnlink: %u\n", finfo->all_info.out.nlink); + d_printf("\tdelete_pending: %u\n", finfo->all_info.out.delete_pending); + d_printf("\tdirectory: %u\n", finfo->all_info.out.directory); + d_printf("\tea_size: %u\n", finfo->all_info.out.ea_size); + d_printf("\tfname: '%s'\n", finfo->all_info.out.fname.s); +} + +/* + dump file infor by name +*/ +void torture_all_info(struct cli_tree *tree, const char *fname) +{ + TALLOC_CTX *mem_ctx = talloc_init(fname); + union smb_fileinfo finfo; + NTSTATUS status; + + finfo.generic.level = RAW_FILEINFO_ALL_INFO; + finfo.generic.in.fname = fname; + status = smb_raw_pathinfo(tree, mem_ctx, &finfo); + if (!NT_STATUS_IS_OK(status)) { + d_printf("%s - %s\n", fname, nt_errstr(status)); + return; + } + + d_printf("%s:\n", fname); + dump_all_info(mem_ctx, &finfo); + talloc_destroy(mem_ctx); +} + + +/* + split a UNC name into server and share names +*/ +BOOL split_unc_name(const char *unc, char **server, char **share) +{ + char *p = strdup(unc); + if (!p) return False; + all_string_sub(p, "\\", "/", 0); + if (strncmp(p, "//", 2) != 0) return False; + + (*server) = p+2; + p = strchr(*server, '/'); + if (!p) return False; + + *p = 0; + (*share) = p+1; + + return True; +} + +/* + split a USER%PASS pair into username and password +*/ +BOOL split_username(const char *pair, char **user, char **pass) +{ + char *p = strdup(pair); + if (!p) return False; + + (*user) = p; + + p = strchr(*user, '%'); + if (!p) return False; + + *p = 0; + (*pass) = p+1; + + return True; +} + +/* + set a attribute on a file +*/ +BOOL torture_set_file_attribute(struct cli_tree *tree, const char *fname, uint16 attrib) +{ + union smb_setfileinfo sfinfo; + NTSTATUS status; + + sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION; + sfinfo.generic.file.fname = fname; + + ZERO_STRUCT(sfinfo.basic_info.in); + sfinfo.basic_info.in.attrib = attrib; + status = smb_raw_setpathinfo(tree, &sfinfo); + return NT_STATUS_IS_OK(status); +} + + +/* + set a file descriptor as sparse +*/ +NTSTATUS torture_set_sparse(struct cli_tree *tree, int fnum) +{ + struct smb_ntioctl nt; + + nt.in.function = 0x900c4; + nt.in.fnum = fnum; + nt.in.fsctl = True; + nt.in.filter = 0; + + return smb_raw_ntioctl(tree, &nt); +} diff --git a/source4/torture/utable.c b/source4/torture/utable.c new file mode 100644 index 0000000000..38e381de9b --- /dev/null +++ b/source4/torture/utable.c @@ -0,0 +1,196 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester - unicode table dumper + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +BOOL torture_utable(int dummy) +{ + struct cli_state *cli; + fstring fname; + char *alt_name; + int fnum; + smb_ucs2_t c2; + int c, len, fd; + int chars_allowed=0, alt_allowed=0; + uint8 valid[0x10000]; + + printf("starting utable\n"); + + printf("Generating valid character table\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + memset(valid, 0, sizeof(valid)); + + cli_mkdir(cli, "\\utable"); + cli_unlink(cli, "\\utable\\*"); + + for (c=1; c < 0x10000; c++) { + char *p; + + SSVAL(&c2, 0, c); + fstrcpy(fname, "\\utable\\x"); + p = fname+strlen(fname); + len = convert_string(CH_UCS2, CH_UNIX, + &c2, 2, + p, sizeof(fname)-strlen(fname)); + p[len] = 0; + fstrcat(fname,"_a_long_extension"); + + fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, + DENY_NONE); + if (fnum == -1) continue; + + chars_allowed++; + + cli_qpathinfo_alt_name(cli, fname, &alt_name); + + if (strncmp(alt_name, "X_A_L", 5) != 0) { + alt_allowed++; + valid[c] = 1; + d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name); + } + + cli_close(cli, fnum); + cli_unlink(cli, fname); + + if (c % 100 == 0) { + printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed); + } + } + printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed); + + cli_rmdir(cli, "\\utable"); + + d_printf("%d chars allowed %d alt chars allowed\n", chars_allowed, alt_allowed); + + fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd == -1) { + d_printf("Failed to create valid.dat - %s", strerror(errno)); + return False; + } + write(fd, valid, 0x10000); + close(fd); + d_printf("wrote valid.dat\n"); + + return True; +} + + +static char *form_name(int c) +{ + static fstring fname; + smb_ucs2_t c2; + char *p; + int len; + + fstrcpy(fname, "\\utable\\"); + p = fname+strlen(fname); + SSVAL(&c2, 0, c); + + len = convert_string(CH_UCS2, CH_UNIX, + &c2, 2, + p, sizeof(fname)-strlen(fname)); + p[len] = 0; + return fname; +} + +BOOL torture_casetable(int dummy) +{ + static struct cli_state *cli; + char *fname; + int fnum; + int c, i; +#define MAX_EQUIVALENCE 8 + smb_ucs2_t equiv[0x10000][MAX_EQUIVALENCE]; + printf("starting casetable\n"); + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("Determining upper/lower case table\n"); + + memset(equiv, 0, sizeof(equiv)); + + cli_unlink(cli, "\\utable\\*"); + cli_rmdir(cli, "\\utable"); + if (!cli_mkdir(cli, "\\utable")) { + printf("Failed to create utable directory!\n"); + return False; + } + + for (c=1; c < 0x10000; c++) { + size_t size; + + if (c == '.' || c == '\\') continue; + + d_printf("%04x (%c)\n", c, isprint(c)?c:'.'); + + fname = form_name(c); + fnum = cli_nt_create_full(cli, fname, 0, + GENERIC_RIGHTS_FILE_ALL_ACCESS, + FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_NONE, + NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum == -1) { + printf("Failed to create file with char %04x\n", c); + continue; + } + + size = 0; + + if (!cli_qfileinfo(cli, fnum, NULL, &size, + NULL, NULL, NULL, NULL, NULL)) continue; + + if (size > 0) { + /* found a character equivalence! */ + int c2[MAX_EQUIVALENCE]; + + if (size/sizeof(int) >= MAX_EQUIVALENCE) { + printf("too many chars match?? size=%d c=0x%04x\n", + size, c); + cli_close(cli, fnum); + return False; + } + + cli_read(cli, fnum, (char *)c2, 0, size); + printf("%04x: ", c); + equiv[c][0] = c; + for (i=0; i<size/sizeof(int); i++) { + printf("%04x ", c2[i]); + equiv[c][i+1] = c2[i]; + } + printf("\n"); + fflush(stdout); + } + + cli_write(cli, fnum, 0, (char *)&c, size, sizeof(c)); + cli_close(cli, fnum); + } + + cli_unlink(cli, "\\utable\\*"); + cli_rmdir(cli, "\\utable"); + + return True; +} diff --git a/source4/torture/vfstest.c b/source4/torture/vfstest.c new file mode 100644 index 0000000000..6975d009a5 --- /dev/null +++ b/source4/torture/vfstest.c @@ -0,0 +1,591 @@ +/* + Unix SMB/CIFS implementation. + VFS module tester + + Copyright (C) Simo Sorce 2002 + Copyright (C) Eric Lorimer 2002 + Copyright (C) Jelmer Vernooij 2002 + + Most of this code was ripped off of rpcclient. + Copyright (C) Tim Potter 2000-2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "vfstest.h" + +/* List to hold groups of commands */ +static struct cmd_list { + struct cmd_list *prev, *next; + struct cmd_set *cmd_set; +} *cmd_list; + +/**************************************************************************** +handle completion of commands for readline +****************************************************************************/ +static char **completion_fn(char *text, int start, int end) +{ +#define MAX_COMPLETIONS 100 + char **matches; + int i, count=0; + struct cmd_list *commands = cmd_list; + + if (start) + return NULL; + + /* make sure we have a list of valid commands */ + if (!commands) + return NULL; + + matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS); + if (!matches) return NULL; + + matches[count++] = strdup(text); + if (!matches[0]) return NULL; + + while (commands && count < MAX_COMPLETIONS-1) + { + if (!commands->cmd_set) + break; + + for (i=0; commands->cmd_set[i].name; i++) + { + if ((strncmp(text, commands->cmd_set[i].name, strlen(text)) == 0) && + commands->cmd_set[i].fn) + { + matches[count] = strdup(commands->cmd_set[i].name); + if (!matches[count]) + return NULL; + count++; + } + } + + commands = commands->next; + + } + + if (count == 2) { + SAFE_FREE(matches[0]); + matches[0] = strdup(matches[1]); + } + matches[count] = NULL; + return matches; +} + +static char* next_command(char** cmdstr) +{ + static pstring command; + char *p; + + if (!cmdstr || !(*cmdstr)) + return NULL; + + p = strchr_m(*cmdstr, ';'); + if (p) + *p = '\0'; + pstrcpy(command, *cmdstr); + *cmdstr = p; + + return command; +} + +/* Load specified configuration file */ +static NTSTATUS cmd_conf(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, + int argc, char **argv) +{ + if (argc != 2) { + printf("Usage: %s <smb.conf>\n", argv[0]); + return NT_STATUS_OK; + } + + if (!lp_load(argv[1], False, True, False)) { + printf("Error loading \"%s\"\n", argv[1]); + return NT_STATUS_OK; + } + + printf("\"%s\" successfully loaded\n", argv[1]); + return NT_STATUS_OK; +} + +/* Display help on commands */ +static NTSTATUS cmd_help(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + struct cmd_list *tmp; + struct cmd_set *tmp_set; + + /* Usage */ + if (argc > 2) { + printf("Usage: %s [command]\n", argv[0]); + return NT_STATUS_OK; + } + + /* Help on one command */ + + if (argc == 2) { + for (tmp = cmd_list; tmp; tmp = tmp->next) { + + tmp_set = tmp->cmd_set; + + while(tmp_set->name) { + if (strequal(argv[1], tmp_set->name)) { + if (tmp_set->usage && + tmp_set->usage[0]) + printf("%s\n", tmp_set->usage); + else + printf("No help for %s\n", tmp_set->name); + + return NT_STATUS_OK; + } + + tmp_set++; + } + } + + printf("No such command: %s\n", argv[1]); + return NT_STATUS_OK; + } + + /* List all commands */ + + for (tmp = cmd_list; tmp; tmp = tmp->next) { + + tmp_set = tmp->cmd_set; + + while(tmp_set->name) { + + printf("%15s\t\t%s\n", tmp_set->name, + tmp_set->description ? tmp_set->description: + ""); + + tmp_set++; + } + } + + return NT_STATUS_OK; +} + +/* Change the debug level */ +static NTSTATUS cmd_debuglevel(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + if (argc > 2) { + printf("Usage: %s [debuglevel]\n", argv[0]); + return NT_STATUS_OK; + } + + if (argc == 2) { + DEBUGLEVEL = atoi(argv[1]); + } + + printf("debuglevel is %d\n", DEBUGLEVEL); + + return NT_STATUS_OK; +} + +static NTSTATUS cmd_freemem(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + /* Cleanup */ + talloc_destroy(mem_ctx); + mem_ctx = NULL; + vfs->data = NULL; + vfs->data_size = 0; + return NT_STATUS_OK; +} + +static NTSTATUS cmd_quit(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv) +{ + /* Cleanup */ + talloc_destroy(mem_ctx); + + exit(0); + return NT_STATUS_OK; /* NOTREACHED */ +} + +static struct cmd_set vfstest_commands[] = { + + { "GENERAL OPTIONS" }, + + { "conf", cmd_conf, "Load smb configuration file", "conf <smb.conf>" }, + { "help", cmd_help, "Get help on commands", "" }, + { "?", cmd_help, "Get help on commands", "" }, + { "debuglevel", cmd_debuglevel, "Set debug level", "" }, + { "freemem", cmd_freemem, "Free currently allocated buffers", "" }, + { "exit", cmd_quit, "Exit program", "" }, + { "quit", cmd_quit, "Exit program", "" }, + + { NULL } +}; + +static struct cmd_set separator_command[] = { + { "---------------", NULL, "----------------------" }, + { NULL } +}; + + +extern struct cmd_set vfs_commands[]; +static struct cmd_set *vfstest_command_list[] = { + vfstest_commands, + vfs_commands, + NULL +}; + +static void add_command_set(struct cmd_set *cmd_set) +{ + struct cmd_list *entry; + + if (!(entry = (struct cmd_list *)malloc(sizeof(struct cmd_list)))) { + DEBUG(0, ("out of memory\n")); + return; + } + + ZERO_STRUCTP(entry); + + entry->cmd_set = cmd_set; + DLIST_ADD(cmd_list, entry); +} + +static NTSTATUS do_cmd(struct vfs_state *vfs, struct cmd_set *cmd_entry, char *cmd) +{ + char *p = cmd, **argv = NULL; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + pstring buf; + TALLOC_CTX *mem_ctx = NULL; + int argc = 0, i; + + /* Count number of arguments first time through the loop then + allocate memory and strdup them. */ + + again: + while(next_token(&p, buf, " ", sizeof(buf))) { + if (argv) { + argv[argc] = strdup(buf); + } + + argc++; + } + + if (!argv) { + + /* Create argument list */ + + argv = (char **)malloc(sizeof(char *) * argc); + memset(argv, 0, sizeof(char *) * argc); + + if (!argv) { + fprintf(stderr, "out of memory\n"); + result = NT_STATUS_NO_MEMORY; + goto done; + } + + p = cmd; + argc = 0; + + goto again; + } + + /* Call the function */ + + if (cmd_entry->fn) { + + if (mem_ctx == NULL) { + /* Create mem_ctx */ + if (!(mem_ctx = talloc_init("do_cmd"))) { + DEBUG(0, ("talloc_init() failed\n")); + goto done; + } + } + + /* Run command */ + result = cmd_entry->fn(vfs, mem_ctx, argc, argv); + + } else { + fprintf (stderr, "Invalid command\n"); + goto done; + } + + done: + + /* Cleanup */ + + if (argv) { + for (i = 0; i < argc; i++) + SAFE_FREE(argv[i]); + + SAFE_FREE(argv); + } + + return result; +} + +/* Process a command entered at the prompt or as part of -c */ +static NTSTATUS process_cmd(struct vfs_state *vfs, char *cmd) +{ + struct cmd_list *temp_list; + BOOL found = False; + pstring buf; + char *p = cmd; + NTSTATUS result = NT_STATUS_OK; + int len = 0; + + if (cmd[strlen(cmd) - 1] == '\n') + cmd[strlen(cmd) - 1] = '\0'; + + if (!next_token(&p, buf, " ", sizeof(buf))) { + return NT_STATUS_OK; + } + + /* strip the trainly \n if it exsists */ + len = strlen(buf); + if (buf[len-1] == '\n') + buf[len-1] = '\0'; + + /* Search for matching commands */ + + for (temp_list = cmd_list; temp_list; temp_list = temp_list->next) { + struct cmd_set *temp_set = temp_list->cmd_set; + + while(temp_set->name) { + if (strequal(buf, temp_set->name)) { + found = True; + result = do_cmd(vfs, temp_set, cmd); + + goto done; + } + temp_set++; + } + } + + done: + if (!found && buf[0]) { + printf("command not found: %s\n", buf); + return NT_STATUS_OK; + } + + if (!NT_STATUS_IS_OK(result)) { + printf("result was %s\n", nt_errstr(result)); + } + + return result; +} + +static void process_file(struct vfs_state *pvfs, char *filename) { + FILE *file; + char command[3 * PATH_MAX]; + + if (*filename == '-') { + file = stdin; + } else { + file = fopen(filename, "r"); + if (file == NULL) { + printf("vfstest: error reading file (%s)!", filename); + printf("errno n.%d: %s", errno, strerror(errno)); + exit(-1); + } + } + + while (fgets(command, 3 * PATH_MAX, file) != NULL) { + process_cmd(pvfs, command); + } +} + +void exit_server(const char *reason) +{ + DEBUG(3,("Server exit (%s)\n", (reason ? reason : ""))); + exit(0); +} + +static int server_fd = -1; +int last_message = -1; + +int smbd_server_fd(void) +{ + return server_fd; +} + +/**************************************************************************** + Reload the services file. +**************************************************************************/ + +BOOL reload_services(BOOL test) +{ + BOOL ret; + + if (lp_loaded()) { + pstring fname; + pstrcpy(fname,lp_configfile()); + if (file_exist(fname, NULL) && + !strcsequal(fname, dyn_CONFIGFILE)) { + pstrcpy(dyn_CONFIGFILE, fname); + test = False; + } + } + + reopen_logs(); + + if (test && !lp_file_list_changed()) + return(True); + + lp_killunused(conn_snum_used); + + ret = lp_load(dyn_CONFIGFILE, False, False, True); + + load_printers(); + + /* perhaps the config filename is now set */ + if (!test) + reload_services(True); + + reopen_logs(); + + load_interfaces(); + + if (smbd_server_fd() != -1) { + set_socket_options(smbd_server_fd(),"SO_KEEPALIVE"); + set_socket_options(smbd_server_fd(), lp_socket_options()); + } + + mangle_reset_cache(); + reset_stat_cache(); + + /* this forces service parameters to be flushed */ + set_current_service(NULL,True); + + return (ret); +} + +/* Main function */ + +int main(int argc, char *argv[]) +{ + BOOL interactive = True; + int opt; + static char *cmdstr = ""; + static char *opt_logfile=NULL; + static int opt_debuglevel; + pstring logfile; + struct cmd_set **cmd_set; + extern BOOL AllowDebugChange; + static struct vfs_state vfs; + int i; + static const char *filename = ""; + + /* make sure the vars that get altered (4th field) are in + a fixed location or certain compilers complain */ + poptContext pc; + struct poptOption long_options[] = { + POPT_AUTOHELP + {"file", 'f', POPT_ARG_STRING, &filename, 0, }, + {"command", 'c', POPT_ARG_STRING, &cmdstr, 0, "Execute specified list of commands" }, + {"logfile", 'l', POPT_ARG_STRING, &opt_logfile, 'l', "Write output to specified logfile" }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, + { 0, 0, 0, 0} + }; + + + setlinebuf(stdout); + + DEBUGLEVEL = 1; + AllowDebugChange = False; + + pc = poptGetContext("vfstest", argc, (const char **) argv, + long_options, 0); + + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'l': + slprintf(logfile, sizeof(logfile) - 1, "%s.client", + opt_logfile); + lp_set_logfile(logfile); + interactive = False; + break; + + case 'd': + DEBUGLEVEL = opt_debuglevel; + break; + } + } + + + poptFreeContext(pc); + + /* TODO: check output */ + reload_services(False); + + /* the following functions are part of the Samba debugging + facilities. See lib/debug.c */ + setup_logging("vfstest", interactive); + if (!interactive) + reopen_logs(); + + /* Load command lists */ + + cmd_set = vfstest_command_list; + + while(*cmd_set) { + add_command_set(*cmd_set); + add_command_set(separator_command); + cmd_set++; + } + + /* some basic initialization stuff */ + conn_init(); + vfs.conn = conn_new(); + vfs.conn->user = "vfstest"; + for (i=0; i < 1024; i++) + vfs.files[i] = NULL; + + /* some advanced initiliazation stuff */ + smbd_vfs_init(vfs.conn); + + /* Do we have a file input? */ + if (filename[0]) { + process_file(&vfs, filename); + return 0; + } + + /* Do anything specified with -c */ + if (cmdstr[0]) { + char *cmd; + char *p = cmdstr; + + while((cmd=next_command(&p)) != NULL) { + process_cmd(&vfs, cmd); + } + + return 0; + } + + /* Loop around accepting commands */ + + while(1) { + pstring prompt; + char *line; + + slprintf(prompt, sizeof(prompt) - 1, "vfstest $> "); + + line = smb_readline(prompt, NULL, completion_fn); + + if (line == NULL) + break; + + if (line[0] != '\n') + process_cmd(&vfs, line); + } + + free(vfs.conn); + return 0; +} diff --git a/source4/torture/vfstest.h b/source4/torture/vfstest.h new file mode 100644 index 0000000000..5910c5ce37 --- /dev/null +++ b/source4/torture/vfstest.h @@ -0,0 +1,45 @@ +/* + Unix SMB/CIFS implementation. + VFS module tester + + Copyright (C) Simo Sorce 2002 + Copyright (C) Eric Lorimer 2002 + + Most of this code was ripped off of rpcclient. + Copyright (C) Tim Potter 2000-2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +struct func_entry { + char *name; + int (*fn)(struct connection_struct *conn, const char *path); +}; + +struct vfs_state { + struct connection_struct *conn; + struct files_struct *files[1024]; + DIR *currentdir; + void *data; + size_t data_size; +}; + +struct cmd_set { + const char *name; + NTSTATUS (*fn)(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, + char **argv); + const char *description; + const char *usage; +}; |