smbd: Hide the SMB1 posix symlink behaviour behind UCF_LCOMP_LNK_OK
authorVolker Lendecke <vl@samba.org>
Tue, 20 Dec 2022 20:26:10 +0000 (21:26 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 22 Dec 2022 19:50:34 +0000 (19:50 +0000)
This will be used in the future to also open symlinks as reparse
points, so this won't be specific to only SMB1 posix extensions.

I have tried to avoid additional flags for several weeks by making
openat_pathref_fsp or other flavors of this to always open fsp's with
symlink O_PATH opens, because I think NT_STATUS_OBJECT_NAME_NOT_FOUND
with a valid stat is a really bad and racy way to express that we just
hit a symlink, but I miserably failed. Adding additional flags (another one
will follow) is wrong, but I don't see another way right now.

Signed-off-by: Volker Lendecke <vl@samba.org>
source3/smbd/filename.c
source3/smbd/smbd.h

index be24854f89ca94625fdfe6b22b93704b41898053..73e88add2c361bcea63d132433bae2b148b0aa7d 100644 (file)
@@ -41,6 +41,10 @@ uint32_t ucf_flags_from_smb_request(struct smb_request *req)
 
        if (req->posix_pathnames) {
                ucf_flags |= UCF_POSIX_PATHNAMES;
+
+               if (!req->sconn->using_smb2) {
+                       ucf_flags |= UCF_LCOMP_LNK_OK;
+               }
        }
        if (req->flags2 & FLAGS2_DFS_PATHNAMES) {
                ucf_flags |= UCF_DFS_PATHNAME;
@@ -1251,7 +1255,7 @@ static NTSTATUS filename_convert_dirfsp_nosymlink(
                 * In SMB1 posix mode, if this is a symlink,
                 * allow access to the name with a NULL smb_fname->fsp.
                 */
-               if (!conn->sconn->using_smb2 && posix) {
+               if (ucf_flags & UCF_LCOMP_LNK_OK) {
                        SMB_ASSERT(smb_fname_rel->fsp == NULL);
                        SMB_ASSERT(streamname == NULL);
 
index 6cf2b64a5a15195393ecdbadb8891545c62a9794..1c98bea43342977d4017bdc6fbcf9ddb6b535b4b 100644 (file)
@@ -84,6 +84,10 @@ struct trans_state {
 #define UCF_POSIX_PATHNAMES            0x00000008
 /* #define UCF_UNIX_NAME_LOOKUP 0x00000010 is no longer used. */
 #define UCF_PREP_CREATEFILE            0x00000020
+/*
+ * Return a non-fsp smb_fname for a symlink
+ */
+#define UCF_LCOMP_LNK_OK                0x00000040
 /*
  * Use the same bit as FLAGS2_REPARSE_PATH
  * which means the same thing.