s3: smbd: Reformat users of can_write_to_file().
[samba.git] / source3 / smbd / file_access.c
index 6ced6a625587798ffdadb1d92b75a1d88048e679..1b9785d670abd356f28d4dfd97487331a7d32850 100644 (file)
 ****************************************************************************/
 
 bool can_delete_file_in_directory(connection_struct *conn,
-                                 const struct smb_filename *smb_fname)
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname)
 {
        TALLOC_CTX *ctx = talloc_tos();
-       char *dname = NULL;
        struct smb_filename *smb_fname_parent = NULL;
-       NTSTATUS status;
        bool ret;
 
+       SMB_ASSERT(dirfsp == conn->cwd_fsp);
+
        if (!CAN_WRITE(conn)) {
                return False;
        }
@@ -51,15 +52,9 @@ bool can_delete_file_in_directory(connection_struct *conn,
        }
 
        /* Get the parent directory permission mask and owners. */
-       if (!parent_dirname(ctx, smb_fname->base_name, &dname, NULL)) {
-               return False;
-       }
-
-       status = create_synthetic_smb_fname(ctx, dname, NULL, NULL,
-                                           &smb_fname_parent);
-       if (!NT_STATUS_IS_OK(status)) {
-               ret = false;
-               goto out;
+       ret = parent_smb_fname(ctx, smb_fname, &smb_fname_parent, NULL);
+       if (ret != true) {
+               return false;
        }
 
        if(SMB_VFS_STAT(conn, smb_fname_parent) != 0) {
@@ -124,9 +119,9 @@ bool can_delete_file_in_directory(connection_struct *conn,
 
        ret = NT_STATUS_IS_OK(smbd_check_access_rights(conn,
                                smb_fname_parent,
+                               false,
                                FILE_DELETE_CHILD));
  out:
-       TALLOC_FREE(dname);
        TALLOC_FREE(smb_fname_parent);
        return ret;
 }
@@ -136,10 +131,11 @@ bool can_delete_file_in_directory(connection_struct *conn,
 ****************************************************************************/
 
 bool can_write_to_file(connection_struct *conn,
-                      const struct smb_filename *smb_fname)
+                       const struct smb_filename *smb_fname)
 {
        return NT_STATUS_IS_OK(smbd_check_access_rights(conn,
                                smb_fname,
+                               false,
                                FILE_WRITE_DATA));
 }
 
@@ -147,13 +143,17 @@ bool can_write_to_file(connection_struct *conn,
  Check for an existing default Windows ACL on a directory.
 ****************************************************************************/
 
-bool directory_has_default_acl(connection_struct *conn, const char *fname)
+bool directory_has_default_acl(connection_struct *conn,
+               struct files_struct *dirfsp,
+               struct smb_filename *smb_fname)
 {
-       /* returns talloced off tos. */
        struct security_descriptor *secdesc = NULL;
        unsigned int i;
-       NTSTATUS status = SMB_VFS_GET_NT_ACL(conn, fname,
-                               SECINFO_DACL, &secdesc);
+       NTSTATUS status;
+
+       status = SMB_VFS_GET_NT_ACL(conn, smb_fname,
+                                            SECINFO_DACL, talloc_tos(),
+                                            &secdesc);
 
        if (!NT_STATUS_IS_OK(status) ||
                        secdesc == NULL ||
@@ -178,7 +178,7 @@ bool directory_has_default_acl(connection_struct *conn, const char *fname)
  Check if setting delete on close is allowed on this fsp.
 ****************************************************************************/
 
-NTSTATUS can_set_delete_on_close(files_struct *fsp, uint32 dosmode)
+NTSTATUS can_set_delete_on_close(files_struct *fsp, uint32_t dosmode)
 {
        /*
         * Only allow delete on close for writable files.
@@ -216,7 +216,7 @@ NTSTATUS can_set_delete_on_close(files_struct *fsp, uint32 dosmode)
        }
 
        /* Don't allow delete on close for non-empty directories. */
-       if (fsp->is_directory) {
+       if (fsp->fsp_flags.is_directory) {
                SMB_ASSERT(!is_ntfs_stream_smb_fname(fsp->fsp_name));
 
                /* Or the root of a share. */
@@ -226,8 +226,7 @@ NTSTATUS can_set_delete_on_close(files_struct *fsp, uint32 dosmode)
                        return NT_STATUS_ACCESS_DENIED;
                }
 
-               return can_delete_directory(fsp->conn,
-                                           fsp->fsp_name->base_name);
+               return can_delete_directory_fsp(fsp);
        }
 
        return NT_STATUS_OK;