2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2008
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "torture/torture.h"
26 #include "torture/smb2/proto.h"
27 #include "param/param.h"
28 #include "librpc/gen_ndr/ndr_security.h"
30 #define FNAME "test_create.dat"
32 #define CHECK_STATUS(status, correct) do { \
33 if (!NT_STATUS_EQUAL(status, correct)) { \
34 printf("(%s) Incorrect status %s - should be %s\n", \
35 __location__, nt_errstr(status), nt_errstr(correct)); \
39 #define CHECK_EQUAL(v, correct) do { \
41 printf("(%s) Incorrect value for %s 0x%08x - should be 0x%08x\n", \
42 __location__, #v, v, correct); \
47 test some interesting combinations found by gentest
49 bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tree *tree)
51 struct smb2_create io;
53 TALLOC_CTX *tmp_ctx = talloc_new(tree);
54 uint32_t access_mask, file_attributes, denied_mask;
57 io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
58 io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
59 io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
61 NTCREATEX_SHARE_ACCESS_DELETE|
62 NTCREATEX_SHARE_ACCESS_READ|
63 NTCREATEX_SHARE_ACCESS_WRITE;
64 io.in.create_options = 0;
67 status = smb2_create(tree, tmp_ctx, &io);
68 CHECK_STATUS(status, NT_STATUS_OK);
70 status = smb2_util_close(tree, io.out.file.handle);
71 CHECK_STATUS(status, NT_STATUS_OK);
73 io.in.create_options = 0xF0000000;
74 status = smb2_create(tree, tmp_ctx, &io);
75 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
77 io.in.create_options = 0x00100000;
78 status = smb2_create(tree, tmp_ctx, &io);
79 CHECK_STATUS(status, NT_STATUS_NOT_SUPPORTED);
81 io.in.create_options = 0xF0100000;
82 status = smb2_create(tree, tmp_ctx, &io);
83 CHECK_STATUS(status, NT_STATUS_NOT_SUPPORTED);
85 io.in.create_options = 0;
87 io.in.file_attributes = FILE_ATTRIBUTE_DEVICE;
88 status = smb2_create(tree, tmp_ctx, &io);
89 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
91 io.in.file_attributes = FILE_ATTRIBUTE_VOLUME;
92 status = smb2_create(tree, tmp_ctx, &io);
93 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
95 io.in.create_disposition = NTCREATEX_DISP_OPEN;
96 io.in.file_attributes = FILE_ATTRIBUTE_VOLUME;
97 status = smb2_create(tree, tmp_ctx, &io);
98 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
100 io.in.create_disposition = NTCREATEX_DISP_CREATE;
101 io.in.desired_access = 0x08000000;
102 status = smb2_create(tree, tmp_ctx, &io);
103 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
105 io.in.desired_access = 0x04000000;
106 status = smb2_create(tree, tmp_ctx, &io);
107 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
109 io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
110 io.in.file_attributes = 0;
115 io.in.desired_access = 1<<i;
116 status = smb2_create(tree, tmp_ctx, &io);
117 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
118 access_mask |= io.in.desired_access;
120 CHECK_STATUS(status, NT_STATUS_OK);
121 status = smb2_util_close(tree, io.out.file.handle);
122 CHECK_STATUS(status, NT_STATUS_OK);
127 CHECK_EQUAL(access_mask, 0x0df0fe00);
129 io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
130 io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
131 io.in.file_attributes = 0;
137 io.in.file_attributes = 1<<i;
138 smb2_deltree(tree, FNAME);
139 status = smb2_create(tree, tmp_ctx, &io);
140 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
141 file_attributes |= io.in.file_attributes;
142 } else if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
143 denied_mask |= io.in.file_attributes;
145 CHECK_STATUS(status, NT_STATUS_OK);
146 status = smb2_util_close(tree, io.out.file.handle);
147 CHECK_STATUS(status, NT_STATUS_OK);
152 CHECK_EQUAL(file_attributes, 0xffff87c8);
153 CHECK_EQUAL(denied_mask, 0x4000);
155 smb2_deltree(tree, FNAME);
158 io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
159 io.in.file_attributes = 0;
160 io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
162 NTCREATEX_SHARE_ACCESS_READ|
163 NTCREATEX_SHARE_ACCESS_WRITE;
164 io.in.create_options = 0;
165 io.in.fname = FNAME ":stream1";
166 status = smb2_create(tree, tmp_ctx, &io);
167 CHECK_STATUS(status, NT_STATUS_OK);
170 io.in.file_attributes = 0x8040;
172 NTCREATEX_SHARE_ACCESS_READ;
173 status = smb2_create(tree, tmp_ctx, &io);
174 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
176 talloc_free(tmp_ctx);
182 basic testing of SMB2 create calls
184 bool torture_smb2_create(struct torture_context *torture)
186 TALLOC_CTX *mem_ctx = talloc_new(NULL);
187 struct smb2_tree *tree;
190 if (!torture_smb2_connection(torture, &tree)) {
194 ret &= torture_smb2_create_gentest(torture, tree);
196 smb2_deltree(tree, FNAME);
198 talloc_free(mem_ctx);