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 "lib/cmdline/popt_common.h"
22 #include "lib/events/events.h"
23 #include "system/time.h"
24 #include "system/filesys.h"
25 #include "libcli/raw/request.h"
26 #include "libcli/libcli.h"
27 #include "libcli/raw/libcliraw.h"
28 #include "librpc/gen_ndr/security.h"
29 #include "auth/credentials/credentials.h"
30 #include "libcli/resolve/resolve.h"
31 #include "auth/gensec/gensec.h"
32 #include "param/param.h"
33 #include "dynconfig/dynconfig.h"
39 static struct gentest_options {
43 int analyze_continuous;
44 uint_t max_open_handles;
48 char **ignore_patterns;
49 const char *seeds_file;
55 /* mapping between open handles on the server and local handles */
59 uint_t server_fnum[NSERVERS];
62 static uint_t num_open_handles;
64 /* state information for the servers. We open NINSTANCES connections to
67 struct smbcli_state *cli[NINSTANCES];
70 struct cli_credentials *credentials;
73 /* the seeds and flags for each operation */
80 /* oplock break info */
87 } oplocks[NSERVERS][NINSTANCES];
89 /* change notify reply info */
93 union smb_notify notify;
94 } notifies[NSERVERS][NINSTANCES];
96 /* info relevant to the current operation */
107 #define BAD_HANDLE 0xFFFE
109 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
110 static void idle_func(struct smbcli_transport *transport, void *private);
113 check if a string should be ignored. This is used as the basis
114 for all error ignore settings
116 static bool ignore_pattern(const char *str)
119 if (!options.ignore_patterns) return false;
121 for (i=0;options.ignore_patterns[i];i++) {
122 if (strcmp(options.ignore_patterns[i], str) == 0 ||
123 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
124 DEBUG(2,("Ignoring '%s'\n", str));
131 /*****************************************************
132 connect to the servers
133 *******************************************************/
134 static bool connect_servers_fast(void)
138 /* close all open files */
139 for (h=0;h<options.max_open_handles;h++) {
140 if (!open_handles[h].active) continue;
141 for (i=0;i<NSERVERS;i++) {
142 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
143 open_handles[h].server_fnum[i])))) {
146 open_handles[h].active = false;
156 /*****************************************************
157 connect to the servers
158 *******************************************************/
159 static bool connect_servers(struct event_context *ev,
160 struct loadparm_context *lp_ctx)
164 if (options.fast_reconnect && servers[0].cli[0]) {
165 if (connect_servers_fast()) {
170 /* close any existing connections */
171 for (i=0;i<NSERVERS;i++) {
172 for (j=0;j<NINSTANCES;j++) {
173 if (servers[i].cli[j]) {
174 smbcli_tdis(servers[i].cli[j]);
175 talloc_free(servers[i].cli[j]);
176 servers[i].cli[j] = NULL;
181 for (i=0;i<NSERVERS;i++) {
182 for (j=0;j<NINSTANCES;j++) {
183 struct smbcli_options smb_options;
185 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
186 servers[i].server_name, servers[i].share_name,
187 servers[i].credentials->username, j);
189 cli_credentials_set_workstation(servers[i].credentials,
190 "gentest", CRED_SPECIFIED);
192 lp_smbcli_options(lp_ctx, &smb_options);
193 status = smbcli_full_connection(NULL, &servers[i].cli[j],
194 servers[i].server_name,
195 lp_smb_ports(lp_ctx),
196 servers[i].share_name, NULL,
197 servers[i].credentials,
198 lp_resolve_context(lp_ctx),
200 if (!NT_STATUS_IS_OK(status)) {
201 printf("Failed to connect to \\\\%s\\%s - %s\n",
202 servers[i].server_name, servers[i].share_name,
207 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
208 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
216 work out the time skew between the servers - be conservative
218 static uint_t time_skew(void)
221 ret = labs(servers[0].cli[0]->transport->negotiate.server_time -
222 servers[1].cli[0]->transport->negotiate.server_time);
227 turn an fnum for an instance into a handle
229 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
232 for (i=0;i<options.max_open_handles;i++) {
233 if (!open_handles[i].active ||
234 instance != open_handles[i].instance) continue;
235 if (open_handles[i].server_fnum[server] == fnum) {
239 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
240 fnum, server, instance);
245 add some newly opened handles
247 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
250 for (h=0;h<options.max_open_handles;h++) {
251 if (!open_handles[h].active) break;
253 if (h == options.max_open_handles) {
254 /* we have to force close a random handle */
255 h = random() % options.max_open_handles;
256 for (i=0;i<NSERVERS;i++) {
257 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
258 open_handles[h].server_fnum[i])))) {
259 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
260 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
263 printf("Recovered handle %d\n", h);
266 for (i=0;i<NSERVERS;i++) {
267 open_handles[h].server_fnum[i] = fnums[i];
268 open_handles[h].instance = instance;
269 open_handles[h].active = true;
270 open_handles[h].name = name;
274 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
276 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
281 remove a closed handle
283 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
286 for (h=0;h<options.max_open_handles;h++) {
287 if (instance == open_handles[h].instance &&
288 open_handles[h].server_fnum[0] == fnums[0]) {
289 open_handles[h].active = false;
291 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
293 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
294 open_handles[h].name);
298 printf("Removing invalid handle!?\n");
303 return true with 'chance' probability as a percentage
305 static bool gen_chance(uint_t chance)
307 return ((random() % 100) <= chance);
311 map an internal handle number to a server fnum
313 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
315 if (handle == BAD_HANDLE) return handle;
316 return open_handles[handle].server_fnum[server];
322 static uint16_t gen_fnum(int instance)
327 if (gen_chance(20)) return BAD_HANDLE;
329 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
330 h = random() % options.max_open_handles;
331 if (open_handles[h].active &&
332 open_handles[h].instance == instance) {
340 return a file handle, but skewed so we don't close the last
341 couple of handles too readily
343 static uint16_t gen_fnum_close(int instance)
345 if (num_open_handles < 3) {
346 if (gen_chance(80)) return BAD_HANDLE;
349 return gen_fnum(instance);
353 generate an integer in a specified range
355 static int gen_int_range(uint_t min, uint_t max)
358 return min + (r % (1+max-min));
362 return a fnum for use as a root fid
363 be careful to call GEN_SET_FNUM() when you use this!
365 static uint16_t gen_root_fid(int instance)
367 if (gen_chance(5)) return gen_fnum(instance);
372 generate a file offset
374 static int gen_offset(void)
376 if (gen_chance(20)) return 0;
377 return gen_int_range(0, 1024*1024);
383 static int gen_io_count(void)
385 if (gen_chance(20)) return 0;
386 return gen_int_range(0, 4096);
392 static const char *gen_fname(void)
394 const char *names[] = {"\\gentest\\gentest.dat",
396 "\\gentest\\foo2.sym",
397 "\\gentest\\foo3.dll",
399 "\\gentest\\foo4:teststream1",
400 "\\gentest\\foo4:teststream2",
401 "\\gentest\\foo5.exe",
402 "\\gentest\\foo5.exe:teststream3",
403 "\\gentest\\foo5.exe:teststream4",
404 "\\gentest\\foo6.com",
406 "\\gentest\\blah\\blergh.txt",
407 "\\gentest\\blah\\blergh2",
408 "\\gentest\\blah\\blergh3.txt",
409 "\\gentest\\blah\\blergh4",
410 "\\gentest\\blah\\blergh5.txt",
411 "\\gentest\\blah\\blergh5",
412 "\\gentest\\blah\\.",
414 /* this causes problem with w2k3 */
415 "\\gentest\\blah\\..",
417 "\\gentest\\a_very_long_name.bin",
423 i = gen_int_range(0, ARRAY_SIZE(names)-1);
424 } while (ignore_pattern(names[i]));
430 generate a filename with a higher chance of choosing an already
433 static const char *gen_fname_open(int instance)
436 h = gen_fnum(instance);
437 if (h == BAD_HANDLE) {
440 return open_handles[h].name;
444 generate a wildcard pattern
446 static const char *gen_pattern(void)
449 const char *names[] = {"\\gentest\\*.dat",
452 "\\gentest\\blah\\*.*",
453 "\\gentest\\blah\\*",
456 if (gen_chance(50)) return gen_fname();
459 i = gen_int_range(0, ARRAY_SIZE(names)-1);
460 } while (ignore_pattern(names[i]));
468 static uint32_t gen_bits_mask(uint_t mask)
470 uint_t ret = random();
475 generate a bitmask with high probability of the first mask
476 and low of the second
478 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
480 if (gen_chance(10)) return gen_bits_mask(mask2);
481 return gen_bits_mask(mask1);
487 static bool gen_bool(void)
489 return gen_bits_mask2(0x1, 0xFF);
493 generate ntrename flags
495 static uint16_t gen_rename_flags(void)
497 if (gen_chance(30)) return RENAME_FLAG_RENAME;
498 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
499 if (gen_chance(30)) return RENAME_FLAG_COPY;
500 return gen_bits_mask(0xFFFF);
505 return a lockingx lock mode
507 static uint16_t gen_lock_mode(void)
509 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
510 if (gen_chance(20)) return gen_bits_mask(0x1F);
511 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
517 static uint16_t gen_pid(void)
519 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
524 generate a lock count
526 static off_t gen_lock_count(void)
528 return gen_int_range(0, 3);
532 generate a ntcreatex flags field
534 static uint32_t gen_ntcreatex_flags(void)
536 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
537 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
541 generate a NT access mask
543 static uint32_t gen_access_mask(void)
545 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
546 if (gen_chance(20)) return SEC_FILE_ALL;
547 return gen_bits_mask(0xFFFFFFFF);
551 generate a ntcreatex create options bitfield
553 static uint32_t gen_create_options(void)
555 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
556 if (gen_chance(50)) return 0;
557 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
561 generate a ntcreatex open disposition
563 static uint32_t gen_open_disp(void)
565 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
566 return gen_int_range(0, 5);
570 generate an openx open mode
572 static uint16_t gen_openx_mode(void)
574 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
575 if (gen_chance(20)) return gen_bits_mask(0xFF);
576 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
580 generate an openx flags field
582 static uint16_t gen_openx_flags(void)
584 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
585 return gen_bits_mask(0x7);
589 generate an openx open function
591 static uint16_t gen_openx_func(void)
593 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
594 return gen_bits_mask(0x13);
598 generate a file attrib combination
600 static uint32_t gen_attrib(void)
602 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
603 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
607 generate a unix timestamp
609 static time_t gen_timet(void)
611 if (gen_chance(30)) return 0;
612 return (time_t)random();
616 generate a unix timestamp
618 static NTTIME gen_nttime(void)
621 unix_to_nt_time(&ret, gen_timet());
626 generate a milliseconds protocol timeout
628 static uint32_t gen_timeout(void)
630 if (gen_chance(98)) return 0;
631 return random() % 50;
635 generate a file allocation size
637 static uint_t gen_alloc_size(void)
641 if (gen_chance(30)) return 0;
643 ret = random() % 4*1024*1024;
644 /* give a high chance of a round number */
645 if (gen_chance(60)) {
646 ret &= ~(1024*1024 - 1);
652 generate an ea_struct
654 static struct ea_struct gen_ea_struct(void)
657 const char *names[] = {"EAONE",
662 "AVERYLONGATTRIBUTENAME"};
663 const char *values[] = {"VALUE1",
668 "ASOMEWHATLONGERATTRIBUTEVALUE"};
674 i = gen_int_range(0, ARRAY_SIZE(names)-1);
675 } while (ignore_pattern(names[i]));
677 ea.name.s = names[i];
680 i = gen_int_range(0, ARRAY_SIZE(values)-1);
681 } while (ignore_pattern(values[i]));
683 ea.value = data_blob(values[i], strlen(values[i]));
685 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
693 this is called when a change notify reply comes in
695 static void async_notify(struct smbcli_request *req)
697 union smb_notify notify;
701 struct smbcli_transport *transport = req->transport;
703 tid = SVAL(req->in.hdr, HDR_TID);
705 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
706 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
707 if (NT_STATUS_IS_OK(status)) {
708 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
710 notify.nttrans.out.num_changes,
711 notify.nttrans.out.changes[0].action,
712 notify.nttrans.out.changes[0].name.s);
715 for (i=0;i<NSERVERS;i++) {
716 for (j=0;j<NINSTANCES;j++) {
717 if (transport == servers[i].cli[j]->transport &&
718 tid == servers[i].cli[j]->tree->tid) {
719 notifies[i][j].notify_count++;
720 notifies[i][j].status = status;
721 notifies[i][j].notify = notify;
727 static void oplock_handler_close_recv(struct smbcli_request *req)
730 status = smbcli_request_simple_recv(req);
731 if (!NT_STATUS_IS_OK(status)) {
732 printf("close failed in oplock_handler\n");
733 smb_panic("close failed in oplock_handler");
738 the oplock handler will either ack the break or close the file
740 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
745 struct smbcli_tree *tree = NULL;
746 struct smbcli_request *req;
748 srandom(current_op.seed);
749 do_close = gen_chance(50);
751 for (i=0;i<NSERVERS;i++) {
752 for (j=0;j<NINSTANCES;j++) {
753 if (transport == servers[i].cli[j]->transport &&
754 tid == servers[i].cli[j]->tree->tid) {
755 oplocks[i][j].got_break = true;
756 oplocks[i][j].fnum = fnum;
757 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
758 oplocks[i][j].level = level;
759 oplocks[i][j].do_close = do_close;
760 tree = servers[i].cli[j]->tree;
766 printf("Oplock break not for one of our trees!?\n");
771 printf("oplock ack fnum=%d\n", fnum);
772 return smbcli_oplock_ack(tree, fnum, level);
775 printf("oplock close fnum=%d\n", fnum);
777 io.close.level = RAW_CLOSE_CLOSE;
778 io.close.in.file.fnum = fnum;
779 io.close.in.write_time = 0;
780 req = smb_raw_close_send(tree, &io);
783 printf("WARNING: close failed in oplock_handler_close\n");
787 req->async.fn = oplock_handler_close_recv;
788 req->async.private = NULL;
795 the idle function tries to cope with getting an oplock break on a connection, and
796 an operation on another connection blocking until that break is acked
797 we check for operations on all transports in the idle function
799 static void idle_func(struct smbcli_transport *transport, void *private)
802 for (i=0;i<NSERVERS;i++) {
803 for (j=0;j<NINSTANCES;j++) {
804 if (servers[i].cli[j] &&
805 transport != servers[i].cli[j]->transport) {
806 smbcli_transport_process(servers[i].cli[j]->transport);
815 compare NTSTATUS, using checking ignored patterns
817 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
819 if (NT_STATUS_EQUAL(status1, status2)) return true;
821 /* one code being an error and the other OK is always an error */
822 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return false;
824 /* if we are ignoring one of the status codes then consider this a match */
825 if (ignore_pattern(nt_errstr(status1)) ||
826 ignore_pattern(nt_errstr(status2))) {
834 check for pending packets on all connections
836 static void check_pending(void)
842 for (j=0;j<NINSTANCES;j++) {
843 for (i=0;i<NSERVERS;i++) {
844 smbcli_transport_process(servers[i].cli[j]->transport);
850 check that the same oplock breaks have been received by all instances
852 static bool check_oplocks(const char *call)
860 for (j=0;j<NINSTANCES;j++) {
861 for (i=1;i<NSERVERS;i++) {
862 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
863 oplocks[0][j].handle != oplocks[i][j].handle ||
864 oplocks[0][j].level != oplocks[i][j].level) {
865 if (tries++ < 10) goto again;
866 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
867 oplocks[0][j].got_break,
868 oplocks[0][j].handle,
870 oplocks[i][j].got_break,
871 oplocks[i][j].handle,
872 oplocks[i][j].level);
878 /* if we got a break and closed then remove the handle */
879 for (j=0;j<NINSTANCES;j++) {
880 if (oplocks[0][j].got_break &&
881 oplocks[0][j].do_close) {
882 uint16_t fnums[NSERVERS];
883 for (i=0;i<NSERVERS;i++) {
884 fnums[i] = oplocks[i][j].fnum;
886 gen_remove_handle(j, fnums);
895 check that the same change notify info has been received by all instances
897 static bool check_notifies(const char *call)
905 for (j=0;j<NINSTANCES;j++) {
906 for (i=1;i<NSERVERS;i++) {
908 union smb_notify not1, not2;
910 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
911 if (tries++ < 10) goto again;
912 printf("Notify count inconsistent %d %d\n",
913 notifies[0][j].notify_count,
914 notifies[i][j].notify_count);
918 if (notifies[0][j].notify_count == 0) continue;
920 if (!NT_STATUS_EQUAL(notifies[0][j].status,
921 notifies[i][j].status)) {
922 printf("Notify status mismatch - %s - %s\n",
923 nt_errstr(notifies[0][j].status),
924 nt_errstr(notifies[i][j].status));
928 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
932 not1 = notifies[0][j].notify;
933 not2 = notifies[i][j].notify;
935 for (n=0;n<not1.nttrans.out.num_changes;n++) {
936 if (not1.nttrans.out.changes[n].action !=
937 not2.nttrans.out.changes[n].action) {
938 printf("Notify action %d inconsistent %d %d\n", n,
939 not1.nttrans.out.changes[n].action,
940 not2.nttrans.out.changes[n].action);
943 if (strcmp(not1.nttrans.out.changes[n].name.s,
944 not2.nttrans.out.changes[n].name.s)) {
945 printf("Notify name %d inconsistent %s %s\n", n,
946 not1.nttrans.out.changes[n].name.s,
947 not2.nttrans.out.changes[n].name.s);
950 if (not1.nttrans.out.changes[n].name.private_length !=
951 not2.nttrans.out.changes[n].name.private_length) {
952 printf("Notify name length %d inconsistent %d %d\n", n,
953 not1.nttrans.out.changes[n].name.private_length,
954 not2.nttrans.out.changes[n].name.private_length);
961 ZERO_STRUCT(notifies);
967 #define GEN_COPY_PARM do { \
969 for (i=1;i<NSERVERS;i++) { \
974 #define GEN_CALL(call) do { \
976 ZERO_STRUCT(oplocks); \
977 ZERO_STRUCT(notifies); \
978 for (i=0;i<NSERVERS;i++) { \
979 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
982 current_op.status = status[0]; \
983 for (i=1;i<NSERVERS;i++) { \
984 if (!compare_status(status[i], status[0])) { \
985 printf("status different in %s - %s %s\n", #call, \
986 nt_errstr(status[0]), nt_errstr(status[i])); \
990 if (!check_oplocks(#call)) return false; \
991 if (!check_notifies(#call)) return false; \
992 if (!NT_STATUS_IS_OK(status[0])) { \
997 #define ADD_HANDLE(name, field) do { \
998 uint16_t fnums[NSERVERS]; \
1000 for (i=0;i<NSERVERS;i++) { \
1001 fnums[i] = parm[i].field; \
1003 gen_add_handle(instance, name, fnums); \
1006 #define REMOVE_HANDLE(field) do { \
1007 uint16_t fnums[NSERVERS]; \
1009 for (i=0;i<NSERVERS;i++) { \
1010 fnums[i] = parm[i].field; \
1012 gen_remove_handle(instance, fnums); \
1015 #define GEN_SET_FNUM(field) do { \
1017 for (i=0;i<NSERVERS;i++) { \
1018 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
1022 #define CHECK_EQUAL(field) do { \
1023 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1024 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1025 (int)parm[0].field, (int)parm[1].field); \
1030 #define CHECK_WSTR_EQUAL(field) do { \
1031 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1032 printf("%s is NULL!\n", #field); \
1035 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1036 printf("Mismatch in %s - %s %s\n", #field, \
1037 parm[0].field.s, parm[1].field.s); \
1040 CHECK_EQUAL(field.private_length); \
1043 #define CHECK_BLOB_EQUAL(field) do { \
1044 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1045 printf("Mismatch in %s\n", #field); \
1048 CHECK_EQUAL(field.length); \
1051 #define CHECK_TIMES_EQUAL(field) do { \
1052 if (labs(parm[0].field - parm[1].field) > time_skew() && \
1053 !ignore_pattern(#field)) { \
1054 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1055 (int)parm[0].field, (int)parm[1].field); \
1060 #define CHECK_NTTIMES_EQUAL(field) do { \
1061 if (labs(nt_time_to_unix(parm[0].field) - \
1062 nt_time_to_unix(parm[1].field)) > time_skew() && \
1063 !ignore_pattern(#field)) { \
1064 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1065 (int)nt_time_to_unix(parm[0].field), \
1066 (int)nt_time_to_unix(parm[1].field)); \
1072 generate openx operations
1074 static bool handler_openx(int instance)
1076 union smb_open parm[NSERVERS];
1077 NTSTATUS status[NSERVERS];
1079 parm[0].openx.level = RAW_OPEN_OPENX;
1080 parm[0].openx.in.flags = gen_openx_flags();
1081 parm[0].openx.in.open_mode = gen_openx_mode();
1082 parm[0].openx.in.search_attrs = gen_attrib();
1083 parm[0].openx.in.file_attrs = gen_attrib();
1084 parm[0].openx.in.write_time = gen_timet();
1085 parm[0].openx.in.open_func = gen_openx_func();
1086 parm[0].openx.in.size = gen_io_count();
1087 parm[0].openx.in.timeout = gen_timeout();
1088 parm[0].openx.in.fname = gen_fname_open(instance);
1090 if (!options.use_oplocks) {
1091 /* mask out oplocks */
1092 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1093 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1097 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1099 CHECK_EQUAL(openx.out.attrib);
1100 CHECK_EQUAL(openx.out.size);
1101 CHECK_EQUAL(openx.out.access);
1102 CHECK_EQUAL(openx.out.ftype);
1103 CHECK_EQUAL(openx.out.devstate);
1104 CHECK_EQUAL(openx.out.action);
1105 CHECK_EQUAL(openx.out.access_mask);
1106 CHECK_EQUAL(openx.out.unknown);
1107 CHECK_TIMES_EQUAL(openx.out.write_time);
1109 /* open creates a new file handle */
1110 ADD_HANDLE(parm[0].openx.in.fname, openx.out.file.fnum);
1117 generate open operations
1119 static bool handler_open(int instance)
1121 union smb_open parm[NSERVERS];
1122 NTSTATUS status[NSERVERS];
1124 parm[0].openold.level = RAW_OPEN_OPEN;
1125 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1126 parm[0].openold.in.search_attrs = gen_attrib();
1127 parm[0].openold.in.fname = gen_fname_open(instance);
1129 if (!options.use_oplocks) {
1130 /* mask out oplocks */
1131 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1132 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1136 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1138 CHECK_EQUAL(openold.out.attrib);
1139 CHECK_TIMES_EQUAL(openold.out.write_time);
1140 CHECK_EQUAL(openold.out.size);
1141 CHECK_EQUAL(openold.out.rmode);
1143 /* open creates a new file handle */
1144 ADD_HANDLE(parm[0].openold.in.fname, openold.out.file.fnum);
1151 generate ntcreatex operations
1153 static bool handler_ntcreatex(int instance)
1155 union smb_open parm[NSERVERS];
1156 NTSTATUS status[NSERVERS];
1158 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1159 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1160 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1161 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1162 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1163 parm[0].ntcreatex.in.file_attr = gen_attrib();
1164 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1165 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1166 parm[0].ntcreatex.in.create_options = gen_create_options();
1167 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1168 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1169 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1171 if (!options.use_oplocks) {
1172 /* mask out oplocks */
1173 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1174 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1178 if (parm[0].ntcreatex.in.root_fid != 0) {
1179 GEN_SET_FNUM(ntcreatex.in.root_fid);
1181 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1183 CHECK_EQUAL(ntcreatex.out.oplock_level);
1184 CHECK_EQUAL(ntcreatex.out.create_action);
1185 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1186 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1187 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1188 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1189 CHECK_EQUAL(ntcreatex.out.attrib);
1190 CHECK_EQUAL(ntcreatex.out.alloc_size);
1191 CHECK_EQUAL(ntcreatex.out.size);
1192 CHECK_EQUAL(ntcreatex.out.file_type);
1193 CHECK_EQUAL(ntcreatex.out.ipc_state);
1194 CHECK_EQUAL(ntcreatex.out.is_directory);
1196 /* ntcreatex creates a new file handle */
1197 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.file.fnum);
1203 generate close operations
1205 static bool handler_close(int instance)
1207 union smb_close parm[NSERVERS];
1208 NTSTATUS status[NSERVERS];
1210 parm[0].close.level = RAW_CLOSE_CLOSE;
1211 parm[0].close.in.file.fnum = gen_fnum_close(instance);
1212 parm[0].close.in.write_time = gen_timet();
1215 GEN_SET_FNUM(close.in.file.fnum);
1216 GEN_CALL(smb_raw_close(tree, &parm[i]));
1218 REMOVE_HANDLE(close.in.file.fnum);
1224 generate unlink operations
1226 static bool handler_unlink(int instance)
1228 union smb_unlink parm[NSERVERS];
1229 NTSTATUS status[NSERVERS];
1231 parm[0].unlink.in.pattern = gen_pattern();
1232 parm[0].unlink.in.attrib = gen_attrib();
1235 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1241 generate chkpath operations
1243 static bool handler_chkpath(int instance)
1245 union smb_chkpath parm[NSERVERS];
1246 NTSTATUS status[NSERVERS];
1248 parm[0].chkpath.in.path = gen_fname_open(instance);
1251 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1257 generate mkdir operations
1259 static bool handler_mkdir(int instance)
1261 union smb_mkdir parm[NSERVERS];
1262 NTSTATUS status[NSERVERS];
1264 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1265 parm[0].mkdir.in.path = gen_fname_open(instance);
1268 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1274 generate rmdir operations
1276 static bool handler_rmdir(int instance)
1278 struct smb_rmdir parm[NSERVERS];
1279 NTSTATUS status[NSERVERS];
1281 parm[0].in.path = gen_fname_open(instance);
1284 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1290 generate rename operations
1292 static bool handler_rename(int instance)
1294 union smb_rename parm[NSERVERS];
1295 NTSTATUS status[NSERVERS];
1297 parm[0].generic.level = RAW_RENAME_RENAME;
1298 parm[0].rename.in.pattern1 = gen_pattern();
1299 parm[0].rename.in.pattern2 = gen_pattern();
1300 parm[0].rename.in.attrib = gen_attrib();
1303 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1309 generate ntrename operations
1311 static bool handler_ntrename(int instance)
1313 union smb_rename parm[NSERVERS];
1314 NTSTATUS status[NSERVERS];
1316 parm[0].generic.level = RAW_RENAME_NTRENAME;
1317 parm[0].ntrename.in.old_name = gen_fname();
1318 parm[0].ntrename.in.new_name = gen_fname();
1319 parm[0].ntrename.in.attrib = gen_attrib();
1320 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1321 parm[0].ntrename.in.flags = gen_rename_flags();
1324 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1331 generate seek operations
1333 static bool handler_seek(int instance)
1335 union smb_seek parm[NSERVERS];
1336 NTSTATUS status[NSERVERS];
1338 parm[0].lseek.in.file.fnum = gen_fnum(instance);
1339 parm[0].lseek.in.mode = gen_bits_mask2(0x3, 0xFFFF);
1340 parm[0].lseek.in.offset = gen_offset();
1343 GEN_SET_FNUM(lseek.in.file.fnum);
1344 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1346 CHECK_EQUAL(lseek.out.offset);
1353 generate readx operations
1355 static bool handler_readx(int instance)
1357 union smb_read parm[NSERVERS];
1358 NTSTATUS status[NSERVERS];
1360 parm[0].readx.level = RAW_READ_READX;
1361 parm[0].readx.in.file.fnum = gen_fnum(instance);
1362 parm[0].readx.in.offset = gen_offset();
1363 parm[0].readx.in.mincnt = gen_io_count();
1364 parm[0].readx.in.maxcnt = gen_io_count();
1365 parm[0].readx.in.remaining = gen_io_count();
1366 parm[0].readx.in.read_for_execute = gen_bool();
1367 parm[0].readx.out.data = talloc_array(current_op.mem_ctx, uint8_t,
1368 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1371 GEN_SET_FNUM(readx.in.file.fnum);
1372 GEN_CALL(smb_raw_read(tree, &parm[i]));
1374 CHECK_EQUAL(readx.out.remaining);
1375 CHECK_EQUAL(readx.out.compaction_mode);
1376 CHECK_EQUAL(readx.out.nread);
1382 generate writex operations
1384 static bool handler_writex(int instance)
1386 union smb_write parm[NSERVERS];
1387 NTSTATUS status[NSERVERS];
1389 parm[0].writex.level = RAW_WRITE_WRITEX;
1390 parm[0].writex.in.file.fnum = gen_fnum(instance);
1391 parm[0].writex.in.offset = gen_offset();
1392 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1393 parm[0].writex.in.remaining = gen_io_count();
1394 parm[0].writex.in.count = gen_io_count();
1395 parm[0].writex.in.data = talloc_zero_array(current_op.mem_ctx, uint8_t, parm[0].writex.in.count);
1398 GEN_SET_FNUM(writex.in.file.fnum);
1399 GEN_CALL(smb_raw_write(tree, &parm[i]));
1401 CHECK_EQUAL(writex.out.nwritten);
1402 CHECK_EQUAL(writex.out.remaining);
1408 generate lockingx operations
1410 static bool handler_lockingx(int instance)
1412 union smb_lock parm[NSERVERS];
1413 NTSTATUS status[NSERVERS];
1416 parm[0].lockx.level = RAW_LOCK_LOCKX;
1417 parm[0].lockx.in.file.fnum = gen_fnum(instance);
1418 parm[0].lockx.in.mode = gen_lock_mode();
1419 parm[0].lockx.in.timeout = gen_timeout();
1421 /* make sure we don't accidentially generate an oplock
1422 break ack - otherwise the server can just block forever */
1423 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1424 parm[0].lockx.in.lock_cnt = gen_lock_count();
1425 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1426 } while (nlocks == 0);
1429 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1430 struct smb_lock_entry,
1432 for (n=0;n<nlocks;n++) {
1433 parm[0].lockx.in.locks[n].pid = gen_pid();
1434 parm[0].lockx.in.locks[n].offset = gen_offset();
1435 parm[0].lockx.in.locks[n].count = gen_io_count();
1440 GEN_SET_FNUM(lockx.in.file.fnum);
1441 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1447 generate a fileinfo query structure
1449 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1452 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1454 enum smb_fileinfo_level level;
1457 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1458 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1459 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1460 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1461 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1462 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1463 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1464 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1465 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1466 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1469 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1470 } while (ignore_pattern(levels[i].name));
1472 info->generic.level = levels[i].level;
1476 compare returned fileinfo structures
1478 static bool cmp_fileinfo(int instance,
1479 union smb_fileinfo parm[NSERVERS],
1480 NTSTATUS status[NSERVERS])
1484 switch (parm[0].generic.level) {
1485 case RAW_FILEINFO_GENERIC:
1488 case RAW_FILEINFO_GETATTR:
1489 CHECK_EQUAL(getattr.out.attrib);
1490 CHECK_EQUAL(getattr.out.size);
1491 CHECK_TIMES_EQUAL(getattr.out.write_time);
1494 case RAW_FILEINFO_GETATTRE:
1495 CHECK_TIMES_EQUAL(getattre.out.create_time);
1496 CHECK_TIMES_EQUAL(getattre.out.access_time);
1497 CHECK_TIMES_EQUAL(getattre.out.write_time);
1498 CHECK_EQUAL(getattre.out.size);
1499 CHECK_EQUAL(getattre.out.alloc_size);
1500 CHECK_EQUAL(getattre.out.attrib);
1503 case RAW_FILEINFO_STANDARD:
1504 CHECK_TIMES_EQUAL(standard.out.create_time);
1505 CHECK_TIMES_EQUAL(standard.out.access_time);
1506 CHECK_TIMES_EQUAL(standard.out.write_time);
1507 CHECK_EQUAL(standard.out.size);
1508 CHECK_EQUAL(standard.out.alloc_size);
1509 CHECK_EQUAL(standard.out.attrib);
1512 case RAW_FILEINFO_EA_SIZE:
1513 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1514 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1515 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1516 CHECK_EQUAL(ea_size.out.size);
1517 CHECK_EQUAL(ea_size.out.alloc_size);
1518 CHECK_EQUAL(ea_size.out.attrib);
1519 CHECK_EQUAL(ea_size.out.ea_size);
1522 case RAW_FILEINFO_ALL_EAS:
1523 CHECK_EQUAL(all_eas.out.num_eas);
1524 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1525 CHECK_EQUAL(all_eas.out.eas[i].flags);
1526 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1527 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1531 case RAW_FILEINFO_IS_NAME_VALID:
1534 case RAW_FILEINFO_BASIC_INFO:
1535 case RAW_FILEINFO_BASIC_INFORMATION:
1536 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1537 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1538 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1539 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1540 CHECK_EQUAL(basic_info.out.attrib);
1543 case RAW_FILEINFO_STANDARD_INFO:
1544 case RAW_FILEINFO_STANDARD_INFORMATION:
1545 CHECK_EQUAL(standard_info.out.alloc_size);
1546 CHECK_EQUAL(standard_info.out.size);
1547 CHECK_EQUAL(standard_info.out.nlink);
1548 CHECK_EQUAL(standard_info.out.delete_pending);
1549 CHECK_EQUAL(standard_info.out.directory);
1552 case RAW_FILEINFO_EA_INFO:
1553 case RAW_FILEINFO_EA_INFORMATION:
1554 CHECK_EQUAL(ea_info.out.ea_size);
1557 case RAW_FILEINFO_NAME_INFO:
1558 case RAW_FILEINFO_NAME_INFORMATION:
1559 CHECK_WSTR_EQUAL(name_info.out.fname);
1562 case RAW_FILEINFO_ALL_INFO:
1563 case RAW_FILEINFO_ALL_INFORMATION:
1564 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1565 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1566 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1567 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1568 CHECK_EQUAL(all_info.out.attrib);
1569 CHECK_EQUAL(all_info.out.alloc_size);
1570 CHECK_EQUAL(all_info.out.size);
1571 CHECK_EQUAL(all_info.out.nlink);
1572 CHECK_EQUAL(all_info.out.delete_pending);
1573 CHECK_EQUAL(all_info.out.directory);
1574 CHECK_EQUAL(all_info.out.ea_size);
1575 CHECK_WSTR_EQUAL(all_info.out.fname);
1578 case RAW_FILEINFO_ALT_NAME_INFO:
1579 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1580 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1583 case RAW_FILEINFO_STREAM_INFO:
1584 case RAW_FILEINFO_STREAM_INFORMATION:
1585 CHECK_EQUAL(stream_info.out.num_streams);
1586 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1587 CHECK_EQUAL(stream_info.out.streams[i].size);
1588 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1589 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1593 case RAW_FILEINFO_COMPRESSION_INFO:
1594 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1595 CHECK_EQUAL(compression_info.out.compressed_size);
1596 CHECK_EQUAL(compression_info.out.format);
1597 CHECK_EQUAL(compression_info.out.unit_shift);
1598 CHECK_EQUAL(compression_info.out.chunk_shift);
1599 CHECK_EQUAL(compression_info.out.cluster_shift);
1602 case RAW_FILEINFO_INTERNAL_INFORMATION:
1603 CHECK_EQUAL(internal_information.out.file_id);
1606 case RAW_FILEINFO_ACCESS_INFORMATION:
1607 CHECK_EQUAL(access_information.out.access_flags);
1610 case RAW_FILEINFO_POSITION_INFORMATION:
1611 CHECK_EQUAL(position_information.out.position);
1614 case RAW_FILEINFO_MODE_INFORMATION:
1615 CHECK_EQUAL(mode_information.out.mode);
1618 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1619 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1622 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1623 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1624 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1625 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1626 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1627 CHECK_EQUAL(network_open_information.out.alloc_size);
1628 CHECK_EQUAL(network_open_information.out.size);
1629 CHECK_EQUAL(network_open_information.out.attrib);
1632 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1633 CHECK_EQUAL(attribute_tag_information.out.attrib);
1634 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1637 /* Unhandled levels */
1639 case RAW_FILEINFO_SEC_DESC:
1640 case RAW_FILEINFO_EA_LIST:
1641 case RAW_FILEINFO_UNIX_BASIC:
1642 case RAW_FILEINFO_UNIX_LINK:
1643 case RAW_FILEINFO_SMB2_ALL_EAS:
1644 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1645 case RAW_FILEINFO_UNIX_INFO2:
1653 generate qpathinfo operations
1655 static bool handler_qpathinfo(int instance)
1657 union smb_fileinfo parm[NSERVERS];
1658 NTSTATUS status[NSERVERS];
1660 parm[0].generic.in.file.path = gen_fname_open(instance);
1662 gen_fileinfo(instance, &parm[0]);
1665 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1667 return cmp_fileinfo(instance, parm, status);
1671 generate qfileinfo operations
1673 static bool handler_qfileinfo(int instance)
1675 union smb_fileinfo parm[NSERVERS];
1676 NTSTATUS status[NSERVERS];
1678 parm[0].generic.in.file.fnum = gen_fnum(instance);
1680 gen_fileinfo(instance, &parm[0]);
1683 GEN_SET_FNUM(generic.in.file.fnum);
1684 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1686 return cmp_fileinfo(instance, parm, status);
1691 generate a fileinfo query structure
1693 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1697 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1699 enum smb_setfileinfo_level level;
1703 /* disabled until win2003 can handle them ... */
1704 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1705 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1707 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1708 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1709 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1710 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1711 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1714 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1715 } while (ignore_pattern(levels[i].name));
1717 info->generic.level = levels[i].level;
1719 switch (info->generic.level) {
1720 case RAW_SFILEINFO_SETATTR:
1721 info->setattr.in.attrib = gen_attrib();
1722 info->setattr.in.write_time = gen_timet();
1724 case RAW_SFILEINFO_SETATTRE:
1725 info->setattre.in.create_time = gen_timet();
1726 info->setattre.in.access_time = gen_timet();
1727 info->setattre.in.write_time = gen_timet();
1729 case RAW_SFILEINFO_STANDARD:
1730 info->standard.in.create_time = gen_timet();
1731 info->standard.in.access_time = gen_timet();
1732 info->standard.in.write_time = gen_timet();
1734 case RAW_SFILEINFO_EA_SET: {
1735 static struct ea_struct ea;
1736 info->ea_set.in.num_eas = 1;
1737 info->ea_set.in.eas = &ea;
1738 info->ea_set.in.eas[0] = gen_ea_struct();
1741 case RAW_SFILEINFO_BASIC_INFO:
1742 case RAW_SFILEINFO_BASIC_INFORMATION:
1743 info->basic_info.in.create_time = gen_nttime();
1744 info->basic_info.in.access_time = gen_nttime();
1745 info->basic_info.in.write_time = gen_nttime();
1746 info->basic_info.in.change_time = gen_nttime();
1747 info->basic_info.in.attrib = gen_attrib();
1749 case RAW_SFILEINFO_DISPOSITION_INFO:
1750 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1751 info->disposition_info.in.delete_on_close = gen_bool();
1753 case RAW_SFILEINFO_ALLOCATION_INFO:
1754 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1755 info->allocation_info.in.alloc_size = gen_alloc_size();
1757 case RAW_SFILEINFO_END_OF_FILE_INFO:
1758 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1759 info->end_of_file_info.in.size = gen_offset();
1761 case RAW_SFILEINFO_RENAME_INFORMATION:
1762 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
1763 info->rename_information.in.overwrite = gen_bool();
1764 info->rename_information.in.root_fid = gen_root_fid(instance);
1765 info->rename_information.in.new_name = gen_fname_open(instance);
1767 case RAW_SFILEINFO_POSITION_INFORMATION:
1768 info->position_information.in.position = gen_offset();
1770 case RAW_SFILEINFO_MODE_INFORMATION:
1771 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1773 case RAW_SFILEINFO_GENERIC:
1774 case RAW_SFILEINFO_SEC_DESC:
1775 case RAW_SFILEINFO_UNIX_BASIC:
1776 case RAW_SFILEINFO_UNIX_LINK:
1777 case RAW_SFILEINFO_UNIX_HLINK:
1778 case RAW_SFILEINFO_1023:
1779 case RAW_SFILEINFO_1025:
1780 case RAW_SFILEINFO_1029:
1781 case RAW_SFILEINFO_1032:
1782 case RAW_SFILEINFO_1039:
1783 case RAW_SFILEINFO_1040:
1784 case RAW_SFILEINFO_UNIX_INFO2:
1791 generate setpathinfo operations
1793 static bool handler_spathinfo(int instance)
1795 union smb_setfileinfo parm[NSERVERS];
1796 NTSTATUS status[NSERVERS];
1798 parm[0].generic.in.file.path = gen_fname_open(instance);
1800 gen_setfileinfo(instance, &parm[0]);
1804 /* a special case for the fid in a RENAME */
1805 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1806 parm[0].rename_information.in.root_fid != 0) {
1807 GEN_SET_FNUM(rename_information.in.root_fid);
1810 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1817 generate setfileinfo operations
1819 static bool handler_sfileinfo(int instance)
1821 union smb_setfileinfo parm[NSERVERS];
1822 NTSTATUS status[NSERVERS];
1824 parm[0].generic.in.file.fnum = gen_fnum(instance);
1826 gen_setfileinfo(instance, &parm[0]);
1829 GEN_SET_FNUM(generic.in.file.fnum);
1830 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1837 generate change notify operations
1839 static bool handler_notify(int instance)
1841 union smb_notify parm[NSERVERS];
1844 ZERO_STRUCT(parm[0]);
1845 parm[0].nttrans.level = RAW_NOTIFY_NTTRANS;
1846 parm[0].nttrans.in.buffer_size = gen_io_count();
1847 parm[0].nttrans.in.completion_filter = gen_bits_mask(0xFF);
1848 parm[0].nttrans.in.file.fnum = gen_fnum(instance);
1849 parm[0].nttrans.in.recursive = gen_bool();
1852 GEN_SET_FNUM(nttrans.in.file.fnum);
1854 for (n=0;n<NSERVERS;n++) {
1855 struct smbcli_request *req;
1856 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1857 req->async.fn = async_notify;
1864 wipe any relevant files
1866 static void wipe_files(void)
1870 if (options.skip_cleanup) {
1874 for (i=0;i<NSERVERS;i++) {
1875 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1877 printf("Failed to wipe tree on server %d\n", i);
1880 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1881 printf("Failed to create \\gentest - %s\n",
1882 smbcli_errstr(servers[i].cli[0]->tree));
1886 printf("Deleted %d files on server %d\n", n, i);
1892 dump the current seeds - useful for continuing a backtrack
1894 static void dump_seeds(void)
1899 if (!options.seeds_file) {
1902 f = fopen("seeds.tmp", "w");
1905 for (i=0;i<options.numops;i++) {
1906 fprintf(f, "%u\n", op_parms[i].seed);
1909 rename("seeds.tmp", options.seeds_file);
1915 the list of top-level operations that we will generate
1919 bool (*handler)(int instance);
1920 int count, success_count;
1922 {"OPEN", handler_open},
1923 {"OPENX", handler_openx},
1924 {"NTCREATEX", handler_ntcreatex},
1925 {"CLOSE", handler_close},
1926 {"UNLINK", handler_unlink},
1927 {"MKDIR", handler_mkdir},
1928 {"RMDIR", handler_rmdir},
1929 {"RENAME", handler_rename},
1930 {"NTRENAME", handler_ntrename},
1931 {"READX", handler_readx},
1932 {"WRITEX", handler_writex},
1933 {"CHKPATH", handler_chkpath},
1934 {"LOCKINGX", handler_lockingx},
1935 {"QPATHINFO", handler_qpathinfo},
1936 {"QFILEINFO", handler_qfileinfo},
1937 {"SPATHINFO", handler_spathinfo},
1938 {"SFILEINFO", handler_sfileinfo},
1939 {"NOTIFY", handler_notify},
1940 {"SEEK", handler_seek},
1945 run the test with the current set of op_parms parameters
1946 return the number of operations that completed successfully
1948 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
1952 if (!connect_servers(ev, lp_ctx)) {
1953 printf("Failed to connect to servers\n");
1959 /* wipe any leftover files from old runs */
1962 /* reset the open handles array */
1963 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1964 num_open_handles = 0;
1966 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1967 gen_ops[i].count = 0;
1968 gen_ops[i].success_count = 0;
1971 for (op=0; op<options.numops; op++) {
1972 int instance, which_op;
1975 if (op_parms[op].disabled) continue;
1977 srandom(op_parms[op].seed);
1979 instance = gen_int_range(0, NINSTANCES-1);
1981 /* generate a non-ignored operation */
1983 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1984 } while (ignore_pattern(gen_ops[which_op].name));
1986 DEBUG(3,("Generating op %s on instance %d\n",
1987 gen_ops[which_op].name, instance));
1989 current_op.seed = op_parms[op].seed;
1990 current_op.opnum = op;
1991 current_op.name = gen_ops[which_op].name;
1992 current_op.status = NT_STATUS_OK;
1993 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1995 ret = gen_ops[which_op].handler(instance);
1997 talloc_free(current_op.mem_ctx);
1999 gen_ops[which_op].count++;
2000 if (NT_STATUS_IS_OK(current_op.status)) {
2001 gen_ops[which_op].success_count++;
2005 printf("Failed at operation %d - %s\n",
2006 op, gen_ops[which_op].name);
2010 if (op % 100 == 0) {
2015 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2016 printf("Op %-10s got %d/%d success\n",
2018 gen_ops[i].success_count,
2026 perform a backtracking analysis of the minimal set of operations
2027 to generate an error
2029 static void backtrack_analyze(struct event_context *ev,
2030 struct loadparm_context *lp_ctx)
2034 chunk = options.numops / 2;
2039 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2042 chunk = MIN(chunk, options.numops / 2);
2044 /* mark this range as disabled */
2045 max = MIN(options.numops, base+chunk);
2046 for (i=base;i<max; i++) {
2047 op_parms[i].disabled = true;
2049 printf("Testing %d ops with %d-%d disabled\n",
2050 options.numops, base, max-1);
2051 ret = run_test(ev, lp_ctx);
2052 printf("Completed %d of %d ops\n", ret, options.numops);
2053 for (i=base;i<max; i++) {
2054 op_parms[i].disabled = false;
2056 if (ret == options.numops) {
2057 /* this chunk is needed */
2059 } else if (ret < base) {
2060 printf("damn - inconsistent errors! found early error\n");
2061 options.numops = ret+1;
2064 /* it failed - this chunk isn't needed for a failure */
2065 memmove(&op_parms[base], &op_parms[max],
2066 sizeof(op_parms[0]) * (options.numops - max));
2067 options.numops = (ret+1) - (max - base);
2077 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2080 } while (chunk > 0);
2082 printf("Reduced to %d ops\n", options.numops);
2083 ret = run_test(ev, lp_ctx);
2084 if (ret != options.numops - 1) {
2085 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2090 start the main gentest process
2092 static bool start_gentest(struct event_context *ev,
2093 struct loadparm_context *lp_ctx)
2098 /* allocate the open_handles array */
2099 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2101 srandom(options.seed);
2102 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2104 /* generate the seeds - after this everything is deterministic */
2105 if (options.use_preset_seeds) {
2107 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
2109 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2112 if (numops < options.numops) {
2113 options.numops = numops;
2115 for (op=0;op<options.numops;op++) {
2117 printf("Not enough seeds in %s\n", options.seeds_file);
2120 op_parms[op].seed = atoi(preset[op]);
2122 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2124 for (op=0; op<options.numops; op++) {
2125 op_parms[op].seed = random();
2129 ret = run_test(ev, lp_ctx);
2131 if (ret != options.numops && options.analyze) {
2132 options.numops = ret+1;
2133 backtrack_analyze(ev, lp_ctx);
2134 } else if (options.analyze_always) {
2135 backtrack_analyze(ev, lp_ctx);
2136 } else if (options.analyze_continuous) {
2137 while (run_test(ev, lp_ctx) == options.numops) ;
2140 return ret == options.numops;
2144 static void usage(poptContext pc)
2148 gentest //server1/share1 //server2/share2 [options..]\n\
2150 poptPrintUsage(pc, stdout, 0);
2154 split a UNC name into server and share names
2156 static bool split_unc_name(const char *unc, char **server, char **share)
2158 char *p = strdup(unc);
2159 if (!p) return false;
2160 all_string_sub(p, "\\", "/", 0);
2161 if (strncmp(p, "//", 2) != 0) return false;
2164 p = strchr(*server, '/');
2165 if (!p) return false;
2175 /****************************************************************************
2177 ****************************************************************************/
2178 int main(int argc, char *argv[])
2181 int i, username_count=0;
2183 char *ignore_file=NULL;
2184 struct event_context *ev;
2185 struct loadparm_context *lp_ctx;
2189 enum {OPT_UNCLIST=1000};
2190 struct poptOption long_options[] = {
2192 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
2193 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
2194 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
2195 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
2196 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
2197 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
2198 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
2199 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
2200 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
2201 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
2202 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
2203 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
2204 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
2205 {"skip-cleanup", 0, POPT_ARG_NONE, &options.skip_cleanup, 0, "don't delete files at start", NULL},
2207 POPT_COMMON_CONNECTION
2208 POPT_COMMON_CREDENTIALS
2214 options.seed = time(NULL);
2215 options.numops = 1000;
2216 options.max_open_handles = 20;
2217 options.seeds_file = "gentest_seeds.dat";
2219 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
2220 POPT_CONTEXT_KEEP_FIRST);
2222 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
2224 lp_ctx = cmdline_lp_ctx;
2225 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
2226 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
2227 cli_credentials_guess(servers[0].credentials, lp_ctx);
2228 cli_credentials_guess(servers[1].credentials, lp_ctx);
2230 while((opt = poptGetNextOpt(pc)) != -1) {
2233 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
2236 if (username_count == 2) {
2240 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
2247 options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
2250 argv_new = discard_const_p(char *, poptGetArgs(pc));
2252 for (i=0; i<argc; i++) {
2253 if (argv_new[i] == NULL) {
2259 if (!(argc_new >= 3)) {
2266 setup_logging("gentest", DEBUG_STDOUT);
2268 if (argc < 3 || argv[1][0] == '-') {
2273 setup_logging(argv[0], DEBUG_STDOUT);
2275 for (i=0;i<NSERVERS;i++) {
2276 const char *share = argv[1+i];
2277 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2278 printf("Invalid share name '%s'\n", share);
2283 if (username_count == 0) {
2287 if (username_count == 1) {
2288 servers[1].credentials = servers[0].credentials;
2291 printf("seed=%u\n", options.seed);
2293 ev = event_context_init(talloc_autofree_context());
2295 gensec_init(lp_ctx);
2297 ret = start_gentest(ev, lp_ctx);
2300 printf("gentest completed - no errors\n");
2302 printf("gentest failed\n");