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_getinfo_send(TALLOC_CTX
*mem_ctx
,
30 struct tevent_context
*ev
,
31 struct smbd_smb2_request
*smb2req
,
33 uint8_t in_file_info_class
,
34 uint32_t in_output_buffer_length
,
35 DATA_BLOB in_input_buffer
,
36 uint32_t in_additional_information
,
38 uint64_t in_file_id_volatile
);
39 static NTSTATUS
smbd_smb2_getinfo_recv(struct tevent_req
*req
,
41 DATA_BLOB
*out_output_buffer
,
42 NTSTATUS
*p_call_status
);
44 static void smbd_smb2_request_getinfo_done(struct tevent_req
*subreq
);
45 NTSTATUS
smbd_smb2_request_process_getinfo(struct smbd_smb2_request
*req
)
48 const uint8_t *inbody
;
49 int i
= req
->current_idx
;
50 size_t expected_body_size
= 0x29;
53 uint8_t in_file_info_class
;
54 uint32_t in_output_buffer_length
;
55 uint16_t in_input_buffer_offset
;
56 uint32_t in_input_buffer_length
;
57 DATA_BLOB in_input_buffer
;
58 uint32_t in_additional_information
;
60 uint64_t in_file_id_persistent
;
61 uint64_t in_file_id_volatile
;
62 struct tevent_req
*subreq
;
64 inhdr
= (const uint8_t *)req
->in
.vector
[i
+0].iov_base
;
65 if (req
->in
.vector
[i
+1].iov_len
!= (expected_body_size
& 0xFFFFFFFE)) {
66 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
69 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
71 body_size
= SVAL(inbody
, 0x00);
72 if (body_size
!= expected_body_size
) {
73 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
76 in_info_type
= CVAL(inbody
, 0x02);
77 in_file_info_class
= CVAL(inbody
, 0x03);
78 in_output_buffer_length
= IVAL(inbody
, 0x04);
79 in_input_buffer_offset
= SVAL(inbody
, 0x08);
80 /* 0x0A 2 bytes reserved */
81 in_input_buffer_length
= IVAL(inbody
, 0x0C);
82 in_additional_information
= IVAL(inbody
, 0x10);
83 in_flags
= IVAL(inbody
, 0x14);
84 in_file_id_persistent
= BVAL(inbody
, 0x18);
85 in_file_id_volatile
= BVAL(inbody
, 0x20);
87 if (in_input_buffer_offset
== 0 && in_input_buffer_length
== 0) {
89 } else if (in_input_buffer_offset
!=
90 (SMB2_HDR_BODY
+ (body_size
& 0xFFFFFFFE))) {
91 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
94 if (in_input_buffer_length
> req
->in
.vector
[i
+2].iov_len
) {
95 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
98 in_input_buffer
.data
= (uint8_t *)req
->in
.vector
[i
+2].iov_base
;
99 in_input_buffer
.length
= in_input_buffer_length
;
101 if (req
->compat_chain_fsp
) {
103 } else if (in_file_id_persistent
!= in_file_id_volatile
) {
104 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
107 subreq
= smbd_smb2_getinfo_send(req
,
108 req
->sconn
->smb2
.event_ctx
,
112 in_output_buffer_length
,
114 in_additional_information
,
116 in_file_id_volatile
);
117 if (subreq
== NULL
) {
118 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
120 tevent_req_set_callback(subreq
, smbd_smb2_request_getinfo_done
, req
);
122 return smbd_smb2_request_pending_queue(req
, subreq
);
125 static void smbd_smb2_request_getinfo_done(struct tevent_req
*subreq
)
127 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
128 struct smbd_smb2_request
);
129 int i
= req
->current_idx
;
133 uint16_t out_output_buffer_offset
;
134 DATA_BLOB out_output_buffer
= data_blob_null
;
136 NTSTATUS call_status
= NT_STATUS_OK
;
137 NTSTATUS error
; /* transport error */
139 status
= smbd_smb2_getinfo_recv(subreq
,
144 if (!NT_STATUS_IS_OK(status
)) {
145 error
= smbd_smb2_request_error(req
, status
);
146 if (!NT_STATUS_IS_OK(error
)) {
147 smbd_server_connection_terminate(req
->sconn
,
154 if (!NT_STATUS_IS_OK(call_status
)) {
155 /* Return a specific error with data. */
156 error
= smbd_smb2_request_error_ex(req
,
160 if (!NT_STATUS_IS_OK(error
)) {
161 smbd_server_connection_terminate(req
->sconn
,
168 out_output_buffer_offset
= SMB2_HDR_BODY
+ 0x08;
170 outhdr
= (uint8_t *)req
->out
.vector
[i
].iov_base
;
172 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x08);
173 if (outbody
.data
== NULL
) {
174 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
175 if (!NT_STATUS_IS_OK(error
)) {
176 smbd_server_connection_terminate(req
->sconn
,
183 SSVAL(outbody
.data
, 0x00, 0x08 + 1); /* struct size */
184 SSVAL(outbody
.data
, 0x02,
185 out_output_buffer_offset
); /* output buffer offset */
186 SIVAL(outbody
.data
, 0x04,
187 out_output_buffer
.length
); /* output buffer length */
189 outdyn
= out_output_buffer
;
191 error
= smbd_smb2_request_done(req
, outbody
, &outdyn
);
192 if (!NT_STATUS_IS_OK(error
)) {
193 smbd_server_connection_terminate(req
->sconn
,
199 struct smbd_smb2_getinfo_state
{
200 struct smbd_smb2_request
*smb2req
;
202 DATA_BLOB out_output_buffer
;
205 static void smb2_ipc_getinfo(struct tevent_req
*req
,
206 struct smbd_smb2_getinfo_state
*state
,
207 struct tevent_context
*ev
,
208 uint8_t in_info_type
,
209 uint8_t in_file_info_class
)
211 /* We want to reply to SMB2_GETINFO_FILE
212 with a class of SMB2_FILE_STANDARD_INFO as
213 otherwise a Win7 client issues this request
214 twice (2xroundtrips) if we return NOT_SUPPORTED.
215 NB. We do the same for SMB1 in call_trans2qpipeinfo() */
217 if (in_info_type
== 0x01 && /* SMB2_GETINFO_FILE */
218 in_file_info_class
== 0x05) { /* SMB2_FILE_STANDARD_INFO */
219 state
->out_output_buffer
= data_blob_talloc(state
,
221 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
225 memset(state
->out_output_buffer
.data
,0,24);
226 SOFF_T(state
->out_output_buffer
.data
,0,4096LL);
227 SIVAL(state
->out_output_buffer
.data
,16,1);
228 SIVAL(state
->out_output_buffer
.data
,20,1);
229 tevent_req_done(req
);
231 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
235 static struct tevent_req
*smbd_smb2_getinfo_send(TALLOC_CTX
*mem_ctx
,
236 struct tevent_context
*ev
,
237 struct smbd_smb2_request
*smb2req
,
238 uint8_t in_info_type
,
239 uint8_t in_file_info_class
,
240 uint32_t in_output_buffer_length
,
241 DATA_BLOB in_input_buffer
,
242 uint32_t in_additional_information
,
244 uint64_t in_file_id_volatile
)
246 struct tevent_req
*req
;
247 struct smbd_smb2_getinfo_state
*state
;
248 struct smb_request
*smbreq
;
249 connection_struct
*conn
= smb2req
->tcon
->compat_conn
;
253 req
= tevent_req_create(mem_ctx
, &state
,
254 struct smbd_smb2_getinfo_state
);
258 state
->smb2req
= smb2req
;
259 state
->status
= NT_STATUS_OK
;
260 state
->out_output_buffer
= data_blob_null
;
262 DEBUG(10,("smbd_smb2_getinfo_send: file_id[0x%016llX]\n",
263 (unsigned long long)in_file_id_volatile
));
265 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
266 if (tevent_req_nomem(smbreq
, req
)) {
267 return tevent_req_post(req
, ev
);
270 fsp
= file_fsp(smbreq
, (uint16_t)in_file_id_volatile
);
272 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
273 return tevent_req_post(req
, ev
);
275 if (conn
!= fsp
->conn
) {
276 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
277 return tevent_req_post(req
, ev
);
279 if (smb2req
->session
->vuid
!= fsp
->vuid
) {
280 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
281 return tevent_req_post(req
, ev
);
285 smb2_ipc_getinfo(req
, state
, ev
,
286 in_info_type
, in_file_info_class
);
287 return tevent_req_post(req
, ev
);
290 switch (in_info_type
) {
291 case 0x01:/* SMB2_GETINFO_FILE */
293 uint16_t file_info_level
;
295 unsigned int data_size
= 0;
296 bool delete_pending
= false;
297 struct timespec write_time_ts
;
298 struct file_id fileid
;
299 struct ea_list
*ea_list
= NULL
;
300 int lock_data_count
= 0;
301 char *lock_data
= NULL
;
303 ZERO_STRUCT(write_time_ts
);
305 switch (in_file_info_class
) {
306 case 0x0F:/* RAW_FILEINFO_SMB2_ALL_EAS */
307 file_info_level
= 0xFF00 | in_file_info_class
;
310 case 0x12:/* RAW_FILEINFO_SMB2_ALL_INFORMATION */
311 file_info_level
= 0xFF00 | in_file_info_class
;
315 /* the levels directly map to the passthru levels */
316 file_info_level
= in_file_info_class
+ 1000;
320 if (fsp
->fake_file_handle
) {
322 * This is actually for the QUOTA_FAKE_FILE --metze
325 /* We know this name is ok, it's already passed the checks. */
327 } else if (fsp
&& fsp
->fh
->fd
== -1) {
329 * This is actually a QFILEINFO on a directory
330 * handle (returned from an NT SMB). NT5.0 seems
331 * to do this call. JRA.
334 if (INFO_LEVEL_IS_UNIX(file_info_level
)) {
335 /* Always do lstat for UNIX calls. */
336 if (SMB_VFS_LSTAT(conn
, fsp
->fsp_name
)) {
337 DEBUG(3,("smbd_smb2_getinfo_send: "
338 "SMB_VFS_LSTAT of %s failed "
339 "(%s)\n", fsp_str_dbg(fsp
),
341 status
= map_nt_error_from_unix(errno
);
342 tevent_req_nterror(req
, status
);
343 return tevent_req_post(req
, ev
);
345 } else if (SMB_VFS_STAT(conn
, fsp
->fsp_name
)) {
346 DEBUG(3,("smbd_smb2_getinfo_send: "
347 "SMB_VFS_STAT of %s failed (%s)\n",
350 status
= map_nt_error_from_unix(errno
);
351 tevent_req_nterror(req
, status
);
352 return tevent_req_post(req
, ev
);
355 fileid
= vfs_file_id_from_sbuf(conn
,
357 get_file_infos(fileid
, fsp
->name_hash
,
358 &delete_pending
, &write_time_ts
);
361 * Original code - this is an open file.
364 if (SMB_VFS_FSTAT(fsp
, &fsp
->fsp_name
->st
) != 0) {
365 DEBUG(3, ("smbd_smb2_getinfo_send: "
366 "fstat of fnum %d failed (%s)\n",
367 fsp
->fnum
, strerror(errno
)));
368 status
= map_nt_error_from_unix(errno
);
369 tevent_req_nterror(req
, status
);
370 return tevent_req_post(req
, ev
);
372 fileid
= vfs_file_id_from_sbuf(conn
,
374 get_file_infos(fileid
, fsp
->name_hash
,
375 &delete_pending
, &write_time_ts
);
378 status
= smbd_do_qfilepathinfo(conn
, state
,
388 in_output_buffer_length
,
391 if (!NT_STATUS_IS_OK(status
)) {
393 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_LEVEL
)) {
394 status
= NT_STATUS_INVALID_INFO_CLASS
;
396 tevent_req_nterror(req
, status
);
397 return tevent_req_post(req
, ev
);
400 state
->out_output_buffer
= data_blob_talloc(state
,
404 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
405 return tevent_req_post(req
, ev
);
412 case 0x02:/* SMB2_GETINFO_FS */
414 uint16_t file_info_level
;
418 /* the levels directly map to the passthru levels */
419 file_info_level
= in_file_info_class
+ 1000;
421 status
= smbd_do_qfsinfo(conn
, state
,
424 in_output_buffer_length
,
427 if (!NT_STATUS_IS_OK(status
)) {
429 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_LEVEL
)) {
430 status
= NT_STATUS_INVALID_INFO_CLASS
;
432 tevent_req_nterror(req
, status
);
433 return tevent_req_post(req
, ev
);
436 state
->out_output_buffer
= data_blob_talloc(state
,
440 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
441 return tevent_req_post(req
, ev
);
448 case 0x03:/* SMB2_GETINFO_SEC */
450 uint8_t *p_marshalled_sd
= NULL
;
453 status
= smbd_do_query_security_desc(conn
,
456 /* Security info wanted. */
457 in_additional_information
,
458 in_output_buffer_length
,
462 if (NT_STATUS_EQUAL(status
, NT_STATUS_BUFFER_TOO_SMALL
)) {
463 /* Return needed size. */
464 state
->out_output_buffer
= data_blob_talloc(state
,
467 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
468 return tevent_req_post(req
, ev
);
470 SIVAL(state
->out_output_buffer
.data
,0,(uint32_t)sd_size
);
471 state
->status
= NT_STATUS_BUFFER_TOO_SMALL
;
474 if (!NT_STATUS_IS_OK(status
)) {
475 DEBUG(10,("smbd_smb2_getinfo_send: "
476 "smbd_do_query_security_desc of %s failed "
477 "(%s)\n", fsp_str_dbg(fsp
),
479 tevent_req_nterror(req
, status
);
480 return tevent_req_post(req
, ev
);
484 state
->out_output_buffer
= data_blob_talloc(state
,
487 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
488 return tevent_req_post(req
, ev
);
495 DEBUG(10,("smbd_smb2_getinfo_send: "
496 "unknown in_info_type of %u "
498 (unsigned int)in_info_type
,
501 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
502 return tevent_req_post(req
, ev
);
505 tevent_req_done(req
);
506 return tevent_req_post(req
, ev
);
509 static NTSTATUS
smbd_smb2_getinfo_recv(struct tevent_req
*req
,
511 DATA_BLOB
*out_output_buffer
,
515 struct smbd_smb2_getinfo_state
*state
= tevent_req_data(req
,
516 struct smbd_smb2_getinfo_state
);
518 if (tevent_req_is_nterror(req
, &status
)) {
519 tevent_req_received(req
);
523 *out_output_buffer
= state
->out_output_buffer
;
524 talloc_steal(mem_ctx
, out_output_buffer
->data
);
525 *pstatus
= state
->status
;
527 tevent_req_received(req
);