Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Core SMB2 server
4 :
5 : Copyright (C) Stefan Metzmacher 2009
6 : Copyright (C) Jeremy Allison 2010
7 :
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.
12 :
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.
17 :
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/>.
20 : */
21 :
22 : #include "includes.h"
23 : #include "smbd/smbd.h"
24 : #include "smbd/globals.h"
25 : #include "../libcli/smb/smb_common.h"
26 : #include "trans2.h"
27 : #include "../lib/util/tevent_ntstatus.h"
28 : #include "librpc/gen_ndr/ndr_quota.h"
29 : #include "librpc/gen_ndr/ndr_security.h"
30 :
31 : #undef DBGC_CLASS
32 : #define DBGC_CLASS DBGC_SMB2
33 :
34 : static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
35 : struct tevent_context *ev,
36 : struct smbd_smb2_request *smb2req,
37 : struct files_struct *in_fsp,
38 : uint8_t in_info_type,
39 : uint8_t in_file_info_class,
40 : uint32_t in_output_buffer_length,
41 : DATA_BLOB in_input_buffer,
42 : uint32_t in_additional_information,
43 : uint32_t in_flags);
44 : static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
45 : TALLOC_CTX *mem_ctx,
46 : DATA_BLOB *out_output_buffer,
47 : NTSTATUS *p_call_status);
48 :
49 : static void smbd_smb2_request_getinfo_done(struct tevent_req *subreq);
50 1620 : NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req)
51 : {
52 1620 : struct smbXsrv_connection *xconn = req->xconn;
53 : NTSTATUS status;
54 : const uint8_t *inbody;
55 : uint8_t in_info_type;
56 : uint8_t in_file_info_class;
57 : uint32_t in_output_buffer_length;
58 : uint16_t in_input_buffer_offset;
59 : uint32_t in_input_buffer_length;
60 : DATA_BLOB in_input_buffer;
61 : uint32_t in_additional_information;
62 : uint32_t in_flags;
63 : uint64_t in_file_id_persistent;
64 : uint64_t in_file_id_volatile;
65 : struct files_struct *in_fsp;
66 : struct tevent_req *subreq;
67 :
68 1620 : status = smbd_smb2_request_verify_sizes(req, 0x29);
69 1620 : if (!NT_STATUS_IS_OK(status)) {
70 0 : return smbd_smb2_request_error(req, status);
71 : }
72 1620 : inbody = SMBD_SMB2_IN_BODY_PTR(req);
73 :
74 1620 : in_info_type = CVAL(inbody, 0x02);
75 1620 : in_file_info_class = CVAL(inbody, 0x03);
76 1620 : in_output_buffer_length = IVAL(inbody, 0x04);
77 1620 : in_input_buffer_offset = SVAL(inbody, 0x08);
78 : /* 0x0A 2 bytes reserved */
79 1620 : in_input_buffer_length = IVAL(inbody, 0x0C);
80 1620 : in_additional_information = IVAL(inbody, 0x10);
81 1620 : in_flags = IVAL(inbody, 0x14);
82 1620 : in_file_id_persistent = BVAL(inbody, 0x18);
83 1620 : in_file_id_volatile = BVAL(inbody, 0x20);
84 :
85 1620 : if (in_input_buffer_offset == 0 && in_input_buffer_length == 0) {
86 : /* This is ok */
87 0 : } else if (in_input_buffer_offset !=
88 0 : (SMB2_HDR_BODY + SMBD_SMB2_IN_BODY_LEN(req))) {
89 0 : return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
90 : }
91 :
92 1620 : if (in_input_buffer_length > SMBD_SMB2_IN_DYN_LEN(req)) {
93 0 : return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
94 : }
95 :
96 1620 : in_input_buffer.data = SMBD_SMB2_IN_DYN_PTR(req);
97 1620 : in_input_buffer.length = in_input_buffer_length;
98 :
99 1620 : if (in_input_buffer.length > xconn->smb2.server.max_trans) {
100 0 : DEBUG(2,("smbd_smb2_request_process_getinfo: "
101 : "client ignored max trans: %s: 0x%08X: 0x%08X\n",
102 : __location__, (unsigned)in_input_buffer.length,
103 : (unsigned)xconn->smb2.server.max_trans));
104 0 : return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
105 : }
106 1620 : if (in_output_buffer_length > xconn->smb2.server.max_trans) {
107 0 : DEBUG(2,("smbd_smb2_request_process_getinfo: "
108 : "client ignored max trans: %s: 0x%08X: 0x%08X\n",
109 : __location__, in_output_buffer_length,
110 : xconn->smb2.server.max_trans));
111 0 : return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
112 : }
113 :
114 1620 : status = smbd_smb2_request_verify_creditcharge(req,
115 1620 : MAX(in_input_buffer.length,in_output_buffer_length));
116 1620 : if (!NT_STATUS_IS_OK(status)) {
117 0 : return smbd_smb2_request_error(req, status);
118 : }
119 :
120 1620 : in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
121 1620 : if (in_fsp == NULL) {
122 0 : return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
123 : }
124 :
125 1620 : subreq = smbd_smb2_getinfo_send(req, req->sconn->ev_ctx,
126 : req, in_fsp,
127 : in_info_type,
128 : in_file_info_class,
129 : in_output_buffer_length,
130 : in_input_buffer,
131 : in_additional_information,
132 : in_flags);
133 1620 : if (subreq == NULL) {
134 0 : return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
135 : }
136 1620 : tevent_req_set_callback(subreq, smbd_smb2_request_getinfo_done, req);
137 :
138 1620 : return smbd_smb2_request_pending_queue(req, subreq, 500);
139 : }
140 :
141 1620 : static void smbd_smb2_request_getinfo_done(struct tevent_req *subreq)
142 : {
143 1620 : struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
144 : struct smbd_smb2_request);
145 : DATA_BLOB outbody;
146 : DATA_BLOB outdyn;
147 : uint16_t out_output_buffer_offset;
148 1620 : DATA_BLOB out_output_buffer = data_blob_null;
149 : NTSTATUS status;
150 1620 : NTSTATUS call_status = NT_STATUS_OK;
151 : NTSTATUS error; /* transport error */
152 :
153 1620 : status = smbd_smb2_getinfo_recv(subreq,
154 : req,
155 : &out_output_buffer,
156 : &call_status);
157 1620 : TALLOC_FREE(subreq);
158 1620 : if (!NT_STATUS_IS_OK(status)) {
159 8 : error = smbd_smb2_request_error(req, status);
160 8 : if (!NT_STATUS_IS_OK(error)) {
161 0 : smbd_server_connection_terminate(req->xconn,
162 : nt_errstr(error));
163 4 : return;
164 : }
165 8 : return;
166 : }
167 :
168 : /* some GetInfo responses set STATUS_BUFFER_OVERFLOW and return partial,
169 : but valid data */
170 1612 : if (!(NT_STATUS_IS_OK(call_status) ||
171 0 : NT_STATUS_EQUAL(call_status, STATUS_BUFFER_OVERFLOW))) {
172 : /* Return a specific error with data. */
173 0 : error = smbd_smb2_request_error_ex(req,
174 : call_status,
175 : &out_output_buffer,
176 : __location__);
177 0 : if (!NT_STATUS_IS_OK(error)) {
178 0 : smbd_server_connection_terminate(req->xconn,
179 : nt_errstr(error));
180 0 : return;
181 : }
182 0 : return;
183 : }
184 :
185 1612 : out_output_buffer_offset = SMB2_HDR_BODY + 0x08;
186 :
187 1612 : outbody = smbd_smb2_generate_outbody(req, 0x08);
188 1612 : if (outbody.data == NULL) {
189 0 : error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
190 0 : if (!NT_STATUS_IS_OK(error)) {
191 0 : smbd_server_connection_terminate(req->xconn,
192 : nt_errstr(error));
193 0 : return;
194 : }
195 0 : return;
196 : }
197 :
198 1612 : SSVAL(outbody.data, 0x00, 0x08 + 1); /* struct size */
199 1612 : SSVAL(outbody.data, 0x02,
200 : out_output_buffer_offset); /* output buffer offset */
201 1612 : SIVAL(outbody.data, 0x04,
202 : out_output_buffer.length); /* output buffer length */
203 :
204 1612 : outdyn = out_output_buffer;
205 :
206 1612 : error = smbd_smb2_request_done_ex(req, call_status, outbody, &outdyn, __location__);
207 1612 : if (!NT_STATUS_IS_OK(error)) {
208 0 : smbd_server_connection_terminate(req->xconn,
209 : nt_errstr(error));
210 0 : return;
211 : }
212 : }
213 :
214 : struct smbd_smb2_getinfo_state {
215 : struct smbd_smb2_request *smb2req;
216 : NTSTATUS status;
217 : DATA_BLOB out_output_buffer;
218 : };
219 :
220 0 : static void smb2_ipc_getinfo(struct tevent_req *req,
221 : struct smbd_smb2_getinfo_state *state,
222 : struct tevent_context *ev,
223 : uint8_t in_info_type,
224 : uint8_t in_file_info_class)
225 : {
226 : /* We want to reply to SMB2_GETINFO_FILE
227 : with a class of SMB2_FILE_STANDARD_INFO as
228 : otherwise a Win7 client issues this request
229 : twice (2xroundtrips) if we return NOT_SUPPORTED.
230 : NB. We do the same for SMB1 in call_trans2qpipeinfo() */
231 :
232 0 : if (in_info_type == 0x01 && /* SMB2_GETINFO_FILE */
233 : in_file_info_class == 0x05) { /* SMB2_FILE_STANDARD_INFO */
234 0 : state->out_output_buffer = data_blob_talloc(state,
235 : NULL, 24);
236 0 : if (tevent_req_nomem(state->out_output_buffer.data, req)) {
237 0 : return;
238 : }
239 :
240 0 : memset(state->out_output_buffer.data,0,24);
241 0 : SOFF_T(state->out_output_buffer.data,0,4096LL);
242 0 : SIVAL(state->out_output_buffer.data,16,1);
243 0 : SIVAL(state->out_output_buffer.data,20,1);
244 0 : tevent_req_done(req);
245 : } else {
246 0 : tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
247 : }
248 : }
249 :
250 1620 : static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
251 : struct tevent_context *ev,
252 : struct smbd_smb2_request *smb2req,
253 : struct files_struct *fsp,
254 : uint8_t in_info_type,
255 : uint8_t in_file_info_class,
256 : uint32_t in_output_buffer_length,
257 : DATA_BLOB in_input_buffer,
258 : uint32_t in_additional_information,
259 : uint32_t in_flags)
260 : {
261 : struct tevent_req *req;
262 : struct smbd_smb2_getinfo_state *state;
263 : struct smb_request *smbreq;
264 1620 : connection_struct *conn = smb2req->tcon->compat;
265 : NTSTATUS status;
266 :
267 1620 : req = tevent_req_create(mem_ctx, &state,
268 : struct smbd_smb2_getinfo_state);
269 1620 : if (req == NULL) {
270 0 : return NULL;
271 : }
272 1620 : state->smb2req = smb2req;
273 1620 : state->status = NT_STATUS_OK;
274 1620 : state->out_output_buffer = data_blob_null;
275 :
276 1620 : DEBUG(10,("smbd_smb2_getinfo_send: %s - %s\n",
277 : fsp_str_dbg(fsp), fsp_fnum_dbg(fsp)));
278 :
279 1620 : smbreq = smbd_smb2_fake_smb_request(smb2req);
280 1620 : if (tevent_req_nomem(smbreq, req)) {
281 0 : return tevent_req_post(req, ev);
282 : }
283 :
284 1620 : if (IS_IPC(conn)) {
285 0 : smb2_ipc_getinfo(req, state, ev,
286 : in_info_type, in_file_info_class);
287 0 : return tevent_req_post(req, ev);
288 : }
289 :
290 1620 : switch (in_info_type) {
291 910 : case SMB2_0_INFO_FILE:
292 : {
293 : uint16_t file_info_level;
294 910 : char *data = NULL;
295 910 : unsigned int data_size = 0;
296 910 : bool delete_pending = false;
297 : struct timespec write_time_ts;
298 : struct file_id fileid;
299 910 : struct ea_list *ea_list = NULL;
300 910 : int lock_data_count = 0;
301 910 : char *lock_data = NULL;
302 : size_t fixed_portion;
303 :
304 910 : ZERO_STRUCT(write_time_ts);
305 :
306 : /*
307 : * MS-SMB2 3.3.5.20.1 "Handling SMB2_0_INFO_FILE"
308 : *
309 : * FileBasicInformation, FileAllInformation,
310 : * FileNetworkOpenInformation, FileAttributeTagInformation
311 : * require FILE_READ_ATTRIBUTES.
312 : *
313 : * FileFullEaInformation requires FILE_READ_EA.
314 : */
315 910 : switch (in_file_info_class) {
316 498 : case FSCC_FILE_BASIC_INFORMATION:
317 : case FSCC_FILE_ALL_INFORMATION:
318 : case FSCC_FILE_NETWORK_OPEN_INFORMATION:
319 : case FSCC_FILE_ATTRIBUTE_TAG_INFORMATION:
320 498 : if (!(fsp->access_mask & SEC_FILE_READ_ATTRIBUTE)) {
321 0 : tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
322 4 : return tevent_req_post(req, ev);
323 : }
324 498 : break;
325 :
326 0 : case FSCC_FILE_FULL_EA_INFORMATION:
327 0 : if (!(fsp->access_mask & SEC_FILE_READ_EA)) {
328 0 : tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
329 0 : return tevent_req_post(req, ev);
330 : }
331 0 : break;
332 : }
333 :
334 910 : switch (in_file_info_class) {
335 0 : case FSCC_FILE_FULL_EA_INFORMATION:
336 0 : file_info_level = SMB2_FILE_FULL_EA_INFORMATION;
337 0 : break;
338 :
339 498 : case FSCC_FILE_ALL_INFORMATION:
340 498 : file_info_level = SMB2_FILE_ALL_INFORMATION;
341 498 : break;
342 :
343 412 : default:
344 : /* the levels directly map to the passthru levels */
345 412 : file_info_level = in_file_info_class + 1000;
346 412 : break;
347 : }
348 :
349 910 : switch (file_info_level) {
350 0 : case SMB_FILE_NORMALIZED_NAME_INFORMATION:
351 0 : if (smb2req->xconn->protocol < PROTOCOL_SMB3_11) {
352 0 : tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
353 0 : return tevent_req_post(req, ev);
354 : }
355 0 : break;
356 : }
357 :
358 910 : if (fsp->fake_file_handle) {
359 : /*
360 : * This is actually for the QUOTA_FAKE_FILE --metze
361 : */
362 :
363 : /* We know this name is ok, it's already passed the checks. */
364 :
365 910 : } else if (fsp_get_pathref_fd(fsp) == -1) {
366 : /*
367 : * This is actually a QFILEINFO on a directory
368 : * handle (returned from an NT SMB). NT5.0 seems
369 : * to do this call. JRA.
370 : */
371 0 : int ret = vfs_stat(conn, fsp->fsp_name);
372 0 : if (ret != 0) {
373 0 : DBG_NOTICE("vfs_stat of %s failed (%s)\n",
374 : fsp_str_dbg(fsp),
375 : strerror(errno));
376 0 : status = map_nt_error_from_unix(errno);
377 0 : tevent_req_nterror(req, status);
378 0 : return tevent_req_post(req, ev);
379 : }
380 :
381 0 : if (lp_smbd_getinfo_ask_sharemode(SNUM(conn))) {
382 0 : fileid = vfs_file_id_from_sbuf(
383 0 : conn, &fsp->fsp_name->st);
384 0 : get_file_infos(fileid, fsp->name_hash,
385 : &delete_pending,
386 : &write_time_ts);
387 : }
388 : } else {
389 : /*
390 : * Original code - this is an open file.
391 : */
392 :
393 910 : status = vfs_stat_fsp(fsp);
394 910 : if (!NT_STATUS_IS_OK(status)) {
395 0 : DEBUG(3, ("smbd_smb2_getinfo_send: "
396 : "fstat of %s failed (%s)\n",
397 : fsp_fnum_dbg(fsp), nt_errstr(status)));
398 0 : tevent_req_nterror(req, status);
399 0 : return tevent_req_post(req, ev);
400 : }
401 910 : if (lp_smbd_getinfo_ask_sharemode(SNUM(conn))) {
402 910 : fileid = vfs_file_id_from_sbuf(
403 910 : conn, &fsp->fsp_name->st);
404 910 : get_file_infos(fileid, fsp->name_hash,
405 : &delete_pending,
406 : &write_time_ts);
407 : }
408 : }
409 :
410 910 : status = smbd_do_qfilepathinfo(conn, state,
411 : smbreq,
412 : file_info_level,
413 : fsp,
414 : fsp->fsp_name,
415 : delete_pending,
416 : write_time_ts,
417 : ea_list,
418 : lock_data_count,
419 : lock_data,
420 : STR_UNICODE,
421 : in_output_buffer_length,
422 : &fixed_portion,
423 : &data,
424 : &data_size);
425 910 : if (!NT_STATUS_IS_OK(status)) {
426 8 : SAFE_FREE(data);
427 8 : if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
428 0 : status = NT_STATUS_INVALID_INFO_CLASS;
429 : }
430 8 : tevent_req_nterror(req, status);
431 8 : return tevent_req_post(req, ev);
432 : }
433 902 : if (in_output_buffer_length < fixed_portion) {
434 0 : SAFE_FREE(data);
435 0 : tevent_req_nterror(
436 : req, NT_STATUS_INFO_LENGTH_MISMATCH);
437 0 : return tevent_req_post(req, ev);
438 : }
439 902 : if (data_size > 0) {
440 894 : state->out_output_buffer = data_blob_talloc(state,
441 : data,
442 : data_size);
443 894 : SAFE_FREE(data);
444 894 : if (tevent_req_nomem(state->out_output_buffer.data, req)) {
445 0 : return tevent_req_post(req, ev);
446 : }
447 894 : if (data_size > in_output_buffer_length) {
448 0 : state->out_output_buffer.length =
449 : in_output_buffer_length;
450 0 : status = STATUS_BUFFER_OVERFLOW;
451 : }
452 : }
453 902 : SAFE_FREE(data);
454 902 : break;
455 : }
456 :
457 379 : case SMB2_0_INFO_FILESYSTEM:
458 : {
459 : uint16_t file_info_level;
460 379 : char *data = NULL;
461 379 : int data_size = 0;
462 : size_t fixed_portion;
463 :
464 : /* the levels directly map to the passthru levels */
465 379 : file_info_level = in_file_info_class + 1000;
466 :
467 379 : status = smbd_do_qfsinfo(smb2req->xconn, conn, state,
468 : file_info_level,
469 : STR_UNICODE,
470 : in_output_buffer_length,
471 : &fixed_portion,
472 : fsp->fsp_name,
473 : &data,
474 : &data_size);
475 : /* some responses set STATUS_BUFFER_OVERFLOW and return
476 : partial, but valid data */
477 379 : if (!(NT_STATUS_IS_OK(status) ||
478 0 : NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW))) {
479 0 : SAFE_FREE(data);
480 0 : if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
481 0 : status = NT_STATUS_INVALID_INFO_CLASS;
482 : }
483 0 : tevent_req_nterror(req, status);
484 0 : return tevent_req_post(req, ev);
485 : }
486 379 : if (in_output_buffer_length < fixed_portion) {
487 0 : SAFE_FREE(data);
488 0 : tevent_req_nterror(
489 : req, NT_STATUS_INFO_LENGTH_MISMATCH);
490 0 : return tevent_req_post(req, ev);
491 : }
492 379 : if (data_size > 0) {
493 379 : state->out_output_buffer = data_blob_talloc(state,
494 : data,
495 : data_size);
496 379 : SAFE_FREE(data);
497 379 : if (tevent_req_nomem(state->out_output_buffer.data, req)) {
498 0 : return tevent_req_post(req, ev);
499 : }
500 379 : if (data_size > in_output_buffer_length) {
501 0 : state->out_output_buffer.length =
502 : in_output_buffer_length;
503 0 : status = STATUS_BUFFER_OVERFLOW;
504 : }
505 : }
506 379 : SAFE_FREE(data);
507 379 : break;
508 : }
509 :
510 331 : case SMB2_0_INFO_SECURITY:
511 : {
512 331 : uint8_t *p_marshalled_sd = NULL;
513 331 : size_t sd_size = 0;
514 :
515 331 : status = smbd_do_query_security_desc(conn,
516 : state,
517 : fsp,
518 : /* Security info wanted. */
519 : in_additional_information &
520 : SMB_SUPPORTED_SECINFO_FLAGS,
521 : in_output_buffer_length,
522 : &p_marshalled_sd,
523 : &sd_size);
524 :
525 331 : if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
526 : /* Return needed size. */
527 0 : state->out_output_buffer = data_blob_talloc(state,
528 : NULL,
529 : 4);
530 0 : if (tevent_req_nomem(state->out_output_buffer.data, req)) {
531 0 : return tevent_req_post(req, ev);
532 : }
533 0 : SIVAL(state->out_output_buffer.data,0,(uint32_t)sd_size);
534 0 : state->status = NT_STATUS_BUFFER_TOO_SMALL;
535 323 : break;
536 : }
537 331 : if (!NT_STATUS_IS_OK(status)) {
538 0 : DEBUG(10,("smbd_smb2_getinfo_send: "
539 : "smbd_do_query_security_desc of %s failed "
540 : "(%s)\n", fsp_str_dbg(fsp),
541 : nt_errstr(status)));
542 0 : tevent_req_nterror(req, status);
543 0 : return tevent_req_post(req, ev);
544 : }
545 :
546 331 : if (sd_size > 0) {
547 331 : state->out_output_buffer = data_blob_talloc(state,
548 : p_marshalled_sd,
549 : sd_size);
550 331 : if (tevent_req_nomem(state->out_output_buffer.data, req)) {
551 0 : return tevent_req_post(req, ev);
552 : }
553 : }
554 331 : break;
555 : }
556 :
557 0 : case SMB2_0_INFO_QUOTA: {
558 : #ifdef HAVE_SYS_QUOTAS
559 : struct smb2_query_quota_info info;
560 : enum ndr_err_code err;
561 0 : uint8_t *data = NULL;
562 0 : uint32_t data_size = 0;
563 0 : struct ndr_pull *ndr_pull = NULL;
564 0 : DATA_BLOB sid_buf = data_blob_null;
565 0 : TALLOC_CTX *tmp_ctx = talloc_init("geninfo_quota");
566 : bool ok;
567 :
568 0 : if (!tmp_ctx) {
569 0 : tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
570 0 : return tevent_req_post(req, ev);
571 : }
572 :
573 0 : ok = check_fsp_ntquota_handle(conn, smbreq, fsp);
574 0 : if (!ok) {
575 0 : DBG_INFO("no valid QUOTA HANDLE\n");
576 0 : TALLOC_FREE(tmp_ctx);
577 0 : tevent_req_nterror(req, NT_STATUS_INVALID_HANDLE);
578 0 : return tevent_req_post(req, ev);
579 : }
580 :
581 0 : ndr_pull = ndr_pull_init_blob(&in_input_buffer, tmp_ctx);
582 0 : if (!ndr_pull) {
583 0 : TALLOC_FREE(tmp_ctx);
584 0 : tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
585 0 : return tevent_req_post(req, ev);
586 : }
587 :
588 0 : err = ndr_pull_smb2_query_quota_info(ndr_pull,
589 : NDR_SCALARS | NDR_BUFFERS,
590 : &info);
591 :
592 0 : if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
593 0 : DBG_DEBUG("failed to pull smb2_query_quota_info\n");
594 0 : TALLOC_FREE(tmp_ctx);
595 0 : tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
596 0 : return tevent_req_post(req, ev);
597 : }
598 :
599 0 : DBG_DEBUG("quota list returnsingle %u, restartscan %u, "
600 : "sid_list_length %u, start_sid_length %u, "
601 : "startsidoffset %u\n",
602 : (unsigned int)info.return_single,
603 : (unsigned int)info.restart_scan,
604 : (unsigned int)info.sid_list_length,
605 : (unsigned int)info.start_sid_length,
606 : (unsigned int)info.start_sid_offset);
607 :
608 : /* Currently we do not support the single start sid format */
609 0 : if (info.start_sid_length != 0 || info.start_sid_offset != 0 ) {
610 0 : DBG_INFO("illegal single sid query\n");
611 0 : TALLOC_FREE(tmp_ctx);
612 0 : tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
613 0 : return tevent_req_post(req, ev);
614 : }
615 :
616 0 : if (in_input_buffer.length < ndr_pull->offset) {
617 0 : DBG_INFO("Invalid buffer length\n");
618 0 : TALLOC_FREE(tmp_ctx);
619 0 : tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
620 0 : return tevent_req_post(req, ev);
621 : }
622 :
623 0 : sid_buf.data = in_input_buffer.data + ndr_pull->offset;
624 0 : sid_buf.length = in_input_buffer.length - ndr_pull->offset;
625 :
626 0 : status = smbd_do_query_getinfo_quota(tmp_ctx,
627 : fsp,
628 0 : info.restart_scan,
629 0 : info.return_single,
630 : info.sid_list_length,
631 : &sid_buf,
632 : in_output_buffer_length,
633 : &data,
634 : &data_size);
635 :
636 0 : if (!NT_STATUS_IS_OK(status)) {
637 0 : TALLOC_FREE(tmp_ctx);
638 0 : tevent_req_nterror(req, status);
639 0 : return tevent_req_post(req, ev);
640 : }
641 :
642 0 : state->out_output_buffer =
643 0 : data_blob_talloc(state, data, data_size);
644 0 : status = NT_STATUS_OK;
645 0 : TALLOC_FREE(tmp_ctx);
646 0 : break;
647 : #else
648 : tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
649 : return tevent_req_post(req, ev);
650 : #endif
651 : }
652 :
653 0 : default:
654 0 : DEBUG(10,("smbd_smb2_getinfo_send: "
655 : "unknown in_info_type of %u "
656 : " for file %s\n",
657 : (unsigned int)in_info_type,
658 : fsp_str_dbg(fsp) ));
659 :
660 0 : tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
661 0 : return tevent_req_post(req, ev);
662 : }
663 :
664 1612 : state->status = status;
665 1612 : tevent_req_done(req);
666 1612 : return tevent_req_post(req, ev);
667 : }
668 :
669 1620 : static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
670 : TALLOC_CTX *mem_ctx,
671 : DATA_BLOB *out_output_buffer,
672 : NTSTATUS *pstatus)
673 : {
674 : NTSTATUS status;
675 1620 : struct smbd_smb2_getinfo_state *state = tevent_req_data(req,
676 : struct smbd_smb2_getinfo_state);
677 :
678 1620 : if (tevent_req_is_nterror(req, &status)) {
679 8 : tevent_req_received(req);
680 8 : return status;
681 : }
682 :
683 1612 : *out_output_buffer = state->out_output_buffer;
684 1612 : talloc_steal(mem_ctx, out_output_buffer->data);
685 1612 : *pstatus = state->status;
686 :
687 1612 : tevent_req_received(req);
688 1612 : return NT_STATUS_OK;
689 : }
|