samba.git
3 years agosmbd: use fdos_mode() in setup_close_full_information()
Ralph Boehme [Mon, 19 Oct 2020 18:53:48 +0000 (20:53 +0200)]
smbd: use fdos_mode() in setup_close_full_information()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in reply_getattrE()
Ralph Boehme [Mon, 19 Oct 2020 18:49:02 +0000 (20:49 +0200)]
smbd: use fdos_mode() in reply_getattrE()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in copy_file()
Ralph Boehme [Mon, 19 Oct 2020 18:48:43 +0000 (20:48 +0200)]
smbd: use fdos_mode() in copy_file()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in rename_internals_fsp()
Ralph Boehme [Fri, 30 Oct 2020 15:08:03 +0000 (16:08 +0100)]
smbd: use fdos_mode() in rename_internals_fsp()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: README.Coding fixes in rename_internals_fsp()
Ralph Boehme [Fri, 30 Oct 2020 15:06:38 +0000 (16:06 +0100)]
smbd: README.Coding fixes in rename_internals_fsp()

No change in behaviour.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use SMB_VFS_FSTAT() in rename_internals_fsp()
Ralph Boehme [Fri, 30 Oct 2020 15:03:19 +0000 (16:03 +0100)]
smbd: use SMB_VFS_FSTAT() in rename_internals_fsp()

While at it, use the open handle on the renamed file to call fstat() instead of
stat().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: call rename_open_files() a bit earlier in rename_internals_fsp()
Ralph Boehme [Fri, 30 Oct 2020 14:38:22 +0000 (15:38 +0100)]
smbd: call rename_open_files() a bit earlier in rename_internals_fsp()

This prepares for using handle based SMB_VFS_FSTAT() and fdos_mode() a few lines
below. As some VFS modules will use the fsp->fsp_name we have to make sure to
rename it first.

Fwiw, notify_rename() is moved as well as it needs to original name in
fsp->fsp_name.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in do_unlink()
Ralph Boehme [Mon, 19 Oct 2020 18:43:21 +0000 (20:43 +0200)]
smbd: use fdos_mode() in do_unlink()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in can_rename()
Ralph Boehme [Mon, 19 Oct 2020 18:42:41 +0000 (20:42 +0200)]
smbd: use fdos_mode() in can_rename()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in reply_open_and_X()
Ralph Boehme [Mon, 19 Oct 2020 18:42:03 +0000 (20:42 +0200)]
smbd: use fdos_mode() in reply_open_and_X()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in reply_open()
Ralph Boehme [Mon, 19 Oct 2020 18:41:43 +0000 (20:41 +0200)]
smbd: use fdos_mode() in reply_open()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in reply_getatr()
Ralph Boehme [Mon, 19 Oct 2020 18:41:18 +0000 (20:41 +0200)]
smbd: use fdos_mode() in reply_getatr()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in open_file_ntcreate()
Ralph Boehme [Mon, 19 Oct 2020 18:40:51 +0000 (20:40 +0200)]
smbd: use fdos_mode() in open_file_ntcreate()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in check_base_file_access()
Ralph Boehme [Mon, 19 Oct 2020 18:39:37 +0000 (20:39 +0200)]
smbd: use fdos_mode() in check_base_file_access()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in copy_internals()
Ralph Boehme [Mon, 19 Oct 2020 18:38:27 +0000 (20:38 +0200)]
smbd: use fdos_mode() in copy_internals()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in call_nt_transact_create()
Ralph Boehme [Mon, 19 Oct 2020 18:37:24 +0000 (20:37 +0200)]
smbd: use fdos_mode() in call_nt_transact_create()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in reply_ntcreate_and_X()
Ralph Boehme [Mon, 19 Oct 2020 18:36:19 +0000 (20:36 +0200)]
smbd: use fdos_mode() in reply_ntcreate_and_X()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in mark_file_modified()
Ralph Boehme [Mon, 19 Oct 2020 18:32:49 +0000 (20:32 +0200)]
smbd: use fdos_mode() in mark_file_modified()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in vfs_default_durable_reconnect()
Ralph Boehme [Mon, 19 Oct 2020 18:32:05 +0000 (20:32 +0200)]
smbd: use fdos_mode() in vfs_default_durable_reconnect()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in set_create_timespec_ea()
Ralph Boehme [Mon, 19 Oct 2020 18:31:15 +0000 (20:31 +0200)]
smbd: use fdos_mode() in set_create_timespec_ea()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: drop pathref from smb_fname_dst_in in rename_internals_fsp()
Ralph Boehme [Thu, 29 Oct 2020 17:36:08 +0000 (18:36 +0100)]
smbd: drop pathref from smb_fname_dst_in in rename_internals_fsp()

