s3: smbd: Reformat users of can_write_to_file().
[samba.git] / source3 / smbd / dosmode.c
index 1baee073a3665ecb59fa7c6663cdd7f497c0e6bf..b061e9ac794122396e3fe6a3667fc5c07d6654f6 100644 (file)
@@ -120,7 +120,7 @@ static int set_link_read_only_flag(const SMB_STRUCT_STAT *const sbuf)
 
 mode_t unix_mode(connection_struct *conn, int dosmode,
                 const struct smb_filename *smb_fname,
-                const char *inherit_from_dir)
+                struct smb_filename *smb_fname_parent)
 {
        mode_t result = (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH);
        mode_t dir_mode = 0; /* Mode of the inherit_from directory if
@@ -130,29 +130,15 @@ mode_t unix_mode(connection_struct *conn, int dosmode,
                result &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
        }
 
-       if ((inherit_from_dir != NULL) && lp_inherit_permissions(SNUM(conn))) {
-               struct smb_filename *smb_fname_parent;
-
-               DEBUG(2, ("unix_mode(%s) inheriting from %s\n",
+       if ((smb_fname_parent != NULL) && lp_inherit_permissions(SNUM(conn))) {
+               DBG_DEBUG("[%s] inheriting from [%s]\n",
                          smb_fname_str_dbg(smb_fname),
-                         inherit_from_dir));
-
-               smb_fname_parent = synthetic_smb_fname(talloc_tos(),
-                                       inherit_from_dir,
-                                       NULL,
-                                       NULL,
-                                       smb_fname->flags);
-               if (smb_fname_parent == NULL) {
-                       DEBUG(1,("unix_mode(%s) failed, [dir %s]: No memory\n",
-                                smb_fname_str_dbg(smb_fname),
-                                inherit_from_dir));
-                       return(0);
-               }
+                         smb_fname_str_dbg(smb_fname_parent));
 
                if (SMB_VFS_STAT(conn, smb_fname_parent) != 0) {
-                       DEBUG(4,("unix_mode(%s) failed, [dir %s]: %s\n",
-                                smb_fname_str_dbg(smb_fname),
-                                inherit_from_dir, strerror(errno)));
+                       DBG_ERR("stat failed [%s]: %s\n",
+                               smb_fname_str_dbg(smb_fname_parent),
+                               strerror(errno));
                        TALLOC_FREE(smb_fname_parent);
                        return(0);      /* *** shouldn't happen! *** */
                }
@@ -233,7 +219,9 @@ static uint32_t dos_mode_from_sbuf(connection_struct *conn,
                }
        } else if (ro_opts == MAP_READONLY_PERMISSIONS) {
                /* Check actual permissions for read-only. */
-               if (!can_write_to_file(conn, smb_fname)) {
+               if (!can_write_to_file(conn,
+                               smb_fname))
+               {
                        result |= FILE_ATTRIBUTE_READONLY;
                }
        } /* Else never set the readonly bit. */
@@ -553,7 +541,8 @@ NTSTATUS set_ea_dos_attribute(connection_struct *conn,
                }
 
                if (!set_dosmode_ok && lp_dos_filemode(SNUM(conn))) {
-                       set_dosmode_ok = can_write_to_file(conn, smb_fname);
+                       set_dosmode_ok = can_write_to_file(conn,
+                                               smb_fname);
                }
 
                if (!set_dosmode_ok) {
@@ -1006,7 +995,7 @@ int file_set_dosmode(connection_struct *conn,
        }
 
        /* Fall back to UNIX modes. */
-       unixmode = unix_mode(conn, dosmode, smb_fname, parent_dir->base_name);
+       unixmode = unix_mode(conn, dosmode, smb_fname, parent_dir);
 
        /* preserve the file type bits */
        mask |= S_IFMT;
@@ -1083,7 +1072,9 @@ int file_set_dosmode(connection_struct *conn,
                bits on a file. Just like file_ntimes below.
        */
 
-       if (!can_write_to_file(conn, smb_fname)) {
+       if (!can_write_to_file(conn,
+                       smb_fname))
+       {
                errno = EACCES;
                return -1;
        }
@@ -1256,7 +1247,9 @@ int file_ntimes(connection_struct *conn, const struct smb_filename *smb_fname,
         */
 
        /* Check if we have write access. */
-       if (can_write_to_file(conn, smb_fname)) {
+       if (can_write_to_file(conn,
+                       smb_fname))
+       {
                /* We are allowed to become root and change the filetime. */
                become_root();
                ret = SMB_VFS_NTIMES(conn, smb_fname, ft);