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"
32 static struct gentest_options {
36 BOOL analyze_continuous;
37 uint_t max_open_handles;
41 char **ignore_patterns;
42 const char *seeds_file;
43 BOOL use_preset_seeds;
47 /* mapping between open handles on the server and local handles */
51 uint_t server_fnum[NSERVERS];
54 static uint_t num_open_handles;
56 /* state information for the servers. We open NINSTANCES connections to
59 struct smbcli_state *cli[NINSTANCES];
62 struct cli_credentials *credentials;
65 /* the seeds and flags for each operation */
72 /* oplock break info */
79 } oplocks[NSERVERS][NINSTANCES];
81 /* change notify reply info */
85 struct smb_notify notify;
86 } notifies[NSERVERS][NINSTANCES];
88 /* info relevant to the current operation */
99 #define BAD_HANDLE 0xFFFE
101 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
102 static void idle_func(struct smbcli_transport *transport, void *private);
105 check if a string should be ignored. This is used as the basis
106 for all error ignore settings
108 static BOOL ignore_pattern(const char *str)
111 if (!options.ignore_patterns) return False;
113 for (i=0;options.ignore_patterns[i];i++) {
114 if (strcmp(options.ignore_patterns[i], str) == 0 ||
115 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
116 DEBUG(2,("Ignoring '%s'\n", str));
123 /*****************************************************
124 connect to the servers
125 *******************************************************/
126 static BOOL connect_servers_fast(void)
130 /* close all open files */
131 for (h=0;h<options.max_open_handles;h++) {
132 if (!open_handles[h].active) continue;
133 for (i=0;i<NSERVERS;i++) {
134 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
135 open_handles[h].server_fnum[i])))) {
138 open_handles[h].active = False;
148 /*****************************************************
149 connect to the servers
150 *******************************************************/
151 static BOOL connect_servers(void)
155 if (options.fast_reconnect && servers[0].cli[0]) {
156 if (connect_servers_fast()) {
161 /* close any existing connections */
162 for (i=0;i<NSERVERS;i++) {
163 for (j=0;j<NINSTANCES;j++) {
164 if (servers[i].cli[j]) {
165 smbcli_tdis(servers[i].cli[j]);
166 talloc_free(servers[i].cli[j]);
167 servers[i].cli[j] = NULL;
172 for (i=0;i<NSERVERS;i++) {
173 for (j=0;j<NINSTANCES;j++) {
175 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
176 servers[i].server_name, servers[i].share_name,
177 servers[i].credentials->username, j);
179 cli_credentials_set_workstation(servers[i].credentials,
180 "gentest", CRED_SPECIFIED);
182 status = smbcli_full_connection(NULL, &servers[i].cli[j],
183 servers[i].server_name,
184 servers[i].share_name, NULL,
185 servers[i].credentials, NULL);
186 if (!NT_STATUS_IS_OK(status)) {
187 printf("Failed to connect to \\\\%s\\%s - %s\n",
188 servers[i].server_name, servers[i].share_name,
193 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
194 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
202 work out the time skew between the servers - be conservative
204 static uint_t time_skew(void)
207 ret = ABS(servers[0].cli[0]->transport->negotiate.server_time -
208 servers[1].cli[0]->transport->negotiate.server_time);
213 turn an fnum for an instance into a handle
215 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
218 for (i=0;i<options.max_open_handles;i++) {
219 if (!open_handles[i].active ||
220 instance != open_handles[i].instance) continue;
221 if (open_handles[i].server_fnum[server] == fnum) {
225 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
226 fnum, server, instance);
231 add some newly opened handles
233 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
236 for (h=0;h<options.max_open_handles;h++) {
237 if (!open_handles[h].active) break;
239 if (h == options.max_open_handles) {
240 /* we have to force close a random handle */
241 h = random() % options.max_open_handles;
242 for (i=0;i<NSERVERS;i++) {
243 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
244 open_handles[h].server_fnum[i])))) {
245 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
246 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
249 printf("Recovered handle %d\n", h);
252 for (i=0;i<NSERVERS;i++) {
253 open_handles[h].server_fnum[i] = fnums[i];
254 open_handles[h].instance = instance;
255 open_handles[h].active = True;
256 open_handles[h].name = name;
260 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
262 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
267 remove a closed handle
269 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
272 for (h=0;h<options.max_open_handles;h++) {
273 if (instance == open_handles[h].instance &&
274 open_handles[h].server_fnum[0] == fnums[0]) {
275 open_handles[h].active = False;
277 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
279 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
280 open_handles[h].name);
284 printf("Removing invalid handle!?\n");
289 return True with 'chance' probability as a percentage
291 static BOOL gen_chance(uint_t chance)
293 return ((random() % 100) <= chance);
297 map an internal handle number to a server fnum
299 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
301 if (handle == BAD_HANDLE) return handle;
302 return open_handles[handle].server_fnum[server];
308 static uint16_t gen_fnum(int instance)
313 if (gen_chance(20)) return BAD_HANDLE;
315 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
316 h = random() % options.max_open_handles;
317 if (open_handles[h].active &&
318 open_handles[h].instance == instance) {
326 return a file handle, but skewed so we don't close the last
327 couple of handles too readily
329 static uint16_t gen_fnum_close(int instance)
331 if (num_open_handles < 3) {
332 if (gen_chance(80)) return BAD_HANDLE;
335 return gen_fnum(instance);
339 generate an integer in a specified range
341 static int gen_int_range(uint_t min, uint_t max)
344 return min + (r % (1+max-min));
348 return a fnum for use as a root fid
349 be careful to call GEN_SET_FNUM() when you use this!
351 static uint16_t gen_root_fid(int instance)
353 if (gen_chance(5)) return gen_fnum(instance);
358 generate a file offset
360 static int gen_offset(void)
362 if (gen_chance(20)) return 0;
363 return gen_int_range(0, 1024*1024);
369 static int gen_io_count(void)
371 if (gen_chance(20)) return 0;
372 return gen_int_range(0, 4096);
378 static const char *gen_fname(void)
380 const char *names[] = {"\\gentest\\gentest.dat",
382 "\\gentest\\foo2.sym",
383 "\\gentest\\foo3.dll",
385 "\\gentest\\foo4:teststream1",
386 "\\gentest\\foo4:teststream2",
387 "\\gentest\\foo5.exe",
388 "\\gentest\\foo5.exe:teststream3",
389 "\\gentest\\foo5.exe:teststream4",
390 "\\gentest\\foo6.com",
392 "\\gentest\\blah\\blergh.txt",
393 "\\gentest\\blah\\blergh2",
394 "\\gentest\\blah\\blergh3.txt",
395 "\\gentest\\blah\\blergh4",
396 "\\gentest\\blah\\blergh5.txt",
397 "\\gentest\\blah\\blergh5",
398 "\\gentest\\blah\\.",
400 /* this causes problem with w2k3 */
401 "\\gentest\\blah\\..",
403 "\\gentest\\a_very_long_name.bin",
409 i = gen_int_range(0, ARRAY_SIZE(names)-1);
410 } while (ignore_pattern(names[i]));
416 generate a filename with a higher chance of choosing an already
419 static const char *gen_fname_open(int instance)
422 h = gen_fnum(instance);
423 if (h == BAD_HANDLE) {
426 return open_handles[h].name;
430 generate a wildcard pattern
432 static const char *gen_pattern(void)
435 const char *names[] = {"\\gentest\\*.dat",
438 "\\gentest\\blah\\*.*",
439 "\\gentest\\blah\\*",
442 if (gen_chance(50)) return gen_fname();
445 i = gen_int_range(0, ARRAY_SIZE(names)-1);
446 } while (ignore_pattern(names[i]));
454 static uint32_t gen_bits_mask(uint_t mask)
456 uint_t ret = random();
461 generate a bitmask with high probability of the first mask
462 and low of the second
464 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
466 if (gen_chance(10)) return gen_bits_mask(mask2);
467 return gen_bits_mask(mask1);
473 static BOOL gen_bool(void)
475 return gen_bits_mask2(0x1, 0xFF);
479 generate ntrename flags
481 static uint16_t gen_rename_flags(void)
483 if (gen_chance(30)) return RENAME_FLAG_RENAME;
484 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
485 if (gen_chance(30)) return RENAME_FLAG_COPY;
486 return gen_bits_mask(0xFFFF);
491 return a lockingx lock mode
493 static uint16_t gen_lock_mode(void)
495 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
496 if (gen_chance(20)) return gen_bits_mask(0x1F);
497 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
503 static uint16_t gen_pid(void)
505 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
510 generate a lock count
512 static off_t gen_lock_count(void)
514 return gen_int_range(0, 3);
518 generate a ntcreatex flags field
520 static uint32_t gen_ntcreatex_flags(void)
522 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
523 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
527 generate a NT access mask
529 static uint32_t gen_access_mask(void)
531 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
532 if (gen_chance(20)) return SEC_FILE_ALL;
533 return gen_bits_mask(0xFFFFFFFF);
537 generate a ntcreatex create options bitfield
539 static uint32_t gen_create_options(void)
541 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
542 if (gen_chance(50)) return 0;
543 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
547 generate a ntcreatex open disposition
549 static uint32_t gen_open_disp(void)
551 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
552 return gen_int_range(0, 5);
556 generate an openx open mode
558 static uint16_t gen_openx_mode(void)
560 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
561 if (gen_chance(20)) return gen_bits_mask(0xFF);
562 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
566 generate an openx flags field
568 static uint16_t gen_openx_flags(void)
570 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
571 return gen_bits_mask(0x7);
575 generate an openx open function
577 static uint16_t gen_openx_func(void)
579 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
580 return gen_bits_mask(0x13);
584 generate a file attrib combination
586 static uint32_t gen_attrib(void)
588 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
589 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
593 generate a unix timestamp
595 static time_t gen_timet(void)
597 if (gen_chance(30)) return 0;
598 return (time_t)random();
602 generate a unix timestamp
604 static NTTIME gen_nttime(void)
607 unix_to_nt_time(&ret, gen_timet());
612 generate a milliseconds protocol timeout
614 static uint32_t gen_timeout(void)
616 if (gen_chance(98)) return 0;
617 return random() % 50;
621 generate a file allocation size
623 static uint_t gen_alloc_size(void)
627 if (gen_chance(30)) return 0;
629 ret = random() % 4*1024*1024;
630 /* give a high chance of a round number */
631 if (gen_chance(60)) {
632 ret &= ~(1024*1024 - 1);
638 generate an ea_struct
640 static struct ea_struct gen_ea_struct(void)
643 const char *names[] = {"EAONE",
648 "AVERYLONGATTRIBUTENAME"};
649 const char *values[] = {"VALUE1",
654 "ASOMEWHATLONGERATTRIBUTEVALUE"};
658 i = gen_int_range(0, ARRAY_SIZE(names)-1);
659 } while (ignore_pattern(names[i]));
661 ea.name.s = names[i];
664 i = gen_int_range(0, ARRAY_SIZE(values)-1);
665 } while (ignore_pattern(values[i]));
667 ea.value = data_blob(values[i], strlen(values[i]));
669 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
677 this is called when a change notify reply comes in
679 static void async_notify(struct smbcli_request *req)
681 struct smb_notify notify;
685 struct smbcli_transport *transport = req->transport;
687 tid = SVAL(req->in.hdr, HDR_TID);
689 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
690 if (NT_STATUS_IS_OK(status)) {
691 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
693 notify.out.num_changes,
694 notify.out.changes[0].action,
695 notify.out.changes[0].name.s);
698 for (i=0;i<NSERVERS;i++) {
699 for (j=0;j<NINSTANCES;j++) {
700 if (transport == servers[i].cli[j]->transport &&
701 tid == servers[i].cli[j]->tree->tid) {
702 notifies[i][j].notify_count++;
703 notifies[i][j].status = status;
704 notifies[i][j].notify = notify;
711 the oplock handler will either ack the break or close the file
713 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
719 struct smbcli_tree *tree = NULL;
721 srandom(current_op.seed);
722 do_close = gen_chance(50);
724 for (i=0;i<NSERVERS;i++) {
725 for (j=0;j<NINSTANCES;j++) {
726 if (transport == servers[i].cli[j]->transport &&
727 tid == servers[i].cli[j]->tree->tid) {
728 oplocks[i][j].got_break = True;
729 oplocks[i][j].fnum = fnum;
730 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
731 oplocks[i][j].level = level;
732 oplocks[i][j].do_close = do_close;
733 tree = servers[i].cli[j]->tree;
739 printf("Oplock break not for one of our trees!?\n");
744 printf("oplock ack fnum=%d\n", fnum);
745 return smbcli_oplock_ack(tree, fnum, level);
748 printf("oplock close fnum=%d\n", fnum);
750 io.close.level = RAW_CLOSE_CLOSE;
751 io.close.in.fnum = fnum;
752 io.close.in.write_time = 0;
753 status = smb_raw_close(tree, &io);
755 if (!NT_STATUS_IS_OK(status)) {
756 printf("WARNING: close failed in oplock_handler_close - %s\n", nt_errstr(status));
763 the idle function tries to cope with getting an oplock break on a connection, and
764 an operation on another connection blocking until that break is acked
765 we check for operations on all transports in the idle function
767 static void idle_func(struct smbcli_transport *transport, void *private)
770 for (i=0;i<NSERVERS;i++) {
771 for (j=0;j<NINSTANCES;j++) {
772 if (servers[i].cli[j] &&
773 transport != servers[i].cli[j]->transport) {
774 smbcli_transport_process(servers[i].cli[j]->transport);
783 compare NTSTATUS, using checking ignored patterns
785 static BOOL compare_status(NTSTATUS status1, NTSTATUS status2)
787 if (NT_STATUS_EQUAL(status1, status2)) return True;
789 /* one code being an error and the other OK is always an error */
790 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return False;
792 /* if we are ignoring one of the status codes then consider this a match */
793 if (ignore_pattern(nt_errstr(status1)) ||
794 ignore_pattern(nt_errstr(status2))) {
802 check for pending packets on all connections
804 static void check_pending(void)
810 for (j=0;j<NINSTANCES;j++) {
811 for (i=0;i<NSERVERS;i++) {
812 smbcli_transport_process(servers[i].cli[j]->transport);
818 check that the same oplock breaks have been received by all instances
820 static BOOL check_oplocks(const char *call)
828 for (j=0;j<NINSTANCES;j++) {
829 for (i=1;i<NSERVERS;i++) {
830 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
831 oplocks[0][j].handle != oplocks[i][j].handle ||
832 oplocks[0][j].level != oplocks[i][j].level) {
833 if (tries++ < 10) goto again;
834 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
835 oplocks[0][j].got_break,
836 oplocks[0][j].handle,
838 oplocks[i][j].got_break,
839 oplocks[i][j].handle,
840 oplocks[i][j].level);
846 /* if we got a break and closed then remove the handle */
847 for (j=0;j<NINSTANCES;j++) {
848 if (oplocks[0][j].got_break &&
849 oplocks[0][j].do_close) {
850 uint16_t fnums[NSERVERS];
851 for (i=0;i<NSERVERS;i++) {
852 fnums[i] = oplocks[i][j].fnum;
854 gen_remove_handle(j, fnums);
863 check that the same change notify info has been received by all instances
865 static BOOL check_notifies(const char *call)
873 for (j=0;j<NINSTANCES;j++) {
874 for (i=1;i<NSERVERS;i++) {
876 struct smb_notify not1, not2;
878 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
879 if (tries++ < 10) goto again;
880 printf("Notify count inconsistent %d %d\n",
881 notifies[0][j].notify_count,
882 notifies[i][j].notify_count);
886 if (notifies[0][j].notify_count == 0) continue;
888 if (!NT_STATUS_EQUAL(notifies[0][j].status,
889 notifies[i][j].status)) {
890 printf("Notify status mismatch - %s - %s\n",
891 nt_errstr(notifies[0][j].status),
892 nt_errstr(notifies[i][j].status));
896 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
900 not1 = notifies[0][j].notify;
901 not2 = notifies[i][j].notify;
903 for (n=0;n<not1.out.num_changes;n++) {
904 if (not1.out.changes[n].action !=
905 not2.out.changes[n].action) {
906 printf("Notify action %d inconsistent %d %d\n", n,
907 not1.out.changes[n].action,
908 not2.out.changes[n].action);
911 if (strcmp(not1.out.changes[n].name.s,
912 not2.out.changes[n].name.s)) {
913 printf("Notify name %d inconsistent %s %s\n", n,
914 not1.out.changes[n].name.s,
915 not2.out.changes[n].name.s);
918 if (not1.out.changes[n].name.private_length !=
919 not2.out.changes[n].name.private_length) {
920 printf("Notify name length %d inconsistent %d %d\n", n,
921 not1.out.changes[n].name.private_length,
922 not2.out.changes[n].name.private_length);
929 ZERO_STRUCT(notifies);
935 #define GEN_COPY_PARM do { \
937 for (i=1;i<NSERVERS;i++) { \
942 #define GEN_CALL(call) do { \
944 ZERO_STRUCT(oplocks); \
945 ZERO_STRUCT(notifies); \
946 for (i=0;i<NSERVERS;i++) { \
947 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
950 current_op.status = status[0]; \
951 for (i=1;i<NSERVERS;i++) { \
952 if (!compare_status(status[i], status[0])) { \
953 printf("status different in %s - %s %s\n", #call, \
954 nt_errstr(status[0]), nt_errstr(status[i])); \
958 if (!check_oplocks(#call)) return False; \
959 if (!check_notifies(#call)) return False; \
960 if (!NT_STATUS_IS_OK(status[0])) { \
965 #define ADD_HANDLE(name, field) do { \
966 uint16_t fnums[NSERVERS]; \
968 for (i=0;i<NSERVERS;i++) { \
969 fnums[i] = parm[i].field; \
971 gen_add_handle(instance, name, fnums); \
974 #define REMOVE_HANDLE(field) do { \
975 uint16_t fnums[NSERVERS]; \
977 for (i=0;i<NSERVERS;i++) { \
978 fnums[i] = parm[i].field; \
980 gen_remove_handle(instance, fnums); \
983 #define GEN_SET_FNUM(field) do { \
985 for (i=0;i<NSERVERS;i++) { \
986 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
990 #define CHECK_EQUAL(field) do { \
991 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
992 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
993 (int)parm[0].field, (int)parm[1].field); \
998 #define CHECK_WSTR_EQUAL(field) do { \
999 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1000 printf("%s is NULL!\n", #field); \
1003 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1004 printf("Mismatch in %s - %s %s\n", #field, \
1005 parm[0].field.s, parm[1].field.s); \
1008 CHECK_EQUAL(field.private_length); \
1011 #define CHECK_BLOB_EQUAL(field) do { \
1012 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1013 printf("Mismatch in %s\n", #field); \
1016 CHECK_EQUAL(field.length); \
1019 #define CHECK_TIMES_EQUAL(field) do { \
1020 if (ABS(parm[0].field - parm[1].field) > time_skew() && \
1021 !ignore_pattern(#field)) { \
1022 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1023 (int)parm[0].field, (int)parm[1].field); \
1028 #define CHECK_NTTIMES_EQUAL(field) do { \
1029 if (ABS(nt_time_to_unix(parm[0].field) - \
1030 nt_time_to_unix(parm[1].field)) > time_skew() && \
1031 !ignore_pattern(#field)) { \
1032 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1033 (int)nt_time_to_unix(parm[0].field), \
1034 (int)nt_time_to_unix(parm[1].field)); \
1040 generate openx operations
1042 static BOOL handler_openx(int instance)
1044 union smb_open parm[NSERVERS];
1045 NTSTATUS status[NSERVERS];
1047 parm[0].openx.level = RAW_OPEN_OPENX;
1048 parm[0].openx.in.flags = gen_openx_flags();
1049 parm[0].openx.in.open_mode = gen_openx_mode();
1050 parm[0].openx.in.search_attrs = gen_attrib();
1051 parm[0].openx.in.file_attrs = gen_attrib();
1052 parm[0].openx.in.write_time = gen_timet();
1053 parm[0].openx.in.open_func = gen_openx_func();
1054 parm[0].openx.in.size = gen_io_count();
1055 parm[0].openx.in.timeout = gen_timeout();
1056 parm[0].openx.in.fname = gen_fname_open(instance);
1058 if (!options.use_oplocks) {
1059 /* mask out oplocks */
1060 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1061 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1065 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1067 CHECK_EQUAL(openx.out.attrib);
1068 CHECK_EQUAL(openx.out.size);
1069 CHECK_EQUAL(openx.out.access);
1070 CHECK_EQUAL(openx.out.ftype);
1071 CHECK_EQUAL(openx.out.devstate);
1072 CHECK_EQUAL(openx.out.action);
1073 CHECK_EQUAL(openx.out.access_mask);
1074 CHECK_EQUAL(openx.out.unknown);
1075 CHECK_TIMES_EQUAL(openx.out.write_time);
1077 /* open creates a new file handle */
1078 ADD_HANDLE(parm[0].openx.in.fname, openx.out.fnum);
1085 generate open operations
1087 static BOOL handler_open(int instance)
1089 union smb_open parm[NSERVERS];
1090 NTSTATUS status[NSERVERS];
1092 parm[0].openold.level = RAW_OPEN_OPEN;
1093 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1094 parm[0].openold.in.search_attrs = gen_attrib();
1095 parm[0].openold.in.fname = gen_fname_open(instance);
1097 if (!options.use_oplocks) {
1098 /* mask out oplocks */
1099 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1100 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1104 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1106 CHECK_EQUAL(openold.out.attrib);
1107 CHECK_TIMES_EQUAL(openold.out.write_time);
1108 CHECK_EQUAL(openold.out.size);
1109 CHECK_EQUAL(openold.out.rmode);
1111 /* open creates a new file handle */
1112 ADD_HANDLE(parm[0].openold.in.fname, openold.out.fnum);
1119 generate ntcreatex operations
1121 static BOOL handler_ntcreatex(int instance)
1123 union smb_open parm[NSERVERS];
1124 NTSTATUS status[NSERVERS];
1126 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1127 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1128 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1129 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1130 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1131 parm[0].ntcreatex.in.file_attr = gen_attrib();
1132 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1133 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1134 parm[0].ntcreatex.in.create_options = gen_create_options();
1135 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1136 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1137 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1139 if (!options.use_oplocks) {
1140 /* mask out oplocks */
1141 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1142 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1146 if (parm[0].ntcreatex.in.root_fid != 0) {
1147 GEN_SET_FNUM(ntcreatex.in.root_fid);
1149 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1151 CHECK_EQUAL(ntcreatex.out.oplock_level);
1152 CHECK_EQUAL(ntcreatex.out.create_action);
1153 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1154 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1155 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1156 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1157 CHECK_EQUAL(ntcreatex.out.attrib);
1158 CHECK_EQUAL(ntcreatex.out.alloc_size);
1159 CHECK_EQUAL(ntcreatex.out.size);
1160 CHECK_EQUAL(ntcreatex.out.file_type);
1161 CHECK_EQUAL(ntcreatex.out.ipc_state);
1162 CHECK_EQUAL(ntcreatex.out.is_directory);
1164 /* ntcreatex creates a new file handle */
1165 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.fnum);
1171 generate close operations
1173 static BOOL handler_close(int instance)
1175 union smb_close parm[NSERVERS];
1176 NTSTATUS status[NSERVERS];
1178 parm[0].close.level = RAW_CLOSE_CLOSE;
1179 parm[0].close.in.fnum = gen_fnum_close(instance);
1180 parm[0].close.in.write_time = gen_timet();
1183 GEN_SET_FNUM(close.in.fnum);
1184 GEN_CALL(smb_raw_close(tree, &parm[i]));
1186 REMOVE_HANDLE(close.in.fnum);
1192 generate unlink operations
1194 static BOOL handler_unlink(int instance)
1196 struct smb_unlink parm[NSERVERS];
1197 NTSTATUS status[NSERVERS];
1199 parm[0].in.pattern = gen_pattern();
1200 parm[0].in.attrib = gen_attrib();
1203 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1209 generate chkpath operations
1211 static BOOL handler_chkpath(int instance)
1213 struct smb_chkpath parm[NSERVERS];
1214 NTSTATUS status[NSERVERS];
1216 parm[0].in.path = gen_fname_open(instance);
1219 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1225 generate mkdir operations
1227 static BOOL handler_mkdir(int instance)
1229 union smb_mkdir parm[NSERVERS];
1230 NTSTATUS status[NSERVERS];
1232 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1233 parm[0].mkdir.in.path = gen_fname_open(instance);
1236 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1242 generate rmdir operations
1244 static BOOL handler_rmdir(int instance)
1246 struct smb_rmdir parm[NSERVERS];
1247 NTSTATUS status[NSERVERS];
1249 parm[0].in.path = gen_fname_open(instance);
1252 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1258 generate rename operations
1260 static BOOL handler_rename(int instance)
1262 union smb_rename parm[NSERVERS];
1263 NTSTATUS status[NSERVERS];
1265 parm[0].generic.level = RAW_RENAME_RENAME;
1266 parm[0].rename.in.pattern1 = gen_pattern();
1267 parm[0].rename.in.pattern2 = gen_pattern();
1268 parm[0].rename.in.attrib = gen_attrib();
1271 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1277 generate ntrename operations
1279 static BOOL handler_ntrename(int instance)
1281 union smb_rename parm[NSERVERS];
1282 NTSTATUS status[NSERVERS];
1284 parm[0].generic.level = RAW_RENAME_NTRENAME;
1285 parm[0].ntrename.in.old_name = gen_fname();
1286 parm[0].ntrename.in.new_name = gen_fname();
1287 parm[0].ntrename.in.attrib = gen_attrib();
1288 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1289 parm[0].ntrename.in.flags = gen_rename_flags();
1292 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1299 generate seek operations
1301 static BOOL handler_seek(int instance)
1303 struct smb_seek parm[NSERVERS];
1304 NTSTATUS status[NSERVERS];
1306 parm[0].in.fnum = gen_fnum(instance);
1307 parm[0].in.mode = gen_bits_mask2(0x3, 0xFFFF);
1308 parm[0].in.offset = gen_offset();
1311 GEN_SET_FNUM(in.fnum);
1312 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1314 CHECK_EQUAL(out.offset);
1321 generate readx operations
1323 static BOOL handler_readx(int instance)
1325 union smb_read parm[NSERVERS];
1326 NTSTATUS status[NSERVERS];
1328 parm[0].readx.level = RAW_READ_READX;
1329 parm[0].readx.in.fnum = gen_fnum(instance);
1330 parm[0].readx.in.offset = gen_offset();
1331 parm[0].readx.in.mincnt = gen_io_count();
1332 parm[0].readx.in.maxcnt = gen_io_count();
1333 parm[0].readx.in.remaining = gen_io_count();
1334 parm[0].readx.out.data = talloc_size(current_op.mem_ctx,
1335 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1338 GEN_SET_FNUM(readx.in.fnum);
1339 GEN_CALL(smb_raw_read(tree, &parm[i]));
1341 CHECK_EQUAL(readx.out.remaining);
1342 CHECK_EQUAL(readx.out.compaction_mode);
1343 CHECK_EQUAL(readx.out.nread);
1349 generate writex operations
1351 static BOOL handler_writex(int instance)
1353 union smb_write parm[NSERVERS];
1354 NTSTATUS status[NSERVERS];
1356 parm[0].writex.level = RAW_WRITE_WRITEX;
1357 parm[0].writex.in.fnum = gen_fnum(instance);
1358 parm[0].writex.in.offset = gen_offset();
1359 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1360 parm[0].writex.in.remaining = gen_io_count();
1361 parm[0].writex.in.count = gen_io_count();
1362 parm[0].writex.in.data = talloc_zero_size(current_op.mem_ctx, parm[0].writex.in.count);
1365 GEN_SET_FNUM(writex.in.fnum);
1366 GEN_CALL(smb_raw_write(tree, &parm[i]));
1368 CHECK_EQUAL(writex.out.nwritten);
1369 CHECK_EQUAL(writex.out.remaining);
1375 generate lockingx operations
1377 static BOOL handler_lockingx(int instance)
1379 union smb_lock parm[NSERVERS];
1380 NTSTATUS status[NSERVERS];
1383 parm[0].lockx.level = RAW_LOCK_LOCKX;
1384 parm[0].lockx.in.fnum = gen_fnum(instance);
1385 parm[0].lockx.in.mode = gen_lock_mode();
1386 parm[0].lockx.in.timeout = gen_timeout();
1388 /* make sure we don't accidentially generate an oplock
1389 break ack - otherwise the server can just block forever */
1390 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1391 parm[0].lockx.in.lock_cnt = gen_lock_count();
1392 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1393 } while (nlocks == 0);
1396 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1397 struct smb_lock_entry,
1399 for (n=0;n<nlocks;n++) {
1400 parm[0].lockx.in.locks[n].pid = gen_pid();
1401 parm[0].lockx.in.locks[n].offset = gen_offset();
1402 parm[0].lockx.in.locks[n].count = gen_io_count();
1407 GEN_SET_FNUM(lockx.in.fnum);
1408 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1414 generate a fileinfo query structure
1416 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1419 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1421 enum smb_fileinfo_level level;
1424 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1425 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1426 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1427 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1428 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1429 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1430 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1431 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1432 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1433 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1436 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1437 } while (ignore_pattern(levels[i].name));
1439 info->generic.level = levels[i].level;
1443 compare returned fileinfo structures
1445 static BOOL cmp_fileinfo(int instance,
1446 union smb_fileinfo parm[NSERVERS],
1447 NTSTATUS status[NSERVERS])
1451 switch (parm[0].generic.level) {
1452 case RAW_FILEINFO_GENERIC:
1455 case RAW_FILEINFO_GETATTR:
1456 CHECK_EQUAL(getattr.out.attrib);
1457 CHECK_EQUAL(getattr.out.size);
1458 CHECK_TIMES_EQUAL(getattr.out.write_time);
1461 case RAW_FILEINFO_GETATTRE:
1462 CHECK_TIMES_EQUAL(getattre.out.create_time);
1463 CHECK_TIMES_EQUAL(getattre.out.access_time);
1464 CHECK_TIMES_EQUAL(getattre.out.write_time);
1465 CHECK_EQUAL(getattre.out.size);
1466 CHECK_EQUAL(getattre.out.alloc_size);
1467 CHECK_EQUAL(getattre.out.attrib);
1470 case RAW_FILEINFO_STANDARD:
1471 CHECK_TIMES_EQUAL(standard.out.create_time);
1472 CHECK_TIMES_EQUAL(standard.out.access_time);
1473 CHECK_TIMES_EQUAL(standard.out.write_time);
1474 CHECK_EQUAL(standard.out.size);
1475 CHECK_EQUAL(standard.out.alloc_size);
1476 CHECK_EQUAL(standard.out.attrib);
1479 case RAW_FILEINFO_EA_SIZE:
1480 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1481 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1482 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1483 CHECK_EQUAL(ea_size.out.size);
1484 CHECK_EQUAL(ea_size.out.alloc_size);
1485 CHECK_EQUAL(ea_size.out.attrib);
1486 CHECK_EQUAL(ea_size.out.ea_size);
1489 case RAW_FILEINFO_ALL_EAS:
1490 CHECK_EQUAL(all_eas.out.num_eas);
1491 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1492 CHECK_EQUAL(all_eas.out.eas[i].flags);
1493 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1494 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1498 case RAW_FILEINFO_IS_NAME_VALID:
1501 case RAW_FILEINFO_BASIC_INFO:
1502 case RAW_FILEINFO_BASIC_INFORMATION:
1503 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1504 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1505 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1506 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1507 CHECK_EQUAL(basic_info.out.attrib);
1510 case RAW_FILEINFO_STANDARD_INFO:
1511 case RAW_FILEINFO_STANDARD_INFORMATION:
1512 CHECK_EQUAL(standard_info.out.alloc_size);
1513 CHECK_EQUAL(standard_info.out.size);
1514 CHECK_EQUAL(standard_info.out.nlink);
1515 CHECK_EQUAL(standard_info.out.delete_pending);
1516 CHECK_EQUAL(standard_info.out.directory);
1519 case RAW_FILEINFO_EA_INFO:
1520 case RAW_FILEINFO_EA_INFORMATION:
1521 CHECK_EQUAL(ea_info.out.ea_size);
1524 case RAW_FILEINFO_NAME_INFO:
1525 case RAW_FILEINFO_NAME_INFORMATION:
1526 CHECK_WSTR_EQUAL(name_info.out.fname);
1529 case RAW_FILEINFO_ALL_INFO:
1530 case RAW_FILEINFO_ALL_INFORMATION:
1531 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1532 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1533 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1534 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1535 CHECK_EQUAL(all_info.out.attrib);
1536 CHECK_EQUAL(all_info.out.alloc_size);
1537 CHECK_EQUAL(all_info.out.size);
1538 CHECK_EQUAL(all_info.out.nlink);
1539 CHECK_EQUAL(all_info.out.delete_pending);
1540 CHECK_EQUAL(all_info.out.directory);
1541 CHECK_EQUAL(all_info.out.ea_size);
1542 CHECK_WSTR_EQUAL(all_info.out.fname);
1545 case RAW_FILEINFO_ALT_NAME_INFO:
1546 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1547 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1550 case RAW_FILEINFO_STREAM_INFO:
1551 case RAW_FILEINFO_STREAM_INFORMATION:
1552 CHECK_EQUAL(stream_info.out.num_streams);
1553 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1554 CHECK_EQUAL(stream_info.out.streams[i].size);
1555 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1556 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1560 case RAW_FILEINFO_COMPRESSION_INFO:
1561 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1562 CHECK_EQUAL(compression_info.out.compressed_size);
1563 CHECK_EQUAL(compression_info.out.format);
1564 CHECK_EQUAL(compression_info.out.unit_shift);
1565 CHECK_EQUAL(compression_info.out.chunk_shift);
1566 CHECK_EQUAL(compression_info.out.cluster_shift);
1569 case RAW_FILEINFO_INTERNAL_INFORMATION:
1570 CHECK_EQUAL(internal_information.out.file_id);
1573 case RAW_FILEINFO_ACCESS_INFORMATION:
1574 CHECK_EQUAL(access_information.out.access_flags);
1577 case RAW_FILEINFO_POSITION_INFORMATION:
1578 CHECK_EQUAL(position_information.out.position);
1581 case RAW_FILEINFO_MODE_INFORMATION:
1582 CHECK_EQUAL(mode_information.out.mode);
1585 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1586 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1589 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1590 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1591 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1592 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1593 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1594 CHECK_EQUAL(network_open_information.out.alloc_size);
1595 CHECK_EQUAL(network_open_information.out.size);
1596 CHECK_EQUAL(network_open_information.out.attrib);
1599 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1600 CHECK_EQUAL(attribute_tag_information.out.attrib);
1601 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1604 /* Unhandled levels */
1606 case RAW_FILEINFO_SEC_DESC:
1607 case RAW_FILEINFO_EA_LIST:
1608 case RAW_FILEINFO_UNIX_BASIC:
1609 case RAW_FILEINFO_UNIX_LINK:
1617 generate qpathinfo operations
1619 static BOOL handler_qpathinfo(int instance)
1621 union smb_fileinfo parm[NSERVERS];
1622 NTSTATUS status[NSERVERS];
1624 parm[0].generic.in.fname = gen_fname_open(instance);
1626 gen_fileinfo(instance, &parm[0]);
1629 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1631 return cmp_fileinfo(instance, parm, status);
1635 generate qfileinfo operations
1637 static BOOL handler_qfileinfo(int instance)
1639 union smb_fileinfo parm[NSERVERS];
1640 NTSTATUS status[NSERVERS];
1642 parm[0].generic.in.fnum = gen_fnum(instance);
1644 gen_fileinfo(instance, &parm[0]);
1647 GEN_SET_FNUM(generic.in.fnum);
1648 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1650 return cmp_fileinfo(instance, parm, status);
1655 generate a fileinfo query structure
1657 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1661 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1663 enum smb_setfileinfo_level level;
1667 /* disabled until win2003 can handle them ... */
1668 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1669 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1671 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1672 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1673 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1674 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1675 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1678 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1679 } while (ignore_pattern(levels[i].name));
1681 info->generic.level = levels[i].level;
1683 switch (info->generic.level) {
1684 case RAW_SFILEINFO_SETATTR:
1685 info->setattr.in.attrib = gen_attrib();
1686 info->setattr.in.write_time = gen_timet();
1688 case RAW_SFILEINFO_SETATTRE:
1689 info->setattre.in.create_time = gen_timet();
1690 info->setattre.in.access_time = gen_timet();
1691 info->setattre.in.write_time = gen_timet();
1693 case RAW_SFILEINFO_STANDARD:
1694 info->standard.in.create_time = gen_timet();
1695 info->standard.in.access_time = gen_timet();
1696 info->standard.in.write_time = gen_timet();
1698 case RAW_SFILEINFO_EA_SET: {
1699 static struct ea_struct ea;
1700 info->ea_set.in.num_eas = 1;
1701 info->ea_set.in.eas = &ea;
1702 info->ea_set.in.eas[0] = gen_ea_struct();
1705 case RAW_SFILEINFO_BASIC_INFO:
1706 case RAW_SFILEINFO_BASIC_INFORMATION:
1707 info->basic_info.in.create_time = gen_nttime();
1708 info->basic_info.in.access_time = gen_nttime();
1709 info->basic_info.in.write_time = gen_nttime();
1710 info->basic_info.in.change_time = gen_nttime();
1711 info->basic_info.in.attrib = gen_attrib();
1713 case RAW_SFILEINFO_DISPOSITION_INFO:
1714 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1715 info->disposition_info.in.delete_on_close = gen_bool();
1717 case RAW_SFILEINFO_ALLOCATION_INFO:
1718 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1719 info->allocation_info.in.alloc_size = gen_alloc_size();
1721 case RAW_SFILEINFO_END_OF_FILE_INFO:
1722 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1723 info->end_of_file_info.in.size = gen_offset();
1725 case RAW_SFILEINFO_RENAME_INFORMATION:
1726 info->rename_information.in.overwrite = gen_bool();
1727 info->rename_information.in.root_fid = gen_root_fid(instance);
1728 info->rename_information.in.new_name = gen_fname_open(instance);
1730 case RAW_SFILEINFO_POSITION_INFORMATION:
1731 info->position_information.in.position = gen_offset();
1733 case RAW_SFILEINFO_MODE_INFORMATION:
1734 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1736 case RAW_SFILEINFO_GENERIC:
1737 case RAW_SFILEINFO_SEC_DESC:
1738 case RAW_SFILEINFO_UNIX_BASIC:
1739 case RAW_SFILEINFO_UNIX_LINK:
1740 case RAW_SFILEINFO_UNIX_HLINK:
1741 case RAW_SFILEINFO_1023:
1742 case RAW_SFILEINFO_1025:
1743 case RAW_SFILEINFO_1029:
1744 case RAW_SFILEINFO_1032:
1745 case RAW_SFILEINFO_1039:
1746 case RAW_SFILEINFO_1040:
1753 generate setpathinfo operations
1755 static BOOL handler_spathinfo(int instance)
1757 union smb_setfileinfo parm[NSERVERS];
1758 NTSTATUS status[NSERVERS];
1760 parm[0].generic.file.fname = gen_fname_open(instance);
1762 gen_setfileinfo(instance, &parm[0]);
1766 /* a special case for the fid in a RENAME */
1767 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1768 parm[0].rename_information.in.root_fid != 0) {
1769 GEN_SET_FNUM(rename_information.in.root_fid);
1772 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1779 generate setfileinfo operations
1781 static BOOL handler_sfileinfo(int instance)
1783 union smb_setfileinfo parm[NSERVERS];
1784 NTSTATUS status[NSERVERS];
1786 parm[0].generic.file.fnum = gen_fnum(instance);
1788 gen_setfileinfo(instance, &parm[0]);
1791 GEN_SET_FNUM(generic.file.fnum);
1792 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1799 generate change notify operations
1801 static BOOL handler_notify(int instance)
1803 struct smb_notify parm[NSERVERS];
1806 parm[0].in.buffer_size = gen_io_count();
1807 parm[0].in.completion_filter = gen_bits_mask(0xFF);
1808 parm[0].in.fnum = gen_fnum(instance);
1809 parm[0].in.recursive = gen_bool();
1812 GEN_SET_FNUM(in.fnum);
1814 for (n=0;n<NSERVERS;n++) {
1815 struct smbcli_request *req;
1816 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1817 req->async.fn = async_notify;
1824 wipe any relevant files
1826 static void wipe_files(void)
1829 for (i=0;i<NSERVERS;i++) {
1830 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1832 printf("Failed to wipe tree on server %d\n", i);
1835 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1836 printf("Failed to create \\gentest - %s\n",
1837 smbcli_errstr(servers[i].cli[0]->tree));
1841 printf("Deleted %d files on server %d\n", n, i);
1847 dump the current seeds - useful for continuing a backtrack
1849 static void dump_seeds(void)
1854 if (!options.seeds_file) {
1857 f = fopen("seeds.tmp", "w");
1860 for (i=0;i<options.numops;i++) {
1861 fprintf(f, "%u\n", op_parms[i].seed);
1864 rename("seeds.tmp", options.seeds_file);
1870 the list of top-level operations that we will generate
1874 BOOL (*handler)(int instance);
1875 int count, success_count;
1877 {"OPEN", handler_open},
1878 {"OPENX", handler_openx},
1879 {"NTCREATEX", handler_ntcreatex},
1880 {"CLOSE", handler_close},
1881 {"UNLINK", handler_unlink},
1882 {"MKDIR", handler_mkdir},
1883 {"RMDIR", handler_rmdir},
1884 {"RENAME", handler_rename},
1885 {"NTRENAME", handler_ntrename},
1886 {"READX", handler_readx},
1887 {"WRITEX", handler_writex},
1888 {"CHKPATH", handler_chkpath},
1889 {"LOCKINGX", handler_lockingx},
1890 {"QPATHINFO", handler_qpathinfo},
1891 {"QFILEINFO", handler_qfileinfo},
1892 {"SPATHINFO", handler_spathinfo},
1893 {"SFILEINFO", handler_sfileinfo},
1894 {"NOTIFY", handler_notify},
1895 {"SEEK", handler_seek},
1900 run the test with the current set of op_parms parameters
1901 return the number of operations that completed successfully
1903 static int run_test(void)
1907 if (!connect_servers()) {
1908 printf("Failed to connect to servers\n");
1914 /* wipe any leftover files from old runs */
1917 /* reset the open handles array */
1918 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1919 num_open_handles = 0;
1921 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1922 gen_ops[i].count = 0;
1923 gen_ops[i].success_count = 0;
1926 for (op=0; op<options.numops; op++) {
1927 int instance, which_op;
1930 if (op_parms[op].disabled) continue;
1932 srandom(op_parms[op].seed);
1934 instance = gen_int_range(0, NINSTANCES-1);
1936 /* generate a non-ignored operation */
1938 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1939 } while (ignore_pattern(gen_ops[which_op].name));
1941 DEBUG(3,("Generating op %s on instance %d\n",
1942 gen_ops[which_op].name, instance));
1944 current_op.seed = op_parms[op].seed;
1945 current_op.opnum = op;
1946 current_op.name = gen_ops[which_op].name;
1947 current_op.status = NT_STATUS_OK;
1948 current_op.mem_ctx = talloc_init("%s", current_op.name);
1950 ret = gen_ops[which_op].handler(instance);
1952 talloc_free(current_op.mem_ctx);
1954 gen_ops[which_op].count++;
1955 if (NT_STATUS_IS_OK(current_op.status)) {
1956 gen_ops[which_op].success_count++;
1960 printf("Failed at operation %d - %s\n",
1961 op, gen_ops[which_op].name);
1965 if (op % 100 == 0) {
1970 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1971 printf("Op %-10s got %d/%d success\n",
1973 gen_ops[i].success_count,
1981 perform a backtracking analysis of the minimal set of operations
1982 to generate an error
1984 static void backtrack_analyze(void)
1988 chunk = options.numops / 2;
1993 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1996 chunk = MIN(chunk, options.numops / 2);
1998 /* mark this range as disabled */
1999 max = MIN(options.numops, base+chunk);
2000 for (i=base;i<max; i++) {
2001 op_parms[i].disabled = True;
2003 printf("Testing %d ops with %d-%d disabled\n",
2004 options.numops, base, max-1);
2006 printf("Completed %d of %d ops\n", ret, options.numops);
2007 for (i=base;i<max; i++) {
2008 op_parms[i].disabled = False;
2010 if (ret == options.numops) {
2011 /* this chunk is needed */
2013 } else if (ret < base) {
2014 printf("damn - inconsistent errors! found early error\n");
2015 options.numops = ret+1;
2018 /* it failed - this chunk isn't needed for a failure */
2019 memmove(&op_parms[base], &op_parms[max],
2020 sizeof(op_parms[0]) * (options.numops - max));
2021 options.numops = (ret+1) - (max - base);
2031 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2034 } while (chunk > 0);
2036 printf("Reduced to %d ops\n", options.numops);
2038 if (ret != options.numops - 1) {
2039 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2044 start the main gentest process
2046 static BOOL start_gentest(void)
2051 /* allocate the open_handles array */
2052 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2054 srandom(options.seed);
2055 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2057 /* generate the seeds - after this everything is deterministic */
2058 if (options.use_preset_seeds) {
2060 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
2062 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2065 if (numops < options.numops) {
2066 options.numops = numops;
2068 for (op=0;op<options.numops;op++) {
2070 printf("Not enough seeds in %s\n", options.seeds_file);
2073 op_parms[op].seed = atoi(preset[op]);
2075 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2077 for (op=0; op<options.numops; op++) {
2078 op_parms[op].seed = random();
2084 if (ret != options.numops && options.analyze) {
2085 options.numops = ret+1;
2086 backtrack_analyze();
2087 } else if (options.analyze_always) {
2088 backtrack_analyze();
2089 } else if (options.analyze_continuous) {
2090 while (run_test() == options.numops) ;
2093 return ret == options.numops;
2097 static void usage(void)
2101 gentest2 //server1/share1 //server2/share2 [options..]\n\
2103 -U user%%pass (can be specified twice)\n\
2106 -a (show all ops)\n\
2107 -A backtrack to find minimal ops\n\
2108 -i FILE add a list of wildcard exclusions\n\
2109 -O enable oplocks\n\
2110 -S FILE set preset seeds file\n\
2111 -L use preset seeds\n\
2112 -F fast reconnect (just close files)\n\
2113 -C continuous analysis mode\n\
2114 -X analyse even when test OK\n\
2118 /****************************************************************************
2120 ****************************************************************************/
2121 int main(int argc, char *argv[])
2124 int i, username_count=0;
2129 setup_logging("gentest", DEBUG_STDOUT);
2131 if (argc < 3 || argv[1][0] == '-') {
2136 setup_logging(argv[0], DEBUG_STDOUT);
2138 for (i=0;i<NSERVERS;i++) {
2139 const char *share = argv[1+i];
2140 servers[i].credentials = cli_credentials_init(NULL);
2141 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2142 printf("Invalid share name '%s'\n", share);
2153 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
2154 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
2155 cli_credentials_guess(servers[0].credentials);
2156 cli_credentials_guess(servers[1].credentials);
2158 options.seed = time(NULL);
2159 options.numops = 1000;
2160 options.max_open_handles = 20;
2161 options.seeds_file = "gentest_seeds.dat";
2163 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2166 if (username_count == 2) {
2170 cli_credentials_parse_string(servers[username_count].credentials,
2171 optarg, CRED_SPECIFIED);
2175 DEBUGLEVEL = atoi(optarg);
2176 setup_logging(NULL, DEBUG_STDOUT);
2179 options.seed = atoi(optarg);
2182 options.seeds_file = optarg;
2185 options.use_preset_seeds = True;
2188 options.fast_reconnect = True;
2191 options.numops = atoi(optarg);
2194 options.use_oplocks = True;
2197 options.showall = True;
2200 options.analyze = True;
2203 options.analyze_always = True;
2206 options.analyze_continuous = True;
2209 options.ignore_patterns = file_lines_load(optarg, NULL, NULL);
2215 printf("Unknown option %c (%d)\n", (char)opt, opt);
2220 gentest_init_subsystems;
2222 if (username_count == 0) {
2226 if (username_count == 1) {
2227 servers[1].credentials = servers[0].credentials;
2230 printf("seed=%u\n", options.seed);
2232 ret = start_gentest();
2235 printf("gentest completed - no errors\n");
2237 printf("gentest failed\n");