The pathref is not needed anymore below this point and it conflicts with the
code that checks for open handles on the destination just below.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: un-const smb_fname_dst_in arg of rename_internals_fsp()
Ralph Boehme [Thu, 29 Oct 2020 17:30:19 +0000 (18:30 +0100)]
smbd: un-const smb_fname_dst_in arg of rename_internals_fsp()

A subsequent commit is going to modify smb_fname_dst_in.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agovfstest: use filename_convert() in cmd_utime()
Ralph Boehme [Wed, 28 Oct 2020 10:31:46 +0000 (11:31 +0100)]
vfstest: use filename_convert() in cmd_utime()

Ensures we have a pathref fsp when calling SMB_VFS_NTIMES().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in file_set_sparse()
Ralph Boehme [Mon, 19 Oct 2020 18:29:28 +0000 (20:29 +0200)]
smbd: use fdos_mode() in file_set_sparse()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in smbd_dirptr_8_3_mode_fn()
Ralph Boehme [Wed, 25 Nov 2020 15:35:11 +0000 (16:35 +0100)]
smbd: use fdos_mode() in smbd_dirptr_8_3_mode_fn()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fdos_mode() in smbd_dirptr_lanman2_mode_fn()
Ralph Boehme [Mon, 19 Oct 2020 14:40:18 +0000 (16:40 +0200)]
smbd: use fdos_mode() in smbd_dirptr_lanman2_mode_fn()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: add fdos_mode()
Ralph Boehme [Mon, 19 Oct 2020 13:44:29 +0000 (15:44 +0200)]
smbd: add fdos_mode()

Note that this continues using the braindead dual path/handle based API mistake,
but only in order to reuse the util functions and because this is an
intermediate step to support transitioning to an all handle based flow.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agovfs_gpfs: fix bogus compiler warning
Ralph Boehme [Tue, 20 Oct 2020 19:59:35 +0000 (21:59 +0200)]
vfs_gpfs: fix bogus compiler warning

The next commit adds the first call inside Samba to the VFS function
SMB_VFS_FGET_DOS_ATTRIBUTES() and therefor also to
vfs_gpfs_fget_dos_attributes().  No idea why gcc is generating this warning:

[4127/4716] Compiling source3/modules/vfs_aio_fork.c
../../source3/modules/vfs_gpfs.c: In function ‘vfs_gpfs_fget_dos_attributes’:
../../source3/modules/vfs_gpfs.c:1728:2: error: ‘file_id’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1728 |  update_stat_ex_file_id(&fsp->fsp_name->st, file_id);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
cc1: all warnings being treated as errors

This change fixes the error.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use fsp in smb_set_file_time()
Ralph Boehme [Wed, 28 Oct 2020 11:24:14 +0000 (12:24 +0100)]
smbd: use fsp in smb_set_file_time()

Ensure we have a valid fsp whos name we pass to file_ntimes(). Remember,
file_ntimes() by default ends up calling SMB_VFS_GET_DOS_ATTRIBUTES() under the
hood in order to get/set the creation date.

As any fsp->fsp_name contains a backpointer to the fsp ie

  fsp->fsp_name->fsp == fsp

passing set_fsp->fsp_name to file_ntimes() allows replacing the path based
SMB_VFS_GET_DOS_ATTRIBUTES() with SMB_VFS_FGET_DOS_ATTRIBUTES() under the hoods.

Also use the base_fsp->fsp_name for the base name in case of setting the
timestamps on a stream.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: always use check_access_fsp() in smb_set_info_standard()
Ralph Boehme [Tue, 27 Oct 2020 20:13:36 +0000 (21:13 +0100)]
smbd: always use check_access_fsp() in smb_set_info_standard()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: always use check_access_fsp() in smb_set_file_basic_info()
Ralph Boehme [Tue, 27 Oct 2020 20:13:12 +0000 (21:13 +0100)]
smbd: always use check_access_fsp() in smb_set_file_basic_info()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: in reply_setatr() pass pathref fsp to smb_set_file_time()
Ralph Boehme [Wed, 4 Nov 2020 09:09:34 +0000 (10:09 +0100)]
smbd: in reply_setatr() pass pathref fsp to smb_set_file_time()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use check_access_fsp() in set_ea()
Ralph Boehme [Tue, 27 Oct 2020 20:12:22 +0000 (21:12 +0100)]
smbd: use check_access_fsp() in set_ea()

