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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "torture/torture.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/raw/raw_proto.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"
31 #include "param/param.h"
33 #define CHECK_STATUS(status, correct) do { \
34 if (!NT_STATUS_EQUAL(status, correct)) { \
35 printf("(%s) Incorrect status %s - should be %s\n", \
36 __location__, nt_errstr(status), nt_errstr(correct)); \
41 #define BASEDIR "\\testlock"
45 test SMBlock and SMBunlock ops
47 static bool test_lock(struct torture_context *tctx, struct smbcli_state *cli)
53 const char *fname = BASEDIR "\\test.txt";
55 if (!torture_setup_dir(cli, BASEDIR)) {
59 printf("Testing RAW_LOCK_LOCK\n");
60 io.generic.level = RAW_LOCK_LOCK;
62 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
64 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
69 printf("Trying 0/0 lock\n");
70 io.lock.level = RAW_LOCK_LOCK;
71 io.lock.in.file.fnum = fnum;
73 io.lock.in.offset = 0;
74 status = smb_raw_lock(cli->tree, &io);
75 CHECK_STATUS(status, NT_STATUS_OK);
77 status = smb_raw_lock(cli->tree, &io);
78 CHECK_STATUS(status, NT_STATUS_OK);
80 io.lock.level = RAW_LOCK_UNLOCK;
81 status = smb_raw_lock(cli->tree, &io);
82 CHECK_STATUS(status, NT_STATUS_OK);
84 printf("Trying 0/1 lock\n");
85 io.lock.level = RAW_LOCK_LOCK;
86 io.lock.in.file.fnum = fnum;
88 io.lock.in.offset = 0;
89 status = smb_raw_lock(cli->tree, &io);
90 CHECK_STATUS(status, NT_STATUS_OK);
92 status = smb_raw_lock(cli->tree, &io);
93 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
95 io.lock.level = RAW_LOCK_UNLOCK;
96 status = smb_raw_lock(cli->tree, &io);
97 CHECK_STATUS(status, NT_STATUS_OK);
98 io.lock.level = RAW_LOCK_UNLOCK;
99 status = smb_raw_lock(cli->tree, &io);
100 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
102 printf("Trying 0xEEFFFFFF lock\n");
103 io.lock.level = RAW_LOCK_LOCK;
104 io.lock.in.file.fnum = fnum;
105 io.lock.in.count = 4000;
106 io.lock.in.offset = 0xEEFFFFFF;
107 status = smb_raw_lock(cli->tree, &io);
108 CHECK_STATUS(status, NT_STATUS_OK);
110 status = smb_raw_lock(cli->tree, &io);
111 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
113 io.lock.level = RAW_LOCK_UNLOCK;
114 status = smb_raw_lock(cli->tree, &io);
115 CHECK_STATUS(status, NT_STATUS_OK);
116 io.lock.level = RAW_LOCK_UNLOCK;
117 status = smb_raw_lock(cli->tree, &io);
118 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
120 printf("Trying 0xEF000000 lock\n");
121 io.lock.level = RAW_LOCK_LOCK;
122 io.lock.in.file.fnum = fnum;
123 io.lock.in.count = 4000;
124 io.lock.in.offset = 0xEEFFFFFF;
125 status = smb_raw_lock(cli->tree, &io);
126 CHECK_STATUS(status, NT_STATUS_OK);
128 status = smb_raw_lock(cli->tree, &io);
129 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
131 io.lock.level = RAW_LOCK_UNLOCK;
132 status = smb_raw_lock(cli->tree, &io);
133 CHECK_STATUS(status, NT_STATUS_OK);
134 io.lock.level = RAW_LOCK_UNLOCK;
135 status = smb_raw_lock(cli->tree, &io);
136 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
138 printf("Trying max lock\n");
139 io.lock.level = RAW_LOCK_LOCK;
140 io.lock.in.file.fnum = fnum;
141 io.lock.in.count = 4000;
142 io.lock.in.offset = 0xEF000000;
143 status = smb_raw_lock(cli->tree, &io);
144 CHECK_STATUS(status, NT_STATUS_OK);
146 status = smb_raw_lock(cli->tree, &io);
147 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
149 io.lock.level = RAW_LOCK_UNLOCK;
150 status = smb_raw_lock(cli->tree, &io);
151 CHECK_STATUS(status, NT_STATUS_OK);
152 io.lock.level = RAW_LOCK_UNLOCK;
153 status = smb_raw_lock(cli->tree, &io);
154 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
156 printf("Trying wrong pid unlock\n");
157 io.lock.level = RAW_LOCK_LOCK;
158 io.lock.in.file.fnum = fnum;
159 io.lock.in.count = 4002;
160 io.lock.in.offset = 10001;
161 status = smb_raw_lock(cli->tree, &io);
162 CHECK_STATUS(status, NT_STATUS_OK);
164 io.lock.level = RAW_LOCK_UNLOCK;
165 status = smb_raw_lock(cli->tree, &io);
166 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
168 status = smb_raw_lock(cli->tree, &io);
169 CHECK_STATUS(status, NT_STATUS_OK);
172 smbcli_close(cli->tree, fnum);
173 smb_raw_exit(cli->session);
174 smbcli_deltree(cli->tree, BASEDIR);
182 static bool test_lockx(struct torture_context *tctx, struct smbcli_state *cli)
185 struct smb_lock_entry lock[1];
189 const char *fname = BASEDIR "\\test.txt";
191 if (!torture_setup_dir(cli, BASEDIR)) {
195 printf("Testing RAW_LOCK_LOCKX\n");
196 io.generic.level = RAW_LOCK_LOCKX;
198 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
200 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
205 io.lockx.level = RAW_LOCK_LOCKX;
206 io.lockx.in.file.fnum = fnum;
207 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
208 io.lockx.in.timeout = 0;
209 io.lockx.in.ulock_cnt = 0;
210 io.lockx.in.lock_cnt = 1;
211 lock[0].pid = cli->session->pid;
214 io.lockx.in.locks = &lock[0];
215 status = smb_raw_lock(cli->tree, &io);
216 CHECK_STATUS(status, NT_STATUS_OK);
219 printf("Trying 0xEEFFFFFF lock\n");
220 io.lockx.in.ulock_cnt = 0;
221 io.lockx.in.lock_cnt = 1;
222 lock[0].count = 4000;
223 lock[0].offset = 0xEEFFFFFF;
224 status = smb_raw_lock(cli->tree, &io);
225 CHECK_STATUS(status, NT_STATUS_OK);
227 status = smb_raw_lock(cli->tree, &io);
228 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
230 io.lockx.in.ulock_cnt = 1;
231 io.lockx.in.lock_cnt = 0;
232 status = smb_raw_lock(cli->tree, &io);
233 CHECK_STATUS(status, NT_STATUS_OK);
234 status = smb_raw_lock(cli->tree, &io);
235 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
237 printf("Trying 0xEF000000 lock\n");
238 io.lockx.in.ulock_cnt = 0;
239 io.lockx.in.lock_cnt = 1;
240 lock[0].count = 4000;
241 lock[0].offset = 0xEF000000;
242 status = smb_raw_lock(cli->tree, &io);
243 CHECK_STATUS(status, NT_STATUS_OK);
245 status = smb_raw_lock(cli->tree, &io);
246 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
248 io.lockx.in.ulock_cnt = 1;
249 io.lockx.in.lock_cnt = 0;
250 status = smb_raw_lock(cli->tree, &io);
251 CHECK_STATUS(status, NT_STATUS_OK);
252 status = smb_raw_lock(cli->tree, &io);
253 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
255 printf("Trying zero lock\n");
256 io.lockx.in.ulock_cnt = 0;
257 io.lockx.in.lock_cnt = 1;
260 status = smb_raw_lock(cli->tree, &io);
261 CHECK_STATUS(status, NT_STATUS_OK);
263 status = smb_raw_lock(cli->tree, &io);
264 CHECK_STATUS(status, NT_STATUS_OK);
266 io.lockx.in.ulock_cnt = 1;
267 io.lockx.in.lock_cnt = 0;
268 status = smb_raw_lock(cli->tree, &io);
269 CHECK_STATUS(status, NT_STATUS_OK);
270 status = smb_raw_lock(cli->tree, &io);
271 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
273 printf("Trying max lock\n");
274 io.lockx.in.ulock_cnt = 0;
275 io.lockx.in.lock_cnt = 1;
278 status = smb_raw_lock(cli->tree, &io);
279 CHECK_STATUS(status, NT_STATUS_OK);
281 status = smb_raw_lock(cli->tree, &io);
282 CHECK_STATUS(status, NT_STATUS_OK);
284 io.lockx.in.ulock_cnt = 1;
285 io.lockx.in.lock_cnt = 0;
286 status = smb_raw_lock(cli->tree, &io);
287 CHECK_STATUS(status, NT_STATUS_OK);
288 status = smb_raw_lock(cli->tree, &io);
289 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
291 printf("Trying 2^63\n");
292 io.lockx.in.ulock_cnt = 0;
293 io.lockx.in.lock_cnt = 1;
296 lock[0].offset <<= 63;
297 status = smb_raw_lock(cli->tree, &io);
298 CHECK_STATUS(status, NT_STATUS_OK);
300 status = smb_raw_lock(cli->tree, &io);
301 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
303 io.lockx.in.ulock_cnt = 1;
304 io.lockx.in.lock_cnt = 0;
305 status = smb_raw_lock(cli->tree, &io);
306 CHECK_STATUS(status, NT_STATUS_OK);
307 status = smb_raw_lock(cli->tree, &io);
308 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
310 printf("Trying 2^63 - 1\n");
311 io.lockx.in.ulock_cnt = 0;
312 io.lockx.in.lock_cnt = 1;
315 lock[0].offset <<= 63;
317 status = smb_raw_lock(cli->tree, &io);
318 CHECK_STATUS(status, NT_STATUS_OK);
320 status = smb_raw_lock(cli->tree, &io);
321 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
323 io.lockx.in.ulock_cnt = 1;
324 io.lockx.in.lock_cnt = 0;
325 status = smb_raw_lock(cli->tree, &io);
326 CHECK_STATUS(status, NT_STATUS_OK);
327 status = smb_raw_lock(cli->tree, &io);
328 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
330 printf("Trying max lock 2\n");
331 io.lockx.in.ulock_cnt = 0;
332 io.lockx.in.lock_cnt = 1;
335 status = smb_raw_lock(cli->tree, &io);
336 CHECK_STATUS(status, NT_STATUS_OK);
339 status = smb_raw_lock(cli->tree, &io);
340 CHECK_STATUS(status, NT_STATUS_OK);
342 io.lockx.in.ulock_cnt = 1;
343 io.lockx.in.lock_cnt = 0;
345 status = smb_raw_lock(cli->tree, &io);
346 CHECK_STATUS(status, NT_STATUS_OK);
347 status = smb_raw_lock(cli->tree, &io);
348 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
351 smbcli_close(cli->tree, fnum);
352 smb_raw_exit(cli->session);
353 smbcli_deltree(cli->tree, BASEDIR);
361 static bool test_pidhigh(struct torture_context *tctx,
362 struct smbcli_state *cli)
365 struct smb_lock_entry lock[1];
369 const char *fname = BASEDIR "\\test.txt";
372 if (!torture_setup_dir(cli, BASEDIR)) {
376 printf("Testing high pid\n");
377 io.generic.level = RAW_LOCK_LOCKX;
379 cli->session->pid = 1;
381 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
383 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
388 if (smbcli_write(cli->tree, fnum, 0, &c, 0, 1) != 1) {
389 printf("Failed to write 1 byte - %s\n", smbcli_errstr(cli->tree));
394 io.lockx.level = RAW_LOCK_LOCKX;
395 io.lockx.in.file.fnum = fnum;
396 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
397 io.lockx.in.timeout = 0;
398 io.lockx.in.ulock_cnt = 0;
399 io.lockx.in.lock_cnt = 1;
400 lock[0].pid = cli->session->pid;
402 lock[0].count = 0xFFFFFFFF;
403 io.lockx.in.locks = &lock[0];
404 status = smb_raw_lock(cli->tree, &io);
405 CHECK_STATUS(status, NT_STATUS_OK);
407 if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
408 printf("Failed to read 1 byte - %s\n", smbcli_errstr(cli->tree));
413 cli->session->pid |= 0x10000;
415 cli->session->pid = 2;
417 if (smbcli_read(cli->tree, fnum, &c, 0, 1) == 1) {
418 printf("pid is incorrect handled for read with lock!\n");
423 cli->session->pid = 0x10001;
425 if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
426 printf("High pid is used on this server!\n");
429 printf("High pid is not used on this server (correct)\n");
433 smbcli_close(cli->tree, fnum);
434 smb_raw_exit(cli->session);
435 smbcli_deltree(cli->tree, BASEDIR);
441 test locking&X async operation
443 static bool test_async(struct torture_context *tctx,
444 struct smbcli_state *cli)
446 struct smbcli_session *session;
447 struct smb_composite_sesssetup setup;
448 struct smbcli_tree *tree;
450 const char *host, *share;
452 struct smb_lock_entry lock[2];
456 const char *fname = BASEDIR "\\test.txt";
458 struct smbcli_request *req;
460 if (!torture_setup_dir(cli, BASEDIR)) {
464 printf("Testing LOCKING_ANDX_CANCEL_LOCK\n");
465 io.generic.level = RAW_LOCK_LOCKX;
467 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
469 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
474 io.lockx.level = RAW_LOCK_LOCKX;
475 io.lockx.in.file.fnum = fnum;
476 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
477 io.lockx.in.timeout = 0;
478 io.lockx.in.ulock_cnt = 0;
479 io.lockx.in.lock_cnt = 1;
480 lock[0].pid = cli->session->pid;
481 lock[0].offset = 100;
483 io.lockx.in.locks = &lock[0];
484 status = smb_raw_lock(cli->tree, &io);
485 CHECK_STATUS(status, NT_STATUS_OK);
489 printf("testing cancel by CANCEL_LOCK\n");
491 /* setup a timed lock */
492 io.lockx.in.timeout = 10000;
493 req = smb_raw_lock_send(cli->tree, &io);
495 printf("Failed to setup timed lock (%s)\n", __location__);
500 /* cancel the wrong range */
502 io.lockx.in.timeout = 0;
503 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK;
504 status = smb_raw_lock(cli->tree, &io);
505 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRcancelviolation));
507 /* cancel with the wrong bits set */
508 lock[0].offset = 100;
509 io.lockx.in.timeout = 0;
510 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK;
511 status = smb_raw_lock(cli->tree, &io);
512 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRcancelviolation));
514 /* cancel the right range */
515 lock[0].offset = 100;
516 io.lockx.in.timeout = 0;
517 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
518 status = smb_raw_lock(cli->tree, &io);
519 CHECK_STATUS(status, NT_STATUS_OK);
521 /* receive the failed lock request */
522 status = smbcli_request_simple_recv(req);
523 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
525 if (time(NULL) > t+2) {
526 printf("lock cancel was not immediate (%s)\n", __location__);
531 printf("testing cancel by unlock\n");
532 io.lockx.in.ulock_cnt = 0;
533 io.lockx.in.lock_cnt = 1;
534 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
535 io.lockx.in.timeout = 0;
536 status = smb_raw_lock(cli->tree, &io);
537 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
539 io.lockx.in.timeout = 5000;
540 req = smb_raw_lock_send(cli->tree, &io);
542 printf("Failed to setup timed lock (%s)\n", __location__);
547 io.lockx.in.ulock_cnt = 1;
548 io.lockx.in.lock_cnt = 0;
549 status = smb_raw_lock(cli->tree, &io);
550 CHECK_STATUS(status, NT_STATUS_OK);
553 status = smbcli_request_simple_recv(req);
554 CHECK_STATUS(status, NT_STATUS_OK);
556 if (time(NULL) > t+2) {
557 printf("lock cancel by unlock was not immediate (%s) - took %d secs\n",
558 __location__, (int)(time(NULL)-t));
563 printf("testing cancel by close\n");
564 io.lockx.in.ulock_cnt = 0;
565 io.lockx.in.lock_cnt = 1;
566 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
567 io.lockx.in.timeout = 0;
568 status = smb_raw_lock(cli->tree, &io);
569 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
572 io.lockx.in.timeout = 10000;
573 req = smb_raw_lock_send(cli->tree, &io);
575 printf("Failed to setup timed lock (%s)\n", __location__);
580 status = smbcli_close(cli->tree, fnum);
581 CHECK_STATUS(status, NT_STATUS_OK);
583 status = smbcli_request_simple_recv(req);
584 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
586 if (time(NULL) > t+2) {
587 printf("lock cancel by close was not immediate (%s)\n", __location__);
592 printf("create a new sessions\n");
593 session = smbcli_session_init(cli->transport, tctx, false);
594 setup.in.sesskey = cli->transport->negotiate.sesskey;
595 setup.in.capabilities = cli->transport->negotiate.capabilities;
596 setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
597 setup.in.credentials = cmdline_credentials;
598 status = smb_composite_sesssetup(session, &setup);
599 CHECK_STATUS(status, NT_STATUS_OK);
600 session->vuid = setup.out.vuid;
602 printf("create new tree context\n");
603 share = torture_setting_string(tctx, "share", NULL);
604 host = torture_setting_string(tctx, "host", NULL);
605 tree = smbcli_tree_init(session, tctx, false);
606 tcon.generic.level = RAW_TCON_TCONX;
607 tcon.tconx.in.flags = 0;
608 tcon.tconx.in.password = data_blob(NULL, 0);
609 tcon.tconx.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
610 tcon.tconx.in.device = "A:";
611 status = smb_raw_tcon(tree, tctx, &tcon);
612 CHECK_STATUS(status, NT_STATUS_OK);
613 tree->tid = tcon.tconx.out.tid;
615 printf("testing cancel by exit\n");
616 fname = BASEDIR "\\test_exit.txt";
617 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
619 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
623 io.lockx.level = RAW_LOCK_LOCKX;
624 io.lockx.in.file.fnum = fnum;
625 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
626 io.lockx.in.timeout = 0;
627 io.lockx.in.ulock_cnt = 0;
628 io.lockx.in.lock_cnt = 1;
629 lock[0].pid = session->pid;
630 lock[0].offset = 100;
632 io.lockx.in.locks = &lock[0];
633 status = smb_raw_lock(tree, &io);
634 CHECK_STATUS(status, NT_STATUS_OK);
636 io.lockx.in.ulock_cnt = 0;
637 io.lockx.in.lock_cnt = 1;
638 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
639 io.lockx.in.timeout = 0;
640 status = smb_raw_lock(tree, &io);
641 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
643 io.lockx.in.timeout = 10000;
645 req = smb_raw_lock_send(tree, &io);
647 printf("Failed to setup timed lock (%s)\n", __location__);
652 status = smb_raw_exit(session);
653 CHECK_STATUS(status, NT_STATUS_OK);
655 status = smbcli_request_simple_recv(req);
656 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
658 if (time(NULL) > t+2) {
659 printf("lock cancel by exit was not immediate (%s)\n", __location__);
664 printf("testing cancel by ulogoff\n");
665 fname = BASEDIR "\\test_ulogoff.txt";
666 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
668 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
672 io.lockx.level = RAW_LOCK_LOCKX;
673 io.lockx.in.file.fnum = fnum;
674 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
675 io.lockx.in.timeout = 0;
676 io.lockx.in.ulock_cnt = 0;
677 io.lockx.in.lock_cnt = 1;
678 lock[0].pid = session->pid;
679 lock[0].offset = 100;
681 io.lockx.in.locks = &lock[0];
682 status = smb_raw_lock(tree, &io);
683 CHECK_STATUS(status, NT_STATUS_OK);
685 io.lockx.in.ulock_cnt = 0;
686 io.lockx.in.lock_cnt = 1;
687 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
688 io.lockx.in.timeout = 0;
689 status = smb_raw_lock(tree, &io);
690 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
692 io.lockx.in.timeout = 10000;
694 req = smb_raw_lock_send(tree, &io);
696 printf("Failed to setup timed lock (%s)\n", __location__);
701 status = smb_raw_ulogoff(session);
702 CHECK_STATUS(status, NT_STATUS_OK);
704 status = smbcli_request_simple_recv(req);
705 if (NT_STATUS_EQUAL(NT_STATUS_FILE_LOCK_CONFLICT, status)) {
706 printf("lock not canceled by ulogoff - %s (ignored because of vfs_vifs fails it)\n",
708 smb_tree_disconnect(tree);
709 smb_raw_exit(session);
712 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
714 if (time(NULL) > t+2) {
715 printf("lock cancel by ulogoff was not immediate (%s)\n", __location__);
720 printf("testing cancel by tdis\n");
721 tree->session = cli->session;
723 fname = BASEDIR "\\test_tdis.txt";
724 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
726 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
730 io.lockx.level = RAW_LOCK_LOCKX;
731 io.lockx.in.file.fnum = fnum;
732 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
733 io.lockx.in.timeout = 0;
734 io.lockx.in.ulock_cnt = 0;
735 io.lockx.in.lock_cnt = 1;
736 lock[0].pid = cli->session->pid;
737 lock[0].offset = 100;
739 io.lockx.in.locks = &lock[0];
740 status = smb_raw_lock(tree, &io);
741 CHECK_STATUS(status, NT_STATUS_OK);
743 status = smb_raw_lock(tree, &io);
744 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
746 io.lockx.in.timeout = 10000;
748 req = smb_raw_lock_send(tree, &io);
750 printf("Failed to setup timed lock (%s)\n", __location__);
755 status = smb_tree_disconnect(tree);
756 CHECK_STATUS(status, NT_STATUS_OK);
758 status = smbcli_request_simple_recv(req);
759 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
761 if (time(NULL) > t+2) {
762 printf("lock cancel by tdis was not immediate (%s)\n", __location__);
768 smb_raw_exit(cli->session);
769 smbcli_deltree(cli->tree, BASEDIR);
774 test NT_STATUS_LOCK_NOT_GRANTED vs. NT_STATUS_FILE_LOCK_CONFLICT
776 static bool test_errorcode(struct torture_context *tctx,
777 struct smbcli_state *cli)
781 struct smb_lock_entry lock[2];
786 struct smbcli_request *req;
790 if (!torture_setup_dir(cli, BASEDIR)) {
794 printf("Testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT\n");
796 printf("testing with timeout = 0\n");
797 fname = BASEDIR "\\test0.txt";
801 * the first run is with t = 0,
802 * the second with t > 0 (=1)
806 * use the DENY_DOS mode, that creates two fnum's of one low-level file handle,
807 * this demonstrates that the cache is per fnum
809 op.openx.level = RAW_OPEN_OPENX;
810 op.openx.in.fname = fname;
811 op.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
812 op.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_DOS;
813 op.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
814 op.openx.in.search_attrs = 0;
815 op.openx.in.file_attrs = 0;
816 op.openx.in.write_time = 0;
817 op.openx.in.size = 0;
818 op.openx.in.timeout = 0;
820 status = smb_raw_open(cli->tree, tctx, &op);
821 CHECK_STATUS(status, NT_STATUS_OK);
822 fnum = op.openx.out.file.fnum;
824 status = smb_raw_open(cli->tree, tctx, &op);
825 CHECK_STATUS(status, NT_STATUS_OK);
826 fnum2 = op.openx.out.file.fnum;
828 io.lockx.level = RAW_LOCK_LOCKX;
829 io.lockx.in.file.fnum = fnum;
830 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
831 io.lockx.in.timeout = t;
832 io.lockx.in.ulock_cnt = 0;
833 io.lockx.in.lock_cnt = 1;
834 lock[0].pid = cli->session->pid;
835 lock[0].offset = 100;
837 io.lockx.in.locks = &lock[0];
838 status = smb_raw_lock(cli->tree, &io);
839 CHECK_STATUS(status, NT_STATUS_OK);
842 * demonstrate that the first conflicting lock on each handle give LOCK_NOT_GRANTED
843 * this also demonstrates that the error code cache is per file handle
844 * (LOCK_NOT_GRANTED is only be used when timeout is 0!)
846 io.lockx.in.file.fnum = fnum2;
847 status = smb_raw_lock(cli->tree, &io);
848 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
850 io.lockx.in.file.fnum = fnum;
851 status = smb_raw_lock(cli->tree, &io);
852 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
854 /* demonstrate that each following conflict gives FILE_LOCK_CONFLICT */
855 io.lockx.in.file.fnum = fnum;
856 status = smb_raw_lock(cli->tree, &io);
857 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
859 io.lockx.in.file.fnum = fnum2;
860 status = smb_raw_lock(cli->tree, &io);
861 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
863 io.lockx.in.file.fnum = fnum;
864 status = smb_raw_lock(cli->tree, &io);
865 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
867 io.lockx.in.file.fnum = fnum2;
868 status = smb_raw_lock(cli->tree, &io);
869 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
871 /* demonstrate that the smbpid doesn't matter */
873 io.lockx.in.file.fnum = fnum;
874 status = smb_raw_lock(cli->tree, &io);
875 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
877 io.lockx.in.file.fnum = fnum2;
878 status = smb_raw_lock(cli->tree, &io);
879 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
883 * demonstrate the a successful lock with count = 0 and the same offset,
884 * doesn't reset the error cache
886 lock[0].offset = 100;
888 io.lockx.in.file.fnum = fnum;
889 status = smb_raw_lock(cli->tree, &io);
890 CHECK_STATUS(status, NT_STATUS_OK);
892 io.lockx.in.file.fnum = fnum2;
893 status = smb_raw_lock(cli->tree, &io);
894 CHECK_STATUS(status, NT_STATUS_OK);
896 lock[0].offset = 100;
898 io.lockx.in.file.fnum = fnum;
899 status = smb_raw_lock(cli->tree, &io);
900 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
902 io.lockx.in.file.fnum = fnum2;
903 status = smb_raw_lock(cli->tree, &io);
904 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
907 * demonstrate the a successful lock with count = 0 and outside the locked range,
908 * doesn't reset the error cache
910 lock[0].offset = 110;
912 io.lockx.in.file.fnum = fnum;
913 status = smb_raw_lock(cli->tree, &io);
914 CHECK_STATUS(status, NT_STATUS_OK);
916 io.lockx.in.file.fnum = fnum2;
917 status = smb_raw_lock(cli->tree, &io);
918 CHECK_STATUS(status, NT_STATUS_OK);
920 lock[0].offset = 100;
922 io.lockx.in.file.fnum = fnum;
923 status = smb_raw_lock(cli->tree, &io);
924 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
926 io.lockx.in.file.fnum = fnum2;
927 status = smb_raw_lock(cli->tree, &io);
928 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
932 io.lockx.in.file.fnum = fnum;
933 status = smb_raw_lock(cli->tree, &io);
934 CHECK_STATUS(status, NT_STATUS_OK);
936 io.lockx.in.file.fnum = fnum2;
937 status = smb_raw_lock(cli->tree, &io);
938 CHECK_STATUS(status, NT_STATUS_OK);
940 lock[0].offset = 100;
942 io.lockx.in.file.fnum = fnum;
943 status = smb_raw_lock(cli->tree, &io);
944 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
946 io.lockx.in.file.fnum = fnum2;
947 status = smb_raw_lock(cli->tree, &io);
948 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
950 /* demonstrate that a changing count doesn't reset the error cache */
951 lock[0].offset = 100;
953 io.lockx.in.file.fnum = fnum;
954 status = smb_raw_lock(cli->tree, &io);
955 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
957 io.lockx.in.file.fnum = fnum2;
958 status = smb_raw_lock(cli->tree, &io);
959 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
961 lock[0].offset = 100;
963 io.lockx.in.file.fnum = fnum;
964 status = smb_raw_lock(cli->tree, &io);
965 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
967 io.lockx.in.file.fnum = fnum2;
968 status = smb_raw_lock(cli->tree, &io);
969 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
972 * demonstrate the a lock with count = 0 and inside the locked range,
973 * fails and resets the error cache
975 lock[0].offset = 101;
977 io.lockx.in.file.fnum = fnum;
978 status = smb_raw_lock(cli->tree, &io);
979 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
980 status = smb_raw_lock(cli->tree, &io);
981 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
983 io.lockx.in.file.fnum = fnum2;
984 status = smb_raw_lock(cli->tree, &io);
985 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
986 status = smb_raw_lock(cli->tree, &io);
987 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
989 lock[0].offset = 100;
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 /* demonstrate the a changing offset, resets the error cache */
1004 lock[0].offset = 105;
1006 io.lockx.in.file.fnum = fnum;
1007 status = smb_raw_lock(cli->tree, &io);
1008 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1009 status = smb_raw_lock(cli->tree, &io);
1010 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1012 io.lockx.in.file.fnum = fnum2;
1013 status = smb_raw_lock(cli->tree, &io);
1014 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1015 status = smb_raw_lock(cli->tree, &io);
1016 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1018 lock[0].offset = 100;
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 = 95;
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 = 100;
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);
1061 * demonstrate the a successful lock in a different range,
1062 * doesn't reset the cache, the failing lock on the 2nd handle
1063 * resets the resets the cache
1065 lock[0].offset = 120;
1067 io.lockx.in.file.fnum = fnum;
1068 status = smb_raw_lock(cli->tree, &io);
1069 CHECK_STATUS(status, NT_STATUS_OK);
1071 io.lockx.in.file.fnum = fnum2;
1072 status = smb_raw_lock(cli->tree, &io);
1073 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1075 lock[0].offset = 100;
1077 io.lockx.in.file.fnum = fnum;
1078 status = smb_raw_lock(cli->tree, &io);
1079 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1080 status = smb_raw_lock(cli->tree, &io);
1081 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1083 io.lockx.in.file.fnum = fnum2;
1084 status = smb_raw_lock(cli->tree, &io);
1085 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1086 status = smb_raw_lock(cli->tree, &io);
1087 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1089 /* end of the loop */
1091 smb_raw_exit(cli->session);
1092 printf("testing with timeout > 0 (=1)\n");
1093 fname = BASEDIR "\\test1.txt";
1099 * the following 3 test sections demonstrate that
1100 * the cache is only set when the error is reported
1101 * to the client (after the timeout went by)
1103 smb_raw_exit(cli->session);
1104 printf("testing a conflict while a lock is pending\n");
1105 fname = BASEDIR "\\test2.txt";
1106 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1108 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1112 io.lockx.level = RAW_LOCK_LOCKX;
1113 io.lockx.in.file.fnum = fnum;
1114 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1115 io.lockx.in.timeout = 0;
1116 io.lockx.in.ulock_cnt = 0;
1117 io.lockx.in.lock_cnt = 1;
1118 lock[0].pid = cli->session->pid;
1119 lock[0].offset = 100;
1121 io.lockx.in.locks = &lock[0];
1122 status = smb_raw_lock(cli->tree, &io);
1123 CHECK_STATUS(status, NT_STATUS_OK);
1126 io.lockx.in.timeout = 1000;
1127 req = smb_raw_lock_send(cli->tree, &io);
1129 printf("Failed to setup timed lock (%s)\n", __location__);
1134 io.lockx.in.timeout = 0;
1135 lock[0].offset = 105;
1137 status = smb_raw_lock(cli->tree, &io);
1138 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1140 status = smbcli_request_simple_recv(req);
1141 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1143 status = smb_raw_lock(cli->tree, &io);
1144 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1146 if (time(NULL) < start+1) {
1147 printf("lock comes back to early (%s)\n", __location__);
1152 smbcli_close(cli->tree, fnum);
1153 fname = BASEDIR "\\test3.txt";
1154 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1156 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1160 io.lockx.level = RAW_LOCK_LOCKX;
1161 io.lockx.in.file.fnum = fnum;
1162 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1163 io.lockx.in.timeout = 0;
1164 io.lockx.in.ulock_cnt = 0;
1165 io.lockx.in.lock_cnt = 1;
1166 lock[0].pid = cli->session->pid;
1167 lock[0].offset = 100;
1169 io.lockx.in.locks = &lock[0];
1170 status = smb_raw_lock(cli->tree, &io);
1171 CHECK_STATUS(status, NT_STATUS_OK);
1174 io.lockx.in.timeout = 1000;
1175 req = smb_raw_lock_send(cli->tree, &io);
1177 printf("Failed to setup timed lock (%s)\n", __location__);
1182 io.lockx.in.timeout = 0;
1183 lock[0].offset = 105;
1185 status = smb_raw_lock(cli->tree, &io);
1186 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1188 status = smbcli_request_simple_recv(req);
1189 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1191 lock[0].offset = 100;
1193 status = smb_raw_lock(cli->tree, &io);
1194 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1196 if (time(NULL) < start+1) {
1197 printf("lock comes back to early (%s)\n", __location__);
1202 smbcli_close(cli->tree, fnum);
1203 fname = BASEDIR "\\test4.txt";
1204 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1206 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1210 io.lockx.level = RAW_LOCK_LOCKX;
1211 io.lockx.in.file.fnum = fnum;
1212 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1213 io.lockx.in.timeout = 0;
1214 io.lockx.in.ulock_cnt = 0;
1215 io.lockx.in.lock_cnt = 1;
1216 lock[0].pid = cli->session->pid;
1217 lock[0].offset = 100;
1219 io.lockx.in.locks = &lock[0];
1220 status = smb_raw_lock(cli->tree, &io);
1221 CHECK_STATUS(status, NT_STATUS_OK);
1224 io.lockx.in.timeout = 1000;
1225 req = smb_raw_lock_send(cli->tree, &io);
1227 printf("Failed to setup timed lock (%s)\n", __location__);
1232 io.lockx.in.timeout = 0;
1233 status = smb_raw_lock(cli->tree, &io);
1234 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1236 status = smbcli_request_simple_recv(req);
1237 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1239 status = smb_raw_lock(cli->tree, &io);
1240 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1242 if (time(NULL) < start+1) {
1243 printf("lock comes back to early (%s)\n", __location__);
1249 smb_raw_exit(cli->session);
1250 smbcli_deltree(cli->tree, BASEDIR);
1256 test LOCKING_ANDX_CHANGE_LOCKTYPE
1258 static bool test_changetype(struct torture_context *tctx,
1259 struct smbcli_state *cli)
1262 struct smb_lock_entry lock[2];
1267 const char *fname = BASEDIR "\\test.txt";
1269 if (!torture_setup_dir(cli, BASEDIR)) {
1273 printf("Testing LOCKING_ANDX_CHANGE_LOCKTYPE\n");
1274 io.generic.level = RAW_LOCK_LOCKX;
1276 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1278 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1283 io.lockx.level = RAW_LOCK_LOCKX;
1284 io.lockx.in.file.fnum = fnum;
1285 io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
1286 io.lockx.in.timeout = 0;
1287 io.lockx.in.ulock_cnt = 0;
1288 io.lockx.in.lock_cnt = 1;
1289 lock[0].pid = cli->session->pid;
1290 lock[0].offset = 100;
1292 io.lockx.in.locks = &lock[0];
1293 status = smb_raw_lock(cli->tree, &io);
1294 CHECK_STATUS(status, NT_STATUS_OK);
1296 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1297 printf("allowed write on read locked region (%s)\n", __location__);
1302 /* windows server don't seem to support this */
1303 io.lockx.in.mode = LOCKING_ANDX_CHANGE_LOCKTYPE;
1304 status = smb_raw_lock(cli->tree, &io);
1305 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRnoatomiclocks));
1307 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1308 printf("allowed write after lock change (%s)\n", __location__);
1314 smbcli_close(cli->tree, fnum);
1315 smb_raw_exit(cli->session);
1316 smbcli_deltree(cli->tree, BASEDIR);
1322 basic testing of lock calls
1324 struct torture_suite *torture_raw_lock(TALLOC_CTX *mem_ctx)
1326 struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCK");
1328 torture_suite_add_1smb_test(suite, "lockx", test_lockx);
1329 torture_suite_add_1smb_test(suite, "lock", test_lock);
1330 torture_suite_add_1smb_test(suite, "pidhigh", test_pidhigh);
1331 torture_suite_add_1smb_test(suite, "async", test_async);
1332 torture_suite_add_1smb_test(suite, "errorcode", test_errorcode);
1333 torture_suite_add_1smb_test(suite, "changetype", test_changetype);