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"
41 #include "../libcli/smb/smbXcli_base.h"
47 static struct gentest_options
{
51 int analyze_continuous
;
52 unsigned int max_open_handles
;
56 char **ignore_patterns
;
57 const char *seeds_file
;
68 /* mapping between open handles on the server and local handles */
71 unsigned int instance
;
72 struct smb2_handle smb2_handle
[NSERVERS
]; /* SMB2 */
73 uint16_t smb_handle
[NSERVERS
]; /* SMB */
76 static unsigned int num_open_handles
;
78 /* state information for the servers. We open NINSTANCES connections to
81 struct smb2_tree
*smb2_tree
[NINSTANCES
];
82 struct smbcli_tree
*smb_tree
[NINSTANCES
];
85 struct cli_credentials
*credentials
;
88 /* the seeds and flags for each operation */
95 /* oplock break info */
98 struct smb2_handle smb2_handle
;
103 } oplocks
[NSERVERS
][NINSTANCES
];
105 /* change notify reply info */
109 union smb_notify notify
;
110 } notifies
[NSERVERS
][NINSTANCES
];
112 /* info relevant to the current operation */
119 const char *mismatch
;
122 static struct smb2_handle bad_smb2_handle
;
125 #define BAD_HANDLE 0xFFFE
127 static bool oplock_handler_smb2(struct smb2_transport
*transport
, const struct smb2_handle
*handle
,
128 uint8_t level
, void *private_data
);
129 static void idle_func_smb2(struct smb2_transport
*transport
, void *private_data
);
130 static bool oplock_handler_smb(struct smbcli_transport
*transport
, uint16_t tid
, uint16_t fnum
, uint8_t level
, void *private_data
);
131 static void idle_func_smb(struct smbcli_transport
*transport
, void *private_data
);
134 check if a string should be ignored. This is used as the basis
135 for all error ignore settings
137 static bool ignore_pattern(const char *str
)
140 if (!options
.ignore_patterns
) return false;
142 for (i
=0;options
.ignore_patterns
[i
];i
++) {
143 if (strcmp(options
.ignore_patterns
[i
], str
) == 0 ||
144 gen_fnmatch(options
.ignore_patterns
[i
], str
) == 0) {
145 DEBUG(2,("Ignoring '%s'\n", str
));
152 /*****************************************************
153 connect to the servers
154 *******************************************************/
155 static bool connect_servers_fast(void)
159 /* close all open files */
160 for (h
=0;h
<options
.max_open_handles
;h
++) {
161 if (!open_handles
[h
].active
) continue;
162 for (i
=0;i
<NSERVERS
;i
++) {
165 status
= smb2_util_close(servers
[i
].smb2_tree
[open_handles
[h
].instance
],
166 open_handles
[h
].smb2_handle
[i
]);
168 status
= smbcli_close(servers
[i
].smb_tree
[open_handles
[h
].instance
],
169 open_handles
[h
].smb_handle
[i
]);
171 if (NT_STATUS_IS_ERR(status
)) {
174 open_handles
[h
].active
= false;
184 /*****************************************************
185 connect to the servers
186 *******************************************************/
187 static bool connect_servers(struct tevent_context
*ev
,
188 struct loadparm_context
*lp_ctx
)
192 if (options
.fast_reconnect
&& servers
[0].smb2_tree
[0]) {
193 if (connect_servers_fast()) {
198 /* close any existing connections */
199 for (i
=0;i
<NSERVERS
;i
++) {
200 for (j
=0;j
<NINSTANCES
;j
++) {
201 if (servers
[i
].smb2_tree
[j
]) {
202 smb2_tdis(servers
[i
].smb2_tree
[j
]);
203 talloc_free(servers
[i
].smb2_tree
[j
]);
204 servers
[i
].smb2_tree
[j
] = NULL
;
206 if (servers
[i
].smb_tree
[j
]) {
207 smb_tree_disconnect(servers
[i
].smb_tree
[j
]);
208 talloc_free(servers
[i
].smb_tree
[j
]);
209 servers
[i
].smb_tree
[j
] = NULL
;
214 for (i
=0;i
<NSERVERS
;i
++) {
215 for (j
=0;j
<NINSTANCES
;j
++) {
217 struct smbcli_options smb_options
;
218 struct smbcli_session_options smb_session_options
;
219 lpcfg_smbcli_options(lp_ctx
, &smb_options
);
220 lpcfg_smbcli_session_options(lp_ctx
, &smb_session_options
);
222 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
223 servers
[i
].server_name
, servers
[i
].share_name
,
224 servers
[i
].credentials
->username
, j
);
226 cli_credentials_set_workstation(servers
[i
].credentials
,
227 "gentest", CRED_SPECIFIED
);
230 status
= smb2_connect(NULL
, servers
[i
].server_name
,
231 lpcfg_smb_ports(lp_ctx
),
232 servers
[i
].share_name
,
233 lpcfg_resolve_context(lp_ctx
),
234 servers
[i
].credentials
,
235 &servers
[i
].smb2_tree
[j
],
237 lpcfg_socket_options(lp_ctx
),
238 lpcfg_gensec_settings(lp_ctx
, lp_ctx
)
241 status
= smbcli_tree_full_connection(NULL
,
242 &servers
[i
].smb_tree
[j
],
243 servers
[i
].server_name
,
244 lpcfg_smb_ports(lp_ctx
),
245 servers
[i
].share_name
, "A:",
246 lpcfg_socket_options(lp_ctx
),
247 servers
[i
].credentials
,
248 lpcfg_resolve_context(lp_ctx
), ev
,
250 &smb_session_options
,
251 lpcfg_gensec_settings(lp_ctx
, lp_ctx
));
253 if (!NT_STATUS_IS_OK(status
)) {
254 printf("Failed to connect to \\\\%s\\%s - %s\n",
255 servers
[i
].server_name
, servers
[i
].share_name
,
261 servers
[i
].smb2_tree
[j
]->session
->transport
->oplock
.handler
= oplock_handler_smb2
;
262 servers
[i
].smb2_tree
[j
]->session
->transport
->oplock
.private_data
= (void *)(uintptr_t)((i
<<8)|j
);
263 smb2_transport_idle_handler(servers
[i
].smb2_tree
[j
]->session
->transport
,
264 idle_func_smb2
, 50000, NULL
);
266 smbcli_oplock_handler(servers
[i
].smb_tree
[j
]->session
->transport
, oplock_handler_smb
,
267 (void *)(uintptr_t)((i
<<8)|j
));
268 smbcli_transport_idle_handler(servers
[i
].smb_tree
[j
]->session
->transport
, idle_func_smb
,
269 50000, (void *)(uintptr_t)((i
<<8)|j
));
278 work out the time skew between the servers - be conservative
280 static unsigned int time_skew(void)
286 struct smbXcli_conn
*c0
, *c1
;
288 c0
= servers
[0].smb2_tree
[0]->session
->transport
->conn
;
289 c1
= servers
[1].smb2_tree
[0]->session
->transport
->conn
;
291 nt0
= smbXcli_conn_server_system_time(c0
);
292 nt1
= smbXcli_conn_server_system_time(c1
);
294 nt0
= servers
[0].smb_tree
[0]->session
->transport
->negotiate
.server_time
;
295 nt1
= servers
[1].smb_tree
[0]->session
->transport
->negotiate
.server_time
;
297 ret
= labs(nt0
- nt1
);
302 static bool smb2_handle_equal(const struct smb2_handle
*h1
, const struct smb2_handle
*h2
)
304 return memcmp(h1
, h2
, sizeof(struct smb2_handle
)) == 0;
308 turn a server handle into a local handle
310 static unsigned int fnum_to_handle_smb2(int server
, int instance
, struct smb2_handle server_handle
)
313 for (i
=0;i
<options
.max_open_handles
;i
++) {
314 if (!open_handles
[i
].active
||
315 instance
!= open_handles
[i
].instance
) continue;
316 if (smb2_handle_equal(&open_handles
[i
].smb2_handle
[server
], &server_handle
)) {
320 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
326 turn a server handle into a local handle
328 static unsigned int fnum_to_handle_smb(int server
, int instance
, uint16_t server_handle
)
331 for (i
=0;i
<options
.max_open_handles
;i
++) {
332 if (!open_handles
[i
].active
||
333 instance
!= open_handles
[i
].instance
) continue;
334 if (open_handles
[i
].smb_handle
[server
] == server_handle
) {
338 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
344 add some newly opened handles
346 static void gen_add_handle_smb2(int instance
, const char *name
, struct smb2_handle handles
[NSERVERS
])
349 for (h
=0;h
<options
.max_open_handles
;h
++) {
350 if (!open_handles
[h
].active
) break;
352 if (h
== options
.max_open_handles
) {
353 /* we have to force close a random handle */
354 h
= random() % options
.max_open_handles
;
355 for (i
=0;i
<NSERVERS
;i
++) {
357 status
= smb2_util_close(servers
[i
].smb2_tree
[open_handles
[h
].instance
],
358 open_handles
[h
].smb2_handle
[i
]);
359 if (NT_STATUS_IS_ERR(status
)) {
360 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
364 printf("Recovered handle %d\n", h
);
367 for (i
=0;i
<NSERVERS
;i
++) {
368 open_handles
[h
].smb2_handle
[i
] = handles
[i
];
369 open_handles
[h
].instance
= instance
;
370 open_handles
[h
].active
= true;
371 open_handles
[h
].name
= name
;
375 printf("OPEN num_open_handles=%d h=%d (%s)\n",
376 num_open_handles
, h
, name
);
380 add some newly opened handles
382 static void gen_add_handle_smb(int instance
, const char *name
, uint16_t handles
[NSERVERS
])
385 for (h
=0;h
<options
.max_open_handles
;h
++) {
386 if (!open_handles
[h
].active
) break;
388 if (h
== options
.max_open_handles
) {
389 /* we have to force close a random handle */
390 h
= random() % options
.max_open_handles
;
391 for (i
=0;i
<NSERVERS
;i
++) {
393 status
= smbcli_close(servers
[i
].smb_tree
[open_handles
[h
].instance
],
394 open_handles
[h
].smb_handle
[i
]);
395 if (NT_STATUS_IS_ERR(status
)) {
396 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
400 printf("Recovered handle %d\n", h
);
403 for (i
=0;i
<NSERVERS
;i
++) {
404 open_handles
[h
].smb_handle
[i
] = handles
[i
];
405 open_handles
[h
].instance
= instance
;
406 open_handles
[h
].active
= true;
407 open_handles
[h
].name
= name
;
411 printf("OPEN num_open_handles=%d h=%d (%s)\n",
412 num_open_handles
, h
, name
);
417 remove a closed handle
419 static void gen_remove_handle_smb2(int instance
, struct smb2_handle handles
[NSERVERS
])
422 for (h
=0;h
<options
.max_open_handles
;h
++) {
423 if (instance
== open_handles
[h
].instance
&&
424 smb2_handle_equal(&open_handles
[h
].smb2_handle
[0], &handles
[0])) {
425 open_handles
[h
].active
= false;
427 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
429 open_handles
[h
].name
);
433 printf("Removing invalid handle!?\n");
438 remove a closed handle
440 static void gen_remove_handle_smb(int instance
, uint16_t handles
[NSERVERS
])
443 for (h
=0;h
<options
.max_open_handles
;h
++) {
444 if (instance
== open_handles
[h
].instance
&&
445 open_handles
[h
].smb_handle
[0] == handles
[0]) {
446 open_handles
[h
].active
= false;
448 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
450 open_handles
[h
].name
);
454 printf("Removing invalid handle!?\n");
459 return true with 'chance' probability as a percentage
461 static bool gen_chance(unsigned int chance
)
463 return ((random() % 100) <= chance
);
467 map an internal handle number to a server handle
469 static struct smb2_handle
gen_lookup_handle_smb2(int server
, uint16_t handle
)
471 if (handle
== BAD_HANDLE
) return bad_smb2_handle
;
472 return open_handles
[handle
].smb2_handle
[server
];
476 map an internal handle number to a server handle
478 static uint16_t gen_lookup_handle_smb(int server
, uint16_t handle
)
480 if (handle
== BAD_HANDLE
) return BAD_HANDLE
;
481 return open_handles
[handle
].smb_handle
[server
];
487 static uint16_t gen_fnum(int instance
)
492 if (gen_chance(20)) return BAD_HANDLE
;
494 while (num_open_handles
> 0 && count
++ < 10*options
.max_open_handles
) {
495 h
= random() % options
.max_open_handles
;
496 if (open_handles
[h
].active
&&
497 open_handles
[h
].instance
== instance
) {
505 return a file handle, but skewed so we don't close the last
506 couple of handles too readily
508 static uint16_t gen_fnum_close(int instance
)
510 if (num_open_handles
< 5) {
511 if (gen_chance(90)) return BAD_HANDLE
;
514 return gen_fnum(instance
);
518 generate an integer in a specified range
520 static int gen_int_range(uint64_t min
, uint64_t max
)
522 unsigned int r
= random();
523 return min
+ (r
% (1+max
-min
));
527 return a fnum for use as a root fid
528 be careful to call GEN_SET_FNUM() when you use this!
530 static uint16_t gen_root_fid(int instance
)
532 if (gen_chance(5)) return gen_fnum(instance
);
537 generate a file offset
539 static int gen_offset(void)
541 if (gen_chance(20)) return 0;
542 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
543 return gen_int_range(0, 1024*1024);
549 static int gen_io_count(void)
551 if (gen_chance(20)) return 0;
552 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
553 return gen_int_range(0, 4096);
559 static const char *gen_fname(void)
561 const char *names
[] = {"gentest\\gentest.dat",
566 "gentest\\foo4:teststream1",
567 "gentest\\foo4:teststream2",
569 "gentest\\foo5.exe:teststream3",
570 "gentest\\foo5.exe:teststream4",
573 "gentest\\blah\\blergh.txt",
574 "gentest\\blah\\blergh2",
575 "gentest\\blah\\blergh3.txt",
576 "gentest\\blah\\blergh4",
577 "gentest\\blah\\blergh5.txt",
578 "gentest\\blah\\blergh5",
581 "gentest\\a_very_long_name.bin",
587 i
= gen_int_range(0, ARRAY_SIZE(names
)-1);
588 } while (ignore_pattern(names
[i
]));
594 generate a filename with a higher chance of choosing an already
597 static const char *gen_fname_open(int instance
)
600 h
= gen_fnum(instance
);
601 if (h
== BAD_HANDLE
) {
604 return open_handles
[h
].name
;
608 generate a wildcard pattern
610 static const char *gen_pattern(void)
613 const char *names
[] = {"gentest\\*.dat",
616 "gentest\\blah\\*.*",
620 if (gen_chance(50)) return gen_fname();
623 i
= gen_int_range(0, ARRAY_SIZE(names
)-1);
624 } while (ignore_pattern(names
[i
]));
629 static uint32_t gen_bits_levels(int nlevels
, ...)
635 va_start(ap
, nlevels
);
636 for (i
=0;i
<nlevels
;i
++) {
637 pct
= va_arg(ap
, uint32_t);
638 mask
= va_arg(ap
, uint32_t);
639 if (pct
== 100 || gen_chance(pct
)) {
641 return mask
& random();
651 static uint32_t gen_bits_mask(unsigned int mask
)
653 unsigned int ret
= random();
658 generate a bitmask with high probability of the first mask
659 and low of the second
661 static uint32_t gen_bits_mask2(uint32_t mask1
, uint32_t mask2
)
663 if (!options
.valid
&& gen_chance(10)) return gen_bits_mask(mask2
);
664 return gen_bits_mask(mask1
);
668 generate reserved values
670 static uint64_t gen_reserved8(void)
672 if (options
.valid
) return 0;
673 return gen_bits_mask(0xFF);
676 static uint64_t gen_reserved16(void)
678 if (options
.valid
) return 0;
679 return gen_bits_mask(0xFFFF);
682 static uint64_t gen_reserved32(void)
684 if (options
.valid
) return 0;
685 return gen_bits_mask(0xFFFFFFFF);
688 static uint64_t gen_reserved64(void)
690 if (options
.valid
) return 0;
691 return gen_bits_mask(0xFFFFFFFF) | (((uint64_t)gen_bits_mask(0xFFFFFFFF))<<32);
699 static bool gen_bool(void)
701 return gen_bits_mask2(0x1, 0xFF);
705 generate ntrename flags
707 static uint16_t gen_rename_flags(void)
709 if (gen_chance(30)) return RENAME_FLAG_RENAME
;
710 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK
;
711 if (gen_chance(30)) return RENAME_FLAG_COPY
;
712 return gen_bits_mask(0xFFFF);
718 static uint16_t gen_pid(void)
720 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
725 return a set of lock flags
727 static uint16_t gen_lock_flags_smb2(void)
729 if (!options
.valid
&& gen_chance(5)) return gen_bits_mask(0xFFFF);
730 if (gen_chance(20)) return gen_bits_mask(0x1F);
731 if (gen_chance(50)) return SMB2_LOCK_FLAG_UNLOCK
;
732 return gen_bits_mask(SMB2_LOCK_FLAG_SHARED
|
733 SMB2_LOCK_FLAG_EXCLUSIVE
|
734 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
);
738 generate a lock count
740 static off_t
gen_lock_count(void)
742 return gen_int_range(0, 3);
746 generate a NT access mask
748 static uint32_t gen_access_mask(void)
751 if (gen_chance(70)) return SEC_FLAG_MAXIMUM_ALLOWED
;
752 if (gen_chance(70)) return SEC_FILE_ALL
;
753 ret
= gen_bits_mask(0xFFFFFFFF);
754 if (options
.valid
) ret
&= ~SEC_MASK_INVALID
;
759 return a lockingx lock mode
761 static uint16_t gen_lock_mode(void)
763 if (!options
.valid
&& gen_chance(5)) return gen_bits_mask(0xFFFF);
764 if (gen_chance(20)) return gen_bits_mask(0x1F);
765 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK
| LOCKING_ANDX_LARGE_FILES
);
769 generate a ntcreatex flags field
771 static uint32_t gen_ntcreatex_flags(void)
773 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED
;
774 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
778 generate a ntcreatex create options bitfield
780 static uint32_t gen_create_options(void)
782 if (!options
.valid
&& gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
783 if (gen_chance(50)) return 0;
784 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE
| NTCREATEX_OPTIONS_DIRECTORY
);
788 generate a ntcreatex open disposition
790 static uint32_t gen_open_disp(void)
792 if (gen_chance(50)) return NTCREATEX_DISP_OPEN_IF
;
793 if (!options
.valid
&& gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
794 return gen_int_range(0, 5);
798 generate an openx open mode
800 static uint16_t gen_openx_mode(void)
802 if (!options
.valid
&& gen_chance(20)) return gen_bits_mask(0xFFFF);
803 if (gen_chance(20)) return gen_bits_mask(0xFF);
804 return OPENX_MODE_DENY_NONE
| gen_bits_mask(0x3);
808 generate an openx flags field
810 static uint16_t gen_openx_flags(void)
812 if (!options
.valid
&& gen_chance(20)) return gen_bits_mask(0xFFFF);
813 return gen_bits_mask(0x7);
817 generate an openx open function
819 static uint16_t gen_openx_func(void)
821 if (!options
.valid
&& gen_chance(20)) return gen_bits_mask(0xFFFF);
822 return gen_bits_mask(0x13);
826 generate a file attrib combination
828 static uint32_t gen_attrib(void)
831 if (gen_chance(20)) {
832 ret
= gen_bits_mask(0xFFFFFFFF);
833 if (options
.valid
) ret
&= FILE_ATTRIBUTE_ALL_MASK
;
836 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL
| FILE_ATTRIBUTE_DIRECTORY
);
840 generate a unix timestamp
842 static time_t gen_timet(void)
844 if (gen_chance(30)) return 0;
845 return (time_t)random();
849 generate a milliseconds protocol timeout
851 static uint32_t gen_timeout(void)
853 if (gen_chance(98)) return 0;
854 return random() % 50;
860 static NTTIME
gen_nttime(void)
863 unix_to_nt_time(&ret
, gen_timet());
868 generate a timewarp value
870 static NTTIME
gen_timewarp(void)
872 NTTIME ret
= gen_nttime();
873 if (gen_chance(98)) ret
= 0;
878 generate a file allocation size
880 static unsigned int gen_alloc_size(void)
884 if (gen_chance(30)) return 0;
886 ret
= random() % 4*1024*1024;
887 /* give a high chance of a round number */
888 if (gen_chance(60)) {
889 ret
&= ~(1024*1024 - 1);
895 generate an ea_struct
897 static struct ea_struct
gen_ea_struct(void)
900 const char *names
[] = {"EAONE",
905 "AVERYLONGATTRIBUTENAME"};
906 const char *values
[] = {"VALUE1",
911 "ASOMEWHATLONGERATTRIBUTEVALUE"};
917 i
= gen_int_range(0, ARRAY_SIZE(names
)-1);
918 } while (ignore_pattern(names
[i
]));
920 ea
.name
.s
= names
[i
];
923 i
= gen_int_range(0, ARRAY_SIZE(values
)-1);
924 } while (ignore_pattern(values
[i
]));
926 ea
.value
= data_blob(values
[i
], strlen(values
[i
]));
928 if (gen_chance(10)) ea
.flags
= gen_bits_mask(0xFF);
935 generate an ea_struct
937 static struct smb_ea_list
gen_ea_list(void)
939 struct smb_ea_list eas
;
941 if (options
.no_eas
) {
945 eas
.num_eas
= gen_int_range(0, 3);
946 eas
.eas
= talloc_array(current_op
.mem_ctx
, struct ea_struct
, eas
.num_eas
);
947 for (i
=0;i
<eas
.num_eas
;i
++) {
948 eas
.eas
[i
] = gen_ea_struct();
953 /* generate a security descriptor */
954 static struct security_descriptor
*gen_sec_desc(void)
956 struct security_descriptor
*sd
;
957 if (options
.no_acls
|| gen_chance(90)) return NULL
;
959 sd
= security_descriptor_dacl_create(current_op
.mem_ctx
,
962 SEC_ACE_TYPE_ACCESS_ALLOWED
,
963 SEC_FILE_WRITE_DATA
| SEC_STD_WRITE_DAC
,
964 SEC_ACE_FLAG_OBJECT_INHERIT
,
966 SEC_ACE_TYPE_ACCESS_ALLOWED
,
967 SEC_FILE_ALL
| SEC_STD_ALL
,
974 static void oplock_handler_close_recv_smb(struct smbcli_request
*req
)
977 status
= smbcli_request_simple_recv(req
);
978 if (!NT_STATUS_IS_OK(status
)) {
979 printf("close failed in oplock_handler\n");
980 smb_panic("close failed in oplock_handler");
985 the oplock handler will either ack the break or close the file
987 static bool oplock_handler_smb(struct smbcli_transport
*transport
, uint16_t tid
, uint16_t fnum
, uint8_t level
, void *private_data
)
992 struct smbcli_tree
*tree
= NULL
;
993 struct smbcli_request
*req
;
995 srandom(current_op
.seed
);
996 do_close
= gen_chance(50);
998 for (i
=0;i
<NSERVERS
;i
++) {
999 for (j
=0;j
<NINSTANCES
;j
++) {
1000 if (transport
== servers
[i
].smb_tree
[j
]->session
->transport
&&
1001 tid
== servers
[i
].smb_tree
[j
]->tid
) {
1002 oplocks
[i
][j
].got_break
= true;
1003 oplocks
[i
][j
].smb_handle
= fnum
;
1004 oplocks
[i
][j
].handle
= fnum_to_handle_smb(i
, j
, fnum
);
1005 oplocks
[i
][j
].level
= level
;
1006 oplocks
[i
][j
].do_close
= do_close
;
1007 tree
= servers
[i
].smb_tree
[j
];
1013 printf("Oplock break not for one of our trees!?\n");
1018 printf("oplock ack fnum=%d\n", fnum
);
1019 return smbcli_oplock_ack(tree
, fnum
, level
);
1022 printf("oplock close fnum=%d\n", fnum
);
1024 io
.close
.level
= RAW_CLOSE_CLOSE
;
1025 io
.close
.in
.file
.fnum
= fnum
;
1026 io
.close
.in
.write_time
= 0;
1027 req
= smb_raw_close_send(tree
, &io
);
1030 printf("WARNING: close failed in oplock_handler_close\n");
1034 req
->async
.fn
= oplock_handler_close_recv_smb
;
1035 req
->async
.private_data
= NULL
;
1042 the idle function tries to cope with getting an oplock break on a connection, and
1043 an operation on another connection blocking until that break is acked
1044 we check for operations on all transports in the idle function
1046 static void idle_func_smb(struct smbcli_transport
*transport
, void *private_data
)
1049 for (i
=0;i
<NSERVERS
;i
++) {
1050 for (j
=0;j
<NINSTANCES
;j
++) {
1051 if (servers
[i
].smb_tree
[j
] &&
1052 transport
!= servers
[i
].smb_tree
[j
]->session
->transport
) {
1053 smbcli_transport_process(servers
[i
].smb_tree
[j
]->session
->transport
);
1060 static void oplock_handler_close_recv_smb2(struct smb2_request
*req
)
1063 struct smb2_close io
;
1064 status
= smb2_close_recv(req
, &io
);
1065 if (!NT_STATUS_IS_OK(status
)) {
1066 printf("close failed in oplock_handler\n");
1067 smb_panic("close failed in oplock_handler");
1071 static void oplock_handler_ack_callback_smb2(struct smb2_request
*req
)
1074 struct smb2_break br
;
1076 status
= smb2_break_recv(req
, &br
);
1077 if (!NT_STATUS_IS_OK(status
)) {
1078 printf("oplock break ack failed in oplock_handler\n");
1079 smb_panic("oplock break ack failed in oplock_handler");
1083 static bool send_oplock_ack_smb2(struct smb2_tree
*tree
, struct smb2_handle handle
,
1086 struct smb2_break br
;
1087 struct smb2_request
*req
;
1090 br
.in
.file
.handle
= handle
;
1091 br
.in
.oplock_level
= level
;
1092 br
.in
.reserved
= gen_reserved8();
1093 br
.in
.reserved2
= gen_reserved32();
1095 req
= smb2_break_send(tree
, &br
);
1096 if (req
== NULL
) return false;
1097 req
->async
.fn
= oplock_handler_ack_callback_smb2
;
1098 req
->async
.private_data
= NULL
;
1103 the oplock handler will either ack the break or close the file
1105 static bool oplock_handler_smb2(struct smb2_transport
*transport
, const struct smb2_handle
*handle
,
1106 uint8_t level
, void *private_data
)
1108 struct smb2_close io
;
1111 struct smb2_tree
*tree
= NULL
;
1112 struct smb2_request
*req
;
1114 srandom(current_op
.seed
);
1115 do_close
= gen_chance(50);
1117 i
= ((uintptr_t)private_data
) >> 8;
1118 j
= ((uintptr_t)private_data
) & 0xFF;
1120 if (i
>= NSERVERS
|| j
>= NINSTANCES
) {
1121 printf("Bad private_data in oplock_handler\n");
1125 oplocks
[i
][j
].got_break
= true;
1126 oplocks
[i
][j
].smb2_handle
= *handle
;
1127 oplocks
[i
][j
].handle
= fnum_to_handle_smb2(i
, j
, *handle
);
1128 oplocks
[i
][j
].level
= level
;
1129 oplocks
[i
][j
].do_close
= do_close
;
1130 tree
= talloc_get_type(servers
[i
].smb2_tree
[j
], struct smb2_tree
);
1133 printf("Oplock break not for one of our trees!?\n");
1138 printf("oplock ack handle=%d\n", oplocks
[i
][j
].handle
);
1139 return send_oplock_ack_smb2(tree
, *handle
, level
);
1142 printf("oplock close fnum=%d\n", oplocks
[i
][j
].handle
);
1145 io
.in
.file
.handle
= *handle
;
1147 req
= smb2_close_send(tree
, &io
);
1150 printf("WARNING: close failed in oplock_handler_close\n");
1154 req
->async
.fn
= oplock_handler_close_recv_smb2
;
1155 req
->async
.private_data
= NULL
;
1162 the idle function tries to cope with getting an oplock break on a connection, and
1163 an operation on another connection blocking until that break is acked
1164 we check for operations on all transports in the idle function
1166 static void idle_func_smb2(struct smb2_transport
*transport
, void *private_data
)
1169 for (i
=0;i
<NSERVERS
;i
++) {
1170 for (j
=0;j
<NINSTANCES
;j
++) {
1171 if (servers
[i
].smb2_tree
[j
] &&
1172 transport
!= servers
[i
].smb2_tree
[j
]->session
->transport
) {
1173 // smb2_transport_process(servers[i].smb2_tree[j]->session->transport);
1182 compare NTSTATUS, using checking ignored patterns
1184 static bool compare_status(NTSTATUS status1
, NTSTATUS status2
)
1188 if (NT_STATUS_EQUAL(status1
, status2
)) return true;
1190 /* one code being an error and the other OK is always an error */
1191 if (NT_STATUS_IS_OK(status1
) || NT_STATUS_IS_OK(status2
)) {
1192 current_op
.mismatch
= nt_errstr(status1
);
1196 /* if we are ignoring one of the status codes then consider this a match */
1197 if (ignore_pattern(nt_errstr(status1
)) ||
1198 ignore_pattern(nt_errstr(status2
))) {
1202 /* also support ignore patterns of the form NT_STATUS_XX:NT_STATUS_YY
1203 meaning that the first server returns NT_STATUS_XX and the 2nd
1204 returns NT_STATUS_YY */
1205 s
= talloc_asprintf(current_op
.mem_ctx
, "%s:%s",
1207 nt_errstr(status2
));
1208 if (ignore_pattern(s
)) {
1212 current_op
.mismatch
= nt_errstr(status1
);
1217 check for pending packets on all connections
1219 static void check_pending(void)
1225 for (j
=0;j
<NINSTANCES
;j
++) {
1226 for (i
=0;i
<NSERVERS
;i
++) {
1227 // smb2_transport_process(servers[i].smb2_tree[j]->session->transport);
1233 check that the same oplock breaks have been received by all instances
1235 static bool check_oplocks(const char *call
)
1240 if (!options
.use_oplocks
|| options
.smb2
) {
1241 /* no smb2 oplocks in gentest yet */
1248 for (j
=0;j
<NINSTANCES
;j
++) {
1249 for (i
=1;i
<NSERVERS
;i
++) {
1250 if (oplocks
[0][j
].got_break
!= oplocks
[i
][j
].got_break
||
1251 oplocks
[0][j
].handle
!= oplocks
[i
][j
].handle
||
1252 oplocks
[0][j
].level
!= oplocks
[i
][j
].level
) {
1253 if (tries
++ < 10) goto again
;
1254 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
1255 oplocks
[0][j
].got_break
,
1256 oplocks
[0][j
].handle
,
1257 oplocks
[0][j
].level
,
1258 oplocks
[i
][j
].got_break
,
1259 oplocks
[i
][j
].handle
,
1260 oplocks
[i
][j
].level
);
1261 current_op
.mismatch
= "oplock break";
1267 /* if we got a break and closed then remove the handle */
1268 for (j
=0;j
<NINSTANCES
;j
++) {
1269 if (oplocks
[0][j
].got_break
&&
1270 oplocks
[0][j
].do_close
) {
1271 uint16_t fnums
[NSERVERS
];
1272 for (i
=0;i
<NSERVERS
;i
++) {
1273 fnums
[i
] = oplocks
[i
][j
].smb_handle
;
1275 gen_remove_handle_smb(j
, fnums
);
1284 check that the same change notify info has been received by all instances
1286 static bool check_notifies(const char *call
)
1292 /* no smb2 notifies in gentest yet */
1299 for (j
=0;j
<NINSTANCES
;j
++) {
1300 for (i
=1;i
<NSERVERS
;i
++) {
1302 union smb_notify not1
, not2
;
1304 if (notifies
[0][j
].notify_count
!= notifies
[i
][j
].notify_count
) {
1305 if (tries
++ < 10) goto again
;
1306 printf("Notify count inconsistent %d %d\n",
1307 notifies
[0][j
].notify_count
,
1308 notifies
[i
][j
].notify_count
);
1309 current_op
.mismatch
= "notify count";
1313 if (notifies
[0][j
].notify_count
== 0) continue;
1315 if (!NT_STATUS_EQUAL(notifies
[0][j
].status
,
1316 notifies
[i
][j
].status
)) {
1317 printf("Notify status mismatch - %s - %s\n",
1318 nt_errstr(notifies
[0][j
].status
),
1319 nt_errstr(notifies
[i
][j
].status
));
1320 current_op
.mismatch
= "Notify status";
1324 if (!NT_STATUS_IS_OK(notifies
[0][j
].status
)) {
1328 not1
= notifies
[0][j
].notify
;
1329 not2
= notifies
[i
][j
].notify
;
1331 for (n
=0;n
<not1
.nttrans
.out
.num_changes
;n
++) {
1332 if (not1
.nttrans
.out
.changes
[n
].action
!=
1333 not2
.nttrans
.out
.changes
[n
].action
) {
1334 printf("Notify action %d inconsistent %d %d\n", n
,
1335 not1
.nttrans
.out
.changes
[n
].action
,
1336 not2
.nttrans
.out
.changes
[n
].action
);
1337 current_op
.mismatch
= "notify action";
1340 if (strcmp(not1
.nttrans
.out
.changes
[n
].name
.s
,
1341 not2
.nttrans
.out
.changes
[n
].name
.s
)) {
1342 printf("Notify name %d inconsistent %s %s\n", n
,
1343 not1
.nttrans
.out
.changes
[n
].name
.s
,
1344 not2
.nttrans
.out
.changes
[n
].name
.s
);
1345 current_op
.mismatch
= "notify name";
1348 if (not1
.nttrans
.out
.changes
[n
].name
.private_length
!=
1349 not2
.nttrans
.out
.changes
[n
].name
.private_length
) {
1350 printf("Notify name length %d inconsistent %d %d\n", n
,
1351 not1
.nttrans
.out
.changes
[n
].name
.private_length
,
1352 not2
.nttrans
.out
.changes
[n
].name
.private_length
);
1353 current_op
.mismatch
= "notify name length";
1360 ZERO_STRUCT(notifies
);
1365 #define GEN_COPY_PARM do { \
1367 for (i=1;i<NSERVERS;i++) { \
1368 parm[i] = parm[0]; \
1372 #define GEN_CALL(call, treetype, treefield) do { \
1374 ZERO_STRUCT(oplocks); \
1375 ZERO_STRUCT(notifies); \
1376 for (i=0;i<NSERVERS;i++) { \
1377 struct treetype *tree = servers[i].treefield[instance]; \
1380 current_op.status = status[0]; \
1381 for (i=1;i<NSERVERS;i++) { \
1382 if (!compare_status(status[0], status[1])) { \
1383 printf("status different in %s - %s %s\n", #call, \
1384 nt_errstr(status[0]), nt_errstr(status[i])); \
1385 current_op.mismatch = nt_errstr(status[0]); \
1389 if (!check_oplocks(#call)) return false; \
1390 if (!check_notifies(#call)) return false; \
1391 if (!NT_STATUS_IS_OK(status[0])) { \
1396 #define GEN_CALL_SMB(call) GEN_CALL(call, smbcli_tree, smb_tree)
1397 #define GEN_CALL_SMB2(call) GEN_CALL(call, smb2_tree, smb2_tree)
1399 #define ADD_HANDLE_SMB2(name, field) do { \
1400 struct smb2_handle handles[NSERVERS]; \
1402 for (i=0;i<NSERVERS;i++) { \
1403 handles[i] = parm[i].field; \
1405 gen_add_handle_smb2(instance, name, handles); \
1408 #define REMOVE_HANDLE_SMB2(field) do { \
1409 struct smb2_handle handles[NSERVERS]; \
1411 for (i=0;i<NSERVERS;i++) { \
1412 handles[i] = parm[i].field; \
1414 gen_remove_handle_smb2(instance, handles); \
1417 #define ADD_HANDLE_SMB(name, field) do { \
1418 uint16_t handles[NSERVERS]; \
1420 for (i=0;i<NSERVERS;i++) { \
1421 handles[i] = parm[i].field; \
1423 gen_add_handle_smb(instance, name, handles); \
1426 #define REMOVE_HANDLE_SMB(field) do { \
1427 uint16_t handles[NSERVERS]; \
1429 for (i=0;i<NSERVERS;i++) { \
1430 handles[i] = parm[i].field; \
1432 gen_remove_handle_smb(instance, handles); \
1435 #define GEN_SET_FNUM_SMB2(field) do { \
1437 for (i=0;i<NSERVERS;i++) { \
1438 parm[i].field = gen_lookup_handle_smb2(i, parm[i].field.data[0]); \
1442 #define GEN_SET_FNUM_SMB(field) do { \
1444 for (i=0;i<NSERVERS;i++) { \
1445 parm[i].field = gen_lookup_handle_smb(i, parm[i].field); \
1449 #define CHECK_EQUAL(field) do { \
1450 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
1451 current_op.mismatch = #field; \
1452 printf("Mismatch in %s - 0x%llx 0x%llx\n", #field, \
1453 (unsigned long long)parm[0].field, (unsigned long long)parm[1].field); \
1458 #define CHECK_SECDESC(field) do { \
1459 if (!security_acl_equal(parm[0].field->dacl, parm[1].field->dacl) && !ignore_pattern(#field)) { \
1460 current_op.mismatch = #field; \
1461 printf("Mismatch in %s\n", #field); \
1466 #define CHECK_ATTRIB(field) do { \
1467 if (!options.mask_indexing) { \
1468 CHECK_EQUAL(field); \
1469 } else if ((~FILE_ATTRIBUTE_NONINDEXED & parm[0].field) != (~FILE_ATTRIBUTE_NONINDEXED & parm[1].field) && !ignore_pattern(#field)) { \
1470 current_op.mismatch = #field; \
1471 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1472 (int)parm[0].field, (int)parm[1].field); \
1477 #define CHECK_WSTR_EQUAL(field) do { \
1478 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
1479 current_op.mismatch = #field; \
1480 printf("%s is NULL!\n", #field); \
1483 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1484 current_op.mismatch = #field; \
1485 printf("Mismatch in %s - %s %s\n", #field, \
1486 parm[0].field.s, parm[1].field.s); \
1489 CHECK_EQUAL(field.private_length); \
1492 #define CHECK_BLOB_EQUAL(field) do { \
1493 if (((parm[0].field.data == NULL && parm[1].field.data != NULL) || \
1494 (parm[1].field.data == NULL && parm[0].field.data != NULL) || \
1495 (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0)) && !ignore_pattern(#field)) { \
1496 current_op.mismatch = #field; \
1497 printf("Mismatch in %s\n", #field); \
1500 CHECK_EQUAL(field.length); \
1503 #define CHECK_TIMES_EQUAL(field) do { \
1504 if (labs(parm[0].field - parm[1].field) > time_skew() && \
1505 !ignore_pattern(#field)) { \
1506 current_op.mismatch = #field; \
1507 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1508 (int)parm[0].field, (int)parm[1].field); \
1513 #define CHECK_NTTIMES_EQUAL(field) do { \
1514 if (labs(nt_time_to_unix(parm[0].field) - \
1515 nt_time_to_unix(parm[1].field)) > time_skew() && \
1516 !ignore_pattern(#field)) { \
1517 current_op.mismatch = #field; \
1518 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1519 (int)nt_time_to_unix(parm[0].field), \
1520 (int)nt_time_to_unix(parm[1].field)); \
1527 compare returned fileinfo structures
1529 static bool cmp_fileinfo(int instance
,
1530 union smb_fileinfo parm
[NSERVERS
],
1531 NTSTATUS status
[NSERVERS
])
1534 enum smb_fileinfo_level level
= parm
[0].generic
.level
;
1536 if (level
== RAW_FILEINFO_ALL_INFORMATION
&&
1538 level
= RAW_FILEINFO_SMB2_ALL_INFORMATION
;
1542 case RAW_FILEINFO_GENERIC
:
1545 case RAW_FILEINFO_GETATTR
:
1546 CHECK_ATTRIB(getattr
.out
.attrib
);
1547 CHECK_EQUAL(getattr
.out
.size
);
1548 CHECK_TIMES_EQUAL(getattr
.out
.write_time
);
1551 case RAW_FILEINFO_GETATTRE
:
1552 CHECK_TIMES_EQUAL(getattre
.out
.create_time
);
1553 CHECK_TIMES_EQUAL(getattre
.out
.access_time
);
1554 CHECK_TIMES_EQUAL(getattre
.out
.write_time
);
1555 CHECK_EQUAL(getattre
.out
.size
);
1556 CHECK_EQUAL(getattre
.out
.alloc_size
);
1557 CHECK_ATTRIB(getattre
.out
.attrib
);
1560 case RAW_FILEINFO_STANDARD
:
1561 CHECK_TIMES_EQUAL(standard
.out
.create_time
);
1562 CHECK_TIMES_EQUAL(standard
.out
.access_time
);
1563 CHECK_TIMES_EQUAL(standard
.out
.write_time
);
1564 CHECK_EQUAL(standard
.out
.size
);
1565 CHECK_EQUAL(standard
.out
.alloc_size
);
1566 CHECK_ATTRIB(standard
.out
.attrib
);
1569 case RAW_FILEINFO_EA_SIZE
:
1570 CHECK_TIMES_EQUAL(ea_size
.out
.create_time
);
1571 CHECK_TIMES_EQUAL(ea_size
.out
.access_time
);
1572 CHECK_TIMES_EQUAL(ea_size
.out
.write_time
);
1573 CHECK_EQUAL(ea_size
.out
.size
);
1574 CHECK_EQUAL(ea_size
.out
.alloc_size
);
1575 CHECK_ATTRIB(ea_size
.out
.attrib
);
1576 CHECK_EQUAL(ea_size
.out
.ea_size
);
1579 case RAW_FILEINFO_ALL_EAS
:
1580 CHECK_EQUAL(all_eas
.out
.num_eas
);
1581 for (i
=0;i
<parm
[0].all_eas
.out
.num_eas
;i
++) {
1582 CHECK_EQUAL(all_eas
.out
.eas
[i
].flags
);
1583 CHECK_WSTR_EQUAL(all_eas
.out
.eas
[i
].name
);
1584 CHECK_BLOB_EQUAL(all_eas
.out
.eas
[i
].value
);
1588 case RAW_FILEINFO_IS_NAME_VALID
:
1591 case RAW_FILEINFO_BASIC_INFO
:
1592 case RAW_FILEINFO_BASIC_INFORMATION
:
1593 CHECK_NTTIMES_EQUAL(basic_info
.out
.create_time
);
1594 CHECK_NTTIMES_EQUAL(basic_info
.out
.access_time
);
1595 CHECK_NTTIMES_EQUAL(basic_info
.out
.write_time
);
1596 CHECK_NTTIMES_EQUAL(basic_info
.out
.change_time
);
1597 CHECK_ATTRIB(basic_info
.out
.attrib
);
1600 case RAW_FILEINFO_STANDARD_INFO
:
1601 case RAW_FILEINFO_STANDARD_INFORMATION
:
1602 CHECK_EQUAL(standard_info
.out
.alloc_size
);
1603 CHECK_EQUAL(standard_info
.out
.size
);
1604 CHECK_EQUAL(standard_info
.out
.nlink
);
1605 CHECK_EQUAL(standard_info
.out
.delete_pending
);
1606 CHECK_EQUAL(standard_info
.out
.directory
);
1609 case RAW_FILEINFO_EA_INFO
:
1610 case RAW_FILEINFO_EA_INFORMATION
:
1611 CHECK_EQUAL(ea_info
.out
.ea_size
);
1614 case RAW_FILEINFO_NAME_INFO
:
1615 case RAW_FILEINFO_NAME_INFORMATION
:
1616 CHECK_WSTR_EQUAL(name_info
.out
.fname
);
1619 case RAW_FILEINFO_ALL_INFO
:
1620 case RAW_FILEINFO_ALL_INFORMATION
:
1621 CHECK_NTTIMES_EQUAL(all_info
.out
.create_time
);
1622 CHECK_NTTIMES_EQUAL(all_info
.out
.access_time
);
1623 CHECK_NTTIMES_EQUAL(all_info
.out
.write_time
);
1624 CHECK_NTTIMES_EQUAL(all_info
.out
.change_time
);
1625 CHECK_ATTRIB(all_info
.out
.attrib
);
1626 CHECK_EQUAL(all_info
.out
.alloc_size
);
1627 CHECK_EQUAL(all_info
.out
.size
);
1628 CHECK_EQUAL(all_info
.out
.nlink
);
1629 CHECK_EQUAL(all_info
.out
.delete_pending
);
1630 CHECK_EQUAL(all_info
.out
.directory
);
1631 CHECK_EQUAL(all_info
.out
.ea_size
);
1632 CHECK_WSTR_EQUAL(all_info
.out
.fname
);
1635 case RAW_FILEINFO_ALT_NAME_INFO
:
1636 case RAW_FILEINFO_ALT_NAME_INFORMATION
:
1637 CHECK_WSTR_EQUAL(alt_name_info
.out
.fname
);
1640 case RAW_FILEINFO_STREAM_INFO
:
1641 case RAW_FILEINFO_STREAM_INFORMATION
:
1642 CHECK_EQUAL(stream_info
.out
.num_streams
);
1643 for (i
=0;i
<parm
[0].stream_info
.out
.num_streams
;i
++) {
1644 CHECK_EQUAL(stream_info
.out
.streams
[i
].size
);
1645 CHECK_EQUAL(stream_info
.out
.streams
[i
].alloc_size
);
1646 CHECK_WSTR_EQUAL(stream_info
.out
.streams
[i
].stream_name
);
1650 case RAW_FILEINFO_COMPRESSION_INFO
:
1651 case RAW_FILEINFO_COMPRESSION_INFORMATION
:
1652 CHECK_EQUAL(compression_info
.out
.compressed_size
);
1653 CHECK_EQUAL(compression_info
.out
.format
);
1654 CHECK_EQUAL(compression_info
.out
.unit_shift
);
1655 CHECK_EQUAL(compression_info
.out
.chunk_shift
);
1656 CHECK_EQUAL(compression_info
.out
.cluster_shift
);
1659 case RAW_FILEINFO_INTERNAL_INFORMATION
:
1660 CHECK_EQUAL(internal_information
.out
.file_id
);
1663 case RAW_FILEINFO_ACCESS_INFORMATION
:
1664 CHECK_EQUAL(access_information
.out
.access_flags
);
1667 case RAW_FILEINFO_POSITION_INFORMATION
:
1668 CHECK_EQUAL(position_information
.out
.position
);
1671 case RAW_FILEINFO_MODE_INFORMATION
:
1672 CHECK_EQUAL(mode_information
.out
.mode
);
1675 case RAW_FILEINFO_ALIGNMENT_INFORMATION
:
1676 CHECK_EQUAL(alignment_information
.out
.alignment_requirement
);
1679 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION
:
1680 CHECK_NTTIMES_EQUAL(network_open_information
.out
.create_time
);
1681 CHECK_NTTIMES_EQUAL(network_open_information
.out
.access_time
);
1682 CHECK_NTTIMES_EQUAL(network_open_information
.out
.write_time
);
1683 CHECK_NTTIMES_EQUAL(network_open_information
.out
.change_time
);
1684 CHECK_EQUAL(network_open_information
.out
.alloc_size
);
1685 CHECK_EQUAL(network_open_information
.out
.size
);
1686 CHECK_ATTRIB(network_open_information
.out
.attrib
);
1689 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION
:
1690 CHECK_ATTRIB(attribute_tag_information
.out
.attrib
);
1691 CHECK_EQUAL(attribute_tag_information
.out
.reparse_tag
);
1694 case RAW_FILEINFO_SMB2_ALL_INFORMATION
:
1695 CHECK_NTTIMES_EQUAL(all_info2
.out
.create_time
);
1696 CHECK_NTTIMES_EQUAL(all_info2
.out
.access_time
);
1697 CHECK_NTTIMES_EQUAL(all_info2
.out
.write_time
);
1698 CHECK_NTTIMES_EQUAL(all_info2
.out
.change_time
);
1699 CHECK_ATTRIB(all_info2
.out
.attrib
);
1700 CHECK_EQUAL(all_info2
.out
.unknown1
);
1701 CHECK_EQUAL(all_info2
.out
.alloc_size
);
1702 CHECK_EQUAL(all_info2
.out
.size
);
1703 CHECK_EQUAL(all_info2
.out
.nlink
);
1704 CHECK_EQUAL(all_info2
.out
.delete_pending
);
1705 CHECK_EQUAL(all_info2
.out
.directory
);
1706 CHECK_EQUAL(all_info2
.out
.file_id
);
1707 CHECK_EQUAL(all_info2
.out
.ea_size
);
1708 CHECK_EQUAL(all_info2
.out
.access_mask
);
1709 CHECK_EQUAL(all_info2
.out
.position
);
1710 CHECK_EQUAL(all_info2
.out
.mode
);
1711 CHECK_EQUAL(all_info2
.out
.alignment_requirement
);
1712 CHECK_WSTR_EQUAL(all_info2
.out
.fname
);
1715 case RAW_FILEINFO_SMB2_ALL_EAS
:
1716 CHECK_EQUAL(all_eas
.out
.num_eas
);
1717 for (i
=0;i
<parm
[0].all_eas
.out
.num_eas
;i
++) {
1718 CHECK_EQUAL(all_eas
.out
.eas
[i
].flags
);
1719 CHECK_WSTR_EQUAL(all_eas
.out
.eas
[i
].name
);
1720 CHECK_BLOB_EQUAL(all_eas
.out
.eas
[i
].value
);
1724 case RAW_FILEINFO_SEC_DESC
:
1725 CHECK_SECDESC(query_secdesc
.out
.sd
);
1728 /* Unhandled levels */
1729 case RAW_FILEINFO_EA_LIST
:
1730 case RAW_FILEINFO_UNIX_BASIC
:
1731 case RAW_FILEINFO_UNIX_LINK
:
1732 case RAW_FILEINFO_UNIX_INFO2
:
1742 generate openx operations
1744 static bool handler_smb_openx(int instance
)
1746 union smb_open parm
[NSERVERS
];
1747 NTSTATUS status
[NSERVERS
];
1749 parm
[0].openx
.level
= RAW_OPEN_OPENX
;
1750 parm
[0].openx
.in
.flags
= gen_openx_flags();
1751 parm
[0].openx
.in
.open_mode
= gen_openx_mode();
1752 parm
[0].openx
.in
.search_attrs
= gen_attrib();
1753 parm
[0].openx
.in
.file_attrs
= gen_attrib();
1754 parm
[0].openx
.in
.write_time
= gen_timet();
1755 parm
[0].openx
.in
.open_func
= gen_openx_func();
1756 parm
[0].openx
.in
.size
= gen_io_count();
1757 parm
[0].openx
.in
.timeout
= gen_timeout();
1758 parm
[0].openx
.in
.fname
= gen_fname_open(instance
);
1760 if (!options
.use_oplocks
) {
1761 /* mask out oplocks */
1762 parm
[0].openx
.in
.flags
&= ~(OPENX_FLAGS_REQUEST_OPLOCK
|
1763 OPENX_FLAGS_REQUEST_BATCH_OPLOCK
);
1767 GEN_CALL_SMB(smb_raw_open(tree
, current_op
.mem_ctx
, &parm
[i
]));
1769 CHECK_ATTRIB(openx
.out
.attrib
);
1770 CHECK_EQUAL(openx
.out
.size
);
1771 CHECK_EQUAL(openx
.out
.access
);
1772 CHECK_EQUAL(openx
.out
.ftype
);
1773 CHECK_EQUAL(openx
.out
.devstate
);
1774 CHECK_EQUAL(openx
.out
.action
);
1775 CHECK_EQUAL(openx
.out
.access_mask
);
1776 CHECK_EQUAL(openx
.out
.unknown
);
1777 CHECK_TIMES_EQUAL(openx
.out
.write_time
);
1779 /* open creates a new file handle */
1780 ADD_HANDLE_SMB(parm
[0].openx
.in
.fname
, openx
.out
.file
.fnum
);
1787 generate open operations
1789 static bool handler_smb_open(int instance
)
1791 union smb_open parm
[NSERVERS
];
1792 NTSTATUS status
[NSERVERS
];
1794 parm
[0].openold
.level
= RAW_OPEN_OPEN
;
1795 parm
[0].openold
.in
.open_mode
= gen_bits_mask2(0xF, 0xFFFF);
1796 parm
[0].openold
.in
.search_attrs
= gen_attrib();
1797 parm
[0].openold
.in
.fname
= gen_fname_open(instance
);
1799 if (!options
.use_oplocks
) {
1800 /* mask out oplocks */
1801 parm
[0].openold
.in
.open_mode
&= ~(OPENX_FLAGS_REQUEST_OPLOCK
|
1802 OPENX_FLAGS_REQUEST_BATCH_OPLOCK
);
1806 GEN_CALL_SMB(smb_raw_open(tree
, current_op
.mem_ctx
, &parm
[i
]));
1808 CHECK_ATTRIB(openold
.out
.attrib
);
1809 CHECK_TIMES_EQUAL(openold
.out
.write_time
);
1810 CHECK_EQUAL(openold
.out
.size
);
1811 CHECK_EQUAL(openold
.out
.rmode
);
1813 /* open creates a new file handle */
1814 ADD_HANDLE_SMB(parm
[0].openold
.in
.fname
, openold
.out
.file
.fnum
);
1821 generate ntcreatex operations
1823 static bool handler_smb_ntcreatex(int instance
)
1825 union smb_open parm
[NSERVERS
];
1826 NTSTATUS status
[NSERVERS
];
1828 parm
[0].ntcreatex
.level
= RAW_OPEN_NTCREATEX
;
1829 parm
[0].ntcreatex
.in
.flags
= gen_ntcreatex_flags();
1830 parm
[0].ntcreatex
.in
.root_fid
.fnum
= gen_root_fid(instance
);
1831 parm
[0].ntcreatex
.in
.access_mask
= gen_access_mask();
1832 parm
[0].ntcreatex
.in
.alloc_size
= gen_alloc_size();
1833 parm
[0].ntcreatex
.in
.file_attr
= gen_attrib();
1834 parm
[0].ntcreatex
.in
.share_access
= gen_bits_mask2(0x7, 0xFFFFFFFF);
1835 parm
[0].ntcreatex
.in
.open_disposition
= gen_open_disp();
1836 parm
[0].ntcreatex
.in
.create_options
= gen_create_options();
1837 parm
[0].ntcreatex
.in
.impersonation
= gen_bits_mask2(0, 0xFFFFFFFF);
1838 parm
[0].ntcreatex
.in
.security_flags
= gen_bits_mask2(0, 0xFF);
1839 parm
[0].ntcreatex
.in
.fname
= gen_fname_open(instance
);
1841 if (!options
.use_oplocks
) {
1842 /* mask out oplocks */
1843 parm
[0].ntcreatex
.in
.flags
&= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK
|
1844 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK
);
1848 if (parm
[0].ntcreatex
.in
.root_fid
.fnum
!= 0) {
1849 GEN_SET_FNUM_SMB(ntcreatex
.in
.root_fid
.fnum
);
1851 GEN_CALL_SMB(smb_raw_open(tree
, current_op
.mem_ctx
, &parm
[i
]));
1853 CHECK_EQUAL(ntcreatex
.out
.oplock_level
);
1854 CHECK_EQUAL(ntcreatex
.out
.create_action
);
1855 CHECK_NTTIMES_EQUAL(ntcreatex
.out
.create_time
);
1856 CHECK_NTTIMES_EQUAL(ntcreatex
.out
.access_time
);
1857 CHECK_NTTIMES_EQUAL(ntcreatex
.out
.write_time
);
1858 CHECK_NTTIMES_EQUAL(ntcreatex
.out
.change_time
);
1859 CHECK_ATTRIB(ntcreatex
.out
.attrib
);
1860 CHECK_EQUAL(ntcreatex
.out
.alloc_size
);
1861 CHECK_EQUAL(ntcreatex
.out
.size
);
1862 CHECK_EQUAL(ntcreatex
.out
.file_type
);
1863 CHECK_EQUAL(ntcreatex
.out
.ipc_state
);
1864 CHECK_EQUAL(ntcreatex
.out
.is_directory
);
1866 /* ntcreatex creates a new file handle */
1867 ADD_HANDLE_SMB(parm
[0].ntcreatex
.in
.fname
, ntcreatex
.out
.file
.fnum
);
1873 generate close operations
1875 static bool handler_smb_close(int instance
)
1877 union smb_close parm
[NSERVERS
];
1878 NTSTATUS status
[NSERVERS
];
1880 parm
[0].close
.level
= RAW_CLOSE_CLOSE
;
1881 parm
[0].close
.in
.file
.fnum
= gen_fnum_close(instance
);
1882 parm
[0].close
.in
.write_time
= gen_timet();
1885 GEN_SET_FNUM_SMB(close
.in
.file
.fnum
);
1886 GEN_CALL_SMB(smb_raw_close(tree
, &parm
[i
]));
1888 REMOVE_HANDLE_SMB(close
.in
.file
.fnum
);
1894 generate unlink operations
1896 static bool handler_smb_unlink(int instance
)
1898 union smb_unlink parm
[NSERVERS
];
1899 NTSTATUS status
[NSERVERS
];
1901 parm
[0].unlink
.in
.pattern
= gen_pattern();
1902 parm
[0].unlink
.in
.attrib
= gen_attrib();
1905 GEN_CALL_SMB(smb_raw_unlink(tree
, &parm
[i
]));
1911 generate chkpath operations
1913 static bool handler_smb_chkpath(int instance
)
1915 union smb_chkpath parm
[NSERVERS
];
1916 NTSTATUS status
[NSERVERS
];
1918 parm
[0].chkpath
.in
.path
= gen_fname_open(instance
);
1921 GEN_CALL_SMB(smb_raw_chkpath(tree
, &parm
[i
]));
1927 generate mkdir operations
1929 static bool handler_smb_mkdir(int instance
)
1931 union smb_mkdir parm
[NSERVERS
];
1932 NTSTATUS status
[NSERVERS
];
1934 parm
[0].mkdir
.level
= RAW_MKDIR_MKDIR
;
1935 parm
[0].mkdir
.in
.path
= gen_fname_open(instance
);
1938 GEN_CALL_SMB(smb_raw_mkdir(tree
, &parm
[i
]));
1944 generate rmdir operations
1946 static bool handler_smb_rmdir(int instance
)
1948 struct smb_rmdir parm
[NSERVERS
];
1949 NTSTATUS status
[NSERVERS
];
1951 parm
[0].in
.path
= gen_fname_open(instance
);
1954 GEN_CALL_SMB(smb_raw_rmdir(tree
, &parm
[i
]));
1960 generate rename operations
1962 static bool handler_smb_rename(int instance
)
1964 union smb_rename parm
[NSERVERS
];
1965 NTSTATUS status
[NSERVERS
];
1967 parm
[0].generic
.level
= RAW_RENAME_RENAME
;
1968 parm
[0].rename
.in
.pattern1
= gen_pattern();
1969 parm
[0].rename
.in
.pattern2
= gen_pattern();
1970 parm
[0].rename
.in
.attrib
= gen_attrib();
1973 GEN_CALL_SMB(smb_raw_rename(tree
, &parm
[i
]));
1979 generate ntrename operations
1981 static bool handler_smb_ntrename(int instance
)
1983 union smb_rename parm
[NSERVERS
];
1984 NTSTATUS status
[NSERVERS
];
1986 parm
[0].generic
.level
= RAW_RENAME_NTRENAME
;
1987 parm
[0].ntrename
.in
.old_name
= gen_fname();
1988 parm
[0].ntrename
.in
.new_name
= gen_fname();
1989 parm
[0].ntrename
.in
.attrib
= gen_attrib();
1990 parm
[0].ntrename
.in
.cluster_size
= gen_bits_mask2(0, 0xFFFFFFF);
1991 parm
[0].ntrename
.in
.flags
= gen_rename_flags();
1994 GEN_CALL_SMB(smb_raw_rename(tree
, &parm
[i
]));
2001 generate seek operations
2003 static bool handler_smb_seek(int instance
)
2005 union smb_seek parm
[NSERVERS
];
2006 NTSTATUS status
[NSERVERS
];
2008 parm
[0].lseek
.in
.file
.fnum
= gen_fnum(instance
);
2009 parm
[0].lseek
.in
.mode
= gen_bits_mask2(0x3, 0xFFFF);
2010 parm
[0].lseek
.in
.offset
= gen_offset();
2013 GEN_SET_FNUM_SMB(lseek
.in
.file
.fnum
);
2014 GEN_CALL_SMB(smb_raw_seek(tree
, &parm
[i
]));
2016 CHECK_EQUAL(lseek
.out
.offset
);
2023 generate readx operations
2025 static bool handler_smb_readx(int instance
)
2027 union smb_read parm
[NSERVERS
];
2028 NTSTATUS status
[NSERVERS
];
2030 parm
[0].readx
.level
= RAW_READ_READX
;
2031 parm
[0].readx
.in
.file
.fnum
= gen_fnum(instance
);
2032 parm
[0].readx
.in
.offset
= gen_offset();
2033 parm
[0].readx
.in
.mincnt
= gen_io_count();
2034 parm
[0].readx
.in
.maxcnt
= gen_io_count();
2035 parm
[0].readx
.in
.remaining
= gen_io_count();
2036 parm
[0].readx
.in
.read_for_execute
= gen_bool();
2037 parm
[0].readx
.out
.data
= talloc_array(current_op
.mem_ctx
, uint8_t,
2038 MAX(parm
[0].readx
.in
.mincnt
, parm
[0].readx
.in
.maxcnt
));
2041 GEN_SET_FNUM_SMB(readx
.in
.file
.fnum
);
2042 GEN_CALL_SMB(smb_raw_read(tree
, &parm
[i
]));
2044 CHECK_EQUAL(readx
.out
.remaining
);
2045 CHECK_EQUAL(readx
.out
.compaction_mode
);
2046 CHECK_EQUAL(readx
.out
.nread
);
2052 generate writex operations
2054 static bool handler_smb_writex(int instance
)
2056 union smb_write parm
[NSERVERS
];
2057 NTSTATUS status
[NSERVERS
];
2059 parm
[0].writex
.level
= RAW_WRITE_WRITEX
;
2060 parm
[0].writex
.in
.file
.fnum
= gen_fnum(instance
);
2061 parm
[0].writex
.in
.offset
= gen_offset();
2062 parm
[0].writex
.in
.wmode
= gen_bits_mask(0xFFFF);
2063 parm
[0].writex
.in
.remaining
= gen_io_count();
2064 parm
[0].writex
.in
.count
= gen_io_count();
2065 parm
[0].writex
.in
.data
= talloc_zero_array(current_op
.mem_ctx
, uint8_t, parm
[0].writex
.in
.count
);
2068 GEN_SET_FNUM_SMB(writex
.in
.file
.fnum
);
2069 GEN_CALL_SMB(smb_raw_write(tree
, &parm
[i
]));
2071 CHECK_EQUAL(writex
.out
.nwritten
);
2072 CHECK_EQUAL(writex
.out
.remaining
);
2078 generate lockingx operations
2080 static bool handler_smb_lockingx(int instance
)
2082 union smb_lock parm
[NSERVERS
];
2083 NTSTATUS status
[NSERVERS
];
2086 parm
[0].lockx
.level
= RAW_LOCK_LOCKX
;
2087 parm
[0].lockx
.in
.file
.fnum
= gen_fnum(instance
);
2088 parm
[0].lockx
.in
.mode
= gen_lock_mode();
2089 parm
[0].lockx
.in
.timeout
= gen_timeout();
2091 /* make sure we don't accidentially generate an oplock
2092 break ack - otherwise the server can just block forever */
2093 parm
[0].lockx
.in
.ulock_cnt
= gen_lock_count();
2094 parm
[0].lockx
.in
.lock_cnt
= gen_lock_count();
2095 nlocks
= parm
[0].lockx
.in
.ulock_cnt
+ parm
[0].lockx
.in
.lock_cnt
;
2096 } while (nlocks
== 0);
2099 parm
[0].lockx
.in
.locks
= talloc_array(current_op
.mem_ctx
,
2100 struct smb_lock_entry
,
2102 for (n
=0;n
<nlocks
;n
++) {
2103 parm
[0].lockx
.in
.locks
[n
].pid
= gen_pid();
2104 parm
[0].lockx
.in
.locks
[n
].offset
= gen_offset();
2105 parm
[0].lockx
.in
.locks
[n
].count
= gen_io_count();
2110 GEN_SET_FNUM_SMB(lockx
.in
.file
.fnum
);
2111 GEN_CALL_SMB(smb_raw_lock(tree
, &parm
[i
]));
2118 generate a fileinfo query structure
2120 static void gen_setfileinfo(int instance
, union smb_setfileinfo
*info
)
2124 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
2126 enum smb_setfileinfo_level level
;
2130 /* disabled until win2003 can handle them ... */
2131 LVL(EA_SET
), LVL(BASIC_INFO
), LVL(DISPOSITION_INFO
),
2132 LVL(STANDARD
), LVL(ALLOCATION_INFO
), LVL(END_OF_FILE_INFO
),
2134 LVL(SETATTR
), LVL(SETATTRE
), LVL(BASIC_INFORMATION
),
2135 LVL(RENAME_INFORMATION
), LVL(DISPOSITION_INFORMATION
),
2136 LVL(POSITION_INFORMATION
), LVL(MODE_INFORMATION
),
2137 LVL(ALLOCATION_INFORMATION
), LVL(END_OF_FILE_INFORMATION
),
2138 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
2141 i
= gen_int_range(0, ARRAY_SIZE(levels
)-1);
2142 } while (ignore_pattern(levels
[i
].name
));
2144 info
->generic
.level
= levels
[i
].level
;
2146 switch (info
->generic
.level
) {
2147 case RAW_SFILEINFO_SETATTR
:
2148 info
->setattr
.in
.attrib
= gen_attrib();
2149 info
->setattr
.in
.write_time
= gen_timet();
2151 case RAW_SFILEINFO_SETATTRE
:
2152 info
->setattre
.in
.create_time
= gen_timet();
2153 info
->setattre
.in
.access_time
= gen_timet();
2154 info
->setattre
.in
.write_time
= gen_timet();
2156 case RAW_SFILEINFO_STANDARD
:
2157 info
->standard
.in
.create_time
= gen_timet();
2158 info
->standard
.in
.access_time
= gen_timet();
2159 info
->standard
.in
.write_time
= gen_timet();
2161 case RAW_SFILEINFO_EA_SET
: {
2162 static struct ea_struct ea
;
2163 info
->ea_set
.in
.num_eas
= 1;
2164 info
->ea_set
.in
.eas
= &ea
;
2165 info
->ea_set
.in
.eas
[0] = gen_ea_struct();
2168 case RAW_SFILEINFO_BASIC_INFO
:
2169 case RAW_SFILEINFO_BASIC_INFORMATION
:
2170 info
->basic_info
.in
.create_time
= gen_nttime();
2171 info
->basic_info
.in
.access_time
= gen_nttime();
2172 info
->basic_info
.in
.write_time
= gen_nttime();
2173 info
->basic_info
.in
.change_time
= gen_nttime();
2174 info
->basic_info
.in
.attrib
= gen_attrib();
2176 case RAW_SFILEINFO_DISPOSITION_INFO
:
2177 case RAW_SFILEINFO_DISPOSITION_INFORMATION
:
2178 info
->disposition_info
.in
.delete_on_close
= gen_bool();
2180 case RAW_SFILEINFO_ALLOCATION_INFO
:
2181 case RAW_SFILEINFO_ALLOCATION_INFORMATION
:
2182 info
->allocation_info
.in
.alloc_size
= gen_alloc_size();
2184 case RAW_SFILEINFO_END_OF_FILE_INFO
:
2185 case RAW_SFILEINFO_END_OF_FILE_INFORMATION
:
2186 info
->end_of_file_info
.in
.size
= gen_offset();
2188 case RAW_SFILEINFO_RENAME_INFORMATION
:
2189 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2
:
2190 info
->rename_information
.in
.overwrite
= gen_bool();
2191 info
->rename_information
.in
.root_fid
= gen_root_fid(instance
);
2192 info
->rename_information
.in
.new_name
= gen_fname_open(instance
);
2194 case RAW_SFILEINFO_POSITION_INFORMATION
:
2195 info
->position_information
.in
.position
= gen_offset();
2197 case RAW_SFILEINFO_MODE_INFORMATION
:
2198 info
->mode_information
.in
.mode
= gen_bits_mask(0xFFFFFFFF);
2200 case RAW_SFILEINFO_FULL_EA_INFORMATION
:
2201 info
->full_ea_information
.in
.eas
= gen_ea_list();
2203 case RAW_SFILEINFO_GENERIC
:
2204 case RAW_SFILEINFO_SEC_DESC
:
2205 case RAW_SFILEINFO_UNIX_BASIC
:
2206 case RAW_SFILEINFO_UNIX_LINK
:
2207 case RAW_SFILEINFO_UNIX_HLINK
:
2208 case RAW_SFILEINFO_1023
:
2209 case RAW_SFILEINFO_1025
:
2210 case RAW_SFILEINFO_1029
:
2211 case RAW_SFILEINFO_1032
:
2212 case RAW_SFILEINFO_1039
:
2213 case RAW_SFILEINFO_1040
:
2214 case RAW_SFILEINFO_UNIX_INFO2
:
2222 generate a fileinfo query structure
2224 static void gen_setfileinfo(int instance
, union smb_setfileinfo
*info
)
2228 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
2230 enum smb_setfileinfo_level level
;
2233 struct levels smb_levels
[] = {
2234 LVL(EA_SET
), LVL(BASIC_INFO
), LVL(DISPOSITION_INFO
),
2235 LVL(STANDARD
), LVL(ALLOCATION_INFO
), LVL(END_OF_FILE_INFO
),
2236 LVL(SETATTR
), LVL(SETATTRE
), LVL(BASIC_INFORMATION
),
2237 LVL(RENAME_INFORMATION
), LVL(DISPOSITION_INFORMATION
),
2238 LVL(POSITION_INFORMATION
), LVL(FULL_EA_INFORMATION
), LVL(MODE_INFORMATION
),
2239 LVL(ALLOCATION_INFORMATION
), LVL(END_OF_FILE_INFORMATION
),
2240 LVL(PIPE_INFORMATION
), LVL(VALID_DATA_INFORMATION
), LVL(SHORT_NAME_INFORMATION
),
2241 LVL(1025), LVL(1027), LVL(1029), LVL(1030), LVL(1031), LVL(1032), LVL(1036),
2242 LVL(1041), LVL(1042), LVL(1043), LVL(1044),
2244 struct levels smb2_levels
[] = {
2245 LVL(BASIC_INFORMATION
),
2246 LVL(RENAME_INFORMATION
), LVL(DISPOSITION_INFORMATION
),
2247 LVL(POSITION_INFORMATION
), LVL(FULL_EA_INFORMATION
), LVL(MODE_INFORMATION
),
2248 LVL(ALLOCATION_INFORMATION
), LVL(END_OF_FILE_INFORMATION
),
2249 LVL(PIPE_INFORMATION
), LVL(VALID_DATA_INFORMATION
), LVL(SHORT_NAME_INFORMATION
),
2250 LVL(1025), LVL(1027), LVL(1029), LVL(1030), LVL(1031), LVL(1032), LVL(1036),
2251 LVL(1041), LVL(1042), LVL(1043), LVL(1044),
2253 struct levels
*levels
= options
.smb2
?smb2_levels
:smb_levels
;
2254 uint32_t num_levels
= options
.smb2
?ARRAY_SIZE(smb2_levels
):ARRAY_SIZE(smb_levels
);
2257 i
= gen_int_range(0, num_levels
-1);
2258 } while (ignore_pattern(levels
[i
].name
));
2261 info
->generic
.level
= levels
[i
].level
;
2263 switch (info
->generic
.level
) {
2264 case RAW_SFILEINFO_SETATTR
:
2265 info
->setattr
.in
.attrib
= gen_attrib();
2266 info
->setattr
.in
.write_time
= gen_timet();
2268 case RAW_SFILEINFO_SETATTRE
:
2269 info
->setattre
.in
.create_time
= gen_timet();
2270 info
->setattre
.in
.access_time
= gen_timet();
2271 info
->setattre
.in
.write_time
= gen_timet();
2273 case RAW_SFILEINFO_STANDARD
:
2274 info
->standard
.in
.create_time
= gen_timet();
2275 info
->standard
.in
.access_time
= gen_timet();
2276 info
->standard
.in
.write_time
= gen_timet();
2278 case RAW_SFILEINFO_EA_SET
: {
2279 static struct ea_struct ea
;
2280 info
->ea_set
.in
.num_eas
= 1;
2281 info
->ea_set
.in
.eas
= &ea
;
2282 info
->ea_set
.in
.eas
[0] = gen_ea_struct();
2285 case RAW_SFILEINFO_BASIC_INFO
:
2286 case RAW_SFILEINFO_BASIC_INFORMATION
:
2287 info
->basic_info
.in
.create_time
= gen_nttime();
2288 info
->basic_info
.in
.access_time
= gen_nttime();
2289 info
->basic_info
.in
.write_time
= gen_nttime();
2290 info
->basic_info
.in
.change_time
= gen_nttime();
2291 info
->basic_info
.in
.attrib
= gen_attrib();
2293 case RAW_SFILEINFO_DISPOSITION_INFO
:
2294 case RAW_SFILEINFO_DISPOSITION_INFORMATION
:
2295 info
->disposition_info
.in
.delete_on_close
= gen_bool();
2297 case RAW_SFILEINFO_ALLOCATION_INFO
:
2298 case RAW_SFILEINFO_ALLOCATION_INFORMATION
:
2299 info
->allocation_info
.in
.alloc_size
= gen_alloc_size();
2301 case RAW_SFILEINFO_END_OF_FILE_INFO
:
2302 case RAW_SFILEINFO_END_OF_FILE_INFORMATION
:
2303 info
->end_of_file_info
.in
.size
= gen_offset();
2305 case RAW_SFILEINFO_RENAME_INFORMATION
:
2306 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2
:
2307 info
->rename_information
.in
.overwrite
= gen_bool();
2308 info
->rename_information
.in
.root_fid
= gen_root_fid(instance
);
2309 info
->rename_information
.in
.new_name
= gen_fname_open(instance
);
2311 case RAW_SFILEINFO_POSITION_INFORMATION
:
2312 info
->position_information
.in
.position
= gen_offset();
2314 case RAW_SFILEINFO_MODE_INFORMATION
:
2315 info
->mode_information
.in
.mode
= gen_bits_mask(0xFFFFFFFF);
2317 case RAW_SFILEINFO_FULL_EA_INFORMATION
:
2318 info
->full_ea_information
.in
.eas
= gen_ea_list();
2321 case RAW_SFILEINFO_GENERIC
:
2322 case RAW_SFILEINFO_SEC_DESC
:
2323 case RAW_SFILEINFO_1025
:
2324 case RAW_SFILEINFO_1029
:
2325 case RAW_SFILEINFO_1032
:
2326 case RAW_SFILEINFO_UNIX_BASIC
:
2327 case RAW_SFILEINFO_UNIX_INFO2
:
2328 case RAW_SFILEINFO_UNIX_LINK
:
2329 case RAW_SFILEINFO_UNIX_HLINK
:
2330 case RAW_SFILEINFO_LINK_INFORMATION
:
2331 case RAW_SFILEINFO_PIPE_INFORMATION
:
2332 case RAW_SFILEINFO_VALID_DATA_INFORMATION
:
2333 case RAW_SFILEINFO_SHORT_NAME_INFORMATION
:
2334 case RAW_SFILEINFO_1027
:
2335 case RAW_SFILEINFO_1030
:
2336 case RAW_SFILEINFO_1031
:
2337 case RAW_SFILEINFO_1036
:
2338 case RAW_SFILEINFO_1041
:
2339 case RAW_SFILEINFO_1042
:
2340 case RAW_SFILEINFO_1043
:
2341 case RAW_SFILEINFO_1044
:
2350 generate a fileinfo query structure
2352 static void gen_fileinfo_smb(int instance
, union smb_fileinfo
*info
)
2356 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
2358 enum smb_fileinfo_level level
;
2361 LVL(GETATTR
), LVL(GETATTRE
), LVL(STANDARD
),
2362 LVL(EA_SIZE
), LVL(ALL_EAS
), LVL(IS_NAME_VALID
),
2363 LVL(BASIC_INFO
), LVL(STANDARD_INFO
), LVL(EA_INFO
),
2364 LVL(NAME_INFO
), LVL(ALL_INFO
), LVL(ALT_NAME_INFO
),
2365 LVL(STREAM_INFO
), LVL(COMPRESSION_INFO
), LVL(BASIC_INFORMATION
),
2366 LVL(STANDARD_INFORMATION
), LVL(INTERNAL_INFORMATION
), LVL(EA_INFORMATION
),
2367 LVL(ACCESS_INFORMATION
), LVL(NAME_INFORMATION
), LVL(POSITION_INFORMATION
),
2368 LVL(MODE_INFORMATION
), LVL(ALIGNMENT_INFORMATION
), LVL(ALL_INFORMATION
),
2369 LVL(ALT_NAME_INFORMATION
), LVL(STREAM_INFORMATION
), LVL(COMPRESSION_INFORMATION
),
2370 LVL(NETWORK_OPEN_INFORMATION
), LVL(ATTRIBUTE_TAG_INFORMATION
)
2373 i
= gen_int_range(0, ARRAY_SIZE(levels
)-1);
2374 } while (ignore_pattern(levels
[i
].name
));
2376 info
->generic
.level
= levels
[i
].level
;
2380 generate qpathinfo operations
2382 static bool handler_smb_qpathinfo(int instance
)
2384 union smb_fileinfo parm
[NSERVERS
];
2385 NTSTATUS status
[NSERVERS
];
2387 parm
[0].generic
.in
.file
.path
= gen_fname_open(instance
);
2389 gen_fileinfo_smb(instance
, &parm
[0]);
2392 GEN_CALL_SMB(smb_raw_pathinfo(tree
, current_op
.mem_ctx
, &parm
[i
]));
2394 return cmp_fileinfo(instance
, parm
, status
);
2398 generate qfileinfo operations
2400 static bool handler_smb_qfileinfo(int instance
)
2402 union smb_fileinfo parm
[NSERVERS
];
2403 NTSTATUS status
[NSERVERS
];
2405 parm
[0].generic
.in
.file
.fnum
= gen_fnum(instance
);
2407 gen_fileinfo_smb(instance
, &parm
[0]);
2410 GEN_SET_FNUM_SMB(generic
.in
.file
.fnum
);
2411 GEN_CALL_SMB(smb_raw_fileinfo(tree
, current_op
.mem_ctx
, &parm
[i
]));
2413 return cmp_fileinfo(instance
, parm
, status
);
2418 generate setpathinfo operations
2420 static bool handler_smb_spathinfo(int instance
)
2422 union smb_setfileinfo parm
[NSERVERS
];
2423 NTSTATUS status
[NSERVERS
];
2425 gen_setfileinfo(instance
, &parm
[0]);
2426 parm
[0].generic
.in
.file
.path
= gen_fname_open(instance
);
2430 /* a special case for the fid in a RENAME */
2431 if (parm
[0].generic
.level
== RAW_SFILEINFO_RENAME_INFORMATION
&&
2432 parm
[0].rename_information
.in
.root_fid
!= 0) {
2433 GEN_SET_FNUM_SMB(rename_information
.in
.root_fid
);
2436 GEN_CALL_SMB(smb_raw_setpathinfo(tree
, &parm
[i
]));
2443 generate setfileinfo operations
2445 static bool handler_smb_sfileinfo(int instance
)
2447 union smb_setfileinfo parm
[NSERVERS
];
2448 NTSTATUS status
[NSERVERS
];
2450 parm
[0].generic
.in
.file
.fnum
= gen_fnum(instance
);
2452 gen_setfileinfo(instance
, &parm
[0]);
2455 GEN_SET_FNUM_SMB(generic
.in
.file
.fnum
);
2456 GEN_CALL_SMB(smb_raw_setfileinfo(tree
, &parm
[i
]));
2463 this is called when a change notify reply comes in
2465 static void async_notify_smb(struct smbcli_request
*req
)
2467 union smb_notify notify
;
2471 struct smbcli_transport
*transport
= req
->transport
;
2474 tid
= req
->tree
->tid
;
2477 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
2478 status
= smb_raw_changenotify_recv(req
, current_op
.mem_ctx
, ¬ify
);
2479 if (NT_STATUS_IS_OK(status
) && notify
.nttrans
.out
.num_changes
> 0) {
2480 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
2482 notify
.nttrans
.out
.num_changes
,
2483 notify
.nttrans
.out
.changes
[0].action
,
2484 notify
.nttrans
.out
.changes
[0].name
.s
);
2487 for (i
=0;i
<NSERVERS
;i
++) {
2488 for (j
=0;j
<NINSTANCES
;j
++) {
2489 if (transport
== servers
[i
].smb_tree
[j
]->session
->transport
&&
2490 tid
== servers
[i
].smb_tree
[j
]->tid
) {
2491 notifies
[i
][j
].notify_count
++;
2492 notifies
[i
][j
].status
= status
;
2493 notifies
[i
][j
].notify
= notify
;
2500 generate change notify operations
2502 static bool handler_smb_notify(int instance
)
2504 union smb_notify parm
[NSERVERS
];
2507 ZERO_STRUCT(parm
[0]);
2508 parm
[0].nttrans
.level
= RAW_NOTIFY_NTTRANS
;
2509 parm
[0].nttrans
.in
.buffer_size
= gen_io_count();
2510 parm
[0].nttrans
.in
.completion_filter
= gen_bits_mask(0xFF);
2511 parm
[0].nttrans
.in
.file
.fnum
= gen_fnum(instance
);
2512 parm
[0].nttrans
.in
.recursive
= gen_bool();
2515 GEN_SET_FNUM_SMB(nttrans
.in
.file
.fnum
);
2517 for (n
=0;n
<NSERVERS
;n
++) {
2518 struct smbcli_request
*req
;
2519 req
= smb_raw_changenotify_send(servers
[n
].smb_tree
[instance
], &parm
[n
]);
2520 req
->async
.fn
= async_notify_smb
;
2528 generate ntcreatex operations
2530 static bool handler_smb2_create(int instance
)
2532 struct smb2_create parm
[NSERVERS
];
2533 NTSTATUS status
[NSERVERS
];
2535 ZERO_STRUCT(parm
[0]);
2536 parm
[0].in
.security_flags
= gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFF);
2537 parm
[0].in
.oplock_level
= gen_bits_levels(3, 90, 0x0, 70, 0x9, 100, 0xFF);
2538 parm
[0].in
.impersonation_level
= gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFFFFFFFF);
2539 parm
[0].in
.create_flags
= gen_reserved64();
2540 parm
[0].in
.reserved
= gen_reserved64();
2541 parm
[0].in
.desired_access
= gen_access_mask();
2542 parm
[0].in
.file_attributes
= gen_attrib();
2543 parm
[0].in
.share_access
= gen_bits_mask2(0x7, 0xFFFFFFFF);
2544 parm
[0].in
.create_disposition
= gen_open_disp();
2545 parm
[0].in
.create_options
= gen_create_options();
2546 parm
[0].in
.fname
= gen_fname_open(instance
);
2547 parm
[0].in
.eas
= gen_ea_list();
2548 parm
[0].in
.alloc_size
= gen_alloc_size();
2549 parm
[0].in
.durable_open
= gen_bool();
2550 parm
[0].in
.query_maximal_access
= gen_bool();
2551 parm
[0].in
.timewarp
= gen_timewarp();
2552 parm
[0].in
.query_on_disk_id
= gen_bool();
2553 parm
[0].in
.sec_desc
= gen_sec_desc();
2555 if (!options
.use_oplocks
) {
2556 /* mask out oplocks */
2557 parm
[0].in
.oplock_level
= 0;
2560 if (options
.valid
) {
2561 parm
[0].in
.security_flags
&= 3;
2562 parm
[0].in
.oplock_level
&= 9;
2563 parm
[0].in
.impersonation_level
&= 3;
2567 GEN_CALL_SMB2(smb2_create(tree
, current_op
.mem_ctx
, &parm
[i
]));
2569 CHECK_EQUAL(out
.oplock_level
);
2570 CHECK_EQUAL(out
.reserved
);
2571 CHECK_EQUAL(out
.create_action
);
2572 CHECK_NTTIMES_EQUAL(out
.create_time
);
2573 CHECK_NTTIMES_EQUAL(out
.access_time
);
2574 CHECK_NTTIMES_EQUAL(out
.write_time
);
2575 CHECK_NTTIMES_EQUAL(out
.change_time
);
2576 CHECK_EQUAL(out
.alloc_size
);
2577 CHECK_EQUAL(out
.size
);
2578 CHECK_ATTRIB(out
.file_attr
);
2579 CHECK_EQUAL(out
.reserved2
);
2580 CHECK_EQUAL(out
.maximal_access
);
2582 /* ntcreatex creates a new file handle */
2583 ADD_HANDLE_SMB2(parm
[0].in
.fname
, out
.file
.handle
);
2589 generate close operations
2591 static bool handler_smb2_close(int instance
)
2593 struct smb2_close parm
[NSERVERS
];
2594 NTSTATUS status
[NSERVERS
];
2596 ZERO_STRUCT(parm
[0]);
2597 parm
[0].in
.file
.handle
.data
[0] = gen_fnum_close(instance
);
2598 parm
[0].in
.flags
= gen_bits_mask2(0x1, 0xFFFF);
2601 GEN_SET_FNUM_SMB2(in
.file
.handle
);
2602 GEN_CALL_SMB2(smb2_close(tree
, &parm
[i
]));
2604 CHECK_EQUAL(out
.flags
);
2605 CHECK_EQUAL(out
._pad
);
2606 CHECK_NTTIMES_EQUAL(out
.create_time
);
2607 CHECK_NTTIMES_EQUAL(out
.access_time
);
2608 CHECK_NTTIMES_EQUAL(out
.write_time
);
2609 CHECK_NTTIMES_EQUAL(out
.change_time
);
2610 CHECK_EQUAL(out
.alloc_size
);
2611 CHECK_EQUAL(out
.size
);
2612 CHECK_ATTRIB(out
.file_attr
);
2614 REMOVE_HANDLE_SMB2(in
.file
.handle
);
2620 generate read operations
2622 static bool handler_smb2_read(int instance
)
2624 struct smb2_read parm
[NSERVERS
];
2625 NTSTATUS status
[NSERVERS
];
2627 parm
[0].in
.file
.handle
.data
[0] = gen_fnum(instance
);
2628 parm
[0].in
.reserved
= gen_reserved8();
2629 parm
[0].in
.length
= gen_io_count();
2630 parm
[0].in
.offset
= gen_offset();
2631 parm
[0].in
.min_count
= gen_io_count();
2632 parm
[0].in
.channel
= gen_bits_mask2(0x0, 0xFFFFFFFF);
2633 parm
[0].in
.remaining
= gen_bits_mask2(0x0, 0xFFFFFFFF);
2634 parm
[0].in
.channel_offset
= gen_bits_mask2(0x0, 0xFFFF);
2635 parm
[0].in
.channel_length
= gen_bits_mask2(0x0, 0xFFFF);
2638 GEN_SET_FNUM_SMB2(in
.file
.handle
);
2639 GEN_CALL_SMB2(smb2_read(tree
, current_op
.mem_ctx
, &parm
[i
]));
2641 CHECK_EQUAL(out
.remaining
);
2642 CHECK_EQUAL(out
.reserved
);
2643 CHECK_EQUAL(out
.data
.length
);
2649 generate write operations
2651 static bool handler_smb2_write(int instance
)
2653 struct smb2_write parm
[NSERVERS
];
2654 NTSTATUS status
[NSERVERS
];
2656 parm
[0].in
.file
.handle
.data
[0] = gen_fnum(instance
);
2657 parm
[0].in
.offset
= gen_offset();
2658 parm
[0].in
.unknown1
= gen_bits_mask2(0, 0xFFFFFFFF);
2659 parm
[0].in
.unknown2
= gen_bits_mask2(0, 0xFFFFFFFF);
2660 parm
[0].in
.data
= data_blob_talloc(current_op
.mem_ctx
, NULL
,
2664 GEN_SET_FNUM_SMB2(in
.file
.handle
);
2665 GEN_CALL_SMB2(smb2_write(tree
, &parm
[i
]));
2667 CHECK_EQUAL(out
._pad
);
2668 CHECK_EQUAL(out
.nwritten
);
2669 CHECK_EQUAL(out
.unknown1
);
2675 generate lockingx operations
2677 static bool handler_smb2_lock(int instance
)
2679 struct smb2_lock parm
[NSERVERS
];
2680 NTSTATUS status
[NSERVERS
];
2683 parm
[0].level
= RAW_LOCK_LOCKX
;
2684 parm
[0].in
.file
.handle
.data
[0] = gen_fnum(instance
);
2685 parm
[0].in
.lock_count
= gen_lock_count();
2686 parm
[0].in
.lock_sequence
= gen_reserved32();
2688 parm
[0].in
.locks
= talloc_array(current_op
.mem_ctx
,
2689 struct smb2_lock_element
,
2690 parm
[0].in
.lock_count
);
2691 for (n
=0;n
<parm
[0].in
.lock_count
;n
++) {
2692 parm
[0].in
.locks
[n
].offset
= gen_offset();
2693 parm
[0].in
.locks
[n
].length
= gen_io_count();
2694 /* don't yet cope with async replies */
2695 parm
[0].in
.locks
[n
].flags
= gen_lock_flags_smb2() |
2696 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
;
2697 parm
[0].in
.locks
[n
].reserved
= gen_bits_mask2(0x0, 0xFFFFFFFF);
2701 GEN_SET_FNUM_SMB2(in
.file
.handle
);
2702 GEN_CALL_SMB2(smb2_lock(tree
, &parm
[i
]));
2708 generate flush operations
2710 static bool handler_smb2_flush(int instance
)
2712 struct smb2_flush parm
[NSERVERS
];
2713 NTSTATUS status
[NSERVERS
];
2715 ZERO_STRUCT(parm
[0]);
2716 parm
[0].in
.file
.handle
.data
[0] = gen_fnum(instance
);
2717 parm
[0].in
.reserved1
= gen_reserved16();
2718 parm
[0].in
.reserved2
= gen_reserved32();
2721 GEN_SET_FNUM_SMB2(in
.file
.handle
);
2722 GEN_CALL_SMB2(smb2_flush(tree
, &parm
[i
]));
2724 CHECK_EQUAL(out
.reserved
);
2730 generate echo operations
2732 static bool handler_smb2_echo(int instance
)
2734 NTSTATUS status
[NSERVERS
];
2736 GEN_CALL_SMB2(smb2_keepalive(tree
->session
->transport
));
2744 generate a fileinfo query structure
2746 static void gen_fileinfo_smb2(int instance
, union smb_fileinfo
*info
)
2749 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
2751 enum smb_fileinfo_level level
;
2754 LVL(BASIC_INFORMATION
),
2755 LVL(STANDARD_INFORMATION
), LVL(INTERNAL_INFORMATION
), LVL(EA_INFORMATION
),
2756 LVL(ACCESS_INFORMATION
), LVL(NAME_INFORMATION
), LVL(POSITION_INFORMATION
),
2757 LVL(MODE_INFORMATION
), LVL(ALIGNMENT_INFORMATION
), LVL(SMB2_ALL_INFORMATION
),
2758 LVL(ALT_NAME_INFORMATION
), LVL(STREAM_INFORMATION
), LVL(COMPRESSION_INFORMATION
),
2759 LVL(NETWORK_OPEN_INFORMATION
), LVL(ATTRIBUTE_TAG_INFORMATION
),
2760 LVL(SMB2_ALL_EAS
), LVL(SMB2_ALL_INFORMATION
), LVL(SEC_DESC
),
2763 i
= gen_int_range(0, ARRAY_SIZE(levels
)-1);
2764 } while (ignore_pattern(levels
[i
].name
));
2766 info
->generic
.level
= levels
[i
].level
;
2770 generate qfileinfo operations
2772 static bool handler_smb2_qfileinfo(int instance
)
2774 union smb_fileinfo parm
[NSERVERS
];
2775 NTSTATUS status
[NSERVERS
];
2777 parm
[0].generic
.in
.file
.handle
.data
[0] = gen_fnum(instance
);
2779 gen_fileinfo_smb2(instance
, &parm
[0]);
2782 GEN_SET_FNUM_SMB2(generic
.in
.file
.handle
);
2783 GEN_CALL_SMB2(smb2_getinfo_file(tree
, current_op
.mem_ctx
, &parm
[i
]));
2785 return cmp_fileinfo(instance
, parm
, status
);
2790 generate setfileinfo operations
2792 static bool handler_smb2_sfileinfo(int instance
)
2794 union smb_setfileinfo parm
[NSERVERS
];
2795 NTSTATUS status
[NSERVERS
];
2797 gen_setfileinfo(instance
, &parm
[0]);
2798 parm
[0].generic
.in
.file
.fnum
= gen_fnum(instance
);
2801 GEN_SET_FNUM_SMB2(generic
.in
.file
.handle
);
2802 GEN_CALL_SMB2(smb2_setinfo_file(tree
, &parm
[i
]));
2808 wipe any relevant files
2810 static void wipe_files(void)
2815 if (options
.skip_cleanup
) {
2819 for (i
=0;i
<NSERVERS
;i
++) {
2822 n
= smb2_deltree(servers
[i
].smb2_tree
[0], "gentest");
2824 n
= smbcli_deltree(servers
[i
].smb_tree
[0], "gentest");
2827 printf("Failed to wipe tree on server %d\n", i
);
2831 status
= smb2_util_mkdir(servers
[i
].smb2_tree
[0], "gentest");
2833 status
= smbcli_mkdir(servers
[i
].smb_tree
[0], "gentest");
2835 if (NT_STATUS_IS_ERR(status
)) {
2836 printf("Failed to create gentest on server %d - %s\n", i
, nt_errstr(status
));
2840 printf("Deleted %d files on server %d\n", n
, i
);
2846 dump the current seeds - useful for continuing a backtrack
2848 static void dump_seeds(void)
2853 if (!options
.seeds_file
) {
2856 f
= fopen("seeds.tmp", "w");
2859 for (i
=0;i
<options
.numops
;i
++) {
2860 fprintf(f
, "%u\n", op_parms
[i
].seed
);
2863 rename("seeds.tmp", options
.seeds_file
);
2869 the list of top-level operations that we will generate
2873 bool (*handler
)(int instance
);
2875 int count
, success_count
;
2877 {"CREATE", handler_smb2_create
, true},
2878 {"CLOSE", handler_smb2_close
, true},
2879 {"READ", handler_smb2_read
, true},
2880 {"WRITE", handler_smb2_write
, true},
2881 {"LOCK", handler_smb2_lock
, true},
2882 {"FLUSH", handler_smb2_flush
, true},
2883 {"ECHO", handler_smb2_echo
, true},
2884 {"QFILEINFO", handler_smb2_qfileinfo
, true},
2885 {"SFILEINFO", handler_smb2_sfileinfo
, true},
2887 {"OPEN", handler_smb_open
, false},
2888 {"OPENX", handler_smb_openx
, false},
2889 {"NTCREATEX", handler_smb_ntcreatex
, false},
2890 {"CLOSE", handler_smb_close
, false},
2891 {"UNLINK", handler_smb_unlink
, false},
2892 {"MKDIR", handler_smb_mkdir
, false},
2893 {"RMDIR", handler_smb_rmdir
, false},
2894 {"RENAME", handler_smb_rename
, false},
2895 {"NTRENAME", handler_smb_ntrename
, false},
2896 {"READX", handler_smb_readx
, false},
2897 {"WRITEX", handler_smb_writex
, false},
2898 {"CHKPATH", handler_smb_chkpath
, false},
2899 {"SEEK", handler_smb_seek
, false},
2900 {"LOCKINGX", handler_smb_lockingx
, false},
2901 {"QPATHINFO", handler_smb_qpathinfo
, false},
2902 {"QFILEINFO", handler_smb_qfileinfo
, false},
2903 {"SPATHINFO", handler_smb_spathinfo
, false},
2904 {"SFILEINFO", handler_smb_sfileinfo
, false},
2905 {"NOTIFY", handler_smb_notify
, false},
2906 {"SEEK", handler_smb_seek
, false},
2911 run the test with the current set of op_parms parameters
2912 return the number of operations that completed successfully
2914 static int run_test(struct tevent_context
*ev
, struct loadparm_context
*lp_ctx
)
2918 if (!connect_servers(ev
, lp_ctx
)) {
2919 printf("Failed to connect to servers\n");
2925 /* wipe any leftover files from old runs */
2928 /* reset the open handles array */
2929 memset(open_handles
, 0, options
.max_open_handles
* sizeof(open_handles
[0]));
2930 num_open_handles
= 0;
2932 for (i
=0;i
<ARRAY_SIZE(gen_ops
);i
++) {
2933 gen_ops
[i
].count
= 0;
2934 gen_ops
[i
].success_count
= 0;
2937 for (op
=0; op
<options
.numops
; op
++) {
2938 int instance
, which_op
;
2941 if (op_parms
[op
].disabled
) continue;
2943 srandom(op_parms
[op
].seed
);
2945 instance
= gen_int_range(0, NINSTANCES
-1);
2947 /* generate a non-ignored operation */
2949 which_op
= gen_int_range(0, ARRAY_SIZE(gen_ops
)-1);
2950 } while (ignore_pattern(gen_ops
[which_op
].name
) ||
2951 gen_ops
[which_op
].smb2
!= options
.smb2
);
2953 DEBUG(3,("Generating op %s on instance %d\n",
2954 gen_ops
[which_op
].name
, instance
));
2956 current_op
.seed
= op_parms
[op
].seed
;
2957 current_op
.opnum
= op
;
2958 current_op
.name
= gen_ops
[which_op
].name
;
2959 current_op
.status
= NT_STATUS_OK
;
2960 talloc_free(current_op
.mem_ctx
);
2961 current_op
.mem_ctx
= talloc_named(NULL
, 0, "%s", current_op
.name
);
2963 ret
= gen_ops
[which_op
].handler(instance
);
2965 gen_ops
[which_op
].count
++;
2966 if (NT_STATUS_IS_OK(current_op
.status
)) {
2967 gen_ops
[which_op
].success_count
++;
2971 printf("Failed at operation %d - %s\n",
2972 op
, gen_ops
[which_op
].name
);
2976 if (op
% 100 == 0) {
2981 for (i
=0;i
<ARRAY_SIZE(gen_ops
);i
++) {
2982 printf("Op %-10s got %d/%d success\n",
2984 gen_ops
[i
].success_count
,
2992 perform a backtracking analysis of the minimal set of operations
2993 to generate an error
2995 static void backtrack_analyze(struct tevent_context
*ev
,
2996 struct loadparm_context
*lp_ctx
)
2999 const char *mismatch
= current_op
.mismatch
;
3001 chunk
= options
.numops
/ 2;
3006 chunk
> 0 && base
+chunk
< options
.numops
&& options
.numops
> 1; ) {
3009 chunk
= MIN(chunk
, options
.numops
/ 2);
3011 /* mark this range as disabled */
3012 max
= MIN(options
.numops
, base
+chunk
);
3013 for (i
=base
;i
<max
; i
++) {
3014 op_parms
[i
].disabled
= true;
3016 printf("Testing %d ops with %d-%d disabled\n",
3017 options
.numops
, base
, max
-1);
3018 ret
= run_test(ev
, lp_ctx
);
3019 printf("Completed %d of %d ops\n", ret
, options
.numops
);
3020 for (i
=base
;i
<max
; i
++) {
3021 op_parms
[i
].disabled
= false;
3023 if (ret
== options
.numops
) {
3024 /* this chunk is needed */
3026 } else if (mismatch
!= current_op
.mismatch
&&
3027 strcmp(mismatch
, current_op
.mismatch
)) {
3029 printf("Different error in backtracking\n");
3030 } else if (ret
< base
) {
3031 printf("damn - inconsistent errors! found early error\n");
3032 options
.numops
= ret
+1;
3035 /* it failed - this chunk isn't needed for a failure */
3036 memmove(&op_parms
[base
], &op_parms
[max
],
3037 sizeof(op_parms
[0]) * (options
.numops
- max
));
3038 options
.numops
= (ret
+1) - (max
- base
);
3048 if (options
.analyze_continuous
&& chunk
== 0 && options
.numops
!= 1) {
3051 } while (chunk
> 0);
3053 printf("Reduced to %d ops\n", options
.numops
);
3054 ret
= run_test(ev
, lp_ctx
);
3055 if (ret
!= options
.numops
- 1) {
3056 printf("Inconsistent result? ret=%d numops=%d\n", ret
, options
.numops
);
3061 start the main gentest process
3063 static bool start_gentest(struct tevent_context
*ev
,
3064 struct loadparm_context
*lp_ctx
)
3069 /* allocate the open_handles array */
3070 open_handles
= calloc(options
.max_open_handles
, sizeof(open_handles
[0]));
3072 srandom(options
.seed
);
3073 op_parms
= calloc(options
.numops
, sizeof(op_parms
[0]));
3075 /* generate the seeds - after this everything is deterministic */
3076 if (options
.use_preset_seeds
) {
3078 char **preset
= file_lines_load(options
.seeds_file
, &numops
, 0, NULL
);
3080 printf("Failed to load %s - %s\n", options
.seeds_file
, strerror(errno
));
3083 if (numops
< options
.numops
) {
3084 options
.numops
= numops
;
3086 for (op
=0;op
<options
.numops
;op
++) {
3088 printf("Not enough seeds in %s\n", options
.seeds_file
);
3091 op_parms
[op
].seed
= atoi(preset
[op
]);
3093 printf("Loaded %d seeds from %s\n", options
.numops
, options
.seeds_file
);
3095 for (op
=0; op
<options
.numops
; op
++) {
3096 op_parms
[op
].seed
= random();
3100 ret
= run_test(ev
, lp_ctx
);
3102 if (ret
!= options
.numops
&& options
.analyze
) {
3103 options
.numops
= ret
+1;
3104 backtrack_analyze(ev
, lp_ctx
);
3105 } else if (options
.analyze_always
) {
3106 backtrack_analyze(ev
, lp_ctx
);
3107 } else if (options
.analyze_continuous
) {
3108 while (run_test(ev
, lp_ctx
) == options
.numops
) ;
3111 return ret
== options
.numops
;
3115 static void usage(poptContext pc
)
3119 gentest //server1/share1 //server2/share2 [options..]\n\
3121 poptPrintUsage(pc
, stdout
, 0);
3125 split a UNC name into server and share names
3127 static bool split_unc_name(const char *unc
, char **server
, char **share
)
3129 char *p
= strdup(unc
);
3130 if (!p
) return false;
3131 all_string_sub(p
, "\\", "/", 0);
3132 if (strncmp(p
, "//", 2) != 0) return false;
3135 p
= strchr(*server
, '/');
3136 if (!p
) return false;
3146 /****************************************************************************
3148 ****************************************************************************/
3149 int main(int argc
, char *argv
[])
3152 int i
, username_count
=0;
3154 char *ignore_file
=NULL
;
3155 struct tevent_context
*ev
;
3156 struct loadparm_context
*lp_ctx
;
3160 enum {OPT_UNCLIST
=1000};
3161 struct poptOption long_options
[] = {
3163 {"smb2", 0, POPT_ARG_NONE
, &options
.smb2
, 0, "use SMB2 protocol", NULL
},
3164 {"seed", 0, POPT_ARG_INT
, &options
.seed
, 0, "Seed to use for randomizer", NULL
},
3165 {"num-ops", 0, POPT_ARG_INT
, &options
.numops
, 0, "num ops", NULL
},
3166 {"oplocks", 0, POPT_ARG_NONE
, &options
.use_oplocks
,0, "use oplocks", NULL
},
3167 {"showall", 0, POPT_ARG_NONE
, &options
.showall
, 0, "display all operations", NULL
},
3168 {"analyse", 0, POPT_ARG_NONE
, &options
.analyze
, 0, "do backtrack analysis", NULL
},
3169 {"analysealways", 0, POPT_ARG_NONE
, &options
.analyze_always
, 0, "analysis always", NULL
},
3170 {"analysecontinuous", 0, POPT_ARG_NONE
, &options
.analyze_continuous
, 0, "analysis continuous", NULL
},
3171 {"ignore", 0, POPT_ARG_STRING
, &ignore_file
, 0, "ignore from file", NULL
},
3172 {"preset", 0, POPT_ARG_NONE
, &options
.use_preset_seeds
, 0, "use preset seeds", NULL
},
3173 {"fast", 0, POPT_ARG_NONE
, &options
.fast_reconnect
, 0, "use fast reconnect", NULL
},
3174 {"unclist", 0, POPT_ARG_STRING
, NULL
, OPT_UNCLIST
, "unclist", NULL
},
3175 {"seedsfile", 0, POPT_ARG_STRING
, &options
.seeds_file
, 0, "seed file", NULL
},
3176 { "user", 'U', POPT_ARG_STRING
, NULL
, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
3177 {"maskindexing", 0, POPT_ARG_NONE
, &options
.mask_indexing
, 0, "mask out the indexed file attrib", NULL
},
3178 {"noeas", 0, POPT_ARG_NONE
, &options
.no_eas
, 0, "don't use extended attributes", NULL
},
3179 {"noacls", 0, POPT_ARG_NONE
, &options
.no_acls
, 0, "don't use ACLs", NULL
},
3180 {"skip-cleanup", 0, POPT_ARG_NONE
, &options
.skip_cleanup
, 0, "don't delete files at start", NULL
},
3181 {"valid", 0, POPT_ARG_NONE
, &options
.valid
, 0, "generate only valid fields", NULL
},
3183 POPT_COMMON_CONNECTION
3184 POPT_COMMON_CREDENTIALS
3189 memset(&bad_smb2_handle
, 0xFF, sizeof(bad_smb2_handle
));
3192 options
.seed
= time(NULL
);
3193 options
.numops
= 1000;
3194 options
.max_open_handles
= 20;
3195 options
.seeds_file
= "gentest_seeds.dat";
3197 pc
= poptGetContext("gentest", argc
, (const char **) argv
, long_options
,
3198 POPT_CONTEXT_KEEP_FIRST
);
3200 poptSetOtherOptionHelp(pc
, "<unc1> <unc2>");
3202 lp_ctx
= cmdline_lp_ctx
;
3203 servers
[0].credentials
= cli_credentials_init(talloc_autofree_context());
3204 servers
[1].credentials
= cli_credentials_init(talloc_autofree_context());
3205 cli_credentials_guess(servers
[0].credentials
, lp_ctx
);
3206 cli_credentials_guess(servers
[1].credentials
, lp_ctx
);
3208 while((opt
= poptGetNextOpt(pc
)) != -1) {
3211 lpcfg_set_cmdline(cmdline_lp_ctx
, "torture:unclist", poptGetOptArg(pc
));
3214 if (username_count
== 2) {
3218 cli_credentials_parse_string(servers
[username_count
].credentials
, poptGetOptArg(pc
), CRED_SPECIFIED
);
3225 options
.ignore_patterns
= file_lines_load(ignore_file
, NULL
, 0, NULL
);
3228 argv_new
= discard_const_p(char *, poptGetArgs(pc
));
3230 for (i
=0; i
<argc
; i
++) {
3231 if (argv_new
[i
] == NULL
) {
3237 if (!(argc_new
>= 3)) {
3244 setup_logging("gentest", DEBUG_STDOUT
);
3246 if (argc
< 3 || argv
[1][0] == '-') {
3251 setup_logging(argv
[0], DEBUG_STDOUT
);
3253 for (i
=0;i
<NSERVERS
;i
++) {
3254 const char *share
= argv
[1+i
];
3255 if (!split_unc_name(share
, &servers
[i
].server_name
, &servers
[i
].share_name
)) {
3256 printf("Invalid share name '%s'\n", share
);
3261 if (username_count
== 0) {
3265 if (username_count
== 1) {
3266 servers
[1].credentials
= servers
[0].credentials
;
3269 printf("seed=%u\n", options
.seed
);
3271 ev
= s4_event_context_init(talloc_autofree_context());
3275 ret
= start_gentest(ev
, lp_ctx
);
3278 printf("gentest completed - no errors\n");
3280 printf("gentest failed\n");