From b43419129dd7bb5fc1352788971fa43789c44717 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 23 Jun 2016 12:23:33 +0200 Subject: [PATCH 1/2] s3/smbd: add helper func dos_mode_from_name() This just moves the computation of "hide dot files" files to a helper functions without changing overall behaviour. Signed-off-by: Ralph Boehme --- source3/smbd/dosmode.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index f490e9a..30f68fd 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -562,6 +562,37 @@ err_out: return status; } +static uint32_t dos_mode_from_name(connection_struct *conn, + const struct smb_filename *smb_fname) +{ + const char *p = NULL; + + if (!lp_hide_dot_files(SNUM(conn))) { + return 0; + } + + p = strrchr_m(smb_fname->base_name, '/'); + if (p) { + p++; + } else { + p = smb_fname->base_name; + } + + if (p[0] != '.') { + return 0; + } + + if (p[1] == '\0') { + return 0; + } + + if (p[1] == '.' && p[2] == '\0') { + return 0; + } + + return FILE_ATTRIBUTE_HIDDEN; +} + /**************************************************************************** Change a unix mode to a dos mode. May also read the create timespec into the stat struct in smb_fname @@ -580,22 +611,7 @@ uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname) return 0; } - /* First do any modifications that depend on the path name. */ - /* hide files with a name starting with a . */ - if (lp_hide_dot_files(SNUM(conn))) { - const char *p = strrchr_m(smb_fname->base_name,'/'); - if (p) { - p++; - } else { - p = smb_fname->base_name; - } - - /* Only . and .. are not hidden. */ - if (p[0] == '.' && !((p[1] == '\0') || - (p[1] == '.' && p[2] == '\0'))) { - result |= FILE_ATTRIBUTE_HIDDEN; - } - } + result = dos_mode_from_name(conn, smb_fname); /* Get the DOS attributes via the VFS if we can */ status = SMB_VFS_GET_DOS_ATTRIBUTES(conn, smb_fname, &result); -- 2.5.0 From 6c22721eecb518988605781af2255df5a740ee7c Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 23 Jun 2016 12:24:33 +0200 Subject: [PATCH 2/2] s3/smbd: only use stored dos attributes for open_match_attributes() check This changes the way we check for old vs new DOS attributes on open with overwrite: only check against the DOS attributes actually set by a client and stored in the DOS attributes xattr. With this change "hide dot files" and "hide files" continue to work with "store dos attributes = yes". Signed-off-by: Ralph Boehme --- source3/smbd/open.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 0c46eb1..9e897db 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -2535,7 +2535,12 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, if (!posix_open) { new_dos_attributes &= SAMBA_ATTRIBUTES_MASK; if (file_existed) { - existing_dos_attributes = dos_mode(conn, smb_fname); + uint32_t attr = 0; + + status = SMB_VFS_GET_DOS_ATTRIBUTES(conn, smb_fname, &attr); + if (NT_STATUS_IS_OK(status)) { + existing_dos_attributes = attr; + } } } -- 2.5.0