2 Unix SMB/CIFS implementation.
4 generic testing tool - version with SMB2 support
6 Copyright (C) Andrew Tridgell 2003-2008
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "lib/cmdline/popt_common.h"
24 #include "lib/events/events.h"
25 #include "system/time.h"
26 #include "system/filesys.h"
27 #include "libcli/raw/request.h"
28 #include "libcli/libcli.h"
29 #include "libcli/raw/libcliraw.h"
30 #include "libcli/smb2/smb2.h"
31 #include "libcli/smb2/smb2_calls.h"
32 #include "librpc/gen_ndr/security.h"
33 #include "auth/credentials/credentials.h"
34 #include "libcli/resolve/resolve.h"
35 #include "auth/gensec/gensec.h"
36 #include "param/param.h"
37 #include "dynconfig.h"
43 static struct gentest_options {
47 bool analyze_continuous;
48 uint_t max_open_handles;
52 char **ignore_patterns;
53 const char *seeds_file;
54 bool use_preset_seeds;
58 /* mapping between open handles on the server and local handles */
62 struct smb2_handle server_handle[NSERVERS];
65 static uint_t num_open_handles;
67 /* state information for the servers. We open NINSTANCES connections to
70 struct smb2_tree *tree[NINSTANCES];
73 struct cli_credentials *credentials;
76 /* the seeds and flags for each operation */
83 /* oplock break info */
86 struct smb2_handle server_handle;
90 } oplocks[NSERVERS][NINSTANCES];
92 /* change notify reply info */
96 union smb_notify notify;
97 } notifies[NSERVERS][NINSTANCES];
99 /* info relevant to the current operation */
108 static struct smb2_handle bad_smb2_handle;
111 #define BAD_HANDLE 0xFFFE
113 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
114 static void idle_func(struct smb2_transport *transport, void *private);
117 check if a string should be ignored. This is used as the basis
118 for all error ignore settings
120 static bool ignore_pattern(const char *str)
123 if (!options.ignore_patterns) return false;
125 for (i=0;options.ignore_patterns[i];i++) {
126 if (strcmp(options.ignore_patterns[i], str) == 0 ||
127 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
128 DEBUG(2,("Ignoring '%s'\n", str));
135 /*****************************************************
136 connect to the servers
137 *******************************************************/
138 static bool connect_servers_fast(void)
142 /* close all open files */
143 for (h=0;h<options.max_open_handles;h++) {
144 if (!open_handles[h].active) continue;
145 for (i=0;i<NSERVERS;i++) {
146 NTSTATUS status = smb2_util_close(servers[i].tree[open_handles[h].instance],
147 open_handles[h].server_handle[i]);
148 if (NT_STATUS_IS_ERR(status)) {
151 open_handles[h].active = false;
161 /*****************************************************
162 connect to the servers
163 *******************************************************/
164 static bool connect_servers(struct event_context *ev,
165 struct loadparm_context *lp_ctx)
169 if (options.fast_reconnect && servers[0].tree[0]) {
170 if (connect_servers_fast()) {
175 /* close any existing connections */
176 for (i=0;i<NSERVERS;i++) {
177 for (j=0;j<NINSTANCES;j++) {
178 if (servers[i].tree[j]) {
179 smb2_tdis(servers[i].tree[j]);
180 talloc_free(servers[i].tree[j]);
181 servers[i].tree[j] = NULL;
186 for (i=0;i<NSERVERS;i++) {
187 for (j=0;j<NINSTANCES;j++) {
189 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
190 servers[i].server_name, servers[i].share_name,
191 servers[i].credentials->username, j);
193 cli_credentials_set_workstation(servers[i].credentials,
194 "gentest", CRED_SPECIFIED);
196 status = smb2_connect(NULL, servers[i].server_name,
197 servers[i].share_name,
198 lp_resolve_context(lp_ctx),
199 servers[i].credentials,
202 if (!NT_STATUS_IS_OK(status)) {
203 printf("Failed to connect to \\\\%s\\%s - %s\n",
204 servers[i].server_name, servers[i].share_name,
209 // smb2_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
210 smb2_transport_idle_handler(servers[i].tree[j]->session->transport, idle_func, 50000, NULL);
218 work out the time skew between the servers - be conservative
220 static uint_t time_skew(void)
223 ret = labs(servers[0].tree[0]->session->transport->negotiate.system_time -
224 servers[1].tree[0]->session->transport->negotiate.system_time);
229 static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_handle *h2)
231 return memcmp(h1, h2, sizeof(struct smb2_handle)) == 0;
235 turn a server handle into a local handle
237 static uint_t fnum_to_handle(int server, int instance, struct smb2_handle server_handle)
240 for (i=0;i<options.max_open_handles;i++) {
241 if (!open_handles[i].active ||
242 instance != open_handles[i].instance) continue;
243 if (smb2_handle_equal(&open_handles[i].server_handle[server], &server_handle)) {
247 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
253 add some newly opened handles
255 static void gen_add_handle(int instance, const char *name, struct smb2_handle handles[NSERVERS])
258 for (h=0;h<options.max_open_handles;h++) {
259 if (!open_handles[h].active) break;
261 if (h == options.max_open_handles) {
262 /* we have to force close a random handle */
263 h = random() % options.max_open_handles;
264 for (i=0;i<NSERVERS;i++) {
266 status = smb2_util_close(servers[i].tree[open_handles[h].instance],
267 open_handles[h].server_handle[i]);
268 if (NT_STATUS_IS_ERR(status)) {
269 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
273 printf("Recovered handle %d\n", h);
276 for (i=0;i<NSERVERS;i++) {
277 open_handles[h].server_handle[i] = handles[i];
278 open_handles[h].instance = instance;
279 open_handles[h].active = true;
280 open_handles[h].name = name;
284 printf("OPEN num_open_handles=%d h=%d (%s)\n",
285 num_open_handles, h, name);
289 remove a closed handle
291 static void gen_remove_handle(int instance, struct smb2_handle handles[NSERVERS])
294 for (h=0;h<options.max_open_handles;h++) {
295 if (instance == open_handles[h].instance &&
296 smb2_handle_equal(&open_handles[h].server_handle[0], &handles[0])) {
297 open_handles[h].active = false;
299 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
301 open_handles[h].name);
305 printf("Removing invalid handle!?\n");
310 return true with 'chance' probability as a percentage
312 static bool gen_chance(uint_t chance)
314 return ((random() % 100) <= chance);
318 map an internal handle number to a server handle
320 static struct smb2_handle gen_lookup_handle(int server, uint16_t handle)
322 if (handle == BAD_HANDLE) return bad_smb2_handle;
323 return open_handles[handle].server_handle[server];
329 static uint16_t gen_fnum(int instance)
334 if (gen_chance(20)) return BAD_HANDLE;
336 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
337 h = random() % options.max_open_handles;
338 if (open_handles[h].active &&
339 open_handles[h].instance == instance) {
347 return a file handle, but skewed so we don't close the last
348 couple of handles too readily
350 static uint16_t gen_fnum_close(int instance)
352 if (num_open_handles < 3) {
353 if (gen_chance(80)) return BAD_HANDLE;
356 return gen_fnum(instance);
360 generate an integer in a specified range
362 static int gen_int_range(uint_t min, uint_t max)
365 return min + (r % (1+max-min));
369 return a fnum for use as a root fid
370 be careful to call GEN_SET_FNUM() when you use this!
372 static uint16_t gen_root_fid(int instance)
374 if (gen_chance(5)) return gen_fnum(instance);
379 generate a file offset
381 static int gen_offset(void)
383 if (gen_chance(20)) return 0;
384 return gen_int_range(0, 1024*1024);
390 static int gen_io_count(void)
392 if (gen_chance(20)) return 0;
393 return gen_int_range(0, 4096);
399 static const char *gen_fname(void)
401 const char *names[] = {"gentest\\gentest.dat",
406 "gentest\\foo4:teststream1",
407 "gentest\\foo4:teststream2",
409 "gentest\\foo5.exe:teststream3",
410 "gentest\\foo5.exe:teststream4",
413 "gentest\\blah\\blergh.txt",
414 "gentest\\blah\\blergh2",
415 "gentest\\blah\\blergh3.txt",
416 "gentest\\blah\\blergh4",
417 "gentest\\blah\\blergh5.txt",
418 "gentest\\blah\\blergh5",
421 /* this causes problem with w2k3 */
424 "gentest\\a_very_long_name.bin",
430 i = gen_int_range(0, ARRAY_SIZE(names)-1);
431 } while (ignore_pattern(names[i]));
437 generate a filename with a higher chance of choosing an already
440 static const char *gen_fname_open(int instance)
443 h = gen_fnum(instance);
444 if (h == BAD_HANDLE) {
447 return open_handles[h].name;
451 generate a wildcard pattern
453 static const char *gen_pattern(void)
456 const char *names[] = {"gentest\\*.dat",
459 "gentest\\blah\\*.*",
463 if (gen_chance(50)) return gen_fname();
466 i = gen_int_range(0, ARRAY_SIZE(names)-1);
467 } while (ignore_pattern(names[i]));
472 static uint32_t gen_bits_levels(int nlevels, ...)
478 va_start(ap, nlevels);
479 for (i=0;i<nlevels;i++) {
480 pct = va_arg(ap, uint32_t);
481 mask = va_arg(ap, uint32_t);
482 if (pct == 100 || gen_chance(pct)) {
484 return mask & random();
494 static uint32_t gen_bits_mask(uint_t mask)
496 uint_t ret = random();
501 generate a bitmask with high probability of the first mask
502 and low of the second
504 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
506 if (gen_chance(10)) return gen_bits_mask(mask2);
507 return gen_bits_mask(mask1);
513 static bool gen_bool(void)
515 return gen_bits_mask2(0x1, 0xFF);
519 generate ntrename flags
521 static uint16_t gen_rename_flags(void)
523 if (gen_chance(30)) return RENAME_FLAG_RENAME;
524 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
525 if (gen_chance(30)) return RENAME_FLAG_COPY;
526 return gen_bits_mask(0xFFFF);
531 return a lockingx lock mode
533 static uint16_t gen_lock_mode(void)
535 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
536 if (gen_chance(20)) return gen_bits_mask(0x1F);
537 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
543 static uint16_t gen_pid(void)
545 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
550 generate a lock count
552 static off_t gen_lock_count(void)
554 return gen_int_range(0, 3);
558 generate a ntcreatex flags field
560 static uint32_t gen_ntcreatex_flags(void)
562 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
563 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
567 generate a NT access mask
569 static uint32_t gen_access_mask(void)
571 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
572 if (gen_chance(20)) return SEC_FILE_ALL;
573 return gen_bits_mask(0xFFFFFFFF);
577 generate a ntcreatex create options bitfield
579 static uint32_t gen_create_options(void)
581 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
582 if (gen_chance(50)) return 0;
583 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
587 generate a ntcreatex open disposition
589 static uint32_t gen_open_disp(void)
591 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
592 return gen_int_range(0, 5);
596 generate an openx open mode
598 static uint16_t gen_openx_mode(void)
600 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
601 if (gen_chance(20)) return gen_bits_mask(0xFF);
602 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
606 generate an openx flags field
608 static uint16_t gen_openx_flags(void)
610 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
611 return gen_bits_mask(0x7);
615 generate an openx open function
617 static uint16_t gen_openx_func(void)
619 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
620 return gen_bits_mask(0x13);
624 generate a file attrib combination
626 static uint32_t gen_attrib(void)
628 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
629 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
633 generate a unix timestamp
635 static time_t gen_timet(void)
637 if (gen_chance(30)) return 0;
638 return (time_t)random();
642 generate a unix timestamp
644 static NTTIME gen_nttime(void)
647 unix_to_nt_time(&ret, gen_timet());
652 generate a milliseconds protocol timeout
654 static uint32_t gen_timeout(void)
656 if (gen_chance(98)) return 0;
657 return random() % 50;
661 generate a file allocation size
663 static uint_t gen_alloc_size(void)
667 if (gen_chance(30)) return 0;
669 ret = random() % 4*1024*1024;
670 /* give a high chance of a round number */
671 if (gen_chance(60)) {
672 ret &= ~(1024*1024 - 1);
678 generate an ea_struct
680 static struct ea_struct gen_ea_struct(void)
683 const char *names[] = {"EAONE",
688 "AVERYLONGATTRIBUTENAME"};
689 const char *values[] = {"VALUE1",
694 "ASOMEWHATLONGERATTRIBUTEVALUE"};
700 i = gen_int_range(0, ARRAY_SIZE(names)-1);
701 } while (ignore_pattern(names[i]));
703 ea.name.s = names[i];
706 i = gen_int_range(0, ARRAY_SIZE(values)-1);
707 } while (ignore_pattern(values[i]));
709 ea.value = data_blob(values[i], strlen(values[i]));
711 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
718 the idle function tries to cope with getting an oplock break on a connection, and
719 an operation on another connection blocking until that break is acked
720 we check for operations on all transports in the idle function
722 static void idle_func(struct smb2_transport *transport, void *private)
725 for (i=0;i<NSERVERS;i++) {
726 for (j=0;j<NINSTANCES;j++) {
727 if (servers[i].tree[j] &&
728 transport != servers[i].tree[j]->session->transport) {
729 // smb2_transport_process(servers[i].tree[j]->session->transport);
738 compare NTSTATUS, using checking ignored patterns
740 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
742 if (NT_STATUS_EQUAL(status1, status2)) return true;
744 /* one code being an error and the other OK is always an error */
745 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return false;
747 /* if we are ignoring one of the status codes then consider this a match */
748 if (ignore_pattern(nt_errstr(status1)) ||
749 ignore_pattern(nt_errstr(status2))) {
757 check for pending packets on all connections
759 static void check_pending(void)
765 for (j=0;j<NINSTANCES;j++) {
766 for (i=0;i<NSERVERS;i++) {
767 // smb2_transport_process(servers[i].tree[j]->session->transport);
773 check that the same oplock breaks have been received by all instances
775 static bool check_oplocks(const char *call)
784 for (j=0;j<NINSTANCES;j++) {
785 for (i=1;i<NSERVERS;i++) {
786 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
787 oplocks[0][j].handle != oplocks[i][j].handle ||
788 oplocks[0][j].level != oplocks[i][j].level) {
789 if (tries++ < 10) goto again;
790 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
791 oplocks[0][j].got_break,
792 oplocks[0][j].handle,
794 oplocks[i][j].got_break,
795 oplocks[i][j].handle,
796 oplocks[i][j].level);
802 /* if we got a break and closed then remove the handle */
803 for (j=0;j<NINSTANCES;j++) {
804 if (oplocks[0][j].got_break &&
805 oplocks[0][j].do_close) {
806 uint16_t fnums[NSERVERS];
807 for (i=0;i<NSERVERS;i++) {
808 fnums[i] = oplocks[i][j].fnum;
810 gen_remove_handle(j, fnums);
820 check that the same change notify info has been received by all instances
822 static bool check_notifies(const char *call)
831 for (j=0;j<NINSTANCES;j++) {
832 for (i=1;i<NSERVERS;i++) {
834 union smb_notify not1, not2;
836 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
837 if (tries++ < 10) goto again;
838 printf("Notify count inconsistent %d %d\n",
839 notifies[0][j].notify_count,
840 notifies[i][j].notify_count);
844 if (notifies[0][j].notify_count == 0) continue;
846 if (!NT_STATUS_EQUAL(notifies[0][j].status,
847 notifies[i][j].status)) {
848 printf("Notify status mismatch - %s - %s\n",
849 nt_errstr(notifies[0][j].status),
850 nt_errstr(notifies[i][j].status));
854 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
858 not1 = notifies[0][j].notify;
859 not2 = notifies[i][j].notify;
861 for (n=0;n<not1.nttrans.out.num_changes;n++) {
862 if (not1.nttrans.out.changes[n].action !=
863 not2.nttrans.out.changes[n].action) {
864 printf("Notify action %d inconsistent %d %d\n", n,
865 not1.nttrans.out.changes[n].action,
866 not2.nttrans.out.changes[n].action);
869 if (strcmp(not1.nttrans.out.changes[n].name.s,
870 not2.nttrans.out.changes[n].name.s)) {
871 printf("Notify name %d inconsistent %s %s\n", n,
872 not1.nttrans.out.changes[n].name.s,
873 not2.nttrans.out.changes[n].name.s);
876 if (not1.nttrans.out.changes[n].name.private_length !=
877 not2.nttrans.out.changes[n].name.private_length) {
878 printf("Notify name length %d inconsistent %d %d\n", n,
879 not1.nttrans.out.changes[n].name.private_length,
880 not2.nttrans.out.changes[n].name.private_length);
887 ZERO_STRUCT(notifies);
893 #define GEN_COPY_PARM do { \
895 for (i=1;i<NSERVERS;i++) { \
900 #define GEN_CALL(call) do { \
902 ZERO_STRUCT(oplocks); \
903 ZERO_STRUCT(notifies); \
904 for (i=0;i<NSERVERS;i++) { \
905 struct smb2_tree *tree = servers[i].tree[instance]; \
908 current_op.status = status[0]; \
909 for (i=1;i<NSERVERS;i++) { \
910 if (!compare_status(status[i], status[0])) { \
911 printf("status different in %s - %s %s\n", #call, \
912 nt_errstr(status[0]), nt_errstr(status[i])); \
916 if (!check_oplocks(#call)) return false; \
917 if (!check_notifies(#call)) return false; \
918 if (!NT_STATUS_IS_OK(status[0])) { \
923 #define ADD_HANDLE(name, field) do { \
924 struct smb2_handle handles[NSERVERS]; \
926 for (i=0;i<NSERVERS;i++) { \
927 handles[i] = parm[i].field; \
929 gen_add_handle(instance, name, handles); \
932 #define REMOVE_HANDLE(field) do { \
933 struct smb2_handle handles[NSERVERS]; \
935 for (i=0;i<NSERVERS;i++) { \
936 handles[i] = parm[i].field; \
938 gen_remove_handle(instance, handles); \
941 #define GEN_SET_FNUM(field) do { \
943 for (i=0;i<NSERVERS;i++) { \
944 parm[i].field = gen_lookup_handle(i, parm[i].field.data[0]); \
948 #define CHECK_EQUAL(field) do { \
949 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
950 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
951 (int)parm[0].field, (int)parm[1].field); \
956 #define CHECK_WSTR_EQUAL(field) do { \
957 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
958 printf("%s is NULL!\n", #field); \
961 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
962 printf("Mismatch in %s - %s %s\n", #field, \
963 parm[0].field.s, parm[1].field.s); \
966 CHECK_EQUAL(field.private_length); \
969 #define CHECK_BLOB_EQUAL(field) do { \
970 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
971 printf("Mismatch in %s\n", #field); \
974 CHECK_EQUAL(field.length); \
977 #define CHECK_TIMES_EQUAL(field) do { \
978 if (labs(parm[0].field - parm[1].field) > time_skew() && \
979 !ignore_pattern(#field)) { \
980 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
981 (int)parm[0].field, (int)parm[1].field); \
986 #define CHECK_NTTIMES_EQUAL(field) do { \
987 if (labs(nt_time_to_unix(parm[0].field) - \
988 nt_time_to_unix(parm[1].field)) > time_skew() && \
989 !ignore_pattern(#field)) { \
990 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
991 (int)nt_time_to_unix(parm[0].field), \
992 (int)nt_time_to_unix(parm[1].field)); \
998 generate ntcreatex operations
1000 static bool handler_ntcreatex(int instance)
1002 struct smb2_create parm[NSERVERS];
1003 NTSTATUS status[NSERVERS];
1005 ZERO_STRUCT(parm[0]);
1006 parm[0].in.security_flags = gen_bits_levels(3, 70, 0x0, 70, 0x3, 100, 0xFF);
1007 parm[0].in.oplock_level = gen_bits_levels(3, 70, 0x0, 70, 0x9, 100, 0xFF);
1008 parm[0].in.impersonation_level = gen_bits_levels(3, 70, 0x0, 70, 0x3, 100, 0xFFFFFFFF);
1009 parm[0].in.create_flags = gen_bits_levels(2, 80, 0x0, 100, 0xFFFFFFFF);
1010 if (gen_chance(2)) {
1011 parm[0].in.create_flags |= gen_bits_mask(0xFFFFFFFF);
1013 parm[0].in.reserved = gen_bits_levels(2, 80, 0x0, 100, 0xFFFFFFFF);
1014 if (gen_chance(2)) {
1015 parm[0].in.reserved |= gen_bits_mask(0xFFFFFFFF);
1017 parm[0].in.desired_access = gen_access_mask();
1018 parm[0].in.file_attributes = gen_attrib();
1019 parm[0].in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1020 parm[0].in.create_disposition = gen_open_disp();
1021 parm[0].in.create_options = gen_create_options();
1022 parm[0].in.fname = gen_fname_open(instance);
1024 if (!options.use_oplocks) {
1025 /* mask out oplocks */
1026 parm[0].in.oplock_level = 0;
1030 GEN_CALL(smb2_create(tree, current_op.mem_ctx, &parm[i]));
1032 CHECK_EQUAL(out.oplock_level);
1033 CHECK_EQUAL(out.reserved);
1034 CHECK_EQUAL(out.create_action);
1035 CHECK_NTTIMES_EQUAL(out.create_time);
1036 CHECK_NTTIMES_EQUAL(out.access_time);
1037 CHECK_NTTIMES_EQUAL(out.write_time);
1038 CHECK_NTTIMES_EQUAL(out.change_time);
1039 CHECK_EQUAL(out.alloc_size);
1040 CHECK_EQUAL(out.size);
1041 CHECK_EQUAL(out.file_attr);
1042 CHECK_EQUAL(out.reserved2);
1044 /* ntcreatex creates a new file handle */
1045 ADD_HANDLE(parm[0].in.fname, out.file.handle);
1051 generate close operations
1053 static bool handler_close(int instance)
1055 struct smb2_close parm[NSERVERS];
1056 NTSTATUS status[NSERVERS];
1058 ZERO_STRUCT(parm[0]);
1059 parm[0].in.file.handle.data[0] = gen_fnum_close(instance);
1060 parm[0].in.flags = gen_bits_mask2(0x1, 0xFFFF);
1063 GEN_SET_FNUM(in.file.handle);
1064 GEN_CALL(smb2_close(tree, &parm[i]));
1066 CHECK_EQUAL(out.flags);
1067 CHECK_EQUAL(out._pad);
1068 CHECK_NTTIMES_EQUAL(out.create_time);
1069 CHECK_NTTIMES_EQUAL(out.access_time);
1070 CHECK_NTTIMES_EQUAL(out.write_time);
1071 CHECK_NTTIMES_EQUAL(out.change_time);
1072 CHECK_EQUAL(out.alloc_size);
1073 CHECK_EQUAL(out.size);
1074 CHECK_EQUAL(out.file_attr);
1076 REMOVE_HANDLE(in.file.handle);
1083 generate read operations
1085 static bool handler_read(int instance)
1087 union smb_read parm[NSERVERS];
1088 NTSTATUS status[NSERVERS];
1090 parm[0].readx.level = RAW_READ_READX;
1091 parm[0].readx.in.file.fnum = gen_fnum(instance);
1092 parm[0].readx.in.offset = gen_offset();
1093 parm[0].readx.in.mincnt = gen_io_count();
1094 parm[0].readx.in.maxcnt = gen_io_count();
1095 parm[0].readx.in.remaining = gen_io_count();
1096 parm[0].readx.in.read_for_execute = gen_bool();
1097 parm[0].readx.out.data = talloc_array(current_op.mem_ctx, uint8_t,
1098 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1101 GEN_SET_FNUM(readx.in.file.fnum);
1102 GEN_CALL(smb_raw_read(tree, &parm[i]));
1104 CHECK_EQUAL(readx.out.remaining);
1105 CHECK_EQUAL(readx.out.compaction_mode);
1106 CHECK_EQUAL(readx.out.nread);
1112 generate write operations
1114 static bool handler_write(int instance)
1116 union smb_write parm[NSERVERS];
1117 NTSTATUS status[NSERVERS];
1119 parm[0].writex.level = RAW_WRITE_WRITEX;
1120 parm[0].writex.in.file.fnum = gen_fnum(instance);
1121 parm[0].writex.in.offset = gen_offset();
1122 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1123 parm[0].writex.in.remaining = gen_io_count();
1124 parm[0].writex.in.count = gen_io_count();
1125 parm[0].writex.in.data = talloc_zero_array(current_op.mem_ctx, uint8_t, parm[0].writex.in.count);
1128 GEN_SET_FNUM(writex.in.file.fnum);
1129 GEN_CALL(smb_raw_write(tree, &parm[i]));
1131 CHECK_EQUAL(writex.out.nwritten);
1132 CHECK_EQUAL(writex.out.remaining);
1138 generate lockingx operations
1140 static bool handler_lock(int instance)
1142 union smb_lock parm[NSERVERS];
1143 NTSTATUS status[NSERVERS];
1146 parm[0].lockx.level = RAW_LOCK_LOCKX;
1147 parm[0].lockx.in.file.fnum = gen_fnum(instance);
1148 parm[0].lockx.in.mode = gen_lock_mode();
1149 parm[0].lockx.in.timeout = gen_timeout();
1151 /* make sure we don't accidentially generate an oplock
1152 break ack - otherwise the server can just block forever */
1153 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1154 parm[0].lockx.in.lock_cnt = gen_lock_count();
1155 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1156 } while (nlocks == 0);
1159 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1160 struct smb_lock_entry,
1162 for (n=0;n<nlocks;n++) {
1163 parm[0].lockx.in.locks[n].pid = gen_pid();
1164 parm[0].lockx.in.locks[n].offset = gen_offset();
1165 parm[0].lockx.in.locks[n].count = gen_io_count();
1170 GEN_SET_FNUM(lockx.in.file.fnum);
1171 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1177 generate a fileinfo query structure
1179 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1182 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1184 enum smb_fileinfo_level level;
1187 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1188 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1189 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1190 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1191 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1192 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1193 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1194 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1195 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1196 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1199 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1200 } while (ignore_pattern(levels[i].name));
1202 info->generic.level = levels[i].level;
1206 compare returned fileinfo structures
1208 static bool cmp_fileinfo(int instance,
1209 union smb_fileinfo parm[NSERVERS],
1210 NTSTATUS status[NSERVERS])
1214 switch (parm[0].generic.level) {
1215 case RAW_FILEINFO_GENERIC:
1218 case RAW_FILEINFO_GETATTR:
1219 CHECK_EQUAL(getattr.out.attrib);
1220 CHECK_EQUAL(getattr.out.size);
1221 CHECK_TIMES_EQUAL(getattr.out.write_time);
1224 case RAW_FILEINFO_GETATTRE:
1225 CHECK_TIMES_EQUAL(getattre.out.create_time);
1226 CHECK_TIMES_EQUAL(getattre.out.access_time);
1227 CHECK_TIMES_EQUAL(getattre.out.write_time);
1228 CHECK_EQUAL(getattre.out.size);
1229 CHECK_EQUAL(getattre.out.alloc_size);
1230 CHECK_EQUAL(getattre.out.attrib);
1233 case RAW_FILEINFO_STANDARD:
1234 CHECK_TIMES_EQUAL(standard.out.create_time);
1235 CHECK_TIMES_EQUAL(standard.out.access_time);
1236 CHECK_TIMES_EQUAL(standard.out.write_time);
1237 CHECK_EQUAL(standard.out.size);
1238 CHECK_EQUAL(standard.out.alloc_size);
1239 CHECK_EQUAL(standard.out.attrib);
1242 case RAW_FILEINFO_EA_SIZE:
1243 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1244 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1245 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1246 CHECK_EQUAL(ea_size.out.size);
1247 CHECK_EQUAL(ea_size.out.alloc_size);
1248 CHECK_EQUAL(ea_size.out.attrib);
1249 CHECK_EQUAL(ea_size.out.ea_size);
1252 case RAW_FILEINFO_ALL_EAS:
1253 CHECK_EQUAL(all_eas.out.num_eas);
1254 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1255 CHECK_EQUAL(all_eas.out.eas[i].flags);
1256 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1257 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1261 case RAW_FILEINFO_IS_NAME_VALID:
1264 case RAW_FILEINFO_BASIC_INFO:
1265 case RAW_FILEINFO_BASIC_INFORMATION:
1266 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1267 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1268 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1269 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1270 CHECK_EQUAL(basic_info.out.attrib);
1273 case RAW_FILEINFO_STANDARD_INFO:
1274 case RAW_FILEINFO_STANDARD_INFORMATION:
1275 CHECK_EQUAL(standard_info.out.alloc_size);
1276 CHECK_EQUAL(standard_info.out.size);
1277 CHECK_EQUAL(standard_info.out.nlink);
1278 CHECK_EQUAL(standard_info.out.delete_pending);
1279 CHECK_EQUAL(standard_info.out.directory);
1282 case RAW_FILEINFO_EA_INFO:
1283 case RAW_FILEINFO_EA_INFORMATION:
1284 CHECK_EQUAL(ea_info.out.ea_size);
1287 case RAW_FILEINFO_NAME_INFO:
1288 case RAW_FILEINFO_NAME_INFORMATION:
1289 CHECK_WSTR_EQUAL(name_info.out.fname);
1292 case RAW_FILEINFO_ALL_INFO:
1293 case RAW_FILEINFO_ALL_INFORMATION:
1294 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1295 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1296 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1297 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1298 CHECK_EQUAL(all_info.out.attrib);
1299 CHECK_EQUAL(all_info.out.alloc_size);
1300 CHECK_EQUAL(all_info.out.size);
1301 CHECK_EQUAL(all_info.out.nlink);
1302 CHECK_EQUAL(all_info.out.delete_pending);
1303 CHECK_EQUAL(all_info.out.directory);
1304 CHECK_EQUAL(all_info.out.ea_size);
1305 CHECK_WSTR_EQUAL(all_info.out.fname);
1308 case RAW_FILEINFO_ALT_NAME_INFO:
1309 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1310 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1313 case RAW_FILEINFO_STREAM_INFO:
1314 case RAW_FILEINFO_STREAM_INFORMATION:
1315 CHECK_EQUAL(stream_info.out.num_streams);
1316 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1317 CHECK_EQUAL(stream_info.out.streams[i].size);
1318 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1319 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1323 case RAW_FILEINFO_COMPRESSION_INFO:
1324 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1325 CHECK_EQUAL(compression_info.out.compressed_size);
1326 CHECK_EQUAL(compression_info.out.format);
1327 CHECK_EQUAL(compression_info.out.unit_shift);
1328 CHECK_EQUAL(compression_info.out.chunk_shift);
1329 CHECK_EQUAL(compression_info.out.cluster_shift);
1332 case RAW_FILEINFO_INTERNAL_INFORMATION:
1333 CHECK_EQUAL(internal_information.out.file_id);
1336 case RAW_FILEINFO_ACCESS_INFORMATION:
1337 CHECK_EQUAL(access_information.out.access_flags);
1340 case RAW_FILEINFO_POSITION_INFORMATION:
1341 CHECK_EQUAL(position_information.out.position);
1344 case RAW_FILEINFO_MODE_INFORMATION:
1345 CHECK_EQUAL(mode_information.out.mode);
1348 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1349 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1352 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1353 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1354 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1355 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1356 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1357 CHECK_EQUAL(network_open_information.out.alloc_size);
1358 CHECK_EQUAL(network_open_information.out.size);
1359 CHECK_EQUAL(network_open_information.out.attrib);
1362 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1363 CHECK_EQUAL(attribute_tag_information.out.attrib);
1364 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1367 /* Unhandled levels */
1369 case RAW_FILEINFO_SEC_DESC:
1370 case RAW_FILEINFO_EA_LIST:
1371 case RAW_FILEINFO_UNIX_BASIC:
1372 case RAW_FILEINFO_UNIX_LINK:
1373 case RAW_FILEINFO_SMB2_ALL_EAS:
1374 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1375 case RAW_FILEINFO_UNIX_INFO2:
1383 generate qpathinfo operations
1385 static bool handler_qpathinfo(int instance)
1387 union smb_fileinfo parm[NSERVERS];
1388 NTSTATUS status[NSERVERS];
1390 parm[0].generic.in.file.path = gen_fname_open(instance);
1392 gen_fileinfo(instance, &parm[0]);
1395 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1397 return cmp_fileinfo(instance, parm, status);
1401 generate qfileinfo operations
1403 static bool handler_qfileinfo(int instance)
1405 union smb_fileinfo parm[NSERVERS];
1406 NTSTATUS status[NSERVERS];
1408 parm[0].generic.in.file.fnum = gen_fnum(instance);
1410 gen_fileinfo(instance, &parm[0]);
1413 GEN_SET_FNUM(generic.in.file.fnum);
1414 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1416 return cmp_fileinfo(instance, parm, status);
1421 generate a fileinfo query structure
1423 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1427 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1429 enum smb_setfileinfo_level level;
1433 /* disabled until win2003 can handle them ... */
1434 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1435 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1437 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1438 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1439 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1440 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1441 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1444 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1445 } while (ignore_pattern(levels[i].name));
1447 info->generic.level = levels[i].level;
1449 switch (info->generic.level) {
1450 case RAW_SFILEINFO_SETATTR:
1451 info->setattr.in.attrib = gen_attrib();
1452 info->setattr.in.write_time = gen_timet();
1454 case RAW_SFILEINFO_SETATTRE:
1455 info->setattre.in.create_time = gen_timet();
1456 info->setattre.in.access_time = gen_timet();
1457 info->setattre.in.write_time = gen_timet();
1459 case RAW_SFILEINFO_STANDARD:
1460 info->standard.in.create_time = gen_timet();
1461 info->standard.in.access_time = gen_timet();
1462 info->standard.in.write_time = gen_timet();
1464 case RAW_SFILEINFO_EA_SET: {
1465 static struct ea_struct ea;
1466 info->ea_set.in.num_eas = 1;
1467 info->ea_set.in.eas = &ea;
1468 info->ea_set.in.eas[0] = gen_ea_struct();
1471 case RAW_SFILEINFO_BASIC_INFO:
1472 case RAW_SFILEINFO_BASIC_INFORMATION:
1473 info->basic_info.in.create_time = gen_nttime();
1474 info->basic_info.in.access_time = gen_nttime();
1475 info->basic_info.in.write_time = gen_nttime();
1476 info->basic_info.in.change_time = gen_nttime();
1477 info->basic_info.in.attrib = gen_attrib();
1479 case RAW_SFILEINFO_DISPOSITION_INFO:
1480 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1481 info->disposition_info.in.delete_on_close = gen_bool();
1483 case RAW_SFILEINFO_ALLOCATION_INFO:
1484 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1485 info->allocation_info.in.alloc_size = gen_alloc_size();
1487 case RAW_SFILEINFO_END_OF_FILE_INFO:
1488 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1489 info->end_of_file_info.in.size = gen_offset();
1491 case RAW_SFILEINFO_RENAME_INFORMATION:
1492 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
1493 info->rename_information.in.overwrite = gen_bool();
1494 info->rename_information.in.root_fid = gen_root_fid(instance);
1495 info->rename_information.in.new_name = gen_fname_open(instance);
1497 case RAW_SFILEINFO_POSITION_INFORMATION:
1498 info->position_information.in.position = gen_offset();
1500 case RAW_SFILEINFO_MODE_INFORMATION:
1501 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1503 case RAW_SFILEINFO_GENERIC:
1504 case RAW_SFILEINFO_SEC_DESC:
1505 case RAW_SFILEINFO_UNIX_BASIC:
1506 case RAW_SFILEINFO_UNIX_LINK:
1507 case RAW_SFILEINFO_UNIX_HLINK:
1508 case RAW_SFILEINFO_1023:
1509 case RAW_SFILEINFO_1025:
1510 case RAW_SFILEINFO_1029:
1511 case RAW_SFILEINFO_1032:
1512 case RAW_SFILEINFO_1039:
1513 case RAW_SFILEINFO_1040:
1514 case RAW_SFILEINFO_UNIX_INFO2:
1521 generate setfileinfo operations
1523 static bool handler_sfileinfo(int instance)
1525 union smb_setfileinfo parm[NSERVERS];
1526 NTSTATUS status[NSERVERS];
1528 parm[0].generic.in.file.fnum = gen_fnum(instance);
1530 gen_setfileinfo(instance, &parm[0]);
1533 GEN_SET_FNUM(generic.in.file.fnum);
1534 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1543 wipe any relevant files
1545 static void wipe_files(void)
1550 for (i=0;i<NSERVERS;i++) {
1551 int n = smb2_deltree(servers[i].tree[0], "gentest");
1553 printf("Failed to wipe tree on server %d\n", i);
1556 status = smb2_util_mkdir(servers[i].tree[0], "gentest");
1557 if (NT_STATUS_IS_ERR(status)) {
1558 printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status));
1562 printf("Deleted %d files on server %d\n", n, i);
1568 dump the current seeds - useful for continuing a backtrack
1570 static void dump_seeds(void)
1575 if (!options.seeds_file) {
1578 f = fopen("seeds.tmp", "w");
1581 for (i=0;i<options.numops;i++) {
1582 fprintf(f, "%u\n", op_parms[i].seed);
1585 rename("seeds.tmp", options.seeds_file);
1591 the list of top-level operations that we will generate
1595 bool (*handler)(int instance);
1596 int count, success_count;
1598 {"NTCREATEX", handler_ntcreatex},
1599 {"CLOSE", handler_close},
1604 run the test with the current set of op_parms parameters
1605 return the number of operations that completed successfully
1607 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
1611 if (!connect_servers(ev, lp_ctx)) {
1612 printf("Failed to connect to servers\n");
1618 /* wipe any leftover files from old runs */
1621 /* reset the open handles array */
1622 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1623 num_open_handles = 0;
1625 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1626 gen_ops[i].count = 0;
1627 gen_ops[i].success_count = 0;
1630 for (op=0; op<options.numops; op++) {
1631 int instance, which_op;
1634 if (op_parms[op].disabled) continue;
1636 srandom(op_parms[op].seed);
1638 instance = gen_int_range(0, NINSTANCES-1);
1640 /* generate a non-ignored operation */
1642 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1643 } while (ignore_pattern(gen_ops[which_op].name));
1645 DEBUG(3,("Generating op %s on instance %d\n",
1646 gen_ops[which_op].name, instance));
1648 current_op.seed = op_parms[op].seed;
1649 current_op.opnum = op;
1650 current_op.name = gen_ops[which_op].name;
1651 current_op.status = NT_STATUS_OK;
1652 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1654 ret = gen_ops[which_op].handler(instance);
1656 talloc_free(current_op.mem_ctx);
1658 gen_ops[which_op].count++;
1659 if (NT_STATUS_IS_OK(current_op.status)) {
1660 gen_ops[which_op].success_count++;
1664 printf("Failed at operation %d - %s\n",
1665 op, gen_ops[which_op].name);
1669 if (op % 100 == 0) {
1674 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1675 printf("Op %-10s got %d/%d success\n",
1677 gen_ops[i].success_count,
1685 perform a backtracking analysis of the minimal set of operations
1686 to generate an error
1688 static void backtrack_analyze(struct event_context *ev,
1689 struct loadparm_context *lp_ctx)
1693 chunk = options.numops / 2;
1698 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1701 chunk = MIN(chunk, options.numops / 2);
1703 /* mark this range as disabled */
1704 max = MIN(options.numops, base+chunk);
1705 for (i=base;i<max; i++) {
1706 op_parms[i].disabled = true;
1708 printf("Testing %d ops with %d-%d disabled\n",
1709 options.numops, base, max-1);
1710 ret = run_test(ev, lp_ctx);
1711 printf("Completed %d of %d ops\n", ret, options.numops);
1712 for (i=base;i<max; i++) {
1713 op_parms[i].disabled = false;
1715 if (ret == options.numops) {
1716 /* this chunk is needed */
1718 } else if (ret < base) {
1719 printf("damn - inconsistent errors! found early error\n");
1720 options.numops = ret+1;
1723 /* it failed - this chunk isn't needed for a failure */
1724 memmove(&op_parms[base], &op_parms[max],
1725 sizeof(op_parms[0]) * (options.numops - max));
1726 options.numops = (ret+1) - (max - base);
1736 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
1739 } while (chunk > 0);
1741 printf("Reduced to %d ops\n", options.numops);
1742 ret = run_test(ev, lp_ctx);
1743 if (ret != options.numops - 1) {
1744 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
1749 start the main gentest process
1751 static bool start_gentest(struct event_context *ev,
1752 struct loadparm_context *lp_ctx)
1757 /* allocate the open_handles array */
1758 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
1760 srandom(options.seed);
1761 op_parms = calloc(options.numops, sizeof(op_parms[0]));
1763 /* generate the seeds - after this everything is deterministic */
1764 if (options.use_preset_seeds) {
1766 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
1768 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
1771 if (numops < options.numops) {
1772 options.numops = numops;
1774 for (op=0;op<options.numops;op++) {
1776 printf("Not enough seeds in %s\n", options.seeds_file);
1779 op_parms[op].seed = atoi(preset[op]);
1781 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
1783 for (op=0; op<options.numops; op++) {
1784 op_parms[op].seed = random();
1788 ret = run_test(ev, lp_ctx);
1790 if (ret != options.numops && options.analyze) {
1791 options.numops = ret+1;
1792 backtrack_analyze(ev, lp_ctx);
1793 } else if (options.analyze_always) {
1794 backtrack_analyze(ev, lp_ctx);
1795 } else if (options.analyze_continuous) {
1796 while (run_test(ev, lp_ctx) == options.numops) ;
1799 return ret == options.numops;
1803 static void usage(poptContext pc)
1807 gentest //server1/share1 //server2/share2 [options..]\n\
1809 poptPrintUsage(pc, stdout, 0);
1813 split a UNC name into server and share names
1815 static bool split_unc_name(const char *unc, char **server, char **share)
1817 char *p = strdup(unc);
1818 if (!p) return false;
1819 all_string_sub(p, "\\", "/", 0);
1820 if (strncmp(p, "//", 2) != 0) return false;
1823 p = strchr(*server, '/');
1824 if (!p) return false;
1834 /****************************************************************************
1836 ****************************************************************************/
1837 int main(int argc, char *argv[])
1840 int i, username_count=0;
1842 char *ignore_file=NULL;
1843 struct event_context *ev;
1844 struct loadparm_context *lp_ctx;
1848 enum {OPT_UNCLIST=1000};
1849 struct poptOption long_options[] = {
1851 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
1852 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
1853 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
1854 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
1855 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
1856 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
1857 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
1858 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
1859 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
1860 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
1861 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
1862 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
1863 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
1865 POPT_COMMON_CONNECTION
1866 POPT_COMMON_CREDENTIALS
1871 memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
1874 options.seed = time(NULL);
1875 options.numops = 1000;
1876 options.max_open_handles = 20;
1877 options.seeds_file = "gentest_seeds.dat";
1879 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
1880 POPT_CONTEXT_KEEP_FIRST);
1882 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
1884 lp_ctx = cmdline_lp_ctx;
1885 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
1886 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
1887 cli_credentials_guess(servers[0].credentials, lp_ctx);
1888 cli_credentials_guess(servers[1].credentials, lp_ctx);
1890 while((opt = poptGetNextOpt(pc)) != -1) {
1893 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
1896 if (username_count == 2) {
1900 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
1907 options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
1910 argv_new = discard_const_p(char *, poptGetArgs(pc));
1912 for (i=0; i<argc; i++) {
1913 if (argv_new[i] == NULL) {
1919 if (!(argc_new >= 3)) {
1926 setup_logging("gentest", DEBUG_STDOUT);
1928 if (argc < 3 || argv[1][0] == '-') {
1933 setup_logging(argv[0], DEBUG_STDOUT);
1935 for (i=0;i<NSERVERS;i++) {
1936 const char *share = argv[1+i];
1937 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
1938 printf("Invalid share name '%s'\n", share);
1943 if (username_count == 0) {
1947 if (username_count == 1) {
1948 servers[1].credentials = servers[0].credentials;
1951 printf("seed=%u\n", options.seed);
1953 ev = event_context_init(talloc_autofree_context());
1955 gensec_init(lp_ctx);
1957 ret = start_gentest(ev, lp_ctx);
1960 printf("gentest completed - no errors\n");
1962 printf("gentest failed\n");