2 Unix SMB/CIFS implementation.
3 test suite for various lock operations
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "torture/torture.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "system/time.h"
25 #include "system/filesys.h"
26 #include "libcli/libcli.h"
27 #include "torture/util.h"
28 #include "libcli/composite/composite.h"
29 #include "libcli/smb_composite/smb_composite.h"
30 #include "lib/cmdline/popt_common.h"
32 #define CHECK_STATUS(status, correct) do { \
33 if (!NT_STATUS_EQUAL(status, correct)) { \
34 printf("(%s) Incorrect status %s - should be %s\n", \
35 __location__, nt_errstr(status), nt_errstr(correct)); \
40 #define CHECK_VALUE(v, correct) do { \
41 if ((v) != (correct)) { \
42 printf("(%s) Incorrect value %s=%d - should be %d\n", \
43 __location__, #v, v, correct); \
48 #define BASEDIR "\\testlock"
52 test SMBlock and SMBunlock ops
54 static BOOL test_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
60 const char *fname = BASEDIR "\\test.txt";
62 if (!torture_setup_dir(cli, BASEDIR)) {
66 printf("Testing RAW_LOCK_LOCK\n");
67 io.generic.level = RAW_LOCK_LOCK;
69 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
71 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
76 printf("Trying 0/0 lock\n");
77 io.lock.level = RAW_LOCK_LOCK;
78 io.lock.in.file.fnum = fnum;
80 io.lock.in.offset = 0;
81 status = smb_raw_lock(cli->tree, &io);
82 CHECK_STATUS(status, NT_STATUS_OK);
84 status = smb_raw_lock(cli->tree, &io);
85 CHECK_STATUS(status, NT_STATUS_OK);
87 io.lock.level = RAW_LOCK_UNLOCK;
88 status = smb_raw_lock(cli->tree, &io);
89 CHECK_STATUS(status, NT_STATUS_OK);
91 printf("Trying 0/1 lock\n");
92 io.lock.level = RAW_LOCK_LOCK;
93 io.lock.in.file.fnum = fnum;
95 io.lock.in.offset = 0;
96 status = smb_raw_lock(cli->tree, &io);
97 CHECK_STATUS(status, NT_STATUS_OK);
99 status = smb_raw_lock(cli->tree, &io);
100 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
102 io.lock.level = RAW_LOCK_UNLOCK;
103 status = smb_raw_lock(cli->tree, &io);
104 CHECK_STATUS(status, NT_STATUS_OK);
105 io.lock.level = RAW_LOCK_UNLOCK;
106 status = smb_raw_lock(cli->tree, &io);
107 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
109 printf("Trying 0xEEFFFFFF lock\n");
110 io.lock.level = RAW_LOCK_LOCK;
111 io.lock.in.file.fnum = fnum;
112 io.lock.in.count = 4000;
113 io.lock.in.offset = 0xEEFFFFFF;
114 status = smb_raw_lock(cli->tree, &io);
115 CHECK_STATUS(status, NT_STATUS_OK);
117 status = smb_raw_lock(cli->tree, &io);
118 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
120 io.lock.level = RAW_LOCK_UNLOCK;
121 status = smb_raw_lock(cli->tree, &io);
122 CHECK_STATUS(status, NT_STATUS_OK);
123 io.lock.level = RAW_LOCK_UNLOCK;
124 status = smb_raw_lock(cli->tree, &io);
125 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
127 printf("Trying 0xEF000000 lock\n");
128 io.lock.level = RAW_LOCK_LOCK;
129 io.lock.in.file.fnum = fnum;
130 io.lock.in.count = 4000;
131 io.lock.in.offset = 0xEEFFFFFF;
132 status = smb_raw_lock(cli->tree, &io);
133 CHECK_STATUS(status, NT_STATUS_OK);
135 status = smb_raw_lock(cli->tree, &io);
136 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
138 io.lock.level = RAW_LOCK_UNLOCK;
139 status = smb_raw_lock(cli->tree, &io);
140 CHECK_STATUS(status, NT_STATUS_OK);
141 io.lock.level = RAW_LOCK_UNLOCK;
142 status = smb_raw_lock(cli->tree, &io);
143 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
145 printf("Trying max lock\n");
146 io.lock.level = RAW_LOCK_LOCK;
147 io.lock.in.file.fnum = fnum;
148 io.lock.in.count = 4000;
149 io.lock.in.offset = 0xEF000000;
150 status = smb_raw_lock(cli->tree, &io);
151 CHECK_STATUS(status, NT_STATUS_OK);
153 status = smb_raw_lock(cli->tree, &io);
154 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
156 io.lock.level = RAW_LOCK_UNLOCK;
157 status = smb_raw_lock(cli->tree, &io);
158 CHECK_STATUS(status, NT_STATUS_OK);
159 io.lock.level = RAW_LOCK_UNLOCK;
160 status = smb_raw_lock(cli->tree, &io);
161 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
163 printf("Trying wrong pid unlock\n");
164 io.lock.level = RAW_LOCK_LOCK;
165 io.lock.in.file.fnum = fnum;
166 io.lock.in.count = 4002;
167 io.lock.in.offset = 10001;
168 status = smb_raw_lock(cli->tree, &io);
169 CHECK_STATUS(status, NT_STATUS_OK);
171 io.lock.level = RAW_LOCK_UNLOCK;
172 status = smb_raw_lock(cli->tree, &io);
173 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
175 status = smb_raw_lock(cli->tree, &io);
176 CHECK_STATUS(status, NT_STATUS_OK);
179 smbcli_close(cli->tree, fnum);
180 smb_raw_exit(cli->session);
181 smbcli_deltree(cli->tree, BASEDIR);
189 static BOOL test_lockx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
192 struct smb_lock_entry lock[1];
196 const char *fname = BASEDIR "\\test.txt";
198 if (!torture_setup_dir(cli, BASEDIR)) {
202 printf("Testing RAW_LOCK_LOCKX\n");
203 io.generic.level = RAW_LOCK_LOCKX;
205 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
207 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
212 io.lockx.level = RAW_LOCK_LOCKX;
213 io.lockx.in.file.fnum = fnum;
214 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
215 io.lockx.in.timeout = 0;
216 io.lockx.in.ulock_cnt = 0;
217 io.lockx.in.lock_cnt = 1;
218 lock[0].pid = cli->session->pid;
221 io.lockx.in.locks = &lock[0];
222 status = smb_raw_lock(cli->tree, &io);
223 CHECK_STATUS(status, NT_STATUS_OK);
226 printf("Trying 0xEEFFFFFF lock\n");
227 io.lockx.in.ulock_cnt = 0;
228 io.lockx.in.lock_cnt = 1;
229 lock[0].count = 4000;
230 lock[0].offset = 0xEEFFFFFF;
231 status = smb_raw_lock(cli->tree, &io);
232 CHECK_STATUS(status, NT_STATUS_OK);
234 status = smb_raw_lock(cli->tree, &io);
235 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
237 io.lockx.in.ulock_cnt = 1;
238 io.lockx.in.lock_cnt = 0;
239 status = smb_raw_lock(cli->tree, &io);
240 CHECK_STATUS(status, NT_STATUS_OK);
241 status = smb_raw_lock(cli->tree, &io);
242 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
244 printf("Trying 0xEF000000 lock\n");
245 io.lockx.in.ulock_cnt = 0;
246 io.lockx.in.lock_cnt = 1;
247 lock[0].count = 4000;
248 lock[0].offset = 0xEF000000;
249 status = smb_raw_lock(cli->tree, &io);
250 CHECK_STATUS(status, NT_STATUS_OK);
252 status = smb_raw_lock(cli->tree, &io);
253 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
255 io.lockx.in.ulock_cnt = 1;
256 io.lockx.in.lock_cnt = 0;
257 status = smb_raw_lock(cli->tree, &io);
258 CHECK_STATUS(status, NT_STATUS_OK);
259 status = smb_raw_lock(cli->tree, &io);
260 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
262 printf("Trying zero lock\n");
263 io.lockx.in.ulock_cnt = 0;
264 io.lockx.in.lock_cnt = 1;
267 status = smb_raw_lock(cli->tree, &io);
268 CHECK_STATUS(status, NT_STATUS_OK);
270 status = smb_raw_lock(cli->tree, &io);
271 CHECK_STATUS(status, NT_STATUS_OK);
273 io.lockx.in.ulock_cnt = 1;
274 io.lockx.in.lock_cnt = 0;
275 status = smb_raw_lock(cli->tree, &io);
276 CHECK_STATUS(status, NT_STATUS_OK);
277 status = smb_raw_lock(cli->tree, &io);
278 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
280 printf("Trying max lock\n");
281 io.lockx.in.ulock_cnt = 0;
282 io.lockx.in.lock_cnt = 1;
285 status = smb_raw_lock(cli->tree, &io);
286 CHECK_STATUS(status, NT_STATUS_OK);
288 status = smb_raw_lock(cli->tree, &io);
289 CHECK_STATUS(status, NT_STATUS_OK);
291 io.lockx.in.ulock_cnt = 1;
292 io.lockx.in.lock_cnt = 0;
293 status = smb_raw_lock(cli->tree, &io);
294 CHECK_STATUS(status, NT_STATUS_OK);
295 status = smb_raw_lock(cli->tree, &io);
296 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
298 printf("Trying 2^63\n");
299 io.lockx.in.ulock_cnt = 0;
300 io.lockx.in.lock_cnt = 1;
303 lock[0].offset <<= 63;
304 status = smb_raw_lock(cli->tree, &io);
305 CHECK_STATUS(status, NT_STATUS_OK);
307 status = smb_raw_lock(cli->tree, &io);
308 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
310 io.lockx.in.ulock_cnt = 1;
311 io.lockx.in.lock_cnt = 0;
312 status = smb_raw_lock(cli->tree, &io);
313 CHECK_STATUS(status, NT_STATUS_OK);
314 status = smb_raw_lock(cli->tree, &io);
315 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
317 printf("Trying 2^63 - 1\n");
318 io.lockx.in.ulock_cnt = 0;
319 io.lockx.in.lock_cnt = 1;
322 lock[0].offset <<= 63;
324 status = smb_raw_lock(cli->tree, &io);
325 CHECK_STATUS(status, NT_STATUS_OK);
327 status = smb_raw_lock(cli->tree, &io);
328 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
330 io.lockx.in.ulock_cnt = 1;
331 io.lockx.in.lock_cnt = 0;
332 status = smb_raw_lock(cli->tree, &io);
333 CHECK_STATUS(status, NT_STATUS_OK);
334 status = smb_raw_lock(cli->tree, &io);
335 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
337 printf("Trying max lock 2\n");
338 io.lockx.in.ulock_cnt = 0;
339 io.lockx.in.lock_cnt = 1;
342 status = smb_raw_lock(cli->tree, &io);
343 CHECK_STATUS(status, NT_STATUS_OK);
346 status = smb_raw_lock(cli->tree, &io);
347 CHECK_STATUS(status, NT_STATUS_OK);
349 io.lockx.in.ulock_cnt = 1;
350 io.lockx.in.lock_cnt = 0;
352 status = smb_raw_lock(cli->tree, &io);
353 CHECK_STATUS(status, NT_STATUS_OK);
354 status = smb_raw_lock(cli->tree, &io);
355 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
358 smbcli_close(cli->tree, fnum);
359 smb_raw_exit(cli->session);
360 smbcli_deltree(cli->tree, BASEDIR);
368 static BOOL test_pidhigh(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
371 struct smb_lock_entry lock[1];
375 const char *fname = BASEDIR "\\test.txt";
378 if (!torture_setup_dir(cli, BASEDIR)) {
382 printf("Testing high pid\n");
383 io.generic.level = RAW_LOCK_LOCKX;
385 cli->session->pid = 1;
387 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
389 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
394 if (smbcli_write(cli->tree, fnum, 0, &c, 0, 1) != 1) {
395 printf("Failed to write 1 byte - %s\n", smbcli_errstr(cli->tree));
400 io.lockx.level = RAW_LOCK_LOCKX;
401 io.lockx.in.file.fnum = fnum;
402 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
403 io.lockx.in.timeout = 0;
404 io.lockx.in.ulock_cnt = 0;
405 io.lockx.in.lock_cnt = 1;
406 lock[0].pid = cli->session->pid;
408 lock[0].count = 0xFFFFFFFF;
409 io.lockx.in.locks = &lock[0];
410 status = smb_raw_lock(cli->tree, &io);
411 CHECK_STATUS(status, NT_STATUS_OK);
413 if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
414 printf("Failed to read 1 byte - %s\n", smbcli_errstr(cli->tree));
419 cli->session->pid |= 0x10000;
421 cli->session->pid = 2;
423 if (smbcli_read(cli->tree, fnum, &c, 0, 1) == 1) {
424 printf("pid is incorrect handled for read with lock!\n");
429 cli->session->pid = 0x10001;
431 if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
432 printf("High pid is used on this server!\n");
435 printf("High pid is not used on this server (correct)\n");
439 smbcli_close(cli->tree, fnum);
440 smb_raw_exit(cli->session);
441 smbcli_deltree(cli->tree, BASEDIR);
447 test locking&X async operation
449 static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
451 struct smbcli_session *session;
452 struct smb_composite_sesssetup setup;
453 struct smbcli_tree *tree;
455 const char *host, *share;
457 struct smb_lock_entry lock[2];
461 const char *fname = BASEDIR "\\test.txt";
463 struct smbcli_request *req;
465 if (lp_parm_bool(-1, "target", "samba3", False)) {
466 printf("SAMBA3: ignore testing LOCKING_ANDX_CANCEL_LOCK...\n");
470 if (!torture_setup_dir(cli, BASEDIR)) {
474 printf("Testing LOCKING_ANDX_CANCEL_LOCK\n");
475 io.generic.level = RAW_LOCK_LOCKX;
477 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
479 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
484 io.lockx.level = RAW_LOCK_LOCKX;
485 io.lockx.in.file.fnum = fnum;
486 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
487 io.lockx.in.timeout = 0;
488 io.lockx.in.ulock_cnt = 0;
489 io.lockx.in.lock_cnt = 1;
490 lock[0].pid = cli->session->pid;
491 lock[0].offset = 100;
493 io.lockx.in.locks = &lock[0];
494 status = smb_raw_lock(cli->tree, &io);
495 CHECK_STATUS(status, NT_STATUS_OK);
499 printf("testing cancel by CANCEL_LOCK\n");
501 /* setup a timed lock */
502 io.lockx.in.timeout = 10000;
503 req = smb_raw_lock_send(cli->tree, &io);
505 printf("Failed to setup timed lock (%s)\n", __location__);
510 /* cancel the wrong range */
512 io.lockx.in.timeout = 0;
513 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK;
514 status = smb_raw_lock(cli->tree, &io);
515 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRcancelviolation));
517 /* cancel with the wrong bits set */
518 lock[0].offset = 100;
519 io.lockx.in.timeout = 0;
520 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK;
521 status = smb_raw_lock(cli->tree, &io);
522 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRcancelviolation));
524 /* cancel the right range */
525 lock[0].offset = 100;
526 io.lockx.in.timeout = 0;
527 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
528 status = smb_raw_lock(cli->tree, &io);
529 CHECK_STATUS(status, NT_STATUS_OK);
531 /* receive the failed lock request */
532 status = smbcli_request_simple_recv(req);
533 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
535 if (time(NULL) > t+2) {
536 printf("lock cancel was not immediate (%s)\n", __location__);
541 printf("testing cancel by unlock\n");
542 io.lockx.in.ulock_cnt = 0;
543 io.lockx.in.lock_cnt = 1;
544 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
545 io.lockx.in.timeout = 0;
546 status = smb_raw_lock(cli->tree, &io);
547 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
549 io.lockx.in.timeout = 5000;
550 req = smb_raw_lock_send(cli->tree, &io);
552 printf("Failed to setup timed lock (%s)\n", __location__);
557 io.lockx.in.ulock_cnt = 1;
558 io.lockx.in.lock_cnt = 0;
559 status = smb_raw_lock(cli->tree, &io);
560 CHECK_STATUS(status, NT_STATUS_OK);
563 status = smbcli_request_simple_recv(req);
564 CHECK_STATUS(status, NT_STATUS_OK);
566 if (time(NULL) > t+2) {
567 printf("lock cancel by unlock was not immediate (%s) - took %d secs\n",
568 __location__, (int)(time(NULL)-t));
573 printf("testing cancel by close\n");
574 io.lockx.in.ulock_cnt = 0;
575 io.lockx.in.lock_cnt = 1;
576 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
577 io.lockx.in.timeout = 0;
578 status = smb_raw_lock(cli->tree, &io);
579 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
582 io.lockx.in.timeout = 10000;
583 req = smb_raw_lock_send(cli->tree, &io);
585 printf("Failed to setup timed lock (%s)\n", __location__);
590 status = smbcli_close(cli->tree, fnum);
591 CHECK_STATUS(status, NT_STATUS_OK);
593 status = smbcli_request_simple_recv(req);
594 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
596 if (time(NULL) > t+2) {
597 printf("lock cancel by close was not immediate (%s)\n", __location__);
602 printf("create a new sessions\n");
603 session = smbcli_session_init(cli->transport, mem_ctx, False);
604 setup.in.sesskey = cli->transport->negotiate.sesskey;
605 setup.in.capabilities = cli->transport->negotiate.capabilities;
606 setup.in.workgroup = lp_workgroup();
607 setup.in.credentials = cmdline_credentials;
608 status = smb_composite_sesssetup(session, &setup);
609 CHECK_STATUS(status, NT_STATUS_OK);
610 session->vuid = setup.out.vuid;
612 printf("create new tree context\n");
613 share = lp_parm_string(-1, "torture", "share");
614 host = lp_parm_string(-1, "torture", "host");
615 tree = smbcli_tree_init(session, mem_ctx, False);
616 tcon.generic.level = RAW_TCON_TCONX;
617 tcon.tconx.in.flags = 0;
618 tcon.tconx.in.password = data_blob(NULL, 0);
619 tcon.tconx.in.path = talloc_asprintf(mem_ctx, "\\\\%s\\%s", host, share);
620 tcon.tconx.in.device = "A:";
621 status = smb_raw_tcon(tree, mem_ctx, &tcon);
622 CHECK_STATUS(status, NT_STATUS_OK);
623 tree->tid = tcon.tconx.out.tid;
625 printf("testing cancel by exit\n");
626 fname = BASEDIR "\\test_exit.txt";
627 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
629 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
633 io.lockx.level = RAW_LOCK_LOCKX;
634 io.lockx.in.file.fnum = fnum;
635 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
636 io.lockx.in.timeout = 0;
637 io.lockx.in.ulock_cnt = 0;
638 io.lockx.in.lock_cnt = 1;
639 lock[0].pid = session->pid;
640 lock[0].offset = 100;
642 io.lockx.in.locks = &lock[0];
643 status = smb_raw_lock(tree, &io);
644 CHECK_STATUS(status, NT_STATUS_OK);
646 io.lockx.in.ulock_cnt = 0;
647 io.lockx.in.lock_cnt = 1;
648 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
649 io.lockx.in.timeout = 0;
650 status = smb_raw_lock(tree, &io);
651 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
653 io.lockx.in.timeout = 10000;
655 req = smb_raw_lock_send(tree, &io);
657 printf("Failed to setup timed lock (%s)\n", __location__);
662 status = smb_raw_exit(session);
663 CHECK_STATUS(status, NT_STATUS_OK);
665 status = smbcli_request_simple_recv(req);
666 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
668 if (time(NULL) > t+2) {
669 printf("lock cancel by exit was not immediate (%s)\n", __location__);
674 printf("testing cancel by ulogoff\n");
675 fname = BASEDIR "\\test_ulogoff.txt";
676 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
678 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
682 io.lockx.level = RAW_LOCK_LOCKX;
683 io.lockx.in.file.fnum = fnum;
684 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
685 io.lockx.in.timeout = 0;
686 io.lockx.in.ulock_cnt = 0;
687 io.lockx.in.lock_cnt = 1;
688 lock[0].pid = session->pid;
689 lock[0].offset = 100;
691 io.lockx.in.locks = &lock[0];
692 status = smb_raw_lock(tree, &io);
693 CHECK_STATUS(status, NT_STATUS_OK);
695 io.lockx.in.ulock_cnt = 0;
696 io.lockx.in.lock_cnt = 1;
697 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
698 io.lockx.in.timeout = 0;
699 status = smb_raw_lock(tree, &io);
700 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
702 io.lockx.in.timeout = 10000;
704 req = smb_raw_lock_send(tree, &io);
706 printf("Failed to setup timed lock (%s)\n", __location__);
711 status = smb_raw_ulogoff(session);
712 CHECK_STATUS(status, NT_STATUS_OK);
714 status = smbcli_request_simple_recv(req);
715 if (NT_STATUS_EQUAL(NT_STATUS_FILE_LOCK_CONFLICT, status)) {
716 printf("lock not canceled by ulogoff - %s (ignored because of vfs_vifs fails it)\n",
718 smb_tree_disconnect(tree);
719 smb_raw_exit(session);
722 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
724 if (time(NULL) > t+2) {
725 printf("lock cancel by ulogoff was not immediate (%s)\n", __location__);
730 printf("testing cancel by tdis\n");
731 tree->session = cli->session;
733 fname = BASEDIR "\\test_tdis.txt";
734 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
736 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
740 io.lockx.level = RAW_LOCK_LOCKX;
741 io.lockx.in.file.fnum = fnum;
742 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
743 io.lockx.in.timeout = 0;
744 io.lockx.in.ulock_cnt = 0;
745 io.lockx.in.lock_cnt = 1;
746 lock[0].pid = cli->session->pid;
747 lock[0].offset = 100;
749 io.lockx.in.locks = &lock[0];
750 status = smb_raw_lock(tree, &io);
751 CHECK_STATUS(status, NT_STATUS_OK);
753 status = smb_raw_lock(tree, &io);
754 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
756 io.lockx.in.timeout = 10000;
758 req = smb_raw_lock_send(tree, &io);
760 printf("Failed to setup timed lock (%s)\n", __location__);
765 status = smb_tree_disconnect(tree);
766 CHECK_STATUS(status, NT_STATUS_OK);
768 status = smbcli_request_simple_recv(req);
769 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
771 if (time(NULL) > t+2) {
772 printf("lock cancel by tdis was not immediate (%s)\n", __location__);
778 smb_raw_exit(cli->session);
779 smbcli_deltree(cli->tree, BASEDIR);
784 test NT_STATUS_LOCK_NOT_GRANTED vs. NT_STATUS_FILE_LOCK_CONFLICT
786 static BOOL test_errorcode(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
790 struct smb_lock_entry lock[2];
795 struct smbcli_request *req;
799 if (lp_parm_bool(-1, "target", "samba3", False)) {
800 printf("SAMBA3: ignore testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT...\n");
804 if (!torture_setup_dir(cli, BASEDIR)) {
808 printf("Testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT\n");
810 printf("testing with timeout = 0\n");
811 fname = BASEDIR "\\test0.txt";
815 * the first run is with t = 0,
816 * the second with t > 0 (=1)
820 * use the DENY_DOS mode, that creates two fnum's of one low-level file handle,
821 * this demonstrates that the cache is per fnum
823 op.openx.level = RAW_OPEN_OPENX;
824 op.openx.in.fname = fname;
825 op.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
826 op.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_DOS;
827 op.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
828 op.openx.in.search_attrs = 0;
829 op.openx.in.file_attrs = 0;
830 op.openx.in.write_time = 0;
831 op.openx.in.size = 0;
832 op.openx.in.timeout = 0;
834 status = smb_raw_open(cli->tree, mem_ctx, &op);
835 CHECK_STATUS(status, NT_STATUS_OK);
836 fnum = op.openx.out.file.fnum;
838 status = smb_raw_open(cli->tree, mem_ctx, &op);
839 CHECK_STATUS(status, NT_STATUS_OK);
840 fnum2 = op.openx.out.file.fnum;
842 io.lockx.level = RAW_LOCK_LOCKX;
843 io.lockx.in.file.fnum = fnum;
844 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
845 io.lockx.in.timeout = t;
846 io.lockx.in.ulock_cnt = 0;
847 io.lockx.in.lock_cnt = 1;
848 lock[0].pid = cli->session->pid;
849 lock[0].offset = 100;
851 io.lockx.in.locks = &lock[0];
852 status = smb_raw_lock(cli->tree, &io);
853 CHECK_STATUS(status, NT_STATUS_OK);
856 * demonstrate that the first conflicting lock on each handle give LOCK_NOT_GRANTED
857 * this also demonstrates that the error code cache is per file handle
858 * (LOCK_NOT_GRANTED is only be used when timeout is 0!)
860 io.lockx.in.file.fnum = fnum2;
861 status = smb_raw_lock(cli->tree, &io);
862 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
864 io.lockx.in.file.fnum = fnum;
865 status = smb_raw_lock(cli->tree, &io);
866 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
868 /* demonstrate that each following conflict gives FILE_LOCK_CONFLICT */
869 io.lockx.in.file.fnum = fnum;
870 status = smb_raw_lock(cli->tree, &io);
871 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
873 io.lockx.in.file.fnum = fnum2;
874 status = smb_raw_lock(cli->tree, &io);
875 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
877 io.lockx.in.file.fnum = fnum;
878 status = smb_raw_lock(cli->tree, &io);
879 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
881 io.lockx.in.file.fnum = fnum2;
882 status = smb_raw_lock(cli->tree, &io);
883 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
885 /* demonstrate that the smbpid doesn't matter */
887 io.lockx.in.file.fnum = fnum;
888 status = smb_raw_lock(cli->tree, &io);
889 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
891 io.lockx.in.file.fnum = fnum2;
892 status = smb_raw_lock(cli->tree, &io);
893 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
897 * demonstrate the a successful lock with count = 0 and the same offset,
898 * doesn't reset the error cache
900 lock[0].offset = 100;
902 io.lockx.in.file.fnum = fnum;
903 status = smb_raw_lock(cli->tree, &io);
904 CHECK_STATUS(status, NT_STATUS_OK);
906 io.lockx.in.file.fnum = fnum2;
907 status = smb_raw_lock(cli->tree, &io);
908 CHECK_STATUS(status, NT_STATUS_OK);
910 lock[0].offset = 100;
912 io.lockx.in.file.fnum = fnum;
913 status = smb_raw_lock(cli->tree, &io);
914 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
916 io.lockx.in.file.fnum = fnum2;
917 status = smb_raw_lock(cli->tree, &io);
918 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
921 * demonstrate the a successful lock with count = 0 and outside the locked range,
922 * doesn't reset the error cache
924 lock[0].offset = 110;
926 io.lockx.in.file.fnum = fnum;
927 status = smb_raw_lock(cli->tree, &io);
928 CHECK_STATUS(status, NT_STATUS_OK);
930 io.lockx.in.file.fnum = fnum2;
931 status = smb_raw_lock(cli->tree, &io);
932 CHECK_STATUS(status, NT_STATUS_OK);
934 lock[0].offset = 100;
936 io.lockx.in.file.fnum = fnum;
937 status = smb_raw_lock(cli->tree, &io);
938 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
940 io.lockx.in.file.fnum = fnum2;
941 status = smb_raw_lock(cli->tree, &io);
942 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
946 io.lockx.in.file.fnum = fnum;
947 status = smb_raw_lock(cli->tree, &io);
948 CHECK_STATUS(status, NT_STATUS_OK);
950 io.lockx.in.file.fnum = fnum2;
951 status = smb_raw_lock(cli->tree, &io);
952 CHECK_STATUS(status, NT_STATUS_OK);
954 lock[0].offset = 100;
956 io.lockx.in.file.fnum = fnum;
957 status = smb_raw_lock(cli->tree, &io);
958 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
960 io.lockx.in.file.fnum = fnum2;
961 status = smb_raw_lock(cli->tree, &io);
962 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
964 /* demonstrate that a changing count doesn't reset the error cache */
965 lock[0].offset = 100;
967 io.lockx.in.file.fnum = fnum;
968 status = smb_raw_lock(cli->tree, &io);
969 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
971 io.lockx.in.file.fnum = fnum2;
972 status = smb_raw_lock(cli->tree, &io);
973 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
975 lock[0].offset = 100;
977 io.lockx.in.file.fnum = fnum;
978 status = smb_raw_lock(cli->tree, &io);
979 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
981 io.lockx.in.file.fnum = fnum2;
982 status = smb_raw_lock(cli->tree, &io);
983 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
986 * demonstrate the a lock with count = 0 and inside the locked range,
987 * fails and resets the error cache
989 lock[0].offset = 101;
991 io.lockx.in.file.fnum = fnum;
992 status = smb_raw_lock(cli->tree, &io);
993 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
994 status = smb_raw_lock(cli->tree, &io);
995 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
997 io.lockx.in.file.fnum = fnum2;
998 status = smb_raw_lock(cli->tree, &io);
999 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1000 status = smb_raw_lock(cli->tree, &io);
1001 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1003 lock[0].offset = 100;
1005 io.lockx.in.file.fnum = fnum;
1006 status = smb_raw_lock(cli->tree, &io);
1007 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1008 status = smb_raw_lock(cli->tree, &io);
1009 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1011 io.lockx.in.file.fnum = fnum2;
1012 status = smb_raw_lock(cli->tree, &io);
1013 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1014 status = smb_raw_lock(cli->tree, &io);
1015 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1017 /* demonstrate the a changing offset, resets the error cache */
1018 lock[0].offset = 105;
1020 io.lockx.in.file.fnum = fnum;
1021 status = smb_raw_lock(cli->tree, &io);
1022 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1023 status = smb_raw_lock(cli->tree, &io);
1024 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1026 io.lockx.in.file.fnum = fnum2;
1027 status = smb_raw_lock(cli->tree, &io);
1028 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1029 status = smb_raw_lock(cli->tree, &io);
1030 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1032 lock[0].offset = 100;
1034 io.lockx.in.file.fnum = fnum;
1035 status = smb_raw_lock(cli->tree, &io);
1036 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1037 status = smb_raw_lock(cli->tree, &io);
1038 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1040 io.lockx.in.file.fnum = fnum2;
1041 status = smb_raw_lock(cli->tree, &io);
1042 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1043 status = smb_raw_lock(cli->tree, &io);
1044 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1046 lock[0].offset = 95;
1048 io.lockx.in.file.fnum = fnum;
1049 status = smb_raw_lock(cli->tree, &io);
1050 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1051 status = smb_raw_lock(cli->tree, &io);
1052 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1054 io.lockx.in.file.fnum = fnum2;
1055 status = smb_raw_lock(cli->tree, &io);
1056 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1057 status = smb_raw_lock(cli->tree, &io);
1058 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1060 lock[0].offset = 100;
1062 io.lockx.in.file.fnum = fnum;
1063 status = smb_raw_lock(cli->tree, &io);
1064 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1065 status = smb_raw_lock(cli->tree, &io);
1066 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1068 io.lockx.in.file.fnum = fnum2;
1069 status = smb_raw_lock(cli->tree, &io);
1070 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1071 status = smb_raw_lock(cli->tree, &io);
1072 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1075 * demonstrate the a successful lock in a different range,
1076 * doesn't reset the cache, the failing lock on the 2nd handle
1077 * resets the resets the cache
1079 lock[0].offset = 120;
1081 io.lockx.in.file.fnum = fnum;
1082 status = smb_raw_lock(cli->tree, &io);
1083 CHECK_STATUS(status, NT_STATUS_OK);
1085 io.lockx.in.file.fnum = fnum2;
1086 status = smb_raw_lock(cli->tree, &io);
1087 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1089 lock[0].offset = 100;
1091 io.lockx.in.file.fnum = fnum;
1092 status = smb_raw_lock(cli->tree, &io);
1093 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1094 status = smb_raw_lock(cli->tree, &io);
1095 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1097 io.lockx.in.file.fnum = fnum2;
1098 status = smb_raw_lock(cli->tree, &io);
1099 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1100 status = smb_raw_lock(cli->tree, &io);
1101 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1103 /* end of the loop */
1105 smb_raw_exit(cli->session);
1106 printf("testing with timeout > 0 (=1)\n");
1107 fname = BASEDIR "\\test1.txt";
1113 * the following 3 test sections demonstrate that
1114 * the cache is only set when the error is reported
1115 * to the client (after the timeout went by)
1117 smb_raw_exit(cli->session);
1118 printf("testing a conflict while a lock is pending\n");
1119 fname = BASEDIR "\\test2.txt";
1120 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1122 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1126 io.lockx.level = RAW_LOCK_LOCKX;
1127 io.lockx.in.file.fnum = fnum;
1128 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1129 io.lockx.in.timeout = 0;
1130 io.lockx.in.ulock_cnt = 0;
1131 io.lockx.in.lock_cnt = 1;
1132 lock[0].pid = cli->session->pid;
1133 lock[0].offset = 100;
1135 io.lockx.in.locks = &lock[0];
1136 status = smb_raw_lock(cli->tree, &io);
1137 CHECK_STATUS(status, NT_STATUS_OK);
1140 io.lockx.in.timeout = 1000;
1141 req = smb_raw_lock_send(cli->tree, &io);
1143 printf("Failed to setup timed lock (%s)\n", __location__);
1148 io.lockx.in.timeout = 0;
1149 lock[0].offset = 105;
1151 status = smb_raw_lock(cli->tree, &io);
1152 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1154 status = smbcli_request_simple_recv(req);
1155 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1157 status = smb_raw_lock(cli->tree, &io);
1158 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1160 if (time(NULL) < start+1) {
1161 printf("lock comes back to early (%s)\n", __location__);
1166 smbcli_close(cli->tree, fnum);
1167 fname = BASEDIR "\\test3.txt";
1168 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1170 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1174 io.lockx.level = RAW_LOCK_LOCKX;
1175 io.lockx.in.file.fnum = fnum;
1176 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1177 io.lockx.in.timeout = 0;
1178 io.lockx.in.ulock_cnt = 0;
1179 io.lockx.in.lock_cnt = 1;
1180 lock[0].pid = cli->session->pid;
1181 lock[0].offset = 100;
1183 io.lockx.in.locks = &lock[0];
1184 status = smb_raw_lock(cli->tree, &io);
1185 CHECK_STATUS(status, NT_STATUS_OK);
1188 io.lockx.in.timeout = 1000;
1189 req = smb_raw_lock_send(cli->tree, &io);
1191 printf("Failed to setup timed lock (%s)\n", __location__);
1196 io.lockx.in.timeout = 0;
1197 lock[0].offset = 105;
1199 status = smb_raw_lock(cli->tree, &io);
1200 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1202 status = smbcli_request_simple_recv(req);
1203 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1205 lock[0].offset = 100;
1207 status = smb_raw_lock(cli->tree, &io);
1208 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1210 if (time(NULL) < start+1) {
1211 printf("lock comes back to early (%s)\n", __location__);
1216 smbcli_close(cli->tree, fnum);
1217 fname = BASEDIR "\\test4.txt";
1218 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1220 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1224 io.lockx.level = RAW_LOCK_LOCKX;
1225 io.lockx.in.file.fnum = fnum;
1226 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1227 io.lockx.in.timeout = 0;
1228 io.lockx.in.ulock_cnt = 0;
1229 io.lockx.in.lock_cnt = 1;
1230 lock[0].pid = cli->session->pid;
1231 lock[0].offset = 100;
1233 io.lockx.in.locks = &lock[0];
1234 status = smb_raw_lock(cli->tree, &io);
1235 CHECK_STATUS(status, NT_STATUS_OK);
1238 io.lockx.in.timeout = 1000;
1239 req = smb_raw_lock_send(cli->tree, &io);
1241 printf("Failed to setup timed lock (%s)\n", __location__);
1246 io.lockx.in.timeout = 0;
1247 status = smb_raw_lock(cli->tree, &io);
1248 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1250 status = smbcli_request_simple_recv(req);
1251 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1253 status = smb_raw_lock(cli->tree, &io);
1254 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1256 if (time(NULL) < start+1) {
1257 printf("lock comes back to early (%s)\n", __location__);
1263 smb_raw_exit(cli->session);
1264 smbcli_deltree(cli->tree, BASEDIR);
1270 test LOCKING_ANDX_CHANGE_LOCKTYPE
1272 static BOOL test_changetype(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1275 struct smb_lock_entry lock[2];
1280 const char *fname = BASEDIR "\\test.txt";
1282 if (!torture_setup_dir(cli, BASEDIR)) {
1286 printf("Testing LOCKING_ANDX_CHANGE_LOCKTYPE\n");
1287 io.generic.level = RAW_LOCK_LOCKX;
1289 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1291 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1296 io.lockx.level = RAW_LOCK_LOCKX;
1297 io.lockx.in.file.fnum = fnum;
1298 io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
1299 io.lockx.in.timeout = 0;
1300 io.lockx.in.ulock_cnt = 0;
1301 io.lockx.in.lock_cnt = 1;
1302 lock[0].pid = cli->session->pid;
1303 lock[0].offset = 100;
1305 io.lockx.in.locks = &lock[0];
1306 status = smb_raw_lock(cli->tree, &io);
1307 CHECK_STATUS(status, NT_STATUS_OK);
1309 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1310 printf("allowed write on read locked region (%s)\n", __location__);
1315 /* windows server don't seem to support this */
1316 io.lockx.in.mode = LOCKING_ANDX_CHANGE_LOCKTYPE;
1317 status = smb_raw_lock(cli->tree, &io);
1318 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRnoatomiclocks));
1320 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1321 printf("allowed write after lock change (%s)\n", __location__);
1327 smbcli_close(cli->tree, fnum);
1328 smb_raw_exit(cli->session);
1329 smbcli_deltree(cli->tree, BASEDIR);
1335 basic testing of lock calls
1337 BOOL torture_raw_lock(struct torture_context *torture)
1339 struct smbcli_state *cli;
1341 TALLOC_CTX *mem_ctx;
1343 if (!torture_open_connection(&cli)) {
1347 mem_ctx = talloc_init("torture_raw_lock");
1349 ret &= test_lockx(cli, mem_ctx);
1350 ret &= test_lock(cli, mem_ctx);
1351 ret &= test_pidhigh(cli, mem_ctx);
1352 ret &= test_async(cli, mem_ctx);
1353 ret &= test_errorcode(cli, mem_ctx);
1354 ret &= test_changetype(cli, mem_ctx);
1356 torture_close_connection(cli);
1357 talloc_free(mem_ctx);