2 Unix SMB/CIFS implementation.
3 RAW_MKDIR_* and RAW_RMDIR_* individual test suite
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 "libcli/raw/raw_proto.h"
24 #include "libcli/libcli.h"
25 #include "torture/util.h"
27 #define BASEDIR "\\mkdirtest"
29 #define CHECK_STATUS(status, correct) do { \
30 if (!NT_STATUS_EQUAL(status, correct)) { \
31 printf("(%s) Incorrect status %s - should be %s\n", \
32 __location__, nt_errstr(status), nt_errstr(correct)); \
40 static bool test_mkdir(struct smbcli_state
*cli
, struct torture_context
*tctx
)
44 const char *path
= BASEDIR
"\\mkdir.dir";
48 if (!torture_setup_dir(cli
, BASEDIR
)) {
55 md
.mkdir
.level
= RAW_MKDIR_MKDIR
;
56 md
.mkdir
.in
.path
= path
;
58 status
= smb_raw_mkdir(cli
->tree
, &md
);
59 CHECK_STATUS(status
, NT_STATUS_OK
);
61 printf("testing mkdir collision\n");
64 status
= smb_raw_mkdir(cli
->tree
, &md
);
65 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_COLLISION
);
69 status
= smb_raw_rmdir(cli
->tree
, &rd
);
70 CHECK_STATUS(status
, NT_STATUS_OK
);
72 status
= smb_raw_rmdir(cli
->tree
, &rd
);
73 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
75 printf("testing mkdir collision with file\n");
77 /* name collision with a file */
78 smbcli_close(cli
->tree
, create_complex_file(cli
, tctx
, path
));
79 status
= smb_raw_mkdir(cli
->tree
, &md
);
80 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_COLLISION
);
82 printf("testing rmdir with file\n");
84 /* delete a file with rmdir */
85 status
= smb_raw_rmdir(cli
->tree
, &rd
);
86 CHECK_STATUS(status
, NT_STATUS_NOT_A_DIRECTORY
);
88 smbcli_unlink(cli
->tree
, path
);
90 printf("testing invalid dir\n");
92 /* create an invalid dir */
93 md
.mkdir
.in
.path
= "..\\..\\..";
94 status
= smb_raw_mkdir(cli
->tree
, &md
);
95 CHECK_STATUS(status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
97 printf("testing t2mkdir\n");
99 /* try a t2mkdir - need to work out why this fails! */
100 md
.t2mkdir
.level
= RAW_MKDIR_T2MKDIR
;
101 md
.t2mkdir
.in
.path
= path
;
102 md
.t2mkdir
.in
.num_eas
= 0;
103 status
= smb_raw_mkdir(cli
->tree
, &md
);
104 CHECK_STATUS(status
, NT_STATUS_OK
);
106 status
= smb_raw_rmdir(cli
->tree
, &rd
);
107 CHECK_STATUS(status
, NT_STATUS_OK
);
109 printf("testing t2mkdir bad path\n");
110 md
.t2mkdir
.in
.path
= talloc_asprintf(tctx
, "%s\\bad_path\\bad_path",
112 status
= smb_raw_mkdir(cli
->tree
, &md
);
113 CHECK_STATUS(status
, NT_STATUS_OBJECT_PATH_NOT_FOUND
);
115 printf("testing t2mkdir with EAs\n");
118 md
.t2mkdir
.level
= RAW_MKDIR_T2MKDIR
;
119 md
.t2mkdir
.in
.path
= path
;
120 md
.t2mkdir
.in
.num_eas
= 3;
121 md
.t2mkdir
.in
.eas
= talloc_array(tctx
, struct ea_struct
, md
.t2mkdir
.in
.num_eas
);
122 md
.t2mkdir
.in
.eas
[0].flags
= 0;
123 md
.t2mkdir
.in
.eas
[0].name
.s
= "EAONE";
124 md
.t2mkdir
.in
.eas
[0].value
= data_blob_talloc(tctx
, "blah", 4);
125 md
.t2mkdir
.in
.eas
[1].flags
= 0;
126 md
.t2mkdir
.in
.eas
[1].name
.s
= "EA TWO";
127 md
.t2mkdir
.in
.eas
[1].value
= data_blob_talloc(tctx
, "foo bar", 7);
128 md
.t2mkdir
.in
.eas
[2].flags
= 0;
129 md
.t2mkdir
.in
.eas
[2].name
.s
= "EATHREE";
130 md
.t2mkdir
.in
.eas
[2].value
= data_blob_talloc(tctx
, "xx1", 3);
131 status
= smb_raw_mkdir(cli
->tree
, &md
);
133 if (torture_setting_bool(tctx
, "samba3", false)
134 && NT_STATUS_EQUAL(status
, NT_STATUS_EAS_NOT_SUPPORTED
)) {
135 d_printf("EAS not supported -- not treating as fatal\n");
139 * In Samba3, don't see this error as fatal
141 CHECK_STATUS(status
, NT_STATUS_OK
);
143 status
= torture_check_ea(cli
, path
, "EAONE", "blah");
144 CHECK_STATUS(status
, NT_STATUS_OK
);
145 status
= torture_check_ea(cli
, path
, "EA TWO", "foo bar");
146 CHECK_STATUS(status
, NT_STATUS_OK
);
147 status
= torture_check_ea(cli
, path
, "EATHREE", "xx1");
148 CHECK_STATUS(status
, NT_STATUS_OK
);
150 status
= smb_raw_rmdir(cli
->tree
, &rd
);
151 CHECK_STATUS(status
, NT_STATUS_OK
);
155 smb_raw_exit(cli
->session
);
156 smbcli_deltree(cli
->tree
, BASEDIR
);
162 basic testing of all RAW_MKDIR_* calls
164 bool torture_raw_mkdir(struct torture_context
*torture
,
165 struct smbcli_state
*cli
)
169 if (!test_mkdir(cli
, torture
)) {