1 /*
2 Unix SMB/CIFS implementation.
3 RAW_MKDIR_* and RAW_RMDIR_* individual test suite
4 Copyright (C) Andrew Tridgell 2003
5
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.
10
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.
15
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.
19 */
20
21 #include "includes.h"
22 #include "torture/torture.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/libcli.h"
25 #include "torture/util.h"
26
27 #define BASEDIR "\\mkdirtest"
28
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)); \
33 ret = False; \
34 goto done; \
35 }} while (0)
36
37 /*
38 test mkdir ops
39 */
test_mkdir(struct smbcli_state * cli,TALLOC_CTX * mem_ctx)40 static BOOL test_mkdir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
41 {
42 union smb_mkdir md;
43 struct smb_rmdir rd;
44 const char *path = BASEDIR "\\mkdir.dir";
45 NTSTATUS status;
46 BOOL ret = True;
47
48 if (!torture_setup_dir(cli, BASEDIR)) {
49 return False;
50 }
51
52 /*
53 basic mkdir
54 */
55 md.mkdir.level = RAW_MKDIR_MKDIR;
56 md.mkdir.in.path = path;
57
58 status = smb_raw_mkdir(cli->tree, &md);
59 CHECK_STATUS(status, NT_STATUS_OK);
60
61 printf("testing mkdir collision\n");
62
63 /* 2nd create */
64 status = smb_raw_mkdir(cli->tree, &md);
65 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
66
67 /* basic rmdir */
68 rd.in.path = path;
69 status = smb_raw_rmdir(cli->tree, &rd);
70 CHECK_STATUS(status, NT_STATUS_OK);
71
72 status = smb_raw_rmdir(cli->tree, &rd);
73 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
74
75 printf("testing mkdir collision with file\n");
76
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);
81
82 printf("testing rmdir with file\n");
83
84 /* delete a file with rmdir */
85 status = smb_raw_rmdir(cli->tree, &rd);
86 CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
87
88 smbcli_unlink(cli->tree, path);
89
90 printf("testing invalid dir\n");
91
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);
96
97 printf("testing t2mkdir\n");
98
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);
105
106 status = smb_raw_rmdir(cli->tree, &rd);
107 CHECK_STATUS(status, NT_STATUS_OK);
108
109 printf("testing t2mkdir with EAs\n");
110
111 /* with EAs */
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);
127
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);
134
135 status = smb_raw_rmdir(cli->tree, &rd);
136 CHECK_STATUS(status, NT_STATUS_OK);
137
138 done:
139 smb_raw_exit(cli->session);
140 smbcli_deltree(cli->tree, BASEDIR);
141 return ret;
142 }
143
144
145 /*
146 basic testing of all RAW_MKDIR_* calls
147 */
torture_raw_mkdir(struct torture_context * torture)148 BOOL torture_raw_mkdir(struct torture_context *torture)
149 {
150 struct smbcli_state *cli;
151 BOOL ret = True;
152 TALLOC_CTX *mem_ctx;
153
154 if (!torture_open_connection(&cli, 0)) {
155 return False;
156 }
157
158 mem_ctx = talloc_init("torture_raw_mkdir");
159
160 if (!test_mkdir(cli, mem_ctx)) {
161 ret = False;
162 }
163
164 torture_close_connection(cli);
165 talloc_free(mem_ctx);
166 return ret;
167 }
168