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 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.
22 #include "torture/torture.h"
23 #include "libcli/raw/libcliraw.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, TALLOC_CTX *mem_ctx)
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, mem_ctx, 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 with EAs\n");
112 md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
113 md.t2mkdir.in.path = path;
114 md.t2mkdir.in.num_eas = 3;
115 md.t2mkdir.in.eas = talloc_array(mem_ctx, struct ea_struct, md.t2mkdir.in.num_eas);
116 md.t2mkdir.in.eas[0].flags = 0;
117 md.t2mkdir.in.eas[0].name.s = "EAONE";
118 md.t2mkdir.in.eas[0].value = data_blob_talloc(mem_ctx, "blah", 4);
119 md.t2mkdir.in.eas[1].flags = 0;
120 md.t2mkdir.in.eas[1].name.s = "EA TWO";
121 md.t2mkdir.in.eas[1].value = data_blob_talloc(mem_ctx, "foo bar", 7);
122 md.t2mkdir.in.eas[2].flags = 0;
123 md.t2mkdir.in.eas[2].name.s = "EATHREE";
124 md.t2mkdir.in.eas[2].value = data_blob_talloc(mem_ctx, "xx1", 3);
125 status = smb_raw_mkdir(cli->tree, &md);
126 CHECK_STATUS(status, NT_STATUS_OK);
128 status = torture_check_ea(cli, path, "EAONE", "blah");
129 CHECK_STATUS(status, NT_STATUS_OK);
130 status = torture_check_ea(cli, path, "EA TWO", "foo bar");
131 CHECK_STATUS(status, NT_STATUS_OK);
132 status = torture_check_ea(cli, path, "EATHREE", "xx1");
133 CHECK_STATUS(status, NT_STATUS_OK);
135 status = smb_raw_rmdir(cli->tree, &rd);
136 CHECK_STATUS(status, NT_STATUS_OK);
139 smb_raw_exit(cli->session);
140 smbcli_deltree(cli->tree, BASEDIR);
146 basic testing of all RAW_MKDIR_* calls
148 BOOL torture_raw_mkdir(struct torture_context *torture)
150 struct smbcli_state *cli;
154 if (!torture_open_connection(&cli)) {
158 mem_ctx = talloc_init("torture_raw_mkdir");
160 if (!test_mkdir(cli, mem_ctx)) {
164 torture_close_connection(cli);
165 talloc_free(mem_ctx);