]> git.ipfire.org Git - thirdparty/samba.git/log
thirdparty/samba.git
4 years agovfs: Add dirfsp arg to SMB_VFS_READDIR()
Ralph Boehme [Sun, 22 Nov 2020 12:57:27 +0000 (13:57 +0100)] 
vfs: Add dirfsp arg to SMB_VFS_READDIR()

This allows for optimisations in VFS module: by passing the dirfsp as an
additional arg, the function can check fsp->fsp_name->flags which may include eg
SMB_FILENAME_POSIX_PATH to trigger POSIX pathname processing.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use vfs_stat() in more places
Ralph Boehme [Wed, 25 Nov 2020 11:29:40 +0000 (12:29 +0100)] 
smbd: use vfs_stat() in more places

This replaces the code in a bunch of places where we choose between stat() and
lstat() based on req->posix_pathname. The new code inside vfs_stat() is based on
checking the smb_fname flag SMB_FILENAME_POSIX_PATH.

req->posix_pathname is inherited from the global POSIX pathnames state and the
smb_fname flags is also inherited from that indirectly via the UCF flags.

Tl;dr: no change in behaviour. :)

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use vfs_stat() in dptr_ReadDirName()
Ralph Boehme [Wed, 14 Oct 2020 13:48:07 +0000 (15:48 +0200)] 
smbd: use vfs_stat() in dptr_ReadDirName()

This is subtle: we inherit the smb_fname flags from the directory to its
directory entries while listing a directory. This means if were listing a
directory in POSIX context, we now treat all entries as POSIX paths and
correctly call lstat() on the entries instead of stat().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: add vfs_stat()
Ralph Boehme [Fri, 16 Oct 2020 12:35:10 +0000 (14:35 +0200)] 
smbd: add vfs_stat()

Deals with POSIX paths and either calls lstat() for POSIX or stat().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/torture: add POSIX-STAT test
Ralph Boehme [Thu, 15 Oct 2020 13:36:42 +0000 (15:36 +0200)] 
s3/torture: add POSIX-STAT test

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/torture: add POSIX-READLINK test
Ralph Boehme [Thu, 15 Oct 2020 13:32:34 +0000 (15:32 +0200)] 
s3/torture: add POSIX-READLINK test

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/torture: add POSIX-LS-SINGLE test
Ralph Boehme [Thu, 15 Oct 2020 13:24:11 +0000 (15:24 +0200)] 
s3/torture: add POSIX-LS-SINGLE test

Note that uses SMB2 for the "Windows client" (aka non-POSIX) connection as SMB1
directory listing code translates a directory listing with a search mask that
matches an existing file to a CREATE which won't cut it for our test as we're
targetting the directory listing code.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/torture: add POSIX-LS-WILDCARD test
Ralph Boehme [Thu, 15 Oct 2020 13:11:20 +0000 (15:11 +0200)] 
s3/torture: add POSIX-LS-WILDCARD test

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/torture: add torture_conn_set_sockopt() wrapper
Ralph Boehme [Thu, 15 Oct 2020 10:32:53 +0000 (12:32 +0200)] 
s3/torture: add torture_conn_set_sockopt() wrapper

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: optimisation using pathref fd to open real fd if possible
Ralph Boehme [Mon, 12 Oct 2020 13:28:08 +0000 (15:28 +0200)] 
smbd: optimisation using pathref fd to open real fd if possible

This is an optimisation that avoids going through the expensive
non_widelink_open() logic a second time. It depends on a usable /proc/%d/fd/%d
filesystem and this is checked and set as "can_reopen" flag by the VFS in the
openat() function in the fsp.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_fruit: disable fd reopening optimisations for the two special macOS streams
Ralph Boehme [Tue, 24 Nov 2020 17:02:26 +0000 (18:02 +0100)] 
vfs_fruit: disable fd reopening optimisations for the two special macOS streams

