Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Richacl #109

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d5d1fb4
vfs: Indicate that the permission functions take all the MAY_* flags
Oct 18, 2011
0f69c40
vfs: Add hex format for MAY_* flag values
kvaneesh Oct 18, 2011
bf56180
vfs: Pass all mask flags down to iop->check_acl
Oct 18, 2011
518cbba
vfs: Add a comment to inode_permission()
Oct 18, 2011
89e1033
vfs: Add generic IS_ACL() test for acl support
Oct 18, 2011
45481f1
vfs: Add IS_RICHACL() test for richacl support
Oct 18, 2011
c684918
vfs: Optimize out IS_RICHACL() if CONFIG_FS_RICHACL is not defined
Oct 18, 2011
004723e
vfs: Add new file and directory create permission flags
Oct 18, 2011
1654a09
vfs: Add delete child and delete self permission flags
Oct 18, 2011
3437a82
vfs: Make the inode passed to inode_change_ok non-const
Oct 18, 2011
e963a4c
vfs: Add permission flags for setting file attributes
Oct 18, 2011
26dc449
vfs: Make acl_permission_check() work for richacls
Oct 18, 2011
e210ab8
richacl: In-memory representation and helper functions
Oct 18, 2011
36ee026
richacl: Permission mapping functions
Oct 18, 2011
dc240c0
richacl: Compute maximum file masks from an acl
Oct 18, 2011
6be646b
richacl: Update the file masks in chmod()
Oct 18, 2011
61bf134
richacl: Permission check algorithm
Oct 18, 2011
9d9bef3
richacl: Create-time inheritance
Oct 18, 2011
8013f16
richacl: Check if an acl is equivalent to a file mode
Oct 18, 2011
5882a81
richacl: Automatic Inheritance
Oct 18, 2011
862d861
richacl: xattr mapping functions
Oct 18, 2011
69d9df5
vfs: Cache richacl in struct inode
Oct 18, 2011
e86e410
vfs: Add richacl permission check
kvaneesh Oct 18, 2011
434e398
ext4: Use IS_POSIXACL() to check for POSIX ACL support
kvaneesh Oct 18, 2011
69b47fd
ext4: Implement rich acl for ext4
kvaneesh Oct 18, 2011
e17ad31
ext4: Add Ext4 compat richacl feature flag
kvaneesh Oct 18, 2011
13fc237
ext4: Add temporary richacl mount option for ext4
kvaneesh Oct 18, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
richacl: Create-time inheritance
When a new file is created, it can inherit an acl from its parent
directory; this is similar to how default acls work in POSIX (draft)
ACLs.

As with POSIX ACLs, if a file inherits an acl from its parent directory,
the intersection between the create mode and the permissions granted by
the inherited acl determines the file masks and file permission bits,
and the umask is ignored.

Acked-by: J. Bruce Fields <[email protected]>
Acked-by: David Howells <[email protected]>
Signed-off-by: Andreas Gruenbacher <[email protected]>
Signed-off-by: Aneesh Kumar K.V <[email protected]>
  • Loading branch information
Andreas Gruenbacher authored and kvaneesh committed Oct 23, 2011
commit 9d9bef3788daeeec62c6bd5aa53dcfffe3373dd8
2 changes: 1 addition & 1 deletion fs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ obj-$(CONFIG_GENERIC_ACL) += generic_acl.o

obj-$(CONFIG_FHANDLE) += fhandle.o
obj-$(CONFIG_FS_RICHACL) += richacl.o
richacl-y := richacl_base.o
richacl-y := richacl_base.o richacl_inode.o

obj-y += quota/

Expand Down
69 changes: 69 additions & 0 deletions fs/richacl_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,72 @@ richacl_permission(struct inode *inode, const struct richacl *acl,
return denied ? -EACCES : 0;
}
EXPORT_SYMBOL_GPL(richacl_permission);

