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