I couldn't figure out why the reopen fails a few vfs.fruit tests, so for now
disable the optimisations. It only affects the two special Mac streams, so it's
not *that* bad, but definitely something we would want to improve on in the near
future.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_xattr_tdb: don't leak the fd into the caller
Ralph Boehme [Tue, 24 Nov 2020 15:16:10 +0000 (16:16 +0100)] 
vfs_xattr_tdb: don't leak the fd into the caller

This is subtle: generally fsp_set_fd(fd) is called in the caller of
SMB_VFS_OPENAT() in non_widelink_open().

fsp_set_fd() has a check that asserts certain combindations of the existing
fsp->fh->fd and the new fd. Both being valid fds is not allowed.

Therefor inside the VFS we must reset fsp->fh->fd if we've set it.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: reuse smb_fname->fsp in create_file_default()
Ralph Boehme [Fri, 2 Oct 2020 15:40:41 +0000 (17:40 +0200)] 
smbd: reuse smb_fname->fsp in create_file_default()

This is the big bang for the internal pathref fsps: up to this point the pathref
fsps were lingering around unused inside smb_fname->fsp.

With this change, the internal fsp will be the one that is going to be returned
from SMB_VFS_CREATE_FILE() if the client requested access mask matches the
criteria in open_file():

uint32_t need_fd_mask =
FILE_READ_DATA |
FILE_WRITE_DATA |
FILE_APPEND_DATA |
FILE_EXECUTE |
WRITE_DAC_ACCESS |
WRITE_OWNER_ACCESS |
SEC_FLAG_SYSTEM_SECURITY |
READ_CONTROL_ACCESS;

As long as the client doesn't request any of the access rights listed above, we
reuse the smb_fname->fsp, otherwise we close the smb_fname->fsp and call
fd_open() to open a new fsp.

In the future we can remove the four non-IO related access rights from the list:

WRITE_DAC_ACCESS |
WRITE_OWNER_ACCESS |
SEC_FLAG_SYSTEM_SECURITY |
READ_CONTROL_ACCESS

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: replace a stat() with an fstat() in create_file_unixpath()
Ralph Boehme [Mon, 23 Nov 2020 06:46:42 +0000 (07:46 +0100)] 
smbd: replace a stat() with an fstat() in create_file_unixpath()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: we DO NEED the low level fd
Ralph Boehme [Tue, 27 Oct 2020 18:21:48 +0000 (19:21 +0100)] 
smbd: we DO NEED the low level fd

In order to make everything handle based, we will need the basefile handle when
eg the client requests setting any of the filemetadata that is common across all
streams, eg the file's timestamps.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: call open_pathref_fsp() in unlink_internals() in wildcard matching loop
Ralph Boehme [Fri, 17 Jul 2020 17:35:50 +0000 (19:35 +0200)] 
smbd: call open_pathref_fsp() in unlink_internals() in wildcard matching loop

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: prevent non-POSIX stat-opens of symlinks in open_file()
Ralph Boehme [Thu, 1 Oct 2020 12:40:33 +0000 (14:40 +0200)] 
smbd: prevent non-POSIX stat-opens of symlinks in open_file()

Also adjust the test that checks for this.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agonet: use openat_pathref_fsp() in net_vfs_get_ntacl()
Ralph Boehme [Thu, 12 Nov 2020 15:54:28 +0000 (16:54 +0100)] 
net: use openat_pathref_fsp() in net_vfs_get_ntacl()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: avoid a smb_fname copy in smb_set_file_size()
Ralph Boehme [Thu, 12 Nov 2020 15:51:26 +0000 (16:51 +0100)] 
smbd: avoid a smb_fname copy in smb_set_file_size()

Now that we get a non-const smb_fname we can use that for the call to
SMB_VFS_CREATE_FILE().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: unconst smb_fname arg of all setfileinfo worker functions
Ralph Boehme [Thu, 12 Nov 2020 15:28:41 +0000 (16:28 +0100)] 
smbd: unconst smb_fname arg of all setfileinfo worker functions

