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.
23 #define CHECK_STATUS(status, correct) do { \
24 if (!NT_STATUS_EQUAL(status, correct)) { \
25 printf("(%d) Incorrect status %s - should be %s\n", \
26 __LINE__, nt_errstr(status), nt_errstr(correct)); \
34 static BOOL test_mkdir(struct cli_state *cli, TALLOC_CTX *mem_ctx)
38 const char *path = "\\test_mkdir.dir";
44 cli_unlink(cli, path);
49 md.mkdir.level = RAW_MKDIR_MKDIR;
50 md.mkdir.in.path = path;
52 status = smb_raw_mkdir(cli->tree, &md);
53 CHECK_STATUS(status, NT_STATUS_OK);
55 printf("testing mkdir collision\n");
58 status = smb_raw_mkdir(cli->tree, &md);
59 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
63 status = smb_raw_rmdir(cli->tree, &rd);
64 CHECK_STATUS(status, NT_STATUS_OK);
66 status = smb_raw_rmdir(cli->tree, &rd);
67 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
69 printf("testing mkdir collision with file\n");
71 /* name collision with a file */
72 cli_close(cli, create_complex_file(cli, mem_ctx, path));
73 status = smb_raw_mkdir(cli->tree, &md);
74 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
76 printf("testing rmdir with file\n");
78 /* delete a file with rmdir */
79 status = smb_raw_rmdir(cli->tree, &rd);
80 CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
82 cli_unlink(cli, path);
84 printf("testing invalid dir\n");
86 /* create an invalid dir */
87 md.mkdir.in.path = "..\\..\\..";
88 status = smb_raw_mkdir(cli->tree, &md);
89 CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
91 printf("testing t2mkdir\n");
93 /* try a t2mkdir - need to work out why this fails! */
94 md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
95 md.t2mkdir.in.path = path;
96 md.t2mkdir.in.num_eas = 0;
97 status = smb_raw_mkdir(cli->tree, &md);
98 CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL);
100 printf("testing t2mkdir with EAs\n");
103 md.t2mkdir.in.num_eas = 1;
104 md.t2mkdir.in.eas = talloc(mem_ctx, sizeof(md.t2mkdir.in.eas[0]));
105 md.t2mkdir.in.eas[0].flags = 0;
106 md.t2mkdir.in.eas[0].name.s = "EAONE";
107 md.t2mkdir.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1);
108 status = smb_raw_mkdir(cli->tree, &md);
109 CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL);
113 cli_rmdir(cli, path);
114 cli_unlink(cli, path);
120 basic testing of all RAW_MKDIR_* calls
122 BOOL torture_raw_mkdir(int dummy)
124 struct cli_state *cli;
128 if (!torture_open_connection(&cli)) {
132 mem_ctx = talloc_init("torture_raw_mkdir");
134 if (!test_mkdir(cli, mem_ctx)) {
138 torture_close_connection(cli);
139 talloc_destroy(mem_ctx);