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
;
51 uint8_t in_file_info_class
;
52 uint32_t in_output_buffer_length
;
53 uint16_t in_input_buffer_offset
;
54 uint32_t in_input_buffer_length
;
55 DATA_BLOB in_input_buffer
;
56 uint32_t in_additional_information
;
58 uint64_t in_file_id_persistent
;
59 uint64_t in_file_id_volatile
;
60 struct tevent_req
*subreq
;
62 status
= smbd_smb2_request_verify_sizes(req
, 0x29);
63 if (!NT_STATUS_IS_OK(status
)) {
64 return smbd_smb2_request_error(req
, status
);
66 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
68 in_info_type
= CVAL(inbody
, 0x02);
69 in_file_info_class
= CVAL(inbody
, 0x03);
70 in_output_buffer_length
= IVAL(inbody
, 0x04);
71 in_input_buffer_offset
= SVAL(inbody
, 0x08);
72 /* 0x0A 2 bytes reserved */
73 in_input_buffer_length
= IVAL(inbody
, 0x0C);
74 in_additional_information
= IVAL(inbody
, 0x10);
75 in_flags
= IVAL(inbody
, 0x14);
76 in_file_id_persistent
= BVAL(inbody
, 0x18);
77 in_file_id_volatile
= BVAL(inbody
, 0x20);
79 if (in_input_buffer_offset
== 0 && in_input_buffer_length
== 0) {
81 } else if (in_input_buffer_offset
!=
82 (SMB2_HDR_BODY
+ req
->in
.vector
[i
+1].iov_len
)) {
83 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
86 if (in_input_buffer_length
> req
->in
.vector
[i
+2].iov_len
) {
87 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
90 in_input_buffer
.data
= (uint8_t *)req
->in
.vector
[i
+2].iov_base
;
91 in_input_buffer
.length
= in_input_buffer_length
;
93 if (req
->compat_chain_fsp
) {
95 } else if (in_file_id_persistent
!= in_file_id_volatile
) {
96 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
99 subreq
= smbd_smb2_getinfo_send(req
,
100 req
->sconn
->smb2
.event_ctx
,
104 in_output_buffer_length
,
106 in_additional_information
,
108 in_file_id_volatile
);
109 if (subreq
== NULL
) {
110 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
112 tevent_req_set_callback(subreq
, smbd_smb2_request_getinfo_done
, req
);
114 return smbd_smb2_request_pending_queue(req
, subreq
);
117 static void smbd_smb2_request_getinfo_done(struct tevent_req
*subreq
)
119 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
120 struct smbd_smb2_request
);
121 int i
= req
->current_idx
;
125 uint16_t out_output_buffer_offset
;
126 DATA_BLOB out_output_buffer
= data_blob_null
;
128 NTSTATUS call_status
= NT_STATUS_OK
;
129 NTSTATUS error
; /* transport error */
131 status
= smbd_smb2_getinfo_recv(subreq
,
136 if (!NT_STATUS_IS_OK(status
)) {
137 error
= smbd_smb2_request_error(req
, status
);
138 if (!NT_STATUS_IS_OK(error
)) {
139 smbd_server_connection_terminate(req
->sconn
,
146 if (!NT_STATUS_IS_OK(call_status
)) {
147 /* Return a specific error with data. */
148 error
= smbd_smb2_request_error_ex(req
,
152 if (!NT_STATUS_IS_OK(error
)) {
153 smbd_server_connection_terminate(req
->sconn
,
160 out_output_buffer_offset
= SMB2_HDR_BODY
+ 0x08;
162 outhdr
= (uint8_t *)req
->out
.vector
[i
].iov_base
;
164 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x08);
165 if (outbody
.data
== NULL
) {
166 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
167 if (!NT_STATUS_IS_OK(error
)) {
168 smbd_server_connection_terminate(req
->sconn
,
175 SSVAL(outbody
.data
, 0x00, 0x08 + 1); /* struct size */
176 SSVAL(outbody
.data
, 0x02,
177 out_output_buffer_offset
); /* output buffer offset */
178 SIVAL(outbody
.data
, 0x04,
179 out_output_buffer
.length
); /* output buffer length */
181 outdyn
= out_output_buffer
;
183 error
= smbd_smb2_request_done(req
, outbody
, &outdyn
);
184 if (!NT_STATUS_IS_OK(error
)) {
185 smbd_server_connection_terminate(req
->sconn
,
191 struct smbd_smb2_getinfo_state
{
192 struct smbd_smb2_request
*smb2req
;
194 DATA_BLOB out_output_buffer
;
197 static void smb2_ipc_getinfo(struct tevent_req
*req
,
198 struct smbd_smb2_getinfo_state
*state
,
199 struct tevent_context
*ev
,
200 uint8_t in_info_type
,
201 uint8_t in_file_info_class
)
203 /* We want to reply to SMB2_GETINFO_FILE
204 with a class of SMB2_FILE_STANDARD_INFO as
205 otherwise a Win7 client issues this request
206 twice (2xroundtrips) if we return NOT_SUPPORTED.
207 NB. We do the same for SMB1 in call_trans2qpipeinfo() */
209 if (in_info_type
== 0x01 && /* SMB2_GETINFO_FILE */
210 in_file_info_class
== 0x05) { /* SMB2_FILE_STANDARD_INFO */
211 state
->out_output_buffer
= data_blob_talloc(state
,
213 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
217 memset(state
->out_output_buffer
.data
,0,24);
218 SOFF_T(state
->out_output_buffer
.data
,0,4096LL);
219 SIVAL(state
->out_output_buffer
.data
,16,1);
220 SIVAL(state
->out_output_buffer
.data
,20,1);
221 tevent_req_done(req
);
223 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
227 static struct tevent_req
*smbd_smb2_getinfo_send(TALLOC_CTX
*mem_ctx
,
228 struct tevent_context
*ev
,
229 struct smbd_smb2_request
*smb2req
,
230 uint8_t in_info_type
,
231 uint8_t in_file_info_class
,
232 uint32_t in_output_buffer_length
,
233 DATA_BLOB in_input_buffer
,
234 uint32_t in_additional_information
,
236 uint64_t in_file_id_volatile
)
238 struct tevent_req
*req
;
239 struct smbd_smb2_getinfo_state
*state
;
240 struct smb_request
*smbreq
;
241 connection_struct
*conn
= smb2req
->tcon
->compat_conn
;
245 req
= tevent_req_create(mem_ctx
, &state
,
246 struct smbd_smb2_getinfo_state
);
250 state
->smb2req
= smb2req
;
251 state
->status
= NT_STATUS_OK
;
252 state
->out_output_buffer
= data_blob_null
;
254 DEBUG(10,("smbd_smb2_getinfo_send: file_id[0x%016llX]\n",
255 (unsigned long long)in_file_id_volatile
));
257 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
258 if (tevent_req_nomem(smbreq
, req
)) {
259 return tevent_req_post(req
, ev
);
262 fsp
= file_fsp(smbreq
, (uint16_t)in_file_id_volatile
);
264 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
265 return tevent_req_post(req
, ev
);
267 if (conn
!= fsp
->conn
) {
268 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
269 return tevent_req_post(req
, ev
);
271 if (smb2req
->session
->vuid
!= fsp
->vuid
) {
272 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
273 return tevent_req_post(req
, ev
);
277 smb2_ipc_getinfo(req
, state
, ev
,
278 in_info_type
, in_file_info_class
);
279 return tevent_req_post(req
, ev
);
282 switch (in_info_type
) {
283 case 0x01:/* SMB2_GETINFO_FILE */
285 uint16_t file_info_level
;
287 unsigned int data_size
= 0;
288 bool delete_pending
= false;
289 struct timespec write_time_ts
;
290 struct file_id fileid
;
291 struct ea_list
*ea_list
= NULL
;
292 int lock_data_count
= 0;
293 char *lock_data
= NULL
;
295 ZERO_STRUCT(write_time_ts
);
297 switch (in_file_info_class
) {
298 case 0x0F:/* RAW_FILEINFO_SMB2_ALL_EAS */
299 file_info_level
= 0xFF00 | in_file_info_class
;
302 case 0x12:/* RAW_FILEINFO_SMB2_ALL_INFORMATION */
303 file_info_level
= 0xFF00 | in_file_info_class
;
307 /* the levels directly map to the passthru levels */
308 file_info_level
= in_file_info_class
+ 1000;
312 if (fsp
->fake_file_handle
) {
314 * This is actually for the QUOTA_FAKE_FILE --metze
317 /* We know this name is ok, it's already passed the checks. */
319 } else if (fsp
&& fsp
->fh
->fd
== -1) {
321 * This is actually a QFILEINFO on a directory
322 * handle (returned from an NT SMB). NT5.0 seems
323 * to do this call. JRA.
326 if (INFO_LEVEL_IS_UNIX(file_info_level
)) {
327 /* Always do lstat for UNIX calls. */
328 if (SMB_VFS_LSTAT(conn
, fsp
->fsp_name
)) {
329 DEBUG(3,("smbd_smb2_getinfo_send: "
330 "SMB_VFS_LSTAT of %s failed "
331 "(%s)\n", fsp_str_dbg(fsp
),
333 status
= map_nt_error_from_unix(errno
);
334 tevent_req_nterror(req
, status
);
335 return tevent_req_post(req
, ev
);
337 } else if (SMB_VFS_STAT(conn
, fsp
->fsp_name
)) {
338 DEBUG(3,("smbd_smb2_getinfo_send: "
339 "SMB_VFS_STAT of %s failed (%s)\n",
342 status
= map_nt_error_from_unix(errno
);
343 tevent_req_nterror(req
, status
);
344 return tevent_req_post(req
, ev
);
347 fileid
= vfs_file_id_from_sbuf(conn
,
349 get_file_infos(fileid
, fsp
->name_hash
,
350 &delete_pending
, &write_time_ts
);
353 * Original code - this is an open file.
356 if (SMB_VFS_FSTAT(fsp
, &fsp
->fsp_name
->st
) != 0) {
357 DEBUG(3, ("smbd_smb2_getinfo_send: "
358 "fstat of fnum %d failed (%s)\n",
359 fsp
->fnum
, strerror(errno
)));
360 status
= map_nt_error_from_unix(errno
);
361 tevent_req_nterror(req
, status
);
362 return tevent_req_post(req
, ev
);
364 fileid
= vfs_file_id_from_sbuf(conn
,
366 get_file_infos(fileid
, fsp
->name_hash
,
367 &delete_pending
, &write_time_ts
);
370 status
= smbd_do_qfilepathinfo(conn
, state
,
380 in_output_buffer_length
,
383 if (!NT_STATUS_IS_OK(status
)) {
385 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_LEVEL
)) {
386 status
= NT_STATUS_INVALID_INFO_CLASS
;
388 tevent_req_nterror(req
, status
);
389 return tevent_req_post(req
, ev
);
392 state
->out_output_buffer
= data_blob_talloc(state
,
396 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
397 return tevent_req_post(req
, ev
);
404 case 0x02:/* SMB2_GETINFO_FS */
406 uint16_t file_info_level
;
410 /* the levels directly map to the passthru levels */
411 file_info_level
= in_file_info_class
+ 1000;
413 status
= smbd_do_qfsinfo(conn
, state
,
416 in_output_buffer_length
,
419 if (!NT_STATUS_IS_OK(status
)) {
421 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_LEVEL
)) {
422 status
= NT_STATUS_INVALID_INFO_CLASS
;
424 tevent_req_nterror(req
, status
);
425 return tevent_req_post(req
, ev
);
428 state
->out_output_buffer
= data_blob_talloc(state
,
432 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
433 return tevent_req_post(req
, ev
);
440 case 0x03:/* SMB2_GETINFO_SEC */
442 uint8_t *p_marshalled_sd
= NULL
;
445 status
= smbd_do_query_security_desc(conn
,
448 /* Security info wanted. */
449 in_additional_information
,
450 in_output_buffer_length
,
454 if (NT_STATUS_EQUAL(status
, NT_STATUS_BUFFER_TOO_SMALL
)) {
455 /* Return needed size. */
456 state
->out_output_buffer
= data_blob_talloc(state
,
459 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
460 return tevent_req_post(req
, ev
);
462 SIVAL(state
->out_output_buffer
.data
,0,(uint32_t)sd_size
);
463 state
->status
= NT_STATUS_BUFFER_TOO_SMALL
;
466 if (!NT_STATUS_IS_OK(status
)) {
467 DEBUG(10,("smbd_smb2_getinfo_send: "
468 "smbd_do_query_security_desc of %s failed "
469 "(%s)\n", fsp_str_dbg(fsp
),
471 tevent_req_nterror(req
, status
);
472 return tevent_req_post(req
, ev
);
476 state
->out_output_buffer
= data_blob_talloc(state
,
479 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
480 return tevent_req_post(req
, ev
);
487 DEBUG(10,("smbd_smb2_getinfo_send: "
488 "unknown in_info_type of %u "
490 (unsigned int)in_info_type
,
493 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
494 return tevent_req_post(req
, ev
);
497 tevent_req_done(req
);
498 return tevent_req_post(req
, ev
);
501 static NTSTATUS
smbd_smb2_getinfo_recv(struct tevent_req
*req
,
503 DATA_BLOB
*out_output_buffer
,
507 struct smbd_smb2_getinfo_state
*state
= tevent_req_data(req
,
508 struct smbd_smb2_getinfo_state
);
510 if (tevent_req_is_nterror(req
, &status
)) {
511 tevent_req_received(req
);
515 *out_output_buffer
= state
->out_output_buffer
;
516 talloc_steal(mem_ctx
, out_output_buffer
->data
);
517 *pstatus
= state
->status
;
519 tevent_req_received(req
);