This allows avoiding making copies of the smb_fname when it needs to be passed
to a function that takes a non-const smb_fname.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use openat_pathref_fsp() in call_trans2findfirst()
Ralph Boehme [Thu, 12 Nov 2020 14:51:59 +0000 (15:51 +0100)] 
smbd: use openat_pathref_fsp() in call_trans2findfirst()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

Also drop pathref fsp from filename_convert() in call_trans2findfirst(), because
the call to filename_convert() is on the path from the client including the
search mask.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: un-const smb_fname in get_posix_fsp()
Ralph Boehme [Thu, 12 Nov 2020 14:48:15 +0000 (15:48 +0100)] 
smbd: un-const smb_fname in get_posix_fsp()

Avoids making a copy of smb_fname which allows using smb_fname->fsp if there is
one.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use openat_pathref_fsp() in copy_file()
Ralph Boehme [Thu, 12 Nov 2020 14:46:57 +0000 (15:46 +0100)] 
smbd: use openat_pathref_fsp() in copy_file()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use openat_pathref_fsp() rename_internals()
Ralph Boehme [Thu, 12 Nov 2020 14:44:08 +0000 (15:44 +0100)] 
smbd: use openat_pathref_fsp() rename_internals()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agoprinting: use openat_pathref_fsp() in driver_unlink_internals()
Ralph Boehme [Thu, 12 Nov 2020 13:57:45 +0000 (14:57 +0100)] 
printing: use openat_pathref_fsp() in driver_unlink_internals()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use openat_pathref_fsp() in reply_search()
Ralph Boehme [Thu, 12 Nov 2020 13:52:31 +0000 (14:52 +0100)] 
smbd: use openat_pathref_fsp() in reply_search()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use openat_pathref_fsp() in open_streams_for_delete()
Ralph Boehme [Thu, 12 Nov 2020 11:56:56 +0000 (12:56 +0100)] 
smbd: use openat_pathref_fsp() in open_streams_for_delete()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use openat_pathref_fsp() in get_file_handle_for_metadata()
Ralph Boehme [Thu, 12 Nov 2020 11:51:04 +0000 (12:51 +0100)] 
smbd: use openat_pathref_fsp() in get_file_handle_for_metadata()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agoprinting: use openat_pathref_fsp() in get_correct_cversion()
Ralph Boehme [Thu, 12 Nov 2020 11:47:19 +0000 (12:47 +0100)] 
printing: use openat_pathref_fsp() in get_correct_cversion()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agoprinting: use openat_pathref_fsp() in file_version_is_newer()
Ralph Boehme [Thu, 12 Nov 2020 11:39:29 +0000 (12:39 +0100)] 
printing: use openat_pathref_fsp() in file_version_is_newer()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agoprinting: use openat_pathref_fsp() in file_version_is_newer()
Ralph Boehme [Thu, 12 Nov 2020 11:38:43 +0000 (12:38 +0100)] 
printing: use openat_pathref_fsp() in file_version_is_newer()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/libadouble: use openat_pathref_fsp() in readdir_attr_meta_finderi_stream()
Ralph Boehme [Thu, 12 Nov 2020 11:37:52 +0000 (12:37 +0100)] 
s3/libadouble: use openat_pathref_fsp() in readdir_attr_meta_finderi_stream()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/libadouble: use openat_pathref_fsp() in ad_open_rsrc()
Ralph Boehme [Thu, 12 Nov 2020 11:34:21 +0000 (12:34 +0100)] 
s3/libadouble: use openat_pathref_fsp() in ad_open_rsrc()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

