37 #include <linux/slab.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/export.h>
44 #define NFS4_READ_MODE (NFS4_ACE_READ_DATA)
45 #define NFS4_WRITE_MODE (NFS4_ACE_WRITE_DATA | NFS4_ACE_APPEND_DATA)
46 #define NFS4_EXECUTE_MODE NFS4_ACE_EXECUTE
47 #define NFS4_ANYONE_MODE (NFS4_ACE_READ_ATTRIBUTES | NFS4_ACE_READ_ACL | NFS4_ACE_SYNCHRONIZE)
48 #define NFS4_OWNER_MODE (NFS4_ACE_WRITE_ATTRIBUTES | NFS4_ACE_WRITE_ACL)
51 #define NFS4_MASK_UNSUPP (NFS4_ACE_DELETE | NFS4_ACE_WRITE_OWNER \
52 | NFS4_ACE_READ_NAMED_ATTRS | NFS4_ACE_WRITE_NAMED_ATTRS)
55 #define NFS4_INHERITANCE_FLAGS (NFS4_ACE_FILE_INHERIT_ACE \
56 | NFS4_ACE_DIRECTORY_INHERIT_ACE)
58 #define NFS4_SUPPORTED_FLAGS (NFS4_INHERITANCE_FLAGS \
59 | NFS4_ACE_INHERIT_ONLY_ACE \
60 | NFS4_ACE_IDENTIFIER_GROUP)
62 #define MASK_EQUAL(mask1, mask2) \
63 ( ((mask1) & NFS4_ACE_MASK_ALL) == ((mask2) & NFS4_ACE_MASK_ALL) )
66 mask_from_posix(
unsigned short perm,
unsigned int flags)
109 low_mode_from_nfs4(
u32 perm,
unsigned short *
mode,
unsigned int flags)
113 if (flags & NFS4_ACL_DIR)
118 if ((perm & write_mode) == write_mode)
129 static short ace2type(
struct nfs4_ace *);
184 memset(pas, 0,
sizeof(*pas));
230 summarize_posix_acl(pacl, &pas);
241 deny &= pas.users | pas.group | pas.groups | pas.other;
245 ace->
access_mask = deny_mask_from_posix(deny, flags);
260 deny = ~(pa->
e_perm & pas.mask);
261 deny &= pas.groups | pas.group | pas.other;
265 ace->
access_mask = deny_mask_from_posix(deny, flags);
287 group_owner_entry = pa;
291 ace->
access_mask = mask_from_posix(pas.group, flags);
311 pa = group_owner_entry;
313 deny = ~pas.group & pas.other;
317 ace->
access_mask = deny_mask_from_posix(deny, flags);
325 deny = ~(pa->
e_perm & pas.mask);
330 ace->
access_mask = deny_mask_from_posix(deny, flags);
357 for (
i = start;
i <
end;
i++) {
381 sort_pacl_range(pacl, 1, i-1);
387 sort_pacl_range(pacl, i, j-1);
480 static inline int check_deny(
u32 mask,
int isowner)
506 return pacl ? pacl : ERR_PTR(-
ENOMEM);
520 error = check_deny(state->
owner.deny, 1);
523 low_mode_from_nfs4(state->
owner.allow, &pace->
e_perm, flags);
526 for (i=0; i < state->
users->n; i++) {
529 error = check_deny(state->
users->aces[i].perms.deny, 0);
532 low_mode_from_nfs4(state->
users->aces[i].perms.allow,
535 add_to_mask(state, &state->
users->aces[i].perms);
540 error = check_deny(state->
group.deny, 0);
543 low_mode_from_nfs4(state->
group.allow, &pace->
e_perm, flags);
545 add_to_mask(state, &state->
group);
547 for (i=0; i < state->
groups->n; i++) {
550 error = check_deny(state->
groups->aces[i].perms.deny, 0);
553 low_mode_from_nfs4(state->
groups->aces[i].perms.allow,
556 add_to_mask(state, &state->
groups->aces[i].perms);
561 low_mode_from_nfs4(state->
mask.allow, &pace->
e_perm, flags);
566 error = check_deny(state->
other.deny, 0);
569 low_mode_from_nfs4(state->
other.allow, &pace->
e_perm, flags);
574 posix_acl_release(pacl);
575 return ERR_PTR(error);
594 for (i = 0; i < a->
n; i++)
595 if (a->
aces[i].uid == uid)
610 for (i=0; i < a->
n; i++)
611 deny_bits(&a->
aces[i].perms, mask);
618 for (i=0; i < a->
n; i++)
619 allow_bits(&a->
aces[i].perms, mask);
630 switch (ace2type(ace)) {
633 allow_bits(&state->
owner, mask);
635 deny_bits(&state->
owner, mask);
639 i = find_uid(state, state->
users, ace->
who);
641 allow_bits(&state->
users->aces[i].perms, mask);
643 deny_bits(&state->
users->aces[i].perms, mask);
644 mask = state->
users->aces[
i].perms.deny;
645 deny_bits(&state->
owner, mask);
650 allow_bits(&state->
group, mask);
652 deny_bits(&state->
group, mask);
653 mask = state->
group.deny;
654 deny_bits(&state->
owner, mask);
656 deny_bits_array(state->
users, mask);
657 deny_bits_array(state->
groups, mask);
661 i = find_uid(state, state->
groups, ace->
who);
663 allow_bits(&state->
groups->aces[i].perms, mask);
665 deny_bits(&state->
groups->aces[i].perms, mask);
666 mask = state->
groups->aces[
i].perms.deny;
667 deny_bits(&state->
owner, mask);
668 deny_bits(&state->
group, mask);
670 deny_bits_array(state->
users, mask);
671 deny_bits_array(state->
groups, mask);
676 allow_bits(&state->
owner, mask);
677 allow_bits(&state->
group, mask);
678 allow_bits(&state->
other, mask);
680 allow_bits_array(state->
users, mask);
681 allow_bits_array(state->
groups, mask);
683 deny_bits(&state->
owner, mask);
684 deny_bits(&state->
group, mask);
685 deny_bits(&state->
other, mask);
687 deny_bits_array(state->
users, mask);
688 deny_bits_array(state->
groups, mask);
694 struct posix_acl **dpacl,
unsigned int flags)
700 ret = init_state(&effective_acl_state, acl->
naces);
703 ret = init_state(&default_acl_state, acl->
naces);
707 for (ace = acl->
aces; ace < acl->aces + acl->
naces; ace++) {
714 process_one_v4_ace(&effective_acl_state, ace);
717 if (!(flags & NFS4_ACL_DIR))
724 process_one_v4_ace(&default_acl_state, ace);
727 process_one_v4_ace(&effective_acl_state, ace);
729 *pacl = posix_state_to_acl(&effective_acl_state, flags);
731 ret = PTR_ERR(*pacl);
735 *dpacl = posix_state_to_acl(&default_acl_state,
736 flags | NFS4_ACL_TYPE_DEFAULT);
737 if (IS_ERR(*dpacl)) {
738 ret = PTR_ERR(*dpacl);
740 posix_acl_release(*pacl);
748 free_state(&default_acl_state);
750 free_state(&effective_acl_state);
794 .stringlen =
sizeof(
"OWNER@") - 1,
799 .stringlen =
sizeof(
"GROUP@") - 1,
803 .string =
"EVERYONE@",
804 .stringlen =
sizeof(
"EVERYONE@") - 1,
816 0 ==
memcmp(s2t_map[i].
string, p, len))
817 return s2t_map[i].
type;
828 if (s2t_map[i].
type == who) {
830 return s2t_map[
i].stringlen;