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;
60 /* mapping between open handles on the server and local handles */
64 struct smb2_handle server_handle[NSERVERS];
67 static uint_t num_open_handles;
69 /* state information for the servers. We open NINSTANCES connections to
72 struct smb2_tree *tree[NINSTANCES];
75 struct cli_credentials *credentials;
78 /* the seeds and flags for each operation */
85 /* oplock break info */
88 struct smb2_handle server_handle;
92 } oplocks[NSERVERS][NINSTANCES];
94 /* change notify reply info */
98 union smb_notify notify;
99 } notifies[NSERVERS][NINSTANCES];
101 /* info relevant to the current operation */
110 static struct smb2_handle bad_smb2_handle;
113 #define BAD_HANDLE 0xFFFE
115 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
116 static void idle_func(struct smb2_transport *transport, void *private);
119 check if a string should be ignored. This is used as the basis
120 for all error ignore settings
122 static bool ignore_pattern(const char *str)
125 if (!options.ignore_patterns) return false;
127 for (i=0;options.ignore_patterns[i];i++) {
128 if (strcmp(options.ignore_patterns[i], str) == 0 ||
129 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
130 DEBUG(2,("Ignoring '%s'\n", str));
137 /*****************************************************
138 connect to the servers
139 *******************************************************/
140 static bool connect_servers_fast(void)
144 /* close all open files */
145 for (h=0;h<options.max_open_handles;h++) {
146 if (!open_handles[h].active) continue;
147 for (i=0;i<NSERVERS;i++) {
148 NTSTATUS status = smb2_util_close(servers[i].tree[open_handles[h].instance],
149 open_handles[h].server_handle[i]);
150 if (NT_STATUS_IS_ERR(status)) {
153 open_handles[h].active = false;
163 /*****************************************************
164 connect to the servers
165 *******************************************************/
166 static bool connect_servers(struct event_context *ev,
167 struct loadparm_context *lp_ctx)
171 if (options.fast_reconnect && servers[0].tree[0]) {
172 if (connect_servers_fast()) {
177 /* close any existing connections */
178 for (i=0;i<NSERVERS;i++) {
179 for (j=0;j<NINSTANCES;j++) {
180 if (servers[i].tree[j]) {
181 smb2_tdis(servers[i].tree[j]);
182 talloc_free(servers[i].tree[j]);
183 servers[i].tree[j] = NULL;
188 for (i=0;i<NSERVERS;i++) {
189 for (j=0;j<NINSTANCES;j++) {
191 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
192 servers[i].server_name, servers[i].share_name,
193 servers[i].credentials->username, j);
195 cli_credentials_set_workstation(servers[i].credentials,
196 "gentest", CRED_SPECIFIED);
198 status = smb2_connect(NULL, servers[i].server_name,
199 servers[i].share_name,
200 lp_resolve_context(lp_ctx),
201 servers[i].credentials,
204 if (!NT_STATUS_IS_OK(status)) {
205 printf("Failed to connect to \\\\%s\\%s - %s\n",
206 servers[i].server_name, servers[i].share_name,
211 // smb2_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
212 smb2_transport_idle_handler(servers[i].tree[j]->session->transport, idle_func, 50000, NULL);
220 work out the time skew between the servers - be conservative
222 static uint_t time_skew(void)
225 ret = labs(servers[0].tree[0]->session->transport->negotiate.system_time -
226 servers[1].tree[0]->session->transport->negotiate.system_time);
231 static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_handle *h2)
233 return memcmp(h1, h2, sizeof(struct smb2_handle)) == 0;
237 turn a server handle into a local handle
239 static uint_t fnum_to_handle(int server, int instance, struct smb2_handle server_handle)
242 for (i=0;i<options.max_open_handles;i++) {
243 if (!open_handles[i].active ||
244 instance != open_handles[i].instance) continue;
245 if (smb2_handle_equal(&open_handles[i].server_handle[server], &server_handle)) {
249 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
255 add some newly opened handles
257 static void gen_add_handle(int instance, const char *name, struct smb2_handle handles[NSERVERS])
260 for (h=0;h<options.max_open_handles;h++) {
261 if (!open_handles[h].active) break;
263 if (h == options.max_open_handles) {
264 /* we have to force close a random handle */
265 h = random() % options.max_open_handles;
266 for (i=0;i<NSERVERS;i++) {
268 status = smb2_util_close(servers[i].tree[open_handles[h].instance],
269 open_handles[h].server_handle[i]);
270 if (NT_STATUS_IS_ERR(status)) {
271 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
275 printf("Recovered handle %d\n", h);
278 for (i=0;i<NSERVERS;i++) {
279 open_handles[h].server_handle[i] = handles[i];
280 open_handles[h].instance = instance;
281 open_handles[h].active = true;
282 open_handles[h].name = name;
286 printf("OPEN num_open_handles=%d h=%d (%s)\n",
287 num_open_handles, h, name);
291 remove a closed handle
293 static void gen_remove_handle(int instance, struct smb2_handle handles[NSERVERS])
296 for (h=0;h<options.max_open_handles;h++) {
297 if (instance == open_handles[h].instance &&
298 smb2_handle_equal(&open_handles[h].server_handle[0], &handles[0])) {
299 open_handles[h].active = false;
301 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
303 open_handles[h].name);
307 printf("Removing invalid handle!?\n");
312 return true with 'chance' probability as a percentage
314 static bool gen_chance(uint_t chance)
316 return ((random() % 100) <= chance);
320 map an internal handle number to a server handle
322 static struct smb2_handle gen_lookup_handle(int server, uint16_t handle)
324 if (handle == BAD_HANDLE) return bad_smb2_handle;
325 return open_handles[handle].server_handle[server];
331 static uint16_t gen_fnum(int instance)
336 if (gen_chance(20)) return BAD_HANDLE;
338 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
339 h = random() % options.max_open_handles;
340 if (open_handles[h].active &&
341 open_handles[h].instance == instance) {
349 return a file handle, but skewed so we don't close the last
350 couple of handles too readily
352 static uint16_t gen_fnum_close(int instance)
354 if (num_open_handles < 5) {
355 if (gen_chance(90)) return BAD_HANDLE;
358 return gen_fnum(instance);
362 generate an integer in a specified range
364 static int gen_int_range(uint64_t min, uint64_t max)
367 return min + (r % (1+max-min));
371 return a fnum for use as a root fid
372 be careful to call GEN_SET_FNUM() when you use this!
374 static uint16_t gen_root_fid(int instance)
376 if (gen_chance(5)) return gen_fnum(instance);
381 generate a file offset
383 static int gen_offset(void)
385 if (gen_chance(20)) return 0;
386 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
387 return gen_int_range(0, 1024*1024);
393 static int gen_io_count(void)
395 if (gen_chance(20)) return 0;
396 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
397 return gen_int_range(0, 4096);
403 static const char *gen_fname(void)
405 const char *names[] = {"gentest\\gentest.dat",
410 "gentest\\foo4:teststream1",
411 "gentest\\foo4:teststream2",
413 "gentest\\foo5.exe:teststream3",
414 "gentest\\foo5.exe:teststream4",
417 "gentest\\blah\\blergh.txt",
418 "gentest\\blah\\blergh2",
419 "gentest\\blah\\blergh3.txt",
420 "gentest\\blah\\blergh4",
421 "gentest\\blah\\blergh5.txt",
422 "gentest\\blah\\blergh5",
425 /* this causes problem with w2k3 */
428 "gentest\\a_very_long_name.bin",
434 i = gen_int_range(0, ARRAY_SIZE(names)-1);
435 } while (ignore_pattern(names[i]));
441 generate a filename with a higher chance of choosing an already
444 static const char *gen_fname_open(int instance)
447 h = gen_fnum(instance);
448 if (h == BAD_HANDLE) {
451 return open_handles[h].name;
455 generate a wildcard pattern
457 static const char *gen_pattern(void)
460 const char *names[] = {"gentest\\*.dat",
463 "gentest\\blah\\*.*",
467 if (gen_chance(50)) return gen_fname();
470 i = gen_int_range(0, ARRAY_SIZE(names)-1);
471 } while (ignore_pattern(names[i]));
476 static uint32_t gen_bits_levels(int nlevels, ...)
482 va_start(ap, nlevels);
483 for (i=0;i<nlevels;i++) {
484 pct = va_arg(ap, uint32_t);
485 mask = va_arg(ap, uint32_t);
486 if (pct == 100 || gen_chance(pct)) {
488 return mask & random();
498 static uint32_t gen_bits_mask(uint_t mask)
500 uint_t ret = random();
505 generate a bitmask with high probability of the first mask
506 and low of the second
508 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
510 if (gen_chance(10)) return gen_bits_mask(mask2);
511 return gen_bits_mask(mask1);
517 static bool gen_bool(void)
519 return gen_bits_mask2(0x1, 0xFF);
523 generate ntrename flags
525 static uint16_t gen_rename_flags(void)
527 if (gen_chance(30)) return RENAME_FLAG_RENAME;
528 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
529 if (gen_chance(30)) return RENAME_FLAG_COPY;
530 return gen_bits_mask(0xFFFF);
535 return a set of lock flags
537 static uint16_t gen_lock_flags(void)
539 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
540 if (gen_chance(20)) return gen_bits_mask(0x1F);
541 if (gen_chance(50)) return SMB2_LOCK_FLAG_UNLOCK;
542 return gen_bits_mask(SMB2_LOCK_FLAG_SHARED |
543 SMB2_LOCK_FLAG_EXCLUSIVE |
544 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY);
548 generate a lock count
550 static off_t gen_lock_count(void)
552 return gen_int_range(0, 3);
556 generate a ntcreatex flags field
558 static uint32_t gen_ntcreatex_flags(void)
560 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
561 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
565 generate a NT access mask
567 static uint32_t gen_access_mask(void)
569 if (gen_chance(70)) return SEC_FLAG_MAXIMUM_ALLOWED;
570 if (gen_chance(70)) return SEC_FILE_ALL;
571 return gen_bits_mask(0xFFFFFFFF);
575 generate a ntcreatex create options bitfield
577 static uint32_t gen_create_options(void)
579 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
580 if (gen_chance(50)) return 0;
581 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
585 generate a ntcreatex open disposition
587 static uint32_t gen_open_disp(void)
589 if (gen_chance(50)) return NTCREATEX_DISP_OPEN_IF;
590 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
591 return gen_int_range(0, 5);
595 generate a file attrib combination
597 static uint32_t gen_attrib(void)
599 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
600 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
604 generate a unix timestamp
606 static time_t gen_timet(void)
608 if (gen_chance(30)) return 0;
609 return (time_t)random();
613 generate a unix timestamp
615 static NTTIME gen_nttime(void)
618 unix_to_nt_time(&ret, gen_timet());
623 generate a milliseconds protocol timeout
625 static uint32_t gen_timeout(void)
627 if (gen_chance(98)) return 0;
628 return random() % 50;
632 generate a file allocation size
634 static uint_t gen_alloc_size(void)
638 if (gen_chance(30)) return 0;
640 ret = random() % 4*1024*1024;
641 /* give a high chance of a round number */
642 if (gen_chance(60)) {
643 ret &= ~(1024*1024 - 1);
649 generate an ea_struct
651 static struct ea_struct gen_ea_struct(void)
654 const char *names[] = {"EAONE",
659 "AVERYLONGATTRIBUTENAME"};
660 const char *values[] = {"VALUE1",
665 "ASOMEWHATLONGERATTRIBUTEVALUE"};
671 i = gen_int_range(0, ARRAY_SIZE(names)-1);
672 } while (ignore_pattern(names[i]));
674 ea.name.s = names[i];
677 i = gen_int_range(0, ARRAY_SIZE(values)-1);
678 } while (ignore_pattern(values[i]));
680 ea.value = data_blob(values[i], strlen(values[i]));
682 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
689 generate an ea_struct
691 static struct smb_ea_list gen_ea_list(void)
693 struct smb_ea_list eas;
695 if (options.no_eas) {
699 eas.num_eas = gen_int_range(0, 3);
700 eas.eas = talloc_array(current_op.mem_ctx, struct ea_struct, eas.num_eas);
701 for (i=0;i<eas.num_eas;i++) {
702 eas.eas[i] = gen_ea_struct();
708 the idle function tries to cope with getting an oplock break on a connection, and
709 an operation on another connection blocking until that break is acked
710 we check for operations on all transports in the idle function
712 static void idle_func(struct smb2_transport *transport, void *private)
715 for (i=0;i<NSERVERS;i++) {
716 for (j=0;j<NINSTANCES;j++) {
717 if (servers[i].tree[j] &&
718 transport != servers[i].tree[j]->session->transport) {
719 // smb2_transport_process(servers[i].tree[j]->session->transport);
728 compare NTSTATUS, using checking ignored patterns
730 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
732 if (NT_STATUS_EQUAL(status1, status2)) return true;
734 /* one code being an error and the other OK is always an error */
735 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return false;
737 /* if we are ignoring one of the status codes then consider this a match */
738 if (ignore_pattern(nt_errstr(status1)) ||
739 ignore_pattern(nt_errstr(status2))) {
747 check for pending packets on all connections
749 static void check_pending(void)
755 for (j=0;j<NINSTANCES;j++) {
756 for (i=0;i<NSERVERS;i++) {
757 // smb2_transport_process(servers[i].tree[j]->session->transport);
763 check that the same oplock breaks have been received by all instances
765 static bool check_oplocks(const char *call)
774 for (j=0;j<NINSTANCES;j++) {
775 for (i=1;i<NSERVERS;i++) {
776 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
777 oplocks[0][j].handle != oplocks[i][j].handle ||
778 oplocks[0][j].level != oplocks[i][j].level) {
779 if (tries++ < 10) goto again;
780 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
781 oplocks[0][j].got_break,
782 oplocks[0][j].handle,
784 oplocks[i][j].got_break,
785 oplocks[i][j].handle,
786 oplocks[i][j].level);
792 /* if we got a break and closed then remove the handle */
793 for (j=0;j<NINSTANCES;j++) {
794 if (oplocks[0][j].got_break &&
795 oplocks[0][j].do_close) {
796 uint16_t fnums[NSERVERS];
797 for (i=0;i<NSERVERS;i++) {
798 fnums[i] = oplocks[i][j].fnum;
800 gen_remove_handle(j, fnums);
810 check that the same change notify info has been received by all instances
812 static bool check_notifies(const char *call)
821 for (j=0;j<NINSTANCES;j++) {
822 for (i=1;i<NSERVERS;i++) {
824 union smb_notify not1, not2;
826 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
827 if (tries++ < 10) goto again;
828 printf("Notify count inconsistent %d %d\n",
829 notifies[0][j].notify_count,
830 notifies[i][j].notify_count);
834 if (notifies[0][j].notify_count == 0) continue;
836 if (!NT_STATUS_EQUAL(notifies[0][j].status,
837 notifies[i][j].status)) {
838 printf("Notify status mismatch - %s - %s\n",
839 nt_errstr(notifies[0][j].status),
840 nt_errstr(notifies[i][j].status));
844 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
848 not1 = notifies[0][j].notify;
849 not2 = notifies[i][j].notify;
851 for (n=0;n<not1.nttrans.out.num_changes;n++) {
852 if (not1.nttrans.out.changes[n].action !=
853 not2.nttrans.out.changes[n].action) {
854 printf("Notify action %d inconsistent %d %d\n", n,
855 not1.nttrans.out.changes[n].action,
856 not2.nttrans.out.changes[n].action);
859 if (strcmp(not1.nttrans.out.changes[n].name.s,
860 not2.nttrans.out.changes[n].name.s)) {
861 printf("Notify name %d inconsistent %s %s\n", n,
862 not1.nttrans.out.changes[n].name.s,
863 not2.nttrans.out.changes[n].name.s);
866 if (not1.nttrans.out.changes[n].name.private_length !=
867 not2.nttrans.out.changes[n].name.private_length) {
868 printf("Notify name length %d inconsistent %d %d\n", n,
869 not1.nttrans.out.changes[n].name.private_length,
870 not2.nttrans.out.changes[n].name.private_length);
877 ZERO_STRUCT(notifies);
883 #define GEN_COPY_PARM do { \
885 for (i=1;i<NSERVERS;i++) { \
890 #define GEN_CALL(call) do { \
892 ZERO_STRUCT(oplocks); \
893 ZERO_STRUCT(notifies); \
894 for (i=0;i<NSERVERS;i++) { \
895 struct smb2_tree *tree = servers[i].tree[instance]; \
898 current_op.status = status[0]; \
899 for (i=1;i<NSERVERS;i++) { \
900 if (!compare_status(status[i], status[0])) { \
901 printf("status different in %s - %s %s\n", #call, \
902 nt_errstr(status[0]), nt_errstr(status[i])); \
906 if (!check_oplocks(#call)) return false; \
907 if (!check_notifies(#call)) return false; \
908 if (!NT_STATUS_IS_OK(status[0])) { \
913 #define ADD_HANDLE(name, field) do { \
914 struct smb2_handle handles[NSERVERS]; \
916 for (i=0;i<NSERVERS;i++) { \
917 handles[i] = parm[i].field; \
919 gen_add_handle(instance, name, handles); \
922 #define REMOVE_HANDLE(field) do { \
923 struct smb2_handle handles[NSERVERS]; \
925 for (i=0;i<NSERVERS;i++) { \
926 handles[i] = parm[i].field; \
928 gen_remove_handle(instance, handles); \
931 #define GEN_SET_FNUM(field) do { \
933 for (i=0;i<NSERVERS;i++) { \
934 parm[i].field = gen_lookup_handle(i, parm[i].field.data[0]); \
938 #define CHECK_EQUAL(field) do { \
939 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
940 printf("Mismatch in %s - 0x%llx 0x%llx\n", #field, \
941 (unsigned long long)parm[0].field, (unsigned long long)parm[1].field); \
946 #define CHECK_ATTRIB(field) do { \
947 if (!options.mask_indexing) { \
948 CHECK_EQUAL(field); \
949 } else if ((~FILE_ATTRIBUTE_NONINDEXED & parm[0].field) != (~FILE_ATTRIBUTE_NONINDEXED & 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_create(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, 90, 0x0, 70, 0x3, 100, 0xFF);
1007 parm[0].in.oplock_level = gen_bits_levels(3, 90, 0x0, 70, 0x9, 100, 0xFF);
1008 parm[0].in.impersonation_level = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFFFFFFFF);
1009 parm[0].in.create_flags = gen_bits_levels(2, 90, 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, 95, 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);
1023 parm[0].in.eas = gen_ea_list();
1025 if (!options.use_oplocks) {
1026 /* mask out oplocks */
1027 parm[0].in.oplock_level = 0;
1031 GEN_CALL(smb2_create(tree, current_op.mem_ctx, &parm[i]));
1033 CHECK_EQUAL(out.oplock_level);
1034 CHECK_EQUAL(out.reserved);
1035 CHECK_EQUAL(out.create_action);
1036 CHECK_NTTIMES_EQUAL(out.create_time);
1037 CHECK_NTTIMES_EQUAL(out.access_time);
1038 CHECK_NTTIMES_EQUAL(out.write_time);
1039 CHECK_NTTIMES_EQUAL(out.change_time);
1040 CHECK_EQUAL(out.alloc_size);
1041 CHECK_EQUAL(out.size);
1042 CHECK_ATTRIB(out.file_attr);
1043 CHECK_EQUAL(out.reserved2);
1045 /* ntcreatex creates a new file handle */
1046 ADD_HANDLE(parm[0].in.fname, out.file.handle);
1052 generate close operations
1054 static bool handler_close(int instance)
1056 struct smb2_close parm[NSERVERS];
1057 NTSTATUS status[NSERVERS];
1059 ZERO_STRUCT(parm[0]);
1060 parm[0].in.file.handle.data[0] = gen_fnum_close(instance);
1061 parm[0].in.flags = gen_bits_mask2(0x1, 0xFFFF);
1064 GEN_SET_FNUM(in.file.handle);
1065 GEN_CALL(smb2_close(tree, &parm[i]));
1067 CHECK_EQUAL(out.flags);
1068 CHECK_EQUAL(out._pad);
1069 CHECK_NTTIMES_EQUAL(out.create_time);
1070 CHECK_NTTIMES_EQUAL(out.access_time);
1071 CHECK_NTTIMES_EQUAL(out.write_time);
1072 CHECK_NTTIMES_EQUAL(out.change_time);
1073 CHECK_EQUAL(out.alloc_size);
1074 CHECK_EQUAL(out.size);
1075 CHECK_ATTRIB(out.file_attr);
1077 REMOVE_HANDLE(in.file.handle);
1083 generate read operations
1085 static bool handler_read(int instance)
1087 struct smb2_read parm[NSERVERS];
1088 NTSTATUS status[NSERVERS];
1090 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1091 parm[0].in.reserved = gen_bits_mask2(0x0, 0xFF);
1092 parm[0].in.length = gen_io_count();
1093 parm[0].in.offset = gen_offset();
1094 parm[0].in.min_count = gen_io_count();
1095 parm[0].in.channel = gen_bits_mask2(0x0, 0xFFFFFFFF);
1096 parm[0].in.remaining = gen_bits_mask2(0x0, 0xFFFFFFFF);
1097 parm[0].in.channel_offset = gen_bits_mask2(0x0, 0xFFFF);
1098 parm[0].in.channel_length = gen_bits_mask2(0x0, 0xFFFF);
1101 GEN_SET_FNUM(in.file.handle);
1102 GEN_CALL(smb2_read(tree, current_op.mem_ctx, &parm[i]));
1104 CHECK_EQUAL(out.remaining);
1105 CHECK_EQUAL(out.reserved);
1106 CHECK_EQUAL(out.data.length);
1112 generate write operations
1114 static bool handler_write(int instance)
1116 struct smb2_write parm[NSERVERS];
1117 NTSTATUS status[NSERVERS];
1119 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1120 parm[0].in.offset = gen_offset();
1121 parm[0].in.unknown1 = gen_bits_mask2(0, 0xFFFFFFFF);
1122 parm[0].in.unknown2 = gen_bits_mask2(0, 0xFFFFFFFF);
1123 parm[0].in.data = data_blob_talloc(current_op.mem_ctx, NULL,
1127 GEN_SET_FNUM(in.file.handle);
1128 GEN_CALL(smb2_write(tree, &parm[i]));
1130 CHECK_EQUAL(out._pad);
1131 CHECK_EQUAL(out.nwritten);
1132 CHECK_EQUAL(out.unknown1);
1138 generate lockingx operations
1140 static bool handler_lock(int instance)
1142 struct smb2_lock parm[NSERVERS];
1143 NTSTATUS status[NSERVERS];
1146 parm[0].level = RAW_LOCK_LOCKX;
1147 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1148 parm[0].in.lock_count = gen_lock_count();
1149 parm[0].in.reserved = gen_bits_mask2(0, 0xFFFFFFFF);
1151 parm[0].in.locks = talloc_array(current_op.mem_ctx,
1152 struct smb2_lock_element,
1153 parm[0].in.lock_count);
1154 for (n=0;n<parm[0].in.lock_count;n++) {
1155 parm[0].in.locks[n].offset = gen_offset();
1156 parm[0].in.locks[n].length = gen_io_count();
1157 /* don't yet cope with async replies */
1158 parm[0].in.locks[n].flags = gen_lock_flags() |
1159 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY;
1160 parm[0].in.locks[n].reserved = gen_bits_mask2(0x0, 0xFFFFFFFF);
1164 GEN_SET_FNUM(in.file.handle);
1165 GEN_CALL(smb2_lock(tree, &parm[i]));
1171 generate flush operations
1173 static bool handler_flush(int instance)
1175 struct smb2_flush parm[NSERVERS];
1176 NTSTATUS status[NSERVERS];
1178 ZERO_STRUCT(parm[0]);
1179 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1180 parm[0].in.reserved1 = gen_bits_mask2(0x0, 0xFFFF);
1181 parm[0].in.reserved2 = gen_bits_mask2(0x0, 0xFFFFFFFF);
1184 GEN_SET_FNUM(in.file.handle);
1185 GEN_CALL(smb2_flush(tree, &parm[i]));
1187 CHECK_EQUAL(out.reserved);
1193 generate echo operations
1195 static bool handler_echo(int instance)
1197 NTSTATUS status[NSERVERS];
1199 GEN_CALL(smb2_keepalive(tree->session->transport));
1207 generate a fileinfo query structure
1209 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1212 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1214 enum smb_fileinfo_level level;
1217 LVL(BASIC_INFORMATION),
1218 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1219 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1220 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(SMB2_ALL_INFORMATION),
1221 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1222 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION),
1223 LVL(SMB2_ALL_EAS), LVL(SMB2_ALL_INFORMATION),
1226 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1227 } while (ignore_pattern(levels[i].name));
1229 info->generic.level = levels[i].level;
1233 compare returned fileinfo structures
1235 static bool cmp_fileinfo(int instance,
1236 union smb_fileinfo parm[NSERVERS],
1237 NTSTATUS status[NSERVERS])
1241 switch (parm[0].generic.level) {
1242 case RAW_FILEINFO_GENERIC:
1245 case RAW_FILEINFO_BASIC_INFORMATION:
1246 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1247 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1248 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1249 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1250 CHECK_ATTRIB(basic_info.out.attrib);
1253 case RAW_FILEINFO_STANDARD_INFORMATION:
1254 CHECK_EQUAL(standard_info.out.alloc_size);
1255 CHECK_EQUAL(standard_info.out.size);
1256 CHECK_EQUAL(standard_info.out.nlink);
1257 CHECK_EQUAL(standard_info.out.delete_pending);
1258 CHECK_EQUAL(standard_info.out.directory);
1261 case RAW_FILEINFO_EA_INFORMATION:
1262 CHECK_EQUAL(ea_info.out.ea_size);
1265 case RAW_FILEINFO_NAME_INFORMATION:
1266 CHECK_WSTR_EQUAL(name_info.out.fname);
1269 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1270 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1273 case RAW_FILEINFO_STREAM_INFORMATION:
1274 CHECK_EQUAL(stream_info.out.num_streams);
1275 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1276 CHECK_EQUAL(stream_info.out.streams[i].size);
1277 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1278 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1282 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1283 CHECK_EQUAL(compression_info.out.compressed_size);
1284 CHECK_EQUAL(compression_info.out.format);
1285 CHECK_EQUAL(compression_info.out.unit_shift);
1286 CHECK_EQUAL(compression_info.out.chunk_shift);
1287 CHECK_EQUAL(compression_info.out.cluster_shift);
1290 case RAW_FILEINFO_INTERNAL_INFORMATION:
1291 CHECK_EQUAL(internal_information.out.file_id);
1294 case RAW_FILEINFO_ACCESS_INFORMATION:
1295 CHECK_EQUAL(access_information.out.access_flags);
1298 case RAW_FILEINFO_POSITION_INFORMATION:
1299 CHECK_EQUAL(position_information.out.position);
1302 case RAW_FILEINFO_MODE_INFORMATION:
1303 CHECK_EQUAL(mode_information.out.mode);
1306 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1307 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1310 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1311 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1312 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1313 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1314 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1315 CHECK_EQUAL(network_open_information.out.alloc_size);
1316 CHECK_EQUAL(network_open_information.out.size);
1317 CHECK_ATTRIB(network_open_information.out.attrib);
1320 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1321 CHECK_ATTRIB(attribute_tag_information.out.attrib);
1322 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1325 case RAW_FILEINFO_ALL_INFORMATION:
1326 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1327 CHECK_NTTIMES_EQUAL(all_info2.out.create_time);
1328 CHECK_NTTIMES_EQUAL(all_info2.out.access_time);
1329 CHECK_NTTIMES_EQUAL(all_info2.out.write_time);
1330 CHECK_NTTIMES_EQUAL(all_info2.out.change_time);
1331 CHECK_ATTRIB(all_info2.out.attrib);
1332 CHECK_EQUAL(all_info2.out.unknown1);
1333 CHECK_EQUAL(all_info2.out.alloc_size);
1334 CHECK_EQUAL(all_info2.out.size);
1335 CHECK_EQUAL(all_info2.out.nlink);
1336 CHECK_EQUAL(all_info2.out.delete_pending);
1337 CHECK_EQUAL(all_info2.out.directory);
1338 CHECK_EQUAL(all_info2.out.file_id);
1339 CHECK_EQUAL(all_info2.out.ea_size);
1340 CHECK_EQUAL(all_info2.out.access_mask);
1341 CHECK_EQUAL(all_info2.out.position);
1342 CHECK_EQUAL(all_info2.out.mode);
1343 CHECK_EQUAL(all_info2.out.alignment_requirement);
1344 CHECK_WSTR_EQUAL(all_info2.out.fname);
1347 case RAW_FILEINFO_SMB2_ALL_EAS:
1348 CHECK_EQUAL(all_eas.out.num_eas);
1349 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1350 CHECK_EQUAL(all_eas.out.eas[i].flags);
1351 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1352 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1356 /* Unhandled levels */
1358 case RAW_FILEINFO_SEC_DESC:
1359 case RAW_FILEINFO_EA_LIST:
1360 case RAW_FILEINFO_UNIX_BASIC:
1361 case RAW_FILEINFO_UNIX_LINK:
1362 case RAW_FILEINFO_UNIX_INFO2:
1370 generate qfileinfo operations
1372 static bool handler_qfileinfo(int instance)
1374 union smb_fileinfo parm[NSERVERS];
1375 NTSTATUS status[NSERVERS];
1377 parm[0].generic.in.file.handle.data[0] = gen_fnum(instance);
1379 gen_fileinfo(instance, &parm[0]);
1382 GEN_SET_FNUM(generic.in.file.handle);
1383 GEN_CALL(smb2_getinfo_file(tree, current_op.mem_ctx, &parm[i]));
1385 return cmp_fileinfo(instance, parm, status);
1390 generate a fileinfo query structure
1392 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1396 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1398 enum smb_setfileinfo_level level;
1401 LVL(BASIC_INFORMATION),
1402 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1403 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1404 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1405 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1408 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1409 } while (ignore_pattern(levels[i].name));
1411 info->generic.level = levels[i].level;
1413 switch (info->generic.level) {
1414 case RAW_SFILEINFO_BASIC_INFORMATION:
1415 info->basic_info.in.create_time = gen_nttime();
1416 info->basic_info.in.access_time = gen_nttime();
1417 info->basic_info.in.write_time = gen_nttime();
1418 info->basic_info.in.change_time = gen_nttime();
1419 info->basic_info.in.attrib = gen_attrib();
1421 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1422 info->disposition_info.in.delete_on_close = gen_bool();
1424 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1425 info->allocation_info.in.alloc_size = gen_alloc_size();
1427 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1428 info->end_of_file_info.in.size = gen_offset();
1430 case RAW_SFILEINFO_RENAME_INFORMATION:
1431 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
1432 info->rename_information.in.overwrite = gen_bool();
1433 info->rename_information.in.root_fid = gen_root_fid(instance);
1434 info->rename_information.in.new_name = gen_fname_open(instance);
1436 case RAW_SFILEINFO_POSITION_INFORMATION:
1437 info->position_information.in.position = gen_offset();
1439 case RAW_SFILEINFO_MODE_INFORMATION:
1440 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1442 case RAW_SFILEINFO_GENERIC:
1443 case RAW_SFILEINFO_SEC_DESC:
1444 case RAW_SFILEINFO_1023:
1445 case RAW_SFILEINFO_1025:
1446 case RAW_SFILEINFO_1029:
1447 case RAW_SFILEINFO_1032:
1448 case RAW_SFILEINFO_1039:
1449 case RAW_SFILEINFO_1040:
1456 generate setfileinfo operations
1458 static bool handler_sfileinfo(int instance)
1460 union smb_setfileinfo parm[NSERVERS];
1461 NTSTATUS status[NSERVERS];
1463 parm[0].generic.in.file.fnum = gen_fnum(instance);
1465 gen_setfileinfo(instance, &parm[0]);
1468 GEN_SET_FNUM(generic.in.file.handle);
1469 GEN_CALL(smb2_setinfo_file(tree, &parm[i]));
1475 wipe any relevant files
1477 static void wipe_files(void)
1482 for (i=0;i<NSERVERS;i++) {
1483 int n = smb2_deltree(servers[i].tree[0], "gentest");
1485 printf("Failed to wipe tree on server %d\n", i);
1488 status = smb2_util_mkdir(servers[i].tree[0], "gentest");
1489 if (NT_STATUS_IS_ERR(status)) {
1490 printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status));
1494 printf("Deleted %d files on server %d\n", n, i);
1500 dump the current seeds - useful for continuing a backtrack
1502 static void dump_seeds(void)
1507 if (!options.seeds_file) {
1510 f = fopen("seeds.tmp", "w");
1513 for (i=0;i<options.numops;i++) {
1514 fprintf(f, "%u\n", op_parms[i].seed);
1517 rename("seeds.tmp", options.seeds_file);
1523 the list of top-level operations that we will generate
1527 bool (*handler)(int instance);
1528 int count, success_count;
1530 {"CREATE", handler_create},
1531 {"CLOSE", handler_close},
1532 {"READ", handler_read},
1533 {"WRITE", handler_write},
1534 {"LOCK", handler_lock},
1535 {"FLUSH", handler_flush},
1536 {"ECHO", handler_echo},
1537 {"QFILEINFO", handler_qfileinfo},
1538 {"SFILEINFO", handler_sfileinfo},
1543 run the test with the current set of op_parms parameters
1544 return the number of operations that completed successfully
1546 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
1550 if (!connect_servers(ev, lp_ctx)) {
1551 printf("Failed to connect to servers\n");
1557 /* wipe any leftover files from old runs */
1560 /* reset the open handles array */
1561 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1562 num_open_handles = 0;
1564 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1565 gen_ops[i].count = 0;
1566 gen_ops[i].success_count = 0;
1569 for (op=0; op<options.numops; op++) {
1570 int instance, which_op;
1573 if (op_parms[op].disabled) continue;
1575 srandom(op_parms[op].seed);
1577 instance = gen_int_range(0, NINSTANCES-1);
1579 /* generate a non-ignored operation */
1581 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1582 } while (ignore_pattern(gen_ops[which_op].name));
1584 DEBUG(3,("Generating op %s on instance %d\n",
1585 gen_ops[which_op].name, instance));
1587 current_op.seed = op_parms[op].seed;
1588 current_op.opnum = op;
1589 current_op.name = gen_ops[which_op].name;
1590 current_op.status = NT_STATUS_OK;
1591 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1593 ret = gen_ops[which_op].handler(instance);
1595 talloc_free(current_op.mem_ctx);
1597 gen_ops[which_op].count++;
1598 if (NT_STATUS_IS_OK(current_op.status)) {
1599 gen_ops[which_op].success_count++;
1603 printf("Failed at operation %d - %s\n",
1604 op, gen_ops[which_op].name);
1608 if (op % 100 == 0) {
1613 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1614 printf("Op %-10s got %d/%d success\n",
1616 gen_ops[i].success_count,
1624 perform a backtracking analysis of the minimal set of operations
1625 to generate an error
1627 static void backtrack_analyze(struct event_context *ev,
1628 struct loadparm_context *lp_ctx)
1632 chunk = options.numops / 2;
1637 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1640 chunk = MIN(chunk, options.numops / 2);
1642 /* mark this range as disabled */
1643 max = MIN(options.numops, base+chunk);
1644 for (i=base;i<max; i++) {
1645 op_parms[i].disabled = true;
1647 printf("Testing %d ops with %d-%d disabled\n",
1648 options.numops, base, max-1);
1649 ret = run_test(ev, lp_ctx);
1650 printf("Completed %d of %d ops\n", ret, options.numops);
1651 for (i=base;i<max; i++) {
1652 op_parms[i].disabled = false;
1654 if (ret == options.numops) {
1655 /* this chunk is needed */
1657 } else if (ret < base) {
1658 printf("damn - inconsistent errors! found early error\n");
1659 options.numops = ret+1;
1662 /* it failed - this chunk isn't needed for a failure */
1663 memmove(&op_parms[base], &op_parms[max],
1664 sizeof(op_parms[0]) * (options.numops - max));
1665 options.numops = (ret+1) - (max - base);
1675 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
1678 } while (chunk > 0);
1680 printf("Reduced to %d ops\n", options.numops);
1681 ret = run_test(ev, lp_ctx);
1682 if (ret != options.numops - 1) {
1683 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
1688 start the main gentest process
1690 static bool start_gentest(struct event_context *ev,
1691 struct loadparm_context *lp_ctx)
1696 /* allocate the open_handles array */
1697 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
1699 srandom(options.seed);
1700 op_parms = calloc(options.numops, sizeof(op_parms[0]));
1702 /* generate the seeds - after this everything is deterministic */
1703 if (options.use_preset_seeds) {
1705 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
1707 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
1710 if (numops < options.numops) {
1711 options.numops = numops;
1713 for (op=0;op<options.numops;op++) {
1715 printf("Not enough seeds in %s\n", options.seeds_file);
1718 op_parms[op].seed = atoi(preset[op]);
1720 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
1722 for (op=0; op<options.numops; op++) {
1723 op_parms[op].seed = random();
1727 ret = run_test(ev, lp_ctx);
1729 if (ret != options.numops && options.analyze) {
1730 options.numops = ret+1;
1731 backtrack_analyze(ev, lp_ctx);
1732 } else if (options.analyze_always) {
1733 backtrack_analyze(ev, lp_ctx);
1734 } else if (options.analyze_continuous) {
1735 while (run_test(ev, lp_ctx) == options.numops) ;
1738 return ret == options.numops;
1742 static void usage(poptContext pc)
1746 gentest //server1/share1 //server2/share2 [options..]\n\
1748 poptPrintUsage(pc, stdout, 0);
1752 split a UNC name into server and share names
1754 static bool split_unc_name(const char *unc, char **server, char **share)
1756 char *p = strdup(unc);
1757 if (!p) return false;
1758 all_string_sub(p, "\\", "/", 0);
1759 if (strncmp(p, "//", 2) != 0) return false;
1762 p = strchr(*server, '/');
1763 if (!p) return false;
1773 /****************************************************************************
1775 ****************************************************************************/
1776 int main(int argc, char *argv[])
1779 int i, username_count=0;
1781 char *ignore_file=NULL;
1782 struct event_context *ev;
1783 struct loadparm_context *lp_ctx;
1787 enum {OPT_UNCLIST=1000};
1788 struct poptOption long_options[] = {
1790 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
1791 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
1792 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
1793 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
1794 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
1795 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
1796 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
1797 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
1798 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
1799 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
1800 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
1801 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
1802 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
1803 {"maskindexing", 0, POPT_ARG_NONE, &options.mask_indexing, 0, "mask out the indexed file attrib", NULL},
1804 {"noeas", 0, POPT_ARG_NONE, &options.no_eas, 0, "don't use extended attributes", NULL},
1806 POPT_COMMON_CONNECTION
1807 POPT_COMMON_CREDENTIALS
1812 memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
1815 options.seed = time(NULL);
1816 options.numops = 1000;
1817 options.max_open_handles = 20;
1818 options.seeds_file = "gentest_seeds.dat";
1820 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
1821 POPT_CONTEXT_KEEP_FIRST);
1823 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
1825 lp_ctx = cmdline_lp_ctx;
1826 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
1827 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
1828 cli_credentials_guess(servers[0].credentials, lp_ctx);
1829 cli_credentials_guess(servers[1].credentials, lp_ctx);
1831 while((opt = poptGetNextOpt(pc)) != -1) {
1834 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
1837 if (username_count == 2) {
1841 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
1848 options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
1851 argv_new = discard_const_p(char *, poptGetArgs(pc));
1853 for (i=0; i<argc; i++) {
1854 if (argv_new[i] == NULL) {
1860 if (!(argc_new >= 3)) {
1867 setup_logging("gentest", DEBUG_STDOUT);
1869 if (argc < 3 || argv[1][0] == '-') {
1874 setup_logging(argv[0], DEBUG_STDOUT);
1876 for (i=0;i<NSERVERS;i++) {
1877 const char *share = argv[1+i];
1878 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
1879 printf("Invalid share name '%s'\n", share);
1884 if (username_count == 0) {
1888 if (username_count == 1) {
1889 servers[1].credentials = servers[0].credentials;
1892 printf("seed=%u\n", options.seed);
1894 ev = event_context_init(talloc_autofree_context());
1896 gensec_init(lp_ctx);
1898 ret = start_gentest(ev, lp_ctx);
1901 printf("gentest completed - no errors\n");
1903 printf("gentest failed\n");