As the create_disposition is FILE_OPEN we just return the error if
openat_pathref_fsp() fails

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/libadouble: use openat_pathref_fsp() in ad_collect_one_stream()
Ralph Boehme [Thu, 12 Nov 2020 11:32:02 +0000 (12:32 +0100)] 
s3/libadouble: use openat_pathref_fsp() in ad_collect_one_stream()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/libadouble: use openat_pathref_fsp() in ad_unconvert_get_streams()
Ralph Boehme [Thu, 12 Nov 2020 11:31:13 +0000 (12:31 +0100)] 
s3/libadouble: use openat_pathref_fsp() in ad_unconvert_get_streams()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/libadouble: use openat_pathref_fsp() in ad_unconvert_open_ad()
Ralph Boehme [Thu, 12 Nov 2020 11:30:18 +0000 (12:30 +0100)] 
s3/libadouble: use openat_pathref_fsp() in ad_unconvert_open_ad()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/libadouble: use openat_pathref_fsp() in ad_convert_finderinfo()
Ralph Boehme [Thu, 12 Nov 2020 11:28:30 +0000 (12:28 +0100)] 
s3/libadouble: use openat_pathref_fsp() in ad_convert_finderinfo()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/libadouble: use openat_pathref_fsp() in ad_convert_xattr()
Ralph Boehme [Thu, 12 Nov 2020 11:25:56 +0000 (12:25 +0100)] 
s3/libadouble: use openat_pathref_fsp() in ad_convert_xattr()

Ensures we have a pathref handle in the smb_fname we pass to
SMB_VFS_CREATE_FILE().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use open_pathref_fsp() in filename_convert_internal()
Ralph Boehme [Sat, 13 Jun 2020 17:16:39 +0000 (19:16 +0200)] 
smbd: use open_pathref_fsp() in filename_convert_internal()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use common exit in filename_convert_internal()
Ralph Boehme [Mon, 23 Nov 2020 05:40:16 +0000 (06:40 +0100)] 
smbd: use common exit in filename_convert_internal()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: add need_fsa arg and logic to file_find_di_(first|next)
Ralph Boehme [Thu, 19 Nov 2020 10:35:23 +0000 (11:35 +0100)] 
smbd: add need_fsa arg and logic to file_find_di_(first|next)

All callers except rename_open_files() can ignore non FSA fsps.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: ignore non FSA fsps in file_find_dif()
Ralph Boehme [Thu, 19 Nov 2020 10:21:42 +0000 (11:21 +0100)] 
smbd: ignore non FSA fsps in file_find_dif()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: reduce indentation in file_find_dif()
Ralph Boehme [Thu, 19 Nov 2020 10:10:35 +0000 (11:10 +0100)] 
smbd: reduce indentation in file_find_dif()

No change in behaviour.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: README.Coding fixes in file_find_dif()
Ralph Boehme [Thu, 19 Nov 2020 10:09:05 +0000 (11:09 +0100)] 
smbd: README.Coding fixes in file_find_dif()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use move_smb_fname_fsp_link() in fsp_set_smb_fname()
Ralph Boehme [Mon, 23 Nov 2020 05:23:12 +0000 (06:23 +0100)] 
smbd: use move_smb_fname_fsp_link() in fsp_set_smb_fname()

This ensures that fsp->fsp_name->fsp is again set to the fsp and also preserves
the link fsp->fsp_name->fsp_link.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: maintain correct destructor order in fsp_free()
Ralph Boehme [Wed, 10 Jun 2020 13:21:35 +0000 (15:21 +0200)] 
smbd: maintain correct destructor order in fsp_free()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: add move_smb_fname_fsp_link()
Ralph Boehme [Mon, 23 Nov 2020 05:00:40 +0000 (06:00 +0100)] 
smbd: add move_smb_fname_fsp_link()

Function to move fsps from one smb_fname to another.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: add smb_fname_fsp_unlink()
Ralph Boehme [Mon, 23 Nov 2020 04:59:02 +0000 (05:59 +0100)] 
smbd: add smb_fname_fsp_unlink()

Remove the link between an smb_fname and it's embedded smb_fname->fsp.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: add openat_pathref_fsp()
Ralph Boehme [Tue, 29 Sep 2020 08:14:47 +0000 (10:14 +0200)] 
smbd: add openat_pathref_fsp()

open_pathref_fsp() opens an "embedded" fsp inside smb_fname as
smb_fname->fsp. We call such an fsp a "pathref" fsp.

On system that support O_PATH the low level openat() is done with O_PATH. On
systems that lack support for O_PATH, we impersonate the root user as a
fallback.

