1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
Commit Graph

12616 Commits

Author SHA1 Message Date
Ralph Boehme
6d71edab5a smbd: use fsctl_get_reparse_point() in smb3_file_posix_information_init()
This allows returning the POSIX type info from fsctl_get_reparse_point().

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Wed Nov 27 19:32:45 UTC 2024 on atb-devel-224
2024-11-27 19:32:45 +00:00
Ralph Boehme
b51a827e47 smbd: move calling fsctl_get_reparse_tag() into smb3_file_posix_information_init()
This already fixes SMB2-GETINFO with POSIX infolevel to return the reparse tag
of reparse points.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
2024-11-27 18:22:29 +00:00
Ralph Boehme
a10755881e smbd: simplify smb3_file_posix_information_init()
The dos attributes are already setup by fdos_mode(). Still assert
FILE_ATTRIBUTE_REPARSE_POINT is correctly set just in case.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
2024-11-27 18:22:29 +00:00
Ralph Boehme
306d4e7fff smbd: fix DOS attributes for reparse points in fdos_mode()
Reparse have only FILE_ATTRIBUTE_REPARSE_POINT set, but never
FILE_ATTRIBUTE_NORMAL or FILE_ATTRIBUTE_DIRECTORY at the same time.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
2024-11-27 18:22:29 +00:00
Ralph Boehme
239d8f463b smbd: rename SMB2_FS_POSIX_INFORMATION to FSCC_FS_POSIX_INFORMATION
Streamline the info-level defines. Also get rid of
SMB2_FS_POSIX_INFORMATION_INTERNAL which is not needed for an info-level that
is exclusive to SMB2.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
2024-11-27 18:22:28 +00:00
Ralph Boehme
27198998ed smbd: rename SMB2_FILE_POSIX_INFORMATION to FSCC_FILE_POSIX_INFORMATION
Streamline the info-level defines. Also get rid of
SMB2_FILE_POSIX_INFORMATION_INTERNAL which is not needed for an info-level that
is exclusive to SMB2.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
2024-11-27 18:22:28 +00:00
Ralph Boehme
8eccfbea7d smbd: use NT_PASSTHROUGH_OFFSET in a few places
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
2024-11-27 18:22:28 +00:00
Volker Lendecke
34be8ef596 smbd: Return NT_STATUS_STOPPED_ON_SYMLINK
Do this for "follow symlinks = now" and smb2 unix extensions

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
cc0ed15fec smbd: Always init symlink_err in filename_convert_dirfsp_nosymlink()
Make sure that we don't leave symlink_err in the caller
uninitialized.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
239df72787 smbd: Create the proper error blob for STOPPED_ON_SYMLINK
Unused so far, our lowerlevel routines so far never return
NT_STATUS_STOPPED_ON_SYMLINK. Also see the NULL passed as
"symlink_reparse", this will change soon. Separate patch for easier
review.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
2065778b5c smbd: Prepare smbd_smb2_create_recv() to return a symlink error
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
ed239d3f29 smbd: Allow a symlink as lcomp when asking for REPARSE_POINT
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
0d8b71f0b6 smbd: Fix the turning an absolute symlink into a relative one
If dirfsp is the share root, we end up with a "/." at the end of
subdir_path. subdir_of() does not cover that case. fsp_fullbasepath()
takes care of that case and also avoids a talloc.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
259517d7ae smbd: Set fsp->fsp_flags.posix_open in openat_pathref_fsp_lcomp()
Not sure why this wasn't caught as a bug yet...

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
c87269f528 smbd: Prepare fdos_mode() for handling symlinks in smb2
We should show all special files as NORMAL|REPARSE_POINT, except
symlinks for SMB1 Posix Extensions. IFREG and IFDIR are handled via
our xattr mechanisms.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
079d95da0b smbd: Make filename_convert_dirfsp_nosymlink() public
To be used directly in smb2_create.c

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
76f5156906 smbd: Revert "smbd: Simplify filename_convert_dirfsp()"
This reverts commit bd30c9c128.

