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/globals.h"
24 #include "../libcli/smb/smb_common.h"
26 static struct tevent_req
*smbd_smb2_setinfo_send(TALLOC_CTX
*mem_ctx
,
27 struct tevent_context
*ev
,
28 struct smbd_smb2_request
*smb2req
,
30 uint8_t in_file_info_class
,
31 DATA_BLOB in_input_buffer
,
32 uint32_t in_additional_information
,
33 uint64_t in_file_id_volatile
);
34 static NTSTATUS
smbd_smb2_setinfo_recv(struct tevent_req
*req
);
36 static void smbd_smb2_request_setinfo_done(struct tevent_req
*subreq
);
37 NTSTATUS
smbd_smb2_request_process_setinfo(struct smbd_smb2_request
*req
)
40 const uint8_t *inbody
;
41 int i
= req
->current_idx
;
42 size_t expected_body_size
= 0x21;
45 uint8_t in_file_info_class
;
46 uint16_t in_input_buffer_offset
;
47 uint32_t in_input_buffer_length
;
48 DATA_BLOB in_input_buffer
;
49 uint32_t in_additional_information
;
50 uint64_t in_file_id_persistent
;
51 uint64_t in_file_id_volatile
;
52 struct tevent_req
*subreq
;
54 inhdr
= (const uint8_t *)req
->in
.vector
[i
+0].iov_base
;
55 if (req
->in
.vector
[i
+1].iov_len
!= (expected_body_size
& 0xFFFFFFFE)) {
56 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
59 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
61 body_size
= SVAL(inbody
, 0x00);
62 if (body_size
!= expected_body_size
) {
63 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
66 in_info_type
= CVAL(inbody
, 0x02);
67 in_file_info_class
= CVAL(inbody
, 0x03);
68 in_input_buffer_length
= IVAL(inbody
, 0x04);
69 in_input_buffer_offset
= SVAL(inbody
, 0x08);
70 /* 0x0A 2 bytes reserved */
71 in_additional_information
= IVAL(inbody
, 0x0C);
72 in_file_id_persistent
= BVAL(inbody
, 0x10);
73 in_file_id_volatile
= BVAL(inbody
, 0x18);
75 if (in_input_buffer_offset
== 0 && in_input_buffer_length
== 0) {
77 } else if (in_input_buffer_offset
!=
78 (SMB2_HDR_BODY
+ (body_size
& 0xFFFFFFFE))) {
79 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
82 if (in_input_buffer_length
> req
->in
.vector
[i
+2].iov_len
) {
83 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
86 in_input_buffer
.data
= (uint8_t *)req
->in
.vector
[i
+2].iov_base
;
87 in_input_buffer
.length
= in_input_buffer_length
;
89 if (req
->compat_chain_fsp
) {
91 } else if (in_file_id_persistent
!= in_file_id_volatile
) {
92 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
95 subreq
= smbd_smb2_setinfo_send(req
,
96 req
->sconn
->smb2
.event_ctx
,
101 in_additional_information
,
102 in_file_id_volatile
);
103 if (subreq
== NULL
) {
104 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
106 tevent_req_set_callback(subreq
, smbd_smb2_request_setinfo_done
, req
);
108 return smbd_smb2_request_pending_queue(req
, subreq
);
111 static void smbd_smb2_request_setinfo_done(struct tevent_req
*subreq
)
113 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
114 struct smbd_smb2_request
);
117 NTSTATUS error
; /* transport error */
119 status
= smbd_smb2_setinfo_recv(subreq
);
121 if (!NT_STATUS_IS_OK(status
)) {
122 error
= smbd_smb2_request_error(req
, status
);
123 if (!NT_STATUS_IS_OK(error
)) {
124 smbd_server_connection_terminate(req
->sconn
,
131 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x02);
132 if (outbody
.data
== NULL
) {
133 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
134 if (!NT_STATUS_IS_OK(error
)) {
135 smbd_server_connection_terminate(req
->sconn
,
142 SSVAL(outbody
.data
, 0x00, 0x02); /* struct size */
144 error
= smbd_smb2_request_done(req
, outbody
, NULL
);
145 if (!NT_STATUS_IS_OK(error
)) {
146 smbd_server_connection_terminate(req
->sconn
,
152 struct smbd_smb2_setinfo_state
{
153 struct smbd_smb2_request
*smb2req
;
156 static struct tevent_req
*smbd_smb2_setinfo_send(TALLOC_CTX
*mem_ctx
,
157 struct tevent_context
*ev
,
158 struct smbd_smb2_request
*smb2req
,
159 uint8_t in_info_type
,
160 uint8_t in_file_info_class
,
161 DATA_BLOB in_input_buffer
,
162 uint32_t in_additional_information
,
163 uint64_t in_file_id_volatile
)
165 struct tevent_req
*req
= NULL
;
166 struct smbd_smb2_setinfo_state
*state
= NULL
;
167 struct smb_request
*smbreq
= NULL
;
168 connection_struct
*conn
= smb2req
->tcon
->compat_conn
;
169 files_struct
*fsp
= NULL
;
172 req
= tevent_req_create(mem_ctx
, &state
,
173 struct smbd_smb2_setinfo_state
);
177 state
->smb2req
= smb2req
;
179 DEBUG(10,("smbd_smb2_setinfo_send: file_id[0x%016llX]\n",
180 (unsigned long long)in_file_id_volatile
));
182 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
183 if (tevent_req_nomem(smbreq
, req
)) {
184 return tevent_req_post(req
, ev
);
187 fsp
= file_fsp(smbreq
, (uint16_t)in_file_id_volatile
);
189 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
190 return tevent_req_post(req
, ev
);
192 if (conn
!= fsp
->conn
) {
193 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
194 return tevent_req_post(req
, ev
);
196 if (smb2req
->session
->vuid
!= fsp
->vuid
) {
197 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
198 return tevent_req_post(req
, ev
);
202 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
203 return tevent_req_post(req
, ev
);
206 switch (in_info_type
) {
207 case 0x01:/* SMB2_SETINFO_FILE */
209 uint16_t file_info_level
;
215 file_info_level
= in_file_info_class
+ 1000;
216 if (file_info_level
== SMB_FILE_RENAME_INFORMATION
) {
217 /* SMB2_FILE_RENAME_INFORMATION_INTERNAL == 0xFF00 + in_file_info_class */
218 file_info_level
= SMB2_FILE_RENAME_INFORMATION_INTERNAL
;
221 if (fsp
->is_directory
|| fsp
->fh
->fd
== -1) {
223 * This is actually a SETFILEINFO on a directory
224 * handle (returned from an NT SMB). NT5.0 seems
225 * to do this call. JRA.
227 if (INFO_LEVEL_IS_UNIX(file_info_level
)) {
228 /* Always do lstat for UNIX calls. */
229 if (SMB_VFS_LSTAT(conn
, fsp
->fsp_name
)) {
230 DEBUG(3,("smbd_smb2_setinfo_send: "
231 "SMB_VFS_LSTAT of %s failed "
232 "(%s)\n", fsp_str_dbg(fsp
),
234 status
= map_nt_error_from_unix(errno
);
235 tevent_req_nterror(req
, status
);
236 return tevent_req_post(req
, ev
);
239 if (SMB_VFS_STAT(conn
, fsp
->fsp_name
) != 0) {
240 DEBUG(3,("smbd_smb2_setinfo_send: "
241 "fileinfo of %s failed (%s)\n",
244 status
= map_nt_error_from_unix(errno
);
245 tevent_req_nterror(req
, status
);
246 return tevent_req_post(req
, ev
);
249 } else if (fsp
->print_file
) {
251 * Doing a DELETE_ON_CLOSE should cancel a print job.
253 if ((file_info_level
== SMB_SET_FILE_DISPOSITION_INFO
)
254 && in_input_buffer
.length
>= 1
255 && CVAL(in_input_buffer
.data
,0)) {
256 fsp
->fh
->private_options
|= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE
;
258 DEBUG(3,("smbd_smb2_setinfo_send: "
259 "Cancelling print job (%s)\n",
262 tevent_req_done(req
);
263 return tevent_req_post(req
, ev
);
265 tevent_req_nterror(req
,
266 NT_STATUS_OBJECT_PATH_INVALID
);
267 return tevent_req_post(req
, ev
);
271 * Original code - this is an open file.
274 if (SMB_VFS_FSTAT(fsp
, &fsp
->fsp_name
->st
) != 0) {
275 DEBUG(3,("smbd_smb2_setinfo_send: fstat "
276 "of fnum %d failed (%s)\n", fsp
->fnum
,
278 status
= map_nt_error_from_unix(errno
);
279 tevent_req_nterror(req
, status
);
280 return tevent_req_post(req
, ev
);
285 data_size
= in_input_buffer
.length
;
287 data
= (char *)SMB_MALLOC_ARRAY(char, data_size
);
288 if (tevent_req_nomem(data
, req
)) {
289 return tevent_req_post(req
, ev
);
291 memcpy(data
, in_input_buffer
.data
, data_size
);
294 status
= smbd_do_setfilepathinfo(conn
, smbreq
, state
,
302 if (!NT_STATUS_IS_OK(status
)) {
303 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_LEVEL
)) {
304 status
= NT_STATUS_INVALID_INFO_CLASS
;
306 tevent_req_nterror(req
, status
);
307 return tevent_req_post(req
, ev
);
312 case 0x03:/* SMB2_SETINFO_SECURITY */
314 if (!CAN_WRITE(conn
)) {
315 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
316 return tevent_req_post(req
, ev
);
320 in_input_buffer
.data
,
321 in_input_buffer
.length
,
322 in_additional_information
);
323 if (!NT_STATUS_IS_OK(status
)) {
324 tevent_req_nterror(req
, status
);
325 return tevent_req_post(req
, ev
);
331 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
332 return tevent_req_post(req
, ev
);
335 tevent_req_done(req
);
336 return tevent_req_post(req
, ev
);
339 static NTSTATUS
smbd_smb2_setinfo_recv(struct tevent_req
*req
)
343 if (tevent_req_is_nterror(req
, &status
)) {
344 tevent_req_received(req
);
348 tevent_req_received(req
);