2 Unix SMB/CIFS implementation.
4 test suite for SMB2 persistent file handles
6 Copyright (C) Stefan Metzmacher 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 "librpc/gen_ndr/security.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
28 #include "param/param.h"
30 #define CHECK_VAL(v, correct) do { \
31 if ((v) != (correct)) { \
32 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \
33 __location__, #v, (int)v, (int)correct); \
37 #define CHECK_STATUS(status, correct) do { \
38 if (!NT_STATUS_EQUAL(status, correct)) { \
39 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
40 nt_errstr(status), nt_errstr(correct)); \
46 basic testing of SMB2 persistent file handles
47 regarding the position information on the handle
49 bool torture_smb2_persistent_handles1(struct torture_context *tctx,
50 struct smb2_tree *tree1,
51 struct smb2_tree *tree2)
53 TALLOC_CTX *mem_ctx = talloc_new(tctx);
54 struct smb2_handle h1, h2;
55 struct smb2_create io1, io2;
57 const char *fname = "persistent_handles.dat";
59 union smb_fileinfo qfinfo;
60 union smb_setfileinfo sfinfo;
64 smb2_util_unlink(tree1, fname);
67 io1.in.security_flags = 0x00;
68 io1.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH;
69 io1.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
70 io1.in.create_flags = 0x00000000;
71 io1.in.reserved = 0x00000000;
72 io1.in.desired_access = SEC_RIGHTS_FILE_ALL;
73 io1.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
74 io1.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
75 NTCREATEX_SHARE_ACCESS_WRITE |
76 NTCREATEX_SHARE_ACCESS_DELETE;
77 io1.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
78 io1.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
79 NTCREATEX_OPTIONS_ASYNC_ALERT |
80 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
84 b = data_blob_talloc(mem_ctx, NULL, 16);
88 status = smb2_create_blob_add(tree1, &io1.in.blobs,
91 CHECK_STATUS(status, NT_STATUS_OK);
93 status = smb2_create(tree1, mem_ctx, &io1);
94 CHECK_STATUS(status, NT_STATUS_OK);
95 CHECK_VAL(io1.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
96 /*CHECK_VAL(io1.out.reserved, 0);*/
97 CHECK_VAL(io1.out.create_action, NTCREATEX_ACTION_CREATED);
98 CHECK_VAL(io1.out.alloc_size, 0);
99 CHECK_VAL(io1.out.size, 0);
100 CHECK_VAL(io1.out.file_attr, FILE_ATTRIBUTE_ARCHIVE);
101 CHECK_VAL(io1.out.reserved2, 0);
103 /* TODO: check extra blob content */
105 h1 = io1.out.file.handle;
108 qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
109 qfinfo.generic.in.file.handle = h1;
110 status = smb2_getinfo_file(tree1, mem_ctx, &qfinfo);
111 CHECK_STATUS(status, NT_STATUS_OK);
112 CHECK_VAL(qfinfo.position_information.out.position, 0);
113 pos = qfinfo.position_information.out.position;
114 torture_comment(tctx, "position: %llu\n",
115 (unsigned long long)pos);
118 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
119 sfinfo.generic.in.file.handle = h1;
120 sfinfo.position_information.in.position = 0x1000;
121 status = smb2_setinfo_file(tree1, &sfinfo);
122 CHECK_STATUS(status, NT_STATUS_OK);
125 qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
126 qfinfo.generic.in.file.handle = h1;
127 status = smb2_getinfo_file(tree1, mem_ctx, &qfinfo);
128 CHECK_STATUS(status, NT_STATUS_OK);
129 CHECK_VAL(qfinfo.position_information.out.position, 0x1000);
130 pos = qfinfo.position_information.out.position;
131 torture_comment(tctx, "position: %llu\n",
132 (unsigned long long)pos);
138 qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
139 qfinfo.generic.in.file.handle = h1;
140 status = smb2_getinfo_file(tree2, mem_ctx, &qfinfo);
141 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
144 io2.in.fname = fname;
146 b = data_blob_talloc(tctx, NULL, 16);
147 SBVAL(b.data, 0, h1.data[0]);
148 SBVAL(b.data, 8, h1.data[1]);
150 status = smb2_create_blob_add(tree2, &io2.in.blobs,
151 SMB2_CREATE_TAG_DHNC,
153 CHECK_STATUS(status, NT_STATUS_OK);
155 status = smb2_create(tree2, mem_ctx, &io2);
156 CHECK_STATUS(status, NT_STATUS_OK);
157 CHECK_VAL(io2.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
158 CHECK_VAL(io2.out.reserved, 0x00);
159 CHECK_VAL(io2.out.create_action, NTCREATEX_ACTION_EXISTED);
160 CHECK_VAL(io2.out.alloc_size, 0);
161 CHECK_VAL(io2.out.size, 0);
162 CHECK_VAL(io2.out.file_attr, FILE_ATTRIBUTE_ARCHIVE);
163 CHECK_VAL(io2.out.reserved2, 0);
165 h2 = io2.out.file.handle;
168 qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
169 qfinfo.generic.in.file.handle = h2;
170 status = smb2_getinfo_file(tree2, mem_ctx, &qfinfo);
171 CHECK_STATUS(status, NT_STATUS_OK);
172 CHECK_VAL(qfinfo.position_information.out.position, 0x1000);
173 pos = qfinfo.position_information.out.position;
174 torture_comment(tctx, "position: %llu\n",
175 (unsigned long long)pos);
177 smb2_util_close(tree2, h2);
179 talloc_free(mem_ctx);
181 smb2_util_unlink(tree2, fname);