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"
30 #define DBGC_CLASS DBGC_SMB2
32 static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
33 struct tevent_context *ev,
34 struct smbd_smb2_request *smb2req,
35 struct files_struct *in_fsp,
37 uint8_t in_file_info_class,
38 uint32_t in_output_buffer_length,
39 DATA_BLOB in_input_buffer,
40 uint32_t in_additional_information,
42 static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
44 DATA_BLOB *out_output_buffer,
45 NTSTATUS *p_call_status);
47 static void smbd_smb2_request_getinfo_done(struct tevent_req *subreq);
48 NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req)
50 struct smbXsrv_connection *xconn = req->xconn;
52 const uint8_t *inbody;
54 uint8_t in_file_info_class;
55 uint32_t in_output_buffer_length;
56 uint16_t in_input_buffer_offset;
57 uint32_t in_input_buffer_length;
58 DATA_BLOB in_input_buffer;
59 uint32_t in_additional_information;
61 uint64_t in_file_id_persistent;
62 uint64_t in_file_id_volatile;
63 struct files_struct *in_fsp;
64 struct tevent_req *subreq;
66 status = smbd_smb2_request_verify_sizes(req, 0x29);
67 if (!NT_STATUS_IS_OK(status)) {
68 return smbd_smb2_request_error(req, status);
70 inbody = SMBD_SMB2_IN_BODY_PTR(req);
72 in_info_type = CVAL(inbody, 0x02);
73 in_file_info_class = CVAL(inbody, 0x03);
74 in_output_buffer_length = IVAL(inbody, 0x04);
75 in_input_buffer_offset = SVAL(inbody, 0x08);
76 /* 0x0A 2 bytes reserved */
77 in_input_buffer_length = IVAL(inbody, 0x0C);
78 in_additional_information = IVAL(inbody, 0x10);
79 in_flags = IVAL(inbody, 0x14);
80 in_file_id_persistent = BVAL(inbody, 0x18);
81 in_file_id_volatile = BVAL(inbody, 0x20);
83 if (in_input_buffer_offset == 0 && in_input_buffer_length == 0) {
85 } else if (in_input_buffer_offset !=
86 (SMB2_HDR_BODY + SMBD_SMB2_IN_BODY_LEN(req))) {
87 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
90 if (in_input_buffer_length > SMBD_SMB2_IN_DYN_LEN(req)) {
91 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
94 in_input_buffer.data = SMBD_SMB2_IN_DYN_PTR(req);
95 in_input_buffer.length = in_input_buffer_length;
97 if (in_input_buffer.length > xconn->smb2.server.max_trans) {
98 DEBUG(2,("smbd_smb2_request_process_getinfo: "
99 "client ignored max trans: %s: 0x%08X: 0x%08X\n",
100 __location__, (unsigned)in_input_buffer.length,
101 (unsigned)xconn->smb2.server.max_trans));
102 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
104 if (in_output_buffer_length > xconn->smb2.server.max_trans) {
105 DEBUG(2,("smbd_smb2_request_process_getinfo: "
106 "client ignored max trans: %s: 0x%08X: 0x%08X\n",
107 __location__, in_output_buffer_length,
108 xconn->smb2.server.max_trans));
109 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
112 status = smbd_smb2_request_verify_creditcharge(req,
113 MAX(in_input_buffer.length,in_output_buffer_length));
114 if (!NT_STATUS_IS_OK(status)) {
115 return smbd_smb2_request_error(req, status);
118 in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
119 if (in_fsp == NULL) {
120 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
123 subreq = smbd_smb2_getinfo_send(req, req->sconn->ev_ctx,
127 in_output_buffer_length,
129 in_additional_information,
131 if (subreq == NULL) {
132 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
134 tevent_req_set_callback(subreq, smbd_smb2_request_getinfo_done, req);
136 return smbd_smb2_request_pending_queue(req, subreq, 500);
139 static void smbd_smb2_request_getinfo_done(struct tevent_req *subreq)
141 struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
142 struct smbd_smb2_request);
145 uint16_t out_output_buffer_offset;
146 DATA_BLOB out_output_buffer = data_blob_null;
148 NTSTATUS call_status = NT_STATUS_OK;
149 NTSTATUS error; /* transport error */
151 status = smbd_smb2_getinfo_recv(subreq,
156 if (!NT_STATUS_IS_OK(status)) {
157 error = smbd_smb2_request_error(req, status);
158 if (!NT_STATUS_IS_OK(error)) {
159 smbd_server_connection_terminate(req->xconn,
166 /* some GetInfo responses set STATUS_BUFFER_OVERFLOW and return partial,
168 if (!(NT_STATUS_IS_OK(call_status) ||
169 NT_STATUS_EQUAL(call_status, STATUS_BUFFER_OVERFLOW))) {
170 /* Return a specific error with data. */
171 error = smbd_smb2_request_error_ex(req,
175 if (!NT_STATUS_IS_OK(error)) {
176 smbd_server_connection_terminate(req->xconn,
183 out_output_buffer_offset = SMB2_HDR_BODY + 0x08;
185 outbody = smbd_smb2_generate_outbody(req, 0x08);
186 if (outbody.data == NULL) {
187 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
188 if (!NT_STATUS_IS_OK(error)) {
189 smbd_server_connection_terminate(req->xconn,
196 SSVAL(outbody.data, 0x00, 0x08 + 1); /* struct size */
197 SSVAL(outbody.data, 0x02,
198 out_output_buffer_offset); /* output buffer offset */
199 SIVAL(outbody.data, 0x04,
200 out_output_buffer.length); /* output buffer length */
202 outdyn = out_output_buffer;
204 error = smbd_smb2_request_done_ex(req, call_status, outbody, &outdyn, __location__);
205 if (!NT_STATUS_IS_OK(error)) {
206 smbd_server_connection_terminate(req->xconn,
212 struct smbd_smb2_getinfo_state {
213 struct smbd_smb2_request *smb2req;
215 DATA_BLOB out_output_buffer;
218 static void smb2_ipc_getinfo(struct tevent_req *req,
219 struct smbd_smb2_getinfo_state *state,
220 struct tevent_context *ev,
221 uint8_t in_info_type,
222 uint8_t in_file_info_class)
224 /* We want to reply to SMB2_GETINFO_FILE
225 with a class of SMB2_FILE_STANDARD_INFO as
226 otherwise a Win7 client issues this request
227 twice (2xroundtrips) if we return NOT_SUPPORTED.
228 NB. We do the same for SMB1 in call_trans2qpipeinfo() */
230 if (in_info_type == 0x01 && /* SMB2_GETINFO_FILE */
231 in_file_info_class == 0x05) { /* SMB2_FILE_STANDARD_INFO */
232 state->out_output_buffer = data_blob_talloc(state,
234 if (tevent_req_nomem(state->out_output_buffer.data, req)) {
238 memset(state->out_output_buffer.data,0,24);
239 SOFF_T(state->out_output_buffer.data,0,4096LL);
240 SIVAL(state->out_output_buffer.data,16,1);
241 SIVAL(state->out_output_buffer.data,20,1);
242 tevent_req_done(req);
244 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
248 static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
249 struct tevent_context *ev,
250 struct smbd_smb2_request *smb2req,
251 struct files_struct *fsp,
252 uint8_t in_info_type,
253 uint8_t in_file_info_class,
254 uint32_t in_output_buffer_length,
255 DATA_BLOB in_input_buffer,
256 uint32_t in_additional_information,
259 struct tevent_req *req;
260 struct smbd_smb2_getinfo_state *state;
261 struct smb_request *smbreq;
262 connection_struct *conn = smb2req->tcon->compat;
265 req = tevent_req_create(mem_ctx, &state,
266 struct smbd_smb2_getinfo_state);
270 state->smb2req = smb2req;
271 state->status = NT_STATUS_OK;
272 state->out_output_buffer = data_blob_null;
274 DEBUG(10,("smbd_smb2_getinfo_send: %s - %s\n",
275 fsp_str_dbg(fsp), fsp_fnum_dbg(fsp)));
277 smbreq = smbd_smb2_fake_smb_request(smb2req);
278 if (tevent_req_nomem(smbreq, req)) {
279 return tevent_req_post(req, ev);
283 smb2_ipc_getinfo(req, state, ev,
284 in_info_type, in_file_info_class);
285 return tevent_req_post(req, ev);
288 switch (in_info_type) {
289 case SMB2_GETINFO_FILE:
291 uint16_t file_info_level;
293 unsigned int data_size = 0;
294 bool delete_pending = false;
295 struct timespec write_time_ts;
296 struct file_id fileid;
297 struct ea_list *ea_list = NULL;
298 int lock_data_count = 0;
299 char *lock_data = NULL;
300 size_t fixed_portion;
302 ZERO_STRUCT(write_time_ts);
304 switch (in_file_info_class) {
305 case 0x0F:/* RAW_FILEINFO_SMB2_ALL_EAS */
306 file_info_level = 0xFF00 | in_file_info_class;
309 case 0x12:/* RAW_FILEINFO_SMB2_ALL_INFORMATION */
310 file_info_level = 0xFF00 | in_file_info_class;
314 /* the levels directly map to the passthru levels */
315 file_info_level = in_file_info_class + 1000;
319 if (fsp->fake_file_handle) {
321 * This is actually for the QUOTA_FAKE_FILE --metze
324 /* We know this name is ok, it's already passed the checks. */
326 } else if (fsp->fh->fd == -1) {
328 * This is actually a QFILEINFO on a directory
329 * handle (returned from an NT SMB). NT5.0 seems
330 * to do this call. JRA.
333 if (INFO_LEVEL_IS_UNIX(file_info_level)) {
334 /* Always do lstat for UNIX calls. */
335 if (SMB_VFS_LSTAT(conn, fsp->fsp_name)) {
336 DEBUG(3,("smbd_smb2_getinfo_send: "
337 "SMB_VFS_LSTAT of %s failed "
338 "(%s)\n", fsp_str_dbg(fsp),
340 status = map_nt_error_from_unix(errno);
341 tevent_req_nterror(req, status);
342 return tevent_req_post(req, ev);
344 } else if (SMB_VFS_STAT(conn, fsp->fsp_name)) {
345 DEBUG(3,("smbd_smb2_getinfo_send: "
346 "SMB_VFS_STAT of %s failed (%s)\n",
349 status = map_nt_error_from_unix(errno);
350 tevent_req_nterror(req, status);
351 return tevent_req_post(req, ev);
354 fileid = vfs_file_id_from_sbuf(conn,
356 get_file_infos(fileid, fsp->name_hash,
357 &delete_pending, &write_time_ts);
360 * Original code - this is an open file.
363 if (SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) != 0) {
364 DEBUG(3, ("smbd_smb2_getinfo_send: "
365 "fstat of %s failed (%s)\n",
366 fsp_fnum_dbg(fsp), strerror(errno)));
367 status = map_nt_error_from_unix(errno);
368 tevent_req_nterror(req, status);
369 return tevent_req_post(req, ev);
371 fileid = vfs_file_id_from_sbuf(conn,
373 get_file_infos(fileid, fsp->name_hash,
374 &delete_pending, &write_time_ts);
377 status = smbd_do_qfilepathinfo(conn, state,
387 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);
399 if (in_output_buffer_length < fixed_portion) {
402 req, NT_STATUS_INFO_LENGTH_MISMATCH);
403 return tevent_req_post(req, ev);
406 state->out_output_buffer = data_blob_talloc(state,
410 if (tevent_req_nomem(state->out_output_buffer.data, req)) {
411 return tevent_req_post(req, ev);
413 if (data_size > in_output_buffer_length) {
414 state->out_output_buffer.length =
415 in_output_buffer_length;
416 status = STATUS_BUFFER_OVERFLOW;
423 case SMB2_GETINFO_FS:
425 uint16_t file_info_level;
428 size_t fixed_portion;
430 /* the levels directly map to the passthru levels */
431 file_info_level = in_file_info_class + 1000;
433 status = smbd_do_qfsinfo(smb2req->xconn, conn, state,
436 in_output_buffer_length,
441 /* some responses set STATUS_BUFFER_OVERFLOW and return
442 partial, but valid data */
443 if (!(NT_STATUS_IS_OK(status) ||
444 NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW))) {
446 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
447 status = NT_STATUS_INVALID_INFO_CLASS;
449 tevent_req_nterror(req, status);
450 return tevent_req_post(req, ev);
452 if (in_output_buffer_length < fixed_portion) {
455 req, NT_STATUS_INFO_LENGTH_MISMATCH);
456 return tevent_req_post(req, ev);
459 state->out_output_buffer = data_blob_talloc(state,
463 if (tevent_req_nomem(state->out_output_buffer.data, req)) {
464 return tevent_req_post(req, ev);
466 if (data_size > in_output_buffer_length) {
467 state->out_output_buffer.length =
468 in_output_buffer_length;
469 status = STATUS_BUFFER_OVERFLOW;
476 case SMB2_GETINFO_SECURITY:
478 uint8_t *p_marshalled_sd = NULL;
481 status = smbd_do_query_security_desc(conn,
484 /* Security info wanted. */
485 in_additional_information &
486 SMB_SUPPORTED_SECINFO_FLAGS,
487 in_output_buffer_length,
491 if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
492 /* Return needed size. */
493 state->out_output_buffer = data_blob_talloc(state,
496 if (tevent_req_nomem(state->out_output_buffer.data, req)) {
497 return tevent_req_post(req, ev);
499 SIVAL(state->out_output_buffer.data,0,(uint32_t)sd_size);
500 state->status = NT_STATUS_BUFFER_TOO_SMALL;
503 if (!NT_STATUS_IS_OK(status)) {
504 DEBUG(10,("smbd_smb2_getinfo_send: "
505 "smbd_do_query_security_desc of %s failed "
506 "(%s)\n", fsp_str_dbg(fsp),
508 tevent_req_nterror(req, status);
509 return tevent_req_post(req, ev);
513 state->out_output_buffer = data_blob_talloc(state,
516 if (tevent_req_nomem(state->out_output_buffer.data, req)) {
517 return tevent_req_post(req, ev);
523 case SMB2_GETINFO_QUOTA:
524 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
525 return tevent_req_post(req, ev);
528 DEBUG(10,("smbd_smb2_getinfo_send: "
529 "unknown in_info_type of %u "
531 (unsigned int)in_info_type,
534 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
535 return tevent_req_post(req, ev);
538 state->status = status;
539 tevent_req_done(req);
540 return tevent_req_post(req, ev);
543 static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
545 DATA_BLOB *out_output_buffer,
549 struct smbd_smb2_getinfo_state *state = tevent_req_data(req,
550 struct smbd_smb2_getinfo_state);
552 if (tevent_req_is_nterror(req, &status)) {
553 tevent_req_received(req);
557 *out_output_buffer = state->out_output_buffer;
558 talloc_steal(mem_ctx, out_output_buffer->data);
559 *pstatus = state->status;
561 tevent_req_received(req);