2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "system/time.h"
22 #include "system/filesys.h"
23 #include "libcli/raw/request.h"
24 #include "libcli/libcli.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "librpc/gen_ndr/security.h"
27 #include "auth/credentials/credentials.h"
28 #include "auth/gensec/gensec.h"
29 #include "param/param.h"
30 #include "dynconfig.h"
36 static struct gentest_options {
40 bool analyze_continuous;
41 uint_t max_open_handles;
45 char **ignore_patterns;
46 const char *seeds_file;
47 bool use_preset_seeds;
51 /* mapping between open handles on the server and local handles */
55 uint_t server_fnum[NSERVERS];
58 static uint_t num_open_handles;
60 /* state information for the servers. We open NINSTANCES connections to
63 struct smbcli_state *cli[NINSTANCES];
66 struct cli_credentials *credentials;
69 /* the seeds and flags for each operation */
76 /* oplock break info */
83 } oplocks[NSERVERS][NINSTANCES];
85 /* change notify reply info */
89 union smb_notify notify;
90 } notifies[NSERVERS][NINSTANCES];
92 /* info relevant to the current operation */
103 #define BAD_HANDLE 0xFFFE
105 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
106 static void idle_func(struct smbcli_transport *transport, void *private);
109 check if a string should be ignored. This is used as the basis
110 for all error ignore settings
112 static bool ignore_pattern(const char *str)
115 if (!options.ignore_patterns) return false;
117 for (i=0;options.ignore_patterns[i];i++) {
118 if (strcmp(options.ignore_patterns[i], str) == 0 ||
119 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
120 DEBUG(2,("Ignoring '%s'\n", str));
127 /*****************************************************
128 connect to the servers
129 *******************************************************/
130 static bool connect_servers_fast(void)
134 /* close all open files */
135 for (h=0;h<options.max_open_handles;h++) {
136 if (!open_handles[h].active) continue;
137 for (i=0;i<NSERVERS;i++) {
138 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
139 open_handles[h].server_fnum[i])))) {
142 open_handles[h].active = false;
152 /*****************************************************
153 connect to the servers
154 *******************************************************/
155 static bool connect_servers(void)
159 if (options.fast_reconnect && servers[0].cli[0]) {
160 if (connect_servers_fast()) {
165 /* close any existing connections */
166 for (i=0;i<NSERVERS;i++) {
167 for (j=0;j<NINSTANCES;j++) {
168 if (servers[i].cli[j]) {
169 smbcli_tdis(servers[i].cli[j]);
170 talloc_free(servers[i].cli[j]);
171 servers[i].cli[j] = NULL;
176 for (i=0;i<NSERVERS;i++) {
177 for (j=0;j<NINSTANCES;j++) {
179 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
180 servers[i].server_name, servers[i].share_name,
181 servers[i].credentials->username, j);
183 cli_credentials_set_workstation(servers[i].credentials,
184 "gentest", CRED_SPECIFIED);
186 status = smbcli_full_connection(NULL, &servers[i].cli[j],
187 servers[i].server_name,
188 servers[i].share_name, NULL,
189 servers[i].credentials, NULL);
190 if (!NT_STATUS_IS_OK(status)) {
191 printf("Failed to connect to \\\\%s\\%s - %s\n",
192 servers[i].server_name, servers[i].share_name,
197 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
198 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
206 work out the time skew between the servers - be conservative
208 static uint_t time_skew(void)
211 ret = labs(servers[0].cli[0]->transport->negotiate.server_time -
212 servers[1].cli[0]->transport->negotiate.server_time);
217 turn an fnum for an instance into a handle
219 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
222 for (i=0;i<options.max_open_handles;i++) {
223 if (!open_handles[i].active ||
224 instance != open_handles[i].instance) continue;
225 if (open_handles[i].server_fnum[server] == fnum) {
229 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
230 fnum, server, instance);
235 add some newly opened handles
237 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
240 for (h=0;h<options.max_open_handles;h++) {
241 if (!open_handles[h].active) break;
243 if (h == options.max_open_handles) {
244 /* we have to force close a random handle */
245 h = random() % options.max_open_handles;
246 for (i=0;i<NSERVERS;i++) {
247 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
248 open_handles[h].server_fnum[i])))) {
249 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
250 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
253 printf("Recovered handle %d\n", h);
256 for (i=0;i<NSERVERS;i++) {
257 open_handles[h].server_fnum[i] = fnums[i];
258 open_handles[h].instance = instance;
259 open_handles[h].active = true;
260 open_handles[h].name = name;
264 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
266 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
271 remove a closed handle
273 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
276 for (h=0;h<options.max_open_handles;h++) {
277 if (instance == open_handles[h].instance &&
278 open_handles[h].server_fnum[0] == fnums[0]) {
279 open_handles[h].active = false;
281 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
283 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
284 open_handles[h].name);
288 printf("Removing invalid handle!?\n");
293 return true with 'chance' probability as a percentage
295 static bool gen_chance(uint_t chance)
297 return ((random() % 100) <= chance);
301 map an internal handle number to a server fnum
303 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
305 if (handle == BAD_HANDLE) return handle;
306 return open_handles[handle].server_fnum[server];
312 static uint16_t gen_fnum(int instance)
317 if (gen_chance(20)) return BAD_HANDLE;
319 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
320 h = random() % options.max_open_handles;
321 if (open_handles[h].active &&
322 open_handles[h].instance == instance) {
330 return a file handle, but skewed so we don't close the last
331 couple of handles too readily
333 static uint16_t gen_fnum_close(int instance)
335 if (num_open_handles < 3) {
336 if (gen_chance(80)) return BAD_HANDLE;
339 return gen_fnum(instance);
343 generate an integer in a specified range
345 static int gen_int_range(uint_t min, uint_t max)
348 return min + (r % (1+max-min));
352 return a fnum for use as a root fid
353 be careful to call GEN_SET_FNUM() when you use this!
355 static uint16_t gen_root_fid(int instance)
357 if (gen_chance(5)) return gen_fnum(instance);
362 generate a file offset
364 static int gen_offset(void)
366 if (gen_chance(20)) return 0;
367 return gen_int_range(0, 1024*1024);
373 static int gen_io_count(void)
375 if (gen_chance(20)) return 0;
376 return gen_int_range(0, 4096);
382 static const char *gen_fname(void)
384 const char *names[] = {"\\gentest\\gentest.dat",
386 "\\gentest\\foo2.sym",
387 "\\gentest\\foo3.dll",
389 "\\gentest\\foo4:teststream1",
390 "\\gentest\\foo4:teststream2",
391 "\\gentest\\foo5.exe",
392 "\\gentest\\foo5.exe:teststream3",
393 "\\gentest\\foo5.exe:teststream4",
394 "\\gentest\\foo6.com",
396 "\\gentest\\blah\\blergh.txt",
397 "\\gentest\\blah\\blergh2",
398 "\\gentest\\blah\\blergh3.txt",
399 "\\gentest\\blah\\blergh4",
400 "\\gentest\\blah\\blergh5.txt",
401 "\\gentest\\blah\\blergh5",
402 "\\gentest\\blah\\.",
404 /* this causes problem with w2k3 */
405 "\\gentest\\blah\\..",
407 "\\gentest\\a_very_long_name.bin",
413 i = gen_int_range(0, ARRAY_SIZE(names)-1);
414 } while (ignore_pattern(names[i]));
420 generate a filename with a higher chance of choosing an already
423 static const char *gen_fname_open(int instance)
426 h = gen_fnum(instance);
427 if (h == BAD_HANDLE) {
430 return open_handles[h].name;
434 generate a wildcard pattern
436 static const char *gen_pattern(void)
439 const char *names[] = {"\\gentest\\*.dat",
442 "\\gentest\\blah\\*.*",
443 "\\gentest\\blah\\*",
446 if (gen_chance(50)) return gen_fname();
449 i = gen_int_range(0, ARRAY_SIZE(names)-1);
450 } while (ignore_pattern(names[i]));
458 static uint32_t gen_bits_mask(uint_t mask)
460 uint_t ret = random();
465 generate a bitmask with high probability of the first mask
466 and low of the second
468 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
470 if (gen_chance(10)) return gen_bits_mask(mask2);
471 return gen_bits_mask(mask1);
477 static bool gen_bool(void)
479 return gen_bits_mask2(0x1, 0xFF);
483 generate ntrename flags
485 static uint16_t gen_rename_flags(void)
487 if (gen_chance(30)) return RENAME_FLAG_RENAME;
488 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
489 if (gen_chance(30)) return RENAME_FLAG_COPY;
490 return gen_bits_mask(0xFFFF);
495 return a lockingx lock mode
497 static uint16_t gen_lock_mode(void)
499 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
500 if (gen_chance(20)) return gen_bits_mask(0x1F);
501 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
507 static uint16_t gen_pid(void)
509 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
514 generate a lock count
516 static off_t gen_lock_count(void)
518 return gen_int_range(0, 3);
522 generate a ntcreatex flags field
524 static uint32_t gen_ntcreatex_flags(void)
526 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
527 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
531 generate a NT access mask
533 static uint32_t gen_access_mask(void)
535 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
536 if (gen_chance(20)) return SEC_FILE_ALL;
537 return gen_bits_mask(0xFFFFFFFF);
541 generate a ntcreatex create options bitfield
543 static uint32_t gen_create_options(void)
545 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
546 if (gen_chance(50)) return 0;
547 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
551 generate a ntcreatex open disposition
553 static uint32_t gen_open_disp(void)
555 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
556 return gen_int_range(0, 5);
560 generate an openx open mode
562 static uint16_t gen_openx_mode(void)
564 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
565 if (gen_chance(20)) return gen_bits_mask(0xFF);
566 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
570 generate an openx flags field
572 static uint16_t gen_openx_flags(void)
574 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
575 return gen_bits_mask(0x7);
579 generate an openx open function
581 static uint16_t gen_openx_func(void)
583 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
584 return gen_bits_mask(0x13);
588 generate a file attrib combination
590 static uint32_t gen_attrib(void)
592 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
593 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
597 generate a unix timestamp
599 static time_t gen_timet(void)
601 if (gen_chance(30)) return 0;
602 return (time_t)random();
606 generate a unix timestamp
608 static NTTIME gen_nttime(void)
611 unix_to_nt_time(&ret, gen_timet());
616 generate a milliseconds protocol timeout
618 static uint32_t gen_timeout(void)
620 if (gen_chance(98)) return 0;
621 return random() % 50;
625 generate a file allocation size
627 static uint_t gen_alloc_size(void)
631 if (gen_chance(30)) return 0;
633 ret = random() % 4*1024*1024;
634 /* give a high chance of a round number */
635 if (gen_chance(60)) {
636 ret &= ~(1024*1024 - 1);
642 generate an ea_struct
644 static struct ea_struct gen_ea_struct(void)
647 const char *names[] = {"EAONE",
652 "AVERYLONGATTRIBUTENAME"};
653 const char *values[] = {"VALUE1",
658 "ASOMEWHATLONGERATTRIBUTEVALUE"};
664 i = gen_int_range(0, ARRAY_SIZE(names)-1);
665 } while (ignore_pattern(names[i]));
667 ea.name.s = names[i];
670 i = gen_int_range(0, ARRAY_SIZE(values)-1);
671 } while (ignore_pattern(values[i]));
673 ea.value = data_blob(values[i], strlen(values[i]));
675 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
683 this is called when a change notify reply comes in
685 static void async_notify(struct smbcli_request *req)
687 union smb_notify notify;
691 struct smbcli_transport *transport = req->transport;
693 tid = SVAL(req->in.hdr, HDR_TID);
695 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
696 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
697 if (NT_STATUS_IS_OK(status)) {
698 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
700 notify.nttrans.out.num_changes,
701 notify.nttrans.out.changes[0].action,
702 notify.nttrans.out.changes[0].name.s);
705 for (i=0;i<NSERVERS;i++) {
706 for (j=0;j<NINSTANCES;j++) {
707 if (transport == servers[i].cli[j]->transport &&
708 tid == servers[i].cli[j]->tree->tid) {
709 notifies[i][j].notify_count++;
710 notifies[i][j].status = status;
711 notifies[i][j].notify = notify;
717 static void oplock_handler_close_recv(struct smbcli_request *req)
720 status = smbcli_request_simple_recv(req);
721 if (!NT_STATUS_IS_OK(status)) {
722 printf("close failed in oplock_handler\n");
723 smb_panic("close failed in oplock_handler");
728 the oplock handler will either ack the break or close the file
730 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
735 struct smbcli_tree *tree = NULL;
736 struct smbcli_request *req;
738 srandom(current_op.seed);
739 do_close = gen_chance(50);
741 for (i=0;i<NSERVERS;i++) {
742 for (j=0;j<NINSTANCES;j++) {
743 if (transport == servers[i].cli[j]->transport &&
744 tid == servers[i].cli[j]->tree->tid) {
745 oplocks[i][j].got_break = true;
746 oplocks[i][j].fnum = fnum;
747 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
748 oplocks[i][j].level = level;
749 oplocks[i][j].do_close = do_close;
750 tree = servers[i].cli[j]->tree;
756 printf("Oplock break not for one of our trees!?\n");
761 printf("oplock ack fnum=%d\n", fnum);
762 return smbcli_oplock_ack(tree, fnum, level);
765 printf("oplock close fnum=%d\n", fnum);
767 io.close.level = RAW_CLOSE_CLOSE;
768 io.close.in.file.fnum = fnum;
769 io.close.in.write_time = 0;
770 req = smb_raw_close_send(tree, &io);
773 printf("WARNING: close failed in oplock_handler_close\n");
777 req->async.fn = oplock_handler_close_recv;
778 req->async.private = NULL;
785 the idle function tries to cope with getting an oplock break on a connection, and
786 an operation on another connection blocking until that break is acked
787 we check for operations on all transports in the idle function
789 static void idle_func(struct smbcli_transport *transport, void *private)
792 for (i=0;i<NSERVERS;i++) {
793 for (j=0;j<NINSTANCES;j++) {
794 if (servers[i].cli[j] &&
795 transport != servers[i].cli[j]->transport) {
796 smbcli_transport_process(servers[i].cli[j]->transport);
805 compare NTSTATUS, using checking ignored patterns
807 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
809 if (NT_STATUS_EQUAL(status1, status2)) return true;
811 /* one code being an error and the other OK is always an error */
812 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return false;
814 /* if we are ignoring one of the status codes then consider this a match */
815 if (ignore_pattern(nt_errstr(status1)) ||
816 ignore_pattern(nt_errstr(status2))) {
824 check for pending packets on all connections
826 static void check_pending(void)
832 for (j=0;j<NINSTANCES;j++) {
833 for (i=0;i<NSERVERS;i++) {
834 smbcli_transport_process(servers[i].cli[j]->transport);
840 check that the same oplock breaks have been received by all instances
842 static bool check_oplocks(const char *call)
850 for (j=0;j<NINSTANCES;j++) {
851 for (i=1;i<NSERVERS;i++) {
852 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
853 oplocks[0][j].handle != oplocks[i][j].handle ||
854 oplocks[0][j].level != oplocks[i][j].level) {
855 if (tries++ < 10) goto again;
856 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
857 oplocks[0][j].got_break,
858 oplocks[0][j].handle,
860 oplocks[i][j].got_break,
861 oplocks[i][j].handle,
862 oplocks[i][j].level);
868 /* if we got a break and closed then remove the handle */
869 for (j=0;j<NINSTANCES;j++) {
870 if (oplocks[0][j].got_break &&
871 oplocks[0][j].do_close) {
872 uint16_t fnums[NSERVERS];
873 for (i=0;i<NSERVERS;i++) {
874 fnums[i] = oplocks[i][j].fnum;
876 gen_remove_handle(j, fnums);
885 check that the same change notify info has been received by all instances
887 static bool check_notifies(const char *call)
895 for (j=0;j<NINSTANCES;j++) {
896 for (i=1;i<NSERVERS;i++) {
898 union smb_notify not1, not2;
900 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
901 if (tries++ < 10) goto again;
902 printf("Notify count inconsistent %d %d\n",
903 notifies[0][j].notify_count,
904 notifies[i][j].notify_count);
908 if (notifies[0][j].notify_count == 0) continue;
910 if (!NT_STATUS_EQUAL(notifies[0][j].status,
911 notifies[i][j].status)) {
912 printf("Notify status mismatch - %s - %s\n",
913 nt_errstr(notifies[0][j].status),
914 nt_errstr(notifies[i][j].status));
918 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
922 not1 = notifies[0][j].notify;
923 not2 = notifies[i][j].notify;
925 for (n=0;n<not1.nttrans.out.num_changes;n++) {
926 if (not1.nttrans.out.changes[n].action !=
927 not2.nttrans.out.changes[n].action) {
928 printf("Notify action %d inconsistent %d %d\n", n,
929 not1.nttrans.out.changes[n].action,
930 not2.nttrans.out.changes[n].action);
933 if (strcmp(not1.nttrans.out.changes[n].name.s,
934 not2.nttrans.out.changes[n].name.s)) {
935 printf("Notify name %d inconsistent %s %s\n", n,
936 not1.nttrans.out.changes[n].name.s,
937 not2.nttrans.out.changes[n].name.s);
940 if (not1.nttrans.out.changes[n].name.private_length !=
941 not2.nttrans.out.changes[n].name.private_length) {
942 printf("Notify name length %d inconsistent %d %d\n", n,
943 not1.nttrans.out.changes[n].name.private_length,
944 not2.nttrans.out.changes[n].name.private_length);
951 ZERO_STRUCT(notifies);
957 #define GEN_COPY_PARM do { \
959 for (i=1;i<NSERVERS;i++) { \
964 #define GEN_CALL(call) do { \
966 ZERO_STRUCT(oplocks); \
967 ZERO_STRUCT(notifies); \
968 for (i=0;i<NSERVERS;i++) { \
969 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
972 current_op.status = status[0]; \
973 for (i=1;i<NSERVERS;i++) { \
974 if (!compare_status(status[i], status[0])) { \
975 printf("status different in %s - %s %s\n", #call, \
976 nt_errstr(status[0]), nt_errstr(status[i])); \
980 if (!check_oplocks(#call)) return false; \
981 if (!check_notifies(#call)) return false; \
982 if (!NT_STATUS_IS_OK(status[0])) { \
987 #define ADD_HANDLE(name, field) do { \
988 uint16_t fnums[NSERVERS]; \
990 for (i=0;i<NSERVERS;i++) { \
991 fnums[i] = parm[i].field; \
993 gen_add_handle(instance, name, fnums); \
996 #define REMOVE_HANDLE(field) do { \
997 uint16_t fnums[NSERVERS]; \
999 for (i=0;i<NSERVERS;i++) { \
1000 fnums[i] = parm[i].field; \
1002 gen_remove_handle(instance, fnums); \
1005 #define GEN_SET_FNUM(field) do { \
1007 for (i=0;i<NSERVERS;i++) { \
1008 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
1012 #define CHECK_EQUAL(field) do { \
1013 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1014 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1015 (int)parm[0].field, (int)parm[1].field); \
1020 #define CHECK_WSTR_EQUAL(field) do { \
1021 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1022 printf("%s is NULL!\n", #field); \
1025 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1026 printf("Mismatch in %s - %s %s\n", #field, \
1027 parm[0].field.s, parm[1].field.s); \
1030 CHECK_EQUAL(field.private_length); \
1033 #define CHECK_BLOB_EQUAL(field) do { \
1034 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1035 printf("Mismatch in %s\n", #field); \
1038 CHECK_EQUAL(field.length); \
1041 #define CHECK_TIMES_EQUAL(field) do { \
1042 if (labs(parm[0].field - parm[1].field) > time_skew() && \
1043 !ignore_pattern(#field)) { \
1044 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1045 (int)parm[0].field, (int)parm[1].field); \
1050 #define CHECK_NTTIMES_EQUAL(field) do { \
1051 if (labs(nt_time_to_unix(parm[0].field) - \
1052 nt_time_to_unix(parm[1].field)) > time_skew() && \
1053 !ignore_pattern(#field)) { \
1054 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1055 (int)nt_time_to_unix(parm[0].field), \
1056 (int)nt_time_to_unix(parm[1].field)); \
1062 generate openx operations
1064 static bool handler_openx(int instance)
1066 union smb_open parm[NSERVERS];
1067 NTSTATUS status[NSERVERS];
1069 parm[0].openx.level = RAW_OPEN_OPENX;
1070 parm[0].openx.in.flags = gen_openx_flags();
1071 parm[0].openx.in.open_mode = gen_openx_mode();
1072 parm[0].openx.in.search_attrs = gen_attrib();
1073 parm[0].openx.in.file_attrs = gen_attrib();
1074 parm[0].openx.in.write_time = gen_timet();
1075 parm[0].openx.in.open_func = gen_openx_func();
1076 parm[0].openx.in.size = gen_io_count();
1077 parm[0].openx.in.timeout = gen_timeout();
1078 parm[0].openx.in.fname = gen_fname_open(instance);
1080 if (!options.use_oplocks) {
1081 /* mask out oplocks */
1082 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1083 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1087 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1089 CHECK_EQUAL(openx.out.attrib);
1090 CHECK_EQUAL(openx.out.size);
1091 CHECK_EQUAL(openx.out.access);
1092 CHECK_EQUAL(openx.out.ftype);
1093 CHECK_EQUAL(openx.out.devstate);
1094 CHECK_EQUAL(openx.out.action);
1095 CHECK_EQUAL(openx.out.access_mask);
1096 CHECK_EQUAL(openx.out.unknown);
1097 CHECK_TIMES_EQUAL(openx.out.write_time);
1099 /* open creates a new file handle */
1100 ADD_HANDLE(parm[0].openx.in.fname, openx.out.file.fnum);
1107 generate open operations
1109 static bool handler_open(int instance)
1111 union smb_open parm[NSERVERS];
1112 NTSTATUS status[NSERVERS];
1114 parm[0].openold.level = RAW_OPEN_OPEN;
1115 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1116 parm[0].openold.in.search_attrs = gen_attrib();
1117 parm[0].openold.in.fname = gen_fname_open(instance);
1119 if (!options.use_oplocks) {
1120 /* mask out oplocks */
1121 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1122 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1126 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1128 CHECK_EQUAL(openold.out.attrib);
1129 CHECK_TIMES_EQUAL(openold.out.write_time);
1130 CHECK_EQUAL(openold.out.size);
1131 CHECK_EQUAL(openold.out.rmode);
1133 /* open creates a new file handle */
1134 ADD_HANDLE(parm[0].openold.in.fname, openold.out.file.fnum);
1141 generate ntcreatex operations
1143 static bool handler_ntcreatex(int instance)
1145 union smb_open parm[NSERVERS];
1146 NTSTATUS status[NSERVERS];
1148 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1149 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1150 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1151 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1152 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1153 parm[0].ntcreatex.in.file_attr = gen_attrib();
1154 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1155 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1156 parm[0].ntcreatex.in.create_options = gen_create_options();
1157 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1158 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1159 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1161 if (!options.use_oplocks) {
1162 /* mask out oplocks */
1163 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1164 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1168 if (parm[0].ntcreatex.in.root_fid != 0) {
1169 GEN_SET_FNUM(ntcreatex.in.root_fid);
1171 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1173 CHECK_EQUAL(ntcreatex.out.oplock_level);
1174 CHECK_EQUAL(ntcreatex.out.create_action);
1175 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1176 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1177 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1178 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1179 CHECK_EQUAL(ntcreatex.out.attrib);
1180 CHECK_EQUAL(ntcreatex.out.alloc_size);
1181 CHECK_EQUAL(ntcreatex.out.size);
1182 CHECK_EQUAL(ntcreatex.out.file_type);
1183 CHECK_EQUAL(ntcreatex.out.ipc_state);
1184 CHECK_EQUAL(ntcreatex.out.is_directory);
1186 /* ntcreatex creates a new file handle */
1187 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.file.fnum);
1193 generate close operations
1195 static bool handler_close(int instance)
1197 union smb_close parm[NSERVERS];
1198 NTSTATUS status[NSERVERS];
1200 parm[0].close.level = RAW_CLOSE_CLOSE;
1201 parm[0].close.in.file.fnum = gen_fnum_close(instance);
1202 parm[0].close.in.write_time = gen_timet();
1205 GEN_SET_FNUM(close.in.file.fnum);
1206 GEN_CALL(smb_raw_close(tree, &parm[i]));
1208 REMOVE_HANDLE(close.in.file.fnum);
1214 generate unlink operations
1216 static bool handler_unlink(int instance)
1218 union smb_unlink parm[NSERVERS];
1219 NTSTATUS status[NSERVERS];
1221 parm[0].unlink.in.pattern = gen_pattern();
1222 parm[0].unlink.in.attrib = gen_attrib();
1225 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1231 generate chkpath operations
1233 static bool handler_chkpath(int instance)
1235 union smb_chkpath parm[NSERVERS];
1236 NTSTATUS status[NSERVERS];
1238 parm[0].chkpath.in.path = gen_fname_open(instance);
1241 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1247 generate mkdir operations
1249 static bool handler_mkdir(int instance)
1251 union smb_mkdir parm[NSERVERS];
1252 NTSTATUS status[NSERVERS];
1254 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1255 parm[0].mkdir.in.path = gen_fname_open(instance);
1258 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1264 generate rmdir operations
1266 static bool handler_rmdir(int instance)
1268 struct smb_rmdir parm[NSERVERS];
1269 NTSTATUS status[NSERVERS];
1271 parm[0].in.path = gen_fname_open(instance);
1274 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1280 generate rename operations
1282 static bool handler_rename(int instance)
1284 union smb_rename parm[NSERVERS];
1285 NTSTATUS status[NSERVERS];
1287 parm[0].generic.level = RAW_RENAME_RENAME;
1288 parm[0].rename.in.pattern1 = gen_pattern();
1289 parm[0].rename.in.pattern2 = gen_pattern();
1290 parm[0].rename.in.attrib = gen_attrib();
1293 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1299 generate ntrename operations
1301 static bool handler_ntrename(int instance)
1303 union smb_rename parm[NSERVERS];
1304 NTSTATUS status[NSERVERS];
1306 parm[0].generic.level = RAW_RENAME_NTRENAME;
1307 parm[0].ntrename.in.old_name = gen_fname();
1308 parm[0].ntrename.in.new_name = gen_fname();
1309 parm[0].ntrename.in.attrib = gen_attrib();
1310 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1311 parm[0].ntrename.in.flags = gen_rename_flags();
1314 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1321 generate seek operations
1323 static bool handler_seek(int instance)
1325 union smb_seek parm[NSERVERS];
1326 NTSTATUS status[NSERVERS];
1328 parm[0].lseek.in.file.fnum = gen_fnum(instance);
1329 parm[0].lseek.in.mode = gen_bits_mask2(0x3, 0xFFFF);
1330 parm[0].lseek.in.offset = gen_offset();
1333 GEN_SET_FNUM(lseek.in.file.fnum);
1334 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1336 CHECK_EQUAL(lseek.out.offset);
1343 generate readx operations
1345 static bool handler_readx(int instance)
1347 union smb_read parm[NSERVERS];
1348 NTSTATUS status[NSERVERS];
1350 parm[0].readx.level = RAW_READ_READX;
1351 parm[0].readx.in.file.fnum = gen_fnum(instance);
1352 parm[0].readx.in.offset = gen_offset();
1353 parm[0].readx.in.mincnt = gen_io_count();
1354 parm[0].readx.in.maxcnt = gen_io_count();
1355 parm[0].readx.in.remaining = gen_io_count();
1356 parm[0].readx.in.read_for_execute = gen_bool();
1357 parm[0].readx.out.data = talloc_array(current_op.mem_ctx, uint8_t,
1358 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1361 GEN_SET_FNUM(readx.in.file.fnum);
1362 GEN_CALL(smb_raw_read(tree, &parm[i]));
1364 CHECK_EQUAL(readx.out.remaining);
1365 CHECK_EQUAL(readx.out.compaction_mode);
1366 CHECK_EQUAL(readx.out.nread);
1372 generate writex operations
1374 static bool handler_writex(int instance)
1376 union smb_write parm[NSERVERS];
1377 NTSTATUS status[NSERVERS];
1379 parm[0].writex.level = RAW_WRITE_WRITEX;
1380 parm[0].writex.in.file.fnum = gen_fnum(instance);
1381 parm[0].writex.in.offset = gen_offset();
1382 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1383 parm[0].writex.in.remaining = gen_io_count();
1384 parm[0].writex.in.count = gen_io_count();
1385 parm[0].writex.in.data = talloc_zero_array(current_op.mem_ctx, uint8_t, parm[0].writex.in.count);
1388 GEN_SET_FNUM(writex.in.file.fnum);
1389 GEN_CALL(smb_raw_write(tree, &parm[i]));
1391 CHECK_EQUAL(writex.out.nwritten);
1392 CHECK_EQUAL(writex.out.remaining);
1398 generate lockingx operations
1400 static bool handler_lockingx(int instance)
1402 union smb_lock parm[NSERVERS];
1403 NTSTATUS status[NSERVERS];
1406 parm[0].lockx.level = RAW_LOCK_LOCKX;
1407 parm[0].lockx.in.file.fnum = gen_fnum(instance);
1408 parm[0].lockx.in.mode = gen_lock_mode();
1409 parm[0].lockx.in.timeout = gen_timeout();
1411 /* make sure we don't accidentially generate an oplock
1412 break ack - otherwise the server can just block forever */
1413 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1414 parm[0].lockx.in.lock_cnt = gen_lock_count();
1415 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1416 } while (nlocks == 0);
1419 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1420 struct smb_lock_entry,
1422 for (n=0;n<nlocks;n++) {
1423 parm[0].lockx.in.locks[n].pid = gen_pid();
1424 parm[0].lockx.in.locks[n].offset = gen_offset();
1425 parm[0].lockx.in.locks[n].count = gen_io_count();
1430 GEN_SET_FNUM(lockx.in.file.fnum);
1431 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1437 generate a fileinfo query structure
1439 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1442 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1444 enum smb_fileinfo_level level;
1447 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1448 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1449 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1450 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1451 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1452 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1453 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1454 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1455 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1456 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1459 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1460 } while (ignore_pattern(levels[i].name));
1462 info->generic.level = levels[i].level;
1466 compare returned fileinfo structures
1468 static bool cmp_fileinfo(int instance,
1469 union smb_fileinfo parm[NSERVERS],
1470 NTSTATUS status[NSERVERS])
1474 switch (parm[0].generic.level) {
1475 case RAW_FILEINFO_GENERIC:
1478 case RAW_FILEINFO_GETATTR:
1479 CHECK_EQUAL(getattr.out.attrib);
1480 CHECK_EQUAL(getattr.out.size);
1481 CHECK_TIMES_EQUAL(getattr.out.write_time);
1484 case RAW_FILEINFO_GETATTRE:
1485 CHECK_TIMES_EQUAL(getattre.out.create_time);
1486 CHECK_TIMES_EQUAL(getattre.out.access_time);
1487 CHECK_TIMES_EQUAL(getattre.out.write_time);
1488 CHECK_EQUAL(getattre.out.size);
1489 CHECK_EQUAL(getattre.out.alloc_size);
1490 CHECK_EQUAL(getattre.out.attrib);
1493 case RAW_FILEINFO_STANDARD:
1494 CHECK_TIMES_EQUAL(standard.out.create_time);
1495 CHECK_TIMES_EQUAL(standard.out.access_time);
1496 CHECK_TIMES_EQUAL(standard.out.write_time);
1497 CHECK_EQUAL(standard.out.size);
1498 CHECK_EQUAL(standard.out.alloc_size);
1499 CHECK_EQUAL(standard.out.attrib);
1502 case RAW_FILEINFO_EA_SIZE:
1503 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1504 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1505 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1506 CHECK_EQUAL(ea_size.out.size);
1507 CHECK_EQUAL(ea_size.out.alloc_size);
1508 CHECK_EQUAL(ea_size.out.attrib);
1509 CHECK_EQUAL(ea_size.out.ea_size);
1512 case RAW_FILEINFO_ALL_EAS:
1513 CHECK_EQUAL(all_eas.out.num_eas);
1514 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1515 CHECK_EQUAL(all_eas.out.eas[i].flags);
1516 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1517 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1521 case RAW_FILEINFO_IS_NAME_VALID:
1524 case RAW_FILEINFO_BASIC_INFO:
1525 case RAW_FILEINFO_BASIC_INFORMATION:
1526 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1527 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1528 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1529 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1530 CHECK_EQUAL(basic_info.out.attrib);
1533 case RAW_FILEINFO_STANDARD_INFO:
1534 case RAW_FILEINFO_STANDARD_INFORMATION:
1535 CHECK_EQUAL(standard_info.out.alloc_size);
1536 CHECK_EQUAL(standard_info.out.size);
1537 CHECK_EQUAL(standard_info.out.nlink);
1538 CHECK_EQUAL(standard_info.out.delete_pending);
1539 CHECK_EQUAL(standard_info.out.directory);
1542 case RAW_FILEINFO_EA_INFO:
1543 case RAW_FILEINFO_EA_INFORMATION:
1544 CHECK_EQUAL(ea_info.out.ea_size);
1547 case RAW_FILEINFO_NAME_INFO:
1548 case RAW_FILEINFO_NAME_INFORMATION:
1549 CHECK_WSTR_EQUAL(name_info.out.fname);
1552 case RAW_FILEINFO_ALL_INFO:
1553 case RAW_FILEINFO_ALL_INFORMATION:
1554 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1555 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1556 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1557 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1558 CHECK_EQUAL(all_info.out.attrib);
1559 CHECK_EQUAL(all_info.out.alloc_size);
1560 CHECK_EQUAL(all_info.out.size);
1561 CHECK_EQUAL(all_info.out.nlink);
1562 CHECK_EQUAL(all_info.out.delete_pending);
1563 CHECK_EQUAL(all_info.out.directory);
1564 CHECK_EQUAL(all_info.out.ea_size);
1565 CHECK_WSTR_EQUAL(all_info.out.fname);
1568 case RAW_FILEINFO_ALT_NAME_INFO:
1569 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1570 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1573 case RAW_FILEINFO_STREAM_INFO:
1574 case RAW_FILEINFO_STREAM_INFORMATION:
1575 CHECK_EQUAL(stream_info.out.num_streams);
1576 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1577 CHECK_EQUAL(stream_info.out.streams[i].size);
1578 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1579 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1583 case RAW_FILEINFO_COMPRESSION_INFO:
1584 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1585 CHECK_EQUAL(compression_info.out.compressed_size);
1586 CHECK_EQUAL(compression_info.out.format);
1587 CHECK_EQUAL(compression_info.out.unit_shift);
1588 CHECK_EQUAL(compression_info.out.chunk_shift);
1589 CHECK_EQUAL(compression_info.out.cluster_shift);
1592 case RAW_FILEINFO_INTERNAL_INFORMATION:
1593 CHECK_EQUAL(internal_information.out.file_id);
1596 case RAW_FILEINFO_ACCESS_INFORMATION:
1597 CHECK_EQUAL(access_information.out.access_flags);
1600 case RAW_FILEINFO_POSITION_INFORMATION:
1601 CHECK_EQUAL(position_information.out.position);
1604 case RAW_FILEINFO_MODE_INFORMATION:
1605 CHECK_EQUAL(mode_information.out.mode);
1608 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1609 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1612 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1613 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1614 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1615 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1616 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1617 CHECK_EQUAL(network_open_information.out.alloc_size);
1618 CHECK_EQUAL(network_open_information.out.size);
1619 CHECK_EQUAL(network_open_information.out.attrib);
1622 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1623 CHECK_EQUAL(attribute_tag_information.out.attrib);
1624 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1627 /* Unhandled levels */
1629 case RAW_FILEINFO_SEC_DESC:
1630 case RAW_FILEINFO_EA_LIST:
1631 case RAW_FILEINFO_UNIX_BASIC:
1632 case RAW_FILEINFO_UNIX_LINK:
1633 case RAW_FILEINFO_SMB2_ALL_EAS:
1634 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1642 generate qpathinfo operations
1644 static bool handler_qpathinfo(int instance)
1646 union smb_fileinfo parm[NSERVERS];
1647 NTSTATUS status[NSERVERS];
1649 parm[0].generic.in.file.path = gen_fname_open(instance);
1651 gen_fileinfo(instance, &parm[0]);
1654 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1656 return cmp_fileinfo(instance, parm, status);
1660 generate qfileinfo operations
1662 static bool handler_qfileinfo(int instance)
1664 union smb_fileinfo parm[NSERVERS];
1665 NTSTATUS status[NSERVERS];
1667 parm[0].generic.in.file.fnum = gen_fnum(instance);
1669 gen_fileinfo(instance, &parm[0]);
1672 GEN_SET_FNUM(generic.in.file.fnum);
1673 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1675 return cmp_fileinfo(instance, parm, status);
1680 generate a fileinfo query structure
1682 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1686 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1688 enum smb_setfileinfo_level level;
1692 /* disabled until win2003 can handle them ... */
1693 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1694 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1696 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1697 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1698 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1699 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1700 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1703 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1704 } while (ignore_pattern(levels[i].name));
1706 info->generic.level = levels[i].level;
1708 switch (info->generic.level) {
1709 case RAW_SFILEINFO_SETATTR:
1710 info->setattr.in.attrib = gen_attrib();
1711 info->setattr.in.write_time = gen_timet();
1713 case RAW_SFILEINFO_SETATTRE:
1714 info->setattre.in.create_time = gen_timet();
1715 info->setattre.in.access_time = gen_timet();
1716 info->setattre.in.write_time = gen_timet();
1718 case RAW_SFILEINFO_STANDARD:
1719 info->standard.in.create_time = gen_timet();
1720 info->standard.in.access_time = gen_timet();
1721 info->standard.in.write_time = gen_timet();
1723 case RAW_SFILEINFO_EA_SET: {
1724 static struct ea_struct ea;
1725 info->ea_set.in.num_eas = 1;
1726 info->ea_set.in.eas = &ea;
1727 info->ea_set.in.eas[0] = gen_ea_struct();
1730 case RAW_SFILEINFO_BASIC_INFO:
1731 case RAW_SFILEINFO_BASIC_INFORMATION:
1732 info->basic_info.in.create_time = gen_nttime();
1733 info->basic_info.in.access_time = gen_nttime();
1734 info->basic_info.in.write_time = gen_nttime();
1735 info->basic_info.in.change_time = gen_nttime();
1736 info->basic_info.in.attrib = gen_attrib();
1738 case RAW_SFILEINFO_DISPOSITION_INFO:
1739 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1740 info->disposition_info.in.delete_on_close = gen_bool();
1742 case RAW_SFILEINFO_ALLOCATION_INFO:
1743 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1744 info->allocation_info.in.alloc_size = gen_alloc_size();
1746 case RAW_SFILEINFO_END_OF_FILE_INFO:
1747 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1748 info->end_of_file_info.in.size = gen_offset();
1750 case RAW_SFILEINFO_RENAME_INFORMATION:
1751 info->rename_information.in.overwrite = gen_bool();
1752 info->rename_information.in.root_fid = gen_root_fid(instance);
1753 info->rename_information.in.new_name = gen_fname_open(instance);
1755 case RAW_SFILEINFO_POSITION_INFORMATION:
1756 info->position_information.in.position = gen_offset();
1758 case RAW_SFILEINFO_MODE_INFORMATION:
1759 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1761 case RAW_SFILEINFO_GENERIC:
1762 case RAW_SFILEINFO_SEC_DESC:
1763 case RAW_SFILEINFO_UNIX_BASIC:
1764 case RAW_SFILEINFO_UNIX_LINK:
1765 case RAW_SFILEINFO_UNIX_HLINK:
1766 case RAW_SFILEINFO_1023:
1767 case RAW_SFILEINFO_1025:
1768 case RAW_SFILEINFO_1029:
1769 case RAW_SFILEINFO_1032:
1770 case RAW_SFILEINFO_1039:
1771 case RAW_SFILEINFO_1040:
1778 generate setpathinfo operations
1780 static bool handler_spathinfo(int instance)
1782 union smb_setfileinfo parm[NSERVERS];
1783 NTSTATUS status[NSERVERS];
1785 parm[0].generic.in.file.path = gen_fname_open(instance);
1787 gen_setfileinfo(instance, &parm[0]);
1791 /* a special case for the fid in a RENAME */
1792 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1793 parm[0].rename_information.in.root_fid != 0) {
1794 GEN_SET_FNUM(rename_information.in.root_fid);
1797 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1804 generate setfileinfo operations
1806 static bool handler_sfileinfo(int instance)
1808 union smb_setfileinfo parm[NSERVERS];
1809 NTSTATUS status[NSERVERS];
1811 parm[0].generic.in.file.fnum = gen_fnum(instance);
1813 gen_setfileinfo(instance, &parm[0]);
1816 GEN_SET_FNUM(generic.in.file.fnum);
1817 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1824 generate change notify operations
1826 static bool handler_notify(int instance)
1828 union smb_notify parm[NSERVERS];
1831 ZERO_STRUCT(parm[0]);
1832 parm[0].nttrans.level = RAW_NOTIFY_NTTRANS;
1833 parm[0].nttrans.in.buffer_size = gen_io_count();
1834 parm[0].nttrans.in.completion_filter = gen_bits_mask(0xFF);
1835 parm[0].nttrans.in.file.fnum = gen_fnum(instance);
1836 parm[0].nttrans.in.recursive = gen_bool();
1839 GEN_SET_FNUM(nttrans.in.file.fnum);
1841 for (n=0;n<NSERVERS;n++) {
1842 struct smbcli_request *req;
1843 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1844 req->async.fn = async_notify;
1851 wipe any relevant files
1853 static void wipe_files(void)
1856 for (i=0;i<NSERVERS;i++) {
1857 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1859 printf("Failed to wipe tree on server %d\n", i);
1862 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1863 printf("Failed to create \\gentest - %s\n",
1864 smbcli_errstr(servers[i].cli[0]->tree));
1868 printf("Deleted %d files on server %d\n", n, i);
1874 dump the current seeds - useful for continuing a backtrack
1876 static void dump_seeds(void)
1881 if (!options.seeds_file) {
1884 f = fopen("seeds.tmp", "w");
1887 for (i=0;i<options.numops;i++) {
1888 fprintf(f, "%u\n", op_parms[i].seed);
1891 rename("seeds.tmp", options.seeds_file);
1897 the list of top-level operations that we will generate
1901 bool (*handler)(int instance);
1902 int count, success_count;
1904 {"OPEN", handler_open},
1905 {"OPENX", handler_openx},
1906 {"NTCREATEX", handler_ntcreatex},
1907 {"CLOSE", handler_close},
1908 {"UNLINK", handler_unlink},
1909 {"MKDIR", handler_mkdir},
1910 {"RMDIR", handler_rmdir},
1911 {"RENAME", handler_rename},
1912 {"NTRENAME", handler_ntrename},
1913 {"READX", handler_readx},
1914 {"WRITEX", handler_writex},
1915 {"CHKPATH", handler_chkpath},
1916 {"LOCKINGX", handler_lockingx},
1917 {"QPATHINFO", handler_qpathinfo},
1918 {"QFILEINFO", handler_qfileinfo},
1919 {"SPATHINFO", handler_spathinfo},
1920 {"SFILEINFO", handler_sfileinfo},
1921 {"NOTIFY", handler_notify},
1922 {"SEEK", handler_seek},
1927 run the test with the current set of op_parms parameters
1928 return the number of operations that completed successfully
1930 static int run_test(void)
1934 if (!connect_servers()) {
1935 printf("Failed to connect to servers\n");
1941 /* wipe any leftover files from old runs */
1944 /* reset the open handles array */
1945 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1946 num_open_handles = 0;
1948 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1949 gen_ops[i].count = 0;
1950 gen_ops[i].success_count = 0;
1953 for (op=0; op<options.numops; op++) {
1954 int instance, which_op;
1957 if (op_parms[op].disabled) continue;
1959 srandom(op_parms[op].seed);
1961 instance = gen_int_range(0, NINSTANCES-1);
1963 /* generate a non-ignored operation */
1965 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1966 } while (ignore_pattern(gen_ops[which_op].name));
1968 DEBUG(3,("Generating op %s on instance %d\n",
1969 gen_ops[which_op].name, instance));
1971 current_op.seed = op_parms[op].seed;
1972 current_op.opnum = op;
1973 current_op.name = gen_ops[which_op].name;
1974 current_op.status = NT_STATUS_OK;
1975 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1977 ret = gen_ops[which_op].handler(instance);
1979 talloc_free(current_op.mem_ctx);
1981 gen_ops[which_op].count++;
1982 if (NT_STATUS_IS_OK(current_op.status)) {
1983 gen_ops[which_op].success_count++;
1987 printf("Failed at operation %d - %s\n",
1988 op, gen_ops[which_op].name);
1992 if (op % 100 == 0) {
1997 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1998 printf("Op %-10s got %d/%d success\n",
2000 gen_ops[i].success_count,
2008 perform a backtracking analysis of the minimal set of operations
2009 to generate an error
2011 static void backtrack_analyze(void)
2015 chunk = options.numops / 2;
2020 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2023 chunk = MIN(chunk, options.numops / 2);
2025 /* mark this range as disabled */
2026 max = MIN(options.numops, base+chunk);
2027 for (i=base;i<max; i++) {
2028 op_parms[i].disabled = true;
2030 printf("Testing %d ops with %d-%d disabled\n",
2031 options.numops, base, max-1);
2033 printf("Completed %d of %d ops\n", ret, options.numops);
2034 for (i=base;i<max; i++) {
2035 op_parms[i].disabled = false;
2037 if (ret == options.numops) {
2038 /* this chunk is needed */
2040 } else if (ret < base) {
2041 printf("damn - inconsistent errors! found early error\n");
2042 options.numops = ret+1;
2045 /* it failed - this chunk isn't needed for a failure */
2046 memmove(&op_parms[base], &op_parms[max],
2047 sizeof(op_parms[0]) * (options.numops - max));
2048 options.numops = (ret+1) - (max - base);
2058 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2061 } while (chunk > 0);
2063 printf("Reduced to %d ops\n", options.numops);
2065 if (ret != options.numops - 1) {
2066 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2071 start the main gentest process
2073 static bool start_gentest(void)
2078 /* allocate the open_handles array */
2079 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2081 srandom(options.seed);
2082 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2084 /* generate the seeds - after this everything is deterministic */
2085 if (options.use_preset_seeds) {
2087 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
2089 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2092 if (numops < options.numops) {
2093 options.numops = numops;
2095 for (op=0;op<options.numops;op++) {
2097 printf("Not enough seeds in %s\n", options.seeds_file);
2100 op_parms[op].seed = atoi(preset[op]);
2102 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2104 for (op=0; op<options.numops; op++) {
2105 op_parms[op].seed = random();
2111 if (ret != options.numops && options.analyze) {
2112 options.numops = ret+1;
2113 backtrack_analyze();
2114 } else if (options.analyze_always) {
2115 backtrack_analyze();
2116 } else if (options.analyze_continuous) {
2117 while (run_test() == options.numops) ;
2120 return ret == options.numops;
2124 static void usage(void)
2128 gentest2 //server1/share1 //server2/share2 [options..]\n\
2130 -U user%%pass (can be specified twice)\n\
2133 -a (show all ops)\n\
2134 -A backtrack to find minimal ops\n\
2135 -i FILE add a list of wildcard exclusions\n\
2136 -O enable oplocks\n\
2137 -S FILE set preset seeds file\n\
2138 -L use preset seeds\n\
2139 -F fast reconnect (just close files)\n\
2140 -C continuous analysis mode\n\
2141 -X analyse even when test OK\n\
2146 split a UNC name into server and share names
2148 static bool split_unc_name(const char *unc, char **server, char **share)
2150 char *p = strdup(unc);
2151 if (!p) return false;
2152 all_string_sub(p, "\\", "/", 0);
2153 if (strncmp(p, "//", 2) != 0) return false;
2156 p = strchr(*server, '/');
2157 if (!p) return false;
2167 /****************************************************************************
2169 ****************************************************************************/
2170 int main(int argc, char *argv[])
2173 int i, username_count=0;
2175 struct loadparm_context *lp_ctx;
2179 setup_logging("gentest", DEBUG_STDOUT);
2181 if (argc < 3 || argv[1][0] == '-') {
2186 setup_logging(argv[0], DEBUG_STDOUT);
2188 for (i=0;i<NSERVERS;i++) {
2189 const char *share = argv[1+i];
2190 servers[i].credentials = cli_credentials_init(NULL);
2191 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2192 printf("Invalid share name '%s'\n", share);
2200 lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
2202 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
2203 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
2204 cli_credentials_guess(servers[0].credentials, lp_ctx);
2205 cli_credentials_guess(servers[1].credentials, lp_ctx);
2207 options.seed = time(NULL);
2208 options.numops = 1000;
2209 options.max_open_handles = 20;
2210 options.seeds_file = "gentest_seeds.dat";
2212 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2215 if (username_count == 2) {
2219 cli_credentials_parse_string(servers[username_count].credentials,
2220 optarg, CRED_SPECIFIED);
2224 DEBUGLEVEL = atoi(optarg);
2225 setup_logging(NULL, DEBUG_STDOUT);
2228 options.seed = atoi(optarg);
2231 options.seeds_file = optarg;
2234 options.use_preset_seeds = true;
2237 options.fast_reconnect = true;
2240 options.numops = atoi(optarg);
2243 options.use_oplocks = true;
2246 options.showall = true;
2249 options.analyze = true;
2252 options.analyze_always = true;
2255 options.analyze_continuous = true;
2258 options.ignore_patterns = file_lines_load(optarg, NULL, NULL);
2264 printf("Unknown option %c (%d)\n", (char)opt, opt);
2269 gensec_init(lp_ctx);
2271 if (username_count == 0) {
2275 if (username_count == 1) {
2276 servers[1].credentials = servers[0].credentials;
2279 printf("seed=%u\n", options.seed);
2281 ret = start_gentest();
2284 printf("gentest completed - no errors\n");
2286 printf("gentest failed\n");