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 if (req
->compat_chain_fsp
) {
90 } else if (in_file_id_persistent
!= in_file_id_volatile
) {
91 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
94 subreq
= smbd_smb2_setinfo_send(req
,
95 req
->sconn
->smb2
.event_ctx
,
100 in_additional_information
,
101 in_file_id_volatile
);
102 if (subreq
== NULL
) {
103 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
105 tevent_req_set_callback(subreq
, smbd_smb2_request_setinfo_done
, req
);
107 return smbd_smb2_request_pending_queue(req
, subreq
);
110 static void smbd_smb2_request_setinfo_done(struct tevent_req
*subreq
)
112 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
113 struct smbd_smb2_request
);
116 NTSTATUS error
; /* transport error */
118 status
= smbd_smb2_setinfo_recv(subreq
);
120 if (!NT_STATUS_IS_OK(status
)) {
121 error
= smbd_smb2_request_error(req
, status
);
122 if (!NT_STATUS_IS_OK(error
)) {
123 smbd_server_connection_terminate(req
->sconn
,
130 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x02);
131 if (outbody
.data
== NULL
) {
132 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
133 if (!NT_STATUS_IS_OK(error
)) {
134 smbd_server_connection_terminate(req
->sconn
,
141 SSVAL(outbody
.data
, 0x00, 0x02); /* struct size */
143 error
= smbd_smb2_request_done(req
, outbody
, NULL
);
144 if (!NT_STATUS_IS_OK(error
)) {
145 smbd_server_connection_terminate(req
->sconn
,
151 struct smbd_smb2_setinfo_state
{
152 struct smbd_smb2_request
*smb2req
;
155 static struct tevent_req
*smbd_smb2_setinfo_send(TALLOC_CTX
*mem_ctx
,
156 struct tevent_context
*ev
,
157 struct smbd_smb2_request
*smb2req
,
158 uint8_t in_info_type
,
159 uint8_t in_file_info_class
,
160 DATA_BLOB in_input_buffer
,
161 uint32_t in_additional_information
,
162 uint64_t in_file_id_volatile
)
164 struct tevent_req
*req
= NULL
;
165 struct smbd_smb2_setinfo_state
*state
= NULL
;
166 struct smb_request
*smbreq
= NULL
;
167 connection_struct
*conn
= smb2req
->tcon
->compat_conn
;
168 files_struct
*fsp
= NULL
;
171 req
= tevent_req_create(mem_ctx
, &state
,
172 struct smbd_smb2_setinfo_state
);
176 state
->smb2req
= smb2req
;
178 DEBUG(10,("smbd_smb2_setinfo_send: file_id[0x%016llX]\n",
179 (unsigned long long)in_file_id_volatile
));
181 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
182 if (tevent_req_nomem(smbreq
, req
)) {
183 return tevent_req_post(req
, ev
);
186 fsp
= file_fsp(smbreq
, (uint16_t)in_file_id_volatile
);
188 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
189 return tevent_req_post(req
, ev
);
191 if (conn
!= fsp
->conn
) {
192 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
193 return tevent_req_post(req
, ev
);
195 if (smb2req
->session
->vuid
!= fsp
->vuid
) {
196 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
197 return tevent_req_post(req
, ev
);
201 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
202 return tevent_req_post(req
, ev
);
205 switch (in_info_type
) {
206 case 0x01:/* SMB2_SETINFO_FILE */
208 uint16_t file_info_level
;
214 file_info_level
= in_file_info_class
+ 1000;
215 if (file_info_level
== SMB_FILE_RENAME_INFORMATION
) {
216 /* SMB2_FILE_RENAME_INFORMATION_INTERNAL == 0xFF00 + in_file_info_class */
217 file_info_level
= SMB2_FILE_RENAME_INFORMATION_INTERNAL
;
220 if (fsp
->fh
->fd
== -1) {
222 * This is actually a SETFILEINFO on a directory
223 * handle (returned from an NT SMB). NT5.0 seems
224 * to do this call. JRA.
226 if (INFO_LEVEL_IS_UNIX(file_info_level
)) {
227 /* Always do lstat for UNIX calls. */
228 if (SMB_VFS_LSTAT(conn
, fsp
->fsp_name
)) {
229 DEBUG(3,("smbd_smb2_setinfo_send: "
230 "SMB_VFS_LSTAT of %s failed "
231 "(%s)\n", fsp_str_dbg(fsp
),
233 status
= map_nt_error_from_unix(errno
);
234 tevent_req_nterror(req
, status
);
235 return tevent_req_post(req
, ev
);
238 if (SMB_VFS_STAT(conn
, fsp
->fsp_name
) != 0) {
239 DEBUG(3,("smbd_smb2_setinfo_send: "
240 "fileinfo of %s failed (%s)\n",
243 status
= map_nt_error_from_unix(errno
);
244 tevent_req_nterror(req
, status
);
245 return tevent_req_post(req
, ev
);
248 } else if (fsp
->print_file
) {
250 * Doing a DELETE_ON_CLOSE should cancel a print job.
252 if ((file_info_level
== SMB_SET_FILE_DISPOSITION_INFO
)
253 && in_input_buffer
.length
>= 1
254 && CVAL(in_input_buffer
.data
,0)) {
255 fsp
->fh
->private_options
|= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE
;
257 DEBUG(3,("smbd_smb2_setinfo_send: "
258 "Cancelling print job (%s)\n",
261 tevent_req_done(req
);
262 return tevent_req_post(req
, ev
);
264 tevent_req_nterror(req
,
265 NT_STATUS_OBJECT_PATH_INVALID
);
266 return tevent_req_post(req
, ev
);
270 * Original code - this is an open file.
273 if (SMB_VFS_FSTAT(fsp
, &fsp
->fsp_name
->st
) != 0) {
274 DEBUG(3,("smbd_smb2_setinfo_send: fstat "
275 "of fnum %d failed (%s)\n", fsp
->fnum
,
277 status
= map_nt_error_from_unix(errno
);
278 tevent_req_nterror(req
, status
);
279 return tevent_req_post(req
, ev
);
284 data_size
= in_input_buffer
.length
;
286 data
= (char *)SMB_MALLOC_ARRAY(char, data_size
);
287 if (tevent_req_nomem(data
, req
)) {
288 return tevent_req_post(req
, ev
);
290 memcpy(data
, in_input_buffer
.data
, data_size
);
293 status
= smbd_do_setfilepathinfo(conn
, smbreq
, state
,
301 if (!NT_STATUS_IS_OK(status
)) {
302 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_LEVEL
)) {
303 status
= NT_STATUS_INVALID_INFO_CLASS
;
305 tevent_req_nterror(req
, status
);
306 return tevent_req_post(req
, ev
);
311 case 0x03:/* SMB2_SETINFO_SECURITY */
313 if (!CAN_WRITE(conn
)) {
314 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
315 return tevent_req_post(req
, ev
);
319 in_input_buffer
.data
,
320 in_input_buffer
.length
,
321 in_additional_information
);
322 if (!NT_STATUS_IS_OK(status
)) {
323 tevent_req_nterror(req
, status
);
324 return tevent_req_post(req
, ev
);
330 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
331 return tevent_req_post(req
, ev
);
334 tevent_req_done(req
);
335 return tevent_req_post(req
, ev
);
338 static NTSTATUS
smbd_smb2_setinfo_recv(struct tevent_req
*req
)
342 if (tevent_req_is_nterror(req
, &status
)) {
343 tevent_req_received(req
);
347 tevent_req_received(req
);