ext2/3/4: use generic posix ACL infrastructure
Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
996a710d46
commit
64e178a711
21 changed files with 109 additions and 614 deletions
190
fs/ext2/acl.c
190
fs/ext2/acl.c
|
@ -148,13 +148,6 @@ ext2_get_acl(struct inode *inode, int type)
|
|||
struct posix_acl *acl;
|
||||
int retval;
|
||||
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return NULL;
|
||||
|
||||
acl = get_cached_acl(inode, type);
|
||||
if (acl != ACL_NOT_CACHED)
|
||||
return acl;
|
||||
|
||||
switch (type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
|
||||
|
@ -189,19 +182,14 @@ ext2_get_acl(struct inode *inode, int type)
|
|||
/*
|
||||
* inode->i_mutex: down
|
||||
*/
|
||||
static int
|
||||
ext2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
|
||||
int
|
||||
ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
{
|
||||
int name_index;
|
||||
void *value = NULL;
|
||||
size_t size = 0;
|
||||
int error;
|
||||
|
||||
if (S_ISLNK(inode->i_mode))
|
||||
return -EOPNOTSUPP;
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return 0;
|
||||
|
||||
switch(type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
|
||||
|
@ -250,169 +238,21 @@ ext2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
|
|||
int
|
||||
ext2_init_acl(struct inode *inode, struct inode *dir)
|
||||
{
|
||||
struct posix_acl *acl = NULL;
|
||||
int error = 0;
|
||||
struct posix_acl *default_acl, *acl;
|
||||
int error;
|
||||
|
||||
if (!S_ISLNK(inode->i_mode)) {
|
||||
if (test_opt(dir->i_sb, POSIX_ACL)) {
|
||||
acl = ext2_get_acl(dir, ACL_TYPE_DEFAULT);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
}
|
||||
if (!acl)
|
||||
inode->i_mode &= ~current_umask();
|
||||
}
|
||||
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
|
||||
if (S_ISDIR(inode->i_mode)) {
|
||||
error = ext2_set_acl(inode, ACL_TYPE_DEFAULT, acl);
|
||||
if (error)
|
||||
goto cleanup;
|
||||
}
|
||||
error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
|
||||
if (error < 0)
|
||||
return error;
|
||||
if (error > 0) {
|
||||
/* This is an extended ACL */
|
||||
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
|
||||
}
|
||||
}
|
||||
cleanup:
|
||||
posix_acl_release(acl);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Does chmod for an inode that may have an Access Control List. The
|
||||
* inode->i_mode field must be updated to the desired value by the caller
|
||||
* before calling this function.
|
||||
* Returns 0 on success, or a negative error number.
|
||||
*
|
||||
* We change the ACL rather than storing some ACL entries in the file
|
||||
* mode permission bits (which would be more efficient), because that
|
||||
* would break once additional permissions (like ACL_APPEND, ACL_DELETE
|
||||
* for directories) are added. There are no more bits available in the
|
||||
* file mode.
|
||||
*
|
||||
* inode->i_mutex: down
|
||||
*/
|
||||
int
|
||||
ext2_acl_chmod(struct inode *inode)
|
||||
{
|
||||
struct posix_acl *acl;
|
||||
int error;
|
||||
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return 0;
|
||||
if (S_ISLNK(inode->i_mode))
|
||||
return -EOPNOTSUPP;
|
||||
acl = ext2_get_acl(inode, ACL_TYPE_ACCESS);
|
||||
if (IS_ERR(acl) || !acl)
|
||||
return PTR_ERR(acl);
|
||||
error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
|
||||
error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
|
||||
if (error)
|
||||
return error;
|
||||
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
|
||||
posix_acl_release(acl);
|
||||
|
||||
if (default_acl) {
|
||||
error = ext2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
|
||||
posix_acl_release(default_acl);
|
||||
}
|
||||
if (acl) {
|
||||
if (!error)
|
||||
error = ext2_set_acl(inode, acl, ACL_TYPE_ACCESS);
|
||||
posix_acl_release(acl);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extended attribut handlers
|
||||
*/
|
||||
static size_t
|
||||
ext2_xattr_list_acl_access(struct dentry *dentry, char *list, size_t list_size,
|
||||
const char *name, size_t name_len, int type)
|
||||
{
|
||||
const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
|
||||
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return 0;
|
||||
if (list && size <= list_size)
|
||||
memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
static size_t
|
||||
ext2_xattr_list_acl_default(struct dentry *dentry, char *list, size_t list_size,
|
||||
const char *name, size_t name_len, int type)
|
||||
{
|
||||
const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
|
||||
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return 0;
|
||||
if (list && size <= list_size)
|
||||
memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int
|
||||
ext2_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer,
|
||||
size_t size, int type)
|
||||
{
|
||||
struct posix_acl *acl;
|
||||
int error;
|
||||
|
||||
if (strcmp(name, "") != 0)
|
||||
return -EINVAL;
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
acl = ext2_get_acl(dentry->d_inode, type);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
if (acl == NULL)
|
||||
return -ENODATA;
|
||||
error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
|
||||
posix_acl_release(acl);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static int
|
||||
ext2_xattr_set_acl(struct dentry *dentry, const char *name, const void *value,
|
||||
size_t size, int flags, int type)
|
||||
{
|
||||
struct posix_acl *acl;
|
||||
int error;
|
||||
|
||||
if (strcmp(name, "") != 0)
|
||||
return -EINVAL;
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return -EOPNOTSUPP;
|
||||
if (!inode_owner_or_capable(dentry->d_inode))
|
||||
return -EPERM;
|
||||
|
||||
if (value) {
|
||||
acl = posix_acl_from_xattr(&init_user_ns, value, size);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
else if (acl) {
|
||||
error = posix_acl_valid(acl);
|
||||
if (error)
|
||||
goto release_and_out;
|
||||
}
|
||||
} else
|
||||
acl = NULL;
|
||||
|
||||
error = ext2_set_acl(dentry->d_inode, type, acl);
|
||||
|
||||
release_and_out:
|
||||
posix_acl_release(acl);
|
||||
return error;
|
||||
}
|
||||
|
||||
const struct xattr_handler ext2_xattr_acl_access_handler = {
|
||||
.prefix = POSIX_ACL_XATTR_ACCESS,
|
||||
.flags = ACL_TYPE_ACCESS,
|
||||
.list = ext2_xattr_list_acl_access,
|
||||
.get = ext2_xattr_get_acl,
|
||||
.set = ext2_xattr_set_acl,
|
||||
};
|
||||
|
||||
const struct xattr_handler ext2_xattr_acl_default_handler = {
|
||||
.prefix = POSIX_ACL_XATTR_DEFAULT,
|
||||
.flags = ACL_TYPE_DEFAULT,
|
||||
.list = ext2_xattr_list_acl_default,
|
||||
.get = ext2_xattr_get_acl,
|
||||
.set = ext2_xattr_set_acl,
|
||||
};
|
||||
|
|
|
@ -55,7 +55,7 @@ static inline int ext2_acl_count(size_t size)
|
|||
|
||||
/* acl.c */
|
||||
extern struct posix_acl *ext2_get_acl(struct inode *inode, int type);
|
||||
extern int ext2_acl_chmod (struct inode *);
|
||||
extern int ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
|
||||
extern int ext2_init_acl (struct inode *, struct inode *);
|
||||
|
||||
#else
|
||||
|
@ -63,12 +63,6 @@ extern int ext2_init_acl (struct inode *, struct inode *);
|
|||
#define ext2_get_acl NULL
|
||||
#define ext2_set_acl NULL
|
||||
|
||||
static inline int
|
||||
ext2_acl_chmod (struct inode *inode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int ext2_init_acl (struct inode *inode, struct inode *dir)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -103,5 +103,6 @@ const struct inode_operations ext2_file_inode_operations = {
|
|||
#endif
|
||||
.setattr = ext2_setattr,
|
||||
.get_acl = ext2_get_acl,
|
||||
.set_acl = ext2_set_acl,
|
||||
.fiemap = ext2_fiemap,
|
||||
};
|
||||
|
|
|
@ -1566,7 +1566,7 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
|
|||
}
|
||||
setattr_copy(inode, iattr);
|
||||
if (iattr->ia_valid & ATTR_MODE)
|
||||
error = ext2_acl_chmod(inode);
|
||||
error = posix_acl_chmod(inode, inode->i_mode);
|
||||
mark_inode_dirty(inode);
|
||||
|
||||
return error;
|
||||
|
|
|
@ -421,6 +421,7 @@ const struct inode_operations ext2_dir_inode_operations = {
|
|||
#endif
|
||||
.setattr = ext2_setattr,
|
||||
.get_acl = ext2_get_acl,
|
||||
.set_acl = ext2_set_acl,
|
||||
.tmpfile = ext2_tmpfile,
|
||||
};
|
||||
|
||||
|
@ -433,4 +434,5 @@ const struct inode_operations ext2_special_inode_operations = {
|
|||
#endif
|
||||
.setattr = ext2_setattr,
|
||||
.get_acl = ext2_get_acl,
|
||||
.set_acl = ext2_set_acl,
|
||||
};
|
||||
|
|
|
@ -103,8 +103,8 @@ static struct mb_cache *ext2_xattr_cache;
|
|||
static const struct xattr_handler *ext2_xattr_handler_map[] = {
|
||||
[EXT2_XATTR_INDEX_USER] = &ext2_xattr_user_handler,
|
||||
#ifdef CONFIG_EXT2_FS_POSIX_ACL
|
||||
[EXT2_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext2_xattr_acl_access_handler,
|
||||
[EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext2_xattr_acl_default_handler,
|
||||
[EXT2_XATTR_INDEX_POSIX_ACL_ACCESS] = &posix_acl_access_xattr_handler,
|
||||
[EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT] = &posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
[EXT2_XATTR_INDEX_TRUSTED] = &ext2_xattr_trusted_handler,
|
||||
#ifdef CONFIG_EXT2_FS_SECURITY
|
||||
|
@ -116,8 +116,8 @@ const struct xattr_handler *ext2_xattr_handlers[] = {
|
|||
&ext2_xattr_user_handler,
|
||||
&ext2_xattr_trusted_handler,
|
||||
#ifdef CONFIG_EXT2_FS_POSIX_ACL
|
||||
&ext2_xattr_acl_access_handler,
|
||||
&ext2_xattr_acl_default_handler,
|
||||
&posix_acl_access_xattr_handler,
|
||||
&posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
#ifdef CONFIG_EXT2_FS_SECURITY
|
||||
&ext2_xattr_security_handler,
|
||||
|
|
|
@ -57,8 +57,6 @@ struct ext2_xattr_entry {
|
|||
|
||||
extern const struct xattr_handler ext2_xattr_user_handler;
|
||||
extern const struct xattr_handler ext2_xattr_trusted_handler;
|
||||
extern const struct xattr_handler ext2_xattr_acl_access_handler;
|
||||
extern const struct xattr_handler ext2_xattr_acl_default_handler;
|
||||
extern const struct xattr_handler ext2_xattr_security_handler;
|
||||
|
||||
extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
|
||||
|
|
231
fs/ext3/acl.c
231
fs/ext3/acl.c
|
@ -145,13 +145,6 @@ ext3_get_acl(struct inode *inode, int type)
|
|||
struct posix_acl *acl;
|
||||
int retval;
|
||||
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return NULL;
|
||||
|
||||
acl = get_cached_acl(inode, type);
|
||||
if (acl != ACL_NOT_CACHED)
|
||||
return acl;
|
||||
|
||||
switch (type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
|
||||
|
@ -190,7 +183,7 @@ ext3_get_acl(struct inode *inode, int type)
|
|||
* inode->i_mutex: down unless called from ext3_new_inode
|
||||
*/
|
||||
static int
|
||||
ext3_set_acl(handle_t *handle, struct inode *inode, int type,
|
||||
__ext3_set_acl(handle_t *handle, struct inode *inode, int type,
|
||||
struct posix_acl *acl)
|
||||
{
|
||||
int name_index;
|
||||
|
@ -198,9 +191,6 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
|
|||
size_t size = 0;
|
||||
int error;
|
||||
|
||||
if (S_ISLNK(inode->i_mode))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
switch(type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
|
||||
|
@ -243,6 +233,23 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
|
|||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
ext3_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
{
|
||||
handle_t *handle;
|
||||
int error, retries = 0;
|
||||
|
||||
retry:
|
||||
handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
|
||||
if (IS_ERR(handle))
|
||||
return PTR_ERR(handle);
|
||||
error = __ext3_set_acl(handle, inode, type, acl);
|
||||
ext3_journal_stop(handle);
|
||||
if (error == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries))
|
||||
goto retry;
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the ACLs of a new inode. Called from ext3_new_inode.
|
||||
*
|
||||
|
@ -252,195 +259,23 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
|
|||
int
|
||||
ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
|
||||
{
|
||||
struct posix_acl *acl = NULL;
|
||||
int error = 0;
|
||||
|
||||
if (!S_ISLNK(inode->i_mode)) {
|
||||
if (test_opt(dir->i_sb, POSIX_ACL)) {
|
||||
acl = ext3_get_acl(dir, ACL_TYPE_DEFAULT);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
}
|
||||
if (!acl)
|
||||
inode->i_mode &= ~current_umask();
|
||||
}
|
||||
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
|
||||
if (S_ISDIR(inode->i_mode)) {
|
||||
error = ext3_set_acl(handle, inode,
|
||||
ACL_TYPE_DEFAULT, acl);
|
||||
if (error)
|
||||
goto cleanup;
|
||||
}
|
||||
error = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
if (error > 0) {
|
||||
/* This is an extended ACL */
|
||||
error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
|
||||
}
|
||||
}
|
||||
cleanup:
|
||||
posix_acl_release(acl);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Does chmod for an inode that may have an Access Control List. The
|
||||
* inode->i_mode field must be updated to the desired value by the caller
|
||||
* before calling this function.
|
||||
* Returns 0 on success, or a negative error number.
|
||||
*
|
||||
* We change the ACL rather than storing some ACL entries in the file
|
||||
* mode permission bits (which would be more efficient), because that
|
||||
* would break once additional permissions (like ACL_APPEND, ACL_DELETE
|
||||
* for directories) are added. There are no more bits available in the
|
||||
* file mode.
|
||||
*
|
||||
* inode->i_mutex: down
|
||||
*/
|
||||
int
|
||||
ext3_acl_chmod(struct inode *inode)
|
||||
{
|
||||
struct posix_acl *acl;
|
||||
handle_t *handle;
|
||||
int retries = 0;
|
||||
int error;
|
||||
|
||||
if (S_ISLNK(inode->i_mode))
|
||||
return -EOPNOTSUPP;
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return 0;
|
||||
acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
|
||||
if (IS_ERR(acl) || !acl)
|
||||
return PTR_ERR(acl);
|
||||
error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
|
||||
if (error)
|
||||
return error;
|
||||
retry:
|
||||
handle = ext3_journal_start(inode,
|
||||
EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
|
||||
if (IS_ERR(handle)) {
|
||||
error = PTR_ERR(handle);
|
||||
ext3_std_error(inode->i_sb, error);
|
||||
goto out;
|
||||
}
|
||||
error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
|
||||
ext3_journal_stop(handle);
|
||||
if (error == -ENOSPC &&
|
||||
ext3_should_retry_alloc(inode->i_sb, &retries))
|
||||
goto retry;
|
||||
out:
|
||||
posix_acl_release(acl);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extended attribute handlers
|
||||
*/
|
||||
static size_t
|
||||
ext3_xattr_list_acl_access(struct dentry *dentry, char *list, size_t list_len,
|
||||
const char *name, size_t name_len, int type)
|
||||
{
|
||||
const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
|
||||
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return 0;
|
||||
if (list && size <= list_len)
|
||||
memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
static size_t
|
||||
ext3_xattr_list_acl_default(struct dentry *dentry, char *list, size_t list_len,
|
||||
const char *name, size_t name_len, int type)
|
||||
{
|
||||
const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
|
||||
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return 0;
|
||||
if (list && size <= list_len)
|
||||
memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int
|
||||
ext3_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer,
|
||||
size_t size, int type)
|
||||
{
|
||||
struct posix_acl *acl;
|
||||
struct posix_acl *default_acl, *acl;
|
||||
int error;
|
||||
|
||||
if (strcmp(name, "") != 0)
|
||||
return -EINVAL;
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
acl = ext3_get_acl(dentry->d_inode, type);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
if (acl == NULL)
|
||||
return -ENODATA;
|
||||
error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
|
||||
posix_acl_release(acl);
|
||||
error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (default_acl) {
|
||||
error = __ext3_set_acl(handle, inode, ACL_TYPE_DEFAULT,
|
||||
default_acl);
|
||||
posix_acl_release(default_acl);
|
||||
}
|
||||
if (acl) {
|
||||
if (!error)
|
||||
error = __ext3_set_acl(handle, inode, ACL_TYPE_ACCESS,
|
||||
acl);
|
||||
posix_acl_release(acl);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
static int
|
||||
ext3_xattr_set_acl(struct dentry *dentry, const char *name, const void *value,
|
||||
size_t size, int flags, int type)
|
||||
{
|
||||
struct inode *inode = dentry->d_inode;
|
||||
handle_t *handle;
|
||||
struct posix_acl *acl;
|
||||
int error, retries = 0;
|
||||
|
||||
if (strcmp(name, "") != 0)
|
||||
return -EINVAL;
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return -EOPNOTSUPP;
|
||||
if (!inode_owner_or_capable(inode))
|
||||
return -EPERM;
|
||||
|
||||
if (value) {
|
||||
acl = posix_acl_from_xattr(&init_user_ns, value, size);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
else if (acl) {
|
||||
error = posix_acl_valid(acl);
|
||||
if (error)
|
||||
goto release_and_out;
|
||||
}
|
||||
} else
|
||||
acl = NULL;
|
||||
|
||||
retry:
|
||||
handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
|
||||
if (IS_ERR(handle))
|
||||
return PTR_ERR(handle);
|
||||
error = ext3_set_acl(handle, inode, type, acl);
|
||||
ext3_journal_stop(handle);
|
||||
if (error == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries))
|
||||
goto retry;
|
||||
|
||||
release_and_out:
|
||||
posix_acl_release(acl);
|
||||
return error;
|
||||
}
|
||||
|
||||
const struct xattr_handler ext3_xattr_acl_access_handler = {
|
||||
.prefix = POSIX_ACL_XATTR_ACCESS,
|
||||
.flags = ACL_TYPE_ACCESS,
|
||||
.list = ext3_xattr_list_acl_access,
|
||||
.get = ext3_xattr_get_acl,
|
||||
.set = ext3_xattr_set_acl,
|
||||
};
|
||||
|
||||
const struct xattr_handler ext3_xattr_acl_default_handler = {
|
||||
.prefix = POSIX_ACL_XATTR_DEFAULT,
|
||||
.flags = ACL_TYPE_DEFAULT,
|
||||
.list = ext3_xattr_list_acl_default,
|
||||
.get = ext3_xattr_get_acl,
|
||||
.set = ext3_xattr_set_acl,
|
||||
};
|
||||
|
|
|
@ -55,18 +55,13 @@ static inline int ext3_acl_count(size_t size)
|
|||
|
||||
/* acl.c */
|
||||
extern struct posix_acl *ext3_get_acl(struct inode *inode, int type);
|
||||
extern int ext3_acl_chmod (struct inode *);
|
||||
extern int ext3_set_acl(struct inode *inode, struct posix_acl *acl, int type);
|
||||
extern int ext3_init_acl (handle_t *, struct inode *, struct inode *);
|
||||
|
||||
#else /* CONFIG_EXT3_FS_POSIX_ACL */
|
||||
#include <linux/sched.h>
|
||||
#define ext3_get_acl NULL
|
||||
|
||||
static inline int
|
||||
ext3_acl_chmod(struct inode *inode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#define ext3_set_acl NULL
|
||||
|
||||
static inline int
|
||||
ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
|
||||
|
|
|
@ -75,6 +75,7 @@ const struct inode_operations ext3_file_inode_operations = {
|
|||
.removexattr = generic_removexattr,
|
||||
#endif
|
||||
.get_acl = ext3_get_acl,
|
||||
.set_acl = ext3_set_acl,
|
||||
.fiemap = ext3_fiemap,
|
||||
};
|
||||
|
||||
|
|
|
@ -3365,7 +3365,7 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
|
|||
mark_inode_dirty(inode);
|
||||
|
||||
if (ia_valid & ATTR_MODE)
|
||||
rc = ext3_acl_chmod(inode);
|
||||
rc = posix_acl_chmod(inode, inode->i_mode);
|
||||
|
||||
err_out:
|
||||
ext3_std_error(inode->i_sb, error);
|
||||
|
|
|
@ -2569,6 +2569,7 @@ const struct inode_operations ext3_dir_inode_operations = {
|
|||
.removexattr = generic_removexattr,
|
||||
#endif
|
||||
.get_acl = ext3_get_acl,
|
||||
.set_acl = ext3_set_acl,
|
||||
};
|
||||
|
||||
const struct inode_operations ext3_special_inode_operations = {
|
||||
|
@ -2580,4 +2581,5 @@ const struct inode_operations ext3_special_inode_operations = {
|
|||
.removexattr = generic_removexattr,
|
||||
#endif
|
||||
.get_acl = ext3_get_acl,
|
||||
.set_acl = ext3_set_acl,
|
||||
};
|
||||
|
|
|
@ -102,8 +102,8 @@ static struct mb_cache *ext3_xattr_cache;
|
|||
static const struct xattr_handler *ext3_xattr_handler_map[] = {
|
||||
[EXT3_XATTR_INDEX_USER] = &ext3_xattr_user_handler,
|
||||
#ifdef CONFIG_EXT3_FS_POSIX_ACL
|
||||
[EXT3_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext3_xattr_acl_access_handler,
|
||||
[EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext3_xattr_acl_default_handler,
|
||||
[EXT3_XATTR_INDEX_POSIX_ACL_ACCESS] = &posix_acl_access_xattr_handler,
|
||||
[EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT] = &posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
[EXT3_XATTR_INDEX_TRUSTED] = &ext3_xattr_trusted_handler,
|
||||
#ifdef CONFIG_EXT3_FS_SECURITY
|
||||
|
@ -115,8 +115,8 @@ const struct xattr_handler *ext3_xattr_handlers[] = {
|
|||
&ext3_xattr_user_handler,
|
||||
&ext3_xattr_trusted_handler,
|
||||
#ifdef CONFIG_EXT3_FS_POSIX_ACL
|
||||
&ext3_xattr_acl_access_handler,
|
||||
&ext3_xattr_acl_default_handler,
|
||||
&posix_acl_access_xattr_handler,
|
||||
&posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
#ifdef CONFIG_EXT3_FS_SECURITY
|
||||
&ext3_xattr_security_handler,
|
||||
|
|
|
@ -60,8 +60,6 @@ struct ext3_xattr_entry {
|
|||
|
||||
extern const struct xattr_handler ext3_xattr_user_handler;
|
||||
extern const struct xattr_handler ext3_xattr_trusted_handler;
|
||||
extern const struct xattr_handler ext3_xattr_acl_access_handler;
|
||||
extern const struct xattr_handler ext3_xattr_acl_default_handler;
|
||||
extern const struct xattr_handler ext3_xattr_security_handler;
|
||||
|
||||
extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
|
||||
|
|
231
fs/ext4/acl.c
231
fs/ext4/acl.c
|
@ -152,13 +152,6 @@ ext4_get_acl(struct inode *inode, int type)
|
|||
struct posix_acl *acl;
|
||||
int retval;
|
||||
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return NULL;
|
||||
|
||||
acl = get_cached_acl(inode, type);
|
||||
if (acl != ACL_NOT_CACHED)
|
||||
return acl;
|
||||
|
||||
switch (type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
|
||||
|
@ -196,7 +189,7 @@ ext4_get_acl(struct inode *inode, int type)
|
|||
* inode->i_mutex: down unless called from ext4_new_inode
|
||||
*/
|
||||
static int
|
||||
ext4_set_acl(handle_t *handle, struct inode *inode, int type,
|
||||
__ext4_set_acl(handle_t *handle, struct inode *inode, int type,
|
||||
struct posix_acl *acl)
|
||||
{
|
||||
int name_index;
|
||||
|
@ -204,9 +197,6 @@ ext4_set_acl(handle_t *handle, struct inode *inode, int type,
|
|||
size_t size = 0;
|
||||
int error;
|
||||
|
||||
if (S_ISLNK(inode->i_mode))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
switch (type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
|
||||
|
@ -248,6 +238,25 @@ ext4_set_acl(handle_t *handle, struct inode *inode, int type,
|
|||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
{
|
||||
handle_t *handle;
|
||||
int error, retries = 0;
|
||||
|
||||
retry:
|
||||
handle = ext4_journal_start(inode, EXT4_HT_XATTR,
|
||||
ext4_jbd2_credits_xattr(inode));
|
||||
if (IS_ERR(handle))
|
||||
return PTR_ERR(handle);
|
||||
|
||||
error = __ext4_set_acl(handle, inode, type, acl);
|
||||
ext4_journal_stop(handle);
|
||||
if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
|
||||
goto retry;
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the ACLs of a new inode. Called from ext4_new_inode.
|
||||
*
|
||||
|
@ -257,199 +266,23 @@ ext4_set_acl(handle_t *handle, struct inode *inode, int type,
|
|||
int
|
||||
ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
|
||||
{
|
||||
struct posix_acl *acl = NULL;
|
||||
int error = 0;
|
||||
|
||||
if (!S_ISLNK(inode->i_mode)) {
|
||||
if (test_opt(dir->i_sb, POSIX_ACL)) {
|
||||
acl = ext4_get_acl(dir, ACL_TYPE_DEFAULT);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
}
|
||||
if (!acl)
|
||||
inode->i_mode &= ~current_umask();
|
||||
}
|
||||
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
|
||||
if (S_ISDIR(inode->i_mode)) {
|
||||
error = ext4_set_acl(handle, inode,
|
||||
ACL_TYPE_DEFAULT, acl);
|
||||
if (error)
|
||||
goto cleanup;
|
||||
}
|
||||
error = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
|
||||
if (error < 0)
|
||||
return error;
|
||||
|
||||
if (error > 0) {
|
||||
/* This is an extended ACL */
|
||||
error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
|
||||
}
|
||||
}
|
||||
cleanup:
|
||||
posix_acl_release(acl);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Does chmod for an inode that may have an Access Control List. The
|
||||
* inode->i_mode field must be updated to the desired value by the caller
|
||||
* before calling this function.
|
||||
* Returns 0 on success, or a negative error number.
|
||||
*
|
||||
* We change the ACL rather than storing some ACL entries in the file
|
||||
* mode permission bits (which would be more efficient), because that
|
||||
* would break once additional permissions (like ACL_APPEND, ACL_DELETE
|
||||
* for directories) are added. There are no more bits available in the
|
||||
* file mode.
|
||||
*
|
||||
* inode->i_mutex: down
|
||||
*/
|
||||
int
|
||||
ext4_acl_chmod(struct inode *inode)
|
||||
{
|
||||
struct posix_acl *acl;
|
||||
handle_t *handle;
|
||||
int retries = 0;
|
||||
struct posix_acl *default_acl, *acl;
|
||||
int error;
|
||||
|
||||
|
||||
if (S_ISLNK(inode->i_mode))
|
||||
return -EOPNOTSUPP;
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return 0;
|
||||
acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
|
||||
if (IS_ERR(acl) || !acl)
|
||||
return PTR_ERR(acl);
|
||||
error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
|
||||
error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
|
||||
if (error)
|
||||
return error;
|
||||
retry:
|
||||
handle = ext4_journal_start(inode, EXT4_HT_XATTR,
|
||||
ext4_jbd2_credits_xattr(inode));
|
||||
if (IS_ERR(handle)) {
|
||||
error = PTR_ERR(handle);
|
||||
ext4_std_error(inode->i_sb, error);
|
||||
goto out;
|
||||
|
||||
if (default_acl) {
|
||||
error = __ext4_set_acl(handle, inode, ACL_TYPE_DEFAULT,
|
||||
default_acl);
|
||||
posix_acl_release(default_acl);
|
||||
}
|
||||
error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
|
||||
ext4_journal_stop(handle);
|
||||
if (error == -ENOSPC &&
|
||||
ext4_should_retry_alloc(inode->i_sb, &retries))
|
||||
goto retry;
|
||||
out:
|
||||
posix_acl_release(acl);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extended attribute handlers
|
||||
*/
|
||||
static size_t
|
||||
ext4_xattr_list_acl_access(struct dentry *dentry, char *list, size_t list_len,
|
||||
const char *name, size_t name_len, int type)
|
||||
{
|
||||
const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
|
||||
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return 0;
|
||||
if (list && size <= list_len)
|
||||
memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
static size_t
|
||||
ext4_xattr_list_acl_default(struct dentry *dentry, char *list, size_t list_len,
|
||||
const char *name, size_t name_len, int type)
|
||||
{
|
||||
const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
|
||||
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return 0;
|
||||
if (list && size <= list_len)
|
||||
memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int
|
||||
ext4_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer,
|
||||
size_t size, int type)
|
||||
{
|
||||
struct posix_acl *acl;
|
||||
int error;
|
||||
|
||||
if (strcmp(name, "") != 0)
|
||||
return -EINVAL;
|
||||
if (!test_opt(dentry->d_sb, POSIX_ACL))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
acl = ext4_get_acl(dentry->d_inode, type);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
if (acl == NULL)
|
||||
return -ENODATA;
|
||||
error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
|
||||
posix_acl_release(acl);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static int
|
||||
ext4_xattr_set_acl(struct dentry *dentry, const char *name, const void *value,
|
||||
size_t size, int flags, int type)
|
||||
{
|
||||
struct inode *inode = dentry->d_inode;
|
||||
handle_t *handle;
|
||||
struct posix_acl *acl;
|
||||
int error, retries = 0;
|
||||
|
||||
if (strcmp(name, "") != 0)
|
||||
return -EINVAL;
|
||||
if (!test_opt(inode->i_sb, POSIX_ACL))
|
||||
return -EOPNOTSUPP;
|
||||
if (!inode_owner_or_capable(inode))
|
||||
return -EPERM;
|
||||
|
||||
if (value) {
|
||||
acl = posix_acl_from_xattr(&init_user_ns, value, size);
|
||||
if (IS_ERR(acl))
|
||||
return PTR_ERR(acl);
|
||||
else if (acl) {
|
||||
error = posix_acl_valid(acl);
|
||||
if (error)
|
||||
goto release_and_out;
|
||||
}
|
||||
} else
|
||||
acl = NULL;
|
||||
|
||||
retry:
|
||||
handle = ext4_journal_start(inode, EXT4_HT_XATTR,
|
||||
ext4_jbd2_credits_xattr(inode));
|
||||
if (IS_ERR(handle)) {
|
||||
error = PTR_ERR(handle);
|
||||
goto release_and_out;
|
||||
if (acl) {
|
||||
if (!error)
|
||||
error = __ext4_set_acl(handle, inode, ACL_TYPE_ACCESS,
|
||||
acl);
|
||||
posix_acl_release(acl);
|
||||
}
|
||||
error = ext4_set_acl(handle, inode, type, acl);
|
||||
ext4_journal_stop(handle);
|
||||
if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
|
||||
goto retry;
|
||||
|
||||
release_and_out:
|
||||
posix_acl_release(acl);
|
||||
return error;
|
||||
}
|
||||
|
||||
const struct xattr_handler ext4_xattr_acl_access_handler = {
|
||||
.prefix = POSIX_ACL_XATTR_ACCESS,
|
||||
.flags = ACL_TYPE_ACCESS,
|
||||
.list = ext4_xattr_list_acl_access,
|
||||
.get = ext4_xattr_get_acl,
|
||||
.set = ext4_xattr_set_acl,
|
||||
};
|
||||
|
||||
const struct xattr_handler ext4_xattr_acl_default_handler = {
|
||||
.prefix = POSIX_ACL_XATTR_DEFAULT,
|
||||
.flags = ACL_TYPE_DEFAULT,
|
||||
.list = ext4_xattr_list_acl_default,
|
||||
.get = ext4_xattr_get_acl,
|
||||
.set = ext4_xattr_set_acl,
|
||||
};
|
||||
|
|
|
@ -55,18 +55,13 @@ static inline int ext4_acl_count(size_t size)
|
|||
|
||||
/* acl.c */
|
||||
struct posix_acl *ext4_get_acl(struct inode *inode, int type);
|
||||
extern int ext4_acl_chmod(struct inode *);
|
||||
int ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type);
|
||||
extern int ext4_init_acl(handle_t *, struct inode *, struct inode *);
|
||||
|
||||
#else /* CONFIG_EXT4_FS_POSIX_ACL */
|
||||
#include <linux/sched.h>
|
||||
#define ext4_get_acl NULL
|
||||
|
||||
static inline int
|
||||
ext4_acl_chmod(struct inode *inode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#define ext4_set_acl NULL
|
||||
|
||||
static inline int
|
||||
ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
|
||||
|
|
|
@ -617,6 +617,7 @@ const struct inode_operations ext4_file_inode_operations = {
|
|||
.listxattr = ext4_listxattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.get_acl = ext4_get_acl,
|
||||
.set_acl = ext4_set_acl,
|
||||
.fiemap = ext4_fiemap,
|
||||
};
|
||||
|
||||
|
|
|
@ -4663,7 +4663,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
|
|||
ext4_orphan_del(NULL, inode);
|
||||
|
||||
if (!rc && (ia_valid & ATTR_MODE))
|
||||
rc = ext4_acl_chmod(inode);
|
||||
rc = posix_acl_chmod(inode, inode->i_mode);
|
||||
|
||||
err_out:
|
||||
ext4_std_error(inode->i_sb, error);
|
||||
|
|
|
@ -3225,6 +3225,7 @@ const struct inode_operations ext4_dir_inode_operations = {
|
|||
.listxattr = ext4_listxattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.get_acl = ext4_get_acl,
|
||||
.set_acl = ext4_set_acl,
|
||||
.fiemap = ext4_fiemap,
|
||||
};
|
||||
|
||||
|
@ -3235,4 +3236,5 @@ const struct inode_operations ext4_special_inode_operations = {
|
|||
.listxattr = ext4_listxattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.get_acl = ext4_get_acl,
|
||||
.set_acl = ext4_set_acl,
|
||||
};
|
||||
|
|
|
@ -95,8 +95,8 @@ static struct mb_cache *ext4_xattr_cache;
|
|||
static const struct xattr_handler *ext4_xattr_handler_map[] = {
|
||||
[EXT4_XATTR_INDEX_USER] = &ext4_xattr_user_handler,
|
||||
#ifdef CONFIG_EXT4_FS_POSIX_ACL
|
||||
[EXT4_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext4_xattr_acl_access_handler,
|
||||
[EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext4_xattr_acl_default_handler,
|
||||
[EXT4_XATTR_INDEX_POSIX_ACL_ACCESS] = &posix_acl_access_xattr_handler,
|
||||
[EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT] = &posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
[EXT4_XATTR_INDEX_TRUSTED] = &ext4_xattr_trusted_handler,
|
||||
#ifdef CONFIG_EXT4_FS_SECURITY
|
||||
|
@ -108,8 +108,8 @@ const struct xattr_handler *ext4_xattr_handlers[] = {
|
|||
&ext4_xattr_user_handler,
|
||||
&ext4_xattr_trusted_handler,
|
||||
#ifdef CONFIG_EXT4_FS_POSIX_ACL
|
||||
&ext4_xattr_acl_access_handler,
|
||||
&ext4_xattr_acl_default_handler,
|
||||
&posix_acl_access_xattr_handler,
|
||||
&posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
#ifdef CONFIG_EXT4_FS_SECURITY
|
||||
&ext4_xattr_security_handler,
|
||||
|
|
|
@ -96,8 +96,6 @@ struct ext4_xattr_ibody_find {
|
|||
|
||||
extern const struct xattr_handler ext4_xattr_user_handler;
|
||||
extern const struct xattr_handler ext4_xattr_trusted_handler;
|
||||
extern const struct xattr_handler ext4_xattr_acl_access_handler;
|
||||
extern const struct xattr_handler ext4_xattr_acl_default_handler;
|
||||
extern const struct xattr_handler ext4_xattr_security_handler;
|
||||
|
||||
extern ssize_t ext4_listxattr(struct dentry *, char *, size_t);
|
||||
|
|
Loading…
Reference in a new issue