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 "libcli/raw/libcliraw.h"
22 #include "libcli/libcli.h"
23 #include "torture/util.h"
24 #include "torture/raw/proto.h"
26 #define BASEDIR "\\mkdirtest"
28 #define CHECK_STATUS(status, correct) do { \
29 if (!NT_STATUS_EQUAL(status, correct)) { \
30 printf("(%s) Incorrect status %s - should be %s\n", \
31 __location__, nt_errstr(status), nt_errstr(correct)); \
39 static bool test_mkdir(struct smbcli_state
*cli
, struct torture_context
*tctx
)
43 const char *path
= BASEDIR
"\\mkdir.dir";
47 if (!torture_setup_dir(cli
, BASEDIR
)) {
54 md
.mkdir
.level
= RAW_MKDIR_MKDIR
;
55 md
.mkdir
.in
.path
= path
;
57 status
= smb_raw_mkdir(cli
->tree
, &md
);
58 CHECK_STATUS(status
, NT_STATUS_OK
);
60 printf("Testing mkdir collision\n");
63 status
= smb_raw_mkdir(cli
->tree
, &md
);
64 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_COLLISION
);
68 status
= smb_raw_rmdir(cli
->tree
, &rd
);
69 CHECK_STATUS(status
, NT_STATUS_OK
);
71 status
= smb_raw_rmdir(cli
->tree
, &rd
);
72 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
74 printf("Testing mkdir collision with file\n");
76 /* name collision with a file */
77 smbcli_close(cli
->tree
, create_complex_file(cli
, tctx
, path
));
78 status
= smb_raw_mkdir(cli
->tree
, &md
);
79 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_COLLISION
);
81 printf("Testing rmdir with file\n");
83 /* delete a file with rmdir */
84 status
= smb_raw_rmdir(cli
->tree
, &rd
);
85 CHECK_STATUS(status
, NT_STATUS_NOT_A_DIRECTORY
);
87 smbcli_unlink(cli
->tree
, path
);
89 printf("Testing invalid dir\n");
91 /* create an invalid dir */
92 md
.mkdir
.in
.path
= "..\\..\\..";
93 status
= smb_raw_mkdir(cli
->tree
, &md
);
94 CHECK_STATUS(status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
96 printf("Testing t2mkdir\n");
98 /* try a t2mkdir - need to work out why this fails! */
99 md
.t2mkdir
.level
= RAW_MKDIR_T2MKDIR
;
100 md
.t2mkdir
.in
.path
= path
;
101 md
.t2mkdir
.in
.num_eas
= 0;
102 status
= smb_raw_mkdir(cli
->tree
, &md
);
103 CHECK_STATUS(status
, NT_STATUS_OK
);
105 status
= smb_raw_rmdir(cli
->tree
, &rd
);
106 CHECK_STATUS(status
, NT_STATUS_OK
);
108 printf("Testing t2mkdir bad path\n");
109 md
.t2mkdir
.in
.path
= talloc_asprintf(tctx
, "%s\\bad_path\\bad_path",
111 status
= smb_raw_mkdir(cli
->tree
, &md
);
112 CHECK_STATUS(status
, NT_STATUS_OBJECT_PATH_NOT_FOUND
);
114 printf("Testing t2mkdir with EAs\n");
117 md
.t2mkdir
.level
= RAW_MKDIR_T2MKDIR
;
118 md
.t2mkdir
.in
.path
= path
;
119 md
.t2mkdir
.in
.num_eas
= 3;
120 md
.t2mkdir
.in
.eas
= talloc_array(tctx
, struct ea_struct
, md
.t2mkdir
.in
.num_eas
);
121 md
.t2mkdir
.in
.eas
[0].flags
= 0;
122 md
.t2mkdir
.in
.eas
[0].name
.s
= "EAONE";
123 md
.t2mkdir
.in
.eas
[0].value
= data_blob_talloc(tctx
, "blah", 4);
124 md
.t2mkdir
.in
.eas
[1].flags
= 0;
125 md
.t2mkdir
.in
.eas
[1].name
.s
= "EA TWO";
126 md
.t2mkdir
.in
.eas
[1].value
= data_blob_talloc(tctx
, "foo bar", 7);
127 md
.t2mkdir
.in
.eas
[2].flags
= 0;
128 md
.t2mkdir
.in
.eas
[2].name
.s
= "EATHREE";
129 md
.t2mkdir
.in
.eas
[2].value
= data_blob_talloc(tctx
, "xx1", 3);
130 status
= smb_raw_mkdir(cli
->tree
, &md
);
132 if (torture_setting_bool(tctx
, "samba3", false)
133 && NT_STATUS_EQUAL(status
, NT_STATUS_EAS_NOT_SUPPORTED
)) {
134 d_printf("EAS not supported -- not treating as fatal\n");
138 * In Samba3, don't see this error as fatal
140 CHECK_STATUS(status
, NT_STATUS_OK
);
142 status
= torture_check_ea(cli
, path
, "EAONE", "blah");
143 CHECK_STATUS(status
, NT_STATUS_OK
);
144 status
= torture_check_ea(cli
, path
, "EA TWO", "foo bar");
145 CHECK_STATUS(status
, NT_STATUS_OK
);
146 status
= torture_check_ea(cli
, path
, "EATHREE", "xx1");
147 CHECK_STATUS(status
, NT_STATUS_OK
);
149 status
= smb_raw_rmdir(cli
->tree
, &rd
);
150 CHECK_STATUS(status
, NT_STATUS_OK
);
154 smb_raw_exit(cli
->session
);
155 smbcli_deltree(cli
->tree
, BASEDIR
);
161 basic testing of all RAW_MKDIR_* calls
163 bool torture_raw_mkdir(struct torture_context
*torture
,
164 struct smbcli_state
*cli
)
168 if (!test_mkdir(cli
, torture
)) {