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 "system/time.h"
24 #include "system/filesys.h"
25 #include "libcli/libcli.h"
26 #include "torture/util.h"
27 #include "libcli/composite/composite.h"
28 #include "libcli/smb_composite/smb_composite.h"
29 #include "lib/cmdline/popt_common.h"
31 #define CHECK_STATUS(status, correct) do { \
32 if (!NT_STATUS_EQUAL(status, correct)) { \
33 printf("(%s) Incorrect status %s - should be %s\n", \
34 __location__, nt_errstr(status), nt_errstr(correct)); \
39 #define BASEDIR "\\testlock"
43 test SMBlock and SMBunlock ops
45 static BOOL test_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
51 const char *fname = BASEDIR "\\test.txt";
53 if (!torture_setup_dir(cli, BASEDIR)) {
57 printf("Testing RAW_LOCK_LOCK\n");
58 io.generic.level = RAW_LOCK_LOCK;
60 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
62 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
67 printf("Trying 0/0 lock\n");
68 io.lock.level = RAW_LOCK_LOCK;
69 io.lock.in.file.fnum = fnum;
71 io.lock.in.offset = 0;
72 status = smb_raw_lock(cli->tree, &io);
73 CHECK_STATUS(status, NT_STATUS_OK);
75 status = smb_raw_lock(cli->tree, &io);
76 CHECK_STATUS(status, NT_STATUS_OK);
78 io.lock.level = RAW_LOCK_UNLOCK;
79 status = smb_raw_lock(cli->tree, &io);
80 CHECK_STATUS(status, NT_STATUS_OK);
82 printf("Trying 0/1 lock\n");
83 io.lock.level = RAW_LOCK_LOCK;
84 io.lock.in.file.fnum = fnum;
86 io.lock.in.offset = 0;
87 status = smb_raw_lock(cli->tree, &io);
88 CHECK_STATUS(status, NT_STATUS_OK);
90 status = smb_raw_lock(cli->tree, &io);
91 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
93 io.lock.level = RAW_LOCK_UNLOCK;
94 status = smb_raw_lock(cli->tree, &io);
95 CHECK_STATUS(status, NT_STATUS_OK);
96 io.lock.level = RAW_LOCK_UNLOCK;
97 status = smb_raw_lock(cli->tree, &io);
98 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
100 printf("Trying 0xEEFFFFFF lock\n");
101 io.lock.level = RAW_LOCK_LOCK;
102 io.lock.in.file.fnum = fnum;
103 io.lock.in.count = 4000;
104 io.lock.in.offset = 0xEEFFFFFF;
105 status = smb_raw_lock(cli->tree, &io);
106 CHECK_STATUS(status, NT_STATUS_OK);
108 status = smb_raw_lock(cli->tree, &io);
109 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
111 io.lock.level = RAW_LOCK_UNLOCK;
112 status = smb_raw_lock(cli->tree, &io);
113 CHECK_STATUS(status, NT_STATUS_OK);
114 io.lock.level = RAW_LOCK_UNLOCK;
115 status = smb_raw_lock(cli->tree, &io);
116 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
118 printf("Trying 0xEF000000 lock\n");
119 io.lock.level = RAW_LOCK_LOCK;
120 io.lock.in.file.fnum = fnum;
121 io.lock.in.count = 4000;
122 io.lock.in.offset = 0xEEFFFFFF;
123 status = smb_raw_lock(cli->tree, &io);
124 CHECK_STATUS(status, NT_STATUS_OK);
126 status = smb_raw_lock(cli->tree, &io);
127 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
129 io.lock.level = RAW_LOCK_UNLOCK;
130 status = smb_raw_lock(cli->tree, &io);
131 CHECK_STATUS(status, NT_STATUS_OK);
132 io.lock.level = RAW_LOCK_UNLOCK;
133 status = smb_raw_lock(cli->tree, &io);
134 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
136 printf("Trying max lock\n");
137 io.lock.level = RAW_LOCK_LOCK;
138 io.lock.in.file.fnum = fnum;
139 io.lock.in.count = 4000;
140 io.lock.in.offset = 0xEF000000;
141 status = smb_raw_lock(cli->tree, &io);
142 CHECK_STATUS(status, NT_STATUS_OK);
144 status = smb_raw_lock(cli->tree, &io);
145 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
147 io.lock.level = RAW_LOCK_UNLOCK;
148 status = smb_raw_lock(cli->tree, &io);
149 CHECK_STATUS(status, NT_STATUS_OK);
150 io.lock.level = RAW_LOCK_UNLOCK;
151 status = smb_raw_lock(cli->tree, &io);
152 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
154 printf("Trying wrong pid unlock\n");
155 io.lock.level = RAW_LOCK_LOCK;
156 io.lock.in.file.fnum = fnum;
157 io.lock.in.count = 4002;
158 io.lock.in.offset = 10001;
159 status = smb_raw_lock(cli->tree, &io);
160 CHECK_STATUS(status, NT_STATUS_OK);
162 io.lock.level = RAW_LOCK_UNLOCK;
163 status = smb_raw_lock(cli->tree, &io);
164 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
166 status = smb_raw_lock(cli->tree, &io);
167 CHECK_STATUS(status, NT_STATUS_OK);
170 smbcli_close(cli->tree, fnum);
171 smb_raw_exit(cli->session);
172 smbcli_deltree(cli->tree, BASEDIR);
180 static BOOL test_lockx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
183 struct smb_lock_entry lock[1];
187 const char *fname = BASEDIR "\\test.txt";
189 if (!torture_setup_dir(cli, BASEDIR)) {
193 printf("Testing RAW_LOCK_LOCKX\n");
194 io.generic.level = RAW_LOCK_LOCKX;
196 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
198 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
203 io.lockx.level = RAW_LOCK_LOCKX;
204 io.lockx.in.file.fnum = fnum;
205 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
206 io.lockx.in.timeout = 0;
207 io.lockx.in.ulock_cnt = 0;
208 io.lockx.in.lock_cnt = 1;
209 lock[0].pid = cli->session->pid;
212 io.lockx.in.locks = &lock[0];
213 status = smb_raw_lock(cli->tree, &io);
214 CHECK_STATUS(status, NT_STATUS_OK);
217 printf("Trying 0xEEFFFFFF lock\n");
218 io.lockx.in.ulock_cnt = 0;
219 io.lockx.in.lock_cnt = 1;
220 lock[0].count = 4000;
221 lock[0].offset = 0xEEFFFFFF;
222 status = smb_raw_lock(cli->tree, &io);
223 CHECK_STATUS(status, NT_STATUS_OK);
225 status = smb_raw_lock(cli->tree, &io);
226 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
228 io.lockx.in.ulock_cnt = 1;
229 io.lockx.in.lock_cnt = 0;
230 status = smb_raw_lock(cli->tree, &io);
231 CHECK_STATUS(status, NT_STATUS_OK);
232 status = smb_raw_lock(cli->tree, &io);
233 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
235 printf("Trying 0xEF000000 lock\n");
236 io.lockx.in.ulock_cnt = 0;
237 io.lockx.in.lock_cnt = 1;
238 lock[0].count = 4000;
239 lock[0].offset = 0xEF000000;
240 status = smb_raw_lock(cli->tree, &io);
241 CHECK_STATUS(status, NT_STATUS_OK);
243 status = smb_raw_lock(cli->tree, &io);
244 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
246 io.lockx.in.ulock_cnt = 1;
247 io.lockx.in.lock_cnt = 0;
248 status = smb_raw_lock(cli->tree, &io);
249 CHECK_STATUS(status, NT_STATUS_OK);
250 status = smb_raw_lock(cli->tree, &io);
251 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
253 printf("Trying zero lock\n");
254 io.lockx.in.ulock_cnt = 0;
255 io.lockx.in.lock_cnt = 1;
258 status = smb_raw_lock(cli->tree, &io);
259 CHECK_STATUS(status, NT_STATUS_OK);
261 status = smb_raw_lock(cli->tree, &io);
262 CHECK_STATUS(status, NT_STATUS_OK);
264 io.lockx.in.ulock_cnt = 1;
265 io.lockx.in.lock_cnt = 0;
266 status = smb_raw_lock(cli->tree, &io);
267 CHECK_STATUS(status, NT_STATUS_OK);
268 status = smb_raw_lock(cli->tree, &io);
269 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
271 printf("Trying max lock\n");
272 io.lockx.in.ulock_cnt = 0;
273 io.lockx.in.lock_cnt = 1;
276 status = smb_raw_lock(cli->tree, &io);
277 CHECK_STATUS(status, NT_STATUS_OK);
279 status = smb_raw_lock(cli->tree, &io);
280 CHECK_STATUS(status, NT_STATUS_OK);
282 io.lockx.in.ulock_cnt = 1;
283 io.lockx.in.lock_cnt = 0;
284 status = smb_raw_lock(cli->tree, &io);
285 CHECK_STATUS(status, NT_STATUS_OK);
286 status = smb_raw_lock(cli->tree, &io);
287 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
289 printf("Trying 2^63\n");
290 io.lockx.in.ulock_cnt = 0;
291 io.lockx.in.lock_cnt = 1;
294 lock[0].offset <<= 63;
295 status = smb_raw_lock(cli->tree, &io);
296 CHECK_STATUS(status, NT_STATUS_OK);
298 status = smb_raw_lock(cli->tree, &io);
299 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
301 io.lockx.in.ulock_cnt = 1;
302 io.lockx.in.lock_cnt = 0;
303 status = smb_raw_lock(cli->tree, &io);
304 CHECK_STATUS(status, NT_STATUS_OK);
305 status = smb_raw_lock(cli->tree, &io);
306 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
308 printf("Trying 2^63 - 1\n");
309 io.lockx.in.ulock_cnt = 0;
310 io.lockx.in.lock_cnt = 1;
313 lock[0].offset <<= 63;
315 status = smb_raw_lock(cli->tree, &io);
316 CHECK_STATUS(status, NT_STATUS_OK);
318 status = smb_raw_lock(cli->tree, &io);
319 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
321 io.lockx.in.ulock_cnt = 1;
322 io.lockx.in.lock_cnt = 0;
323 status = smb_raw_lock(cli->tree, &io);
324 CHECK_STATUS(status, NT_STATUS_OK);
325 status = smb_raw_lock(cli->tree, &io);
326 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
328 printf("Trying max lock 2\n");
329 io.lockx.in.ulock_cnt = 0;
330 io.lockx.in.lock_cnt = 1;
333 status = smb_raw_lock(cli->tree, &io);
334 CHECK_STATUS(status, NT_STATUS_OK);
337 status = smb_raw_lock(cli->tree, &io);
338 CHECK_STATUS(status, NT_STATUS_OK);
340 io.lockx.in.ulock_cnt = 1;
341 io.lockx.in.lock_cnt = 0;
343 status = smb_raw_lock(cli->tree, &io);
344 CHECK_STATUS(status, NT_STATUS_OK);
345 status = smb_raw_lock(cli->tree, &io);
346 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
349 smbcli_close(cli->tree, fnum);
350 smb_raw_exit(cli->session);
351 smbcli_deltree(cli->tree, BASEDIR);
359 static BOOL test_pidhigh(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
362 struct smb_lock_entry lock[1];
366 const char *fname = BASEDIR "\\test.txt";
369 if (!torture_setup_dir(cli, BASEDIR)) {
373 printf("Testing high pid\n");
374 io.generic.level = RAW_LOCK_LOCKX;
376 cli->session->pid = 1;
378 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
380 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
385 if (smbcli_write(cli->tree, fnum, 0, &c, 0, 1) != 1) {
386 printf("Failed to write 1 byte - %s\n", smbcli_errstr(cli->tree));
391 io.lockx.level = RAW_LOCK_LOCKX;
392 io.lockx.in.file.fnum = fnum;
393 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
394 io.lockx.in.timeout = 0;
395 io.lockx.in.ulock_cnt = 0;
396 io.lockx.in.lock_cnt = 1;
397 lock[0].pid = cli->session->pid;
399 lock[0].count = 0xFFFFFFFF;
400 io.lockx.in.locks = &lock[0];
401 status = smb_raw_lock(cli->tree, &io);
402 CHECK_STATUS(status, NT_STATUS_OK);
404 if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
405 printf("Failed to read 1 byte - %s\n", smbcli_errstr(cli->tree));
410 cli->session->pid |= 0x10000;
412 cli->session->pid = 2;
414 if (smbcli_read(cli->tree, fnum, &c, 0, 1) == 1) {
415 printf("pid is incorrect handled for read with lock!\n");
420 cli->session->pid = 0x10001;
422 if (smbcli_read(cli->tree, fnum, &c, 0, 1) != 1) {
423 printf("High pid is used on this server!\n");
426 printf("High pid is not used on this server (correct)\n");
430 smbcli_close(cli->tree, fnum);
431 smb_raw_exit(cli->session);
432 smbcli_deltree(cli->tree, BASEDIR);
438 test locking&X async operation
440 static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
442 struct smbcli_session *session;
443 struct smb_composite_sesssetup setup;
444 struct smbcli_tree *tree;
446 const char *host, *share;
448 struct smb_lock_entry lock[2];
452 const char *fname = BASEDIR "\\test.txt";
454 struct smbcli_request *req;
456 if (!torture_setup_dir(cli, BASEDIR)) {
460 printf("Testing LOCKING_ANDX_CANCEL_LOCK\n");
461 io.generic.level = RAW_LOCK_LOCKX;
463 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
465 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
470 io.lockx.level = RAW_LOCK_LOCKX;
471 io.lockx.in.file.fnum = fnum;
472 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
473 io.lockx.in.timeout = 0;
474 io.lockx.in.ulock_cnt = 0;
475 io.lockx.in.lock_cnt = 1;
476 lock[0].pid = cli->session->pid;
477 lock[0].offset = 100;
479 io.lockx.in.locks = &lock[0];
480 status = smb_raw_lock(cli->tree, &io);
481 CHECK_STATUS(status, NT_STATUS_OK);
485 printf("testing cancel by CANCEL_LOCK\n");
487 /* setup a timed lock */
488 io.lockx.in.timeout = 10000;
489 req = smb_raw_lock_send(cli->tree, &io);
491 printf("Failed to setup timed lock (%s)\n", __location__);
496 /* cancel the wrong range */
498 io.lockx.in.timeout = 0;
499 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK;
500 status = smb_raw_lock(cli->tree, &io);
501 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRcancelviolation));
503 /* cancel with the wrong bits set */
504 lock[0].offset = 100;
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 the right range */
511 lock[0].offset = 100;
512 io.lockx.in.timeout = 0;
513 io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
514 status = smb_raw_lock(cli->tree, &io);
515 CHECK_STATUS(status, NT_STATUS_OK);
517 /* receive the failed lock request */
518 status = smbcli_request_simple_recv(req);
519 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
521 if (time(NULL) > t+2) {
522 printf("lock cancel was not immediate (%s)\n", __location__);
527 printf("testing cancel by unlock\n");
528 io.lockx.in.ulock_cnt = 0;
529 io.lockx.in.lock_cnt = 1;
530 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
531 io.lockx.in.timeout = 0;
532 status = smb_raw_lock(cli->tree, &io);
533 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
535 io.lockx.in.timeout = 5000;
536 req = smb_raw_lock_send(cli->tree, &io);
538 printf("Failed to setup timed lock (%s)\n", __location__);
543 io.lockx.in.ulock_cnt = 1;
544 io.lockx.in.lock_cnt = 0;
545 status = smb_raw_lock(cli->tree, &io);
546 CHECK_STATUS(status, NT_STATUS_OK);
549 status = smbcli_request_simple_recv(req);
550 CHECK_STATUS(status, NT_STATUS_OK);
552 if (time(NULL) > t+2) {
553 printf("lock cancel by unlock was not immediate (%s) - took %d secs\n",
554 __location__, (int)(time(NULL)-t));
559 printf("testing cancel by close\n");
560 io.lockx.in.ulock_cnt = 0;
561 io.lockx.in.lock_cnt = 1;
562 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
563 io.lockx.in.timeout = 0;
564 status = smb_raw_lock(cli->tree, &io);
565 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
568 io.lockx.in.timeout = 10000;
569 req = smb_raw_lock_send(cli->tree, &io);
571 printf("Failed to setup timed lock (%s)\n", __location__);
576 status = smbcli_close(cli->tree, fnum);
577 CHECK_STATUS(status, NT_STATUS_OK);
579 status = smbcli_request_simple_recv(req);
580 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
582 if (time(NULL) > t+2) {
583 printf("lock cancel by close was not immediate (%s)\n", __location__);
588 printf("create a new sessions\n");
589 session = smbcli_session_init(cli->transport, mem_ctx, False);
590 setup.in.sesskey = cli->transport->negotiate.sesskey;
591 setup.in.capabilities = cli->transport->negotiate.capabilities;
592 setup.in.workgroup = lp_workgroup();
593 setup.in.credentials = cmdline_credentials;
594 status = smb_composite_sesssetup(session, &setup);
595 CHECK_STATUS(status, NT_STATUS_OK);
596 session->vuid = setup.out.vuid;
598 printf("create new tree context\n");
599 share = lp_parm_string(-1, "torture", "share");
600 host = lp_parm_string(-1, "torture", "host");
601 tree = smbcli_tree_init(session, mem_ctx, False);
602 tcon.generic.level = RAW_TCON_TCONX;
603 tcon.tconx.in.flags = 0;
604 tcon.tconx.in.password = data_blob(NULL, 0);
605 tcon.tconx.in.path = talloc_asprintf(mem_ctx, "\\\\%s\\%s", host, share);
606 tcon.tconx.in.device = "A:";
607 status = smb_raw_tcon(tree, mem_ctx, &tcon);
608 CHECK_STATUS(status, NT_STATUS_OK);
609 tree->tid = tcon.tconx.out.tid;
611 printf("testing cancel by exit\n");
612 fname = BASEDIR "\\test_exit.txt";
613 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
615 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
619 io.lockx.level = RAW_LOCK_LOCKX;
620 io.lockx.in.file.fnum = fnum;
621 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
622 io.lockx.in.timeout = 0;
623 io.lockx.in.ulock_cnt = 0;
624 io.lockx.in.lock_cnt = 1;
625 lock[0].pid = session->pid;
626 lock[0].offset = 100;
628 io.lockx.in.locks = &lock[0];
629 status = smb_raw_lock(tree, &io);
630 CHECK_STATUS(status, NT_STATUS_OK);
632 io.lockx.in.ulock_cnt = 0;
633 io.lockx.in.lock_cnt = 1;
634 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
635 io.lockx.in.timeout = 0;
636 status = smb_raw_lock(tree, &io);
637 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
639 io.lockx.in.timeout = 10000;
641 req = smb_raw_lock_send(tree, &io);
643 printf("Failed to setup timed lock (%s)\n", __location__);
648 status = smb_raw_exit(session);
649 CHECK_STATUS(status, NT_STATUS_OK);
651 status = smbcli_request_simple_recv(req);
652 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
654 if (time(NULL) > t+2) {
655 printf("lock cancel by exit was not immediate (%s)\n", __location__);
660 printf("testing cancel by ulogoff\n");
661 fname = BASEDIR "\\test_ulogoff.txt";
662 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
664 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
668 io.lockx.level = RAW_LOCK_LOCKX;
669 io.lockx.in.file.fnum = fnum;
670 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
671 io.lockx.in.timeout = 0;
672 io.lockx.in.ulock_cnt = 0;
673 io.lockx.in.lock_cnt = 1;
674 lock[0].pid = session->pid;
675 lock[0].offset = 100;
677 io.lockx.in.locks = &lock[0];
678 status = smb_raw_lock(tree, &io);
679 CHECK_STATUS(status, NT_STATUS_OK);
681 io.lockx.in.ulock_cnt = 0;
682 io.lockx.in.lock_cnt = 1;
683 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
684 io.lockx.in.timeout = 0;
685 status = smb_raw_lock(tree, &io);
686 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
688 io.lockx.in.timeout = 10000;
690 req = smb_raw_lock_send(tree, &io);
692 printf("Failed to setup timed lock (%s)\n", __location__);
697 status = smb_raw_ulogoff(session);
698 CHECK_STATUS(status, NT_STATUS_OK);
700 status = smbcli_request_simple_recv(req);
701 if (NT_STATUS_EQUAL(NT_STATUS_FILE_LOCK_CONFLICT, status)) {
702 printf("lock not canceled by ulogoff - %s (ignored because of vfs_vifs fails it)\n",
704 smb_tree_disconnect(tree);
705 smb_raw_exit(session);
708 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
710 if (time(NULL) > t+2) {
711 printf("lock cancel by ulogoff was not immediate (%s)\n", __location__);
716 printf("testing cancel by tdis\n");
717 tree->session = cli->session;
719 fname = BASEDIR "\\test_tdis.txt";
720 fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
722 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(tree));
726 io.lockx.level = RAW_LOCK_LOCKX;
727 io.lockx.in.file.fnum = fnum;
728 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
729 io.lockx.in.timeout = 0;
730 io.lockx.in.ulock_cnt = 0;
731 io.lockx.in.lock_cnt = 1;
732 lock[0].pid = cli->session->pid;
733 lock[0].offset = 100;
735 io.lockx.in.locks = &lock[0];
736 status = smb_raw_lock(tree, &io);
737 CHECK_STATUS(status, NT_STATUS_OK);
739 status = smb_raw_lock(tree, &io);
740 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
742 io.lockx.in.timeout = 10000;
744 req = smb_raw_lock_send(tree, &io);
746 printf("Failed to setup timed lock (%s)\n", __location__);
751 status = smb_tree_disconnect(tree);
752 CHECK_STATUS(status, NT_STATUS_OK);
754 status = smbcli_request_simple_recv(req);
755 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
757 if (time(NULL) > t+2) {
758 printf("lock cancel by tdis was not immediate (%s)\n", __location__);
764 smb_raw_exit(cli->session);
765 smbcli_deltree(cli->tree, BASEDIR);
770 test NT_STATUS_LOCK_NOT_GRANTED vs. NT_STATUS_FILE_LOCK_CONFLICT
772 static BOOL test_errorcode(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
776 struct smb_lock_entry lock[2];
781 struct smbcli_request *req;
785 if (!torture_setup_dir(cli, BASEDIR)) {
789 printf("Testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT\n");
791 printf("testing with timeout = 0\n");
792 fname = BASEDIR "\\test0.txt";
796 * the first run is with t = 0,
797 * the second with t > 0 (=1)
801 * use the DENY_DOS mode, that creates two fnum's of one low-level file handle,
802 * this demonstrates that the cache is per fnum
804 op.openx.level = RAW_OPEN_OPENX;
805 op.openx.in.fname = fname;
806 op.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
807 op.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_DOS;
808 op.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
809 op.openx.in.search_attrs = 0;
810 op.openx.in.file_attrs = 0;
811 op.openx.in.write_time = 0;
812 op.openx.in.size = 0;
813 op.openx.in.timeout = 0;
815 status = smb_raw_open(cli->tree, mem_ctx, &op);
816 CHECK_STATUS(status, NT_STATUS_OK);
817 fnum = op.openx.out.file.fnum;
819 status = smb_raw_open(cli->tree, mem_ctx, &op);
820 CHECK_STATUS(status, NT_STATUS_OK);
821 fnum2 = op.openx.out.file.fnum;
823 io.lockx.level = RAW_LOCK_LOCKX;
824 io.lockx.in.file.fnum = fnum;
825 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
826 io.lockx.in.timeout = t;
827 io.lockx.in.ulock_cnt = 0;
828 io.lockx.in.lock_cnt = 1;
829 lock[0].pid = cli->session->pid;
830 lock[0].offset = 100;
832 io.lockx.in.locks = &lock[0];
833 status = smb_raw_lock(cli->tree, &io);
834 CHECK_STATUS(status, NT_STATUS_OK);
837 * demonstrate that the first conflicting lock on each handle give LOCK_NOT_GRANTED
838 * this also demonstrates that the error code cache is per file handle
839 * (LOCK_NOT_GRANTED is only be used when timeout is 0!)
841 io.lockx.in.file.fnum = fnum2;
842 status = smb_raw_lock(cli->tree, &io);
843 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
845 io.lockx.in.file.fnum = fnum;
846 status = smb_raw_lock(cli->tree, &io);
847 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
849 /* demonstrate that each following conflict gives FILE_LOCK_CONFLICT */
850 io.lockx.in.file.fnum = fnum;
851 status = smb_raw_lock(cli->tree, &io);
852 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
854 io.lockx.in.file.fnum = fnum2;
855 status = smb_raw_lock(cli->tree, &io);
856 CHECK_STATUS(status, NT_STATUS_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 /* demonstrate that the smbpid doesn't matter */
868 io.lockx.in.file.fnum = fnum;
869 status = smb_raw_lock(cli->tree, &io);
870 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
872 io.lockx.in.file.fnum = fnum2;
873 status = smb_raw_lock(cli->tree, &io);
874 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
878 * demonstrate the a successful lock with count = 0 and the same offset,
879 * doesn't reset the error cache
881 lock[0].offset = 100;
883 io.lockx.in.file.fnum = fnum;
884 status = smb_raw_lock(cli->tree, &io);
885 CHECK_STATUS(status, NT_STATUS_OK);
887 io.lockx.in.file.fnum = fnum2;
888 status = smb_raw_lock(cli->tree, &io);
889 CHECK_STATUS(status, NT_STATUS_OK);
891 lock[0].offset = 100;
893 io.lockx.in.file.fnum = fnum;
894 status = smb_raw_lock(cli->tree, &io);
895 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
897 io.lockx.in.file.fnum = fnum2;
898 status = smb_raw_lock(cli->tree, &io);
899 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
902 * demonstrate the a successful lock with count = 0 and outside the locked range,
903 * doesn't reset the error cache
905 lock[0].offset = 110;
907 io.lockx.in.file.fnum = fnum;
908 status = smb_raw_lock(cli->tree, &io);
909 CHECK_STATUS(status, NT_STATUS_OK);
911 io.lockx.in.file.fnum = fnum2;
912 status = smb_raw_lock(cli->tree, &io);
913 CHECK_STATUS(status, NT_STATUS_OK);
915 lock[0].offset = 100;
917 io.lockx.in.file.fnum = fnum;
918 status = smb_raw_lock(cli->tree, &io);
919 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
921 io.lockx.in.file.fnum = fnum2;
922 status = smb_raw_lock(cli->tree, &io);
923 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
927 io.lockx.in.file.fnum = fnum;
928 status = smb_raw_lock(cli->tree, &io);
929 CHECK_STATUS(status, NT_STATUS_OK);
931 io.lockx.in.file.fnum = fnum2;
932 status = smb_raw_lock(cli->tree, &io);
933 CHECK_STATUS(status, NT_STATUS_OK);
935 lock[0].offset = 100;
937 io.lockx.in.file.fnum = fnum;
938 status = smb_raw_lock(cli->tree, &io);
939 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
941 io.lockx.in.file.fnum = fnum2;
942 status = smb_raw_lock(cli->tree, &io);
943 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
945 /* demonstrate that a changing count doesn't reset the error cache */
946 lock[0].offset = 100;
948 io.lockx.in.file.fnum = fnum;
949 status = smb_raw_lock(cli->tree, &io);
950 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
952 io.lockx.in.file.fnum = fnum2;
953 status = smb_raw_lock(cli->tree, &io);
954 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
956 lock[0].offset = 100;
958 io.lockx.in.file.fnum = fnum;
959 status = smb_raw_lock(cli->tree, &io);
960 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
962 io.lockx.in.file.fnum = fnum2;
963 status = smb_raw_lock(cli->tree, &io);
964 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
967 * demonstrate the a lock with count = 0 and inside the locked range,
968 * fails and resets the error cache
970 lock[0].offset = 101;
972 io.lockx.in.file.fnum = fnum;
973 status = smb_raw_lock(cli->tree, &io);
974 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
975 status = smb_raw_lock(cli->tree, &io);
976 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
978 io.lockx.in.file.fnum = fnum2;
979 status = smb_raw_lock(cli->tree, &io);
980 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
981 status = smb_raw_lock(cli->tree, &io);
982 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
984 lock[0].offset = 100;
986 io.lockx.in.file.fnum = fnum;
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 io.lockx.in.file.fnum = fnum2;
993 status = smb_raw_lock(cli->tree, &io);
994 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
995 status = smb_raw_lock(cli->tree, &io);
996 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
998 /* demonstrate the a changing offset, resets the error cache */
999 lock[0].offset = 105;
1001 io.lockx.in.file.fnum = fnum;
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 io.lockx.in.file.fnum = fnum2;
1008 status = smb_raw_lock(cli->tree, &io);
1009 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1010 status = smb_raw_lock(cli->tree, &io);
1011 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1013 lock[0].offset = 100;
1015 io.lockx.in.file.fnum = fnum;
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 io.lockx.in.file.fnum = fnum2;
1022 status = smb_raw_lock(cli->tree, &io);
1023 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1024 status = smb_raw_lock(cli->tree, &io);
1025 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1027 lock[0].offset = 95;
1029 io.lockx.in.file.fnum = fnum;
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 io.lockx.in.file.fnum = fnum2;
1036 status = smb_raw_lock(cli->tree, &io);
1037 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1038 status = smb_raw_lock(cli->tree, &io);
1039 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1041 lock[0].offset = 100;
1043 io.lockx.in.file.fnum = fnum;
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 io.lockx.in.file.fnum = fnum2;
1050 status = smb_raw_lock(cli->tree, &io);
1051 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1052 status = smb_raw_lock(cli->tree, &io);
1053 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1056 * demonstrate the a successful lock in a different range,
1057 * doesn't reset the cache, the failing lock on the 2nd handle
1058 * resets the resets the cache
1060 lock[0].offset = 120;
1062 io.lockx.in.file.fnum = fnum;
1063 status = smb_raw_lock(cli->tree, &io);
1064 CHECK_STATUS(status, NT_STATUS_OK);
1066 io.lockx.in.file.fnum = fnum2;
1067 status = smb_raw_lock(cli->tree, &io);
1068 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1070 lock[0].offset = 100;
1072 io.lockx.in.file.fnum = fnum;
1073 status = smb_raw_lock(cli->tree, &io);
1074 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1075 status = smb_raw_lock(cli->tree, &io);
1076 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1078 io.lockx.in.file.fnum = fnum2;
1079 status = smb_raw_lock(cli->tree, &io);
1080 CHECK_STATUS(status, (t?NT_STATUS_FILE_LOCK_CONFLICT:NT_STATUS_LOCK_NOT_GRANTED));
1081 status = smb_raw_lock(cli->tree, &io);
1082 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1084 /* end of the loop */
1086 smb_raw_exit(cli->session);
1087 printf("testing with timeout > 0 (=1)\n");
1088 fname = BASEDIR "\\test1.txt";
1094 * the following 3 test sections demonstrate that
1095 * the cache is only set when the error is reported
1096 * to the client (after the timeout went by)
1098 smb_raw_exit(cli->session);
1099 printf("testing a conflict while a lock is pending\n");
1100 fname = BASEDIR "\\test2.txt";
1101 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1103 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1107 io.lockx.level = RAW_LOCK_LOCKX;
1108 io.lockx.in.file.fnum = fnum;
1109 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1110 io.lockx.in.timeout = 0;
1111 io.lockx.in.ulock_cnt = 0;
1112 io.lockx.in.lock_cnt = 1;
1113 lock[0].pid = cli->session->pid;
1114 lock[0].offset = 100;
1116 io.lockx.in.locks = &lock[0];
1117 status = smb_raw_lock(cli->tree, &io);
1118 CHECK_STATUS(status, NT_STATUS_OK);
1121 io.lockx.in.timeout = 1000;
1122 req = smb_raw_lock_send(cli->tree, &io);
1124 printf("Failed to setup timed lock (%s)\n", __location__);
1129 io.lockx.in.timeout = 0;
1130 lock[0].offset = 105;
1132 status = smb_raw_lock(cli->tree, &io);
1133 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1135 status = smbcli_request_simple_recv(req);
1136 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1138 status = smb_raw_lock(cli->tree, &io);
1139 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1141 if (time(NULL) < start+1) {
1142 printf("lock comes back to early (%s)\n", __location__);
1147 smbcli_close(cli->tree, fnum);
1148 fname = BASEDIR "\\test3.txt";
1149 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1151 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1155 io.lockx.level = RAW_LOCK_LOCKX;
1156 io.lockx.in.file.fnum = fnum;
1157 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1158 io.lockx.in.timeout = 0;
1159 io.lockx.in.ulock_cnt = 0;
1160 io.lockx.in.lock_cnt = 1;
1161 lock[0].pid = cli->session->pid;
1162 lock[0].offset = 100;
1164 io.lockx.in.locks = &lock[0];
1165 status = smb_raw_lock(cli->tree, &io);
1166 CHECK_STATUS(status, NT_STATUS_OK);
1169 io.lockx.in.timeout = 1000;
1170 req = smb_raw_lock_send(cli->tree, &io);
1172 printf("Failed to setup timed lock (%s)\n", __location__);
1177 io.lockx.in.timeout = 0;
1178 lock[0].offset = 105;
1180 status = smb_raw_lock(cli->tree, &io);
1181 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1183 status = smbcli_request_simple_recv(req);
1184 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1186 lock[0].offset = 100;
1188 status = smb_raw_lock(cli->tree, &io);
1189 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1191 if (time(NULL) < start+1) {
1192 printf("lock comes back to early (%s)\n", __location__);
1197 smbcli_close(cli->tree, fnum);
1198 fname = BASEDIR "\\test4.txt";
1199 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1201 printf("Failed to reopen %s - %s\n", fname, smbcli_errstr(cli->tree));
1205 io.lockx.level = RAW_LOCK_LOCKX;
1206 io.lockx.in.file.fnum = fnum;
1207 io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1208 io.lockx.in.timeout = 0;
1209 io.lockx.in.ulock_cnt = 0;
1210 io.lockx.in.lock_cnt = 1;
1211 lock[0].pid = cli->session->pid;
1212 lock[0].offset = 100;
1214 io.lockx.in.locks = &lock[0];
1215 status = smb_raw_lock(cli->tree, &io);
1216 CHECK_STATUS(status, NT_STATUS_OK);
1219 io.lockx.in.timeout = 1000;
1220 req = smb_raw_lock_send(cli->tree, &io);
1222 printf("Failed to setup timed lock (%s)\n", __location__);
1227 io.lockx.in.timeout = 0;
1228 status = smb_raw_lock(cli->tree, &io);
1229 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
1231 status = smbcli_request_simple_recv(req);
1232 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1234 status = smb_raw_lock(cli->tree, &io);
1235 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
1237 if (time(NULL) < start+1) {
1238 printf("lock comes back to early (%s)\n", __location__);
1244 smb_raw_exit(cli->session);
1245 smbcli_deltree(cli->tree, BASEDIR);
1251 test LOCKING_ANDX_CHANGE_LOCKTYPE
1253 static BOOL test_changetype(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1256 struct smb_lock_entry lock[2];
1261 const char *fname = BASEDIR "\\test.txt";
1263 if (!torture_setup_dir(cli, BASEDIR)) {
1267 printf("Testing LOCKING_ANDX_CHANGE_LOCKTYPE\n");
1268 io.generic.level = RAW_LOCK_LOCKX;
1270 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1272 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
1277 io.lockx.level = RAW_LOCK_LOCKX;
1278 io.lockx.in.file.fnum = fnum;
1279 io.lockx.in.mode = LOCKING_ANDX_SHARED_LOCK;
1280 io.lockx.in.timeout = 0;
1281 io.lockx.in.ulock_cnt = 0;
1282 io.lockx.in.lock_cnt = 1;
1283 lock[0].pid = cli->session->pid;
1284 lock[0].offset = 100;
1286 io.lockx.in.locks = &lock[0];
1287 status = smb_raw_lock(cli->tree, &io);
1288 CHECK_STATUS(status, NT_STATUS_OK);
1290 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1291 printf("allowed write on read locked region (%s)\n", __location__);
1296 /* windows server don't seem to support this */
1297 io.lockx.in.mode = LOCKING_ANDX_CHANGE_LOCKTYPE;
1298 status = smb_raw_lock(cli->tree, &io);
1299 CHECK_STATUS(status, NT_STATUS_DOS(ERRDOS, ERRnoatomiclocks));
1301 if (smbcli_write(cli->tree, fnum, 0, &c, 100, 1) == 1) {
1302 printf("allowed write after lock change (%s)\n", __location__);
1308 smbcli_close(cli->tree, fnum);
1309 smb_raw_exit(cli->session);
1310 smbcli_deltree(cli->tree, BASEDIR);
1316 basic testing of lock calls
1318 BOOL torture_raw_lock(struct torture_context *torture)
1320 struct smbcli_state *cli;
1322 TALLOC_CTX *mem_ctx;
1324 if (!torture_open_connection(&cli, 0)) {
1328 mem_ctx = talloc_init("torture_raw_lock");
1330 ret &= test_lockx(cli, mem_ctx);
1331 ret &= test_lock(cli, mem_ctx);
1332 ret &= test_pidhigh(cli, mem_ctx);
1333 ret &= test_async(cli, mem_ctx);
1334 ret &= test_errorcode(cli, mem_ctx);
1335 ret &= test_changetype(cli, mem_ctx);
1337 torture_close_connection(cli);
1338 talloc_free(mem_ctx);