2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "system/time.h"
23 #include "system/filesys.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "librpc/gen_ndr/ndr_security.h"
27 #include "auth/gensec/gensec.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];
63 struct cli_credentials *credentials;
66 /* the seeds and flags for each operation */
73 /* oplock break info */
80 } oplocks[NSERVERS][NINSTANCES];
82 /* change notify reply info */
86 struct smb_notify notify;
87 } notifies[NSERVERS][NINSTANCES];
89 /* info relevant to the current operation */
100 #define BAD_HANDLE 0xFFFE
102 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
103 static void idle_func(struct smbcli_transport *transport, void *private);
106 check if a string should be ignored. This is used as the basis
107 for all error ignore settings
109 static BOOL ignore_pattern(const char *str)
112 if (!options.ignore_patterns) return False;
114 for (i=0;options.ignore_patterns[i];i++) {
115 if (strcmp(options.ignore_patterns[i], str) == 0 ||
116 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
117 DEBUG(2,("Ignoring '%s'\n", str));
124 /*****************************************************
125 connect to the servers
126 *******************************************************/
127 static BOOL connect_servers_fast(void)
131 /* close all open files */
132 for (h=0;h<options.max_open_handles;h++) {
133 if (!open_handles[h].active) continue;
134 for (i=0;i<NSERVERS;i++) {
135 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
136 open_handles[h].server_fnum[i])))) {
139 open_handles[h].active = False;
149 /*****************************************************
150 connect to the servers
151 *******************************************************/
152 static BOOL connect_servers(void)
156 if (options.fast_reconnect && servers[0].cli[0]) {
157 if (connect_servers_fast()) {
162 /* close any existing connections */
163 for (i=0;i<NSERVERS;i++) {
164 for (j=0;j<NINSTANCES;j++) {
165 if (servers[i].cli[j]) {
166 smbcli_tdis(servers[i].cli[j]);
167 talloc_free(servers[i].cli[j]);
168 servers[i].cli[j] = NULL;
173 for (i=0;i<NSERVERS;i++) {
174 for (j=0;j<NINSTANCES;j++) {
176 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
177 servers[i].server_name, servers[i].share_name,
178 servers[i].credentials->username, j);
180 cli_credentials_set_workstation(servers[i].credentials,
181 "gentest", CRED_SPECIFIED);
183 status = smbcli_full_connection(NULL, &servers[i].cli[j],
184 servers[i].server_name,
185 servers[i].share_name, NULL,
186 servers[i].credentials, NULL);
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;
711 static void oplock_handler_close_recv(struct smbcli_request *req)
714 status = smbcli_request_simple_recv(req);
715 if (!NT_STATUS_IS_OK(status)) {
716 printf("close failed in oplock_handler\n");
717 smb_panic("close failed in oplock_handler");
722 the oplock handler will either ack the break or close the file
724 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
730 struct smbcli_tree *tree = NULL;
731 struct smbcli_request *req;
733 srandom(current_op.seed);
734 do_close = gen_chance(50);
736 for (i=0;i<NSERVERS;i++) {
737 for (j=0;j<NINSTANCES;j++) {
738 if (transport == servers[i].cli[j]->transport &&
739 tid == servers[i].cli[j]->tree->tid) {
740 oplocks[i][j].got_break = True;
741 oplocks[i][j].fnum = fnum;
742 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
743 oplocks[i][j].level = level;
744 oplocks[i][j].do_close = do_close;
745 tree = servers[i].cli[j]->tree;
751 printf("Oplock break not for one of our trees!?\n");
756 printf("oplock ack fnum=%d\n", fnum);
757 return smbcli_oplock_ack(tree, fnum, level);
760 printf("oplock close fnum=%d\n", fnum);
762 io.close.level = RAW_CLOSE_CLOSE;
763 io.close.in.fnum = fnum;
764 io.close.in.write_time = 0;
765 req = smb_raw_close_send(tree, &io);
768 printf("WARNING: close failed in oplock_handler_close - %s\n",
773 req->async.fn = oplock_handler_close_recv;
774 req->async.private = NULL;
781 the idle function tries to cope with getting an oplock break on a connection, and
782 an operation on another connection blocking until that break is acked
783 we check for operations on all transports in the idle function
785 static void idle_func(struct smbcli_transport *transport, void *private)
788 for (i=0;i<NSERVERS;i++) {
789 for (j=0;j<NINSTANCES;j++) {
790 if (servers[i].cli[j] &&
791 transport != servers[i].cli[j]->transport) {
792 smbcli_transport_process(servers[i].cli[j]->transport);
801 compare NTSTATUS, using checking ignored patterns
803 static BOOL compare_status(NTSTATUS status1, NTSTATUS status2)
805 if (NT_STATUS_EQUAL(status1, status2)) return True;
807 /* one code being an error and the other OK is always an error */
808 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return False;
810 /* if we are ignoring one of the status codes then consider this a match */
811 if (ignore_pattern(nt_errstr(status1)) ||
812 ignore_pattern(nt_errstr(status2))) {
820 check for pending packets on all connections
822 static void check_pending(void)
828 for (j=0;j<NINSTANCES;j++) {
829 for (i=0;i<NSERVERS;i++) {
830 smbcli_transport_process(servers[i].cli[j]->transport);
836 check that the same oplock breaks have been received by all instances
838 static BOOL check_oplocks(const char *call)
846 for (j=0;j<NINSTANCES;j++) {
847 for (i=1;i<NSERVERS;i++) {
848 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
849 oplocks[0][j].handle != oplocks[i][j].handle ||
850 oplocks[0][j].level != oplocks[i][j].level) {
851 if (tries++ < 10) goto again;
852 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
853 oplocks[0][j].got_break,
854 oplocks[0][j].handle,
856 oplocks[i][j].got_break,
857 oplocks[i][j].handle,
858 oplocks[i][j].level);
864 /* if we got a break and closed then remove the handle */
865 for (j=0;j<NINSTANCES;j++) {
866 if (oplocks[0][j].got_break &&
867 oplocks[0][j].do_close) {
868 uint16_t fnums[NSERVERS];
869 for (i=0;i<NSERVERS;i++) {
870 fnums[i] = oplocks[i][j].fnum;
872 gen_remove_handle(j, fnums);
881 check that the same change notify info has been received by all instances
883 static BOOL check_notifies(const char *call)
891 for (j=0;j<NINSTANCES;j++) {
892 for (i=1;i<NSERVERS;i++) {
894 struct smb_notify not1, not2;
896 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
897 if (tries++ < 10) goto again;
898 printf("Notify count inconsistent %d %d\n",
899 notifies[0][j].notify_count,
900 notifies[i][j].notify_count);
904 if (notifies[0][j].notify_count == 0) continue;
906 if (!NT_STATUS_EQUAL(notifies[0][j].status,
907 notifies[i][j].status)) {
908 printf("Notify status mismatch - %s - %s\n",
909 nt_errstr(notifies[0][j].status),
910 nt_errstr(notifies[i][j].status));
914 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
918 not1 = notifies[0][j].notify;
919 not2 = notifies[i][j].notify;
921 for (n=0;n<not1.out.num_changes;n++) {
922 if (not1.out.changes[n].action !=
923 not2.out.changes[n].action) {
924 printf("Notify action %d inconsistent %d %d\n", n,
925 not1.out.changes[n].action,
926 not2.out.changes[n].action);
929 if (strcmp(not1.out.changes[n].name.s,
930 not2.out.changes[n].name.s)) {
931 printf("Notify name %d inconsistent %s %s\n", n,
932 not1.out.changes[n].name.s,
933 not2.out.changes[n].name.s);
936 if (not1.out.changes[n].name.private_length !=
937 not2.out.changes[n].name.private_length) {
938 printf("Notify name length %d inconsistent %d %d\n", n,
939 not1.out.changes[n].name.private_length,
940 not2.out.changes[n].name.private_length);
947 ZERO_STRUCT(notifies);
953 #define GEN_COPY_PARM do { \
955 for (i=1;i<NSERVERS;i++) { \
960 #define GEN_CALL(call) do { \
962 ZERO_STRUCT(oplocks); \
963 ZERO_STRUCT(notifies); \
964 for (i=0;i<NSERVERS;i++) { \
965 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
968 current_op.status = status[0]; \
969 for (i=1;i<NSERVERS;i++) { \
970 if (!compare_status(status[i], status[0])) { \
971 printf("status different in %s - %s %s\n", #call, \
972 nt_errstr(status[0]), nt_errstr(status[i])); \
976 if (!check_oplocks(#call)) return False; \
977 if (!check_notifies(#call)) return False; \
978 if (!NT_STATUS_IS_OK(status[0])) { \
983 #define ADD_HANDLE(name, field) do { \
984 uint16_t fnums[NSERVERS]; \
986 for (i=0;i<NSERVERS;i++) { \
987 fnums[i] = parm[i].field; \
989 gen_add_handle(instance, name, fnums); \
992 #define REMOVE_HANDLE(field) do { \
993 uint16_t fnums[NSERVERS]; \
995 for (i=0;i<NSERVERS;i++) { \
996 fnums[i] = parm[i].field; \
998 gen_remove_handle(instance, fnums); \
1001 #define GEN_SET_FNUM(field) do { \
1003 for (i=0;i<NSERVERS;i++) { \
1004 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
1008 #define CHECK_EQUAL(field) do { \
1009 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1010 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1011 (int)parm[0].field, (int)parm[1].field); \
1016 #define CHECK_WSTR_EQUAL(field) do { \
1017 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1018 printf("%s is NULL!\n", #field); \
1021 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1022 printf("Mismatch in %s - %s %s\n", #field, \
1023 parm[0].field.s, parm[1].field.s); \
1026 CHECK_EQUAL(field.private_length); \
1029 #define CHECK_BLOB_EQUAL(field) do { \
1030 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1031 printf("Mismatch in %s\n", #field); \
1034 CHECK_EQUAL(field.length); \
1037 #define CHECK_TIMES_EQUAL(field) do { \
1038 if (ABS(parm[0].field - parm[1].field) > time_skew() && \
1039 !ignore_pattern(#field)) { \
1040 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1041 (int)parm[0].field, (int)parm[1].field); \
1046 #define CHECK_NTTIMES_EQUAL(field) do { \
1047 if (ABS(nt_time_to_unix(parm[0].field) - \
1048 nt_time_to_unix(parm[1].field)) > time_skew() && \
1049 !ignore_pattern(#field)) { \
1050 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1051 (int)nt_time_to_unix(parm[0].field), \
1052 (int)nt_time_to_unix(parm[1].field)); \
1058 generate openx operations
1060 static BOOL handler_openx(int instance)
1062 union smb_open parm[NSERVERS];
1063 NTSTATUS status[NSERVERS];
1065 parm[0].openx.level = RAW_OPEN_OPENX;
1066 parm[0].openx.in.flags = gen_openx_flags();
1067 parm[0].openx.in.open_mode = gen_openx_mode();
1068 parm[0].openx.in.search_attrs = gen_attrib();
1069 parm[0].openx.in.file_attrs = gen_attrib();
1070 parm[0].openx.in.write_time = gen_timet();
1071 parm[0].openx.in.open_func = gen_openx_func();
1072 parm[0].openx.in.size = gen_io_count();
1073 parm[0].openx.in.timeout = gen_timeout();
1074 parm[0].openx.in.fname = gen_fname_open(instance);
1076 if (!options.use_oplocks) {
1077 /* mask out oplocks */
1078 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1079 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1083 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1085 CHECK_EQUAL(openx.out.attrib);
1086 CHECK_EQUAL(openx.out.size);
1087 CHECK_EQUAL(openx.out.access);
1088 CHECK_EQUAL(openx.out.ftype);
1089 CHECK_EQUAL(openx.out.devstate);
1090 CHECK_EQUAL(openx.out.action);
1091 CHECK_EQUAL(openx.out.access_mask);
1092 CHECK_EQUAL(openx.out.unknown);
1093 CHECK_TIMES_EQUAL(openx.out.write_time);
1095 /* open creates a new file handle */
1096 ADD_HANDLE(parm[0].openx.in.fname, openx.out.fnum);
1103 generate open operations
1105 static BOOL handler_open(int instance)
1107 union smb_open parm[NSERVERS];
1108 NTSTATUS status[NSERVERS];
1110 parm[0].openold.level = RAW_OPEN_OPEN;
1111 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1112 parm[0].openold.in.search_attrs = gen_attrib();
1113 parm[0].openold.in.fname = gen_fname_open(instance);
1115 if (!options.use_oplocks) {
1116 /* mask out oplocks */
1117 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1118 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1122 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1124 CHECK_EQUAL(openold.out.attrib);
1125 CHECK_TIMES_EQUAL(openold.out.write_time);
1126 CHECK_EQUAL(openold.out.size);
1127 CHECK_EQUAL(openold.out.rmode);
1129 /* open creates a new file handle */
1130 ADD_HANDLE(parm[0].openold.in.fname, openold.out.fnum);
1137 generate ntcreatex operations
1139 static BOOL handler_ntcreatex(int instance)
1141 union smb_open parm[NSERVERS];
1142 NTSTATUS status[NSERVERS];
1144 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1145 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1146 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1147 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1148 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1149 parm[0].ntcreatex.in.file_attr = gen_attrib();
1150 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1151 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1152 parm[0].ntcreatex.in.create_options = gen_create_options();
1153 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1154 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1155 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1157 if (!options.use_oplocks) {
1158 /* mask out oplocks */
1159 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1160 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1164 if (parm[0].ntcreatex.in.root_fid != 0) {
1165 GEN_SET_FNUM(ntcreatex.in.root_fid);
1167 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1169 CHECK_EQUAL(ntcreatex.out.oplock_level);
1170 CHECK_EQUAL(ntcreatex.out.create_action);
1171 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1172 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1173 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1174 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1175 CHECK_EQUAL(ntcreatex.out.attrib);
1176 CHECK_EQUAL(ntcreatex.out.alloc_size);
1177 CHECK_EQUAL(ntcreatex.out.size);
1178 CHECK_EQUAL(ntcreatex.out.file_type);
1179 CHECK_EQUAL(ntcreatex.out.ipc_state);
1180 CHECK_EQUAL(ntcreatex.out.is_directory);
1182 /* ntcreatex creates a new file handle */
1183 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.fnum);
1189 generate close operations
1191 static BOOL handler_close(int instance)
1193 union smb_close parm[NSERVERS];
1194 NTSTATUS status[NSERVERS];
1196 parm[0].close.level = RAW_CLOSE_CLOSE;
1197 parm[0].close.in.fnum = gen_fnum_close(instance);
1198 parm[0].close.in.write_time = gen_timet();
1201 GEN_SET_FNUM(close.in.fnum);
1202 GEN_CALL(smb_raw_close(tree, &parm[i]));
1204 REMOVE_HANDLE(close.in.fnum);
1210 generate unlink operations
1212 static BOOL handler_unlink(int instance)
1214 struct smb_unlink parm[NSERVERS];
1215 NTSTATUS status[NSERVERS];
1217 parm[0].in.pattern = gen_pattern();
1218 parm[0].in.attrib = gen_attrib();
1221 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1227 generate chkpath operations
1229 static BOOL handler_chkpath(int instance)
1231 struct smb_chkpath parm[NSERVERS];
1232 NTSTATUS status[NSERVERS];
1234 parm[0].in.path = gen_fname_open(instance);
1237 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1243 generate mkdir operations
1245 static BOOL handler_mkdir(int instance)
1247 union smb_mkdir parm[NSERVERS];
1248 NTSTATUS status[NSERVERS];
1250 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1251 parm[0].mkdir.in.path = gen_fname_open(instance);
1254 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1260 generate rmdir operations
1262 static BOOL handler_rmdir(int instance)
1264 struct smb_rmdir parm[NSERVERS];
1265 NTSTATUS status[NSERVERS];
1267 parm[0].in.path = gen_fname_open(instance);
1270 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1276 generate rename operations
1278 static BOOL handler_rename(int instance)
1280 union smb_rename parm[NSERVERS];
1281 NTSTATUS status[NSERVERS];
1283 parm[0].generic.level = RAW_RENAME_RENAME;
1284 parm[0].rename.in.pattern1 = gen_pattern();
1285 parm[0].rename.in.pattern2 = gen_pattern();
1286 parm[0].rename.in.attrib = gen_attrib();
1289 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1295 generate ntrename operations
1297 static BOOL handler_ntrename(int instance)
1299 union smb_rename parm[NSERVERS];
1300 NTSTATUS status[NSERVERS];
1302 parm[0].generic.level = RAW_RENAME_NTRENAME;
1303 parm[0].ntrename.in.old_name = gen_fname();
1304 parm[0].ntrename.in.new_name = gen_fname();
1305 parm[0].ntrename.in.attrib = gen_attrib();
1306 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1307 parm[0].ntrename.in.flags = gen_rename_flags();
1310 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1317 generate seek operations
1319 static BOOL handler_seek(int instance)
1321 struct smb_seek parm[NSERVERS];
1322 NTSTATUS status[NSERVERS];
1324 parm[0].in.fnum = gen_fnum(instance);
1325 parm[0].in.mode = gen_bits_mask2(0x3, 0xFFFF);
1326 parm[0].in.offset = gen_offset();
1329 GEN_SET_FNUM(in.fnum);
1330 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1332 CHECK_EQUAL(out.offset);
1339 generate readx operations
1341 static BOOL handler_readx(int instance)
1343 union smb_read parm[NSERVERS];
1344 NTSTATUS status[NSERVERS];
1346 parm[0].readx.level = RAW_READ_READX;
1347 parm[0].readx.in.fnum = gen_fnum(instance);
1348 parm[0].readx.in.offset = gen_offset();
1349 parm[0].readx.in.mincnt = gen_io_count();
1350 parm[0].readx.in.maxcnt = gen_io_count();
1351 parm[0].readx.in.remaining = gen_io_count();
1352 parm[0].readx.out.data = talloc_size(current_op.mem_ctx,
1353 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1356 GEN_SET_FNUM(readx.in.fnum);
1357 GEN_CALL(smb_raw_read(tree, &parm[i]));
1359 CHECK_EQUAL(readx.out.remaining);
1360 CHECK_EQUAL(readx.out.compaction_mode);
1361 CHECK_EQUAL(readx.out.nread);
1367 generate writex operations
1369 static BOOL handler_writex(int instance)
1371 union smb_write parm[NSERVERS];
1372 NTSTATUS status[NSERVERS];
1374 parm[0].writex.level = RAW_WRITE_WRITEX;
1375 parm[0].writex.in.fnum = gen_fnum(instance);
1376 parm[0].writex.in.offset = gen_offset();
1377 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1378 parm[0].writex.in.remaining = gen_io_count();
1379 parm[0].writex.in.count = gen_io_count();
1380 parm[0].writex.in.data = talloc_zero_size(current_op.mem_ctx, parm[0].writex.in.count);
1383 GEN_SET_FNUM(writex.in.fnum);
1384 GEN_CALL(smb_raw_write(tree, &parm[i]));
1386 CHECK_EQUAL(writex.out.nwritten);
1387 CHECK_EQUAL(writex.out.remaining);
1393 generate lockingx operations
1395 static BOOL handler_lockingx(int instance)
1397 union smb_lock parm[NSERVERS];
1398 NTSTATUS status[NSERVERS];
1401 parm[0].lockx.level = RAW_LOCK_LOCKX;
1402 parm[0].lockx.in.fnum = gen_fnum(instance);
1403 parm[0].lockx.in.mode = gen_lock_mode();
1404 parm[0].lockx.in.timeout = gen_timeout();
1406 /* make sure we don't accidentially generate an oplock
1407 break ack - otherwise the server can just block forever */
1408 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1409 parm[0].lockx.in.lock_cnt = gen_lock_count();
1410 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1411 } while (nlocks == 0);
1414 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1415 struct smb_lock_entry,
1417 for (n=0;n<nlocks;n++) {
1418 parm[0].lockx.in.locks[n].pid = gen_pid();
1419 parm[0].lockx.in.locks[n].offset = gen_offset();
1420 parm[0].lockx.in.locks[n].count = gen_io_count();
1425 GEN_SET_FNUM(lockx.in.fnum);
1426 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1432 generate a fileinfo query structure
1434 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1437 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1439 enum smb_fileinfo_level level;
1442 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1443 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1444 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1445 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1446 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1447 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1448 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1449 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1450 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1451 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1454 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1455 } while (ignore_pattern(levels[i].name));
1457 info->generic.level = levels[i].level;
1461 compare returned fileinfo structures
1463 static BOOL cmp_fileinfo(int instance,
1464 union smb_fileinfo parm[NSERVERS],
1465 NTSTATUS status[NSERVERS])
1469 switch (parm[0].generic.level) {
1470 case RAW_FILEINFO_GENERIC:
1473 case RAW_FILEINFO_GETATTR:
1474 CHECK_EQUAL(getattr.out.attrib);
1475 CHECK_EQUAL(getattr.out.size);
1476 CHECK_TIMES_EQUAL(getattr.out.write_time);
1479 case RAW_FILEINFO_GETATTRE:
1480 CHECK_TIMES_EQUAL(getattre.out.create_time);
1481 CHECK_TIMES_EQUAL(getattre.out.access_time);
1482 CHECK_TIMES_EQUAL(getattre.out.write_time);
1483 CHECK_EQUAL(getattre.out.size);
1484 CHECK_EQUAL(getattre.out.alloc_size);
1485 CHECK_EQUAL(getattre.out.attrib);
1488 case RAW_FILEINFO_STANDARD:
1489 CHECK_TIMES_EQUAL(standard.out.create_time);
1490 CHECK_TIMES_EQUAL(standard.out.access_time);
1491 CHECK_TIMES_EQUAL(standard.out.write_time);
1492 CHECK_EQUAL(standard.out.size);
1493 CHECK_EQUAL(standard.out.alloc_size);
1494 CHECK_EQUAL(standard.out.attrib);
1497 case RAW_FILEINFO_EA_SIZE:
1498 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1499 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1500 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1501 CHECK_EQUAL(ea_size.out.size);
1502 CHECK_EQUAL(ea_size.out.alloc_size);
1503 CHECK_EQUAL(ea_size.out.attrib);
1504 CHECK_EQUAL(ea_size.out.ea_size);
1507 case RAW_FILEINFO_ALL_EAS:
1508 CHECK_EQUAL(all_eas.out.num_eas);
1509 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1510 CHECK_EQUAL(all_eas.out.eas[i].flags);
1511 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1512 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1516 case RAW_FILEINFO_IS_NAME_VALID:
1519 case RAW_FILEINFO_BASIC_INFO:
1520 case RAW_FILEINFO_BASIC_INFORMATION:
1521 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1522 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1523 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1524 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1525 CHECK_EQUAL(basic_info.out.attrib);
1528 case RAW_FILEINFO_STANDARD_INFO:
1529 case RAW_FILEINFO_STANDARD_INFORMATION:
1530 CHECK_EQUAL(standard_info.out.alloc_size);
1531 CHECK_EQUAL(standard_info.out.size);
1532 CHECK_EQUAL(standard_info.out.nlink);
1533 CHECK_EQUAL(standard_info.out.delete_pending);
1534 CHECK_EQUAL(standard_info.out.directory);
1537 case RAW_FILEINFO_EA_INFO:
1538 case RAW_FILEINFO_EA_INFORMATION:
1539 CHECK_EQUAL(ea_info.out.ea_size);
1542 case RAW_FILEINFO_NAME_INFO:
1543 case RAW_FILEINFO_NAME_INFORMATION:
1544 CHECK_WSTR_EQUAL(name_info.out.fname);
1547 case RAW_FILEINFO_ALL_INFO:
1548 case RAW_FILEINFO_ALL_INFORMATION:
1549 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1550 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1551 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1552 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1553 CHECK_EQUAL(all_info.out.attrib);
1554 CHECK_EQUAL(all_info.out.alloc_size);
1555 CHECK_EQUAL(all_info.out.size);
1556 CHECK_EQUAL(all_info.out.nlink);
1557 CHECK_EQUAL(all_info.out.delete_pending);
1558 CHECK_EQUAL(all_info.out.directory);
1559 CHECK_EQUAL(all_info.out.ea_size);
1560 CHECK_WSTR_EQUAL(all_info.out.fname);
1563 case RAW_FILEINFO_ALT_NAME_INFO:
1564 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1565 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1568 case RAW_FILEINFO_STREAM_INFO:
1569 case RAW_FILEINFO_STREAM_INFORMATION:
1570 CHECK_EQUAL(stream_info.out.num_streams);
1571 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1572 CHECK_EQUAL(stream_info.out.streams[i].size);
1573 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1574 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1578 case RAW_FILEINFO_COMPRESSION_INFO:
1579 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1580 CHECK_EQUAL(compression_info.out.compressed_size);
1581 CHECK_EQUAL(compression_info.out.format);
1582 CHECK_EQUAL(compression_info.out.unit_shift);
1583 CHECK_EQUAL(compression_info.out.chunk_shift);
1584 CHECK_EQUAL(compression_info.out.cluster_shift);
1587 case RAW_FILEINFO_INTERNAL_INFORMATION:
1588 CHECK_EQUAL(internal_information.out.file_id);
1591 case RAW_FILEINFO_ACCESS_INFORMATION:
1592 CHECK_EQUAL(access_information.out.access_flags);
1595 case RAW_FILEINFO_POSITION_INFORMATION:
1596 CHECK_EQUAL(position_information.out.position);
1599 case RAW_FILEINFO_MODE_INFORMATION:
1600 CHECK_EQUAL(mode_information.out.mode);
1603 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1604 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1607 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1608 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1609 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1610 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1611 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1612 CHECK_EQUAL(network_open_information.out.alloc_size);
1613 CHECK_EQUAL(network_open_information.out.size);
1614 CHECK_EQUAL(network_open_information.out.attrib);
1617 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1618 CHECK_EQUAL(attribute_tag_information.out.attrib);
1619 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1622 /* Unhandled levels */
1624 case RAW_FILEINFO_SEC_DESC:
1625 case RAW_FILEINFO_EA_LIST:
1626 case RAW_FILEINFO_UNIX_BASIC:
1627 case RAW_FILEINFO_UNIX_LINK:
1635 generate qpathinfo operations
1637 static BOOL handler_qpathinfo(int instance)
1639 union smb_fileinfo parm[NSERVERS];
1640 NTSTATUS status[NSERVERS];
1642 parm[0].generic.in.fname = gen_fname_open(instance);
1644 gen_fileinfo(instance, &parm[0]);
1647 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1649 return cmp_fileinfo(instance, parm, status);
1653 generate qfileinfo operations
1655 static BOOL handler_qfileinfo(int instance)
1657 union smb_fileinfo parm[NSERVERS];
1658 NTSTATUS status[NSERVERS];
1660 parm[0].generic.in.fnum = gen_fnum(instance);
1662 gen_fileinfo(instance, &parm[0]);
1665 GEN_SET_FNUM(generic.in.fnum);
1666 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1668 return cmp_fileinfo(instance, parm, status);
1673 generate a fileinfo query structure
1675 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1679 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1681 enum smb_setfileinfo_level level;
1685 /* disabled until win2003 can handle them ... */
1686 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1687 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1689 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1690 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1691 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1692 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1693 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1696 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1697 } while (ignore_pattern(levels[i].name));
1699 info->generic.level = levels[i].level;
1701 switch (info->generic.level) {
1702 case RAW_SFILEINFO_SETATTR:
1703 info->setattr.in.attrib = gen_attrib();
1704 info->setattr.in.write_time = gen_timet();
1706 case RAW_SFILEINFO_SETATTRE:
1707 info->setattre.in.create_time = gen_timet();
1708 info->setattre.in.access_time = gen_timet();
1709 info->setattre.in.write_time = gen_timet();
1711 case RAW_SFILEINFO_STANDARD:
1712 info->standard.in.create_time = gen_timet();
1713 info->standard.in.access_time = gen_timet();
1714 info->standard.in.write_time = gen_timet();
1716 case RAW_SFILEINFO_EA_SET: {
1717 static struct ea_struct ea;
1718 info->ea_set.in.num_eas = 1;
1719 info->ea_set.in.eas = &ea;
1720 info->ea_set.in.eas[0] = gen_ea_struct();
1723 case RAW_SFILEINFO_BASIC_INFO:
1724 case RAW_SFILEINFO_BASIC_INFORMATION:
1725 info->basic_info.in.create_time = gen_nttime();
1726 info->basic_info.in.access_time = gen_nttime();
1727 info->basic_info.in.write_time = gen_nttime();
1728 info->basic_info.in.change_time = gen_nttime();
1729 info->basic_info.in.attrib = gen_attrib();
1731 case RAW_SFILEINFO_DISPOSITION_INFO:
1732 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1733 info->disposition_info.in.delete_on_close = gen_bool();
1735 case RAW_SFILEINFO_ALLOCATION_INFO:
1736 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1737 info->allocation_info.in.alloc_size = gen_alloc_size();
1739 case RAW_SFILEINFO_END_OF_FILE_INFO:
1740 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1741 info->end_of_file_info.in.size = gen_offset();
1743 case RAW_SFILEINFO_RENAME_INFORMATION:
1744 info->rename_information.in.overwrite = gen_bool();
1745 info->rename_information.in.root_fid = gen_root_fid(instance);
1746 info->rename_information.in.new_name = gen_fname_open(instance);
1748 case RAW_SFILEINFO_POSITION_INFORMATION:
1749 info->position_information.in.position = gen_offset();
1751 case RAW_SFILEINFO_MODE_INFORMATION:
1752 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1754 case RAW_SFILEINFO_GENERIC:
1755 case RAW_SFILEINFO_SEC_DESC:
1756 case RAW_SFILEINFO_UNIX_BASIC:
1757 case RAW_SFILEINFO_UNIX_LINK:
1758 case RAW_SFILEINFO_UNIX_HLINK:
1759 case RAW_SFILEINFO_1023:
1760 case RAW_SFILEINFO_1025:
1761 case RAW_SFILEINFO_1029:
1762 case RAW_SFILEINFO_1032:
1763 case RAW_SFILEINFO_1039:
1764 case RAW_SFILEINFO_1040:
1771 generate setpathinfo operations
1773 static BOOL handler_spathinfo(int instance)
1775 union smb_setfileinfo parm[NSERVERS];
1776 NTSTATUS status[NSERVERS];
1778 parm[0].generic.file.fname = gen_fname_open(instance);
1780 gen_setfileinfo(instance, &parm[0]);
1784 /* a special case for the fid in a RENAME */
1785 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1786 parm[0].rename_information.in.root_fid != 0) {
1787 GEN_SET_FNUM(rename_information.in.root_fid);
1790 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1797 generate setfileinfo operations
1799 static BOOL handler_sfileinfo(int instance)
1801 union smb_setfileinfo parm[NSERVERS];
1802 NTSTATUS status[NSERVERS];
1804 parm[0].generic.file.fnum = gen_fnum(instance);
1806 gen_setfileinfo(instance, &parm[0]);
1809 GEN_SET_FNUM(generic.file.fnum);
1810 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1817 generate change notify operations
1819 static BOOL handler_notify(int instance)
1821 struct smb_notify parm[NSERVERS];
1824 parm[0].in.buffer_size = gen_io_count();
1825 parm[0].in.completion_filter = gen_bits_mask(0xFF);
1826 parm[0].in.fnum = gen_fnum(instance);
1827 parm[0].in.recursive = gen_bool();
1830 GEN_SET_FNUM(in.fnum);
1832 for (n=0;n<NSERVERS;n++) {
1833 struct smbcli_request *req;
1834 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1835 req->async.fn = async_notify;
1842 wipe any relevant files
1844 static void wipe_files(void)
1847 for (i=0;i<NSERVERS;i++) {
1848 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1850 printf("Failed to wipe tree on server %d\n", i);
1853 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1854 printf("Failed to create \\gentest - %s\n",
1855 smbcli_errstr(servers[i].cli[0]->tree));
1859 printf("Deleted %d files on server %d\n", n, i);
1865 dump the current seeds - useful for continuing a backtrack
1867 static void dump_seeds(void)
1872 if (!options.seeds_file) {
1875 f = fopen("seeds.tmp", "w");
1878 for (i=0;i<options.numops;i++) {
1879 fprintf(f, "%u\n", op_parms[i].seed);
1882 rename("seeds.tmp", options.seeds_file);
1888 the list of top-level operations that we will generate
1892 BOOL (*handler)(int instance);
1893 int count, success_count;
1895 {"OPEN", handler_open},
1896 {"OPENX", handler_openx},
1897 {"NTCREATEX", handler_ntcreatex},
1898 {"CLOSE", handler_close},
1899 {"UNLINK", handler_unlink},
1900 {"MKDIR", handler_mkdir},
1901 {"RMDIR", handler_rmdir},
1902 {"RENAME", handler_rename},
1903 {"NTRENAME", handler_ntrename},
1904 {"READX", handler_readx},
1905 {"WRITEX", handler_writex},
1906 {"CHKPATH", handler_chkpath},
1907 {"LOCKINGX", handler_lockingx},
1908 {"QPATHINFO", handler_qpathinfo},
1909 {"QFILEINFO", handler_qfileinfo},
1910 {"SPATHINFO", handler_spathinfo},
1911 {"SFILEINFO", handler_sfileinfo},
1912 {"NOTIFY", handler_notify},
1913 {"SEEK", handler_seek},
1918 run the test with the current set of op_parms parameters
1919 return the number of operations that completed successfully
1921 static int run_test(void)
1925 if (!connect_servers()) {
1926 printf("Failed to connect to servers\n");
1932 /* wipe any leftover files from old runs */
1935 /* reset the open handles array */
1936 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1937 num_open_handles = 0;
1939 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1940 gen_ops[i].count = 0;
1941 gen_ops[i].success_count = 0;
1944 for (op=0; op<options.numops; op++) {
1945 int instance, which_op;
1948 if (op_parms[op].disabled) continue;
1950 srandom(op_parms[op].seed);
1952 instance = gen_int_range(0, NINSTANCES-1);
1954 /* generate a non-ignored operation */
1956 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1957 } while (ignore_pattern(gen_ops[which_op].name));
1959 DEBUG(3,("Generating op %s on instance %d\n",
1960 gen_ops[which_op].name, instance));
1962 current_op.seed = op_parms[op].seed;
1963 current_op.opnum = op;
1964 current_op.name = gen_ops[which_op].name;
1965 current_op.status = NT_STATUS_OK;
1966 current_op.mem_ctx = talloc_init("%s", current_op.name);
1968 ret = gen_ops[which_op].handler(instance);
1970 talloc_free(current_op.mem_ctx);
1972 gen_ops[which_op].count++;
1973 if (NT_STATUS_IS_OK(current_op.status)) {
1974 gen_ops[which_op].success_count++;
1978 printf("Failed at operation %d - %s\n",
1979 op, gen_ops[which_op].name);
1983 if (op % 100 == 0) {
1988 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1989 printf("Op %-10s got %d/%d success\n",
1991 gen_ops[i].success_count,
1999 perform a backtracking analysis of the minimal set of operations
2000 to generate an error
2002 static void backtrack_analyze(void)
2006 chunk = options.numops / 2;
2011 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2014 chunk = MIN(chunk, options.numops / 2);
2016 /* mark this range as disabled */
2017 max = MIN(options.numops, base+chunk);
2018 for (i=base;i<max; i++) {
2019 op_parms[i].disabled = True;
2021 printf("Testing %d ops with %d-%d disabled\n",
2022 options.numops, base, max-1);
2024 printf("Completed %d of %d ops\n", ret, options.numops);
2025 for (i=base;i<max; i++) {
2026 op_parms[i].disabled = False;
2028 if (ret == options.numops) {
2029 /* this chunk is needed */
2031 } else if (ret < base) {
2032 printf("damn - inconsistent errors! found early error\n");
2033 options.numops = ret+1;
2036 /* it failed - this chunk isn't needed for a failure */
2037 memmove(&op_parms[base], &op_parms[max],
2038 sizeof(op_parms[0]) * (options.numops - max));
2039 options.numops = (ret+1) - (max - base);
2049 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2052 } while (chunk > 0);
2054 printf("Reduced to %d ops\n", options.numops);
2056 if (ret != options.numops - 1) {
2057 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2062 start the main gentest process
2064 static BOOL start_gentest(void)
2069 /* allocate the open_handles array */
2070 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2072 srandom(options.seed);
2073 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2075 /* generate the seeds - after this everything is deterministic */
2076 if (options.use_preset_seeds) {
2078 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
2080 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2083 if (numops < options.numops) {
2084 options.numops = numops;
2086 for (op=0;op<options.numops;op++) {
2088 printf("Not enough seeds in %s\n", options.seeds_file);
2091 op_parms[op].seed = atoi(preset[op]);
2093 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2095 for (op=0; op<options.numops; op++) {
2096 op_parms[op].seed = random();
2102 if (ret != options.numops && options.analyze) {
2103 options.numops = ret+1;
2104 backtrack_analyze();
2105 } else if (options.analyze_always) {
2106 backtrack_analyze();
2107 } else if (options.analyze_continuous) {
2108 while (run_test() == options.numops) ;
2111 return ret == options.numops;
2115 static void usage(void)
2119 gentest2 //server1/share1 //server2/share2 [options..]\n\
2121 -U user%%pass (can be specified twice)\n\
2124 -a (show all ops)\n\
2125 -A backtrack to find minimal ops\n\
2126 -i FILE add a list of wildcard exclusions\n\
2127 -O enable oplocks\n\
2128 -S FILE set preset seeds file\n\
2129 -L use preset seeds\n\
2130 -F fast reconnect (just close files)\n\
2131 -C continuous analysis mode\n\
2132 -X analyse even when test OK\n\
2136 /****************************************************************************
2138 ****************************************************************************/
2139 int main(int argc, char *argv[])
2142 int i, username_count=0;
2147 setup_logging("gentest", DEBUG_STDOUT);
2149 if (argc < 3 || argv[1][0] == '-') {
2154 setup_logging(argv[0], DEBUG_STDOUT);
2156 for (i=0;i<NSERVERS;i++) {
2157 const char *share = argv[1+i];
2158 servers[i].credentials = cli_credentials_init(NULL);
2159 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2160 printf("Invalid share name '%s'\n", share);
2170 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
2171 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
2172 cli_credentials_guess(servers[0].credentials);
2173 cli_credentials_guess(servers[1].credentials);
2175 options.seed = time(NULL);
2176 options.numops = 1000;
2177 options.max_open_handles = 20;
2178 options.seeds_file = "gentest_seeds.dat";
2180 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2183 if (username_count == 2) {
2187 cli_credentials_parse_string(servers[username_count].credentials,
2188 optarg, CRED_SPECIFIED);
2192 DEBUGLEVEL = atoi(optarg);
2193 setup_logging(NULL, DEBUG_STDOUT);
2196 options.seed = atoi(optarg);
2199 options.seeds_file = optarg;
2202 options.use_preset_seeds = True;
2205 options.fast_reconnect = True;
2208 options.numops = atoi(optarg);
2211 options.use_oplocks = True;
2214 options.showall = True;
2217 options.analyze = True;
2220 options.analyze_always = True;
2223 options.analyze_continuous = True;
2226 options.ignore_patterns = file_lines_load(optarg, NULL, NULL);
2232 printf("Unknown option %c (%d)\n", (char)opt, opt);
2239 if (username_count == 0) {
2243 if (username_count == 1) {
2244 servers[1].credentials = servers[0].credentials;
2247 printf("seed=%u\n", options.seed);
2249 ret = start_gentest();
2252 printf("gentest completed - no errors\n");
2254 printf("gentest failed\n");