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 servers[i].share_name,
231 lp_resolve_context(lp_ctx),
232 servers[i].credentials,
233 &servers[i].smb2_tree[j],
236 status = smbcli_tree_full_connection(NULL,
237 &servers[i].smb_tree[j],
238 servers[i].server_name,
239 lp_smb_ports(lp_ctx),
240 servers[i].share_name, "A:",
241 servers[i].credentials,
242 lp_resolve_context(lp_ctx), ev,
244 &smb_session_options);
246 if (!NT_STATUS_IS_OK(status)) {
247 printf("Failed to connect to \\\\%s\\%s - %s\n",
248 servers[i].server_name, servers[i].share_name,
254 servers[i].smb2_tree[j]->session->transport->oplock.handler = oplock_handler_smb2;
255 servers[i].smb2_tree[j]->session->transport->oplock.private_data = (void *)(uintptr_t)((i<<8)|j);
256 smb2_transport_idle_handler(servers[i].smb2_tree[j]->session->transport,
257 idle_func_smb2, 50000, NULL);
259 smbcli_oplock_handler(servers[i].smb_tree[j]->session->transport, oplock_handler_smb,
260 (void *)(uintptr_t)((i<<8)|j));
261 smbcli_transport_idle_handler(servers[i].smb_tree[j]->session->transport, idle_func_smb,
262 50000, (void *)(uintptr_t)((i<<8)|j));
271 work out the time skew between the servers - be conservative
273 static uint_t time_skew(void)
277 ret = labs(servers[0].smb2_tree[0]->session->transport->negotiate.system_time -
278 servers[1].smb2_tree[0]->session->transport->negotiate.system_time);
280 ret = labs(servers[0].smb_tree[0]->session->transport->negotiate.server_time -
281 servers[1].smb_tree[0]->session->transport->negotiate.server_time);
287 static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_handle *h2)
289 return memcmp(h1, h2, sizeof(struct smb2_handle)) == 0;
293 turn a server handle into a local handle
295 static uint_t fnum_to_handle_smb2(int server, int instance, struct smb2_handle server_handle)
298 for (i=0;i<options.max_open_handles;i++) {
299 if (!open_handles[i].active ||
300 instance != open_handles[i].instance) continue;
301 if (smb2_handle_equal(&open_handles[i].smb2_handle[server], &server_handle)) {
305 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
311 turn a server handle into a local handle
313 static uint_t fnum_to_handle_smb(int server, int instance, uint16_t server_handle)
316 for (i=0;i<options.max_open_handles;i++) {
317 if (!open_handles[i].active ||
318 instance != open_handles[i].instance) continue;
319 if (open_handles[i].smb_handle[server] == server_handle) {
323 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
329 add some newly opened handles
331 static void gen_add_handle_smb2(int instance, const char *name, struct smb2_handle handles[NSERVERS])
334 for (h=0;h<options.max_open_handles;h++) {
335 if (!open_handles[h].active) break;
337 if (h == options.max_open_handles) {
338 /* we have to force close a random handle */
339 h = random() % options.max_open_handles;
340 for (i=0;i<NSERVERS;i++) {
342 status = smb2_util_close(servers[i].smb2_tree[open_handles[h].instance],
343 open_handles[h].smb2_handle[i]);
344 if (NT_STATUS_IS_ERR(status)) {
345 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
349 printf("Recovered handle %d\n", h);
352 for (i=0;i<NSERVERS;i++) {
353 open_handles[h].smb2_handle[i] = handles[i];
354 open_handles[h].instance = instance;
355 open_handles[h].active = true;
356 open_handles[h].name = name;
360 printf("OPEN num_open_handles=%d h=%d (%s)\n",
361 num_open_handles, h, name);
365 add some newly opened handles
367 static void gen_add_handle_smb(int instance, const char *name, uint16_t handles[NSERVERS])
370 for (h=0;h<options.max_open_handles;h++) {
371 if (!open_handles[h].active) break;
373 if (h == options.max_open_handles) {
374 /* we have to force close a random handle */
375 h = random() % options.max_open_handles;
376 for (i=0;i<NSERVERS;i++) {
378 status = smbcli_close(servers[i].smb_tree[open_handles[h].instance],
379 open_handles[h].smb_handle[i]);
380 if (NT_STATUS_IS_ERR(status)) {
381 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
385 printf("Recovered handle %d\n", h);
388 for (i=0;i<NSERVERS;i++) {
389 open_handles[h].smb_handle[i] = handles[i];
390 open_handles[h].instance = instance;
391 open_handles[h].active = true;
392 open_handles[h].name = name;
396 printf("OPEN num_open_handles=%d h=%d (%s)\n",
397 num_open_handles, h, name);
402 remove a closed handle
404 static void gen_remove_handle_smb2(int instance, struct smb2_handle handles[NSERVERS])
407 for (h=0;h<options.max_open_handles;h++) {
408 if (instance == open_handles[h].instance &&
409 smb2_handle_equal(&open_handles[h].smb2_handle[0], &handles[0])) {
410 open_handles[h].active = false;
412 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
414 open_handles[h].name);
418 printf("Removing invalid handle!?\n");
423 remove a closed handle
425 static void gen_remove_handle_smb(int instance, uint16_t handles[NSERVERS])
428 for (h=0;h<options.max_open_handles;h++) {
429 if (instance == open_handles[h].instance &&
430 open_handles[h].smb_handle[0] == handles[0]) {
431 open_handles[h].active = false;
433 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
435 open_handles[h].name);
439 printf("Removing invalid handle!?\n");
444 return true with 'chance' probability as a percentage
446 static bool gen_chance(uint_t chance)
448 return ((random() % 100) <= chance);
452 map an internal handle number to a server handle
454 static struct smb2_handle gen_lookup_handle_smb2(int server, uint16_t handle)
456 if (handle == BAD_HANDLE) return bad_smb2_handle;
457 return open_handles[handle].smb2_handle[server];
461 map an internal handle number to a server handle
463 static uint16_t gen_lookup_handle_smb(int server, uint16_t handle)
465 if (handle == BAD_HANDLE) return BAD_HANDLE;
466 return open_handles[handle].smb_handle[server];
472 static uint16_t gen_fnum(int instance)
477 if (gen_chance(20)) return BAD_HANDLE;
479 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
480 h = random() % options.max_open_handles;
481 if (open_handles[h].active &&
482 open_handles[h].instance == instance) {
490 return a file handle, but skewed so we don't close the last
491 couple of handles too readily
493 static uint16_t gen_fnum_close(int instance)
495 if (num_open_handles < 5) {
496 if (gen_chance(90)) return BAD_HANDLE;
499 return gen_fnum(instance);
503 generate an integer in a specified range
505 static int gen_int_range(uint64_t min, uint64_t max)
508 return min + (r % (1+max-min));
512 return a fnum for use as a root fid
513 be careful to call GEN_SET_FNUM() when you use this!
515 static uint16_t gen_root_fid(int instance)
517 if (gen_chance(5)) return gen_fnum(instance);
522 generate a file offset
524 static int gen_offset(void)
526 if (gen_chance(20)) return 0;
527 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
528 return gen_int_range(0, 1024*1024);
534 static int gen_io_count(void)
536 if (gen_chance(20)) return 0;
537 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
538 return gen_int_range(0, 4096);
544 static const char *gen_fname(void)
546 const char *names[] = {"gentest\\gentest.dat",
551 "gentest\\foo4:teststream1",
552 "gentest\\foo4:teststream2",
554 "gentest\\foo5.exe:teststream3",
555 "gentest\\foo5.exe:teststream4",
558 "gentest\\blah\\blergh.txt",
559 "gentest\\blah\\blergh2",
560 "gentest\\blah\\blergh3.txt",
561 "gentest\\blah\\blergh4",
562 "gentest\\blah\\blergh5.txt",
563 "gentest\\blah\\blergh5",
566 "gentest\\a_very_long_name.bin",
572 i = gen_int_range(0, ARRAY_SIZE(names)-1);
573 } while (ignore_pattern(names[i]));
579 generate a filename with a higher chance of choosing an already
582 static const char *gen_fname_open(int instance)
585 h = gen_fnum(instance);
586 if (h == BAD_HANDLE) {
589 return open_handles[h].name;
593 generate a wildcard pattern
595 static const char *gen_pattern(void)
598 const char *names[] = {"gentest\\*.dat",
601 "gentest\\blah\\*.*",
605 if (gen_chance(50)) return gen_fname();
608 i = gen_int_range(0, ARRAY_SIZE(names)-1);
609 } while (ignore_pattern(names[i]));
614 static uint32_t gen_bits_levels(int nlevels, ...)
620 va_start(ap, nlevels);
621 for (i=0;i<nlevels;i++) {
622 pct = va_arg(ap, uint32_t);
623 mask = va_arg(ap, uint32_t);
624 if (pct == 100 || gen_chance(pct)) {
626 return mask & random();
636 static uint32_t gen_bits_mask(uint_t mask)
638 uint_t ret = random();
643 generate a bitmask with high probability of the first mask
644 and low of the second
646 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
648 if (!options.valid && gen_chance(10)) return gen_bits_mask(mask2);
649 return gen_bits_mask(mask1);
653 generate reserved values
655 static uint64_t gen_reserved8(void)
657 if (options.valid) return 0;
658 return gen_bits_mask(0xFF);
661 static uint64_t gen_reserved16(void)
663 if (options.valid) return 0;
664 return gen_bits_mask(0xFFFF);
667 static uint64_t gen_reserved32(void)
669 if (options.valid) return 0;
670 return gen_bits_mask(0xFFFFFFFF);
673 static uint64_t gen_reserved64(void)
675 if (options.valid) return 0;
676 return gen_bits_mask(0xFFFFFFFF) | (((uint64_t)gen_bits_mask(0xFFFFFFFF))<<32);
684 static bool gen_bool(void)
686 return gen_bits_mask2(0x1, 0xFF);
690 generate ntrename flags
692 static uint16_t gen_rename_flags(void)
694 if (gen_chance(30)) return RENAME_FLAG_RENAME;
695 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
696 if (gen_chance(30)) return RENAME_FLAG_COPY;
697 return gen_bits_mask(0xFFFF);
703 static uint16_t gen_pid(void)
705 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
710 return a set of lock flags
712 static uint16_t gen_lock_flags_smb2(void)
714 if (!options.valid && gen_chance(5)) return gen_bits_mask(0xFFFF);
715 if (gen_chance(20)) return gen_bits_mask(0x1F);
716 if (gen_chance(50)) return SMB2_LOCK_FLAG_UNLOCK;
717 return gen_bits_mask(SMB2_LOCK_FLAG_SHARED |
718 SMB2_LOCK_FLAG_EXCLUSIVE |
719 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY);
723 generate a lock count
725 static off_t gen_lock_count(void)
727 return gen_int_range(0, 3);
731 generate a NT access mask
733 static uint32_t gen_access_mask(void)
736 if (gen_chance(70)) return SEC_FLAG_MAXIMUM_ALLOWED;
737 if (gen_chance(70)) return SEC_FILE_ALL;
738 ret = gen_bits_mask(0xFFFFFFFF);
739 if (options.valid) ret &= ~SEC_MASK_INVALID;
744 return a lockingx lock mode
746 static uint16_t gen_lock_mode(void)
748 if (!options.valid && gen_chance(5)) return gen_bits_mask(0xFFFF);
749 if (gen_chance(20)) return gen_bits_mask(0x1F);
750 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
754 generate a ntcreatex flags field
756 static uint32_t gen_ntcreatex_flags(void)
758 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
759 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
763 generate a ntcreatex create options bitfield
765 static uint32_t gen_create_options(void)
767 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
768 if (gen_chance(50)) return 0;
769 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
773 generate a ntcreatex open disposition
775 static uint32_t gen_open_disp(void)
777 if (gen_chance(50)) return NTCREATEX_DISP_OPEN_IF;
778 if (!options.valid && gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
779 return gen_int_range(0, 5);
783 generate an openx open mode
785 static uint16_t gen_openx_mode(void)
787 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
788 if (gen_chance(20)) return gen_bits_mask(0xFF);
789 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
793 generate an openx flags field
795 static uint16_t gen_openx_flags(void)
797 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
798 return gen_bits_mask(0x7);
802 generate an openx open function
804 static uint16_t gen_openx_func(void)
806 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
807 return gen_bits_mask(0x13);
811 generate a file attrib combination
813 static uint32_t gen_attrib(void)
816 if (gen_chance(20)) {
817 ret = gen_bits_mask(0xFFFFFFFF);
818 if (options.valid) ret &= FILE_ATTRIBUTE_ALL_MASK;
821 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
825 generate a unix timestamp
827 static time_t gen_timet(void)
829 if (gen_chance(30)) return 0;
830 return (time_t)random();
834 generate a milliseconds protocol timeout
836 static uint32_t gen_timeout(void)
838 if (gen_chance(98)) return 0;
839 return random() % 50;
845 static NTTIME gen_nttime(void)
848 unix_to_nt_time(&ret, gen_timet());
853 generate a timewarp value
855 static NTTIME gen_timewarp(void)
857 NTTIME ret = gen_nttime();
858 if (gen_chance(98)) ret = 0;
863 generate a file allocation size
865 static uint_t gen_alloc_size(void)
869 if (gen_chance(30)) return 0;
871 ret = random() % 4*1024*1024;
872 /* give a high chance of a round number */
873 if (gen_chance(60)) {
874 ret &= ~(1024*1024 - 1);
880 generate an ea_struct
882 static struct ea_struct gen_ea_struct(void)
885 const char *names[] = {"EAONE",
890 "AVERYLONGATTRIBUTENAME"};
891 const char *values[] = {"VALUE1",
896 "ASOMEWHATLONGERATTRIBUTEVALUE"};
902 i = gen_int_range(0, ARRAY_SIZE(names)-1);
903 } while (ignore_pattern(names[i]));
905 ea.name.s = names[i];
908 i = gen_int_range(0, ARRAY_SIZE(values)-1);
909 } while (ignore_pattern(values[i]));
911 ea.value = data_blob(values[i], strlen(values[i]));
913 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
920 generate an ea_struct
922 static struct smb_ea_list gen_ea_list(void)
924 struct smb_ea_list eas;
926 if (options.no_eas) {
930 eas.num_eas = gen_int_range(0, 3);
931 eas.eas = talloc_array(current_op.mem_ctx, struct ea_struct, eas.num_eas);
932 for (i=0;i<eas.num_eas;i++) {
933 eas.eas[i] = gen_ea_struct();
938 /* generate a security descriptor */
939 static struct security_descriptor *gen_sec_desc(void)
941 struct security_descriptor *sd;
942 if (options.no_acls || gen_chance(90)) return NULL;
944 sd = security_descriptor_dacl_create(current_op.mem_ctx,
947 SEC_ACE_TYPE_ACCESS_ALLOWED,
948 SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
949 SEC_ACE_FLAG_OBJECT_INHERIT,
951 SEC_ACE_TYPE_ACCESS_ALLOWED,
952 SEC_FILE_ALL | SEC_STD_ALL,
959 static void oplock_handler_close_recv_smb(struct smbcli_request *req)
962 status = smbcli_request_simple_recv(req);
963 if (!NT_STATUS_IS_OK(status)) {
964 printf("close failed in oplock_handler\n");
965 smb_panic("close failed in oplock_handler");
970 the oplock handler will either ack the break or close the file
972 static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
977 struct smbcli_tree *tree = NULL;
978 struct smbcli_request *req;
980 srandom(current_op.seed);
981 do_close = gen_chance(50);
983 for (i=0;i<NSERVERS;i++) {
984 for (j=0;j<NINSTANCES;j++) {
985 if (transport == servers[i].smb_tree[j]->session->transport &&
986 tid == servers[i].smb_tree[j]->tid) {
987 oplocks[i][j].got_break = true;
988 oplocks[i][j].smb_handle = fnum;
989 oplocks[i][j].handle = fnum_to_handle_smb(i, j, fnum);
990 oplocks[i][j].level = level;
991 oplocks[i][j].do_close = do_close;
992 tree = servers[i].smb_tree[j];
998 printf("Oplock break not for one of our trees!?\n");
1003 printf("oplock ack fnum=%d\n", fnum);
1004 return smbcli_oplock_ack(tree, fnum, level);
1007 printf("oplock close fnum=%d\n", fnum);
1009 io.close.level = RAW_CLOSE_CLOSE;
1010 io.close.in.file.fnum = fnum;
1011 io.close.in.write_time = 0;
1012 req = smb_raw_close_send(tree, &io);
1015 printf("WARNING: close failed in oplock_handler_close\n");
1019 req->async.fn = oplock_handler_close_recv_smb;
1020 req->async.private = NULL;
1027 the idle function tries to cope with getting an oplock break on a connection, and
1028 an operation on another connection blocking until that break is acked
1029 we check for operations on all transports in the idle function
1031 static void idle_func_smb(struct smbcli_transport *transport, void *private)
1034 for (i=0;i<NSERVERS;i++) {
1035 for (j=0;j<NINSTANCES;j++) {
1036 if (servers[i].smb_tree[j] &&
1037 transport != servers[i].smb_tree[j]->session->transport) {
1038 smbcli_transport_process(servers[i].smb_tree[j]->session->transport);
1045 static void oplock_handler_close_recv_smb2(struct smb2_request *req)
1048 struct smb2_close io;
1049 status = smb2_close_recv(req, &io);
1050 if (!NT_STATUS_IS_OK(status)) {
1051 printf("close failed in oplock_handler\n");
1052 smb_panic("close failed in oplock_handler");
1056 static void oplock_handler_ack_callback_smb2(struct smb2_request *req)
1059 struct smb2_break br;
1061 status = smb2_break_recv(req, &br);
1062 if (!NT_STATUS_IS_OK(status)) {
1063 printf("oplock break ack failed in oplock_handler\n");
1064 smb_panic("oplock break ack failed in oplock_handler");
1068 static bool send_oplock_ack_smb2(struct smb2_tree *tree, struct smb2_handle handle,
1071 struct smb2_break br;
1072 struct smb2_request *req;
1075 br.in.file.handle = handle;
1076 br.in.oplock_level = level;
1077 br.in.reserved = gen_reserved8();
1078 br.in.reserved2 = gen_reserved32();
1080 req = smb2_break_send(tree, &br);
1081 if (req == NULL) return false;
1082 req->async.fn = oplock_handler_ack_callback_smb2;
1083 req->async.private_data = NULL;
1088 the oplock handler will either ack the break or close the file
1090 static bool oplock_handler_smb2(struct smb2_transport *transport, const struct smb2_handle *handle,
1091 uint8_t level, void *private_data)
1093 struct smb2_close io;
1096 struct smb2_tree *tree = NULL;
1097 struct smb2_request *req;
1099 srandom(current_op.seed);
1100 do_close = gen_chance(50);
1102 i = ((uintptr_t)private_data) >> 8;
1103 j = ((uintptr_t)private_data) & 0xFF;
1105 if (i >= NSERVERS || j >= NINSTANCES) {
1106 printf("Bad private_data in oplock_handler\n");
1110 oplocks[i][j].got_break = true;
1111 oplocks[i][j].smb2_handle = *handle;
1112 oplocks[i][j].handle = fnum_to_handle_smb2(i, j, *handle);
1113 oplocks[i][j].level = level;
1114 oplocks[i][j].do_close = do_close;
1115 tree = talloc_get_type(servers[i].smb2_tree[j], struct smb2_tree);
1118 printf("Oplock break not for one of our trees!?\n");
1123 printf("oplock ack handle=%d\n", oplocks[i][j].handle);
1124 return send_oplock_ack_smb2(tree, *handle, level);
1127 printf("oplock close fnum=%d\n", oplocks[i][j].handle);
1130 io.in.file.handle = *handle;
1132 req = smb2_close_send(tree, &io);
1135 printf("WARNING: close failed in oplock_handler_close\n");
1139 req->async.fn = oplock_handler_close_recv_smb2;
1140 req->async.private_data = NULL;
1147 the idle function tries to cope with getting an oplock break on a connection, and
1148 an operation on another connection blocking until that break is acked
1149 we check for operations on all transports in the idle function
1151 static void idle_func_smb2(struct smb2_transport *transport, void *private)
1154 for (i=0;i<NSERVERS;i++) {
1155 for (j=0;j<NINSTANCES;j++) {
1156 if (servers[i].smb2_tree[j] &&
1157 transport != servers[i].smb2_tree[j]->session->transport) {
1158 // smb2_transport_process(servers[i].smb2_tree[j]->session->transport);
1167 compare NTSTATUS, using checking ignored patterns
1169 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
1173 if (NT_STATUS_EQUAL(status1, status2)) return true;
1175 /* one code being an error and the other OK is always an error */
1176 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) {
1177 current_op.mismatch = nt_errstr(status1);
1181 /* if we are ignoring one of the status codes then consider this a match */
1182 if (ignore_pattern(nt_errstr(status1)) ||
1183 ignore_pattern(nt_errstr(status2))) {
1187 /* also support ignore patterns of the form NT_STATUS_XX:NT_STATUS_YY
1188 meaning that the first server returns NT_STATUS_XX and the 2nd
1189 returns NT_STATUS_YY */
1190 s = talloc_asprintf(current_op.mem_ctx, "%s:%s",
1192 nt_errstr(status2));
1193 if (ignore_pattern(s)) {
1197 current_op.mismatch = nt_errstr(status1);
1202 check for pending packets on all connections
1204 static void check_pending(void)
1210 for (j=0;j<NINSTANCES;j++) {
1211 for (i=0;i<NSERVERS;i++) {
1212 // smb2_transport_process(servers[i].smb2_tree[j]->session->transport);
1218 check that the same oplock breaks have been received by all instances
1220 static bool check_oplocks(const char *call)
1225 if (!options.use_oplocks || options.smb2) {
1226 /* no smb2 oplocks in gentest yet */
1233 for (j=0;j<NINSTANCES;j++) {
1234 for (i=1;i<NSERVERS;i++) {
1235 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
1236 oplocks[0][j].handle != oplocks[i][j].handle ||
1237 oplocks[0][j].level != oplocks[i][j].level) {
1238 if (tries++ < 10) goto again;
1239 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
1240 oplocks[0][j].got_break,
1241 oplocks[0][j].handle,
1242 oplocks[0][j].level,
1243 oplocks[i][j].got_break,
1244 oplocks[i][j].handle,
1245 oplocks[i][j].level);
1246 current_op.mismatch = "oplock break";
1252 /* if we got a break and closed then remove the handle */
1253 for (j=0;j<NINSTANCES;j++) {
1254 if (oplocks[0][j].got_break &&
1255 oplocks[0][j].do_close) {
1256 uint16_t fnums[NSERVERS];
1257 for (i=0;i<NSERVERS;i++) {
1258 fnums[i] = oplocks[i][j].smb_handle;
1260 gen_remove_handle_smb(j, fnums);
1269 check that the same change notify info has been received by all instances
1271 static bool check_notifies(const char *call)
1277 /* no smb2 notifies in gentest yet */
1284 for (j=0;j<NINSTANCES;j++) {
1285 for (i=1;i<NSERVERS;i++) {
1287 union smb_notify not1, not2;
1289 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
1290 if (tries++ < 10) goto again;
1291 printf("Notify count inconsistent %d %d\n",
1292 notifies[0][j].notify_count,
1293 notifies[i][j].notify_count);
1294 current_op.mismatch = "notify count";
1298 if (notifies[0][j].notify_count == 0) continue;
1300 if (!NT_STATUS_EQUAL(notifies[0][j].status,
1301 notifies[i][j].status)) {
1302 printf("Notify status mismatch - %s - %s\n",
1303 nt_errstr(notifies[0][j].status),
1304 nt_errstr(notifies[i][j].status));
1305 current_op.mismatch = "Notify status";
1309 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
1313 not1 = notifies[0][j].notify;
1314 not2 = notifies[i][j].notify;
1316 for (n=0;n<not1.nttrans.out.num_changes;n++) {
1317 if (not1.nttrans.out.changes[n].action !=
1318 not2.nttrans.out.changes[n].action) {
1319 printf("Notify action %d inconsistent %d %d\n", n,
1320 not1.nttrans.out.changes[n].action,
1321 not2.nttrans.out.changes[n].action);
1322 current_op.mismatch = "notify action";
1325 if (strcmp(not1.nttrans.out.changes[n].name.s,
1326 not2.nttrans.out.changes[n].name.s)) {
1327 printf("Notify name %d inconsistent %s %s\n", n,
1328 not1.nttrans.out.changes[n].name.s,
1329 not2.nttrans.out.changes[n].name.s);
1330 current_op.mismatch = "notify name";
1333 if (not1.nttrans.out.changes[n].name.private_length !=
1334 not2.nttrans.out.changes[n].name.private_length) {
1335 printf("Notify name length %d inconsistent %d %d\n", n,
1336 not1.nttrans.out.changes[n].name.private_length,
1337 not2.nttrans.out.changes[n].name.private_length);
1338 current_op.mismatch = "notify name length";
1345 ZERO_STRUCT(notifies);
1350 #define GEN_COPY_PARM do { \
1352 for (i=1;i<NSERVERS;i++) { \
1353 parm[i] = parm[0]; \
1357 #define GEN_CALL(call, treetype, treefield) do { \
1359 ZERO_STRUCT(oplocks); \
1360 ZERO_STRUCT(notifies); \
1361 for (i=0;i<NSERVERS;i++) { \
1362 struct treetype *tree = servers[i].treefield[instance]; \
1365 current_op.status = status[0]; \
1366 for (i=1;i<NSERVERS;i++) { \
1367 if (!compare_status(status[0], status[1])) { \
1368 printf("status different in %s - %s %s\n", #call, \
1369 nt_errstr(status[0]), nt_errstr(status[i])); \
1370 current_op.mismatch = nt_errstr(status[0]); \
1374 if (!check_oplocks(#call)) return false; \
1375 if (!check_notifies(#call)) return false; \
1376 if (!NT_STATUS_IS_OK(status[0])) { \
1381 #define GEN_CALL_SMB(call) GEN_CALL(call, smbcli_tree, smb_tree)
1382 #define GEN_CALL_SMB2(call) GEN_CALL(call, smb2_tree, smb2_tree)
1384 #define ADD_HANDLE_SMB2(name, field) do { \
1385 struct smb2_handle handles[NSERVERS]; \
1387 for (i=0;i<NSERVERS;i++) { \
1388 handles[i] = parm[i].field; \
1390 gen_add_handle_smb2(instance, name, handles); \
1393 #define REMOVE_HANDLE_SMB2(field) do { \
1394 struct smb2_handle handles[NSERVERS]; \
1396 for (i=0;i<NSERVERS;i++) { \
1397 handles[i] = parm[i].field; \
1399 gen_remove_handle_smb2(instance, handles); \
1402 #define ADD_HANDLE_SMB(name, field) do { \
1403 uint16_t handles[NSERVERS]; \
1405 for (i=0;i<NSERVERS;i++) { \
1406 handles[i] = parm[i].field; \
1408 gen_add_handle_smb(instance, name, handles); \
1411 #define REMOVE_HANDLE_SMB(field) do { \
1412 uint16_t handles[NSERVERS]; \
1414 for (i=0;i<NSERVERS;i++) { \
1415 handles[i] = parm[i].field; \
1417 gen_remove_handle_smb(instance, handles); \
1420 #define GEN_SET_FNUM_SMB2(field) do { \
1422 for (i=0;i<NSERVERS;i++) { \
1423 parm[i].field = gen_lookup_handle_smb2(i, parm[i].field.data[0]); \
1427 #define GEN_SET_FNUM_SMB(field) do { \
1429 for (i=0;i<NSERVERS;i++) { \
1430 parm[i].field = gen_lookup_handle_smb(i, parm[i].field); \
1434 #define CHECK_EQUAL(field) do { \
1435 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1436 current_op.mismatch = #field; \
1437 printf("Mismatch in %s - 0x%llx 0x%llx\n", #field, \
1438 (unsigned long long)parm[0].field, (unsigned long long)parm[1].field); \
1443 #define CHECK_SECDESC(field) do { \
1444 if (!security_acl_equal(parm[0].field->dacl, parm[1].field->dacl) && !ignore_pattern(#field)) { \
1445 current_op.mismatch = #field; \
1446 printf("Mismatch in %s\n", #field); \
1451 #define CHECK_ATTRIB(field) do { \
1452 if (!options.mask_indexing) { \
1453 CHECK_EQUAL(field); \
1454 } else if ((~FILE_ATTRIBUTE_NONINDEXED & parm[0].field) != (~FILE_ATTRIBUTE_NONINDEXED & parm[1].field) && !ignore_pattern(#field)) { \
1455 current_op.mismatch = #field; \
1456 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1457 (int)parm[0].field, (int)parm[1].field); \
1462 #define CHECK_WSTR_EQUAL(field) do { \
1463 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1464 current_op.mismatch = #field; \
1465 printf("%s is NULL!\n", #field); \
1468 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1469 current_op.mismatch = #field; \
1470 printf("Mismatch in %s - %s %s\n", #field, \
1471 parm[0].field.s, parm[1].field.s); \
1474 CHECK_EQUAL(field.private_length); \
1477 #define CHECK_BLOB_EQUAL(field) do { \
1478 if (((parm[0].field.data == NULL && parm[1].field.data != NULL) || \
1479 (parm[1].field.data == NULL && parm[0].field.data != NULL) || \
1480 (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0)) && !ignore_pattern(#field)) { \
1481 current_op.mismatch = #field; \
1482 printf("Mismatch in %s\n", #field); \
1485 CHECK_EQUAL(field.length); \
1488 #define CHECK_TIMES_EQUAL(field) do { \
1489 if (labs(parm[0].field - parm[1].field) > time_skew() && \
1490 !ignore_pattern(#field)) { \
1491 current_op.mismatch = #field; \
1492 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1493 (int)parm[0].field, (int)parm[1].field); \
1498 #define CHECK_NTTIMES_EQUAL(field) do { \
1499 if (labs(nt_time_to_unix(parm[0].field) - \
1500 nt_time_to_unix(parm[1].field)) > time_skew() && \
1501 !ignore_pattern(#field)) { \
1502 current_op.mismatch = #field; \
1503 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1504 (int)nt_time_to_unix(parm[0].field), \
1505 (int)nt_time_to_unix(parm[1].field)); \
1512 compare returned fileinfo structures
1514 static bool cmp_fileinfo(int instance,
1515 union smb_fileinfo parm[NSERVERS],
1516 NTSTATUS status[NSERVERS])
1519 enum smb_fileinfo_level level = parm[0].generic.level;
1521 if (level == RAW_FILEINFO_ALL_INFORMATION &&
1523 level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
1527 case RAW_FILEINFO_GENERIC:
1530 case RAW_FILEINFO_GETATTR:
1531 CHECK_ATTRIB(getattr.out.attrib);
1532 CHECK_EQUAL(getattr.out.size);
1533 CHECK_TIMES_EQUAL(getattr.out.write_time);
1536 case RAW_FILEINFO_GETATTRE:
1537 CHECK_TIMES_EQUAL(getattre.out.create_time);
1538 CHECK_TIMES_EQUAL(getattre.out.access_time);
1539 CHECK_TIMES_EQUAL(getattre.out.write_time);
1540 CHECK_EQUAL(getattre.out.size);
1541 CHECK_EQUAL(getattre.out.alloc_size);
1542 CHECK_ATTRIB(getattre.out.attrib);
1545 case RAW_FILEINFO_STANDARD:
1546 CHECK_TIMES_EQUAL(standard.out.create_time);
1547 CHECK_TIMES_EQUAL(standard.out.access_time);
1548 CHECK_TIMES_EQUAL(standard.out.write_time);
1549 CHECK_EQUAL(standard.out.size);
1550 CHECK_EQUAL(standard.out.alloc_size);
1551 CHECK_ATTRIB(standard.out.attrib);
1554 case RAW_FILEINFO_EA_SIZE:
1555 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1556 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1557 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1558 CHECK_EQUAL(ea_size.out.size);
1559 CHECK_EQUAL(ea_size.out.alloc_size);
1560 CHECK_ATTRIB(ea_size.out.attrib);
1561 CHECK_EQUAL(ea_size.out.ea_size);
1564 case RAW_FILEINFO_ALL_EAS:
1565 CHECK_EQUAL(all_eas.out.num_eas);
1566 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1567 CHECK_EQUAL(all_eas.out.eas[i].flags);
1568 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1569 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1573 case RAW_FILEINFO_IS_NAME_VALID:
1576 case RAW_FILEINFO_BASIC_INFO:
1577 case RAW_FILEINFO_BASIC_INFORMATION:
1578 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1579 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1580 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1581 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1582 CHECK_ATTRIB(basic_info.out.attrib);
1585 case RAW_FILEINFO_STANDARD_INFO:
1586 case RAW_FILEINFO_STANDARD_INFORMATION:
1587 CHECK_EQUAL(standard_info.out.alloc_size);
1588 CHECK_EQUAL(standard_info.out.size);
1589 CHECK_EQUAL(standard_info.out.nlink);
1590 CHECK_EQUAL(standard_info.out.delete_pending);
1591 CHECK_EQUAL(standard_info.out.directory);
1594 case RAW_FILEINFO_EA_INFO:
1595 case RAW_FILEINFO_EA_INFORMATION:
1596 CHECK_EQUAL(ea_info.out.ea_size);
1599 case RAW_FILEINFO_NAME_INFO:
1600 case RAW_FILEINFO_NAME_INFORMATION:
1601 CHECK_WSTR_EQUAL(name_info.out.fname);
1604 case RAW_FILEINFO_ALL_INFO:
1605 case RAW_FILEINFO_ALL_INFORMATION:
1606 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1607 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1608 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1609 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1610 CHECK_ATTRIB(all_info.out.attrib);
1611 CHECK_EQUAL(all_info.out.alloc_size);
1612 CHECK_EQUAL(all_info.out.size);
1613 CHECK_EQUAL(all_info.out.nlink);
1614 CHECK_EQUAL(all_info.out.delete_pending);
1615 CHECK_EQUAL(all_info.out.directory);
1616 CHECK_EQUAL(all_info.out.ea_size);
1617 CHECK_WSTR_EQUAL(all_info.out.fname);
1620 case RAW_FILEINFO_ALT_NAME_INFO:
1621 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1622 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1625 case RAW_FILEINFO_STREAM_INFO:
1626 case RAW_FILEINFO_STREAM_INFORMATION:
1627 CHECK_EQUAL(stream_info.out.num_streams);
1628 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1629 CHECK_EQUAL(stream_info.out.streams[i].size);
1630 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1631 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1635 case RAW_FILEINFO_COMPRESSION_INFO:
1636 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1637 CHECK_EQUAL(compression_info.out.compressed_size);
1638 CHECK_EQUAL(compression_info.out.format);
1639 CHECK_EQUAL(compression_info.out.unit_shift);
1640 CHECK_EQUAL(compression_info.out.chunk_shift);
1641 CHECK_EQUAL(compression_info.out.cluster_shift);
1644 case RAW_FILEINFO_INTERNAL_INFORMATION:
1645 CHECK_EQUAL(internal_information.out.file_id);
1648 case RAW_FILEINFO_ACCESS_INFORMATION:
1649 CHECK_EQUAL(access_information.out.access_flags);
1652 case RAW_FILEINFO_POSITION_INFORMATION:
1653 CHECK_EQUAL(position_information.out.position);
1656 case RAW_FILEINFO_MODE_INFORMATION:
1657 CHECK_EQUAL(mode_information.out.mode);
1660 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1661 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1664 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1665 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1666 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1667 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1668 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1669 CHECK_EQUAL(network_open_information.out.alloc_size);
1670 CHECK_EQUAL(network_open_information.out.size);
1671 CHECK_ATTRIB(network_open_information.out.attrib);
1674 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1675 CHECK_ATTRIB(attribute_tag_information.out.attrib);
1676 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1679 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1680 CHECK_NTTIMES_EQUAL(all_info2.out.create_time);
1681 CHECK_NTTIMES_EQUAL(all_info2.out.access_time);
1682 CHECK_NTTIMES_EQUAL(all_info2.out.write_time);
1683 CHECK_NTTIMES_EQUAL(all_info2.out.change_time);
1684 CHECK_ATTRIB(all_info2.out.attrib);
1685 CHECK_EQUAL(all_info2.out.unknown1);
1686 CHECK_EQUAL(all_info2.out.alloc_size);
1687 CHECK_EQUAL(all_info2.out.size);
1688 CHECK_EQUAL(all_info2.out.nlink);
1689 CHECK_EQUAL(all_info2.out.delete_pending);
1690 CHECK_EQUAL(all_info2.out.directory);
1691 CHECK_EQUAL(all_info2.out.file_id);
1692 CHECK_EQUAL(all_info2.out.ea_size);
1693 CHECK_EQUAL(all_info2.out.access_mask);
1694 CHECK_EQUAL(all_info2.out.position);
1695 CHECK_EQUAL(all_info2.out.mode);
1696 CHECK_EQUAL(all_info2.out.alignment_requirement);
1697 CHECK_WSTR_EQUAL(all_info2.out.fname);
1700 case RAW_FILEINFO_SMB2_ALL_EAS:
1701 CHECK_EQUAL(all_eas.out.num_eas);
1702 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1703 CHECK_EQUAL(all_eas.out.eas[i].flags);
1704 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1705 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1709 case RAW_FILEINFO_SEC_DESC:
1710 CHECK_SECDESC(query_secdesc.out.sd);
1713 /* Unhandled levels */
1714 case RAW_FILEINFO_EA_LIST:
1715 case RAW_FILEINFO_UNIX_BASIC:
1716 case RAW_FILEINFO_UNIX_LINK:
1717 case RAW_FILEINFO_UNIX_INFO2:
1727 generate openx operations
1729 static bool handler_smb_openx(int instance)
1731 union smb_open parm[NSERVERS];
1732 NTSTATUS status[NSERVERS];
1734 parm[0].openx.level = RAW_OPEN_OPENX;
1735 parm[0].openx.in.flags = gen_openx_flags();
1736 parm[0].openx.in.open_mode = gen_openx_mode();
1737 parm[0].openx.in.search_attrs = gen_attrib();
1738 parm[0].openx.in.file_attrs = gen_attrib();
1739 parm[0].openx.in.write_time = gen_timet();
1740 parm[0].openx.in.open_func = gen_openx_func();
1741 parm[0].openx.in.size = gen_io_count();
1742 parm[0].openx.in.timeout = gen_timeout();
1743 parm[0].openx.in.fname = gen_fname_open(instance);
1745 if (!options.use_oplocks) {
1746 /* mask out oplocks */
1747 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1748 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1752 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1754 CHECK_ATTRIB(openx.out.attrib);
1755 CHECK_EQUAL(openx.out.size);
1756 CHECK_EQUAL(openx.out.access);
1757 CHECK_EQUAL(openx.out.ftype);
1758 CHECK_EQUAL(openx.out.devstate);
1759 CHECK_EQUAL(openx.out.action);
1760 CHECK_EQUAL(openx.out.access_mask);
1761 CHECK_EQUAL(openx.out.unknown);
1762 CHECK_TIMES_EQUAL(openx.out.write_time);
1764 /* open creates a new file handle */
1765 ADD_HANDLE_SMB(parm[0].openx.in.fname, openx.out.file.fnum);
1772 generate open operations
1774 static bool handler_smb_open(int instance)
1776 union smb_open parm[NSERVERS];
1777 NTSTATUS status[NSERVERS];
1779 parm[0].openold.level = RAW_OPEN_OPEN;
1780 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1781 parm[0].openold.in.search_attrs = gen_attrib();
1782 parm[0].openold.in.fname = gen_fname_open(instance);
1784 if (!options.use_oplocks) {
1785 /* mask out oplocks */
1786 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1787 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1791 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1793 CHECK_ATTRIB(openold.out.attrib);
1794 CHECK_TIMES_EQUAL(openold.out.write_time);
1795 CHECK_EQUAL(openold.out.size);
1796 CHECK_EQUAL(openold.out.rmode);
1798 /* open creates a new file handle */
1799 ADD_HANDLE_SMB(parm[0].openold.in.fname, openold.out.file.fnum);
1806 generate ntcreatex operations
1808 static bool handler_smb_ntcreatex(int instance)
1810 union smb_open parm[NSERVERS];
1811 NTSTATUS status[NSERVERS];
1813 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1814 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1815 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1816 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1817 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1818 parm[0].ntcreatex.in.file_attr = gen_attrib();
1819 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1820 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1821 parm[0].ntcreatex.in.create_options = gen_create_options();
1822 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1823 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1824 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1826 if (!options.use_oplocks) {
1827 /* mask out oplocks */
1828 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1829 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1833 if (parm[0].ntcreatex.in.root_fid != 0) {
1834 GEN_SET_FNUM_SMB(ntcreatex.in.root_fid);
1836 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1838 CHECK_EQUAL(ntcreatex.out.oplock_level);
1839 CHECK_EQUAL(ntcreatex.out.create_action);
1840 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1841 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1842 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1843 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1844 CHECK_ATTRIB(ntcreatex.out.attrib);
1845 CHECK_EQUAL(ntcreatex.out.alloc_size);
1846 CHECK_EQUAL(ntcreatex.out.size);
1847 CHECK_EQUAL(ntcreatex.out.file_type);
1848 CHECK_EQUAL(ntcreatex.out.ipc_state);
1849 CHECK_EQUAL(ntcreatex.out.is_directory);
1851 /* ntcreatex creates a new file handle */
1852 ADD_HANDLE_SMB(parm[0].ntcreatex.in.fname, ntcreatex.out.file.fnum);
1858 generate close operations
1860 static bool handler_smb_close(int instance)
1862 union smb_close parm[NSERVERS];
1863 NTSTATUS status[NSERVERS];
1865 parm[0].close.level = RAW_CLOSE_CLOSE;
1866 parm[0].close.in.file.fnum = gen_fnum_close(instance);
1867 parm[0].close.in.write_time = gen_timet();
1870 GEN_SET_FNUM_SMB(close.in.file.fnum);
1871 GEN_CALL_SMB(smb_raw_close(tree, &parm[i]));
1873 REMOVE_HANDLE_SMB(close.in.file.fnum);
1879 generate unlink operations
1881 static bool handler_smb_unlink(int instance)
1883 union smb_unlink parm[NSERVERS];
1884 NTSTATUS status[NSERVERS];
1886 parm[0].unlink.in.pattern = gen_pattern();
1887 parm[0].unlink.in.attrib = gen_attrib();
1890 GEN_CALL_SMB(smb_raw_unlink(tree, &parm[i]));
1896 generate chkpath operations
1898 static bool handler_smb_chkpath(int instance)
1900 union smb_chkpath parm[NSERVERS];
1901 NTSTATUS status[NSERVERS];
1903 parm[0].chkpath.in.path = gen_fname_open(instance);
1906 GEN_CALL_SMB(smb_raw_chkpath(tree, &parm[i]));
1912 generate mkdir operations
1914 static bool handler_smb_mkdir(int instance)
1916 union smb_mkdir parm[NSERVERS];
1917 NTSTATUS status[NSERVERS];
1919 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1920 parm[0].mkdir.in.path = gen_fname_open(instance);
1923 GEN_CALL_SMB(smb_raw_mkdir(tree, &parm[i]));
1929 generate rmdir operations
1931 static bool handler_smb_rmdir(int instance)
1933 struct smb_rmdir parm[NSERVERS];
1934 NTSTATUS status[NSERVERS];
1936 parm[0].in.path = gen_fname_open(instance);
1939 GEN_CALL_SMB(smb_raw_rmdir(tree, &parm[i]));
1945 generate rename operations
1947 static bool handler_smb_rename(int instance)
1949 union smb_rename parm[NSERVERS];
1950 NTSTATUS status[NSERVERS];
1952 parm[0].generic.level = RAW_RENAME_RENAME;
1953 parm[0].rename.in.pattern1 = gen_pattern();
1954 parm[0].rename.in.pattern2 = gen_pattern();
1955 parm[0].rename.in.attrib = gen_attrib();
1958 GEN_CALL_SMB(smb_raw_rename(tree, &parm[i]));
1964 generate ntrename operations
1966 static bool handler_smb_ntrename(int instance)
1968 union smb_rename parm[NSERVERS];
1969 NTSTATUS status[NSERVERS];
1971 parm[0].generic.level = RAW_RENAME_NTRENAME;
1972 parm[0].ntrename.in.old_name = gen_fname();
1973 parm[0].ntrename.in.new_name = gen_fname();
1974 parm[0].ntrename.in.attrib = gen_attrib();
1975 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1976 parm[0].ntrename.in.flags = gen_rename_flags();
1979 GEN_CALL_SMB(smb_raw_rename(tree, &parm[i]));
1986 generate seek operations
1988 static bool handler_smb_seek(int instance)
1990 union smb_seek parm[NSERVERS];
1991 NTSTATUS status[NSERVERS];
1993 parm[0].lseek.in.file.fnum = gen_fnum(instance);
1994 parm[0].lseek.in.mode = gen_bits_mask2(0x3, 0xFFFF);
1995 parm[0].lseek.in.offset = gen_offset();
1998 GEN_SET_FNUM_SMB(lseek.in.file.fnum);
1999 GEN_CALL_SMB(smb_raw_seek(tree, &parm[i]));
2001 CHECK_EQUAL(lseek.out.offset);
2008 generate readx operations
2010 static bool handler_smb_readx(int instance)
2012 union smb_read parm[NSERVERS];
2013 NTSTATUS status[NSERVERS];
2015 parm[0].readx.level = RAW_READ_READX;
2016 parm[0].readx.in.file.fnum = gen_fnum(instance);
2017 parm[0].readx.in.offset = gen_offset();
2018 parm[0].readx.in.mincnt = gen_io_count();
2019 parm[0].readx.in.maxcnt = gen_io_count();
2020 parm[0].readx.in.remaining = gen_io_count();
2021 parm[0].readx.in.read_for_execute = gen_bool();
2022 parm[0].readx.out.data = talloc_array(current_op.mem_ctx, uint8_t,
2023 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
2026 GEN_SET_FNUM_SMB(readx.in.file.fnum);
2027 GEN_CALL_SMB(smb_raw_read(tree, &parm[i]));
2029 CHECK_EQUAL(readx.out.remaining);
2030 CHECK_EQUAL(readx.out.compaction_mode);
2031 CHECK_EQUAL(readx.out.nread);
2037 generate writex operations
2039 static bool handler_smb_writex(int instance)
2041 union smb_write parm[NSERVERS];
2042 NTSTATUS status[NSERVERS];
2044 parm[0].writex.level = RAW_WRITE_WRITEX;
2045 parm[0].writex.in.file.fnum = gen_fnum(instance);
2046 parm[0].writex.in.offset = gen_offset();
2047 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
2048 parm[0].writex.in.remaining = gen_io_count();
2049 parm[0].writex.in.count = gen_io_count();
2050 parm[0].writex.in.data = talloc_zero_array(current_op.mem_ctx, uint8_t, parm[0].writex.in.count);
2053 GEN_SET_FNUM_SMB(writex.in.file.fnum);
2054 GEN_CALL_SMB(smb_raw_write(tree, &parm[i]));
2056 CHECK_EQUAL(writex.out.nwritten);
2057 CHECK_EQUAL(writex.out.remaining);
2063 generate lockingx operations
2065 static bool handler_smb_lockingx(int instance)
2067 union smb_lock parm[NSERVERS];
2068 NTSTATUS status[NSERVERS];
2071 parm[0].lockx.level = RAW_LOCK_LOCKX;
2072 parm[0].lockx.in.file.fnum = gen_fnum(instance);
2073 parm[0].lockx.in.mode = gen_lock_mode();
2074 parm[0].lockx.in.timeout = gen_timeout();
2076 /* make sure we don't accidentially generate an oplock
2077 break ack - otherwise the server can just block forever */
2078 parm[0].lockx.in.ulock_cnt = gen_lock_count();
2079 parm[0].lockx.in.lock_cnt = gen_lock_count();
2080 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
2081 } while (nlocks == 0);
2084 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
2085 struct smb_lock_entry,
2087 for (n=0;n<nlocks;n++) {
2088 parm[0].lockx.in.locks[n].pid = gen_pid();
2089 parm[0].lockx.in.locks[n].offset = gen_offset();
2090 parm[0].lockx.in.locks[n].count = gen_io_count();
2095 GEN_SET_FNUM_SMB(lockx.in.file.fnum);
2096 GEN_CALL_SMB(smb_raw_lock(tree, &parm[i]));
2103 generate a fileinfo query structure
2105 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
2109 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
2111 enum smb_setfileinfo_level level;
2115 /* disabled until win2003 can handle them ... */
2116 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
2117 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
2119 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
2120 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2121 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
2122 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2123 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
2126 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2127 } while (ignore_pattern(levels[i].name));
2129 info->generic.level = levels[i].level;
2131 switch (info->generic.level) {
2132 case RAW_SFILEINFO_SETATTR:
2133 info->setattr.in.attrib = gen_attrib();
2134 info->setattr.in.write_time = gen_timet();
2136 case RAW_SFILEINFO_SETATTRE:
2137 info->setattre.in.create_time = gen_timet();
2138 info->setattre.in.access_time = gen_timet();
2139 info->setattre.in.write_time = gen_timet();
2141 case RAW_SFILEINFO_STANDARD:
2142 info->standard.in.create_time = gen_timet();
2143 info->standard.in.access_time = gen_timet();
2144 info->standard.in.write_time = gen_timet();
2146 case RAW_SFILEINFO_EA_SET: {
2147 static struct ea_struct ea;
2148 info->ea_set.in.num_eas = 1;
2149 info->ea_set.in.eas = &ea;
2150 info->ea_set.in.eas[0] = gen_ea_struct();
2153 case RAW_SFILEINFO_BASIC_INFO:
2154 case RAW_SFILEINFO_BASIC_INFORMATION:
2155 info->basic_info.in.create_time = gen_nttime();
2156 info->basic_info.in.access_time = gen_nttime();
2157 info->basic_info.in.write_time = gen_nttime();
2158 info->basic_info.in.change_time = gen_nttime();
2159 info->basic_info.in.attrib = gen_attrib();
2161 case RAW_SFILEINFO_DISPOSITION_INFO:
2162 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
2163 info->disposition_info.in.delete_on_close = gen_bool();
2165 case RAW_SFILEINFO_ALLOCATION_INFO:
2166 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
2167 info->allocation_info.in.alloc_size = gen_alloc_size();
2169 case RAW_SFILEINFO_END_OF_FILE_INFO:
2170 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
2171 info->end_of_file_info.in.size = gen_offset();
2173 case RAW_SFILEINFO_RENAME_INFORMATION:
2174 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
2175 info->rename_information.in.overwrite = gen_bool();
2176 info->rename_information.in.root_fid = gen_root_fid(instance);
2177 info->rename_information.in.new_name = gen_fname_open(instance);
2179 case RAW_SFILEINFO_POSITION_INFORMATION:
2180 info->position_information.in.position = gen_offset();
2182 case RAW_SFILEINFO_MODE_INFORMATION:
2183 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
2185 case RAW_SFILEINFO_FULL_EA_INFORMATION:
2186 info->full_ea_information.in.eas = gen_ea_list();
2188 case RAW_SFILEINFO_GENERIC:
2189 case RAW_SFILEINFO_SEC_DESC:
2190 case RAW_SFILEINFO_UNIX_BASIC:
2191 case RAW_SFILEINFO_UNIX_LINK:
2192 case RAW_SFILEINFO_UNIX_HLINK:
2193 case RAW_SFILEINFO_1023:
2194 case RAW_SFILEINFO_1025:
2195 case RAW_SFILEINFO_1029:
2196 case RAW_SFILEINFO_1032:
2197 case RAW_SFILEINFO_1039:
2198 case RAW_SFILEINFO_1040:
2199 case RAW_SFILEINFO_UNIX_INFO2:
2207 generate a fileinfo query structure
2209 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
2213 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
2215 enum smb_setfileinfo_level level;
2218 struct levels smb_levels[] = {
2219 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
2220 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
2221 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
2222 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2223 LVL(POSITION_INFORMATION), LVL(FULL_EA_INFORMATION), LVL(MODE_INFORMATION),
2224 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2225 LVL(PIPE_INFORMATION), LVL(VALID_DATA_INFORMATION), LVL(SHORT_NAME_INFORMATION),
2226 LVL(1025), LVL(1027), LVL(1029), LVL(1030), LVL(1031), LVL(1032), LVL(1036),
2227 LVL(1041), LVL(1042), LVL(1043), LVL(1044),
2229 struct levels smb2_levels[] = {
2230 LVL(BASIC_INFORMATION),
2231 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2232 LVL(POSITION_INFORMATION), LVL(FULL_EA_INFORMATION), LVL(MODE_INFORMATION),
2233 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2234 LVL(PIPE_INFORMATION), LVL(VALID_DATA_INFORMATION), LVL(SHORT_NAME_INFORMATION),
2235 LVL(1025), LVL(1027), LVL(1029), LVL(1030), LVL(1031), LVL(1032), LVL(1036),
2236 LVL(1041), LVL(1042), LVL(1043), LVL(1044),
2238 struct levels *levels = options.smb2?smb2_levels:smb_levels;
2239 uint32_t num_levels = options.smb2?ARRAY_SIZE(smb2_levels):ARRAY_SIZE(smb_levels);
2242 i = gen_int_range(0, num_levels-1);
2243 } while (ignore_pattern(levels[i].name));
2246 info->generic.level = levels[i].level;
2248 switch (info->generic.level) {
2249 case RAW_SFILEINFO_SETATTR:
2250 info->setattr.in.attrib = gen_attrib();
2251 info->setattr.in.write_time = gen_timet();
2253 case RAW_SFILEINFO_SETATTRE:
2254 info->setattre.in.create_time = gen_timet();
2255 info->setattre.in.access_time = gen_timet();
2256 info->setattre.in.write_time = gen_timet();
2258 case RAW_SFILEINFO_STANDARD:
2259 info->standard.in.create_time = gen_timet();
2260 info->standard.in.access_time = gen_timet();
2261 info->standard.in.write_time = gen_timet();
2263 case RAW_SFILEINFO_EA_SET: {
2264 static struct ea_struct ea;
2265 info->ea_set.in.num_eas = 1;
2266 info->ea_set.in.eas = &ea;
2267 info->ea_set.in.eas[0] = gen_ea_struct();
2270 case RAW_SFILEINFO_BASIC_INFO:
2271 case RAW_SFILEINFO_BASIC_INFORMATION:
2272 info->basic_info.in.create_time = gen_nttime();
2273 info->basic_info.in.access_time = gen_nttime();
2274 info->basic_info.in.write_time = gen_nttime();
2275 info->basic_info.in.change_time = gen_nttime();
2276 info->basic_info.in.attrib = gen_attrib();
2278 case RAW_SFILEINFO_DISPOSITION_INFO:
2279 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
2280 info->disposition_info.in.delete_on_close = gen_bool();
2282 case RAW_SFILEINFO_ALLOCATION_INFO:
2283 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
2284 info->allocation_info.in.alloc_size = gen_alloc_size();
2286 case RAW_SFILEINFO_END_OF_FILE_INFO:
2287 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
2288 info->end_of_file_info.in.size = gen_offset();
2290 case RAW_SFILEINFO_RENAME_INFORMATION:
2291 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
2292 info->rename_information.in.overwrite = gen_bool();
2293 info->rename_information.in.root_fid = gen_root_fid(instance);
2294 info->rename_information.in.new_name = gen_fname_open(instance);
2296 case RAW_SFILEINFO_POSITION_INFORMATION:
2297 info->position_information.in.position = gen_offset();
2299 case RAW_SFILEINFO_MODE_INFORMATION:
2300 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
2302 case RAW_SFILEINFO_FULL_EA_INFORMATION:
2303 info->full_ea_information.in.eas = gen_ea_list();
2306 case RAW_SFILEINFO_GENERIC:
2307 case RAW_SFILEINFO_SEC_DESC:
2308 case RAW_SFILEINFO_1025:
2309 case RAW_SFILEINFO_1029:
2310 case RAW_SFILEINFO_1032:
2311 case RAW_SFILEINFO_UNIX_BASIC:
2312 case RAW_SFILEINFO_UNIX_INFO2:
2313 case RAW_SFILEINFO_UNIX_LINK:
2314 case RAW_SFILEINFO_UNIX_HLINK:
2323 generate a fileinfo query structure
2325 static void gen_fileinfo_smb(int instance, union smb_fileinfo *info)
2329 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
2331 enum smb_fileinfo_level level;
2334 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
2335 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
2336 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
2337 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
2338 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
2339 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
2340 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
2341 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
2342 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
2343 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
2346 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2347 } while (ignore_pattern(levels[i].name));
2349 info->generic.level = levels[i].level;
2353 generate qpathinfo operations
2355 static bool handler_smb_qpathinfo(int instance)
2357 union smb_fileinfo parm[NSERVERS];
2358 NTSTATUS status[NSERVERS];
2360 parm[0].generic.in.file.path = gen_fname_open(instance);
2362 gen_fileinfo_smb(instance, &parm[0]);
2365 GEN_CALL_SMB(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
2367 return cmp_fileinfo(instance, parm, status);
2371 generate qfileinfo operations
2373 static bool handler_smb_qfileinfo(int instance)
2375 union smb_fileinfo parm[NSERVERS];
2376 NTSTATUS status[NSERVERS];
2378 parm[0].generic.in.file.fnum = gen_fnum(instance);
2380 gen_fileinfo_smb(instance, &parm[0]);
2383 GEN_SET_FNUM_SMB(generic.in.file.fnum);
2384 GEN_CALL_SMB(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
2386 return cmp_fileinfo(instance, parm, status);
2391 generate setpathinfo operations
2393 static bool handler_smb_spathinfo(int instance)
2395 union smb_setfileinfo parm[NSERVERS];
2396 NTSTATUS status[NSERVERS];
2398 gen_setfileinfo(instance, &parm[0]);
2399 parm[0].generic.in.file.path = gen_fname_open(instance);
2403 /* a special case for the fid in a RENAME */
2404 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
2405 parm[0].rename_information.in.root_fid != 0) {
2406 GEN_SET_FNUM_SMB(rename_information.in.root_fid);
2409 GEN_CALL_SMB(smb_raw_setpathinfo(tree, &parm[i]));
2416 generate setfileinfo operations
2418 static bool handler_smb_sfileinfo(int instance)
2420 union smb_setfileinfo parm[NSERVERS];
2421 NTSTATUS status[NSERVERS];
2423 parm[0].generic.in.file.fnum = gen_fnum(instance);
2425 gen_setfileinfo(instance, &parm[0]);
2428 GEN_SET_FNUM_SMB(generic.in.file.fnum);
2429 GEN_CALL_SMB(smb_raw_setfileinfo(tree, &parm[i]));
2436 this is called when a change notify reply comes in
2438 static void async_notify_smb(struct smbcli_request *req)
2440 union smb_notify notify;
2444 struct smbcli_transport *transport = req->transport;
2446 tid = SVAL(req->in.hdr, HDR_TID);
2448 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
2449 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
2450 if (NT_STATUS_IS_OK(status) && notify.nttrans.out.num_changes > 0) {
2451 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
2453 notify.nttrans.out.num_changes,
2454 notify.nttrans.out.changes[0].action,
2455 notify.nttrans.out.changes[0].name.s);
2458 for (i=0;i<NSERVERS;i++) {
2459 for (j=0;j<NINSTANCES;j++) {
2460 if (transport == servers[i].smb_tree[j]->session->transport &&
2461 tid == servers[i].smb_tree[j]->tid) {
2462 notifies[i][j].notify_count++;
2463 notifies[i][j].status = status;
2464 notifies[i][j].notify = notify;
2471 generate change notify operations
2473 static bool handler_smb_notify(int instance)
2475 union smb_notify parm[NSERVERS];
2478 ZERO_STRUCT(parm[0]);
2479 parm[0].nttrans.level = RAW_NOTIFY_NTTRANS;
2480 parm[0].nttrans.in.buffer_size = gen_io_count();
2481 parm[0].nttrans.in.completion_filter = gen_bits_mask(0xFF);
2482 parm[0].nttrans.in.file.fnum = gen_fnum(instance);
2483 parm[0].nttrans.in.recursive = gen_bool();
2486 GEN_SET_FNUM_SMB(nttrans.in.file.fnum);
2488 for (n=0;n<NSERVERS;n++) {
2489 struct smbcli_request *req;
2490 req = smb_raw_changenotify_send(servers[n].smb_tree[instance], &parm[n]);
2491 req->async.fn = async_notify_smb;
2499 generate ntcreatex operations
2501 static bool handler_smb2_create(int instance)
2503 struct smb2_create parm[NSERVERS];
2504 NTSTATUS status[NSERVERS];
2506 ZERO_STRUCT(parm[0]);
2507 parm[0].in.security_flags = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFF);
2508 parm[0].in.oplock_level = gen_bits_levels(3, 90, 0x0, 70, 0x9, 100, 0xFF);
2509 parm[0].in.impersonation_level = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFFFFFFFF);
2510 parm[0].in.create_flags = gen_reserved64();
2511 parm[0].in.reserved = gen_reserved64();
2512 parm[0].in.desired_access = gen_access_mask();
2513 parm[0].in.file_attributes = gen_attrib();
2514 parm[0].in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
2515 parm[0].in.create_disposition = gen_open_disp();
2516 parm[0].in.create_options = gen_create_options();
2517 parm[0].in.fname = gen_fname_open(instance);
2518 parm[0].in.eas = gen_ea_list();
2519 parm[0].in.alloc_size = gen_alloc_size();
2520 parm[0].in.durable_open = gen_bool();
2521 parm[0].in.query_maximal_access = gen_bool();
2522 parm[0].in.timewarp = gen_timewarp();
2523 parm[0].in.query_on_disk_id = gen_bool();
2524 parm[0].in.sec_desc = gen_sec_desc();
2526 if (!options.use_oplocks) {
2527 /* mask out oplocks */
2528 parm[0].in.oplock_level = 0;
2531 if (options.valid) {
2532 parm[0].in.security_flags &= 3;
2533 parm[0].in.oplock_level &= 9;
2534 parm[0].in.impersonation_level &= 3;
2538 GEN_CALL_SMB2(smb2_create(tree, current_op.mem_ctx, &parm[i]));
2540 CHECK_EQUAL(out.oplock_level);
2541 CHECK_EQUAL(out.reserved);
2542 CHECK_EQUAL(out.create_action);
2543 CHECK_NTTIMES_EQUAL(out.create_time);
2544 CHECK_NTTIMES_EQUAL(out.access_time);
2545 CHECK_NTTIMES_EQUAL(out.write_time);
2546 CHECK_NTTIMES_EQUAL(out.change_time);
2547 CHECK_EQUAL(out.alloc_size);
2548 CHECK_EQUAL(out.size);
2549 CHECK_ATTRIB(out.file_attr);
2550 CHECK_EQUAL(out.reserved2);
2551 CHECK_EQUAL(out.maximal_access);
2553 /* ntcreatex creates a new file handle */
2554 ADD_HANDLE_SMB2(parm[0].in.fname, out.file.handle);
2560 generate close operations
2562 static bool handler_smb2_close(int instance)
2564 struct smb2_close parm[NSERVERS];
2565 NTSTATUS status[NSERVERS];
2567 ZERO_STRUCT(parm[0]);
2568 parm[0].in.file.handle.data[0] = gen_fnum_close(instance);
2569 parm[0].in.flags = gen_bits_mask2(0x1, 0xFFFF);
2572 GEN_SET_FNUM_SMB2(in.file.handle);
2573 GEN_CALL_SMB2(smb2_close(tree, &parm[i]));
2575 CHECK_EQUAL(out.flags);
2576 CHECK_EQUAL(out._pad);
2577 CHECK_NTTIMES_EQUAL(out.create_time);
2578 CHECK_NTTIMES_EQUAL(out.access_time);
2579 CHECK_NTTIMES_EQUAL(out.write_time);
2580 CHECK_NTTIMES_EQUAL(out.change_time);
2581 CHECK_EQUAL(out.alloc_size);
2582 CHECK_EQUAL(out.size);
2583 CHECK_ATTRIB(out.file_attr);
2585 REMOVE_HANDLE_SMB2(in.file.handle);
2591 generate read operations
2593 static bool handler_smb2_read(int instance)
2595 struct smb2_read parm[NSERVERS];
2596 NTSTATUS status[NSERVERS];
2598 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2599 parm[0].in.reserved = gen_reserved8();
2600 parm[0].in.length = gen_io_count();
2601 parm[0].in.offset = gen_offset();
2602 parm[0].in.min_count = gen_io_count();
2603 parm[0].in.channel = gen_bits_mask2(0x0, 0xFFFFFFFF);
2604 parm[0].in.remaining = gen_bits_mask2(0x0, 0xFFFFFFFF);
2605 parm[0].in.channel_offset = gen_bits_mask2(0x0, 0xFFFF);
2606 parm[0].in.channel_length = gen_bits_mask2(0x0, 0xFFFF);
2609 GEN_SET_FNUM_SMB2(in.file.handle);
2610 GEN_CALL_SMB2(smb2_read(tree, current_op.mem_ctx, &parm[i]));
2612 CHECK_EQUAL(out.remaining);
2613 CHECK_EQUAL(out.reserved);
2614 CHECK_EQUAL(out.data.length);
2620 generate write operations
2622 static bool handler_smb2_write(int instance)
2624 struct smb2_write parm[NSERVERS];
2625 NTSTATUS status[NSERVERS];
2627 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2628 parm[0].in.offset = gen_offset();
2629 parm[0].in.unknown1 = gen_bits_mask2(0, 0xFFFFFFFF);
2630 parm[0].in.unknown2 = gen_bits_mask2(0, 0xFFFFFFFF);
2631 parm[0].in.data = data_blob_talloc(current_op.mem_ctx, NULL,
2635 GEN_SET_FNUM_SMB2(in.file.handle);
2636 GEN_CALL_SMB2(smb2_write(tree, &parm[i]));
2638 CHECK_EQUAL(out._pad);
2639 CHECK_EQUAL(out.nwritten);
2640 CHECK_EQUAL(out.unknown1);
2646 generate lockingx operations
2648 static bool handler_smb2_lock(int instance)
2650 struct smb2_lock parm[NSERVERS];
2651 NTSTATUS status[NSERVERS];
2654 parm[0].level = RAW_LOCK_LOCKX;
2655 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2656 parm[0].in.lock_count = gen_lock_count();
2657 parm[0].in.reserved = gen_reserved32();
2659 parm[0].in.locks = talloc_array(current_op.mem_ctx,
2660 struct smb2_lock_element,
2661 parm[0].in.lock_count);
2662 for (n=0;n<parm[0].in.lock_count;n++) {
2663 parm[0].in.locks[n].offset = gen_offset();
2664 parm[0].in.locks[n].length = gen_io_count();
2665 /* don't yet cope with async replies */
2666 parm[0].in.locks[n].flags = gen_lock_flags_smb2() |
2667 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY;
2668 parm[0].in.locks[n].reserved = gen_bits_mask2(0x0, 0xFFFFFFFF);
2672 GEN_SET_FNUM_SMB2(in.file.handle);
2673 GEN_CALL_SMB2(smb2_lock(tree, &parm[i]));
2679 generate flush operations
2681 static bool handler_smb2_flush(int instance)
2683 struct smb2_flush parm[NSERVERS];
2684 NTSTATUS status[NSERVERS];
2686 ZERO_STRUCT(parm[0]);
2687 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2688 parm[0].in.reserved1 = gen_reserved16();
2689 parm[0].in.reserved2 = gen_reserved32();
2692 GEN_SET_FNUM_SMB2(in.file.handle);
2693 GEN_CALL_SMB2(smb2_flush(tree, &parm[i]));
2695 CHECK_EQUAL(out.reserved);
2701 generate echo operations
2703 static bool handler_smb2_echo(int instance)
2705 NTSTATUS status[NSERVERS];
2707 GEN_CALL_SMB2(smb2_keepalive(tree->session->transport));
2715 generate a fileinfo query structure
2717 static void gen_fileinfo_smb2(int instance, union smb_fileinfo *info)
2720 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
2722 enum smb_fileinfo_level level;
2725 LVL(BASIC_INFORMATION),
2726 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
2727 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
2728 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(SMB2_ALL_INFORMATION),
2729 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
2730 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION),
2731 LVL(SMB2_ALL_EAS), LVL(SMB2_ALL_INFORMATION), LVL(SEC_DESC),
2734 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2735 } while (ignore_pattern(levels[i].name));
2737 info->generic.level = levels[i].level;
2741 generate qfileinfo operations
2743 static bool handler_smb2_qfileinfo(int instance)
2745 union smb_fileinfo parm[NSERVERS];
2746 NTSTATUS status[NSERVERS];
2748 parm[0].generic.in.file.handle.data[0] = gen_fnum(instance);
2750 gen_fileinfo_smb2(instance, &parm[0]);
2753 GEN_SET_FNUM_SMB2(generic.in.file.handle);
2754 GEN_CALL_SMB2(smb2_getinfo_file(tree, current_op.mem_ctx, &parm[i]));
2756 return cmp_fileinfo(instance, parm, status);
2761 generate setfileinfo operations
2763 static bool handler_smb2_sfileinfo(int instance)
2765 union smb_setfileinfo parm[NSERVERS];
2766 NTSTATUS status[NSERVERS];
2768 gen_setfileinfo(instance, &parm[0]);
2769 parm[0].generic.in.file.fnum = gen_fnum(instance);
2772 GEN_SET_FNUM_SMB2(generic.in.file.handle);
2773 GEN_CALL_SMB2(smb2_setinfo_file(tree, &parm[i]));
2779 wipe any relevant files
2781 static void wipe_files(void)
2786 if (options.skip_cleanup) {
2790 for (i=0;i<NSERVERS;i++) {
2793 n = smb2_deltree(servers[i].smb2_tree[0], "gentest");
2795 n = smbcli_deltree(servers[i].smb_tree[0], "gentest");
2798 printf("Failed to wipe tree on server %d\n", i);
2802 status = smb2_util_mkdir(servers[i].smb2_tree[0], "gentest");
2804 status = smbcli_mkdir(servers[i].smb_tree[0], "gentest");
2806 if (NT_STATUS_IS_ERR(status)) {
2807 printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status));
2811 printf("Deleted %d files on server %d\n", n, i);
2817 dump the current seeds - useful for continuing a backtrack
2819 static void dump_seeds(void)
2824 if (!options.seeds_file) {
2827 f = fopen("seeds.tmp", "w");
2830 for (i=0;i<options.numops;i++) {
2831 fprintf(f, "%u\n", op_parms[i].seed);
2834 rename("seeds.tmp", options.seeds_file);
2840 the list of top-level operations that we will generate
2844 bool (*handler)(int instance);
2846 int count, success_count;
2848 {"CREATE", handler_smb2_create, true},
2849 {"CLOSE", handler_smb2_close, true},
2850 {"READ", handler_smb2_read, true},
2851 {"WRITE", handler_smb2_write, true},
2852 {"LOCK", handler_smb2_lock, true},
2853 {"FLUSH", handler_smb2_flush, true},
2854 {"ECHO", handler_smb2_echo, true},
2855 {"QFILEINFO", handler_smb2_qfileinfo, true},
2856 {"SFILEINFO", handler_smb2_sfileinfo, true},
2858 {"OPEN", handler_smb_open, false},
2859 {"OPENX", handler_smb_openx, false},
2860 {"NTCREATEX", handler_smb_ntcreatex, false},
2861 {"CLOSE", handler_smb_close, false},
2862 {"UNLINK", handler_smb_unlink, false},
2863 {"MKDIR", handler_smb_mkdir, false},
2864 {"RMDIR", handler_smb_rmdir, false},
2865 {"RENAME", handler_smb_rename, false},
2866 {"NTRENAME", handler_smb_ntrename, false},
2867 {"READX", handler_smb_readx, false},
2868 {"WRITEX", handler_smb_writex, false},
2869 {"CHKPATH", handler_smb_chkpath, false},
2870 {"SEEK", handler_smb_seek, false},
2871 {"LOCKINGX", handler_smb_lockingx, false},
2872 {"QPATHINFO", handler_smb_qpathinfo, false},
2873 {"QFILEINFO", handler_smb_qfileinfo, false},
2874 {"SPATHINFO", handler_smb_spathinfo, false},
2875 {"SFILEINFO", handler_smb_sfileinfo, false},
2876 {"NOTIFY", handler_smb_notify, false},
2877 {"SEEK", handler_smb_seek, false},
2882 run the test with the current set of op_parms parameters
2883 return the number of operations that completed successfully
2885 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
2889 if (!connect_servers(ev, lp_ctx)) {
2890 printf("Failed to connect to servers\n");
2896 /* wipe any leftover files from old runs */
2899 /* reset the open handles array */
2900 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
2901 num_open_handles = 0;
2903 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2904 gen_ops[i].count = 0;
2905 gen_ops[i].success_count = 0;
2908 for (op=0; op<options.numops; op++) {
2909 int instance, which_op;
2912 if (op_parms[op].disabled) continue;
2914 srandom(op_parms[op].seed);
2916 instance = gen_int_range(0, NINSTANCES-1);
2918 /* generate a non-ignored operation */
2920 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
2921 } while (ignore_pattern(gen_ops[which_op].name) ||
2922 gen_ops[which_op].smb2 != options.smb2);
2924 DEBUG(3,("Generating op %s on instance %d\n",
2925 gen_ops[which_op].name, instance));
2927 current_op.seed = op_parms[op].seed;
2928 current_op.opnum = op;
2929 current_op.name = gen_ops[which_op].name;
2930 current_op.status = NT_STATUS_OK;
2931 talloc_free(current_op.mem_ctx);
2932 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
2934 ret = gen_ops[which_op].handler(instance);
2936 gen_ops[which_op].count++;
2937 if (NT_STATUS_IS_OK(current_op.status)) {
2938 gen_ops[which_op].success_count++;
2942 printf("Failed at operation %d - %s\n",
2943 op, gen_ops[which_op].name);
2947 if (op % 100 == 0) {
2952 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2953 printf("Op %-10s got %d/%d success\n",
2955 gen_ops[i].success_count,
2963 perform a backtracking analysis of the minimal set of operations
2964 to generate an error
2966 static void backtrack_analyze(struct event_context *ev,
2967 struct loadparm_context *lp_ctx)
2970 const char *mismatch = current_op.mismatch;
2972 chunk = options.numops / 2;
2977 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2980 chunk = MIN(chunk, options.numops / 2);
2982 /* mark this range as disabled */
2983 max = MIN(options.numops, base+chunk);
2984 for (i=base;i<max; i++) {
2985 op_parms[i].disabled = true;
2987 printf("Testing %d ops with %d-%d disabled\n",
2988 options.numops, base, max-1);
2989 ret = run_test(ev, lp_ctx);
2990 printf("Completed %d of %d ops\n", ret, options.numops);
2991 for (i=base;i<max; i++) {
2992 op_parms[i].disabled = false;
2994 if (ret == options.numops) {
2995 /* this chunk is needed */
2997 } else if (mismatch != current_op.mismatch &&
2998 strcmp(mismatch, current_op.mismatch)) {
3000 printf("Different error in backtracking\n");
3001 } else if (ret < base) {
3002 printf("damn - inconsistent errors! found early error\n");
3003 options.numops = ret+1;
3006 /* it failed - this chunk isn't needed for a failure */
3007 memmove(&op_parms[base], &op_parms[max],
3008 sizeof(op_parms[0]) * (options.numops - max));
3009 options.numops = (ret+1) - (max - base);
3019 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
3022 } while (chunk > 0);
3024 printf("Reduced to %d ops\n", options.numops);
3025 ret = run_test(ev, lp_ctx);
3026 if (ret != options.numops - 1) {
3027 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
3032 start the main gentest process
3034 static bool start_gentest(struct event_context *ev,
3035 struct loadparm_context *lp_ctx)
3040 /* allocate the open_handles array */
3041 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
3043 srandom(options.seed);
3044 op_parms = calloc(options.numops, sizeof(op_parms[0]));
3046 /* generate the seeds - after this everything is deterministic */
3047 if (options.use_preset_seeds) {
3049 char **preset = file_lines_load(options.seeds_file, &numops, 0, NULL);
3051 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
3054 if (numops < options.numops) {
3055 options.numops = numops;
3057 for (op=0;op<options.numops;op++) {
3059 printf("Not enough seeds in %s\n", options.seeds_file);
3062 op_parms[op].seed = atoi(preset[op]);
3064 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
3066 for (op=0; op<options.numops; op++) {
3067 op_parms[op].seed = random();
3071 ret = run_test(ev, lp_ctx);
3073 if (ret != options.numops && options.analyze) {
3074 options.numops = ret+1;
3075 backtrack_analyze(ev, lp_ctx);
3076 } else if (options.analyze_always) {
3077 backtrack_analyze(ev, lp_ctx);
3078 } else if (options.analyze_continuous) {
3079 while (run_test(ev, lp_ctx) == options.numops) ;
3082 return ret == options.numops;
3086 static void usage(poptContext pc)
3090 gentest //server1/share1 //server2/share2 [options..]\n\
3092 poptPrintUsage(pc, stdout, 0);
3096 split a UNC name into server and share names
3098 static bool split_unc_name(const char *unc, char **server, char **share)
3100 char *p = strdup(unc);
3101 if (!p) return false;
3102 all_string_sub(p, "\\", "/", 0);
3103 if (strncmp(p, "//", 2) != 0) return false;
3106 p = strchr(*server, '/');
3107 if (!p) return false;
3117 /****************************************************************************
3119 ****************************************************************************/
3120 int main(int argc, char *argv[])
3123 int i, username_count=0;
3125 char *ignore_file=NULL;
3126 struct event_context *ev;
3127 struct loadparm_context *lp_ctx;
3131 enum {OPT_UNCLIST=1000};
3132 struct poptOption long_options[] = {
3134 {"smb2", 0, POPT_ARG_NONE, &options.smb2, 0, "use SMB2 protocol", NULL},
3135 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
3136 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
3137 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
3138 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
3139 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
3140 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
3141 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
3142 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
3143 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
3144 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
3145 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
3146 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
3147 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
3148 {"maskindexing", 0, POPT_ARG_NONE, &options.mask_indexing, 0, "mask out the indexed file attrib", NULL},
3149 {"noeas", 0, POPT_ARG_NONE, &options.no_eas, 0, "don't use extended attributes", NULL},
3150 {"noacls", 0, POPT_ARG_NONE, &options.no_acls, 0, "don't use ACLs", NULL},
3151 {"skip-cleanup", 0, POPT_ARG_NONE, &options.skip_cleanup, 0, "don't delete files at start", NULL},
3152 {"valid", 0, POPT_ARG_NONE, &options.valid, 0, "generate only valid fields", NULL},
3154 POPT_COMMON_CONNECTION
3155 POPT_COMMON_CREDENTIALS
3160 memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
3163 options.seed = time(NULL);
3164 options.numops = 1000;
3165 options.max_open_handles = 20;
3166 options.seeds_file = "gentest_seeds.dat";
3168 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
3169 POPT_CONTEXT_KEEP_FIRST);
3171 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
3173 lp_ctx = cmdline_lp_ctx;
3174 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
3175 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
3176 cli_credentials_guess(servers[0].credentials, lp_ctx);
3177 cli_credentials_guess(servers[1].credentials, lp_ctx);
3179 while((opt = poptGetNextOpt(pc)) != -1) {
3182 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
3185 if (username_count == 2) {
3189 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
3196 options.ignore_patterns = file_lines_load(ignore_file, NULL, 0, NULL);
3199 argv_new = discard_const_p(char *, poptGetArgs(pc));
3201 for (i=0; i<argc; i++) {
3202 if (argv_new[i] == NULL) {
3208 if (!(argc_new >= 3)) {
3215 setup_logging("gentest", DEBUG_STDOUT);
3217 if (argc < 3 || argv[1][0] == '-') {
3222 setup_logging(argv[0], DEBUG_STDOUT);
3224 for (i=0;i<NSERVERS;i++) {
3225 const char *share = argv[1+i];
3226 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
3227 printf("Invalid share name '%s'\n", share);
3232 if (username_count == 0) {
3236 if (username_count == 1) {
3237 servers[1].credentials = servers[0].credentials;
3240 printf("seed=%u\n", options.seed);
3242 ev = s4_event_context_init(talloc_autofree_context());
3244 gensec_init(lp_ctx);
3246 ret = start_gentest(ev, lp_ctx);
3249 printf("gentest completed - no errors\n");
3251 printf("gentest failed\n");