smbd: Simplify openat_pathref_fsp_case_insensitive()
authorVolker Lendecke <vl@samba.org>
Wed, 18 Oct 2023 09:50:20 +0000 (11:50 +0200)
committerVolker Lendecke <vl@samba.org>
Tue, 7 Nov 2023 12:46:37 +0000 (12:46 +0000)
commit8d00b0e664d76931dd29b417e90ec1e4ff488939
tree71d0df68c88054f354bd77c9265f24735499e29f
parentab56379c22702d364b0b55fe993e407739b6af91
smbd: Simplify openat_pathref_fsp_case_insensitive()

This is more lines of code, but it's still a simplification. With this
patch we don't call the full openat_pathref_fsp() anymore when looking
up the last component in filename_convert_dirfsp(), instead we do the
direct SMB_VFS_OPENAT(). We don't need the whole complexity of
non_widelink_open() for this case, we do know that we have a real
non-cwd dirfsp.

The other big change that is not obvious just from looking at the
patch: This removes the special case for looking up posix
symlinks. Before this patch, filename_convert_dirfsp() returned a
proper smb_filename but without an attached fsp when a smb1 posix
client hits a symlink. This caused all sorts of special case code
everywhere. For example smbd_do_qfilepathinfo() needs to cover both
cases just for the smb1 posix symlink case. This special-case handling
can go now. We can do the path lookup in the smb1-only qpathinfo code
and call into the common code with a proper fsp.

When hitting a symlink and with O_PATH available, we'll get the
symlink opened with an O_PATH fd. Without O_PATH we obviously can't do
that, there we get fd=-1 and an indication that we don't have the
procfd fallback around.

Why all this?

I want to present FIFOs (and eventually symlinks) as reparse points as
the very next step. Without this patch, there is no real unified way
to get the file attributes from disk. Now we can use the proper logic
of fdos_mode() everywhere and not rely on special cases for fsp==NULL.

This patch also changes some error codes for smb1 posix extensions. I
chose to just change the test instead of going after each and every
change. As long as we do get an error, I'm willing to accept that we
slightly change error path behaviour for this deprecated code.

And, I tried to split this up into smaller patches but I failed.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/modules/vfs_widelinks.c
source3/script/tests/test_symlink_traversal_smb1_posix.sh
source3/smbd/filename.c
source3/smbd/files.c
source3/smbd/open.c
source3/smbd/proto.h
source3/smbd/smb2_create.c