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 "dynconfig.h"
23 #include "system/time.h"
24 #include "system/filesys.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "librpc/gen_ndr/ndr_security.h"
33 static struct gentest_options {
37 BOOL analyze_continuous;
38 uint_t max_open_handles;
42 char **ignore_patterns;
43 const char *seeds_file;
44 BOOL use_preset_seeds;
48 /* mapping between open handles on the server and local handles */
52 uint_t server_fnum[NSERVERS];
55 static uint_t num_open_handles;
57 /* state information for the servers. We open NINSTANCES connections to
60 struct smbcli_state *cli[NINSTANCES];
67 /* the seeds and flags for each operation */
74 /* oplock break info */
81 } oplocks[NSERVERS][NINSTANCES];
83 /* change notify reply info */
87 struct 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 smbcli_shutdown(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].username, j);
180 status = smbcli_full_connection(NULL, &servers[i].cli[j],
182 servers[i].server_name,
183 servers[i].share_name, NULL,
186 servers[i].password);
187 if (!NT_STATUS_IS_OK(status)) {
188 printf("Failed to connect to \\\\%s\\%s - %s\n",
189 servers[i].server_name, servers[i].share_name,
194 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
195 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
203 work out the time skew between the servers - be conservative
205 static uint_t time_skew(void)
208 ret = ABS(servers[0].cli[0]->transport->negotiate.server_time -
209 servers[1].cli[0]->transport->negotiate.server_time);
214 turn an fnum for an instance into a handle
216 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
219 for (i=0;i<options.max_open_handles;i++) {
220 if (!open_handles[i].active ||
221 instance != open_handles[i].instance) continue;
222 if (open_handles[i].server_fnum[server] == fnum) {
226 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
227 fnum, server, instance);
232 add some newly opened handles
234 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
237 for (h=0;h<options.max_open_handles;h++) {
238 if (!open_handles[h].active) break;
240 if (h == options.max_open_handles) {
241 /* we have to force close a random handle */
242 h = random() % options.max_open_handles;
243 for (i=0;i<NSERVERS;i++) {
244 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
245 open_handles[h].server_fnum[i])))) {
246 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
247 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
250 printf("Recovered handle %d\n", h);
253 for (i=0;i<NSERVERS;i++) {
254 open_handles[h].server_fnum[i] = fnums[i];
255 open_handles[h].instance = instance;
256 open_handles[h].active = True;
257 open_handles[h].name = name;
261 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
263 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
268 remove a closed handle
270 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
273 for (h=0;h<options.max_open_handles;h++) {
274 if (instance == open_handles[h].instance &&
275 open_handles[h].server_fnum[0] == fnums[0]) {
276 open_handles[h].active = False;
278 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
280 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
281 open_handles[h].name);
285 printf("Removing invalid handle!?\n");
290 return True with 'chance' probability as a percentage
292 static BOOL gen_chance(uint_t chance)
294 return ((random() % 100) <= chance);
298 map an internal handle number to a server fnum
300 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
302 if (handle == BAD_HANDLE) return handle;
303 return open_handles[handle].server_fnum[server];
309 static uint16_t gen_fnum(int instance)
314 if (gen_chance(20)) return BAD_HANDLE;
316 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
317 h = random() % options.max_open_handles;
318 if (open_handles[h].active &&
319 open_handles[h].instance == instance) {
327 return a file handle, but skewed so we don't close the last
328 couple of handles too readily
330 static uint16_t gen_fnum_close(int instance)
332 if (num_open_handles < 3) {
333 if (gen_chance(80)) return BAD_HANDLE;
336 return gen_fnum(instance);
340 generate an integer in a specified range
342 static int gen_int_range(uint_t min, uint_t max)
345 return min + (r % (1+max-min));
349 return a fnum for use as a root fid
350 be careful to call GEN_SET_FNUM() when you use this!
352 static uint16_t gen_root_fid(int instance)
354 if (gen_chance(5)) return gen_fnum(instance);
359 generate a file offset
361 static int gen_offset(void)
363 if (gen_chance(20)) return 0;
364 return gen_int_range(0, 1024*1024);
370 static int gen_io_count(void)
372 if (gen_chance(20)) return 0;
373 return gen_int_range(0, 4096);
379 static const char *gen_fname(void)
381 const char *names[] = {"\\gentest\\gentest.dat",
383 "\\gentest\\foo2.sym",
384 "\\gentest\\foo3.dll",
386 "\\gentest\\foo4:teststream1",
387 "\\gentest\\foo4:teststream2",
388 "\\gentest\\foo5.exe",
389 "\\gentest\\foo5.exe:teststream3",
390 "\\gentest\\foo5.exe:teststream4",
391 "\\gentest\\foo6.com",
393 "\\gentest\\blah\\blergh.txt",
394 "\\gentest\\blah\\blergh2",
395 "\\gentest\\blah\\blergh3.txt",
396 "\\gentest\\blah\\blergh4",
397 "\\gentest\\blah\\blergh5.txt",
398 "\\gentest\\blah\\blergh5",
399 "\\gentest\\blah\\.",
401 /* this causes problem with w2k3 */
402 "\\gentest\\blah\\..",
404 "\\gentest\\a_very_long_name.bin",
410 i = gen_int_range(0, ARRAY_SIZE(names)-1);
411 } while (ignore_pattern(names[i]));
417 generate a filename with a higher chance of choosing an already
420 static const char *gen_fname_open(int instance)
423 h = gen_fnum(instance);
424 if (h == BAD_HANDLE) {
427 return open_handles[h].name;
431 generate a wildcard pattern
433 static const char *gen_pattern(void)
436 const char *names[] = {"\\gentest\\*.dat",
439 "\\gentest\\blah\\*.*",
440 "\\gentest\\blah\\*",
443 if (gen_chance(50)) return gen_fname();
446 i = gen_int_range(0, ARRAY_SIZE(names)-1);
447 } while (ignore_pattern(names[i]));
455 static uint32_t gen_bits_mask(uint_t mask)
457 uint_t ret = random();
462 generate a bitmask with high probability of the first mask
463 and low of the second
465 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
467 if (gen_chance(10)) return gen_bits_mask(mask2);
468 return gen_bits_mask(mask1);
474 static BOOL gen_bool(void)
476 return gen_bits_mask2(0x1, 0xFF);
480 generate ntrename flags
482 static uint16_t gen_rename_flags(void)
484 if (gen_chance(30)) return RENAME_FLAG_RENAME;
485 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
486 if (gen_chance(30)) return RENAME_FLAG_COPY;
487 return gen_bits_mask(0xFFFF);
492 return a lockingx lock mode
494 static uint16_t gen_lock_mode(void)
496 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
497 if (gen_chance(20)) return gen_bits_mask(0x1F);
498 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
504 static uint16_t gen_pid(void)
506 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
511 generate a lock count
513 static off_t gen_lock_count(void)
515 return gen_int_range(0, 3);
519 generate a ntcreatex flags field
521 static uint32_t gen_ntcreatex_flags(void)
523 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
524 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
528 generate a NT access mask
530 static uint32_t gen_access_mask(void)
532 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
533 if (gen_chance(20)) return SEC_FILE_ALL;
534 return gen_bits_mask(0xFFFFFFFF);
538 generate a ntcreatex create options bitfield
540 static uint32_t gen_create_options(void)
542 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
543 if (gen_chance(50)) return 0;
544 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
548 generate a ntcreatex open disposition
550 static uint32_t gen_open_disp(void)
552 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
553 return gen_int_range(0, 5);
557 generate an openx open mode
559 static uint16_t gen_openx_mode(void)
561 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
562 if (gen_chance(20)) return gen_bits_mask(0xFF);
563 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
567 generate an openx flags field
569 static uint16_t gen_openx_flags(void)
571 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
572 return gen_bits_mask(0x7);
576 generate an openx open function
578 static uint16_t gen_openx_func(void)
580 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
581 return gen_bits_mask(0x13);
585 generate a file attrib combination
587 static uint32_t gen_attrib(void)
589 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
590 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
594 generate a unix timestamp
596 static time_t gen_timet(void)
598 if (gen_chance(30)) return 0;
599 return (time_t)random();
603 generate a unix timestamp
605 static NTTIME gen_nttime(void)
608 unix_to_nt_time(&ret, gen_timet());
613 generate a milliseconds protocol timeout
615 static uint32_t gen_timeout(void)
617 if (gen_chance(98)) return 0;
618 return random() % 50;
622 generate a file allocation size
624 static uint_t gen_alloc_size(void)
628 if (gen_chance(30)) return 0;
630 ret = random() % 4*1024*1024;
631 /* give a high chance of a round number */
632 if (gen_chance(60)) {
633 ret &= ~(1024*1024 - 1);
639 generate an ea_struct
641 static struct ea_struct gen_ea_struct(void)
644 const char *names[] = {"EAONE",
649 "AVERYLONGATTRIBUTENAME"};
650 const char *values[] = {"VALUE1",
655 "ASOMEWHATLONGERATTRIBUTEVALUE"};
659 i = gen_int_range(0, ARRAY_SIZE(names)-1);
660 } while (ignore_pattern(names[i]));
662 ea.name.s = names[i];
665 i = gen_int_range(0, ARRAY_SIZE(values)-1);
666 } while (ignore_pattern(values[i]));
668 ea.value = data_blob(values[i], strlen(values[i]));
670 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
678 this is called when a change notify reply comes in
680 static void async_notify(struct smbcli_request *req)
682 struct smb_notify notify;
686 struct smbcli_transport *transport = req->transport;
688 tid = SVAL(req->in.hdr, HDR_TID);
690 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
691 if (NT_STATUS_IS_OK(status)) {
692 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
694 notify.out.num_changes,
695 notify.out.changes[0].action,
696 notify.out.changes[0].name.s);
699 for (i=0;i<NSERVERS;i++) {
700 for (j=0;j<NINSTANCES;j++) {
701 if (transport == servers[i].cli[j]->transport &&
702 tid == servers[i].cli[j]->tree->tid) {
703 notifies[i][j].notify_count++;
704 notifies[i][j].status = status;
705 notifies[i][j].notify = notify;
712 the oplock handler will either ack the break or close the file
714 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
720 struct smbcli_tree *tree = NULL;
722 srandom(current_op.seed);
723 do_close = gen_chance(50);
725 for (i=0;i<NSERVERS;i++) {
726 for (j=0;j<NINSTANCES;j++) {
727 if (transport == servers[i].cli[j]->transport &&
728 tid == servers[i].cli[j]->tree->tid) {
729 oplocks[i][j].got_break = True;
730 oplocks[i][j].fnum = fnum;
731 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
732 oplocks[i][j].level = level;
733 oplocks[i][j].do_close = do_close;
734 tree = servers[i].cli[j]->tree;
740 printf("Oplock break not for one of our trees!?\n");
745 printf("oplock ack fnum=%d\n", fnum);
746 return smbcli_oplock_ack(tree, fnum, level);
749 printf("oplock close fnum=%d\n", fnum);
751 io.close.level = RAW_CLOSE_CLOSE;
752 io.close.in.fnum = fnum;
753 io.close.in.write_time = 0;
754 status = smb_raw_close(tree, &io);
756 if (!NT_STATUS_IS_OK(status)) {
757 printf("WARNING: close failed in oplock_handler_close - %s\n", nt_errstr(status));
764 the idle function tries to cope with getting an oplock break on a connection, and
765 an operation on another connection blocking until that break is acked
766 we check for operations on all transports in the idle function
768 static void idle_func(struct smbcli_transport *transport, void *private)
771 for (i=0;i<NSERVERS;i++) {
772 for (j=0;j<NINSTANCES;j++) {
773 if (servers[i].cli[j] &&
774 transport != servers[i].cli[j]->transport) {
775 smbcli_transport_process(servers[i].cli[j]->transport);
784 compare NTSTATUS, using checking ignored patterns
786 static BOOL compare_status(NTSTATUS status1, NTSTATUS status2)
788 if (NT_STATUS_EQUAL(status1, status2)) return True;
790 /* one code being an error and the other OK is always an error */
791 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return False;
793 /* if we are ignoring one of the status codes then consider this a match */
794 if (ignore_pattern(nt_errstr(status1)) ||
795 ignore_pattern(nt_errstr(status2))) {
803 check for pending packets on all connections
805 static void check_pending(void)
811 for (j=0;j<NINSTANCES;j++) {
812 for (i=0;i<NSERVERS;i++) {
813 smbcli_transport_process(servers[i].cli[j]->transport);
819 check that the same oplock breaks have been received by all instances
821 static BOOL check_oplocks(const char *call)
829 for (j=0;j<NINSTANCES;j++) {
830 for (i=1;i<NSERVERS;i++) {
831 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
832 oplocks[0][j].handle != oplocks[i][j].handle ||
833 oplocks[0][j].level != oplocks[i][j].level) {
834 if (tries++ < 10) goto again;
835 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
836 oplocks[0][j].got_break,
837 oplocks[0][j].handle,
839 oplocks[i][j].got_break,
840 oplocks[i][j].handle,
841 oplocks[i][j].level);
847 /* if we got a break and closed then remove the handle */
848 for (j=0;j<NINSTANCES;j++) {
849 if (oplocks[0][j].got_break &&
850 oplocks[0][j].do_close) {
851 uint16_t fnums[NSERVERS];
852 for (i=0;i<NSERVERS;i++) {
853 fnums[i] = oplocks[i][j].fnum;
855 gen_remove_handle(j, fnums);
864 check that the same change notify info has been received by all instances
866 static BOOL check_notifies(const char *call)
874 for (j=0;j<NINSTANCES;j++) {
875 for (i=1;i<NSERVERS;i++) {
877 struct smb_notify not1, not2;
879 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
880 if (tries++ < 10) goto again;
881 printf("Notify count inconsistent %d %d\n",
882 notifies[0][j].notify_count,
883 notifies[i][j].notify_count);
887 if (notifies[0][j].notify_count == 0) continue;
889 if (!NT_STATUS_EQUAL(notifies[0][j].status,
890 notifies[i][j].status)) {
891 printf("Notify status mismatch - %s - %s\n",
892 nt_errstr(notifies[0][j].status),
893 nt_errstr(notifies[i][j].status));
897 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
901 not1 = notifies[0][j].notify;
902 not2 = notifies[i][j].notify;
904 for (n=0;n<not1.out.num_changes;n++) {
905 if (not1.out.changes[n].action !=
906 not2.out.changes[n].action) {
907 printf("Notify action %d inconsistent %d %d\n", n,
908 not1.out.changes[n].action,
909 not2.out.changes[n].action);
912 if (strcmp(not1.out.changes[n].name.s,
913 not2.out.changes[n].name.s)) {
914 printf("Notify name %d inconsistent %s %s\n", n,
915 not1.out.changes[n].name.s,
916 not2.out.changes[n].name.s);
919 if (not1.out.changes[n].name.private_length !=
920 not2.out.changes[n].name.private_length) {
921 printf("Notify name length %d inconsistent %d %d\n", n,
922 not1.out.changes[n].name.private_length,
923 not2.out.changes[n].name.private_length);
930 ZERO_STRUCT(notifies);
936 #define GEN_COPY_PARM do { \
938 for (i=1;i<NSERVERS;i++) { \
943 #define GEN_CALL(call) do { \
945 ZERO_STRUCT(oplocks); \
946 ZERO_STRUCT(notifies); \
947 for (i=0;i<NSERVERS;i++) { \
948 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
951 current_op.status = status[0]; \
952 for (i=1;i<NSERVERS;i++) { \
953 if (!compare_status(status[i], status[0])) { \
954 printf("status different in %s - %s %s\n", #call, \
955 nt_errstr(status[0]), nt_errstr(status[i])); \
959 if (!check_oplocks(#call)) return False; \
960 if (!check_notifies(#call)) return False; \
961 if (!NT_STATUS_IS_OK(status[0])) { \
966 #define ADD_HANDLE(name, field) do { \
967 uint16_t fnums[NSERVERS]; \
969 for (i=0;i<NSERVERS;i++) { \
970 fnums[i] = parm[i].field; \
972 gen_add_handle(instance, name, fnums); \
975 #define REMOVE_HANDLE(field) do { \
976 uint16_t fnums[NSERVERS]; \
978 for (i=0;i<NSERVERS;i++) { \
979 fnums[i] = parm[i].field; \
981 gen_remove_handle(instance, fnums); \
984 #define GEN_SET_FNUM(field) do { \
986 for (i=0;i<NSERVERS;i++) { \
987 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
991 #define CHECK_EQUAL(field) do { \
992 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
993 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
994 (int)parm[0].field, (int)parm[1].field); \
999 #define CHECK_WSTR_EQUAL(field) do { \
1000 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1001 printf("%s is NULL!\n", #field); \
1004 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1005 printf("Mismatch in %s - %s %s\n", #field, \
1006 parm[0].field.s, parm[1].field.s); \
1009 CHECK_EQUAL(field.private_length); \
1012 #define CHECK_BLOB_EQUAL(field) do { \
1013 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1014 printf("Mismatch in %s\n", #field); \
1017 CHECK_EQUAL(field.length); \
1020 #define CHECK_TIMES_EQUAL(field) do { \
1021 if (ABS(parm[0].field - parm[1].field) > time_skew() && \
1022 !ignore_pattern(#field)) { \
1023 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1024 (int)parm[0].field, (int)parm[1].field); \
1029 #define CHECK_NTTIMES_EQUAL(field) do { \
1030 if (ABS(nt_time_to_unix(parm[0].field) - \
1031 nt_time_to_unix(parm[1].field)) > time_skew() && \
1032 !ignore_pattern(#field)) { \
1033 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1034 (int)nt_time_to_unix(parm[0].field), \
1035 (int)nt_time_to_unix(parm[1].field)); \
1041 generate openx operations
1043 static BOOL handler_openx(int instance)
1045 union smb_open parm[NSERVERS];
1046 NTSTATUS status[NSERVERS];
1048 parm[0].openx.level = RAW_OPEN_OPENX;
1049 parm[0].openx.in.flags = gen_openx_flags();
1050 parm[0].openx.in.open_mode = gen_openx_mode();
1051 parm[0].openx.in.search_attrs = gen_attrib();
1052 parm[0].openx.in.file_attrs = gen_attrib();
1053 parm[0].openx.in.write_time = gen_timet();
1054 parm[0].openx.in.open_func = gen_openx_func();
1055 parm[0].openx.in.size = gen_io_count();
1056 parm[0].openx.in.timeout = gen_timeout();
1057 parm[0].openx.in.fname = gen_fname_open(instance);
1059 if (!options.use_oplocks) {
1060 /* mask out oplocks */
1061 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1062 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1066 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1068 CHECK_EQUAL(openx.out.attrib);
1069 CHECK_EQUAL(openx.out.size);
1070 CHECK_EQUAL(openx.out.access);
1071 CHECK_EQUAL(openx.out.ftype);
1072 CHECK_EQUAL(openx.out.devstate);
1073 CHECK_EQUAL(openx.out.action);
1074 CHECK_EQUAL(openx.out.access_mask);
1075 CHECK_EQUAL(openx.out.unknown);
1076 CHECK_TIMES_EQUAL(openx.out.write_time);
1078 /* open creates a new file handle */
1079 ADD_HANDLE(parm[0].openx.in.fname, openx.out.fnum);
1086 generate open operations
1088 static BOOL handler_open(int instance)
1090 union smb_open parm[NSERVERS];
1091 NTSTATUS status[NSERVERS];
1093 parm[0].openold.level = RAW_OPEN_OPEN;
1094 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1095 parm[0].openold.in.search_attrs = gen_attrib();
1096 parm[0].openold.in.fname = gen_fname_open(instance);
1098 if (!options.use_oplocks) {
1099 /* mask out oplocks */
1100 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1101 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1105 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1107 CHECK_EQUAL(openold.out.attrib);
1108 CHECK_TIMES_EQUAL(openold.out.write_time);
1109 CHECK_EQUAL(openold.out.size);
1110 CHECK_EQUAL(openold.out.rmode);
1112 /* open creates a new file handle */
1113 ADD_HANDLE(parm[0].openold.in.fname, openold.out.fnum);
1120 generate ntcreatex operations
1122 static BOOL handler_ntcreatex(int instance)
1124 union smb_open parm[NSERVERS];
1125 NTSTATUS status[NSERVERS];
1127 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1128 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1129 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1130 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1131 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1132 parm[0].ntcreatex.in.file_attr = gen_attrib();
1133 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1134 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1135 parm[0].ntcreatex.in.create_options = gen_create_options();
1136 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1137 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1138 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1140 if (!options.use_oplocks) {
1141 /* mask out oplocks */
1142 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1143 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1147 if (parm[0].ntcreatex.in.root_fid != 0) {
1148 GEN_SET_FNUM(ntcreatex.in.root_fid);
1150 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1152 CHECK_EQUAL(ntcreatex.out.oplock_level);
1153 CHECK_EQUAL(ntcreatex.out.create_action);
1154 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1155 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1156 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1157 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1158 CHECK_EQUAL(ntcreatex.out.attrib);
1159 CHECK_EQUAL(ntcreatex.out.alloc_size);
1160 CHECK_EQUAL(ntcreatex.out.size);
1161 CHECK_EQUAL(ntcreatex.out.file_type);
1162 CHECK_EQUAL(ntcreatex.out.ipc_state);
1163 CHECK_EQUAL(ntcreatex.out.is_directory);
1165 /* ntcreatex creates a new file handle */
1166 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.fnum);
1172 generate close operations
1174 static BOOL handler_close(int instance)
1176 union smb_close parm[NSERVERS];
1177 NTSTATUS status[NSERVERS];
1179 parm[0].close.level = RAW_CLOSE_CLOSE;
1180 parm[0].close.in.fnum = gen_fnum_close(instance);
1181 parm[0].close.in.write_time = gen_timet();
1184 GEN_SET_FNUM(close.in.fnum);
1185 GEN_CALL(smb_raw_close(tree, &parm[i]));
1187 REMOVE_HANDLE(close.in.fnum);
1193 generate unlink operations
1195 static BOOL handler_unlink(int instance)
1197 struct smb_unlink parm[NSERVERS];
1198 NTSTATUS status[NSERVERS];
1200 parm[0].in.pattern = gen_pattern();
1201 parm[0].in.attrib = gen_attrib();
1204 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1210 generate chkpath operations
1212 static BOOL handler_chkpath(int instance)
1214 struct smb_chkpath parm[NSERVERS];
1215 NTSTATUS status[NSERVERS];
1217 parm[0].in.path = gen_fname_open(instance);
1220 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1226 generate mkdir operations
1228 static BOOL handler_mkdir(int instance)
1230 union smb_mkdir parm[NSERVERS];
1231 NTSTATUS status[NSERVERS];
1233 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1234 parm[0].mkdir.in.path = gen_fname_open(instance);
1237 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1243 generate rmdir operations
1245 static BOOL handler_rmdir(int instance)
1247 struct smb_rmdir parm[NSERVERS];
1248 NTSTATUS status[NSERVERS];
1250 parm[0].in.path = gen_fname_open(instance);
1253 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1259 generate rename operations
1261 static BOOL handler_rename(int instance)
1263 union smb_rename parm[NSERVERS];
1264 NTSTATUS status[NSERVERS];
1266 parm[0].generic.level = RAW_RENAME_RENAME;
1267 parm[0].rename.in.pattern1 = gen_pattern();
1268 parm[0].rename.in.pattern2 = gen_pattern();
1269 parm[0].rename.in.attrib = gen_attrib();
1272 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1278 generate ntrename operations
1280 static BOOL handler_ntrename(int instance)
1282 union smb_rename parm[NSERVERS];
1283 NTSTATUS status[NSERVERS];
1285 parm[0].generic.level = RAW_RENAME_NTRENAME;
1286 parm[0].ntrename.in.old_name = gen_fname();
1287 parm[0].ntrename.in.new_name = gen_fname();
1288 parm[0].ntrename.in.attrib = gen_attrib();
1289 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1290 parm[0].ntrename.in.flags = gen_rename_flags();
1293 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1300 generate seek operations
1302 static BOOL handler_seek(int instance)
1304 struct smb_seek parm[NSERVERS];
1305 NTSTATUS status[NSERVERS];
1307 parm[0].in.fnum = gen_fnum(instance);
1308 parm[0].in.mode = gen_bits_mask2(0x3, 0xFFFF);
1309 parm[0].in.offset = gen_offset();
1312 GEN_SET_FNUM(in.fnum);
1313 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1315 CHECK_EQUAL(out.offset);
1322 generate readx operations
1324 static BOOL handler_readx(int instance)
1326 union smb_read parm[NSERVERS];
1327 NTSTATUS status[NSERVERS];
1329 parm[0].readx.level = RAW_READ_READX;
1330 parm[0].readx.in.fnum = gen_fnum(instance);
1331 parm[0].readx.in.offset = gen_offset();
1332 parm[0].readx.in.mincnt = gen_io_count();
1333 parm[0].readx.in.maxcnt = gen_io_count();
1334 parm[0].readx.in.remaining = gen_io_count();
1335 parm[0].readx.out.data = talloc_size(current_op.mem_ctx,
1336 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1339 GEN_SET_FNUM(readx.in.fnum);
1340 GEN_CALL(smb_raw_read(tree, &parm[i]));
1342 CHECK_EQUAL(readx.out.remaining);
1343 CHECK_EQUAL(readx.out.compaction_mode);
1344 CHECK_EQUAL(readx.out.nread);
1350 generate writex operations
1352 static BOOL handler_writex(int instance)
1354 union smb_write parm[NSERVERS];
1355 NTSTATUS status[NSERVERS];
1357 parm[0].writex.level = RAW_WRITE_WRITEX;
1358 parm[0].writex.in.fnum = gen_fnum(instance);
1359 parm[0].writex.in.offset = gen_offset();
1360 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1361 parm[0].writex.in.remaining = gen_io_count();
1362 parm[0].writex.in.count = gen_io_count();
1363 parm[0].writex.in.data = talloc_zero_size(current_op.mem_ctx, parm[0].writex.in.count);
1366 GEN_SET_FNUM(writex.in.fnum);
1367 GEN_CALL(smb_raw_write(tree, &parm[i]));
1369 CHECK_EQUAL(writex.out.nwritten);
1370 CHECK_EQUAL(writex.out.remaining);
1376 generate lockingx operations
1378 static BOOL handler_lockingx(int instance)
1380 union smb_lock parm[NSERVERS];
1381 NTSTATUS status[NSERVERS];
1384 parm[0].lockx.level = RAW_LOCK_LOCKX;
1385 parm[0].lockx.in.fnum = gen_fnum(instance);
1386 parm[0].lockx.in.mode = gen_lock_mode();
1387 parm[0].lockx.in.timeout = gen_timeout();
1389 /* make sure we don't accidentially generate an oplock
1390 break ack - otherwise the server can just block forever */
1391 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1392 parm[0].lockx.in.lock_cnt = gen_lock_count();
1393 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1394 } while (nlocks == 0);
1397 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1398 struct smb_lock_entry,
1400 for (n=0;n<nlocks;n++) {
1401 parm[0].lockx.in.locks[n].pid = gen_pid();
1402 parm[0].lockx.in.locks[n].offset = gen_offset();
1403 parm[0].lockx.in.locks[n].count = gen_io_count();
1408 GEN_SET_FNUM(lockx.in.fnum);
1409 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1415 generate a fileinfo query structure
1417 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1420 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1422 enum smb_fileinfo_level level;
1425 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1426 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1427 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1428 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1429 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1430 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1431 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1432 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1433 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1434 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1437 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1438 } while (ignore_pattern(levels[i].name));
1440 info->generic.level = levels[i].level;
1444 compare returned fileinfo structures
1446 static BOOL cmp_fileinfo(int instance,
1447 union smb_fileinfo parm[NSERVERS],
1448 NTSTATUS status[NSERVERS])
1452 switch (parm[0].generic.level) {
1453 case RAW_FILEINFO_GENERIC:
1456 case RAW_FILEINFO_GETATTR:
1457 CHECK_EQUAL(getattr.out.attrib);
1458 CHECK_EQUAL(getattr.out.size);
1459 CHECK_TIMES_EQUAL(getattr.out.write_time);
1462 case RAW_FILEINFO_GETATTRE:
1463 CHECK_TIMES_EQUAL(getattre.out.create_time);
1464 CHECK_TIMES_EQUAL(getattre.out.access_time);
1465 CHECK_TIMES_EQUAL(getattre.out.write_time);
1466 CHECK_EQUAL(getattre.out.size);
1467 CHECK_EQUAL(getattre.out.alloc_size);
1468 CHECK_EQUAL(getattre.out.attrib);
1471 case RAW_FILEINFO_STANDARD:
1472 CHECK_TIMES_EQUAL(standard.out.create_time);
1473 CHECK_TIMES_EQUAL(standard.out.access_time);
1474 CHECK_TIMES_EQUAL(standard.out.write_time);
1475 CHECK_EQUAL(standard.out.size);
1476 CHECK_EQUAL(standard.out.alloc_size);
1477 CHECK_EQUAL(standard.out.attrib);
1480 case RAW_FILEINFO_EA_SIZE:
1481 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1482 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1483 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1484 CHECK_EQUAL(ea_size.out.size);
1485 CHECK_EQUAL(ea_size.out.alloc_size);
1486 CHECK_EQUAL(ea_size.out.attrib);
1487 CHECK_EQUAL(ea_size.out.ea_size);
1490 case RAW_FILEINFO_ALL_EAS:
1491 CHECK_EQUAL(all_eas.out.num_eas);
1492 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1493 CHECK_EQUAL(all_eas.out.eas[i].flags);
1494 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1495 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1499 case RAW_FILEINFO_IS_NAME_VALID:
1502 case RAW_FILEINFO_BASIC_INFO:
1503 case RAW_FILEINFO_BASIC_INFORMATION:
1504 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1505 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1506 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1507 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1508 CHECK_EQUAL(basic_info.out.attrib);
1511 case RAW_FILEINFO_STANDARD_INFO:
1512 case RAW_FILEINFO_STANDARD_INFORMATION:
1513 CHECK_EQUAL(standard_info.out.alloc_size);
1514 CHECK_EQUAL(standard_info.out.size);
1515 CHECK_EQUAL(standard_info.out.nlink);
1516 CHECK_EQUAL(standard_info.out.delete_pending);
1517 CHECK_EQUAL(standard_info.out.directory);
1520 case RAW_FILEINFO_EA_INFO:
1521 case RAW_FILEINFO_EA_INFORMATION:
1522 CHECK_EQUAL(ea_info.out.ea_size);
1525 case RAW_FILEINFO_NAME_INFO:
1526 case RAW_FILEINFO_NAME_INFORMATION:
1527 CHECK_WSTR_EQUAL(name_info.out.fname);
1530 case RAW_FILEINFO_ALL_INFO:
1531 case RAW_FILEINFO_ALL_INFORMATION:
1532 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1533 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1534 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1535 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1536 CHECK_EQUAL(all_info.out.attrib);
1537 CHECK_EQUAL(all_info.out.alloc_size);
1538 CHECK_EQUAL(all_info.out.size);
1539 CHECK_EQUAL(all_info.out.nlink);
1540 CHECK_EQUAL(all_info.out.delete_pending);
1541 CHECK_EQUAL(all_info.out.directory);
1542 CHECK_EQUAL(all_info.out.ea_size);
1543 CHECK_WSTR_EQUAL(all_info.out.fname);
1546 case RAW_FILEINFO_ALT_NAME_INFO:
1547 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1548 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1551 case RAW_FILEINFO_STREAM_INFO:
1552 case RAW_FILEINFO_STREAM_INFORMATION:
1553 CHECK_EQUAL(stream_info.out.num_streams);
1554 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1555 CHECK_EQUAL(stream_info.out.streams[i].size);
1556 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1557 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1561 case RAW_FILEINFO_COMPRESSION_INFO:
1562 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1563 CHECK_EQUAL(compression_info.out.compressed_size);
1564 CHECK_EQUAL(compression_info.out.format);
1565 CHECK_EQUAL(compression_info.out.unit_shift);
1566 CHECK_EQUAL(compression_info.out.chunk_shift);
1567 CHECK_EQUAL(compression_info.out.cluster_shift);
1570 case RAW_FILEINFO_INTERNAL_INFORMATION:
1571 CHECK_EQUAL(internal_information.out.file_id);
1574 case RAW_FILEINFO_ACCESS_INFORMATION:
1575 CHECK_EQUAL(access_information.out.access_flags);
1578 case RAW_FILEINFO_POSITION_INFORMATION:
1579 CHECK_EQUAL(position_information.out.position);
1582 case RAW_FILEINFO_MODE_INFORMATION:
1583 CHECK_EQUAL(mode_information.out.mode);
1586 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1587 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1590 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1591 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1592 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1593 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1594 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1595 CHECK_EQUAL(network_open_information.out.alloc_size);
1596 CHECK_EQUAL(network_open_information.out.size);
1597 CHECK_EQUAL(network_open_information.out.attrib);
1600 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1601 CHECK_EQUAL(attribute_tag_information.out.attrib);
1602 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1610 generate qpathinfo operations
1612 static BOOL handler_qpathinfo(int instance)
1614 union smb_fileinfo parm[NSERVERS];
1615 NTSTATUS status[NSERVERS];
1617 parm[0].generic.in.fname = gen_fname_open(instance);
1619 gen_fileinfo(instance, &parm[0]);
1622 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1624 return cmp_fileinfo(instance, parm, status);
1628 generate qfileinfo operations
1630 static BOOL handler_qfileinfo(int instance)
1632 union smb_fileinfo parm[NSERVERS];
1633 NTSTATUS status[NSERVERS];
1635 parm[0].generic.in.fnum = gen_fnum(instance);
1637 gen_fileinfo(instance, &parm[0]);
1640 GEN_SET_FNUM(generic.in.fnum);
1641 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1643 return cmp_fileinfo(instance, parm, status);
1648 generate a fileinfo query structure
1650 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1654 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1656 enum smb_setfileinfo_level level;
1660 /* disabled until win2003 can handle them ... */
1661 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1662 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1664 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1665 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1666 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1667 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1668 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1671 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1672 } while (ignore_pattern(levels[i].name));
1674 info->generic.level = levels[i].level;
1676 switch (info->generic.level) {
1677 case RAW_SFILEINFO_SETATTR:
1678 info->setattr.in.attrib = gen_attrib();
1679 info->setattr.in.write_time = gen_timet();
1681 case RAW_SFILEINFO_SETATTRE:
1682 info->setattre.in.create_time = gen_timet();
1683 info->setattre.in.access_time = gen_timet();
1684 info->setattre.in.write_time = gen_timet();
1686 case RAW_SFILEINFO_STANDARD:
1687 info->standard.in.create_time = gen_timet();
1688 info->standard.in.access_time = gen_timet();
1689 info->standard.in.write_time = gen_timet();
1691 case RAW_SFILEINFO_EA_SET: {
1692 static struct ea_struct ea;
1693 info->ea_set.in.num_eas = 1;
1694 info->ea_set.in.eas = &ea;
1695 info->ea_set.in.eas[0] = gen_ea_struct();
1698 case RAW_SFILEINFO_BASIC_INFO:
1699 case RAW_SFILEINFO_BASIC_INFORMATION:
1700 info->basic_info.in.create_time = gen_nttime();
1701 info->basic_info.in.access_time = gen_nttime();
1702 info->basic_info.in.write_time = gen_nttime();
1703 info->basic_info.in.change_time = gen_nttime();
1704 info->basic_info.in.attrib = gen_attrib();
1706 case RAW_SFILEINFO_DISPOSITION_INFO:
1707 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1708 info->disposition_info.in.delete_on_close = gen_bool();
1710 case RAW_SFILEINFO_ALLOCATION_INFO:
1711 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1712 info->allocation_info.in.alloc_size = gen_alloc_size();
1714 case RAW_SFILEINFO_END_OF_FILE_INFO:
1715 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1716 info->end_of_file_info.in.size = gen_offset();
1718 case RAW_SFILEINFO_RENAME_INFORMATION:
1719 info->rename_information.in.overwrite = gen_bool();
1720 info->rename_information.in.root_fid = gen_root_fid(instance);
1721 info->rename_information.in.new_name = gen_fname_open(instance);
1723 case RAW_SFILEINFO_POSITION_INFORMATION:
1724 info->position_information.in.position = gen_offset();
1726 case RAW_SFILEINFO_MODE_INFORMATION:
1727 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1733 generate setpathinfo operations
1735 static BOOL handler_spathinfo(int instance)
1737 union smb_setfileinfo parm[NSERVERS];
1738 NTSTATUS status[NSERVERS];
1740 parm[0].generic.file.fname = gen_fname_open(instance);
1742 gen_setfileinfo(instance, &parm[0]);
1746 /* a special case for the fid in a RENAME */
1747 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1748 parm[0].rename_information.in.root_fid != 0) {
1749 GEN_SET_FNUM(rename_information.in.root_fid);
1752 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1759 generate setfileinfo operations
1761 static BOOL handler_sfileinfo(int instance)
1763 union smb_setfileinfo parm[NSERVERS];
1764 NTSTATUS status[NSERVERS];
1766 parm[0].generic.file.fnum = gen_fnum(instance);
1768 gen_setfileinfo(instance, &parm[0]);
1771 GEN_SET_FNUM(generic.file.fnum);
1772 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1779 generate change notify operations
1781 static BOOL handler_notify(int instance)
1783 struct smb_notify parm[NSERVERS];
1786 parm[0].in.buffer_size = gen_io_count();
1787 parm[0].in.completion_filter = gen_bits_mask(0xFF);
1788 parm[0].in.fnum = gen_fnum(instance);
1789 parm[0].in.recursive = gen_bool();
1792 GEN_SET_FNUM(in.fnum);
1794 for (n=0;n<NSERVERS;n++) {
1795 struct smbcli_request *req;
1796 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1797 req->async.fn = async_notify;
1804 wipe any relevant files
1806 static void wipe_files(void)
1809 for (i=0;i<NSERVERS;i++) {
1810 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1812 printf("Failed to wipe tree on server %d\n", i);
1815 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1816 printf("Failed to create \\gentest - %s\n",
1817 smbcli_errstr(servers[i].cli[0]->tree));
1821 printf("Deleted %d files on server %d\n", n, i);
1827 dump the current seeds - useful for continuing a backtrack
1829 static void dump_seeds(void)
1834 if (!options.seeds_file) {
1837 f = fopen("seeds.tmp", "w");
1840 for (i=0;i<options.numops;i++) {
1841 fprintf(f, "%u\n", op_parms[i].seed);
1844 rename("seeds.tmp", options.seeds_file);
1850 the list of top-level operations that we will generate
1854 BOOL (*handler)(int instance);
1855 int count, success_count;
1857 {"OPEN", handler_open},
1858 {"OPENX", handler_openx},
1859 {"NTCREATEX", handler_ntcreatex},
1860 {"CLOSE", handler_close},
1861 {"UNLINK", handler_unlink},
1862 {"MKDIR", handler_mkdir},
1863 {"RMDIR", handler_rmdir},
1864 {"RENAME", handler_rename},
1865 {"NTRENAME", handler_ntrename},
1866 {"READX", handler_readx},
1867 {"WRITEX", handler_writex},
1868 {"CHKPATH", handler_chkpath},
1869 {"LOCKINGX", handler_lockingx},
1870 {"QPATHINFO", handler_qpathinfo},
1871 {"QFILEINFO", handler_qfileinfo},
1872 {"SPATHINFO", handler_spathinfo},
1873 {"SFILEINFO", handler_sfileinfo},
1874 {"NOTIFY", handler_notify},
1875 {"SEEK", handler_seek},
1880 run the test with the current set of op_parms parameters
1881 return the number of operations that completed successfully
1883 static int run_test(void)
1887 if (!connect_servers()) {
1888 printf("Failed to connect to servers\n");
1894 /* wipe any leftover files from old runs */
1897 /* reset the open handles array */
1898 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1899 num_open_handles = 0;
1901 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1902 gen_ops[i].count = 0;
1903 gen_ops[i].success_count = 0;
1906 for (op=0; op<options.numops; op++) {
1907 int instance, which_op;
1910 if (op_parms[op].disabled) continue;
1912 srandom(op_parms[op].seed);
1914 instance = gen_int_range(0, NINSTANCES-1);
1916 /* generate a non-ignored operation */
1918 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1919 } while (ignore_pattern(gen_ops[which_op].name));
1921 DEBUG(3,("Generating op %s on instance %d\n",
1922 gen_ops[which_op].name, instance));
1924 current_op.seed = op_parms[op].seed;
1925 current_op.opnum = op;
1926 current_op.name = gen_ops[which_op].name;
1927 current_op.status = NT_STATUS_OK;
1928 current_op.mem_ctx = talloc_init("%s", current_op.name);
1930 ret = gen_ops[which_op].handler(instance);
1932 talloc_free(current_op.mem_ctx);
1934 gen_ops[which_op].count++;
1935 if (NT_STATUS_IS_OK(current_op.status)) {
1936 gen_ops[which_op].success_count++;
1940 printf("Failed at operation %d - %s\n",
1941 op, gen_ops[which_op].name);
1945 if (op % 100 == 0) {
1950 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1951 printf("Op %-10s got %d/%d success\n",
1953 gen_ops[i].success_count,
1961 perform a backtracking analysis of the minimal set of operations
1962 to generate an error
1964 static void backtrack_analyze(void)
1968 chunk = options.numops / 2;
1973 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1976 chunk = MIN(chunk, options.numops / 2);
1978 /* mark this range as disabled */
1979 max = MIN(options.numops, base+chunk);
1980 for (i=base;i<max; i++) {
1981 op_parms[i].disabled = True;
1983 printf("Testing %d ops with %d-%d disabled\n",
1984 options.numops, base, max-1);
1986 printf("Completed %d of %d ops\n", ret, options.numops);
1987 for (i=base;i<max; i++) {
1988 op_parms[i].disabled = False;
1990 if (ret == options.numops) {
1991 /* this chunk is needed */
1993 } else if (ret < base) {
1994 printf("damn - inconsistent errors! found early error\n");
1995 options.numops = ret+1;
1998 /* it failed - this chunk isn't needed for a failure */
1999 memmove(&op_parms[base], &op_parms[max],
2000 sizeof(op_parms[0]) * (options.numops - max));
2001 options.numops = (ret+1) - (max - base);
2011 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2014 } while (chunk > 0);
2016 printf("Reduced to %d ops\n", options.numops);
2018 if (ret != options.numops - 1) {
2019 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2024 start the main gentest process
2026 static BOOL start_gentest(void)
2031 /* allocate the open_handles array */
2032 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2034 srandom(options.seed);
2035 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2037 /* generate the seeds - after this everything is deterministic */
2038 if (options.use_preset_seeds) {
2040 char **preset = file_lines_load(options.seeds_file, &numops);
2042 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2045 if (numops < options.numops) {
2046 options.numops = numops;
2048 for (op=0;op<options.numops;op++) {
2050 printf("Not enough seeds in %s\n", options.seeds_file);
2053 op_parms[op].seed = atoi(preset[op]);
2055 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2057 for (op=0; op<options.numops; op++) {
2058 op_parms[op].seed = random();
2064 if (ret != options.numops && options.analyze) {
2065 options.numops = ret+1;
2066 backtrack_analyze();
2067 } else if (options.analyze_always) {
2068 backtrack_analyze();
2069 } else if (options.analyze_continuous) {
2070 while (run_test() == options.numops) ;
2073 return ret == options.numops;
2077 static void usage(void)
2081 gentest2 //server1/share1 //server2/share2 [options..]\n\
2083 -U user%%pass (can be specified twice)\n\
2086 -a (show all ops)\n\
2087 -A backtrack to find minimal ops\n\
2088 -i FILE add a list of wildcard exclusions\n\
2089 -O enable oplocks\n\
2090 -S FILE set preset seeds file\n\
2091 -L use preset seeds\n\
2092 -F fast reconnect (just close files)\n\
2093 -C continuous analysis mode\n\
2094 -X analyse even when test OK\n\
2098 /****************************************************************************
2100 ****************************************************************************/
2101 int main(int argc, char *argv[])
2109 setup_logging("gentest", DEBUG_STDOUT);
2111 if (argc < 3 || argv[1][0] == '-') {
2116 setup_logging(argv[0], DEBUG_STDOUT);
2118 for (i=0;i<NSERVERS;i++) {
2119 const char *share = argv[1+i];
2120 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2121 printf("Invalid share name '%s'\n", share);
2129 lp_load(dyn_CONFIGFILE,True,False,False);
2132 options.seed = time(NULL);
2133 options.numops = 1000;
2134 options.max_open_handles = 20;
2135 options.seeds_file = "gentest_seeds.dat";
2137 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2140 i = servers[0].username?1:0;
2141 if (!split_username(optarg,
2142 &servers[i].username,
2143 &servers[i].password)) {
2144 printf("Must supply USER%%PASS\n");
2149 DEBUGLEVEL = atoi(optarg);
2150 setup_logging(NULL, DEBUG_STDOUT);
2153 options.seed = atoi(optarg);
2156 options.seeds_file = optarg;
2159 options.use_preset_seeds = True;
2162 options.fast_reconnect = True;
2165 options.numops = atoi(optarg);
2168 options.use_oplocks = True;
2171 options.showall = True;
2174 options.analyze = True;
2177 options.analyze_always = True;
2180 options.analyze_continuous = True;
2183 options.ignore_patterns = file_lines_load(optarg, NULL);
2189 printf("Unknown option %c (%d)\n", (char)opt, opt);
2194 gentest_init_subsystems;
2196 if (!servers[0].username) {
2200 if (!servers[1].username) {
2201 servers[1].username = servers[0].username;
2202 servers[1].password = servers[0].password;
2205 printf("seed=%u\n", options.seed);
2207 ret = start_gentest();
2210 printf("gentest completed - no errors\n");
2212 printf("gentest failed\n");