Convert mtime from a time_t to a struct timespec.
[Samba.git] / source4 / torture / raw / mkdir.c
blob9c744b2db8ec26bfaca27b0375e11635d105949d
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"
25 #define BASEDIR "\\mkdirtest"
27 #define CHECK_STATUS(status, correct) do { \
28 if (!NT_STATUS_EQUAL(status, correct)) { \
29 printf("(%s) Incorrect status %s - should be %s\n", \
30 __location__, nt_errstr(status), nt_errstr(correct)); \
31 ret = false; \
32 goto done; \
33 }} while (0)
36 test mkdir ops
38 static bool test_mkdir(struct smbcli_state *cli, struct torture_context *tctx)
40 union smb_mkdir md;
41 struct smb_rmdir rd;
42 const char *path = BASEDIR "\\mkdir.dir";
43 NTSTATUS status;
44 bool ret = true;
46 if (!torture_setup_dir(cli, BASEDIR)) {
47 return false;
50 /*
51 basic mkdir
53 md.mkdir.level = RAW_MKDIR_MKDIR;
54 md.mkdir.in.path = path;
56 status = smb_raw_mkdir(cli->tree, &md);
57 CHECK_STATUS(status, NT_STATUS_OK);
59 printf("Testing mkdir collision\n");
61 /* 2nd create */
62 status = smb_raw_mkdir(cli->tree, &md);
63 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
65 /* basic rmdir */
66 rd.in.path = path;
67 status = smb_raw_rmdir(cli->tree, &rd);
68 CHECK_STATUS(status, NT_STATUS_OK);
70 status = smb_raw_rmdir(cli->tree, &rd);
71 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
73 printf("Testing mkdir collision with file\n");
75 /* name collision with a file */
76 smbcli_close(cli->tree, create_complex_file(cli, tctx, path));
77 status = smb_raw_mkdir(cli->tree, &md);
78 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
80 printf("Testing rmdir with file\n");
82 /* delete a file with rmdir */
83 status = smb_raw_rmdir(cli->tree, &rd);
84 CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
86 smbcli_unlink(cli->tree, path);
88 printf("Testing invalid dir\n");
90 /* create an invalid dir */
91 md.mkdir.in.path = "..\\..\\..";
92 status = smb_raw_mkdir(cli->tree, &md);
93 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
95 printf("Testing t2mkdir\n");
97 /* try a t2mkdir - need to work out why this fails! */
98 md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
99 md.t2mkdir.in.path = path;
100 md.t2mkdir.in.num_eas = 0;
101 status = smb_raw_mkdir(cli->tree, &md);
102 CHECK_STATUS(status, NT_STATUS_OK);
104 status = smb_raw_rmdir(cli->tree, &rd);
105 CHECK_STATUS(status, NT_STATUS_OK);
107 printf("Testing t2mkdir bad path\n");
108 md.t2mkdir.in.path = talloc_asprintf(tctx, "%s\\bad_path\\bad_path",
109 BASEDIR);
110 status = smb_raw_mkdir(cli->tree, &md);
111 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND);
113 printf("Testing t2mkdir with EAs\n");
115 /* with EAs */
116 md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
117 md.t2mkdir.in.path = path;
118 md.t2mkdir.in.num_eas = 3;
119 md.t2mkdir.in.eas = talloc_array(tctx, struct ea_struct, md.t2mkdir.in.num_eas);
120 md.t2mkdir.in.eas[0].flags = 0;
121 md.t2mkdir.in.eas[0].name.s = "EAONE";
122 md.t2mkdir.in.eas[0].value = data_blob_talloc(tctx, "blah", 4);
123 md.t2mkdir.in.eas[1].flags = 0;
124 md.t2mkdir.in.eas[1].name.s = "EA TWO";
125 md.t2mkdir.in.eas[1].value = data_blob_talloc(tctx, "foo bar", 7);
126 md.t2mkdir.in.eas[2].flags = 0;
127 md.t2mkdir.in.eas[2].name.s = "EATHREE";
128 md.t2mkdir.in.eas[2].value = data_blob_talloc(tctx, "xx1", 3);
129 status = smb_raw_mkdir(cli->tree, &md);
131 if (torture_setting_bool(tctx, "samba3", false)
132 && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)) {
133 d_printf("EAS not supported -- not treating as fatal\n");
135 else {
137 * In Samba3, don't see this error as fatal
139 CHECK_STATUS(status, NT_STATUS_OK);
141 status = torture_check_ea(cli, path, "EAONE", "blah");
142 CHECK_STATUS(status, NT_STATUS_OK);
143 status = torture_check_ea(cli, path, "EA TWO", "foo bar");
144 CHECK_STATUS(status, NT_STATUS_OK);
145 status = torture_check_ea(cli, path, "EATHREE", "xx1");
146 CHECK_STATUS(status, NT_STATUS_OK);
148 status = smb_raw_rmdir(cli->tree, &rd);
149 CHECK_STATUS(status, NT_STATUS_OK);
152 done:
153 smb_raw_exit(cli->session);
154 smbcli_deltree(cli->tree, BASEDIR);
155 return ret;
160 basic testing of all RAW_MKDIR_* calls
162 bool torture_raw_mkdir(struct torture_context *torture,
163 struct smbcli_state *cli)
165 bool ret = true;
167 if (!test_mkdir(cli, torture)) {
168 ret = false;
171 return ret;