4 * Common NFSv4 ACL handling code.
6 * Copyright (c) 2002, 2003 The Regents of the University of Michigan.
9 * Marius Aamodt Eriksen <marius@umich.edu>
10 * Jeff Sedlak <jsedlak@umich.edu>
11 * J. Bruce Fields <bfields@umich.edu>
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the University nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
33 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <linux/string.h>
40 #include <linux/slab.h>
41 #include <linux/list.h>
42 #include <linux/types.h>
44 #include <linux/module.h>
45 #include <linux/nfs_fs.h>
46 #include <linux/posix_acl.h>
47 #include <linux/nfs4.h>
48 #include <linux/nfs4_acl.h>
51 /* mode bit translations: */
52 #define NFS4_READ_MODE (NFS4_ACE_READ_DATA)
53 #define NFS4_WRITE_MODE (NFS4_ACE_WRITE_DATA | NFS4_ACE_APPEND_DATA)
54 #define NFS4_EXECUTE_MODE NFS4_ACE_EXECUTE
55 #define NFS4_ANYONE_MODE (NFS4_ACE_READ_ATTRIBUTES | NFS4_ACE_READ_ACL | NFS4_ACE_SYNCHRONIZE)
56 #define NFS4_OWNER_MODE (NFS4_ACE_WRITE_ATTRIBUTES | NFS4_ACE_WRITE_ACL)
58 /* We don't support these bits; insist they be neither allowed nor denied */
59 #define NFS4_MASK_UNSUPP (NFS4_ACE_DELETE | NFS4_ACE_WRITE_OWNER \
60 | NFS4_ACE_READ_NAMED_ATTRS | NFS4_ACE_WRITE_NAMED_ATTRS)
62 /* flags used to simulate posix default ACLs */
63 #define NFS4_INHERITANCE_FLAGS (NFS4_ACE_FILE_INHERIT_ACE \
64 | NFS4_ACE_DIRECTORY_INHERIT_ACE)
66 #define NFS4_SUPPORTED_FLAGS (NFS4_INHERITANCE_FLAGS \
67 | NFS4_ACE_INHERIT_ONLY_ACE \
68 | NFS4_ACE_IDENTIFIER_GROUP)
70 #define MASK_EQUAL(mask1, mask2) \
71 ( ((mask1) & NFS4_ACE_MASK_ALL) == ((mask2) & NFS4_ACE_MASK_ALL) )
74 mask_from_posix(unsigned short perm
, unsigned int flags
)
76 int mask
= NFS4_ANYONE_MODE
;
78 if (flags
& NFS4_ACL_OWNER
)
79 mask
|= NFS4_OWNER_MODE
;
81 mask
|= NFS4_READ_MODE
;
83 mask
|= NFS4_WRITE_MODE
;
84 if ((perm
& ACL_WRITE
) && (flags
& NFS4_ACL_DIR
))
85 mask
|= NFS4_ACE_DELETE_CHILD
;
86 if (perm
& ACL_EXECUTE
)
87 mask
|= NFS4_EXECUTE_MODE
;
92 deny_mask_from_posix(unsigned short perm
, u32 flags
)
97 mask
|= NFS4_READ_MODE
;
99 mask
|= NFS4_WRITE_MODE
;
100 if ((perm
& ACL_WRITE
) && (flags
& NFS4_ACL_DIR
))
101 mask
|= NFS4_ACE_DELETE_CHILD
;
102 if (perm
& ACL_EXECUTE
)
103 mask
|= NFS4_EXECUTE_MODE
;
107 /* XXX: modify functions to return NFS errors; they're only ever
108 * used by nfs code, after all.... */
110 /* We only map from NFSv4 to POSIX ACLs when setting ACLs, when we err on the
111 * side of being more restrictive, so the mode bit mapping below is
112 * pessimistic. An optimistic version would be needed to handle DENY's,
113 * but we espect to coalesce all ALLOWs and DENYs before mapping to mode
117 low_mode_from_nfs4(u32 perm
, unsigned short *mode
, unsigned int flags
)
119 u32 write_mode
= NFS4_WRITE_MODE
;
121 if (flags
& NFS4_ACL_DIR
)
122 write_mode
|= NFS4_ACE_DELETE_CHILD
;
124 if ((perm
& NFS4_READ_MODE
) == NFS4_READ_MODE
)
126 if ((perm
& write_mode
) == write_mode
)
128 if ((perm
& NFS4_EXECUTE_MODE
) == NFS4_EXECUTE_MODE
)
129 *mode
|= ACL_EXECUTE
;
132 struct ace_container
{
133 struct nfs4_ace
*ace
;
134 struct list_head ace_l
;
137 static short ace2type(struct nfs4_ace
*);
138 static void _posix_to_nfsv4_one(struct posix_acl
*, struct nfs4_acl
*,
142 nfs4_acl_posix_to_nfsv4(struct posix_acl
*pacl
, struct posix_acl
*dpacl
,
145 struct nfs4_acl
*acl
;
149 if (posix_acl_valid(pacl
) < 0)
150 return ERR_PTR(-EINVAL
);
151 size
+= 2*pacl
->a_count
;
154 if (posix_acl_valid(dpacl
) < 0)
155 return ERR_PTR(-EINVAL
);
156 size
+= 2*dpacl
->a_count
;
159 /* Allocate for worst case: one (deny, allow) pair each: */
160 acl
= nfs4_acl_new(size
);
162 return ERR_PTR(-ENOMEM
);
165 _posix_to_nfsv4_one(pacl
, acl
, flags
& ~NFS4_ACL_TYPE_DEFAULT
);
168 _posix_to_nfsv4_one(dpacl
, acl
, flags
| NFS4_ACL_TYPE_DEFAULT
);
173 struct posix_acl_summary
{
174 unsigned short owner
;
175 unsigned short users
;
176 unsigned short group
;
177 unsigned short groups
;
178 unsigned short other
;
183 summarize_posix_acl(struct posix_acl
*acl
, struct posix_acl_summary
*pas
)
185 struct posix_acl_entry
*pa
, *pe
;
190 pe
= acl
->a_entries
+ acl
->a_count
;
192 FOREACH_ACL_ENTRY(pa
, acl
, pe
) {
195 pas
->owner
= pa
->e_perm
;
198 pas
->group
= pa
->e_perm
;
201 pas
->users
|= pa
->e_perm
;
204 pas
->groups
|= pa
->e_perm
;
207 pas
->other
= pa
->e_perm
;
210 pas
->mask
= pa
->e_perm
;
214 /* We'll only care about effective permissions: */
215 pas
->users
&= pas
->mask
;
216 pas
->group
&= pas
->mask
;
217 pas
->groups
&= pas
->mask
;
220 /* We assume the acl has been verified with posix_acl_valid. */
222 _posix_to_nfsv4_one(struct posix_acl
*pacl
, struct nfs4_acl
*acl
,
225 struct posix_acl_entry
*pa
, *group_owner_entry
;
226 struct nfs4_ace
*ace
;
227 struct posix_acl_summary pas
;
229 int eflag
= ((flags
& NFS4_ACL_TYPE_DEFAULT
) ?
230 NFS4_INHERITANCE_FLAGS
| NFS4_ACE_INHERIT_ONLY_ACE
: 0);
232 BUG_ON(pacl
->a_count
< 3);
233 summarize_posix_acl(pacl
, &pas
);
235 pa
= pacl
->a_entries
;
236 ace
= acl
->aces
+ acl
->naces
;
238 /* We could deny everything not granted by the owner: */
241 * but it is equivalent (and simpler) to deny only what is not
242 * granted by later entries:
244 deny
&= pas
.users
| pas
.group
| pas
.groups
| pas
.other
;
246 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
248 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
249 ace
->whotype
= NFS4_ACL_WHO_OWNER
;
254 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
256 ace
->access_mask
= mask_from_posix(pa
->e_perm
, flags
| NFS4_ACL_OWNER
);
257 ace
->whotype
= NFS4_ACL_WHO_OWNER
;
262 while (pa
->e_tag
== ACL_USER
) {
263 deny
= ~(pa
->e_perm
& pas
.mask
);
264 deny
&= pas
.groups
| pas
.group
| pas
.other
;
266 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
268 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
269 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
274 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
276 ace
->access_mask
= mask_from_posix(pa
->e_perm
& pas
.mask
,
278 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
285 /* In the case of groups, we apply allow ACEs first, then deny ACEs,
286 * since a user can be in more than one group. */
290 group_owner_entry
= pa
;
292 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
294 ace
->access_mask
= mask_from_posix(pas
.group
, flags
);
295 ace
->whotype
= NFS4_ACL_WHO_GROUP
;
300 while (pa
->e_tag
== ACL_GROUP
) {
301 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
302 ace
->flag
= eflag
| NFS4_ACE_IDENTIFIER_GROUP
;
303 ace
->access_mask
= mask_from_posix(pa
->e_perm
& pas
.mask
,
305 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
314 pa
= group_owner_entry
;
316 deny
= ~pas
.group
& pas
.other
;
318 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
319 ace
->flag
= eflag
| NFS4_ACE_IDENTIFIER_GROUP
;
320 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
321 ace
->whotype
= NFS4_ACL_WHO_GROUP
;
327 while (pa
->e_tag
== ACL_GROUP
) {
328 deny
= ~(pa
->e_perm
& pas
.mask
);
331 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
332 ace
->flag
= eflag
| NFS4_ACE_IDENTIFIER_GROUP
;
333 ace
->access_mask
= mask_from_posix(deny
, flags
);
334 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
342 if (pa
->e_tag
== ACL_MASK
)
344 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
346 ace
->access_mask
= mask_from_posix(pa
->e_perm
, flags
);
347 ace
->whotype
= NFS4_ACL_WHO_EVERYONE
;
352 sort_pacl_range(struct posix_acl
*pacl
, int start
, int end
) {
354 struct posix_acl_entry tmp
;
356 /* We just do a bubble sort; easy to do in place, and we're not
357 * expecting acl's to be long enough to justify anything more. */
360 for (i
= start
; i
< end
; i
++) {
361 if (pacl
->a_entries
[i
].e_id
362 > pacl
->a_entries
[i
+1].e_id
) {
364 tmp
= pacl
->a_entries
[i
];
365 pacl
->a_entries
[i
] = pacl
->a_entries
[i
+1];
366 pacl
->a_entries
[i
+1] = tmp
;
373 sort_pacl(struct posix_acl
*pacl
)
375 /* posix_acl_valid requires that users and groups be in order
379 if (pacl
->a_count
<= 4)
380 return; /* no users or groups */
382 while (pacl
->a_entries
[i
].e_tag
== ACL_USER
)
384 sort_pacl_range(pacl
, 1, i
-1);
386 BUG_ON(pacl
->a_entries
[i
].e_tag
!= ACL_GROUP_OBJ
);
388 while (pacl
->a_entries
[j
].e_tag
== ACL_GROUP
)
390 sort_pacl_range(pacl
, i
, j
-1);
395 * While processing the NFSv4 ACE, this maintains bitmasks representing
396 * which permission bits have been allowed and which denied to a given
398 struct posix_ace_state
{
403 struct posix_user_ace_state
{
405 struct posix_ace_state perms
;
408 struct posix_ace_state_array
{
410 struct posix_user_ace_state aces
[];
414 * While processing the NFSv4 ACE, this maintains the partial permissions
415 * calculated so far: */
417 struct posix_acl_state
{
419 struct posix_ace_state owner
;
420 struct posix_ace_state group
;
421 struct posix_ace_state other
;
422 struct posix_ace_state everyone
;
423 struct posix_ace_state mask
; /* Deny unused in this case */
424 struct posix_ace_state_array
*users
;
425 struct posix_ace_state_array
*groups
;
429 init_state(struct posix_acl_state
*state
, int cnt
)
433 memset(state
, 0, sizeof(struct posix_acl_state
));
436 * In the worst case, each individual acl could be for a distinct
437 * named user or group, but we don't no which, so we allocate
438 * enough space for either:
440 alloc
= sizeof(struct posix_ace_state_array
)
441 + cnt
*sizeof(struct posix_ace_state
);
442 state
->users
= kzalloc(alloc
, GFP_KERNEL
);
445 state
->groups
= kzalloc(alloc
, GFP_KERNEL
);
446 if (!state
->groups
) {
454 free_state(struct posix_acl_state
*state
) {
456 kfree(state
->groups
);
459 static inline void add_to_mask(struct posix_acl_state
*state
, struct posix_ace_state
*astate
)
461 state
->mask
.allow
|= astate
->allow
;
465 * Certain bits (SYNCHRONIZE, DELETE, WRITE_OWNER, READ/WRITE_NAMED_ATTRS,
466 * READ_ATTRIBUTES, READ_ACL) are currently unenforceable and don't translate
467 * to traditional read/write/execute permissions.
469 * It's problematic to reject acls that use certain mode bits, because it
470 * places the burden on users to learn the rules about which bits one
471 * particular server sets, without giving the user a lot of help--we return an
472 * error that could mean any number of different things. To make matters
473 * worse, the problematic bits might be introduced by some application that's
474 * automatically mapping from some other acl model.
476 * So wherever possible we accept anything, possibly erring on the side of
477 * denying more permissions than necessary.
479 * However we do reject *explicit* DENY's of a few bits representing
480 * permissions we could never deny:
483 static inline int check_deny(u32 mask
, int isowner
)
485 if (mask
& (NFS4_ACE_READ_ATTRIBUTES
| NFS4_ACE_READ_ACL
))
489 if (mask
& (NFS4_ACE_WRITE_ATTRIBUTES
| NFS4_ACE_WRITE_ACL
))
494 static struct posix_acl
*
495 posix_state_to_acl(struct posix_acl_state
*state
, unsigned int flags
)
497 struct posix_acl_entry
*pace
;
498 struct posix_acl
*pacl
;
503 * ACLs with no ACEs are treated differently in the inheritable
504 * and effective cases: when there are no inheritable ACEs, we
505 * set a zero-length default posix acl:
507 if (state
->empty
&& (flags
& NFS4_ACL_TYPE_DEFAULT
)) {
508 pacl
= posix_acl_alloc(0, GFP_KERNEL
);
509 return pacl
? pacl
: ERR_PTR(-ENOMEM
);
512 * When there are no effective ACEs, the following will end
513 * up setting a 3-element effective posix ACL with all
516 nace
= 4 + state
->users
->n
+ state
->groups
->n
;
517 pacl
= posix_acl_alloc(nace
, GFP_KERNEL
);
519 return ERR_PTR(-ENOMEM
);
521 pace
= pacl
->a_entries
;
522 pace
->e_tag
= ACL_USER_OBJ
;
523 error
= check_deny(state
->owner
.deny
, 1);
526 low_mode_from_nfs4(state
->owner
.allow
, &pace
->e_perm
, flags
);
527 pace
->e_id
= ACL_UNDEFINED_ID
;
529 for (i
=0; i
< state
->users
->n
; i
++) {
531 pace
->e_tag
= ACL_USER
;
532 error
= check_deny(state
->users
->aces
[i
].perms
.deny
, 0);
535 low_mode_from_nfs4(state
->users
->aces
[i
].perms
.allow
,
536 &pace
->e_perm
, flags
);
537 pace
->e_id
= state
->users
->aces
[i
].uid
;
538 add_to_mask(state
, &state
->users
->aces
[i
].perms
);
542 pace
->e_tag
= ACL_GROUP_OBJ
;
543 error
= check_deny(state
->group
.deny
, 0);
546 low_mode_from_nfs4(state
->group
.allow
, &pace
->e_perm
, flags
);
547 pace
->e_id
= ACL_UNDEFINED_ID
;
548 add_to_mask(state
, &state
->group
);
550 for (i
=0; i
< state
->groups
->n
; i
++) {
552 pace
->e_tag
= ACL_GROUP
;
553 error
= check_deny(state
->groups
->aces
[i
].perms
.deny
, 0);
556 low_mode_from_nfs4(state
->groups
->aces
[i
].perms
.allow
,
557 &pace
->e_perm
, flags
);
558 pace
->e_id
= state
->groups
->aces
[i
].uid
;
559 add_to_mask(state
, &state
->groups
->aces
[i
].perms
);
563 pace
->e_tag
= ACL_MASK
;
564 low_mode_from_nfs4(state
->mask
.allow
, &pace
->e_perm
, flags
);
565 pace
->e_id
= ACL_UNDEFINED_ID
;
568 pace
->e_tag
= ACL_OTHER
;
569 error
= check_deny(state
->other
.deny
, 0);
572 low_mode_from_nfs4(state
->other
.allow
, &pace
->e_perm
, flags
);
573 pace
->e_id
= ACL_UNDEFINED_ID
;
577 posix_acl_release(pacl
);
578 return ERR_PTR(error
);
581 static inline void allow_bits(struct posix_ace_state
*astate
, u32 mask
)
583 /* Allow all bits in the mask not already denied: */
584 astate
->allow
|= mask
& ~astate
->deny
;
587 static inline void deny_bits(struct posix_ace_state
*astate
, u32 mask
)
589 /* Deny all bits in the mask not already allowed: */
590 astate
->deny
|= mask
& ~astate
->allow
;
593 static int find_uid(struct posix_acl_state
*state
, struct posix_ace_state_array
*a
, uid_t uid
)
597 for (i
= 0; i
< a
->n
; i
++)
598 if (a
->aces
[i
].uid
== uid
)
602 a
->aces
[i
].uid
= uid
;
603 a
->aces
[i
].perms
.allow
= state
->everyone
.allow
;
604 a
->aces
[i
].perms
.deny
= state
->everyone
.deny
;
609 static void deny_bits_array(struct posix_ace_state_array
*a
, u32 mask
)
613 for (i
=0; i
< a
->n
; i
++)
614 deny_bits(&a
->aces
[i
].perms
, mask
);
617 static void allow_bits_array(struct posix_ace_state_array
*a
, u32 mask
)
621 for (i
=0; i
< a
->n
; i
++)
622 allow_bits(&a
->aces
[i
].perms
, mask
);
625 static void process_one_v4_ace(struct posix_acl_state
*state
,
626 struct nfs4_ace
*ace
)
628 u32 mask
= ace
->access_mask
;
633 switch (ace2type(ace
)) {
635 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
636 allow_bits(&state
->owner
, mask
);
638 deny_bits(&state
->owner
, mask
);
642 i
= find_uid(state
, state
->users
, ace
->who
);
643 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
644 allow_bits(&state
->users
->aces
[i
].perms
, mask
);
646 deny_bits(&state
->users
->aces
[i
].perms
, mask
);
647 mask
= state
->users
->aces
[i
].perms
.deny
;
648 deny_bits(&state
->owner
, mask
);
652 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
653 allow_bits(&state
->group
, mask
);
655 deny_bits(&state
->group
, mask
);
656 mask
= state
->group
.deny
;
657 deny_bits(&state
->owner
, mask
);
658 deny_bits(&state
->everyone
, mask
);
659 deny_bits_array(state
->users
, mask
);
660 deny_bits_array(state
->groups
, mask
);
664 i
= find_uid(state
, state
->groups
, ace
->who
);
665 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
666 allow_bits(&state
->groups
->aces
[i
].perms
, mask
);
668 deny_bits(&state
->groups
->aces
[i
].perms
, mask
);
669 mask
= state
->groups
->aces
[i
].perms
.deny
;
670 deny_bits(&state
->owner
, mask
);
671 deny_bits(&state
->group
, mask
);
672 deny_bits(&state
->everyone
, mask
);
673 deny_bits_array(state
->users
, mask
);
674 deny_bits_array(state
->groups
, mask
);
678 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
679 allow_bits(&state
->owner
, mask
);
680 allow_bits(&state
->group
, mask
);
681 allow_bits(&state
->other
, mask
);
682 allow_bits(&state
->everyone
, mask
);
683 allow_bits_array(state
->users
, mask
);
684 allow_bits_array(state
->groups
, mask
);
686 deny_bits(&state
->owner
, mask
);
687 deny_bits(&state
->group
, mask
);
688 deny_bits(&state
->other
, mask
);
689 deny_bits(&state
->everyone
, mask
);
690 deny_bits_array(state
->users
, mask
);
691 deny_bits_array(state
->groups
, mask
);
696 int nfs4_acl_nfsv4_to_posix(struct nfs4_acl
*acl
, struct posix_acl
**pacl
,
697 struct posix_acl
**dpacl
, unsigned int flags
)
699 struct posix_acl_state effective_acl_state
, default_acl_state
;
700 struct nfs4_ace
*ace
;
703 ret
= init_state(&effective_acl_state
, acl
->naces
);
706 ret
= init_state(&default_acl_state
, acl
->naces
);
710 for (ace
= acl
->aces
; ace
< acl
->aces
+ acl
->naces
; ace
++) {
711 if (ace
->type
!= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
&&
712 ace
->type
!= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
)
714 if (ace
->flag
& ~NFS4_SUPPORTED_FLAGS
)
716 if ((ace
->flag
& NFS4_INHERITANCE_FLAGS
) == 0) {
717 process_one_v4_ace(&effective_acl_state
, ace
);
720 if (!(flags
& NFS4_ACL_DIR
))
723 * Note that when only one of FILE_INHERIT or DIRECTORY_INHERIT
724 * is set, we're effectively turning on the other. That's OK,
725 * according to rfc 3530.
727 process_one_v4_ace(&default_acl_state
, ace
);
729 if (!(ace
->flag
& NFS4_ACE_INHERIT_ONLY_ACE
))
730 process_one_v4_ace(&effective_acl_state
, ace
);
732 *pacl
= posix_state_to_acl(&effective_acl_state
, flags
);
734 ret
= PTR_ERR(*pacl
);
737 *dpacl
= posix_state_to_acl(&default_acl_state
,
738 flags
| NFS4_ACL_TYPE_DEFAULT
);
739 if (IS_ERR(*dpacl
)) {
740 ret
= PTR_ERR(*dpacl
);
741 posix_acl_release(*pacl
);
748 free_state(&default_acl_state
);
750 free_state(&effective_acl_state
);
755 ace2type(struct nfs4_ace
*ace
)
757 switch (ace
->whotype
) {
758 case NFS4_ACL_WHO_NAMED
:
759 return (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
?
760 ACL_GROUP
: ACL_USER
);
761 case NFS4_ACL_WHO_OWNER
:
763 case NFS4_ACL_WHO_GROUP
:
764 return ACL_GROUP_OBJ
;
765 case NFS4_ACL_WHO_EVERYONE
:
772 EXPORT_SYMBOL(nfs4_acl_posix_to_nfsv4
);
773 EXPORT_SYMBOL(nfs4_acl_nfsv4_to_posix
);
778 struct nfs4_acl
*acl
;
780 acl
= kmalloc(sizeof(*acl
) + n
*sizeof(struct nfs4_ace
), GFP_KERNEL
);
794 .stringlen
= sizeof("OWNER@") - 1,
795 .type
= NFS4_ACL_WHO_OWNER
,
799 .stringlen
= sizeof("GROUP@") - 1,
800 .type
= NFS4_ACL_WHO_GROUP
,
803 .string
= "EVERYONE@",
804 .stringlen
= sizeof("EVERYONE@") - 1,
805 .type
= NFS4_ACL_WHO_EVERYONE
,
810 nfs4_acl_get_whotype(char *p
, u32 len
)
814 for (i
= 0; i
< ARRAY_SIZE(s2t_map
); i
++) {
815 if (s2t_map
[i
].stringlen
== len
&&
816 0 == memcmp(s2t_map
[i
].string
, p
, len
))
817 return s2t_map
[i
].type
;
819 return NFS4_ACL_WHO_NAMED
;
823 nfs4_acl_write_who(int who
, char *p
)
827 for (i
= 0; i
< ARRAY_SIZE(s2t_map
); i
++) {
828 if (s2t_map
[i
].type
== who
) {
829 memcpy(p
, s2t_map
[i
].string
, s2t_map
[i
].stringlen
);
830 return s2t_map
[i
].stringlen
;
837 EXPORT_SYMBOL(nfs4_acl_new
);
838 EXPORT_SYMBOL(nfs4_acl_get_whotype
);
839 EXPORT_SYMBOL(nfs4_acl_write_who
);