2 Unix SMB/CIFS implementation.
4 generic testing tool - version with both SMB and SMB2 support
6 Copyright (C) Andrew Tridgell 2003-2008
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "lib/cmdline/popt_common.h"
24 #include "lib/events/events.h"
25 #include "system/time.h"
26 #include "system/filesys.h"
27 #include "libcli/raw/request.h"
28 #include "libcli/libcli.h"
29 #include "libcli/raw/libcliraw.h"
30 #include "libcli/smb2/smb2.h"
31 #include "libcli/smb2/smb2_calls.h"
32 #include "librpc/gen_ndr/security.h"
33 #include "librpc/gen_ndr/ndr_security.h"
34 #include "auth/credentials/credentials.h"
35 #include "libcli/resolve/resolve.h"
36 #include "auth/gensec/gensec.h"
37 #include "param/param.h"
38 #include "dynconfig/dynconfig.h"
39 #include "libcli/security/security.h"
40 #include "libcli/raw/raw_proto.h"
46 static struct gentest_options {
50 int analyze_continuous;
51 uint_t max_open_handles;
55 char **ignore_patterns;
56 const char *seeds_file;
67 /* mapping between open handles on the server and local handles */
71 struct smb2_handle smb2_handle[NSERVERS]; /* SMB2 */
72 uint16_t smb_handle[NSERVERS]; /* SMB */
75 static uint_t num_open_handles;
77 /* state information for the servers. We open NINSTANCES connections to
80 struct smb2_tree *smb2_tree[NINSTANCES];
81 struct smbcli_tree *smb_tree[NINSTANCES];
84 struct cli_credentials *credentials;
87 /* the seeds and flags for each operation */
94 /* oplock break info */
97 struct smb2_handle smb2_handle;
102 } oplocks[NSERVERS][NINSTANCES];
104 /* change notify reply info */
108 union smb_notify notify;
109 } notifies[NSERVERS][NINSTANCES];
111 /* info relevant to the current operation */
118 const char *mismatch;
121 static struct smb2_handle bad_smb2_handle;
124 #define BAD_HANDLE 0xFFFE
126 static bool oplock_handler_smb2(struct smb2_transport *transport, const struct smb2_handle *handle,
127 uint8_t level, void *private_data);
128 static void idle_func_smb2(struct smb2_transport *transport, void *private);
129 static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
130 static void idle_func_smb(struct smbcli_transport *transport, void *private);
133 check if a string should be ignored. This is used as the basis
134 for all error ignore settings
136 static bool ignore_pattern(const char *str)
139 if (!options.ignore_patterns) return false;
141 for (i=0;options.ignore_patterns[i];i++) {
142 if (strcmp(options.ignore_patterns[i], str) == 0 ||
143 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
144 DEBUG(2,("Ignoring '%s'\n", str));
151 /*****************************************************
152 connect to the servers
153 *******************************************************/
154 static bool connect_servers_fast(void)
158 /* close all open files */
159 for (h=0;h<options.max_open_handles;h++) {
160 if (!open_handles[h].active) continue;
161 for (i=0;i<NSERVERS;i++) {
164 status = smb2_util_close(servers[i].smb2_tree[open_handles[h].instance],
165 open_handles[h].smb2_handle[i]);
167 status = smbcli_close(servers[i].smb_tree[open_handles[h].instance],
168 open_handles[h].smb_handle[i]);
170 if (NT_STATUS_IS_ERR(status)) {
173 open_handles[h].active = false;
183 /*****************************************************
184 connect to the servers
185 *******************************************************/
186 static bool connect_servers(struct event_context *ev,
187 struct loadparm_context *lp_ctx)
191 if (options.fast_reconnect && servers[0].smb2_tree[0]) {
192 if (connect_servers_fast()) {
197 /* close any existing connections */
198 for (i=0;i<NSERVERS;i++) {
199 for (j=0;j<NINSTANCES;j++) {
200 if (servers[i].smb2_tree[j]) {
201 smb2_tdis(servers[i].smb2_tree[j]);
202 talloc_free(servers[i].smb2_tree[j]);
203 servers[i].smb2_tree[j] = NULL;
205 if (servers[i].smb_tree[j]) {
206 smb_tree_disconnect(servers[i].smb_tree[j]);
207 talloc_free(servers[i].smb_tree[j]);
208 servers[i].smb_tree[j] = NULL;
213 for (i=0;i<NSERVERS;i++) {
214 for (j=0;j<NINSTANCES;j++) {
216 struct smbcli_options smb_options;
217 struct smbcli_session_options smb_session_options;
218 lp_smbcli_options(lp_ctx, &smb_options);
219 lp_smbcli_session_options(lp_ctx, &smb_session_options);
221 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
222 servers[i].server_name, servers[i].share_name,
223 servers[i].credentials->username, j);
225 cli_credentials_set_workstation(servers[i].credentials,
226 "gentest", CRED_SPECIFIED);
229 status = smb2_connect(NULL, servers[i].server_name,
230 lp_smb_ports(lp_ctx),
231 servers[i].share_name,
232 lp_resolve_context(lp_ctx),
233 servers[i].credentials,
234 &servers[i].smb2_tree[j],
236 lp_socket_options(lp_ctx)
239 status = smbcli_tree_full_connection(NULL,
240 &servers[i].smb_tree[j],
241 servers[i].server_name,
242 lp_smb_ports(lp_ctx),
243 servers[i].share_name, "A:",
244 lp_socket_options(lp_ctx),
245 servers[i].credentials,
246 lp_resolve_context(lp_ctx), ev,
248 &smb_session_options,
249 lp_iconv_convenience(lp_ctx));
251 if (!NT_STATUS_IS_OK(status)) {
252 printf("Failed to connect to \\\\%s\\%s - %s\n",
253 servers[i].server_name, servers[i].share_name,
259 servers[i].smb2_tree[j]->session->transport->oplock.handler = oplock_handler_smb2;
260 servers[i].smb2_tree[j]->session->transport->oplock.private_data = (void *)(uintptr_t)((i<<8)|j);
261 smb2_transport_idle_handler(servers[i].smb2_tree[j]->session->transport,
262 idle_func_smb2, 50000, NULL);
264 smbcli_oplock_handler(servers[i].smb_tree[j]->session->transport, oplock_handler_smb,
265 (void *)(uintptr_t)((i<<8)|j));
266 smbcli_transport_idle_handler(servers[i].smb_tree[j]->session->transport, idle_func_smb,
267 50000, (void *)(uintptr_t)((i<<8)|j));
276 work out the time skew between the servers - be conservative
278 static uint_t time_skew(void)
282 ret = labs(servers[0].smb2_tree[0]->session->transport->negotiate.system_time -
283 servers[1].smb2_tree[0]->session->transport->negotiate.system_time);
285 ret = labs(servers[0].smb_tree[0]->session->transport->negotiate.server_time -
286 servers[1].smb_tree[0]->session->transport->negotiate.server_time);
292 static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_handle *h2)
294 return memcmp(h1, h2, sizeof(struct smb2_handle)) == 0;
298 turn a server handle into a local handle
300 static uint_t fnum_to_handle_smb2(int server, int instance, struct smb2_handle server_handle)
303 for (i=0;i<options.max_open_handles;i++) {
304 if (!open_handles[i].active ||
305 instance != open_handles[i].instance) continue;
306 if (smb2_handle_equal(&open_handles[i].smb2_handle[server], &server_handle)) {
310 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
316 turn a server handle into a local handle
318 static uint_t fnum_to_handle_smb(int server, int instance, uint16_t server_handle)
321 for (i=0;i<options.max_open_handles;i++) {
322 if (!open_handles[i].active ||
323 instance != open_handles[i].instance) continue;
324 if (open_handles[i].smb_handle[server] == server_handle) {
328 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
334 add some newly opened handles
336 static void gen_add_handle_smb2(int instance, const char *name, struct smb2_handle handles[NSERVERS])
339 for (h=0;h<options.max_open_handles;h++) {
340 if (!open_handles[h].active) break;
342 if (h == options.max_open_handles) {
343 /* we have to force close a random handle */
344 h = random() % options.max_open_handles;
345 for (i=0;i<NSERVERS;i++) {
347 status = smb2_util_close(servers[i].smb2_tree[open_handles[h].instance],
348 open_handles[h].smb2_handle[i]);
349 if (NT_STATUS_IS_ERR(status)) {
350 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
354 printf("Recovered handle %d\n", h);
357 for (i=0;i<NSERVERS;i++) {
358 open_handles[h].smb2_handle[i] = handles[i];
359 open_handles[h].instance = instance;
360 open_handles[h].active = true;
361 open_handles[h].name = name;
365 printf("OPEN num_open_handles=%d h=%d (%s)\n",
366 num_open_handles, h, name);
370 add some newly opened handles
372 static void gen_add_handle_smb(int instance, const char *name, uint16_t handles[NSERVERS])
375 for (h=0;h<options.max_open_handles;h++) {
376 if (!open_handles[h].active) break;
378 if (h == options.max_open_handles) {
379 /* we have to force close a random handle */
380 h = random() % options.max_open_handles;
381 for (i=0;i<NSERVERS;i++) {
383 status = smbcli_close(servers[i].smb_tree[open_handles[h].instance],
384 open_handles[h].smb_handle[i]);
385 if (NT_STATUS_IS_ERR(status)) {
386 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
390 printf("Recovered handle %d\n", h);
393 for (i=0;i<NSERVERS;i++) {
394 open_handles[h].smb_handle[i] = handles[i];
395 open_handles[h].instance = instance;
396 open_handles[h].active = true;
397 open_handles[h].name = name;
401 printf("OPEN num_open_handles=%d h=%d (%s)\n",
402 num_open_handles, h, name);
407 remove a closed handle
409 static void gen_remove_handle_smb2(int instance, struct smb2_handle handles[NSERVERS])
412 for (h=0;h<options.max_open_handles;h++) {
413 if (instance == open_handles[h].instance &&
414 smb2_handle_equal(&open_handles[h].smb2_handle[0], &handles[0])) {
415 open_handles[h].active = false;
417 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
419 open_handles[h].name);
423 printf("Removing invalid handle!?\n");
428 remove a closed handle
430 static void gen_remove_handle_smb(int instance, uint16_t handles[NSERVERS])
433 for (h=0;h<options.max_open_handles;h++) {
434 if (instance == open_handles[h].instance &&
435 open_handles[h].smb_handle[0] == handles[0]) {
436 open_handles[h].active = false;
438 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
440 open_handles[h].name);
444 printf("Removing invalid handle!?\n");
449 return true with 'chance' probability as a percentage
451 static bool gen_chance(uint_t chance)
453 return ((random() % 100) <= chance);
457 map an internal handle number to a server handle
459 static struct smb2_handle gen_lookup_handle_smb2(int server, uint16_t handle)
461 if (handle == BAD_HANDLE) return bad_smb2_handle;
462 return open_handles[handle].smb2_handle[server];
466 map an internal handle number to a server handle
468 static uint16_t gen_lookup_handle_smb(int server, uint16_t handle)
470 if (handle == BAD_HANDLE) return BAD_HANDLE;
471 return open_handles[handle].smb_handle[server];
477 static uint16_t gen_fnum(int instance)
482 if (gen_chance(20)) return BAD_HANDLE;
484 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
485 h = random() % options.max_open_handles;
486 if (open_handles[h].active &&
487 open_handles[h].instance == instance) {
495 return a file handle, but skewed so we don't close the last
496 couple of handles too readily
498 static uint16_t gen_fnum_close(int instance)
500 if (num_open_handles < 5) {
501 if (gen_chance(90)) return BAD_HANDLE;
504 return gen_fnum(instance);
508 generate an integer in a specified range
510 static int gen_int_range(uint64_t min, uint64_t max)
513 return min + (r % (1+max-min));
517 return a fnum for use as a root fid
518 be careful to call GEN_SET_FNUM() when you use this!
520 static uint16_t gen_root_fid(int instance)
522 if (gen_chance(5)) return gen_fnum(instance);
527 generate a file offset
529 static int gen_offset(void)
531 if (gen_chance(20)) return 0;
532 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
533 return gen_int_range(0, 1024*1024);
539 static int gen_io_count(void)
541 if (gen_chance(20)) return 0;
542 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
543 return gen_int_range(0, 4096);
549 static const char *gen_fname(void)
551 const char *names[] = {"gentest\\gentest.dat",
556 "gentest\\foo4:teststream1",
557 "gentest\\foo4:teststream2",
559 "gentest\\foo5.exe:teststream3",
560 "gentest\\foo5.exe:teststream4",
563 "gentest\\blah\\blergh.txt",
564 "gentest\\blah\\blergh2",
565 "gentest\\blah\\blergh3.txt",
566 "gentest\\blah\\blergh4",
567 "gentest\\blah\\blergh5.txt",
568 "gentest\\blah\\blergh5",
571 "gentest\\a_very_long_name.bin",
577 i = gen_int_range(0, ARRAY_SIZE(names)-1);
578 } while (ignore_pattern(names[i]));
584 generate a filename with a higher chance of choosing an already
587 static const char *gen_fname_open(int instance)
590 h = gen_fnum(instance);
591 if (h == BAD_HANDLE) {
594 return open_handles[h].name;
598 generate a wildcard pattern
600 static const char *gen_pattern(void)
603 const char *names[] = {"gentest\\*.dat",
606 "gentest\\blah\\*.*",
610 if (gen_chance(50)) return gen_fname();
613 i = gen_int_range(0, ARRAY_SIZE(names)-1);
614 } while (ignore_pattern(names[i]));
619 static uint32_t gen_bits_levels(int nlevels, ...)
625 va_start(ap, nlevels);
626 for (i=0;i<nlevels;i++) {
627 pct = va_arg(ap, uint32_t);
628 mask = va_arg(ap, uint32_t);
629 if (pct == 100 || gen_chance(pct)) {
631 return mask & random();
641 static uint32_t gen_bits_mask(uint_t mask)
643 uint_t ret = random();
648 generate a bitmask with high probability of the first mask
649 and low of the second
651 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
653 if (!options.valid && gen_chance(10)) return gen_bits_mask(mask2);
654 return gen_bits_mask(mask1);
658 generate reserved values
660 static uint64_t gen_reserved8(void)
662 if (options.valid) return 0;
663 return gen_bits_mask(0xFF);
666 static uint64_t gen_reserved16(void)
668 if (options.valid) return 0;
669 return gen_bits_mask(0xFFFF);
672 static uint64_t gen_reserved32(void)
674 if (options.valid) return 0;
675 return gen_bits_mask(0xFFFFFFFF);
678 static uint64_t gen_reserved64(void)
680 if (options.valid) return 0;
681 return gen_bits_mask(0xFFFFFFFF) | (((uint64_t)gen_bits_mask(0xFFFFFFFF))<<32);
689 static bool gen_bool(void)
691 return gen_bits_mask2(0x1, 0xFF);
695 generate ntrename flags
697 static uint16_t gen_rename_flags(void)
699 if (gen_chance(30)) return RENAME_FLAG_RENAME;
700 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
701 if (gen_chance(30)) return RENAME_FLAG_COPY;
702 return gen_bits_mask(0xFFFF);
708 static uint16_t gen_pid(void)
710 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
715 return a set of lock flags
717 static uint16_t gen_lock_flags_smb2(void)
719 if (!options.valid && gen_chance(5)) return gen_bits_mask(0xFFFF);
720 if (gen_chance(20)) return gen_bits_mask(0x1F);
721 if (gen_chance(50)) return SMB2_LOCK_FLAG_UNLOCK;
722 return gen_bits_mask(SMB2_LOCK_FLAG_SHARED |
723 SMB2_LOCK_FLAG_EXCLUSIVE |
724 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY);
728 generate a lock count
730 static off_t gen_lock_count(void)
732 return gen_int_range(0, 3);
736 generate a NT access mask
738 static uint32_t gen_access_mask(void)
741 if (gen_chance(70)) return SEC_FLAG_MAXIMUM_ALLOWED;
742 if (gen_chance(70)) return SEC_FILE_ALL;
743 ret = gen_bits_mask(0xFFFFFFFF);
744 if (options.valid) ret &= ~SEC_MASK_INVALID;
749 return a lockingx lock mode
751 static uint16_t gen_lock_mode(void)
753 if (!options.valid && gen_chance(5)) return gen_bits_mask(0xFFFF);
754 if (gen_chance(20)) return gen_bits_mask(0x1F);
755 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
759 generate a ntcreatex flags field
761 static uint32_t gen_ntcreatex_flags(void)
763 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
764 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
768 generate a ntcreatex create options bitfield
770 static uint32_t gen_create_options(void)
772 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
773 if (gen_chance(50)) return 0;
774 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
778 generate a ntcreatex open disposition
780 static uint32_t gen_open_disp(void)
782 if (gen_chance(50)) return NTCREATEX_DISP_OPEN_IF;
783 if (!options.valid && gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
784 return gen_int_range(0, 5);
788 generate an openx open mode
790 static uint16_t gen_openx_mode(void)
792 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
793 if (gen_chance(20)) return gen_bits_mask(0xFF);
794 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
798 generate an openx flags field
800 static uint16_t gen_openx_flags(void)
802 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
803 return gen_bits_mask(0x7);
807 generate an openx open function
809 static uint16_t gen_openx_func(void)
811 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
812 return gen_bits_mask(0x13);
816 generate a file attrib combination
818 static uint32_t gen_attrib(void)
821 if (gen_chance(20)) {
822 ret = gen_bits_mask(0xFFFFFFFF);
823 if (options.valid) ret &= FILE_ATTRIBUTE_ALL_MASK;
826 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
830 generate a unix timestamp
832 static time_t gen_timet(void)
834 if (gen_chance(30)) return 0;
835 return (time_t)random();
839 generate a milliseconds protocol timeout
841 static uint32_t gen_timeout(void)
843 if (gen_chance(98)) return 0;
844 return random() % 50;
850 static NTTIME gen_nttime(void)
853 unix_to_nt_time(&ret, gen_timet());
858 generate a timewarp value
860 static NTTIME gen_timewarp(void)
862 NTTIME ret = gen_nttime();
863 if (gen_chance(98)) ret = 0;
868 generate a file allocation size
870 static uint_t gen_alloc_size(void)
874 if (gen_chance(30)) return 0;
876 ret = random() % 4*1024*1024;
877 /* give a high chance of a round number */
878 if (gen_chance(60)) {
879 ret &= ~(1024*1024 - 1);
885 generate an ea_struct
887 static struct ea_struct gen_ea_struct(void)
890 const char *names[] = {"EAONE",
895 "AVERYLONGATTRIBUTENAME"};
896 const char *values[] = {"VALUE1",
901 "ASOMEWHATLONGERATTRIBUTEVALUE"};
907 i = gen_int_range(0, ARRAY_SIZE(names)-1);
908 } while (ignore_pattern(names[i]));
910 ea.name.s = names[i];
913 i = gen_int_range(0, ARRAY_SIZE(values)-1);
914 } while (ignore_pattern(values[i]));
916 ea.value = data_blob(values[i], strlen(values[i]));
918 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
925 generate an ea_struct
927 static struct smb_ea_list gen_ea_list(void)
929 struct smb_ea_list eas;
931 if (options.no_eas) {
935 eas.num_eas = gen_int_range(0, 3);
936 eas.eas = talloc_array(current_op.mem_ctx, struct ea_struct, eas.num_eas);
937 for (i=0;i<eas.num_eas;i++) {
938 eas.eas[i] = gen_ea_struct();
943 /* generate a security descriptor */
944 static struct security_descriptor *gen_sec_desc(void)
946 struct security_descriptor *sd;
947 if (options.no_acls || gen_chance(90)) return NULL;
949 sd = security_descriptor_dacl_create(current_op.mem_ctx,
952 SEC_ACE_TYPE_ACCESS_ALLOWED,
953 SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
954 SEC_ACE_FLAG_OBJECT_INHERIT,
956 SEC_ACE_TYPE_ACCESS_ALLOWED,
957 SEC_FILE_ALL | SEC_STD_ALL,
964 static void oplock_handler_close_recv_smb(struct smbcli_request *req)
967 status = smbcli_request_simple_recv(req);
968 if (!NT_STATUS_IS_OK(status)) {
969 printf("close failed in oplock_handler\n");
970 smb_panic("close failed in oplock_handler");
975 the oplock handler will either ack the break or close the file
977 static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
982 struct smbcli_tree *tree = NULL;
983 struct smbcli_request *req;
985 srandom(current_op.seed);
986 do_close = gen_chance(50);
988 for (i=0;i<NSERVERS;i++) {
989 for (j=0;j<NINSTANCES;j++) {
990 if (transport == servers[i].smb_tree[j]->session->transport &&
991 tid == servers[i].smb_tree[j]->tid) {
992 oplocks[i][j].got_break = true;
993 oplocks[i][j].smb_handle = fnum;
994 oplocks[i][j].handle = fnum_to_handle_smb(i, j, fnum);
995 oplocks[i][j].level = level;
996 oplocks[i][j].do_close = do_close;
997 tree = servers[i].smb_tree[j];
1003 printf("Oplock break not for one of our trees!?\n");
1008 printf("oplock ack fnum=%d\n", fnum);
1009 return smbcli_oplock_ack(tree, fnum, level);
1012 printf("oplock close fnum=%d\n", fnum);
1014 io.close.level = RAW_CLOSE_CLOSE;
1015 io.close.in.file.fnum = fnum;
1016 io.close.in.write_time = 0;
1017 req = smb_raw_close_send(tree, &io);
1020 printf("WARNING: close failed in oplock_handler_close\n");
1024 req->async.fn = oplock_handler_close_recv_smb;
1025 req->async.private = NULL;
1032 the idle function tries to cope with getting an oplock break on a connection, and
1033 an operation on another connection blocking until that break is acked
1034 we check for operations on all transports in the idle function
1036 static void idle_func_smb(struct smbcli_transport *transport, void *private)
1039 for (i=0;i<NSERVERS;i++) {
1040 for (j=0;j<NINSTANCES;j++) {
1041 if (servers[i].smb_tree[j] &&
1042 transport != servers[i].smb_tree[j]->session->transport) {
1043 smbcli_transport_process(servers[i].smb_tree[j]->session->transport);
1050 static void oplock_handler_close_recv_smb2(struct smb2_request *req)
1053 struct smb2_close io;
1054 status = smb2_close_recv(req, &io);
1055 if (!NT_STATUS_IS_OK(status)) {
1056 printf("close failed in oplock_handler\n");
1057 smb_panic("close failed in oplock_handler");
1061 static void oplock_handler_ack_callback_smb2(struct smb2_request *req)
1064 struct smb2_break br;
1066 status = smb2_break_recv(req, &br);
1067 if (!NT_STATUS_IS_OK(status)) {
1068 printf("oplock break ack failed in oplock_handler\n");
1069 smb_panic("oplock break ack failed in oplock_handler");
1073 static bool send_oplock_ack_smb2(struct smb2_tree *tree, struct smb2_handle handle,
1076 struct smb2_break br;
1077 struct smb2_request *req;
1080 br.in.file.handle = handle;
1081 br.in.oplock_level = level;
1082 br.in.reserved = gen_reserved8();
1083 br.in.reserved2 = gen_reserved32();
1085 req = smb2_break_send(tree, &br);
1086 if (req == NULL) return false;
1087 req->async.fn = oplock_handler_ack_callback_smb2;
1088 req->async.private_data = NULL;
1093 the oplock handler will either ack the break or close the file
1095 static bool oplock_handler_smb2(struct smb2_transport *transport, const struct smb2_handle *handle,
1096 uint8_t level, void *private_data)
1098 struct smb2_close io;
1101 struct smb2_tree *tree = NULL;
1102 struct smb2_request *req;
1104 srandom(current_op.seed);
1105 do_close = gen_chance(50);
1107 i = ((uintptr_t)private_data) >> 8;
1108 j = ((uintptr_t)private_data) & 0xFF;
1110 if (i >= NSERVERS || j >= NINSTANCES) {
1111 printf("Bad private_data in oplock_handler\n");
1115 oplocks[i][j].got_break = true;
1116 oplocks[i][j].smb2_handle = *handle;
1117 oplocks[i][j].handle = fnum_to_handle_smb2(i, j, *handle);
1118 oplocks[i][j].level = level;
1119 oplocks[i][j].do_close = do_close;
1120 tree = talloc_get_type(servers[i].smb2_tree[j], struct smb2_tree);
1123 printf("Oplock break not for one of our trees!?\n");
1128 printf("oplock ack handle=%d\n", oplocks[i][j].handle);
1129 return send_oplock_ack_smb2(tree, *handle, level);
1132 printf("oplock close fnum=%d\n", oplocks[i][j].handle);
1135 io.in.file.handle = *handle;
1137 req = smb2_close_send(tree, &io);
1140 printf("WARNING: close failed in oplock_handler_close\n");
1144 req->async.fn = oplock_handler_close_recv_smb2;
1145 req->async.private_data = NULL;
1152 the idle function tries to cope with getting an oplock break on a connection, and
1153 an operation on another connection blocking until that break is acked
1154 we check for operations on all transports in the idle function
1156 static void idle_func_smb2(struct smb2_transport *transport, void *private)
1159 for (i=0;i<NSERVERS;i++) {
1160 for (j=0;j<NINSTANCES;j++) {
1161 if (servers[i].smb2_tree[j] &&
1162 transport != servers[i].smb2_tree[j]->session->transport) {
1163 // smb2_transport_process(servers[i].smb2_tree[j]->session->transport);
1172 compare NTSTATUS, using checking ignored patterns
1174 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
1178 if (NT_STATUS_EQUAL(status1, status2)) return true;
1180 /* one code being an error and the other OK is always an error */
1181 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) {
1182 current_op.mismatch = nt_errstr(status1);
1186 /* if we are ignoring one of the status codes then consider this a match */
1187 if (ignore_pattern(nt_errstr(status1)) ||
1188 ignore_pattern(nt_errstr(status2))) {
1192 /* also support ignore patterns of the form NT_STATUS_XX:NT_STATUS_YY
1193 meaning that the first server returns NT_STATUS_XX and the 2nd
1194 returns NT_STATUS_YY */
1195 s = talloc_asprintf(current_op.mem_ctx, "%s:%s",
1197 nt_errstr(status2));
1198 if (ignore_pattern(s)) {
1202 current_op.mismatch = nt_errstr(status1);
1207 check for pending packets on all connections
1209 static void check_pending(void)
1215 for (j=0;j<NINSTANCES;j++) {
1216 for (i=0;i<NSERVERS;i++) {
1217 // smb2_transport_process(servers[i].smb2_tree[j]->session->transport);
1223 check that the same oplock breaks have been received by all instances
1225 static bool check_oplocks(const char *call)
1230 if (!options.use_oplocks || options.smb2) {
1231 /* no smb2 oplocks in gentest yet */
1238 for (j=0;j<NINSTANCES;j++) {
1239 for (i=1;i<NSERVERS;i++) {
1240 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
1241 oplocks[0][j].handle != oplocks[i][j].handle ||
1242 oplocks[0][j].level != oplocks[i][j].level) {
1243 if (tries++ < 10) goto again;
1244 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
1245 oplocks[0][j].got_break,
1246 oplocks[0][j].handle,
1247 oplocks[0][j].level,
1248 oplocks[i][j].got_break,
1249 oplocks[i][j].handle,
1250 oplocks[i][j].level);
1251 current_op.mismatch = "oplock break";
1257 /* if we got a break and closed then remove the handle */
1258 for (j=0;j<NINSTANCES;j++) {
1259 if (oplocks[0][j].got_break &&
1260 oplocks[0][j].do_close) {
1261 uint16_t fnums[NSERVERS];
1262 for (i=0;i<NSERVERS;i++) {
1263 fnums[i] = oplocks[i][j].smb_handle;
1265 gen_remove_handle_smb(j, fnums);
1274 check that the same change notify info has been received by all instances
1276 static bool check_notifies(const char *call)
1282 /* no smb2 notifies in gentest yet */
1289 for (j=0;j<NINSTANCES;j++) {
1290 for (i=1;i<NSERVERS;i++) {
1292 union smb_notify not1, not2;
1294 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
1295 if (tries++ < 10) goto again;
1296 printf("Notify count inconsistent %d %d\n",
1297 notifies[0][j].notify_count,
1298 notifies[i][j].notify_count);
1299 current_op.mismatch = "notify count";
1303 if (notifies[0][j].notify_count == 0) continue;
1305 if (!NT_STATUS_EQUAL(notifies[0][j].status,
1306 notifies[i][j].status)) {
1307 printf("Notify status mismatch - %s - %s\n",
1308 nt_errstr(notifies[0][j].status),
1309 nt_errstr(notifies[i][j].status));
1310 current_op.mismatch = "Notify status";
1314 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
1318 not1 = notifies[0][j].notify;
1319 not2 = notifies[i][j].notify;
1321 for (n=0;n<not1.nttrans.out.num_changes;n++) {
1322 if (not1.nttrans.out.changes[n].action !=
1323 not2.nttrans.out.changes[n].action) {
1324 printf("Notify action %d inconsistent %d %d\n", n,
1325 not1.nttrans.out.changes[n].action,
1326 not2.nttrans.out.changes[n].action);
1327 current_op.mismatch = "notify action";
1330 if (strcmp(not1.nttrans.out.changes[n].name.s,
1331 not2.nttrans.out.changes[n].name.s)) {
1332 printf("Notify name %d inconsistent %s %s\n", n,
1333 not1.nttrans.out.changes[n].name.s,
1334 not2.nttrans.out.changes[n].name.s);
1335 current_op.mismatch = "notify name";
1338 if (not1.nttrans.out.changes[n].name.private_length !=
1339 not2.nttrans.out.changes[n].name.private_length) {
1340 printf("Notify name length %d inconsistent %d %d\n", n,
1341 not1.nttrans.out.changes[n].name.private_length,
1342 not2.nttrans.out.changes[n].name.private_length);
1343 current_op.mismatch = "notify name length";
1350 ZERO_STRUCT(notifies);
1355 #define GEN_COPY_PARM do { \
1357 for (i=1;i<NSERVERS;i++) { \
1358 parm[i] = parm[0]; \
1362 #define GEN_CALL(call, treetype, treefield) do { \
1364 ZERO_STRUCT(oplocks); \
1365 ZERO_STRUCT(notifies); \
1366 for (i=0;i<NSERVERS;i++) { \
1367 struct treetype *tree = servers[i].treefield[instance]; \
1370 current_op.status = status[0]; \
1371 for (i=1;i<NSERVERS;i++) { \
1372 if (!compare_status(status[0], status[1])) { \
1373 printf("status different in %s - %s %s\n", #call, \
1374 nt_errstr(status[0]), nt_errstr(status[i])); \
1375 current_op.mismatch = nt_errstr(status[0]); \
1379 if (!check_oplocks(#call)) return false; \
1380 if (!check_notifies(#call)) return false; \
1381 if (!NT_STATUS_IS_OK(status[0])) { \
1386 #define GEN_CALL_SMB(call) GEN_CALL(call, smbcli_tree, smb_tree)
1387 #define GEN_CALL_SMB2(call) GEN_CALL(call, smb2_tree, smb2_tree)
1389 #define ADD_HANDLE_SMB2(name, field) do { \
1390 struct smb2_handle handles[NSERVERS]; \
1392 for (i=0;i<NSERVERS;i++) { \
1393 handles[i] = parm[i].field; \
1395 gen_add_handle_smb2(instance, name, handles); \
1398 #define REMOVE_HANDLE_SMB2(field) do { \
1399 struct smb2_handle handles[NSERVERS]; \
1401 for (i=0;i<NSERVERS;i++) { \
1402 handles[i] = parm[i].field; \
1404 gen_remove_handle_smb2(instance, handles); \
1407 #define ADD_HANDLE_SMB(name, field) do { \
1408 uint16_t handles[NSERVERS]; \
1410 for (i=0;i<NSERVERS;i++) { \
1411 handles[i] = parm[i].field; \
1413 gen_add_handle_smb(instance, name, handles); \
1416 #define REMOVE_HANDLE_SMB(field) do { \
1417 uint16_t handles[NSERVERS]; \
1419 for (i=0;i<NSERVERS;i++) { \
1420 handles[i] = parm[i].field; \
1422 gen_remove_handle_smb(instance, handles); \
1425 #define GEN_SET_FNUM_SMB2(field) do { \
1427 for (i=0;i<NSERVERS;i++) { \
1428 parm[i].field = gen_lookup_handle_smb2(i, parm[i].field.data[0]); \
1432 #define GEN_SET_FNUM_SMB(field) do { \
1434 for (i=0;i<NSERVERS;i++) { \
1435 parm[i].field = gen_lookup_handle_smb(i, parm[i].field); \
1439 #define CHECK_EQUAL(field) do { \
1440 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1441 current_op.mismatch = #field; \
1442 printf("Mismatch in %s - 0x%llx 0x%llx\n", #field, \
1443 (unsigned long long)parm[0].field, (unsigned long long)parm[1].field); \
1448 #define CHECK_SECDESC(field) do { \
1449 if (!security_acl_equal(parm[0].field->dacl, parm[1].field->dacl) && !ignore_pattern(#field)) { \
1450 current_op.mismatch = #field; \
1451 printf("Mismatch in %s\n", #field); \
1456 #define CHECK_ATTRIB(field) do { \
1457 if (!options.mask_indexing) { \
1458 CHECK_EQUAL(field); \
1459 } else if ((~FILE_ATTRIBUTE_NONINDEXED & parm[0].field) != (~FILE_ATTRIBUTE_NONINDEXED & parm[1].field) && !ignore_pattern(#field)) { \
1460 current_op.mismatch = #field; \
1461 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1462 (int)parm[0].field, (int)parm[1].field); \
1467 #define CHECK_WSTR_EQUAL(field) do { \
1468 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1469 current_op.mismatch = #field; \
1470 printf("%s is NULL!\n", #field); \
1473 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1474 current_op.mismatch = #field; \
1475 printf("Mismatch in %s - %s %s\n", #field, \
1476 parm[0].field.s, parm[1].field.s); \
1479 CHECK_EQUAL(field.private_length); \
1482 #define CHECK_BLOB_EQUAL(field) do { \
1483 if (((parm[0].field.data == NULL && parm[1].field.data != NULL) || \
1484 (parm[1].field.data == NULL && parm[0].field.data != NULL) || \
1485 (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0)) && !ignore_pattern(#field)) { \
1486 current_op.mismatch = #field; \
1487 printf("Mismatch in %s\n", #field); \
1490 CHECK_EQUAL(field.length); \
1493 #define CHECK_TIMES_EQUAL(field) do { \
1494 if (labs(parm[0].field - parm[1].field) > time_skew() && \
1495 !ignore_pattern(#field)) { \
1496 current_op.mismatch = #field; \
1497 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1498 (int)parm[0].field, (int)parm[1].field); \
1503 #define CHECK_NTTIMES_EQUAL(field) do { \
1504 if (labs(nt_time_to_unix(parm[0].field) - \
1505 nt_time_to_unix(parm[1].field)) > time_skew() && \
1506 !ignore_pattern(#field)) { \
1507 current_op.mismatch = #field; \
1508 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1509 (int)nt_time_to_unix(parm[0].field), \
1510 (int)nt_time_to_unix(parm[1].field)); \
1517 compare returned fileinfo structures
1519 static bool cmp_fileinfo(int instance,
1520 union smb_fileinfo parm[NSERVERS],
1521 NTSTATUS status[NSERVERS])
1524 enum smb_fileinfo_level level = parm[0].generic.level;
1526 if (level == RAW_FILEINFO_ALL_INFORMATION &&
1528 level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
1532 case RAW_FILEINFO_GENERIC:
1535 case RAW_FILEINFO_GETATTR:
1536 CHECK_ATTRIB(getattr.out.attrib);
1537 CHECK_EQUAL(getattr.out.size);
1538 CHECK_TIMES_EQUAL(getattr.out.write_time);
1541 case RAW_FILEINFO_GETATTRE:
1542 CHECK_TIMES_EQUAL(getattre.out.create_time);
1543 CHECK_TIMES_EQUAL(getattre.out.access_time);
1544 CHECK_TIMES_EQUAL(getattre.out.write_time);
1545 CHECK_EQUAL(getattre.out.size);
1546 CHECK_EQUAL(getattre.out.alloc_size);
1547 CHECK_ATTRIB(getattre.out.attrib);
1550 case RAW_FILEINFO_STANDARD:
1551 CHECK_TIMES_EQUAL(standard.out.create_time);
1552 CHECK_TIMES_EQUAL(standard.out.access_time);
1553 CHECK_TIMES_EQUAL(standard.out.write_time);
1554 CHECK_EQUAL(standard.out.size);
1555 CHECK_EQUAL(standard.out.alloc_size);
1556 CHECK_ATTRIB(standard.out.attrib);
1559 case RAW_FILEINFO_EA_SIZE:
1560 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1561 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1562 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1563 CHECK_EQUAL(ea_size.out.size);
1564 CHECK_EQUAL(ea_size.out.alloc_size);
1565 CHECK_ATTRIB(ea_size.out.attrib);
1566 CHECK_EQUAL(ea_size.out.ea_size);
1569 case RAW_FILEINFO_ALL_EAS:
1570 CHECK_EQUAL(all_eas.out.num_eas);
1571 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1572 CHECK_EQUAL(all_eas.out.eas[i].flags);
1573 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1574 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1578 case RAW_FILEINFO_IS_NAME_VALID:
1581 case RAW_FILEINFO_BASIC_INFO:
1582 case RAW_FILEINFO_BASIC_INFORMATION:
1583 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1584 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1585 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1586 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1587 CHECK_ATTRIB(basic_info.out.attrib);
1590 case RAW_FILEINFO_STANDARD_INFO:
1591 case RAW_FILEINFO_STANDARD_INFORMATION:
1592 CHECK_EQUAL(standard_info.out.alloc_size);
1593 CHECK_EQUAL(standard_info.out.size);
1594 CHECK_EQUAL(standard_info.out.nlink);
1595 CHECK_EQUAL(standard_info.out.delete_pending);
1596 CHECK_EQUAL(standard_info.out.directory);
1599 case RAW_FILEINFO_EA_INFO:
1600 case RAW_FILEINFO_EA_INFORMATION:
1601 CHECK_EQUAL(ea_info.out.ea_size);
1604 case RAW_FILEINFO_NAME_INFO:
1605 case RAW_FILEINFO_NAME_INFORMATION:
1606 CHECK_WSTR_EQUAL(name_info.out.fname);
1609 case RAW_FILEINFO_ALL_INFO:
1610 case RAW_FILEINFO_ALL_INFORMATION:
1611 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1612 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1613 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1614 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1615 CHECK_ATTRIB(all_info.out.attrib);
1616 CHECK_EQUAL(all_info.out.alloc_size);
1617 CHECK_EQUAL(all_info.out.size);
1618 CHECK_EQUAL(all_info.out.nlink);
1619 CHECK_EQUAL(all_info.out.delete_pending);
1620 CHECK_EQUAL(all_info.out.directory);
1621 CHECK_EQUAL(all_info.out.ea_size);
1622 CHECK_WSTR_EQUAL(all_info.out.fname);
1625 case RAW_FILEINFO_ALT_NAME_INFO:
1626 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1627 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1630 case RAW_FILEINFO_STREAM_INFO:
1631 case RAW_FILEINFO_STREAM_INFORMATION:
1632 CHECK_EQUAL(stream_info.out.num_streams);
1633 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1634 CHECK_EQUAL(stream_info.out.streams[i].size);
1635 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1636 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1640 case RAW_FILEINFO_COMPRESSION_INFO:
1641 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1642 CHECK_EQUAL(compression_info.out.compressed_size);
1643 CHECK_EQUAL(compression_info.out.format);
1644 CHECK_EQUAL(compression_info.out.unit_shift);
1645 CHECK_EQUAL(compression_info.out.chunk_shift);
1646 CHECK_EQUAL(compression_info.out.cluster_shift);
1649 case RAW_FILEINFO_INTERNAL_INFORMATION:
1650 CHECK_EQUAL(internal_information.out.file_id);
1653 case RAW_FILEINFO_ACCESS_INFORMATION:
1654 CHECK_EQUAL(access_information.out.access_flags);
1657 case RAW_FILEINFO_POSITION_INFORMATION:
1658 CHECK_EQUAL(position_information.out.position);
1661 case RAW_FILEINFO_MODE_INFORMATION:
1662 CHECK_EQUAL(mode_information.out.mode);
1665 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1666 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1669 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1670 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1671 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1672 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1673 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1674 CHECK_EQUAL(network_open_information.out.alloc_size);
1675 CHECK_EQUAL(network_open_information.out.size);
1676 CHECK_ATTRIB(network_open_information.out.attrib);
1679 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1680 CHECK_ATTRIB(attribute_tag_information.out.attrib);
1681 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1684 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1685 CHECK_NTTIMES_EQUAL(all_info2.out.create_time);
1686 CHECK_NTTIMES_EQUAL(all_info2.out.access_time);
1687 CHECK_NTTIMES_EQUAL(all_info2.out.write_time);
1688 CHECK_NTTIMES_EQUAL(all_info2.out.change_time);
1689 CHECK_ATTRIB(all_info2.out.attrib);
1690 CHECK_EQUAL(all_info2.out.unknown1);
1691 CHECK_EQUAL(all_info2.out.alloc_size);
1692 CHECK_EQUAL(all_info2.out.size);
1693 CHECK_EQUAL(all_info2.out.nlink);
1694 CHECK_EQUAL(all_info2.out.delete_pending);
1695 CHECK_EQUAL(all_info2.out.directory);
1696 CHECK_EQUAL(all_info2.out.file_id);
1697 CHECK_EQUAL(all_info2.out.ea_size);
1698 CHECK_EQUAL(all_info2.out.access_mask);
1699 CHECK_EQUAL(all_info2.out.position);
1700 CHECK_EQUAL(all_info2.out.mode);
1701 CHECK_EQUAL(all_info2.out.alignment_requirement);
1702 CHECK_WSTR_EQUAL(all_info2.out.fname);
1705 case RAW_FILEINFO_SMB2_ALL_EAS:
1706 CHECK_EQUAL(all_eas.out.num_eas);
1707 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1708 CHECK_EQUAL(all_eas.out.eas[i].flags);
1709 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1710 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1714 case RAW_FILEINFO_SEC_DESC:
1715 CHECK_SECDESC(query_secdesc.out.sd);
1718 /* Unhandled levels */
1719 case RAW_FILEINFO_EA_LIST:
1720 case RAW_FILEINFO_UNIX_BASIC:
1721 case RAW_FILEINFO_UNIX_LINK:
1722 case RAW_FILEINFO_UNIX_INFO2:
1732 generate openx operations
1734 static bool handler_smb_openx(int instance)
1736 union smb_open parm[NSERVERS];
1737 NTSTATUS status[NSERVERS];
1739 parm[0].openx.level = RAW_OPEN_OPENX;
1740 parm[0].openx.in.flags = gen_openx_flags();
1741 parm[0].openx.in.open_mode = gen_openx_mode();
1742 parm[0].openx.in.search_attrs = gen_attrib();
1743 parm[0].openx.in.file_attrs = gen_attrib();
1744 parm[0].openx.in.write_time = gen_timet();
1745 parm[0].openx.in.open_func = gen_openx_func();
1746 parm[0].openx.in.size = gen_io_count();
1747 parm[0].openx.in.timeout = gen_timeout();
1748 parm[0].openx.in.fname = gen_fname_open(instance);
1750 if (!options.use_oplocks) {
1751 /* mask out oplocks */
1752 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1753 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1757 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1759 CHECK_ATTRIB(openx.out.attrib);
1760 CHECK_EQUAL(openx.out.size);
1761 CHECK_EQUAL(openx.out.access);
1762 CHECK_EQUAL(openx.out.ftype);
1763 CHECK_EQUAL(openx.out.devstate);
1764 CHECK_EQUAL(openx.out.action);
1765 CHECK_EQUAL(openx.out.access_mask);
1766 CHECK_EQUAL(openx.out.unknown);
1767 CHECK_TIMES_EQUAL(openx.out.write_time);
1769 /* open creates a new file handle */
1770 ADD_HANDLE_SMB(parm[0].openx.in.fname, openx.out.file.fnum);
1777 generate open operations
1779 static bool handler_smb_open(int instance)
1781 union smb_open parm[NSERVERS];
1782 NTSTATUS status[NSERVERS];
1784 parm[0].openold.level = RAW_OPEN_OPEN;
1785 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1786 parm[0].openold.in.search_attrs = gen_attrib();
1787 parm[0].openold.in.fname = gen_fname_open(instance);
1789 if (!options.use_oplocks) {
1790 /* mask out oplocks */
1791 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1792 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1796 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1798 CHECK_ATTRIB(openold.out.attrib);
1799 CHECK_TIMES_EQUAL(openold.out.write_time);
1800 CHECK_EQUAL(openold.out.size);
1801 CHECK_EQUAL(openold.out.rmode);
1803 /* open creates a new file handle */
1804 ADD_HANDLE_SMB(parm[0].openold.in.fname, openold.out.file.fnum);
1811 generate ntcreatex operations
1813 static bool handler_smb_ntcreatex(int instance)
1815 union smb_open parm[NSERVERS];
1816 NTSTATUS status[NSERVERS];
1818 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1819 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1820 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1821 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1822 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1823 parm[0].ntcreatex.in.file_attr = gen_attrib();
1824 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1825 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1826 parm[0].ntcreatex.in.create_options = gen_create_options();
1827 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1828 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1829 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1831 if (!options.use_oplocks) {
1832 /* mask out oplocks */
1833 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1834 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1838 if (parm[0].ntcreatex.in.root_fid != 0) {
1839 GEN_SET_FNUM_SMB(ntcreatex.in.root_fid);
1841 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1843 CHECK_EQUAL(ntcreatex.out.oplock_level);
1844 CHECK_EQUAL(ntcreatex.out.create_action);
1845 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1846 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1847 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1848 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1849 CHECK_ATTRIB(ntcreatex.out.attrib);
1850 CHECK_EQUAL(ntcreatex.out.alloc_size);
1851 CHECK_EQUAL(ntcreatex.out.size);
1852 CHECK_EQUAL(ntcreatex.out.file_type);
1853 CHECK_EQUAL(ntcreatex.out.ipc_state);
1854 CHECK_EQUAL(ntcreatex.out.is_directory);
1856 /* ntcreatex creates a new file handle */
1857 ADD_HANDLE_SMB(parm[0].ntcreatex.in.fname, ntcreatex.out.file.fnum);
1863 generate close operations
1865 static bool handler_smb_close(int instance)
1867 union smb_close parm[NSERVERS];
1868 NTSTATUS status[NSERVERS];
1870 parm[0].close.level = RAW_CLOSE_CLOSE;
1871 parm[0].close.in.file.fnum = gen_fnum_close(instance);
1872 parm[0].close.in.write_time = gen_timet();
1875 GEN_SET_FNUM_SMB(close.in.file.fnum);
1876 GEN_CALL_SMB(smb_raw_close(tree, &parm[i]));
1878 REMOVE_HANDLE_SMB(close.in.file.fnum);
1884 generate unlink operations
1886 static bool handler_smb_unlink(int instance)
1888 union smb_unlink parm[NSERVERS];
1889 NTSTATUS status[NSERVERS];
1891 parm[0].unlink.in.pattern = gen_pattern();
1892 parm[0].unlink.in.attrib = gen_attrib();
1895 GEN_CALL_SMB(smb_raw_unlink(tree, &parm[i]));
1901 generate chkpath operations
1903 static bool handler_smb_chkpath(int instance)
1905 union smb_chkpath parm[NSERVERS];
1906 NTSTATUS status[NSERVERS];
1908 parm[0].chkpath.in.path = gen_fname_open(instance);
1911 GEN_CALL_SMB(smb_raw_chkpath(tree, &parm[i]));
1917 generate mkdir operations
1919 static bool handler_smb_mkdir(int instance)
1921 union smb_mkdir parm[NSERVERS];
1922 NTSTATUS status[NSERVERS];
1924 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1925 parm[0].mkdir.in.path = gen_fname_open(instance);
1928 GEN_CALL_SMB(smb_raw_mkdir(tree, &parm[i]));
1934 generate rmdir operations
1936 static bool handler_smb_rmdir(int instance)
1938 struct smb_rmdir parm[NSERVERS];
1939 NTSTATUS status[NSERVERS];
1941 parm[0].in.path = gen_fname_open(instance);
1944 GEN_CALL_SMB(smb_raw_rmdir(tree, &parm[i]));
1950 generate rename operations
1952 static bool handler_smb_rename(int instance)
1954 union smb_rename parm[NSERVERS];
1955 NTSTATUS status[NSERVERS];
1957 parm[0].generic.level = RAW_RENAME_RENAME;
1958 parm[0].rename.in.pattern1 = gen_pattern();
1959 parm[0].rename.in.pattern2 = gen_pattern();
1960 parm[0].rename.in.attrib = gen_attrib();
1963 GEN_CALL_SMB(smb_raw_rename(tree, &parm[i]));
1969 generate ntrename operations
1971 static bool handler_smb_ntrename(int instance)
1973 union smb_rename parm[NSERVERS];
1974 NTSTATUS status[NSERVERS];
1976 parm[0].generic.level = RAW_RENAME_NTRENAME;
1977 parm[0].ntrename.in.old_name = gen_fname();
1978 parm[0].ntrename.in.new_name = gen_fname();
1979 parm[0].ntrename.in.attrib = gen_attrib();
1980 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1981 parm[0].ntrename.in.flags = gen_rename_flags();
1984 GEN_CALL_SMB(smb_raw_rename(tree, &parm[i]));
1991 generate seek operations
1993 static bool handler_smb_seek(int instance)
1995 union smb_seek parm[NSERVERS];
1996 NTSTATUS status[NSERVERS];
1998 parm[0].lseek.in.file.fnum = gen_fnum(instance);
1999 parm[0].lseek.in.mode = gen_bits_mask2(0x3, 0xFFFF);
2000 parm[0].lseek.in.offset = gen_offset();
2003 GEN_SET_FNUM_SMB(lseek.in.file.fnum);
2004 GEN_CALL_SMB(smb_raw_seek(tree, &parm[i]));
2006 CHECK_EQUAL(lseek.out.offset);
2013 generate readx operations
2015 static bool handler_smb_readx(int instance)
2017 union smb_read parm[NSERVERS];
2018 NTSTATUS status[NSERVERS];
2020 parm[0].readx.level = RAW_READ_READX;
2021 parm[0].readx.in.file.fnum = gen_fnum(instance);
2022 parm[0].readx.in.offset = gen_offset();
2023 parm[0].readx.in.mincnt = gen_io_count();
2024 parm[0].readx.in.maxcnt = gen_io_count();
2025 parm[0].readx.in.remaining = gen_io_count();
2026 parm[0].readx.in.read_for_execute = gen_bool();
2027 parm[0].readx.out.data = talloc_array(current_op.mem_ctx, uint8_t,
2028 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
2031 GEN_SET_FNUM_SMB(readx.in.file.fnum);
2032 GEN_CALL_SMB(smb_raw_read(tree, &parm[i]));
2034 CHECK_EQUAL(readx.out.remaining);
2035 CHECK_EQUAL(readx.out.compaction_mode);
2036 CHECK_EQUAL(readx.out.nread);
2042 generate writex operations
2044 static bool handler_smb_writex(int instance)
2046 union smb_write parm[NSERVERS];
2047 NTSTATUS status[NSERVERS];
2049 parm[0].writex.level = RAW_WRITE_WRITEX;
2050 parm[0].writex.in.file.fnum = gen_fnum(instance);
2051 parm[0].writex.in.offset = gen_offset();
2052 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
2053 parm[0].writex.in.remaining = gen_io_count();
2054 parm[0].writex.in.count = gen_io_count();
2055 parm[0].writex.in.data = talloc_zero_array(current_op.mem_ctx, uint8_t, parm[0].writex.in.count);
2058 GEN_SET_FNUM_SMB(writex.in.file.fnum);
2059 GEN_CALL_SMB(smb_raw_write(tree, &parm[i]));
2061 CHECK_EQUAL(writex.out.nwritten);
2062 CHECK_EQUAL(writex.out.remaining);
2068 generate lockingx operations
2070 static bool handler_smb_lockingx(int instance)
2072 union smb_lock parm[NSERVERS];
2073 NTSTATUS status[NSERVERS];
2076 parm[0].lockx.level = RAW_LOCK_LOCKX;
2077 parm[0].lockx.in.file.fnum = gen_fnum(instance);
2078 parm[0].lockx.in.mode = gen_lock_mode();
2079 parm[0].lockx.in.timeout = gen_timeout();
2081 /* make sure we don't accidentially generate an oplock
2082 break ack - otherwise the server can just block forever */
2083 parm[0].lockx.in.ulock_cnt = gen_lock_count();
2084 parm[0].lockx.in.lock_cnt = gen_lock_count();
2085 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
2086 } while (nlocks == 0);
2089 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
2090 struct smb_lock_entry,
2092 for (n=0;n<nlocks;n++) {
2093 parm[0].lockx.in.locks[n].pid = gen_pid();
2094 parm[0].lockx.in.locks[n].offset = gen_offset();
2095 parm[0].lockx.in.locks[n].count = gen_io_count();
2100 GEN_SET_FNUM_SMB(lockx.in.file.fnum);
2101 GEN_CALL_SMB(smb_raw_lock(tree, &parm[i]));
2108 generate a fileinfo query structure
2110 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
2114 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
2116 enum smb_setfileinfo_level level;
2120 /* disabled until win2003 can handle them ... */
2121 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
2122 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
2124 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
2125 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2126 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
2127 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2128 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
2131 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2132 } while (ignore_pattern(levels[i].name));
2134 info->generic.level = levels[i].level;
2136 switch (info->generic.level) {
2137 case RAW_SFILEINFO_SETATTR:
2138 info->setattr.in.attrib = gen_attrib();
2139 info->setattr.in.write_time = gen_timet();
2141 case RAW_SFILEINFO_SETATTRE:
2142 info->setattre.in.create_time = gen_timet();
2143 info->setattre.in.access_time = gen_timet();
2144 info->setattre.in.write_time = gen_timet();
2146 case RAW_SFILEINFO_STANDARD:
2147 info->standard.in.create_time = gen_timet();
2148 info->standard.in.access_time = gen_timet();
2149 info->standard.in.write_time = gen_timet();
2151 case RAW_SFILEINFO_EA_SET: {
2152 static struct ea_struct ea;
2153 info->ea_set.in.num_eas = 1;
2154 info->ea_set.in.eas = &ea;
2155 info->ea_set.in.eas[0] = gen_ea_struct();
2158 case RAW_SFILEINFO_BASIC_INFO:
2159 case RAW_SFILEINFO_BASIC_INFORMATION:
2160 info->basic_info.in.create_time = gen_nttime();
2161 info->basic_info.in.access_time = gen_nttime();
2162 info->basic_info.in.write_time = gen_nttime();
2163 info->basic_info.in.change_time = gen_nttime();
2164 info->basic_info.in.attrib = gen_attrib();
2166 case RAW_SFILEINFO_DISPOSITION_INFO:
2167 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
2168 info->disposition_info.in.delete_on_close = gen_bool();
2170 case RAW_SFILEINFO_ALLOCATION_INFO:
2171 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
2172 info->allocation_info.in.alloc_size = gen_alloc_size();
2174 case RAW_SFILEINFO_END_OF_FILE_INFO:
2175 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
2176 info->end_of_file_info.in.size = gen_offset();
2178 case RAW_SFILEINFO_RENAME_INFORMATION:
2179 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
2180 info->rename_information.in.overwrite = gen_bool();
2181 info->rename_information.in.root_fid = gen_root_fid(instance);
2182 info->rename_information.in.new_name = gen_fname_open(instance);
2184 case RAW_SFILEINFO_POSITION_INFORMATION:
2185 info->position_information.in.position = gen_offset();
2187 case RAW_SFILEINFO_MODE_INFORMATION:
2188 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
2190 case RAW_SFILEINFO_FULL_EA_INFORMATION:
2191 info->full_ea_information.in.eas = gen_ea_list();
2193 case RAW_SFILEINFO_GENERIC:
2194 case RAW_SFILEINFO_SEC_DESC:
2195 case RAW_SFILEINFO_UNIX_BASIC:
2196 case RAW_SFILEINFO_UNIX_LINK:
2197 case RAW_SFILEINFO_UNIX_HLINK:
2198 case RAW_SFILEINFO_1023:
2199 case RAW_SFILEINFO_1025:
2200 case RAW_SFILEINFO_1029:
2201 case RAW_SFILEINFO_1032:
2202 case RAW_SFILEINFO_1039:
2203 case RAW_SFILEINFO_1040:
2204 case RAW_SFILEINFO_UNIX_INFO2:
2212 generate a fileinfo query structure
2214 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
2218 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
2220 enum smb_setfileinfo_level level;
2223 struct levels smb_levels[] = {
2224 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
2225 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
2226 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
2227 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2228 LVL(POSITION_INFORMATION), LVL(FULL_EA_INFORMATION), LVL(MODE_INFORMATION),
2229 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2230 LVL(PIPE_INFORMATION), LVL(VALID_DATA_INFORMATION), LVL(SHORT_NAME_INFORMATION),
2231 LVL(1025), LVL(1027), LVL(1029), LVL(1030), LVL(1031), LVL(1032), LVL(1036),
2232 LVL(1041), LVL(1042), LVL(1043), LVL(1044),
2234 struct levels smb2_levels[] = {
2235 LVL(BASIC_INFORMATION),
2236 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2237 LVL(POSITION_INFORMATION), LVL(FULL_EA_INFORMATION), LVL(MODE_INFORMATION),
2238 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2239 LVL(PIPE_INFORMATION), LVL(VALID_DATA_INFORMATION), LVL(SHORT_NAME_INFORMATION),
2240 LVL(1025), LVL(1027), LVL(1029), LVL(1030), LVL(1031), LVL(1032), LVL(1036),
2241 LVL(1041), LVL(1042), LVL(1043), LVL(1044),
2243 struct levels *levels = options.smb2?smb2_levels:smb_levels;
2244 uint32_t num_levels = options.smb2?ARRAY_SIZE(smb2_levels):ARRAY_SIZE(smb_levels);
2247 i = gen_int_range(0, num_levels-1);
2248 } while (ignore_pattern(levels[i].name));
2251 info->generic.level = levels[i].level;
2253 switch (info->generic.level) {
2254 case RAW_SFILEINFO_SETATTR:
2255 info->setattr.in.attrib = gen_attrib();
2256 info->setattr.in.write_time = gen_timet();
2258 case RAW_SFILEINFO_SETATTRE:
2259 info->setattre.in.create_time = gen_timet();
2260 info->setattre.in.access_time = gen_timet();
2261 info->setattre.in.write_time = gen_timet();
2263 case RAW_SFILEINFO_STANDARD:
2264 info->standard.in.create_time = gen_timet();
2265 info->standard.in.access_time = gen_timet();
2266 info->standard.in.write_time = gen_timet();
2268 case RAW_SFILEINFO_EA_SET: {
2269 static struct ea_struct ea;
2270 info->ea_set.in.num_eas = 1;
2271 info->ea_set.in.eas = &ea;
2272 info->ea_set.in.eas[0] = gen_ea_struct();
2275 case RAW_SFILEINFO_BASIC_INFO:
2276 case RAW_SFILEINFO_BASIC_INFORMATION:
2277 info->basic_info.in.create_time = gen_nttime();
2278 info->basic_info.in.access_time = gen_nttime();
2279 info->basic_info.in.write_time = gen_nttime();
2280 info->basic_info.in.change_time = gen_nttime();
2281 info->basic_info.in.attrib = gen_attrib();
2283 case RAW_SFILEINFO_DISPOSITION_INFO:
2284 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
2285 info->disposition_info.in.delete_on_close = gen_bool();
2287 case RAW_SFILEINFO_ALLOCATION_INFO:
2288 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
2289 info->allocation_info.in.alloc_size = gen_alloc_size();
2291 case RAW_SFILEINFO_END_OF_FILE_INFO:
2292 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
2293 info->end_of_file_info.in.size = gen_offset();
2295 case RAW_SFILEINFO_RENAME_INFORMATION:
2296 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
2297 info->rename_information.in.overwrite = gen_bool();
2298 info->rename_information.in.root_fid = gen_root_fid(instance);
2299 info->rename_information.in.new_name = gen_fname_open(instance);
2301 case RAW_SFILEINFO_POSITION_INFORMATION:
2302 info->position_information.in.position = gen_offset();
2304 case RAW_SFILEINFO_MODE_INFORMATION:
2305 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
2307 case RAW_SFILEINFO_FULL_EA_INFORMATION:
2308 info->full_ea_information.in.eas = gen_ea_list();
2311 case RAW_SFILEINFO_GENERIC:
2312 case RAW_SFILEINFO_SEC_DESC:
2313 case RAW_SFILEINFO_1025:
2314 case RAW_SFILEINFO_1029:
2315 case RAW_SFILEINFO_1032:
2316 case RAW_SFILEINFO_UNIX_BASIC:
2317 case RAW_SFILEINFO_UNIX_INFO2:
2318 case RAW_SFILEINFO_UNIX_LINK:
2319 case RAW_SFILEINFO_UNIX_HLINK:
2328 generate a fileinfo query structure
2330 static void gen_fileinfo_smb(int instance, union smb_fileinfo *info)
2334 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
2336 enum smb_fileinfo_level level;
2339 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
2340 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
2341 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
2342 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
2343 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
2344 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
2345 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
2346 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
2347 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
2348 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
2351 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2352 } while (ignore_pattern(levels[i].name));
2354 info->generic.level = levels[i].level;
2358 generate qpathinfo operations
2360 static bool handler_smb_qpathinfo(int instance)
2362 union smb_fileinfo parm[NSERVERS];
2363 NTSTATUS status[NSERVERS];
2365 parm[0].generic.in.file.path = gen_fname_open(instance);
2367 gen_fileinfo_smb(instance, &parm[0]);
2370 GEN_CALL_SMB(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
2372 return cmp_fileinfo(instance, parm, status);
2376 generate qfileinfo operations
2378 static bool handler_smb_qfileinfo(int instance)
2380 union smb_fileinfo parm[NSERVERS];
2381 NTSTATUS status[NSERVERS];
2383 parm[0].generic.in.file.fnum = gen_fnum(instance);
2385 gen_fileinfo_smb(instance, &parm[0]);
2388 GEN_SET_FNUM_SMB(generic.in.file.fnum);
2389 GEN_CALL_SMB(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
2391 return cmp_fileinfo(instance, parm, status);
2396 generate setpathinfo operations
2398 static bool handler_smb_spathinfo(int instance)
2400 union smb_setfileinfo parm[NSERVERS];
2401 NTSTATUS status[NSERVERS];
2403 gen_setfileinfo(instance, &parm[0]);
2404 parm[0].generic.in.file.path = gen_fname_open(instance);
2408 /* a special case for the fid in a RENAME */
2409 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
2410 parm[0].rename_information.in.root_fid != 0) {
2411 GEN_SET_FNUM_SMB(rename_information.in.root_fid);
2414 GEN_CALL_SMB(smb_raw_setpathinfo(tree, &parm[i]));
2421 generate setfileinfo operations
2423 static bool handler_smb_sfileinfo(int instance)
2425 union smb_setfileinfo parm[NSERVERS];
2426 NTSTATUS status[NSERVERS];
2428 parm[0].generic.in.file.fnum = gen_fnum(instance);
2430 gen_setfileinfo(instance, &parm[0]);
2433 GEN_SET_FNUM_SMB(generic.in.file.fnum);
2434 GEN_CALL_SMB(smb_raw_setfileinfo(tree, &parm[i]));
2441 this is called when a change notify reply comes in
2443 static void async_notify_smb(struct smbcli_request *req)
2445 union smb_notify notify;
2449 struct smbcli_transport *transport = req->transport;
2451 tid = SVAL(req->in.hdr, HDR_TID);
2453 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
2454 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
2455 if (NT_STATUS_IS_OK(status) && notify.nttrans.out.num_changes > 0) {
2456 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
2458 notify.nttrans.out.num_changes,
2459 notify.nttrans.out.changes[0].action,
2460 notify.nttrans.out.changes[0].name.s);
2463 for (i=0;i<NSERVERS;i++) {
2464 for (j=0;j<NINSTANCES;j++) {
2465 if (transport == servers[i].smb_tree[j]->session->transport &&
2466 tid == servers[i].smb_tree[j]->tid) {
2467 notifies[i][j].notify_count++;
2468 notifies[i][j].status = status;
2469 notifies[i][j].notify = notify;
2476 generate change notify operations
2478 static bool handler_smb_notify(int instance)
2480 union smb_notify parm[NSERVERS];
2483 ZERO_STRUCT(parm[0]);
2484 parm[0].nttrans.level = RAW_NOTIFY_NTTRANS;
2485 parm[0].nttrans.in.buffer_size = gen_io_count();
2486 parm[0].nttrans.in.completion_filter = gen_bits_mask(0xFF);
2487 parm[0].nttrans.in.file.fnum = gen_fnum(instance);
2488 parm[0].nttrans.in.recursive = gen_bool();
2491 GEN_SET_FNUM_SMB(nttrans.in.file.fnum);
2493 for (n=0;n<NSERVERS;n++) {
2494 struct smbcli_request *req;
2495 req = smb_raw_changenotify_send(servers[n].smb_tree[instance], &parm[n]);
2496 req->async.fn = async_notify_smb;
2504 generate ntcreatex operations
2506 static bool handler_smb2_create(int instance)
2508 struct smb2_create parm[NSERVERS];
2509 NTSTATUS status[NSERVERS];
2511 ZERO_STRUCT(parm[0]);
2512 parm[0].in.security_flags = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFF);
2513 parm[0].in.oplock_level = gen_bits_levels(3, 90, 0x0, 70, 0x9, 100, 0xFF);
2514 parm[0].in.impersonation_level = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFFFFFFFF);
2515 parm[0].in.create_flags = gen_reserved64();
2516 parm[0].in.reserved = gen_reserved64();
2517 parm[0].in.desired_access = gen_access_mask();
2518 parm[0].in.file_attributes = gen_attrib();
2519 parm[0].in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
2520 parm[0].in.create_disposition = gen_open_disp();
2521 parm[0].in.create_options = gen_create_options();
2522 parm[0].in.fname = gen_fname_open(instance);
2523 parm[0].in.eas = gen_ea_list();
2524 parm[0].in.alloc_size = gen_alloc_size();
2525 parm[0].in.durable_open = gen_bool();
2526 parm[0].in.query_maximal_access = gen_bool();
2527 parm[0].in.timewarp = gen_timewarp();
2528 parm[0].in.query_on_disk_id = gen_bool();
2529 parm[0].in.sec_desc = gen_sec_desc();
2531 if (!options.use_oplocks) {
2532 /* mask out oplocks */
2533 parm[0].in.oplock_level = 0;
2536 if (options.valid) {
2537 parm[0].in.security_flags &= 3;
2538 parm[0].in.oplock_level &= 9;
2539 parm[0].in.impersonation_level &= 3;
2543 GEN_CALL_SMB2(smb2_create(tree, current_op.mem_ctx, &parm[i]));
2545 CHECK_EQUAL(out.oplock_level);
2546 CHECK_EQUAL(out.reserved);
2547 CHECK_EQUAL(out.create_action);
2548 CHECK_NTTIMES_EQUAL(out.create_time);
2549 CHECK_NTTIMES_EQUAL(out.access_time);
2550 CHECK_NTTIMES_EQUAL(out.write_time);
2551 CHECK_NTTIMES_EQUAL(out.change_time);
2552 CHECK_EQUAL(out.alloc_size);
2553 CHECK_EQUAL(out.size);
2554 CHECK_ATTRIB(out.file_attr);
2555 CHECK_EQUAL(out.reserved2);
2556 CHECK_EQUAL(out.maximal_access);
2558 /* ntcreatex creates a new file handle */
2559 ADD_HANDLE_SMB2(parm[0].in.fname, out.file.handle);
2565 generate close operations
2567 static bool handler_smb2_close(int instance)
2569 struct smb2_close parm[NSERVERS];
2570 NTSTATUS status[NSERVERS];
2572 ZERO_STRUCT(parm[0]);
2573 parm[0].in.file.handle.data[0] = gen_fnum_close(instance);
2574 parm[0].in.flags = gen_bits_mask2(0x1, 0xFFFF);
2577 GEN_SET_FNUM_SMB2(in.file.handle);
2578 GEN_CALL_SMB2(smb2_close(tree, &parm[i]));
2580 CHECK_EQUAL(out.flags);
2581 CHECK_EQUAL(out._pad);
2582 CHECK_NTTIMES_EQUAL(out.create_time);
2583 CHECK_NTTIMES_EQUAL(out.access_time);
2584 CHECK_NTTIMES_EQUAL(out.write_time);
2585 CHECK_NTTIMES_EQUAL(out.change_time);
2586 CHECK_EQUAL(out.alloc_size);
2587 CHECK_EQUAL(out.size);
2588 CHECK_ATTRIB(out.file_attr);
2590 REMOVE_HANDLE_SMB2(in.file.handle);
2596 generate read operations
2598 static bool handler_smb2_read(int instance)
2600 struct smb2_read parm[NSERVERS];
2601 NTSTATUS status[NSERVERS];
2603 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2604 parm[0].in.reserved = gen_reserved8();
2605 parm[0].in.length = gen_io_count();
2606 parm[0].in.offset = gen_offset();
2607 parm[0].in.min_count = gen_io_count();
2608 parm[0].in.channel = gen_bits_mask2(0x0, 0xFFFFFFFF);
2609 parm[0].in.remaining = gen_bits_mask2(0x0, 0xFFFFFFFF);
2610 parm[0].in.channel_offset = gen_bits_mask2(0x0, 0xFFFF);
2611 parm[0].in.channel_length = gen_bits_mask2(0x0, 0xFFFF);
2614 GEN_SET_FNUM_SMB2(in.file.handle);
2615 GEN_CALL_SMB2(smb2_read(tree, current_op.mem_ctx, &parm[i]));
2617 CHECK_EQUAL(out.remaining);
2618 CHECK_EQUAL(out.reserved);
2619 CHECK_EQUAL(out.data.length);
2625 generate write operations
2627 static bool handler_smb2_write(int instance)
2629 struct smb2_write parm[NSERVERS];
2630 NTSTATUS status[NSERVERS];
2632 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2633 parm[0].in.offset = gen_offset();
2634 parm[0].in.unknown1 = gen_bits_mask2(0, 0xFFFFFFFF);
2635 parm[0].in.unknown2 = gen_bits_mask2(0, 0xFFFFFFFF);
2636 parm[0].in.data = data_blob_talloc(current_op.mem_ctx, NULL,
2640 GEN_SET_FNUM_SMB2(in.file.handle);
2641 GEN_CALL_SMB2(smb2_write(tree, &parm[i]));
2643 CHECK_EQUAL(out._pad);
2644 CHECK_EQUAL(out.nwritten);
2645 CHECK_EQUAL(out.unknown1);
2651 generate lockingx operations
2653 static bool handler_smb2_lock(int instance)
2655 struct smb2_lock parm[NSERVERS];
2656 NTSTATUS status[NSERVERS];
2659 parm[0].level = RAW_LOCK_LOCKX;
2660 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2661 parm[0].in.lock_count = gen_lock_count();
2662 parm[0].in.reserved = gen_reserved32();
2664 parm[0].in.locks = talloc_array(current_op.mem_ctx,
2665 struct smb2_lock_element,
2666 parm[0].in.lock_count);
2667 for (n=0;n<parm[0].in.lock_count;n++) {
2668 parm[0].in.locks[n].offset = gen_offset();
2669 parm[0].in.locks[n].length = gen_io_count();
2670 /* don't yet cope with async replies */
2671 parm[0].in.locks[n].flags = gen_lock_flags_smb2() |
2672 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY;
2673 parm[0].in.locks[n].reserved = gen_bits_mask2(0x0, 0xFFFFFFFF);
2677 GEN_SET_FNUM_SMB2(in.file.handle);
2678 GEN_CALL_SMB2(smb2_lock(tree, &parm[i]));
2684 generate flush operations
2686 static bool handler_smb2_flush(int instance)
2688 struct smb2_flush parm[NSERVERS];
2689 NTSTATUS status[NSERVERS];
2691 ZERO_STRUCT(parm[0]);
2692 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2693 parm[0].in.reserved1 = gen_reserved16();
2694 parm[0].in.reserved2 = gen_reserved32();
2697 GEN_SET_FNUM_SMB2(in.file.handle);
2698 GEN_CALL_SMB2(smb2_flush(tree, &parm[i]));
2700 CHECK_EQUAL(out.reserved);
2706 generate echo operations
2708 static bool handler_smb2_echo(int instance)
2710 NTSTATUS status[NSERVERS];
2712 GEN_CALL_SMB2(smb2_keepalive(tree->session->transport));
2720 generate a fileinfo query structure
2722 static void gen_fileinfo_smb2(int instance, union smb_fileinfo *info)
2725 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
2727 enum smb_fileinfo_level level;
2730 LVL(BASIC_INFORMATION),
2731 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
2732 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
2733 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(SMB2_ALL_INFORMATION),
2734 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
2735 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION),
2736 LVL(SMB2_ALL_EAS), LVL(SMB2_ALL_INFORMATION), LVL(SEC_DESC),
2739 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2740 } while (ignore_pattern(levels[i].name));
2742 info->generic.level = levels[i].level;
2746 generate qfileinfo operations
2748 static bool handler_smb2_qfileinfo(int instance)
2750 union smb_fileinfo parm[NSERVERS];
2751 NTSTATUS status[NSERVERS];
2753 parm[0].generic.in.file.handle.data[0] = gen_fnum(instance);
2755 gen_fileinfo_smb2(instance, &parm[0]);
2758 GEN_SET_FNUM_SMB2(generic.in.file.handle);
2759 GEN_CALL_SMB2(smb2_getinfo_file(tree, current_op.mem_ctx, &parm[i]));
2761 return cmp_fileinfo(instance, parm, status);
2766 generate setfileinfo operations
2768 static bool handler_smb2_sfileinfo(int instance)
2770 union smb_setfileinfo parm[NSERVERS];
2771 NTSTATUS status[NSERVERS];
2773 gen_setfileinfo(instance, &parm[0]);
2774 parm[0].generic.in.file.fnum = gen_fnum(instance);
2777 GEN_SET_FNUM_SMB2(generic.in.file.handle);
2778 GEN_CALL_SMB2(smb2_setinfo_file(tree, &parm[i]));
2784 wipe any relevant files
2786 static void wipe_files(void)
2791 if (options.skip_cleanup) {
2795 for (i=0;i<NSERVERS;i++) {
2798 n = smb2_deltree(servers[i].smb2_tree[0], "gentest");
2800 n = smbcli_deltree(servers[i].smb_tree[0], "gentest");
2803 printf("Failed to wipe tree on server %d\n", i);
2807 status = smb2_util_mkdir(servers[i].smb2_tree[0], "gentest");
2809 status = smbcli_mkdir(servers[i].smb_tree[0], "gentest");
2811 if (NT_STATUS_IS_ERR(status)) {
2812 printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status));
2816 printf("Deleted %d files on server %d\n", n, i);
2822 dump the current seeds - useful for continuing a backtrack
2824 static void dump_seeds(void)
2829 if (!options.seeds_file) {
2832 f = fopen("seeds.tmp", "w");
2835 for (i=0;i<options.numops;i++) {
2836 fprintf(f, "%u\n", op_parms[i].seed);
2839 rename("seeds.tmp", options.seeds_file);
2845 the list of top-level operations that we will generate
2849 bool (*handler)(int instance);
2851 int count, success_count;
2853 {"CREATE", handler_smb2_create, true},
2854 {"CLOSE", handler_smb2_close, true},
2855 {"READ", handler_smb2_read, true},
2856 {"WRITE", handler_smb2_write, true},
2857 {"LOCK", handler_smb2_lock, true},
2858 {"FLUSH", handler_smb2_flush, true},
2859 {"ECHO", handler_smb2_echo, true},
2860 {"QFILEINFO", handler_smb2_qfileinfo, true},
2861 {"SFILEINFO", handler_smb2_sfileinfo, true},
2863 {"OPEN", handler_smb_open, false},
2864 {"OPENX", handler_smb_openx, false},
2865 {"NTCREATEX", handler_smb_ntcreatex, false},
2866 {"CLOSE", handler_smb_close, false},
2867 {"UNLINK", handler_smb_unlink, false},
2868 {"MKDIR", handler_smb_mkdir, false},
2869 {"RMDIR", handler_smb_rmdir, false},
2870 {"RENAME", handler_smb_rename, false},
2871 {"NTRENAME", handler_smb_ntrename, false},
2872 {"READX", handler_smb_readx, false},
2873 {"WRITEX", handler_smb_writex, false},
2874 {"CHKPATH", handler_smb_chkpath, false},
2875 {"SEEK", handler_smb_seek, false},
2876 {"LOCKINGX", handler_smb_lockingx, false},
2877 {"QPATHINFO", handler_smb_qpathinfo, false},
2878 {"QFILEINFO", handler_smb_qfileinfo, false},
2879 {"SPATHINFO", handler_smb_spathinfo, false},
2880 {"SFILEINFO", handler_smb_sfileinfo, false},
2881 {"NOTIFY", handler_smb_notify, false},
2882 {"SEEK", handler_smb_seek, false},
2887 run the test with the current set of op_parms parameters
2888 return the number of operations that completed successfully
2890 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
2894 if (!connect_servers(ev, lp_ctx)) {
2895 printf("Failed to connect to servers\n");
2901 /* wipe any leftover files from old runs */
2904 /* reset the open handles array */
2905 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
2906 num_open_handles = 0;
2908 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2909 gen_ops[i].count = 0;
2910 gen_ops[i].success_count = 0;
2913 for (op=0; op<options.numops; op++) {
2914 int instance, which_op;
2917 if (op_parms[op].disabled) continue;
2919 srandom(op_parms[op].seed);
2921 instance = gen_int_range(0, NINSTANCES-1);
2923 /* generate a non-ignored operation */
2925 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
2926 } while (ignore_pattern(gen_ops[which_op].name) ||
2927 gen_ops[which_op].smb2 != options.smb2);
2929 DEBUG(3,("Generating op %s on instance %d\n",
2930 gen_ops[which_op].name, instance));
2932 current_op.seed = op_parms[op].seed;
2933 current_op.opnum = op;
2934 current_op.name = gen_ops[which_op].name;
2935 current_op.status = NT_STATUS_OK;
2936 talloc_free(current_op.mem_ctx);
2937 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
2939 ret = gen_ops[which_op].handler(instance);
2941 gen_ops[which_op].count++;
2942 if (NT_STATUS_IS_OK(current_op.status)) {
2943 gen_ops[which_op].success_count++;
2947 printf("Failed at operation %d - %s\n",
2948 op, gen_ops[which_op].name);
2952 if (op % 100 == 0) {
2957 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2958 printf("Op %-10s got %d/%d success\n",
2960 gen_ops[i].success_count,
2968 perform a backtracking analysis of the minimal set of operations
2969 to generate an error
2971 static void backtrack_analyze(struct event_context *ev,
2972 struct loadparm_context *lp_ctx)
2975 const char *mismatch = current_op.mismatch;
2977 chunk = options.numops / 2;
2982 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2985 chunk = MIN(chunk, options.numops / 2);
2987 /* mark this range as disabled */
2988 max = MIN(options.numops, base+chunk);
2989 for (i=base;i<max; i++) {
2990 op_parms[i].disabled = true;
2992 printf("Testing %d ops with %d-%d disabled\n",
2993 options.numops, base, max-1);
2994 ret = run_test(ev, lp_ctx);
2995 printf("Completed %d of %d ops\n", ret, options.numops);
2996 for (i=base;i<max; i++) {
2997 op_parms[i].disabled = false;
2999 if (ret == options.numops) {
3000 /* this chunk is needed */
3002 } else if (mismatch != current_op.mismatch &&
3003 strcmp(mismatch, current_op.mismatch)) {
3005 printf("Different error in backtracking\n");
3006 } else if (ret < base) {
3007 printf("damn - inconsistent errors! found early error\n");
3008 options.numops = ret+1;
3011 /* it failed - this chunk isn't needed for a failure */
3012 memmove(&op_parms[base], &op_parms[max],
3013 sizeof(op_parms[0]) * (options.numops - max));
3014 options.numops = (ret+1) - (max - base);
3024 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
3027 } while (chunk > 0);
3029 printf("Reduced to %d ops\n", options.numops);
3030 ret = run_test(ev, lp_ctx);
3031 if (ret != options.numops - 1) {
3032 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
3037 start the main gentest process
3039 static bool start_gentest(struct event_context *ev,
3040 struct loadparm_context *lp_ctx)
3045 /* allocate the open_handles array */
3046 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
3048 srandom(options.seed);
3049 op_parms = calloc(options.numops, sizeof(op_parms[0]));
3051 /* generate the seeds - after this everything is deterministic */
3052 if (options.use_preset_seeds) {
3054 char **preset = file_lines_load(options.seeds_file, &numops, 0, NULL);
3056 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
3059 if (numops < options.numops) {
3060 options.numops = numops;
3062 for (op=0;op<options.numops;op++) {
3064 printf("Not enough seeds in %s\n", options.seeds_file);
3067 op_parms[op].seed = atoi(preset[op]);
3069 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
3071 for (op=0; op<options.numops; op++) {
3072 op_parms[op].seed = random();
3076 ret = run_test(ev, lp_ctx);
3078 if (ret != options.numops && options.analyze) {
3079 options.numops = ret+1;
3080 backtrack_analyze(ev, lp_ctx);
3081 } else if (options.analyze_always) {
3082 backtrack_analyze(ev, lp_ctx);
3083 } else if (options.analyze_continuous) {
3084 while (run_test(ev, lp_ctx) == options.numops) ;
3087 return ret == options.numops;
3091 static void usage(poptContext pc)
3095 gentest //server1/share1 //server2/share2 [options..]\n\
3097 poptPrintUsage(pc, stdout, 0);
3101 split a UNC name into server and share names
3103 static bool split_unc_name(const char *unc, char **server, char **share)
3105 char *p = strdup(unc);
3106 if (!p) return false;
3107 all_string_sub(p, "\\", "/", 0);
3108 if (strncmp(p, "//", 2) != 0) return false;
3111 p = strchr(*server, '/');
3112 if (!p) return false;
3122 /****************************************************************************
3124 ****************************************************************************/
3125 int main(int argc, char *argv[])
3128 int i, username_count=0;
3130 char *ignore_file=NULL;
3131 struct event_context *ev;
3132 struct loadparm_context *lp_ctx;
3136 enum {OPT_UNCLIST=1000};
3137 struct poptOption long_options[] = {
3139 {"smb2", 0, POPT_ARG_NONE, &options.smb2, 0, "use SMB2 protocol", NULL},
3140 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
3141 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
3142 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
3143 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
3144 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
3145 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
3146 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
3147 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
3148 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
3149 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
3150 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
3151 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
3152 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
3153 {"maskindexing", 0, POPT_ARG_NONE, &options.mask_indexing, 0, "mask out the indexed file attrib", NULL},
3154 {"noeas", 0, POPT_ARG_NONE, &options.no_eas, 0, "don't use extended attributes", NULL},
3155 {"noacls", 0, POPT_ARG_NONE, &options.no_acls, 0, "don't use ACLs", NULL},
3156 {"skip-cleanup", 0, POPT_ARG_NONE, &options.skip_cleanup, 0, "don't delete files at start", NULL},
3157 {"valid", 0, POPT_ARG_NONE, &options.valid, 0, "generate only valid fields", NULL},
3159 POPT_COMMON_CONNECTION
3160 POPT_COMMON_CREDENTIALS
3165 memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
3168 options.seed = time(NULL);
3169 options.numops = 1000;
3170 options.max_open_handles = 20;
3171 options.seeds_file = "gentest_seeds.dat";
3173 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
3174 POPT_CONTEXT_KEEP_FIRST);
3176 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
3178 lp_ctx = cmdline_lp_ctx;
3179 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
3180 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
3181 cli_credentials_guess(servers[0].credentials, lp_ctx);
3182 cli_credentials_guess(servers[1].credentials, lp_ctx);
3184 while((opt = poptGetNextOpt(pc)) != -1) {
3187 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
3190 if (username_count == 2) {
3194 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
3201 options.ignore_patterns = file_lines_load(ignore_file, NULL, 0, NULL);
3204 argv_new = discard_const_p(char *, poptGetArgs(pc));
3206 for (i=0; i<argc; i++) {
3207 if (argv_new[i] == NULL) {
3213 if (!(argc_new >= 3)) {
3220 setup_logging("gentest", DEBUG_STDOUT);
3222 if (argc < 3 || argv[1][0] == '-') {
3227 setup_logging(argv[0], DEBUG_STDOUT);
3229 for (i=0;i<NSERVERS;i++) {
3230 const char *share = argv[1+i];
3231 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
3232 printf("Invalid share name '%s'\n", share);
3237 if (username_count == 0) {
3241 if (username_count == 1) {
3242 servers[1].credentials = servers[0].credentials;
3245 printf("seed=%u\n", options.seed);
3247 ev = s4_event_context_init(talloc_autofree_context());
3249 gensec_init(lp_ctx);
3251 ret = start_gentest(ev, lp_ctx);
3254 printf("gentest completed - no errors\n");
3256 printf("gentest failed\n");