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
,
32 struct files_struct
*in_fsp
,
34 uint8_t in_file_info_class
,
35 uint32_t in_output_buffer_length
,
36 DATA_BLOB in_input_buffer
,
37 uint32_t in_additional_information
,
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 files_struct
*in_fsp
;
61 struct tevent_req
*subreq
;
63 status
= smbd_smb2_request_verify_sizes(req
, 0x29);
64 if (!NT_STATUS_IS_OK(status
)) {
65 return smbd_smb2_request_error(req
, status
);
67 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
69 in_info_type
= CVAL(inbody
, 0x02);
70 in_file_info_class
= CVAL(inbody
, 0x03);
71 in_output_buffer_length
= IVAL(inbody
, 0x04);
72 in_input_buffer_offset
= SVAL(inbody
, 0x08);
73 /* 0x0A 2 bytes reserved */
74 in_input_buffer_length
= IVAL(inbody
, 0x0C);
75 in_additional_information
= IVAL(inbody
, 0x10);
76 in_flags
= IVAL(inbody
, 0x14);
77 in_file_id_persistent
= BVAL(inbody
, 0x18);
78 in_file_id_volatile
= BVAL(inbody
, 0x20);
80 if (in_input_buffer_offset
== 0 && in_input_buffer_length
== 0) {
82 } else if (in_input_buffer_offset
!=
83 (SMB2_HDR_BODY
+ req
->in
.vector
[i
+1].iov_len
)) {
84 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
87 if (in_input_buffer_length
> req
->in
.vector
[i
+2].iov_len
) {
88 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
91 in_input_buffer
.data
= (uint8_t *)req
->in
.vector
[i
+2].iov_base
;
92 in_input_buffer
.length
= in_input_buffer_length
;
94 if (in_input_buffer
.length
> req
->sconn
->smb2
.max_trans
) {
95 DEBUG(2,("smbd_smb2_request_process_getinfo: "
96 "client ignored max trans: %s: 0x%08X: 0x%08X\n",
97 __location__
, (unsigned)in_input_buffer
.length
,
98 (unsigned)req
->sconn
->smb2
.max_trans
));
99 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
101 if (in_output_buffer_length
> req
->sconn
->smb2
.max_trans
) {
102 DEBUG(2,("smbd_smb2_request_process_getinfo: "
103 "client ignored max trans: %s: 0x%08X: 0x%08X\n",
104 __location__
, in_output_buffer_length
,
105 req
->sconn
->smb2
.max_trans
));
106 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
109 status
= smbd_smb2_request_verify_creditcharge(req
,
110 MAX(in_input_buffer
.length
,in_output_buffer_length
));
111 if (!NT_STATUS_IS_OK(status
)) {
112 return smbd_smb2_request_error(req
, status
);
115 in_fsp
= file_fsp_smb2(req
, in_file_id_persistent
, in_file_id_volatile
);
116 if (in_fsp
== NULL
) {
117 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
120 subreq
= smbd_smb2_getinfo_send(req
, req
->sconn
->ev_ctx
,
124 in_output_buffer_length
,
126 in_additional_information
,
128 if (subreq
== NULL
) {
129 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
131 tevent_req_set_callback(subreq
, smbd_smb2_request_getinfo_done
, req
);
133 return smbd_smb2_request_pending_queue(req
, subreq
, 500);
136 static void smbd_smb2_request_getinfo_done(struct tevent_req
*subreq
)
138 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
139 struct smbd_smb2_request
);
142 uint16_t out_output_buffer_offset
;
143 DATA_BLOB out_output_buffer
= data_blob_null
;
145 NTSTATUS call_status
= NT_STATUS_OK
;
146 NTSTATUS error
; /* transport error */
148 status
= smbd_smb2_getinfo_recv(subreq
,
153 if (!NT_STATUS_IS_OK(status
)) {
154 error
= smbd_smb2_request_error(req
, status
);
155 if (!NT_STATUS_IS_OK(error
)) {
156 smbd_server_connection_terminate(req
->sconn
,
163 if (!NT_STATUS_IS_OK(call_status
)) {
164 /* Return a specific error with data. */
165 error
= smbd_smb2_request_error_ex(req
,
169 if (!NT_STATUS_IS_OK(error
)) {
170 smbd_server_connection_terminate(req
->sconn
,
177 out_output_buffer_offset
= SMB2_HDR_BODY
+ 0x08;
179 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x08);
180 if (outbody
.data
== NULL
) {
181 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
182 if (!NT_STATUS_IS_OK(error
)) {
183 smbd_server_connection_terminate(req
->sconn
,
190 SSVAL(outbody
.data
, 0x00, 0x08 + 1); /* struct size */
191 SSVAL(outbody
.data
, 0x02,
192 out_output_buffer_offset
); /* output buffer offset */
193 SIVAL(outbody
.data
, 0x04,
194 out_output_buffer
.length
); /* output buffer length */
196 outdyn
= out_output_buffer
;
198 error
= smbd_smb2_request_done(req
, outbody
, &outdyn
);
199 if (!NT_STATUS_IS_OK(error
)) {
200 smbd_server_connection_terminate(req
->sconn
,
206 struct smbd_smb2_getinfo_state
{
207 struct smbd_smb2_request
*smb2req
;
209 DATA_BLOB out_output_buffer
;
212 static void smb2_ipc_getinfo(struct tevent_req
*req
,
213 struct smbd_smb2_getinfo_state
*state
,
214 struct tevent_context
*ev
,
215 uint8_t in_info_type
,
216 uint8_t in_file_info_class
)
218 /* We want to reply to SMB2_GETINFO_FILE
219 with a class of SMB2_FILE_STANDARD_INFO as
220 otherwise a Win7 client issues this request
221 twice (2xroundtrips) if we return NOT_SUPPORTED.
222 NB. We do the same for SMB1 in call_trans2qpipeinfo() */
224 if (in_info_type
== 0x01 && /* SMB2_GETINFO_FILE */
225 in_file_info_class
== 0x05) { /* SMB2_FILE_STANDARD_INFO */
226 state
->out_output_buffer
= data_blob_talloc(state
,
228 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
232 memset(state
->out_output_buffer
.data
,0,24);
233 SOFF_T(state
->out_output_buffer
.data
,0,4096LL);
234 SIVAL(state
->out_output_buffer
.data
,16,1);
235 SIVAL(state
->out_output_buffer
.data
,20,1);
236 tevent_req_done(req
);
238 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
242 static struct tevent_req
*smbd_smb2_getinfo_send(TALLOC_CTX
*mem_ctx
,
243 struct tevent_context
*ev
,
244 struct smbd_smb2_request
*smb2req
,
245 struct files_struct
*fsp
,
246 uint8_t in_info_type
,
247 uint8_t in_file_info_class
,
248 uint32_t in_output_buffer_length
,
249 DATA_BLOB in_input_buffer
,
250 uint32_t in_additional_information
,
253 struct tevent_req
*req
;
254 struct smbd_smb2_getinfo_state
*state
;
255 struct smb_request
*smbreq
;
256 connection_struct
*conn
= smb2req
->tcon
->compat
;
259 req
= tevent_req_create(mem_ctx
, &state
,
260 struct smbd_smb2_getinfo_state
);
264 state
->smb2req
= smb2req
;
265 state
->status
= NT_STATUS_OK
;
266 state
->out_output_buffer
= data_blob_null
;
268 DEBUG(10,("smbd_smb2_getinfo_send: %s - %s\n",
269 fsp_str_dbg(fsp
), fsp_fnum_dbg(fsp
)));
271 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
272 if (tevent_req_nomem(smbreq
, req
)) {
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
->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 %s failed (%s)\n",
359 fsp_fnum_dbg(fsp
), 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
);