2 Unix SMB/CIFS implementation.
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define CHECK_STATUS(status, correct) do { \
24 if (!NT_STATUS_EQUAL(status, correct)) { \
25 printf("(%s) Incorrect status %s - should be %s\n", \
26 __location__, nt_errstr(status), nt_errstr(correct)); \
31 #define BASEDIR "\\testunlink"
36 static BOOL test_unlink(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
41 const char *fname = BASEDIR "\\test.txt";
43 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
44 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
45 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
49 printf("Trying non-existant file\n");
50 io.in.pattern = fname;
52 status = smb_raw_unlink(cli->tree, &io);
53 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
55 smbcli_close(cli->tree, smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
57 io.in.pattern = fname;
59 status = smb_raw_unlink(cli->tree, &io);
60 CHECK_STATUS(status, NT_STATUS_OK);
62 printf("Trying a hidden file\n");
63 smbcli_close(cli->tree, smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
64 torture_set_file_attribute(cli->tree, fname, FILE_ATTRIBUTE_HIDDEN);
66 io.in.pattern = fname;
68 status = smb_raw_unlink(cli->tree, &io);
69 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
71 io.in.pattern = fname;
72 io.in.attrib = FILE_ATTRIBUTE_HIDDEN;
73 status = smb_raw_unlink(cli->tree, &io);
74 CHECK_STATUS(status, NT_STATUS_OK);
76 io.in.pattern = fname;
77 io.in.attrib = FILE_ATTRIBUTE_HIDDEN;
78 status = smb_raw_unlink(cli->tree, &io);
79 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
81 printf("Trying a directory\n");
82 io.in.pattern = BASEDIR;
84 status = smb_raw_unlink(cli->tree, &io);
85 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
87 io.in.pattern = BASEDIR;
88 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
89 status = smb_raw_unlink(cli->tree, &io);
90 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
92 printf("Trying a bad path\n");
95 status = smb_raw_unlink(cli->tree, &io);
96 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
98 io.in.pattern = "\\..";
100 status = smb_raw_unlink(cli->tree, &io);
101 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
103 io.in.pattern = BASEDIR "\\..\\..";
105 status = smb_raw_unlink(cli->tree, &io);
106 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
108 io.in.pattern = BASEDIR "\\..";
110 status = smb_raw_unlink(cli->tree, &io);
111 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
113 printf("Trying wildcards\n");
114 smbcli_close(cli->tree, smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
115 io.in.pattern = BASEDIR "\\t*.t";
117 status = smb_raw_unlink(cli->tree, &io);
118 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
120 io.in.pattern = BASEDIR "\\z*";
122 status = smb_raw_unlink(cli->tree, &io);
123 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
125 io.in.pattern = BASEDIR "\\z*";
126 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
127 status = smb_raw_unlink(cli->tree, &io);
128 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
130 io.in.pattern = BASEDIR "\\*";
131 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
132 status = smb_raw_unlink(cli->tree, &io);
133 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
135 io.in.pattern = BASEDIR "\\?";
136 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
137 status = smb_raw_unlink(cli->tree, &io);
138 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
140 io.in.pattern = BASEDIR "\\t*";
141 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
142 status = smb_raw_unlink(cli->tree, &io);
143 CHECK_STATUS(status, NT_STATUS_OK);
145 smbcli_close(cli->tree, smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
147 io.in.pattern = BASEDIR "\\*.dat";
148 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
149 status = smb_raw_unlink(cli->tree, &io);
150 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
152 io.in.pattern = BASEDIR "\\*.tx?";
154 status = smb_raw_unlink(cli->tree, &io);
155 CHECK_STATUS(status, NT_STATUS_OK);
157 status = smb_raw_unlink(cli->tree, &io);
158 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
162 smb_raw_exit(cli->session);
163 smbcli_deltree(cli->tree, BASEDIR);
169 basic testing of unlink calls
171 BOOL torture_raw_unlink(int dummy)
173 struct smbcli_state *cli;
177 if (!torture_open_connection(&cli)) {
181 mem_ctx = talloc_init("torture_raw_unlink");
183 if (!test_unlink(cli, mem_ctx)) {
187 torture_close_connection(cli);
188 talloc_destroy(mem_ctx);