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 (!torture_setup_dir(cli, BASEDIR)) {
47 printf("Trying non-existant file\n");
48 io.in.pattern = fname;
50 status = smb_raw_unlink(cli->tree, &io);
51 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
53 smbcli_close(cli->tree, smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
55 io.in.pattern = fname;
57 status = smb_raw_unlink(cli->tree, &io);
58 CHECK_STATUS(status, NT_STATUS_OK);
60 printf("Trying a hidden file\n");
61 smbcli_close(cli->tree, smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
62 torture_set_file_attribute(cli->tree, fname, FILE_ATTRIBUTE_HIDDEN);
64 io.in.pattern = fname;
66 status = smb_raw_unlink(cli->tree, &io);
67 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
69 io.in.pattern = fname;
70 io.in.attrib = FILE_ATTRIBUTE_HIDDEN;
71 status = smb_raw_unlink(cli->tree, &io);
72 CHECK_STATUS(status, NT_STATUS_OK);
74 io.in.pattern = fname;
75 io.in.attrib = FILE_ATTRIBUTE_HIDDEN;
76 status = smb_raw_unlink(cli->tree, &io);
77 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
79 printf("Trying a directory\n");
80 io.in.pattern = BASEDIR;
82 status = smb_raw_unlink(cli->tree, &io);
83 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
85 io.in.pattern = BASEDIR;
86 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
87 status = smb_raw_unlink(cli->tree, &io);
88 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
90 printf("Trying a bad path\n");
93 status = smb_raw_unlink(cli->tree, &io);
94 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
96 io.in.pattern = "\\..";
98 status = smb_raw_unlink(cli->tree, &io);
99 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
101 io.in.pattern = BASEDIR "\\..\\..";
103 status = smb_raw_unlink(cli->tree, &io);
104 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
106 io.in.pattern = BASEDIR "\\..";
108 status = smb_raw_unlink(cli->tree, &io);
109 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
111 printf("Trying wildcards\n");
112 smbcli_close(cli->tree, smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
113 io.in.pattern = BASEDIR "\\t*.t";
115 status = smb_raw_unlink(cli->tree, &io);
116 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
118 io.in.pattern = BASEDIR "\\z*";
120 status = smb_raw_unlink(cli->tree, &io);
121 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
123 io.in.pattern = BASEDIR "\\z*";
124 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
125 status = smb_raw_unlink(cli->tree, &io);
126 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
128 io.in.pattern = BASEDIR "\\*";
129 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
130 status = smb_raw_unlink(cli->tree, &io);
131 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
133 io.in.pattern = BASEDIR "\\?";
134 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
135 status = smb_raw_unlink(cli->tree, &io);
136 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
138 io.in.pattern = BASEDIR "\\t*";
139 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
140 status = smb_raw_unlink(cli->tree, &io);
141 CHECK_STATUS(status, NT_STATUS_OK);
143 smbcli_close(cli->tree, smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
145 io.in.pattern = BASEDIR "\\*.dat";
146 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
147 status = smb_raw_unlink(cli->tree, &io);
148 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
150 io.in.pattern = BASEDIR "\\*.tx?";
152 status = smb_raw_unlink(cli->tree, &io);
153 CHECK_STATUS(status, NT_STATUS_OK);
155 status = smb_raw_unlink(cli->tree, &io);
156 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
160 smb_raw_exit(cli->session);
161 smbcli_deltree(cli->tree, BASEDIR);
167 basic testing of unlink calls
169 BOOL torture_raw_unlink(void)
171 struct smbcli_state *cli;
175 if (!torture_open_connection(&cli)) {
179 mem_ctx = talloc_init("torture_raw_unlink");
181 if (!test_unlink(cli, mem_ctx)) {
185 torture_close_connection(cli);
186 talloc_free(mem_ctx);