diff options
author | Nadezhda Ivanova <nadezhda.ivanova@postpath.com> | 2010-01-13 12:02:31 +0200 |
---|---|---|
committer | Nadezhda Ivanova <nadezhda.ivanova@postpath.com> | 2010-01-13 12:02:31 +0200 |
commit | 9b3871ed293f76e770e572cd6b59f59670f1f6f8 (patch) | |
tree | 2b79286e3a6f7af9e26466393a0b26075a238be8 /source3/modules/vfs_acl_common.c | |
parent | 309473f938d18b9993c2c4f120eeff7b4641985a (diff) | |
parent | ca847952054f5bbde1d40ad4260589b6fcc9721d (diff) | |
download | samba-9b3871ed293f76e770e572cd6b59f59670f1f6f8.tar.gz samba-9b3871ed293f76e770e572cd6b59f59670f1f6f8.tar.bz2 samba-9b3871ed293f76e770e572cd6b59f59670f1f6f8.zip |
Merge branch 'master' of git://git.samba.org/samba
Diffstat (limited to 'source3/modules/vfs_acl_common.c')
-rw-r--r-- | source3/modules/vfs_acl_common.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/source3/modules/vfs_acl_common.c b/source3/modules/vfs_acl_common.c index 1eec448083..aeb9ce37ea 100644 --- a/source3/modules/vfs_acl_common.c +++ b/source3/modules/vfs_acl_common.c @@ -760,6 +760,108 @@ static SMB_STRUCT_DIR *opendir_acl_common(vfs_handle_struct *handle, return SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr); } +static int acl_common_remove_object(vfs_handle_struct *handle, + const char *path, + bool is_directory) +{ + connection_struct *conn = handle->conn; + struct file_id id; + files_struct *fsp = NULL; + int ret = 0; + char *parent_dir = NULL; + const char *final_component = NULL; + struct smb_filename local_fname; + int saved_errno = 0; + + if (!parent_dirname(talloc_tos(), path, + &parent_dir, &final_component)) { + saved_errno = ENOMEM; + goto out; + } + + DEBUG(10,("acl_common_remove_object: removing %s %s/%s\n", + is_directory ? "directory" : "file", + parent_dir, final_component )); + + /* cd into the parent dir to pin it. */ + ret = SMB_VFS_CHDIR(conn, parent_dir); + if (ret == -1) { + saved_errno = errno; + goto out; + } + + ZERO_STRUCT(local_fname); + local_fname.base_name = CONST_DISCARD(char *,final_component); + + /* Must use lstat here. */ + ret = SMB_VFS_LSTAT(conn, &local_fname); + if (ret == -1) { + saved_errno = errno; + goto out; + } + + /* Ensure we have this file open with DELETE access. */ + id = vfs_file_id_from_sbuf(conn, &local_fname.st); + for (fsp = file_find_di_first(id); fsp; file_find_di_next(fsp)) { + if (fsp->access_mask & DELETE_ACCESS && + fsp->delete_on_close) { + /* We did open this for delete, + * allow the delete as root. + */ + break; + } + } + + if (!fsp) { + DEBUG(10,("acl_common_remove_object: %s %s/%s " + "not an open file\n", + is_directory ? "directory" : "file", + parent_dir, final_component )); + saved_errno = EACCES; + goto out; + } + + if (is_directory) { + ret = SMB_VFS_NEXT_RMDIR(handle, final_component); + } else { + ret = SMB_VFS_NEXT_UNLINK(handle, &local_fname); + } + if (ret == -1) { + saved_errno = errno; + } + + out: + + TALLOC_FREE(parent_dir); + + vfs_ChDir(conn, conn->connectpath); + if (saved_errno) { + errno = saved_errno; + } + return ret; +} + +static int rmdir_acl_common(struct vfs_handle_struct *handle, + const char *path) +{ + int ret; + + ret = SMB_VFS_NEXT_RMDIR(handle, path); + if (!(ret == -1 && (errno == EACCES || errno == EPERM))) { + DEBUG(10,("rmdir_acl_common: unlink of %s failed %s\n", + path, + strerror(errno) )); + return ret; + } + + become_root(); + ret = acl_common_remove_object(handle, + path, + true); + unbecome_root(); + return ret; +} + static NTSTATUS create_file_acl_common(struct vfs_handle_struct *handle, struct smb_request *req, uint16_t root_dir_fid, @@ -857,3 +959,28 @@ static NTSTATUS create_file_acl_common(struct vfs_handle_struct *handle, /* NOTREACHED */ return status; } + +static int unlink_acl_common(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname) +{ + int ret; + + ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname); + if (!(ret == -1 && (errno == EACCES || errno == EPERM))) { + DEBUG(10,("unlink_acl_common: unlink of %s failed %s\n", + smb_fname->base_name, + strerror(errno) )); + return ret; + } + /* Don't do anything fancy for streams. */ + if (smb_fname->stream_name) { + return ret; + } + + become_root(); + ret = acl_common_remove_object(handle, + smb_fname->base_name, + false); + unbecome_root(); + return ret; +} |