smbd: factor out dosmode post processing
authorRalph Boehme <slow@samba.org>
Wed, 25 Jul 2018 15:15:46 +0000 (17:15 +0200)
committerRalph Boehme <slow@samba.org>
Fri, 27 Jul 2018 11:07:14 +0000 (13:07 +0200)
We apply some post processing to the dosmode returned from the VFS
function. Move this to a seperate function which will be reused in the
next commit in the async dos_mode_send/recv post processing.

Best viewed with: git show --histogram

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/dosmode.c

index ed5ecc9120c50bc968f9604c8082e0cb7a3c8dcf..141001c74a9f87beb4240816622652791631ecd7 100644 (file)
@@ -665,33 +665,12 @@ static uint32_t dos_mode_from_name(connection_struct *conn,
        return result;
 }
 
-/****************************************************************************
- Change a unix mode to a dos mode.
- May also read the create timespec into the stat struct in smb_fname
- if "store dos attributes" is true.
-****************************************************************************/
-
-uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname)
+static uint32_t dos_mode_post(uint32_t dosmode,
+                             connection_struct *conn,
+                             struct smb_filename *smb_fname,
+                             const char *func)
 {
-       uint32_t result = 0;
-       NTSTATUS status = NT_STATUS_OK;
-
-       DEBUG(8,("dos_mode: %s\n", smb_fname_str_dbg(smb_fname)));
-
-       if (!VALID_STAT(smb_fname->st)) {
-               return 0;
-       }
-
-       /* Get the DOS attributes via the VFS if we can */
-       status = SMB_VFS_GET_DOS_ATTRIBUTES(conn, smb_fname, &result);
-       if (!NT_STATUS_IS_OK(status)) {
-               /*
-                * Only fall back to using UNIX modes if we get NOT_IMPLEMENTED.
-                */
-               if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
-                       result |= dos_mode_from_sbuf(conn, smb_fname);
-               }
-       }
+       NTSTATUS status;
 
        /*
         * According to MS-FSA a stream name does not have
@@ -711,31 +690,63 @@ uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname)
                        /*
                         * Non-default stream name, not a posix path.
                         */
-                       result &= ~(FILE_ATTRIBUTE_DIRECTORY);
+                       dosmode &= ~(FILE_ATTRIBUTE_DIRECTORY);
                }
        }
 
        if (conn->fs_capabilities & FILE_FILE_COMPRESSION) {
                bool compressed = false;
+
                status = dos_mode_check_compressed(conn, smb_fname,
                                                   &compressed);
                if (NT_STATUS_IS_OK(status) && compressed) {
-                       result |= FILE_ATTRIBUTE_COMPRESSED;
+                       dosmode |= FILE_ATTRIBUTE_COMPRESSED;
                }
        }
 
-       result |= dos_mode_from_name(conn, smb_fname, result);
+       dosmode |= dos_mode_from_name(conn, smb_fname, dosmode);
 
        if (S_ISDIR(smb_fname->st.st_ex_mode)) {
-               result |= FILE_ATTRIBUTE_DIRECTORY;
-       } else if (result == 0) {
-               result = FILE_ATTRIBUTE_NORMAL;
+               dosmode |= FILE_ATTRIBUTE_DIRECTORY;
+       } else if (dosmode == 0) {
+               dosmode = FILE_ATTRIBUTE_NORMAL;
        }
 
-       result = filter_mode_by_protocol(result);
+       dosmode = filter_mode_by_protocol(dosmode);
 
-       dos_mode_debug_print(__func__, result);
+       dos_mode_debug_print(func, dosmode);
+       return dosmode;
+}
+
+/****************************************************************************
+ Change a unix mode to a dos mode.
+ May also read the create timespec into the stat struct in smb_fname
+ if "store dos attributes" is true.
+****************************************************************************/
+
+uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname)
+{
+       uint32_t result = 0;
+       NTSTATUS status = NT_STATUS_OK;
+
+       DEBUG(8,("dos_mode: %s\n", smb_fname_str_dbg(smb_fname)));
+
+       if (!VALID_STAT(smb_fname->st)) {
+               return 0;
+       }
+
+       /* Get the DOS attributes via the VFS if we can */
+       status = SMB_VFS_GET_DOS_ATTRIBUTES(conn, smb_fname, &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               /*
+                * Only fall back to using UNIX modes if we get NOT_IMPLEMENTED.
+                */
+               if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
+                       result |= dos_mode_from_sbuf(conn, smb_fname);
+               }
+       }
 
+       result = dos_mode_post(result, conn, smb_fname, __func__);
        return result;
 }