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 "libcli/resolve/resolve.h"
29 #include "auth/gensec/gensec.h"
30 #include "param/param.h"
31 #include "dynconfig.h"
37 static struct gentest_options {
41 bool analyze_continuous;
42 uint_t max_open_handles;
46 char **ignore_patterns;
47 const char *seeds_file;
48 bool use_preset_seeds;
52 /* mapping between open handles on the server and local handles */
56 uint_t server_fnum[NSERVERS];
59 static uint_t num_open_handles;
61 /* state information for the servers. We open NINSTANCES connections to
64 struct smbcli_state *cli[NINSTANCES];
67 struct cli_credentials *credentials;
70 /* the seeds and flags for each operation */
77 /* oplock break info */
84 } oplocks[NSERVERS][NINSTANCES];
86 /* change notify reply info */
90 union smb_notify notify;
91 } notifies[NSERVERS][NINSTANCES];
93 /* info relevant to the current operation */
104 #define BAD_HANDLE 0xFFFE
106 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
107 static void idle_func(struct smbcli_transport *transport, void *private);
110 check if a string should be ignored. This is used as the basis
111 for all error ignore settings
113 static bool ignore_pattern(const char *str)
116 if (!options.ignore_patterns) return false;
118 for (i=0;options.ignore_patterns[i];i++) {
119 if (strcmp(options.ignore_patterns[i], str) == 0 ||
120 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
121 DEBUG(2,("Ignoring '%s'\n", str));
128 /*****************************************************
129 connect to the servers
130 *******************************************************/
131 static bool connect_servers_fast(void)
135 /* close all open files */
136 for (h=0;h<options.max_open_handles;h++) {
137 if (!open_handles[h].active) continue;
138 for (i=0;i<NSERVERS;i++) {
139 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
140 open_handles[h].server_fnum[i])))) {
143 open_handles[h].active = false;
153 /*****************************************************
154 connect to the servers
155 *******************************************************/
156 static bool connect_servers(struct loadparm_context *lp_ctx)
160 if (options.fast_reconnect && servers[0].cli[0]) {
161 if (connect_servers_fast()) {
166 /* close any existing connections */
167 for (i=0;i<NSERVERS;i++) {
168 for (j=0;j<NINSTANCES;j++) {
169 if (servers[i].cli[j]) {
170 smbcli_tdis(servers[i].cli[j]);
171 talloc_free(servers[i].cli[j]);
172 servers[i].cli[j] = NULL;
177 for (i=0;i<NSERVERS;i++) {
178 for (j=0;j<NINSTANCES;j++) {
179 struct smbcli_options smb_options;
181 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
182 servers[i].server_name, servers[i].share_name,
183 servers[i].credentials->username, j);
185 cli_credentials_set_workstation(servers[i].credentials,
186 "gentest", CRED_SPECIFIED);
188 lp_smbcli_options(lp_ctx, &smb_options);
189 status = smbcli_full_connection(NULL, &servers[i].cli[j],
190 servers[i].server_name,
191 lp_smb_ports(lp_ctx),
192 servers[i].share_name, NULL,
193 servers[i].credentials,
194 lp_resolve_context(lp_ctx),
196 if (!NT_STATUS_IS_OK(status)) {
197 printf("Failed to connect to \\\\%s\\%s - %s\n",
198 servers[i].server_name, servers[i].share_name,
203 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
204 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
212 work out the time skew between the servers - be conservative
214 static uint_t time_skew(void)
217 ret = labs(servers[0].cli[0]->transport->negotiate.server_time -
218 servers[1].cli[0]->transport->negotiate.server_time);
223 turn an fnum for an instance into a handle
225 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
228 for (i=0;i<options.max_open_handles;i++) {
229 if (!open_handles[i].active ||
230 instance != open_handles[i].instance) continue;
231 if (open_handles[i].server_fnum[server] == fnum) {
235 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
236 fnum, server, instance);
241 add some newly opened handles
243 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
246 for (h=0;h<options.max_open_handles;h++) {
247 if (!open_handles[h].active) break;
249 if (h == options.max_open_handles) {
250 /* we have to force close a random handle */
251 h = random() % options.max_open_handles;
252 for (i=0;i<NSERVERS;i++) {
253 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
254 open_handles[h].server_fnum[i])))) {
255 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
256 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
259 printf("Recovered handle %d\n", h);
262 for (i=0;i<NSERVERS;i++) {
263 open_handles[h].server_fnum[i] = fnums[i];
264 open_handles[h].instance = instance;
265 open_handles[h].active = true;
266 open_handles[h].name = name;
270 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
272 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
277 remove a closed handle
279 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
282 for (h=0;h<options.max_open_handles;h++) {
283 if (instance == open_handles[h].instance &&
284 open_handles[h].server_fnum[0] == fnums[0]) {
285 open_handles[h].active = false;
287 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
289 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
290 open_handles[h].name);
294 printf("Removing invalid handle!?\n");
299 return true with 'chance' probability as a percentage
301 static bool gen_chance(uint_t chance)
303 return ((random() % 100) <= chance);
307 map an internal handle number to a server fnum
309 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
311 if (handle == BAD_HANDLE) return handle;
312 return open_handles[handle].server_fnum[server];
318 static uint16_t gen_fnum(int instance)
323 if (gen_chance(20)) return BAD_HANDLE;
325 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
326 h = random() % options.max_open_handles;
327 if (open_handles[h].active &&
328 open_handles[h].instance == instance) {
336 return a file handle, but skewed so we don't close the last
337 couple of handles too readily
339 static uint16_t gen_fnum_close(int instance)
341 if (num_open_handles < 3) {
342 if (gen_chance(80)) return BAD_HANDLE;
345 return gen_fnum(instance);
349 generate an integer in a specified range
351 static int gen_int_range(uint_t min, uint_t max)
354 return min + (r % (1+max-min));
358 return a fnum for use as a root fid
359 be careful to call GEN_SET_FNUM() when you use this!
361 static uint16_t gen_root_fid(int instance)
363 if (gen_chance(5)) return gen_fnum(instance);
368 generate a file offset
370 static int gen_offset(void)
372 if (gen_chance(20)) return 0;
373 return gen_int_range(0, 1024*1024);
379 static int gen_io_count(void)
381 if (gen_chance(20)) return 0;
382 return gen_int_range(0, 4096);
388 static const char *gen_fname(void)
390 const char *names[] = {"\\gentest\\gentest.dat",
392 "\\gentest\\foo2.sym",
393 "\\gentest\\foo3.dll",
395 "\\gentest\\foo4:teststream1",
396 "\\gentest\\foo4:teststream2",
397 "\\gentest\\foo5.exe",
398 "\\gentest\\foo5.exe:teststream3",
399 "\\gentest\\foo5.exe:teststream4",
400 "\\gentest\\foo6.com",
402 "\\gentest\\blah\\blergh.txt",
403 "\\gentest\\blah\\blergh2",
404 "\\gentest\\blah\\blergh3.txt",
405 "\\gentest\\blah\\blergh4",
406 "\\gentest\\blah\\blergh5.txt",
407 "\\gentest\\blah\\blergh5",
408 "\\gentest\\blah\\.",
410 /* this causes problem with w2k3 */
411 "\\gentest\\blah\\..",
413 "\\gentest\\a_very_long_name.bin",
419 i = gen_int_range(0, ARRAY_SIZE(names)-1);
420 } while (ignore_pattern(names[i]));
426 generate a filename with a higher chance of choosing an already
429 static const char *gen_fname_open(int instance)
432 h = gen_fnum(instance);
433 if (h == BAD_HANDLE) {
436 return open_handles[h].name;
440 generate a wildcard pattern
442 static const char *gen_pattern(void)
445 const char *names[] = {"\\gentest\\*.dat",
448 "\\gentest\\blah\\*.*",
449 "\\gentest\\blah\\*",
452 if (gen_chance(50)) return gen_fname();
455 i = gen_int_range(0, ARRAY_SIZE(names)-1);
456 } while (ignore_pattern(names[i]));
464 static uint32_t gen_bits_mask(uint_t mask)
466 uint_t ret = random();
471 generate a bitmask with high probability of the first mask
472 and low of the second
474 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
476 if (gen_chance(10)) return gen_bits_mask(mask2);
477 return gen_bits_mask(mask1);
483 static bool gen_bool(void)
485 return gen_bits_mask2(0x1, 0xFF);
489 generate ntrename flags
491 static uint16_t gen_rename_flags(void)
493 if (gen_chance(30)) return RENAME_FLAG_RENAME;
494 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
495 if (gen_chance(30)) return RENAME_FLAG_COPY;
496 return gen_bits_mask(0xFFFF);
501 return a lockingx lock mode
503 static uint16_t gen_lock_mode(void)
505 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
506 if (gen_chance(20)) return gen_bits_mask(0x1F);
507 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
513 static uint16_t gen_pid(void)
515 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
520 generate a lock count
522 static off_t gen_lock_count(void)
524 return gen_int_range(0, 3);
528 generate a ntcreatex flags field
530 static uint32_t gen_ntcreatex_flags(void)
532 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
533 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
537 generate a NT access mask
539 static uint32_t gen_access_mask(void)
541 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
542 if (gen_chance(20)) return SEC_FILE_ALL;
543 return gen_bits_mask(0xFFFFFFFF);
547 generate a ntcreatex create options bitfield
549 static uint32_t gen_create_options(void)
551 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
552 if (gen_chance(50)) return 0;
553 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
557 generate a ntcreatex open disposition
559 static uint32_t gen_open_disp(void)
561 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
562 return gen_int_range(0, 5);
566 generate an openx open mode
568 static uint16_t gen_openx_mode(void)
570 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
571 if (gen_chance(20)) return gen_bits_mask(0xFF);
572 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
576 generate an openx flags field
578 static uint16_t gen_openx_flags(void)
580 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
581 return gen_bits_mask(0x7);
585 generate an openx open function
587 static uint16_t gen_openx_func(void)
589 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
590 return gen_bits_mask(0x13);
594 generate a file attrib combination
596 static uint32_t gen_attrib(void)
598 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
599 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
603 generate a unix timestamp
605 static time_t gen_timet(void)
607 if (gen_chance(30)) return 0;
608 return (time_t)random();
612 generate a unix timestamp
614 static NTTIME gen_nttime(void)
617 unix_to_nt_time(&ret, gen_timet());
622 generate a milliseconds protocol timeout
624 static uint32_t gen_timeout(void)
626 if (gen_chance(98)) return 0;
627 return random() % 50;
631 generate a file allocation size
633 static uint_t gen_alloc_size(void)
637 if (gen_chance(30)) return 0;
639 ret = random() % 4*1024*1024;
640 /* give a high chance of a round number */
641 if (gen_chance(60)) {
642 ret &= ~(1024*1024 - 1);
648 generate an ea_struct
650 static struct ea_struct gen_ea_struct(void)
653 const char *names[] = {"EAONE",
658 "AVERYLONGATTRIBUTENAME"};
659 const char *values[] = {"VALUE1",
664 "ASOMEWHATLONGERATTRIBUTEVALUE"};
670 i = gen_int_range(0, ARRAY_SIZE(names)-1);
671 } while (ignore_pattern(names[i]));
673 ea.name.s = names[i];
676 i = gen_int_range(0, ARRAY_SIZE(values)-1);
677 } while (ignore_pattern(values[i]));
679 ea.value = data_blob(values[i], strlen(values[i]));
681 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
689 this is called when a change notify reply comes in
691 static void async_notify(struct smbcli_request *req)
693 union smb_notify notify;
697 struct smbcli_transport *transport = req->transport;
699 tid = SVAL(req->in.hdr, HDR_TID);
701 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
702 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
703 if (NT_STATUS_IS_OK(status)) {
704 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
706 notify.nttrans.out.num_changes,
707 notify.nttrans.out.changes[0].action,
708 notify.nttrans.out.changes[0].name.s);
711 for (i=0;i<NSERVERS;i++) {
712 for (j=0;j<NINSTANCES;j++) {
713 if (transport == servers[i].cli[j]->transport &&
714 tid == servers[i].cli[j]->tree->tid) {
715 notifies[i][j].notify_count++;
716 notifies[i][j].status = status;
717 notifies[i][j].notify = notify;
723 static void oplock_handler_close_recv(struct smbcli_request *req)
726 status = smbcli_request_simple_recv(req);
727 if (!NT_STATUS_IS_OK(status)) {
728 printf("close failed in oplock_handler\n");
729 smb_panic("close failed in oplock_handler");
734 the oplock handler will either ack the break or close the file
736 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
741 struct smbcli_tree *tree = NULL;
742 struct smbcli_request *req;
744 srandom(current_op.seed);
745 do_close = gen_chance(50);
747 for (i=0;i<NSERVERS;i++) {
748 for (j=0;j<NINSTANCES;j++) {
749 if (transport == servers[i].cli[j]->transport &&
750 tid == servers[i].cli[j]->tree->tid) {
751 oplocks[i][j].got_break = true;
752 oplocks[i][j].fnum = fnum;
753 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
754 oplocks[i][j].level = level;
755 oplocks[i][j].do_close = do_close;
756 tree = servers[i].cli[j]->tree;
762 printf("Oplock break not for one of our trees!?\n");
767 printf("oplock ack fnum=%d\n", fnum);
768 return smbcli_oplock_ack(tree, fnum, level);
771 printf("oplock close fnum=%d\n", fnum);
773 io.close.level = RAW_CLOSE_CLOSE;
774 io.close.in.file.fnum = fnum;
775 io.close.in.write_time = 0;
776 req = smb_raw_close_send(tree, &io);
779 printf("WARNING: close failed in oplock_handler_close\n");
783 req->async.fn = oplock_handler_close_recv;
784 req->async.private = NULL;
791 the idle function tries to cope with getting an oplock break on a connection, and
792 an operation on another connection blocking until that break is acked
793 we check for operations on all transports in the idle function
795 static void idle_func(struct smbcli_transport *transport, void *private)
798 for (i=0;i<NSERVERS;i++) {
799 for (j=0;j<NINSTANCES;j++) {
800 if (servers[i].cli[j] &&
801 transport != servers[i].cli[j]->transport) {
802 smbcli_transport_process(servers[i].cli[j]->transport);
811 compare NTSTATUS, using checking ignored patterns
813 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
815 if (NT_STATUS_EQUAL(status1, status2)) return true;
817 /* one code being an error and the other OK is always an error */
818 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return false;
820 /* if we are ignoring one of the status codes then consider this a match */
821 if (ignore_pattern(nt_errstr(status1)) ||
822 ignore_pattern(nt_errstr(status2))) {
830 check for pending packets on all connections
832 static void check_pending(void)
838 for (j=0;j<NINSTANCES;j++) {
839 for (i=0;i<NSERVERS;i++) {
840 smbcli_transport_process(servers[i].cli[j]->transport);
846 check that the same oplock breaks have been received by all instances
848 static bool check_oplocks(const char *call)
856 for (j=0;j<NINSTANCES;j++) {
857 for (i=1;i<NSERVERS;i++) {
858 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
859 oplocks[0][j].handle != oplocks[i][j].handle ||
860 oplocks[0][j].level != oplocks[i][j].level) {
861 if (tries++ < 10) goto again;
862 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
863 oplocks[0][j].got_break,
864 oplocks[0][j].handle,
866 oplocks[i][j].got_break,
867 oplocks[i][j].handle,
868 oplocks[i][j].level);
874 /* if we got a break and closed then remove the handle */
875 for (j=0;j<NINSTANCES;j++) {
876 if (oplocks[0][j].got_break &&
877 oplocks[0][j].do_close) {
878 uint16_t fnums[NSERVERS];
879 for (i=0;i<NSERVERS;i++) {
880 fnums[i] = oplocks[i][j].fnum;
882 gen_remove_handle(j, fnums);
891 check that the same change notify info has been received by all instances
893 static bool check_notifies(const char *call)
901 for (j=0;j<NINSTANCES;j++) {
902 for (i=1;i<NSERVERS;i++) {
904 union smb_notify not1, not2;
906 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
907 if (tries++ < 10) goto again;
908 printf("Notify count inconsistent %d %d\n",
909 notifies[0][j].notify_count,
910 notifies[i][j].notify_count);
914 if (notifies[0][j].notify_count == 0) continue;
916 if (!NT_STATUS_EQUAL(notifies[0][j].status,
917 notifies[i][j].status)) {
918 printf("Notify status mismatch - %s - %s\n",
919 nt_errstr(notifies[0][j].status),
920 nt_errstr(notifies[i][j].status));
924 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
928 not1 = notifies[0][j].notify;
929 not2 = notifies[i][j].notify;
931 for (n=0;n<not1.nttrans.out.num_changes;n++) {
932 if (not1.nttrans.out.changes[n].action !=
933 not2.nttrans.out.changes[n].action) {
934 printf("Notify action %d inconsistent %d %d\n", n,
935 not1.nttrans.out.changes[n].action,
936 not2.nttrans.out.changes[n].action);
939 if (strcmp(not1.nttrans.out.changes[n].name.s,
940 not2.nttrans.out.changes[n].name.s)) {
941 printf("Notify name %d inconsistent %s %s\n", n,
942 not1.nttrans.out.changes[n].name.s,
943 not2.nttrans.out.changes[n].name.s);
946 if (not1.nttrans.out.changes[n].name.private_length !=
947 not2.nttrans.out.changes[n].name.private_length) {
948 printf("Notify name length %d inconsistent %d %d\n", n,
949 not1.nttrans.out.changes[n].name.private_length,
950 not2.nttrans.out.changes[n].name.private_length);
957 ZERO_STRUCT(notifies);
963 #define GEN_COPY_PARM do { \
965 for (i=1;i<NSERVERS;i++) { \
970 #define GEN_CALL(call) do { \
972 ZERO_STRUCT(oplocks); \
973 ZERO_STRUCT(notifies); \
974 for (i=0;i<NSERVERS;i++) { \
975 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
978 current_op.status = status[0]; \
979 for (i=1;i<NSERVERS;i++) { \
980 if (!compare_status(status[i], status[0])) { \
981 printf("status different in %s - %s %s\n", #call, \
982 nt_errstr(status[0]), nt_errstr(status[i])); \
986 if (!check_oplocks(#call)) return false; \
987 if (!check_notifies(#call)) return false; \
988 if (!NT_STATUS_IS_OK(status[0])) { \
993 #define ADD_HANDLE(name, field) do { \
994 uint16_t fnums[NSERVERS]; \
996 for (i=0;i<NSERVERS;i++) { \
997 fnums[i] = parm[i].field; \
999 gen_add_handle(instance, name, fnums); \
1002 #define REMOVE_HANDLE(field) do { \
1003 uint16_t fnums[NSERVERS]; \
1005 for (i=0;i<NSERVERS;i++) { \
1006 fnums[i] = parm[i].field; \
1008 gen_remove_handle(instance, fnums); \
1011 #define GEN_SET_FNUM(field) do { \
1013 for (i=0;i<NSERVERS;i++) { \
1014 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
1018 #define CHECK_EQUAL(field) do { \
1019 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1020 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1021 (int)parm[0].field, (int)parm[1].field); \
1026 #define CHECK_WSTR_EQUAL(field) do { \
1027 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1028 printf("%s is NULL!\n", #field); \
1031 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1032 printf("Mismatch in %s - %s %s\n", #field, \
1033 parm[0].field.s, parm[1].field.s); \
1036 CHECK_EQUAL(field.private_length); \
1039 #define CHECK_BLOB_EQUAL(field) do { \
1040 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1041 printf("Mismatch in %s\n", #field); \
1044 CHECK_EQUAL(field.length); \
1047 #define CHECK_TIMES_EQUAL(field) do { \
1048 if (labs(parm[0].field - parm[1].field) > time_skew() && \
1049 !ignore_pattern(#field)) { \
1050 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1051 (int)parm[0].field, (int)parm[1].field); \
1056 #define CHECK_NTTIMES_EQUAL(field) do { \
1057 if (labs(nt_time_to_unix(parm[0].field) - \
1058 nt_time_to_unix(parm[1].field)) > time_skew() && \
1059 !ignore_pattern(#field)) { \
1060 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1061 (int)nt_time_to_unix(parm[0].field), \
1062 (int)nt_time_to_unix(parm[1].field)); \
1068 generate openx operations
1070 static bool handler_openx(int instance)
1072 union smb_open parm[NSERVERS];
1073 NTSTATUS status[NSERVERS];
1075 parm[0].openx.level = RAW_OPEN_OPENX;
1076 parm[0].openx.in.flags = gen_openx_flags();
1077 parm[0].openx.in.open_mode = gen_openx_mode();
1078 parm[0].openx.in.search_attrs = gen_attrib();
1079 parm[0].openx.in.file_attrs = gen_attrib();
1080 parm[0].openx.in.write_time = gen_timet();
1081 parm[0].openx.in.open_func = gen_openx_func();
1082 parm[0].openx.in.size = gen_io_count();
1083 parm[0].openx.in.timeout = gen_timeout();
1084 parm[0].openx.in.fname = gen_fname_open(instance);
1086 if (!options.use_oplocks) {
1087 /* mask out oplocks */
1088 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1089 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1093 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1095 CHECK_EQUAL(openx.out.attrib);
1096 CHECK_EQUAL(openx.out.size);
1097 CHECK_EQUAL(openx.out.access);
1098 CHECK_EQUAL(openx.out.ftype);
1099 CHECK_EQUAL(openx.out.devstate);
1100 CHECK_EQUAL(openx.out.action);
1101 CHECK_EQUAL(openx.out.access_mask);
1102 CHECK_EQUAL(openx.out.unknown);
1103 CHECK_TIMES_EQUAL(openx.out.write_time);
1105 /* open creates a new file handle */
1106 ADD_HANDLE(parm[0].openx.in.fname, openx.out.file.fnum);
1113 generate open operations
1115 static bool handler_open(int instance)
1117 union smb_open parm[NSERVERS];
1118 NTSTATUS status[NSERVERS];
1120 parm[0].openold.level = RAW_OPEN_OPEN;
1121 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1122 parm[0].openold.in.search_attrs = gen_attrib();
1123 parm[0].openold.in.fname = gen_fname_open(instance);
1125 if (!options.use_oplocks) {
1126 /* mask out oplocks */
1127 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1128 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1132 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1134 CHECK_EQUAL(openold.out.attrib);
1135 CHECK_TIMES_EQUAL(openold.out.write_time);
1136 CHECK_EQUAL(openold.out.size);
1137 CHECK_EQUAL(openold.out.rmode);
1139 /* open creates a new file handle */
1140 ADD_HANDLE(parm[0].openold.in.fname, openold.out.file.fnum);
1147 generate ntcreatex operations
1149 static bool handler_ntcreatex(int instance)
1151 union smb_open parm[NSERVERS];
1152 NTSTATUS status[NSERVERS];
1154 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1155 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1156 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1157 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1158 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1159 parm[0].ntcreatex.in.file_attr = gen_attrib();
1160 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1161 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1162 parm[0].ntcreatex.in.create_options = gen_create_options();
1163 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1164 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1165 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1167 if (!options.use_oplocks) {
1168 /* mask out oplocks */
1169 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1170 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1174 if (parm[0].ntcreatex.in.root_fid != 0) {
1175 GEN_SET_FNUM(ntcreatex.in.root_fid);
1177 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1179 CHECK_EQUAL(ntcreatex.out.oplock_level);
1180 CHECK_EQUAL(ntcreatex.out.create_action);
1181 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1182 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1183 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1184 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1185 CHECK_EQUAL(ntcreatex.out.attrib);
1186 CHECK_EQUAL(ntcreatex.out.alloc_size);
1187 CHECK_EQUAL(ntcreatex.out.size);
1188 CHECK_EQUAL(ntcreatex.out.file_type);
1189 CHECK_EQUAL(ntcreatex.out.ipc_state);
1190 CHECK_EQUAL(ntcreatex.out.is_directory);
1192 /* ntcreatex creates a new file handle */
1193 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.file.fnum);
1199 generate close operations
1201 static bool handler_close(int instance)
1203 union smb_close parm[NSERVERS];
1204 NTSTATUS status[NSERVERS];
1206 parm[0].close.level = RAW_CLOSE_CLOSE;
1207 parm[0].close.in.file.fnum = gen_fnum_close(instance);
1208 parm[0].close.in.write_time = gen_timet();
1211 GEN_SET_FNUM(close.in.file.fnum);
1212 GEN_CALL(smb_raw_close(tree, &parm[i]));
1214 REMOVE_HANDLE(close.in.file.fnum);
1220 generate unlink operations
1222 static bool handler_unlink(int instance)
1224 union smb_unlink parm[NSERVERS];
1225 NTSTATUS status[NSERVERS];
1227 parm[0].unlink.in.pattern = gen_pattern();
1228 parm[0].unlink.in.attrib = gen_attrib();
1231 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1237 generate chkpath operations
1239 static bool handler_chkpath(int instance)
1241 union smb_chkpath parm[NSERVERS];
1242 NTSTATUS status[NSERVERS];
1244 parm[0].chkpath.in.path = gen_fname_open(instance);
1247 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1253 generate mkdir operations
1255 static bool handler_mkdir(int instance)
1257 union smb_mkdir parm[NSERVERS];
1258 NTSTATUS status[NSERVERS];
1260 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1261 parm[0].mkdir.in.path = gen_fname_open(instance);
1264 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1270 generate rmdir operations
1272 static bool handler_rmdir(int instance)
1274 struct smb_rmdir parm[NSERVERS];
1275 NTSTATUS status[NSERVERS];
1277 parm[0].in.path = gen_fname_open(instance);
1280 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1286 generate rename operations
1288 static bool handler_rename(int instance)
1290 union smb_rename parm[NSERVERS];
1291 NTSTATUS status[NSERVERS];
1293 parm[0].generic.level = RAW_RENAME_RENAME;
1294 parm[0].rename.in.pattern1 = gen_pattern();
1295 parm[0].rename.in.pattern2 = gen_pattern();
1296 parm[0].rename.in.attrib = gen_attrib();
1299 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1305 generate ntrename operations
1307 static bool handler_ntrename(int instance)
1309 union smb_rename parm[NSERVERS];
1310 NTSTATUS status[NSERVERS];
1312 parm[0].generic.level = RAW_RENAME_NTRENAME;
1313 parm[0].ntrename.in.old_name = gen_fname();
1314 parm[0].ntrename.in.new_name = gen_fname();
1315 parm[0].ntrename.in.attrib = gen_attrib();
1316 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1317 parm[0].ntrename.in.flags = gen_rename_flags();
1320 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1327 generate seek operations
1329 static bool handler_seek(int instance)
1331 union smb_seek parm[NSERVERS];
1332 NTSTATUS status[NSERVERS];
1334 parm[0].lseek.in.file.fnum = gen_fnum(instance);
1335 parm[0].lseek.in.mode = gen_bits_mask2(0x3, 0xFFFF);
1336 parm[0].lseek.in.offset = gen_offset();
1339 GEN_SET_FNUM(lseek.in.file.fnum);
1340 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1342 CHECK_EQUAL(lseek.out.offset);
1349 generate readx operations
1351 static bool handler_readx(int instance)
1353 union smb_read parm[NSERVERS];
1354 NTSTATUS status[NSERVERS];
1356 parm[0].readx.level = RAW_READ_READX;
1357 parm[0].readx.in.file.fnum = gen_fnum(instance);
1358 parm[0].readx.in.offset = gen_offset();
1359 parm[0].readx.in.mincnt = gen_io_count();
1360 parm[0].readx.in.maxcnt = gen_io_count();
1361 parm[0].readx.in.remaining = gen_io_count();
1362 parm[0].readx.in.read_for_execute = gen_bool();
1363 parm[0].readx.out.data = talloc_array(current_op.mem_ctx, uint8_t,
1364 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1367 GEN_SET_FNUM(readx.in.file.fnum);
1368 GEN_CALL(smb_raw_read(tree, &parm[i]));
1370 CHECK_EQUAL(readx.out.remaining);
1371 CHECK_EQUAL(readx.out.compaction_mode);
1372 CHECK_EQUAL(readx.out.nread);
1378 generate writex operations
1380 static bool handler_writex(int instance)
1382 union smb_write parm[NSERVERS];
1383 NTSTATUS status[NSERVERS];
1385 parm[0].writex.level = RAW_WRITE_WRITEX;
1386 parm[0].writex.in.file.fnum = gen_fnum(instance);
1387 parm[0].writex.in.offset = gen_offset();
1388 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1389 parm[0].writex.in.remaining = gen_io_count();
1390 parm[0].writex.in.count = gen_io_count();
1391 parm[0].writex.in.data = talloc_zero_array(current_op.mem_ctx, uint8_t, parm[0].writex.in.count);
1394 GEN_SET_FNUM(writex.in.file.fnum);
1395 GEN_CALL(smb_raw_write(tree, &parm[i]));
1397 CHECK_EQUAL(writex.out.nwritten);
1398 CHECK_EQUAL(writex.out.remaining);
1404 generate lockingx operations
1406 static bool handler_lockingx(int instance)
1408 union smb_lock parm[NSERVERS];
1409 NTSTATUS status[NSERVERS];
1412 parm[0].lockx.level = RAW_LOCK_LOCKX;
1413 parm[0].lockx.in.file.fnum = gen_fnum(instance);
1414 parm[0].lockx.in.mode = gen_lock_mode();
1415 parm[0].lockx.in.timeout = gen_timeout();
1417 /* make sure we don't accidentially generate an oplock
1418 break ack - otherwise the server can just block forever */
1419 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1420 parm[0].lockx.in.lock_cnt = gen_lock_count();
1421 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1422 } while (nlocks == 0);
1425 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1426 struct smb_lock_entry,
1428 for (n=0;n<nlocks;n++) {
1429 parm[0].lockx.in.locks[n].pid = gen_pid();
1430 parm[0].lockx.in.locks[n].offset = gen_offset();
1431 parm[0].lockx.in.locks[n].count = gen_io_count();
1436 GEN_SET_FNUM(lockx.in.file.fnum);
1437 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1443 generate a fileinfo query structure
1445 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1448 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1450 enum smb_fileinfo_level level;
1453 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1454 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1455 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1456 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1457 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1458 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1459 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1460 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1461 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1462 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1465 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1466 } while (ignore_pattern(levels[i].name));
1468 info->generic.level = levels[i].level;
1472 compare returned fileinfo structures
1474 static bool cmp_fileinfo(int instance,
1475 union smb_fileinfo parm[NSERVERS],
1476 NTSTATUS status[NSERVERS])
1480 switch (parm[0].generic.level) {
1481 case RAW_FILEINFO_GENERIC:
1484 case RAW_FILEINFO_GETATTR:
1485 CHECK_EQUAL(getattr.out.attrib);
1486 CHECK_EQUAL(getattr.out.size);
1487 CHECK_TIMES_EQUAL(getattr.out.write_time);
1490 case RAW_FILEINFO_GETATTRE:
1491 CHECK_TIMES_EQUAL(getattre.out.create_time);
1492 CHECK_TIMES_EQUAL(getattre.out.access_time);
1493 CHECK_TIMES_EQUAL(getattre.out.write_time);
1494 CHECK_EQUAL(getattre.out.size);
1495 CHECK_EQUAL(getattre.out.alloc_size);
1496 CHECK_EQUAL(getattre.out.attrib);
1499 case RAW_FILEINFO_STANDARD:
1500 CHECK_TIMES_EQUAL(standard.out.create_time);
1501 CHECK_TIMES_EQUAL(standard.out.access_time);
1502 CHECK_TIMES_EQUAL(standard.out.write_time);
1503 CHECK_EQUAL(standard.out.size);
1504 CHECK_EQUAL(standard.out.alloc_size);
1505 CHECK_EQUAL(standard.out.attrib);
1508 case RAW_FILEINFO_EA_SIZE:
1509 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1510 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1511 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1512 CHECK_EQUAL(ea_size.out.size);
1513 CHECK_EQUAL(ea_size.out.alloc_size);
1514 CHECK_EQUAL(ea_size.out.attrib);
1515 CHECK_EQUAL(ea_size.out.ea_size);
1518 case RAW_FILEINFO_ALL_EAS:
1519 CHECK_EQUAL(all_eas.out.num_eas);
1520 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1521 CHECK_EQUAL(all_eas.out.eas[i].flags);
1522 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1523 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1527 case RAW_FILEINFO_IS_NAME_VALID:
1530 case RAW_FILEINFO_BASIC_INFO:
1531 case RAW_FILEINFO_BASIC_INFORMATION:
1532 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1533 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1534 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1535 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1536 CHECK_EQUAL(basic_info.out.attrib);
1539 case RAW_FILEINFO_STANDARD_INFO:
1540 case RAW_FILEINFO_STANDARD_INFORMATION:
1541 CHECK_EQUAL(standard_info.out.alloc_size);
1542 CHECK_EQUAL(standard_info.out.size);
1543 CHECK_EQUAL(standard_info.out.nlink);
1544 CHECK_EQUAL(standard_info.out.delete_pending);
1545 CHECK_EQUAL(standard_info.out.directory);
1548 case RAW_FILEINFO_EA_INFO:
1549 case RAW_FILEINFO_EA_INFORMATION:
1550 CHECK_EQUAL(ea_info.out.ea_size);
1553 case RAW_FILEINFO_NAME_INFO:
1554 case RAW_FILEINFO_NAME_INFORMATION:
1555 CHECK_WSTR_EQUAL(name_info.out.fname);
1558 case RAW_FILEINFO_ALL_INFO:
1559 case RAW_FILEINFO_ALL_INFORMATION:
1560 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1561 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1562 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1563 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1564 CHECK_EQUAL(all_info.out.attrib);
1565 CHECK_EQUAL(all_info.out.alloc_size);
1566 CHECK_EQUAL(all_info.out.size);
1567 CHECK_EQUAL(all_info.out.nlink);
1568 CHECK_EQUAL(all_info.out.delete_pending);
1569 CHECK_EQUAL(all_info.out.directory);
1570 CHECK_EQUAL(all_info.out.ea_size);
1571 CHECK_WSTR_EQUAL(all_info.out.fname);
1574 case RAW_FILEINFO_ALT_NAME_INFO:
1575 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1576 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1579 case RAW_FILEINFO_STREAM_INFO:
1580 case RAW_FILEINFO_STREAM_INFORMATION:
1581 CHECK_EQUAL(stream_info.out.num_streams);
1582 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1583 CHECK_EQUAL(stream_info.out.streams[i].size);
1584 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1585 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1589 case RAW_FILEINFO_COMPRESSION_INFO:
1590 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1591 CHECK_EQUAL(compression_info.out.compressed_size);
1592 CHECK_EQUAL(compression_info.out.format);
1593 CHECK_EQUAL(compression_info.out.unit_shift);
1594 CHECK_EQUAL(compression_info.out.chunk_shift);
1595 CHECK_EQUAL(compression_info.out.cluster_shift);
1598 case RAW_FILEINFO_INTERNAL_INFORMATION:
1599 CHECK_EQUAL(internal_information.out.file_id);
1602 case RAW_FILEINFO_ACCESS_INFORMATION:
1603 CHECK_EQUAL(access_information.out.access_flags);
1606 case RAW_FILEINFO_POSITION_INFORMATION:
1607 CHECK_EQUAL(position_information.out.position);
1610 case RAW_FILEINFO_MODE_INFORMATION:
1611 CHECK_EQUAL(mode_information.out.mode);
1614 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1615 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1618 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1619 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1620 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1621 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1622 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1623 CHECK_EQUAL(network_open_information.out.alloc_size);
1624 CHECK_EQUAL(network_open_information.out.size);
1625 CHECK_EQUAL(network_open_information.out.attrib);
1628 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1629 CHECK_EQUAL(attribute_tag_information.out.attrib);
1630 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1633 /* Unhandled levels */
1635 case RAW_FILEINFO_SEC_DESC:
1636 case RAW_FILEINFO_EA_LIST:
1637 case RAW_FILEINFO_UNIX_BASIC:
1638 case RAW_FILEINFO_UNIX_LINK:
1639 case RAW_FILEINFO_SMB2_ALL_EAS:
1640 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1648 generate qpathinfo operations
1650 static bool handler_qpathinfo(int instance)
1652 union smb_fileinfo parm[NSERVERS];
1653 NTSTATUS status[NSERVERS];
1655 parm[0].generic.in.file.path = gen_fname_open(instance);
1657 gen_fileinfo(instance, &parm[0]);
1660 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1662 return cmp_fileinfo(instance, parm, status);
1666 generate qfileinfo operations
1668 static bool handler_qfileinfo(int instance)
1670 union smb_fileinfo parm[NSERVERS];
1671 NTSTATUS status[NSERVERS];
1673 parm[0].generic.in.file.fnum = gen_fnum(instance);
1675 gen_fileinfo(instance, &parm[0]);
1678 GEN_SET_FNUM(generic.in.file.fnum);
1679 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1681 return cmp_fileinfo(instance, parm, status);
1686 generate a fileinfo query structure
1688 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1692 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1694 enum smb_setfileinfo_level level;
1698 /* disabled until win2003 can handle them ... */
1699 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1700 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1702 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1703 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1704 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1705 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1706 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1709 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1710 } while (ignore_pattern(levels[i].name));
1712 info->generic.level = levels[i].level;
1714 switch (info->generic.level) {
1715 case RAW_SFILEINFO_SETATTR:
1716 info->setattr.in.attrib = gen_attrib();
1717 info->setattr.in.write_time = gen_timet();
1719 case RAW_SFILEINFO_SETATTRE:
1720 info->setattre.in.create_time = gen_timet();
1721 info->setattre.in.access_time = gen_timet();
1722 info->setattre.in.write_time = gen_timet();
1724 case RAW_SFILEINFO_STANDARD:
1725 info->standard.in.create_time = gen_timet();
1726 info->standard.in.access_time = gen_timet();
1727 info->standard.in.write_time = gen_timet();
1729 case RAW_SFILEINFO_EA_SET: {
1730 static struct ea_struct ea;
1731 info->ea_set.in.num_eas = 1;
1732 info->ea_set.in.eas = &ea;
1733 info->ea_set.in.eas[0] = gen_ea_struct();
1736 case RAW_SFILEINFO_BASIC_INFO:
1737 case RAW_SFILEINFO_BASIC_INFORMATION:
1738 info->basic_info.in.create_time = gen_nttime();
1739 info->basic_info.in.access_time = gen_nttime();
1740 info->basic_info.in.write_time = gen_nttime();
1741 info->basic_info.in.change_time = gen_nttime();
1742 info->basic_info.in.attrib = gen_attrib();
1744 case RAW_SFILEINFO_DISPOSITION_INFO:
1745 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1746 info->disposition_info.in.delete_on_close = gen_bool();
1748 case RAW_SFILEINFO_ALLOCATION_INFO:
1749 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1750 info->allocation_info.in.alloc_size = gen_alloc_size();
1752 case RAW_SFILEINFO_END_OF_FILE_INFO:
1753 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1754 info->end_of_file_info.in.size = gen_offset();
1756 case RAW_SFILEINFO_RENAME_INFORMATION:
1757 info->rename_information.in.overwrite = gen_bool();
1758 info->rename_information.in.root_fid = gen_root_fid(instance);
1759 info->rename_information.in.new_name = gen_fname_open(instance);
1761 case RAW_SFILEINFO_POSITION_INFORMATION:
1762 info->position_information.in.position = gen_offset();
1764 case RAW_SFILEINFO_MODE_INFORMATION:
1765 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1767 case RAW_SFILEINFO_GENERIC:
1768 case RAW_SFILEINFO_SEC_DESC:
1769 case RAW_SFILEINFO_UNIX_BASIC:
1770 case RAW_SFILEINFO_UNIX_LINK:
1771 case RAW_SFILEINFO_UNIX_HLINK:
1772 case RAW_SFILEINFO_1023:
1773 case RAW_SFILEINFO_1025:
1774 case RAW_SFILEINFO_1029:
1775 case RAW_SFILEINFO_1032:
1776 case RAW_SFILEINFO_1039:
1777 case RAW_SFILEINFO_1040:
1784 generate setpathinfo operations
1786 static bool handler_spathinfo(int instance)
1788 union smb_setfileinfo parm[NSERVERS];
1789 NTSTATUS status[NSERVERS];
1791 parm[0].generic.in.file.path = gen_fname_open(instance);
1793 gen_setfileinfo(instance, &parm[0]);
1797 /* a special case for the fid in a RENAME */
1798 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1799 parm[0].rename_information.in.root_fid != 0) {
1800 GEN_SET_FNUM(rename_information.in.root_fid);
1803 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1810 generate setfileinfo operations
1812 static bool handler_sfileinfo(int instance)
1814 union smb_setfileinfo parm[NSERVERS];
1815 NTSTATUS status[NSERVERS];
1817 parm[0].generic.in.file.fnum = gen_fnum(instance);
1819 gen_setfileinfo(instance, &parm[0]);
1822 GEN_SET_FNUM(generic.in.file.fnum);
1823 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1830 generate change notify operations
1832 static bool handler_notify(int instance)
1834 union smb_notify parm[NSERVERS];
1837 ZERO_STRUCT(parm[0]);
1838 parm[0].nttrans.level = RAW_NOTIFY_NTTRANS;
1839 parm[0].nttrans.in.buffer_size = gen_io_count();
1840 parm[0].nttrans.in.completion_filter = gen_bits_mask(0xFF);
1841 parm[0].nttrans.in.file.fnum = gen_fnum(instance);
1842 parm[0].nttrans.in.recursive = gen_bool();
1845 GEN_SET_FNUM(nttrans.in.file.fnum);
1847 for (n=0;n<NSERVERS;n++) {
1848 struct smbcli_request *req;
1849 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1850 req->async.fn = async_notify;
1857 wipe any relevant files
1859 static void wipe_files(void)
1862 for (i=0;i<NSERVERS;i++) {
1863 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1865 printf("Failed to wipe tree on server %d\n", i);
1868 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1869 printf("Failed to create \\gentest - %s\n",
1870 smbcli_errstr(servers[i].cli[0]->tree));
1874 printf("Deleted %d files on server %d\n", n, i);
1880 dump the current seeds - useful for continuing a backtrack
1882 static void dump_seeds(void)
1887 if (!options.seeds_file) {
1890 f = fopen("seeds.tmp", "w");
1893 for (i=0;i<options.numops;i++) {
1894 fprintf(f, "%u\n", op_parms[i].seed);
1897 rename("seeds.tmp", options.seeds_file);
1903 the list of top-level operations that we will generate
1907 bool (*handler)(int instance);
1908 int count, success_count;
1910 {"OPEN", handler_open},
1911 {"OPENX", handler_openx},
1912 {"NTCREATEX", handler_ntcreatex},
1913 {"CLOSE", handler_close},
1914 {"UNLINK", handler_unlink},
1915 {"MKDIR", handler_mkdir},
1916 {"RMDIR", handler_rmdir},
1917 {"RENAME", handler_rename},
1918 {"NTRENAME", handler_ntrename},
1919 {"READX", handler_readx},
1920 {"WRITEX", handler_writex},
1921 {"CHKPATH", handler_chkpath},
1922 {"LOCKINGX", handler_lockingx},
1923 {"QPATHINFO", handler_qpathinfo},
1924 {"QFILEINFO", handler_qfileinfo},
1925 {"SPATHINFO", handler_spathinfo},
1926 {"SFILEINFO", handler_sfileinfo},
1927 {"NOTIFY", handler_notify},
1928 {"SEEK", handler_seek},
1933 run the test with the current set of op_parms parameters
1934 return the number of operations that completed successfully
1936 static int run_test(struct loadparm_context *lp_ctx)
1940 if (!connect_servers(lp_ctx)) {
1941 printf("Failed to connect to servers\n");
1947 /* wipe any leftover files from old runs */
1950 /* reset the open handles array */
1951 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1952 num_open_handles = 0;
1954 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1955 gen_ops[i].count = 0;
1956 gen_ops[i].success_count = 0;
1959 for (op=0; op<options.numops; op++) {
1960 int instance, which_op;
1963 if (op_parms[op].disabled) continue;
1965 srandom(op_parms[op].seed);
1967 instance = gen_int_range(0, NINSTANCES-1);
1969 /* generate a non-ignored operation */
1971 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1972 } while (ignore_pattern(gen_ops[which_op].name));
1974 DEBUG(3,("Generating op %s on instance %d\n",
1975 gen_ops[which_op].name, instance));
1977 current_op.seed = op_parms[op].seed;
1978 current_op.opnum = op;
1979 current_op.name = gen_ops[which_op].name;
1980 current_op.status = NT_STATUS_OK;
1981 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1983 ret = gen_ops[which_op].handler(instance);
1985 talloc_free(current_op.mem_ctx);
1987 gen_ops[which_op].count++;
1988 if (NT_STATUS_IS_OK(current_op.status)) {
1989 gen_ops[which_op].success_count++;
1993 printf("Failed at operation %d - %s\n",
1994 op, gen_ops[which_op].name);
1998 if (op % 100 == 0) {
2003 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2004 printf("Op %-10s got %d/%d success\n",
2006 gen_ops[i].success_count,
2014 perform a backtracking analysis of the minimal set of operations
2015 to generate an error
2017 static void backtrack_analyze(struct loadparm_context *lp_ctx)
2021 chunk = options.numops / 2;
2026 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2029 chunk = MIN(chunk, options.numops / 2);
2031 /* mark this range as disabled */
2032 max = MIN(options.numops, base+chunk);
2033 for (i=base;i<max; i++) {
2034 op_parms[i].disabled = true;
2036 printf("Testing %d ops with %d-%d disabled\n",
2037 options.numops, base, max-1);
2038 ret = run_test(lp_ctx);
2039 printf("Completed %d of %d ops\n", ret, options.numops);
2040 for (i=base;i<max; i++) {
2041 op_parms[i].disabled = false;
2043 if (ret == options.numops) {
2044 /* this chunk is needed */
2046 } else if (ret < base) {
2047 printf("damn - inconsistent errors! found early error\n");
2048 options.numops = ret+1;
2051 /* it failed - this chunk isn't needed for a failure */
2052 memmove(&op_parms[base], &op_parms[max],
2053 sizeof(op_parms[0]) * (options.numops - max));
2054 options.numops = (ret+1) - (max - base);
2064 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2067 } while (chunk > 0);
2069 printf("Reduced to %d ops\n", options.numops);
2070 ret = run_test(lp_ctx);
2071 if (ret != options.numops - 1) {
2072 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2077 start the main gentest process
2079 static bool start_gentest(struct loadparm_context *lp_ctx)
2084 /* allocate the open_handles array */
2085 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2087 srandom(options.seed);
2088 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2090 /* generate the seeds - after this everything is deterministic */
2091 if (options.use_preset_seeds) {
2093 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
2095 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2098 if (numops < options.numops) {
2099 options.numops = numops;
2101 for (op=0;op<options.numops;op++) {
2103 printf("Not enough seeds in %s\n", options.seeds_file);
2106 op_parms[op].seed = atoi(preset[op]);
2108 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2110 for (op=0; op<options.numops; op++) {
2111 op_parms[op].seed = random();
2115 ret = run_test(lp_ctx);
2117 if (ret != options.numops && options.analyze) {
2118 options.numops = ret+1;
2119 backtrack_analyze(lp_ctx);
2120 } else if (options.analyze_always) {
2121 backtrack_analyze(lp_ctx);
2122 } else if (options.analyze_continuous) {
2123 while (run_test(lp_ctx) == options.numops) ;
2126 return ret == options.numops;
2130 static void usage(void)
2134 gentest2 //server1/share1 //server2/share2 [options..]\n\
2136 -U user%%pass (can be specified twice)\n\
2139 -a (show all ops)\n\
2140 -A backtrack to find minimal ops\n\
2141 -i FILE add a list of wildcard exclusions\n\
2142 -O enable oplocks\n\
2143 -S FILE set preset seeds file\n\
2144 -L use preset seeds\n\
2145 -F fast reconnect (just close files)\n\
2146 -C continuous analysis mode\n\
2147 -X analyse even when test OK\n\
2152 split a UNC name into server and share names
2154 static bool split_unc_name(const char *unc, char **server, char **share)
2156 char *p = strdup(unc);
2157 if (!p) return false;
2158 all_string_sub(p, "\\", "/", 0);
2159 if (strncmp(p, "//", 2) != 0) return false;
2162 p = strchr(*server, '/');
2163 if (!p) return false;
2173 /****************************************************************************
2175 ****************************************************************************/
2176 int main(int argc, char *argv[])
2179 int i, username_count=0;
2181 struct loadparm_context *lp_ctx;
2185 setup_logging("gentest", DEBUG_STDOUT);
2187 if (argc < 3 || argv[1][0] == '-') {
2192 setup_logging(argv[0], DEBUG_STDOUT);
2194 for (i=0;i<NSERVERS;i++) {
2195 const char *share = argv[1+i];
2196 servers[i].credentials = cli_credentials_init(NULL);
2197 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2198 printf("Invalid share name '%s'\n", share);
2206 lp_ctx = loadparm_init(talloc_autofree_context());
2207 lp_load(lp_ctx, dyn_CONFIGFILE);
2209 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
2210 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
2211 cli_credentials_guess(servers[0].credentials, lp_ctx);
2212 cli_credentials_guess(servers[1].credentials, lp_ctx);
2214 options.seed = time(NULL);
2215 options.numops = 1000;
2216 options.max_open_handles = 20;
2217 options.seeds_file = "gentest_seeds.dat";
2219 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2222 if (username_count == 2) {
2226 cli_credentials_parse_string(servers[username_count].credentials,
2227 optarg, CRED_SPECIFIED);
2231 DEBUGLEVEL = atoi(optarg);
2232 setup_logging(NULL, DEBUG_STDOUT);
2235 options.seed = atoi(optarg);
2238 options.seeds_file = optarg;
2241 options.use_preset_seeds = true;
2244 options.fast_reconnect = true;
2247 options.numops = atoi(optarg);
2250 options.use_oplocks = true;
2253 options.showall = true;
2256 options.analyze = true;
2259 options.analyze_always = true;
2262 options.analyze_continuous = true;
2265 options.ignore_patterns = file_lines_load(optarg, NULL, NULL);
2271 printf("Unknown option %c (%d)\n", (char)opt, opt);
2276 gensec_init(lp_ctx);
2278 if (username_count == 0) {
2282 if (username_count == 1) {
2283 servers[1].credentials = servers[0].credentials;
2286 printf("seed=%u\n", options.seed);
2288 ret = start_gentest(lp_ctx);
2291 printf("gentest completed - no errors\n");
2293 printf("gentest failed\n");