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("(%d) Incorrect status %s - should be %s\n", \
26 __LINE__, nt_errstr(status), nt_errstr(correct)); \
31 #define BASEDIR "\\testunlink"
36 static BOOL test_unlink(struct cli_state *cli, TALLOC_CTX *mem_ctx)
41 const char *fname = BASEDIR "\\test.txt";
43 if (cli_deltree(cli->tree, BASEDIR) == -1 ||
44 NT_STATUS_IS_ERR(cli_mkdir(cli->tree, BASEDIR))) {
45 printf("Unable to setup %s - %s\n", BASEDIR, cli_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 cli_close(cli->tree, cli_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 cli_close(cli->tree, cli_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 printf("Trying a directory\n");
77 io.in.pattern = BASEDIR;
79 status = smb_raw_unlink(cli->tree, &io);
80 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
82 io.in.pattern = BASEDIR;
83 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
84 status = smb_raw_unlink(cli->tree, &io);
85 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
87 printf("Trying a bad path\n");
90 status = smb_raw_unlink(cli->tree, &io);
91 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
93 io.in.pattern = "\\..";
95 status = smb_raw_unlink(cli->tree, &io);
96 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
98 io.in.pattern = BASEDIR "\\..";
100 status = smb_raw_unlink(cli->tree, &io);
101 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
103 printf("Trying wildcards\n");
104 cli_close(cli->tree, cli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE));
105 io.in.pattern = BASEDIR "\\t*.t";
107 status = smb_raw_unlink(cli->tree, &io);
108 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
110 io.in.pattern = BASEDIR "\\*";
111 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
112 status = smb_raw_unlink(cli->tree, &io);
113 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
115 io.in.pattern = BASEDIR "\\*.dat";
116 io.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
117 status = smb_raw_unlink(cli->tree, &io);
118 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
120 io.in.pattern = BASEDIR "\\*.tx?";
122 status = smb_raw_unlink(cli->tree, &io);
123 CHECK_STATUS(status, NT_STATUS_OK);
125 status = smb_raw_unlink(cli->tree, &io);
126 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
130 smb_raw_exit(cli->session);
131 cli_deltree(cli->tree, BASEDIR);
137 basic testing of unlink calls
139 BOOL torture_raw_unlink(int dummy)
141 struct cli_state *cli;
145 if (!torture_open_connection(&cli)) {
149 mem_ctx = talloc_init("torture_raw_unlink");
151 if (!test_unlink(cli, mem_ctx)) {
155 torture_close_connection(cli);
156 talloc_destroy(mem_ctx);