From: Ralph Boehme Date: Wed, 25 Jul 2018 15:15:46 +0000 (+0200) Subject: smbd: factor out dosmode post processing X-Git-Tag: ldb-1.5.0~148 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0feef1684e5a3a1889182e68597298a0e25df4ba;p=thirdparty%2Fsamba.git smbd: factor out dosmode post processing 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 Reviewed-by: Stefan Metzmacher --- diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index ed5ecc9120c..141001c74a9 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -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; }