smbd: Simplify filename_convert_dirfsp_nosymlink()
authorVolker Lendecke <vl@samba.org>
Tue, 20 Dec 2022 13:38:02 +0000 (14:38 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 22 Dec 2022 19:50:34 +0000 (19:50 +0000)
Factor out the symlink-case into a more obvious if-statement with less
indentation.

Review with git show -b

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/filename.c

index 406618c0af754321a9847fcfc302cc38bfc61a4e..a7cf7a14d92411bce9e94f87574407923999ac54 100644 (file)
@@ -1230,46 +1230,49 @@ static NTSTATUS filename_convert_dirfsp_nosymlink(
        status = openat_pathref_fsp_case_insensitive(
                smb_dirname->fsp, smb_fname_rel, ucf_flags);
 
-       if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
-
-               char *normalized = NULL;
+       if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) &&
+           VALID_STAT(smb_fname_rel->st) &&
+           S_ISLNK(smb_fname_rel->st.st_ex_mode)) {
 
-               if (VALID_STAT(smb_fname_rel->st)) {
-                       /*
-                        * If we're on an MSDFS share, see if this is
-                        * an MSDFS link.
-                        */
-                       if (lp_host_msdfs() &&
-                           lp_msdfs_root(SNUM(conn)) &&
-                           S_ISLNK(smb_fname_rel->st.st_ex_mode) &&
-                           is_msdfs_link(smb_dirname->fsp, smb_fname_rel))
-                       {
-                               status = NT_STATUS_PATH_NOT_COVERED;
-                               goto fail;
-                       }
+               /*
+                * If we're on an MSDFS share, see if this is
+                * an MSDFS link.
+                */
+               if (lp_host_msdfs() &&
+                   lp_msdfs_root(SNUM(conn)) &&
+                   is_msdfs_link(smb_dirname->fsp, smb_fname_rel))
+               {
+                       status = NT_STATUS_PATH_NOT_COVERED;
+                       goto fail;
+               }
 
 #if defined(WITH_SMB1SERVER)
-                       /*
-                        * 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 &&
-                                       S_ISLNK(smb_fname_rel->st.st_ex_mode)) {
-                               SMB_ASSERT(smb_fname_rel->fsp == NULL);
-                               SMB_ASSERT(streamname == NULL);
-
-                               smb_fname = full_path_from_dirfsp_atname(
-                                               mem_ctx,
-                                               smb_dirname->fsp,
-                                               smb_fname_rel);
-                               if (smb_fname == NULL) {
-                                       status = NT_STATUS_NO_MEMORY;
-                                       goto fail;
-                               }
-                               goto done;
+               /*
+                * 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) {
+                       SMB_ASSERT(smb_fname_rel->fsp == NULL);
+                       SMB_ASSERT(streamname == NULL);
+
+                       smb_fname = full_path_from_dirfsp_atname(
+                               mem_ctx,
+                               smb_dirname->fsp,
+                               smb_fname_rel);
+                       if (smb_fname == NULL) {
+                               status = NT_STATUS_NO_MEMORY;
+                               goto fail;
                        }
+                       goto done;
+               }
 #endif
+       }
+
+       if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+
+               char *normalized = NULL;
+
+               if (VALID_STAT(smb_fname_rel->st)) {
                        /*
                         * NT_STATUS_OBJECT_NAME_NOT_FOUND is
                         * misleading: The object exists but might be