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"
29 #define CHECK_VAL(v, correct) do { \
30 if ((v) != (correct)) { \
31 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \
32 __location__, #v, (int)v, (int)correct); \
36 #define CHECK_STATUS(status, correct) do { \
37 if (!NT_STATUS_EQUAL(status, correct)) { \
38 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
39 nt_errstr(status), nt_errstr(correct)); \
45 basic testing of SMB2 persistent file handles
46 regarding the position information on the handle
48 bool torture_smb2_persistent_handles1(struct torture_context
*tctx
,
49 struct smb2_tree
*tree1
,
50 struct smb2_tree
*tree2
)
52 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
53 struct smb2_handle h1
, h2
;
54 struct smb2_create io1
, io2
;
56 const char *fname
= "persistent_handles.dat";
58 union smb_fileinfo qfinfo
;
59 union smb_setfileinfo sfinfo
;
63 smb2_util_unlink(tree1
, fname
);
66 io1
.in
.security_flags
= 0x00;
67 io1
.in
.oplock_level
= SMB2_OPLOCK_LEVEL_BATCH
;
68 io1
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
69 io1
.in
.create_flags
= 0x00000000;
70 io1
.in
.reserved
= 0x00000000;
71 io1
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
72 io1
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
73 io1
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
74 NTCREATEX_SHARE_ACCESS_WRITE
|
75 NTCREATEX_SHARE_ACCESS_DELETE
;
76 io1
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
77 io1
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
78 NTCREATEX_OPTIONS_ASYNC_ALERT
|
79 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
83 b
= data_blob_talloc(mem_ctx
, NULL
, 16);
87 status
= smb2_create_blob_add(tree1
, &io1
.in
.blobs
,
90 CHECK_STATUS(status
, NT_STATUS_OK
);
92 status
= smb2_create(tree1
, mem_ctx
, &io1
);
93 CHECK_STATUS(status
, NT_STATUS_OK
);
94 CHECK_VAL(io1
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_BATCH
);
95 /*CHECK_VAL(io1.out.reserved, 0);*/
96 CHECK_VAL(io1
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
97 CHECK_VAL(io1
.out
.alloc_size
, 0);
98 CHECK_VAL(io1
.out
.size
, 0);
99 CHECK_VAL(io1
.out
.file_attr
, FILE_ATTRIBUTE_ARCHIVE
);
100 CHECK_VAL(io1
.out
.reserved2
, 0);
102 /* TODO: check extra blob content */
104 h1
= io1
.out
.file
.handle
;
107 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
108 qfinfo
.generic
.in
.file
.handle
= h1
;
109 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
110 CHECK_STATUS(status
, NT_STATUS_OK
);
111 CHECK_VAL(qfinfo
.position_information
.out
.position
, 0);
112 pos
= qfinfo
.position_information
.out
.position
;
113 torture_comment(tctx
, "position: %llu\n",
114 (unsigned long long)pos
);
117 sfinfo
.generic
.level
= RAW_SFILEINFO_POSITION_INFORMATION
;
118 sfinfo
.generic
.in
.file
.handle
= h1
;
119 sfinfo
.position_information
.in
.position
= 0x1000;
120 status
= smb2_setinfo_file(tree1
, &sfinfo
);
121 CHECK_STATUS(status
, NT_STATUS_OK
);
124 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
125 qfinfo
.generic
.in
.file
.handle
= h1
;
126 status
= smb2_getinfo_file(tree1
, mem_ctx
, &qfinfo
);
127 CHECK_STATUS(status
, NT_STATUS_OK
);
128 CHECK_VAL(qfinfo
.position_information
.out
.position
, 0x1000);
129 pos
= qfinfo
.position_information
.out
.position
;
130 torture_comment(tctx
, "position: %llu\n",
131 (unsigned long long)pos
);
137 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
138 qfinfo
.generic
.in
.file
.handle
= h1
;
139 status
= smb2_getinfo_file(tree2
, mem_ctx
, &qfinfo
);
140 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
143 io2
.in
.fname
= fname
;
145 b
= data_blob_talloc(tctx
, NULL
, 16);
146 SBVAL(b
.data
, 0, h1
.data
[0]);
147 SBVAL(b
.data
, 8, h1
.data
[1]);
149 status
= smb2_create_blob_add(tree2
, &io2
.in
.blobs
,
150 SMB2_CREATE_TAG_DHNC
,
152 CHECK_STATUS(status
, NT_STATUS_OK
);
154 status
= smb2_create(tree2
, mem_ctx
, &io2
);
155 CHECK_STATUS(status
, NT_STATUS_OK
);
156 CHECK_VAL(io2
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_BATCH
);
157 CHECK_VAL(io2
.out
.reserved
, 0x00);
158 CHECK_VAL(io2
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
159 CHECK_VAL(io2
.out
.alloc_size
, 0);
160 CHECK_VAL(io2
.out
.size
, 0);
161 CHECK_VAL(io2
.out
.file_attr
, FILE_ATTRIBUTE_ARCHIVE
);
162 CHECK_VAL(io2
.out
.reserved2
, 0);
164 h2
= io2
.out
.file
.handle
;
167 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
168 qfinfo
.generic
.in
.file
.handle
= h2
;
169 status
= smb2_getinfo_file(tree2
, mem_ctx
, &qfinfo
);
170 CHECK_STATUS(status
, NT_STATUS_OK
);
171 CHECK_VAL(qfinfo
.position_information
.out
.position
, 0x1000);
172 pos
= qfinfo
.position_information
.out
.position
;
173 torture_comment(tctx
, "position: %llu\n",
174 (unsigned long long)pos
);
176 smb2_util_close(tree2
, h2
);
178 talloc_free(mem_ctx
);
180 smb2_util_unlink(tree2
, fname
);