Setting "is_pathref" in the fsp_flags before calling fd_openat() is what
triggers the special low-level behaviour inside the VFS.

The use of pathref fsps allows updating all callers of path based VFS functions
like

  dos_mode(smb_fname)
  -> SMB_VFS_GET_DOS_ATTRIBUTES(smb_fname)
     -> SMB_VFS_GETXATTR(smb_fname)

to use the handle based VFS function like

  fdos_mode(smb_fname->fsp)
  -> SMB_VFS_FGET_DOS_ATTRIBUTES(fsp)
     -> SMB_VFS_FGETXATTR(fsp)

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: remove SMB_VFS_FSTAT() from open_file()
Ralph Boehme [Tue, 17 Nov 2020 15:05:11 +0000 (16:05 +0100)] 
smbd: remove SMB_VFS_FSTAT() from open_file()

This is now done in non_widelink_open().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: always fstat in non_widelink_open()
Ralph Boehme [Mon, 16 Nov 2020 12:54:49 +0000 (13:54 +0100)] 
smbd: always fstat in non_widelink_open()

This way we can avoid stating twice: once here and possibly a second time in
the caller open_file().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: convert non_widelink_open() and process_symlink_open() to return NTSTATUS
Ralph Boehme [Tue, 24 Nov 2020 11:30:58 +0000 (12:30 +0100)] 
smbd: convert non_widelink_open() and process_symlink_open() to return NTSTATUS

non_widelink_open() now also returns NT_STATUS_STOPPED_ON_SYMLINK in case an
attempt was made to either

1. open a symlink from a POSIX client, or

2. open a symlink from a Windows client but any of the symlink behaviour
   configuring options "follow symlink", "wide links" or "allow insecure wide
   links" prevents access to the symlink target

Caller open_file() has already been updated to map NT_STATUS_STOPPED_ON_SYMLINK
to NT_STATUS_NT_STATUS_OBJECT_PATH_NOT_FOUND.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: maps NT_STATUS_STOPPED_ON_SYMLINK to NT_STATUS_OBJECT_PATH_NOT_FOUND in open_file()
Ralph Boehme [Fri, 23 Oct 2020 10:16:38 +0000 (12:16 +0200)] 
smbd: maps NT_STATUS_STOPPED_ON_SYMLINK to NT_STATUS_OBJECT_PATH_NOT_FOUND in open_file()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: pass private_flags to open_file()
Ralph Boehme [Mon, 26 Oct 2020 11:31:10 +0000 (12:31 +0100)] 
smbd: pass private_flags to open_file()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: deal with real dirfsps in non_widelink_open()
Ralph Boehme [Tue, 24 Nov 2020 11:30:28 +0000 (12:30 +0100)] 
smbd: deal with real dirfsps in non_widelink_open()

If we get a real dirfsp, skip the parent-directory logic. Just pass the dirfsp
to SMB_VFS_OPENAT() which by now supports real dirfsps.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: simplify setting and resetting fsp->fsp_name in non_widelink_open()
Ralph Boehme [Mon, 19 Oct 2020 08:19:28 +0000 (10:19 +0200)] 
smbd: simplify setting and resetting fsp->fsp_name in non_widelink_open()

Instead of setting and resetting the name to the relative name every time we
call into the VFS, just set it once and reset it at the end and when recursing
via process_symlink_open().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use orig_fsp_name as variable name in non_widelink_open()
Ralph Boehme [Mon, 19 Oct 2020 08:16:06 +0000 (10:16 +0200)] 
smbd: use orig_fsp_name as variable name in non_widelink_open()

No change in behaviour.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: remove unused cwdfsp from non_widelink_open()
Ralph Boehme [Tue, 13 Oct 2020 14:47:51 +0000 (16:47 +0200)] 
smbd: remove unused cwdfsp from non_widelink_open()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: pass dirfsp down to non_widelink_open() and process_symlink_open()
Ralph Boehme [Tue, 13 Oct 2020 14:38:18 +0000 (16:38 +0200)] 
smbd: pass dirfsp down to non_widelink_open() and process_symlink_open()