/**
* richacl_inherit - compute the inherited acl of a new file
* @dir_acl: acl of the containing directory
* @isdir: inherit by a directory or non-directory?
*
* A directory can have acl entries which files and/or directories created
* inside the directory will inherit. This function computes the acl for such
* a new file. If there is no inheritable acl, it will return %NULL.
*/
struct richacl *
richacl_inherit(const struct richacl *dir_acl, int isdir)
{
const struct richace *dir_ace;
struct richacl *acl = NULL;
struct richace *ace;
int count = 0;

if (isdir) {
richacl_for_each_entry(dir_ace, dir_acl) {
if (!richace_is_inheritable(dir_ace))
continue;
count++;
}
if (!count)
return NULL;
acl = richacl_alloc(count);
if (!acl)
return ERR_PTR(-ENOMEM);
ace = acl->a_entries;
richacl_for_each_entry(dir_ace, dir_acl) {
if (!richace_is_inheritable(dir_ace))
continue;
memcpy(ace, dir_ace, sizeof(struct richace));
if (dir_ace->e_flags & ACE4_NO_PROPAGATE_INHERIT_ACE)
richace_clear_inheritance_flags(ace);
if ((dir_ace->e_flags & ACE4_FILE_INHERIT_ACE) &&
!(dir_ace->e_flags & ACE4_DIRECTORY_INHERIT_ACE))
ace->e_flags |= ACE4_INHERIT_ONLY_ACE;
ace++;
}
} else {
richacl_for_each_entry(dir_ace, dir_acl) {
if (!(dir_ace->e_flags & ACE4_FILE_INHERIT_ACE))
continue;
count++;
}
if (!count)
return NULL;
acl = richacl_alloc(count);
if (!acl)
return ERR_PTR(-ENOMEM);
ace = acl->a_entries;
richacl_for_each_entry(dir_ace, dir_acl) {
if (!(dir_ace->e_flags & ACE4_FILE_INHERIT_ACE))
continue;
memcpy(ace, dir_ace, sizeof(struct richace));
richace_clear_inheritance_flags(ace);
/*
* ACE4_DELETE_CHILD is meaningless for
* non-directories, so clear it.
*/
ace->e_mask &= ~ACE4_DELETE_CHILD;
ace++;
}
}

return acl;
}
59 changes: 59 additions & 0 deletions fs/richacl_inode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2010 Novell, Inc.
* Written by Andreas Gruenbacher <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/

#include <linux/sched.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/richacl.h>

/**
* richacl_inherit_inode - compute inherited acl and file mode
* @dir_acl: acl of the containing directory
* @inode: inode of the new file (create mode in i_mode)
*
* The file permission bits in inode->i_mode must be set to the create mode.
* If there is an inheritable acl, the maximum permissions that the acl grants
* will be computed and permissions not granted by the acl will be removed from
* inode->i_mode. If there is no inheritable acl, the umask will be applied
* instead.
*/
struct richacl *
richacl_inherit_inode(const struct richacl *dir_acl, struct inode *inode)
{
struct richacl *acl;
mode_t mask;

acl = richacl_inherit(dir_acl, S_ISDIR(inode->i_mode));
if (acl) {

richacl_compute_max_masks(acl);

/*
* Ensure that the acl will not grant any permissions beyond
* the create mode.
*/
acl->a_flags |= ACL4_MASKED;
acl->a_owner_mask &= richacl_mode_to_mask(inode->i_mode >> 6) |
ACE4_POSIX_OWNER_ALLOWED;
acl->a_group_mask &= richacl_mode_to_mask(inode->i_mode >> 3);
acl->a_other_mask &= richacl_mode_to_mask(inode->i_mode);
mask = ~S_IRWXUGO | richacl_masks_to_mode(acl);
} else
mask = ~current_umask();

inode->i_mode &= mask;
return acl;
}
EXPORT_SYMBOL_GPL(richacl_inherit_inode);
4 changes: 4 additions & 0 deletions include/linux/richacl.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,9 @@ extern void richacl_compute_max_masks(struct richacl *);
extern struct richacl *richacl_chmod(struct richacl *, mode_t);
extern int richacl_permission(struct inode *, const struct richacl *,
unsigned int);
extern struct richacl *richacl_inherit(const struct richacl *, int);

/* richacl_inode.c */
extern struct richacl *richacl_inherit_inode(const struct richacl *,
struct inode *);
#endif /* __RICHACL_H */