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 "smbd/smbd.h"
23 #include "smbd/globals.h"
24 #include "../libcli/smb/smb_common.h"
26 #include "../lib/util/tevent_ntstatus.h"
27 #include "system/filesys.h"
28 #include "lib/pthreadpool/pthreadpool_tevent.h"
31 #define DBGC_CLASS DBGC_SMB2
33 static struct tevent_req
*smbd_smb2_query_directory_send(TALLOC_CTX
*mem_ctx
,
34 struct tevent_context
*ev
,
35 struct smbd_smb2_request
*smb2req
,
36 struct files_struct
*in_fsp
,
37 uint8_t in_file_info_class
,
39 uint32_t in_file_index
,
40 uint32_t in_output_buffer_length
,
41 const char *in_file_name
);
42 static NTSTATUS
smbd_smb2_query_directory_recv(struct tevent_req
*req
,
44 DATA_BLOB
*out_output_buffer
);
46 static void smbd_smb2_request_find_done(struct tevent_req
*subreq
);
47 NTSTATUS
smbd_smb2_request_process_query_directory(struct smbd_smb2_request
*req
)
50 const uint8_t *inbody
;
51 uint8_t in_file_info_class
;
53 uint32_t in_file_index
;
54 uint64_t in_file_id_persistent
;
55 uint64_t in_file_id_volatile
;
56 struct files_struct
*in_fsp
;
57 uint16_t in_file_name_offset
;
58 uint16_t in_file_name_length
;
59 DATA_BLOB in_file_name_buffer
;
60 char *in_file_name_string
;
61 size_t in_file_name_string_size
;
62 uint32_t in_output_buffer_length
;
63 struct tevent_req
*subreq
;
66 status
= smbd_smb2_request_verify_sizes(req
, 0x21);
67 if (!NT_STATUS_IS_OK(status
)) {
68 return smbd_smb2_request_error(req
, status
);
70 inbody
= SMBD_SMB2_IN_BODY_PTR(req
);
72 in_file_info_class
= CVAL(inbody
, 0x02);
73 in_flags
= CVAL(inbody
, 0x03);
74 in_file_index
= IVAL(inbody
, 0x04);
75 in_file_id_persistent
= BVAL(inbody
, 0x08);
76 in_file_id_volatile
= BVAL(inbody
, 0x10);
77 in_file_name_offset
= SVAL(inbody
, 0x18);
78 in_file_name_length
= SVAL(inbody
, 0x1A);
79 in_output_buffer_length
= IVAL(inbody
, 0x1C);
81 if (in_file_name_offset
== 0 && in_file_name_length
== 0) {
83 } else if (in_file_name_offset
!=
84 (SMB2_HDR_BODY
+ SMBD_SMB2_IN_BODY_LEN(req
))) {
85 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
88 if (in_file_name_length
> SMBD_SMB2_IN_DYN_LEN(req
)) {
89 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
92 /* The output header is 8 bytes. */
93 if (in_output_buffer_length
<= 8) {
94 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
97 DEBUG(10,("smbd_smb2_request_find_done: in_output_buffer_length = %u\n",
98 (unsigned int)in_output_buffer_length
));
100 /* Take into account the output header. */
101 in_output_buffer_length
-= 8;
103 in_file_name_buffer
.data
= SMBD_SMB2_IN_DYN_PTR(req
);
104 in_file_name_buffer
.length
= in_file_name_length
;
106 ok
= convert_string_talloc(req
, CH_UTF16
, CH_UNIX
,
107 in_file_name_buffer
.data
,
108 in_file_name_buffer
.length
,
109 &in_file_name_string
,
110 &in_file_name_string_size
);
112 return smbd_smb2_request_error(req
, NT_STATUS_ILLEGAL_CHARACTER
);
115 if (in_file_name_buffer
.length
== 0) {
116 in_file_name_string_size
= 0;
119 if (strlen(in_file_name_string
) != in_file_name_string_size
) {
120 return smbd_smb2_request_error(req
, NT_STATUS_OBJECT_NAME_INVALID
);
123 in_fsp
= file_fsp_smb2(req
, in_file_id_persistent
, in_file_id_volatile
);
124 if (in_fsp
== NULL
) {
125 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
128 subreq
= smbd_smb2_query_directory_send(req
, req
->ev_ctx
,
133 in_output_buffer_length
,
134 in_file_name_string
);
135 if (subreq
== NULL
) {
136 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
138 tevent_req_set_callback(subreq
, smbd_smb2_request_find_done
, req
);
140 return smbd_smb2_request_pending_queue(req
, subreq
, 500);
143 static void smbd_smb2_request_find_done(struct tevent_req
*subreq
)
145 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
146 struct smbd_smb2_request
);
149 uint16_t out_output_buffer_offset
;
150 DATA_BLOB out_output_buffer
= data_blob_null
;
152 NTSTATUS error
; /* transport error */
154 status
= smbd_smb2_query_directory_recv(subreq
,
158 if (!NT_STATUS_IS_OK(status
)) {
159 error
= smbd_smb2_request_error(req
, status
);
160 if (!NT_STATUS_IS_OK(error
)) {
161 smbd_server_connection_terminate(req
->xconn
,
168 out_output_buffer_offset
= SMB2_HDR_BODY
+ 0x08;
170 outbody
= smbd_smb2_generate_outbody(req
, 0x08);
171 if (outbody
.data
== NULL
) {
172 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
173 if (!NT_STATUS_IS_OK(error
)) {
174 smbd_server_connection_terminate(req
->xconn
,
181 SSVAL(outbody
.data
, 0x00, 0x08 + 1); /* struct size */
182 SSVAL(outbody
.data
, 0x02,
183 out_output_buffer_offset
); /* output buffer offset */
184 SIVAL(outbody
.data
, 0x04,
185 out_output_buffer
.length
); /* output buffer length */
187 DEBUG(10,("smbd_smb2_request_find_done: out_output_buffer.length = %u\n",
188 (unsigned int)out_output_buffer
.length
));
190 outdyn
= out_output_buffer
;
192 error
= smbd_smb2_request_done(req
, outbody
, &outdyn
);
193 if (!NT_STATUS_IS_OK(error
)) {
194 smbd_server_connection_terminate(req
->xconn
,
200 static struct tevent_req
*fetch_write_time_send(TALLOC_CTX
*mem_ctx
,
201 struct tevent_context
*ev
,
202 connection_struct
*conn
,
205 char *entry_marshall_buf
,
207 static NTSTATUS
fetch_write_time_recv(struct tevent_req
*req
);
209 static struct tevent_req
*fetch_dos_mode_send(
211 struct smb_vfs_ev_glue
*evg
,
212 struct files_struct
*dir_fsp
,
213 struct smb_filename
**smb_fname
,
215 uint8_t *entry_marshall_buf
);
217 static NTSTATUS
fetch_dos_mode_recv(struct tevent_req
*req
);
219 struct smbd_smb2_query_directory_state
{
220 struct smb_vfs_ev_glue
*evg
;
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 struct pthreadpool_tevent
*tp_chdir_safe
;
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
;
269 bool wcard_has_wild
= false;
275 req
= tevent_req_create(mem_ctx
, &state
,
276 struct smbd_smb2_query_directory_state
);
280 state
->evg
= conn
->user_vfs_evg
;
282 state
->tp_chdir_safe
= smb_vfs_ev_glue_tp_chdir_safe(state
->evg
);
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
);
294 if (tevent_req_nomem(state
->smbreq
, req
)) {
295 return tevent_req_post(req
, ev
);
298 if (!fsp
->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
;
370 tevent_req_nterror(req
, NT_STATUS_INVALID_INFO_CLASS
);
371 return tevent_req_post(req
, ev
);
374 if (in_flags
& SMB2_CONTINUE_FLAG_REOPEN
) {
377 status
= fd_close(fsp
);
378 if (tevent_req_nterror(req
, status
)) {
379 return tevent_req_post(req
, ev
);
383 * fd_close() will close and invalidate the fsp's file
384 * descriptor. So we have to reopen it.
389 flags
|= O_DIRECTORY
;
391 status
= fd_open(conn
, fsp
, flags
, 0);
392 if (tevent_req_nterror(req
, status
)) {
393 return tevent_req_post(req
, ev
);
397 if (!state
->smbreq
->posix_pathnames
) {
398 wcard_has_wild
= ms_has_wild(state
->in_file_name
);
401 /* Ensure we've canonicalized any search path if not a wildcard. */
402 if (!wcard_has_wild
) {
403 struct smb_filename
*smb_fname
= NULL
;
404 const char *fullpath
;
405 char tmpbuf
[PATH_MAX
];
406 char *to_free
= NULL
;
407 uint32_t ucf_flags
= UCF_SAVE_LCOMP
|
408 UCF_ALWAYS_ALLOW_WCARD_LCOMP
|
409 (state
->smbreq
->posix_pathnames
?
410 UCF_POSIX_PATHNAMES
: 0);
412 if (ISDOT(fsp
->fsp_name
->base_name
)) {
413 fullpath
= state
->in_file_name
;
419 fsp
->fsp_name
->base_name
, state
->in_file_name
,
420 tmpbuf
, sizeof(tmpbuf
), &tmp
, &to_free
);
423 return tevent_req_post(req
, ev
);
427 status
= filename_convert(state
,
435 TALLOC_FREE(to_free
);
437 if (tevent_req_nterror(req
, status
)) {
438 return tevent_req_post(req
, ev
);
441 state
->in_file_name
= smb_fname
->original_lcomp
;
444 if (fsp
->dptr
== NULL
) {
445 status
= dptr_create(conn
,
449 false, /* old_handle */
450 false, /* expect_close */
452 state
->in_file_name
, /* wcard */
456 if (!NT_STATUS_IS_OK(status
)) {
457 tevent_req_nterror(req
, status
);
458 return tevent_req_post(req
, ev
);
461 state
->empty_status
= NT_STATUS_NO_SUCH_FILE
;
463 state
->empty_status
= STATUS_NO_MORE_FILES
;
466 if (in_flags
& SMB2_CONTINUE_FLAG_RESTART
) {
467 dptr_SeekDir(fsp
->dptr
, 0);
470 if (in_flags
& SMB2_CONTINUE_FLAG_SINGLE
) {
471 state
->max_count
= 1;
473 state
->max_count
= UINT16_MAX
;
476 #define DIR_ENTRY_SAFETY_MARGIN 4096
478 state
->out_output_buffer
= data_blob_talloc(state
, NULL
,
479 in_output_buffer_length
+ DIR_ENTRY_SAFETY_MARGIN
);
480 if (tevent_req_nomem(state
->out_output_buffer
.data
, req
)) {
481 return tevent_req_post(req
, ev
);
484 state
->out_output_buffer
.length
= 0;
485 state
->pdata
= (char *)state
->out_output_buffer
.data
;
486 state
->base_data
= state
->pdata
;
488 * end_data must include the safety margin as it's what is
489 * used to determine if pushed strings have been truncated.
491 state
->end_data
= state
->pdata
+ in_output_buffer_length
+ DIR_ENTRY_SAFETY_MARGIN
- 1;
493 DEBUG(8,("smbd_smb2_query_directory_send: dirpath=<%s> dontdescend=<%s>, "
494 "in_output_buffer_length = %u\n",
495 fsp
->fsp_name
->base_name
, lp_dont_descend(talloc_tos(), SNUM(conn
)),
496 (unsigned int)in_output_buffer_length
));
497 if (in_list(fsp
->fsp_name
->base_name
,lp_dont_descend(talloc_tos(), SNUM(conn
)),
498 conn
->case_sensitive
)) {
499 state
->dont_descend
= true;
503 * SMB_FIND_FILE_NAMES_INFO doesn't need stat information
505 * This may change when we try to improve the delete on close
506 * handling in future.
508 if (state
->info_level
!= SMB_FIND_FILE_NAMES_INFO
) {
509 state
->ask_sharemode
= lp_smbd_search_ask_sharemode(SNUM(conn
));
511 state
->async_dosmode
= lp_parm_bool(
512 SNUM(conn
), "smbd", "async dosmode", false);
515 if (state
->ask_sharemode
&& lp_clustering()) {
516 state
->ask_sharemode
= false;
517 state
->async_ask_sharemode
= true;
520 if (state
->async_dosmode
) {
523 max_threads
= pthreadpool_tevent_max_threads(state
->tp_chdir_safe
);
525 state
->max_async_dosmode_active
= lp_parm_ulong(
526 SNUM(conn
), "smbd", "max async dosmode",
529 if (state
->max_async_dosmode_active
== 0) {
530 state
->max_async_dosmode_active
= 1;
534 if (state
->async_dosmode
|| state
->async_ask_sharemode
) {
536 * Should we only set async_internal
537 * if we're not the last request in
540 smb2_request_set_async_internal(smb2req
, true);
544 * This gets set in autobuild for some tests
546 state
->find_async_delay_usec
= lp_parm_ulong(SNUM(conn
), "smbd",
547 "find async delay usec",
551 stop
= smb2_query_directory_next_entry(req
);
554 if (!tevent_req_is_in_progress(req
)) {
555 return tevent_req_post(req
, ev
);
558 ok
= aio_add_req_to_fsp(fsp
, req
);
560 DBG_ERR("Could not add req to fsp\n");
561 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
562 return tevent_req_post(req
, ev
);
568 static bool smb2_query_directory_next_entry(struct tevent_req
*req
)
570 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
571 req
, struct smbd_smb2_query_directory_state
);
572 struct smb_filename
*smb_fname
= NULL
; /* relative to fsp !! */
573 bool got_exact_match
= false;
574 int off
= state
->out_output_buffer
.length
;
575 int space_remaining
= state
->in_output_buffer_length
- off
;
576 struct file_id file_id
;
578 bool get_dosmode
= !state
->async_dosmode
;
581 SMB_ASSERT(space_remaining
>= 0);
583 status
= smbd_dirptr_lanman2_entry(state
,
586 state
->smbreq
->flags2
,
590 false, /* requires_resume_key */
592 state
->ask_sharemode
,
594 8, /* align to 8 bytes */
595 false, /* no padding */
602 &state
->last_entry_off
,
606 off
= (int)PTR_DIFF(state
->pdata
, state
->base_data
);
608 if (!NT_STATUS_IS_OK(status
)) {
609 if (NT_STATUS_EQUAL(status
, NT_STATUS_ILLEGAL_CHARACTER
)) {
611 * Bad character conversion on name. Ignore this
615 } else if (state
->num
> 0) {
616 goto last_entry_done
;
617 } else if (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
618 tevent_req_nterror(req
, NT_STATUS_INFO_LENGTH_MISMATCH
);
621 tevent_req_nterror(req
, state
->empty_status
);
626 if (state
->async_ask_sharemode
) {
627 struct tevent_req
*subreq
= NULL
;
628 char *buf
= state
->base_data
+ state
->last_entry_off
;
630 subreq
= fetch_write_time_send(state
,
637 if (tevent_req_nomem(subreq
, req
)) {
640 tevent_req_set_callback(
642 smb2_query_directory_fetch_write_time_done
,
644 state
->async_sharemode_count
++;
647 if (state
->async_dosmode
) {
648 struct tevent_req
*subreq
= NULL
;
650 size_t outstanding_aio
;
652 buf
= (uint8_t *)state
->base_data
+ state
->last_entry_off
;
654 subreq
= fetch_dos_mode_send(state
,
660 if (tevent_req_nomem(subreq
, req
)) {
663 tevent_req_set_callback(subreq
,
664 smb2_query_directory_dos_mode_done
,
667 state
->async_dosmode_active
++;
669 outstanding_aio
= pthreadpool_tevent_queued_jobs(
670 state
->tp_chdir_safe
);
672 if (outstanding_aio
> state
->max_async_dosmode_active
) {
677 TALLOC_FREE(smb_fname
);
680 state
->out_output_buffer
.length
= off
;
682 if (!state
->done
&& state
->num
< state
->max_count
) {
687 SIVAL(state
->out_output_buffer
.data
, state
->last_entry_off
, 0);
691 if (state
->async_sharemode_count
> 0) {
692 DBG_DEBUG("Stopping after %"PRIu64
" async mtime "
693 "updates\n", state
->async_sharemode_count
);
697 if (state
->async_dosmode_active
> 0) {
701 if (state
->find_async_delay_usec
> 0) {
703 struct tevent_req
*subreq
= NULL
;
706 * Should we only set async_internal
707 * if we're not the last request in
710 smb2_request_set_async_internal(state
->smb2req
, true);
712 tv
= timeval_current_ofs(0, state
->find_async_delay_usec
);
714 subreq
= tevent_wakeup_send(state
, state
->ev
, tv
);
715 if (tevent_req_nomem(subreq
, req
)) {
718 tevent_req_set_callback(subreq
,
719 smb2_query_directory_waited
,
724 tevent_req_done(req
);
728 static void smb2_query_directory_check_next_entry(struct tevent_req
*req
);
730 static void smb2_query_directory_fetch_write_time_done(struct tevent_req
*subreq
)
732 struct tevent_req
*req
= tevent_req_callback_data(
733 subreq
, struct tevent_req
);
734 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
735 req
, struct smbd_smb2_query_directory_state
);
738 state
->async_sharemode_count
--;
740 status
= fetch_write_time_recv(subreq
);
742 if (tevent_req_nterror(req
, status
)) {
746 smb2_query_directory_check_next_entry(req
);
750 static void smb2_query_directory_dos_mode_done(struct tevent_req
*subreq
)
752 struct tevent_req
*req
=
753 tevent_req_callback_data(subreq
,
755 struct smbd_smb2_query_directory_state
*state
=
757 struct smbd_smb2_query_directory_state
);
760 status
= fetch_dos_mode_recv(subreq
);
762 if (tevent_req_nterror(req
, status
)) {
766 state
->async_dosmode_active
--;
768 smb2_query_directory_check_next_entry(req
);
772 static void smb2_query_directory_check_next_entry(struct tevent_req
*req
)
774 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(
775 req
, struct smbd_smb2_query_directory_state
);
780 stop
= smb2_query_directory_next_entry(req
);
785 if (state
->async_sharemode_count
> 0 ||
786 state
->async_dosmode_active
> 0)
791 if (state
->find_async_delay_usec
> 0) {
793 struct tevent_req
*subreq
= NULL
;
795 tv
= timeval_current_ofs(0, state
->find_async_delay_usec
);
797 subreq
= tevent_wakeup_send(state
, state
->ev
, tv
);
798 if (tevent_req_nomem(subreq
, req
)) {
799 tevent_req_post(req
, state
->ev
);
802 tevent_req_set_callback(subreq
,
803 smb2_query_directory_waited
,
808 tevent_req_done(req
);
812 static void smb2_query_directory_waited(struct tevent_req
*subreq
)
814 struct tevent_req
*req
= tevent_req_callback_data(
815 subreq
, struct tevent_req
);
818 ok
= tevent_wakeup_recv(subreq
);
824 tevent_req_done(req
);
827 static NTSTATUS
smbd_smb2_query_directory_recv(struct tevent_req
*req
,
829 DATA_BLOB
*out_output_buffer
)
832 struct smbd_smb2_query_directory_state
*state
= tevent_req_data(req
,
833 struct smbd_smb2_query_directory_state
);
835 if (tevent_req_is_nterror(req
, &status
)) {
836 tevent_req_received(req
);
840 *out_output_buffer
= state
->out_output_buffer
;
841 talloc_steal(mem_ctx
, out_output_buffer
->data
);
843 tevent_req_received(req
);
847 struct fetch_write_time_state
{
848 connection_struct
*conn
;
851 char *entry_marshall_buf
;
854 static void fetch_write_time_done(struct tevent_req
*subreq
);
856 static struct tevent_req
*fetch_write_time_send(TALLOC_CTX
*mem_ctx
,
857 struct tevent_context
*ev
,
858 connection_struct
*conn
,
861 char *entry_marshall_buf
,
864 struct tevent_req
*req
= NULL
;
865 struct fetch_write_time_state
*state
= NULL
;
866 struct tevent_req
*subreq
= NULL
;
871 req
= tevent_req_create(mem_ctx
, &state
, struct fetch_write_time_state
);
876 *state
= (struct fetch_write_time_state
) {
879 .info_level
= info_level
,
880 .entry_marshall_buf
= entry_marshall_buf
,
883 subreq
= fetch_share_mode_send(state
, ev
, id
, &req_queued
);
884 if (tevent_req_nomem(subreq
, req
)) {
885 return tevent_req_post(req
, ev
);
887 tevent_req_set_callback(subreq
, fetch_write_time_done
, req
);
895 static void fetch_write_time_done(struct tevent_req
*subreq
)
897 struct tevent_req
*req
= tevent_req_callback_data(
898 subreq
, struct tevent_req
);
899 struct fetch_write_time_state
*state
= tevent_req_data(
900 req
, struct fetch_write_time_state
);
901 struct timespec write_time
;
902 struct share_mode_lock
*lck
= NULL
;
906 status
= fetch_share_mode_recv(subreq
, state
, &lck
);
908 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
909 tevent_req_done(req
);
912 if (!NT_STATUS_IS_OK(status
)) {
913 tevent_req_nterror(req
, status
);
917 write_time
= get_share_mode_write_time(lck
);
920 if (null_timespec(write_time
)) {
921 tevent_req_done(req
);
925 switch (state
->info_level
) {
926 case SMB_FIND_FILE_DIRECTORY_INFO
:
927 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
928 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
929 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
930 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
935 DBG_ERR("Unsupported info_level [%d]\n", state
->info_level
);
936 tevent_req_nterror(req
, NT_STATUS_INVALID_LEVEL
);
940 put_long_date_timespec(state
->conn
->ts_res
,
941 state
->entry_marshall_buf
+ off
,
944 tevent_req_done(req
);
948 static NTSTATUS
fetch_write_time_recv(struct tevent_req
*req
)
952 if (tevent_req_is_nterror(req
, &status
)) {
953 tevent_req_received(req
);
957 tevent_req_received(req
);
961 struct fetch_dos_mode_state
{
962 struct files_struct
*dir_fsp
;
963 struct smb_filename
*smb_fname
;
965 uint8_t *entry_marshall_buf
;
968 static void fetch_dos_mode_done(struct tevent_req
*subreq
);
970 static struct tevent_req
*fetch_dos_mode_send(
972 struct smb_vfs_ev_glue
*evg
,
973 struct files_struct
*dir_fsp
,
974 struct smb_filename
**smb_fname
,
976 uint8_t *entry_marshall_buf
)
978 struct tevent_context
*ev
= smb_vfs_ev_glue_ev_ctx(evg
);
979 struct tevent_req
*req
= NULL
;
980 struct fetch_dos_mode_state
*state
= NULL
;
981 struct tevent_req
*subreq
= NULL
;
983 req
= tevent_req_create(mem_ctx
, &state
, struct fetch_dos_mode_state
);
987 *state
= (struct fetch_dos_mode_state
) {
989 .info_level
= info_level
,
990 .entry_marshall_buf
= entry_marshall_buf
,
993 state
->smb_fname
= talloc_move(state
, smb_fname
);
995 subreq
= dos_mode_at_send(state
, evg
, dir_fsp
, state
->smb_fname
);
996 if (tevent_req_nomem(subreq
, req
)) {
997 return tevent_req_post(req
, ev
);
999 tevent_req_set_callback(subreq
, fetch_dos_mode_done
, req
);
1004 static void fetch_dos_mode_done(struct tevent_req
*subreq
)
1006 struct tevent_req
*req
=
1007 tevent_req_callback_data(subreq
,
1009 struct fetch_dos_mode_state
*state
=
1010 tevent_req_data(req
,
1011 struct fetch_dos_mode_state
);
1012 uint32_t dfs_dosmode
;
1014 struct timespec btime_ts
= {0};
1019 status
= dos_mode_at_recv(subreq
, &dosmode
);
1020 TALLOC_FREE(subreq
);
1021 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
1022 tevent_req_done(req
);
1025 if (!NT_STATUS_IS_OK(status
)) {
1026 tevent_req_nterror(req
, status
);
1030 switch (state
->info_level
) {
1031 case SMB_FIND_ID_BOTH_DIRECTORY_INFO
:
1032 case SMB_FIND_FILE_BOTH_DIRECTORY_INFO
:
1033 case SMB_FIND_FILE_DIRECTORY_INFO
:
1034 case SMB_FIND_FILE_FULL_DIRECTORY_INFO
:
1035 case SMB_FIND_ID_FULL_DIRECTORY_INFO
:
1041 DBG_ERR("Unsupported info_level [%u]\n", state
->info_level
);
1042 tevent_req_nterror(req
, NT_STATUS_INVALID_LEVEL
);
1047 dfs_dosmode
= IVAL(state
->entry_marshall_buf
, dosmode_off
);
1048 if (dfs_dosmode
== 0) {
1050 * DOS mode for a DFS link, only overwrite if still set to 0 and
1051 * not already populated by the lower layer for a DFS link in
1052 * smbd_dirptr_lanman2_mode_fn().
1054 SIVAL(state
->entry_marshall_buf
, dosmode_off
, dosmode
);
1057 btime_ts
= get_create_timespec(state
->dir_fsp
->conn
,
1060 if (lp_dos_filetime_resolution(SNUM(state
->dir_fsp
->conn
))) {
1061 dos_filetime_timespec(&btime_ts
);
1064 put_long_date_timespec(state
->dir_fsp
->conn
->ts_res
,
1065 (char *)state
->entry_marshall_buf
+ btime_off
,
1068 tevent_req_done(req
);
1072 static NTSTATUS
fetch_dos_mode_recv(struct tevent_req
*req
)
1076 if (tevent_req_is_nterror(req
, &status
)) {
1077 tevent_req_received(req
);
1081 tevent_req_received(req
);
1082 return NT_STATUS_OK
;