2 * Common NFSv4 ACL handling code.
4 * Copyright (c) 2002, 2003 The Regents of the University of Michigan.
7 * Marius Aamodt Eriksen <marius@umich.edu>
8 * Jeff Sedlak <jsedlak@umich.edu>
9 * J. Bruce Fields <bfields@umich.edu>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <linux/slab.h>
38 #include <linux/nfs_fs.h>
39 #include <linux/export.h>
44 #define NFS4_ACL_TYPE_DEFAULT 0x01
45 #define NFS4_ACL_DIR 0x02
46 #define NFS4_ACL_OWNER 0x04
48 /* mode bit translations: */
49 #define NFS4_READ_MODE (NFS4_ACE_READ_DATA)
50 #define NFS4_WRITE_MODE (NFS4_ACE_WRITE_DATA | NFS4_ACE_APPEND_DATA)
51 #define NFS4_EXECUTE_MODE NFS4_ACE_EXECUTE
52 #define NFS4_ANYONE_MODE (NFS4_ACE_READ_ATTRIBUTES | NFS4_ACE_READ_ACL | NFS4_ACE_SYNCHRONIZE)
53 #define NFS4_OWNER_MODE (NFS4_ACE_WRITE_ATTRIBUTES | NFS4_ACE_WRITE_ACL)
55 /* We don't support these bits; insist they be neither allowed nor denied */
56 #define NFS4_MASK_UNSUPP (NFS4_ACE_DELETE | NFS4_ACE_WRITE_OWNER \
57 | NFS4_ACE_READ_NAMED_ATTRS | NFS4_ACE_WRITE_NAMED_ATTRS)
59 /* flags used to simulate posix default ACLs */
60 #define NFS4_INHERITANCE_FLAGS (NFS4_ACE_FILE_INHERIT_ACE \
61 | NFS4_ACE_DIRECTORY_INHERIT_ACE)
63 #define NFS4_SUPPORTED_FLAGS (NFS4_INHERITANCE_FLAGS \
64 | NFS4_ACE_INHERIT_ONLY_ACE \
65 | NFS4_ACE_IDENTIFIER_GROUP)
67 #define MASK_EQUAL(mask1, mask2) \
68 ( ((mask1) & NFS4_ACE_MASK_ALL) == ((mask2) & NFS4_ACE_MASK_ALL) )
71 mask_from_posix(unsigned short perm, unsigned int flags)
73 int mask = NFS4_ANYONE_MODE;
75 if (flags & NFS4_ACL_OWNER)
76 mask |= NFS4_OWNER_MODE;
78 mask |= NFS4_READ_MODE;
80 mask |= NFS4_WRITE_MODE;
81 if ((perm & ACL_WRITE) && (flags & NFS4_ACL_DIR))
82 mask |= NFS4_ACE_DELETE_CHILD;
83 if (perm & ACL_EXECUTE)
84 mask |= NFS4_EXECUTE_MODE;
89 deny_mask_from_posix(unsigned short perm, u32 flags)
94 mask |= NFS4_READ_MODE;
96 mask |= NFS4_WRITE_MODE;
97 if ((perm & ACL_WRITE) && (flags & NFS4_ACL_DIR))
98 mask |= NFS4_ACE_DELETE_CHILD;
99 if (perm & ACL_EXECUTE)
100 mask |= NFS4_EXECUTE_MODE;
104 /* XXX: modify functions to return NFS errors; they're only ever
105 * used by nfs code, after all.... */
107 /* We only map from NFSv4 to POSIX ACLs when setting ACLs, when we err on the
108 * side of being more restrictive, so the mode bit mapping below is
109 * pessimistic. An optimistic version would be needed to handle DENY's,
110 * but we espect to coalesce all ALLOWs and DENYs before mapping to mode
114 low_mode_from_nfs4(u32 perm, unsigned short *mode, unsigned int flags)
116 u32 write_mode = NFS4_WRITE_MODE;
118 if (flags & NFS4_ACL_DIR)
119 write_mode |= NFS4_ACE_DELETE_CHILD;
121 if ((perm & NFS4_READ_MODE) == NFS4_READ_MODE)
123 if ((perm & write_mode) == write_mode)
125 if ((perm & NFS4_EXECUTE_MODE) == NFS4_EXECUTE_MODE)
126 *mode |= ACL_EXECUTE;
129 struct ace_container {
130 struct nfs4_ace *ace;
131 struct list_head ace_l;
134 static short ace2type(struct nfs4_ace *);
135 static void _posix_to_nfsv4_one(struct posix_acl *, struct nfs4_acl *,
139 nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
140 struct nfs4_acl **acl)
142 struct inode *inode = dentry->d_inode;
144 struct posix_acl *pacl = NULL, *dpacl = NULL;
145 unsigned int flags = 0;
148 pacl = get_acl(inode, ACL_TYPE_ACCESS);
150 pacl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
152 return PTR_ERR(pacl);
153 /* allocate for worst case: one (deny, allow) pair each: */
154 size += 2 * pacl->a_count;
157 if (S_ISDIR(inode->i_mode)) {
158 flags = NFS4_ACL_DIR;
159 dpacl = get_acl(inode, ACL_TYPE_DEFAULT);
161 size += 2 * dpacl->a_count;
166 *acl = nfs4_acl_new(size);
173 _posix_to_nfsv4_one(pacl, *acl, flags & ~NFS4_ACL_TYPE_DEFAULT);
176 _posix_to_nfsv4_one(dpacl, *acl, flags | NFS4_ACL_TYPE_DEFAULT);
179 posix_acl_release(pacl);
180 posix_acl_release(dpacl);
184 struct posix_acl_summary {
185 unsigned short owner;
186 unsigned short users;
187 unsigned short group;
188 unsigned short groups;
189 unsigned short other;
194 summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
196 struct posix_acl_entry *pa, *pe;
199 * Only pas.users and pas.groups need initialization; previous
200 * posix_acl_valid() calls ensure that the other fields will be
201 * initialized in the following loop. But, just to placate gcc:
203 memset(pas, 0, sizeof(*pas));
206 pe = acl->a_entries + acl->a_count;
208 FOREACH_ACL_ENTRY(pa, acl, pe) {
211 pas->owner = pa->e_perm;
214 pas->group = pa->e_perm;
217 pas->users |= pa->e_perm;
220 pas->groups |= pa->e_perm;
223 pas->other = pa->e_perm;
226 pas->mask = pa->e_perm;
230 /* We'll only care about effective permissions: */
231 pas->users &= pas->mask;
232 pas->group &= pas->mask;
233 pas->groups &= pas->mask;
236 /* We assume the acl has been verified with posix_acl_valid. */
238 _posix_to_nfsv4_one(struct posix_acl *pacl, struct nfs4_acl *acl,
241 struct posix_acl_entry *pa, *group_owner_entry;
242 struct nfs4_ace *ace;
243 struct posix_acl_summary pas;
245 int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
246 NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);
248 BUG_ON(pacl->a_count < 3);
249 summarize_posix_acl(pacl, &pas);
251 pa = pacl->a_entries;
252 ace = acl->aces + acl->naces;
254 /* We could deny everything not granted by the owner: */
257 * but it is equivalent (and simpler) to deny only what is not
258 * granted by later entries:
260 deny &= pas.users | pas.group | pas.groups | pas.other;
262 ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
264 ace->access_mask = deny_mask_from_posix(deny, flags);
265 ace->whotype = NFS4_ACL_WHO_OWNER;
270 ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
272 ace->access_mask = mask_from_posix(pa->e_perm, flags | NFS4_ACL_OWNER);
273 ace->whotype = NFS4_ACL_WHO_OWNER;
278 while (pa->e_tag == ACL_USER) {
279 deny = ~(pa->e_perm & pas.mask);
280 deny &= pas.groups | pas.group | pas.other;
282 ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
284 ace->access_mask = deny_mask_from_posix(deny, flags);
285 ace->whotype = NFS4_ACL_WHO_NAMED;
286 ace->who_uid = pa->e_uid;
290 ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
292 ace->access_mask = mask_from_posix(pa->e_perm & pas.mask,
294 ace->whotype = NFS4_ACL_WHO_NAMED;
295 ace->who_uid = pa->e_uid;
301 /* In the case of groups, we apply allow ACEs first, then deny ACEs,
302 * since a user can be in more than one group. */
306 group_owner_entry = pa;
308 ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
310 ace->access_mask = mask_from_posix(pas.group, flags);
311 ace->whotype = NFS4_ACL_WHO_GROUP;
316 while (pa->e_tag == ACL_GROUP) {
317 ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
318 ace->flag = eflag | NFS4_ACE_IDENTIFIER_GROUP;
319 ace->access_mask = mask_from_posix(pa->e_perm & pas.mask,
321 ace->whotype = NFS4_ACL_WHO_NAMED;
322 ace->who_gid = pa->e_gid;
330 pa = group_owner_entry;
332 deny = ~pas.group & pas.other;
334 ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
336 ace->access_mask = deny_mask_from_posix(deny, flags);
337 ace->whotype = NFS4_ACL_WHO_GROUP;
343 while (pa->e_tag == ACL_GROUP) {
344 deny = ~(pa->e_perm & pas.mask);
347 ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
348 ace->flag = eflag | NFS4_ACE_IDENTIFIER_GROUP;
349 ace->access_mask = deny_mask_from_posix(deny, flags);
350 ace->whotype = NFS4_ACL_WHO_NAMED;
351 ace->who_gid = pa->e_gid;
358 if (pa->e_tag == ACL_MASK)
360 ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
362 ace->access_mask = mask_from_posix(pa->e_perm, flags);
363 ace->whotype = NFS4_ACL_WHO_EVERYONE;
368 pace_gt(struct posix_acl_entry *pace1, struct posix_acl_entry *pace2)
370 if (pace1->e_tag != pace2->e_tag)
371 return pace1->e_tag > pace2->e_tag;
372 if (pace1->e_tag == ACL_USER)
373 return uid_gt(pace1->e_uid, pace2->e_uid);
374 if (pace1->e_tag == ACL_GROUP)
375 return gid_gt(pace1->e_gid, pace2->e_gid);
380 sort_pacl_range(struct posix_acl *pacl, int start, int end) {
382 struct posix_acl_entry tmp;
384 /* We just do a bubble sort; easy to do in place, and we're not
385 * expecting acl's to be long enough to justify anything more. */
388 for (i = start; i < end; i++) {
389 if (pace_gt(&pacl->a_entries[i],
390 &pacl->a_entries[i+1])) {
392 tmp = pacl->a_entries[i];
393 pacl->a_entries[i] = pacl->a_entries[i+1];
394 pacl->a_entries[i+1] = tmp;
401 sort_pacl(struct posix_acl *pacl)
403 /* posix_acl_valid requires that users and groups be in order
407 if (pacl->a_count <= 4)
408 return; /* no users or groups */
410 while (pacl->a_entries[i].e_tag == ACL_USER)
412 sort_pacl_range(pacl, 1, i-1);
414 BUG_ON(pacl->a_entries[i].e_tag != ACL_GROUP_OBJ);
416 while (pacl->a_entries[j].e_tag == ACL_GROUP)
418 sort_pacl_range(pacl, i, j-1);
423 * While processing the NFSv4 ACE, this maintains bitmasks representing
424 * which permission bits have been allowed and which denied to a given
426 struct posix_ace_state {
431 struct posix_user_ace_state {
436 struct posix_ace_state perms;
439 struct posix_ace_state_array {
441 struct posix_user_ace_state aces[];
445 * While processing the NFSv4 ACE, this maintains the partial permissions
446 * calculated so far: */
448 struct posix_acl_state {
450 struct posix_ace_state owner;
451 struct posix_ace_state group;
452 struct posix_ace_state other;
453 struct posix_ace_state everyone;
454 struct posix_ace_state mask; /* Deny unused in this case */
455 struct posix_ace_state_array *users;
456 struct posix_ace_state_array *groups;
460 init_state(struct posix_acl_state *state, int cnt)
464 memset(state, 0, sizeof(struct posix_acl_state));
467 * In the worst case, each individual acl could be for a distinct
468 * named user or group, but we don't no which, so we allocate
469 * enough space for either:
471 alloc = sizeof(struct posix_ace_state_array)
472 + cnt*sizeof(struct posix_user_ace_state);
473 state->users = kzalloc(alloc, GFP_KERNEL);
476 state->groups = kzalloc(alloc, GFP_KERNEL);
477 if (!state->groups) {
485 free_state(struct posix_acl_state *state) {
487 kfree(state->groups);
490 static inline void add_to_mask(struct posix_acl_state *state, struct posix_ace_state *astate)
492 state->mask.allow |= astate->allow;
496 * Certain bits (SYNCHRONIZE, DELETE, WRITE_OWNER, READ/WRITE_NAMED_ATTRS,
497 * READ_ATTRIBUTES, READ_ACL) are currently unenforceable and don't translate
498 * to traditional read/write/execute permissions.
500 * It's problematic to reject acls that use certain mode bits, because it
501 * places the burden on users to learn the rules about which bits one
502 * particular server sets, without giving the user a lot of help--we return an
503 * error that could mean any number of different things. To make matters
504 * worse, the problematic bits might be introduced by some application that's
505 * automatically mapping from some other acl model.
507 * So wherever possible we accept anything, possibly erring on the side of
508 * denying more permissions than necessary.
510 * However we do reject *explicit* DENY's of a few bits representing
511 * permissions we could never deny:
514 static inline int check_deny(u32 mask, int isowner)
516 if (mask & (NFS4_ACE_READ_ATTRIBUTES | NFS4_ACE_READ_ACL))
520 if (mask & (NFS4_ACE_WRITE_ATTRIBUTES | NFS4_ACE_WRITE_ACL))
525 static struct posix_acl *
526 posix_state_to_acl(struct posix_acl_state *state, unsigned int flags)
528 struct posix_acl_entry *pace;
529 struct posix_acl *pacl;
534 * ACLs with no ACEs are treated differently in the inheritable
535 * and effective cases: when there are no inheritable ACEs, we
536 * set a zero-length default posix acl:
538 if (state->empty && (flags & NFS4_ACL_TYPE_DEFAULT)) {
539 pacl = posix_acl_alloc(0, GFP_KERNEL);
540 return pacl ? pacl : ERR_PTR(-ENOMEM);
543 * When there are no effective ACEs, the following will end
544 * up setting a 3-element effective posix ACL with all
547 nace = 4 + state->users->n + state->groups->n;
548 pacl = posix_acl_alloc(nace, GFP_KERNEL);
550 return ERR_PTR(-ENOMEM);
552 pace = pacl->a_entries;
553 pace->e_tag = ACL_USER_OBJ;
554 error = check_deny(state->owner.deny, 1);
557 low_mode_from_nfs4(state->owner.allow, &pace->e_perm, flags);
559 for (i=0; i < state->users->n; i++) {
561 pace->e_tag = ACL_USER;
562 error = check_deny(state->users->aces[i].perms.deny, 0);
565 low_mode_from_nfs4(state->users->aces[i].perms.allow,
566 &pace->e_perm, flags);
567 pace->e_uid = state->users->aces[i].uid;
568 add_to_mask(state, &state->users->aces[i].perms);
572 pace->e_tag = ACL_GROUP_OBJ;
573 error = check_deny(state->group.deny, 0);
576 low_mode_from_nfs4(state->group.allow, &pace->e_perm, flags);
577 add_to_mask(state, &state->group);
579 for (i=0; i < state->groups->n; i++) {
581 pace->e_tag = ACL_GROUP;
582 error = check_deny(state->groups->aces[i].perms.deny, 0);
585 low_mode_from_nfs4(state->groups->aces[i].perms.allow,
586 &pace->e_perm, flags);
587 pace->e_gid = state->groups->aces[i].gid;
588 add_to_mask(state, &state->groups->aces[i].perms);
592 pace->e_tag = ACL_MASK;
593 low_mode_from_nfs4(state->mask.allow, &pace->e_perm, flags);
596 pace->e_tag = ACL_OTHER;
597 error = check_deny(state->other.deny, 0);
600 low_mode_from_nfs4(state->other.allow, &pace->e_perm, flags);
604 posix_acl_release(pacl);
605 return ERR_PTR(error);
608 static inline void allow_bits(struct posix_ace_state *astate, u32 mask)
610 /* Allow all bits in the mask not already denied: */
611 astate->allow |= mask & ~astate->deny;
614 static inline void deny_bits(struct posix_ace_state *astate, u32 mask)
616 /* Deny all bits in the mask not already allowed: */
617 astate->deny |= mask & ~astate->allow;
620 static int find_uid(struct posix_acl_state *state, kuid_t uid)
622 struct posix_ace_state_array *a = state->users;
625 for (i = 0; i < a->n; i++)
626 if (uid_eq(a->aces[i].uid, uid))
630 a->aces[i].uid = uid;
631 a->aces[i].perms.allow = state->everyone.allow;
632 a->aces[i].perms.deny = state->everyone.deny;
637 static int find_gid(struct posix_acl_state *state, kgid_t gid)
639 struct posix_ace_state_array *a = state->groups;
642 for (i = 0; i < a->n; i++)
643 if (gid_eq(a->aces[i].gid, gid))
647 a->aces[i].gid = gid;
648 a->aces[i].perms.allow = state->everyone.allow;
649 a->aces[i].perms.deny = state->everyone.deny;
654 static void deny_bits_array(struct posix_ace_state_array *a, u32 mask)
658 for (i=0; i < a->n; i++)
659 deny_bits(&a->aces[i].perms, mask);
662 static void allow_bits_array(struct posix_ace_state_array *a, u32 mask)
666 for (i=0; i < a->n; i++)
667 allow_bits(&a->aces[i].perms, mask);
670 static void process_one_v4_ace(struct posix_acl_state *state,
671 struct nfs4_ace *ace)
673 u32 mask = ace->access_mask;
678 switch (ace2type(ace)) {
680 if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
681 allow_bits(&state->owner, mask);
683 deny_bits(&state->owner, mask);
687 i = find_uid(state, ace->who_uid);
688 if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
689 allow_bits(&state->users->aces[i].perms, mask);
691 deny_bits(&state->users->aces[i].perms, mask);
692 mask = state->users->aces[i].perms.deny;
693 deny_bits(&state->owner, mask);
697 if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
698 allow_bits(&state->group, mask);
700 deny_bits(&state->group, mask);
701 mask = state->group.deny;
702 deny_bits(&state->owner, mask);
703 deny_bits(&state->everyone, mask);
704 deny_bits_array(state->users, mask);
705 deny_bits_array(state->groups, mask);
709 i = find_gid(state, ace->who_gid);
710 if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
711 allow_bits(&state->groups->aces[i].perms, mask);
713 deny_bits(&state->groups->aces[i].perms, mask);
714 mask = state->groups->aces[i].perms.deny;
715 deny_bits(&state->owner, mask);
716 deny_bits(&state->group, mask);
717 deny_bits(&state->everyone, mask);
718 deny_bits_array(state->users, mask);
719 deny_bits_array(state->groups, mask);
723 if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
724 allow_bits(&state->owner, mask);
725 allow_bits(&state->group, mask);
726 allow_bits(&state->other, mask);
727 allow_bits(&state->everyone, mask);
728 allow_bits_array(state->users, mask);
729 allow_bits_array(state->groups, mask);
731 deny_bits(&state->owner, mask);
732 deny_bits(&state->group, mask);
733 deny_bits(&state->other, mask);
734 deny_bits(&state->everyone, mask);
735 deny_bits_array(state->users, mask);
736 deny_bits_array(state->groups, mask);
741 static int nfs4_acl_nfsv4_to_posix(struct nfs4_acl *acl,
742 struct posix_acl **pacl, struct posix_acl **dpacl,
745 struct posix_acl_state effective_acl_state, default_acl_state;
746 struct nfs4_ace *ace;
749 ret = init_state(&effective_acl_state, acl->naces);
752 ret = init_state(&default_acl_state, acl->naces);
756 for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
757 if (ace->type != NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE &&
758 ace->type != NFS4_ACE_ACCESS_DENIED_ACE_TYPE)
760 if (ace->flag & ~NFS4_SUPPORTED_FLAGS)
762 if ((ace->flag & NFS4_INHERITANCE_FLAGS) == 0) {
763 process_one_v4_ace(&effective_acl_state, ace);
766 if (!(flags & NFS4_ACL_DIR))
769 * Note that when only one of FILE_INHERIT or DIRECTORY_INHERIT
770 * is set, we're effectively turning on the other. That's OK,
771 * according to rfc 3530.
773 process_one_v4_ace(&default_acl_state, ace);
775 if (!(ace->flag & NFS4_ACE_INHERIT_ONLY_ACE))
776 process_one_v4_ace(&effective_acl_state, ace);
778 *pacl = posix_state_to_acl(&effective_acl_state, flags);
780 ret = PTR_ERR(*pacl);
784 *dpacl = posix_state_to_acl(&default_acl_state,
785 flags | NFS4_ACL_TYPE_DEFAULT);
786 if (IS_ERR(*dpacl)) {
787 ret = PTR_ERR(*dpacl);
789 posix_acl_release(*pacl);
797 free_state(&default_acl_state);
799 free_state(&effective_acl_state);
804 nfsd4_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
805 struct nfs4_acl *acl)
809 struct dentry *dentry;
811 struct posix_acl *pacl = NULL, *dpacl = NULL;
812 unsigned int flags = 0;
815 error = fh_verify(rqstp, fhp, 0, NFSD_MAY_SATTR);
819 dentry = fhp->fh_dentry;
820 inode = dentry->d_inode;
822 if (!inode->i_op->set_acl || !IS_POSIXACL(inode))
823 return nfserr_attrnotsupp;
825 if (S_ISDIR(inode->i_mode))
826 flags = NFS4_ACL_DIR;
828 host_error = nfs4_acl_nfsv4_to_posix(acl, &pacl, &dpacl, flags);
829 if (host_error == -EINVAL)
830 return nfserr_attrnotsupp;
834 host_error = inode->i_op->set_acl(inode, pacl, ACL_TYPE_ACCESS);
838 if (S_ISDIR(inode->i_mode)) {
839 host_error = inode->i_op->set_acl(inode, dpacl,
844 posix_acl_release(pacl);
845 posix_acl_release(dpacl);
847 if (host_error == -EOPNOTSUPP)
848 return nfserr_attrnotsupp;
850 return nfserrno(host_error);
855 ace2type(struct nfs4_ace *ace)
857 switch (ace->whotype) {
858 case NFS4_ACL_WHO_NAMED:
859 return (ace->flag & NFS4_ACE_IDENTIFIER_GROUP ?
860 ACL_GROUP : ACL_USER);
861 case NFS4_ACL_WHO_OWNER:
863 case NFS4_ACL_WHO_GROUP:
864 return ACL_GROUP_OBJ;
865 case NFS4_ACL_WHO_EVERYONE:
875 struct nfs4_acl *acl;
877 acl = kmalloc(sizeof(*acl) + n*sizeof(struct nfs4_ace), GFP_KERNEL);
891 .stringlen = sizeof("OWNER@") - 1,
892 .type = NFS4_ACL_WHO_OWNER,
896 .stringlen = sizeof("GROUP@") - 1,
897 .type = NFS4_ACL_WHO_GROUP,
900 .string = "EVERYONE@",
901 .stringlen = sizeof("EVERYONE@") - 1,
902 .type = NFS4_ACL_WHO_EVERYONE,
907 nfs4_acl_get_whotype(char *p, u32 len)
911 for (i = 0; i < ARRAY_SIZE(s2t_map); i++) {
912 if (s2t_map[i].stringlen == len &&
913 0 == memcmp(s2t_map[i].string, p, len))
914 return s2t_map[i].type;
916 return NFS4_ACL_WHO_NAMED;
920 nfs4_acl_write_who(int who, char *p)
924 for (i = 0; i < ARRAY_SIZE(s2t_map); i++) {
925 if (s2t_map[i].type == who) {
926 memcpy(p, s2t_map[i].string, s2t_map[i].stringlen);
927 return s2t_map[i].stringlen;