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 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
217 servers[i].server_name, servers[i].share_name,
218 servers[i].credentials->username, j);
220 cli_credentials_set_workstation(servers[i].credentials,
221 "gentest", CRED_SPECIFIED);
224 status = smb2_connect(NULL, servers[i].server_name,
225 servers[i].share_name,
226 lp_resolve_context(lp_ctx),
227 servers[i].credentials,
228 &servers[i].smb2_tree[j],
231 struct smbcli_options smb_options;
232 lp_smbcli_options(lp_ctx, &smb_options);
233 status = smbcli_tree_full_connection(NULL,
234 &servers[i].smb_tree[j],
235 servers[i].server_name,
236 lp_smb_ports(lp_ctx),
237 servers[i].share_name, "A:",
238 servers[i].credentials,
239 lp_resolve_context(lp_ctx), ev,
242 if (!NT_STATUS_IS_OK(status)) {
243 printf("Failed to connect to \\\\%s\\%s - %s\n",
244 servers[i].server_name, servers[i].share_name,
250 servers[i].smb2_tree[j]->session->transport->oplock.handler = oplock_handler_smb2;
251 servers[i].smb2_tree[j]->session->transport->oplock.private_data = (void *)(uintptr_t)((i<<8)|j);
252 smb2_transport_idle_handler(servers[i].smb2_tree[j]->session->transport,
253 idle_func_smb2, 50000, NULL);
255 smbcli_oplock_handler(servers[i].smb_tree[j]->session->transport, oplock_handler_smb,
256 (void *)(uintptr_t)((i<<8)|j));
257 smbcli_transport_idle_handler(servers[i].smb_tree[j]->session->transport, idle_func_smb,
258 50000, (void *)(uintptr_t)((i<<8)|j));
267 work out the time skew between the servers - be conservative
269 static uint_t time_skew(void)
273 ret = labs(servers[0].smb2_tree[0]->session->transport->negotiate.system_time -
274 servers[1].smb2_tree[0]->session->transport->negotiate.system_time);
276 ret = labs(servers[0].smb_tree[0]->session->transport->negotiate.server_time -
277 servers[1].smb_tree[0]->session->transport->negotiate.server_time);
283 static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_handle *h2)
285 return memcmp(h1, h2, sizeof(struct smb2_handle)) == 0;
289 turn a server handle into a local handle
291 static uint_t fnum_to_handle_smb2(int server, int instance, struct smb2_handle server_handle)
294 for (i=0;i<options.max_open_handles;i++) {
295 if (!open_handles[i].active ||
296 instance != open_handles[i].instance) continue;
297 if (smb2_handle_equal(&open_handles[i].smb2_handle[server], &server_handle)) {
301 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
307 turn a server handle into a local handle
309 static uint_t fnum_to_handle_smb(int server, int instance, uint16_t server_handle)
312 for (i=0;i<options.max_open_handles;i++) {
313 if (!open_handles[i].active ||
314 instance != open_handles[i].instance) continue;
315 if (open_handles[i].smb_handle[server] == server_handle) {
319 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
325 add some newly opened handles
327 static void gen_add_handle_smb2(int instance, const char *name, struct smb2_handle handles[NSERVERS])
330 for (h=0;h<options.max_open_handles;h++) {
331 if (!open_handles[h].active) break;
333 if (h == options.max_open_handles) {
334 /* we have to force close a random handle */
335 h = random() % options.max_open_handles;
336 for (i=0;i<NSERVERS;i++) {
338 status = smb2_util_close(servers[i].smb2_tree[open_handles[h].instance],
339 open_handles[h].smb2_handle[i]);
340 if (NT_STATUS_IS_ERR(status)) {
341 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
345 printf("Recovered handle %d\n", h);
348 for (i=0;i<NSERVERS;i++) {
349 open_handles[h].smb2_handle[i] = handles[i];
350 open_handles[h].instance = instance;
351 open_handles[h].active = true;
352 open_handles[h].name = name;
356 printf("OPEN num_open_handles=%d h=%d (%s)\n",
357 num_open_handles, h, name);
361 add some newly opened handles
363 static void gen_add_handle_smb(int instance, const char *name, uint16_t handles[NSERVERS])
366 for (h=0;h<options.max_open_handles;h++) {
367 if (!open_handles[h].active) break;
369 if (h == options.max_open_handles) {
370 /* we have to force close a random handle */
371 h = random() % options.max_open_handles;
372 for (i=0;i<NSERVERS;i++) {
374 status = smbcli_close(servers[i].smb_tree[open_handles[h].instance],
375 open_handles[h].smb_handle[i]);
376 if (NT_STATUS_IS_ERR(status)) {
377 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
381 printf("Recovered handle %d\n", h);
384 for (i=0;i<NSERVERS;i++) {
385 open_handles[h].smb_handle[i] = handles[i];
386 open_handles[h].instance = instance;
387 open_handles[h].active = true;
388 open_handles[h].name = name;
392 printf("OPEN num_open_handles=%d h=%d (%s)\n",
393 num_open_handles, h, name);
398 remove a closed handle
400 static void gen_remove_handle_smb2(int instance, struct smb2_handle handles[NSERVERS])
403 for (h=0;h<options.max_open_handles;h++) {
404 if (instance == open_handles[h].instance &&
405 smb2_handle_equal(&open_handles[h].smb2_handle[0], &handles[0])) {
406 open_handles[h].active = false;
408 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
410 open_handles[h].name);
414 printf("Removing invalid handle!?\n");
419 remove a closed handle
421 static void gen_remove_handle_smb(int instance, uint16_t handles[NSERVERS])
424 for (h=0;h<options.max_open_handles;h++) {
425 if (instance == open_handles[h].instance &&
426 open_handles[h].smb_handle[0] == handles[0]) {
427 open_handles[h].active = false;
429 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
431 open_handles[h].name);
435 printf("Removing invalid handle!?\n");
440 return true with 'chance' probability as a percentage
442 static bool gen_chance(uint_t chance)
444 return ((random() % 100) <= chance);
448 map an internal handle number to a server handle
450 static struct smb2_handle gen_lookup_handle_smb2(int server, uint16_t handle)
452 if (handle == BAD_HANDLE) return bad_smb2_handle;
453 return open_handles[handle].smb2_handle[server];
457 map an internal handle number to a server handle
459 static uint16_t gen_lookup_handle_smb(int server, uint16_t handle)
461 if (handle == BAD_HANDLE) return BAD_HANDLE;
462 return open_handles[handle].smb_handle[server];
468 static uint16_t gen_fnum(int instance)
473 if (gen_chance(20)) return BAD_HANDLE;
475 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
476 h = random() % options.max_open_handles;
477 if (open_handles[h].active &&
478 open_handles[h].instance == instance) {
486 return a file handle, but skewed so we don't close the last
487 couple of handles too readily
489 static uint16_t gen_fnum_close(int instance)
491 if (num_open_handles < 5) {
492 if (gen_chance(90)) return BAD_HANDLE;
495 return gen_fnum(instance);
499 generate an integer in a specified range
501 static int gen_int_range(uint64_t min, uint64_t max)
504 return min + (r % (1+max-min));
508 return a fnum for use as a root fid
509 be careful to call GEN_SET_FNUM() when you use this!
511 static uint16_t gen_root_fid(int instance)
513 if (gen_chance(5)) return gen_fnum(instance);
518 generate a file offset
520 static int gen_offset(void)
522 if (gen_chance(20)) return 0;
523 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
524 return gen_int_range(0, 1024*1024);
530 static int gen_io_count(void)
532 if (gen_chance(20)) return 0;
533 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
534 return gen_int_range(0, 4096);
540 static const char *gen_fname(void)
542 const char *names[] = {"gentest\\gentest.dat",
547 "gentest\\foo4:teststream1",
548 "gentest\\foo4:teststream2",
550 "gentest\\foo5.exe:teststream3",
551 "gentest\\foo5.exe:teststream4",
554 "gentest\\blah\\blergh.txt",
555 "gentest\\blah\\blergh2",
556 "gentest\\blah\\blergh3.txt",
557 "gentest\\blah\\blergh4",
558 "gentest\\blah\\blergh5.txt",
559 "gentest\\blah\\blergh5",
562 "gentest\\a_very_long_name.bin",
568 i = gen_int_range(0, ARRAY_SIZE(names)-1);
569 } while (ignore_pattern(names[i]));
575 generate a filename with a higher chance of choosing an already
578 static const char *gen_fname_open(int instance)
581 h = gen_fnum(instance);
582 if (h == BAD_HANDLE) {
585 return open_handles[h].name;
589 generate a wildcard pattern
591 static const char *gen_pattern(void)
594 const char *names[] = {"gentest\\*.dat",
597 "gentest\\blah\\*.*",
601 if (gen_chance(50)) return gen_fname();
604 i = gen_int_range(0, ARRAY_SIZE(names)-1);
605 } while (ignore_pattern(names[i]));
610 static uint32_t gen_bits_levels(int nlevels, ...)
616 va_start(ap, nlevels);
617 for (i=0;i<nlevels;i++) {
618 pct = va_arg(ap, uint32_t);
619 mask = va_arg(ap, uint32_t);
620 if (pct == 100 || gen_chance(pct)) {
622 return mask & random();
632 static uint32_t gen_bits_mask(uint_t mask)
634 uint_t ret = random();
639 generate a bitmask with high probability of the first mask
640 and low of the second
642 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
644 if (!options.valid && gen_chance(10)) return gen_bits_mask(mask2);
645 return gen_bits_mask(mask1);
649 generate reserved values
651 static uint64_t gen_reserved8(void)
653 if (options.valid) return 0;
654 return gen_bits_mask(0xFF);
657 static uint64_t gen_reserved16(void)
659 if (options.valid) return 0;
660 return gen_bits_mask(0xFFFF);
663 static uint64_t gen_reserved32(void)
665 if (options.valid) return 0;
666 return gen_bits_mask(0xFFFFFFFF);
669 static uint64_t gen_reserved64(void)
671 if (options.valid) return 0;
672 return gen_bits_mask(0xFFFFFFFF) | (((uint64_t)gen_bits_mask(0xFFFFFFFF))<<32);
680 static bool gen_bool(void)
682 return gen_bits_mask2(0x1, 0xFF);
686 generate ntrename flags
688 static uint16_t gen_rename_flags(void)
690 if (gen_chance(30)) return RENAME_FLAG_RENAME;
691 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
692 if (gen_chance(30)) return RENAME_FLAG_COPY;
693 return gen_bits_mask(0xFFFF);
699 static uint16_t gen_pid(void)
701 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
706 return a set of lock flags
708 static uint16_t gen_lock_flags_smb2(void)
710 if (!options.valid && gen_chance(5)) return gen_bits_mask(0xFFFF);
711 if (gen_chance(20)) return gen_bits_mask(0x1F);
712 if (gen_chance(50)) return SMB2_LOCK_FLAG_UNLOCK;
713 return gen_bits_mask(SMB2_LOCK_FLAG_SHARED |
714 SMB2_LOCK_FLAG_EXCLUSIVE |
715 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY);
719 generate a lock count
721 static off_t gen_lock_count(void)
723 return gen_int_range(0, 3);
727 generate a NT access mask
729 static uint32_t gen_access_mask(void)
732 if (gen_chance(70)) return SEC_FLAG_MAXIMUM_ALLOWED;
733 if (gen_chance(70)) return SEC_FILE_ALL;
734 ret = gen_bits_mask(0xFFFFFFFF);
735 if (options.valid) ret &= ~SEC_MASK_INVALID;
740 return a lockingx lock mode
742 static uint16_t gen_lock_mode(void)
744 if (!options.valid && gen_chance(5)) return gen_bits_mask(0xFFFF);
745 if (gen_chance(20)) return gen_bits_mask(0x1F);
746 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
750 generate a ntcreatex flags field
752 static uint32_t gen_ntcreatex_flags(void)
754 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
755 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
759 generate a ntcreatex create options bitfield
761 static uint32_t gen_create_options(void)
763 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
764 if (gen_chance(50)) return 0;
765 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
769 generate a ntcreatex open disposition
771 static uint32_t gen_open_disp(void)
773 if (gen_chance(50)) return NTCREATEX_DISP_OPEN_IF;
774 if (!options.valid && gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
775 return gen_int_range(0, 5);
779 generate an openx open mode
781 static uint16_t gen_openx_mode(void)
783 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
784 if (gen_chance(20)) return gen_bits_mask(0xFF);
785 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
789 generate an openx flags field
791 static uint16_t gen_openx_flags(void)
793 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
794 return gen_bits_mask(0x7);
798 generate an openx open function
800 static uint16_t gen_openx_func(void)
802 if (!options.valid && gen_chance(20)) return gen_bits_mask(0xFFFF);
803 return gen_bits_mask(0x13);
807 generate a file attrib combination
809 static uint32_t gen_attrib(void)
812 if (gen_chance(20)) {
813 ret = gen_bits_mask(0xFFFFFFFF);
814 if (options.valid) ret &= FILE_ATTRIBUTE_ALL_MASK;
817 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
821 generate a unix timestamp
823 static time_t gen_timet(void)
825 if (gen_chance(30)) return 0;
826 return (time_t)random();
830 generate a milliseconds protocol timeout
832 static uint32_t gen_timeout(void)
834 if (gen_chance(98)) return 0;
835 return random() % 50;
841 static NTTIME gen_nttime(void)
844 unix_to_nt_time(&ret, gen_timet());
849 generate a timewarp value
851 static NTTIME gen_timewarp(void)
853 NTTIME ret = gen_nttime();
854 if (gen_chance(98)) ret = 0;
859 generate a file allocation size
861 static uint_t gen_alloc_size(void)
865 if (gen_chance(30)) return 0;
867 ret = random() % 4*1024*1024;
868 /* give a high chance of a round number */
869 if (gen_chance(60)) {
870 ret &= ~(1024*1024 - 1);
876 generate an ea_struct
878 static struct ea_struct gen_ea_struct(void)
881 const char *names[] = {"EAONE",
886 "AVERYLONGATTRIBUTENAME"};
887 const char *values[] = {"VALUE1",
892 "ASOMEWHATLONGERATTRIBUTEVALUE"};
898 i = gen_int_range(0, ARRAY_SIZE(names)-1);
899 } while (ignore_pattern(names[i]));
901 ea.name.s = names[i];
904 i = gen_int_range(0, ARRAY_SIZE(values)-1);
905 } while (ignore_pattern(values[i]));
907 ea.value = data_blob(values[i], strlen(values[i]));
909 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
916 generate an ea_struct
918 static struct smb_ea_list gen_ea_list(void)
920 struct smb_ea_list eas;
922 if (options.no_eas) {
926 eas.num_eas = gen_int_range(0, 3);
927 eas.eas = talloc_array(current_op.mem_ctx, struct ea_struct, eas.num_eas);
928 for (i=0;i<eas.num_eas;i++) {
929 eas.eas[i] = gen_ea_struct();
934 /* generate a security descriptor */
935 static struct security_descriptor *gen_sec_desc(void)
937 struct security_descriptor *sd;
938 if (options.no_acls || gen_chance(90)) return NULL;
940 sd = security_descriptor_dacl_create(current_op.mem_ctx,
943 SEC_ACE_TYPE_ACCESS_ALLOWED,
944 SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
945 SEC_ACE_FLAG_OBJECT_INHERIT,
947 SEC_ACE_TYPE_ACCESS_ALLOWED,
948 SEC_FILE_ALL | SEC_STD_ALL,
955 static void oplock_handler_close_recv_smb(struct smbcli_request *req)
958 status = smbcli_request_simple_recv(req);
959 if (!NT_STATUS_IS_OK(status)) {
960 printf("close failed in oplock_handler\n");
961 smb_panic("close failed in oplock_handler");
966 the oplock handler will either ack the break or close the file
968 static bool oplock_handler_smb(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
973 struct smbcli_tree *tree = NULL;
974 struct smbcli_request *req;
976 srandom(current_op.seed);
977 do_close = gen_chance(50);
979 for (i=0;i<NSERVERS;i++) {
980 for (j=0;j<NINSTANCES;j++) {
981 if (transport == servers[i].smb_tree[j]->session->transport &&
982 tid == servers[i].smb_tree[j]->tid) {
983 oplocks[i][j].got_break = true;
984 oplocks[i][j].smb_handle = fnum;
985 oplocks[i][j].handle = fnum_to_handle_smb(i, j, fnum);
986 oplocks[i][j].level = level;
987 oplocks[i][j].do_close = do_close;
988 tree = servers[i].smb_tree[j];
994 printf("Oplock break not for one of our trees!?\n");
999 printf("oplock ack fnum=%d\n", fnum);
1000 return smbcli_oplock_ack(tree, fnum, level);
1003 printf("oplock close fnum=%d\n", fnum);
1005 io.close.level = RAW_CLOSE_CLOSE;
1006 io.close.in.file.fnum = fnum;
1007 io.close.in.write_time = 0;
1008 req = smb_raw_close_send(tree, &io);
1011 printf("WARNING: close failed in oplock_handler_close\n");
1015 req->async.fn = oplock_handler_close_recv_smb;
1016 req->async.private = NULL;
1023 the idle function tries to cope with getting an oplock break on a connection, and
1024 an operation on another connection blocking until that break is acked
1025 we check for operations on all transports in the idle function
1027 static void idle_func_smb(struct smbcli_transport *transport, void *private)
1030 for (i=0;i<NSERVERS;i++) {
1031 for (j=0;j<NINSTANCES;j++) {
1032 if (servers[i].smb_tree[j] &&
1033 transport != servers[i].smb_tree[j]->session->transport) {
1034 smbcli_transport_process(servers[i].smb_tree[j]->session->transport);
1041 static void oplock_handler_close_recv_smb2(struct smb2_request *req)
1044 struct smb2_close io;
1045 status = smb2_close_recv(req, &io);
1046 if (!NT_STATUS_IS_OK(status)) {
1047 printf("close failed in oplock_handler\n");
1048 smb_panic("close failed in oplock_handler");
1052 static void oplock_handler_ack_callback_smb2(struct smb2_request *req)
1055 struct smb2_break br;
1057 status = smb2_break_recv(req, &br);
1058 if (!NT_STATUS_IS_OK(status)) {
1059 printf("oplock break ack failed in oplock_handler\n");
1060 smb_panic("oplock break ack failed in oplock_handler");
1064 static bool send_oplock_ack_smb2(struct smb2_tree *tree, struct smb2_handle handle,
1067 struct smb2_break br;
1068 struct smb2_request *req;
1071 br.in.file.handle = handle;
1072 br.in.oplock_level = level;
1073 br.in.reserved = gen_reserved8();
1074 br.in.reserved2 = gen_reserved32();
1076 req = smb2_break_send(tree, &br);
1077 if (req == NULL) return false;
1078 req->async.fn = oplock_handler_ack_callback_smb2;
1079 req->async.private_data = NULL;
1084 the oplock handler will either ack the break or close the file
1086 static bool oplock_handler_smb2(struct smb2_transport *transport, const struct smb2_handle *handle,
1087 uint8_t level, void *private_data)
1089 struct smb2_close io;
1092 struct smb2_tree *tree = NULL;
1093 struct smb2_request *req;
1095 srandom(current_op.seed);
1096 do_close = gen_chance(50);
1098 i = ((uintptr_t)private_data) >> 8;
1099 j = ((uintptr_t)private_data) & 0xFF;
1101 if (i >= NSERVERS || j >= NINSTANCES) {
1102 printf("Bad private_data in oplock_handler\n");
1106 oplocks[i][j].got_break = true;
1107 oplocks[i][j].smb2_handle = *handle;
1108 oplocks[i][j].handle = fnum_to_handle_smb2(i, j, *handle);
1109 oplocks[i][j].level = level;
1110 oplocks[i][j].do_close = do_close;
1111 tree = talloc_get_type(servers[i].smb2_tree[j], struct smb2_tree);
1114 printf("Oplock break not for one of our trees!?\n");
1119 printf("oplock ack handle=%d\n", oplocks[i][j].handle);
1120 return send_oplock_ack_smb2(tree, *handle, level);
1123 printf("oplock close fnum=%d\n", oplocks[i][j].handle);
1126 io.in.file.handle = *handle;
1128 req = smb2_close_send(tree, &io);
1131 printf("WARNING: close failed in oplock_handler_close\n");
1135 req->async.fn = oplock_handler_close_recv_smb2;
1136 req->async.private_data = NULL;
1143 the idle function tries to cope with getting an oplock break on a connection, and
1144 an operation on another connection blocking until that break is acked
1145 we check for operations on all transports in the idle function
1147 static void idle_func_smb2(struct smb2_transport *transport, void *private)
1150 for (i=0;i<NSERVERS;i++) {
1151 for (j=0;j<NINSTANCES;j++) {
1152 if (servers[i].smb2_tree[j] &&
1153 transport != servers[i].smb2_tree[j]->session->transport) {
1154 // smb2_transport_process(servers[i].smb2_tree[j]->session->transport);
1163 compare NTSTATUS, using checking ignored patterns
1165 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
1167 if (NT_STATUS_EQUAL(status1, status2)) return true;
1169 /* one code being an error and the other OK is always an error */
1170 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) {
1171 current_op.mismatch = nt_errstr(status1);
1175 /* if we are ignoring one of the status codes then consider this a match */
1176 if (ignore_pattern(nt_errstr(status1)) ||
1177 ignore_pattern(nt_errstr(status2))) {
1180 current_op.mismatch = nt_errstr(status1);
1185 check for pending packets on all connections
1187 static void check_pending(void)
1193 for (j=0;j<NINSTANCES;j++) {
1194 for (i=0;i<NSERVERS;i++) {
1195 // smb2_transport_process(servers[i].smb2_tree[j]->session->transport);
1201 check that the same oplock breaks have been received by all instances
1203 static bool check_oplocks(const char *call)
1208 if (!options.use_oplocks || options.smb2) {
1209 /* no smb2 oplocks in gentest yet */
1216 for (j=0;j<NINSTANCES;j++) {
1217 for (i=1;i<NSERVERS;i++) {
1218 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
1219 oplocks[0][j].handle != oplocks[i][j].handle ||
1220 oplocks[0][j].level != oplocks[i][j].level) {
1221 if (tries++ < 10) goto again;
1222 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
1223 oplocks[0][j].got_break,
1224 oplocks[0][j].handle,
1225 oplocks[0][j].level,
1226 oplocks[i][j].got_break,
1227 oplocks[i][j].handle,
1228 oplocks[i][j].level);
1229 current_op.mismatch = "oplock break";
1235 /* if we got a break and closed then remove the handle */
1236 for (j=0;j<NINSTANCES;j++) {
1237 if (oplocks[0][j].got_break &&
1238 oplocks[0][j].do_close) {
1239 uint16_t fnums[NSERVERS];
1240 for (i=0;i<NSERVERS;i++) {
1241 fnums[i] = oplocks[i][j].smb_handle;
1243 gen_remove_handle_smb(j, fnums);
1252 check that the same change notify info has been received by all instances
1254 static bool check_notifies(const char *call)
1260 /* no smb2 notifies in gentest yet */
1267 for (j=0;j<NINSTANCES;j++) {
1268 for (i=1;i<NSERVERS;i++) {
1270 union smb_notify not1, not2;
1272 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
1273 if (tries++ < 10) goto again;
1274 printf("Notify count inconsistent %d %d\n",
1275 notifies[0][j].notify_count,
1276 notifies[i][j].notify_count);
1277 current_op.mismatch = "notify count";
1281 if (notifies[0][j].notify_count == 0) continue;
1283 if (!NT_STATUS_EQUAL(notifies[0][j].status,
1284 notifies[i][j].status)) {
1285 printf("Notify status mismatch - %s - %s\n",
1286 nt_errstr(notifies[0][j].status),
1287 nt_errstr(notifies[i][j].status));
1288 current_op.mismatch = "Notify status";
1292 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
1296 not1 = notifies[0][j].notify;
1297 not2 = notifies[i][j].notify;
1299 for (n=0;n<not1.nttrans.out.num_changes;n++) {
1300 if (not1.nttrans.out.changes[n].action !=
1301 not2.nttrans.out.changes[n].action) {
1302 printf("Notify action %d inconsistent %d %d\n", n,
1303 not1.nttrans.out.changes[n].action,
1304 not2.nttrans.out.changes[n].action);
1305 current_op.mismatch = "notify action";
1308 if (strcmp(not1.nttrans.out.changes[n].name.s,
1309 not2.nttrans.out.changes[n].name.s)) {
1310 printf("Notify name %d inconsistent %s %s\n", n,
1311 not1.nttrans.out.changes[n].name.s,
1312 not2.nttrans.out.changes[n].name.s);
1313 current_op.mismatch = "notify name";
1316 if (not1.nttrans.out.changes[n].name.private_length !=
1317 not2.nttrans.out.changes[n].name.private_length) {
1318 printf("Notify name length %d inconsistent %d %d\n", n,
1319 not1.nttrans.out.changes[n].name.private_length,
1320 not2.nttrans.out.changes[n].name.private_length);
1321 current_op.mismatch = "notify name length";
1328 ZERO_STRUCT(notifies);
1333 #define GEN_COPY_PARM do { \
1335 for (i=1;i<NSERVERS;i++) { \
1336 parm[i] = parm[0]; \
1340 #define GEN_CALL(call, treetype, treefield) do { \
1342 ZERO_STRUCT(oplocks); \
1343 ZERO_STRUCT(notifies); \
1344 for (i=0;i<NSERVERS;i++) { \
1345 struct treetype *tree = servers[i].treefield[instance]; \
1348 current_op.status = status[0]; \
1349 for (i=1;i<NSERVERS;i++) { \
1350 if (!compare_status(status[i], status[0])) { \
1351 printf("status different in %s - %s %s\n", #call, \
1352 nt_errstr(status[0]), nt_errstr(status[i])); \
1353 current_op.mismatch = nt_errstr(status[0]); \
1357 if (!check_oplocks(#call)) return false; \
1358 if (!check_notifies(#call)) return false; \
1359 if (!NT_STATUS_IS_OK(status[0])) { \
1364 #define GEN_CALL_SMB(call) GEN_CALL(call, smbcli_tree, smb_tree)
1365 #define GEN_CALL_SMB2(call) GEN_CALL(call, smb2_tree, smb2_tree)
1367 #define ADD_HANDLE_SMB2(name, field) do { \
1368 struct smb2_handle handles[NSERVERS]; \
1370 for (i=0;i<NSERVERS;i++) { \
1371 handles[i] = parm[i].field; \
1373 gen_add_handle_smb2(instance, name, handles); \
1376 #define REMOVE_HANDLE_SMB2(field) do { \
1377 struct smb2_handle handles[NSERVERS]; \
1379 for (i=0;i<NSERVERS;i++) { \
1380 handles[i] = parm[i].field; \
1382 gen_remove_handle_smb2(instance, handles); \
1385 #define ADD_HANDLE_SMB(name, field) do { \
1386 uint16_t handles[NSERVERS]; \
1388 for (i=0;i<NSERVERS;i++) { \
1389 handles[i] = parm[i].field; \
1391 gen_add_handle_smb(instance, name, handles); \
1394 #define REMOVE_HANDLE_SMB(field) do { \
1395 uint16_t handles[NSERVERS]; \
1397 for (i=0;i<NSERVERS;i++) { \
1398 handles[i] = parm[i].field; \
1400 gen_remove_handle_smb(instance, handles); \
1403 #define GEN_SET_FNUM_SMB2(field) do { \
1405 for (i=0;i<NSERVERS;i++) { \
1406 parm[i].field = gen_lookup_handle_smb2(i, parm[i].field.data[0]); \
1410 #define GEN_SET_FNUM_SMB(field) do { \
1412 for (i=0;i<NSERVERS;i++) { \
1413 parm[i].field = gen_lookup_handle_smb(i, parm[i].field); \
1417 #define CHECK_EQUAL(field) do { \
1418 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1419 current_op.mismatch = #field; \
1420 printf("Mismatch in %s - 0x%llx 0x%llx\n", #field, \
1421 (unsigned long long)parm[0].field, (unsigned long long)parm[1].field); \
1426 #define CHECK_SECDESC(field) do { \
1427 if (!security_acl_equal(parm[0].field->dacl, parm[1].field->dacl) && !ignore_pattern(#field)) { \
1428 current_op.mismatch = #field; \
1429 printf("Mismatch in %s\n", #field); \
1434 #define CHECK_ATTRIB(field) do { \
1435 if (!options.mask_indexing) { \
1436 CHECK_EQUAL(field); \
1437 } else if ((~FILE_ATTRIBUTE_NONINDEXED & parm[0].field) != (~FILE_ATTRIBUTE_NONINDEXED & parm[1].field) && !ignore_pattern(#field)) { \
1438 current_op.mismatch = #field; \
1439 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1440 (int)parm[0].field, (int)parm[1].field); \
1445 #define CHECK_WSTR_EQUAL(field) do { \
1446 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1447 current_op.mismatch = #field; \
1448 printf("%s is NULL!\n", #field); \
1451 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1452 current_op.mismatch = #field; \
1453 printf("Mismatch in %s - %s %s\n", #field, \
1454 parm[0].field.s, parm[1].field.s); \
1457 CHECK_EQUAL(field.private_length); \
1460 #define CHECK_BLOB_EQUAL(field) do { \
1461 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1462 current_op.mismatch = #field; \
1463 printf("Mismatch in %s\n", #field); \
1466 CHECK_EQUAL(field.length); \
1469 #define CHECK_TIMES_EQUAL(field) do { \
1470 if (labs(parm[0].field - parm[1].field) > time_skew() && \
1471 !ignore_pattern(#field)) { \
1472 current_op.mismatch = #field; \
1473 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1474 (int)parm[0].field, (int)parm[1].field); \
1479 #define CHECK_NTTIMES_EQUAL(field) do { \
1480 if (labs(nt_time_to_unix(parm[0].field) - \
1481 nt_time_to_unix(parm[1].field)) > time_skew() && \
1482 !ignore_pattern(#field)) { \
1483 current_op.mismatch = #field; \
1484 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1485 (int)nt_time_to_unix(parm[0].field), \
1486 (int)nt_time_to_unix(parm[1].field)); \
1493 compare returned fileinfo structures
1495 static bool cmp_fileinfo(int instance,
1496 union smb_fileinfo parm[NSERVERS],
1497 NTSTATUS status[NSERVERS])
1500 enum smb_fileinfo_level level = parm[0].generic.level;
1502 if (level == RAW_FILEINFO_ALL_INFORMATION &&
1504 level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
1508 case RAW_FILEINFO_GENERIC:
1511 case RAW_FILEINFO_GETATTR:
1512 CHECK_ATTRIB(getattr.out.attrib);
1513 CHECK_EQUAL(getattr.out.size);
1514 CHECK_TIMES_EQUAL(getattr.out.write_time);
1517 case RAW_FILEINFO_GETATTRE:
1518 CHECK_TIMES_EQUAL(getattre.out.create_time);
1519 CHECK_TIMES_EQUAL(getattre.out.access_time);
1520 CHECK_TIMES_EQUAL(getattre.out.write_time);
1521 CHECK_EQUAL(getattre.out.size);
1522 CHECK_EQUAL(getattre.out.alloc_size);
1523 CHECK_ATTRIB(getattre.out.attrib);
1526 case RAW_FILEINFO_STANDARD:
1527 CHECK_TIMES_EQUAL(standard.out.create_time);
1528 CHECK_TIMES_EQUAL(standard.out.access_time);
1529 CHECK_TIMES_EQUAL(standard.out.write_time);
1530 CHECK_EQUAL(standard.out.size);
1531 CHECK_EQUAL(standard.out.alloc_size);
1532 CHECK_ATTRIB(standard.out.attrib);
1535 case RAW_FILEINFO_EA_SIZE:
1536 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1537 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1538 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1539 CHECK_EQUAL(ea_size.out.size);
1540 CHECK_EQUAL(ea_size.out.alloc_size);
1541 CHECK_ATTRIB(ea_size.out.attrib);
1542 CHECK_EQUAL(ea_size.out.ea_size);
1545 case RAW_FILEINFO_ALL_EAS:
1546 CHECK_EQUAL(all_eas.out.num_eas);
1547 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1548 CHECK_EQUAL(all_eas.out.eas[i].flags);
1549 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1550 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1554 case RAW_FILEINFO_IS_NAME_VALID:
1557 case RAW_FILEINFO_BASIC_INFO:
1558 case RAW_FILEINFO_BASIC_INFORMATION:
1559 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1560 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1561 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1562 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1563 CHECK_ATTRIB(basic_info.out.attrib);
1566 case RAW_FILEINFO_STANDARD_INFO:
1567 case RAW_FILEINFO_STANDARD_INFORMATION:
1568 CHECK_EQUAL(standard_info.out.alloc_size);
1569 CHECK_EQUAL(standard_info.out.size);
1570 CHECK_EQUAL(standard_info.out.nlink);
1571 CHECK_EQUAL(standard_info.out.delete_pending);
1572 CHECK_EQUAL(standard_info.out.directory);
1575 case RAW_FILEINFO_EA_INFO:
1576 case RAW_FILEINFO_EA_INFORMATION:
1577 CHECK_EQUAL(ea_info.out.ea_size);
1580 case RAW_FILEINFO_NAME_INFO:
1581 case RAW_FILEINFO_NAME_INFORMATION:
1582 CHECK_WSTR_EQUAL(name_info.out.fname);
1585 case RAW_FILEINFO_ALL_INFO:
1586 case RAW_FILEINFO_ALL_INFORMATION:
1587 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1588 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1589 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1590 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1591 CHECK_ATTRIB(all_info.out.attrib);
1592 CHECK_EQUAL(all_info.out.alloc_size);
1593 CHECK_EQUAL(all_info.out.size);
1594 CHECK_EQUAL(all_info.out.nlink);
1595 CHECK_EQUAL(all_info.out.delete_pending);
1596 CHECK_EQUAL(all_info.out.directory);
1597 CHECK_EQUAL(all_info.out.ea_size);
1598 CHECK_WSTR_EQUAL(all_info.out.fname);
1601 case RAW_FILEINFO_ALT_NAME_INFO:
1602 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1603 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1606 case RAW_FILEINFO_STREAM_INFO:
1607 case RAW_FILEINFO_STREAM_INFORMATION:
1608 CHECK_EQUAL(stream_info.out.num_streams);
1609 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1610 CHECK_EQUAL(stream_info.out.streams[i].size);
1611 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1612 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1616 case RAW_FILEINFO_COMPRESSION_INFO:
1617 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1618 CHECK_EQUAL(compression_info.out.compressed_size);
1619 CHECK_EQUAL(compression_info.out.format);
1620 CHECK_EQUAL(compression_info.out.unit_shift);
1621 CHECK_EQUAL(compression_info.out.chunk_shift);
1622 CHECK_EQUAL(compression_info.out.cluster_shift);
1625 case RAW_FILEINFO_INTERNAL_INFORMATION:
1626 CHECK_EQUAL(internal_information.out.file_id);
1629 case RAW_FILEINFO_ACCESS_INFORMATION:
1630 CHECK_EQUAL(access_information.out.access_flags);
1633 case RAW_FILEINFO_POSITION_INFORMATION:
1634 CHECK_EQUAL(position_information.out.position);
1637 case RAW_FILEINFO_MODE_INFORMATION:
1638 CHECK_EQUAL(mode_information.out.mode);
1641 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1642 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1645 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1646 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1647 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1648 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1649 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1650 CHECK_EQUAL(network_open_information.out.alloc_size);
1651 CHECK_EQUAL(network_open_information.out.size);
1652 CHECK_ATTRIB(network_open_information.out.attrib);
1655 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1656 CHECK_ATTRIB(attribute_tag_information.out.attrib);
1657 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1660 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1661 CHECK_NTTIMES_EQUAL(all_info2.out.create_time);
1662 CHECK_NTTIMES_EQUAL(all_info2.out.access_time);
1663 CHECK_NTTIMES_EQUAL(all_info2.out.write_time);
1664 CHECK_NTTIMES_EQUAL(all_info2.out.change_time);
1665 CHECK_ATTRIB(all_info2.out.attrib);
1666 CHECK_EQUAL(all_info2.out.unknown1);
1667 CHECK_EQUAL(all_info2.out.alloc_size);
1668 CHECK_EQUAL(all_info2.out.size);
1669 CHECK_EQUAL(all_info2.out.nlink);
1670 CHECK_EQUAL(all_info2.out.delete_pending);
1671 CHECK_EQUAL(all_info2.out.directory);
1672 CHECK_EQUAL(all_info2.out.file_id);
1673 CHECK_EQUAL(all_info2.out.ea_size);
1674 CHECK_EQUAL(all_info2.out.access_mask);
1675 CHECK_EQUAL(all_info2.out.position);
1676 CHECK_EQUAL(all_info2.out.mode);
1677 CHECK_EQUAL(all_info2.out.alignment_requirement);
1678 CHECK_WSTR_EQUAL(all_info2.out.fname);
1681 case RAW_FILEINFO_SMB2_ALL_EAS:
1682 CHECK_EQUAL(all_eas.out.num_eas);
1683 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1684 CHECK_EQUAL(all_eas.out.eas[i].flags);
1685 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1686 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1690 case RAW_FILEINFO_SEC_DESC:
1691 CHECK_SECDESC(query_secdesc.out.sd);
1694 /* Unhandled levels */
1695 case RAW_FILEINFO_EA_LIST:
1696 case RAW_FILEINFO_UNIX_BASIC:
1697 case RAW_FILEINFO_UNIX_LINK:
1698 case RAW_FILEINFO_UNIX_INFO2:
1708 generate openx operations
1710 static bool handler_smb_openx(int instance)
1712 union smb_open parm[NSERVERS];
1713 NTSTATUS status[NSERVERS];
1715 parm[0].openx.level = RAW_OPEN_OPENX;
1716 parm[0].openx.in.flags = gen_openx_flags();
1717 parm[0].openx.in.open_mode = gen_openx_mode();
1718 parm[0].openx.in.search_attrs = gen_attrib();
1719 parm[0].openx.in.file_attrs = gen_attrib();
1720 parm[0].openx.in.write_time = gen_timet();
1721 parm[0].openx.in.open_func = gen_openx_func();
1722 parm[0].openx.in.size = gen_io_count();
1723 parm[0].openx.in.timeout = gen_timeout();
1724 parm[0].openx.in.fname = gen_fname_open(instance);
1726 if (!options.use_oplocks) {
1727 /* mask out oplocks */
1728 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1729 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1733 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1735 CHECK_ATTRIB(openx.out.attrib);
1736 CHECK_EQUAL(openx.out.size);
1737 CHECK_EQUAL(openx.out.access);
1738 CHECK_EQUAL(openx.out.ftype);
1739 CHECK_EQUAL(openx.out.devstate);
1740 CHECK_EQUAL(openx.out.action);
1741 CHECK_EQUAL(openx.out.access_mask);
1742 CHECK_EQUAL(openx.out.unknown);
1743 CHECK_TIMES_EQUAL(openx.out.write_time);
1745 /* open creates a new file handle */
1746 ADD_HANDLE_SMB(parm[0].openx.in.fname, openx.out.file.fnum);
1753 generate open operations
1755 static bool handler_smb_open(int instance)
1757 union smb_open parm[NSERVERS];
1758 NTSTATUS status[NSERVERS];
1760 parm[0].openold.level = RAW_OPEN_OPEN;
1761 parm[0].openold.in.open_mode = gen_bits_mask2(0xF, 0xFFFF);
1762 parm[0].openold.in.search_attrs = gen_attrib();
1763 parm[0].openold.in.fname = gen_fname_open(instance);
1765 if (!options.use_oplocks) {
1766 /* mask out oplocks */
1767 parm[0].openold.in.open_mode &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1768 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1772 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1774 CHECK_ATTRIB(openold.out.attrib);
1775 CHECK_TIMES_EQUAL(openold.out.write_time);
1776 CHECK_EQUAL(openold.out.size);
1777 CHECK_EQUAL(openold.out.rmode);
1779 /* open creates a new file handle */
1780 ADD_HANDLE_SMB(parm[0].openold.in.fname, openold.out.file.fnum);
1787 generate ntcreatex operations
1789 static bool handler_smb_ntcreatex(int instance)
1791 union smb_open parm[NSERVERS];
1792 NTSTATUS status[NSERVERS];
1794 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1795 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1796 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1797 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1798 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1799 parm[0].ntcreatex.in.file_attr = gen_attrib();
1800 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1801 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1802 parm[0].ntcreatex.in.create_options = gen_create_options();
1803 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1804 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1805 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1807 if (!options.use_oplocks) {
1808 /* mask out oplocks */
1809 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1810 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1814 if (parm[0].ntcreatex.in.root_fid != 0) {
1815 GEN_SET_FNUM_SMB(ntcreatex.in.root_fid);
1817 GEN_CALL_SMB(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1819 CHECK_EQUAL(ntcreatex.out.oplock_level);
1820 CHECK_EQUAL(ntcreatex.out.create_action);
1821 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1822 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1823 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1824 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1825 CHECK_ATTRIB(ntcreatex.out.attrib);
1826 CHECK_EQUAL(ntcreatex.out.alloc_size);
1827 CHECK_EQUAL(ntcreatex.out.size);
1828 CHECK_EQUAL(ntcreatex.out.file_type);
1829 CHECK_EQUAL(ntcreatex.out.ipc_state);
1830 CHECK_EQUAL(ntcreatex.out.is_directory);
1832 /* ntcreatex creates a new file handle */
1833 ADD_HANDLE_SMB(parm[0].ntcreatex.in.fname, ntcreatex.out.file.fnum);
1839 generate close operations
1841 static bool handler_smb_close(int instance)
1843 union smb_close parm[NSERVERS];
1844 NTSTATUS status[NSERVERS];
1846 parm[0].close.level = RAW_CLOSE_CLOSE;
1847 parm[0].close.in.file.fnum = gen_fnum_close(instance);
1848 parm[0].close.in.write_time = gen_timet();
1851 GEN_SET_FNUM_SMB(close.in.file.fnum);
1852 GEN_CALL_SMB(smb_raw_close(tree, &parm[i]));
1854 REMOVE_HANDLE_SMB(close.in.file.fnum);
1860 generate unlink operations
1862 static bool handler_smb_unlink(int instance)
1864 union smb_unlink parm[NSERVERS];
1865 NTSTATUS status[NSERVERS];
1867 parm[0].unlink.in.pattern = gen_pattern();
1868 parm[0].unlink.in.attrib = gen_attrib();
1871 GEN_CALL_SMB(smb_raw_unlink(tree, &parm[i]));
1877 generate chkpath operations
1879 static bool handler_smb_chkpath(int instance)
1881 union smb_chkpath parm[NSERVERS];
1882 NTSTATUS status[NSERVERS];
1884 parm[0].chkpath.in.path = gen_fname_open(instance);
1887 GEN_CALL_SMB(smb_raw_chkpath(tree, &parm[i]));
1893 generate mkdir operations
1895 static bool handler_smb_mkdir(int instance)
1897 union smb_mkdir parm[NSERVERS];
1898 NTSTATUS status[NSERVERS];
1900 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1901 parm[0].mkdir.in.path = gen_fname_open(instance);
1904 GEN_CALL_SMB(smb_raw_mkdir(tree, &parm[i]));
1910 generate rmdir operations
1912 static bool handler_smb_rmdir(int instance)
1914 struct smb_rmdir parm[NSERVERS];
1915 NTSTATUS status[NSERVERS];
1917 parm[0].in.path = gen_fname_open(instance);
1920 GEN_CALL_SMB(smb_raw_rmdir(tree, &parm[i]));
1926 generate rename operations
1928 static bool handler_smb_rename(int instance)
1930 union smb_rename parm[NSERVERS];
1931 NTSTATUS status[NSERVERS];
1933 parm[0].generic.level = RAW_RENAME_RENAME;
1934 parm[0].rename.in.pattern1 = gen_pattern();
1935 parm[0].rename.in.pattern2 = gen_pattern();
1936 parm[0].rename.in.attrib = gen_attrib();
1939 GEN_CALL_SMB(smb_raw_rename(tree, &parm[i]));
1945 generate ntrename operations
1947 static bool handler_smb_ntrename(int instance)
1949 union smb_rename parm[NSERVERS];
1950 NTSTATUS status[NSERVERS];
1952 parm[0].generic.level = RAW_RENAME_NTRENAME;
1953 parm[0].ntrename.in.old_name = gen_fname();
1954 parm[0].ntrename.in.new_name = gen_fname();
1955 parm[0].ntrename.in.attrib = gen_attrib();
1956 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1957 parm[0].ntrename.in.flags = gen_rename_flags();
1960 GEN_CALL_SMB(smb_raw_rename(tree, &parm[i]));
1967 generate seek operations
1969 static bool handler_smb_seek(int instance)
1971 union smb_seek parm[NSERVERS];
1972 NTSTATUS status[NSERVERS];
1974 parm[0].lseek.in.file.fnum = gen_fnum(instance);
1975 parm[0].lseek.in.mode = gen_bits_mask2(0x3, 0xFFFF);
1976 parm[0].lseek.in.offset = gen_offset();
1979 GEN_SET_FNUM_SMB(lseek.in.file.fnum);
1980 GEN_CALL_SMB(smb_raw_seek(tree, &parm[i]));
1982 CHECK_EQUAL(lseek.out.offset);
1989 generate readx operations
1991 static bool handler_smb_readx(int instance)
1993 union smb_read parm[NSERVERS];
1994 NTSTATUS status[NSERVERS];
1996 parm[0].readx.level = RAW_READ_READX;
1997 parm[0].readx.in.file.fnum = gen_fnum(instance);
1998 parm[0].readx.in.offset = gen_offset();
1999 parm[0].readx.in.mincnt = gen_io_count();
2000 parm[0].readx.in.maxcnt = gen_io_count();
2001 parm[0].readx.in.remaining = gen_io_count();
2002 parm[0].readx.in.read_for_execute = gen_bool();
2003 parm[0].readx.out.data = talloc_array(current_op.mem_ctx, uint8_t,
2004 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
2007 GEN_SET_FNUM_SMB(readx.in.file.fnum);
2008 GEN_CALL_SMB(smb_raw_read(tree, &parm[i]));
2010 CHECK_EQUAL(readx.out.remaining);
2011 CHECK_EQUAL(readx.out.compaction_mode);
2012 CHECK_EQUAL(readx.out.nread);
2018 generate writex operations
2020 static bool handler_smb_writex(int instance)
2022 union smb_write parm[NSERVERS];
2023 NTSTATUS status[NSERVERS];
2025 parm[0].writex.level = RAW_WRITE_WRITEX;
2026 parm[0].writex.in.file.fnum = gen_fnum(instance);
2027 parm[0].writex.in.offset = gen_offset();
2028 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
2029 parm[0].writex.in.remaining = gen_io_count();
2030 parm[0].writex.in.count = gen_io_count();
2031 parm[0].writex.in.data = talloc_zero_array(current_op.mem_ctx, uint8_t, parm[0].writex.in.count);
2034 GEN_SET_FNUM_SMB(writex.in.file.fnum);
2035 GEN_CALL_SMB(smb_raw_write(tree, &parm[i]));
2037 CHECK_EQUAL(writex.out.nwritten);
2038 CHECK_EQUAL(writex.out.remaining);
2044 generate lockingx operations
2046 static bool handler_smb_lockingx(int instance)
2048 union smb_lock parm[NSERVERS];
2049 NTSTATUS status[NSERVERS];
2052 parm[0].lockx.level = RAW_LOCK_LOCKX;
2053 parm[0].lockx.in.file.fnum = gen_fnum(instance);
2054 parm[0].lockx.in.mode = gen_lock_mode();
2055 parm[0].lockx.in.timeout = gen_timeout();
2057 /* make sure we don't accidentially generate an oplock
2058 break ack - otherwise the server can just block forever */
2059 parm[0].lockx.in.ulock_cnt = gen_lock_count();
2060 parm[0].lockx.in.lock_cnt = gen_lock_count();
2061 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
2062 } while (nlocks == 0);
2065 parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx,
2066 struct smb_lock_entry,
2068 for (n=0;n<nlocks;n++) {
2069 parm[0].lockx.in.locks[n].pid = gen_pid();
2070 parm[0].lockx.in.locks[n].offset = gen_offset();
2071 parm[0].lockx.in.locks[n].count = gen_io_count();
2076 GEN_SET_FNUM_SMB(lockx.in.file.fnum);
2077 GEN_CALL_SMB(smb_raw_lock(tree, &parm[i]));
2084 generate a fileinfo query structure
2086 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
2090 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
2092 enum smb_setfileinfo_level level;
2096 /* disabled until win2003 can handle them ... */
2097 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
2098 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
2100 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
2101 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2102 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
2103 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2104 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
2107 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2108 } while (ignore_pattern(levels[i].name));
2110 info->generic.level = levels[i].level;
2112 switch (info->generic.level) {
2113 case RAW_SFILEINFO_SETATTR:
2114 info->setattr.in.attrib = gen_attrib();
2115 info->setattr.in.write_time = gen_timet();
2117 case RAW_SFILEINFO_SETATTRE:
2118 info->setattre.in.create_time = gen_timet();
2119 info->setattre.in.access_time = gen_timet();
2120 info->setattre.in.write_time = gen_timet();
2122 case RAW_SFILEINFO_STANDARD:
2123 info->standard.in.create_time = gen_timet();
2124 info->standard.in.access_time = gen_timet();
2125 info->standard.in.write_time = gen_timet();
2127 case RAW_SFILEINFO_EA_SET: {
2128 static struct ea_struct ea;
2129 info->ea_set.in.num_eas = 1;
2130 info->ea_set.in.eas = &ea;
2131 info->ea_set.in.eas[0] = gen_ea_struct();
2134 case RAW_SFILEINFO_BASIC_INFO:
2135 case RAW_SFILEINFO_BASIC_INFORMATION:
2136 info->basic_info.in.create_time = gen_nttime();
2137 info->basic_info.in.access_time = gen_nttime();
2138 info->basic_info.in.write_time = gen_nttime();
2139 info->basic_info.in.change_time = gen_nttime();
2140 info->basic_info.in.attrib = gen_attrib();
2142 case RAW_SFILEINFO_DISPOSITION_INFO:
2143 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
2144 info->disposition_info.in.delete_on_close = gen_bool();
2146 case RAW_SFILEINFO_ALLOCATION_INFO:
2147 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
2148 info->allocation_info.in.alloc_size = gen_alloc_size();
2150 case RAW_SFILEINFO_END_OF_FILE_INFO:
2151 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
2152 info->end_of_file_info.in.size = gen_offset();
2154 case RAW_SFILEINFO_RENAME_INFORMATION:
2155 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
2156 info->rename_information.in.overwrite = gen_bool();
2157 info->rename_information.in.root_fid = gen_root_fid(instance);
2158 info->rename_information.in.new_name = gen_fname_open(instance);
2160 case RAW_SFILEINFO_POSITION_INFORMATION:
2161 info->position_information.in.position = gen_offset();
2163 case RAW_SFILEINFO_MODE_INFORMATION:
2164 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
2166 case RAW_SFILEINFO_GENERIC:
2167 case RAW_SFILEINFO_SEC_DESC:
2168 case RAW_SFILEINFO_UNIX_BASIC:
2169 case RAW_SFILEINFO_UNIX_LINK:
2170 case RAW_SFILEINFO_UNIX_HLINK:
2171 case RAW_SFILEINFO_1023:
2172 case RAW_SFILEINFO_1025:
2173 case RAW_SFILEINFO_1029:
2174 case RAW_SFILEINFO_1032:
2175 case RAW_SFILEINFO_1039:
2176 case RAW_SFILEINFO_1040:
2177 case RAW_SFILEINFO_UNIX_INFO2:
2185 generate a fileinfo query structure
2187 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
2191 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
2193 enum smb_setfileinfo_level level;
2196 struct levels smb_levels[] = {
2197 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
2198 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
2199 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
2200 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2201 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
2202 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2203 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040),
2205 struct levels smb2_levels[] = {
2206 LVL(BASIC_INFORMATION),
2207 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
2208 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
2209 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
2210 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
2212 struct levels *levels = options.smb2?smb2_levels:smb_levels;
2213 uint32_t num_levels = options.smb2?ARRAY_SIZE(smb2_levels):ARRAY_SIZE(smb_levels);
2216 i = gen_int_range(0, num_levels-1);
2217 } while (ignore_pattern(levels[i].name));
2219 info->generic.level = levels[i].level;
2221 switch (info->generic.level) {
2222 case RAW_SFILEINFO_SETATTR:
2223 info->setattr.in.attrib = gen_attrib();
2224 info->setattr.in.write_time = gen_timet();
2226 case RAW_SFILEINFO_SETATTRE:
2227 info->setattre.in.create_time = gen_timet();
2228 info->setattre.in.access_time = gen_timet();
2229 info->setattre.in.write_time = gen_timet();
2231 case RAW_SFILEINFO_STANDARD:
2232 info->standard.in.create_time = gen_timet();
2233 info->standard.in.access_time = gen_timet();
2234 info->standard.in.write_time = gen_timet();
2236 case RAW_SFILEINFO_EA_SET: {
2237 static struct ea_struct ea;
2238 info->ea_set.in.num_eas = 1;
2239 info->ea_set.in.eas = &ea;
2240 info->ea_set.in.eas[0] = gen_ea_struct();
2243 case RAW_SFILEINFO_BASIC_INFO:
2244 case RAW_SFILEINFO_BASIC_INFORMATION:
2245 info->basic_info.in.create_time = gen_nttime();
2246 info->basic_info.in.access_time = gen_nttime();
2247 info->basic_info.in.write_time = gen_nttime();
2248 info->basic_info.in.change_time = gen_nttime();
2249 info->basic_info.in.attrib = gen_attrib();
2251 case RAW_SFILEINFO_DISPOSITION_INFO:
2252 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
2253 info->disposition_info.in.delete_on_close = gen_bool();
2255 case RAW_SFILEINFO_ALLOCATION_INFO:
2256 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
2257 info->allocation_info.in.alloc_size = gen_alloc_size();
2259 case RAW_SFILEINFO_END_OF_FILE_INFO:
2260 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
2261 info->end_of_file_info.in.size = gen_offset();
2263 case RAW_SFILEINFO_RENAME_INFORMATION:
2264 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
2265 info->rename_information.in.overwrite = gen_bool();
2266 info->rename_information.in.root_fid = gen_root_fid(instance);
2267 info->rename_information.in.new_name = gen_fname_open(instance);
2269 case RAW_SFILEINFO_POSITION_INFORMATION:
2270 info->position_information.in.position = gen_offset();
2272 case RAW_SFILEINFO_MODE_INFORMATION:
2273 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
2276 case RAW_SFILEINFO_GENERIC:
2277 case RAW_SFILEINFO_SEC_DESC:
2278 case RAW_SFILEINFO_1023:
2279 case RAW_SFILEINFO_1025:
2280 case RAW_SFILEINFO_1029:
2281 case RAW_SFILEINFO_1032:
2282 case RAW_SFILEINFO_1039:
2283 case RAW_SFILEINFO_1040:
2284 case RAW_SFILEINFO_UNIX_BASIC:
2285 case RAW_SFILEINFO_UNIX_INFO2:
2286 case RAW_SFILEINFO_UNIX_LINK:
2287 case RAW_SFILEINFO_UNIX_HLINK:
2296 generate a fileinfo query structure
2298 static void gen_fileinfo_smb(int instance, union smb_fileinfo *info)
2302 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
2304 enum smb_fileinfo_level level;
2307 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
2308 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
2309 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
2310 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
2311 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
2312 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
2313 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
2314 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
2315 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
2316 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
2319 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2320 } while (ignore_pattern(levels[i].name));
2322 info->generic.level = levels[i].level;
2326 generate qpathinfo operations
2328 static bool handler_smb_qpathinfo(int instance)
2330 union smb_fileinfo parm[NSERVERS];
2331 NTSTATUS status[NSERVERS];
2333 parm[0].generic.in.file.path = gen_fname_open(instance);
2335 gen_fileinfo_smb(instance, &parm[0]);
2338 GEN_CALL_SMB(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
2340 return cmp_fileinfo(instance, parm, status);
2344 generate qfileinfo operations
2346 static bool handler_smb_qfileinfo(int instance)
2348 union smb_fileinfo parm[NSERVERS];
2349 NTSTATUS status[NSERVERS];
2351 parm[0].generic.in.file.fnum = gen_fnum(instance);
2353 gen_fileinfo_smb(instance, &parm[0]);
2356 GEN_SET_FNUM_SMB(generic.in.file.fnum);
2357 GEN_CALL_SMB(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
2359 return cmp_fileinfo(instance, parm, status);
2364 generate setpathinfo operations
2366 static bool handler_smb_spathinfo(int instance)
2368 union smb_setfileinfo parm[NSERVERS];
2369 NTSTATUS status[NSERVERS];
2371 parm[0].generic.in.file.path = gen_fname_open(instance);
2373 gen_setfileinfo(instance, &parm[0]);
2377 /* a special case for the fid in a RENAME */
2378 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
2379 parm[0].rename_information.in.root_fid != 0) {
2380 GEN_SET_FNUM_SMB(rename_information.in.root_fid);
2383 GEN_CALL_SMB(smb_raw_setpathinfo(tree, &parm[i]));
2390 generate setfileinfo operations
2392 static bool handler_smb_sfileinfo(int instance)
2394 union smb_setfileinfo parm[NSERVERS];
2395 NTSTATUS status[NSERVERS];
2397 parm[0].generic.in.file.fnum = gen_fnum(instance);
2399 gen_setfileinfo(instance, &parm[0]);
2402 GEN_SET_FNUM_SMB(generic.in.file.fnum);
2403 GEN_CALL_SMB(smb_raw_setfileinfo(tree, &parm[i]));
2410 this is called when a change notify reply comes in
2412 static void async_notify_smb(struct smbcli_request *req)
2414 union smb_notify notify;
2418 struct smbcli_transport *transport = req->transport;
2420 tid = SVAL(req->in.hdr, HDR_TID);
2422 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
2423 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
2424 if (NT_STATUS_IS_OK(status) && notify.nttrans.out.num_changes > 0) {
2425 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
2427 notify.nttrans.out.num_changes,
2428 notify.nttrans.out.changes[0].action,
2429 notify.nttrans.out.changes[0].name.s);
2432 for (i=0;i<NSERVERS;i++) {
2433 for (j=0;j<NINSTANCES;j++) {
2434 if (transport == servers[i].smb_tree[j]->session->transport &&
2435 tid == servers[i].smb_tree[j]->tid) {
2436 notifies[i][j].notify_count++;
2437 notifies[i][j].status = status;
2438 notifies[i][j].notify = notify;
2445 generate change notify operations
2447 static bool handler_smb_notify(int instance)
2449 union smb_notify parm[NSERVERS];
2452 ZERO_STRUCT(parm[0]);
2453 parm[0].nttrans.level = RAW_NOTIFY_NTTRANS;
2454 parm[0].nttrans.in.buffer_size = gen_io_count();
2455 parm[0].nttrans.in.completion_filter = gen_bits_mask(0xFF);
2456 parm[0].nttrans.in.file.fnum = gen_fnum(instance);
2457 parm[0].nttrans.in.recursive = gen_bool();
2460 GEN_SET_FNUM_SMB(nttrans.in.file.fnum);
2462 for (n=0;n<NSERVERS;n++) {
2463 struct smbcli_request *req;
2464 req = smb_raw_changenotify_send(servers[n].smb_tree[instance], &parm[n]);
2465 req->async.fn = async_notify_smb;
2473 generate ntcreatex operations
2475 static bool handler_smb2_create(int instance)
2477 struct smb2_create parm[NSERVERS];
2478 NTSTATUS status[NSERVERS];
2480 ZERO_STRUCT(parm[0]);
2481 parm[0].in.security_flags = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFF);
2482 parm[0].in.oplock_level = gen_bits_levels(3, 90, 0x0, 70, 0x9, 100, 0xFF);
2483 parm[0].in.impersonation_level = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFFFFFFFF);
2484 parm[0].in.create_flags = gen_reserved64();
2485 parm[0].in.reserved = gen_reserved64();
2486 parm[0].in.desired_access = gen_access_mask();
2487 parm[0].in.file_attributes = gen_attrib();
2488 parm[0].in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
2489 parm[0].in.create_disposition = gen_open_disp();
2490 parm[0].in.create_options = gen_create_options();
2491 parm[0].in.fname = gen_fname_open(instance);
2492 parm[0].in.eas = gen_ea_list();
2493 parm[0].in.alloc_size = gen_alloc_size();
2494 parm[0].in.durable_open = gen_bool();
2495 parm[0].in.query_maximal_access = gen_bool();
2496 parm[0].in.timewarp = gen_timewarp();
2497 parm[0].in.query_on_disk_id = gen_bool();
2498 parm[0].in.sec_desc = gen_sec_desc();
2500 if (!options.use_oplocks) {
2501 /* mask out oplocks */
2502 parm[0].in.oplock_level = 0;
2505 if (options.valid) {
2506 parm[0].in.security_flags &= 3;
2507 parm[0].in.oplock_level &= 9;
2508 parm[0].in.impersonation_level &= 3;
2512 GEN_CALL_SMB2(smb2_create(tree, current_op.mem_ctx, &parm[i]));
2514 CHECK_EQUAL(out.oplock_level);
2515 CHECK_EQUAL(out.reserved);
2516 CHECK_EQUAL(out.create_action);
2517 CHECK_NTTIMES_EQUAL(out.create_time);
2518 CHECK_NTTIMES_EQUAL(out.access_time);
2519 CHECK_NTTIMES_EQUAL(out.write_time);
2520 CHECK_NTTIMES_EQUAL(out.change_time);
2521 CHECK_EQUAL(out.alloc_size);
2522 CHECK_EQUAL(out.size);
2523 CHECK_ATTRIB(out.file_attr);
2524 CHECK_EQUAL(out.reserved2);
2525 CHECK_EQUAL(out.maximal_access);
2527 /* ntcreatex creates a new file handle */
2528 ADD_HANDLE_SMB2(parm[0].in.fname, out.file.handle);
2534 generate close operations
2536 static bool handler_smb2_close(int instance)
2538 struct smb2_close parm[NSERVERS];
2539 NTSTATUS status[NSERVERS];
2541 ZERO_STRUCT(parm[0]);
2542 parm[0].in.file.handle.data[0] = gen_fnum_close(instance);
2543 parm[0].in.flags = gen_bits_mask2(0x1, 0xFFFF);
2546 GEN_SET_FNUM_SMB2(in.file.handle);
2547 GEN_CALL_SMB2(smb2_close(tree, &parm[i]));
2549 CHECK_EQUAL(out.flags);
2550 CHECK_EQUAL(out._pad);
2551 CHECK_NTTIMES_EQUAL(out.create_time);
2552 CHECK_NTTIMES_EQUAL(out.access_time);
2553 CHECK_NTTIMES_EQUAL(out.write_time);
2554 CHECK_NTTIMES_EQUAL(out.change_time);
2555 CHECK_EQUAL(out.alloc_size);
2556 CHECK_EQUAL(out.size);
2557 CHECK_ATTRIB(out.file_attr);
2559 REMOVE_HANDLE_SMB2(in.file.handle);
2565 generate read operations
2567 static bool handler_smb2_read(int instance)
2569 struct smb2_read parm[NSERVERS];
2570 NTSTATUS status[NSERVERS];
2572 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2573 parm[0].in.reserved = gen_reserved8();
2574 parm[0].in.length = gen_io_count();
2575 parm[0].in.offset = gen_offset();
2576 parm[0].in.min_count = gen_io_count();
2577 parm[0].in.channel = gen_bits_mask2(0x0, 0xFFFFFFFF);
2578 parm[0].in.remaining = gen_bits_mask2(0x0, 0xFFFFFFFF);
2579 parm[0].in.channel_offset = gen_bits_mask2(0x0, 0xFFFF);
2580 parm[0].in.channel_length = gen_bits_mask2(0x0, 0xFFFF);
2583 GEN_SET_FNUM_SMB2(in.file.handle);
2584 GEN_CALL_SMB2(smb2_read(tree, current_op.mem_ctx, &parm[i]));
2586 CHECK_EQUAL(out.remaining);
2587 CHECK_EQUAL(out.reserved);
2588 CHECK_EQUAL(out.data.length);
2594 generate write operations
2596 static bool handler_smb2_write(int instance)
2598 struct smb2_write parm[NSERVERS];
2599 NTSTATUS status[NSERVERS];
2601 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2602 parm[0].in.offset = gen_offset();
2603 parm[0].in.unknown1 = gen_bits_mask2(0, 0xFFFFFFFF);
2604 parm[0].in.unknown2 = gen_bits_mask2(0, 0xFFFFFFFF);
2605 parm[0].in.data = data_blob_talloc(current_op.mem_ctx, NULL,
2609 GEN_SET_FNUM_SMB2(in.file.handle);
2610 GEN_CALL_SMB2(smb2_write(tree, &parm[i]));
2612 CHECK_EQUAL(out._pad);
2613 CHECK_EQUAL(out.nwritten);
2614 CHECK_EQUAL(out.unknown1);
2620 generate lockingx operations
2622 static bool handler_smb2_lock(int instance)
2624 struct smb2_lock parm[NSERVERS];
2625 NTSTATUS status[NSERVERS];
2628 parm[0].level = RAW_LOCK_LOCKX;
2629 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2630 parm[0].in.lock_count = gen_lock_count();
2631 parm[0].in.reserved = gen_reserved32();
2633 parm[0].in.locks = talloc_array(current_op.mem_ctx,
2634 struct smb2_lock_element,
2635 parm[0].in.lock_count);
2636 for (n=0;n<parm[0].in.lock_count;n++) {
2637 parm[0].in.locks[n].offset = gen_offset();
2638 parm[0].in.locks[n].length = gen_io_count();
2639 /* don't yet cope with async replies */
2640 parm[0].in.locks[n].flags = gen_lock_flags_smb2() |
2641 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY;
2642 parm[0].in.locks[n].reserved = gen_bits_mask2(0x0, 0xFFFFFFFF);
2646 GEN_SET_FNUM_SMB2(in.file.handle);
2647 GEN_CALL_SMB2(smb2_lock(tree, &parm[i]));
2653 generate flush operations
2655 static bool handler_smb2_flush(int instance)
2657 struct smb2_flush parm[NSERVERS];
2658 NTSTATUS status[NSERVERS];
2660 ZERO_STRUCT(parm[0]);
2661 parm[0].in.file.handle.data[0] = gen_fnum(instance);
2662 parm[0].in.reserved1 = gen_reserved16();
2663 parm[0].in.reserved2 = gen_reserved32();
2666 GEN_SET_FNUM_SMB2(in.file.handle);
2667 GEN_CALL_SMB2(smb2_flush(tree, &parm[i]));
2669 CHECK_EQUAL(out.reserved);
2675 generate echo operations
2677 static bool handler_smb2_echo(int instance)
2679 NTSTATUS status[NSERVERS];
2681 GEN_CALL_SMB2(smb2_keepalive(tree->session->transport));
2689 generate a fileinfo query structure
2691 static void gen_fileinfo_smb2(int instance, union smb_fileinfo *info)
2694 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
2696 enum smb_fileinfo_level level;
2699 LVL(BASIC_INFORMATION),
2700 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
2701 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
2702 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(SMB2_ALL_INFORMATION),
2703 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
2704 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION),
2705 LVL(SMB2_ALL_EAS), LVL(SMB2_ALL_INFORMATION), LVL(SEC_DESC),
2708 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
2709 } while (ignore_pattern(levels[i].name));
2711 info->generic.level = levels[i].level;
2715 generate qfileinfo operations
2717 static bool handler_smb2_qfileinfo(int instance)
2719 union smb_fileinfo parm[NSERVERS];
2720 NTSTATUS status[NSERVERS];
2722 parm[0].generic.in.file.handle.data[0] = gen_fnum(instance);
2724 gen_fileinfo_smb2(instance, &parm[0]);
2727 GEN_SET_FNUM_SMB2(generic.in.file.handle);
2728 GEN_CALL_SMB2(smb2_getinfo_file(tree, current_op.mem_ctx, &parm[i]));
2730 return cmp_fileinfo(instance, parm, status);
2735 generate setfileinfo operations
2737 static bool handler_smb2_sfileinfo(int instance)
2739 union smb_setfileinfo parm[NSERVERS];
2740 NTSTATUS status[NSERVERS];
2742 parm[0].generic.in.file.fnum = gen_fnum(instance);
2744 gen_setfileinfo(instance, &parm[0]);
2747 GEN_SET_FNUM_SMB2(generic.in.file.handle);
2748 GEN_CALL_SMB2(smb2_setinfo_file(tree, &parm[i]));
2754 wipe any relevant files
2756 static void wipe_files(void)
2761 if (options.skip_cleanup) {
2765 for (i=0;i<NSERVERS;i++) {
2768 n = smb2_deltree(servers[i].smb2_tree[0], "gentest");
2770 n = smbcli_deltree(servers[i].smb_tree[0], "gentest");
2773 printf("Failed to wipe tree on server %d\n", i);
2777 status = smb2_util_mkdir(servers[i].smb2_tree[0], "gentest");
2779 status = smbcli_mkdir(servers[i].smb_tree[0], "gentest");
2781 if (NT_STATUS_IS_ERR(status)) {
2782 printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status));
2786 printf("Deleted %d files on server %d\n", n, i);
2792 dump the current seeds - useful for continuing a backtrack
2794 static void dump_seeds(void)
2799 if (!options.seeds_file) {
2802 f = fopen("seeds.tmp", "w");
2805 for (i=0;i<options.numops;i++) {
2806 fprintf(f, "%u\n", op_parms[i].seed);
2809 rename("seeds.tmp", options.seeds_file);
2815 the list of top-level operations that we will generate
2819 bool (*handler)(int instance);
2821 int count, success_count;
2823 {"CREATE", handler_smb2_create, true},
2824 {"CLOSE", handler_smb2_close, true},
2825 {"READ", handler_smb2_read, true},
2826 {"WRITE", handler_smb2_write, true},
2827 {"LOCK", handler_smb2_lock, true},
2828 {"FLUSH", handler_smb2_flush, true},
2829 {"ECHO", handler_smb2_echo, true},
2830 {"QFILEINFO", handler_smb2_qfileinfo, true},
2831 {"SFILEINFO", handler_smb2_sfileinfo, true},
2833 {"OPEN", handler_smb_open, false},
2834 {"OPENX", handler_smb_openx, false},
2835 {"NTCREATEX", handler_smb_ntcreatex, false},
2836 {"CLOSE", handler_smb_close, false},
2837 {"UNLINK", handler_smb_unlink, false},
2838 {"MKDIR", handler_smb_mkdir, false},
2839 {"RMDIR", handler_smb_rmdir, false},
2840 {"RENAME", handler_smb_rename, false},
2841 {"NTRENAME", handler_smb_ntrename, false},
2842 {"READX", handler_smb_readx, false},
2843 {"WRITEX", handler_smb_writex, false},
2844 {"CHKPATH", handler_smb_chkpath, false},
2845 {"SEEK", handler_smb_seek, false},
2846 {"LOCKINGX", handler_smb_lockingx, false},
2847 {"QPATHINFO", handler_smb_qpathinfo, false},
2848 {"QFILEINFO", handler_smb_qfileinfo, false},
2849 {"SPATHINFO", handler_smb_spathinfo, false},
2850 {"SFILEINFO", handler_smb_sfileinfo, false},
2851 {"NOTIFY", handler_smb_notify, false},
2852 {"SEEK", handler_smb_seek, false},
2857 run the test with the current set of op_parms parameters
2858 return the number of operations that completed successfully
2860 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
2864 if (!connect_servers(ev, lp_ctx)) {
2865 printf("Failed to connect to servers\n");
2871 /* wipe any leftover files from old runs */
2874 /* reset the open handles array */
2875 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
2876 num_open_handles = 0;
2878 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2879 gen_ops[i].count = 0;
2880 gen_ops[i].success_count = 0;
2883 for (op=0; op<options.numops; op++) {
2884 int instance, which_op;
2887 if (op_parms[op].disabled) continue;
2889 srandom(op_parms[op].seed);
2891 instance = gen_int_range(0, NINSTANCES-1);
2893 /* generate a non-ignored operation */
2895 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
2896 } while (ignore_pattern(gen_ops[which_op].name) ||
2897 gen_ops[which_op].smb2 != options.smb2);
2899 DEBUG(3,("Generating op %s on instance %d\n",
2900 gen_ops[which_op].name, instance));
2902 current_op.seed = op_parms[op].seed;
2903 current_op.opnum = op;
2904 current_op.name = gen_ops[which_op].name;
2905 current_op.status = NT_STATUS_OK;
2906 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
2908 ret = gen_ops[which_op].handler(instance);
2910 talloc_free(current_op.mem_ctx);
2912 gen_ops[which_op].count++;
2913 if (NT_STATUS_IS_OK(current_op.status)) {
2914 gen_ops[which_op].success_count++;
2918 printf("Failed at operation %d - %s\n",
2919 op, gen_ops[which_op].name);
2923 if (op % 100 == 0) {
2928 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
2929 printf("Op %-10s got %d/%d success\n",
2931 gen_ops[i].success_count,
2939 perform a backtracking analysis of the minimal set of operations
2940 to generate an error
2942 static void backtrack_analyze(struct event_context *ev,
2943 struct loadparm_context *lp_ctx)
2946 const char *mismatch = current_op.mismatch;
2948 chunk = options.numops / 2;
2953 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
2956 chunk = MIN(chunk, options.numops / 2);
2958 /* mark this range as disabled */
2959 max = MIN(options.numops, base+chunk);
2960 for (i=base;i<max; i++) {
2961 op_parms[i].disabled = true;
2963 printf("Testing %d ops with %d-%d disabled\n",
2964 options.numops, base, max-1);
2965 ret = run_test(ev, lp_ctx);
2966 printf("Completed %d of %d ops\n", ret, options.numops);
2967 for (i=base;i<max; i++) {
2968 op_parms[i].disabled = false;
2970 if (ret == options.numops) {
2971 /* this chunk is needed */
2973 } else if (mismatch != current_op.mismatch &&
2974 strcmp(mismatch, current_op.mismatch)) {
2976 printf("Different error in backtracking\n");
2977 } else if (ret < base) {
2978 printf("damn - inconsistent errors! found early error\n");
2979 options.numops = ret+1;
2982 /* it failed - this chunk isn't needed for a failure */
2983 memmove(&op_parms[base], &op_parms[max],
2984 sizeof(op_parms[0]) * (options.numops - max));
2985 options.numops = (ret+1) - (max - base);
2995 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2998 } while (chunk > 0);
3000 printf("Reduced to %d ops\n", options.numops);
3001 ret = run_test(ev, lp_ctx);
3002 if (ret != options.numops - 1) {
3003 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
3008 start the main gentest process
3010 static bool start_gentest(struct event_context *ev,
3011 struct loadparm_context *lp_ctx)
3016 /* allocate the open_handles array */
3017 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
3019 srandom(options.seed);
3020 op_parms = calloc(options.numops, sizeof(op_parms[0]));
3022 /* generate the seeds - after this everything is deterministic */
3023 if (options.use_preset_seeds) {
3025 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
3027 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
3030 if (numops < options.numops) {
3031 options.numops = numops;
3033 for (op=0;op<options.numops;op++) {
3035 printf("Not enough seeds in %s\n", options.seeds_file);
3038 op_parms[op].seed = atoi(preset[op]);
3040 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
3042 for (op=0; op<options.numops; op++) {
3043 op_parms[op].seed = random();
3047 ret = run_test(ev, lp_ctx);
3049 if (ret != options.numops && options.analyze) {
3050 options.numops = ret+1;
3051 backtrack_analyze(ev, lp_ctx);
3052 } else if (options.analyze_always) {
3053 backtrack_analyze(ev, lp_ctx);
3054 } else if (options.analyze_continuous) {
3055 while (run_test(ev, lp_ctx) == options.numops) ;
3058 return ret == options.numops;
3062 static void usage(poptContext pc)
3066 gentest //server1/share1 //server2/share2 [options..]\n\
3068 poptPrintUsage(pc, stdout, 0);
3072 split a UNC name into server and share names
3074 static bool split_unc_name(const char *unc, char **server, char **share)
3076 char *p = strdup(unc);
3077 if (!p) return false;
3078 all_string_sub(p, "\\", "/", 0);
3079 if (strncmp(p, "//", 2) != 0) return false;
3082 p = strchr(*server, '/');
3083 if (!p) return false;
3093 /****************************************************************************
3095 ****************************************************************************/
3096 int main(int argc, char *argv[])
3099 int i, username_count=0;
3101 char *ignore_file=NULL;
3102 struct event_context *ev;
3103 struct loadparm_context *lp_ctx;
3107 enum {OPT_UNCLIST=1000};
3108 struct poptOption long_options[] = {
3110 {"smb2", 0, POPT_ARG_NONE, &options.smb2, 0, "use SMB2 protocol", NULL},
3111 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
3112 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
3113 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
3114 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
3115 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
3116 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
3117 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
3118 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
3119 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
3120 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
3121 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
3122 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
3123 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
3124 {"maskindexing", 0, POPT_ARG_NONE, &options.mask_indexing, 0, "mask out the indexed file attrib", NULL},
3125 {"noeas", 0, POPT_ARG_NONE, &options.no_eas, 0, "don't use extended attributes", NULL},
3126 {"noacls", 0, POPT_ARG_NONE, &options.no_acls, 0, "don't use ACLs", NULL},
3127 {"skip-cleanup", 0, POPT_ARG_NONE, &options.skip_cleanup, 0, "don't delete files at start", NULL},
3128 {"valid", 0, POPT_ARG_NONE, &options.valid, 0, "generate only valid fields", NULL},
3130 POPT_COMMON_CONNECTION
3131 POPT_COMMON_CREDENTIALS
3136 memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
3139 options.seed = time(NULL);
3140 options.numops = 1000;
3141 options.max_open_handles = 20;
3142 options.seeds_file = "gentest_seeds.dat";
3144 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
3145 POPT_CONTEXT_KEEP_FIRST);
3147 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
3149 lp_ctx = cmdline_lp_ctx;
3150 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
3151 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
3152 cli_credentials_guess(servers[0].credentials, lp_ctx);
3153 cli_credentials_guess(servers[1].credentials, lp_ctx);
3155 while((opt = poptGetNextOpt(pc)) != -1) {
3158 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
3161 if (username_count == 2) {
3165 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
3172 options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
3175 argv_new = discard_const_p(char *, poptGetArgs(pc));
3177 for (i=0; i<argc; i++) {
3178 if (argv_new[i] == NULL) {
3184 if (!(argc_new >= 3)) {
3191 setup_logging("gentest", DEBUG_STDOUT);
3193 if (argc < 3 || argv[1][0] == '-') {
3198 setup_logging(argv[0], DEBUG_STDOUT);
3200 for (i=0;i<NSERVERS;i++) {
3201 const char *share = argv[1+i];
3202 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
3203 printf("Invalid share name '%s'\n", share);
3208 if (username_count == 0) {
3212 if (username_count == 1) {
3213 servers[1].credentials = servers[0].credentials;
3216 printf("seed=%u\n", options.seed);
3218 ev = event_context_init(talloc_autofree_context());
3220 gensec_init(lp_ctx);
3222 ret = start_gentest(ev, lp_ctx);
3225 printf("gentest completed - no errors\n");
3227 printf("gentest failed\n");