While this does indeed slightly simplify code, it simplifies too much: Soon we
will need filename_convert_dirfsp_nosymlink raw without looking at
UCF_LCOMP_LNK_OK. So in hindsight this went too far.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
ec64f81df9 smbd: Pass "create_options" to filename_create_ucf_flags()
OPEN_REPARSE_POINT will trigger symlinks not being followed but
returned, even if we have "follow symlinks = yes". Prepare for setting
UCF_LCOMP_LNK_OK for this case in a central place.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-22 09:50:37 +00:00
Volker Lendecke
3859156fd8 smbd: Simplify smb_q_posix_symlink()
Use the lcomp from filename_convert_dirfsp_rel()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-19 18:11:29 +00:00
Volker Lendecke
ffc676dd87 smbd: Early talloc_free in an error case
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-19 18:11:29 +00:00
Volker Lendecke
d4c13988c9 smbd: Simplify smbd_do_qfilepathinfo()
fdos_mode(fsp) unconditionally dereferences fsp, so we can get rid of
checking for fsp!=NULL.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-19 18:11:28 +00:00
Ralph Boehme
f86d1a3591 smbd: avoid a panic in close_directory()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15754

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Mon Nov 18 12:43:28 UTC 2024 on atb-devel-224
2024-11-18 12:43:28 +00:00
Volker Lendecke
c7839facdb smbd: Remove non_widelink_open()
Better look at the final code, not at the patch. The idea is to call
filename_convert_dirfsp() from fd_openat() and just have one place to
follow symlinks.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Tue Nov 12 19:21:11 UTC 2024 on atb-devel-224
2024-11-12 19:21:11 +00:00
Volker Lendecke
31eac22e08 smbd: simplify openat_pathref_fullname()
We don't have to deal with stream opens anymore.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
9a80e4e27a smbd: simplify open_stream_pathref_fsp()
Looks more complex, but we don't have to go through all of
fd_openat()/non_widelink_open() for opening streams. SMB_VFS_OPENAT
knows how to deal with this.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
0bb35e2461 pysmbd: Python code calls smbd code with "." and ".."
Soon we will call filename_convert_dirfsp() on these, which can't deal
with paths that are invalid by containing . and .. as path components.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
800363a2cd smbd: Simplify filename_convert_dirfsp_nosymlink()
Looks more complex, but this avoids calling openat_pathref_fsp, which
eventually calls into non_widelink_open(). We need to open the pretty paranoid
SMB_ASSERT in openat_pathref_fsp_lcomp() a little bit.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
56e3a8e3f8 smbd: Add open_rootdir_pathref_fsp()
Get a pathref handle on the file system root. This will serve as
"basedir" for filename_convert_dirfsp_rel() to turn an absolute path
into one relative to the handle created here.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
0fc8d8bfc5 smbd: Factor out filename_convert_dirfsp_rel()
Soon we'll have a caller that needs the last component as a relative
file name. Make sure it does not have to call get_lcomp or so.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
99fa20b418 smbd: Fix following symlinks if basedir != cwd_fsp
Unused so far, but soon we'll call this routine with a basedir that's
somewhere below the share root.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
82fd2230a8 smbd: Slightly simplify filename_convert_dirfsp_nosymlink()
Reference conn->cwd_fsp just once, shrinks next patches

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
88abb775dc smbd: Use OpenDir_from_pathref() in rmdir_internals()
Make strace look nicer

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
10512eebec smbd: Use OpenDir_from_pathref() in can_delete_directory_fsp()
This avoids a full path traversal if /proc/self/fd is available.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
c0bbeded93 smbd: Simplify OpenDir_from_pathref()
Use the /proc/self/fd trick to make get_real_filename_fullscan_at look
a bit nicer and faster in strace. Direct SMB_VFS_OPENAT also is
cheaper in user space, we don't need the full fd_openat and
non_widelink_open magic here.

Also avoid opening ".", which can fail where a full path open would
succeed: If the directory in question does not give "x" perms to the
user, we get a handle on the dir as such but can't cd into it.

