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