Callers still all pass conn->cwd_fsp so no change in behaviour yet.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: pass a dirfsp to fd_open() and rename it to fd_openat()
Ralph Boehme [Tue, 13 Oct 2020 12:38:28 +0000 (14:38 +0200)] 
smbd: pass a dirfsp to fd_open() and rename it to fd_openat()

For now no change in behaviour as all callers still pass conn->cwd_fsp. This
just prepared fd_openat() to deal with real dirfsp's pass by callers later on
when adding calls to fd_openat(dirfspm ...) in the directory enumeration loop.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: catch O_PATH opens of symlinks in in non_widelink_open()
Ralph Boehme [Tue, 29 Sep 2020 08:00:21 +0000 (10:00 +0200)] 
smbd: catch O_PATH opens of symlinks in in non_widelink_open()

Calling openat() with O_PATH|O_NOFOLLOW will open a handle on the symlink
itself. That would be a nice feature if it would be supported on more platforms,
but being a Linux only thing, we have to preserve the behaviour of failing to
open a handle on symlinks.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: already set fsp fd in non_widelink_open()
Ralph Boehme [Mon, 12 Oct 2020 11:21:07 +0000 (13:21 +0200)] 
smbd: already set fsp fd in non_widelink_open()

A subsequent commit will add a consumer of the fd to non_widelink_open() (by
calling SMB_VFS_FSTAT()), so we need to set the fd already here. And it makes
more sense anyway. :)

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: check for pathref fd's in vfs_set_blocking()
Ralph Boehme [Mon, 26 Oct 2020 13:39:02 +0000 (14:39 +0100)] 
smbd: check for pathref fd's in vfs_set_blocking()

Don't try to set pathref fd's to non-blocking, they're not used with IO.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_shadow_copy2: deal with real dirfsps in shadow_copy2_openat()
Ralph Boehme [Fri, 16 Oct 2020 10:28:39 +0000 (12:28 +0200)] 
vfs_shadow_copy2: deal with real dirfsps in shadow_copy2_openat()

Prepare shadow_copy2_openat() for real dirfsps flying by.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3: add full_path_from_dirfsp_atname()
Ralph Boehme [Tue, 14 Apr 2020 15:44:37 +0000 (17:44 +0200)] 
s3: add full_path_from_dirfsp_atname()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_glusterfs: implement pathref opens with become_root() fallback
Ralph Boehme [Thu, 1 Oct 2020 13:44:15 +0000 (15:44 +0200)] 
vfs_glusterfs: implement pathref opens with become_root() fallback

Until glusterfs supports O_PATH, fallback to become_root().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_ceph: implement pathref opens in cephwrap_openat()
Ralph Boehme [Thu, 1 Oct 2020 13:44:15 +0000 (15:44 +0200)] 
vfs_ceph: implement pathref opens in cephwrap_openat()

Ceph supports O_PATH since v0.93 from 2015:

https://ceph.io/geen-categorie/v0-93-hammer-release-candidate-released/

This seems to be old enough so we can hopefully use this without a runtime
version check.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_default: implement pathref opens in vfswrap_openat()
Ralph Boehme [Fri, 9 Oct 2020 12:24:43 +0000 (14:24 +0200)] 
vfs_default: implement pathref opens in vfswrap_openat()