I haven't seen real-world cases of this, but one of our tests creates
such a scenario. I have further refactoring in my local tree that make
this patch necessary.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
9550f4370e smbd: Enable fd_openat(cwd_fsp, "/absolute/share/path")
So far fd_openat needed to be called with cwd_fsp and "." if you
wanted to open the share root, this enables using the absolute share
path. The next patch will remove sending the "." with cwd_fsp as a
simplification. Enable that with this little change.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
e571da800f smbd: Tighten non_wide_link_open() for absolute root share open
Make it clear that non_widelink_open being called for absolute paths
is not done during regular operations, i.e. when we have passed our
pathnames through filename_convert_dirfsp and we work on a real
dirfsp.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
88f582d3ca smbd: Ignore twrp in chdir_below_conn()
We can't deal with snapdir paths in non_widelink_open fully with
snapdirseverywhere active: There is no way for
shadow_copy2_parent_pathname() to work when a snapshot directory is
below the directory that we want to calculate the parent for. What is
the parent directory supposed to point at? I don't know.

For me the only way out is to accept that we should ignore what
happens behind shadow_copy2's path manipulation in core
smbd. This *might* open symlink races, but the whole point of
snapshots is that they are r/o copies of the real active file system
and as such they should be immune to those races.

Found while trying to refactor code around fd_openat()

P.S: This code will go away pretty soon

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
bd30c9c128 smbd: Simplify filename_convert_dirfsp()
If we do the S_ISLNK check in the lower level, the if-condition is
simpler and we get the close_file_free() call for free.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
3ab6a9a9bf smbd: Inline dup_file_fsp() into fcb_or_dos_open()
Only used once, an not really complex

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 18:07:33 +00:00
Volker Lendecke
142a78eb24 vfs: Use the getwd-cache only if we have a valid tcon
A valid tcon will have changed fsp_get_pathref_fd() to AT_FDCWD, -100
on Linux.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 13:44:32 +00:00
Volker Lendecke
c31e7aecba vfs: Change the condition when to fill the getwd cache
The next patch will add another excluding condition, this change
keeps the if-condition that is changed here simple.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 13:44:32 +00:00
Volker Lendecke
0ab88a1fe7 smbd: Don't print cwd before tcon is done
vfs_GetWd depends upon a current tcon in fake_acls, otherwise it will
call openat with an invalid dirfd on a relative pathname.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 13:44:32 +00:00
Volker Lendecke
f8994bc289 smbd: Fix an error resource leak in OpenDir_from_pathref()
We have to undo the fsp allocation and open we've done. Not noticed,
it's probably highly unlikely OpenDir_fsp() fails.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Tue Nov 12 13:26:10 UTC 2024 on atb-devel-224
2024-11-12 13:26:10 +00:00
Volker Lendecke
48464c66f8 smbd: Simplify smbd_smb2_query_directory_send()
Use reopen_from_fsp(), this will use the /proc/self/fd/<fd> trick if
available, no need to go through non_widelink_open

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 12:09:35 +00:00
Volker Lendecke
774005be76 smbd: reopen_from_fsp also works for full fsps
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 12:09:35 +00:00
Volker Lendecke
3b38639330 smbd: Make reopen_from_fsp() public
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 12:09:35 +00:00
Volker Lendecke
7430831f88 smbd: Convert get_ea_value_fsp() to return 0/errno
Avoid a map_errno_from_nt_status()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 12:09:35 +00:00
Volker Lendecke
eecdd0fb59 smbd: Convert refuse_symlink_fsp() to bool
I want to simplify get_ea_value_fsp next

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 12:09:35 +00:00
Volker Lendecke
4b3b283b1f smbd: Simplify make_connection_snum()
Avoid nested if's, don't check for ISDIR twice

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2024-11-12 12:09:35 +00:00
Ralph Boehme
7653ae2702 smbd: initialize delete_on_close in smbd_smb2_setinfo_lease_break_fsp_check()
CID 1634488:  Uninitialized variables  (UNINIT)

/source3/smbd/smb2_setinfo.c: 475 in smbd_smb2_setinfo_lease_break_fsp_check()
469     			&delete_on_close);
470     		if (tevent_req_nterror(req, status)) {
471     			return;
472     		}
473     	}
474
>>>     CID 1634488:  Uninitialized variables  (UNINIT)
>>>     Using uninitialized value "delete_on_close".
475     	if (!rename && !delete_on_close) {
476     		return;
477     	}
478
479     	state->lck = get_existing_share_mode_lock(state, fsp->file_id);
480     	if (state->lck == NULL) {

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Nov  7 17:21:53 UTC 2024 on atb-devel-224
2024-11-07 17:21:53 +00:00