s3:torture:delete: fix a comment
[Samba/gebeck_regimport.git] / source4 / torture / raw / mkdir.c
blob477501644a898053137efb3f436f0e82fca1d82b
1 /*
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/>.
20 #include "includes.h"
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)); \
32 ret = false; \
33 goto done; \
34 }} while (0)
37 test mkdir ops
39 static bool test_mkdir(struct smbcli_state *cli, struct torture_context *tctx)
41 union smb_mkdir md;
42 struct smb_rmdir rd;
43 const char *path = BASEDIR "\\mkdir.dir";
44 NTSTATUS status;
45 bool ret = true;
47 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
49 /*
50 basic mkdir
52 md.mkdir.level = RAW_MKDIR_MKDIR;
53 md.mkdir.in.path = path;
55 status = smb_raw_mkdir(cli->tree, &md);
56 CHECK_STATUS(status, NT_STATUS_OK);
58 printf("Testing mkdir collision\n");
60 /* 2nd create */
61 status = smb_raw_mkdir(cli->tree, &md);
62 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
64 /* basic rmdir */
65 rd.in.path = path;
66 status = smb_raw_rmdir(cli->tree, &rd);
67 CHECK_STATUS(status, NT_STATUS_OK);
69 status = smb_raw_rmdir(cli->tree, &rd);
70 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
72 printf("Testing mkdir collision with file\n");
74 /* name collision with a file */
75 smbcli_close(cli->tree, create_complex_file(cli, tctx, path));
76 status = smb_raw_mkdir(cli->tree, &md);
77 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
79 printf("Testing rmdir with file\n");
81 /* delete a file with rmdir */
82 status = smb_raw_rmdir(cli->tree, &rd);
83 CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
85 smbcli_unlink(cli->tree, path);
87 printf("Testing invalid dir\n");
89 /* create an invalid dir */
90 md.mkdir.in.path = "..\\..\\..";
91 status = smb_raw_mkdir(cli->tree, &md);
92 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
94 printf("Testing t2mkdir\n");
96 /* try a t2mkdir - need to work out why this fails! */
97 md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
98 md.t2mkdir.in.path = path;
99 md.t2mkdir.in.num_eas = 0;
100 status = smb_raw_mkdir(cli->tree, &md);
101 CHECK_STATUS(status, NT_STATUS_OK);
103 status = smb_raw_rmdir(cli->tree, &rd);
104 CHECK_STATUS(status, NT_STATUS_OK);
106 printf("Testing t2mkdir bad path\n");
107 md.t2mkdir.in.path = talloc_asprintf(tctx, "%s\\bad_path\\bad_path",
108 BASEDIR);
109 status = smb_raw_mkdir(cli->tree, &md);
110 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND);
112 printf("Testing t2mkdir with EAs\n");
114 /* with EAs */
115 md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
116 md.t2mkdir.in.path = path;
117 md.t2mkdir.in.num_eas = 3;
118 md.t2mkdir.in.eas = talloc_array(tctx, struct ea_struct, md.t2mkdir.in.num_eas);
119 md.t2mkdir.in.eas[0].flags = 0;
120 md.t2mkdir.in.eas[0].name.s = "EAONE";
121 md.t2mkdir.in.eas[0].value = data_blob_talloc(tctx, "blah", 4);
122 md.t2mkdir.in.eas[1].flags = 0;
123 md.t2mkdir.in.eas[1].name.s = "EA TWO";
124 md.t2mkdir.in.eas[1].value = data_blob_talloc(tctx, "foo bar", 7);
125 md.t2mkdir.in.eas[2].flags = 0;
126 md.t2mkdir.in.eas[2].name.s = "EATHREE";
127 md.t2mkdir.in.eas[2].value = data_blob_talloc(tctx, "xx1", 3);
128 status = smb_raw_mkdir(cli->tree, &md);
130 if (torture_setting_bool(tctx, "samba3", false)
131 && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)) {
132 d_printf("EAS not supported -- not treating as fatal\n");
134 else {
136 * In Samba3, don't see this error as fatal
138 CHECK_STATUS(status, NT_STATUS_OK);
140 status = torture_check_ea(cli, path, "EAONE", "blah");
141 CHECK_STATUS(status, NT_STATUS_OK);
142 status = torture_check_ea(cli, path, "EA TWO", "foo bar");
143 CHECK_STATUS(status, NT_STATUS_OK);
144 status = torture_check_ea(cli, path, "EATHREE", "xx1");
145 CHECK_STATUS(status, NT_STATUS_OK);
147 status = smb_raw_rmdir(cli->tree, &rd);
148 CHECK_STATUS(status, NT_STATUS_OK);
151 done:
152 smb_raw_exit(cli->session);
153 smbcli_deltree(cli->tree, BASEDIR);
154 return ret;
159 basic testing of all RAW_MKDIR_* calls
161 bool torture_raw_mkdir(struct torture_context *torture,
162 struct smbcli_state *cli)
164 bool ret = true;
166 if (!test_mkdir(cli, torture)) {
167 ret = false;
170 return ret;