2 Unix SMB/CIFS implementation.
3 Files[] structure handling
4 Copyright (C) Andrew Tridgell 1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "smbd/smbd.h"
22 #include "smbd/globals.h"
23 #include "smbd/smbXsrv_open.h"
24 #include "libcli/security/security.h"
26 #include "lib/util/bitmap.h"
27 #include "lib/util/strv.h"
28 #include "lib/util/memcache.h"
29 #include "libcli/smb/reparse.h"
31 #define FILE_HANDLE_OFFSET 0x1000
33 static NTSTATUS
fsp_attach_smb_fname(struct files_struct
*fsp
,
34 struct smb_filename
**_smb_fname
);
37 * create new fsp to be used for file_new or a durable handle reconnect
39 NTSTATUS
fsp_new(struct connection_struct
*conn
, TALLOC_CTX
*mem_ctx
,
40 files_struct
**result
)
42 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
43 files_struct
*fsp
= NULL
;
44 struct smbd_server_connection
*sconn
= conn
->sconn
;
46 fsp
= talloc_zero(mem_ctx
, struct files_struct
);
52 * This can't be a child of fsp because the file_handle can be ref'd
53 * when doing a dos/fcb open, which will then share the file_handle
54 * across multiple fsps.
56 fsp
->fh
= fd_handle_create(mem_ctx
);
57 if (fsp
->fh
== NULL
) {
61 fsp
->fsp_flags
.use_ofd_locks
= !lp_smbd_force_process_locks(SNUM(conn
));
62 #ifndef HAVE_OFD_LOCKS
63 fsp
->fsp_flags
.use_ofd_locks
= false;
66 fh_set_refcount(fsp
->fh
, 1);
69 fsp
->fnum
= FNUM_FIELD_INVALID
;
71 fsp
->close_write_time
= make_omit_timespec();
73 DLIST_ADD(sconn
->files
, fsp
);
74 sconn
->num_files
+= 1;
76 conn
->num_files_open
++;
78 DBG_INFO("allocated files structure (%u used)\n",
79 (unsigned int)sconn
->num_files
);
93 void fsp_set_gen_id(files_struct
*fsp
)
95 static uint64_t gen_id
= 1;
98 * A billion of 64-bit increments per second gives us
99 * more than 500 years of runtime without wrap.
102 fh_set_gen_id(fsp
->fh
, gen_id
);
105 /****************************************************************************
106 Find first available file slot.
107 ****************************************************************************/
109 NTSTATUS
fsp_bind_smb(struct files_struct
*fsp
, struct smb_request
*req
)
111 struct smbXsrv_open
*op
= NULL
;
116 DBG_DEBUG("INTERNAL_OPEN_ONLY, skipping smbXsrv_open\n");
120 now
= timeval_to_nttime(&fsp
->open_time
);
122 status
= smbXsrv_open_create(req
->xconn
,
123 fsp
->conn
->session_info
,
126 if (!NT_STATUS_IS_OK(status
)) {
131 fsp
->fnum
= op
->local_id
;
134 req
->chain_fsp
= fsp
;
136 DBG_DEBUG("fsp [%s] mid [%" PRIu64
"]\n",
137 fsp_str_dbg(fsp
), fsp
->mid
);
142 NTSTATUS
file_new(struct smb_request
*req
, connection_struct
*conn
,
143 files_struct
**result
)
145 struct smbd_server_connection
*sconn
= conn
->sconn
;
149 status
= fsp_new(conn
, conn
, &fsp
);
150 if (!NT_STATUS_IS_OK(status
)) {
154 GetTimeOfDay(&fsp
->open_time
);
156 status
= fsp_bind_smb(fsp
, req
);
157 if (!NT_STATUS_IS_OK(status
)) {
158 file_free(NULL
, fsp
);
165 * Create an smb_filename with "" for the base_name. There are very
166 * few NULL checks, so make sure it's initialized with something. to
167 * be safe until an audit can be done.
169 fsp
->fsp_name
= synthetic_smb_fname(fsp
,
175 if (fsp
->fsp_name
== NULL
) {
176 file_free(NULL
, fsp
);
177 return NT_STATUS_NO_MEMORY
;
180 DBG_INFO("new file %s\n", fsp_fnum_dbg(fsp
));
182 /* A new fsp invalidates the positive and
183 negative fsp_fi_cache as the new fsp is pushed
184 at the start of the list and we search from
185 a cache hit to the *end* of the list. */
187 ZERO_STRUCT(sconn
->fsp_fi_cache
);
193 NTSTATUS
create_internal_fsp(connection_struct
*conn
,
194 const struct smb_filename
*smb_fname
,
195 struct files_struct
**_fsp
)
197 struct files_struct
*fsp
= NULL
;
200 status
= file_new(NULL
, conn
, &fsp
);
201 if (!NT_STATUS_IS_OK(status
)) {
205 status
= fsp_set_smb_fname(fsp
, smb_fname
);
206 if (!NT_STATUS_IS_OK(status
)) {
207 file_free(NULL
, fsp
);
216 * Create an internal fsp for an *existing* directory.
218 * This should only be used by callers in the VFS that need to control the
219 * opening of the directory. Otherwise use open_internal_dirfsp().
221 NTSTATUS
create_internal_dirfsp(connection_struct
*conn
,
222 const struct smb_filename
*smb_dname
,
223 struct files_struct
**_fsp
)
225 struct files_struct
*fsp
= NULL
;
228 status
= create_internal_fsp(conn
, smb_dname
, &fsp
);
229 if (!NT_STATUS_IS_OK(status
)) {
233 fsp
->access_mask
= FILE_LIST_DIRECTORY
;
234 fsp
->fsp_flags
.is_directory
= true;
235 fsp
->fsp_flags
.is_dirfsp
= true;
242 * Open an internal fsp for an *existing* directory.
244 NTSTATUS
open_internal_dirfsp(connection_struct
*conn
,
245 const struct smb_filename
*smb_dname
,
247 struct files_struct
**_fsp
)
249 struct vfs_open_how how
= { .flags
= _open_flags
, };
250 struct files_struct
*fsp
= NULL
;
253 status
= create_internal_dirfsp(conn
, smb_dname
, &fsp
);
254 if (!NT_STATUS_IS_OK(status
)) {
259 how
.flags
|= O_DIRECTORY
;
261 status
= fd_openat(conn
->cwd_fsp
, fsp
->fsp_name
, fsp
, &how
);
262 if (!NT_STATUS_IS_OK(status
)) {
263 DBG_INFO("Could not open fd for %s (%s)\n",
264 smb_fname_str_dbg(smb_dname
),
266 file_free(NULL
, fsp
);
270 status
= vfs_stat_fsp(fsp
);
271 if (!NT_STATUS_IS_OK(status
)) {
272 file_free(NULL
, fsp
);
276 if (!S_ISDIR(fsp
->fsp_name
->st
.st_ex_mode
)) {
277 DBG_ERR("%s is not a directory!\n",
278 smb_fname_str_dbg(smb_dname
));
279 file_free(NULL
, fsp
);
280 return NT_STATUS_NOT_A_DIRECTORY
;
283 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &fsp
->fsp_name
->st
);
290 * Convert a pathref dirfsp into a real fsp. No need to do any cwd
291 * tricks, we just open ".".
293 NTSTATUS
openat_internal_dir_from_pathref(
294 struct files_struct
*dirfsp
,
296 struct files_struct
**_fsp
)
298 struct connection_struct
*conn
= dirfsp
->conn
;
299 struct smb_filename
*smb_dname
= dirfsp
->fsp_name
;
300 struct files_struct
*fsp
= NULL
;
302 struct smb_filename smb_dot
= {
304 .flags
= smb_dname
->flags
,
305 .twrp
= smb_dname
->twrp
,
307 struct vfs_open_how how
= { .flags
= _open_flags
, };
310 status
= create_internal_dirfsp(conn
, smb_dname
, &fsp
);
311 if (!NT_STATUS_IS_OK(status
)) {
316 * Pointless for opening ".", but you never know...
318 how
.flags
|= O_NOFOLLOW
;
320 status
= fd_openat(dirfsp
, &smb_dot
, fsp
, &how
);
321 if (!NT_STATUS_IS_OK(status
)) {
322 DBG_INFO("fd_openat(\"%s\", \".\") failed: %s\n",
325 file_free(NULL
, fsp
);
329 fsp
->fsp_name
->st
= smb_dname
->st
;
330 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &fsp
->fsp_name
->st
);
336 * The "link" in the name doesn't imply link in the filesystem
337 * sense. It's a object that "links" together an fsp and an smb_fname
338 * and the link allocated as talloc child of an fsp.
340 * The link is created for fsps that openat_pathref_fsp() returns in
341 * smb_fname->fsp. When this fsp is freed by file_free() by some caller
342 * somewhere, the destructor fsp_smb_fname_link_destructor() on the link object
343 * will use the link to reset the reference in smb_fname->fsp that is about to
346 * This prevents smb_fname_internal_fsp_destructor() from seeing dangling fsp
350 struct fsp_smb_fname_link
{
351 struct fsp_smb_fname_link
**smb_fname_link
;
352 struct files_struct
**smb_fname_fsp
;
355 static int fsp_smb_fname_link_destructor(struct fsp_smb_fname_link
*link
)
357 if (link
->smb_fname_link
== NULL
) {
361 *link
->smb_fname_link
= NULL
;
362 *link
->smb_fname_fsp
= NULL
;
366 static NTSTATUS
fsp_smb_fname_link(struct files_struct
*fsp
,
367 struct fsp_smb_fname_link
**smb_fname_link
,
368 struct files_struct
**smb_fname_fsp
)
370 struct fsp_smb_fname_link
*link
= NULL
;
372 SMB_ASSERT(*smb_fname_link
== NULL
);
373 SMB_ASSERT(*smb_fname_fsp
== NULL
);
375 link
= talloc_zero(fsp
, struct fsp_smb_fname_link
);
377 return NT_STATUS_NO_MEMORY
;
380 link
->smb_fname_link
= smb_fname_link
;
381 link
->smb_fname_fsp
= smb_fname_fsp
;
382 *smb_fname_link
= link
;
383 *smb_fname_fsp
= fsp
;
385 talloc_set_destructor(link
, fsp_smb_fname_link_destructor
);
390 * Free a link, carefully avoiding to trigger the link destructor
392 static void destroy_fsp_smb_fname_link(struct fsp_smb_fname_link
**_link
)
394 struct fsp_smb_fname_link
*link
= *_link
;
399 talloc_set_destructor(link
, NULL
);
405 * Talloc destructor set on an smb_fname set by openat_pathref_fsp() used to
406 * close the embedded smb_fname->fsp.
408 static int smb_fname_fsp_destructor(struct smb_filename
*smb_fname
)
410 struct files_struct
*fsp
= smb_fname
->fsp
;
411 struct files_struct
*base_fsp
= NULL
;
413 int saved_errno
= errno
;
415 destroy_fsp_smb_fname_link(&smb_fname
->fsp_link
);
422 if (fsp_is_alternate_stream(fsp
)) {
423 base_fsp
= fsp
->base_fsp
;
426 status
= fd_close(fsp
);
427 if (!NT_STATUS_IS_OK(status
)) {
428 DBG_ERR("Closing fd for fsp [%s] failed: %s. "
429 "Please check your filesystem!!!\n",
430 fsp_str_dbg(fsp
), nt_errstr(status
));
432 file_free(NULL
, fsp
);
433 smb_fname
->fsp
= NULL
;
435 if (base_fsp
!= NULL
) {
436 base_fsp
->stream_fsp
= NULL
;
437 status
= fd_close(base_fsp
);
438 if (!NT_STATUS_IS_OK(status
)) {
439 DBG_ERR("Closing fd for base_fsp [%s] failed: %s. "
440 "Please check your filesystem!!!\n",
441 fsp_str_dbg(base_fsp
), nt_errstr(status
));
443 file_free(NULL
, base_fsp
);
450 static NTSTATUS
openat_pathref_fullname(
451 struct connection_struct
*conn
,
452 const struct files_struct
*dirfsp
,
453 struct files_struct
*basefsp
,
454 struct smb_filename
**full_fname
,
455 struct smb_filename
*smb_fname
,
456 const struct vfs_open_how
*how
)
458 struct files_struct
*fsp
= NULL
;
459 bool have_dirfsp
= (dirfsp
!= NULL
);
460 bool have_basefsp
= (basefsp
!= NULL
);
463 DBG_DEBUG("smb_fname [%s]\n", smb_fname_str_dbg(smb_fname
));
465 SMB_ASSERT(smb_fname
->fsp
== NULL
);
466 SMB_ASSERT(have_dirfsp
!= have_basefsp
);
468 status
= fsp_new(conn
, conn
, &fsp
);
469 if (!NT_STATUS_IS_OK(status
)) {
473 GetTimeOfDay(&fsp
->open_time
);
475 ZERO_STRUCT(conn
->sconn
->fsp_fi_cache
);
477 fsp
->fsp_flags
.is_pathref
= true;
479 status
= fsp_attach_smb_fname(fsp
, full_fname
);
480 if (!NT_STATUS_IS_OK(status
)) {
483 fsp_set_base_fsp(fsp
, basefsp
);
485 status
= fd_openat(dirfsp
, smb_fname
, fsp
, how
);
486 if (!NT_STATUS_IS_OK(status
)) {
488 smb_fname
->st
= fsp
->fsp_name
->st
;
490 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
) ||
491 NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_PATH_NOT_FOUND
) ||
492 NT_STATUS_EQUAL(status
, NT_STATUS_STOPPED_ON_SYMLINK
))
495 * streams_xattr return NT_STATUS_NOT_FOUND for
496 * opens of not yet existing streams.
498 * ELOOP maps to NT_STATUS_OBJECT_PATH_NOT_FOUND
499 * and this will result from a open request from
500 * a POSIX client on a symlink.
502 * NT_STATUS_OBJECT_NAME_NOT_FOUND is the simple
505 * NT_STATUS_STOPPED_ON_SYMLINK is returned when trying
506 * to open a symlink, our callers are not interested in
509 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
515 * fd_openat() has done an FSTAT on the handle
516 * so update the smb_fname stat info with "truth".
519 smb_fname
->st
= fsp
->fsp_name
->st
;
521 fsp
->fsp_flags
.is_directory
= S_ISDIR(fsp
->fsp_name
->st
.st_ex_mode
);
523 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &fsp
->fsp_name
->st
);
525 status
= fsp_smb_fname_link(fsp
,
526 &smb_fname
->fsp_link
,
528 if (!NT_STATUS_IS_OK(status
)) {
532 DBG_DEBUG("fsp [%s]: OK\n", fsp_str_dbg(fsp
));
534 talloc_set_destructor(smb_fname
, smb_fname_fsp_destructor
);
538 DBG_DEBUG("Opening pathref for [%s] failed: %s\n",
539 smb_fname_str_dbg(smb_fname
),
542 fsp_set_base_fsp(fsp
, NULL
);
544 file_free(NULL
, fsp
);
549 * Open an internal O_PATH based fsp for smb_fname. If O_PATH is not
550 * available, open O_RDONLY as root. Both is done in fd_open() ->
551 * non_widelink_open(), triggered by setting fsp->fsp_flags.is_pathref to
554 NTSTATUS
openat_pathref_fsp(const struct files_struct
*dirfsp
,
555 struct smb_filename
*smb_fname
)
557 connection_struct
*conn
= dirfsp
->conn
;
558 struct smb_filename
*full_fname
= NULL
;
559 struct smb_filename
*base_fname
= NULL
;
560 struct vfs_open_how how
= { .flags
= O_RDONLY
|O_NONBLOCK
, };
563 DBG_DEBUG("smb_fname [%s]\n", smb_fname_str_dbg(smb_fname
));
565 if (smb_fname
->fsp
!= NULL
) {
566 /* We already have one for this name. */
567 DBG_DEBUG("smb_fname [%s] already has a pathref fsp.\n",
568 smb_fname_str_dbg(smb_fname
));
572 if (is_named_stream(smb_fname
) &&
573 ((conn
->fs_capabilities
& FILE_NAMED_STREAMS
) == 0)) {
574 DBG_DEBUG("stream open [%s] on non-stream share\n",
575 smb_fname_str_dbg(smb_fname
));
576 return NT_STATUS_OBJECT_NAME_INVALID
;
579 if (!is_named_stream(smb_fname
)) {
581 * openat_pathref_fullname() will make "full_fname" a
582 * talloc child of the smb_fname->fsp. Don't use
583 * talloc_tos() to allocate it to avoid making the
584 * talloc stackframe pool long-lived.
586 full_fname
= full_path_from_dirfsp_atname(
590 if (full_fname
== NULL
) {
591 status
= NT_STATUS_NO_MEMORY
;
594 status
= openat_pathref_fullname(
595 conn
, dirfsp
, NULL
, &full_fname
, smb_fname
, &how
);
596 TALLOC_FREE(full_fname
);
603 base_fname
= cp_smb_filename_nostream(conn
, smb_fname
);
604 if (base_fname
== NULL
) {
605 return NT_STATUS_NO_MEMORY
;
608 full_fname
= full_path_from_dirfsp_atname(
609 conn
, /* no talloc_tos(), see comment above */
612 if (full_fname
== NULL
) {
613 status
= NT_STATUS_NO_MEMORY
;
617 status
= openat_pathref_fullname(
618 conn
, dirfsp
, NULL
, &full_fname
, base_fname
, &how
);
619 TALLOC_FREE(full_fname
);
620 if (!NT_STATUS_IS_OK(status
)) {
621 DBG_DEBUG("openat_pathref_fullname() failed: %s\n",
626 status
= open_stream_pathref_fsp(&base_fname
->fsp
, smb_fname
);
627 if (!NT_STATUS_IS_OK(status
)) {
628 DBG_DEBUG("open_stream_pathref_fsp failed: %s\n",
633 smb_fname_fsp_unlink(base_fname
);
635 TALLOC_FREE(base_fname
);
640 * Open a stream given an already opened base_fsp. Avoid
641 * non_widelink_open: This is only valid for the case where we have a
642 * valid non-cwd_fsp dirfsp that we can pass to SMB_VFS_OPENAT()
644 NTSTATUS
open_stream_pathref_fsp(
645 struct files_struct
**_base_fsp
,
646 struct smb_filename
*smb_fname
)
648 struct files_struct
*base_fsp
= *_base_fsp
;
649 connection_struct
*conn
= base_fsp
->conn
;
650 struct smb_filename
*base_fname
= base_fsp
->fsp_name
;
651 struct smb_filename
*full_fname
= NULL
;
652 struct vfs_open_how how
= { .flags
= O_RDONLY
|O_NONBLOCK
, };
655 SMB_ASSERT(smb_fname
->fsp
== NULL
);
656 SMB_ASSERT(is_named_stream(smb_fname
));
658 full_fname
= synthetic_smb_fname(
659 conn
, /* no talloc_tos(), this will be long-lived */
660 base_fname
->base_name
,
661 smb_fname
->stream_name
,
665 if (full_fname
== NULL
) {
666 return NT_STATUS_NO_MEMORY
;
669 status
= openat_pathref_fullname(
670 conn
, NULL
, base_fsp
, &full_fname
, smb_fname
, &how
);
671 TALLOC_FREE(full_fname
);
675 static char *path_to_strv(TALLOC_CTX
*mem_ctx
, const char *path
)
677 char *result
= talloc_strdup(mem_ctx
, path
);
679 if (result
== NULL
) {
682 string_replace(result
, '/', '\0');
686 NTSTATUS
readlink_talloc(
688 struct files_struct
*dirfsp
,
689 struct smb_filename
*smb_relname
,
692 struct smb_filename null_fname
= {
693 .base_name
= discard_const_p(char, ""),
700 if (smb_relname
== NULL
) {
702 * We have a Linux O_PATH handle in dirfsp and want to
703 * read its value, essentially a freadlink
705 smb_relname
= &null_fname
;
708 ret
= SMB_VFS_READLINKAT(
709 dirfsp
->conn
, dirfsp
, smb_relname
, buf
, sizeof(buf
));
711 status
= map_nt_error_from_unix(errno
);
712 DBG_DEBUG("SMB_VFS_READLINKAT() failed: %s\n",
717 if ((size_t)ret
== sizeof(buf
)) {
719 * Do we need symlink targets longer than PATH_MAX?
721 DBG_DEBUG("Got full %zu bytes from readlink, too long\n",
723 return NT_STATUS_BUFFER_OVERFLOW
;
726 substitute
= talloc_strndup(mem_ctx
, buf
, ret
);
727 if (substitute
== NULL
) {
728 DBG_DEBUG("talloc_strndup() failed\n");
729 return NT_STATUS_NO_MEMORY
;
732 *_substitute
= substitute
;
736 NTSTATUS
read_symlink_reparse(TALLOC_CTX
*mem_ctx
,
737 struct files_struct
*dirfsp
,
738 struct smb_filename
*smb_relname
,
739 struct reparse_data_buffer
**_reparse
)
741 struct reparse_data_buffer
*reparse
= NULL
;
742 struct symlink_reparse_struct
*lnk
= NULL
;
745 reparse
= talloc_zero(mem_ctx
, struct reparse_data_buffer
);
746 if (reparse
== NULL
) {
749 *reparse
= (struct reparse_data_buffer
){
750 .tag
= IO_REPARSE_TAG_SYMLINK
,
752 lnk
= &reparse
->parsed
.lnk
;
754 status
= readlink_talloc(reparse
,
757 &lnk
->substitute_name
);
758 if (!NT_STATUS_IS_OK(status
)) {
759 DBG_DEBUG("readlink_talloc failed: %s\n", nt_errstr(status
));
763 if (lnk
->substitute_name
[0] == '/') {
764 char *subdir_path
= NULL
;
765 char *abs_target_canon
= NULL
;
766 const char *relative
= NULL
;
769 subdir_path
= talloc_asprintf(talloc_tos(),
771 dirfsp
->conn
->connectpath
,
772 dirfsp
->fsp_name
->base_name
);
773 if (subdir_path
== NULL
) {
777 abs_target_canon
= canonicalize_absolute_path(
778 talloc_tos(), lnk
->substitute_name
);
779 if (abs_target_canon
== NULL
) {
783 in_share
= subdir_of(subdir_path
,
788 TALLOC_FREE(lnk
->substitute_name
);
789 lnk
->substitute_name
= talloc_strdup(reparse
,
791 if (lnk
->substitute_name
== NULL
) {
797 if (!IS_DIRECTORY_SEP(lnk
->substitute_name
[0])) {
798 lnk
->flags
|= SYMLINK_FLAG_RELATIVE
;
804 status
= NT_STATUS_NO_MEMORY
;
806 TALLOC_FREE(reparse
);
810 static bool full_path_extend(char **dir
, const char *atname
)
812 talloc_asprintf_addbuf(dir
,
814 (*dir
)[0] == '\0' ? "" : "/",
816 return (*dir
) != NULL
;
819 NTSTATUS
create_open_symlink_err(TALLOC_CTX
*mem_ctx
,
820 files_struct
*dirfsp
,
821 struct smb_filename
*smb_relname
,
822 struct open_symlink_err
**_err
)
824 struct open_symlink_err
*err
= NULL
;
827 err
= talloc_zero(mem_ctx
, struct open_symlink_err
);
829 return NT_STATUS_NO_MEMORY
;
832 status
= read_symlink_reparse(err
, dirfsp
, smb_relname
, &err
->reparse
);
833 if (!NT_STATUS_IS_OK(status
)) {
843 * Create the memcache-key for GETREALFILENAME_CACHE: This supplements
844 * the stat cache for the last component to be looked up. Cache
845 * contents is the correctly capitalized translation of the parameter
846 * "name" as it exists on disk. This is indexed by inode of the dirfsp
847 * and name, and contrary to stat_cahce_lookup() it does not
848 * vfs_stat() the last component. This will be taken care of by an
849 * attempt to do a openat_pathref_fsp().
851 static bool get_real_filename_cache_key(TALLOC_CTX
*mem_ctx
,
852 struct files_struct
*dirfsp
,
856 struct file_id fid
= vfs_file_id_from_sbuf(dirfsp
->conn
,
857 &dirfsp
->fsp_name
->st
);
860 size_t namelen
, keylen
;
862 upper
= talloc_strdup_upper(mem_ctx
, name
);
866 namelen
= talloc_get_size(upper
);
868 keylen
= namelen
+ sizeof(fid
);
869 if (keylen
< sizeof(fid
)) {
874 key
= talloc_size(mem_ctx
, keylen
);
880 memcpy(key
, &fid
, sizeof(fid
));
881 memcpy(key
+ sizeof(fid
), upper
, namelen
);
891 static int smb_vfs_openat_ci(TALLOC_CTX
*mem_ctx
,
893 struct connection_struct
*conn
,
894 struct files_struct
*dirfsp
,
895 struct smb_filename
*smb_fname_rel
,
897 const struct vfs_open_how
*how
)
899 char *orig_base_name
= smb_fname_rel
->base_name
;
900 DATA_BLOB cache_key
= {
903 DATA_BLOB cache_value
= {
910 fd
= SMB_VFS_OPENAT(conn
, dirfsp
, smb_fname_rel
, fsp
, how
);
911 if ((fd
>= 0) || case_sensitive
) {
914 if (errno
!= ENOENT
) {
918 if (!lp_stat_cache()) {
922 ok
= get_real_filename_cache_key(mem_ctx
,
928 * probably ENOMEM, just bail
934 DO_PROFILE_INC(statcache_lookups
);
936 ok
= memcache_lookup(NULL
,
937 GETREALFILENAME_CACHE
,
941 DO_PROFILE_INC(statcache_misses
);
944 DO_PROFILE_INC(statcache_hits
);
946 smb_fname_rel
->base_name
= talloc_strndup(mem_ctx
,
947 (char *)cache_value
.data
,
949 if (smb_fname_rel
->base_name
== NULL
) {
950 TALLOC_FREE(cache_key
.data
);
951 smb_fname_rel
->base_name
= orig_base_name
;
956 if (IS_VETO_PATH(dirfsp
->conn
, smb_fname_rel
->base_name
)) {
957 DBG_DEBUG("veto files rejecting last component %s\n",
958 smb_fname_str_dbg(smb_fname_rel
));
959 TALLOC_FREE(cache_key
.data
);
960 smb_fname_rel
->base_name
= orig_base_name
;
965 fd
= SMB_VFS_OPENAT(conn
, dirfsp
, smb_fname_rel
, fsp
, how
);
967 TALLOC_FREE(cache_key
.data
);
971 memcache_delete(NULL
, GETREALFILENAME_CACHE
, cache_key
);
974 * For the "new filename" case we need to preserve the
975 * capitalization the client sent us, see
976 * https://bugzilla.samba.org/show_bug.cgi?id=15481
978 TALLOC_FREE(smb_fname_rel
->base_name
);
979 smb_fname_rel
->base_name
= orig_base_name
;
983 status
= get_real_filename_at(dirfsp
,
986 &smb_fname_rel
->base_name
);
987 if (!NT_STATUS_IS_OK(status
)) {
988 DBG_DEBUG("get_real_filename_at() failed: %s\n",
994 if (IS_VETO_PATH(conn
, smb_fname_rel
->base_name
)) {
995 DBG_DEBUG("found veto files path component "
998 smb_fname_rel
->base_name
);
999 TALLOC_FREE(smb_fname_rel
->base_name
);
1000 smb_fname_rel
->base_name
= orig_base_name
;
1005 fd
= SMB_VFS_OPENAT(conn
, dirfsp
, smb_fname_rel
, fsp
, how
);
1007 if ((fd
>= 0) && (cache_key
.data
!= NULL
)) {
1009 .data
= (uint8_t *)smb_fname_rel
->base_name
,
1010 .length
= strlen(smb_fname_rel
->base_name
) + 1,
1013 memcache_add(NULL
, GETREALFILENAME_CACHE
, cache_key
, value
);
1014 TALLOC_FREE(cache_key
.data
);
1020 NTSTATUS
openat_pathref_fsp_nosymlink(TALLOC_CTX
*mem_ctx
,
1021 struct connection_struct
*conn
,
1022 struct files_struct
*in_dirfsp
,
1023 const char *path_in
,
1026 struct smb_filename
**_smb_fname
,
1027 struct open_symlink_err
**_symlink_err
)
1029 struct files_struct
*dirfsp
= in_dirfsp
;
1030 struct smb_filename full_fname
= {
1033 .flags
= posix
? SMB_FILENAME_POSIX_PATH
: 0,
1035 struct smb_filename rel_fname
= {
1038 .flags
= full_fname
.flags
,
1040 struct smb_filename
*result
= NULL
;
1041 struct open_symlink_err
*symlink_err
= NULL
;
1042 struct files_struct
*fsp
= NULL
;
1043 char *path
= NULL
, *next
= NULL
;
1044 bool ok
, is_toplevel
;
1047 struct vfs_open_how how
= {
1048 .flags
= O_NOFOLLOW
| O_NONBLOCK
,
1052 DBG_DEBUG("path_in=%s\n", path_in
);
1054 status
= fsp_new(conn
, conn
, &fsp
);
1055 if (!NT_STATUS_IS_OK(status
)) {
1056 DBG_DEBUG("fsp_new() failed: %s\n", nt_errstr(status
));
1060 GetTimeOfDay(&fsp
->open_time
);
1061 fsp_set_gen_id(fsp
);
1062 ZERO_STRUCT(conn
->sconn
->fsp_fi_cache
);
1064 fsp
->fsp_name
= &full_fname
;
1068 * Add O_PATH manually, doing this by setting
1069 * fsp->fsp_flags.is_pathref will make us become_root() in the
1070 * non-O_PATH case, which would cause a security problem.
1072 how
.flags
|= O_PATH
;
1076 * O_SEARCH just checks for the "x" bit. We are traversing
1077 * directories, so we don't need the implicit O_RDONLY ("r"
1078 * permissions) but only the "x"-permissions requested by
1079 * O_SEARCH. We need either O_PATH or O_SEARCH to correctly
1080 * function, without either we will incorrectly require also
1081 * the "r" bit when traversing the directory hierarchy.
1083 how
.flags
|= O_SEARCH
;
1087 is_toplevel
= (dirfsp
== dirfsp
->conn
->cwd_fsp
);
1088 is_toplevel
|= ISDOT(dirfsp
->fsp_name
->base_name
);
1090 full_fname
.base_name
=
1091 talloc_strdup(talloc_tos(),
1092 is_toplevel
? "" : dirfsp
->fsp_name
->base_name
);
1093 if (full_fname
.base_name
== NULL
) {
1094 DBG_DEBUG("talloc_strdup() failed\n");
1099 * First split the path into individual components.
1101 path
= path_to_strv(talloc_tos(), path_in
);
1103 DBG_DEBUG("path_to_strv() failed\n");
1108 * First we loop over all components
1109 * in order to verify, there's no '.' or '..'
1111 rel_fname
.base_name
= path
;
1112 while (rel_fname
.base_name
!= NULL
) {
1114 next
= strv_next(path
, rel_fname
.base_name
);
1117 * Path sanitizing further up has cleaned or rejected
1118 * empty path components. Assert this here.
1120 SMB_ASSERT(rel_fname
.base_name
[0] != '\0');
1122 if (ISDOT(rel_fname
.base_name
) ||
1123 ISDOTDOT(rel_fname
.base_name
)) {
1124 DBG_DEBUG("%s contains a dot\n", path_in
);
1125 status
= NT_STATUS_OBJECT_NAME_INVALID
;
1129 /* Check veto files. */
1130 if (IS_VETO_PATH(conn
, rel_fname
.base_name
)) {
1131 DBG_DEBUG("%s contains veto files path component %s\n",
1132 path_in
, rel_fname
.base_name
);
1133 status
= NT_STATUS_OBJECT_PATH_NOT_FOUND
;
1137 rel_fname
.base_name
= next
;
1140 if (conn
->open_how_resolve
& VFS_OPEN_HOW_RESOLVE_NO_SYMLINKS
) {
1143 * Try a direct openat2 with RESOLVE_NO_SYMLINKS to
1144 * avoid the openat/close loop further down.
1147 rel_fname
.base_name
= discard_const_p(char, path_in
);
1148 how
.resolve
= VFS_OPEN_HOW_RESOLVE_NO_SYMLINKS
;
1150 fd
= SMB_VFS_OPENAT(conn
, dirfsp
, &rel_fname
, fsp
, &how
);
1152 fsp_set_fd(fsp
, fd
);
1153 ok
= full_path_extend(&full_fname
.base_name
,
1154 rel_fname
.base_name
);
1161 status
= map_nt_error_from_unix(errno
);
1162 DBG_DEBUG("SMB_VFS_OPENAT(%s, %s, RESOLVE_NO_SYMLINKS) "
1163 "returned %d %s => %s\n",
1164 smb_fname_str_dbg(dirfsp
->fsp_name
), path_in
,
1165 errno
, strerror(errno
), nt_errstr(status
));
1166 SMB_ASSERT(fd
== -1);
1170 * We got ENOSYS, so fallback to the old code
1171 * if the kernel doesn't support openat2() yet.
1178 * For ELOOP we also fallback in order to
1179 * return the correct information with
1180 * NT_STATUS_STOPPED_ON_SYMLINK.
1182 * O_NOFOLLOW|O_DIRECTORY results in
1183 * ENOTDIR instead of ELOOP for the final
1190 * If we got ENOENT, the filesystem could
1191 * be case sensitive. For now we only do
1192 * the get_real_filename_at() dance in
1193 * the fallback loop below.
1202 * Just fallback to the openat loop
1208 * Now we loop over all components
1209 * opening each one and using it
1210 * as dirfd for the next one.
1212 * It means we can detect symlinks
1215 rel_fname
.base_name
= path
;
1217 next
= strv_next(path
, rel_fname
.base_name
);
1219 fd
= smb_vfs_openat_ci(talloc_tos(),
1220 posix
|| conn
->case_sensitive
,
1228 if ((fd
== -1) && (errno
== ELOOP
)) {
1232 * openat() hit a symlink. With O_PATH we open the
1233 * symlink and get ENOTDIR in the next round, see
1237 status
= create_open_symlink_err(mem_ctx
,
1241 if (!NT_STATUS_IS_OK(status
)) {
1242 DBG_DEBUG("create_open_symlink_err failed: %s\n",
1248 size_t parsed
= next
- path
;
1249 size_t len
= talloc_get_size(path
);
1250 symlink_err
->unparsed
= len
- parsed
;
1254 * We know rel_fname is a symlink, now fill in the
1255 * rest of the metadata for our callers.
1258 ret
= SMB_VFS_FSTATAT(conn
,
1262 AT_SYMLINK_NOFOLLOW
);
1264 status
= map_nt_error_from_unix(errno
);
1265 DBG_DEBUG("SMB_VFS_FSTATAT(%s/%s) failed: %s\n",
1266 fsp_str_dbg(dirfsp
),
1267 rel_fname
.base_name
,
1269 TALLOC_FREE(symlink_err
);
1273 if (!S_ISLNK(full_fname
.st
.st_ex_mode
)) {
1275 * Hit a race: readlink_talloc() worked before
1276 * the fstatat(), but rel_fname changed to
1277 * something that's not a symlink.
1279 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1280 TALLOC_FREE(symlink_err
);
1284 status
= NT_STATUS_STOPPED_ON_SYMLINK
;
1289 if ((fd
== -1) && (errno
== ENOTDIR
)) {
1293 * dirfsp does not point at a directory, try a
1297 status
= create_open_symlink_err(mem_ctx
,
1302 if (!NT_STATUS_IS_OK(status
)) {
1303 DBG_DEBUG("create_open_symlink_err failed: %s\n",
1305 status
= NT_STATUS_NOT_A_DIRECTORY
;
1309 parsed
= rel_fname
.base_name
- path
;
1310 len
= talloc_get_size(path
);
1311 symlink_err
->unparsed
= len
- parsed
;
1313 symlink_err
->st
= dirfsp
->fsp_name
->st
;
1315 status
= NT_STATUS_STOPPED_ON_SYMLINK
;
1320 status
= map_nt_error_from_unix(errno
);
1321 DBG_DEBUG("SMB_VFS_OPENAT() failed: %s\n",
1325 fsp_set_fd(fsp
, fd
);
1327 ok
= full_path_extend(&full_fname
.base_name
, rel_fname
.base_name
);
1333 struct files_struct
*tmp
= NULL
;
1335 if (dirfsp
!= in_dirfsp
) {
1342 if (tmp
== in_dirfsp
) {
1343 status
= fsp_new(conn
, conn
, &fsp
);
1344 if (!NT_STATUS_IS_OK(status
)) {
1345 DBG_DEBUG("fsp_new() failed: %s\n",
1349 fsp
->fsp_name
= &full_fname
;
1354 rel_fname
.base_name
= next
;
1359 if (dirfsp
!= in_dirfsp
) {
1360 SMB_ASSERT(fsp_get_pathref_fd(dirfsp
) != -1);
1362 dirfsp
->fsp_name
= NULL
;
1363 file_free(NULL
, dirfsp
);
1368 fsp
->fsp_flags
.is_pathref
= true;
1369 fsp
->fsp_name
= NULL
;
1371 status
= fsp_set_smb_fname(fsp
, &full_fname
);
1372 if (!NT_STATUS_IS_OK(status
)) {
1373 DBG_DEBUG("fsp_set_smb_fname() failed: %s\n",
1378 status
= vfs_stat_fsp(fsp
);
1379 if (!NT_STATUS_IS_OK(status
)) {
1380 DBG_DEBUG("vfs_stat_fsp(%s) failed: %s\n",
1386 if (S_ISLNK(fsp
->fsp_name
->st
.st_ex_mode
)) {
1388 * Last component was a symlink we opened with O_PATH, fail it
1391 status
= create_open_symlink_err(mem_ctx
,
1395 if (!NT_STATUS_IS_OK(status
)) {
1398 symlink_err
->st
= fsp
->fsp_name
->st
;
1400 status
= NT_STATUS_STOPPED_ON_SYMLINK
;
1405 * We must correctly set fsp->file_id as code inside
1406 * open.c will use this to check if delete_on_close
1407 * has been set on the dirfsp.
1409 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &fsp
->fsp_name
->st
);
1411 result
= cp_smb_filename(mem_ctx
, fsp
->fsp_name
);
1412 if (result
== NULL
) {
1413 DBG_DEBUG("cp_smb_filename() failed\n");
1417 status
= fsp_smb_fname_link(fsp
,
1420 if (!NT_STATUS_IS_OK(status
)) {
1423 talloc_set_destructor(result
, smb_fname_fsp_destructor
);
1425 *_smb_fname
= result
;
1427 DBG_DEBUG("returning %s\n", smb_fname_str_dbg(result
));
1429 return NT_STATUS_OK
;
1432 status
= NT_STATUS_NO_MEMORY
;
1435 if (fsp_get_pathref_fd(fsp
) != -1) {
1438 file_free(NULL
, fsp
);
1442 if ((dirfsp
!= NULL
) && (dirfsp
!= in_dirfsp
)) {
1443 SMB_ASSERT(fsp_get_pathref_fd(dirfsp
) != -1);
1445 dirfsp
->fsp_name
= NULL
;
1446 file_free(NULL
, dirfsp
);
1450 if (NT_STATUS_EQUAL(status
, NT_STATUS_STOPPED_ON_SYMLINK
)) {
1451 *_symlink_err
= symlink_err
;
1459 * Open smb_fname_rel->fsp as a pathref fsp with a case insensitive
1460 * fallback using GETREALFILENAME_CACHE and get_real_filename_at() if
1461 * the first attempt based on the filename sent by the client gives
1464 NTSTATUS
openat_pathref_fsp_lcomp(struct files_struct
*dirfsp
,
1465 struct smb_filename
*smb_fname_rel
,
1468 struct connection_struct
*conn
= dirfsp
->conn
;
1469 const char *orig_rel_base_name
= smb_fname_rel
->base_name
;
1470 struct files_struct
*fsp
= NULL
;
1471 struct smb_filename
*full_fname
= NULL
;
1472 struct vfs_open_how how
= {
1473 .flags
= O_RDONLY
| O_NONBLOCK
| O_NOFOLLOW
,
1479 * Make sure we don't need of the all the magic in
1480 * openat_pathref_fsp() with regards non_widelink_open etc.
1483 SMB_ASSERT((smb_fname_rel
->fsp
== NULL
) &&
1484 (dirfsp
!= dirfsp
->conn
->cwd_fsp
) &&
1485 (strchr_m(smb_fname_rel
->base_name
, '/') == NULL
) &&
1486 !is_named_stream(smb_fname_rel
));
1488 SET_STAT_INVALID(smb_fname_rel
->st
);
1490 /* Check veto files - only looks at last component. */
1491 if (IS_VETO_PATH(dirfsp
->conn
, smb_fname_rel
->base_name
)) {
1492 DBG_DEBUG("veto files rejecting last component %s\n",
1493 smb_fname_str_dbg(smb_fname_rel
));
1494 return NT_STATUS_NETWORK_OPEN_RESTRICTION
;
1497 status
= fsp_new(conn
, conn
, &fsp
);
1498 if (!NT_STATUS_IS_OK(status
)) {
1499 DBG_DEBUG("fsp_new() failed: %s\n", nt_errstr(status
));
1503 GetTimeOfDay(&fsp
->open_time
);
1504 fsp_set_gen_id(fsp
);
1505 ZERO_STRUCT(conn
->sconn
->fsp_fi_cache
);
1507 fsp
->fsp_flags
.is_pathref
= true;
1509 full_fname
= full_path_from_dirfsp_atname(conn
, dirfsp
, smb_fname_rel
);
1510 if (full_fname
== NULL
) {
1511 DBG_DEBUG("full_path_from_dirfsp_atname(%s/%s) failed\n",
1512 dirfsp
->fsp_name
->base_name
,
1513 smb_fname_rel
->base_name
);
1514 file_free(NULL
, fsp
);
1515 return NT_STATUS_NO_MEMORY
;
1518 status
= fsp_attach_smb_fname(fsp
, &full_fname
);
1519 if (!NT_STATUS_IS_OK(status
)) {
1520 DBG_DEBUG("fsp_attach_smb_fname(fsp, %s) failed: %s\n",
1521 smb_fname_str_dbg(full_fname
),
1523 file_free(NULL
, fsp
);
1527 fd
= smb_vfs_openat_ci(smb_fname_rel
,
1528 (ucf_flags
& UCF_POSIX_PATHNAMES
) ||
1529 conn
->case_sensitive
,
1536 if ((fd
== -1) && (errno
== ENOENT
)) {
1537 status
= map_nt_error_from_unix(errno
);
1538 DBG_DEBUG("smb_vfs_openat(%s/%s) failed: %s\n",
1539 dirfsp
->fsp_name
->base_name
,
1540 smb_fname_rel
->base_name
,
1542 file_free(NULL
, fsp
);
1546 if (smb_fname_rel
->base_name
!= orig_rel_base_name
) {
1547 struct smb_filename new_fullname
= *smb_fname_rel
;
1549 DBG_DEBUG("rel->base_name changed from %s to %s\n",
1551 smb_fname_rel
->base_name
);
1553 new_fullname
.base_name
= full_path_from_dirfsp_at_basename(
1554 talloc_tos(), dirfsp
, new_fullname
.base_name
);
1555 if (new_fullname
.base_name
== NULL
) {
1557 file_free(NULL
, fsp
);
1558 return NT_STATUS_NO_MEMORY
;
1561 status
= fsp_set_smb_fname(fsp
, &new_fullname
);
1562 if (!NT_STATUS_IS_OK(status
)) {
1564 file_free(NULL
, fsp
);
1569 fsp_set_fd(fsp
, fd
);
1572 ret
= SMB_VFS_FSTAT(fsp
, &fsp
->fsp_name
->st
);
1574 ret
= SMB_VFS_FSTATAT(fsp
->conn
,
1578 AT_SYMLINK_NOFOLLOW
);
1581 status
= map_nt_error_from_unix(errno
);
1582 DBG_DEBUG("SMB_VFS_%sSTAT(%s/%s) failed: %s\n",
1583 (fd
>= 0) ? "F" : "",
1584 dirfsp
->fsp_name
->base_name
,
1585 smb_fname_rel
->base_name
,
1588 file_free(NULL
, fsp
);
1592 fsp
->fsp_flags
.is_directory
= S_ISDIR(fsp
->fsp_name
->st
.st_ex_mode
);
1593 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &fsp
->fsp_name
->st
);
1595 smb_fname_rel
->st
= fsp
->fsp_name
->st
;
1597 status
= fsp_smb_fname_link(fsp
,
1598 &smb_fname_rel
->fsp_link
,
1599 &smb_fname_rel
->fsp
);
1600 if (!NT_STATUS_IS_OK(status
)) {
1601 DBG_DEBUG("fsp_smb_fname_link() failed: %s\n",
1604 file_free(NULL
, fsp
);
1608 DBG_DEBUG("fsp [%s]: OK, fd=%d\n", fsp_str_dbg(fsp
), fd
);
1610 talloc_set_destructor(smb_fname_rel
, smb_fname_fsp_destructor
);
1611 return NT_STATUS_OK
;
1614 void smb_fname_fsp_unlink(struct smb_filename
*smb_fname
)
1616 talloc_set_destructor(smb_fname
, NULL
);
1617 smb_fname
->fsp
= NULL
;
1618 destroy_fsp_smb_fname_link(&smb_fname
->fsp_link
);
1622 * Move any existing embedded fsp refs from the src name to the
1623 * destination. It's safe to call this on src smb_fname's that have no embedded
1626 NTSTATUS
move_smb_fname_fsp_link(struct smb_filename
*smb_fname_dst
,
1627 struct smb_filename
*smb_fname_src
)
1632 * The target should always not be linked yet!
1634 SMB_ASSERT(smb_fname_dst
->fsp
== NULL
);
1635 SMB_ASSERT(smb_fname_dst
->fsp_link
== NULL
);
1637 if (smb_fname_src
->fsp
== NULL
) {
1638 return NT_STATUS_OK
;
1641 status
= fsp_smb_fname_link(smb_fname_src
->fsp
,
1642 &smb_fname_dst
->fsp_link
,
1643 &smb_fname_dst
->fsp
);
1644 if (!NT_STATUS_IS_OK(status
)) {
1648 talloc_set_destructor(smb_fname_dst
, smb_fname_fsp_destructor
);
1650 smb_fname_fsp_unlink(smb_fname_src
);
1652 return NT_STATUS_OK
;
1655 static int fsp_ref_no_close_destructor(struct smb_filename
*smb_fname
)
1657 destroy_fsp_smb_fname_link(&smb_fname
->fsp_link
);
1661 NTSTATUS
reference_smb_fname_fsp_link(struct smb_filename
*smb_fname_dst
,
1662 const struct smb_filename
*smb_fname_src
)
1667 * The target should always not be linked yet!
1669 SMB_ASSERT(smb_fname_dst
->fsp
== NULL
);
1670 SMB_ASSERT(smb_fname_dst
->fsp_link
== NULL
);
1672 if (smb_fname_src
->fsp
== NULL
) {
1673 return NT_STATUS_OK
;
1676 status
= fsp_smb_fname_link(smb_fname_src
->fsp
,
1677 &smb_fname_dst
->fsp_link
,
1678 &smb_fname_dst
->fsp
);
1679 if (!NT_STATUS_IS_OK(status
)) {
1683 talloc_set_destructor(smb_fname_dst
, fsp_ref_no_close_destructor
);
1685 return NT_STATUS_OK
;
1689 * Create an smb_fname and open smb_fname->fsp pathref
1691 NTSTATUS
synthetic_pathref(TALLOC_CTX
*mem_ctx
,
1692 struct files_struct
*dirfsp
,
1693 const char *base_name
,
1694 const char *stream_name
,
1695 const SMB_STRUCT_STAT
*psbuf
,
1698 struct smb_filename
**_smb_fname
)
1700 struct smb_filename
*smb_fname
= NULL
;
1703 smb_fname
= synthetic_smb_fname(mem_ctx
,
1709 if (smb_fname
== NULL
) {
1710 return NT_STATUS_NO_MEMORY
;
1713 status
= openat_pathref_fsp(dirfsp
, smb_fname
);
1714 if (!NT_STATUS_IS_OK(status
)) {
1715 DBG_NOTICE("opening [%s] failed\n",
1716 smb_fname_str_dbg(smb_fname
));
1717 TALLOC_FREE(smb_fname
);
1721 *_smb_fname
= smb_fname
;
1722 return NT_STATUS_OK
;
1726 * Turn a path into a parent pathref and atname
1728 * This returns the parent pathref in _parent and the name relative to it. If
1729 * smb_fname was a pathref (ie smb_fname->fsp != NULL), then _atname will be a
1730 * pathref as well, ie _atname->fsp will point at the same fsp as
1733 NTSTATUS
parent_pathref(TALLOC_CTX
*mem_ctx
,
1734 struct files_struct
*dirfsp
,
1735 const struct smb_filename
*smb_fname
,
1736 struct smb_filename
**_parent
,
1737 struct smb_filename
**_atname
)
1739 struct smb_filename
*parent
= NULL
;
1740 struct smb_filename
*atname
= NULL
;
1743 status
= SMB_VFS_PARENT_PATHNAME(dirfsp
->conn
,
1748 if (!NT_STATUS_IS_OK(status
)) {
1753 * We know that the parent name must
1754 * exist, and the name has been canonicalized
1755 * even if this was a POSIX pathname.
1756 * Ensure that we follow symlinks for
1757 * the parent. See the torture test
1758 * POSIX-SYMLINK-PARENT for details.
1760 parent
->flags
&= ~SMB_FILENAME_POSIX_PATH
;
1762 status
= openat_pathref_fsp(dirfsp
, parent
);
1763 if (!NT_STATUS_IS_OK(status
)) {
1764 TALLOC_FREE(parent
);
1768 status
= reference_smb_fname_fsp_link(atname
, smb_fname
);
1769 if (!NT_STATUS_IS_OK(status
)) {
1770 TALLOC_FREE(parent
);
1776 return NT_STATUS_OK
;
1779 static bool close_file_in_loop(struct files_struct
*fsp
,
1780 enum file_close_type close_type
)
1782 if (fsp_is_alternate_stream(fsp
)) {
1784 * This is a stream, it can't be a base
1786 SMB_ASSERT(fsp
->stream_fsp
== NULL
);
1787 SMB_ASSERT(fsp
->base_fsp
->stream_fsp
== fsp
);
1790 * Remove the base<->stream link so that
1791 * close_file_free() does not close fsp->base_fsp as
1792 * well. This would destroy walking the linked list of
1795 fsp
->base_fsp
->stream_fsp
= NULL
;
1796 fsp
->base_fsp
= NULL
;
1798 close_file_free(NULL
, &fsp
, close_type
);
1802 if (fsp
->stream_fsp
!= NULL
) {
1804 * This is the base of a stream.
1806 SMB_ASSERT(fsp
->stream_fsp
->base_fsp
== fsp
);
1809 * Remove the base<->stream link. This will make fsp
1810 * look like a normal fsp for the next round.
1812 fsp
->stream_fsp
->base_fsp
= NULL
;
1813 fsp
->stream_fsp
= NULL
;
1816 * Have us called back a second time. In the second
1817 * round, "fsp" now looks like a normal fsp.
1822 close_file_free(NULL
, &fsp
, close_type
);
1826 /****************************************************************************
1827 Close all open files for a connection.
1828 ****************************************************************************/
1830 struct file_close_conn_state
{
1831 struct connection_struct
*conn
;
1832 enum file_close_type close_type
;
1833 bool fsp_left_behind
;
1836 static struct files_struct
*file_close_conn_fn(
1837 struct files_struct
*fsp
,
1840 struct file_close_conn_state
*state
= private_data
;
1843 if (fsp
->conn
!= state
->conn
) {
1847 if (fsp
->op
!= NULL
&& fsp
->op
->global
->durable
) {
1849 * A tree disconnect closes a durable handle
1851 fsp
->op
->global
->durable
= false;
1854 did_close
= close_file_in_loop(fsp
, state
->close_type
);
1856 state
->fsp_left_behind
= true;
1862 void file_close_conn(connection_struct
*conn
, enum file_close_type close_type
)
1864 struct file_close_conn_state state
= { .conn
= conn
,
1865 .close_type
= close_type
};
1867 files_forall(conn
->sconn
, file_close_conn_fn
, &state
);
1869 if (state
.fsp_left_behind
) {
1870 state
.fsp_left_behind
= false;
1871 files_forall(conn
->sconn
, file_close_conn_fn
, &state
);
1872 SMB_ASSERT(!state
.fsp_left_behind
);
1876 /****************************************************************************
1877 Initialise file structures.
1878 ****************************************************************************/
1880 static int files_max_open_fds
;
1882 bool file_init_global(void)
1884 int request_max
= lp_max_open_files();
1888 if (files_max_open_fds
!= 0) {
1893 * Set the max_open files to be the requested
1894 * max plus a fudgefactor to allow for the extra
1895 * fd's we need such as log files etc...
1897 real_lim
= set_maxfiles(request_max
+ MAX_OPEN_FUDGEFACTOR
);
1899 real_max
= real_lim
- MAX_OPEN_FUDGEFACTOR
;
1901 if (real_max
+ FILE_HANDLE_OFFSET
+ MAX_OPEN_PIPES
> 65536) {
1902 real_max
= 65536 - FILE_HANDLE_OFFSET
- MAX_OPEN_PIPES
;
1905 if (real_max
!= request_max
) {
1906 DEBUG(1, ("file_init_global: Information only: requested %d "
1907 "open files, %d are available.\n",
1908 request_max
, real_max
));
1911 SMB_ASSERT(real_max
> 100);
1913 files_max_open_fds
= real_max
;
1917 bool file_init(struct smbd_server_connection
*sconn
)
1921 ok
= file_init_global();
1926 sconn
->real_max_open_files
= files_max_open_fds
;
1931 /****************************************************************************
1932 Close files open by a specified vuid.
1933 ****************************************************************************/
1935 struct file_close_user_state
{
1937 bool fsp_left_behind
;
1940 static struct files_struct
*file_close_user_fn(
1941 struct files_struct
*fsp
,
1944 struct file_close_user_state
*state
= private_data
;
1947 if (fsp
->vuid
!= state
->vuid
) {
1951 did_close
= close_file_in_loop(fsp
, SHUTDOWN_CLOSE
);
1953 state
->fsp_left_behind
= true;
1959 void file_close_user(struct smbd_server_connection
*sconn
, uint64_t vuid
)
1961 struct file_close_user_state state
= { .vuid
= vuid
};
1963 files_forall(sconn
, file_close_user_fn
, &state
);
1965 if (state
.fsp_left_behind
) {
1966 state
.fsp_left_behind
= false;
1967 files_forall(sconn
, file_close_user_fn
, &state
);
1968 SMB_ASSERT(!state
.fsp_left_behind
);
1973 * Walk the files table until "fn" returns non-NULL
1976 struct files_struct
*files_forall(
1977 struct smbd_server_connection
*sconn
,
1978 struct files_struct
*(*fn
)(struct files_struct
*fsp
,
1979 void *private_data
),
1982 struct files_struct
*fsp
, *next
;
1984 for (fsp
= sconn
->files
; fsp
; fsp
= next
) {
1985 struct files_struct
*ret
;
1987 ret
= fn(fsp
, private_data
);
1995 /****************************************************************************
1996 Find a fsp given a file descriptor.
1997 ****************************************************************************/
1999 files_struct
*file_find_fd(struct smbd_server_connection
*sconn
, int fd
)
2004 for (fsp
=sconn
->files
; fsp
; fsp
=fsp
->next
,count
++) {
2005 if (fsp_get_pathref_fd(fsp
) == fd
) {
2007 DLIST_PROMOTE(sconn
->files
, fsp
);
2016 /****************************************************************************
2017 Find a fsp given a device, inode and file_id.
2018 ****************************************************************************/
2020 files_struct
*file_find_dif(struct smbd_server_connection
*sconn
,
2021 struct file_id id
, unsigned long gen_id
)
2030 for (fsp
= sconn
->files
; fsp
; fsp
= fsp
->next
,count
++) {
2032 * We can have a fsp->fh->fd == -1 here as it could be a stat
2035 if (!file_id_equal(&fsp
->file_id
, &id
)) {
2038 if (!fsp
->fsp_flags
.is_fsa
) {
2041 if (fh_get_gen_id(fsp
->fh
) != gen_id
) {
2045 DLIST_PROMOTE(sconn
->files
, fsp
);
2053 /****************************************************************************
2054 Find the first fsp given a device and inode.
2055 We use a singleton cache here to speed up searching from getfilepathinfo
2057 ****************************************************************************/
2059 files_struct
*file_find_di_first(struct smbd_server_connection
*sconn
,
2065 if (file_id_equal(&sconn
->fsp_fi_cache
.id
, &id
)) {
2066 /* Positive or negative cache hit. */
2067 return sconn
->fsp_fi_cache
.fsp
;
2070 sconn
->fsp_fi_cache
.id
= id
;
2072 for (fsp
=sconn
->files
;fsp
;fsp
=fsp
->next
) {
2073 if (need_fsa
&& !fsp
->fsp_flags
.is_fsa
) {
2076 if (file_id_equal(&fsp
->file_id
, &id
)) {
2077 /* Setup positive cache. */
2078 sconn
->fsp_fi_cache
.fsp
= fsp
;
2083 /* Setup negative cache. */
2084 sconn
->fsp_fi_cache
.fsp
= NULL
;
2088 /****************************************************************************
2089 Find the next fsp having the same device and inode.
2090 ****************************************************************************/
2092 files_struct
*file_find_di_next(files_struct
*start_fsp
,
2097 for (fsp
= start_fsp
->next
;fsp
;fsp
=fsp
->next
) {
2098 if (need_fsa
&& !fsp
->fsp_flags
.is_fsa
) {
2101 if (file_id_equal(&fsp
->file_id
, &start_fsp
->file_id
)) {
2109 struct files_struct
*file_find_one_fsp_from_lease_key(
2110 struct smbd_server_connection
*sconn
,
2111 const struct smb2_lease_key
*lease_key
)
2113 struct files_struct
*fsp
;
2115 for (fsp
= sconn
->files
; fsp
; fsp
=fsp
->next
) {
2116 if ((fsp
->lease
!= NULL
) &&
2117 (fsp
->lease
->lease
.lease_key
.data
[0] ==
2118 lease_key
->data
[0]) &&
2119 (fsp
->lease
->lease
.lease_key
.data
[1] ==
2120 lease_key
->data
[1])) {
2127 /****************************************************************************
2128 Find any fsp open with a pathname below that of an already open path.
2129 ****************************************************************************/
2131 bool file_find_subpath(files_struct
*dir_fsp
)
2135 char *d_fullname
= NULL
;
2137 d_fullname
= talloc_asprintf(talloc_tos(), "%s/%s",
2138 dir_fsp
->conn
->connectpath
,
2139 dir_fsp
->fsp_name
->base_name
);
2145 dlen
= strlen(d_fullname
);
2147 for (fsp
=dir_fsp
->conn
->sconn
->files
; fsp
; fsp
=fsp
->next
) {
2150 if (fsp
== dir_fsp
) {
2154 d1_fullname
= talloc_asprintf(talloc_tos(),
2156 fsp
->conn
->connectpath
,
2157 fsp
->fsp_name
->base_name
);
2160 * If the open file has a path that is a longer
2161 * component, then it's a subpath.
2163 if (strnequal(d_fullname
, d1_fullname
, dlen
) &&
2164 (d1_fullname
[dlen
] == '/')) {
2165 TALLOC_FREE(d1_fullname
);
2166 TALLOC_FREE(d_fullname
);
2169 TALLOC_FREE(d1_fullname
);
2172 TALLOC_FREE(d_fullname
);
2176 /****************************************************************************
2178 ****************************************************************************/
2180 static void fsp_free(files_struct
*fsp
)
2182 struct smbd_server_connection
*sconn
= fsp
->conn
->sconn
;
2184 if (fsp
== sconn
->fsp_fi_cache
.fsp
) {
2185 ZERO_STRUCT(sconn
->fsp_fi_cache
);
2188 DLIST_REMOVE(sconn
->files
, fsp
);
2189 SMB_ASSERT(sconn
->num_files
> 0);
2192 TALLOC_FREE(fsp
->fake_file_handle
);
2194 if (fh_get_refcount(fsp
->fh
) == 1) {
2195 TALLOC_FREE(fsp
->fh
);
2197 size_t new_refcount
= fh_get_refcount(fsp
->fh
) - 1;
2198 fh_set_refcount(fsp
->fh
, new_refcount
);
2201 if (fsp
->lease
!= NULL
) {
2202 if (fsp
->lease
->ref_count
== 1) {
2203 TALLOC_FREE(fsp
->lease
);
2205 fsp
->lease
->ref_count
--;
2209 fsp
->conn
->num_files_open
--;
2211 if (fsp
->fsp_name
!= NULL
&&
2212 fsp
->fsp_name
->fsp_link
!= NULL
)
2215 * Free fsp_link of fsp->fsp_name. To do this in the correct
2216 * talloc destructor order we have to do it here. The
2217 * talloc_free() of the link should set the fsp pointer to NULL.
2219 TALLOC_FREE(fsp
->fsp_name
->fsp_link
);
2220 SMB_ASSERT(fsp
->fsp_name
->fsp
== NULL
);
2223 /* this is paranoia, just in case someone tries to reuse the
2227 /* fsp->fsp_name is a talloc child and is free'd automatically. */
2232 * Rundown of all smb-related sub-structures of an fsp
2234 void fsp_unbind_smb(struct smb_request
*req
, files_struct
*fsp
)
2236 if (fsp
== fsp
->conn
->cwd_fsp
) {
2241 size_t len
= fsp_fullbasepath(fsp
, NULL
, 0);
2242 char fullpath
[len
+1];
2244 fsp_fullbasepath(fsp
, fullpath
, sizeof(fullpath
));
2246 notify_remove(fsp
->conn
->sconn
->notify_ctx
, fsp
, fullpath
);
2247 TALLOC_FREE(fsp
->notify
);
2250 /* Ensure this event will never fire. */
2251 TALLOC_FREE(fsp
->update_write_time_event
);
2253 if (fsp
->op
!= NULL
) {
2254 fsp
->op
->compat
= NULL
;
2256 TALLOC_FREE(fsp
->op
);
2258 if ((req
!= NULL
) && (fsp
== req
->chain_fsp
)) {
2259 req
->chain_fsp
= NULL
;
2263 * Clear all possible chained fsp
2264 * pointers in the SMB2 request queue.
2266 remove_smb2_chained_fsp(fsp
);
2269 void file_free(struct smb_request
*req
, files_struct
*fsp
)
2271 struct smbd_server_connection
*sconn
= fsp
->conn
->sconn
;
2272 uint64_t fnum
= fsp
->fnum
;
2274 fsp_unbind_smb(req
, fsp
);
2276 /* Drop all remaining extensions. */
2277 vfs_remove_all_fsp_extensions(fsp
);
2281 DBG_INFO("freed files structure %"PRIu64
" (%zu used)\n",
2286 /****************************************************************************
2287 Get an fsp from a packet given a 16 bit fnum.
2288 ****************************************************************************/
2290 files_struct
*file_fsp(struct smb_request
*req
, uint16_t fid
)
2292 struct smbXsrv_open
*op
;
2299 * We should never get here. req==NULL could in theory
2300 * only happen from internal opens with a non-zero
2301 * root_dir_fid. Internal opens just don't do that, at
2302 * least they are not supposed to do so. And if they
2303 * start to do so, they better fake up a smb_request
2304 * from which we get the right smbd_server_conn. While
2305 * this should never happen, let's return NULL here.
2310 if (req
->chain_fsp
!= NULL
) {
2311 if (req
->chain_fsp
->fsp_flags
.closing
) {
2314 return req
->chain_fsp
;
2317 if (req
->xconn
== NULL
) {
2321 now
= timeval_to_nttime(&req
->request_time
);
2323 status
= smb1srv_open_lookup(req
->xconn
,
2325 if (!NT_STATUS_IS_OK(status
)) {
2334 if (fsp
->fsp_flags
.closing
) {
2338 req
->chain_fsp
= fsp
;
2339 fsp
->fsp_name
->st
.cached_dos_attributes
= FILE_ATTRIBUTE_INVALID
;
2343 struct files_struct
*file_fsp_get(struct smbd_smb2_request
*smb2req
,
2344 uint64_t persistent_id
,
2345 uint64_t volatile_id
)
2347 struct smbXsrv_open
*op
;
2350 struct files_struct
*fsp
;
2352 now
= timeval_to_nttime(&smb2req
->request_time
);
2354 status
= smb2srv_open_lookup(smb2req
->xconn
,
2355 persistent_id
, volatile_id
,
2357 if (!NT_STATUS_IS_OK(status
)) {
2366 if (smb2req
->tcon
== NULL
) {
2370 if (smb2req
->tcon
->compat
!= fsp
->conn
) {
2374 if (smb2req
->session
== NULL
) {
2378 if (smb2req
->session
->global
->session_wire_id
!= fsp
->vuid
) {
2382 if (fsp
->fsp_flags
.closing
) {
2386 fsp
->fsp_name
->st
.cached_dos_attributes
= FILE_ATTRIBUTE_INVALID
;
2391 struct files_struct
*file_fsp_smb2(struct smbd_smb2_request
*smb2req
,
2392 uint64_t persistent_id
,
2393 uint64_t volatile_id
)
2395 struct files_struct
*fsp
;
2397 if (smb2req
->compat_chain_fsp
!= NULL
) {
2398 if (smb2req
->compat_chain_fsp
->fsp_flags
.closing
) {
2401 smb2req
->compat_chain_fsp
->fsp_name
->st
.cached_dos_attributes
=
2402 FILE_ATTRIBUTE_INVALID
;
2403 return smb2req
->compat_chain_fsp
;
2406 fsp
= file_fsp_get(smb2req
, persistent_id
, volatile_id
);
2411 smb2req
->compat_chain_fsp
= fsp
;
2415 /****************************************************************************
2416 Duplicate the file handle part for a DOS or FCB open.
2417 ****************************************************************************/
2419 NTSTATUS
dup_file_fsp(
2421 uint32_t access_mask
,
2424 size_t new_refcount
;
2426 /* this can never happen for print files */
2427 SMB_ASSERT(from
->print_file
== NULL
);
2429 TALLOC_FREE(to
->fh
);
2432 new_refcount
= fh_get_refcount(to
->fh
) + 1;
2433 fh_set_refcount(to
->fh
, new_refcount
);
2435 to
->file_id
= from
->file_id
;
2436 to
->initial_allocation_size
= from
->initial_allocation_size
;
2437 to
->file_pid
= from
->file_pid
;
2438 to
->vuid
= from
->vuid
;
2439 to
->open_time
= from
->open_time
;
2440 to
->access_mask
= access_mask
;
2441 to
->oplock_type
= from
->oplock_type
;
2442 to
->fsp_flags
.can_lock
= from
->fsp_flags
.can_lock
;
2443 to
->fsp_flags
.can_read
= ((access_mask
& FILE_READ_DATA
) != 0);
2444 to
->fsp_flags
.can_write
=
2445 CAN_WRITE(from
->conn
) &&
2446 ((access_mask
& (FILE_WRITE_DATA
| FILE_APPEND_DATA
)) != 0);
2447 if (from
->fsp_name
->twrp
!= 0) {
2448 to
->fsp_flags
.can_write
= false;
2450 to
->fsp_flags
.modified
= from
->fsp_flags
.modified
;
2451 to
->fsp_flags
.is_directory
= from
->fsp_flags
.is_directory
;
2452 to
->fsp_flags
.aio_write_behind
= from
->fsp_flags
.aio_write_behind
;
2453 to
->fsp_flags
.is_fsa
= from
->fsp_flags
.is_fsa
;
2454 to
->fsp_flags
.is_pathref
= from
->fsp_flags
.is_pathref
;
2455 to
->fsp_flags
.have_proc_fds
= from
->fsp_flags
.have_proc_fds
;
2456 to
->fsp_flags
.is_dirfsp
= from
->fsp_flags
.is_dirfsp
;
2458 return fsp_set_smb_fname(to
, from
->fsp_name
);
2462 * Return a jenkins hash of a pathname on a connection.
2465 NTSTATUS
file_name_hash(connection_struct
*conn
,
2466 const char *name
, uint32_t *p_name_hash
)
2468 char tmpbuf
[PATH_MAX
];
2469 char *fullpath
, *to_free
;
2473 /* Set the hash of the full pathname. */
2475 if (name
[0] == '/') {
2476 strlcpy(tmpbuf
, name
, sizeof(tmpbuf
));
2478 len
= strlen(fullpath
);
2481 len
= full_path_tos(conn
->connectpath
,
2489 return NT_STATUS_NO_MEMORY
;
2491 key
= (TDB_DATA
) { .dptr
= (uint8_t *)fullpath
, .dsize
= len
+1 };
2492 *p_name_hash
= tdb_jenkins_hash(&key
);
2494 DEBUG(10,("file_name_hash: %s hash 0x%x\n",
2496 (unsigned int)*p_name_hash
));
2498 TALLOC_FREE(to_free
);
2499 return NT_STATUS_OK
;
2502 static NTSTATUS
fsp_attach_smb_fname(struct files_struct
*fsp
,
2503 struct smb_filename
**_smb_fname
)
2505 TALLOC_CTX
*frame
= talloc_stackframe();
2506 struct smb_filename
*smb_fname_new
= talloc_move(fsp
, _smb_fname
);
2507 const char *name_str
= NULL
;
2508 uint32_t name_hash
= 0;
2511 name_str
= smb_fname_str_dbg(smb_fname_new
);
2512 if (name_str
== NULL
) {
2514 return NT_STATUS_NO_MEMORY
;
2517 status
= file_name_hash(fsp
->conn
,
2522 if (!NT_STATUS_IS_OK(status
)) {
2526 status
= fsp_smb_fname_link(fsp
,
2527 &smb_fname_new
->fsp_link
,
2528 &smb_fname_new
->fsp
);
2529 if (!NT_STATUS_IS_OK(status
)) {
2533 fsp
->name_hash
= name_hash
;
2534 fsp
->fsp_name
= smb_fname_new
;
2535 fsp
->fsp_name
->st
.cached_dos_attributes
= FILE_ATTRIBUTE_INVALID
;
2537 return NT_STATUS_OK
;
2541 * The only way that the fsp->fsp_name field should ever be set.
2543 NTSTATUS
fsp_set_smb_fname(struct files_struct
*fsp
,
2544 const struct smb_filename
*smb_fname_in
)
2546 struct smb_filename
*smb_fname_old
= fsp
->fsp_name
;
2547 struct smb_filename
*smb_fname_new
= NULL
;
2550 smb_fname_new
= cp_smb_filename(fsp
, smb_fname_in
);
2551 if (smb_fname_new
== NULL
) {
2552 return NT_STATUS_NO_MEMORY
;
2555 status
= fsp_attach_smb_fname(fsp
, &smb_fname_new
);
2556 if (!NT_STATUS_IS_OK(status
)) {
2557 TALLOC_FREE(smb_fname_new
);
2561 if (smb_fname_old
!= NULL
) {
2562 smb_fname_fsp_unlink(smb_fname_old
);
2563 TALLOC_FREE(smb_fname_old
);
2566 return NT_STATUS_OK
;
2569 size_t fsp_fullbasepath(struct files_struct
*fsp
, char *buf
, size_t buflen
)
2575 * susv4 allows buf==NULL if buflen==0 for snprintf.
2577 SMB_ASSERT(buflen
== 0);
2580 if (ISDOT(fsp
->fsp_name
->base_name
)) {
2581 len
= snprintf(buf
, buflen
, "%s", fsp
->conn
->connectpath
);
2586 fsp
->conn
->connectpath
,
2587 fsp
->fsp_name
->base_name
);
2589 SMB_ASSERT(len
> 0);
2594 void fsp_set_base_fsp(struct files_struct
*fsp
, struct files_struct
*base_fsp
)
2596 SMB_ASSERT(fsp
->stream_fsp
== NULL
);
2597 if (base_fsp
!= NULL
) {
2598 SMB_ASSERT(base_fsp
->base_fsp
== NULL
);
2599 SMB_ASSERT(base_fsp
->stream_fsp
== NULL
);
2602 if (fsp
->base_fsp
!= NULL
) {
2603 SMB_ASSERT(fsp
->base_fsp
->stream_fsp
== fsp
);
2604 fsp
->base_fsp
->stream_fsp
= NULL
;
2607 fsp
->base_fsp
= base_fsp
;
2608 if (fsp
->base_fsp
!= NULL
) {
2609 fsp
->base_fsp
->stream_fsp
= fsp
;
2613 bool fsp_is_alternate_stream(const struct files_struct
*fsp
)
2615 return (fsp
->base_fsp
!= NULL
);
2618 struct files_struct
*metadata_fsp(struct files_struct
*fsp
)
2620 if (fsp_is_alternate_stream(fsp
)) {
2621 return fsp
->base_fsp
;
2626 static bool fsp_generic_ask_sharemode(struct files_struct
*fsp
)
2632 if (fsp
->posix_flags
& FSP_POSIX_FLAGS_PATHNAMES
) {
2633 /* Always use filesystem for UNIX mtime query. */
2640 bool fsp_search_ask_sharemode(struct files_struct
*fsp
)
2642 if (!fsp_generic_ask_sharemode(fsp
)) {
2646 return lp_smbd_search_ask_sharemode(SNUM(fsp
->conn
));
2649 bool fsp_getinfo_ask_sharemode(struct files_struct
*fsp
)
2651 if (!fsp_generic_ask_sharemode(fsp
)) {
2655 return lp_smbd_getinfo_ask_sharemode(SNUM(fsp
->conn
));