If the system supports O_PATH we use that, otherwise we fallback to root opens.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd/posix_acls: support pathref fd's in posix_sys_acl_blob_get_fd()
Ralph Boehme [Thu, 1 Oct 2020 13:22:18 +0000 (15:22 +0200)] 
smbd/posix_acls: support pathref fd's in posix_sys_acl_blob_get_fd()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_posixacl: support pathref fd's in posixacl_sys_acl_set_fd()
Ralph Boehme [Thu, 1 Oct 2020 13:21:45 +0000 (15:21 +0200)] 
vfs_posixacl: support pathref fd's in posixacl_sys_acl_set_fd()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_posixacl: support pathref fd's in posixacl_sys_acl_get_fd()
Ralph Boehme [Thu, 1 Oct 2020 13:20:56 +0000 (15:20 +0200)] 
vfs_posixacl: support pathref fd's in posixacl_sys_acl_get_fd()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_fruit: skip Netatalk locking checks for path-ref fd's
Ralph Boehme [Sat, 1 Aug 2020 14:19:20 +0000 (16:19 +0200)] 
vfs_fruit: skip Netatalk locking checks for path-ref fd's

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_default: support pathref fd's in vfswrap_fsetxattr()
Ralph Boehme [Tue, 29 Sep 2020 09:11:53 +0000 (11:11 +0200)] 
vfs_default: support pathref fd's in vfswrap_fsetxattr()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_default: support pathref fd's in vfswrap_fremovexattr()
Ralph Boehme [Tue, 29 Sep 2020 09:10:51 +0000 (11:10 +0200)] 
vfs_default: support pathref fd's in vfswrap_fremovexattr()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_default: support pathref fd's in vfswrap_flistxattr()
Ralph Boehme [Tue, 29 Sep 2020 08:56:19 +0000 (10:56 +0200)] 
vfs_default: support pathref fd's in vfswrap_flistxattr()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_default: support pathref fd's in vfswrap_fgetxattr()
Ralph Boehme [Tue, 29 Sep 2020 08:55:52 +0000 (10:55 +0200)] 
vfs_default: support pathref fd's in vfswrap_fgetxattr()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_default: initialize conn->have_proc_fds
Ralph Boehme [Wed, 25 Nov 2020 06:05:20 +0000 (07:05 +0100)] 
vfs_default: initialize conn->have_proc_fds

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_default: fix indentation
Ralph Boehme [Wed, 25 Nov 2020 06:04:31 +0000 (07:04 +0100)] 
vfs_default: fix indentation

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs: add fsp flag "have_proc_fds"
Ralph Boehme [Tue, 24 Nov 2020 11:20:23 +0000 (12:20 +0100)] 
vfs: add fsp flag "have_proc_fds"

This flag is used by the VFS layer to tell the FSA layer that it is allowed to
reopen an fsp by using an exisiting pathref fd with /proc/PID/fd/FD to open a
full fd.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs: add struct connection_struct flag "have_proc_fds"
Ralph Boehme [Wed, 25 Nov 2020 04:32:19 +0000 (05:32 +0100)] 
vfs: add struct connection_struct flag "have_proc_fds"

Allows the VFS layer to tell the higher layers if fds opened by the openat() VFS
implementation are visible objects inside a /proc/PID/fd/FD filesystem.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs_error_inject: ignore path_ref_fd's
Ralph Boehme [Mon, 15 Jun 2020 09:33:39 +0000 (11:33 +0200)] 
vfs_error_inject: ignore path_ref_fd's

This avoids failing opens triggered by filename_convert() ->
openat_pathref_fsp().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agos3/lib: add proc fds infrastructure
Ralph Boehme [Wed, 30 Sep 2020 12:45:34 +0000 (14:45 +0200)] 
s3/lib: add proc fds infrastructure

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs: make struct fd_handle private
Ralph Boehme [Sun, 27 Sep 2020 17:39:37 +0000 (19:39 +0200)] 
vfs: make struct fd_handle private

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: remove redundant initialisation of the fsp fd
Ralph Boehme [Fri, 2 Oct 2020 15:40:51 +0000 (17:40 +0200)] 
smbd: remove redundant initialisation of the fsp fd

