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
;
188 * Only pas.users and pas.groups need initialization; previous
189 * posix_acl_valid() calls ensure that the other fields will be
190 * initialized in the following loop. But, just to placate gcc:
192 memset(pas
, 0, sizeof(*pas
));
195 pe
= acl
->a_entries
+ acl
->a_count
;
197 FOREACH_ACL_ENTRY(pa
, acl
, pe
) {
200 pas
->owner
= pa
->e_perm
;
203 pas
->group
= pa
->e_perm
;
206 pas
->users
|= pa
->e_perm
;
209 pas
->groups
|= pa
->e_perm
;
212 pas
->other
= pa
->e_perm
;
215 pas
->mask
= pa
->e_perm
;
219 /* We'll only care about effective permissions: */
220 pas
->users
&= pas
->mask
;
221 pas
->group
&= pas
->mask
;
222 pas
->groups
&= pas
->mask
;
225 /* We assume the acl has been verified with posix_acl_valid. */
227 _posix_to_nfsv4_one(struct posix_acl
*pacl
, struct nfs4_acl
*acl
,
230 struct posix_acl_entry
*pa
, *group_owner_entry
;
231 struct nfs4_ace
*ace
;
232 struct posix_acl_summary pas
;
234 int eflag
= ((flags
& NFS4_ACL_TYPE_DEFAULT
) ?
235 NFS4_INHERITANCE_FLAGS
| NFS4_ACE_INHERIT_ONLY_ACE
: 0);
237 BUG_ON(pacl
->a_count
< 3);
238 summarize_posix_acl(pacl
, &pas
);
240 pa
= pacl
->a_entries
;
241 ace
= acl
->aces
+ acl
->naces
;
243 /* We could deny everything not granted by the owner: */
246 * but it is equivalent (and simpler) to deny only what is not
247 * granted by later entries:
249 deny
&= pas
.users
| pas
.group
| pas
.groups
| pas
.other
;
251 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
253 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
254 ace
->whotype
= NFS4_ACL_WHO_OWNER
;
259 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
261 ace
->access_mask
= mask_from_posix(pa
->e_perm
, flags
| NFS4_ACL_OWNER
);
262 ace
->whotype
= NFS4_ACL_WHO_OWNER
;
267 while (pa
->e_tag
== ACL_USER
) {
268 deny
= ~(pa
->e_perm
& pas
.mask
);
269 deny
&= pas
.groups
| pas
.group
| pas
.other
;
271 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
273 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
274 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
279 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
281 ace
->access_mask
= mask_from_posix(pa
->e_perm
& pas
.mask
,
283 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
290 /* In the case of groups, we apply allow ACEs first, then deny ACEs,
291 * since a user can be in more than one group. */
295 group_owner_entry
= pa
;
297 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
299 ace
->access_mask
= mask_from_posix(pas
.group
, flags
);
300 ace
->whotype
= NFS4_ACL_WHO_GROUP
;
305 while (pa
->e_tag
== ACL_GROUP
) {
306 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
307 ace
->flag
= eflag
| NFS4_ACE_IDENTIFIER_GROUP
;
308 ace
->access_mask
= mask_from_posix(pa
->e_perm
& pas
.mask
,
310 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
319 pa
= group_owner_entry
;
321 deny
= ~pas
.group
& pas
.other
;
323 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
324 ace
->flag
= eflag
| NFS4_ACE_IDENTIFIER_GROUP
;
325 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
326 ace
->whotype
= NFS4_ACL_WHO_GROUP
;
332 while (pa
->e_tag
== ACL_GROUP
) {
333 deny
= ~(pa
->e_perm
& pas
.mask
);
336 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
337 ace
->flag
= eflag
| NFS4_ACE_IDENTIFIER_GROUP
;
338 ace
->access_mask
= mask_from_posix(deny
, flags
);
339 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
347 if (pa
->e_tag
== ACL_MASK
)
349 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
351 ace
->access_mask
= mask_from_posix(pa
->e_perm
, flags
);
352 ace
->whotype
= NFS4_ACL_WHO_EVERYONE
;
357 sort_pacl_range(struct posix_acl
*pacl
, int start
, int end
) {
359 struct posix_acl_entry tmp
;
361 /* We just do a bubble sort; easy to do in place, and we're not
362 * expecting acl's to be long enough to justify anything more. */
365 for (i
= start
; i
< end
; i
++) {
366 if (pacl
->a_entries
[i
].e_id
367 > pacl
->a_entries
[i
+1].e_id
) {
369 tmp
= pacl
->a_entries
[i
];
370 pacl
->a_entries
[i
] = pacl
->a_entries
[i
+1];
371 pacl
->a_entries
[i
+1] = tmp
;
378 sort_pacl(struct posix_acl
*pacl
)
380 /* posix_acl_valid requires that users and groups be in order
384 if (pacl
->a_count
<= 4)
385 return; /* no users or groups */
387 while (pacl
->a_entries
[i
].e_tag
== ACL_USER
)
389 sort_pacl_range(pacl
, 1, i
-1);
391 BUG_ON(pacl
->a_entries
[i
].e_tag
!= ACL_GROUP_OBJ
);
393 while (pacl
->a_entries
[j
].e_tag
== ACL_GROUP
)
395 sort_pacl_range(pacl
, i
, j
-1);
400 * While processing the NFSv4 ACE, this maintains bitmasks representing
401 * which permission bits have been allowed and which denied to a given
403 struct posix_ace_state
{
408 struct posix_user_ace_state
{
410 struct posix_ace_state perms
;
413 struct posix_ace_state_array
{
415 struct posix_user_ace_state aces
[];
419 * While processing the NFSv4 ACE, this maintains the partial permissions
420 * calculated so far: */
422 struct posix_acl_state
{
424 struct posix_ace_state owner
;
425 struct posix_ace_state group
;
426 struct posix_ace_state other
;
427 struct posix_ace_state everyone
;
428 struct posix_ace_state mask
; /* Deny unused in this case */
429 struct posix_ace_state_array
*users
;
430 struct posix_ace_state_array
*groups
;
434 init_state(struct posix_acl_state
*state
, int cnt
)
438 memset(state
, 0, sizeof(struct posix_acl_state
));
441 * In the worst case, each individual acl could be for a distinct
442 * named user or group, but we don't no which, so we allocate
443 * enough space for either:
445 alloc
= sizeof(struct posix_ace_state_array
)
446 + cnt
*sizeof(struct posix_ace_state
);
447 state
->users
= kzalloc(alloc
, GFP_KERNEL
);
450 state
->groups
= kzalloc(alloc
, GFP_KERNEL
);
451 if (!state
->groups
) {
459 free_state(struct posix_acl_state
*state
) {
461 kfree(state
->groups
);
464 static inline void add_to_mask(struct posix_acl_state
*state
, struct posix_ace_state
*astate
)
466 state
->mask
.allow
|= astate
->allow
;
470 * Certain bits (SYNCHRONIZE, DELETE, WRITE_OWNER, READ/WRITE_NAMED_ATTRS,
471 * READ_ATTRIBUTES, READ_ACL) are currently unenforceable and don't translate
472 * to traditional read/write/execute permissions.
474 * It's problematic to reject acls that use certain mode bits, because it
475 * places the burden on users to learn the rules about which bits one
476 * particular server sets, without giving the user a lot of help--we return an
477 * error that could mean any number of different things. To make matters
478 * worse, the problematic bits might be introduced by some application that's
479 * automatically mapping from some other acl model.
481 * So wherever possible we accept anything, possibly erring on the side of
482 * denying more permissions than necessary.
484 * However we do reject *explicit* DENY's of a few bits representing
485 * permissions we could never deny:
488 static inline int check_deny(u32 mask
, int isowner
)
490 if (mask
& (NFS4_ACE_READ_ATTRIBUTES
| NFS4_ACE_READ_ACL
))
494 if (mask
& (NFS4_ACE_WRITE_ATTRIBUTES
| NFS4_ACE_WRITE_ACL
))
499 static struct posix_acl
*
500 posix_state_to_acl(struct posix_acl_state
*state
, unsigned int flags
)
502 struct posix_acl_entry
*pace
;
503 struct posix_acl
*pacl
;
508 * ACLs with no ACEs are treated differently in the inheritable
509 * and effective cases: when there are no inheritable ACEs, we
510 * set a zero-length default posix acl:
512 if (state
->empty
&& (flags
& NFS4_ACL_TYPE_DEFAULT
)) {
513 pacl
= posix_acl_alloc(0, GFP_KERNEL
);
514 return pacl
? pacl
: ERR_PTR(-ENOMEM
);
517 * When there are no effective ACEs, the following will end
518 * up setting a 3-element effective posix ACL with all
521 nace
= 4 + state
->users
->n
+ state
->groups
->n
;
522 pacl
= posix_acl_alloc(nace
, GFP_KERNEL
);
524 return ERR_PTR(-ENOMEM
);
526 pace
= pacl
->a_entries
;
527 pace
->e_tag
= ACL_USER_OBJ
;
528 error
= check_deny(state
->owner
.deny
, 1);
531 low_mode_from_nfs4(state
->owner
.allow
, &pace
->e_perm
, flags
);
532 pace
->e_id
= ACL_UNDEFINED_ID
;
534 for (i
=0; i
< state
->users
->n
; i
++) {
536 pace
->e_tag
= ACL_USER
;
537 error
= check_deny(state
->users
->aces
[i
].perms
.deny
, 0);
540 low_mode_from_nfs4(state
->users
->aces
[i
].perms
.allow
,
541 &pace
->e_perm
, flags
);
542 pace
->e_id
= state
->users
->aces
[i
].uid
;
543 add_to_mask(state
, &state
->users
->aces
[i
].perms
);
547 pace
->e_tag
= ACL_GROUP_OBJ
;
548 error
= check_deny(state
->group
.deny
, 0);
551 low_mode_from_nfs4(state
->group
.allow
, &pace
->e_perm
, flags
);
552 pace
->e_id
= ACL_UNDEFINED_ID
;
553 add_to_mask(state
, &state
->group
);
555 for (i
=0; i
< state
->groups
->n
; i
++) {
557 pace
->e_tag
= ACL_GROUP
;
558 error
= check_deny(state
->groups
->aces
[i
].perms
.deny
, 0);
561 low_mode_from_nfs4(state
->groups
->aces
[i
].perms
.allow
,
562 &pace
->e_perm
, flags
);
563 pace
->e_id
= state
->groups
->aces
[i
].uid
;
564 add_to_mask(state
, &state
->groups
->aces
[i
].perms
);
568 pace
->e_tag
= ACL_MASK
;
569 low_mode_from_nfs4(state
->mask
.allow
, &pace
->e_perm
, flags
);
570 pace
->e_id
= ACL_UNDEFINED_ID
;
573 pace
->e_tag
= ACL_OTHER
;
574 error
= check_deny(state
->other
.deny
, 0);
577 low_mode_from_nfs4(state
->other
.allow
, &pace
->e_perm
, flags
);
578 pace
->e_id
= ACL_UNDEFINED_ID
;
582 posix_acl_release(pacl
);
583 return ERR_PTR(error
);
586 static inline void allow_bits(struct posix_ace_state
*astate
, u32 mask
)
588 /* Allow all bits in the mask not already denied: */
589 astate
->allow
|= mask
& ~astate
->deny
;
592 static inline void deny_bits(struct posix_ace_state
*astate
, u32 mask
)
594 /* Deny all bits in the mask not already allowed: */
595 astate
->deny
|= mask
& ~astate
->allow
;
598 static int find_uid(struct posix_acl_state
*state
, struct posix_ace_state_array
*a
, uid_t uid
)
602 for (i
= 0; i
< a
->n
; i
++)
603 if (a
->aces
[i
].uid
== uid
)
607 a
->aces
[i
].uid
= uid
;
608 a
->aces
[i
].perms
.allow
= state
->everyone
.allow
;
609 a
->aces
[i
].perms
.deny
= state
->everyone
.deny
;
614 static void deny_bits_array(struct posix_ace_state_array
*a
, u32 mask
)
618 for (i
=0; i
< a
->n
; i
++)
619 deny_bits(&a
->aces
[i
].perms
, mask
);
622 static void allow_bits_array(struct posix_ace_state_array
*a
, u32 mask
)
626 for (i
=0; i
< a
->n
; i
++)
627 allow_bits(&a
->aces
[i
].perms
, mask
);
630 static void process_one_v4_ace(struct posix_acl_state
*state
,
631 struct nfs4_ace
*ace
)
633 u32 mask
= ace
->access_mask
;
638 switch (ace2type(ace
)) {
640 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
641 allow_bits(&state
->owner
, mask
);
643 deny_bits(&state
->owner
, mask
);
647 i
= find_uid(state
, state
->users
, ace
->who
);
648 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
649 allow_bits(&state
->users
->aces
[i
].perms
, mask
);
651 deny_bits(&state
->users
->aces
[i
].perms
, mask
);
652 mask
= state
->users
->aces
[i
].perms
.deny
;
653 deny_bits(&state
->owner
, mask
);
657 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
658 allow_bits(&state
->group
, mask
);
660 deny_bits(&state
->group
, mask
);
661 mask
= state
->group
.deny
;
662 deny_bits(&state
->owner
, mask
);
663 deny_bits(&state
->everyone
, mask
);
664 deny_bits_array(state
->users
, mask
);
665 deny_bits_array(state
->groups
, mask
);
669 i
= find_uid(state
, state
->groups
, ace
->who
);
670 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
671 allow_bits(&state
->groups
->aces
[i
].perms
, mask
);
673 deny_bits(&state
->groups
->aces
[i
].perms
, mask
);
674 mask
= state
->groups
->aces
[i
].perms
.deny
;
675 deny_bits(&state
->owner
, mask
);
676 deny_bits(&state
->group
, mask
);
677 deny_bits(&state
->everyone
, mask
);
678 deny_bits_array(state
->users
, mask
);
679 deny_bits_array(state
->groups
, mask
);
683 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
684 allow_bits(&state
->owner
, mask
);
685 allow_bits(&state
->group
, mask
);
686 allow_bits(&state
->other
, mask
);
687 allow_bits(&state
->everyone
, mask
);
688 allow_bits_array(state
->users
, mask
);
689 allow_bits_array(state
->groups
, mask
);
691 deny_bits(&state
->owner
, mask
);
692 deny_bits(&state
->group
, mask
);
693 deny_bits(&state
->other
, mask
);
694 deny_bits(&state
->everyone
, mask
);
695 deny_bits_array(state
->users
, mask
);
696 deny_bits_array(state
->groups
, mask
);
701 int nfs4_acl_nfsv4_to_posix(struct nfs4_acl
*acl
, struct posix_acl
**pacl
,
702 struct posix_acl
**dpacl
, unsigned int flags
)
704 struct posix_acl_state effective_acl_state
, default_acl_state
;
705 struct nfs4_ace
*ace
;
708 ret
= init_state(&effective_acl_state
, acl
->naces
);
711 ret
= init_state(&default_acl_state
, acl
->naces
);
715 for (ace
= acl
->aces
; ace
< acl
->aces
+ acl
->naces
; ace
++) {
716 if (ace
->type
!= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
&&
717 ace
->type
!= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
)
719 if (ace
->flag
& ~NFS4_SUPPORTED_FLAGS
)
721 if ((ace
->flag
& NFS4_INHERITANCE_FLAGS
) == 0) {
722 process_one_v4_ace(&effective_acl_state
, ace
);
725 if (!(flags
& NFS4_ACL_DIR
))
728 * Note that when only one of FILE_INHERIT or DIRECTORY_INHERIT
729 * is set, we're effectively turning on the other. That's OK,
730 * according to rfc 3530.
732 process_one_v4_ace(&default_acl_state
, ace
);
734 if (!(ace
->flag
& NFS4_ACE_INHERIT_ONLY_ACE
))
735 process_one_v4_ace(&effective_acl_state
, ace
);
737 *pacl
= posix_state_to_acl(&effective_acl_state
, flags
);
739 ret
= PTR_ERR(*pacl
);
743 *dpacl
= posix_state_to_acl(&default_acl_state
,
744 flags
| NFS4_ACL_TYPE_DEFAULT
);
745 if (IS_ERR(*dpacl
)) {
746 ret
= PTR_ERR(*dpacl
);
748 posix_acl_release(*pacl
);
756 free_state(&default_acl_state
);
758 free_state(&effective_acl_state
);
763 ace2type(struct nfs4_ace
*ace
)
765 switch (ace
->whotype
) {
766 case NFS4_ACL_WHO_NAMED
:
767 return (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
?
768 ACL_GROUP
: ACL_USER
);
769 case NFS4_ACL_WHO_OWNER
:
771 case NFS4_ACL_WHO_GROUP
:
772 return ACL_GROUP_OBJ
;
773 case NFS4_ACL_WHO_EVERYONE
:
780 EXPORT_SYMBOL(nfs4_acl_posix_to_nfsv4
);
781 EXPORT_SYMBOL(nfs4_acl_nfsv4_to_posix
);
786 struct nfs4_acl
*acl
;
788 acl
= kmalloc(sizeof(*acl
) + n
*sizeof(struct nfs4_ace
), GFP_KERNEL
);
802 .stringlen
= sizeof("OWNER@") - 1,
803 .type
= NFS4_ACL_WHO_OWNER
,
807 .stringlen
= sizeof("GROUP@") - 1,
808 .type
= NFS4_ACL_WHO_GROUP
,
811 .string
= "EVERYONE@",
812 .stringlen
= sizeof("EVERYONE@") - 1,
813 .type
= NFS4_ACL_WHO_EVERYONE
,
818 nfs4_acl_get_whotype(char *p
, u32 len
)
822 for (i
= 0; i
< ARRAY_SIZE(s2t_map
); i
++) {
823 if (s2t_map
[i
].stringlen
== len
&&
824 0 == memcmp(s2t_map
[i
].string
, p
, len
))
825 return s2t_map
[i
].type
;
827 return NFS4_ACL_WHO_NAMED
;
831 nfs4_acl_write_who(int who
, char *p
)
835 for (i
= 0; i
< ARRAY_SIZE(s2t_map
); i
++) {
836 if (s2t_map
[i
].type
== who
) {
837 memcpy(p
, s2t_map
[i
].string
, s2t_map
[i
].stringlen
);
838 return s2t_map
[i
].stringlen
;
845 EXPORT_SYMBOL(nfs4_acl_new
);
846 EXPORT_SYMBOL(nfs4_acl_get_whotype
);
847 EXPORT_SYMBOL(nfs4_acl_write_who
);