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 int analyze_continuous;
48 uint_t max_open_handles;
52 char **ignore_patterns;
53 const char *seeds_file;
59 /* mapping between open handles on the server and local handles */
63 struct smb2_handle server_handle[NSERVERS];
66 static uint_t num_open_handles;
68 /* state information for the servers. We open NINSTANCES connections to
71 struct smb2_tree *tree[NINSTANCES];
74 struct cli_credentials *credentials;
77 /* the seeds and flags for each operation */
84 /* oplock break info */
87 struct smb2_handle server_handle;
91 } oplocks[NSERVERS][NINSTANCES];
93 /* change notify reply info */
97 union smb_notify notify;
98 } notifies[NSERVERS][NINSTANCES];
100 /* info relevant to the current operation */
109 static struct smb2_handle bad_smb2_handle;
112 #define BAD_HANDLE 0xFFFE
114 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
115 static void idle_func(struct smb2_transport *transport, void *private);
118 check if a string should be ignored. This is used as the basis
119 for all error ignore settings
121 static bool ignore_pattern(const char *str)
124 if (!options.ignore_patterns) return false;
126 for (i=0;options.ignore_patterns[i];i++) {
127 if (strcmp(options.ignore_patterns[i], str) == 0 ||
128 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
129 DEBUG(2,("Ignoring '%s'\n", str));
136 /*****************************************************
137 connect to the servers
138 *******************************************************/
139 static bool connect_servers_fast(void)
143 /* close all open files */
144 for (h=0;h<options.max_open_handles;h++) {
145 if (!open_handles[h].active) continue;
146 for (i=0;i<NSERVERS;i++) {
147 NTSTATUS status = smb2_util_close(servers[i].tree[open_handles[h].instance],
148 open_handles[h].server_handle[i]);
149 if (NT_STATUS_IS_ERR(status)) {
152 open_handles[h].active = false;
162 /*****************************************************
163 connect to the servers
164 *******************************************************/
165 static bool connect_servers(struct event_context *ev,
166 struct loadparm_context *lp_ctx)
170 if (options.fast_reconnect && servers[0].tree[0]) {
171 if (connect_servers_fast()) {
176 /* close any existing connections */
177 for (i=0;i<NSERVERS;i++) {
178 for (j=0;j<NINSTANCES;j++) {
179 if (servers[i].tree[j]) {
180 smb2_tdis(servers[i].tree[j]);
181 talloc_free(servers[i].tree[j]);
182 servers[i].tree[j] = NULL;
187 for (i=0;i<NSERVERS;i++) {
188 for (j=0;j<NINSTANCES;j++) {
190 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
191 servers[i].server_name, servers[i].share_name,
192 servers[i].credentials->username, j);
194 cli_credentials_set_workstation(servers[i].credentials,
195 "gentest", CRED_SPECIFIED);
197 status = smb2_connect(NULL, servers[i].server_name,
198 servers[i].share_name,
199 lp_resolve_context(lp_ctx),
200 servers[i].credentials,
203 if (!NT_STATUS_IS_OK(status)) {
204 printf("Failed to connect to \\\\%s\\%s - %s\n",
205 servers[i].server_name, servers[i].share_name,
210 // smb2_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
211 smb2_transport_idle_handler(servers[i].tree[j]->session->transport, idle_func, 50000, NULL);
219 work out the time skew between the servers - be conservative
221 static uint_t time_skew(void)
224 ret = labs(servers[0].tree[0]->session->transport->negotiate.system_time -
225 servers[1].tree[0]->session->transport->negotiate.system_time);
230 static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_handle *h2)
232 return memcmp(h1, h2, sizeof(struct smb2_handle)) == 0;
236 turn a server handle into a local handle
238 static uint_t fnum_to_handle(int server, int instance, struct smb2_handle server_handle)
241 for (i=0;i<options.max_open_handles;i++) {
242 if (!open_handles[i].active ||
243 instance != open_handles[i].instance) continue;
244 if (smb2_handle_equal(&open_handles[i].server_handle[server], &server_handle)) {
248 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
254 add some newly opened handles
256 static void gen_add_handle(int instance, const char *name, struct smb2_handle handles[NSERVERS])
259 for (h=0;h<options.max_open_handles;h++) {
260 if (!open_handles[h].active) break;
262 if (h == options.max_open_handles) {
263 /* we have to force close a random handle */
264 h = random() % options.max_open_handles;
265 for (i=0;i<NSERVERS;i++) {
267 status = smb2_util_close(servers[i].tree[open_handles[h].instance],
268 open_handles[h].server_handle[i]);
269 if (NT_STATUS_IS_ERR(status)) {
270 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
274 printf("Recovered handle %d\n", h);
277 for (i=0;i<NSERVERS;i++) {
278 open_handles[h].server_handle[i] = handles[i];
279 open_handles[h].instance = instance;
280 open_handles[h].active = true;
281 open_handles[h].name = name;
285 printf("OPEN num_open_handles=%d h=%d (%s)\n",
286 num_open_handles, h, name);
290 remove a closed handle
292 static void gen_remove_handle(int instance, struct smb2_handle handles[NSERVERS])
295 for (h=0;h<options.max_open_handles;h++) {
296 if (instance == open_handles[h].instance &&
297 smb2_handle_equal(&open_handles[h].server_handle[0], &handles[0])) {
298 open_handles[h].active = false;
300 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
302 open_handles[h].name);
306 printf("Removing invalid handle!?\n");
311 return true with 'chance' probability as a percentage
313 static bool gen_chance(uint_t chance)
315 return ((random() % 100) <= chance);
319 map an internal handle number to a server handle
321 static struct smb2_handle gen_lookup_handle(int server, uint16_t handle)
323 if (handle == BAD_HANDLE) return bad_smb2_handle;
324 return open_handles[handle].server_handle[server];
330 static uint16_t gen_fnum(int instance)
335 if (gen_chance(20)) return BAD_HANDLE;
337 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
338 h = random() % options.max_open_handles;
339 if (open_handles[h].active &&
340 open_handles[h].instance == instance) {
348 return a file handle, but skewed so we don't close the last
349 couple of handles too readily
351 static uint16_t gen_fnum_close(int instance)
353 if (num_open_handles < 5) {
354 if (gen_chance(90)) return BAD_HANDLE;
357 return gen_fnum(instance);
361 generate an integer in a specified range
363 static int gen_int_range(uint64_t min, uint64_t max)
366 return min + (r % (1+max-min));
370 return a fnum for use as a root fid
371 be careful to call GEN_SET_FNUM() when you use this!
373 static uint16_t gen_root_fid(int instance)
375 if (gen_chance(5)) return gen_fnum(instance);
380 generate a file offset
382 static int gen_offset(void)
384 if (gen_chance(20)) return 0;
385 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
386 return gen_int_range(0, 1024*1024);
392 static int gen_io_count(void)
394 if (gen_chance(20)) return 0;
395 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
396 return gen_int_range(0, 4096);
402 static const char *gen_fname(void)
404 const char *names[] = {"gentest\\gentest.dat",
409 "gentest\\foo4:teststream1",
410 "gentest\\foo4:teststream2",
412 "gentest\\foo5.exe:teststream3",
413 "gentest\\foo5.exe:teststream4",
416 "gentest\\blah\\blergh.txt",
417 "gentest\\blah\\blergh2",
418 "gentest\\blah\\blergh3.txt",
419 "gentest\\blah\\blergh4",
420 "gentest\\blah\\blergh5.txt",
421 "gentest\\blah\\blergh5",
424 /* this causes problem with w2k3 */
427 "gentest\\a_very_long_name.bin",
433 i = gen_int_range(0, ARRAY_SIZE(names)-1);
434 } while (ignore_pattern(names[i]));
440 generate a filename with a higher chance of choosing an already
443 static const char *gen_fname_open(int instance)
446 h = gen_fnum(instance);
447 if (h == BAD_HANDLE) {
450 return open_handles[h].name;
454 generate a wildcard pattern
456 static const char *gen_pattern(void)
459 const char *names[] = {"gentest\\*.dat",
462 "gentest\\blah\\*.*",
466 if (gen_chance(50)) return gen_fname();
469 i = gen_int_range(0, ARRAY_SIZE(names)-1);
470 } while (ignore_pattern(names[i]));
475 static uint32_t gen_bits_levels(int nlevels, ...)
481 va_start(ap, nlevels);
482 for (i=0;i<nlevels;i++) {
483 pct = va_arg(ap, uint32_t);
484 mask = va_arg(ap, uint32_t);
485 if (pct == 100 || gen_chance(pct)) {
487 return mask & random();
497 static uint32_t gen_bits_mask(uint_t mask)
499 uint_t ret = random();
504 generate a bitmask with high probability of the first mask
505 and low of the second
507 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
509 if (gen_chance(10)) return gen_bits_mask(mask2);
510 return gen_bits_mask(mask1);
516 static bool gen_bool(void)
518 return gen_bits_mask2(0x1, 0xFF);
522 generate ntrename flags
524 static uint16_t gen_rename_flags(void)
526 if (gen_chance(30)) return RENAME_FLAG_RENAME;
527 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
528 if (gen_chance(30)) return RENAME_FLAG_COPY;
529 return gen_bits_mask(0xFFFF);
534 return a set of lock flags
536 static uint16_t gen_lock_flags(void)
538 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
539 if (gen_chance(20)) return gen_bits_mask(0x1F);
540 if (gen_chance(50)) return SMB2_LOCK_FLAG_UNLOCK;
541 return gen_bits_mask(SMB2_LOCK_FLAG_SHARED |
542 SMB2_LOCK_FLAG_EXCLUSIVE |
543 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY);
547 generate a lock count
549 static off_t gen_lock_count(void)
551 return gen_int_range(0, 3);
555 generate a ntcreatex flags field
557 static uint32_t gen_ntcreatex_flags(void)
559 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
560 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
564 generate a NT access mask
566 static uint32_t gen_access_mask(void)
568 if (gen_chance(70)) return SEC_FLAG_MAXIMUM_ALLOWED;
569 if (gen_chance(70)) return SEC_FILE_ALL;
570 return gen_bits_mask(0xFFFFFFFF);
574 generate a ntcreatex create options bitfield
576 static uint32_t gen_create_options(void)
578 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
579 if (gen_chance(50)) return 0;
580 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
584 generate a ntcreatex open disposition
586 static uint32_t gen_open_disp(void)
588 if (gen_chance(50)) return NTCREATEX_DISP_OPEN_IF;
589 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
590 return gen_int_range(0, 5);
594 generate a file attrib combination
596 static uint32_t gen_attrib(void)
598 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
599 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
603 generate a unix timestamp
605 static time_t gen_timet(void)
607 if (gen_chance(30)) return 0;
608 return (time_t)random();
612 generate a unix timestamp
614 static NTTIME gen_nttime(void)
617 unix_to_nt_time(&ret, gen_timet());
622 generate a milliseconds protocol timeout
624 static uint32_t gen_timeout(void)
626 if (gen_chance(98)) return 0;
627 return random() % 50;
631 generate a file allocation size
633 static uint_t gen_alloc_size(void)
637 if (gen_chance(30)) return 0;
639 ret = random() % 4*1024*1024;
640 /* give a high chance of a round number */
641 if (gen_chance(60)) {
642 ret &= ~(1024*1024 - 1);
648 generate an ea_struct
650 static struct ea_struct gen_ea_struct(void)
653 const char *names[] = {"EAONE",
658 "AVERYLONGATTRIBUTENAME"};
659 const char *values[] = {"VALUE1",
664 "ASOMEWHATLONGERATTRIBUTEVALUE"};
670 i = gen_int_range(0, ARRAY_SIZE(names)-1);
671 } while (ignore_pattern(names[i]));
673 ea.name.s = names[i];
676 i = gen_int_range(0, ARRAY_SIZE(values)-1);
677 } while (ignore_pattern(values[i]));
679 ea.value = data_blob(values[i], strlen(values[i]));
681 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
688 the idle function tries to cope with getting an oplock break on a connection, and
689 an operation on another connection blocking until that break is acked
690 we check for operations on all transports in the idle function
692 static void idle_func(struct smb2_transport *transport, void *private)
695 for (i=0;i<NSERVERS;i++) {
696 for (j=0;j<NINSTANCES;j++) {
697 if (servers[i].tree[j] &&
698 transport != servers[i].tree[j]->session->transport) {
699 // smb2_transport_process(servers[i].tree[j]->session->transport);
708 compare NTSTATUS, using checking ignored patterns
710 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
712 if (NT_STATUS_EQUAL(status1, status2)) return true;
714 /* one code being an error and the other OK is always an error */
715 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return false;
717 /* if we are ignoring one of the status codes then consider this a match */
718 if (ignore_pattern(nt_errstr(status1)) ||
719 ignore_pattern(nt_errstr(status2))) {
727 check for pending packets on all connections
729 static void check_pending(void)
735 for (j=0;j<NINSTANCES;j++) {
736 for (i=0;i<NSERVERS;i++) {
737 // smb2_transport_process(servers[i].tree[j]->session->transport);
743 check that the same oplock breaks have been received by all instances
745 static bool check_oplocks(const char *call)
754 for (j=0;j<NINSTANCES;j++) {
755 for (i=1;i<NSERVERS;i++) {
756 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
757 oplocks[0][j].handle != oplocks[i][j].handle ||
758 oplocks[0][j].level != oplocks[i][j].level) {
759 if (tries++ < 10) goto again;
760 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
761 oplocks[0][j].got_break,
762 oplocks[0][j].handle,
764 oplocks[i][j].got_break,
765 oplocks[i][j].handle,
766 oplocks[i][j].level);
772 /* if we got a break and closed then remove the handle */
773 for (j=0;j<NINSTANCES;j++) {
774 if (oplocks[0][j].got_break &&
775 oplocks[0][j].do_close) {
776 uint16_t fnums[NSERVERS];
777 for (i=0;i<NSERVERS;i++) {
778 fnums[i] = oplocks[i][j].fnum;
780 gen_remove_handle(j, fnums);
790 check that the same change notify info has been received by all instances
792 static bool check_notifies(const char *call)
801 for (j=0;j<NINSTANCES;j++) {
802 for (i=1;i<NSERVERS;i++) {
804 union smb_notify not1, not2;
806 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
807 if (tries++ < 10) goto again;
808 printf("Notify count inconsistent %d %d\n",
809 notifies[0][j].notify_count,
810 notifies[i][j].notify_count);
814 if (notifies[0][j].notify_count == 0) continue;
816 if (!NT_STATUS_EQUAL(notifies[0][j].status,
817 notifies[i][j].status)) {
818 printf("Notify status mismatch - %s - %s\n",
819 nt_errstr(notifies[0][j].status),
820 nt_errstr(notifies[i][j].status));
824 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
828 not1 = notifies[0][j].notify;
829 not2 = notifies[i][j].notify;
831 for (n=0;n<not1.nttrans.out.num_changes;n++) {
832 if (not1.nttrans.out.changes[n].action !=
833 not2.nttrans.out.changes[n].action) {
834 printf("Notify action %d inconsistent %d %d\n", n,
835 not1.nttrans.out.changes[n].action,
836 not2.nttrans.out.changes[n].action);
839 if (strcmp(not1.nttrans.out.changes[n].name.s,
840 not2.nttrans.out.changes[n].name.s)) {
841 printf("Notify name %d inconsistent %s %s\n", n,
842 not1.nttrans.out.changes[n].name.s,
843 not2.nttrans.out.changes[n].name.s);
846 if (not1.nttrans.out.changes[n].name.private_length !=
847 not2.nttrans.out.changes[n].name.private_length) {
848 printf("Notify name length %d inconsistent %d %d\n", n,
849 not1.nttrans.out.changes[n].name.private_length,
850 not2.nttrans.out.changes[n].name.private_length);
857 ZERO_STRUCT(notifies);
863 #define GEN_COPY_PARM do { \
865 for (i=1;i<NSERVERS;i++) { \
870 #define GEN_CALL(call) do { \
872 ZERO_STRUCT(oplocks); \
873 ZERO_STRUCT(notifies); \
874 for (i=0;i<NSERVERS;i++) { \
875 struct smb2_tree *tree = servers[i].tree[instance]; \
878 current_op.status = status[0]; \
879 for (i=1;i<NSERVERS;i++) { \
880 if (!compare_status(status[i], status[0])) { \
881 printf("status different in %s - %s %s\n", #call, \
882 nt_errstr(status[0]), nt_errstr(status[i])); \
886 if (!check_oplocks(#call)) return false; \
887 if (!check_notifies(#call)) return false; \
888 if (!NT_STATUS_IS_OK(status[0])) { \
893 #define ADD_HANDLE(name, field) do { \
894 struct smb2_handle handles[NSERVERS]; \
896 for (i=0;i<NSERVERS;i++) { \
897 handles[i] = parm[i].field; \
899 gen_add_handle(instance, name, handles); \
902 #define REMOVE_HANDLE(field) do { \
903 struct smb2_handle handles[NSERVERS]; \
905 for (i=0;i<NSERVERS;i++) { \
906 handles[i] = parm[i].field; \
908 gen_remove_handle(instance, handles); \
911 #define GEN_SET_FNUM(field) do { \
913 for (i=0;i<NSERVERS;i++) { \
914 parm[i].field = gen_lookup_handle(i, parm[i].field.data[0]); \
918 #define CHECK_EQUAL(field) do { \
919 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
920 printf("Mismatch in %s - 0x%llx 0x%llx\n", #field, \
921 (unsigned long long)parm[0].field, (unsigned long long)parm[1].field); \
926 #define CHECK_ATTRIB(field) do { \
927 if (!options.mask_indexing) { \
928 CHECK_EQUAL(field); \
929 } else if ((~FILE_ATTRIBUTE_NONINDEXED & parm[0].field) != (~FILE_ATTRIBUTE_NONINDEXED & parm[1].field) && !ignore_pattern(#field)) { \
930 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
931 (int)parm[0].field, (int)parm[1].field); \
936 #define CHECK_WSTR_EQUAL(field) do { \
937 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
938 printf("%s is NULL!\n", #field); \
941 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
942 printf("Mismatch in %s - %s %s\n", #field, \
943 parm[0].field.s, parm[1].field.s); \
946 CHECK_EQUAL(field.private_length); \
949 #define CHECK_BLOB_EQUAL(field) do { \
950 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
951 printf("Mismatch in %s\n", #field); \
954 CHECK_EQUAL(field.length); \
957 #define CHECK_TIMES_EQUAL(field) do { \
958 if (labs(parm[0].field - parm[1].field) > time_skew() && \
959 !ignore_pattern(#field)) { \
960 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
961 (int)parm[0].field, (int)parm[1].field); \
966 #define CHECK_NTTIMES_EQUAL(field) do { \
967 if (labs(nt_time_to_unix(parm[0].field) - \
968 nt_time_to_unix(parm[1].field)) > time_skew() && \
969 !ignore_pattern(#field)) { \
970 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
971 (int)nt_time_to_unix(parm[0].field), \
972 (int)nt_time_to_unix(parm[1].field)); \
978 generate ntcreatex operations
980 static bool handler_create(int instance)
982 struct smb2_create parm[NSERVERS];
983 NTSTATUS status[NSERVERS];
985 ZERO_STRUCT(parm[0]);
986 parm[0].in.security_flags = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFF);
987 parm[0].in.oplock_level = gen_bits_levels(3, 90, 0x0, 70, 0x9, 100, 0xFF);
988 parm[0].in.impersonation_level = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFFFFFFFF);
989 parm[0].in.create_flags = gen_bits_levels(2, 90, 0x0, 100, 0xFFFFFFFF);
991 parm[0].in.create_flags |= gen_bits_mask(0xFFFFFFFF);
993 parm[0].in.reserved = gen_bits_levels(2, 95, 0x0, 100, 0xFFFFFFFF);
995 parm[0].in.reserved |= gen_bits_mask(0xFFFFFFFF);
997 parm[0].in.desired_access = gen_access_mask();
998 parm[0].in.file_attributes = gen_attrib();
999 parm[0].in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1000 parm[0].in.create_disposition = gen_open_disp();
1001 parm[0].in.create_options = gen_create_options();
1002 parm[0].in.fname = gen_fname_open(instance);
1004 if (!options.use_oplocks) {
1005 /* mask out oplocks */
1006 parm[0].in.oplock_level = 0;
1010 GEN_CALL(smb2_create(tree, current_op.mem_ctx, &parm[i]));
1012 CHECK_EQUAL(out.oplock_level);
1013 CHECK_EQUAL(out.reserved);
1014 CHECK_EQUAL(out.create_action);
1015 CHECK_NTTIMES_EQUAL(out.create_time);
1016 CHECK_NTTIMES_EQUAL(out.access_time);
1017 CHECK_NTTIMES_EQUAL(out.write_time);
1018 CHECK_NTTIMES_EQUAL(out.change_time);
1019 CHECK_EQUAL(out.alloc_size);
1020 CHECK_EQUAL(out.size);
1021 CHECK_ATTRIB(out.file_attr);
1022 CHECK_EQUAL(out.reserved2);
1024 /* ntcreatex creates a new file handle */
1025 ADD_HANDLE(parm[0].in.fname, out.file.handle);
1031 generate close operations
1033 static bool handler_close(int instance)
1035 struct smb2_close parm[NSERVERS];
1036 NTSTATUS status[NSERVERS];
1038 ZERO_STRUCT(parm[0]);
1039 parm[0].in.file.handle.data[0] = gen_fnum_close(instance);
1040 parm[0].in.flags = gen_bits_mask2(0x1, 0xFFFF);
1043 GEN_SET_FNUM(in.file.handle);
1044 GEN_CALL(smb2_close(tree, &parm[i]));
1046 CHECK_EQUAL(out.flags);
1047 CHECK_EQUAL(out._pad);
1048 CHECK_NTTIMES_EQUAL(out.create_time);
1049 CHECK_NTTIMES_EQUAL(out.access_time);
1050 CHECK_NTTIMES_EQUAL(out.write_time);
1051 CHECK_NTTIMES_EQUAL(out.change_time);
1052 CHECK_EQUAL(out.alloc_size);
1053 CHECK_EQUAL(out.size);
1054 CHECK_ATTRIB(out.file_attr);
1056 REMOVE_HANDLE(in.file.handle);
1062 generate read operations
1064 static bool handler_read(int instance)
1066 struct smb2_read parm[NSERVERS];
1067 NTSTATUS status[NSERVERS];
1069 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1070 parm[0].in.reserved = gen_bits_mask2(0x0, 0xFF);
1071 parm[0].in.length = gen_io_count();
1072 parm[0].in.offset = gen_offset();
1073 parm[0].in.min_count = gen_io_count();
1074 parm[0].in.channel = gen_bits_mask2(0x0, 0xFFFFFFFF);
1075 parm[0].in.remaining = gen_bits_mask2(0x0, 0xFFFFFFFF);
1076 parm[0].in.channel_offset = gen_bits_mask2(0x0, 0xFFFF);
1077 parm[0].in.channel_length = gen_bits_mask2(0x0, 0xFFFF);
1080 GEN_SET_FNUM(in.file.handle);
1081 GEN_CALL(smb2_read(tree, current_op.mem_ctx, &parm[i]));
1083 CHECK_EQUAL(out.remaining);
1084 CHECK_EQUAL(out.reserved);
1085 CHECK_EQUAL(out.data.length);
1091 generate write operations
1093 static bool handler_write(int instance)
1095 struct smb2_write parm[NSERVERS];
1096 NTSTATUS status[NSERVERS];
1098 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1099 parm[0].in.offset = gen_offset();
1100 parm[0].in.unknown1 = gen_bits_mask2(0, 0xFFFFFFFF);
1101 parm[0].in.unknown2 = gen_bits_mask2(0, 0xFFFFFFFF);
1102 parm[0].in.data = data_blob_talloc(current_op.mem_ctx, NULL,
1106 GEN_SET_FNUM(in.file.handle);
1107 GEN_CALL(smb2_write(tree, &parm[i]));
1109 CHECK_EQUAL(out._pad);
1110 CHECK_EQUAL(out.nwritten);
1111 CHECK_EQUAL(out.unknown1);
1117 generate lockingx operations
1119 static bool handler_lock(int instance)
1121 struct smb2_lock parm[NSERVERS];
1122 NTSTATUS status[NSERVERS];
1125 parm[0].level = RAW_LOCK_LOCKX;
1126 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1127 parm[0].in.lock_count = gen_lock_count();
1128 parm[0].in.reserved = gen_bits_mask2(0, 0xFFFFFFFF);
1130 parm[0].in.locks = talloc_array(current_op.mem_ctx,
1131 struct smb2_lock_element,
1132 parm[0].in.lock_count);
1133 for (n=0;n<parm[0].in.lock_count;n++) {
1134 parm[0].in.locks[n].offset = gen_offset();
1135 parm[0].in.locks[n].length = gen_io_count();
1136 /* don't yet cope with async replies */
1137 parm[0].in.locks[n].flags = gen_lock_flags() |
1138 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY;
1139 parm[0].in.locks[n].reserved = gen_bits_mask2(0x0, 0xFFFFFFFF);
1143 GEN_SET_FNUM(in.file.handle);
1144 GEN_CALL(smb2_lock(tree, &parm[i]));
1150 generate flush operations
1152 static bool handler_flush(int instance)
1154 struct smb2_flush parm[NSERVERS];
1155 NTSTATUS status[NSERVERS];
1157 ZERO_STRUCT(parm[0]);
1158 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1159 parm[0].in.reserved1 = gen_bits_mask2(0x0, 0xFFFF);
1160 parm[0].in.reserved2 = gen_bits_mask2(0x0, 0xFFFFFFFF);
1163 GEN_SET_FNUM(in.file.handle);
1164 GEN_CALL(smb2_flush(tree, &parm[i]));
1166 CHECK_EQUAL(out.reserved);
1172 generate echo operations
1174 static bool handler_echo(int instance)
1176 NTSTATUS status[NSERVERS];
1178 GEN_CALL(smb2_keepalive(tree->session->transport));
1186 generate a fileinfo query structure
1188 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1191 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1193 enum smb_fileinfo_level level;
1196 LVL(BASIC_INFORMATION),
1197 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1198 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1199 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(SMB2_ALL_INFORMATION),
1200 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1201 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION),
1202 LVL(SMB2_ALL_EAS), LVL(SMB2_ALL_INFORMATION),
1205 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1206 } while (ignore_pattern(levels[i].name));
1208 info->generic.level = levels[i].level;
1212 compare returned fileinfo structures
1214 static bool cmp_fileinfo(int instance,
1215 union smb_fileinfo parm[NSERVERS],
1216 NTSTATUS status[NSERVERS])
1220 switch (parm[0].generic.level) {
1221 case RAW_FILEINFO_GENERIC:
1224 case RAW_FILEINFO_BASIC_INFORMATION:
1225 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1226 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1227 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1228 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1229 CHECK_ATTRIB(basic_info.out.attrib);
1232 case RAW_FILEINFO_STANDARD_INFORMATION:
1233 CHECK_EQUAL(standard_info.out.alloc_size);
1234 CHECK_EQUAL(standard_info.out.size);
1235 CHECK_EQUAL(standard_info.out.nlink);
1236 CHECK_EQUAL(standard_info.out.delete_pending);
1237 CHECK_EQUAL(standard_info.out.directory);
1240 case RAW_FILEINFO_EA_INFORMATION:
1241 CHECK_EQUAL(ea_info.out.ea_size);
1244 case RAW_FILEINFO_NAME_INFORMATION:
1245 CHECK_WSTR_EQUAL(name_info.out.fname);
1248 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1249 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1252 case RAW_FILEINFO_STREAM_INFORMATION:
1253 CHECK_EQUAL(stream_info.out.num_streams);
1254 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1255 CHECK_EQUAL(stream_info.out.streams[i].size);
1256 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1257 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1261 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1262 CHECK_EQUAL(compression_info.out.compressed_size);
1263 CHECK_EQUAL(compression_info.out.format);
1264 CHECK_EQUAL(compression_info.out.unit_shift);
1265 CHECK_EQUAL(compression_info.out.chunk_shift);
1266 CHECK_EQUAL(compression_info.out.cluster_shift);
1269 case RAW_FILEINFO_INTERNAL_INFORMATION:
1270 CHECK_EQUAL(internal_information.out.file_id);
1273 case RAW_FILEINFO_ACCESS_INFORMATION:
1274 CHECK_EQUAL(access_information.out.access_flags);
1277 case RAW_FILEINFO_POSITION_INFORMATION:
1278 CHECK_EQUAL(position_information.out.position);
1281 case RAW_FILEINFO_MODE_INFORMATION:
1282 CHECK_EQUAL(mode_information.out.mode);
1285 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1286 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1289 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1290 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1291 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1292 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1293 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1294 CHECK_EQUAL(network_open_information.out.alloc_size);
1295 CHECK_EQUAL(network_open_information.out.size);
1296 CHECK_ATTRIB(network_open_information.out.attrib);
1299 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1300 CHECK_ATTRIB(attribute_tag_information.out.attrib);
1301 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1304 case RAW_FILEINFO_ALL_INFORMATION:
1305 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1306 CHECK_NTTIMES_EQUAL(all_info2.out.create_time);
1307 CHECK_NTTIMES_EQUAL(all_info2.out.access_time);
1308 CHECK_NTTIMES_EQUAL(all_info2.out.write_time);
1309 CHECK_NTTIMES_EQUAL(all_info2.out.change_time);
1310 CHECK_ATTRIB(all_info2.out.attrib);
1311 CHECK_EQUAL(all_info2.out.unknown1);
1312 CHECK_EQUAL(all_info2.out.alloc_size);
1313 CHECK_EQUAL(all_info2.out.size);
1314 CHECK_EQUAL(all_info2.out.nlink);
1315 CHECK_EQUAL(all_info2.out.delete_pending);
1316 CHECK_EQUAL(all_info2.out.directory);
1317 CHECK_EQUAL(all_info2.out.file_id);
1318 CHECK_EQUAL(all_info2.out.ea_size);
1319 CHECK_EQUAL(all_info2.out.access_mask);
1320 CHECK_EQUAL(all_info2.out.position);
1321 CHECK_EQUAL(all_info2.out.mode);
1322 CHECK_EQUAL(all_info2.out.alignment_requirement);
1323 CHECK_WSTR_EQUAL(all_info2.out.fname);
1326 case RAW_FILEINFO_SMB2_ALL_EAS:
1327 CHECK_EQUAL(all_eas.out.num_eas);
1328 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1329 CHECK_EQUAL(all_eas.out.eas[i].flags);
1330 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1331 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1335 /* Unhandled levels */
1337 case RAW_FILEINFO_SEC_DESC:
1338 case RAW_FILEINFO_EA_LIST:
1339 case RAW_FILEINFO_UNIX_BASIC:
1340 case RAW_FILEINFO_UNIX_LINK:
1341 case RAW_FILEINFO_UNIX_INFO2:
1349 generate qfileinfo operations
1351 static bool handler_qfileinfo(int instance)
1353 union smb_fileinfo parm[NSERVERS];
1354 NTSTATUS status[NSERVERS];
1356 parm[0].generic.in.file.handle.data[0] = gen_fnum(instance);
1358 gen_fileinfo(instance, &parm[0]);
1361 GEN_SET_FNUM(generic.in.file.handle);
1362 GEN_CALL(smb2_getinfo_file(tree, current_op.mem_ctx, &parm[i]));
1364 return cmp_fileinfo(instance, parm, status);
1371 generate a fileinfo query structure
1373 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1377 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1379 enum smb_setfileinfo_level level;
1383 /* disabled until win2003 can handle them ... */
1384 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1385 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1387 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1388 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1389 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1390 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1391 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1394 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1395 } while (ignore_pattern(levels[i].name));
1397 info->generic.level = levels[i].level;
1399 switch (info->generic.level) {
1400 case RAW_SFILEINFO_SETATTR:
1401 info->setattr.in.attrib = gen_attrib();
1402 info->setattr.in.write_time = gen_timet();
1404 case RAW_SFILEINFO_SETATTRE:
1405 info->setattre.in.create_time = gen_timet();
1406 info->setattre.in.access_time = gen_timet();
1407 info->setattre.in.write_time = gen_timet();
1409 case RAW_SFILEINFO_STANDARD:
1410 info->standard.in.create_time = gen_timet();
1411 info->standard.in.access_time = gen_timet();
1412 info->standard.in.write_time = gen_timet();
1414 case RAW_SFILEINFO_EA_SET: {
1415 static struct ea_struct ea;
1416 info->ea_set.in.num_eas = 1;
1417 info->ea_set.in.eas = &ea;
1418 info->ea_set.in.eas[0] = gen_ea_struct();
1421 case RAW_SFILEINFO_BASIC_INFO:
1422 case RAW_SFILEINFO_BASIC_INFORMATION:
1423 info->basic_info.in.create_time = gen_nttime();
1424 info->basic_info.in.access_time = gen_nttime();
1425 info->basic_info.in.write_time = gen_nttime();
1426 info->basic_info.in.change_time = gen_nttime();
1427 info->basic_info.in.attrib = gen_attrib();
1429 case RAW_SFILEINFO_DISPOSITION_INFO:
1430 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1431 info->disposition_info.in.delete_on_close = gen_bool();
1433 case RAW_SFILEINFO_ALLOCATION_INFO:
1434 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1435 info->allocation_info.in.alloc_size = gen_alloc_size();
1437 case RAW_SFILEINFO_END_OF_FILE_INFO:
1438 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1439 info->end_of_file_info.in.size = gen_offset();
1441 case RAW_SFILEINFO_RENAME_INFORMATION:
1442 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
1443 info->rename_information.in.overwrite = gen_bool();
1444 info->rename_information.in.root_fid = gen_root_fid(instance);
1445 info->rename_information.in.new_name = gen_fname_open(instance);
1447 case RAW_SFILEINFO_POSITION_INFORMATION:
1448 info->position_information.in.position = gen_offset();
1450 case RAW_SFILEINFO_MODE_INFORMATION:
1451 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1453 case RAW_SFILEINFO_GENERIC:
1454 case RAW_SFILEINFO_SEC_DESC:
1455 case RAW_SFILEINFO_UNIX_BASIC:
1456 case RAW_SFILEINFO_UNIX_LINK:
1457 case RAW_SFILEINFO_UNIX_HLINK:
1458 case RAW_SFILEINFO_1023:
1459 case RAW_SFILEINFO_1025:
1460 case RAW_SFILEINFO_1029:
1461 case RAW_SFILEINFO_1032:
1462 case RAW_SFILEINFO_1039:
1463 case RAW_SFILEINFO_1040:
1464 case RAW_SFILEINFO_UNIX_INFO2:
1471 generate setfileinfo operations
1473 static bool handler_sfileinfo(int instance)
1475 union smb_setfileinfo parm[NSERVERS];
1476 NTSTATUS status[NSERVERS];
1478 parm[0].generic.in.file.fnum = gen_fnum(instance);
1480 gen_setfileinfo(instance, &parm[0]);
1483 GEN_SET_FNUM(generic.in.file.fnum);
1484 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1493 wipe any relevant files
1495 static void wipe_files(void)
1500 for (i=0;i<NSERVERS;i++) {
1501 int n = smb2_deltree(servers[i].tree[0], "gentest");
1503 printf("Failed to wipe tree on server %d\n", i);
1506 status = smb2_util_mkdir(servers[i].tree[0], "gentest");
1507 if (NT_STATUS_IS_ERR(status)) {
1508 printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status));
1512 printf("Deleted %d files on server %d\n", n, i);
1518 dump the current seeds - useful for continuing a backtrack
1520 static void dump_seeds(void)
1525 if (!options.seeds_file) {
1528 f = fopen("seeds.tmp", "w");
1531 for (i=0;i<options.numops;i++) {
1532 fprintf(f, "%u\n", op_parms[i].seed);
1535 rename("seeds.tmp", options.seeds_file);
1541 the list of top-level operations that we will generate
1545 bool (*handler)(int instance);
1546 int count, success_count;
1548 {"CREATE", handler_create},
1549 {"CLOSE", handler_close},
1550 {"READ", handler_read},
1551 {"WRITE", handler_write},
1552 {"LOCK", handler_lock},
1553 {"FLUSH", handler_flush},
1554 {"ECHO", handler_echo},
1555 {"FILEINFO", handler_qfileinfo},
1560 run the test with the current set of op_parms parameters
1561 return the number of operations that completed successfully
1563 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
1567 if (!connect_servers(ev, lp_ctx)) {
1568 printf("Failed to connect to servers\n");
1574 /* wipe any leftover files from old runs */
1577 /* reset the open handles array */
1578 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1579 num_open_handles = 0;
1581 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1582 gen_ops[i].count = 0;
1583 gen_ops[i].success_count = 0;
1586 for (op=0; op<options.numops; op++) {
1587 int instance, which_op;
1590 if (op_parms[op].disabled) continue;
1592 srandom(op_parms[op].seed);
1594 instance = gen_int_range(0, NINSTANCES-1);
1596 /* generate a non-ignored operation */
1598 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1599 } while (ignore_pattern(gen_ops[which_op].name));
1601 DEBUG(3,("Generating op %s on instance %d\n",
1602 gen_ops[which_op].name, instance));
1604 current_op.seed = op_parms[op].seed;
1605 current_op.opnum = op;
1606 current_op.name = gen_ops[which_op].name;
1607 current_op.status = NT_STATUS_OK;
1608 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1610 ret = gen_ops[which_op].handler(instance);
1612 talloc_free(current_op.mem_ctx);
1614 gen_ops[which_op].count++;
1615 if (NT_STATUS_IS_OK(current_op.status)) {
1616 gen_ops[which_op].success_count++;
1620 printf("Failed at operation %d - %s\n",
1621 op, gen_ops[which_op].name);
1625 if (op % 100 == 0) {
1630 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1631 printf("Op %-10s got %d/%d success\n",
1633 gen_ops[i].success_count,
1641 perform a backtracking analysis of the minimal set of operations
1642 to generate an error
1644 static void backtrack_analyze(struct event_context *ev,
1645 struct loadparm_context *lp_ctx)
1649 chunk = options.numops / 2;
1654 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1657 chunk = MIN(chunk, options.numops / 2);
1659 /* mark this range as disabled */
1660 max = MIN(options.numops, base+chunk);
1661 for (i=base;i<max; i++) {
1662 op_parms[i].disabled = true;
1664 printf("Testing %d ops with %d-%d disabled\n",
1665 options.numops, base, max-1);
1666 ret = run_test(ev, lp_ctx);
1667 printf("Completed %d of %d ops\n", ret, options.numops);
1668 for (i=base;i<max; i++) {
1669 op_parms[i].disabled = false;
1671 if (ret == options.numops) {
1672 /* this chunk is needed */
1674 } else if (ret < base) {
1675 printf("damn - inconsistent errors! found early error\n");
1676 options.numops = ret+1;
1679 /* it failed - this chunk isn't needed for a failure */
1680 memmove(&op_parms[base], &op_parms[max],
1681 sizeof(op_parms[0]) * (options.numops - max));
1682 options.numops = (ret+1) - (max - base);
1692 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
1695 } while (chunk > 0);
1697 printf("Reduced to %d ops\n", options.numops);
1698 ret = run_test(ev, lp_ctx);
1699 if (ret != options.numops - 1) {
1700 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
1705 start the main gentest process
1707 static bool start_gentest(struct event_context *ev,
1708 struct loadparm_context *lp_ctx)
1713 /* allocate the open_handles array */
1714 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
1716 srandom(options.seed);
1717 op_parms = calloc(options.numops, sizeof(op_parms[0]));
1719 /* generate the seeds - after this everything is deterministic */
1720 if (options.use_preset_seeds) {
1722 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
1724 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
1727 if (numops < options.numops) {
1728 options.numops = numops;
1730 for (op=0;op<options.numops;op++) {
1732 printf("Not enough seeds in %s\n", options.seeds_file);
1735 op_parms[op].seed = atoi(preset[op]);
1737 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
1739 for (op=0; op<options.numops; op++) {
1740 op_parms[op].seed = random();
1744 ret = run_test(ev, lp_ctx);
1746 if (ret != options.numops && options.analyze) {
1747 options.numops = ret+1;
1748 backtrack_analyze(ev, lp_ctx);
1749 } else if (options.analyze_always) {
1750 backtrack_analyze(ev, lp_ctx);
1751 } else if (options.analyze_continuous) {
1752 while (run_test(ev, lp_ctx) == options.numops) ;
1755 return ret == options.numops;
1759 static void usage(poptContext pc)
1763 gentest //server1/share1 //server2/share2 [options..]\n\
1765 poptPrintUsage(pc, stdout, 0);
1769 split a UNC name into server and share names
1771 static bool split_unc_name(const char *unc, char **server, char **share)
1773 char *p = strdup(unc);
1774 if (!p) return false;
1775 all_string_sub(p, "\\", "/", 0);
1776 if (strncmp(p, "//", 2) != 0) return false;
1779 p = strchr(*server, '/');
1780 if (!p) return false;
1790 /****************************************************************************
1792 ****************************************************************************/
1793 int main(int argc, char *argv[])
1796 int i, username_count=0;
1798 char *ignore_file=NULL;
1799 struct event_context *ev;
1800 struct loadparm_context *lp_ctx;
1804 enum {OPT_UNCLIST=1000};
1805 struct poptOption long_options[] = {
1807 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
1808 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
1809 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
1810 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
1811 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
1812 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
1813 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
1814 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
1815 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
1816 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
1817 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
1818 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
1819 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
1820 {"maskindexing", 0, POPT_ARG_NONE, &options.mask_indexing, 0, "mask out the indexed file attrib", NULL},
1822 POPT_COMMON_CONNECTION
1823 POPT_COMMON_CREDENTIALS
1828 memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
1831 options.seed = time(NULL);
1832 options.numops = 1000;
1833 options.max_open_handles = 20;
1834 options.seeds_file = "gentest_seeds.dat";
1836 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
1837 POPT_CONTEXT_KEEP_FIRST);
1839 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
1841 lp_ctx = cmdline_lp_ctx;
1842 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
1843 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
1844 cli_credentials_guess(servers[0].credentials, lp_ctx);
1845 cli_credentials_guess(servers[1].credentials, lp_ctx);
1847 while((opt = poptGetNextOpt(pc)) != -1) {
1850 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
1853 if (username_count == 2) {
1857 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
1864 options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
1867 argv_new = discard_const_p(char *, poptGetArgs(pc));
1869 for (i=0; i<argc; i++) {
1870 if (argv_new[i] == NULL) {
1876 if (!(argc_new >= 3)) {
1883 setup_logging("gentest", DEBUG_STDOUT);
1885 if (argc < 3 || argv[1][0] == '-') {
1890 setup_logging(argv[0], DEBUG_STDOUT);
1892 for (i=0;i<NSERVERS;i++) {
1893 const char *share = argv[1+i];
1894 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
1895 printf("Invalid share name '%s'\n", share);
1900 if (username_count == 0) {
1904 if (username_count == 1) {
1905 servers[1].credentials = servers[0].credentials;
1908 printf("seed=%u\n", options.seed);
1910 ev = event_context_init(talloc_autofree_context());
1912 gensec_init(lp_ctx);
1914 ret = start_gentest(ev, lp_ctx);
1917 printf("gentest completed - no errors\n");
1919 printf("gentest failed\n");