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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "system/time.h"
22 #include "system/filesys.h"
23 #include "libcli/raw/request.h"
24 #include "libcli/libcli.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "librpc/gen_ndr/security.h"
27 #include "auth/credentials/credentials.h"
28 #include "auth/gensec/gensec.h"
34 static struct gentest_options {
38 BOOL analyze_continuous;
39 uint_t max_open_handles;
43 char **ignore_patterns;
44 const char *seeds_file;
45 BOOL use_preset_seeds;
49 /* mapping between open handles on the server and local handles */
53 uint_t server_fnum[NSERVERS];
56 static uint_t num_open_handles;
58 /* state information for the servers. We open NINSTANCES connections to
61 struct smbcli_state *cli[NINSTANCES];
64 struct cli_credentials *credentials;
67 /* the seeds and flags for each operation */
74 /* oplock break info */
81 } oplocks[NSERVERS][NINSTANCES];
83 /* change notify reply info */
87 union smb_notify notify;
88 } notifies[NSERVERS][NINSTANCES];
90 /* info relevant to the current operation */
101 #define BAD_HANDLE 0xFFFE
103 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
104 static void idle_func(struct smbcli_transport *transport, void *private);
107 check if a string should be ignored. This is used as the basis
108 for all error ignore settings
110 static BOOL ignore_pattern(const char *str)
113 if (!options.ignore_patterns) return False;
115 for (i=0;options.ignore_patterns[i];i++) {
116 if (strcmp(options.ignore_patterns[i], str) == 0 ||
117 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
118 DEBUG(2,("Ignoring '%s'\n", str));
125 /*****************************************************
126 connect to the servers
127 *******************************************************/
128 static BOOL connect_servers_fast(void)
132 /* close all open files */
133 for (h=0;h<options.max_open_handles;h++) {
134 if (!open_handles[h].active) continue;
135 for (i=0;i<NSERVERS;i++) {
136 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
137 open_handles[h].server_fnum[i])))) {
140 open_handles[h].active = False;
150 /*****************************************************
151 connect to the servers
152 *******************************************************/
153 static BOOL connect_servers(void)
157 if (options.fast_reconnect && servers[0].cli[0]) {
158 if (connect_servers_fast()) {
163 /* close any existing connections */
164 for (i=0;i<NSERVERS;i++) {
165 for (j=0;j<NINSTANCES;j++) {
166 if (servers[i].cli[j]) {
167 smbcli_tdis(servers[i].cli[j]);
168 talloc_free(servers[i].cli[j]);
169 servers[i].cli[j] = NULL;
174 for (i=0;i<NSERVERS;i++) {
175 for (j=0;j<NINSTANCES;j++) {
177 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
178 servers[i].server_name, servers[i].share_name,
179 servers[i].credentials->username, j);
181 cli_credentials_set_workstation(servers[i].credentials,
182 "gentest", CRED_SPECIFIED);
184 status = smbcli_full_connection(NULL, &servers[i].cli[j],
185 servers[i].server_name,
186 servers[i].share_name, NULL,
187 servers[i].credentials, NULL);
188 if (!NT_STATUS_IS_OK(status)) {
189 printf("Failed to connect to \\\\%s\\%s - %s\n",
190 servers[i].server_name, servers[i].share_name,
195 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
196 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
204 work out the time skew between the servers - be conservative
206 static uint_t time_skew(void)
209 ret = labs(servers[0].cli[0]->transport->negotiate.server_time -
210 servers[1].cli[0]->transport->negotiate.server_time);
215 turn an fnum for an instance into a handle
217 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
220 for (i=0;i<options.max_open_handles;i++) {
221 if (!open_handles[i].active ||
222 instance != open_handles[i].instance) continue;
223 if (open_handles[i].server_fnum[server] == fnum) {
227 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
228 fnum, server, instance);
233 add some newly opened handles
235 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
238 for (h=0;h<options.max_open_handles;h++) {
239 if (!open_handles[h].active) break;
241 if (h == options.max_open_handles) {
242 /* we have to force close a random handle */
243 h = random() % options.max_open_handles;
244 for (i=0;i<NSERVERS;i++) {
245 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
246 open_handles[h].server_fnum[i])))) {
247 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
248 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
251 printf("Recovered handle %d\n", h);
254 for (i=0;i<NSERVERS;i++) {
255 open_handles[h].server_fnum[i] = fnums[i];
256 open_handles[h].instance = instance;
257 open_handles[h].active = True;
258 open_handles[h].name = name;
262 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
264 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
269 remove a closed handle
271 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
274 for (h=0;h<options.max_open_handles;h++) {
275 if (instance == open_handles[h].instance &&
276 open_handles[h].server_fnum[0] == fnums[0]) {
277 open_handles[h].active = False;
279 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
281 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
282 open_handles[h].name);
286 printf("Removing invalid handle!?\n");
291 return True with 'chance' probability as a percentage
293 static BOOL gen_chance(uint_t chance)
295 return ((random() % 100) <= chance);
299 map an internal handle number to a server fnum
301 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
303 if (handle == BAD_HANDLE) return handle;
304 return open_handles[handle].server_fnum[server];
310 static uint16_t gen_fnum(int instance)
315 if (gen_chance(20)) return BAD_HANDLE;
317 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
318 h = random() % options.max_open_handles;
319 if (open_handles[h].active &&
320 open_handles[h].instance == instance) {
328 return a file handle, but skewed so we don't close the last
329 couple of handles too readily
331 static uint16_t gen_fnum_close(int instance)
333 if (num_open_handles < 3) {
334 if (gen_chance(80)) return BAD_HANDLE;
337 return gen_fnum(instance);
341 generate an integer in a specified range
343 static int gen_int_range(uint_t min, uint_t max)
346 return min + (r % (1+max-min));
350 return a fnum for use as a root fid
351 be careful to call GEN_SET_FNUM() when you use this!
353 static uint16_t gen_root_fid(int instance)
355 if (gen_chance(5)) return gen_fnum(instance);
360 generate a file offset
362 static int gen_offset(void)
364 if (gen_chance(20)) return 0;
365 return gen_int_range(0, 1024*1024);
371 static int gen_io_count(void)
373 if (gen_chance(20)) return 0;
374 return gen_int_range(0, 4096);
380 static const char *gen_fname(void)
382 const char *names[] = {"\\gentest\\gentest.dat",
384 "\\gentest\\foo2.sym",
385 "\\gentest\\foo3.dll",
387 "\\gentest\\foo4:teststream1",
388 "\\gentest\\foo4:teststream2",
389 "\\gentest\\foo5.exe",
390 "\\gentest\\foo5.exe:teststream3",
391 "\\gentest\\foo5.exe:teststream4",
392 "\\gentest\\foo6.com",
394 "\\gentest\\blah\\blergh.txt",
395 "\\gentest\\blah\\blergh2",
396 "\\gentest\\blah\\blergh3.txt",
397 "\\gentest\\blah\\blergh4",
398 "\\gentest\\blah\\blergh5.txt",
399 "\\gentest\\blah\\blergh5",
400 "\\gentest\\blah\\.",
402 /* this causes problem with w2k3 */
403 "\\gentest\\blah\\..",
405 "\\gentest\\a_very_long_name.bin",
411 i = gen_int_range(0, ARRAY_SIZE(names)-1);
412 } while (ignore_pattern(names[i]));
418 generate a filename with a higher chance of choosing an already
421 static const char *gen_fname_open(int instance)
424 h = gen_fnum(instance);
425 if (h == BAD_HANDLE) {
428 return open_handles[h].name;
432 generate a wildcard pattern
434 static const char *gen_pattern(void)
437 const char *names[] = {"\\gentest\\*.dat",
440 "\\gentest\\blah\\*.*",
441 "\\gentest\\blah\\*",
444 if (gen_chance(50)) return gen_fname();
447 i = gen_int_range(0, ARRAY_SIZE(names)-1);
448 } while (ignore_pattern(names[i]));
456 static uint32_t gen_bits_mask(uint_t mask)
458 uint_t ret = random();
463 generate a bitmask with high probability of the first mask
464 and low of the second
466 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
468 if (gen_chance(10)) return gen_bits_mask(mask2);
469 return gen_bits_mask(mask1);
475 static BOOL gen_bool(void)
477 return gen_bits_mask2(0x1, 0xFF);
481 generate ntrename flags
483 static uint16_t gen_rename_flags(void)
485 if (gen_chance(30)) return RENAME_FLAG_RENAME;
486 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
487 if (gen_chance(30)) return RENAME_FLAG_COPY;
488 return gen_bits_mask(0xFFFF);
493 return a lockingx lock mode
495 static uint16_t gen_lock_mode(void)
497 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
498 if (gen_chance(20)) return gen_bits_mask(0x1F);
499 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
505 static uint16_t gen_pid(void)
507 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
512 generate a lock count
514 static off_t gen_lock_count(void)
516 return gen_int_range(0, 3);
520 generate a ntcreatex flags field
522 static uint32_t gen_ntcreatex_flags(void)
524 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
525 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
529 generate a NT access mask
531 static uint32_t gen_access_mask(void)
533 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
534 if (gen_chance(20)) return SEC_FILE_ALL;
535 return gen_bits_mask(0xFFFFFFFF);
539 generate a ntcreatex create options bitfield
541 static uint32_t gen_create_options(void)
543 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
544 if (gen_chance(50)) return 0;
545 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
549 generate a ntcreatex open disposition
551 static uint32_t gen_open_disp(void)
553 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
554 return gen_int_range(0, 5);
558 generate an openx open mode
560 static uint16_t gen_openx_mode(void)
562 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
563 if (gen_chance(20)) return gen_bits_mask(0xFF);
564 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
568 generate an openx flags field
570 static uint16_t gen_openx_flags(void)
572 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
573 return gen_bits_mask(0x7);
577 generate an openx open function
579 static uint16_t gen_openx_func(void)
581 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
582 return gen_bits_mask(0x13);
586 generate a file attrib combination
588 static uint32_t gen_attrib(void)
590 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
591 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
595 generate a unix timestamp
597 static time_t gen_timet(void)
599 if (gen_chance(30)) return 0;
600 return (time_t)random();
604 generate a unix timestamp
606 static NTTIME gen_nttime(void)
609 unix_to_nt_time(&ret, gen_timet());
614 generate a milliseconds protocol timeout
616 static uint32_t gen_timeout(void)
618 if (gen_chance(98)) return 0;
619 return random() % 50;
623 generate a file allocation size
625 static uint_t gen_alloc_size(void)
629 if (gen_chance(30)) return 0;
631 ret = random() % 4*1024*1024;
632 /* give a high chance of a round number */
633 if (gen_chance(60)) {
634 ret &= ~(1024*1024 - 1);
640 generate an ea_struct
642 static struct ea_struct gen_ea_struct(void)
645 const char *names[] = {"EAONE",
650 "AVERYLONGATTRIBUTENAME"};
651 const char *values[] = {"VALUE1",
656 "ASOMEWHATLONGERATTRIBUTEVALUE"};
662 i = gen_int_range(0, ARRAY_SIZE(names)-1);
663 } while (ignore_pattern(names[i]));
665 ea.name.s = names[i];
668 i = gen_int_range(0, ARRAY_SIZE(values)-1);
669 } while (ignore_pattern(values[i]));
671 ea.value = data_blob(values[i], strlen(values[i]));
673 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
681 this is called when a change notify reply comes in
683 static void async_notify(struct smbcli_request *req)
685 union smb_notify notify;
689 struct smbcli_transport *transport = req->transport;
691 tid = SVAL(req->in.hdr, HDR_TID);
693 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
694 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
695 if (NT_STATUS_IS_OK(status)) {
696 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
698 notify.nttrans.out.num_changes,
699 notify.nttrans.out.changes[0].action,
700 notify.nttrans.out.changes[0].name.s);
703 for (i=0;i<NSERVERS;i++) {
704 for (j=0;j<NINSTANCES;j++) {
705 if (transport == servers[i].cli[j]->transport &&
706 tid == servers[i].cli[j]->tree->tid) {
707 notifies[i][j].notify_count++;
708 notifies[i][j].status = status;
709 notifies[i][j].notify = notify;
715 static void oplock_handler_close_recv(struct smbcli_request *req)
718 status = smbcli_request_simple_recv(req);
719 if (!NT_STATUS_IS_OK(status)) {
720 printf("close failed in oplock_handler\n");
721 smb_panic("close failed in oplock_handler");
726 the oplock handler will either ack the break or close the file
728 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
733 struct smbcli_tree *tree = NULL;
734 struct smbcli_request *req;
736 srandom(current_op.seed);
737 do_close = gen_chance(50);
739 for (i=0;i<NSERVERS;i++) {
740 for (j=0;j<NINSTANCES;j++) {
741 if (transport == servers[i].cli[j]->transport &&
742 tid == servers[i].cli[j]->tree->tid) {
743 oplocks[i][j].got_break = True;
744 oplocks[i][j].fnum = fnum;
745 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
746 oplocks[i][j].level = level;
747 oplocks[i][j].do_close = do_close;
748 tree = servers[i].cli[j]->tree;
754 printf("Oplock break not for one of our trees!?\n");
759 printf("oplock ack fnum=%d\n", fnum);
760 return smbcli_oplock_ack(tree, fnum, level);
763 printf("oplock close fnum=%d\n", fnum);
765 io.close.level = RAW_CLOSE_CLOSE;
766 io.close.in.file.fnum = fnum;
767 io.close.in.write_time = 0;
768 req = smb_raw_close_send(tree, &io);
771 printf("WARNING: close failed in oplock_handler_close\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.nttrans.out.num_changes;n++) {
924 if (not1.nttrans.out.changes[n].action !=
925 not2.nttrans.out.changes[n].action) {
926 printf("Notify action %d inconsistent %d %d\n", n,
927 not1.nttrans.out.changes[n].action,
928 not2.nttrans.out.changes[n].action);
931 if (strcmp(not1.nttrans.out.changes[n].name.s,
932 not2.nttrans.out.changes[n].name.s)) {
933 printf("Notify name %d inconsistent %s %s\n", n,
934 not1.nttrans.out.changes[n].name.s,
935 not2.nttrans.out.changes[n].name.s);
938 if (not1.nttrans.out.changes[n].name.private_length !=
939 not2.nttrans.out.changes[n].name.private_length) {
940 printf("Notify name length %d inconsistent %d %d\n", n,
941 not1.nttrans.out.changes[n].name.private_length,
942 not2.nttrans.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 (labs(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 (labs(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.out.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.out.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.out.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.in.file.fnum = gen_fnum_close(instance);
1200 parm[0].close.in.write_time = gen_timet();
1203 GEN_SET_FNUM(close.in.file.fnum);
1204 GEN_CALL(smb_raw_close(tree, &parm[i]));
1206 REMOVE_HANDLE(close.in.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.in.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.in.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.in.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.in.read_for_execute = gen_bool();
1355 parm[0].readx.out.data = talloc_size(current_op.mem_ctx,
1356 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1359 GEN_SET_FNUM(readx.in.file.fnum);
1360 GEN_CALL(smb_raw_read(tree, &parm[i]));
1362 CHECK_EQUAL(readx.out.remaining);
1363 CHECK_EQUAL(readx.out.compaction_mode);
1364 CHECK_EQUAL(readx.out.nread);
1370 generate writex operations
1372 static BOOL handler_writex(int instance)
1374 union smb_write parm[NSERVERS];
1375 NTSTATUS status[NSERVERS];
1377 parm[0].writex.level = RAW_WRITE_WRITEX;
1378 parm[0].writex.in.file.fnum = gen_fnum(instance);
1379 parm[0].writex.in.offset = gen_offset();
1380 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1381 parm[0].writex.in.remaining = gen_io_count();
1382 parm[0].writex.in.count = gen_io_count();
1383 parm[0].writex.in.data = talloc_zero_size(current_op.mem_ctx, parm[0].writex.in.count);
1386 GEN_SET_FNUM(writex.in.file.fnum);
1387 GEN_CALL(smb_raw_write(tree, &parm[i]));
1389 CHECK_EQUAL(writex.out.nwritten);
1390 CHECK_EQUAL(writex.out.remaining);
1396 generate lockingx operations
1398 static BOOL handler_lockingx(int instance)
1400 union smb_lock parm[NSERVERS];
1401 NTSTATUS status[NSERVERS];
1404 parm[0].lockx.level = RAW_LOCK_LOCKX;
1405 parm[0].lockx.in.file.fnum = gen_fnum(instance);
1406 parm[0].lockx.in.mode = gen_lock_mode();
1407 parm[0].lockx.in.timeout = gen_timeout();
1409 /* make sure we don't accidentially generate an oplock
1410 break ack - otherwise the server can just block forever */
1411 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1412 parm[0].lockx.in.lock_cnt = gen_lock_count();
1413 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1414 } while (nlocks == 0);
1417 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1418 struct smb_lock_entry,
1420 for (n=0;n<nlocks;n++) {
1421 parm[0].lockx.in.locks[n].pid = gen_pid();
1422 parm[0].lockx.in.locks[n].offset = gen_offset();
1423 parm[0].lockx.in.locks[n].count = gen_io_count();
1428 GEN_SET_FNUM(lockx.in.file.fnum);
1429 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1435 generate a fileinfo query structure
1437 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1440 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1442 enum smb_fileinfo_level level;
1445 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1446 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1447 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1448 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1449 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1450 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1451 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1452 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1453 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1454 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1457 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1458 } while (ignore_pattern(levels[i].name));
1460 info->generic.level = levels[i].level;
1464 compare returned fileinfo structures
1466 static BOOL cmp_fileinfo(int instance,
1467 union smb_fileinfo parm[NSERVERS],
1468 NTSTATUS status[NSERVERS])
1472 switch (parm[0].generic.level) {
1473 case RAW_FILEINFO_GENERIC:
1476 case RAW_FILEINFO_GETATTR:
1477 CHECK_EQUAL(getattr.out.attrib);
1478 CHECK_EQUAL(getattr.out.size);
1479 CHECK_TIMES_EQUAL(getattr.out.write_time);
1482 case RAW_FILEINFO_GETATTRE:
1483 CHECK_TIMES_EQUAL(getattre.out.create_time);
1484 CHECK_TIMES_EQUAL(getattre.out.access_time);
1485 CHECK_TIMES_EQUAL(getattre.out.write_time);
1486 CHECK_EQUAL(getattre.out.size);
1487 CHECK_EQUAL(getattre.out.alloc_size);
1488 CHECK_EQUAL(getattre.out.attrib);
1491 case RAW_FILEINFO_STANDARD:
1492 CHECK_TIMES_EQUAL(standard.out.create_time);
1493 CHECK_TIMES_EQUAL(standard.out.access_time);
1494 CHECK_TIMES_EQUAL(standard.out.write_time);
1495 CHECK_EQUAL(standard.out.size);
1496 CHECK_EQUAL(standard.out.alloc_size);
1497 CHECK_EQUAL(standard.out.attrib);
1500 case RAW_FILEINFO_EA_SIZE:
1501 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1502 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1503 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1504 CHECK_EQUAL(ea_size.out.size);
1505 CHECK_EQUAL(ea_size.out.alloc_size);
1506 CHECK_EQUAL(ea_size.out.attrib);
1507 CHECK_EQUAL(ea_size.out.ea_size);
1510 case RAW_FILEINFO_ALL_EAS:
1511 CHECK_EQUAL(all_eas.out.num_eas);
1512 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1513 CHECK_EQUAL(all_eas.out.eas[i].flags);
1514 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1515 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1519 case RAW_FILEINFO_IS_NAME_VALID:
1522 case RAW_FILEINFO_BASIC_INFO:
1523 case RAW_FILEINFO_BASIC_INFORMATION:
1524 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1525 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1526 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1527 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1528 CHECK_EQUAL(basic_info.out.attrib);
1531 case RAW_FILEINFO_STANDARD_INFO:
1532 case RAW_FILEINFO_STANDARD_INFORMATION:
1533 CHECK_EQUAL(standard_info.out.alloc_size);
1534 CHECK_EQUAL(standard_info.out.size);
1535 CHECK_EQUAL(standard_info.out.nlink);
1536 CHECK_EQUAL(standard_info.out.delete_pending);
1537 CHECK_EQUAL(standard_info.out.directory);
1540 case RAW_FILEINFO_EA_INFO:
1541 case RAW_FILEINFO_EA_INFORMATION:
1542 CHECK_EQUAL(ea_info.out.ea_size);
1545 case RAW_FILEINFO_NAME_INFO:
1546 case RAW_FILEINFO_NAME_INFORMATION:
1547 CHECK_WSTR_EQUAL(name_info.out.fname);
1550 case RAW_FILEINFO_ALL_INFO:
1551 case RAW_FILEINFO_ALL_INFORMATION:
1552 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1553 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1554 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1555 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1556 CHECK_EQUAL(all_info.out.attrib);
1557 CHECK_EQUAL(all_info.out.alloc_size);
1558 CHECK_EQUAL(all_info.out.size);
1559 CHECK_EQUAL(all_info.out.nlink);
1560 CHECK_EQUAL(all_info.out.delete_pending);
1561 CHECK_EQUAL(all_info.out.directory);
1562 CHECK_EQUAL(all_info.out.ea_size);
1563 CHECK_WSTR_EQUAL(all_info.out.fname);
1566 case RAW_FILEINFO_ALT_NAME_INFO:
1567 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1568 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1571 case RAW_FILEINFO_STREAM_INFO:
1572 case RAW_FILEINFO_STREAM_INFORMATION:
1573 CHECK_EQUAL(stream_info.out.num_streams);
1574 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1575 CHECK_EQUAL(stream_info.out.streams[i].size);
1576 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1577 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1581 case RAW_FILEINFO_COMPRESSION_INFO:
1582 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1583 CHECK_EQUAL(compression_info.out.compressed_size);
1584 CHECK_EQUAL(compression_info.out.format);
1585 CHECK_EQUAL(compression_info.out.unit_shift);
1586 CHECK_EQUAL(compression_info.out.chunk_shift);
1587 CHECK_EQUAL(compression_info.out.cluster_shift);
1590 case RAW_FILEINFO_INTERNAL_INFORMATION:
1591 CHECK_EQUAL(internal_information.out.file_id);
1594 case RAW_FILEINFO_ACCESS_INFORMATION:
1595 CHECK_EQUAL(access_information.out.access_flags);
1598 case RAW_FILEINFO_POSITION_INFORMATION:
1599 CHECK_EQUAL(position_information.out.position);
1602 case RAW_FILEINFO_MODE_INFORMATION:
1603 CHECK_EQUAL(mode_information.out.mode);
1606 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1607 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1610 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1611 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1612 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1613 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1614 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1615 CHECK_EQUAL(network_open_information.out.alloc_size);
1616 CHECK_EQUAL(network_open_information.out.size);
1617 CHECK_EQUAL(network_open_information.out.attrib);
1620 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1621 CHECK_EQUAL(attribute_tag_information.out.attrib);
1622 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1625 /* Unhandled levels */
1627 case RAW_FILEINFO_SEC_DESC:
1628 case RAW_FILEINFO_EA_LIST:
1629 case RAW_FILEINFO_UNIX_BASIC:
1630 case RAW_FILEINFO_UNIX_LINK:
1631 case RAW_FILEINFO_SMB2_ALL_EAS:
1632 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1640 generate qpathinfo operations
1642 static BOOL handler_qpathinfo(int instance)
1644 union smb_fileinfo parm[NSERVERS];
1645 NTSTATUS status[NSERVERS];
1647 parm[0].generic.in.file.path = gen_fname_open(instance);
1649 gen_fileinfo(instance, &parm[0]);
1652 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1654 return cmp_fileinfo(instance, parm, status);
1658 generate qfileinfo operations
1660 static BOOL handler_qfileinfo(int instance)
1662 union smb_fileinfo parm[NSERVERS];
1663 NTSTATUS status[NSERVERS];
1665 parm[0].generic.in.file.fnum = gen_fnum(instance);
1667 gen_fileinfo(instance, &parm[0]);
1670 GEN_SET_FNUM(generic.in.file.fnum);
1671 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1673 return cmp_fileinfo(instance, parm, status);
1678 generate a fileinfo query structure
1680 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1684 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1686 enum smb_setfileinfo_level level;
1690 /* disabled until win2003 can handle them ... */
1691 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1692 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1694 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1695 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1696 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1697 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1698 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1701 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1702 } while (ignore_pattern(levels[i].name));
1704 info->generic.level = levels[i].level;
1706 switch (info->generic.level) {
1707 case RAW_SFILEINFO_SETATTR:
1708 info->setattr.in.attrib = gen_attrib();
1709 info->setattr.in.write_time = gen_timet();
1711 case RAW_SFILEINFO_SETATTRE:
1712 info->setattre.in.create_time = gen_timet();
1713 info->setattre.in.access_time = gen_timet();
1714 info->setattre.in.write_time = gen_timet();
1716 case RAW_SFILEINFO_STANDARD:
1717 info->standard.in.create_time = gen_timet();
1718 info->standard.in.access_time = gen_timet();
1719 info->standard.in.write_time = gen_timet();
1721 case RAW_SFILEINFO_EA_SET: {
1722 static struct ea_struct ea;
1723 info->ea_set.in.num_eas = 1;
1724 info->ea_set.in.eas = &ea;
1725 info->ea_set.in.eas[0] = gen_ea_struct();
1728 case RAW_SFILEINFO_BASIC_INFO:
1729 case RAW_SFILEINFO_BASIC_INFORMATION:
1730 info->basic_info.in.create_time = gen_nttime();
1731 info->basic_info.in.access_time = gen_nttime();
1732 info->basic_info.in.write_time = gen_nttime();
1733 info->basic_info.in.change_time = gen_nttime();
1734 info->basic_info.in.attrib = gen_attrib();
1736 case RAW_SFILEINFO_DISPOSITION_INFO:
1737 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1738 info->disposition_info.in.delete_on_close = gen_bool();
1740 case RAW_SFILEINFO_ALLOCATION_INFO:
1741 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1742 info->allocation_info.in.alloc_size = gen_alloc_size();
1744 case RAW_SFILEINFO_END_OF_FILE_INFO:
1745 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1746 info->end_of_file_info.in.size = gen_offset();
1748 case RAW_SFILEINFO_RENAME_INFORMATION:
1749 info->rename_information.in.overwrite = gen_bool();
1750 info->rename_information.in.root_fid = gen_root_fid(instance);
1751 info->rename_information.in.new_name = gen_fname_open(instance);
1753 case RAW_SFILEINFO_POSITION_INFORMATION:
1754 info->position_information.in.position = gen_offset();
1756 case RAW_SFILEINFO_MODE_INFORMATION:
1757 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1759 case RAW_SFILEINFO_GENERIC:
1760 case RAW_SFILEINFO_SEC_DESC:
1761 case RAW_SFILEINFO_UNIX_BASIC:
1762 case RAW_SFILEINFO_UNIX_LINK:
1763 case RAW_SFILEINFO_UNIX_HLINK:
1764 case RAW_SFILEINFO_1023:
1765 case RAW_SFILEINFO_1025:
1766 case RAW_SFILEINFO_1029:
1767 case RAW_SFILEINFO_1032:
1768 case RAW_SFILEINFO_1039:
1769 case RAW_SFILEINFO_1040:
1776 generate setpathinfo operations
1778 static BOOL handler_spathinfo(int instance)
1780 union smb_setfileinfo parm[NSERVERS];
1781 NTSTATUS status[NSERVERS];
1783 parm[0].generic.in.file.path = gen_fname_open(instance);
1785 gen_setfileinfo(instance, &parm[0]);
1789 /* a special case for the fid in a RENAME */
1790 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1791 parm[0].rename_information.in.root_fid != 0) {
1792 GEN_SET_FNUM(rename_information.in.root_fid);
1795 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1802 generate setfileinfo operations
1804 static BOOL handler_sfileinfo(int instance)
1806 union smb_setfileinfo parm[NSERVERS];
1807 NTSTATUS status[NSERVERS];
1809 parm[0].generic.in.file.fnum = gen_fnum(instance);
1811 gen_setfileinfo(instance, &parm[0]);
1814 GEN_SET_FNUM(generic.in.file.fnum);
1815 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1822 generate change notify operations
1824 static BOOL handler_notify(int instance)
1826 union smb_notify parm[NSERVERS];
1829 ZERO_STRUCT(parm[0]);
1830 parm[0].nttrans.level = RAW_NOTIFY_NTTRANS;
1831 parm[0].nttrans.in.buffer_size = gen_io_count();
1832 parm[0].nttrans.in.completion_filter = gen_bits_mask(0xFF);
1833 parm[0].nttrans.in.file.fnum = gen_fnum(instance);
1834 parm[0].nttrans.in.recursive = gen_bool();
1837 GEN_SET_FNUM(nttrans.in.file.fnum);
1839 for (n=0;n<NSERVERS;n++) {
1840 struct smbcli_request *req;
1841 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1842 req->async.fn = async_notify;
1849 wipe any relevant files
1851 static void wipe_files(void)
1854 for (i=0;i<NSERVERS;i++) {
1855 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1857 printf("Failed to wipe tree on server %d\n", i);
1860 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1861 printf("Failed to create \\gentest - %s\n",
1862 smbcli_errstr(servers[i].cli[0]->tree));
1866 printf("Deleted %d files on server %d\n", n, i);
1872 dump the current seeds - useful for continuing a backtrack
1874 static void dump_seeds(void)
1879 if (!options.seeds_file) {
1882 f = fopen("seeds.tmp", "w");
1885 for (i=0;i<options.numops;i++) {
1886 fprintf(f, "%u\n", op_parms[i].seed);
1889 rename("seeds.tmp", options.seeds_file);
1895 the list of top-level operations that we will generate
1899 BOOL (*handler)(int instance);
1900 int count, success_count;
1902 {"OPEN", handler_open},
1903 {"OPENX", handler_openx},
1904 {"NTCREATEX", handler_ntcreatex},
1905 {"CLOSE", handler_close},
1906 {"UNLINK", handler_unlink},
1907 {"MKDIR", handler_mkdir},
1908 {"RMDIR", handler_rmdir},
1909 {"RENAME", handler_rename},
1910 {"NTRENAME", handler_ntrename},
1911 {"READX", handler_readx},
1912 {"WRITEX", handler_writex},
1913 {"CHKPATH", handler_chkpath},
1914 {"LOCKINGX", handler_lockingx},
1915 {"QPATHINFO", handler_qpathinfo},
1916 {"QFILEINFO", handler_qfileinfo},
1917 {"SPATHINFO", handler_spathinfo},
1918 {"SFILEINFO", handler_sfileinfo},
1919 {"NOTIFY", handler_notify},
1920 {"SEEK", handler_seek},
1925 run the test with the current set of op_parms parameters
1926 return the number of operations that completed successfully
1928 static int run_test(void)
1932 if (!connect_servers()) {
1933 printf("Failed to connect to servers\n");
1939 /* wipe any leftover files from old runs */
1942 /* reset the open handles array */
1943 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1944 num_open_handles = 0;
1946 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1947 gen_ops[i].count = 0;
1948 gen_ops[i].success_count = 0;
1951 for (op=0; op<options.numops; op++) {
1952 int instance, which_op;
1955 if (op_parms[op].disabled) continue;
1957 srandom(op_parms[op].seed);
1959 instance = gen_int_range(0, NINSTANCES-1);
1961 /* generate a non-ignored operation */
1963 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1964 } while (ignore_pattern(gen_ops[which_op].name));
1966 DEBUG(3,("Generating op %s on instance %d\n",
1967 gen_ops[which_op].name, instance));
1969 current_op.seed = op_parms[op].seed;
1970 current_op.opnum = op;
1971 current_op.name = gen_ops[which_op].name;
1972 current_op.status = NT_STATUS_OK;
1973 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1975 ret = gen_ops[which_op].handler(instance);
1977 talloc_free(current_op.mem_ctx);
1979 gen_ops[which_op].count++;
1980 if (NT_STATUS_IS_OK(current_op.status)) {
1981 gen_ops[which_op].success_count++;
1985 printf("Failed at operation %d - %s\n",
1986 op, gen_ops[which_op].name);
1990 if (op % 100 == 0) {
1995 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1996 printf("Op %-10s got %d/%d success\n",
1998 gen_ops[i].success_count,
2006 perform a backtracking analysis of the minimal set of operations
2007 to generate an error
2009 static void backtrack_analyze(void)
2013 chunk = options.numops / 2;
2018 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2021 chunk = MIN(chunk, options.numops / 2);
2023 /* mark this range as disabled */
2024 max = MIN(options.numops, base+chunk);
2025 for (i=base;i<max; i++) {
2026 op_parms[i].disabled = True;
2028 printf("Testing %d ops with %d-%d disabled\n",
2029 options.numops, base, max-1);
2031 printf("Completed %d of %d ops\n", ret, options.numops);
2032 for (i=base;i<max; i++) {
2033 op_parms[i].disabled = False;
2035 if (ret == options.numops) {
2036 /* this chunk is needed */
2038 } else if (ret < base) {
2039 printf("damn - inconsistent errors! found early error\n");
2040 options.numops = ret+1;
2043 /* it failed - this chunk isn't needed for a failure */
2044 memmove(&op_parms[base], &op_parms[max],
2045 sizeof(op_parms[0]) * (options.numops - max));
2046 options.numops = (ret+1) - (max - base);
2056 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2059 } while (chunk > 0);
2061 printf("Reduced to %d ops\n", options.numops);
2063 if (ret != options.numops - 1) {
2064 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2069 start the main gentest process
2071 static BOOL start_gentest(void)
2076 /* allocate the open_handles array */
2077 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2079 srandom(options.seed);
2080 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2082 /* generate the seeds - after this everything is deterministic */
2083 if (options.use_preset_seeds) {
2085 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
2087 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2090 if (numops < options.numops) {
2091 options.numops = numops;
2093 for (op=0;op<options.numops;op++) {
2095 printf("Not enough seeds in %s\n", options.seeds_file);
2098 op_parms[op].seed = atoi(preset[op]);
2100 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2102 for (op=0; op<options.numops; op++) {
2103 op_parms[op].seed = random();
2109 if (ret != options.numops && options.analyze) {
2110 options.numops = ret+1;
2111 backtrack_analyze();
2112 } else if (options.analyze_always) {
2113 backtrack_analyze();
2114 } else if (options.analyze_continuous) {
2115 while (run_test() == options.numops) ;
2118 return ret == options.numops;
2122 static void usage(void)
2126 gentest2 //server1/share1 //server2/share2 [options..]\n\
2128 -U user%%pass (can be specified twice)\n\
2131 -a (show all ops)\n\
2132 -A backtrack to find minimal ops\n\
2133 -i FILE add a list of wildcard exclusions\n\
2134 -O enable oplocks\n\
2135 -S FILE set preset seeds file\n\
2136 -L use preset seeds\n\
2137 -F fast reconnect (just close files)\n\
2138 -C continuous analysis mode\n\
2139 -X analyse even when test OK\n\
2144 split a UNC name into server and share names
2146 static BOOL split_unc_name(const char *unc, char **server, char **share)
2148 char *p = strdup(unc);
2149 if (!p) return False;
2150 all_string_sub(p, "\\", "/", 0);
2151 if (strncmp(p, "//", 2) != 0) return False;
2154 p = strchr(*server, '/');
2155 if (!p) return False;
2165 /****************************************************************************
2167 ****************************************************************************/
2168 int main(int argc, char *argv[])
2171 int i, username_count=0;
2176 setup_logging("gentest", DEBUG_STDOUT);
2178 if (argc < 3 || argv[1][0] == '-') {
2183 setup_logging(argv[0], DEBUG_STDOUT);
2185 for (i=0;i<NSERVERS;i++) {
2186 const char *share = argv[1+i];
2187 servers[i].credentials = cli_credentials_init(NULL);
2188 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2189 printf("Invalid share name '%s'\n", share);
2199 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
2200 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
2201 cli_credentials_guess(servers[0].credentials);
2202 cli_credentials_guess(servers[1].credentials);
2204 options.seed = time(NULL);
2205 options.numops = 1000;
2206 options.max_open_handles = 20;
2207 options.seeds_file = "gentest_seeds.dat";
2209 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2212 if (username_count == 2) {
2216 cli_credentials_parse_string(servers[username_count].credentials,
2217 optarg, CRED_SPECIFIED);
2221 DEBUGLEVEL = atoi(optarg);
2222 setup_logging(NULL, DEBUG_STDOUT);
2225 options.seed = atoi(optarg);
2228 options.seeds_file = optarg;
2231 options.use_preset_seeds = True;
2234 options.fast_reconnect = True;
2237 options.numops = atoi(optarg);
2240 options.use_oplocks = True;
2243 options.showall = True;
2246 options.analyze = True;
2249 options.analyze_always = True;
2252 options.analyze_continuous = True;
2255 options.ignore_patterns = file_lines_load(optarg, NULL, NULL);
2261 printf("Unknown option %c (%d)\n", (char)opt, opt);
2268 if (username_count == 0) {
2272 if (username_count == 1) {
2273 servers[1].credentials = servers[0].credentials;
2276 printf("seed=%u\n", options.seed);
2278 ret = start_gentest();
2281 printf("gentest completed - no errors\n");
2283 printf("gentest failed\n");