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;
459 struct smbcli_session_options options;
461 if (!torture_setup_dir(cli, BASEDIR)) {
465 lp_smbcli_session_options(tctx->lp_ctx, &options);
467 printf("Testing LOCKING_ANDX_CANCEL_LOCK\n");
468 io.generic.level = RAW_LOCK_LOCKX;
470 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
472 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
477 io.lockx.level = RAW_LOCK_LOCKX;
478 io.lockx.in.file.fnum = fnum;
479 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
480 io.lockx.in.timeout = 0;
481 io.lockx.in.ulock_cnt = 0;
482 io.lockx.in.lock_cnt = 1;
483 lock[0].pid = cli->session->pid;
484 lock[0].offset = 100;
486 io.lockx.in.locks = &lock[0];
487 status = smb_raw_lock(cli->tree, &io);
488 CHECK_STATUS(status, NT_STATUS_OK);
492 printf("testing cancel by CANCEL_LOCK\n");
494 /* setup a timed lock */
495 io.lockx.in.timeout = 10000;
496 req = smb_raw_lock_send(cli->tree, &io);
498 printf("Failed to setup timed lock (%s)\n", __location__);
503 /* cancel the wrong range */
505 io.lockx.in.timeout = 0;
506 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK;
507 status = smb_raw_lock(cli->tree, &io);
508 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRcancelviolation));
510 /* cancel with the wrong bits set */
511 lock[0].offset = 100;
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 the right range */
518 lock[0].offset = 100;
519 io.lockx.in.timeout = 0;
520 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
521 status = smb_raw_lock(cli->tree, &io);
522 CHECK_STATUS(status, NT_STATUS_OK);
524 /* receive the failed lock request */
525 status = smbcli_request_simple_recv(req);
526 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
528 if (time(NULL) > t+2) {
529 printf("lock cancel was not immediate (%s)\n", __location__);
534 printf("testing cancel by unlock\n");
535 io.lockx.in.ulock_cnt = 0;
536 io.lockx.in.lock_cnt = 1;
537 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
538 io.lockx.in.timeout = 0;
539 status = smb_raw_lock(cli->tree, &io);
540 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
542 io.lockx.in.timeout = 5000;
543 req = smb_raw_lock_send(cli->tree, &io);
545 printf("Failed to setup timed lock (%s)\n", __location__);
550 io.lockx.in.ulock_cnt = 1;
551 io.lockx.in.lock_cnt = 0;
552 status = smb_raw_lock(cli->tree, &io);
553 CHECK_STATUS(status, NT_STATUS_OK);
556 status = smbcli_request_simple_recv(req);
557 CHECK_STATUS(status, NT_STATUS_OK);
559 if (time(NULL) > t+2) {
560 printf("lock cancel by unlock was not immediate (%s) - took %d secs\n",
561 __location__, (int)(time(NULL)-t));
566 printf("testing cancel by close\n");
567 io.lockx.in.ulock_cnt = 0;
568 io.lockx.in.lock_cnt = 1;
569 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
570 io.lockx.in.timeout = 0;
571 status = smb_raw_lock(cli->tree, &io);
572 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
575 io.lockx.in.timeout = 10000;
576 req = smb_raw_lock_send(cli->tree, &io);
578 printf("Failed to setup timed lock (%s)\n", __location__);
583 status = smbcli_close(cli->tree, fnum);
584 CHECK_STATUS(status, NT_STATUS_OK);
586 status = smbcli_request_simple_recv(req);
587 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
589 if (time(NULL) > t+2) {
590 printf("lock cancel by close was not immediate (%s)\n", __location__);
595 printf("create a new sessions\n");
596 session = smbcli_session_init(cli->transport, tctx, false, options);
597 setup.in.sesskey = cli->transport->negotiate.sesskey;
598 setup.in.capabilities = cli->transport->negotiate.capabilities;
599 setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
600 setup.in.credentials = cmdline_credentials;
601 status = smb_composite_sesssetup(session, &setup);
602 CHECK_STATUS(status, NT_STATUS_OK);
603 session->vuid = setup.out.vuid;
605 printf("create new tree context\n");
606 share = torture_setting_string(tctx, "share", NULL);
607 host = torture_setting_string(tctx, "host", NULL);
608 tree = smbcli_tree_init(session, tctx, false);
609 tcon.generic.level = RAW_TCON_TCONX;
610 tcon.tconx.in.flags = 0;
611 tcon.tconx.in.password = data_blob(NULL, 0);
612 tcon.tconx.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
613 tcon.tconx.in.device = "A:";
614 status = smb_raw_tcon(tree, tctx, &tcon);
615 CHECK_STATUS(status, NT_STATUS_OK);
616 tree->tid = tcon.tconx.out.tid;
618 printf("testing cancel by exit\n");
619 fname = BASEDIR "\\test_exit.txt";
620 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
622 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
626 io.lockx.level = RAW_LOCK_LOCKX;
627 io.lockx.in.file.fnum = fnum;
628 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
629 io.lockx.in.timeout = 0;
630 io.lockx.in.ulock_cnt = 0;
631 io.lockx.in.lock_cnt = 1;
632 lock[0].pid = session->pid;
633 lock[0].offset = 100;
635 io.lockx.in.locks = &lock[0];
636 status = smb_raw_lock(tree, &io);
637 CHECK_STATUS(status, NT_STATUS_OK);
639 io.lockx.in.ulock_cnt = 0;
640 io.lockx.in.lock_cnt = 1;
641 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
642 io.lockx.in.timeout = 0;
643 status = smb_raw_lock(tree, &io);
644 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
646 io.lockx.in.timeout = 10000;
648 req = smb_raw_lock_send(tree, &io);
650 printf("Failed to setup timed lock (%s)\n", __location__);
655 status = smb_raw_exit(session);
656 CHECK_STATUS(status, NT_STATUS_OK);
658 status = smbcli_request_simple_recv(req);
659 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
661 if (time(NULL) > t+2) {
662 printf("lock cancel by exit was not immediate (%s)\n", __location__);
667 printf("testing cancel by ulogoff\n");
668 fname = BASEDIR "\\test_ulogoff.txt";
669 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
671 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
675 io.lockx.level = RAW_LOCK_LOCKX;
676 io.lockx.in.file.fnum = fnum;
677 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
678 io.lockx.in.timeout = 0;
679 io.lockx.in.ulock_cnt = 0;
680 io.lockx.in.lock_cnt = 1;
681 lock[0].pid = session->pid;
682 lock[0].offset = 100;
684 io.lockx.in.locks = &lock[0];
685 status = smb_raw_lock(tree, &io);
686 CHECK_STATUS(status, NT_STATUS_OK);
688 io.lockx.in.ulock_cnt = 0;
689 io.lockx.in.lock_cnt = 1;
690 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
691 io.lockx.in.timeout = 0;
692 status = smb_raw_lock(tree, &io);
693 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
695 io.lockx.in.timeout = 10000;
697 req = smb_raw_lock_send(tree, &io);
699 printf("Failed to setup timed lock (%s)\n", __location__);
704 status = smb_raw_ulogoff(session);
705 CHECK_STATUS(status, NT_STATUS_OK);
707 status = smbcli_request_simple_recv(req);
708 if (NT_STATUS_EQUAL(NT_STATUS_FILE_LOCK_CONFLICT, status)) {
709 printf("lock not canceled by ulogoff - %s (ignored because of vfs_vifs fails it)\n",
711 smb_tree_disconnect(tree);
712 smb_raw_exit(session);
715 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
717 if (time(NULL) > t+2) {
718 printf("lock cancel by ulogoff was not immediate (%s)\n", __location__);
723 printf("testing cancel by tdis\n");
724 tree->session = cli->session;
726 fname = BASEDIR "\\test_tdis.txt";
727 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
729 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
733 io.lockx.level = RAW_LOCK_LOCKX;
734 io.lockx.in.file.fnum = fnum;
735 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
736 io.lockx.in.timeout = 0;
737 io.lockx.in.ulock_cnt = 0;
738 io.lockx.in.lock_cnt = 1;
739 lock[0].pid = cli->session->pid;
740 lock[0].offset = 100;
742 io.lockx.in.locks = &lock[0];
743 status = smb_raw_lock(tree, &io);
744 CHECK_STATUS(status, NT_STATUS_OK);
746 status = smb_raw_lock(tree, &io);
747 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
749 io.lockx.in.timeout = 10000;
751 req = smb_raw_lock_send(tree, &io);
753 printf("Failed to setup timed lock (%s)\n", __location__);
758 status = smb_tree_disconnect(tree);
759 CHECK_STATUS(status, NT_STATUS_OK);
761 status = smbcli_request_simple_recv(req);
762 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
764 if (time(NULL) > t+2) {
765 printf("lock cancel by tdis was not immediate (%s)\n", __location__);
771 smb_raw_exit(cli->session);
772 smbcli_deltree(cli->tree, BASEDIR);
777 test NT_STATUS_LOCK_NOT_GRANTED vs. NT_STATUS_FILE_LOCK_CONFLICT
779 static bool test_errorcode(struct torture_context *tctx,
780 struct smbcli_state *cli)
784 struct smb_lock_entry lock[2];
789 struct smbcli_request *req;
793 if (!torture_setup_dir(cli, BASEDIR)) {
797 printf("Testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT\n");
799 printf("testing with timeout = 0\n");
800 fname = BASEDIR "\\test0.txt";
804 * the first run is with t = 0,
805 * the second with t > 0 (=1)
809 * use the DENY_DOS mode, that creates two fnum's of one low-level file handle,
810 * this demonstrates that the cache is per fnum
812 op.openx.level = RAW_OPEN_OPENX;
813 op.openx.in.fname = fname;
814 op.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
815 op.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_DOS;
816 op.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
817 op.openx.in.search_attrs = 0;
818 op.openx.in.file_attrs = 0;
819 op.openx.in.write_time = 0;
820 op.openx.in.size = 0;
821 op.openx.in.timeout = 0;
823 status = smb_raw_open(cli->tree, tctx, &op);
824 CHECK_STATUS(status, NT_STATUS_OK);
825 fnum = op.openx.out.file.fnum;
827 status = smb_raw_open(cli->tree, tctx, &op);
828 CHECK_STATUS(status, NT_STATUS_OK);
829 fnum2 = op.openx.out.file.fnum;
831 io.lockx.level = RAW_LOCK_LOCKX;
832 io.lockx.in.file.fnum = fnum;
833 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
834 io.lockx.in.timeout = t;
835 io.lockx.in.ulock_cnt = 0;
836 io.lockx.in.lock_cnt = 1;
837 lock[0].pid = cli->session->pid;
838 lock[0].offset = 100;
840 io.lockx.in.locks = &lock[0];
841 status = smb_raw_lock(cli->tree, &io);
842 CHECK_STATUS(status, NT_STATUS_OK);
845 * demonstrate that the first conflicting lock on each handle give LOCK_NOT_GRANTED
846 * this also demonstrates that the error code cache is per file handle
847 * (LOCK_NOT_GRANTED is only be used when timeout is 0!)
849 io.lockx.in.file.fnum = fnum2;
850 status = smb_raw_lock(cli->tree, &io);
851 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
853 io.lockx.in.file.fnum = fnum;
854 status = smb_raw_lock(cli->tree, &io);
855 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
857 /* demonstrate that each following conflict gives FILE_LOCK_CONFLICT */
858 io.lockx.in.file.fnum = fnum;
859 status = smb_raw_lock(cli->tree, &io);
860 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
862 io.lockx.in.file.fnum = fnum2;
863 status = smb_raw_lock(cli->tree, &io);
864 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
866 io.lockx.in.file.fnum = fnum;
867 status = smb_raw_lock(cli->tree, &io);
868 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
870 io.lockx.in.file.fnum = fnum2;
871 status = smb_raw_lock(cli->tree, &io);
872 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
874 /* demonstrate that the smbpid doesn't matter */
876 io.lockx.in.file.fnum = fnum;
877 status = smb_raw_lock(cli->tree, &io);
878 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
880 io.lockx.in.file.fnum = fnum2;
881 status = smb_raw_lock(cli->tree, &io);
882 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
886 * demonstrate the a successful lock with count = 0 and the same offset,
887 * doesn't reset the error cache
889 lock[0].offset = 100;
891 io.lockx.in.file.fnum = fnum;
892 status = smb_raw_lock(cli->tree, &io);
893 CHECK_STATUS(status, NT_STATUS_OK);
895 io.lockx.in.file.fnum = fnum2;
896 status = smb_raw_lock(cli->tree, &io);
897 CHECK_STATUS(status, NT_STATUS_OK);
899 lock[0].offset = 100;
901 io.lockx.in.file.fnum = fnum;
902 status = smb_raw_lock(cli->tree, &io);
903 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
905 io.lockx.in.file.fnum = fnum2;
906 status = smb_raw_lock(cli->tree, &io);
907 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
910 * demonstrate the a successful lock with count = 0 and outside the locked range,
911 * doesn't reset the error cache
913 lock[0].offset = 110;
915 io.lockx.in.file.fnum = fnum;
916 status = smb_raw_lock(cli->tree, &io);
917 CHECK_STATUS(status, NT_STATUS_OK);
919 io.lockx.in.file.fnum = fnum2;
920 status = smb_raw_lock(cli->tree, &io);
921 CHECK_STATUS(status, NT_STATUS_OK);
923 lock[0].offset = 100;
925 io.lockx.in.file.fnum = fnum;
926 status = smb_raw_lock(cli->tree, &io);
927 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
929 io.lockx.in.file.fnum = fnum2;
930 status = smb_raw_lock(cli->tree, &io);
931 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
935 io.lockx.in.file.fnum = fnum;
936 status = smb_raw_lock(cli->tree, &io);
937 CHECK_STATUS(status, NT_STATUS_OK);
939 io.lockx.in.file.fnum = fnum2;
940 status = smb_raw_lock(cli->tree, &io);
941 CHECK_STATUS(status, NT_STATUS_OK);
943 lock[0].offset = 100;
945 io.lockx.in.file.fnum = fnum;
946 status = smb_raw_lock(cli->tree, &io);
947 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
949 io.lockx.in.file.fnum = fnum2;
950 status = smb_raw_lock(cli->tree, &io);
951 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
953 /* demonstrate that a changing count doesn't reset the error cache */
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 lock[0].offset = 100;
966 io.lockx.in.file.fnum = fnum;
967 status = smb_raw_lock(cli->tree, &io);
968 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
970 io.lockx.in.file.fnum = fnum2;
971 status = smb_raw_lock(cli->tree, &io);
972 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
975 * demonstrate the a lock with count = 0 and inside the locked range,
976 * fails and resets the error cache
978 lock[0].offset = 101;
980 io.lockx.in.file.fnum = fnum;
981 status = smb_raw_lock(cli->tree, &io);
982 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
983 status = smb_raw_lock(cli->tree, &io);
984 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
986 io.lockx.in.file.fnum = fnum2;
987 status = smb_raw_lock(cli->tree, &io);
988 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
989 status = smb_raw_lock(cli->tree, &io);
990 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
992 lock[0].offset = 100;
994 io.lockx.in.file.fnum = fnum;
995 status = smb_raw_lock(cli->tree, &io);
996 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
997 status = smb_raw_lock(cli->tree, &io);
998 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1000 io.lockx.in.file.fnum = fnum2;
1001 status = smb_raw_lock(cli->tree, &io);
1002 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1003 status = smb_raw_lock(cli->tree, &io);
1004 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1006 /* demonstrate the a changing offset, resets the error cache */
1007 lock[0].offset = 105;
1009 io.lockx.in.file.fnum = fnum;
1010 status = smb_raw_lock(cli->tree, &io);
1011 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1012 status = smb_raw_lock(cli->tree, &io);
1013 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1015 io.lockx.in.file.fnum = fnum2;
1016 status = smb_raw_lock(cli->tree, &io);
1017 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1018 status = smb_raw_lock(cli->tree, &io);
1019 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1021 lock[0].offset = 100;
1023 io.lockx.in.file.fnum = fnum;
1024 status = smb_raw_lock(cli->tree, &io);
1025 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1026 status = smb_raw_lock(cli->tree, &io);
1027 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1029 io.lockx.in.file.fnum = fnum2;
1030 status = smb_raw_lock(cli->tree, &io);
1031 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1032 status = smb_raw_lock(cli->tree, &io);
1033 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1035 lock[0].offset = 95;
1037 io.lockx.in.file.fnum = fnum;
1038 status = smb_raw_lock(cli->tree, &io);
1039 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1040 status = smb_raw_lock(cli->tree, &io);
1041 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1043 io.lockx.in.file.fnum = fnum2;
1044 status = smb_raw_lock(cli->tree, &io);
1045 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1046 status = smb_raw_lock(cli->tree, &io);
1047 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1049 lock[0].offset = 100;
1051 io.lockx.in.file.fnum = fnum;
1052 status = smb_raw_lock(cli->tree, &io);
1053 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1054 status = smb_raw_lock(cli->tree, &io);
1055 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1057 io.lockx.in.file.fnum = fnum2;
1058 status = smb_raw_lock(cli->tree, &io);
1059 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1060 status = smb_raw_lock(cli->tree, &io);
1061 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1064 * demonstrate the a successful lock in a different range,
1065 * doesn't reset the cache, the failing lock on the 2nd handle
1066 * resets the resets the cache
1068 lock[0].offset = 120;
1070 io.lockx.in.file.fnum = fnum;
1071 status = smb_raw_lock(cli->tree, &io);
1072 CHECK_STATUS(status, NT_STATUS_OK);
1074 io.lockx.in.file.fnum = fnum2;
1075 status = smb_raw_lock(cli->tree, &io);
1076 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1078 lock[0].offset = 100;
1080 io.lockx.in.file.fnum = fnum;
1081 status = smb_raw_lock(cli->tree, &io);
1082 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1083 status = smb_raw_lock(cli->tree, &io);
1084 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1086 io.lockx.in.file.fnum = fnum2;
1087 status = smb_raw_lock(cli->tree, &io);
1088 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1089 status = smb_raw_lock(cli->tree, &io);
1090 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1092 /* end of the loop */
1094 smb_raw_exit(cli->session);
1095 printf("testing with timeout > 0 (=1)\n");
1096 fname = BASEDIR "\\test1.txt";
1102 * the following 3 test sections demonstrate that
1103 * the cache is only set when the error is reported
1104 * to the client (after the timeout went by)
1106 smb_raw_exit(cli->session);
1107 printf("testing a conflict while a lock is pending\n");
1108 fname = BASEDIR "\\test2.txt";
1109 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1111 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1115 io.lockx.level = RAW_LOCK_LOCKX;
1116 io.lockx.in.file.fnum = fnum;
1117 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1118 io.lockx.in.timeout = 0;
1119 io.lockx.in.ulock_cnt = 0;
1120 io.lockx.in.lock_cnt = 1;
1121 lock[0].pid = cli->session->pid;
1122 lock[0].offset = 100;
1124 io.lockx.in.locks = &lock[0];
1125 status = smb_raw_lock(cli->tree, &io);
1126 CHECK_STATUS(status, NT_STATUS_OK);
1129 io.lockx.in.timeout = 1000;
1130 req = smb_raw_lock_send(cli->tree, &io);
1132 printf("Failed to setup timed lock (%s)\n", __location__);
1137 io.lockx.in.timeout = 0;
1138 lock[0].offset = 105;
1140 status = smb_raw_lock(cli->tree, &io);
1141 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1143 status = smbcli_request_simple_recv(req);
1144 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1146 status = smb_raw_lock(cli->tree, &io);
1147 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1149 if (time(NULL) < start+1) {
1150 printf("lock comes back to early (%s)\n", __location__);
1155 smbcli_close(cli->tree, fnum);
1156 fname = BASEDIR "\\test3.txt";
1157 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1159 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1163 io.lockx.level = RAW_LOCK_LOCKX;
1164 io.lockx.in.file.fnum = fnum;
1165 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1166 io.lockx.in.timeout = 0;
1167 io.lockx.in.ulock_cnt = 0;
1168 io.lockx.in.lock_cnt = 1;
1169 lock[0].pid = cli->session->pid;
1170 lock[0].offset = 100;
1172 io.lockx.in.locks = &lock[0];
1173 status = smb_raw_lock(cli->tree, &io);
1174 CHECK_STATUS(status, NT_STATUS_OK);
1177 io.lockx.in.timeout = 1000;
1178 req = smb_raw_lock_send(cli->tree, &io);
1180 printf("Failed to setup timed lock (%s)\n", __location__);
1185 io.lockx.in.timeout = 0;
1186 lock[0].offset = 105;
1188 status = smb_raw_lock(cli->tree, &io);
1189 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1191 status = smbcli_request_simple_recv(req);
1192 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1194 lock[0].offset = 100;
1196 status = smb_raw_lock(cli->tree, &io);
1197 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1199 if (time(NULL) < start+1) {
1200 printf("lock comes back to early (%s)\n", __location__);
1205 smbcli_close(cli->tree, fnum);
1206 fname = BASEDIR "\\test4.txt";
1207 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1209 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1213 io.lockx.level = RAW_LOCK_LOCKX;
1214 io.lockx.in.file.fnum = fnum;
1215 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1216 io.lockx.in.timeout = 0;
1217 io.lockx.in.ulock_cnt = 0;
1218 io.lockx.in.lock_cnt = 1;
1219 lock[0].pid = cli->session->pid;
1220 lock[0].offset = 100;
1222 io.lockx.in.locks = &lock[0];
1223 status = smb_raw_lock(cli->tree, &io);
1224 CHECK_STATUS(status, NT_STATUS_OK);
1227 io.lockx.in.timeout = 1000;
1228 req = smb_raw_lock_send(cli->tree, &io);
1230 printf("Failed to setup timed lock (%s)\n", __location__);
1235 io.lockx.in.timeout = 0;
1236 status = smb_raw_lock(cli->tree, &io);
1237 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1239 status = smbcli_request_simple_recv(req);
1240 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1242 status = smb_raw_lock(cli->tree, &io);
1243 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1245 if (time(NULL) < start+1) {
1246 printf("lock comes back to early (%s)\n", __location__);
1252 smb_raw_exit(cli->session);
1253 smbcli_deltree(cli->tree, BASEDIR);
1259 test LOCKING_ANDX_CHANGE_LOCKTYPE
1261 static bool test_changetype(struct torture_context *tctx,
1262 struct smbcli_state *cli)
1265 struct smb_lock_entry lock[2];
1270 const char *fname = BASEDIR "\\test.txt";
1272 if (!torture_setup_dir(cli, BASEDIR)) {
1276 printf("Testing LOCKING_ANDX_CHANGE_LOCKTYPE\n");
1277 io.generic.level = RAW_LOCK_LOCKX;
1279 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1281 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1286 io.lockx.level = RAW_LOCK_LOCKX;
1287 io.lockx.in.file.fnum = fnum;
1288 io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
1289 io.lockx.in.timeout = 0;
1290 io.lockx.in.ulock_cnt = 0;
1291 io.lockx.in.lock_cnt = 1;
1292 lock[0].pid = cli->session->pid;
1293 lock[0].offset = 100;
1295 io.lockx.in.locks = &lock[0];
1296 status = smb_raw_lock(cli->tree, &io);
1297 CHECK_STATUS(status, NT_STATUS_OK);
1299 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1300 printf("allowed write on read locked region (%s)\n", __location__);
1305 /* windows server don't seem to support this */
1306 io.lockx.in.mode = LOCKING_ANDX_CHANGE_LOCKTYPE;
1307 status = smb_raw_lock(cli->tree, &io);
1308 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRnoatomiclocks));
1310 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1311 printf("allowed write after lock change (%s)\n", __location__);
1317 smbcli_close(cli->tree, fnum);
1318 smb_raw_exit(cli->session);
1319 smbcli_deltree(cli->tree, BASEDIR);
1325 basic testing of lock calls
1327 struct torture_suite *torture_raw_lock(TALLOC_CTX *mem_ctx)
1329 struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCK");
1331 torture_suite_add_1smb_test(suite, "lockx", test_lockx);
1332 torture_suite_add_1smb_test(suite, "lock", test_lock);
1333 torture_suite_add_1smb_test(suite, "pidhigh", test_pidhigh);
1334 torture_suite_add_1smb_test(suite, "async", test_async);
1335 torture_suite_add_1smb_test(suite, "errorcode", test_errorcode);
1336 torture_suite_add_1smb_test(suite, "changetype", test_changetype);