2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "locking/share_mode_lock.h"
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "../libcli/smb/smb_common.h"
27 #include "../lib/util/tevent_ntstatus.h"
28 #include "system/filesys.h"
29 #include "lib/pthreadpool/pthreadpool_tevent.h"
30 #include "source3/smbd/dir.h"
33 #define DBGC_CLASS DBGC_SMB2
35 static struct tevent_req
*smbd_smb2_query_directory_send(TALLOC_CTX
*mem_ctx
,
36 struct tevent_context
*ev
,
37 struct smbd_smb2_request
*smb2req
,
38 struct files_struct
*in_fsp
,
39 uint8_t in_file_info_class
,
41 uint32_t in_file_index
,
42 uint32_t in_output_buffer_length
,
43 const char *in_file_name
);
44 static NTSTATUS
smbd_smb2_query_directory_recv(struct tevent_req
*req
,
46 DATA_BLOB
*out_output_buffer
);
48 static void smbd_smb2_request_find_done(struct tevent_req
*subreq
);
49 NTSTATUS
smbd_smb2_request_process_query_directory(struct smbd_smb2_request
*req
)
52 const uint8_t *inbody
;
53 uint8_t in_file_info_class
;
55 uint32_t in_file_index
;
56 uint64_t in_file_id_persistent
;
57 uint64_t in_file_id_volatile
;
58 struct files_struct
*in_fsp
;
59 uint16_t in_file_name_offset
;
60 uint16_t in_file_name_length
;
61 DATA_BLOB in_file_name_buffer
;
62 char *in_file_name_string
;
63 size_t in_file_name_string_size
;
64 uint32_t in_output_buffer_length
;
65 struct tevent_req
*subreq
;
68 status
= smbd_smb2_request_verify_sizes(req
, 0x21);
69 if (!NT_STATUS_IS_OK(status
)) {
70 return smbd_smb2_request_error(req
, status
);
72 inbody
= SMBD_SMB2_IN_BODY_PTR(req
);
74 in_file_info_class
= CVAL(inbody
, 0x02);
75 in_flags
= CVAL(inbody
, 0x03);
76 in_file_index
= IVAL(inbody
, 0x04);
77 in_file_id_persistent
= BVAL(inbody
, 0x08);
78 in_file_id_volatile
= BVAL(inbody
, 0x10);
79 in_file_name_offset
= SVAL(inbody
, 0x18);
80 in_file_name_length
= SVAL(inbody
, 0x1A);
81 in_output_buffer_length
= IVAL(inbody
, 0x1C);
83 if (in_file_name_offset
== 0 && in_file_name_length
== 0) {
85 } else if (in_file_name_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_file_name_length
> SMBD_SMB2_IN_DYN_LEN(req
)) {
91 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
94 /* The output header is 8 bytes. */
95 if (in_output_buffer_length
<= 8) {
96 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
99 DEBUG(10,("smbd_smb2_request_find_done: in_output_buffer_length = %u\n",
100 (unsigned int)in_output_buffer_length
));
102 /* Take into account the output header. */
103 in_output_buffer_length
-= 8;
105 in_file_name_buffer
.data
= SMBD_SMB2_IN_DYN_PTR(req
);
106 in_file_name_buffer
.length
= in_file_name_length
;
108 ok
= convert_string_talloc(req
, CH_UTF16
, CH_UNIX
,
109 in_file_name_buffer
.data
,
110 in_file_name_buffer
.length
,
111 &in_file_name_string
,
112 &in_file_name_string_size
);
114 return smbd_smb2_request_error(req
, NT_STATUS_ILLEGAL_CHARACTER
);
117 if (in_file_name_buffer
.length
== 0) {
118 in_file_name_string_size
= 0;
121 if (strlen(in_file_name_string
) != in_file_name_string_size
) {
122 return smbd_smb2_request_error(req
, NT_STATUS_OBJECT_NAME_INVALID
);
125 in_fsp
= file_fsp_smb2(req
, in_file_id_persistent
, in_file_id_volatile
);
126 if (in_fsp
== NULL
) {
127 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
130 subreq
= smbd_smb2_query_directory_send(req
, req
->sconn
->ev_ctx
,
135 in_output_buffer_length
,
136 in_file_name_string
);
137 if (subreq
== NULL
) {
138 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
140 tevent_req_set_callback(subreq
, smbd_smb2_request_find_done
, req
);
142 return smbd_smb2_request_pending_queue(req
, subreq
, 500);
145 static void smbd_smb2_request_find_done(struct tevent_req
*subreq
)
147 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
148 struct smbd_smb2_request
);
151 uint16_t out_output_buffer_offset
;
152 DATA_BLOB out_output_buffer
= data_blob_null
;
154 NTSTATUS error
; /* transport error */
156 status
= smbd_smb2_query_directory_recv(subreq
,
160 if (!NT_STATUS_IS_OK(status
)) {
161 error
= smbd_smb2_request_error(req
, status
);
162 if (!NT_STATUS_IS_OK(error
)) {
163 smbd_server_connection_terminate(req
->xconn
,
170 out_output_buffer_offset
= SMB2_HDR_BODY
+ 0x08;
172 outbody
= smbd_smb2_generate_outbody(req
, 0x08);
173 if (outbody
.data
== NULL
) {
174 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
175 if (!NT_STATUS_IS_OK(error
)) {
176 smbd_server_connection_terminate(req
->xconn
,
183 SSVAL(outbody
.data
, 0x00, 0x08 + 1); /* struct size */
184 SSVAL(outbody
.data
, 0x02,
185 out_output_buffer_offset
); /* output buffer offset */
186 SIVAL(outbody
.data
, 0x04,
187 out_output_buffer
.length
); /* output buffer length */
189 DEBUG(10,("smbd_smb2_request_find_done: out_output_buffer.length = %u\n",
190 (unsigned int)out_output_buffer
.length
));
192 outdyn
= out_output_buffer
;
194 error
= smbd_smb2_request_done(req
, outbody
, &outdyn
);
195 if (!NT_STATUS_IS_OK(error
)) {
196 smbd_server_connection_terminate(req
->xconn
,
202 static struct tevent_req
*fetch_write_time_send(TALLOC_CTX
*mem_ctx
,
203 struct tevent_context
*ev
,
204 connection_struct
*conn
,
207 char *entry_marshall_buf
,
209 static NTSTATUS
fetch_write_time_recv(struct tevent_req
*req
);
211 static struct tevent_req
*fetch_dos_mode_send(
213 struct tevent_context
*ev
,
214 struct files_struct
*dir_fsp
,
215 struct smb_filename
**smb_fname
,
217 uint8_t *entry_marshall_buf
);
219 static NTSTATUS
fetch_dos_mode_recv(struct tevent_req
*req
);
221 struct smbd_smb2_query_directory_state
{
222 struct tevent_context
*ev
;
223 struct smbd_smb2_request
*smb2req
;
224 uint64_t async_sharemode_count
;
225 uint32_t find_async_delay_usec
;
226 DATA_BLOB out_output_buffer
;
227 struct smb_request
*smbreq
;
228 int in_output_buffer_length
;
229 struct files_struct
*dirfsp
;
230 const char *in_file_name
;
231 NTSTATUS empty_status
;
242 bool async_ask_sharemode
;
244 size_t max_async_dosmode_active
;
245 uint32_t async_dosmode_active
;
249 static bool smb2_query_directory_next_entry(struct tevent_req
*req
);
250 static void smb2_query_directory_fetch_write_time_done(struct tevent_req
*subreq
);
251 static void smb2_query_directory_dos_mode_done(struct tevent_req
*subreq
);
252 static void smb2_query_directory_waited(struct tevent_req
*subreq
);
254 static struct tevent_req
*smbd_smb2_query_directory_send(TALLOC_CTX
*mem_ctx
,
255 struct tevent_context
*ev
,
256 struct smbd_smb2_request
*smb2req
,
257 struct files_struct
*fsp
,
258 uint8_t in_file_info_class
,
260 uint32_t in_file_index
,
261 uint32_t in_output_buffer_length
,
262 const char *in_file_name
)
264 struct smbXsrv_connection
*xconn
= smb2req
->xconn
;
265 struct tevent_req
*req
;
266 struct smbd_smb2_query_directory_state
*state
;
267 connection_struct
*conn
= smb2req
->tcon
->compat
;
268 const struct loadparm_substitution
*lp_sub
=
269 loadparm_s3_global_substitution();
271 bool wcard_has_wild
= false;
276 bool posix_dir_handle
= (fsp
->posix_flags
& FSP_POSIX_FLAGS_OPEN
);
278 req
= tevent_req_create(mem_ctx
, &state
,
279 struct smbd_smb2_query_directory_state
);
285 state
->smb2req
= smb2req
;
286 state
->in_output_buffer_length
= in_output_buffer_length
;
287 state
->in_file_name
= in_file_name
;
288 state
->out_output_buffer
= data_blob_null
;
289 state
->dirtype
= FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_DIRECTORY
;
291 DEBUG(10,("smbd_smb2_query_directory_send: %s - %s\n",
292 fsp_str_dbg(fsp
), fsp_fnum_dbg(fsp
)));
294 state
->smbreq
= smbd_smb2_fake_smb_request(smb2req
, fsp
);
295 if (tevent_req_nomem(state
->smbreq
, req
)) {
296 return tevent_req_post(req
, ev
);
299 if (!fsp
->fsp_flags
.is_directory
) {
300 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
301 return tevent_req_post(req
, ev
);
304 if (strcmp(state
->in_file_name
, "") == 0) {
305 tevent_req_nterror(req
, NT_STATUS_OBJECT_NAME_INVALID
);
306 return tevent_req_post(req
, ev
);
308 if (strchr_m(state
->in_file_name
, '\\') != NULL
) {
309 tevent_req_nterror(req
, NT_STATUS_OBJECT_NAME_INVALID
);
310 return tevent_req_post(req
, ev
);
312 if (strchr_m(state
->in_file_name
, '/') != NULL
) {
313 tevent_req_nterror(req
, NT_STATUS_OBJECT_NAME_INVALID
);
314 return tevent_req_post(req
, ev
);
317 p
= strptime(state
->in_file_name
, GMT_FORMAT
, &tm
);
318 if ((p
!= NULL
) && (*p
=='\0')) {
320 * Bogus find that asks for a shadow copy timestamp as a
321 * directory. The correct response is that it does not exist as
324 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_FILE
);
325 return tevent_req_post(req
, ev
);
328 if (in_output_buffer_length
> xconn
->smb2
.server
.max_trans
) {
329 DEBUG(2,("smbd_smb2_query_directory_send: "
330 "client ignored max trans:%s: 0x%08X: 0x%08X\n",
331 __location__
, in_output_buffer_length
,
332 xconn
->smb2
.server
.max_trans
));
333 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
334 return tevent_req_post(req
, ev
);
337 status
= smbd_smb2_request_verify_creditcharge(smb2req
,
338 in_output_buffer_length
);
340 if (!NT_STATUS_IS_OK(status
)) {
341 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
342 return tevent_req_post(req
, ev
);
345 switch (in_file_info_class
) {
346 case SMB2_FIND_DIRECTORY_INFO
:
347 state
->info_level
= SMB_FIND_FILE_DIRECTORY_INFO
;
350 case SMB2_FIND_FULL_DIRECTORY_INFO
:
351 state
->info_level
= SMB_FIND_FILE_FULL_DIRECTORY_INFO
;
354 case SMB2_FIND_BOTH_DIRECTORY_INFO
:
355 state
->info_level
= SMB_FIND_FILE_BOTH_DIRECTORY_INFO
;
358 case SMB2_FIND_NAME_INFO
:
359 state
->info_level
= SMB_FIND_FILE_NAMES_INFO
;
362 case SMB2_FIND_ID_BOTH_DIRECTORY_INFO
:
363 state
->info_level
= SMB_FIND_ID_BOTH_DIRECTORY_INFO
;
366 case SMB2_FIND_ID_FULL_DIRECTORY_INFO
:
367 state
->info_level
= SMB_FIND_ID_FULL_DIRECTORY_INFO
;
370 case SMB2_FIND_POSIX_INFORMATION
:
371 if (!(fsp
->posix_flags
& FSP_POSIX_FLAGS_OPEN
)) {
372 tevent_req_nterror(req
, NT_STATUS_INVALID_LEVEL
);
373 return tevent_req_post(req
, ev
);
375 state
->info_level
= SMB2_FILE_POSIX_INFORMATION
;
378 tevent_req_nterror(req
, NT_STATUS_INVALID_INFO_CLASS
);
379 return tevent_req_post(req
, ev
);
382 if (in_flags
& SMB2_CONTINUE_FLAG_REOPEN
) {
383 struct vfs_open_how how
= { .flags
= O_RDONLY
, };
385 status
= fd_close(fsp
);
386 if (tevent_req_nterror(req
, status
)) {
387 return tevent_req_post(req
, ev
);
391 * fd_close() will close and invalidate the fsp's file
392 * descriptor. So we have to reopen it.
396 how
.flags
|= O_DIRECTORY
;
398 status
= fd_openat(conn
->cwd_fsp
, fsp
->fsp_name
, fsp
, &how
);
399 if (tevent_req_nterror(req
, status
)) {
400 return tevent_req_post(req
, ev
);
404 if (!state
->smbreq
->posix_pathnames
) {
405 wcard_has_wild
= ms_has_wild(state
->in_file_name
);
408 /* Ensure we've canonicalized any search path if not a wildcard. */
409 if (!wcard_has_wild
) {
411 * We still need to do the case processing
412 * to save off the client-supplied last component.
413 * At least we know there's no @GMT normalization
414 * or MS-DFS paths to do in a directory mask.
416 state
->in_file_name
= get_original_lcomp(state
,
420 if (tevent_req_nomem(state
->in_file_name
, req
)) {
421 return tevent_req_post(req
, ev
);
425 if (fsp
->dptr
== NULL
) {
426 status
= dptr_create(conn
,
429 false, /* old_handle */
430 state
->in_file_name
, /* wcard */
433 if (!NT_STATUS_IS_OK(status
)) {
434 tevent_req_nterror(req
, status
);
435 return tevent_req_post(req
, ev
);
438 state
->empty_status
= NT_STATUS_NO_SUCH_FILE
;
440 state
->empty_status
= STATUS_NO_MORE_FILES
;
443 if (in_flags
& SMB2_CONTINUE_FLAG_RESTART
) {
444 dptr_RewindDir(fsp
->dptr
);
447 if (in_flags
& SMB2_CONTINUE_FLAG_SINGLE
) {
448 state
->max_count
= 1;
450 state
->max_count
= UINT16_MAX
;
453 #define DIR_ENTRY_SAFETY_MARGIN 4096
455 state
->out_output_buffer
= data_blob_talloc(state
, NULL
,
456 in_output_buffer_length
+ DIR_ENTRY_SAFETY_MARGIN
);
457 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
458 return tevent_req_post(req
, ev
);
461 state
->out_output_buffer
.length
= 0;
462 state
->pdata
= (char *)state
->out_output_buffer
.data
;
463 state
->base_data
= state
->pdata
;
465 * end_data must include the safety margin as it's what is
466 * used to determine if pushed strings have been truncated.
468 state
->end_data
= state
->pdata
+ in_output_buffer_length
+ DIR_ENTRY_SAFETY_MARGIN
- 1;
470 DEBUG(8,("smbd_smb2_query_directory_send: dirpath=<%s> dontdescend=<%s>, "
471 "in_output_buffer_length = %u\n",
472 fsp
->fsp_name
->base_name
, lp_dont_descend(talloc_tos(), lp_sub
, SNUM(conn
)),
473 (unsigned int)in_output_buffer_length
));
475 state
->dont_descend
= in_list(
476 fsp
->fsp_name
->base_name
,
477 lp_dont_descend(talloc_tos(), lp_sub
, SNUM(conn
)),
478 posix_dir_handle
? true : conn
->case_sensitive
);
481 * SMB_FIND_FILE_NAMES_INFO doesn't need stat information
483 * This may change when we try to improve the delete on close
484 * handling in future.
486 if (state
->info_level
!= SMB_FIND_FILE_NAMES_INFO
) {
487 state
->ask_sharemode
= fsp_search_ask_sharemode(fsp
);
489 state
->async_dosmode
= lp_smbd_async_dosmode(SNUM(conn
));
492 if (state
->ask_sharemode
&& lp_clustering()) {
493 state
->ask_sharemode
= false;
494 state
->async_ask_sharemode
= true;
497 if (state
->async_dosmode
) {
500 max_threads
= pthreadpool_tevent_max_threads(conn
->sconn
->pool
);
501 if (max_threads
== 0 || !per_thread_cwd_supported()) {
502 state
->async_dosmode
= false;
505 state
->max_async_dosmode_active
= lp_smbd_max_async_dosmode(
507 if (state
->max_async_dosmode_active
== 0) {
508 state
->max_async_dosmode_active
= max_threads
* 2;
512 if (state
->async_dosmode
|| state
->async_ask_sharemode
) {
514 * Should we only set async_internal
515 * if we're not the last request in
518 smb2_request_set_async_internal(smb2req
, true);
522 * This gets set in autobuild for some tests
524 state
->find_async_delay_usec
= lp_parm_ulong(SNUM(conn
), "smbd",
525 "find async delay usec",
529 stop
= smb2_query_directory_next_entry(req
);
532 if (!tevent_req_is_in_progress(req
)) {
533 return tevent_req_post(req
, ev
);
536 ok
= aio_add_req_to_fsp(fsp
, req
);
538 DBG_ERR("Could not add req to fsp\n");
539 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
540 return tevent_req_post(req
, ev
);
546 static bool smb2_query_directory_next_entry(struct tevent_req
*req
)
548 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
549 req
, struct smbd_smb2_query_directory_state
);
550 struct smb_filename
*smb_fname
= NULL
; /* relative to fsp !! */
551 int off
= state
->out_output_buffer
.length
;
552 int space_remaining
= state
->in_output_buffer_length
- off
;
553 struct file_id file_id
;
555 bool get_dosmode
= !state
->async_dosmode
;
558 SMB_ASSERT(space_remaining
>= 0);
560 status
= smbd_dirptr_lanman2_entry(state
,
563 state
->smbreq
->flags2
,
567 false, /* requires_resume_key */
569 state
->ask_sharemode
,
571 8, /* align to 8 bytes */
572 false, /* no padding */
578 &state
->last_entry_off
,
582 off
= (int)PTR_DIFF(state
->pdata
, state
->base_data
);
584 if (!NT_STATUS_IS_OK(status
)) {
585 if (NT_STATUS_EQUAL(status
, NT_STATUS_ILLEGAL_CHARACTER
)) {
587 * Bad character conversion on name. Ignore this
593 if (state
->num
> 0) {
594 goto last_entry_done
;
597 if (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
598 tevent_req_nterror(req
, NT_STATUS_INFO_LENGTH_MISMATCH
);
602 tevent_req_nterror(req
, state
->empty_status
);
606 if (state
->async_ask_sharemode
&&
607 !S_ISDIR(smb_fname
->st
.st_ex_mode
))
609 struct tevent_req
*subreq
= NULL
;
610 char *buf
= state
->base_data
+ state
->last_entry_off
;
612 subreq
= fetch_write_time_send(state
,
619 if (tevent_req_nomem(subreq
, req
)) {
622 tevent_req_set_callback(
624 smb2_query_directory_fetch_write_time_done
,
626 state
->async_sharemode_count
++;
629 if (state
->async_dosmode
) {
630 struct tevent_req
*subreq
= NULL
;
632 size_t outstanding_aio
;
634 buf
= (uint8_t *)state
->base_data
+ state
->last_entry_off
;
636 subreq
= fetch_dos_mode_send(state
,
642 if (tevent_req_nomem(subreq
, req
)) {
645 tevent_req_set_callback(subreq
,
646 smb2_query_directory_dos_mode_done
,
649 state
->async_dosmode_active
++;
651 outstanding_aio
= pthreadpool_tevent_queued_jobs(
652 state
->dirfsp
->conn
->sconn
->pool
);
654 if (outstanding_aio
> state
->max_async_dosmode_active
) {
659 TALLOC_FREE(smb_fname
);
662 state
->out_output_buffer
.length
= off
;
664 if (!state
->done
&& state
->num
< state
->max_count
) {
669 SIVAL(state
->out_output_buffer
.data
, state
->last_entry_off
, 0);
673 if (state
->async_sharemode_count
> 0) {
674 DBG_DEBUG("Stopping after %"PRIu64
" async mtime "
675 "updates\n", state
->async_sharemode_count
);
679 if (state
->async_dosmode_active
> 0) {
683 if (state
->find_async_delay_usec
> 0) {
685 struct tevent_req
*subreq
= NULL
;
688 * Should we only set async_internal
689 * if we're not the last request in
692 smb2_request_set_async_internal(state
->smb2req
, true);
694 tv
= timeval_current_ofs(0, state
->find_async_delay_usec
);
696 subreq
= tevent_wakeup_send(state
, state
->ev
, tv
);
697 if (tevent_req_nomem(subreq
, req
)) {
700 tevent_req_set_callback(subreq
,
701 smb2_query_directory_waited
,
706 tevent_req_done(req
);
710 static void smb2_query_directory_check_next_entry(struct tevent_req
*req
);
712 static void smb2_query_directory_fetch_write_time_done(struct tevent_req
*subreq
)
714 struct tevent_req
*req
= tevent_req_callback_data(
715 subreq
, struct tevent_req
);
716 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
717 req
, struct smbd_smb2_query_directory_state
);
722 * Make sure we run as the user again
724 ok
= change_to_user_and_service_by_fsp(state
->dirfsp
);
727 state
->async_sharemode_count
--;
729 status
= fetch_write_time_recv(subreq
);
731 if (tevent_req_nterror(req
, status
)) {
735 smb2_query_directory_check_next_entry(req
);
739 static void smb2_query_directory_dos_mode_done(struct tevent_req
*subreq
)
741 struct tevent_req
*req
=
742 tevent_req_callback_data(subreq
,
744 struct smbd_smb2_query_directory_state
*state
=
746 struct smbd_smb2_query_directory_state
);
751 * Make sure we run as the user again
753 ok
= change_to_user_and_service_by_fsp(state
->dirfsp
);
756 status
= fetch_dos_mode_recv(subreq
);
758 if (tevent_req_nterror(req
, status
)) {
762 state
->async_dosmode_active
--;
764 smb2_query_directory_check_next_entry(req
);
768 static void smb2_query_directory_check_next_entry(struct tevent_req
*req
)
770 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
771 req
, struct smbd_smb2_query_directory_state
);
776 stop
= smb2_query_directory_next_entry(req
);
781 if (state
->async_sharemode_count
> 0 ||
782 state
->async_dosmode_active
> 0)
787 if (state
->find_async_delay_usec
> 0) {
789 struct tevent_req
*subreq
= NULL
;
791 tv
= timeval_current_ofs(0, state
->find_async_delay_usec
);
793 subreq
= tevent_wakeup_send(state
, state
->ev
, tv
);
794 if (tevent_req_nomem(subreq
, req
)) {
795 tevent_req_post(req
, state
->ev
);
798 tevent_req_set_callback(subreq
,
799 smb2_query_directory_waited
,
804 tevent_req_done(req
);
808 static void smb2_query_directory_waited(struct tevent_req
*subreq
)
810 struct tevent_req
*req
= tevent_req_callback_data(
811 subreq
, struct tevent_req
);
814 ok
= tevent_wakeup_recv(subreq
);
820 tevent_req_done(req
);
823 static NTSTATUS
smbd_smb2_query_directory_recv(struct tevent_req
*req
,
825 DATA_BLOB
*out_output_buffer
)
828 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(req
,
829 struct smbd_smb2_query_directory_state
);
831 if (tevent_req_is_nterror(req
, &status
)) {
832 tevent_req_received(req
);
836 *out_output_buffer
= state
->out_output_buffer
;
837 talloc_steal(mem_ctx
, out_output_buffer
->data
);
839 tevent_req_received(req
);
843 struct fetch_write_time_state
{
844 connection_struct
*conn
;
847 char *entry_marshall_buf
;
850 static void fetch_write_time_done(struct tevent_req
*subreq
);
852 static struct tevent_req
*fetch_write_time_send(TALLOC_CTX
*mem_ctx
,
853 struct tevent_context
*ev
,
854 connection_struct
*conn
,
857 char *entry_marshall_buf
,
860 struct tevent_req
*req
= NULL
;
861 struct fetch_write_time_state
*state
= NULL
;
862 struct tevent_req
*subreq
= NULL
;
867 req
= tevent_req_create(mem_ctx
, &state
, struct fetch_write_time_state
);
872 *state
= (struct fetch_write_time_state
) {
875 .info_level
= info_level
,
876 .entry_marshall_buf
= entry_marshall_buf
,
879 subreq
= fetch_share_mode_send(state
, ev
, id
, &req_queued
);
880 if (tevent_req_nomem(subreq
, req
)) {
881 return tevent_req_post(req
, ev
);
883 tevent_req_set_callback(subreq
, fetch_write_time_done
, req
);
891 static void fetch_write_time_done(struct tevent_req
*subreq
)
893 struct tevent_req
*req
= tevent_req_callback_data(
894 subreq
, struct tevent_req
);
895 struct fetch_write_time_state
*state
= tevent_req_data(
896 req
, struct fetch_write_time_state
);
897 struct timespec write_time
;
898 struct share_mode_lock
*lck
= NULL
;
902 status
= fetch_share_mode_recv(subreq
, state
, &lck
);
904 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
905 tevent_req_done(req
);
908 if (tevent_req_nterror(req
, status
)) {
912 write_time
= get_share_mode_write_time(lck
);
915 if (is_omit_timespec(&write_time
)) {
916 tevent_req_done(req
);
920 switch (state
->info_level
) {
921 case SMB_FIND_FILE_DIRECTORY_INFO
:
922 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
923 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
924 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
925 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
930 DBG_ERR("Unsupported info_level [%d]\n", state
->info_level
);
931 tevent_req_nterror(req
, NT_STATUS_INVALID_LEVEL
);
935 put_long_date_full_timespec(state
->conn
->ts_res
,
936 state
->entry_marshall_buf
+ off
,
939 tevent_req_done(req
);
943 static NTSTATUS
fetch_write_time_recv(struct tevent_req
*req
)
947 if (tevent_req_is_nterror(req
, &status
)) {
948 tevent_req_received(req
);
952 tevent_req_received(req
);
956 struct fetch_dos_mode_state
{
957 struct files_struct
*dir_fsp
;
958 struct smb_filename
*smb_fname
;
960 uint8_t *entry_marshall_buf
;
963 static void fetch_dos_mode_done(struct tevent_req
*subreq
);
965 static struct tevent_req
*fetch_dos_mode_send(
967 struct tevent_context
*ev
,
968 struct files_struct
*dir_fsp
,
969 struct smb_filename
**smb_fname
,
971 uint8_t *entry_marshall_buf
)
973 struct tevent_req
*req
= NULL
;
974 struct fetch_dos_mode_state
*state
= NULL
;
975 struct tevent_req
*subreq
= NULL
;
977 req
= tevent_req_create(mem_ctx
, &state
, struct fetch_dos_mode_state
);
981 *state
= (struct fetch_dos_mode_state
) {
983 .info_level
= info_level
,
984 .entry_marshall_buf
= entry_marshall_buf
,
987 state
->smb_fname
= talloc_move(state
, smb_fname
);
989 subreq
= dos_mode_at_send(state
, ev
, dir_fsp
, state
->smb_fname
);
990 if (tevent_req_nomem(subreq
, req
)) {
991 return tevent_req_post(req
, ev
);
993 tevent_req_set_callback(subreq
, fetch_dos_mode_done
, req
);
998 static void fetch_dos_mode_done(struct tevent_req
*subreq
)
1000 struct tevent_req
*req
=
1001 tevent_req_callback_data(subreq
,
1003 struct fetch_dos_mode_state
*state
=
1004 tevent_req_data(req
,
1005 struct fetch_dos_mode_state
);
1006 uint32_t dfs_dosmode
;
1008 struct timespec btime_ts
= {0};
1013 status
= dos_mode_at_recv(subreq
, &dosmode
);
1014 TALLOC_FREE(subreq
);
1015 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
1016 tevent_req_done(req
);
1019 if (tevent_req_nterror(req
, status
)) {
1023 switch (state
->info_level
) {
1024 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
1025 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
1026 case SMB_FIND_FILE_DIRECTORY_INFO
:
1027 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
1028 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
1034 DBG_ERR("Unsupported info_level [%u]\n", state
->info_level
);
1035 tevent_req_nterror(req
, NT_STATUS_INVALID_LEVEL
);
1040 dfs_dosmode
= IVAL(state
->entry_marshall_buf
, dosmode_off
);
1041 if (dfs_dosmode
== 0) {
1043 * DOS mode for a DFS link, only overwrite if still set to 0 and
1044 * not already populated by the lower layer for a DFS link in
1045 * smbd_dirptr_lanman2_mode_fn().
1047 SIVAL(state
->entry_marshall_buf
, dosmode_off
, dosmode
);
1050 btime_ts
= get_create_timespec(state
->dir_fsp
->conn
,
1053 if (lp_dos_filetime_resolution(SNUM(state
->dir_fsp
->conn
))) {
1054 dos_filetime_timespec(&btime_ts
);
1057 put_long_date_full_timespec(state
->dir_fsp
->conn
->ts_res
,
1058 (char *)state
->entry_marshall_buf
+ btime_off
,
1061 tevent_req_done(req
);
1065 static NTSTATUS
fetch_dos_mode_recv(struct tevent_req
*req
)
1069 if (tevent_req_is_nterror(req
, &status
)) {
1070 tevent_req_received(req
);
1074 tevent_req_received(req
);
1075 return NT_STATUS_OK
;