This is already set to -1 by fd_handle_create().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fd_handle_create()
Ralph Boehme [Sun, 27 Sep 2020 19:16:03 +0000 (21:16 +0200)] 
smbd: use fd_handle_create()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fh_[get|set]_refcount()
Ralph Boehme [Mon, 28 Sep 2020 08:37:36 +0000 (10:37 +0200)] 
smbd: use fh_[get|set]_refcount()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fh_[get|set]_private_options()
Ralph Boehme [Fri, 23 Oct 2020 15:47:46 +0000 (17:47 +0200)] 
smbd: use fh_[get|set]_private_options()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fh_[get|set]_gen_id()
Ralph Boehme [Mon, 28 Sep 2020 08:35:32 +0000 (10:35 +0200)] 
smbd: use fh_[get|set]_gen_id()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fh_[get|set]_pos() and fh_[get|set]_position_information()
Ralph Boehme [Mon, 28 Sep 2020 08:32:29 +0000 (10:32 +0200)] 
smbd: use fh_[get|set]_pos() and fh_[get|set]_position_information()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fsp_get_pathref_fd() for logical fd comparisons
Ralph Boehme [Mon, 5 Oct 2020 05:51:50 +0000 (07:51 +0200)] 
smbd: use fsp_get_pathref_fd() for logical fd comparisons

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fsp_get_pathref_fd() for fstat() calls
Ralph Boehme [Mon, 5 Oct 2020 05:50:16 +0000 (07:50 +0200)] 
smbd: use fsp_get_pathref_fd() for fstat() calls

If we can access the path to a file, by default we have FILE_READ_ATTRIBUTES
from the containing directory. See the section: "Algorithm to Check Access to an
Existing File" in MS-FSA.pdf.

So it's also safe to use a root opened pathref fd, as the root open is done on
the final component after a chdir() to the parent directory was done while still
impersonating the use. Qed.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fsp_get_pathref_fd() for "internal" xattr functions
Ralph Boehme [Sun, 4 Oct 2020 12:48:48 +0000 (14:48 +0200)] 
smbd: use fsp_get_pathref_fd() for "internal" xattr functions

We're using xattr data storage for internal reasons in these places, so in all
places it's safe to use a possibly root opened fd.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fsp_get_pathref_fd() for *at related directory handles
Ralph Boehme [Sat, 17 Oct 2020 15:01:47 +0000 (17:01 +0200)] 
smbd: use fsp_get_pathref_fd() for *at related directory handles

Obviously correct to use fsp_get_pathref_fd() here.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fsp_get_pathref_fd() when close()ing fds
Ralph Boehme [Sat, 3 Oct 2020 19:24:29 +0000 (21:24 +0200)] 
smbd: use fsp_get_pathref_fd() when close()ing fds

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fsp_get_pathref_fd() as part of DEBUG and syslog messages
Ralph Boehme [Sat, 3 Oct 2020 15:41:17 +0000 (17:41 +0200)] 
smbd: use fsp_get_pathref_fd() as part of DEBUG and syslog messages

Nothing really dangerous is done with the fds here, so we can safely use
fsp_get_pathref_fd() in these cases.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fsp_get_io_fd() when accessing a file or it's associated metadata
Ralph Boehme [Sat, 26 Sep 2020 19:52:52 +0000 (21:52 +0200)] 
smbd: use fsp_get_io_fd() when accessing a file or it's associated metadata

In all places where we access or modify a file or it's associated metadata, we
use fsp_get_io_fd() to fetch the low-level fd from the fsp. This ensures we
don't accidentally use a pathref fsp where the fd would be opened as root on
systems lacking O_PATH.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: use fsp_set_fd()
Ralph Boehme [Sat, 26 Sep 2020 19:46:51 +0000 (21:46 +0200)] 
smbd: use fsp_set_fd()

No change in behaviour.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agosmbd: add fd_handle.[c|h]
Ralph Boehme [Sun, 27 Sep 2020 11:14:30 +0000 (13:14 +0200)] 
smbd: add fd_handle.[c|h]

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs: add "is_fsa" flag to struct files_struct
Ralph Boehme [Sun, 22 Nov 2020 12:54:51 +0000 (13:54 +0100)] 
vfs: add "is_fsa" flag to struct files_struct

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
4 years agovfs: add "is_pathref" to struct files_struct
Ralph Boehme [Tue, 14 Jul 2020 08:10:19 +0000 (10:10 +0200)] 
vfs: add "is_pathref" to struct files_struct

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>