We now always have a fsp.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use pathref fsp in call_trans2setfilepathinfo()
Ralph Boehme [Tue, 17 Nov 2020 11:14:19 +0000 (12:14 +0100)]
smbd: use pathref fsp in call_trans2setfilepathinfo()

This means we're now passing a valid fsp to all setinfo functions. The only
special case being when dealing with a symlink in POSIX context.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use pathref fsp in call_trans2qfilepathinfo()
Ralph Boehme [Tue, 17 Nov 2020 06:54:42 +0000 (07:54 +0100)]
smbd: use pathref fsp in call_trans2qfilepathinfo()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use SMB_VFS_CREATE_FILE() in call_trans2mkdir()
Ralph Boehme [Wed, 28 Oct 2020 09:35:59 +0000 (10:35 +0100)]
smbd: use SMB_VFS_CREATE_FILE() in call_trans2mkdir()

Use SMB_VFS_CREATE_FILE() instead of the create_directory() in order to have a
fsp that we can pass to set_ea().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: check for non FSA fsps in smb_file_rename_information()
Ralph Boehme [Tue, 17 Nov 2020 11:11:13 +0000 (12:11 +0100)]
smbd: check for non FSA fsps in smb_file_rename_information()

If the fsp is a non FSA fsp created by openat_pathref_fsp(), we can't pass it to
rename_internals_fsp(). We have to go via rename_internals() which internally
uses SMB_VFS_CREATE_FILE() to open an fsp which ensure we go through the lease
checking code.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: deal with non FSA fsps in check_access_fsp()
Ralph Boehme [Tue, 17 Nov 2020 11:09:05 +0000 (12:09 +0100)]
smbd: deal with non FSA fsps in check_access_fsp()

For fsps coming out of openat_pathref_fsp() and not SMB_VFS_CREATE_FILE(),
fsp->access_mask will be 0 and we check the requested rights against the
permissions of the object opened by the fsp.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: unconst fsp arg of check_access_fsp()
Ralph Boehme [Tue, 17 Nov 2020 11:08:48 +0000 (12:08 +0100)]
smbd: unconst fsp arg of check_access_fsp()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: check for valid FSA fsp in smb_set_posix_acl()
Ralph Boehme [Mon, 16 Nov 2020 17:37:42 +0000 (18:37 +0100)]
smbd: check for valid FSA fsp in smb_set_posix_acl()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: check for valid FSA fsp in smb_query_posix_acl()
Ralph Boehme [Mon, 16 Nov 2020 17:37:11 +0000 (18:37 +0100)]
smbd: check for valid FSA fsp in smb_query_posix_acl()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: adjust allocation size check across handles in smbd_do_qfilepathinfo()
Ralph Boehme [Tue, 17 Nov 2020 06:59:13 +0000 (07:59 +0100)]
smbd: adjust allocation size check across handles in smbd_do_qfilepathinfo()

Check all open files if either we don't have an fsp or if the fsp is not a full
FSA fsp, ie not one which was created by SMB_VFS_CREATE_FILE() but by
openat_pathref_fsp().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: add smbd_check_access_rights_fsp()
Ralph Boehme [Tue, 27 Oct 2020 10:24:03 +0000 (11:24 +0100)]
smbd: add smbd_check_access_rights_fsp()

Handle based version of smbd_check_access_rights().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: factor out smbd_check_access_rights_sd() from smbd_check_access_rights()
Ralph Boehme [Tue, 27 Oct 2020 10:23:03 +0000 (11:23 +0100)]
smbd: factor out smbd_check_access_rights_sd() from smbd_check_access_rights()

No change in behaviour.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: call open_pathref_fsp() in smbd_dirptr_get_entry()
Ralph Boehme [Thu, 12 Nov 2020 09:00:57 +0000 (10:00 +0100)]
smbd: call open_pathref_fsp() in smbd_dirptr_get_entry()

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbd: use get_dosmode in smbd_dirptr_8_3_mode_fn()
Ralph Boehme [Wed, 25 Nov 2020 12:21:25 +0000 (13:21 +0100)]
smbd: use get_dosmode in smbd_dirptr_8_3_mode_fn()

Caller currently always passes true, but this will change soonish with a change
to smbd_dirptr_get_entry().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agovfs_default: return stat info for symlinks in POSIX context
Ralph Boehme [Fri, 16 Oct 2020 13:47:50 +0000 (15:47 +0200)]
vfs_default: return stat info for symlinks in POSIX context

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agovfs_default: simplify vfswrap_readdir()
Ralph Boehme [Fri, 16 Oct 2020 13:40:56 +0000 (15:40 +0200)]
vfs_default: simplify vfswrap_readdir()

No change in behaviour.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>