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 setup.in.gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
602 status = smb_composite_sesssetup(session, &setup);
603 CHECK_STATUS(status, NT_STATUS_OK);
604 session->vuid = setup.out.vuid;
606 printf("create new tree context\n");
607 share = torture_setting_string(tctx, "share", NULL);
608 host = torture_setting_string(tctx, "host", NULL);
609 tree = smbcli_tree_init(session, tctx, false);
610 tcon.generic.level = RAW_TCON_TCONX;
611 tcon.tconx.in.flags = 0;
612 tcon.tconx.in.password = data_blob(NULL, 0);
613 tcon.tconx.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
614 tcon.tconx.in.device = "A:";
615 status = smb_raw_tcon(tree, tctx, &tcon);
616 CHECK_STATUS(status, NT_STATUS_OK);
617 tree->tid = tcon.tconx.out.tid;
619 printf("testing cancel by exit\n");
620 fname = BASEDIR "\\test_exit.txt";
621 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
623 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
627 io.lockx.level = RAW_LOCK_LOCKX;
628 io.lockx.in.file.fnum = fnum;
629 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
630 io.lockx.in.timeout = 0;
631 io.lockx.in.ulock_cnt = 0;
632 io.lockx.in.lock_cnt = 1;
633 lock[0].pid = session->pid;
634 lock[0].offset = 100;
636 io.lockx.in.locks = &lock[0];
637 status = smb_raw_lock(tree, &io);
638 CHECK_STATUS(status, NT_STATUS_OK);
640 io.lockx.in.ulock_cnt = 0;
641 io.lockx.in.lock_cnt = 1;
642 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
643 io.lockx.in.timeout = 0;
644 status = smb_raw_lock(tree, &io);
645 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
647 io.lockx.in.timeout = 10000;
649 req = smb_raw_lock_send(tree, &io);
651 printf("Failed to setup timed lock (%s)\n", __location__);
656 status = smb_raw_exit(session);
657 CHECK_STATUS(status, NT_STATUS_OK);
659 status = smbcli_request_simple_recv(req);
660 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
662 if (time(NULL) > t+2) {
663 printf("lock cancel by exit was not immediate (%s)\n", __location__);
668 printf("testing cancel by ulogoff\n");
669 fname = BASEDIR "\\test_ulogoff.txt";
670 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
672 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
676 io.lockx.level = RAW_LOCK_LOCKX;
677 io.lockx.in.file.fnum = fnum;
678 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
679 io.lockx.in.timeout = 0;
680 io.lockx.in.ulock_cnt = 0;
681 io.lockx.in.lock_cnt = 1;
682 lock[0].pid = session->pid;
683 lock[0].offset = 100;
685 io.lockx.in.locks = &lock[0];
686 status = smb_raw_lock(tree, &io);
687 CHECK_STATUS(status, NT_STATUS_OK);
689 io.lockx.in.ulock_cnt = 0;
690 io.lockx.in.lock_cnt = 1;
691 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
692 io.lockx.in.timeout = 0;
693 status = smb_raw_lock(tree, &io);
694 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
696 io.lockx.in.timeout = 10000;
698 req = smb_raw_lock_send(tree, &io);
700 printf("Failed to setup timed lock (%s)\n", __location__);
705 status = smb_raw_ulogoff(session);
706 CHECK_STATUS(status, NT_STATUS_OK);
708 status = smbcli_request_simple_recv(req);
709 if (NT_STATUS_EQUAL(NT_STATUS_FILE_LOCK_CONFLICT, status)) {
710 printf("lock not canceled by ulogoff - %s (ignored because of vfs_vifs fails it)\n",
712 smb_tree_disconnect(tree);
713 smb_raw_exit(session);
716 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
718 if (time(NULL) > t+2) {
719 printf("lock cancel by ulogoff was not immediate (%s)\n", __location__);
724 printf("testing cancel by tdis\n");
725 tree->session = cli->session;
727 fname = BASEDIR "\\test_tdis.txt";
728 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
730 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
734 io.lockx.level = RAW_LOCK_LOCKX;
735 io.lockx.in.file.fnum = fnum;
736 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
737 io.lockx.in.timeout = 0;
738 io.lockx.in.ulock_cnt = 0;
739 io.lockx.in.lock_cnt = 1;
740 lock[0].pid = cli->session->pid;
741 lock[0].offset = 100;
743 io.lockx.in.locks = &lock[0];
744 status = smb_raw_lock(tree, &io);
745 CHECK_STATUS(status, NT_STATUS_OK);
747 status = smb_raw_lock(tree, &io);
748 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
750 io.lockx.in.timeout = 10000;
752 req = smb_raw_lock_send(tree, &io);
754 printf("Failed to setup timed lock (%s)\n", __location__);
759 status = smb_tree_disconnect(tree);
760 CHECK_STATUS(status, NT_STATUS_OK);
762 status = smbcli_request_simple_recv(req);
763 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
765 if (time(NULL) > t+2) {
766 printf("lock cancel by tdis was not immediate (%s)\n", __location__);
772 smb_raw_exit(cli->session);
773 smbcli_deltree(cli->tree, BASEDIR);
778 test NT_STATUS_LOCK_NOT_GRANTED vs. NT_STATUS_FILE_LOCK_CONFLICT
780 static bool test_errorcode(struct torture_context *tctx,
781 struct smbcli_state *cli)
785 struct smb_lock_entry lock[2];
790 struct smbcli_request *req;
794 if (!torture_setup_dir(cli, BASEDIR)) {
798 printf("Testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT\n");
800 printf("testing with timeout = 0\n");
801 fname = BASEDIR "\\test0.txt";
805 * the first run is with t = 0,
806 * the second with t > 0 (=1)
810 * use the DENY_DOS mode, that creates two fnum's of one low-level file handle,
811 * this demonstrates that the cache is per fnum
813 op.openx.level = RAW_OPEN_OPENX;
814 op.openx.in.fname = fname;
815 op.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
816 op.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_DOS;
817 op.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
818 op.openx.in.search_attrs = 0;
819 op.openx.in.file_attrs = 0;
820 op.openx.in.write_time = 0;
821 op.openx.in.size = 0;
822 op.openx.in.timeout = 0;
824 status = smb_raw_open(cli->tree, tctx, &op);
825 CHECK_STATUS(status, NT_STATUS_OK);
826 fnum = op.openx.out.file.fnum;
828 status = smb_raw_open(cli->tree, tctx, &op);
829 CHECK_STATUS(status, NT_STATUS_OK);
830 fnum2 = op.openx.out.file.fnum;
832 io.lockx.level = RAW_LOCK_LOCKX;
833 io.lockx.in.file.fnum = fnum;
834 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
835 io.lockx.in.timeout = t;
836 io.lockx.in.ulock_cnt = 0;
837 io.lockx.in.lock_cnt = 1;
838 lock[0].pid = cli->session->pid;
839 lock[0].offset = 100;
841 io.lockx.in.locks = &lock[0];
842 status = smb_raw_lock(cli->tree, &io);
843 CHECK_STATUS(status, NT_STATUS_OK);
846 * demonstrate that the first conflicting lock on each handle give LOCK_NOT_GRANTED
847 * this also demonstrates that the error code cache is per file handle
848 * (LOCK_NOT_GRANTED is only be used when timeout is 0!)
850 io.lockx.in.file.fnum = fnum2;
851 status = smb_raw_lock(cli->tree, &io);
852 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
854 io.lockx.in.file.fnum = fnum;
855 status = smb_raw_lock(cli->tree, &io);
856 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
858 /* demonstrate that each following conflict gives FILE_LOCK_CONFLICT */
859 io.lockx.in.file.fnum = fnum;
860 status = smb_raw_lock(cli->tree, &io);
861 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
863 io.lockx.in.file.fnum = fnum2;
864 status = smb_raw_lock(cli->tree, &io);
865 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
867 io.lockx.in.file.fnum = fnum;
868 status = smb_raw_lock(cli->tree, &io);
869 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
871 io.lockx.in.file.fnum = fnum2;
872 status = smb_raw_lock(cli->tree, &io);
873 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
875 /* demonstrate that the smbpid doesn't matter */
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);
887 * demonstrate the a successful lock with count = 0 and the same offset,
888 * doesn't reset the error cache
890 lock[0].offset = 100;
892 io.lockx.in.file.fnum = fnum;
893 status = smb_raw_lock(cli->tree, &io);
894 CHECK_STATUS(status, NT_STATUS_OK);
896 io.lockx.in.file.fnum = fnum2;
897 status = smb_raw_lock(cli->tree, &io);
898 CHECK_STATUS(status, NT_STATUS_OK);
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_FILE_LOCK_CONFLICT);
906 io.lockx.in.file.fnum = fnum2;
907 status = smb_raw_lock(cli->tree, &io);
908 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
911 * demonstrate the a successful lock with count = 0 and outside the locked range,
912 * doesn't reset the error cache
914 lock[0].offset = 110;
916 io.lockx.in.file.fnum = fnum;
917 status = smb_raw_lock(cli->tree, &io);
918 CHECK_STATUS(status, NT_STATUS_OK);
920 io.lockx.in.file.fnum = fnum2;
921 status = smb_raw_lock(cli->tree, &io);
922 CHECK_STATUS(status, NT_STATUS_OK);
924 lock[0].offset = 100;
926 io.lockx.in.file.fnum = fnum;
927 status = smb_raw_lock(cli->tree, &io);
928 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
930 io.lockx.in.file.fnum = fnum2;
931 status = smb_raw_lock(cli->tree, &io);
932 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
936 io.lockx.in.file.fnum = fnum;
937 status = smb_raw_lock(cli->tree, &io);
938 CHECK_STATUS(status, NT_STATUS_OK);
940 io.lockx.in.file.fnum = fnum2;
941 status = smb_raw_lock(cli->tree, &io);
942 CHECK_STATUS(status, NT_STATUS_OK);
944 lock[0].offset = 100;
946 io.lockx.in.file.fnum = fnum;
947 status = smb_raw_lock(cli->tree, &io);
948 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
950 io.lockx.in.file.fnum = fnum2;
951 status = smb_raw_lock(cli->tree, &io);
952 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
954 /* demonstrate that a changing count doesn't reset the error cache */
955 lock[0].offset = 100;
957 io.lockx.in.file.fnum = fnum;
958 status = smb_raw_lock(cli->tree, &io);
959 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
961 io.lockx.in.file.fnum = fnum2;
962 status = smb_raw_lock(cli->tree, &io);
963 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
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);
976 * demonstrate the a lock with count = 0 and inside the locked range,
977 * fails and resets the error cache
979 lock[0].offset = 101;
981 io.lockx.in.file.fnum = fnum;
982 status = smb_raw_lock(cli->tree, &io);
983 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
984 status = smb_raw_lock(cli->tree, &io);
985 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
987 io.lockx.in.file.fnum = fnum2;
988 status = smb_raw_lock(cli->tree, &io);
989 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
990 status = smb_raw_lock(cli->tree, &io);
991 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
993 lock[0].offset = 100;
995 io.lockx.in.file.fnum = fnum;
996 status = smb_raw_lock(cli->tree, &io);
997 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
998 status = smb_raw_lock(cli->tree, &io);
999 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1001 io.lockx.in.file.fnum = fnum2;
1002 status = smb_raw_lock(cli->tree, &io);
1003 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1004 status = smb_raw_lock(cli->tree, &io);
1005 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1007 /* demonstrate the a changing offset, resets the error cache */
1008 lock[0].offset = 105;
1010 io.lockx.in.file.fnum = fnum;
1011 status = smb_raw_lock(cli->tree, &io);
1012 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1013 status = smb_raw_lock(cli->tree, &io);
1014 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1016 io.lockx.in.file.fnum = fnum2;
1017 status = smb_raw_lock(cli->tree, &io);
1018 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1019 status = smb_raw_lock(cli->tree, &io);
1020 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1022 lock[0].offset = 100;
1024 io.lockx.in.file.fnum = fnum;
1025 status = smb_raw_lock(cli->tree, &io);
1026 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1027 status = smb_raw_lock(cli->tree, &io);
1028 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1030 io.lockx.in.file.fnum = fnum2;
1031 status = smb_raw_lock(cli->tree, &io);
1032 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1033 status = smb_raw_lock(cli->tree, &io);
1034 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1036 lock[0].offset = 95;
1038 io.lockx.in.file.fnum = fnum;
1039 status = smb_raw_lock(cli->tree, &io);
1040 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1041 status = smb_raw_lock(cli->tree, &io);
1042 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1044 io.lockx.in.file.fnum = fnum2;
1045 status = smb_raw_lock(cli->tree, &io);
1046 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1047 status = smb_raw_lock(cli->tree, &io);
1048 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1050 lock[0].offset = 100;
1052 io.lockx.in.file.fnum = fnum;
1053 status = smb_raw_lock(cli->tree, &io);
1054 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1055 status = smb_raw_lock(cli->tree, &io);
1056 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1058 io.lockx.in.file.fnum = fnum2;
1059 status = smb_raw_lock(cli->tree, &io);
1060 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1061 status = smb_raw_lock(cli->tree, &io);
1062 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1065 * demonstrate the a successful lock in a different range,
1066 * doesn't reset the cache, the failing lock on the 2nd handle
1067 * resets the resets the cache
1069 lock[0].offset = 120;
1071 io.lockx.in.file.fnum = fnum;
1072 status = smb_raw_lock(cli->tree, &io);
1073 CHECK_STATUS(status, NT_STATUS_OK);
1075 io.lockx.in.file.fnum = fnum2;
1076 status = smb_raw_lock(cli->tree, &io);
1077 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1079 lock[0].offset = 100;
1081 io.lockx.in.file.fnum = fnum;
1082 status = smb_raw_lock(cli->tree, &io);
1083 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1084 status = smb_raw_lock(cli->tree, &io);
1085 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1087 io.lockx.in.file.fnum = fnum2;
1088 status = smb_raw_lock(cli->tree, &io);
1089 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1090 status = smb_raw_lock(cli->tree, &io);
1091 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1093 /* end of the loop */
1095 smb_raw_exit(cli->session);
1096 printf("testing with timeout > 0 (=1)\n");
1097 fname = BASEDIR "\\test1.txt";
1103 * the following 3 test sections demonstrate that
1104 * the cache is only set when the error is reported
1105 * to the client (after the timeout went by)
1107 smb_raw_exit(cli->session);
1108 printf("testing a conflict while a lock is pending\n");
1109 fname = BASEDIR "\\test2.txt";
1110 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1112 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1116 io.lockx.level = RAW_LOCK_LOCKX;
1117 io.lockx.in.file.fnum = fnum;
1118 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1119 io.lockx.in.timeout = 0;
1120 io.lockx.in.ulock_cnt = 0;
1121 io.lockx.in.lock_cnt = 1;
1122 lock[0].pid = cli->session->pid;
1123 lock[0].offset = 100;
1125 io.lockx.in.locks = &lock[0];
1126 status = smb_raw_lock(cli->tree, &io);
1127 CHECK_STATUS(status, NT_STATUS_OK);
1130 io.lockx.in.timeout = 1000;
1131 req = smb_raw_lock_send(cli->tree, &io);
1133 printf("Failed to setup timed lock (%s)\n", __location__);
1138 io.lockx.in.timeout = 0;
1139 lock[0].offset = 105;
1141 status = smb_raw_lock(cli->tree, &io);
1142 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1144 status = smbcli_request_simple_recv(req);
1145 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1147 status = smb_raw_lock(cli->tree, &io);
1148 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1150 if (time(NULL) < start+1) {
1151 printf("lock comes back to early (%s)\n", __location__);
1156 smbcli_close(cli->tree, fnum);
1157 fname = BASEDIR "\\test3.txt";
1158 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1160 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1164 io.lockx.level = RAW_LOCK_LOCKX;
1165 io.lockx.in.file.fnum = fnum;
1166 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1167 io.lockx.in.timeout = 0;
1168 io.lockx.in.ulock_cnt = 0;
1169 io.lockx.in.lock_cnt = 1;
1170 lock[0].pid = cli->session->pid;
1171 lock[0].offset = 100;
1173 io.lockx.in.locks = &lock[0];
1174 status = smb_raw_lock(cli->tree, &io);
1175 CHECK_STATUS(status, NT_STATUS_OK);
1178 io.lockx.in.timeout = 1000;
1179 req = smb_raw_lock_send(cli->tree, &io);
1181 printf("Failed to setup timed lock (%s)\n", __location__);
1186 io.lockx.in.timeout = 0;
1187 lock[0].offset = 105;
1189 status = smb_raw_lock(cli->tree, &io);
1190 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1192 status = smbcli_request_simple_recv(req);
1193 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1195 lock[0].offset = 100;
1197 status = smb_raw_lock(cli->tree, &io);
1198 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1200 if (time(NULL) < start+1) {
1201 printf("lock comes back to early (%s)\n", __location__);
1206 smbcli_close(cli->tree, fnum);
1207 fname = BASEDIR "\\test4.txt";
1208 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1210 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1214 io.lockx.level = RAW_LOCK_LOCKX;
1215 io.lockx.in.file.fnum = fnum;
1216 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1217 io.lockx.in.timeout = 0;
1218 io.lockx.in.ulock_cnt = 0;
1219 io.lockx.in.lock_cnt = 1;
1220 lock[0].pid = cli->session->pid;
1221 lock[0].offset = 100;
1223 io.lockx.in.locks = &lock[0];
1224 status = smb_raw_lock(cli->tree, &io);
1225 CHECK_STATUS(status, NT_STATUS_OK);
1228 io.lockx.in.timeout = 1000;
1229 req = smb_raw_lock_send(cli->tree, &io);
1231 printf("Failed to setup timed lock (%s)\n", __location__);
1236 io.lockx.in.timeout = 0;
1237 status = smb_raw_lock(cli->tree, &io);
1238 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1240 status = smbcli_request_simple_recv(req);
1241 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1243 status = smb_raw_lock(cli->tree, &io);
1244 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1246 if (time(NULL) < start+1) {
1247 printf("lock comes back to early (%s)\n", __location__);
1253 smb_raw_exit(cli->session);
1254 smbcli_deltree(cli->tree, BASEDIR);
1260 test LOCKING_ANDX_CHANGE_LOCKTYPE
1262 static bool test_changetype(struct torture_context *tctx,
1263 struct smbcli_state *cli)
1266 struct smb_lock_entry lock[2];
1271 const char *fname = BASEDIR "\\test.txt";
1273 if (!torture_setup_dir(cli, BASEDIR)) {
1277 printf("Testing LOCKING_ANDX_CHANGE_LOCKTYPE\n");
1278 io.generic.level = RAW_LOCK_LOCKX;
1280 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1282 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1287 io.lockx.level = RAW_LOCK_LOCKX;
1288 io.lockx.in.file.fnum = fnum;
1289 io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
1290 io.lockx.in.timeout = 0;
1291 io.lockx.in.ulock_cnt = 0;
1292 io.lockx.in.lock_cnt = 1;
1293 lock[0].pid = cli->session->pid;
1294 lock[0].offset = 100;
1296 io.lockx.in.locks = &lock[0];
1297 status = smb_raw_lock(cli->tree, &io);
1298 CHECK_STATUS(status, NT_STATUS_OK);
1300 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1301 printf("allowed write on read locked region (%s)\n", __location__);
1306 /* windows server don't seem to support this */
1307 io.lockx.in.mode = LOCKING_ANDX_CHANGE_LOCKTYPE;
1308 status = smb_raw_lock(cli->tree, &io);
1309 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRnoatomiclocks));
1311 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1312 printf("allowed write after lock change (%s)\n", __location__);
1318 smbcli_close(cli->tree, fnum);
1319 smb_raw_exit(cli->session);
1320 smbcli_deltree(cli->tree, BASEDIR);
1326 basic testing of lock calls
1328 struct torture_suite *torture_raw_lock(TALLOC_CTX *mem_ctx)
1330 struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCK");
1332 torture_suite_add_1smb_test(suite, "lockx", test_lockx);
1333 torture_suite_add_1smb_test(suite, "lock", test_lock);
1334 torture_suite_add_1smb_test(suite, "pidhigh", test_pidhigh);
1335 torture_suite_add_1smb_test(suite, "async", test_async);
1336 torture_suite_add_1smb_test(suite, "errorcode", test_errorcode);
1337 torture_suite_add_1smb_test(suite, "changetype", test_changetype);