2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
6 Copyright (C) Jeremy Allison 2010
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 "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "../libcli/smb/smb_common.h"
27 #include "../lib/util/tevent_ntstatus.h"
29 static struct tevent_req
*smbd_smb2_setinfo_send(TALLOC_CTX
*mem_ctx
,
30 struct tevent_context
*ev
,
31 struct smbd_smb2_request
*smb2req
,
33 uint8_t in_file_info_class
,
34 DATA_BLOB in_input_buffer
,
35 uint32_t in_additional_information
,
36 uint64_t in_file_id_volatile
);
37 static NTSTATUS
smbd_smb2_setinfo_recv(struct tevent_req
*req
);
39 static void smbd_smb2_request_setinfo_done(struct tevent_req
*subreq
);
40 NTSTATUS
smbd_smb2_request_process_setinfo(struct smbd_smb2_request
*req
)
43 const uint8_t *inbody
;
44 int i
= req
->current_idx
;
45 size_t expected_body_size
= 0x21;
48 uint8_t in_file_info_class
;
49 uint16_t in_input_buffer_offset
;
50 uint32_t in_input_buffer_length
;
51 DATA_BLOB in_input_buffer
;
52 uint32_t in_additional_information
;
53 uint64_t in_file_id_persistent
;
54 uint64_t in_file_id_volatile
;
55 struct tevent_req
*subreq
;
57 inhdr
= (const uint8_t *)req
->in
.vector
[i
+0].iov_base
;
58 if (req
->in
.vector
[i
+1].iov_len
!= (expected_body_size
& 0xFFFFFFFE)) {
59 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
62 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
64 body_size
= SVAL(inbody
, 0x00);
65 if (body_size
!= expected_body_size
) {
66 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
69 in_info_type
= CVAL(inbody
, 0x02);
70 in_file_info_class
= CVAL(inbody
, 0x03);
71 in_input_buffer_length
= IVAL(inbody
, 0x04);
72 in_input_buffer_offset
= SVAL(inbody
, 0x08);
73 /* 0x0A 2 bytes reserved */
74 in_additional_information
= IVAL(inbody
, 0x0C);
75 in_file_id_persistent
= BVAL(inbody
, 0x10);
76 in_file_id_volatile
= BVAL(inbody
, 0x18);
78 if (in_input_buffer_offset
== 0 && in_input_buffer_length
== 0) {
80 } else if (in_input_buffer_offset
!=
81 (SMB2_HDR_BODY
+ (body_size
& 0xFFFFFFFE))) {
82 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
85 if (in_input_buffer_length
> req
->in
.vector
[i
+2].iov_len
) {
86 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
89 in_input_buffer
.data
= (uint8_t *)req
->in
.vector
[i
+2].iov_base
;
90 in_input_buffer
.length
= in_input_buffer_length
;
92 if (req
->compat_chain_fsp
) {
94 } else if (in_file_id_persistent
!= in_file_id_volatile
) {
95 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
98 subreq
= smbd_smb2_setinfo_send(req
,
99 req
->sconn
->smb2
.event_ctx
,
104 in_additional_information
,
105 in_file_id_volatile
);
106 if (subreq
== NULL
) {
107 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
109 tevent_req_set_callback(subreq
, smbd_smb2_request_setinfo_done
, req
);
111 return smbd_smb2_request_pending_queue(req
, subreq
);
114 static void smbd_smb2_request_setinfo_done(struct tevent_req
*subreq
)
116 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
117 struct smbd_smb2_request
);
120 NTSTATUS error
; /* transport error */
122 status
= smbd_smb2_setinfo_recv(subreq
);
124 if (!NT_STATUS_IS_OK(status
)) {
125 error
= smbd_smb2_request_error(req
, status
);
126 if (!NT_STATUS_IS_OK(error
)) {
127 smbd_server_connection_terminate(req
->sconn
,
134 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x02);
135 if (outbody
.data
== NULL
) {
136 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
137 if (!NT_STATUS_IS_OK(error
)) {
138 smbd_server_connection_terminate(req
->sconn
,
145 SSVAL(outbody
.data
, 0x00, 0x02); /* struct size */
147 error
= smbd_smb2_request_done(req
, outbody
, NULL
);
148 if (!NT_STATUS_IS_OK(error
)) {
149 smbd_server_connection_terminate(req
->sconn
,
155 struct smbd_smb2_setinfo_state
{
156 struct smbd_smb2_request
*smb2req
;
159 static struct tevent_req
*smbd_smb2_setinfo_send(TALLOC_CTX
*mem_ctx
,
160 struct tevent_context
*ev
,
161 struct smbd_smb2_request
*smb2req
,
162 uint8_t in_info_type
,
163 uint8_t in_file_info_class
,
164 DATA_BLOB in_input_buffer
,
165 uint32_t in_additional_information
,
166 uint64_t in_file_id_volatile
)
168 struct tevent_req
*req
= NULL
;
169 struct smbd_smb2_setinfo_state
*state
= NULL
;
170 struct smb_request
*smbreq
= NULL
;
171 connection_struct
*conn
= smb2req
->tcon
->compat_conn
;
172 files_struct
*fsp
= NULL
;
175 req
= tevent_req_create(mem_ctx
, &state
,
176 struct smbd_smb2_setinfo_state
);
180 state
->smb2req
= smb2req
;
182 DEBUG(10,("smbd_smb2_setinfo_send: file_id[0x%016llX]\n",
183 (unsigned long long)in_file_id_volatile
));
185 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
186 if (tevent_req_nomem(smbreq
, req
)) {
187 return tevent_req_post(req
, ev
);
190 fsp
= file_fsp(smbreq
, (uint16_t)in_file_id_volatile
);
192 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
193 return tevent_req_post(req
, ev
);
195 if (conn
!= fsp
->conn
) {
196 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
197 return tevent_req_post(req
, ev
);
199 if (smb2req
->session
->vuid
!= fsp
->vuid
) {
200 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
201 return tevent_req_post(req
, ev
);
205 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
206 return tevent_req_post(req
, ev
);
209 switch (in_info_type
) {
210 case 0x01:/* SMB2_SETINFO_FILE */
212 uint16_t file_info_level
;
218 file_info_level
= in_file_info_class
+ 1000;
219 if (file_info_level
== SMB_FILE_RENAME_INFORMATION
) {
220 /* SMB2_FILE_RENAME_INFORMATION_INTERNAL == 0xFF00 + in_file_info_class */
221 file_info_level
= SMB2_FILE_RENAME_INFORMATION_INTERNAL
;
222 if (fsp
->oplock_type
!= FAKE_LEVEL_II_OPLOCK
&&
223 fsp
->oplock_type
!= NO_OPLOCK
) {
224 /* No break, but error. */
225 tevent_req_nterror(req
, NT_STATUS_SHARING_VIOLATION
);
226 return tevent_req_post(req
, ev
);
230 if (fsp
->fh
->fd
== -1) {
232 * This is actually a SETFILEINFO on a directory
233 * handle (returned from an NT SMB). NT5.0 seems
234 * to do this call. JRA.
236 if (INFO_LEVEL_IS_UNIX(file_info_level
)) {
237 /* Always do lstat for UNIX calls. */
238 if (SMB_VFS_LSTAT(conn
, fsp
->fsp_name
)) {
239 DEBUG(3,("smbd_smb2_setinfo_send: "
240 "SMB_VFS_LSTAT of %s failed "
241 "(%s)\n", fsp_str_dbg(fsp
),
243 status
= map_nt_error_from_unix(errno
);
244 tevent_req_nterror(req
, status
);
245 return tevent_req_post(req
, ev
);
248 if (SMB_VFS_STAT(conn
, fsp
->fsp_name
) != 0) {
249 DEBUG(3,("smbd_smb2_setinfo_send: "
250 "fileinfo of %s failed (%s)\n",
253 status
= map_nt_error_from_unix(errno
);
254 tevent_req_nterror(req
, status
);
255 return tevent_req_post(req
, ev
);
258 } else if (fsp
->print_file
) {
260 * Doing a DELETE_ON_CLOSE should cancel a print job.
262 if ((file_info_level
== SMB_SET_FILE_DISPOSITION_INFO
)
263 && in_input_buffer
.length
>= 1
264 && CVAL(in_input_buffer
.data
,0)) {
265 fsp
->fh
->private_options
|= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE
;
267 DEBUG(3,("smbd_smb2_setinfo_send: "
268 "Cancelling print job (%s)\n",
271 tevent_req_done(req
);
272 return tevent_req_post(req
, ev
);
274 tevent_req_nterror(req
,
275 NT_STATUS_OBJECT_PATH_INVALID
);
276 return tevent_req_post(req
, ev
);
280 * Original code - this is an open file.
283 if (SMB_VFS_FSTAT(fsp
, &fsp
->fsp_name
->st
) != 0) {
284 DEBUG(3,("smbd_smb2_setinfo_send: fstat "
285 "of fnum %d failed (%s)\n", fsp
->fnum
,
287 status
= map_nt_error_from_unix(errno
);
288 tevent_req_nterror(req
, status
);
289 return tevent_req_post(req
, ev
);
294 data_size
= in_input_buffer
.length
;
296 data
= (char *)SMB_MALLOC_ARRAY(char, data_size
);
297 if (tevent_req_nomem(data
, req
)) {
298 return tevent_req_post(req
, ev
);
300 memcpy(data
, in_input_buffer
.data
, data_size
);
303 status
= smbd_do_setfilepathinfo(conn
, smbreq
, state
,
311 if (!NT_STATUS_IS_OK(status
)) {
312 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_LEVEL
)) {
313 status
= NT_STATUS_INVALID_INFO_CLASS
;
315 tevent_req_nterror(req
, status
);
316 return tevent_req_post(req
, ev
);
321 case 0x03:/* SMB2_SETINFO_SECURITY */
323 if (!CAN_WRITE(conn
)) {
324 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
325 return tevent_req_post(req
, ev
);
329 in_input_buffer
.data
,
330 in_input_buffer
.length
,
331 in_additional_information
);
332 if (!NT_STATUS_IS_OK(status
)) {
333 tevent_req_nterror(req
, status
);
334 return tevent_req_post(req
, ev
);
340 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
341 return tevent_req_post(req
, ev
);
344 tevent_req_done(req
);
345 return tevent_req_post(req
, ev
);
348 static NTSTATUS
smbd_smb2_setinfo_recv(struct tevent_req
*req
)
352 if (tevent_req_is_nterror(req
, &status
)) {
353 tevent_req_received(req
);
357 tevent_req_received(req
);