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
;
46 uint8_t in_file_info_class
;
47 uint16_t in_input_buffer_offset
;
48 uint32_t in_input_buffer_length
;
49 DATA_BLOB in_input_buffer
;
50 uint32_t in_additional_information
;
51 uint64_t in_file_id_persistent
;
52 uint64_t in_file_id_volatile
;
53 struct tevent_req
*subreq
;
55 status
= smbd_smb2_request_verify_sizes(req
, 0x21);
56 if (!NT_STATUS_IS_OK(status
)) {
57 return smbd_smb2_request_error(req
, status
);
59 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
61 in_info_type
= CVAL(inbody
, 0x02);
62 in_file_info_class
= CVAL(inbody
, 0x03);
63 in_input_buffer_length
= IVAL(inbody
, 0x04);
64 in_input_buffer_offset
= SVAL(inbody
, 0x08);
65 /* 0x0A 2 bytes reserved */
66 in_additional_information
= IVAL(inbody
, 0x0C);
67 in_file_id_persistent
= BVAL(inbody
, 0x10);
68 in_file_id_volatile
= BVAL(inbody
, 0x18);
70 if (in_input_buffer_offset
== 0 && in_input_buffer_length
== 0) {
72 } else if (in_input_buffer_offset
!=
73 (SMB2_HDR_BODY
+ req
->in
.vector
[i
+1].iov_len
)) {
74 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
77 if (in_input_buffer_length
> req
->in
.vector
[i
+2].iov_len
) {
78 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
81 in_input_buffer
.data
= (uint8_t *)req
->in
.vector
[i
+2].iov_base
;
82 in_input_buffer
.length
= in_input_buffer_length
;
84 if (in_input_buffer
.length
> req
->sconn
->smb2
.max_trans
) {
85 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
88 status
= smbd_smb2_request_verify_creditcharge(req
,
89 in_input_buffer
.length
);
90 if (!NT_STATUS_IS_OK(status
)) {
91 return smbd_smb2_request_error(req
, status
);
94 if (req
->compat_chain_fsp
) {
96 } else if (in_file_id_persistent
!= in_file_id_volatile
) {
97 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
100 subreq
= smbd_smb2_setinfo_send(req
,
106 in_additional_information
,
107 in_file_id_volatile
);
108 if (subreq
== NULL
) {
109 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
111 tevent_req_set_callback(subreq
, smbd_smb2_request_setinfo_done
, req
);
113 return smbd_smb2_request_pending_queue(req
, subreq
, 500);
116 static void smbd_smb2_request_setinfo_done(struct tevent_req
*subreq
)
118 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
119 struct smbd_smb2_request
);
122 NTSTATUS error
; /* transport error */
124 status
= smbd_smb2_setinfo_recv(subreq
);
126 if (!NT_STATUS_IS_OK(status
)) {
127 error
= smbd_smb2_request_error(req
, status
);
128 if (!NT_STATUS_IS_OK(error
)) {
129 smbd_server_connection_terminate(req
->sconn
,
136 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x02);
137 if (outbody
.data
== NULL
) {
138 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
139 if (!NT_STATUS_IS_OK(error
)) {
140 smbd_server_connection_terminate(req
->sconn
,
147 SSVAL(outbody
.data
, 0x00, 0x02); /* struct size */
149 error
= smbd_smb2_request_done(req
, outbody
, NULL
);
150 if (!NT_STATUS_IS_OK(error
)) {
151 smbd_server_connection_terminate(req
->sconn
,
157 struct smbd_smb2_setinfo_state
{
158 struct smbd_smb2_request
*smb2req
;
161 static struct tevent_req
*smbd_smb2_setinfo_send(TALLOC_CTX
*mem_ctx
,
162 struct tevent_context
*ev
,
163 struct smbd_smb2_request
*smb2req
,
164 uint8_t in_info_type
,
165 uint8_t in_file_info_class
,
166 DATA_BLOB in_input_buffer
,
167 uint32_t in_additional_information
,
168 uint64_t in_file_id_volatile
)
170 struct tevent_req
*req
= NULL
;
171 struct smbd_smb2_setinfo_state
*state
= NULL
;
172 struct smb_request
*smbreq
= NULL
;
173 connection_struct
*conn
= smb2req
->tcon
->compat_conn
;
174 files_struct
*fsp
= NULL
;
177 req
= tevent_req_create(mem_ctx
, &state
,
178 struct smbd_smb2_setinfo_state
);
182 state
->smb2req
= smb2req
;
184 DEBUG(10,("smbd_smb2_setinfo_send: file_id[0x%016llX]\n",
185 (unsigned long long)in_file_id_volatile
));
187 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
188 if (tevent_req_nomem(smbreq
, req
)) {
189 return tevent_req_post(req
, ev
);
192 fsp
= file_fsp(smbreq
, (uint16_t)in_file_id_volatile
);
194 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
195 return tevent_req_post(req
, ev
);
197 if (conn
!= fsp
->conn
) {
198 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
199 return tevent_req_post(req
, ev
);
201 if (smb2req
->session
->vuid
!= fsp
->vuid
) {
202 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
203 return tevent_req_post(req
, ev
);
207 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
208 return tevent_req_post(req
, ev
);
211 switch (in_info_type
) {
212 case 0x01:/* SMB2_SETINFO_FILE */
214 uint16_t file_info_level
;
220 file_info_level
= in_file_info_class
+ 1000;
221 if (file_info_level
== SMB_FILE_RENAME_INFORMATION
) {
222 /* SMB2_FILE_RENAME_INFORMATION_INTERNAL == 0xFF00 + in_file_info_class */
223 file_info_level
= SMB2_FILE_RENAME_INFORMATION_INTERNAL
;
226 if (fsp
->fh
->fd
== -1) {
228 * This is actually a SETFILEINFO on a directory
229 * handle (returned from an NT SMB). NT5.0 seems
230 * to do this call. JRA.
232 if (INFO_LEVEL_IS_UNIX(file_info_level
)) {
233 /* Always do lstat for UNIX calls. */
234 if (SMB_VFS_LSTAT(conn
, fsp
->fsp_name
)) {
235 DEBUG(3,("smbd_smb2_setinfo_send: "
236 "SMB_VFS_LSTAT of %s failed "
237 "(%s)\n", fsp_str_dbg(fsp
),
239 status
= map_nt_error_from_unix(errno
);
240 tevent_req_nterror(req
, status
);
241 return tevent_req_post(req
, ev
);
244 if (SMB_VFS_STAT(conn
, fsp
->fsp_name
) != 0) {
245 DEBUG(3,("smbd_smb2_setinfo_send: "
246 "fileinfo of %s failed (%s)\n",
249 status
= map_nt_error_from_unix(errno
);
250 tevent_req_nterror(req
, status
);
251 return tevent_req_post(req
, ev
);
254 } else if (fsp
->print_file
) {
256 * Doing a DELETE_ON_CLOSE should cancel a print job.
258 if ((file_info_level
== SMB_SET_FILE_DISPOSITION_INFO
)
259 && in_input_buffer
.length
>= 1
260 && CVAL(in_input_buffer
.data
,0)) {
261 fsp
->fh
->private_options
|= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE
;
263 DEBUG(3,("smbd_smb2_setinfo_send: "
264 "Cancelling print job (%s)\n",
267 tevent_req_done(req
);
268 return tevent_req_post(req
, ev
);
270 tevent_req_nterror(req
,
271 NT_STATUS_OBJECT_PATH_INVALID
);
272 return tevent_req_post(req
, ev
);
276 * Original code - this is an open file.
279 if (SMB_VFS_FSTAT(fsp
, &fsp
->fsp_name
->st
) != 0) {
280 DEBUG(3,("smbd_smb2_setinfo_send: fstat "
281 "of fnum %d failed (%s)\n", fsp
->fnum
,
283 status
= map_nt_error_from_unix(errno
);
284 tevent_req_nterror(req
, status
);
285 return tevent_req_post(req
, ev
);
290 data_size
= in_input_buffer
.length
;
292 data
= (char *)SMB_MALLOC_ARRAY(char, data_size
);
293 if (tevent_req_nomem(data
, req
)) {
294 return tevent_req_post(req
, ev
);
296 memcpy(data
, in_input_buffer
.data
, data_size
);
299 status
= smbd_do_setfilepathinfo(conn
, smbreq
, state
,
307 if (!NT_STATUS_IS_OK(status
)) {
308 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_LEVEL
)) {
309 status
= NT_STATUS_INVALID_INFO_CLASS
;
311 tevent_req_nterror(req
, status
);
312 return tevent_req_post(req
, ev
);
317 case 0x03:/* SMB2_SETINFO_SECURITY */
319 if (!CAN_WRITE(conn
)) {
320 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
321 return tevent_req_post(req
, ev
);
325 in_input_buffer
.data
,
326 in_input_buffer
.length
,
327 in_additional_information
);
328 if (!NT_STATUS_IS_OK(status
)) {
329 tevent_req_nterror(req
, status
);
330 return tevent_req_post(req
, ev
);
336 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
337 return tevent_req_post(req
, ev
);
340 tevent_req_done(req
);
341 return tevent_req_post(req
, ev
);
344 static NTSTATUS
smbd_smb2_setinfo_recv(struct tevent_req
*req
)
348 if (tevent_req_is_nterror(req
, &status
)) {
349 tevent_req_received(req
);
353 tevent_req_received(req
);