s3/smbd: add helper func dos_mode_from_name()
authorRalph Boehme <slow@samba.org>
Thu, 23 Jun 2016 10:23:33 +0000 (12:23 +0200)
committerRalph Boehme <slow@samba.org>
Sat, 25 Jun 2016 16:47:17 +0000 (18:47 +0200)
This just moves the computation of "hide dot files" files to a helper
functions without changing overall behaviour.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=11992

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/dosmode.c

index f490e9a9a232b72cec050fae176c3456179bb420..463c43e66c235f03be3b859c1502a337a12c924d 100644 (file)
@@ -562,6 +562,31 @@ err_out:
        return status;
 }
 
+static uint32_t dos_mode_from_name(connection_struct *conn,
+                                  const struct smb_filename *smb_fname)
+{
+       const char *p = NULL;
+       uint32_t result = 0;
+
+       if (lp_hide_dot_files(SNUM(conn))) {
+               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;
+               }
+       }
+
+       return result;
+}
+
 /****************************************************************************
  Change a unix mode to a dos mode.
  May also read the create timespec into the stat struct in smb_fname
@@ -580,22 +605,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);