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 3 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, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 | #include "libcli/raw/libcliraw.h"
|
---|
22 | #include "libcli/libcli.h"
|
---|
23 | #include "torture/util.h"
|
---|
24 |
|
---|
25 | #define BASEDIR "\\mkdirtest"
|
---|
26 |
|
---|
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)
|
---|
34 |
|
---|
35 | /*
|
---|
36 | test mkdir ops
|
---|
37 | */
|
---|
38 | static bool test_mkdir(struct smbcli_state *cli, struct torture_context *tctx)
|
---|
39 | {
|
---|
40 | union smb_mkdir md;
|
---|
41 | struct smb_rmdir rd;
|
---|
42 | const char *path = BASEDIR "\\mkdir.dir";
|
---|
43 | NTSTATUS status;
|
---|
44 | bool ret = true;
|
---|
45 |
|
---|
46 | if (!torture_setup_dir(cli, BASEDIR)) {
|
---|
47 | return false;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /*
|
---|
51 | basic mkdir
|
---|
52 | */
|
---|
53 | md.mkdir.level = RAW_MKDIR_MKDIR;
|
---|
54 | md.mkdir.in.path = path;
|
---|
55 |
|
---|
56 | status = smb_raw_mkdir(cli->tree, &md);
|
---|
57 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
58 |
|
---|
59 | printf("Testing mkdir collision\n");
|
---|
60 |
|
---|
61 | /* 2nd create */
|
---|
62 | status = smb_raw_mkdir(cli->tree, &md);
|
---|
63 | CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
|
---|
64 |
|
---|
65 | /* basic rmdir */
|
---|
66 | rd.in.path = path;
|
---|
67 | status = smb_raw_rmdir(cli->tree, &rd);
|
---|
68 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
69 |
|
---|
70 | status = smb_raw_rmdir(cli->tree, &rd);
|
---|
71 | CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
|
---|
72 |
|
---|
73 | printf("Testing mkdir collision with file\n");
|
---|
74 |
|
---|
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);
|
---|
79 |
|
---|
80 | printf("Testing rmdir with file\n");
|
---|
81 |
|
---|
82 | /* delete a file with rmdir */
|
---|
83 | status = smb_raw_rmdir(cli->tree, &rd);
|
---|
84 | CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
|
---|
85 |
|
---|
86 | smbcli_unlink(cli->tree, path);
|
---|
87 |
|
---|
88 | printf("Testing invalid dir\n");
|
---|
89 |
|
---|
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);
|
---|
94 |
|
---|
95 | printf("Testing t2mkdir\n");
|
---|
96 |
|
---|
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);
|
---|
103 |
|
---|
104 | status = smb_raw_rmdir(cli->tree, &rd);
|
---|
105 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
106 |
|
---|
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);
|
---|
112 |
|
---|
113 | printf("Testing t2mkdir with EAs\n");
|
---|
114 |
|
---|
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);
|
---|
130 |
|
---|
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");
|
---|
134 | }
|
---|
135 | else {
|
---|
136 | /*
|
---|
137 | * In Samba3, don't see this error as fatal
|
---|
138 | */
|
---|
139 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
140 |
|
---|
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);
|
---|
147 |
|
---|
148 | status = smb_raw_rmdir(cli->tree, &rd);
|
---|
149 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
150 | }
|
---|
151 |
|
---|
152 | done:
|
---|
153 | smb_raw_exit(cli->session);
|
---|
154 | smbcli_deltree(cli->tree, BASEDIR);
|
---|
155 | return ret;
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | /*
|
---|
160 | basic testing of all RAW_MKDIR_* calls
|
---|
161 | */
|
---|
162 | bool torture_raw_mkdir(struct torture_context *torture,
|
---|
163 | struct smbcli_state *cli)
|
---|
164 | {
|
---|
165 | bool ret = true;
|
---|
166 |
|
---|
167 | if (!test_mkdir(cli, torture)) {
|
---|
168 | ret = false;
|
---|
169 | }
|
---|
170 |
|
---|
171 | return ret;
|
---|
172 | }
|
---|