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++) {
180 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
181 servers[i].server_name, servers[i].share_name,
182 servers[i].credentials->username, j);
184 cli_credentials_set_workstation(servers[i].credentials,
185 "gentest", CRED_SPECIFIED);
187 status = smbcli_full_connection(NULL, &servers[i].cli[j],
188 servers[i].server_name,
189 lp_smb_ports(lp_ctx),
190 servers[i].share_name, NULL,
191 servers[i].credentials,
192 lp_resolve_context(lp_ctx),
194 if (!NT_STATUS_IS_OK(status)) {
195 printf("Failed to connect to \\\\%s\\%s - %s\n",
196 servers[i].server_name, servers[i].share_name,
201 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
202 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 50000, NULL);
210 work out the time skew between the servers - be conservative
212 static uint_t time_skew(void)
215 ret = labs(servers[0].cli[0]->transport->negotiate.server_time -
216 servers[1].cli[0]->transport->negotiate.server_time);
221 turn an fnum for an instance into a handle
223 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
226 for (i=0;i<options.max_open_handles;i++) {
227 if (!open_handles[i].active ||
228 instance != open_handles[i].instance) continue;
229 if (open_handles[i].server_fnum[server] == fnum) {
233 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
234 fnum, server, instance);
239 add some newly opened handles
241 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
244 for (h=0;h<options.max_open_handles;h++) {
245 if (!open_handles[h].active) break;
247 if (h == options.max_open_handles) {
248 /* we have to force close a random handle */
249 h = random() % options.max_open_handles;
250 for (i=0;i<NSERVERS;i++) {
251 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
252 open_handles[h].server_fnum[i])))) {
253 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
254 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
257 printf("Recovered handle %d\n", h);
260 for (i=0;i<NSERVERS;i++) {
261 open_handles[h].server_fnum[i] = fnums[i];
262 open_handles[h].instance = instance;
263 open_handles[h].active = true;
264 open_handles[h].name = name;
268 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
270 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
275 remove a closed handle
277 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
280 for (h=0;h<options.max_open_handles;h++) {
281 if (instance == open_handles[h].instance &&
282 open_handles[h].server_fnum[0] == fnums[0]) {
283 open_handles[h].active = false;
285 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
287 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
288 open_handles[h].name);
292 printf("Removing invalid handle!?\n");
297 return true with 'chance' probability as a percentage
299 static bool gen_chance(uint_t chance)
301 return ((random() % 100) <= chance);
305 map an internal handle number to a server fnum
307 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
309 if (handle == BAD_HANDLE) return handle;
310 return open_handles[handle].server_fnum[server];
316 static uint16_t gen_fnum(int instance)
321 if (gen_chance(20)) return BAD_HANDLE;
323 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
324 h = random() % options.max_open_handles;
325 if (open_handles[h].active &&
326 open_handles[h].instance == instance) {
334 return a file handle, but skewed so we don't close the last
335 couple of handles too readily
337 static uint16_t gen_fnum_close(int instance)
339 if (num_open_handles < 3) {
340 if (gen_chance(80)) return BAD_HANDLE;
343 return gen_fnum(instance);
347 generate an integer in a specified range
349 static int gen_int_range(uint_t min, uint_t max)
352 return min + (r % (1+max-min));
356 return a fnum for use as a root fid
357 be careful to call GEN_SET_FNUM() when you use this!
359 static uint16_t gen_root_fid(int instance)
361 if (gen_chance(5)) return gen_fnum(instance);
366 generate a file offset
368 static int gen_offset(void)
370 if (gen_chance(20)) return 0;
371 return gen_int_range(0, 1024*1024);
377 static int gen_io_count(void)
379 if (gen_chance(20)) return 0;
380 return gen_int_range(0, 4096);
386 static const char *gen_fname(void)
388 const char *names[] = {"\\gentest\\gentest.dat",
390 "\\gentest\\foo2.sym",
391 "\\gentest\\foo3.dll",
393 "\\gentest\\foo4:teststream1",
394 "\\gentest\\foo4:teststream2",
395 "\\gentest\\foo5.exe",
396 "\\gentest\\foo5.exe:teststream3",
397 "\\gentest\\foo5.exe:teststream4",
398 "\\gentest\\foo6.com",
400 "\\gentest\\blah\\blergh.txt",
401 "\\gentest\\blah\\blergh2",
402 "\\gentest\\blah\\blergh3.txt",
403 "\\gentest\\blah\\blergh4",
404 "\\gentest\\blah\\blergh5.txt",
405 "\\gentest\\blah\\blergh5",
406 "\\gentest\\blah\\.",
408 /* this causes problem with w2k3 */
409 "\\gentest\\blah\\..",
411 "\\gentest\\a_very_long_name.bin",
417 i = gen_int_range(0, ARRAY_SIZE(names)-1);
418 } while (ignore_pattern(names[i]));
424 generate a filename with a higher chance of choosing an already
427 static const char *gen_fname_open(int instance)
430 h = gen_fnum(instance);
431 if (h == BAD_HANDLE) {
434 return open_handles[h].name;
438 generate a wildcard pattern
440 static const char *gen_pattern(void)
443 const char *names[] = {"\\gentest\\*.dat",
446 "\\gentest\\blah\\*.*",
447 "\\gentest\\blah\\*",
450 if (gen_chance(50)) return gen_fname();
453 i = gen_int_range(0, ARRAY_SIZE(names)-1);
454 } while (ignore_pattern(names[i]));
462 static uint32_t gen_bits_mask(uint_t mask)
464 uint_t ret = random();
469 generate a bitmask with high probability of the first mask
470 and low of the second
472 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
474 if (gen_chance(10)) return gen_bits_mask(mask2);
475 return gen_bits_mask(mask1);
481 static bool gen_bool(void)
483 return gen_bits_mask2(0x1, 0xFF);
487 generate ntrename flags
489 static uint16_t gen_rename_flags(void)
491 if (gen_chance(30)) return RENAME_FLAG_RENAME;
492 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
493 if (gen_chance(30)) return RENAME_FLAG_COPY;
494 return gen_bits_mask(0xFFFF);
499 return a lockingx lock mode
501 static uint16_t gen_lock_mode(void)
503 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
504 if (gen_chance(20)) return gen_bits_mask(0x1F);
505 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
511 static uint16_t gen_pid(void)
513 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
518 generate a lock count
520 static off_t gen_lock_count(void)
522 return gen_int_range(0, 3);
526 generate a ntcreatex flags field
528 static uint32_t gen_ntcreatex_flags(void)
530 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
531 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
535 generate a NT access mask
537 static uint32_t gen_access_mask(void)
539 if (gen_chance(50)) return SEC_FLAG_MAXIMUM_ALLOWED;
540 if (gen_chance(20)) return SEC_FILE_ALL;
541 return gen_bits_mask(0xFFFFFFFF);
545 generate a ntcreatex create options bitfield
547 static uint32_t gen_create_options(void)
549 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
550 if (gen_chance(50)) return 0;
551 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
555 generate a ntcreatex open disposition
557 static uint32_t gen_open_disp(void)
559 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
560 return gen_int_range(0, 5);
564 generate an openx open mode
566 static uint16_t gen_openx_mode(void)
568 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
569 if (gen_chance(20)) return gen_bits_mask(0xFF);
570 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
574 generate an openx flags field
576 static uint16_t gen_openx_flags(void)
578 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
579 return gen_bits_mask(0x7);
583 generate an openx open function
585 static uint16_t gen_openx_func(void)
587 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
588 return gen_bits_mask(0x13);
592 generate a file attrib combination
594 static uint32_t gen_attrib(void)
596 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
597 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
601 generate a unix timestamp
603 static time_t gen_timet(void)
605 if (gen_chance(30)) return 0;
606 return (time_t)random();
610 generate a unix timestamp
612 static NTTIME gen_nttime(void)
615 unix_to_nt_time(&ret, gen_timet());
620 generate a milliseconds protocol timeout
622 static uint32_t gen_timeout(void)
624 if (gen_chance(98)) return 0;
625 return random() % 50;
629 generate a file allocation size
631 static uint_t gen_alloc_size(void)
635 if (gen_chance(30)) return 0;
637 ret = random() % 4*1024*1024;
638 /* give a high chance of a round number */
639 if (gen_chance(60)) {
640 ret &= ~(1024*1024 - 1);
646 generate an ea_struct
648 static struct ea_struct gen_ea_struct(void)
651 const char *names[] = {"EAONE",
656 "AVERYLONGATTRIBUTENAME"};
657 const char *values[] = {"VALUE1",
662 "ASOMEWHATLONGERATTRIBUTEVALUE"};
668 i = gen_int_range(0, ARRAY_SIZE(names)-1);
669 } while (ignore_pattern(names[i]));
671 ea.name.s = names[i];
674 i = gen_int_range(0, ARRAY_SIZE(values)-1);
675 } while (ignore_pattern(values[i]));
677 ea.value = data_blob(values[i], strlen(values[i]));
679 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
687 this is called when a change notify reply comes in
689 static void async_notify(struct smbcli_request *req)
691 union smb_notify notify;
695 struct smbcli_transport *transport = req->transport;
697 tid = SVAL(req->in.hdr, HDR_TID);
699 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
700 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
701 if (NT_STATUS_IS_OK(status)) {
702 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
704 notify.nttrans.out.num_changes,
705 notify.nttrans.out.changes[0].action,
706 notify.nttrans.out.changes[0].name.s);
709 for (i=0;i<NSERVERS;i++) {
710 for (j=0;j<NINSTANCES;j++) {
711 if (transport == servers[i].cli[j]->transport &&
712 tid == servers[i].cli[j]->tree->tid) {
713 notifies[i][j].notify_count++;
714 notifies[i][j].status = status;
715 notifies[i][j].notify = notify;
721 static void oplock_handler_close_recv(struct smbcli_request *req)
724 status = smbcli_request_simple_recv(req);
725 if (!NT_STATUS_IS_OK(status)) {
726 printf("close failed in oplock_handler\n");
727 smb_panic("close failed in oplock_handler");
732 the oplock handler will either ack the break or close the file
734 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
739 struct smbcli_tree *tree = NULL;
740 struct smbcli_request *req;
742 srandom(current_op.seed);
743 do_close = gen_chance(50);
745 for (i=0;i<NSERVERS;i++) {
746 for (j=0;j<NINSTANCES;j++) {
747 if (transport == servers[i].cli[j]->transport &&
748 tid == servers[i].cli[j]->tree->tid) {
749 oplocks[i][j].got_break = true;
750 oplocks[i][j].fnum = fnum;
751 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
752 oplocks[i][j].level = level;
753 oplocks[i][j].do_close = do_close;
754 tree = servers[i].cli[j]->tree;
760 printf("Oplock break not for one of our trees!?\n");
765 printf("oplock ack fnum=%d\n", fnum);
766 return smbcli_oplock_ack(tree, fnum, level);
769 printf("oplock close fnum=%d\n", fnum);
771 io.close.level = RAW_CLOSE_CLOSE;
772 io.close.in.file.fnum = fnum;
773 io.close.in.write_time = 0;
774 req = smb_raw_close_send(tree, &io);
777 printf("WARNING: close failed in oplock_handler_close\n");
781 req->async.fn = oplock_handler_close_recv;
782 req->async.private = NULL;
789 the idle function tries to cope with getting an oplock break on a connection, and
790 an operation on another connection blocking until that break is acked
791 we check for operations on all transports in the idle function
793 static void idle_func(struct smbcli_transport *transport, void *private)
796 for (i=0;i<NSERVERS;i++) {
797 for (j=0;j<NINSTANCES;j++) {
798 if (servers[i].cli[j] &&
799 transport != servers[i].cli[j]->transport) {
800 smbcli_transport_process(servers[i].cli[j]->transport);
809 compare NTSTATUS, using checking ignored patterns
811 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
813 if (NT_STATUS_EQUAL(status1, status2)) return true;
815 /* one code being an error and the other OK is always an error */
816 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return false;
818 /* if we are ignoring one of the status codes then consider this a match */
819 if (ignore_pattern(nt_errstr(status1)) ||
820 ignore_pattern(nt_errstr(status2))) {
828 check for pending packets on all connections
830 static void check_pending(void)
836 for (j=0;j<NINSTANCES;j++) {
837 for (i=0;i<NSERVERS;i++) {
838 smbcli_transport_process(servers[i].cli[j]->transport);
844 check that the same oplock breaks have been received by all instances
846 static bool check_oplocks(const char *call)
854 for (j=0;j<NINSTANCES;j++) {
855 for (i=1;i<NSERVERS;i++) {
856 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
857 oplocks[0][j].handle != oplocks[i][j].handle ||
858 oplocks[0][j].level != oplocks[i][j].level) {
859 if (tries++ < 10) goto again;
860 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
861 oplocks[0][j].got_break,
862 oplocks[0][j].handle,
864 oplocks[i][j].got_break,
865 oplocks[i][j].handle,
866 oplocks[i][j].level);
872 /* if we got a break and closed then remove the handle */
873 for (j=0;j<NINSTANCES;j++) {
874 if (oplocks[0][j].got_break &&
875 oplocks[0][j].do_close) {
876 uint16_t fnums[NSERVERS];
877 for (i=0;i<NSERVERS;i++) {
878 fnums[i] = oplocks[i][j].fnum;
880 gen_remove_handle(j, fnums);
889 check that the same change notify info has been received by all instances
891 static bool check_notifies(const char *call)
899 for (j=0;j<NINSTANCES;j++) {
900 for (i=1;i<NSERVERS;i++) {
902 union smb_notify not1, not2;
904 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
905 if (tries++ < 10) goto again;
906 printf("Notify count inconsistent %d %d\n",
907 notifies[0][j].notify_count,
908 notifies[i][j].notify_count);
912 if (notifies[0][j].notify_count == 0) continue;
914 if (!NT_STATUS_EQUAL(notifies[0][j].status,
915 notifies[i][j].status)) {
916 printf("Notify status mismatch - %s - %s\n",
917 nt_errstr(notifies[0][j].status),
918 nt_errstr(notifies[i][j].status));
922 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
926 not1 = notifies[0][j].notify;
927 not2 = notifies[i][j].notify;
929 for (n=0;n<not1.nttrans.out.num_changes;n++) {
930 if (not1.nttrans.out.changes[n].action !=
931 not2.nttrans.out.changes[n].action) {
932 printf("Notify action %d inconsistent %d %d\n", n,
933 not1.nttrans.out.changes[n].action,
934 not2.nttrans.out.changes[n].action);
937 if (strcmp(not1.nttrans.out.changes[n].name.s,
938 not2.nttrans.out.changes[n].name.s)) {
939 printf("Notify name %d inconsistent %s %s\n", n,
940 not1.nttrans.out.changes[n].name.s,
941 not2.nttrans.out.changes[n].name.s);
944 if (not1.nttrans.out.changes[n].name.private_length !=
945 not2.nttrans.out.changes[n].name.private_length) {
946 printf("Notify name length %d inconsistent %d %d\n", n,
947 not1.nttrans.out.changes[n].name.private_length,
948 not2.nttrans.out.changes[n].name.private_length);
955 ZERO_STRUCT(notifies);
961 #define GEN_COPY_PARM do { \
963 for (i=1;i<NSERVERS;i++) { \
968 #define GEN_CALL(call) do { \
970 ZERO_STRUCT(oplocks); \
971 ZERO_STRUCT(notifies); \
972 for (i=0;i<NSERVERS;i++) { \
973 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
976 current_op.status = status[0]; \
977 for (i=1;i<NSERVERS;i++) { \
978 if (!compare_status(status[i], status[0])) { \
979 printf("status different in %s - %s %s\n", #call, \
980 nt_errstr(status[0]), nt_errstr(status[i])); \
984 if (!check_oplocks(#call)) return false; \
985 if (!check_notifies(#call)) return false; \
986 if (!NT_STATUS_IS_OK(status[0])) { \
991 #define ADD_HANDLE(name, field) do { \
992 uint16_t fnums[NSERVERS]; \
994 for (i=0;i<NSERVERS;i++) { \
995 fnums[i] = parm[i].field; \
997 gen_add_handle(instance, name, fnums); \
1000 #define REMOVE_HANDLE(field) do { \
1001 uint16_t fnums[NSERVERS]; \
1003 for (i=0;i<NSERVERS;i++) { \
1004 fnums[i] = parm[i].field; \
1006 gen_remove_handle(instance, fnums); \
1009 #define GEN_SET_FNUM(field) do { \
1011 for (i=0;i<NSERVERS;i++) { \
1012 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
1016 #define CHECK_EQUAL(field) do { \
1017 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1018 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1019 (int)parm[0].field, (int)parm[1].field); \
1024 #define CHECK_WSTR_EQUAL(field) do { \
1025 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1026 printf("%s is NULL!\n", #field); \
1029 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1030 printf("Mismatch in %s - %s %s\n", #field, \
1031 parm[0].field.s, parm[1].field.s); \
1034 CHECK_EQUAL(field.private_length); \
1037 #define CHECK_BLOB_EQUAL(field) do { \
1038 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1039 printf("Mismatch in %s\n", #field); \
1042 CHECK_EQUAL(field.length); \
1045 #define CHECK_TIMES_EQUAL(field) do { \
1046 if (labs(parm[0].field - parm[1].field) > time_skew() && \
1047 !ignore_pattern(#field)) { \
1048 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1049 (int)parm[0].field, (int)parm[1].field); \
1054 #define CHECK_NTTIMES_EQUAL(field) do { \
1055 if (labs(nt_time_to_unix(parm[0].field) - \
1056 nt_time_to_unix(parm[1].field)) > time_skew() && \
1057 !ignore_pattern(#field)) { \
1058 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1059 (int)nt_time_to_unix(parm[0].field), \
1060 (int)nt_time_to_unix(parm[1].field)); \
1066 generate openx operations
1068 static bool handler_openx(int instance)
1070 union smb_open parm[NSERVERS];
1071 NTSTATUS status[NSERVERS];
1073 parm[0].openx.level = RAW_OPEN_OPENX;
1074 parm[0].openx.in.flags = gen_openx_flags();
1075 parm[0].openx.in.open_mode = gen_openx_mode();
1076 parm[0].openx.in.search_attrs = gen_attrib();
1077 parm[0].openx.in.file_attrs = gen_attrib();
1078 parm[0].openx.in.write_time = gen_timet();
1079 parm[0].openx.in.open_func = gen_openx_func();
1080 parm[0].openx.in.size = gen_io_count();
1081 parm[0].openx.in.timeout = gen_timeout();
1082 parm[0].openx.in.fname = gen_fname_open(instance);
1084 if (!options.use_oplocks) {
1085 /* mask out oplocks */
1086 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1087 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1091 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1093 CHECK_EQUAL(openx.out.attrib);
1094 CHECK_EQUAL(openx.out.size);
1095 CHECK_EQUAL(openx.out.access);
1096 CHECK_EQUAL(openx.out.ftype);
1097 CHECK_EQUAL(openx.out.devstate);
1098 CHECK_EQUAL(openx.out.action);
1099 CHECK_EQUAL(openx.out.access_mask);
1100 CHECK_EQUAL(openx.out.unknown);
1101 CHECK_TIMES_EQUAL(openx.out.write_time);
1103 /* open creates a new file handle */
1104 ADD_HANDLE(parm[0].openx.in.fname, openx.out.file.fnum);
1111 generate open operations
1113 static bool handler_open(int instance)
1115 union smb_open parm[NSERVERS];
1116 NTSTATUS status[NSERVERS];
1118 parm[0].openold.level = RAW_OPEN_OPEN;
1119 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1120 parm[0].openold.in.search_attrs = gen_attrib();
1121 parm[0].openold.in.fname = gen_fname_open(instance);
1123 if (!options.use_oplocks) {
1124 /* mask out oplocks */
1125 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1126 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1130 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1132 CHECK_EQUAL(openold.out.attrib);
1133 CHECK_TIMES_EQUAL(openold.out.write_time);
1134 CHECK_EQUAL(openold.out.size);
1135 CHECK_EQUAL(openold.out.rmode);
1137 /* open creates a new file handle */
1138 ADD_HANDLE(parm[0].openold.in.fname, openold.out.file.fnum);
1145 generate ntcreatex operations
1147 static bool handler_ntcreatex(int instance)
1149 union smb_open parm[NSERVERS];
1150 NTSTATUS status[NSERVERS];
1152 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1153 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1154 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1155 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1156 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1157 parm[0].ntcreatex.in.file_attr = gen_attrib();
1158 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1159 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1160 parm[0].ntcreatex.in.create_options = gen_create_options();
1161 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1162 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1163 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1165 if (!options.use_oplocks) {
1166 /* mask out oplocks */
1167 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1168 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1172 if (parm[0].ntcreatex.in.root_fid != 0) {
1173 GEN_SET_FNUM(ntcreatex.in.root_fid);
1175 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1177 CHECK_EQUAL(ntcreatex.out.oplock_level);
1178 CHECK_EQUAL(ntcreatex.out.create_action);
1179 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1180 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1181 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1182 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1183 CHECK_EQUAL(ntcreatex.out.attrib);
1184 CHECK_EQUAL(ntcreatex.out.alloc_size);
1185 CHECK_EQUAL(ntcreatex.out.size);
1186 CHECK_EQUAL(ntcreatex.out.file_type);
1187 CHECK_EQUAL(ntcreatex.out.ipc_state);
1188 CHECK_EQUAL(ntcreatex.out.is_directory);
1190 /* ntcreatex creates a new file handle */
1191 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.file.fnum);
1197 generate close operations
1199 static bool handler_close(int instance)
1201 union smb_close parm[NSERVERS];
1202 NTSTATUS status[NSERVERS];
1204 parm[0].close.level = RAW_CLOSE_CLOSE;
1205 parm[0].close.in.file.fnum = gen_fnum_close(instance);
1206 parm[0].close.in.write_time = gen_timet();
1209 GEN_SET_FNUM(close.in.file.fnum);
1210 GEN_CALL(smb_raw_close(tree, &parm[i]));
1212 REMOVE_HANDLE(close.in.file.fnum);
1218 generate unlink operations
1220 static bool handler_unlink(int instance)
1222 union smb_unlink parm[NSERVERS];
1223 NTSTATUS status[NSERVERS];
1225 parm[0].unlink.in.pattern = gen_pattern();
1226 parm[0].unlink.in.attrib = gen_attrib();
1229 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1235 generate chkpath operations
1237 static bool handler_chkpath(int instance)
1239 union smb_chkpath parm[NSERVERS];
1240 NTSTATUS status[NSERVERS];
1242 parm[0].chkpath.in.path = gen_fname_open(instance);
1245 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1251 generate mkdir operations
1253 static bool handler_mkdir(int instance)
1255 union smb_mkdir parm[NSERVERS];
1256 NTSTATUS status[NSERVERS];
1258 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1259 parm[0].mkdir.in.path = gen_fname_open(instance);
1262 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1268 generate rmdir operations
1270 static bool handler_rmdir(int instance)
1272 struct smb_rmdir parm[NSERVERS];
1273 NTSTATUS status[NSERVERS];
1275 parm[0].in.path = gen_fname_open(instance);
1278 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1284 generate rename operations
1286 static bool handler_rename(int instance)
1288 union smb_rename parm[NSERVERS];
1289 NTSTATUS status[NSERVERS];
1291 parm[0].generic.level = RAW_RENAME_RENAME;
1292 parm[0].rename.in.pattern1 = gen_pattern();
1293 parm[0].rename.in.pattern2 = gen_pattern();
1294 parm[0].rename.in.attrib = gen_attrib();
1297 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1303 generate ntrename operations
1305 static bool handler_ntrename(int instance)
1307 union smb_rename parm[NSERVERS];
1308 NTSTATUS status[NSERVERS];
1310 parm[0].generic.level = RAW_RENAME_NTRENAME;
1311 parm[0].ntrename.in.old_name = gen_fname();
1312 parm[0].ntrename.in.new_name = gen_fname();
1313 parm[0].ntrename.in.attrib = gen_attrib();
1314 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1315 parm[0].ntrename.in.flags = gen_rename_flags();
1318 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1325 generate seek operations
1327 static bool handler_seek(int instance)
1329 union smb_seek parm[NSERVERS];
1330 NTSTATUS status[NSERVERS];
1332 parm[0].lseek.in.file.fnum = gen_fnum(instance);
1333 parm[0].lseek.in.mode = gen_bits_mask2(0x3, 0xFFFF);
1334 parm[0].lseek.in.offset = gen_offset();
1337 GEN_SET_FNUM(lseek.in.file.fnum);
1338 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1340 CHECK_EQUAL(lseek.out.offset);
1347 generate readx operations
1349 static bool handler_readx(int instance)
1351 union smb_read parm[NSERVERS];
1352 NTSTATUS status[NSERVERS];
1354 parm[0].readx.level = RAW_READ_READX;
1355 parm[0].readx.in.file.fnum = gen_fnum(instance);
1356 parm[0].readx.in.offset = gen_offset();
1357 parm[0].readx.in.mincnt = gen_io_count();
1358 parm[0].readx.in.maxcnt = gen_io_count();
1359 parm[0].readx.in.remaining = gen_io_count();
1360 parm[0].readx.in.read_for_execute = gen_bool();
1361 parm[0].readx.out.data = talloc_array(current_op.mem_ctx, uint8_t,
1362 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1365 GEN_SET_FNUM(readx.in.file.fnum);
1366 GEN_CALL(smb_raw_read(tree, &parm[i]));
1368 CHECK_EQUAL(readx.out.remaining);
1369 CHECK_EQUAL(readx.out.compaction_mode);
1370 CHECK_EQUAL(readx.out.nread);
1376 generate writex operations
1378 static bool handler_writex(int instance)
1380 union smb_write parm[NSERVERS];
1381 NTSTATUS status[NSERVERS];
1383 parm[0].writex.level = RAW_WRITE_WRITEX;
1384 parm[0].writex.in.file.fnum = gen_fnum(instance);
1385 parm[0].writex.in.offset = gen_offset();
1386 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1387 parm[0].writex.in.remaining = gen_io_count();
1388 parm[0].writex.in.count = gen_io_count();
1389 parm[0].writex.in.data = talloc_zero_array(current_op.mem_ctx, uint8_t, parm[0].writex.in.count);
1392 GEN_SET_FNUM(writex.in.file.fnum);
1393 GEN_CALL(smb_raw_write(tree, &parm[i]));
1395 CHECK_EQUAL(writex.out.nwritten);
1396 CHECK_EQUAL(writex.out.remaining);
1402 generate lockingx operations
1404 static bool handler_lockingx(int instance)
1406 union smb_lock parm[NSERVERS];
1407 NTSTATUS status[NSERVERS];
1410 parm[0].lockx.level = RAW_LOCK_LOCKX;
1411 parm[0].lockx.in.file.fnum = gen_fnum(instance);
1412 parm[0].lockx.in.mode = gen_lock_mode();
1413 parm[0].lockx.in.timeout = gen_timeout();
1415 /* make sure we don't accidentially generate an oplock
1416 break ack - otherwise the server can just block forever */
1417 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1418 parm[0].lockx.in.lock_cnt = gen_lock_count();
1419 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1420 } while (nlocks == 0);
1423 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
1424 struct smb_lock_entry,
1426 for (n=0;n<nlocks;n++) {
1427 parm[0].lockx.in.locks[n].pid = gen_pid();
1428 parm[0].lockx.in.locks[n].offset = gen_offset();
1429 parm[0].lockx.in.locks[n].count = gen_io_count();
1434 GEN_SET_FNUM(lockx.in.file.fnum);
1435 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1441 generate a fileinfo query structure
1443 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1446 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1448 enum smb_fileinfo_level level;
1451 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1452 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1453 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1454 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1455 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1456 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1457 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1458 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1459 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1460 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1463 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1464 } while (ignore_pattern(levels[i].name));
1466 info->generic.level = levels[i].level;
1470 compare returned fileinfo structures
1472 static bool cmp_fileinfo(int instance,
1473 union smb_fileinfo parm[NSERVERS],
1474 NTSTATUS status[NSERVERS])
1478 switch (parm[0].generic.level) {
1479 case RAW_FILEINFO_GENERIC:
1482 case RAW_FILEINFO_GETATTR:
1483 CHECK_EQUAL(getattr.out.attrib);
1484 CHECK_EQUAL(getattr.out.size);
1485 CHECK_TIMES_EQUAL(getattr.out.write_time);
1488 case RAW_FILEINFO_GETATTRE:
1489 CHECK_TIMES_EQUAL(getattre.out.create_time);
1490 CHECK_TIMES_EQUAL(getattre.out.access_time);
1491 CHECK_TIMES_EQUAL(getattre.out.write_time);
1492 CHECK_EQUAL(getattre.out.size);
1493 CHECK_EQUAL(getattre.out.alloc_size);
1494 CHECK_EQUAL(getattre.out.attrib);
1497 case RAW_FILEINFO_STANDARD:
1498 CHECK_TIMES_EQUAL(standard.out.create_time);
1499 CHECK_TIMES_EQUAL(standard.out.access_time);
1500 CHECK_TIMES_EQUAL(standard.out.write_time);
1501 CHECK_EQUAL(standard.out.size);
1502 CHECK_EQUAL(standard.out.alloc_size);
1503 CHECK_EQUAL(standard.out.attrib);
1506 case RAW_FILEINFO_EA_SIZE:
1507 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1508 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1509 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1510 CHECK_EQUAL(ea_size.out.size);
1511 CHECK_EQUAL(ea_size.out.alloc_size);
1512 CHECK_EQUAL(ea_size.out.attrib);
1513 CHECK_EQUAL(ea_size.out.ea_size);
1516 case RAW_FILEINFO_ALL_EAS:
1517 CHECK_EQUAL(all_eas.out.num_eas);
1518 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1519 CHECK_EQUAL(all_eas.out.eas[i].flags);
1520 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1521 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1525 case RAW_FILEINFO_IS_NAME_VALID:
1528 case RAW_FILEINFO_BASIC_INFO:
1529 case RAW_FILEINFO_BASIC_INFORMATION:
1530 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1531 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1532 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1533 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1534 CHECK_EQUAL(basic_info.out.attrib);
1537 case RAW_FILEINFO_STANDARD_INFO:
1538 case RAW_FILEINFO_STANDARD_INFORMATION:
1539 CHECK_EQUAL(standard_info.out.alloc_size);
1540 CHECK_EQUAL(standard_info.out.size);
1541 CHECK_EQUAL(standard_info.out.nlink);
1542 CHECK_EQUAL(standard_info.out.delete_pending);
1543 CHECK_EQUAL(standard_info.out.directory);
1546 case RAW_FILEINFO_EA_INFO:
1547 case RAW_FILEINFO_EA_INFORMATION:
1548 CHECK_EQUAL(ea_info.out.ea_size);
1551 case RAW_FILEINFO_NAME_INFO:
1552 case RAW_FILEINFO_NAME_INFORMATION:
1553 CHECK_WSTR_EQUAL(name_info.out.fname);
1556 case RAW_FILEINFO_ALL_INFO:
1557 case RAW_FILEINFO_ALL_INFORMATION:
1558 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1559 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1560 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1561 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1562 CHECK_EQUAL(all_info.out.attrib);
1563 CHECK_EQUAL(all_info.out.alloc_size);
1564 CHECK_EQUAL(all_info.out.size);
1565 CHECK_EQUAL(all_info.out.nlink);
1566 CHECK_EQUAL(all_info.out.delete_pending);
1567 CHECK_EQUAL(all_info.out.directory);
1568 CHECK_EQUAL(all_info.out.ea_size);
1569 CHECK_WSTR_EQUAL(all_info.out.fname);
1572 case RAW_FILEINFO_ALT_NAME_INFO:
1573 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1574 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1577 case RAW_FILEINFO_STREAM_INFO:
1578 case RAW_FILEINFO_STREAM_INFORMATION:
1579 CHECK_EQUAL(stream_info.out.num_streams);
1580 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1581 CHECK_EQUAL(stream_info.out.streams[i].size);
1582 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1583 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1587 case RAW_FILEINFO_COMPRESSION_INFO:
1588 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1589 CHECK_EQUAL(compression_info.out.compressed_size);
1590 CHECK_EQUAL(compression_info.out.format);
1591 CHECK_EQUAL(compression_info.out.unit_shift);
1592 CHECK_EQUAL(compression_info.out.chunk_shift);
1593 CHECK_EQUAL(compression_info.out.cluster_shift);
1596 case RAW_FILEINFO_INTERNAL_INFORMATION:
1597 CHECK_EQUAL(internal_information.out.file_id);
1600 case RAW_FILEINFO_ACCESS_INFORMATION:
1601 CHECK_EQUAL(access_information.out.access_flags);
1604 case RAW_FILEINFO_POSITION_INFORMATION:
1605 CHECK_EQUAL(position_information.out.position);
1608 case RAW_FILEINFO_MODE_INFORMATION:
1609 CHECK_EQUAL(mode_information.out.mode);
1612 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1613 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1616 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1617 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1618 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1619 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1620 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1621 CHECK_EQUAL(network_open_information.out.alloc_size);
1622 CHECK_EQUAL(network_open_information.out.size);
1623 CHECK_EQUAL(network_open_information.out.attrib);
1626 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1627 CHECK_EQUAL(attribute_tag_information.out.attrib);
1628 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1631 /* Unhandled levels */
1633 case RAW_FILEINFO_SEC_DESC:
1634 case RAW_FILEINFO_EA_LIST:
1635 case RAW_FILEINFO_UNIX_BASIC:
1636 case RAW_FILEINFO_UNIX_LINK:
1637 case RAW_FILEINFO_SMB2_ALL_EAS:
1638 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1646 generate qpathinfo operations
1648 static bool handler_qpathinfo(int instance)
1650 union smb_fileinfo parm[NSERVERS];
1651 NTSTATUS status[NSERVERS];
1653 parm[0].generic.in.file.path = gen_fname_open(instance);
1655 gen_fileinfo(instance, &parm[0]);
1658 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1660 return cmp_fileinfo(instance, parm, status);
1664 generate qfileinfo operations
1666 static bool handler_qfileinfo(int instance)
1668 union smb_fileinfo parm[NSERVERS];
1669 NTSTATUS status[NSERVERS];
1671 parm[0].generic.in.file.fnum = gen_fnum(instance);
1673 gen_fileinfo(instance, &parm[0]);
1676 GEN_SET_FNUM(generic.in.file.fnum);
1677 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1679 return cmp_fileinfo(instance, parm, status);
1684 generate a fileinfo query structure
1686 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1690 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1692 enum smb_setfileinfo_level level;
1696 /* disabled until win2003 can handle them ... */
1697 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1698 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1700 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1701 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1702 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1703 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1704 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1707 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1708 } while (ignore_pattern(levels[i].name));
1710 info->generic.level = levels[i].level;
1712 switch (info->generic.level) {
1713 case RAW_SFILEINFO_SETATTR:
1714 info->setattr.in.attrib = gen_attrib();
1715 info->setattr.in.write_time = gen_timet();
1717 case RAW_SFILEINFO_SETATTRE:
1718 info->setattre.in.create_time = gen_timet();
1719 info->setattre.in.access_time = gen_timet();
1720 info->setattre.in.write_time = gen_timet();
1722 case RAW_SFILEINFO_STANDARD:
1723 info->standard.in.create_time = gen_timet();
1724 info->standard.in.access_time = gen_timet();
1725 info->standard.in.write_time = gen_timet();
1727 case RAW_SFILEINFO_EA_SET: {
1728 static struct ea_struct ea;
1729 info->ea_set.in.num_eas = 1;
1730 info->ea_set.in.eas = &ea;
1731 info->ea_set.in.eas[0] = gen_ea_struct();
1734 case RAW_SFILEINFO_BASIC_INFO:
1735 case RAW_SFILEINFO_BASIC_INFORMATION:
1736 info->basic_info.in.create_time = gen_nttime();
1737 info->basic_info.in.access_time = gen_nttime();
1738 info->basic_info.in.write_time = gen_nttime();
1739 info->basic_info.in.change_time = gen_nttime();
1740 info->basic_info.in.attrib = gen_attrib();
1742 case RAW_SFILEINFO_DISPOSITION_INFO:
1743 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1744 info->disposition_info.in.delete_on_close = gen_bool();
1746 case RAW_SFILEINFO_ALLOCATION_INFO:
1747 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1748 info->allocation_info.in.alloc_size = gen_alloc_size();
1750 case RAW_SFILEINFO_END_OF_FILE_INFO:
1751 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1752 info->end_of_file_info.in.size = gen_offset();
1754 case RAW_SFILEINFO_RENAME_INFORMATION:
1755 info->rename_information.in.overwrite = gen_bool();
1756 info->rename_information.in.root_fid = gen_root_fid(instance);
1757 info->rename_information.in.new_name = gen_fname_open(instance);
1759 case RAW_SFILEINFO_POSITION_INFORMATION:
1760 info->position_information.in.position = gen_offset();
1762 case RAW_SFILEINFO_MODE_INFORMATION:
1763 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1765 case RAW_SFILEINFO_GENERIC:
1766 case RAW_SFILEINFO_SEC_DESC:
1767 case RAW_SFILEINFO_UNIX_BASIC:
1768 case RAW_SFILEINFO_UNIX_LINK:
1769 case RAW_SFILEINFO_UNIX_HLINK:
1770 case RAW_SFILEINFO_1023:
1771 case RAW_SFILEINFO_1025:
1772 case RAW_SFILEINFO_1029:
1773 case RAW_SFILEINFO_1032:
1774 case RAW_SFILEINFO_1039:
1775 case RAW_SFILEINFO_1040:
1782 generate setpathinfo operations
1784 static bool handler_spathinfo(int instance)
1786 union smb_setfileinfo parm[NSERVERS];
1787 NTSTATUS status[NSERVERS];
1789 parm[0].generic.in.file.path = gen_fname_open(instance);
1791 gen_setfileinfo(instance, &parm[0]);
1795 /* a special case for the fid in a RENAME */
1796 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1797 parm[0].rename_information.in.root_fid != 0) {
1798 GEN_SET_FNUM(rename_information.in.root_fid);
1801 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1808 generate setfileinfo operations
1810 static bool handler_sfileinfo(int instance)
1812 union smb_setfileinfo parm[NSERVERS];
1813 NTSTATUS status[NSERVERS];
1815 parm[0].generic.in.file.fnum = gen_fnum(instance);
1817 gen_setfileinfo(instance, &parm[0]);
1820 GEN_SET_FNUM(generic.in.file.fnum);
1821 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1828 generate change notify operations
1830 static bool handler_notify(int instance)
1832 union smb_notify parm[NSERVERS];
1835 ZERO_STRUCT(parm[0]);
1836 parm[0].nttrans.level = RAW_NOTIFY_NTTRANS;
1837 parm[0].nttrans.in.buffer_size = gen_io_count();
1838 parm[0].nttrans.in.completion_filter = gen_bits_mask(0xFF);
1839 parm[0].nttrans.in.file.fnum = gen_fnum(instance);
1840 parm[0].nttrans.in.recursive = gen_bool();
1843 GEN_SET_FNUM(nttrans.in.file.fnum);
1845 for (n=0;n<NSERVERS;n++) {
1846 struct smbcli_request *req;
1847 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1848 req->async.fn = async_notify;
1855 wipe any relevant files
1857 static void wipe_files(void)
1860 for (i=0;i<NSERVERS;i++) {
1861 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1863 printf("Failed to wipe tree on server %d\n", i);
1866 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1867 printf("Failed to create \\gentest - %s\n",
1868 smbcli_errstr(servers[i].cli[0]->tree));
1872 printf("Deleted %d files on server %d\n", n, i);
1878 dump the current seeds - useful for continuing a backtrack
1880 static void dump_seeds(void)
1885 if (!options.seeds_file) {
1888 f = fopen("seeds.tmp", "w");
1891 for (i=0;i<options.numops;i++) {
1892 fprintf(f, "%u\n", op_parms[i].seed);
1895 rename("seeds.tmp", options.seeds_file);
1901 the list of top-level operations that we will generate
1905 bool (*handler)(int instance);
1906 int count, success_count;
1908 {"OPEN", handler_open},
1909 {"OPENX", handler_openx},
1910 {"NTCREATEX", handler_ntcreatex},
1911 {"CLOSE", handler_close},
1912 {"UNLINK", handler_unlink},
1913 {"MKDIR", handler_mkdir},
1914 {"RMDIR", handler_rmdir},
1915 {"RENAME", handler_rename},
1916 {"NTRENAME", handler_ntrename},
1917 {"READX", handler_readx},
1918 {"WRITEX", handler_writex},
1919 {"CHKPATH", handler_chkpath},
1920 {"LOCKINGX", handler_lockingx},
1921 {"QPATHINFO", handler_qpathinfo},
1922 {"QFILEINFO", handler_qfileinfo},
1923 {"SPATHINFO", handler_spathinfo},
1924 {"SFILEINFO", handler_sfileinfo},
1925 {"NOTIFY", handler_notify},
1926 {"SEEK", handler_seek},
1931 run the test with the current set of op_parms parameters
1932 return the number of operations that completed successfully
1934 static int run_test(struct loadparm_context *lp_ctx)
1938 if (!connect_servers(lp_ctx)) {
1939 printf("Failed to connect to servers\n");
1945 /* wipe any leftover files from old runs */
1948 /* reset the open handles array */
1949 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1950 num_open_handles = 0;
1952 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1953 gen_ops[i].count = 0;
1954 gen_ops[i].success_count = 0;
1957 for (op=0; op<options.numops; op++) {
1958 int instance, which_op;
1961 if (op_parms[op].disabled) continue;
1963 srandom(op_parms[op].seed);
1965 instance = gen_int_range(0, NINSTANCES-1);
1967 /* generate a non-ignored operation */
1969 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1970 } while (ignore_pattern(gen_ops[which_op].name));
1972 DEBUG(3,("Generating op %s on instance %d\n",
1973 gen_ops[which_op].name, instance));
1975 current_op.seed = op_parms[op].seed;
1976 current_op.opnum = op;
1977 current_op.name = gen_ops[which_op].name;
1978 current_op.status = NT_STATUS_OK;
1979 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1981 ret = gen_ops[which_op].handler(instance);
1983 talloc_free(current_op.mem_ctx);
1985 gen_ops[which_op].count++;
1986 if (NT_STATUS_IS_OK(current_op.status)) {
1987 gen_ops[which_op].success_count++;
1991 printf("Failed at operation %d - %s\n",
1992 op, gen_ops[which_op].name);
1996 if (op % 100 == 0) {
2001 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2002 printf("Op %-10s got %d/%d success\n",
2004 gen_ops[i].success_count,
2012 perform a backtracking analysis of the minimal set of operations
2013 to generate an error
2015 static void backtrack_analyze(struct loadparm_context *lp_ctx)
2019 chunk = options.numops / 2;
2024 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2027 chunk = MIN(chunk, options.numops / 2);
2029 /* mark this range as disabled */
2030 max = MIN(options.numops, base+chunk);
2031 for (i=base;i<max; i++) {
2032 op_parms[i].disabled = true;
2034 printf("Testing %d ops with %d-%d disabled\n",
2035 options.numops, base, max-1);
2036 ret = run_test(lp_ctx);
2037 printf("Completed %d of %d ops\n", ret, options.numops);
2038 for (i=base;i<max; i++) {
2039 op_parms[i].disabled = false;
2041 if (ret == options.numops) {
2042 /* this chunk is needed */
2044 } else if (ret < base) {
2045 printf("damn - inconsistent errors! found early error\n");
2046 options.numops = ret+1;
2049 /* it failed - this chunk isn't needed for a failure */
2050 memmove(&op_parms[base], &op_parms[max],
2051 sizeof(op_parms[0]) * (options.numops - max));
2052 options.numops = (ret+1) - (max - base);
2062 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2065 } while (chunk > 0);
2067 printf("Reduced to %d ops\n", options.numops);
2068 ret = run_test(lp_ctx);
2069 if (ret != options.numops - 1) {
2070 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2075 start the main gentest process
2077 static bool start_gentest(struct loadparm_context *lp_ctx)
2082 /* allocate the open_handles array */
2083 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2085 srandom(options.seed);
2086 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2088 /* generate the seeds - after this everything is deterministic */
2089 if (options.use_preset_seeds) {
2091 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
2093 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2096 if (numops < options.numops) {
2097 options.numops = numops;
2099 for (op=0;op<options.numops;op++) {
2101 printf("Not enough seeds in %s\n", options.seeds_file);
2104 op_parms[op].seed = atoi(preset[op]);
2106 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2108 for (op=0; op<options.numops; op++) {
2109 op_parms[op].seed = random();
2113 ret = run_test(lp_ctx);
2115 if (ret != options.numops && options.analyze) {
2116 options.numops = ret+1;
2117 backtrack_analyze(lp_ctx);
2118 } else if (options.analyze_always) {
2119 backtrack_analyze(lp_ctx);
2120 } else if (options.analyze_continuous) {
2121 while (run_test(lp_ctx) == options.numops) ;
2124 return ret == options.numops;
2128 static void usage(void)
2132 gentest2 //server1/share1 //server2/share2 [options..]\n\
2134 -U user%%pass (can be specified twice)\n\
2137 -a (show all ops)\n\
2138 -A backtrack to find minimal ops\n\
2139 -i FILE add a list of wildcard exclusions\n\
2140 -O enable oplocks\n\
2141 -S FILE set preset seeds file\n\
2142 -L use preset seeds\n\
2143 -F fast reconnect (just close files)\n\
2144 -C continuous analysis mode\n\
2145 -X analyse even when test OK\n\
2150 split a UNC name into server and share names
2152 static bool split_unc_name(const char *unc, char **server, char **share)
2154 char *p = strdup(unc);
2155 if (!p) return false;
2156 all_string_sub(p, "\\", "/", 0);
2157 if (strncmp(p, "//", 2) != 0) return false;
2160 p = strchr(*server, '/');
2161 if (!p) return false;
2171 /****************************************************************************
2173 ****************************************************************************/
2174 int main(int argc, char *argv[])
2177 int i, username_count=0;
2179 struct loadparm_context *lp_ctx;
2183 setup_logging("gentest", DEBUG_STDOUT);
2185 if (argc < 3 || argv[1][0] == '-') {
2190 setup_logging(argv[0], DEBUG_STDOUT);
2192 for (i=0;i<NSERVERS;i++) {
2193 const char *share = argv[1+i];
2194 servers[i].credentials = cli_credentials_init(NULL);
2195 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2196 printf("Invalid share name '%s'\n", share);
2204 lp_ctx = loadparm_init(talloc_autofree_context());
2205 lp_load(lp_ctx, dyn_CONFIGFILE);
2207 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
2208 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
2209 cli_credentials_guess(servers[0].credentials, lp_ctx);
2210 cli_credentials_guess(servers[1].credentials, lp_ctx);
2212 options.seed = time(NULL);
2213 options.numops = 1000;
2214 options.max_open_handles = 20;
2215 options.seeds_file = "gentest_seeds.dat";
2217 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2220 if (username_count == 2) {
2224 cli_credentials_parse_string(servers[username_count].credentials,
2225 optarg, CRED_SPECIFIED);
2229 DEBUGLEVEL = atoi(optarg);
2230 setup_logging(NULL, DEBUG_STDOUT);
2233 options.seed = atoi(optarg);
2236 options.seeds_file = optarg;
2239 options.use_preset_seeds = true;
2242 options.fast_reconnect = true;
2245 options.numops = atoi(optarg);
2248 options.use_oplocks = true;
2251 options.showall = true;
2254 options.analyze = true;
2257 options.analyze_always = true;
2260 options.analyze_continuous = true;
2263 options.ignore_patterns = file_lines_load(optarg, NULL, NULL);
2269 printf("Unknown option %c (%d)\n", (char)opt, opt);
2274 gensec_init(lp_ctx);
2276 if (username_count == 0) {
2280 if (username_count == 1) {
2281 servers[1].credentials = servers[0].credentials;
2284 printf("seed=%u\n", options.seed);
2286 ret = start_gentest(lp_ctx);
2289 printf("gentest completed - no errors\n");
2291 printf("gentest failed\n");