2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "system/time.h"
23 #include "system/filesys.h"
24 #include "libcli/raw/request.h"
25 #include "libcli/libcli.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "librpc/gen_ndr/ndr_security.h"
28 #include "auth/gensec/gensec.h"
29 #include "torture/torture.h"
35 static struct gentest_options {
39 BOOL analyze_continuous;
40 uint_t max_open_handles;
44 char **ignore_patterns;
45 const char *seeds_file;
46 BOOL use_preset_seeds;
50 /* mapping between open handles on the server and local handles */
54 uint_t server_fnum[NSERVERS];
57 static uint_t num_open_handles;
59 /* state information for the servers. We open NINSTANCES connections to
62 struct smbcli_state *cli[NINSTANCES];
65 struct cli_credentials *credentials;
68 /* the seeds and flags for each operation */
75 /* oplock break info */
82 } oplocks[NSERVERS][NINSTANCES];
84 /* change notify reply info */
88 union smb_notify notify;
89 } notifies[NSERVERS][NINSTANCES];
91 /* info relevant to the current operation */
102 #define BAD_HANDLE 0xFFFE
104 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
105 static void idle_func(struct smbcli_transport *transport, void *private);
108 check if a string should be ignored. This is used as the basis
109 for all error ignore settings
111 static BOOL ignore_pattern(const char *str)
114 if (!options.ignore_patterns) return False;
116 for (i=0;options.ignore_patterns[i];i++) {
117 if (strcmp(options.ignore_patterns[i], str) == 0 ||
118 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
119 DEBUG(2,("Ignoring '%s'\n", str));
126 /*****************************************************
127 connect to the servers
128 *******************************************************/
129 static BOOL connect_servers_fast(void)
133 /* close all open files */
134 for (h=0;h<options.max_open_handles;h++) {
135 if (!open_handles[h].active) continue;
136 for (i=0;i<NSERVERS;i++) {
137 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
138 open_handles[h].server_fnum[i])))) {
141 open_handles[h].active = False;
151 /*****************************************************
152 connect to the servers
153 *******************************************************/
154 static BOOL connect_servers(void)
158 if (options.fast_reconnect && servers[0].cli[0]) {
159 if (connect_servers_fast()) {
164 /* close any existing connections */
165 for (i=0;i<NSERVERS;i++) {
166 for (j=0;j<NINSTANCES;j++) {
167 if (servers[i].cli[j]) {
168 smbcli_tdis(servers[i].cli[j]);
169 talloc_free(servers[i].cli[j]);
170 servers[i].cli[j] = NULL;
175 for (i=0;i<NSERVERS;i++) {
176 for (j=0;j<NINSTANCES;j++) {
178 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
179 servers[i].server_name, servers[i].share_name,
180 servers[i].credentials->username, j);
182 cli_credentials_set_workstation(servers[i].credentials,
183 "gentest", CRED_SPECIFIED);
185 status = smbcli_full_connection(NULL, &servers[i].cli[j],
186 servers[i].server_name,
187 servers[i].share_name, NULL,
188 servers[i].credentials, NULL);
189 if (!NT_STATUS_IS_OK(status)) {
190 printf("Failed to connect to \\\\%s\\%s - %s\n",
191 servers[i].server_name, servers[i].share_name,
196 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
197 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
205 work out the time skew between the servers - be conservative
207 static uint_t time_skew(void)
210 ret = ABS(servers[0].cli[0]->transport->negotiate.server_time -
211 servers[1].cli[0]->transport->negotiate.server_time);
216 turn an fnum for an instance into a handle
218 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
221 for (i=0;i<options.max_open_handles;i++) {
222 if (!open_handles[i].active ||
223 instance != open_handles[i].instance) continue;
224 if (open_handles[i].server_fnum[server] == fnum) {
228 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
229 fnum, server, instance);
234 add some newly opened handles
236 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
239 for (h=0;h<options.max_open_handles;h++) {
240 if (!open_handles[h].active) break;
242 if (h == options.max_open_handles) {
243 /* we have to force close a random handle */
244 h = random() % options.max_open_handles;
245 for (i=0;i<NSERVERS;i++) {
246 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
247 open_handles[h].server_fnum[i])))) {
248 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
249 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
252 printf("Recovered handle %d\n", h);
255 for (i=0;i<NSERVERS;i++) {
256 open_handles[h].server_fnum[i] = fnums[i];
257 open_handles[h].instance = instance;
258 open_handles[h].active = True;
259 open_handles[h].name = name;
263 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
265 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
270 remove a closed handle
272 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
275 for (h=0;h<options.max_open_handles;h++) {
276 if (instance == open_handles[h].instance &&
277 open_handles[h].server_fnum[0] == fnums[0]) {
278 open_handles[h].active = False;
280 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
282 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
283 open_handles[h].name);
287 printf("Removing invalid handle!?\n");
292 return True with 'chance' probability as a percentage
294 static BOOL gen_chance(uint_t chance)
296 return ((random() % 100) <= chance);
300 map an internal handle number to a server fnum
302 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
304 if (handle == BAD_HANDLE) return handle;
305 return open_handles[handle].server_fnum[server];
311 static uint16_t gen_fnum(int instance)
316 if (gen_chance(20)) return BAD_HANDLE;
318 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
319 h = random() % options.max_open_handles;
320 if (open_handles[h].active &&
321 open_handles[h].instance == instance) {
329 return a file handle, but skewed so we don't close the last
330 couple of handles too readily
332 static uint16_t gen_fnum_close(int instance)
334 if (num_open_handles < 3) {
335 if (gen_chance(80)) return BAD_HANDLE;
338 return gen_fnum(instance);
342 generate an integer in a specified range
344 static int gen_int_range(uint_t min, uint_t max)
347 return min + (r % (1+max-min));
351 return a fnum for use as a root fid
352 be careful to call GEN_SET_FNUM() when you use this!
354 static uint16_t gen_root_fid(int instance)
356 if (gen_chance(5)) return gen_fnum(instance);
361 generate a file offset
363 static int gen_offset(void)
365 if (gen_chance(20)) return 0;
366 return gen_int_range(0, 1024*1024);
372 static int gen_io_count(void)
374 if (gen_chance(20)) return 0;
375 return gen_int_range(0, 4096);
381 static const char *gen_fname(void)
383 const char *names[] = {"\\gentest\\gentest.dat",
385 "\\gentest\\foo2.sym",
386 "\\gentest\\foo3.dll",
388 "\\gentest\\foo4:teststream1",
389 "\\gentest\\foo4:teststream2",
390 "\\gentest\\foo5.exe",
391 "\\gentest\\foo5.exe:teststream3",
392 "\\gentest\\foo5.exe:teststream4",
393 "\\gentest\\foo6.com",
395 "\\gentest\\blah\\blergh.txt",
396 "\\gentest\\blah\\blergh2",
397 "\\gentest\\blah\\blergh3.txt",
398 "\\gentest\\blah\\blergh4",
399 "\\gentest\\blah\\blergh5.txt",
400 "\\gentest\\blah\\blergh5",
401 "\\gentest\\blah\\.",
403 /* this causes problem with w2k3 */
404 "\\gentest\\blah\\..",
406 "\\gentest\\a_very_long_name.bin",
412 i = gen_int_range(0, ARRAY_SIZE(names)-1);
413 } while (ignore_pattern(names[i]));
419 generate a filename with a higher chance of choosing an already
422 static const char *gen_fname_open(int instance)
425 h = gen_fnum(instance);
426 if (h == BAD_HANDLE) {
429 return open_handles[h].name;
433 generate a wildcard pattern
435 static const char *gen_pattern(void)
438 const char *names[] = {"\\gentest\\*.dat",
441 "\\gentest\\blah\\*.*",
442 "\\gentest\\blah\\*",
445 if (gen_chance(50)) return gen_fname();
448 i = gen_int_range(0, ARRAY_SIZE(names)-1);
449 } while (ignore_pattern(names[i]));
457 static uint32_t gen_bits_mask(uint_t mask)
459 uint_t ret = random();
464 generate a bitmask with high probability of the first mask
465 and low of the second
467 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
469 if (gen_chance(10)) return gen_bits_mask(mask2);
470 return gen_bits_mask(mask1);
476 static BOOL gen_bool(void)
478 return gen_bits_mask2(0x1, 0xFF);
482 generate ntrename flags
484 static uint16_t gen_rename_flags(void)
486 if (gen_chance(30)) return RENAME_FLAG_RENAME;
487 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
488 if (gen_chance(30)) return RENAME_FLAG_COPY;
489 return gen_bits_mask(0xFFFF);
494 return a lockingx lock mode
496 static uint16_t gen_lock_mode(void)
498 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
499 if (gen_chance(20)) return gen_bits_mask(0x1F);
500 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
506 static uint16_t gen_pid(void)
508 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
513 generate a lock count
515 static off_t gen_lock_count(void)
517 return gen_int_range(0, 3);
521 generate a ntcreatex flags field
523 static uint32_t gen_ntcreatex_flags(void)
525 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
526 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
530 generate a NT access mask
532 static uint32_t gen_access_mask(void)
534 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
535 if (gen_chance(20)) return SEC_FILE_ALL;
536 return gen_bits_mask(0xFFFFFFFF);
540 generate a ntcreatex create options bitfield
542 static uint32_t gen_create_options(void)
544 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
545 if (gen_chance(50)) return 0;
546 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
550 generate a ntcreatex open disposition
552 static uint32_t gen_open_disp(void)
554 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
555 return gen_int_range(0, 5);
559 generate an openx open mode
561 static uint16_t gen_openx_mode(void)
563 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
564 if (gen_chance(20)) return gen_bits_mask(0xFF);
565 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
569 generate an openx flags field
571 static uint16_t gen_openx_flags(void)
573 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
574 return gen_bits_mask(0x7);
578 generate an openx open function
580 static uint16_t gen_openx_func(void)
582 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
583 return gen_bits_mask(0x13);
587 generate a file attrib combination
589 static uint32_t gen_attrib(void)
591 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
592 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
596 generate a unix timestamp
598 static time_t gen_timet(void)
600 if (gen_chance(30)) return 0;
601 return (time_t)random();
605 generate a unix timestamp
607 static NTTIME gen_nttime(void)
610 unix_to_nt_time(&ret, gen_timet());
615 generate a milliseconds protocol timeout
617 static uint32_t gen_timeout(void)
619 if (gen_chance(98)) return 0;
620 return random() % 50;
624 generate a file allocation size
626 static uint_t gen_alloc_size(void)
630 if (gen_chance(30)) return 0;
632 ret = random() % 4*1024*1024;
633 /* give a high chance of a round number */
634 if (gen_chance(60)) {
635 ret &= ~(1024*1024 - 1);
641 generate an ea_struct
643 static struct ea_struct gen_ea_struct(void)
646 const char *names[] = {"EAONE",
651 "AVERYLONGATTRIBUTENAME"};
652 const char *values[] = {"VALUE1",
657 "ASOMEWHATLONGERATTRIBUTEVALUE"};
661 i = gen_int_range(0, ARRAY_SIZE(names)-1);
662 } while (ignore_pattern(names[i]));
664 ea.name.s = names[i];
667 i = gen_int_range(0, ARRAY_SIZE(values)-1);
668 } while (ignore_pattern(values[i]));
670 ea.value = data_blob(values[i], strlen(values[i]));
672 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
680 this is called when a change notify reply comes in
682 static void async_notify(struct smbcli_request *req)
684 union smb_notify notify;
688 struct smbcli_transport *transport = req->transport;
690 tid = SVAL(req->in.hdr, HDR_TID);
692 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
693 if (NT_STATUS_IS_OK(status)) {
694 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
696 notify.notify.out.num_changes,
697 notify.notify.out.changes[0].action,
698 notify.notify.out.changes[0].name.s);
701 for (i=0;i<NSERVERS;i++) {
702 for (j=0;j<NINSTANCES;j++) {
703 if (transport == servers[i].cli[j]->transport &&
704 tid == servers[i].cli[j]->tree->tid) {
705 notifies[i][j].notify_count++;
706 notifies[i][j].status = status;
707 notifies[i][j].notify = notify;
713 static void oplock_handler_close_recv(struct smbcli_request *req)
716 status = smbcli_request_simple_recv(req);
717 if (!NT_STATUS_IS_OK(status)) {
718 printf("close failed in oplock_handler\n");
719 smb_panic("close failed in oplock_handler");
724 the oplock handler will either ack the break or close the file
726 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
732 struct smbcli_tree *tree = NULL;
733 struct smbcli_request *req;
735 srandom(current_op.seed);
736 do_close = gen_chance(50);
738 for (i=0;i<NSERVERS;i++) {
739 for (j=0;j<NINSTANCES;j++) {
740 if (transport == servers[i].cli[j]->transport &&
741 tid == servers[i].cli[j]->tree->tid) {
742 oplocks[i][j].got_break = True;
743 oplocks[i][j].fnum = fnum;
744 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
745 oplocks[i][j].level = level;
746 oplocks[i][j].do_close = do_close;
747 tree = servers[i].cli[j]->tree;
753 printf("Oplock break not for one of our trees!?\n");
758 printf("oplock ack fnum=%d\n", fnum);
759 return smbcli_oplock_ack(tree, fnum, level);
762 printf("oplock close fnum=%d\n", fnum);
764 io.close.level = RAW_CLOSE_CLOSE;
765 io.close.file.fnum = fnum;
766 io.close.in.write_time = 0;
767 req = smb_raw_close_send(tree, &io);
770 printf("WARNING: close failed in oplock_handler_close - %s\n",
775 req->async.fn = oplock_handler_close_recv;
776 req->async.private = NULL;
783 the idle function tries to cope with getting an oplock break on a connection, and
784 an operation on another connection blocking until that break is acked
785 we check for operations on all transports in the idle function
787 static void idle_func(struct smbcli_transport *transport, void *private)
790 for (i=0;i<NSERVERS;i++) {
791 for (j=0;j<NINSTANCES;j++) {
792 if (servers[i].cli[j] &&
793 transport != servers[i].cli[j]->transport) {
794 smbcli_transport_process(servers[i].cli[j]->transport);
803 compare NTSTATUS, using checking ignored patterns
805 static BOOL compare_status(NTSTATUS status1, NTSTATUS status2)
807 if (NT_STATUS_EQUAL(status1, status2)) return True;
809 /* one code being an error and the other OK is always an error */
810 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return False;
812 /* if we are ignoring one of the status codes then consider this a match */
813 if (ignore_pattern(nt_errstr(status1)) ||
814 ignore_pattern(nt_errstr(status2))) {
822 check for pending packets on all connections
824 static void check_pending(void)
830 for (j=0;j<NINSTANCES;j++) {
831 for (i=0;i<NSERVERS;i++) {
832 smbcli_transport_process(servers[i].cli[j]->transport);
838 check that the same oplock breaks have been received by all instances
840 static BOOL check_oplocks(const char *call)
848 for (j=0;j<NINSTANCES;j++) {
849 for (i=1;i<NSERVERS;i++) {
850 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
851 oplocks[0][j].handle != oplocks[i][j].handle ||
852 oplocks[0][j].level != oplocks[i][j].level) {
853 if (tries++ < 10) goto again;
854 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
855 oplocks[0][j].got_break,
856 oplocks[0][j].handle,
858 oplocks[i][j].got_break,
859 oplocks[i][j].handle,
860 oplocks[i][j].level);
866 /* if we got a break and closed then remove the handle */
867 for (j=0;j<NINSTANCES;j++) {
868 if (oplocks[0][j].got_break &&
869 oplocks[0][j].do_close) {
870 uint16_t fnums[NSERVERS];
871 for (i=0;i<NSERVERS;i++) {
872 fnums[i] = oplocks[i][j].fnum;
874 gen_remove_handle(j, fnums);
883 check that the same change notify info has been received by all instances
885 static BOOL check_notifies(const char *call)
893 for (j=0;j<NINSTANCES;j++) {
894 for (i=1;i<NSERVERS;i++) {
896 union smb_notify not1, not2;
898 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
899 if (tries++ < 10) goto again;
900 printf("Notify count inconsistent %d %d\n",
901 notifies[0][j].notify_count,
902 notifies[i][j].notify_count);
906 if (notifies[0][j].notify_count == 0) continue;
908 if (!NT_STATUS_EQUAL(notifies[0][j].status,
909 notifies[i][j].status)) {
910 printf("Notify status mismatch - %s - %s\n",
911 nt_errstr(notifies[0][j].status),
912 nt_errstr(notifies[i][j].status));
916 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
920 not1 = notifies[0][j].notify;
921 not2 = notifies[i][j].notify;
923 for (n=0;n<not1.notify.out.num_changes;n++) {
924 if (not1.notify.out.changes[n].action !=
925 not2.notify.out.changes[n].action) {
926 printf("Notify action %d inconsistent %d %d\n", n,
927 not1.notify.out.changes[n].action,
928 not2.notify.out.changes[n].action);
931 if (strcmp(not1.notify.out.changes[n].name.s,
932 not2.notify.out.changes[n].name.s)) {
933 printf("Notify name %d inconsistent %s %s\n", n,
934 not1.notify.out.changes[n].name.s,
935 not2.notify.out.changes[n].name.s);
938 if (not1.notify.out.changes[n].name.private_length !=
939 not2.notify.out.changes[n].name.private_length) {
940 printf("Notify name length %d inconsistent %d %d\n", n,
941 not1.notify.out.changes[n].name.private_length,
942 not2.notify.out.changes[n].name.private_length);
949 ZERO_STRUCT(notifies);
955 #define GEN_COPY_PARM do { \
957 for (i=1;i<NSERVERS;i++) { \
962 #define GEN_CALL(call) do { \
964 ZERO_STRUCT(oplocks); \
965 ZERO_STRUCT(notifies); \
966 for (i=0;i<NSERVERS;i++) { \
967 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
970 current_op.status = status[0]; \
971 for (i=1;i<NSERVERS;i++) { \
972 if (!compare_status(status[i], status[0])) { \
973 printf("status different in %s - %s %s\n", #call, \
974 nt_errstr(status[0]), nt_errstr(status[i])); \
978 if (!check_oplocks(#call)) return False; \
979 if (!check_notifies(#call)) return False; \
980 if (!NT_STATUS_IS_OK(status[0])) { \
985 #define ADD_HANDLE(name, field) do { \
986 uint16_t fnums[NSERVERS]; \
988 for (i=0;i<NSERVERS;i++) { \
989 fnums[i] = parm[i].field; \
991 gen_add_handle(instance, name, fnums); \
994 #define REMOVE_HANDLE(field) do { \
995 uint16_t fnums[NSERVERS]; \
997 for (i=0;i<NSERVERS;i++) { \
998 fnums[i] = parm[i].field; \
1000 gen_remove_handle(instance, fnums); \
1003 #define GEN_SET_FNUM(field) do { \
1005 for (i=0;i<NSERVERS;i++) { \
1006 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
1010 #define CHECK_EQUAL(field) do { \
1011 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1012 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1013 (int)parm[0].field, (int)parm[1].field); \
1018 #define CHECK_WSTR_EQUAL(field) do { \
1019 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1020 printf("%s is NULL!\n", #field); \
1023 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1024 printf("Mismatch in %s - %s %s\n", #field, \
1025 parm[0].field.s, parm[1].field.s); \
1028 CHECK_EQUAL(field.private_length); \
1031 #define CHECK_BLOB_EQUAL(field) do { \
1032 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1033 printf("Mismatch in %s\n", #field); \
1036 CHECK_EQUAL(field.length); \
1039 #define CHECK_TIMES_EQUAL(field) do { \
1040 if (ABS(parm[0].field - parm[1].field) > time_skew() && \
1041 !ignore_pattern(#field)) { \
1042 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1043 (int)parm[0].field, (int)parm[1].field); \
1048 #define CHECK_NTTIMES_EQUAL(field) do { \
1049 if (ABS(nt_time_to_unix(parm[0].field) - \
1050 nt_time_to_unix(parm[1].field)) > time_skew() && \
1051 !ignore_pattern(#field)) { \
1052 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1053 (int)nt_time_to_unix(parm[0].field), \
1054 (int)nt_time_to_unix(parm[1].field)); \
1060 generate openx operations
1062 static BOOL handler_openx(int instance)
1064 union smb_open parm[NSERVERS];
1065 NTSTATUS status[NSERVERS];
1067 parm[0].openx.level = RAW_OPEN_OPENX;
1068 parm[0].openx.in.flags = gen_openx_flags();
1069 parm[0].openx.in.open_mode = gen_openx_mode();
1070 parm[0].openx.in.search_attrs = gen_attrib();
1071 parm[0].openx.in.file_attrs = gen_attrib();
1072 parm[0].openx.in.write_time = gen_timet();
1073 parm[0].openx.in.open_func = gen_openx_func();
1074 parm[0].openx.in.size = gen_io_count();
1075 parm[0].openx.in.timeout = gen_timeout();
1076 parm[0].openx.in.fname = gen_fname_open(instance);
1078 if (!options.use_oplocks) {
1079 /* mask out oplocks */
1080 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1081 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1085 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1087 CHECK_EQUAL(openx.out.attrib);
1088 CHECK_EQUAL(openx.out.size);
1089 CHECK_EQUAL(openx.out.access);
1090 CHECK_EQUAL(openx.out.ftype);
1091 CHECK_EQUAL(openx.out.devstate);
1092 CHECK_EQUAL(openx.out.action);
1093 CHECK_EQUAL(openx.out.access_mask);
1094 CHECK_EQUAL(openx.out.unknown);
1095 CHECK_TIMES_EQUAL(openx.out.write_time);
1097 /* open creates a new file handle */
1098 ADD_HANDLE(parm[0].openx.in.fname, openx.file.fnum);
1105 generate open operations
1107 static BOOL handler_open(int instance)
1109 union smb_open parm[NSERVERS];
1110 NTSTATUS status[NSERVERS];
1112 parm[0].openold.level = RAW_OPEN_OPEN;
1113 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1114 parm[0].openold.in.search_attrs = gen_attrib();
1115 parm[0].openold.in.fname = gen_fname_open(instance);
1117 if (!options.use_oplocks) {
1118 /* mask out oplocks */
1119 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1120 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1124 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1126 CHECK_EQUAL(openold.out.attrib);
1127 CHECK_TIMES_EQUAL(openold.out.write_time);
1128 CHECK_EQUAL(openold.out.size);
1129 CHECK_EQUAL(openold.out.rmode);
1131 /* open creates a new file handle */
1132 ADD_HANDLE(parm[0].openold.in.fname, openold.file.fnum);
1139 generate ntcreatex operations
1141 static BOOL handler_ntcreatex(int instance)
1143 union smb_open parm[NSERVERS];
1144 NTSTATUS status[NSERVERS];
1146 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1147 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1148 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1149 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1150 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1151 parm[0].ntcreatex.in.file_attr = gen_attrib();
1152 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1153 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1154 parm[0].ntcreatex.in.create_options = gen_create_options();
1155 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1156 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1157 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1159 if (!options.use_oplocks) {
1160 /* mask out oplocks */
1161 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1162 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1166 if (parm[0].ntcreatex.in.root_fid != 0) {
1167 GEN_SET_FNUM(ntcreatex.in.root_fid);
1169 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1171 CHECK_EQUAL(ntcreatex.out.oplock_level);
1172 CHECK_EQUAL(ntcreatex.out.create_action);
1173 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1174 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1175 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1176 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1177 CHECK_EQUAL(ntcreatex.out.attrib);
1178 CHECK_EQUAL(ntcreatex.out.alloc_size);
1179 CHECK_EQUAL(ntcreatex.out.size);
1180 CHECK_EQUAL(ntcreatex.out.file_type);
1181 CHECK_EQUAL(ntcreatex.out.ipc_state);
1182 CHECK_EQUAL(ntcreatex.out.is_directory);
1184 /* ntcreatex creates a new file handle */
1185 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.file.fnum);
1191 generate close operations
1193 static BOOL handler_close(int instance)
1195 union smb_close parm[NSERVERS];
1196 NTSTATUS status[NSERVERS];
1198 parm[0].close.level = RAW_CLOSE_CLOSE;
1199 parm[0].close.file.fnum = gen_fnum_close(instance);
1200 parm[0].close.in.write_time = gen_timet();
1203 GEN_SET_FNUM(close.file.fnum);
1204 GEN_CALL(smb_raw_close(tree, &parm[i]));
1206 REMOVE_HANDLE(close.file.fnum);
1212 generate unlink operations
1214 static BOOL handler_unlink(int instance)
1216 union smb_unlink parm[NSERVERS];
1217 NTSTATUS status[NSERVERS];
1219 parm[0].unlink.in.pattern = gen_pattern();
1220 parm[0].unlink.in.attrib = gen_attrib();
1223 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1229 generate chkpath operations
1231 static BOOL handler_chkpath(int instance)
1233 union smb_chkpath parm[NSERVERS];
1234 NTSTATUS status[NSERVERS];
1236 parm[0].chkpath.in.path = gen_fname_open(instance);
1239 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1245 generate mkdir operations
1247 static BOOL handler_mkdir(int instance)
1249 union smb_mkdir parm[NSERVERS];
1250 NTSTATUS status[NSERVERS];
1252 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1253 parm[0].mkdir.in.path = gen_fname_open(instance);
1256 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1262 generate rmdir operations
1264 static BOOL handler_rmdir(int instance)
1266 struct smb_rmdir parm[NSERVERS];
1267 NTSTATUS status[NSERVERS];
1269 parm[0].in.path = gen_fname_open(instance);
1272 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1278 generate rename operations
1280 static BOOL handler_rename(int instance)
1282 union smb_rename parm[NSERVERS];
1283 NTSTATUS status[NSERVERS];
1285 parm[0].generic.level = RAW_RENAME_RENAME;
1286 parm[0].rename.in.pattern1 = gen_pattern();
1287 parm[0].rename.in.pattern2 = gen_pattern();
1288 parm[0].rename.in.attrib = gen_attrib();
1291 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1297 generate ntrename operations
1299 static BOOL handler_ntrename(int instance)
1301 union smb_rename parm[NSERVERS];
1302 NTSTATUS status[NSERVERS];
1304 parm[0].generic.level = RAW_RENAME_NTRENAME;
1305 parm[0].ntrename.in.old_name = gen_fname();
1306 parm[0].ntrename.in.new_name = gen_fname();
1307 parm[0].ntrename.in.attrib = gen_attrib();
1308 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1309 parm[0].ntrename.in.flags = gen_rename_flags();
1312 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1319 generate seek operations
1321 static BOOL handler_seek(int instance)
1323 union smb_seek parm[NSERVERS];
1324 NTSTATUS status[NSERVERS];
1326 parm[0].lseek.file.fnum = gen_fnum(instance);
1327 parm[0].lseek.in.mode = gen_bits_mask2(0x3, 0xFFFF);
1328 parm[0].lseek.in.offset = gen_offset();
1331 GEN_SET_FNUM(lseek.file.fnum);
1332 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1334 CHECK_EQUAL(lseek.out.offset);
1341 generate readx operations
1343 static BOOL handler_readx(int instance)
1345 union smb_read parm[NSERVERS];
1346 NTSTATUS status[NSERVERS];
1348 parm[0].readx.level = RAW_READ_READX;
1349 parm[0].readx.file.fnum = gen_fnum(instance);
1350 parm[0].readx.in.offset = gen_offset();
1351 parm[0].readx.in.mincnt = gen_io_count();
1352 parm[0].readx.in.maxcnt = gen_io_count();
1353 parm[0].readx.in.remaining = gen_io_count();
1354 parm[0].readx.out.data = talloc_size(current_op.mem_ctx,
1355 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1358 GEN_SET_FNUM(readx.file.fnum);
1359 GEN_CALL(smb_raw_read(tree, &parm[i]));
1361 CHECK_EQUAL(readx.out.remaining);
1362 CHECK_EQUAL(readx.out.compaction_mode);
1363 CHECK_EQUAL(readx.out.nread);
1369 generate writex operations
1371 static BOOL handler_writex(int instance)
1373 union smb_write parm[NSERVERS];
1374 NTSTATUS status[NSERVERS];
1376 parm[0].writex.level = RAW_WRITE_WRITEX;
1377 parm[0].writex.file.fnum = gen_fnum(instance);
1378 parm[0].writex.in.offset = gen_offset();
1379 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1380 parm[0].writex.in.remaining = gen_io_count();
1381 parm[0].writex.in.count = gen_io_count();
1382 parm[0].writex.in.data = talloc_zero_size(current_op.mem_ctx, parm[0].writex.in.count);
1385 GEN_SET_FNUM(writex.file.fnum);
1386 GEN_CALL(smb_raw_write(tree, &parm[i]));
1388 CHECK_EQUAL(writex.out.nwritten);
1389 CHECK_EQUAL(writex.out.remaining);
1395 generate lockingx operations
1397 static BOOL handler_lockingx(int instance)
1399 union smb_lock parm[NSERVERS];
1400 NTSTATUS status[NSERVERS];
1403 parm[0].lockx.level = RAW_LOCK_LOCKX;
1404 parm[0].lockx.file.fnum = gen_fnum(instance);
1405 parm[0].lockx.in.mode = gen_lock_mode();
1406 parm[0].lockx.in.timeout = gen_timeout();
1408 /* make sure we don't accidentially generate an oplock
1409 break ack - otherwise the server can just block forever */
1410 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1411 parm[0].lockx.in.lock_cnt = gen_lock_count();
1412 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1413 } while (nlocks == 0);
1416 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1417 struct smb_lock_entry,
1419 for (n=0;n<nlocks;n++) {
1420 parm[0].lockx.in.locks[n].pid = gen_pid();
1421 parm[0].lockx.in.locks[n].offset = gen_offset();
1422 parm[0].lockx.in.locks[n].count = gen_io_count();
1427 GEN_SET_FNUM(lockx.file.fnum);
1428 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1434 generate a fileinfo query structure
1436 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1439 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1441 enum smb_fileinfo_level level;
1444 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1445 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1446 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1447 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1448 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1449 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1450 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1451 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1452 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1453 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1456 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1457 } while (ignore_pattern(levels[i].name));
1459 info->generic.level = levels[i].level;
1463 compare returned fileinfo structures
1465 static BOOL cmp_fileinfo(int instance,
1466 union smb_fileinfo parm[NSERVERS],
1467 NTSTATUS status[NSERVERS])
1471 switch (parm[0].generic.level) {
1472 case RAW_FILEINFO_GENERIC:
1475 case RAW_FILEINFO_GETATTR:
1476 CHECK_EQUAL(getattr.out.attrib);
1477 CHECK_EQUAL(getattr.out.size);
1478 CHECK_TIMES_EQUAL(getattr.out.write_time);
1481 case RAW_FILEINFO_GETATTRE:
1482 CHECK_TIMES_EQUAL(getattre.out.create_time);
1483 CHECK_TIMES_EQUAL(getattre.out.access_time);
1484 CHECK_TIMES_EQUAL(getattre.out.write_time);
1485 CHECK_EQUAL(getattre.out.size);
1486 CHECK_EQUAL(getattre.out.alloc_size);
1487 CHECK_EQUAL(getattre.out.attrib);
1490 case RAW_FILEINFO_STANDARD:
1491 CHECK_TIMES_EQUAL(standard.out.create_time);
1492 CHECK_TIMES_EQUAL(standard.out.access_time);
1493 CHECK_TIMES_EQUAL(standard.out.write_time);
1494 CHECK_EQUAL(standard.out.size);
1495 CHECK_EQUAL(standard.out.alloc_size);
1496 CHECK_EQUAL(standard.out.attrib);
1499 case RAW_FILEINFO_EA_SIZE:
1500 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1501 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1502 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1503 CHECK_EQUAL(ea_size.out.size);
1504 CHECK_EQUAL(ea_size.out.alloc_size);
1505 CHECK_EQUAL(ea_size.out.attrib);
1506 CHECK_EQUAL(ea_size.out.ea_size);
1509 case RAW_FILEINFO_ALL_EAS:
1510 CHECK_EQUAL(all_eas.out.num_eas);
1511 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1512 CHECK_EQUAL(all_eas.out.eas[i].flags);
1513 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1514 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1518 case RAW_FILEINFO_IS_NAME_VALID:
1521 case RAW_FILEINFO_BASIC_INFO:
1522 case RAW_FILEINFO_BASIC_INFORMATION:
1523 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1524 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1525 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1526 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1527 CHECK_EQUAL(basic_info.out.attrib);
1530 case RAW_FILEINFO_STANDARD_INFO:
1531 case RAW_FILEINFO_STANDARD_INFORMATION:
1532 CHECK_EQUAL(standard_info.out.alloc_size);
1533 CHECK_EQUAL(standard_info.out.size);
1534 CHECK_EQUAL(standard_info.out.nlink);
1535 CHECK_EQUAL(standard_info.out.delete_pending);
1536 CHECK_EQUAL(standard_info.out.directory);
1539 case RAW_FILEINFO_EA_INFO:
1540 case RAW_FILEINFO_EA_INFORMATION:
1541 CHECK_EQUAL(ea_info.out.ea_size);
1544 case RAW_FILEINFO_NAME_INFO:
1545 case RAW_FILEINFO_NAME_INFORMATION:
1546 CHECK_WSTR_EQUAL(name_info.out.fname);
1549 case RAW_FILEINFO_ALL_INFO:
1550 case RAW_FILEINFO_ALL_INFORMATION:
1551 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1552 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1553 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1554 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1555 CHECK_EQUAL(all_info.out.attrib);
1556 CHECK_EQUAL(all_info.out.alloc_size);
1557 CHECK_EQUAL(all_info.out.size);
1558 CHECK_EQUAL(all_info.out.nlink);
1559 CHECK_EQUAL(all_info.out.delete_pending);
1560 CHECK_EQUAL(all_info.out.directory);
1561 CHECK_EQUAL(all_info.out.ea_size);
1562 CHECK_WSTR_EQUAL(all_info.out.fname);
1565 case RAW_FILEINFO_ALT_NAME_INFO:
1566 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1567 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1570 case RAW_FILEINFO_STREAM_INFO:
1571 case RAW_FILEINFO_STREAM_INFORMATION:
1572 CHECK_EQUAL(stream_info.out.num_streams);
1573 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1574 CHECK_EQUAL(stream_info.out.streams[i].size);
1575 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1576 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1580 case RAW_FILEINFO_COMPRESSION_INFO:
1581 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1582 CHECK_EQUAL(compression_info.out.compressed_size);
1583 CHECK_EQUAL(compression_info.out.format);
1584 CHECK_EQUAL(compression_info.out.unit_shift);
1585 CHECK_EQUAL(compression_info.out.chunk_shift);
1586 CHECK_EQUAL(compression_info.out.cluster_shift);
1589 case RAW_FILEINFO_INTERNAL_INFORMATION:
1590 CHECK_EQUAL(internal_information.out.file_id);
1593 case RAW_FILEINFO_ACCESS_INFORMATION:
1594 CHECK_EQUAL(access_information.out.access_flags);
1597 case RAW_FILEINFO_POSITION_INFORMATION:
1598 CHECK_EQUAL(position_information.out.position);
1601 case RAW_FILEINFO_MODE_INFORMATION:
1602 CHECK_EQUAL(mode_information.out.mode);
1605 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1606 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1609 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1610 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1611 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1612 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1613 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1614 CHECK_EQUAL(network_open_information.out.alloc_size);
1615 CHECK_EQUAL(network_open_information.out.size);
1616 CHECK_EQUAL(network_open_information.out.attrib);
1619 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1620 CHECK_EQUAL(attribute_tag_information.out.attrib);
1621 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1624 /* Unhandled levels */
1626 case RAW_FILEINFO_SEC_DESC:
1627 case RAW_FILEINFO_EA_LIST:
1628 case RAW_FILEINFO_UNIX_BASIC:
1629 case RAW_FILEINFO_UNIX_LINK:
1637 generate qpathinfo operations
1639 static BOOL handler_qpathinfo(int instance)
1641 union smb_fileinfo parm[NSERVERS];
1642 NTSTATUS status[NSERVERS];
1644 parm[0].generic.file.path = gen_fname_open(instance);
1646 gen_fileinfo(instance, &parm[0]);
1649 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1651 return cmp_fileinfo(instance, parm, status);
1655 generate qfileinfo operations
1657 static BOOL handler_qfileinfo(int instance)
1659 union smb_fileinfo parm[NSERVERS];
1660 NTSTATUS status[NSERVERS];
1662 parm[0].generic.file.fnum = gen_fnum(instance);
1664 gen_fileinfo(instance, &parm[0]);
1667 GEN_SET_FNUM(generic.file.fnum);
1668 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1670 return cmp_fileinfo(instance, parm, status);
1675 generate a fileinfo query structure
1677 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1681 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1683 enum smb_setfileinfo_level level;
1687 /* disabled until win2003 can handle them ... */
1688 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1689 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1691 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1692 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1693 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1694 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1695 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1698 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1699 } while (ignore_pattern(levels[i].name));
1701 info->generic.level = levels[i].level;
1703 switch (info->generic.level) {
1704 case RAW_SFILEINFO_SETATTR:
1705 info->setattr.in.attrib = gen_attrib();
1706 info->setattr.in.write_time = gen_timet();
1708 case RAW_SFILEINFO_SETATTRE:
1709 info->setattre.in.create_time = gen_timet();
1710 info->setattre.in.access_time = gen_timet();
1711 info->setattre.in.write_time = gen_timet();
1713 case RAW_SFILEINFO_STANDARD:
1714 info->standard.in.create_time = gen_timet();
1715 info->standard.in.access_time = gen_timet();
1716 info->standard.in.write_time = gen_timet();
1718 case RAW_SFILEINFO_EA_SET: {
1719 static struct ea_struct ea;
1720 info->ea_set.in.num_eas = 1;
1721 info->ea_set.in.eas = &ea;
1722 info->ea_set.in.eas[0] = gen_ea_struct();
1725 case RAW_SFILEINFO_BASIC_INFO:
1726 case RAW_SFILEINFO_BASIC_INFORMATION:
1727 info->basic_info.in.create_time = gen_nttime();
1728 info->basic_info.in.access_time = gen_nttime();
1729 info->basic_info.in.write_time = gen_nttime();
1730 info->basic_info.in.change_time = gen_nttime();
1731 info->basic_info.in.attrib = gen_attrib();
1733 case RAW_SFILEINFO_DISPOSITION_INFO:
1734 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1735 info->disposition_info.in.delete_on_close = gen_bool();
1737 case RAW_SFILEINFO_ALLOCATION_INFO:
1738 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1739 info->allocation_info.in.alloc_size = gen_alloc_size();
1741 case RAW_SFILEINFO_END_OF_FILE_INFO:
1742 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1743 info->end_of_file_info.in.size = gen_offset();
1745 case RAW_SFILEINFO_RENAME_INFORMATION:
1746 info->rename_information.in.overwrite = gen_bool();
1747 info->rename_information.in.root_fid = gen_root_fid(instance);
1748 info->rename_information.in.new_name = gen_fname_open(instance);
1750 case RAW_SFILEINFO_POSITION_INFORMATION:
1751 info->position_information.in.position = gen_offset();
1753 case RAW_SFILEINFO_MODE_INFORMATION:
1754 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1756 case RAW_SFILEINFO_GENERIC:
1757 case RAW_SFILEINFO_SEC_DESC:
1758 case RAW_SFILEINFO_UNIX_BASIC:
1759 case RAW_SFILEINFO_UNIX_LINK:
1760 case RAW_SFILEINFO_UNIX_HLINK:
1761 case RAW_SFILEINFO_1023:
1762 case RAW_SFILEINFO_1025:
1763 case RAW_SFILEINFO_1029:
1764 case RAW_SFILEINFO_1032:
1765 case RAW_SFILEINFO_1039:
1766 case RAW_SFILEINFO_1040:
1773 generate setpathinfo operations
1775 static BOOL handler_spathinfo(int instance)
1777 union smb_setfileinfo parm[NSERVERS];
1778 NTSTATUS status[NSERVERS];
1780 parm[0].generic.file.path = gen_fname_open(instance);
1782 gen_setfileinfo(instance, &parm[0]);
1786 /* a special case for the fid in a RENAME */
1787 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1788 parm[0].rename_information.in.root_fid != 0) {
1789 GEN_SET_FNUM(rename_information.in.root_fid);
1792 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1799 generate setfileinfo operations
1801 static BOOL handler_sfileinfo(int instance)
1803 union smb_setfileinfo parm[NSERVERS];
1804 NTSTATUS status[NSERVERS];
1806 parm[0].generic.file.fnum = gen_fnum(instance);
1808 gen_setfileinfo(instance, &parm[0]);
1811 GEN_SET_FNUM(generic.file.fnum);
1812 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1819 generate change notify operations
1821 static BOOL handler_notify(int instance)
1823 union smb_notify parm[NSERVERS];
1826 parm[0].notify.in.buffer_size = gen_io_count();
1827 parm[0].notify.in.completion_filter = gen_bits_mask(0xFF);
1828 parm[0].notify.file.fnum = gen_fnum(instance);
1829 parm[0].notify.in.recursive = gen_bool();
1832 GEN_SET_FNUM(notify.file.fnum);
1834 for (n=0;n<NSERVERS;n++) {
1835 struct smbcli_request *req;
1836 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1837 req->async.fn = async_notify;
1844 wipe any relevant files
1846 static void wipe_files(void)
1849 for (i=0;i<NSERVERS;i++) {
1850 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1852 printf("Failed to wipe tree on server %d\n", i);
1855 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1856 printf("Failed to create \\gentest - %s\n",
1857 smbcli_errstr(servers[i].cli[0]->tree));
1861 printf("Deleted %d files on server %d\n", n, i);
1867 dump the current seeds - useful for continuing a backtrack
1869 static void dump_seeds(void)
1874 if (!options.seeds_file) {
1877 f = fopen("seeds.tmp", "w");
1880 for (i=0;i<options.numops;i++) {
1881 fprintf(f, "%u\n", op_parms[i].seed);
1884 rename("seeds.tmp", options.seeds_file);
1890 the list of top-level operations that we will generate
1894 BOOL (*handler)(int instance);
1895 int count, success_count;
1897 {"OPEN", handler_open},
1898 {"OPENX", handler_openx},
1899 {"NTCREATEX", handler_ntcreatex},
1900 {"CLOSE", handler_close},
1901 {"UNLINK", handler_unlink},
1902 {"MKDIR", handler_mkdir},
1903 {"RMDIR", handler_rmdir},
1904 {"RENAME", handler_rename},
1905 {"NTRENAME", handler_ntrename},
1906 {"READX", handler_readx},
1907 {"WRITEX", handler_writex},
1908 {"CHKPATH", handler_chkpath},
1909 {"LOCKINGX", handler_lockingx},
1910 {"QPATHINFO", handler_qpathinfo},
1911 {"QFILEINFO", handler_qfileinfo},
1912 {"SPATHINFO", handler_spathinfo},
1913 {"SFILEINFO", handler_sfileinfo},
1914 {"NOTIFY", handler_notify},
1915 {"SEEK", handler_seek},
1920 run the test with the current set of op_parms parameters
1921 return the number of operations that completed successfully
1923 static int run_test(void)
1927 if (!connect_servers()) {
1928 printf("Failed to connect to servers\n");
1934 /* wipe any leftover files from old runs */
1937 /* reset the open handles array */
1938 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1939 num_open_handles = 0;
1941 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1942 gen_ops[i].count = 0;
1943 gen_ops[i].success_count = 0;
1946 for (op=0; op<options.numops; op++) {
1947 int instance, which_op;
1950 if (op_parms[op].disabled) continue;
1952 srandom(op_parms[op].seed);
1954 instance = gen_int_range(0, NINSTANCES-1);
1956 /* generate a non-ignored operation */
1958 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1959 } while (ignore_pattern(gen_ops[which_op].name));
1961 DEBUG(3,("Generating op %s on instance %d\n",
1962 gen_ops[which_op].name, instance));
1964 current_op.seed = op_parms[op].seed;
1965 current_op.opnum = op;
1966 current_op.name = gen_ops[which_op].name;
1967 current_op.status = NT_STATUS_OK;
1968 current_op.mem_ctx = talloc_init("%s", current_op.name);
1970 ret = gen_ops[which_op].handler(instance);
1972 talloc_free(current_op.mem_ctx);
1974 gen_ops[which_op].count++;
1975 if (NT_STATUS_IS_OK(current_op.status)) {
1976 gen_ops[which_op].success_count++;
1980 printf("Failed at operation %d - %s\n",
1981 op, gen_ops[which_op].name);
1985 if (op % 100 == 0) {
1990 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1991 printf("Op %-10s got %d/%d success\n",
1993 gen_ops[i].success_count,
2001 perform a backtracking analysis of the minimal set of operations
2002 to generate an error
2004 static void backtrack_analyze(void)
2008 chunk = options.numops / 2;
2013 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2016 chunk = MIN(chunk, options.numops / 2);
2018 /* mark this range as disabled */
2019 max = MIN(options.numops, base+chunk);
2020 for (i=base;i<max; i++) {
2021 op_parms[i].disabled = True;
2023 printf("Testing %d ops with %d-%d disabled\n",
2024 options.numops, base, max-1);
2026 printf("Completed %d of %d ops\n", ret, options.numops);
2027 for (i=base;i<max; i++) {
2028 op_parms[i].disabled = False;
2030 if (ret == options.numops) {
2031 /* this chunk is needed */
2033 } else if (ret < base) {
2034 printf("damn - inconsistent errors! found early error\n");
2035 options.numops = ret+1;
2038 /* it failed - this chunk isn't needed for a failure */
2039 memmove(&op_parms[base], &op_parms[max],
2040 sizeof(op_parms[0]) * (options.numops - max));
2041 options.numops = (ret+1) - (max - base);
2051 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2054 } while (chunk > 0);
2056 printf("Reduced to %d ops\n", options.numops);
2058 if (ret != options.numops - 1) {
2059 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2064 start the main gentest process
2066 static BOOL start_gentest(void)
2071 /* allocate the open_handles array */
2072 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2074 srandom(options.seed);
2075 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2077 /* generate the seeds - after this everything is deterministic */
2078 if (options.use_preset_seeds) {
2080 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
2082 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2085 if (numops < options.numops) {
2086 options.numops = numops;
2088 for (op=0;op<options.numops;op++) {
2090 printf("Not enough seeds in %s\n", options.seeds_file);
2093 op_parms[op].seed = atoi(preset[op]);
2095 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2097 for (op=0; op<options.numops; op++) {
2098 op_parms[op].seed = random();
2104 if (ret != options.numops && options.analyze) {
2105 options.numops = ret+1;
2106 backtrack_analyze();
2107 } else if (options.analyze_always) {
2108 backtrack_analyze();
2109 } else if (options.analyze_continuous) {
2110 while (run_test() == options.numops) ;
2113 return ret == options.numops;
2117 static void usage(void)
2121 gentest2 //server1/share1 //server2/share2 [options..]\n\
2123 -U user%%pass (can be specified twice)\n\
2126 -a (show all ops)\n\
2127 -A backtrack to find minimal ops\n\
2128 -i FILE add a list of wildcard exclusions\n\
2129 -O enable oplocks\n\
2130 -S FILE set preset seeds file\n\
2131 -L use preset seeds\n\
2132 -F fast reconnect (just close files)\n\
2133 -C continuous analysis mode\n\
2134 -X analyse even when test OK\n\
2138 /****************************************************************************
2140 ****************************************************************************/
2141 int main(int argc, char *argv[])
2144 int i, username_count=0;
2149 setup_logging("gentest", DEBUG_STDOUT);
2151 if (argc < 3 || argv[1][0] == '-') {
2156 setup_logging(argv[0], DEBUG_STDOUT);
2158 for (i=0;i<NSERVERS;i++) {
2159 const char *share = argv[1+i];
2160 servers[i].credentials = cli_credentials_init(NULL);
2161 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2162 printf("Invalid share name '%s'\n", share);
2172 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
2173 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
2174 cli_credentials_guess(servers[0].credentials);
2175 cli_credentials_guess(servers[1].credentials);
2177 options.seed = time(NULL);
2178 options.numops = 1000;
2179 options.max_open_handles = 20;
2180 options.seeds_file = "gentest_seeds.dat";
2182 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2185 if (username_count == 2) {
2189 cli_credentials_parse_string(servers[username_count].credentials,
2190 optarg, CRED_SPECIFIED);
2194 DEBUGLEVEL = atoi(optarg);
2195 setup_logging(NULL, DEBUG_STDOUT);
2198 options.seed = atoi(optarg);
2201 options.seeds_file = optarg;
2204 options.use_preset_seeds = True;
2207 options.fast_reconnect = True;
2210 options.numops = atoi(optarg);
2213 options.use_oplocks = True;
2216 options.showall = True;
2219 options.analyze = True;
2222 options.analyze_always = True;
2225 options.analyze_continuous = True;
2228 options.ignore_patterns = file_lines_load(optarg, NULL, NULL);
2234 printf("Unknown option %c (%d)\n", (char)opt, opt);
2241 if (username_count == 0) {
2245 if (username_count == 1) {
2246 servers[1].credentials = servers[0].credentials;
2249 printf("seed=%u\n", options.seed);
2251 ret = start_gentest();
2254 printf("gentest completed - no errors\n");
2256 printf("gentest failed\n");