2 Unix SMB/CIFS implementation.
4 Copyright (C) Volker Lendecke 2011
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/proto.h"
22 #include "system/filesys.h"
23 #include "libsmb/libsmb.h"
24 #include "libcli/smb/smbXcli_base.h"
25 #include "libcli/security/security.h"
27 bool run_cleanup1(int dummy)
29 struct cli_state *cli;
30 const char *fname = "\\cleanup1";
34 printf("CLEANUP1: Checking that a conflicting share mode is cleaned "
37 if (!torture_open_connection(&cli, 0)) {
40 status = cli_openx(cli, fname, O_RDWR|O_CREAT, DENY_ALL, &fnum);
41 if (!NT_STATUS_IS_OK(status)) {
42 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
45 status = smbXcli_conn_samba_suicide(cli->conn, 1);
46 if (!NT_STATUS_IS_OK(status)) {
47 printf("smbXcli_conn_samba_suicide failed: %s\n",
52 if (!torture_open_connection(&cli, 1)) {
55 status = cli_ntcreate(
57 FILE_GENERIC_READ|FILE_GENERIC_WRITE|DELETE_ACCESS,
58 FILE_ATTRIBUTE_NORMAL,
59 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
60 FILE_OPEN, FILE_DELETE_ON_CLOSE, 0, &fnum);
61 if (!NT_STATUS_IS_OK(status)) {
62 printf("2nd open of %s failed (%s)\n", fname,
68 torture_close_connection(cli);
69 return NT_STATUS_IS_OK(status);
72 bool run_cleanup2(int dummy)
74 struct cli_state *cli1, *cli2;
75 const char *fname = "\\cleanup2";
76 uint16_t fnum1, fnum2;
80 printf("CLEANUP2: Checking that a conflicting brlock is cleaned up\n");
82 if (!torture_open_connection(&cli1, 0)) {
85 status = cli_ntcreate(
86 cli1, fname, 0, FILE_GENERIC_READ|FILE_GENERIC_WRITE,
87 FILE_ATTRIBUTE_NORMAL,
88 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
89 FILE_OVERWRITE_IF, 0, 0, &fnum1);
90 if (!NT_STATUS_IS_OK(status)) {
91 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
94 status = cli_lock32(cli1, fnum1, 0, 1, 0, WRITE_LOCK);
95 if (!NT_STATUS_IS_OK(status)) {
96 printf("lock failed (%s)\n", nt_errstr(status));
101 * Check the file is indeed locked
103 if (!torture_open_connection(&cli2, 0)) {
106 status = cli_ntcreate(
107 cli2, fname, 0, FILE_GENERIC_READ|FILE_GENERIC_WRITE,
108 FILE_ATTRIBUTE_NORMAL,
109 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
110 FILE_OPEN, 0, 0, &fnum2);
111 if (!NT_STATUS_IS_OK(status)) {
112 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
116 status = cli_smbwrite(cli2, fnum2, &buf, 0, 1, NULL);
117 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
118 printf("write succeeded\n");
123 * Kill the lock holder
125 status = smbXcli_conn_samba_suicide(cli1->conn, 1);
126 if (!NT_STATUS_IS_OK(status)) {
127 printf("smbXcli_conn_samba_suicide failed: %s\n",
133 * Right now we don't clean up immediately. Re-open the 2nd connection.
137 if (!torture_open_connection(&cli2, 0)) {
140 status = cli_ntcreate(
141 cli2, fname, 0, FILE_GENERIC_READ|FILE_GENERIC_WRITE,
142 FILE_ATTRIBUTE_NORMAL,
143 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
144 FILE_OPEN, 0, 0, &fnum2);
145 if (!NT_STATUS_IS_OK(status)) {
146 printf("open of %s failed (%s)\n", fname, nt_errstr(status));
150 status = cli_smbwrite(cli2, fnum2, &buf, 0, 1, NULL);
151 if (!NT_STATUS_IS_OK(status)) {
152 printf("write failed: %s\n", nt_errstr(status));