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"
32 #define DBGC_CLASS DBGC_SMB2
34 static struct tevent_req
*smbd_smb2_query_directory_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_file_info_class
,
40 uint32_t in_file_index
,
41 uint32_t in_output_buffer_length
,
42 const char *in_file_name
);
43 static NTSTATUS
smbd_smb2_query_directory_recv(struct tevent_req
*req
,
45 DATA_BLOB
*out_output_buffer
);
47 static void smbd_smb2_request_find_done(struct tevent_req
*subreq
);
48 NTSTATUS
smbd_smb2_request_process_query_directory(struct smbd_smb2_request
*req
)
51 const uint8_t *inbody
;
52 uint8_t in_file_info_class
;
54 uint32_t in_file_index
;
55 uint64_t in_file_id_persistent
;
56 uint64_t in_file_id_volatile
;
57 struct files_struct
*in_fsp
;
58 uint16_t in_file_name_offset
;
59 uint16_t in_file_name_length
;
60 DATA_BLOB in_file_name_buffer
;
61 char *in_file_name_string
;
62 size_t in_file_name_string_size
;
63 uint32_t in_output_buffer_length
;
64 struct tevent_req
*subreq
;
67 status
= smbd_smb2_request_verify_sizes(req
, 0x21);
68 if (!NT_STATUS_IS_OK(status
)) {
69 return smbd_smb2_request_error(req
, status
);
71 inbody
= SMBD_SMB2_IN_BODY_PTR(req
);
73 in_file_info_class
= CVAL(inbody
, 0x02);
74 in_flags
= CVAL(inbody
, 0x03);
75 in_file_index
= IVAL(inbody
, 0x04);
76 in_file_id_persistent
= BVAL(inbody
, 0x08);
77 in_file_id_volatile
= BVAL(inbody
, 0x10);
78 in_file_name_offset
= SVAL(inbody
, 0x18);
79 in_file_name_length
= SVAL(inbody
, 0x1A);
80 in_output_buffer_length
= IVAL(inbody
, 0x1C);
82 if (in_file_name_offset
== 0 && in_file_name_length
== 0) {
84 } else if (in_file_name_offset
!=
85 (SMB2_HDR_BODY
+ SMBD_SMB2_IN_BODY_LEN(req
))) {
86 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
89 if (in_file_name_length
> SMBD_SMB2_IN_DYN_LEN(req
)) {
90 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
93 /* The output header is 8 bytes. */
94 if (in_output_buffer_length
<= 8) {
95 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
98 DEBUG(10,("smbd_smb2_request_find_done: in_output_buffer_length = %u\n",
99 (unsigned int)in_output_buffer_length
));
101 /* Take into account the output header. */
102 in_output_buffer_length
-= 8;
104 in_file_name_buffer
.data
= SMBD_SMB2_IN_DYN_PTR(req
);
105 in_file_name_buffer
.length
= in_file_name_length
;
107 ok
= convert_string_talloc(req
, CH_UTF16
, CH_UNIX
,
108 in_file_name_buffer
.data
,
109 in_file_name_buffer
.length
,
110 &in_file_name_string
,
111 &in_file_name_string_size
);
113 return smbd_smb2_request_error(req
, NT_STATUS_ILLEGAL_CHARACTER
);
116 if (in_file_name_buffer
.length
== 0) {
117 in_file_name_string_size
= 0;
120 if (strlen(in_file_name_string
) != in_file_name_string_size
) {
121 return smbd_smb2_request_error(req
, NT_STATUS_OBJECT_NAME_INVALID
);
124 in_fsp
= file_fsp_smb2(req
, in_file_id_persistent
, in_file_id_volatile
);
125 if (in_fsp
== NULL
) {
126 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
129 subreq
= smbd_smb2_query_directory_send(req
, req
->sconn
->ev_ctx
,
134 in_output_buffer_length
,
135 in_file_name_string
);
136 if (subreq
== NULL
) {
137 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
139 tevent_req_set_callback(subreq
, smbd_smb2_request_find_done
, req
);
141 return smbd_smb2_request_pending_queue(req
, subreq
, 500);
144 static void smbd_smb2_request_find_done(struct tevent_req
*subreq
)
146 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
147 struct smbd_smb2_request
);
150 uint16_t out_output_buffer_offset
;
151 DATA_BLOB out_output_buffer
= data_blob_null
;
153 NTSTATUS error
; /* transport error */
155 status
= smbd_smb2_query_directory_recv(subreq
,
159 if (!NT_STATUS_IS_OK(status
)) {
160 error
= smbd_smb2_request_error(req
, status
);
161 if (!NT_STATUS_IS_OK(error
)) {
162 smbd_server_connection_terminate(req
->xconn
,
169 out_output_buffer_offset
= SMB2_HDR_BODY
+ 0x08;
171 outbody
= smbd_smb2_generate_outbody(req
, 0x08);
172 if (outbody
.data
== NULL
) {
173 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
174 if (!NT_STATUS_IS_OK(error
)) {
175 smbd_server_connection_terminate(req
->xconn
,
182 SSVAL(outbody
.data
, 0x00, 0x08 + 1); /* struct size */
183 SSVAL(outbody
.data
, 0x02,
184 out_output_buffer_offset
); /* output buffer offset */
185 SIVAL(outbody
.data
, 0x04,
186 out_output_buffer
.length
); /* output buffer length */
188 DEBUG(10,("smbd_smb2_request_find_done: out_output_buffer.length = %u\n",
189 (unsigned int)out_output_buffer
.length
));
191 outdyn
= out_output_buffer
;
193 error
= smbd_smb2_request_done(req
, outbody
, &outdyn
);
194 if (!NT_STATUS_IS_OK(error
)) {
195 smbd_server_connection_terminate(req
->xconn
,
201 static struct tevent_req
*fetch_write_time_send(TALLOC_CTX
*mem_ctx
,
202 struct tevent_context
*ev
,
203 connection_struct
*conn
,
206 char *entry_marshall_buf
,
208 static NTSTATUS
fetch_write_time_recv(struct tevent_req
*req
);
210 static struct tevent_req
*fetch_dos_mode_send(
212 struct tevent_context
*ev
,
213 struct files_struct
*dir_fsp
,
214 struct smb_filename
**smb_fname
,
216 uint8_t *entry_marshall_buf
);
218 static NTSTATUS
fetch_dos_mode_recv(struct tevent_req
*req
);
220 struct smbd_smb2_query_directory_state
{
221 struct tevent_context
*ev
;
222 struct smbd_smb2_request
*smb2req
;
223 uint64_t async_sharemode_count
;
224 uint32_t find_async_delay_usec
;
225 DATA_BLOB out_output_buffer
;
226 struct smb_request
*smbreq
;
227 int in_output_buffer_length
;
228 struct files_struct
*fsp
;
229 const char *in_file_name
;
230 NTSTATUS empty_status
;
241 bool async_ask_sharemode
;
243 size_t max_async_dosmode_active
;
244 uint32_t async_dosmode_active
;
248 static bool smb2_query_directory_next_entry(struct tevent_req
*req
);
249 static void smb2_query_directory_fetch_write_time_done(struct tevent_req
*subreq
);
250 static void smb2_query_directory_dos_mode_done(struct tevent_req
*subreq
);
251 static void smb2_query_directory_waited(struct tevent_req
*subreq
);
253 static struct tevent_req
*smbd_smb2_query_directory_send(TALLOC_CTX
*mem_ctx
,
254 struct tevent_context
*ev
,
255 struct smbd_smb2_request
*smb2req
,
256 struct files_struct
*fsp
,
257 uint8_t in_file_info_class
,
259 uint32_t in_file_index
,
260 uint32_t in_output_buffer_length
,
261 const char *in_file_name
)
263 struct smbXsrv_connection
*xconn
= smb2req
->xconn
;
264 struct tevent_req
*req
;
265 struct smbd_smb2_query_directory_state
*state
;
266 connection_struct
*conn
= smb2req
->tcon
->compat
;
267 const struct loadparm_substitution
*lp_sub
=
268 loadparm_s3_global_substitution();
270 bool wcard_has_wild
= false;
275 bool posix_dir_handle
= (fsp
->posix_flags
& FSP_POSIX_FLAGS_OPEN
);
277 req
= tevent_req_create(mem_ctx
, &state
,
278 struct smbd_smb2_query_directory_state
);
284 state
->smb2req
= smb2req
;
285 state
->in_output_buffer_length
= in_output_buffer_length
;
286 state
->in_file_name
= in_file_name
;
287 state
->out_output_buffer
= data_blob_null
;
288 state
->dirtype
= FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_DIRECTORY
;
290 DEBUG(10,("smbd_smb2_query_directory_send: %s - %s\n",
291 fsp_str_dbg(fsp
), fsp_fnum_dbg(fsp
)));
293 state
->smbreq
= smbd_smb2_fake_smb_request(smb2req
, fsp
);
294 if (tevent_req_nomem(state
->smbreq
, req
)) {
295 return tevent_req_post(req
, ev
);
298 if (!fsp
->fsp_flags
.is_directory
) {
299 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
300 return tevent_req_post(req
, ev
);
303 if (strcmp(state
->in_file_name
, "") == 0) {
304 tevent_req_nterror(req
, NT_STATUS_OBJECT_NAME_INVALID
);
305 return tevent_req_post(req
, ev
);
307 if (strchr_m(state
->in_file_name
, '\\') != NULL
) {
308 tevent_req_nterror(req
, NT_STATUS_OBJECT_NAME_INVALID
);
309 return tevent_req_post(req
, ev
);
311 if (strchr_m(state
->in_file_name
, '/') != NULL
) {
312 tevent_req_nterror(req
, NT_STATUS_OBJECT_NAME_INVALID
);
313 return tevent_req_post(req
, ev
);
316 p
= strptime(state
->in_file_name
, GMT_FORMAT
, &tm
);
317 if ((p
!= NULL
) && (*p
=='\0')) {
319 * Bogus find that asks for a shadow copy timestamp as a
320 * directory. The correct response is that it does not exist as
323 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_FILE
);
324 return tevent_req_post(req
, ev
);
327 if (in_output_buffer_length
> xconn
->smb2
.server
.max_trans
) {
328 DEBUG(2,("smbd_smb2_query_directory_send: "
329 "client ignored max trans:%s: 0x%08X: 0x%08X\n",
330 __location__
, in_output_buffer_length
,
331 xconn
->smb2
.server
.max_trans
));
332 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
333 return tevent_req_post(req
, ev
);
336 status
= smbd_smb2_request_verify_creditcharge(smb2req
,
337 in_output_buffer_length
);
339 if (!NT_STATUS_IS_OK(status
)) {
340 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
341 return tevent_req_post(req
, ev
);
344 switch (in_file_info_class
) {
345 case SMB2_FIND_DIRECTORY_INFO
:
346 state
->info_level
= SMB_FIND_FILE_DIRECTORY_INFO
;
349 case SMB2_FIND_FULL_DIRECTORY_INFO
:
350 state
->info_level
= SMB_FIND_FILE_FULL_DIRECTORY_INFO
;
353 case SMB2_FIND_BOTH_DIRECTORY_INFO
:
354 state
->info_level
= SMB_FIND_FILE_BOTH_DIRECTORY_INFO
;
357 case SMB2_FIND_NAME_INFO
:
358 state
->info_level
= SMB_FIND_FILE_NAMES_INFO
;
361 case SMB2_FIND_ID_BOTH_DIRECTORY_INFO
:
362 state
->info_level
= SMB_FIND_ID_BOTH_DIRECTORY_INFO
;
365 case SMB2_FIND_ID_FULL_DIRECTORY_INFO
:
366 state
->info_level
= SMB_FIND_ID_FULL_DIRECTORY_INFO
;
369 case SMB2_FIND_POSIX_INFORMATION
:
370 if (!(fsp
->posix_flags
& FSP_POSIX_FLAGS_OPEN
)) {
371 tevent_req_nterror(req
, NT_STATUS_INVALID_LEVEL
);
372 return tevent_req_post(req
, ev
);
374 state
->info_level
= SMB2_FILE_POSIX_INFORMATION
;
377 tevent_req_nterror(req
, NT_STATUS_INVALID_INFO_CLASS
);
378 return tevent_req_post(req
, ev
);
381 if (in_flags
& SMB2_CONTINUE_FLAG_REOPEN
) {
382 struct vfs_open_how how
= { .flags
= O_RDONLY
, };
384 status
= fd_close(fsp
);
385 if (tevent_req_nterror(req
, status
)) {
386 return tevent_req_post(req
, ev
);
390 * fd_close() will close and invalidate the fsp's file
391 * descriptor. So we have to reopen it.
395 how
.flags
|= O_DIRECTORY
;
397 status
= fd_openat(conn
->cwd_fsp
, fsp
->fsp_name
, fsp
, &how
);
398 if (tevent_req_nterror(req
, status
)) {
399 return tevent_req_post(req
, ev
);
403 if (!state
->smbreq
->posix_pathnames
) {
404 wcard_has_wild
= ms_has_wild(state
->in_file_name
);
407 /* Ensure we've canonicalized any search path if not a wildcard. */
408 if (!wcard_has_wild
) {
410 * We still need to do the case processing
411 * to save off the client-supplied last component.
412 * At least we know there's no @GMT normalization
413 * or MS-DFS paths to do in a directory mask.
415 state
->in_file_name
= get_original_lcomp(state
,
419 if (tevent_req_nomem(state
->in_file_name
, req
)) {
420 return tevent_req_post(req
, ev
);
424 if (fsp
->dptr
== NULL
) {
425 status
= dptr_create(conn
,
428 false, /* old_handle */
429 state
->in_file_name
, /* wcard */
432 if (!NT_STATUS_IS_OK(status
)) {
433 tevent_req_nterror(req
, status
);
434 return tevent_req_post(req
, ev
);
437 state
->empty_status
= NT_STATUS_NO_SUCH_FILE
;
439 state
->empty_status
= STATUS_NO_MORE_FILES
;
442 if (in_flags
& SMB2_CONTINUE_FLAG_RESTART
) {
443 dptr_SeekDir(fsp
->dptr
, 0);
446 if (in_flags
& SMB2_CONTINUE_FLAG_SINGLE
) {
447 state
->max_count
= 1;
449 state
->max_count
= UINT16_MAX
;
452 #define DIR_ENTRY_SAFETY_MARGIN 4096
454 state
->out_output_buffer
= data_blob_talloc(state
, NULL
,
455 in_output_buffer_length
+ DIR_ENTRY_SAFETY_MARGIN
);
456 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
457 return tevent_req_post(req
, ev
);
460 state
->out_output_buffer
.length
= 0;
461 state
->pdata
= (char *)state
->out_output_buffer
.data
;
462 state
->base_data
= state
->pdata
;
464 * end_data must include the safety margin as it's what is
465 * used to determine if pushed strings have been truncated.
467 state
->end_data
= state
->pdata
+ in_output_buffer_length
+ DIR_ENTRY_SAFETY_MARGIN
- 1;
469 DEBUG(8,("smbd_smb2_query_directory_send: dirpath=<%s> dontdescend=<%s>, "
470 "in_output_buffer_length = %u\n",
471 fsp
->fsp_name
->base_name
, lp_dont_descend(talloc_tos(), lp_sub
, SNUM(conn
)),
472 (unsigned int)in_output_buffer_length
));
473 if (in_list(fsp
->fsp_name
->base_name
,lp_dont_descend(talloc_tos(), lp_sub
, SNUM(conn
)),
474 posix_dir_handle
? true : conn
->case_sensitive
)) {
475 state
->dont_descend
= true;
479 * SMB_FIND_FILE_NAMES_INFO doesn't need stat information
481 * This may change when we try to improve the delete on close
482 * handling in future.
484 if (state
->info_level
!= SMB_FIND_FILE_NAMES_INFO
) {
485 state
->ask_sharemode
= fsp_search_ask_sharemode(fsp
);
487 state
->async_dosmode
= lp_smbd_async_dosmode(SNUM(conn
));
490 if (state
->ask_sharemode
&& lp_clustering()) {
491 state
->ask_sharemode
= false;
492 state
->async_ask_sharemode
= true;
495 if (state
->async_dosmode
) {
498 max_threads
= pthreadpool_tevent_max_threads(conn
->sconn
->pool
);
499 if (max_threads
== 0 || !per_thread_cwd_supported()) {
500 state
->async_dosmode
= false;
503 state
->max_async_dosmode_active
= lp_smbd_max_async_dosmode(
505 if (state
->max_async_dosmode_active
== 0) {
506 state
->max_async_dosmode_active
= max_threads
* 2;
510 if (state
->async_dosmode
|| state
->async_ask_sharemode
) {
512 * Should we only set async_internal
513 * if we're not the last request in
516 smb2_request_set_async_internal(smb2req
, true);
520 * This gets set in autobuild for some tests
522 state
->find_async_delay_usec
= lp_parm_ulong(SNUM(conn
), "smbd",
523 "find async delay usec",
527 stop
= smb2_query_directory_next_entry(req
);
530 if (!tevent_req_is_in_progress(req
)) {
531 return tevent_req_post(req
, ev
);
534 ok
= aio_add_req_to_fsp(fsp
, req
);
536 DBG_ERR("Could not add req to fsp\n");
537 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
538 return tevent_req_post(req
, ev
);
544 static bool smb2_query_directory_next_entry(struct tevent_req
*req
)
546 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
547 req
, struct smbd_smb2_query_directory_state
);
548 struct smb_filename
*smb_fname
= NULL
; /* relative to fsp !! */
549 bool got_exact_match
= false;
550 int off
= state
->out_output_buffer
.length
;
551 int space_remaining
= state
->in_output_buffer_length
- off
;
552 struct file_id file_id
;
554 bool get_dosmode
= !state
->async_dosmode
;
557 SMB_ASSERT(space_remaining
>= 0);
559 status
= smbd_dirptr_lanman2_entry(state
,
562 state
->smbreq
->flags2
,
566 false, /* requires_resume_key */
568 state
->ask_sharemode
,
570 8, /* align to 8 bytes */
571 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
591 } else if (state
->num
> 0) {
592 goto last_entry_done
;
593 } else if (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
594 tevent_req_nterror(req
, NT_STATUS_INFO_LENGTH_MISMATCH
);
597 tevent_req_nterror(req
, state
->empty_status
);
602 if (state
->async_ask_sharemode
&&
603 !S_ISDIR(smb_fname
->st
.st_ex_mode
))
605 struct tevent_req
*subreq
= NULL
;
606 char *buf
= state
->base_data
+ state
->last_entry_off
;
608 subreq
= fetch_write_time_send(state
,
615 if (tevent_req_nomem(subreq
, req
)) {
618 tevent_req_set_callback(
620 smb2_query_directory_fetch_write_time_done
,
622 state
->async_sharemode_count
++;
625 if (state
->async_dosmode
) {
626 struct tevent_req
*subreq
= NULL
;
628 size_t outstanding_aio
;
630 buf
= (uint8_t *)state
->base_data
+ state
->last_entry_off
;
632 subreq
= fetch_dos_mode_send(state
,
638 if (tevent_req_nomem(subreq
, req
)) {
641 tevent_req_set_callback(subreq
,
642 smb2_query_directory_dos_mode_done
,
645 state
->async_dosmode_active
++;
647 outstanding_aio
= pthreadpool_tevent_queued_jobs(
648 state
->fsp
->conn
->sconn
->pool
);
650 if (outstanding_aio
> state
->max_async_dosmode_active
) {
655 TALLOC_FREE(smb_fname
);
658 state
->out_output_buffer
.length
= off
;
660 if (!state
->done
&& state
->num
< state
->max_count
) {
665 SIVAL(state
->out_output_buffer
.data
, state
->last_entry_off
, 0);
669 if (state
->async_sharemode_count
> 0) {
670 DBG_DEBUG("Stopping after %"PRIu64
" async mtime "
671 "updates\n", state
->async_sharemode_count
);
675 if (state
->async_dosmode_active
> 0) {
679 if (state
->find_async_delay_usec
> 0) {
681 struct tevent_req
*subreq
= NULL
;
684 * Should we only set async_internal
685 * if we're not the last request in
688 smb2_request_set_async_internal(state
->smb2req
, true);
690 tv
= timeval_current_ofs(0, state
->find_async_delay_usec
);
692 subreq
= tevent_wakeup_send(state
, state
->ev
, tv
);
693 if (tevent_req_nomem(subreq
, req
)) {
696 tevent_req_set_callback(subreq
,
697 smb2_query_directory_waited
,
702 tevent_req_done(req
);
706 static void smb2_query_directory_check_next_entry(struct tevent_req
*req
);
708 static void smb2_query_directory_fetch_write_time_done(struct tevent_req
*subreq
)
710 struct tevent_req
*req
= tevent_req_callback_data(
711 subreq
, struct tevent_req
);
712 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
713 req
, struct smbd_smb2_query_directory_state
);
718 * Make sure we run as the user again
720 ok
= change_to_user_and_service_by_fsp(state
->fsp
);
723 state
->async_sharemode_count
--;
725 status
= fetch_write_time_recv(subreq
);
727 if (tevent_req_nterror(req
, status
)) {
731 smb2_query_directory_check_next_entry(req
);
735 static void smb2_query_directory_dos_mode_done(struct tevent_req
*subreq
)
737 struct tevent_req
*req
=
738 tevent_req_callback_data(subreq
,
740 struct smbd_smb2_query_directory_state
*state
=
742 struct smbd_smb2_query_directory_state
);
747 * Make sure we run as the user again
749 ok
= change_to_user_and_service_by_fsp(state
->fsp
);
752 status
= fetch_dos_mode_recv(subreq
);
754 if (tevent_req_nterror(req
, status
)) {
758 state
->async_dosmode_active
--;
760 smb2_query_directory_check_next_entry(req
);
764 static void smb2_query_directory_check_next_entry(struct tevent_req
*req
)
766 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
767 req
, struct smbd_smb2_query_directory_state
);
772 stop
= smb2_query_directory_next_entry(req
);
777 if (state
->async_sharemode_count
> 0 ||
778 state
->async_dosmode_active
> 0)
783 if (state
->find_async_delay_usec
> 0) {
785 struct tevent_req
*subreq
= NULL
;
787 tv
= timeval_current_ofs(0, state
->find_async_delay_usec
);
789 subreq
= tevent_wakeup_send(state
, state
->ev
, tv
);
790 if (tevent_req_nomem(subreq
, req
)) {
791 tevent_req_post(req
, state
->ev
);
794 tevent_req_set_callback(subreq
,
795 smb2_query_directory_waited
,
800 tevent_req_done(req
);
804 static void smb2_query_directory_waited(struct tevent_req
*subreq
)
806 struct tevent_req
*req
= tevent_req_callback_data(
807 subreq
, struct tevent_req
);
810 ok
= tevent_wakeup_recv(subreq
);
816 tevent_req_done(req
);
819 static NTSTATUS
smbd_smb2_query_directory_recv(struct tevent_req
*req
,
821 DATA_BLOB
*out_output_buffer
)
824 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(req
,
825 struct smbd_smb2_query_directory_state
);
827 if (tevent_req_is_nterror(req
, &status
)) {
828 tevent_req_received(req
);
832 *out_output_buffer
= state
->out_output_buffer
;
833 talloc_steal(mem_ctx
, out_output_buffer
->data
);
835 tevent_req_received(req
);
839 struct fetch_write_time_state
{
840 connection_struct
*conn
;
843 char *entry_marshall_buf
;
846 static void fetch_write_time_done(struct tevent_req
*subreq
);
848 static struct tevent_req
*fetch_write_time_send(TALLOC_CTX
*mem_ctx
,
849 struct tevent_context
*ev
,
850 connection_struct
*conn
,
853 char *entry_marshall_buf
,
856 struct tevent_req
*req
= NULL
;
857 struct fetch_write_time_state
*state
= NULL
;
858 struct tevent_req
*subreq
= NULL
;
863 req
= tevent_req_create(mem_ctx
, &state
, struct fetch_write_time_state
);
868 *state
= (struct fetch_write_time_state
) {
871 .info_level
= info_level
,
872 .entry_marshall_buf
= entry_marshall_buf
,
875 subreq
= fetch_share_mode_send(state
, ev
, id
, &req_queued
);
876 if (tevent_req_nomem(subreq
, req
)) {
877 return tevent_req_post(req
, ev
);
879 tevent_req_set_callback(subreq
, fetch_write_time_done
, req
);
887 static void fetch_write_time_done(struct tevent_req
*subreq
)
889 struct tevent_req
*req
= tevent_req_callback_data(
890 subreq
, struct tevent_req
);
891 struct fetch_write_time_state
*state
= tevent_req_data(
892 req
, struct fetch_write_time_state
);
893 struct timespec write_time
;
894 struct share_mode_lock
*lck
= NULL
;
898 status
= fetch_share_mode_recv(subreq
, state
, &lck
);
900 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
901 tevent_req_done(req
);
904 if (tevent_req_nterror(req
, status
)) {
908 write_time
= get_share_mode_write_time(lck
);
911 if (is_omit_timespec(&write_time
)) {
912 tevent_req_done(req
);
916 switch (state
->info_level
) {
917 case SMB_FIND_FILE_DIRECTORY_INFO
:
918 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
919 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
920 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
921 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
926 DBG_ERR("Unsupported info_level [%d]\n", state
->info_level
);
927 tevent_req_nterror(req
, NT_STATUS_INVALID_LEVEL
);
931 put_long_date_full_timespec(state
->conn
->ts_res
,
932 state
->entry_marshall_buf
+ off
,
935 tevent_req_done(req
);
939 static NTSTATUS
fetch_write_time_recv(struct tevent_req
*req
)
943 if (tevent_req_is_nterror(req
, &status
)) {
944 tevent_req_received(req
);
948 tevent_req_received(req
);
952 struct fetch_dos_mode_state
{
953 struct files_struct
*dir_fsp
;
954 struct smb_filename
*smb_fname
;
956 uint8_t *entry_marshall_buf
;
959 static void fetch_dos_mode_done(struct tevent_req
*subreq
);
961 static struct tevent_req
*fetch_dos_mode_send(
963 struct tevent_context
*ev
,
964 struct files_struct
*dir_fsp
,
965 struct smb_filename
**smb_fname
,
967 uint8_t *entry_marshall_buf
)
969 struct tevent_req
*req
= NULL
;
970 struct fetch_dos_mode_state
*state
= NULL
;
971 struct tevent_req
*subreq
= NULL
;
973 req
= tevent_req_create(mem_ctx
, &state
, struct fetch_dos_mode_state
);
977 *state
= (struct fetch_dos_mode_state
) {
979 .info_level
= info_level
,
980 .entry_marshall_buf
= entry_marshall_buf
,
983 state
->smb_fname
= talloc_move(state
, smb_fname
);
985 subreq
= dos_mode_at_send(state
, ev
, dir_fsp
, state
->smb_fname
);
986 if (tevent_req_nomem(subreq
, req
)) {
987 return tevent_req_post(req
, ev
);
989 tevent_req_set_callback(subreq
, fetch_dos_mode_done
, req
);
994 static void fetch_dos_mode_done(struct tevent_req
*subreq
)
996 struct tevent_req
*req
=
997 tevent_req_callback_data(subreq
,
999 struct fetch_dos_mode_state
*state
=
1000 tevent_req_data(req
,
1001 struct fetch_dos_mode_state
);
1002 uint32_t dfs_dosmode
;
1004 struct timespec btime_ts
= {0};
1009 status
= dos_mode_at_recv(subreq
, &dosmode
);
1010 TALLOC_FREE(subreq
);
1011 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
1012 tevent_req_done(req
);
1015 if (tevent_req_nterror(req
, status
)) {
1019 switch (state
->info_level
) {
1020 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
1021 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
1022 case SMB_FIND_FILE_DIRECTORY_INFO
:
1023 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
1024 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
1030 DBG_ERR("Unsupported info_level [%u]\n", state
->info_level
);
1031 tevent_req_nterror(req
, NT_STATUS_INVALID_LEVEL
);
1036 dfs_dosmode
= IVAL(state
->entry_marshall_buf
, dosmode_off
);
1037 if (dfs_dosmode
== 0) {
1039 * DOS mode for a DFS link, only overwrite if still set to 0 and
1040 * not already populated by the lower layer for a DFS link in
1041 * smbd_dirptr_lanman2_mode_fn().
1043 SIVAL(state
->entry_marshall_buf
, dosmode_off
, dosmode
);
1046 btime_ts
= get_create_timespec(state
->dir_fsp
->conn
,
1049 if (lp_dos_filetime_resolution(SNUM(state
->dir_fsp
->conn
))) {
1050 dos_filetime_timespec(&btime_ts
);
1053 put_long_date_full_timespec(state
->dir_fsp
->conn
->ts_res
,
1054 (char *)state
->entry_marshall_buf
+ btime_off
,
1057 tevent_req_done(req
);
1061 static NTSTATUS
fetch_dos_mode_recv(struct tevent_req
*req
)
1065 if (tevent_req_is_nterror(req
, &status
)) {
1066 tevent_req_received(req
);
1070 tevent_req_received(req
);
1071 return NT_STATUS_OK
;