diff options
Diffstat (limited to 'source4/torture')
-rw-r--r-- | source4/torture/config.mk | 98 | ||||
-rw-r--r-- | source4/torture/gentest_smb2.c | 1952 | ||||
-rw-r--r-- | source4/torture/ldap/cldap.c | 97 | ||||
-rw-r--r-- | source4/torture/local/config.mk | 60 | ||||
-rw-r--r-- | source4/torture/nbt/dgram.c | 404 | ||||
-rw-r--r-- | source4/torture/raw/raw.c | 2 | ||||
-rw-r--r-- | source4/torture/raw/tconrate.c | 201 | ||||
-rw-r--r-- | source4/torture/rpc/dssync.c | 7 | ||||
-rw-r--r-- | source4/torture/rpc/schannel.c | 64 | ||||
-rw-r--r-- | source4/torture/smb2/config.mk | 6 | ||||
-rw-r--r-- | source4/torture/smb2/oplocks.c | 2 | ||||
-rw-r--r-- | source4/torture/smb2/util.c | 42 | ||||
-rw-r--r-- | source4/torture/winbind/config.mk | 6 |
13 files changed, 2728 insertions, 213 deletions
diff --git a/source4/torture/config.mk b/source4/torture/config.mk index ee9f8b71b5..2857b99582 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -2,15 +2,13 @@ PRIVATE_DEPENDENCIES = LIBCLI_RAW LIBPYTHON smbcalls PROVISION PUBLIC_DEPENDENCIES = POPT_CREDENTIALS -TORTURE_UTIL_OBJ_FILES = $(addprefix torture/, util_smb.o) +TORTURE_UTIL_OBJ_FILES = $(addprefix $(torturesrcdir)/, util_smb.o) ################################# # Start SUBSYSTEM TORTURE_BASIC [MODULE::TORTURE_BASIC] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_base_init -PRIVATE_PROTO_HEADER = \ - basic/proto.h PRIVATE_DEPENDENCIES = \ LIBCLI_SMB POPT_CREDENTIALS \ TORTURE_UTIL LIBCLI_RAW \ @@ -18,7 +16,7 @@ PRIVATE_DEPENDENCIES = \ # End SUBSYSTEM TORTURE_BASIC ################################# -TORTURE_BASIC_OBJ_FILES = $(addprefix torture/basic/, \ +TORTURE_BASIC_OBJ_FILES = $(addprefix $(torturesrcdir)/basic/, \ base.o \ misc.o \ scanner.o \ @@ -38,21 +36,20 @@ TORTURE_BASIC_OBJ_FILES = $(addprefix torture/basic/, \ attr.o \ properties.o) +$(eval $(call proto_header_template,$(torturesrcdir)/basic/proto.h,$(TORTURE_BASIC_OBJ_FILES:.o=.c))) ################################# # Start SUBSYSTEM TORTURE_RAW [MODULE::TORTURE_RAW] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_raw_init -PRIVATE_PROTO_HEADER = \ - raw/proto.h PRIVATE_DEPENDENCIES = \ LIBCLI_SMB LIBCLI_LSA LIBCLI_SMB_COMPOSITE \ POPT_CREDENTIALS TORTURE_UTIL # End SUBSYSTEM TORTURE_RAW ################################# -TORTURE_RAW_OBJ_FILES = $(addprefix torture/raw/, \ +TORTURE_RAW_OBJ_FILES = $(addprefix $(torturesrcdir)/raw/, \ qfsinfo.o \ qfileinfo.o \ setfileinfo.o \ @@ -73,6 +70,7 @@ TORTURE_RAW_OBJ_FILES = $(addprefix torture/raw/, \ pingpong.o \ lockbench.o \ lookuprate.o \ + tconrate.o \ openbench.o \ rename.o \ eas.o \ @@ -85,22 +83,22 @@ TORTURE_RAW_OBJ_FILES = $(addprefix torture/raw/, \ raw.o \ offline.o) +$(eval $(call proto_header_template,$(torturesrcdir)/raw/proto.h,$(TORTURE_RAW_OBJ_FILES:.o=.c))) mkinclude smb2/config.mk mkinclude winbind/config.mk [SUBSYSTEM::TORTURE_NDR] -PRIVATE_PROTO_HEADER = ndr/proto.h -TORTURE_NDR_OBJ_FILES = $(addprefix torture/ndr/, ndr.o winreg.o atsvc.o lsa.o epmap.o dfs.o netlogon.o drsuapi.o spoolss.o samr.o) +TORTURE_NDR_OBJ_FILES = $(addprefix $(torturesrcdir)/ndr/, ndr.o winreg.o atsvc.o lsa.o epmap.o dfs.o netlogon.o drsuapi.o spoolss.o samr.o) + +$(eval $(call proto_header_template,$(torturesrcdir)/ndr/proto.h,$(TORTURE_NDR_OBJ_FILES:.o=.c))) [MODULE::torture_rpc] # TORTURE_NET and TORTURE_NBT use functions from torture_rpc... #OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbtorture INIT_FUNCTION = torture_rpc_init -PRIVATE_PROTO_HEADER = \ - rpc/proto.h PRIVATE_DEPENDENCIES = \ NDR_TABLE RPC_NDR_UNIXINFO dcerpc_samr RPC_NDR_WINREG RPC_NDR_INITSHUTDOWN \ RPC_NDR_OXIDRESOLVER RPC_NDR_EVENTLOG RPC_NDR_ECHO RPC_NDR_SVCCTL \ @@ -111,7 +109,7 @@ PRIVATE_DEPENDENCIES = \ LIBCLI_AUTH POPT_CREDENTIALS TORTURE_LDAP TORTURE_UTIL TORTURE_RAP \ dcerpc_server service process_model ntvfs SERVICE_SMB -torture_rpc_OBJ_FILES = $(addprefix torture/rpc/, \ +torture_rpc_OBJ_FILES = $(addprefix $(torturesrcdir)/rpc/, \ join.o lsa.o lsa_lookup.o session_key.o echo.o dfs.o drsuapi.o \ drsuapi_cracknames.o dssync.o spoolss.o spoolss_notify.o spoolss_win.o \ unixinfo.o samr.o samr_accessmask.o wkssvc.o srvsvc.o svcctl.o atsvc.o \ @@ -120,32 +118,34 @@ torture_rpc_OBJ_FILES = $(addprefix torture/rpc/, \ samsync.o bind.o dssetup.o alter_context.o bench.o samba3rpc.o rpc.o async_bind.o \ handles.o frsapi.o) +$(eval $(call proto_header_template,$(torturesrcdir)/rpc/proto.h,$(torture_rpc_OBJ_FILES:.o=.c))) + ################################# # Start SUBSYSTEM TORTURE_RAP [MODULE::TORTURE_RAP] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_rap_init -PRIVATE_PROTO_HEADER = \ - rap/proto.h PRIVATE_DEPENDENCIES = TORTURE_UTIL LIBCLI_SMB # End SUBSYSTEM TORTURE_RAP ################################# -TORTURE_RAP_OBJ_FILES = torture/rap/rap.o +TORTURE_RAP_OBJ_FILES = $(torturesrcdir)/rap/rap.o + +$(eval $(call proto_header_template,$(torturesrcdir)/rap/proto.h,$(TORTURE_RAP_OBJ_FILES:.o=.c))) ################################# # Start SUBSYSTEM TORTURE_AUTH [MODULE::TORTURE_AUTH] SUBSYSTEM = smbtorture -PRIVATE_PROTO_HEADER = \ - auth/proto.h PRIVATE_DEPENDENCIES = \ LIBCLI_SMB gensec auth KERBEROS \ POPT_CREDENTIALS SMBPASSWD # End SUBSYSTEM TORTURE_AUTH ################################# -TORTURE_AUTH_OBJ_FILES = $(addprefix torture/auth/, ntlmssp.o pac.o) +TORTURE_AUTH_OBJ_FILES = $(addprefix $(torturesrcdir)/auth/, ntlmssp.o pac.o) + +$(eval $(call proto_header_template,$(torturesrcdir)/auth/proto.h,$(TORTURE_AUTH_OBJ_FILES:.o=.c))) mkinclude local/config.mk @@ -155,12 +155,12 @@ mkinclude local/config.mk SUBSYSTEM = smbtorture INIT_FUNCTION = torture_nbench_init PRIVATE_DEPENDENCIES = TORTURE_UTIL -PRIVATE_PROTO_HEADER = \ - nbench/proto.h # End MODULE TORTURE_NBENCH ################################# -TORTURE_NBENCH_OBJ_FILES = $(addprefix torture/nbench/, nbio.o nbench.o) +TORTURE_NBENCH_OBJ_FILES = $(addprefix $(torturesrcdir)/nbench/, nbio.o nbench.o) + +$(eval $(call proto_header_template,$(torturesrcdir)/nbench/proto.h,$(TORTURE_NBENCH_OBJ_FILES:.o=.c))) ################################# # Start MODULE TORTURE_UNIX @@ -168,51 +168,47 @@ TORTURE_NBENCH_OBJ_FILES = $(addprefix torture/nbench/, nbio.o nbench.o) SUBSYSTEM = smbtorture INIT_FUNCTION = torture_unix_init PRIVATE_DEPENDENCIES = TORTURE_UTIL -PRIVATE_PROTO_HEADER = \ - unix/proto.h # End MODULE TORTURE_UNIX ################################# -TORTURE_UNIX_OBJ_FILES = $(addprefix torture/unix/, unix.o whoami.o unix_info2.o) +TORTURE_UNIX_OBJ_FILES = $(addprefix $(torturesrcdir)/unix/, unix.o whoami.o unix_info2.o) + +$(eval $(call proto_header_template,$(torturesrcdir)/unix/proto.h,$(TORTURE_UNIX_OBJ_FILES:.o=.c))) ################################# # Start SUBSYSTEM TORTURE_LDAP [MODULE::TORTURE_LDAP] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_ldap_init -PRIVATE_PROTO_HEADER = \ - ldap/proto.h PRIVATE_DEPENDENCIES = \ LIBCLI_LDAP LIBCLI_CLDAP SAMDB POPT_CREDENTIALS # End SUBSYSTEM TORTURE_LDAP ################################# -TORTURE_LDAP_OBJ_FILES = $(addprefix torture/ldap/, common.o basic.o schema.o uptodatevector.o cldap.o cldapbench.o) +TORTURE_LDAP_OBJ_FILES = $(addprefix $(torturesrcdir)/ldap/, common.o basic.o schema.o uptodatevector.o cldap.o cldapbench.o) +$(eval $(call proto_header_template,$(torturesrcdir)/ldap/proto.h,$(TORTURE_LDAP_OBJ_FILES:.o=.c))) ################################# # Start SUBSYSTEM TORTURE_NBT [MODULE::TORTURE_NBT] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_nbt_init -PRIVATE_PROTO_HEADER = \ - nbt/proto.h PRIVATE_DEPENDENCIES = \ LIBCLI_SMB LIBCLI_NBT LIBCLI_DGRAM LIBCLI_WREPL torture_rpc # End SUBSYSTEM TORTURE_NBT ################################# -TORTURE_NBT_OBJ_FILES = $(addprefix torture/nbt/, query.o register.o \ +TORTURE_NBT_OBJ_FILES = $(addprefix $(torturesrcdir)/nbt/, query.o register.o \ wins.o winsbench.o winsreplication.o dgram.o nbt.o) +$(eval $(call proto_header_template,$(torturesrcdir)/nbt/proto.h,$(TORTURE_NBT_OBJ_FILES:.o=.c))) ################################# # Start SUBSYSTEM TORTURE_NET [MODULE::TORTURE_NET] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_net_init -PRIVATE_PROTO_HEADER = \ - libnet/proto.h PRIVATE_DEPENDENCIES = \ LIBSAMBA-NET \ POPT_CREDENTIALS \ @@ -220,11 +216,12 @@ PRIVATE_DEPENDENCIES = \ # End SUBSYSTEM TORTURE_NET ################################# -TORTURE_NET_OBJ_FILES = $(addprefix torture/libnet/, libnet.o \ +TORTURE_NET_OBJ_FILES = $(addprefix $(torturesrcdir)/libnet/, libnet.o \ utils.o userinfo.o userman.o groupinfo.o groupman.o \ domain.o libnet_lookup.o libnet_user.o libnet_group.o \ libnet_share.o libnet_rpc.o libnet_domain.o libnet_BecomeDC.o) +$(eval $(call proto_header_template,$(torturesrcdir)/libnet/proto.h,$(TORTURE_NET_OBJ_FILES:.o=.c))) ################################# # Start BINARY smbtorture @@ -241,10 +238,10 @@ PRIVATE_DEPENDENCIES = \ # End BINARY smbtorture ################################# -smbtorture_OBJ_FILES = torture/smbtorture.o torture/torture.o +smbtorture_OBJ_FILES = $(torturesrcdir)/smbtorture.o $(torturesrcdir)/torture.o -PUBLIC_HEADERS += torture/smbtorture.h -MANPAGES += torture/man/smbtorture.1 +PUBLIC_HEADERS += $(torturesrcdir)/smbtorture.h +MANPAGES += $(torturesrcdir)/man/smbtorture.1 ################################# # Start BINARY gentest @@ -261,9 +258,26 @@ PRIVATE_DEPENDENCIES = \ # End BINARY gentest ################################# -gentest_OBJ_FILES = torture/gentest.o +gentest_OBJ_FILES = $(torturesrcdir)/gentest.o + +MANPAGES += $(torturesrcdir)/man/gentest.1 + +################################# +# Start BINARY gentest_smb2 +[BINARY::gentest_smb2] +INSTALLDIR = BINDIR +PRIVATE_DEPENDENCIES = \ + LIBSAMBA-HOSTCONFIG \ + LIBSAMBA-UTIL \ + LIBPOPT \ + POPT_SAMBA \ + POPT_CREDENTIALS \ + LIBCLI_SMB \ + LIBCLI_RAW +# End BINARY gentest_smb2 +################################# -MANPAGES += torture/man/gentest.1 +gentest_smb2_OBJ_FILES = $(torturesrcdir)/gentest_smb2.o ################################# # Start BINARY masktest @@ -279,9 +293,9 @@ PRIVATE_DEPENDENCIES = \ # End BINARY masktest ################################# -masktest_OBJ_FILES = torture/masktest.o +masktest_OBJ_FILES = $(torturesrcdir)/masktest.o -MANPAGES += torture/man/masktest.1 +MANPAGES += $(torturesrcdir)/man/masktest.1 ################################# # Start BINARY locktest @@ -297,9 +311,9 @@ PRIVATE_DEPENDENCIES = \ # End BINARY locktest ################################# -locktest_OBJ_FILES = torture/locktest.o +locktest_OBJ_FILES = $(torturesrcdir)/locktest.o -MANPAGES += torture/man/locktest.1 +MANPAGES += $(torturesrcdir)/man/locktest.1 GCOV=0 diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c new file mode 100644 index 0000000000..9c4be90b3c --- /dev/null +++ b/source4/torture/gentest_smb2.c @@ -0,0 +1,1952 @@ +/* + Unix SMB/CIFS implementation. + + generic testing tool - version with SMB2 support + + Copyright (C) Andrew Tridgell 2003-2008 + + 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 3 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, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "lib/cmdline/popt_common.h" +#include "lib/events/events.h" +#include "system/time.h" +#include "system/filesys.h" +#include "libcli/raw/request.h" +#include "libcli/libcli.h" +#include "libcli/raw/libcliraw.h" +#include "libcli/smb2/smb2.h" +#include "libcli/smb2/smb2_calls.h" +#include "librpc/gen_ndr/security.h" +#include "auth/credentials/credentials.h" +#include "libcli/resolve/resolve.h" +#include "auth/gensec/gensec.h" +#include "param/param.h" +#include "dynconfig.h" + +#define NSERVERS 2 +#define NINSTANCES 2 + +/* global options */ +static struct gentest_options { + int showall; + int analyze; + int analyze_always; + int analyze_continuous; + uint_t max_open_handles; + uint_t seed; + uint_t numops; + int use_oplocks; + char **ignore_patterns; + const char *seeds_file; + int use_preset_seeds; + int fast_reconnect; +} options; + +/* mapping between open handles on the server and local handles */ +static struct { + bool active; + uint_t instance; + struct smb2_handle server_handle[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 smb2_tree *tree[NINSTANCES]; + char *server_name; + char *share_name; + struct cli_credentials *credentials; +} 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; + struct smb2_handle server_handle; + uint16_t handle; + uint8_t level; + bool do_close; +} oplocks[NSERVERS][NINSTANCES]; + +/* change notify reply info */ +static struct { + int notify_count; + NTSTATUS status; + union 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; + +static struct smb2_handle bad_smb2_handle; + + +#define BAD_HANDLE 0xFFFE + +static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private); +static void idle_func(struct smb2_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++) { + NTSTATUS status = smb2_util_close(servers[i].tree[open_handles[h].instance], + open_handles[h].server_handle[i]); + if (NT_STATUS_IS_ERR(status)) { + return false; + } + open_handles[h].active = false; + } + } + + return true; +} + + + + +/***************************************************** +connect to the servers +*******************************************************/ +static bool connect_servers(struct event_context *ev, + struct loadparm_context *lp_ctx) +{ + int i, j; + + if (options.fast_reconnect && servers[0].tree[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].tree[j]) { + smb2_tdis(servers[i].tree[j]); + talloc_free(servers[i].tree[j]); + servers[i].tree[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].credentials->username, j); + + cli_credentials_set_workstation(servers[i].credentials, + "gentest", CRED_SPECIFIED); + + status = smb2_connect(NULL, servers[i].server_name, + servers[i].share_name, + lp_resolve_context(lp_ctx), + servers[i].credentials, + &servers[i].tree[j], + ev); + 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; + } + +// smb2_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL); + smb2_transport_idle_handler(servers[i].tree[j]->session->transport, idle_func, 50000, NULL); + } + } + + return true; +} + +/* + work out the time skew between the servers - be conservative +*/ +static uint_t time_skew(void) +{ + uint_t ret; + ret = labs(servers[0].tree[0]->session->transport->negotiate.system_time - + servers[1].tree[0]->session->transport->negotiate.system_time); + return ret + 300; +} + + +static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_handle *h2) +{ + return memcmp(h1, h2, sizeof(struct smb2_handle)) == 0; +} + +/* + turn a server handle into a local handle +*/ +static uint_t fnum_to_handle(int server, int instance, struct smb2_handle server_handle) +{ + uint_t i; + for (i=0;i<options.max_open_handles;i++) { + if (!open_handles[i].active || + instance != open_handles[i].instance) continue; + if (smb2_handle_equal(&open_handles[i].server_handle[server], &server_handle)) { + return i; + } + } + printf("Invalid server handle in fnum_to_handle on server %d instance %d\n", + server, instance); + return BAD_HANDLE; +} + +/* + add some newly opened handles +*/ +static void gen_add_handle(int instance, const char *name, struct smb2_handle handles[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++) { + NTSTATUS status; + status = smb2_util_close(servers[i].tree[open_handles[h].instance], + open_handles[h].server_handle[i]); + if (NT_STATUS_IS_ERR(status)) { + printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n", + nt_errstr(status)); + } + } + printf("Recovered handle %d\n", h); + num_open_handles--; + } + for (i=0;i<NSERVERS;i++) { + open_handles[h].server_handle[i] = handles[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 (%s)\n", + num_open_handles, h, name); +} + +/* + remove a closed handle +*/ +static void gen_remove_handle(int instance, struct smb2_handle handles[NSERVERS]) +{ + int h; + for (h=0;h<options.max_open_handles;h++) { + if (instance == open_handles[h].instance && + smb2_handle_equal(&open_handles[h].server_handle[0], &handles[0])) { + open_handles[h].active = false; + num_open_handles--; + printf("CLOSE num_open_handles=%d h=%d (%s)\n", + num_open_handles, h, + 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 handle +*/ +static struct smb2_handle gen_lookup_handle(int server, uint16_t handle) +{ + if (handle == BAD_HANDLE) return bad_smb2_handle; + return open_handles[handle].server_handle[server]; +} + +/* + return a file handle +*/ +static uint16_t gen_fnum(int instance) +{ + uint16_t 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_t 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(uint64_t min, uint64_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_t 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; +// if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF); + return gen_int_range(0, 1024*1024); +} + +/* + generate a io count +*/ +static int gen_io_count(void) +{ + if (gen_chance(20)) return 0; +// if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF); + 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_t 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]; +} + +static uint32_t gen_bits_levels(int nlevels, ...) +{ + va_list ap; + uint32_t pct; + uint32_t mask; + int i; + va_start(ap, nlevels); + for (i=0;i<nlevels;i++) { + pct = va_arg(ap, uint32_t); + mask = va_arg(ap, uint32_t); + if (pct == 100 || gen_chance(pct)) { + va_end(ap); + return mask & random(); + } + } + va_end(ap); + return 0; +} + +/* + generate a bitmask +*/ +static uint32_t 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_t gen_bits_mask2(uint32_t mask1, uint32_t 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); +} + +/* + generate ntrename flags +*/ +static uint16_t gen_rename_flags(void) +{ + if (gen_chance(30)) return RENAME_FLAG_RENAME; + if (gen_chance(30)) return RENAME_FLAG_HARD_LINK; + if (gen_chance(30)) return RENAME_FLAG_COPY; + return gen_bits_mask(0xFFFF); +} + + +/* + return a lockingx lock mode +*/ +static uint16_t 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_t gen_pid(void) +{ + if (gen_chance(10)) return gen_bits_mask(0xFFFF); + return getpid(); +} + +/* + generate a lock count +*/ +static off_t gen_lock_count(void) +{ + return gen_int_range(0, 3); +} + +/* + generate a ntcreatex flags field +*/ +static uint32_t 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_t gen_access_mask(void) +{ + if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED; + if (gen_chance(20)) return SEC_FILE_ALL; + return gen_bits_mask(0xFFFFFFFF); +} + +/* + generate a ntcreatex create options bitfield +*/ +static uint32_t 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_t 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_t 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_t 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_t 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_t 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_t 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 +*/ +static 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; + + ZERO_STRUCT(ea); + + 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; +} + +/* + 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 smb2_transport *transport, void *private) +{ + int i, j; + for (i=0;i<NSERVERS;i++) { + for (j=0;j<NINSTANCES;j++) { + if (servers[i].tree[j] && + transport != servers[i].tree[j]->session->transport) { + // smb2_transport_process(servers[i].tree[j]->session->transport); + } + } + } + +} + + +/* + 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++) { + // smb2_transport_process(servers[i].tree[j]->session->transport); + } + } +} + +/* + check that the same oplock breaks have been received by all instances +*/ +static bool check_oplocks(const char *call) +{ +#if 0 + 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_t fnums[NSERVERS]; + for (i=0;i<NSERVERS;i++) { + fnums[i] = oplocks[i][j].fnum; + } + gen_remove_handle(j, fnums); + break; + } + } +#endif + return true; +} + + +/* + check that the same change notify info has been received by all instances +*/ +static bool check_notifies(const char *call) +{ +#if 0 + int i, j; + int tries = 0; + +again: + check_pending(); + + for (j=0;j<NINSTANCES;j++) { + for (i=1;i<NSERVERS;i++) { + int n; + union 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.nttrans.out.num_changes;n++) { + if (not1.nttrans.out.changes[n].action != + not2.nttrans.out.changes[n].action) { + printf("Notify action %d inconsistent %d %d\n", n, + not1.nttrans.out.changes[n].action, + not2.nttrans.out.changes[n].action); + return false; + } + if (strcmp(not1.nttrans.out.changes[n].name.s, + not2.nttrans.out.changes[n].name.s)) { + printf("Notify name %d inconsistent %s %s\n", n, + not1.nttrans.out.changes[n].name.s, + not2.nttrans.out.changes[n].name.s); + return false; + } + if (not1.nttrans.out.changes[n].name.private_length != + not2.nttrans.out.changes[n].name.private_length) { + printf("Notify name length %d inconsistent %d %d\n", n, + not1.nttrans.out.changes[n].name.private_length, + not2.nttrans.out.changes[n].name.private_length); + return false; + } + } + } + } + + ZERO_STRUCT(notifies); + +#endif + 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 smb2_tree *tree = servers[i].tree[instance]; \ + 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 { \ + struct smb2_handle handles[NSERVERS]; \ + int i; \ + for (i=0;i<NSERVERS;i++) { \ + handles[i] = parm[i].field; \ + } \ + gen_add_handle(instance, name, handles); \ +} while(0) + +#define REMOVE_HANDLE(field) do { \ + struct smb2_handle handles[NSERVERS]; \ + int i; \ + for (i=0;i<NSERVERS;i++) { \ + handles[i] = parm[i].field; \ + } \ + gen_remove_handle(instance, handles); \ +} while(0) + +#define GEN_SET_FNUM(field) do { \ + int i; \ + for (i=0;i<NSERVERS;i++) { \ + parm[i].field = gen_lookup_handle(i, parm[i].field.data[0]); \ + } \ +} 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 ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \ + printf("%s is NULL!\n", #field); \ + return false; \ + } \ + if (parm[0].field.s && 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 (labs(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 (labs(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 ntcreatex operations +*/ +static bool handler_ntcreatex(int instance) +{ + struct smb2_create parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + ZERO_STRUCT(parm[0]); + parm[0].in.security_flags = gen_bits_levels(3, 70, 0x0, 70, 0x3, 100, 0xFF); + parm[0].in.oplock_level = gen_bits_levels(3, 70, 0x0, 70, 0x9, 100, 0xFF); + parm[0].in.impersonation_level = gen_bits_levels(3, 70, 0x0, 70, 0x3, 100, 0xFFFFFFFF); + parm[0].in.create_flags = gen_bits_levels(2, 80, 0x0, 100, 0xFFFFFFFF); + if (gen_chance(2)) { + parm[0].in.create_flags |= gen_bits_mask(0xFFFFFFFF); + } + parm[0].in.reserved = gen_bits_levels(2, 80, 0x0, 100, 0xFFFFFFFF); + if (gen_chance(2)) { + parm[0].in.reserved |= gen_bits_mask(0xFFFFFFFF); + } + parm[0].in.desired_access = gen_access_mask(); + parm[0].in.file_attributes = gen_attrib(); + parm[0].in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF); + parm[0].in.create_disposition = gen_open_disp(); + parm[0].in.create_options = gen_create_options(); + parm[0].in.fname = gen_fname_open(instance); + + if (!options.use_oplocks) { + /* mask out oplocks */ + parm[0].in.oplock_level = 0; + } + + GEN_COPY_PARM; + GEN_CALL(smb2_create(tree, current_op.mem_ctx, &parm[i])); + + CHECK_EQUAL(out.oplock_level); + CHECK_EQUAL(out.reserved); + CHECK_EQUAL(out.create_action); + CHECK_NTTIMES_EQUAL(out.create_time); + CHECK_NTTIMES_EQUAL(out.access_time); + CHECK_NTTIMES_EQUAL(out.write_time); + CHECK_NTTIMES_EQUAL(out.change_time); + CHECK_EQUAL(out.alloc_size); + CHECK_EQUAL(out.size); + CHECK_EQUAL(out.file_attr); + CHECK_EQUAL(out.reserved2); + + /* ntcreatex creates a new file handle */ + ADD_HANDLE(parm[0].in.fname, out.file.handle); + + return true; +} + +/* + generate close operations +*/ +static bool handler_close(int instance) +{ + struct smb2_close parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + ZERO_STRUCT(parm[0]); + parm[0].in.file.handle.data[0] = gen_fnum_close(instance); + parm[0].in.flags = gen_bits_mask2(0x1, 0xFFFF); + + GEN_COPY_PARM; + GEN_SET_FNUM(in.file.handle); + GEN_CALL(smb2_close(tree, &parm[i])); + + CHECK_EQUAL(out.flags); + CHECK_EQUAL(out._pad); + CHECK_NTTIMES_EQUAL(out.create_time); + CHECK_NTTIMES_EQUAL(out.access_time); + CHECK_NTTIMES_EQUAL(out.write_time); + CHECK_NTTIMES_EQUAL(out.change_time); + CHECK_EQUAL(out.alloc_size); + CHECK_EQUAL(out.size); + CHECK_EQUAL(out.file_attr); + + REMOVE_HANDLE(in.file.handle); + + return true; +} + +/* + generate read operations +*/ +static bool handler_read(int instance) +{ + struct smb2_read parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].in.file.handle.data[0] = gen_fnum(instance); + parm[0].in.reserved = gen_bits_mask2(0x0, 0xFF); + parm[0].in.length = gen_io_count(); + parm[0].in.offset = gen_offset(); + parm[0].in.min_count = gen_io_count(); + parm[0].in.channel = gen_bits_mask2(0x0, 0xFFFFFFFF); + parm[0].in.remaining = gen_bits_mask2(0x0, 0xFFFFFFFF); + parm[0].in.channel_offset = gen_bits_mask2(0x0, 0xFFFF); + parm[0].in.channel_length = gen_bits_mask2(0x0, 0xFFFF); + + GEN_COPY_PARM; + GEN_SET_FNUM(in.file.handle); + GEN_CALL(smb2_read(tree, current_op.mem_ctx, &parm[i])); + + CHECK_EQUAL(out.remaining); + CHECK_EQUAL(out.reserved); + CHECK_EQUAL(out.data.length); + + return true; +} + +/* + generate write operations +*/ +static bool handler_write(int instance) +{ + struct smb2_write parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].in.file.handle.data[0] = gen_fnum(instance); + parm[0].in.offset = gen_offset(); + parm[0].in.unknown1 = gen_bits_mask2(0, 0xFFFFFFFF); + parm[0].in.unknown2 = gen_bits_mask2(0, 0xFFFFFFFF); + parm[0].in.data = data_blob_talloc(current_op.mem_ctx, NULL, + gen_io_count()); + + GEN_COPY_PARM; + GEN_SET_FNUM(in.file.handle); + GEN_CALL(smb2_write(tree, &parm[i])); + + CHECK_EQUAL(out._pad); + CHECK_EQUAL(out.nwritten); + CHECK_EQUAL(out.unknown1); + + return true; +} + +#if 0 +/* + generate lockingx operations +*/ +static bool handler_lock(int instance) +{ + union smb_lock parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + int n, nlocks; + + parm[0].lockx.level = RAW_LOCK_LOCKX; + parm[0].lockx.in.file.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_array(current_op.mem_ctx, + struct smb_lock_entry, + 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.file.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 smb_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.file_id); + 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; + + /* Unhandled levels */ + + case RAW_FILEINFO_SEC_DESC: + case RAW_FILEINFO_EA_LIST: + case RAW_FILEINFO_UNIX_BASIC: + case RAW_FILEINFO_UNIX_LINK: + case RAW_FILEINFO_SMB2_ALL_EAS: + case RAW_FILEINFO_SMB2_ALL_INFORMATION: + case RAW_FILEINFO_UNIX_INFO2: + break; + } + + return true; +} + +/* + generate qfileinfo operations +*/ +static bool handler_qfileinfo(int instance) +{ + union smb_fileinfo parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].generic.in.file.fnum = gen_fnum(instance); + + gen_fileinfo(instance, &parm[0]); + + GEN_COPY_PARM; + GEN_SET_FNUM(generic.in.file.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 smb_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: { + static struct ea_struct ea; + info->ea_set.in.num_eas = 1; + info->ea_set.in.eas = &ea; + info->ea_set.in.eas[0] = 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: + case RAW_SFILEINFO_RENAME_INFORMATION_SMB2: + 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; + case RAW_SFILEINFO_GENERIC: + case RAW_SFILEINFO_SEC_DESC: + case RAW_SFILEINFO_UNIX_BASIC: + case RAW_SFILEINFO_UNIX_LINK: + case RAW_SFILEINFO_UNIX_HLINK: + case RAW_SFILEINFO_1023: + case RAW_SFILEINFO_1025: + case RAW_SFILEINFO_1029: + case RAW_SFILEINFO_1032: + case RAW_SFILEINFO_1039: + case RAW_SFILEINFO_1040: + case RAW_SFILEINFO_UNIX_INFO2: + /* Untested */ + break; + } +} + +/* + generate setfileinfo operations +*/ +static bool handler_sfileinfo(int instance) +{ + union smb_setfileinfo parm[NSERVERS]; + NTSTATUS status[NSERVERS]; + + parm[0].generic.in.file.fnum = gen_fnum(instance); + + gen_setfileinfo(instance, &parm[0]); + + GEN_COPY_PARM; + GEN_SET_FNUM(generic.in.file.fnum); + GEN_CALL(smb_raw_setfileinfo(tree, &parm[i])); + + return true; +} + +#endif + + +/* + wipe any relevant files +*/ +static void wipe_files(void) +{ + int i; + NTSTATUS status; + + for (i=0;i<NSERVERS;i++) { + int n = smb2_deltree(servers[i].tree[0], "gentest"); + if (n == -1) { + printf("Failed to wipe tree on server %d\n", i); + exit(1); + } + status = smb2_util_mkdir(servers[i].tree[0], "gentest"); + if (NT_STATUS_IS_ERR(status)) { + printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status)); + 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[] = { + {"NTCREATEX", handler_ntcreatex}, + {"CLOSE", handler_close}, + {"READ", handler_read}, + {"WRITE", handler_write}, +}; + + +/* + run the test with the current set of op_parms parameters + return the number of operations that completed successfully +*/ +static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx) +{ + int op, i; + + if (!connect_servers(ev, lp_ctx)) { + 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_named(NULL, 0, "%s", current_op.name); + + ret = gen_ops[which_op].handler(instance); + + talloc_free(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(struct event_context *ev, + struct loadparm_context *lp_ctx) +{ + 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(ev, lp_ctx); + 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(ev, lp_ctx); + 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(struct event_context *ev, + struct loadparm_context *lp_ctx) +{ + 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, NULL); + 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(ev, lp_ctx); + + if (ret != options.numops && options.analyze) { + options.numops = ret+1; + backtrack_analyze(ev, lp_ctx); + } else if (options.analyze_always) { + backtrack_analyze(ev, lp_ctx); + } else if (options.analyze_continuous) { + while (run_test(ev, lp_ctx) == options.numops) ; + } + + return ret == options.numops; +} + + +static void usage(poptContext pc) +{ + printf( +"Usage:\n\ + gentest //server1/share1 //server2/share2 [options..]\n\ +"); + poptPrintUsage(pc, stdout, 0); +} + +/** + split a UNC name into server and share names +*/ +static 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; +} + + + +/**************************************************************************** + main program +****************************************************************************/ + int main(int argc, char *argv[]) +{ + int opt; + int i, username_count=0; + bool ret; + char *ignore_file=NULL; + struct event_context *ev; + struct loadparm_context *lp_ctx; + poptContext pc; + int argc_new; + char **argv_new; + enum {OPT_UNCLIST=1000}; + struct poptOption long_options[] = { + POPT_AUTOHELP + {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL}, + {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL}, + {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL}, + {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL}, + {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL}, + {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL}, + {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL}, + {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL}, + {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL}, + {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL}, + {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL}, + {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL}, + { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" }, + POPT_COMMON_SAMBA + POPT_COMMON_CONNECTION + POPT_COMMON_CREDENTIALS + POPT_COMMON_VERSION + { NULL } + }; + + memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle)); + + setlinebuf(stdout); + options.seed = time(NULL); + options.numops = 1000; + options.max_open_handles = 20; + options.seeds_file = "gentest_seeds.dat"; + + pc = poptGetContext("gentest", argc, (const char **) argv, long_options, + POPT_CONTEXT_KEEP_FIRST); + + poptSetOtherOptionHelp(pc, "<unc1> <unc2>"); + + lp_ctx = cmdline_lp_ctx; + servers[0].credentials = cli_credentials_init(talloc_autofree_context()); + servers[1].credentials = cli_credentials_init(talloc_autofree_context()); + cli_credentials_guess(servers[0].credentials, lp_ctx); + cli_credentials_guess(servers[1].credentials, lp_ctx); + + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case OPT_UNCLIST: + lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc)); + break; + case 'U': + if (username_count == 2) { + usage(pc); + exit(1); + } + cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED); + username_count++; + break; + } + } + + if (ignore_file) { + options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL); + } + + argv_new = discard_const_p(char *, poptGetArgs(pc)); + argc_new = argc; + for (i=0; i<argc; i++) { + if (argv_new[i] == NULL) { + argc_new = i; + break; + } + } + + if (!(argc_new >= 3)) { + usage(pc); + exit(1); + } + + setlinebuf(stdout); + + setup_logging("gentest", DEBUG_STDOUT); + + if (argc < 3 || argv[1][0] == '-') { + usage(pc); + exit(1); + } + + setup_logging(argv[0], DEBUG_STDOUT); + + 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; + } + } + + if (username_count == 0) { + usage(pc); + return -1; + } + if (username_count == 1) { + servers[1].credentials = servers[0].credentials; + } + + printf("seed=%u\n", options.seed); + + ev = event_context_init(talloc_autofree_context()); + + gensec_init(lp_ctx); + + ret = start_gentest(ev, lp_ctx); + + if (ret) { + printf("gentest completed - no errors\n"); + } else { + printf("gentest failed\n"); + } + + return ret?0:-1; +} diff --git a/source4/torture/ldap/cldap.c b/source4/torture/ldap/cldap.c index ca4d9b7705..5d4acd581b 100644 --- a/source4/torture/ldap/cldap.c +++ b/source4/torture/ldap/cldap.c @@ -41,7 +41,7 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) struct cldap_socket *cldap; NTSTATUS status; struct cldap_netlogon search, empty_search; - union nbt_cldap_netlogon n1; + struct netlogon_samlogon_response n1; struct GUID guid; int i; @@ -51,7 +51,8 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) search.in.dest_address = dest; search.in.dest_port = lp_cldap_port(tctx->lp_ctx); search.in.acct_control = -1; - search.in.version = 6; + search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX; + search.in.map_response = true; empty_search = search; @@ -63,7 +64,7 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) n1 = search.out.netlogon; search.in.user = "Administrator"; - search.in.realm = n1.logon5.dns_domain; + search.in.realm = n1.nt5_ex.dns_domain; search.in.host = "__cldap_torture__"; printf("Scanning for netlogon levels\n"); @@ -82,7 +83,8 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) CHECK_STATUS(status, NT_STATUS_OK); } - search.in.version = 0x20000006; + search.in.version = NETLOGON_NT_VERSION_5|NETLOGON_NT_VERSION_5EX|NETLOGON_NT_VERSION_IP; + status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); @@ -91,8 +93,8 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) search.in.user = NULL; status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_STRING(search.out.netlogon.logon5.user_name, ""); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, ""); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX); printf("Trying with User=Administrator\n"); @@ -100,10 +102,10 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_STRING(search.out.netlogon.logon5.user_name, search.in.user); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC_USER); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, search.in.user); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX); - search.in.version = 6; + search.in.version = NETLOGON_NT_VERSION_5; status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); @@ -112,8 +114,8 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) search.in.user = NULL; status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_STRING(search.out.netlogon.logon5.user_name, ""); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, ""); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE); printf("Trying with User=Administrator\n"); @@ -121,16 +123,18 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_STRING(search.out.netlogon.logon5.user_name, search.in.user); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC_USER); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, search.in.user); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN); + + search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX; printf("Trying with a GUID\n"); search.in.realm = NULL; - search.in.domain_guid = GUID_string(tctx, &n1.logon5.domain_uuid); + search.in.domain_guid = GUID_string(tctx, &n1.nt5_ex.domain_uuid); status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC_USER); - CHECK_STRING(GUID_string(tctx, &search.out.netlogon.logon5.domain_uuid), search.in.domain_guid); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX); + CHECK_STRING(GUID_string(tctx, &search.out.netlogon.nt5_ex.domain_uuid), search.in.domain_guid); printf("Trying with a incorrect GUID\n"); guid = GUID_random(); @@ -140,33 +144,54 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) CHECK_STATUS(status, NT_STATUS_NOT_FOUND); printf("Trying with a AAC\n"); - search.in.acct_control = 0x180; - search.in.realm = n1.logon5.dns_domain; + search.in.acct_control = ACB_WSTRUST|ACB_SVRTRUST; + search.in.realm = n1.nt5_ex.dns_domain; + status = cldap_netlogon(cldap, tctx, &search); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, ""); + + printf("Trying with a zero AAC\n"); + search.in.acct_control = 0x0; + search.in.realm = n1.nt5_ex.dns_domain; status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2); - CHECK_STRING(search.out.netlogon.logon5.user_name, ""); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, ""); + + printf("Trying with a zero AAC and user=Administrator\n"); + search.in.acct_control = 0x0; + search.in.user = "Administrator"; + search.in.realm = n1.nt5_ex.dns_domain; + status = cldap_netlogon(cldap, tctx, &search); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, "Administrator"); printf("Trying with a bad AAC\n"); + search.in.user = NULL; search.in.acct_control = 0xFF00FF00; - search.in.realm = n1.logon5.dns_domain; + search.in.realm = n1.nt5_ex.dns_domain; status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, ""); printf("Trying with a user only\n"); search = empty_search; search.in.user = "Administrator"; status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain); - CHECK_STRING(search.out.netlogon.logon5.user_name, search.in.user); + CHECK_STRING(search.out.netlogon.nt5_ex.dns_domain, n1.nt5_ex.dns_domain); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, search.in.user); printf("Trying with just a bad username\n"); search.in.user = "___no_such_user___"; status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_STRING(search.out.netlogon.logon5.user_name, search.in.user); - CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, search.in.user); + CHECK_STRING(search.out.netlogon.nt5_ex.dns_domain, n1.nt5_ex.dns_domain); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX); printf("Trying with just a bad domain\n"); search = empty_search; @@ -175,29 +200,29 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest) CHECK_STATUS(status, NT_STATUS_NOT_FOUND); printf("Trying with a incorrect domain and correct guid\n"); - search.in.domain_guid = GUID_string(tctx, &n1.logon5.domain_uuid); + search.in.domain_guid = GUID_string(tctx, &n1.nt5_ex.domain_uuid); status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain); - CHECK_STRING(search.out.netlogon.logon5.user_name, ""); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2); + CHECK_STRING(search.out.netlogon.nt5_ex.dns_domain, n1.nt5_ex.dns_domain); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, ""); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX); printf("Trying with a incorrect domain and incorrect guid\n"); search.in.domain_guid = GUID_string(tctx, &guid); status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_NOT_FOUND); - CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain); - CHECK_STRING(search.out.netlogon.logon5.user_name, ""); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2); + CHECK_STRING(search.out.netlogon.nt5_ex.dns_domain, n1.nt5_ex.dns_domain); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, ""); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX); printf("Trying with a incorrect GUID and correct domain\n"); search.in.domain_guid = GUID_string(tctx, &guid); - search.in.realm = n1.logon5.dns_domain; + search.in.realm = n1.nt5_ex.dns_domain; status = cldap_netlogon(cldap, tctx, &search); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain); - CHECK_STRING(search.out.netlogon.logon5.user_name, ""); - CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2); + CHECK_STRING(search.out.netlogon.nt5_ex.dns_domain, n1.nt5_ex.dns_domain); + CHECK_STRING(search.out.netlogon.nt5_ex.user_name, ""); + CHECK_VAL(search.out.netlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX); return true; } diff --git a/source4/torture/local/config.mk b/source4/torture/local/config.mk index d7cac101df..cd1c7b1422 100644 --- a/source4/torture/local/config.mk +++ b/source4/torture/local/config.mk @@ -3,8 +3,6 @@ [MODULE::TORTURE_LOCAL] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_local_init -PRIVATE_PROTO_HEADER = \ - proto.h PRIVATE_DEPENDENCIES = \ RPC_NDR_ECHO \ TDR \ @@ -21,32 +19,34 @@ PRIVATE_DEPENDENCIES = \ ################################# TORTURE_LOCAL_OBJ_FILES = \ - lib/charset/tests/iconv.o \ - lib/talloc/testsuite.o \ - lib/replace/test/getifaddrs.o \ - lib/replace/test/os2_delete.o \ - lib/replace/test/strptime.o \ - lib/replace/test/testsuite.o \ - lib/messaging/tests/messaging.o \ - lib/messaging/tests/irpc.o \ - librpc/tests/binding_string.o \ - lib/util/tests/idtree.o \ - lib/socket/testsuite.o \ - lib/socket_wrapper/testsuite.o \ - libcli/resolve/testsuite.o \ - lib/util/tests/strlist.o \ - lib/util/tests/str.o \ - lib/util/tests/file.o \ - lib/util/tests/genrand.o \ - lib/compression/testsuite.o \ - lib/charset/tests/charset.o \ - libcli/security/tests/sddl.o \ - lib/tdr/testsuite.o \ - lib/events/testsuite.o \ - param/tests/share.o \ - param/tests/loadparm.o \ - auth/credentials/tests/simple.o \ - torture/local/local.o \ - torture/local/dbspeed.o \ - torture/local/torture.o + $(torturesrcdir)/../lib/charset/tests/iconv.o \ + $(torturesrcdir)/../lib/talloc/testsuite.o \ + $(torturesrcdir)/../lib/replace/test/getifaddrs.o \ + $(torturesrcdir)/../lib/replace/test/os2_delete.o \ + $(torturesrcdir)/../lib/replace/test/strptime.o \ + $(torturesrcdir)/../lib/replace/test/testsuite.o \ + $(torturesrcdir)/../lib/messaging/tests/messaging.o \ + $(torturesrcdir)/../lib/messaging/tests/irpc.o \ + $(torturesrcdir)/../librpc/tests/binding_string.o \ + $(torturesrcdir)/../lib/util/tests/idtree.o \ + $(torturesrcdir)/../lib/socket/testsuite.o \ + $(torturesrcdir)/../lib/socket_wrapper/testsuite.o \ + $(torturesrcdir)/../libcli/resolve/testsuite.o \ + $(torturesrcdir)/../lib/util/tests/strlist.o \ + $(torturesrcdir)/../lib/util/tests/str.o \ + $(torturesrcdir)/../lib/util/tests/file.o \ + $(torturesrcdir)/../lib/util/tests/genrand.o \ + $(torturesrcdir)/../lib/compression/testsuite.o \ + $(torturesrcdir)/../lib/charset/tests/charset.o \ + $(torturesrcdir)/../libcli/security/tests/sddl.o \ + $(torturesrcdir)/../lib/tdr/testsuite.o \ + $(torturesrcdir)/../lib/events/testsuite.o \ + $(torturesrcdir)/../param/tests/share.o \ + $(torturesrcdir)/../param/tests/loadparm.o \ + $(torturesrcdir)/../auth/credentials/tests/simple.o \ + $(torturesrcdir)/local/local.o \ + $(torturesrcdir)/local/dbspeed.o \ + $(torturesrcdir)/local/torture.o + +$(eval $(call proto_header_template,$(torturesrcdir)/local/proto.h,$(TORTURE_LOCAL_OBJ_FILES:.o=.c))) diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c index a3585896eb..f8f9eaf884 100644 --- a/source4/torture/nbt/dgram.c +++ b/source4/torture/nbt/dgram.c @@ -42,21 +42,24 @@ static void netlogon_handler(struct dgram_mailslot_handler *dgmslot, struct socket_address *src) { NTSTATUS status; - struct nbt_netlogon_packet netlogon; - int *replies = (int *)dgmslot->private; + struct nbt_netlogon_response *netlogon = dgmslot->private; + dgmslot->private = netlogon = talloc(dgmslot, struct nbt_netlogon_response); + + if (!dgmslot->private) { + return; + } + printf("netlogon reply from %s:%d\n", src->addr, src->port); - status = dgram_mailslot_netlogon_parse(dgmslot, dgmslot, packet, &netlogon); + /* Fills in the netlogon pointer */ + status = dgram_mailslot_netlogon_parse_response(dgmslot, netlogon, packet, netlogon); if (!NT_STATUS_IS_OK(status)) { printf("Failed to parse netlogon packet from %s:%d\n", src->addr, src->port); return; } - NDR_PRINT_DEBUG(nbt_netlogon_packet, &netlogon); - - (*replies)++; } @@ -69,10 +72,10 @@ static bool nbt_test_netlogon(struct torture_context *tctx) struct socket_address *dest; const char *myaddress; struct nbt_netlogon_packet logon; + struct nbt_netlogon_response *response; struct nbt_name myname; NTSTATUS status; struct timeval tv = timeval_current(); - int replies = 0; struct socket_address *socket_address; @@ -80,7 +83,7 @@ static bool nbt_test_netlogon(struct torture_context *tctx) struct nbt_name name; struct interface *ifaces; - + name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; name.scope = NULL; @@ -101,7 +104,7 @@ static bool nbt_test_netlogon(struct torture_context *tctx) /* try receiving replies on port 138 first, which will only work if we are root and smbd/nmbd are not running - fall back to listening on any port, which means replies from - some windows versions won't be seen */ + most windows versions won't be seen */ status = socket_listen(dgmsock->sock, socket_address, 0, 0); if (!NT_STATUS_IS_OK(status)) { talloc_free(socket_address); @@ -114,10 +117,10 @@ static bool nbt_test_netlogon(struct torture_context *tctx) /* setup a temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, - netlogon_handler, &replies); + netlogon_handler, NULL); ZERO_STRUCT(logon); - logon.command = NETLOGON_QUERY_FOR_PDC; + logon.command = LOGON_PRIMARY_QUERY; logon.req.pdc.computer_name = TEST_NAME; logon.req.pdc.mailslot_name = dgmslot->mailslot_name; logon.req.pdc.unicode_name = TEST_NAME; @@ -132,13 +135,21 @@ static bool nbt_test_netlogon(struct torture_context *tctx) torture_assert(tctx, dest != NULL, "Error getting address"); status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, + NBT_MAILSLOT_NETLOGON, &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); - while (timeval_elapsed(&tv) < 5 && replies == 0) { + while (timeval_elapsed(&tv) < 5 && !dgmslot->private) { event_loop_once(dgmsock->event_ctx); } + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); + + torture_assert(tctx, response->response_type == NETLOGON_GET_PDC, "Got incorrect type of netlogon response"); + torture_assert(tctx, response->get_pdc.command == NETLOGON_RESPONSE_FROM_PDC, "Got incorrect netlogon response command"); + return true; } @@ -152,10 +163,10 @@ static bool nbt_test_netlogon2(struct torture_context *tctx) struct socket_address *dest; const char *myaddress; struct nbt_netlogon_packet logon; + struct nbt_netlogon_response *response; struct nbt_name myname; NTSTATUS status; struct timeval tv = timeval_current(); - int replies = 0; struct socket_address *socket_address; @@ -163,6 +174,9 @@ static bool nbt_test_netlogon2(struct torture_context *tctx) struct nbt_name name; struct interface *ifaces; + struct test_join *join_ctx; + struct cli_credentials *machine_credentials; + const struct dom_sid *dom_sid; name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; @@ -196,18 +210,18 @@ static bool nbt_test_netlogon2(struct torture_context *tctx) /* setup a temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, - netlogon_handler, &replies); + netlogon_handler, NULL); ZERO_STRUCT(logon); - logon.command = NETLOGON_QUERY_FOR_PDC2; - logon.req.pdc2.request_count = 0; - logon.req.pdc2.computer_name = TEST_NAME; - logon.req.pdc2.user_name = ""; - logon.req.pdc2.mailslot_name = dgmslot->mailslot_name; - logon.req.pdc2.nt_version = 11; - logon.req.pdc2.lmnt_token = 0xFFFF; - logon.req.pdc2.lm20_token = 0xFFFF; + logon.command = LOGON_SAM_LOGON_REQUEST; + logon.req.logon.request_count = 0; + logon.req.logon.computer_name = TEST_NAME; + logon.req.logon.user_name = ""; + logon.req.logon.mailslot_name = dgmslot->mailslot_name; + logon.req.logon.nt_version = NETLOGON_NT_VERSION_5EX_WITH_IP|NETLOGON_NT_VERSION_5|NETLOGON_NT_VERSION_1; + logon.req.logon.lmnt_token = 0xFFFF; + logon.req.logon.lm20_token = 0xFFFF; make_nbt_name_client(&myname, TEST_NAME); @@ -216,40 +230,191 @@ static bool nbt_test_netlogon2(struct torture_context *tctx) torture_assert(tctx, dest != NULL, "Error getting address"); status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, + NBT_MAILSLOT_NETLOGON, &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); - while (timeval_elapsed(&tv) < 5 && replies == 0) { + while (timeval_elapsed(&tv) < 5 && dgmslot->private == NULL) { event_loop_once(dgmsock->event_ctx); } - return true; -} + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); -/* - reply handler for ntlogon request -*/ -static void ntlogon_handler(struct dgram_mailslot_handler *dgmslot, - struct nbt_dgram_packet *packet, - struct socket_address *src) -{ - NTSTATUS status; - struct nbt_ntlogon_packet ntlogon; - int *replies = (int *)dgmslot->private; + torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); + map_netlogon_samlogon_response(&response->samlogon); - printf("ntlogon reply from %s:%d\n", src->addr, src->port); + torture_assert_int_equal(tctx, response->samlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX, "Got incorrect netlogon response command"); + torture_assert_int_equal(tctx, response->samlogon.nt5_ex.nt_version, NETLOGON_NT_VERSION_5EX_WITH_IP|NETLOGON_NT_VERSION_5EX|NETLOGON_NT_VERSION_5|NETLOGON_NT_VERSION_1, "Got incorrect netlogon response command"); - status = dgram_mailslot_ntlogon_parse(dgmslot, dgmslot, packet, &ntlogon); - if (!NT_STATUS_IS_OK(status)) { - printf("Failed to parse ntlogon packet from %s:%d\n", - src->addr, src->port); - return; + /* setup (another) temporary mailslot listener for replies */ + dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, + netlogon_handler, NULL); + + ZERO_STRUCT(logon); + logon.command = LOGON_SAM_LOGON_REQUEST; + logon.req.logon.request_count = 0; + logon.req.logon.computer_name = TEST_NAME; + logon.req.logon.user_name = TEST_NAME"$"; + logon.req.logon.mailslot_name = dgmslot->mailslot_name; + logon.req.logon.nt_version = 1; + logon.req.logon.lmnt_token = 0xFFFF; + logon.req.logon.lm20_token = 0xFFFF; + + make_nbt_name_client(&myname, TEST_NAME); + + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, lp_dgram_port(tctx->lp_ctx)); + + torture_assert(tctx, dest != NULL, "Error getting address"); + status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, + NBT_MAILSLOT_NETLOGON, + &myname, &logon); + torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); + + while (timeval_elapsed(&tv) < 5 && dgmslot->private == NULL) { + event_loop_once(dgmsock->event_ctx); + } + + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); + + torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); + map_netlogon_samlogon_response(&response->samlogon); + + torture_assert_int_equal(tctx, response->samlogon.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN, "Got incorrect netlogon response command"); + + torture_assert_str_equal(tctx, response->samlogon.nt5_ex.user_name, TEST_NAME"$", "Got incorrect user in netlogon response"); + + join_ctx = torture_join_domain(tctx, TEST_NAME, + ACB_WSTRUST, &machine_credentials); + + dom_sid = torture_join_sid(join_ctx); + + /* setup (another) temporary mailslot listener for replies */ + dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, + netlogon_handler, NULL); + + ZERO_STRUCT(logon); + logon.command = LOGON_SAM_LOGON_REQUEST; + logon.req.logon.request_count = 0; + logon.req.logon.computer_name = TEST_NAME; + logon.req.logon.user_name = TEST_NAME"$"; + logon.req.logon.mailslot_name = dgmslot->mailslot_name; + logon.req.logon.sid = *dom_sid; + logon.req.logon.nt_version = 1; + logon.req.logon.lmnt_token = 0xFFFF; + logon.req.logon.lm20_token = 0xFFFF; + + make_nbt_name_client(&myname, TEST_NAME); + + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, lp_dgram_port(tctx->lp_ctx)); + + torture_assert(tctx, dest != NULL, "Error getting address"); + status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, + NBT_MAILSLOT_NETLOGON, + &myname, &logon); + torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); + + + while (timeval_elapsed(&tv) < 5 && dgmslot->private == NULL) { + event_loop_once(dgmsock->event_ctx); + } + + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); + + torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); + map_netlogon_samlogon_response(&response->samlogon); + + torture_assert_int_equal(tctx, response->samlogon.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN, "Got incorrect netlogon response command"); + + /* setup (another) temporary mailslot listener for replies */ + dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, + netlogon_handler, NULL); + + ZERO_STRUCT(logon); + logon.command = LOGON_SAM_LOGON_REQUEST; + logon.req.logon.request_count = 0; + logon.req.logon.computer_name = TEST_NAME; + logon.req.logon.user_name = TEST_NAME"$"; + logon.req.logon.mailslot_name = dgmslot->mailslot_name; + logon.req.logon.sid = *dom_sid; + logon.req.logon.acct_control = ACB_WSTRUST; + logon.req.logon.nt_version = 1; + logon.req.logon.lmnt_token = 0xFFFF; + logon.req.logon.lm20_token = 0xFFFF; + + make_nbt_name_client(&myname, TEST_NAME); + + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, lp_dgram_port(tctx->lp_ctx)); + + torture_assert(tctx, dest != NULL, "Error getting address"); + status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, + NBT_MAILSLOT_NETLOGON, + &myname, &logon); + torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); + + + while (timeval_elapsed(&tv) < 5 && dgmslot->private == NULL) { + event_loop_once(dgmsock->event_ctx); + } + + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); + + torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); + map_netlogon_samlogon_response(&response->samlogon); + + torture_assert_int_equal(tctx, response->samlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE, "Got incorrect netlogon response command"); + + dgmslot->private = NULL; + + ZERO_STRUCT(logon); + logon.command = LOGON_SAM_LOGON_REQUEST; + logon.req.logon.request_count = 0; + logon.req.logon.computer_name = TEST_NAME; + logon.req.logon.user_name = TEST_NAME"$"; + logon.req.logon.mailslot_name = dgmslot->mailslot_name; + logon.req.logon.sid = *dom_sid; + logon.req.logon.acct_control = ACB_NORMAL; + logon.req.logon.nt_version = 1; + logon.req.logon.lmnt_token = 0xFFFF; + logon.req.logon.lm20_token = 0xFFFF; + + make_nbt_name_client(&myname, TEST_NAME); + + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, lp_dgram_port(tctx->lp_ctx)); + + torture_assert(tctx, dest != NULL, "Error getting address"); + status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, + NBT_MAILSLOT_NETLOGON, + &myname, &logon); + torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); + + + while (timeval_elapsed(&tv) < 5 && dgmslot->private == NULL) { + event_loop_once(dgmsock->event_ctx); } - NDR_PRINT_DEBUG(nbt_ntlogon_packet, &ntlogon); + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); - (*replies)++; + torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); + map_netlogon_samlogon_response(&response->samlogon); + + torture_assert_int_equal(tctx, response->samlogon.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN, "Got incorrect netlogon response command"); + + torture_leave_domain(join_ctx); + return true; } @@ -261,15 +426,15 @@ static bool nbt_test_ntlogon(struct torture_context *tctx) lp_iconv_convenience(tctx->lp_ctx)); struct socket_address *dest; struct test_join *join_ctx; - struct cli_credentials *machine_credentials; const struct dom_sid *dom_sid; + struct cli_credentials *machine_credentials; const char *myaddress; - struct nbt_ntlogon_packet logon; + struct nbt_netlogon_packet logon; + struct nbt_netlogon_response *response; struct nbt_name myname; NTSTATUS status; struct timeval tv = timeval_current(); - int replies = 0; struct socket_address *socket_address; const char *address; @@ -296,7 +461,7 @@ static bool nbt_test_ntlogon(struct torture_context *tctx) /* try receiving replies on port 138 first, which will only work if we are root and smbd/nmbd are not running - fall back to listening on any port, which means replies from - some windows versions won't be seen */ + most windows versions won't be seen */ status = socket_listen(dgmsock->sock, socket_address, 0, 0); if (!NT_STATUS_IS_OK(status)) { talloc_free(socket_address); @@ -309,24 +474,25 @@ static bool nbt_test_ntlogon(struct torture_context *tctx) join_ctx = torture_join_domain(tctx, TEST_NAME, ACB_WSTRUST, &machine_credentials); + dom_sid = torture_join_sid(join_ctx); + torture_assert(tctx, join_ctx != NULL, talloc_asprintf(tctx, "Failed to join domain %s as %s\n", lp_workgroup(tctx->lp_ctx), TEST_NAME)); - dom_sid = torture_join_sid(join_ctx); - /* setup a temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, - ntlogon_handler, &replies); + netlogon_handler, NULL); ZERO_STRUCT(logon); - logon.command = NTLOGON_SAM_LOGON; + logon.command = LOGON_SAM_LOGON_REQUEST; logon.req.logon.request_count = 0; logon.req.logon.computer_name = TEST_NAME; logon.req.logon.user_name = TEST_NAME"$"; logon.req.logon.mailslot_name = dgmslot->mailslot_name; logon.req.logon.acct_control = ACB_WSTRUST; + /* Try with a SID this time */ logon.req.logon.sid = *dom_sid; logon.req.logon.nt_version = 1; logon.req.logon.lmnt_token = 0xFFFF; @@ -337,15 +503,145 @@ static bool nbt_test_ntlogon(struct torture_context *tctx) dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, address, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, dest != NULL, "Error getting address"); - status = dgram_mailslot_ntlogon_send(dgmsock, DGRAM_DIRECT_UNIQUE, - &name, dest, &myname, &logon); + status = dgram_mailslot_netlogon_send(dgmsock, + &name, dest, + NBT_MAILSLOT_NTLOGON, + &myname, &logon); + torture_assert_ntstatus_ok(tctx, status, "Failed to send ntlogon request"); + + while (timeval_elapsed(&tv) < 5 && dgmslot->private == NULL) { + event_loop_once(dgmsock->event_ctx); + } + + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); + + torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); + map_netlogon_samlogon_response(&response->samlogon); + + torture_assert_int_equal(tctx, response->samlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE, "Got incorrect netlogon response command"); + + torture_assert_str_equal(tctx, response->samlogon.nt5_ex.user_name, TEST_NAME"$", "Got incorrect user in netlogon response"); + + + /* setup a temporary mailslot listener for replies */ + dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, + netlogon_handler, NULL); + + + ZERO_STRUCT(logon); + logon.command = LOGON_SAM_LOGON_REQUEST; + logon.req.logon.request_count = 0; + logon.req.logon.computer_name = TEST_NAME; + logon.req.logon.user_name = TEST_NAME"$"; + logon.req.logon.mailslot_name = dgmslot->mailslot_name; + logon.req.logon.acct_control = ACB_WSTRUST; + /* Leave sid as all zero */ + logon.req.logon.nt_version = 1; + logon.req.logon.lmnt_token = 0xFFFF; + logon.req.logon.lm20_token = 0xFFFF; + + make_nbt_name_client(&myname, TEST_NAME); + + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, lp_dgram_port(tctx->lp_ctx)); + torture_assert(tctx, dest != NULL, "Error getting address"); + status = dgram_mailslot_netlogon_send(dgmsock, + &name, dest, + NBT_MAILSLOT_NTLOGON, + &myname, &logon); + torture_assert_ntstatus_ok(tctx, status, "Failed to send ntlogon request"); + + while (timeval_elapsed(&tv) < 5 && dgmslot->private == NULL) { + event_loop_once(dgmsock->event_ctx); + } + + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); + + torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); + map_netlogon_samlogon_response(&response->samlogon); + + torture_assert_int_equal(tctx, response->samlogon.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE, "Got incorrect netlogon response command"); + + torture_assert_str_equal(tctx, response->samlogon.nt5_ex.user_name, TEST_NAME"$", "Got incorrect user in netlogon response"); + + + /* setup (another) temporary mailslot listener for replies */ + dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, + netlogon_handler, NULL); + + ZERO_STRUCT(logon); + logon.command = LOGON_PRIMARY_QUERY; + logon.req.pdc.computer_name = TEST_NAME; + logon.req.pdc.mailslot_name = dgmslot->mailslot_name; + logon.req.pdc.unicode_name = TEST_NAME; + logon.req.pdc.nt_version = 1; + logon.req.pdc.lmnt_token = 0xFFFF; + logon.req.pdc.lm20_token = 0xFFFF; + + make_nbt_name_client(&myname, TEST_NAME); + + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, lp_dgram_port(tctx->lp_ctx)); + torture_assert(tctx, dest != NULL, "Error getting address"); + status = dgram_mailslot_netlogon_send(dgmsock, + &name, dest, + NBT_MAILSLOT_NTLOGON, + &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send ntlogon request"); - while (timeval_elapsed(&tv) < 5 && replies == 0) { + while (timeval_elapsed(&tv) < 5 && !dgmslot->private) { event_loop_once(dgmsock->event_ctx); } + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); + + torture_assert_int_equal(tctx, response->response_type, NETLOGON_GET_PDC, "Got incorrect type of ntlogon response"); + torture_assert_int_equal(tctx, response->get_pdc.command, NETLOGON_RESPONSE_FROM_PDC, "Got incorrect ntlogon response command"); + torture_leave_domain(join_ctx); + + /* setup (another) temporary mailslot listener for replies */ + dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, + netlogon_handler, NULL); + + ZERO_STRUCT(logon); + logon.command = LOGON_PRIMARY_QUERY; + logon.req.pdc.computer_name = TEST_NAME; + logon.req.pdc.mailslot_name = dgmslot->mailslot_name; + logon.req.pdc.unicode_name = TEST_NAME; + logon.req.pdc.nt_version = 1; + logon.req.pdc.lmnt_token = 0xFFFF; + logon.req.pdc.lm20_token = 0xFFFF; + + make_nbt_name_client(&myname, TEST_NAME); + + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, lp_dgram_port(tctx->lp_ctx)); + torture_assert(tctx, dest != NULL, "Error getting address"); + status = dgram_mailslot_netlogon_send(dgmsock, + &name, dest, + NBT_MAILSLOT_NTLOGON, + &myname, &logon); + torture_assert_ntstatus_ok(tctx, status, "Failed to send ntlogon request"); + + while (timeval_elapsed(&tv) < 5 && !dgmslot->private) { + event_loop_once(dgmsock->event_ctx); + } + + response = talloc_get_type(dgmslot->private, struct nbt_netlogon_response); + + torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); + + torture_assert_int_equal(tctx, response->response_type, NETLOGON_GET_PDC, "Got incorrect type of ntlogon response"); + torture_assert_int_equal(tctx, response->get_pdc.command, NETLOGON_RESPONSE_FROM_PDC, "Got incorrect ntlogon response command"); + + return true; } diff --git a/source4/torture/raw/raw.c b/source4/torture/raw/raw.c index c6133081b0..0a7fc3ebfd 100644 --- a/source4/torture/raw/raw.c +++ b/source4/torture/raw/raw.c @@ -35,6 +35,8 @@ NTSTATUS torture_raw_init(void) torture_suite_add_simple_test(suite, "BENCH-OPEN", torture_bench_open); torture_suite_add_simple_test(suite, "BENCH-LOOKUP", torture_bench_lookup); + torture_suite_add_simple_test(suite, "BENCH-TCON", + torture_bench_treeconnect); torture_suite_add_simple_test(suite, "OFFLINE", torture_test_offline); torture_suite_add_1smb_test(suite, "QFSINFO", torture_raw_qfsinfo); torture_suite_add_1smb_test(suite, "QFILEINFO", torture_raw_qfileinfo); diff --git a/source4/torture/raw/tconrate.c b/source4/torture/raw/tconrate.c new file mode 100644 index 0000000000..6f0ba0d617 --- /dev/null +++ b/source4/torture/raw/tconrate.c @@ -0,0 +1,201 @@ +/* + SMB tree connection rate test + + Copyright (C) 2006-2007 James Peach + + 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 3 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, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "libcli/libcli.h" +#include "libcli/resolve/resolve.h" +#include "torture/smbtorture.h" +#include "lib/cmdline/popt_common.h" +#include "param/param.h" + +#include "system/filesys.h" +#include "system/shmem.h" + +#define TIME_LIMIT_SECS 30 +#define usec_to_sec(s) ((s) / 1000000) +#define sec_to_usec(s) ((s) * 1000000) + +/* Map a shared memory buffer of at least nelem counters. */ +static void * map_count_buffer(unsigned nelem, size_t elemsz) +{ + void * buf; + size_t bufsz; + size_t pagesz = getpagesize(); + + bufsz = nelem * elemsz; + bufsz = (bufsz + pagesz) % pagesz; /* round up to pagesz */ + +#ifdef MAP_ANON + /* BSD */ + buf = mmap(NULL, bufsz, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, + -1 /* fd */, 0 /* offset */); +#else + buf = mmap(NULL, bufsz, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, + open("/dev/zero", O_RDWR), 0 /* offset */); +#endif + + if (buf == MAP_FAILED) { + printf("failed to map count buffer: %s\n", + strerror(errno)); + return NULL; + } + + return buf; + +} + +static int fork_tcon_client(struct torture_context *tctx, + int *tcon_count, unsigned tcon_timelimit, + const char *host, const char *share) +{ + pid_t child; + struct smbcli_state *cli; + struct timeval end; + struct timeval now; + struct smbcli_options options; + + lp_smbcli_options(tctx->lp_ctx, &options); + + child = fork(); + if (child == -1) { + printf("failed to fork child: %s\n,", strerror(errno)); + return -1; + } else if (child != 0) { + /* Parent, just return. */ + return 0; + } + + /* Child. Just make as many connections as possible within the + * time limit. Don't bother synchronising the child start times + * because it's probably not work the effort, and a bit of startup + * jitter is probably a more realistic test. + */ + + + end = timeval_current(); + now = timeval_current(); + end.tv_sec += tcon_timelimit; + *tcon_count = 0; + + while (timeval_compare(&now, &end) == -1) { + NTSTATUS status; + + status = smbcli_full_connection(NULL, &cli, + host, lp_smb_ports(tctx->lp_ctx), share, + NULL, cmdline_credentials, + lp_resolve_context(tctx->lp_ctx), + tctx->ev, &options); + + if (!NT_STATUS_IS_OK(status)) { + printf("failed to connect to //%s/%s: %s\n", + host, share, nt_errstr(status)); + goto done; + } + + smbcli_tdis(cli); + + *tcon_count = *tcon_count + 1; + now = timeval_current(); + } + +done: + exit(0); +} + +static bool children_remain(void) +{ + /* Reap as many children as possible. */ + for (;;) { + pid_t ret = waitpid(-1, NULL, WNOHANG); + if (ret == 0) { + /* no children ready */ + return true; + } + if (ret == -1) { + /* no children left. maybe */ + return errno == ECHILD ? false : true; + } + } + + /* notreached */ + return false; +} + +static double rate_convert_secs(unsigned count, + const struct timeval *start, const struct timeval *end) +{ + return (double)count / + usec_to_sec((double)usec_time_diff(end, start)); +} + +/* Test the rate at which the server will accept connections. */ +bool torture_bench_treeconnect(struct torture_context *tctx) +{ + const char *host = torture_setting_string(tctx, "host", NULL); + const char *share = torture_setting_string(tctx, "share", NULL); + + int timelimit = torture_setting_int(tctx, "timelimit", + TIME_LIMIT_SECS); + int nprocs = torture_setting_int(tctx, "nprocs", 4); + + int *curr_counts = map_count_buffer(nprocs, sizeof(int)); + int *last_counts = talloc_array(NULL, int, nprocs); + + struct timeval now, last, start; + int i, delta; + + torture_assert(tctx, nprocs > 0, "bad proc count"); + torture_assert(tctx, timelimit > 0, "bad timelimit"); + torture_assert(tctx, curr_counts, "allocation failure"); + torture_assert(tctx, last_counts, "allocation failure"); + + start = last = timeval_current(); + for (i = 0; i < nprocs; ++i) { + fork_tcon_client(tctx, &curr_counts[i], timelimit, host, share); + } + + while (children_remain()) { + + sleep(1); + now = timeval_current(); + + for (i = 0, delta = 0; i < nprocs; ++i) { + delta += curr_counts[i] - last_counts[i]; + } + + printf("%u connections/sec\n", + (unsigned)rate_convert_secs(delta, &last, &now)); + + memcpy(last_counts, curr_counts, nprocs * sizeof(int)); + last = timeval_current(); + } + + now = timeval_current(); + + for (i = 0, delta = 0; i < nprocs; ++i) { + delta += curr_counts[i]; + } + + printf("TOTAL: %u connections/sec over %u secs\n", + (unsigned)rate_convert_secs(delta, &start, &now), + timelimit); + return true; +} + +/* vim: set sts=8 sw=8 : */ diff --git a/source4/torture/rpc/dssync.c b/source4/torture/rpc/dssync.c index 00617f4072..989a1faf27 100644 --- a/source4/torture/rpc/dssync.c +++ b/source4/torture/rpc/dssync.c @@ -288,16 +288,17 @@ static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx) search.in.dest_address = ctx->drsuapi_binding->host; search.in.dest_port = lp_cldap_port(tctx->lp_ctx); search.in.acct_control = -1; - search.in.version = 6; + search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX; + search.in.map_response = true; status = cldap_netlogon(cldap, ctx, &search); if (!NT_STATUS_IS_OK(status)) { const char *errstr = nt_errstr(status); ctx->site_name = talloc_asprintf(ctx, "%s", "Default-First-Site-Name"); printf("cldap_netlogon() returned %s. Defaulting to Site-Name: %s\n", errstr, ctx->site_name); } else { - ctx->site_name = talloc_steal(ctx, search.out.netlogon.logon5.client_site); + ctx->site_name = talloc_steal(ctx, search.out.netlogon.nt5_ex.client_site); printf("cldap_netlogon() returned Client Site-Name: %s.\n",ctx->site_name); - printf("cldap_netlogon() returned Server Site-Name: %s.\n",search.out.netlogon.logon5.server_site); + printf("cldap_netlogon() returned Server Site-Name: %s.\n",search.out.netlogon.nt5_ex.server_site); } return ret; diff --git a/source4/torture/rpc/schannel.c b/source4/torture/rpc/schannel.c index f0279f0d04..a8f70b2ea9 100644 --- a/source4/torture/rpc/schannel.c +++ b/source4/torture/rpc/schannel.c @@ -738,6 +738,70 @@ bool torture_rpc_schannel_bench1(struct torture_context *torture) } torture_assert_ntstatus_ok(torture, s->error, "Failed establish a connect"); + /* + * Change the workstation password after establishing the netlogon + * schannel connections to prove that existing connections are not + * affected by a wks pwchange. + */ + + { + struct netr_ServerPasswordSet pwset; + char *password = generate_random_str(s->join_ctx1, 8); + struct creds_CredentialState *creds_state; + struct dcerpc_pipe *net_pipe; + + status = dcerpc_pipe_connect_b(s, &net_pipe, s->b, + &ndr_table_netlogon, + s->wks_creds1, + torture->ev, torture->lp_ctx); + + torture_assert_ntstatus_ok(torture, status, + "dcerpc_pipe_connect_b failed"); + + pwset.in.server_name = talloc_asprintf( + net_pipe, "\\\\%s", dcerpc_server_name(net_pipe)); + pwset.in.computer_name = + cli_credentials_get_workstation(s->wks_creds1); + pwset.in.account_name = talloc_asprintf( + net_pipe, "%s$", pwset.in.computer_name); + pwset.in.secure_channel_type = SEC_CHAN_WKSTA; + E_md4hash(password, pwset.in.new_password.hash); + + creds_state = cli_credentials_get_netlogon_creds( + s->wks_creds1); + creds_des_encrypt(creds_state, &pwset.in.new_password); + creds_client_authenticator(creds_state, &pwset.in.credential); + + status = dcerpc_netr_ServerPasswordSet(net_pipe, torture, &pwset); + torture_assert_ntstatus_ok(torture, status, + "ServerPasswordSet failed"); + + if (!creds_client_check(creds_state, + &pwset.out.return_authenticator.cred)) { + printf("Credential chaining failed\n"); + } + + cli_credentials_set_password(s->wks_creds1, password, + CRED_SPECIFIED); + + talloc_free(net_pipe); + + /* Just as a test, connect with the new creds */ + + talloc_free(s->wks_creds1->netlogon_creds); + s->wks_creds1->netlogon_creds = NULL; + + status = dcerpc_pipe_connect_b(s, &net_pipe, s->b, + &ndr_table_netlogon, + s->wks_creds1, + torture->ev, torture->lp_ctx); + + torture_assert_ntstatus_ok(torture, status, + "dcerpc_pipe_connect_b failed"); + + talloc_free(net_pipe); + } + torture_comment(torture, "Start looping LogonSamLogonEx on %d connections for %d secs\n", s->nprocs, s->timelimit); for (i=0; i < s->nprocs; i++) { diff --git a/source4/torture/smb2/config.mk b/source4/torture/smb2/config.mk index 4e0cac0029..11c4e1fa2c 100644 --- a/source4/torture/smb2/config.mk +++ b/source4/torture/smb2/config.mk @@ -4,14 +4,12 @@ [MODULE::TORTURE_SMB2] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_smb2_init -PRIVATE_PROTO_HEADER = \ - proto.h PRIVATE_DEPENDENCIES = \ LIBCLI_SMB2 POPT_CREDENTIALS # End SUBSYSTEM TORTURE_SMB2 ################################# -TORTURE_SMB2_OBJ_FILES = $(addprefix torture/smb2/, \ +TORTURE_SMB2_OBJ_FILES = $(addprefix $(torturesrcdir)/smb2/, \ connect.o \ scan.o \ util.o \ @@ -24,3 +22,5 @@ TORTURE_SMB2_OBJ_FILES = $(addprefix torture/smb2/, \ persistent_handles.o \ oplocks.o) + +$(eval $(call proto_header_template,$(torturesrcdir)/smb2/proto.h,$(TORTURE_SMB2_OBJ_FILES:.o=.c))) diff --git a/source4/torture/smb2/oplocks.c b/source4/torture/smb2/oplocks.c index b0a1b31d1f..9a06ae1f19 100644 --- a/source4/torture/smb2/oplocks.c +++ b/source4/torture/smb2/oplocks.c @@ -99,7 +99,7 @@ static bool torture_oplock_handler(struct smb2_transport *transport, req = smb2_break_send(tree, &break_info.br); req->async.fn = torture_oplock_break_callback; - req->async.private = NULL; + req->async.private_data = NULL; return true; } diff --git a/source4/torture/smb2/util.c b/source4/torture/smb2/util.c index 6ac3926c98..af4f345104 100644 --- a/source4/torture/smb2/util.c +++ b/source4/torture/smb2/util.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/smb2/smb2.h" #include "libcli/smb2/smb2_calls.h" +#include "libcli/smb_composite/smb_composite.h" #include "lib/cmdline/popt_common.h" #include "lib/events/events.h" #include "system/time.h" @@ -34,47 +35,6 @@ /* - close a handle with SMB2 -*/ -NTSTATUS smb2_util_close(struct smb2_tree *tree, struct smb2_handle h) -{ - struct smb2_close c; - - ZERO_STRUCT(c); - c.in.file.handle = h; - - return smb2_close(tree, &c); -} - -/* - unlink a file with SMB2 -*/ -NTSTATUS smb2_util_unlink(struct smb2_tree *tree, const char *fname) -{ - struct smb2_create io; - NTSTATUS status; - - ZERO_STRUCT(io); - io.in.desired_access = SEC_RIGHTS_FILE_ALL; - io.in.file_attributes = FILE_ATTRIBUTE_NORMAL; - io.in.create_disposition = NTCREATEX_DISP_OPEN; - io.in.share_access = - NTCREATEX_SHARE_ACCESS_DELETE| - NTCREATEX_SHARE_ACCESS_READ| - NTCREATEX_SHARE_ACCESS_WRITE; - io.in.create_options = NTCREATEX_OPTIONS_DELETE_ON_CLOSE; - io.in.fname = fname; - - status = smb2_create(tree, tree, &io); - if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { - return NT_STATUS_OK; - } - NT_STATUS_NOT_OK_RETURN(status); - - return smb2_util_close(tree, io.out.file.handle); -} - -/* write to a file on SMB2 */ NTSTATUS smb2_util_write(struct smb2_tree *tree, diff --git a/source4/torture/winbind/config.mk b/source4/torture/winbind/config.mk index ee8ff950a6..15bc51daba 100644 --- a/source4/torture/winbind/config.mk +++ b/source4/torture/winbind/config.mk @@ -4,12 +4,12 @@ [MODULE::TORTURE_WINBIND] SUBSYSTEM = smbtorture INIT_FUNCTION = torture_winbind_init -PRIVATE_PROTO_HEADER = \ - proto.h PRIVATE_DEPENDENCIES = \ LIBWINBIND-CLIENT # End SUBSYSTEM TORTURE_WINBIND ################################# -TORTURE_WINBIND_OBJ_FILES = $(addprefix torture/winbind/, winbind.o struct_based.o) +TORTURE_WINBIND_OBJ_FILES = $(addprefix $(torturesrcdir)/winbind/, winbind.o struct_based.o) + +$(eval $(call proto_header_template,$(torturesrcdir)/winbind/proto.h,$(TORTURE_WINBIND_OBJ_FILES:.o=.c))) |