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/nfs_fs.h>
38 #include <linux/nfs4_acl.h>
41 /* mode bit translations: */
42 #define NFS4_READ_MODE (NFS4_ACE_READ_DATA)
43 #define NFS4_WRITE_MODE (NFS4_ACE_WRITE_DATA | NFS4_ACE_APPEND_DATA)
44 #define NFS4_EXECUTE_MODE NFS4_ACE_EXECUTE
45 #define NFS4_ANYONE_MODE (NFS4_ACE_READ_ATTRIBUTES | NFS4_ACE_READ_ACL | NFS4_ACE_SYNCHRONIZE)
46 #define NFS4_OWNER_MODE (NFS4_ACE_WRITE_ATTRIBUTES | NFS4_ACE_WRITE_ACL)
48 /* We don't support these bits; insist they be neither allowed nor denied */
49 #define NFS4_MASK_UNSUPP (NFS4_ACE_DELETE | NFS4_ACE_WRITE_OWNER \
50 | NFS4_ACE_READ_NAMED_ATTRS | NFS4_ACE_WRITE_NAMED_ATTRS)
52 /* flags used to simulate posix default ACLs */
53 #define NFS4_INHERITANCE_FLAGS (NFS4_ACE_FILE_INHERIT_ACE \
54 | NFS4_ACE_DIRECTORY_INHERIT_ACE)
56 #define NFS4_SUPPORTED_FLAGS (NFS4_INHERITANCE_FLAGS \
57 | NFS4_ACE_INHERIT_ONLY_ACE \
58 | NFS4_ACE_IDENTIFIER_GROUP)
60 #define MASK_EQUAL(mask1, mask2) \
61 ( ((mask1) & NFS4_ACE_MASK_ALL) == ((mask2) & NFS4_ACE_MASK_ALL) )
64 mask_from_posix(unsigned short perm
, unsigned int flags
)
66 int mask
= NFS4_ANYONE_MODE
;
68 if (flags
& NFS4_ACL_OWNER
)
69 mask
|= NFS4_OWNER_MODE
;
71 mask
|= NFS4_READ_MODE
;
73 mask
|= NFS4_WRITE_MODE
;
74 if ((perm
& ACL_WRITE
) && (flags
& NFS4_ACL_DIR
))
75 mask
|= NFS4_ACE_DELETE_CHILD
;
76 if (perm
& ACL_EXECUTE
)
77 mask
|= NFS4_EXECUTE_MODE
;
82 deny_mask_from_posix(unsigned short perm
, u32 flags
)
87 mask
|= NFS4_READ_MODE
;
89 mask
|= NFS4_WRITE_MODE
;
90 if ((perm
& ACL_WRITE
) && (flags
& NFS4_ACL_DIR
))
91 mask
|= NFS4_ACE_DELETE_CHILD
;
92 if (perm
& ACL_EXECUTE
)
93 mask
|= NFS4_EXECUTE_MODE
;
97 /* XXX: modify functions to return NFS errors; they're only ever
98 * used by nfs code, after all.... */
100 /* We only map from NFSv4 to POSIX ACLs when setting ACLs, when we err on the
101 * side of being more restrictive, so the mode bit mapping below is
102 * pessimistic. An optimistic version would be needed to handle DENY's,
103 * but we espect to coalesce all ALLOWs and DENYs before mapping to mode
107 low_mode_from_nfs4(u32 perm
, unsigned short *mode
, unsigned int flags
)
109 u32 write_mode
= NFS4_WRITE_MODE
;
111 if (flags
& NFS4_ACL_DIR
)
112 write_mode
|= NFS4_ACE_DELETE_CHILD
;
114 if ((perm
& NFS4_READ_MODE
) == NFS4_READ_MODE
)
116 if ((perm
& write_mode
) == write_mode
)
118 if ((perm
& NFS4_EXECUTE_MODE
) == NFS4_EXECUTE_MODE
)
119 *mode
|= ACL_EXECUTE
;
122 struct ace_container
{
123 struct nfs4_ace
*ace
;
124 struct list_head ace_l
;
127 static short ace2type(struct nfs4_ace
*);
128 static void _posix_to_nfsv4_one(struct posix_acl
*, struct nfs4_acl
*,
132 nfs4_acl_posix_to_nfsv4(struct posix_acl
*pacl
, struct posix_acl
*dpacl
,
135 struct nfs4_acl
*acl
;
139 if (posix_acl_valid(pacl
) < 0)
140 return ERR_PTR(-EINVAL
);
141 size
+= 2*pacl
->a_count
;
144 if (posix_acl_valid(dpacl
) < 0)
145 return ERR_PTR(-EINVAL
);
146 size
+= 2*dpacl
->a_count
;
149 /* Allocate for worst case: one (deny, allow) pair each: */
150 acl
= nfs4_acl_new(size
);
152 return ERR_PTR(-ENOMEM
);
155 _posix_to_nfsv4_one(pacl
, acl
, flags
& ~NFS4_ACL_TYPE_DEFAULT
);
158 _posix_to_nfsv4_one(dpacl
, acl
, flags
| NFS4_ACL_TYPE_DEFAULT
);
163 struct posix_acl_summary
{
164 unsigned short owner
;
165 unsigned short users
;
166 unsigned short group
;
167 unsigned short groups
;
168 unsigned short other
;
173 summarize_posix_acl(struct posix_acl
*acl
, struct posix_acl_summary
*pas
)
175 struct posix_acl_entry
*pa
, *pe
;
178 * Only pas.users and pas.groups need initialization; previous
179 * posix_acl_valid() calls ensure that the other fields will be
180 * initialized in the following loop. But, just to placate gcc:
182 memset(pas
, 0, sizeof(*pas
));
185 pe
= acl
->a_entries
+ acl
->a_count
;
187 FOREACH_ACL_ENTRY(pa
, acl
, pe
) {
190 pas
->owner
= pa
->e_perm
;
193 pas
->group
= pa
->e_perm
;
196 pas
->users
|= pa
->e_perm
;
199 pas
->groups
|= pa
->e_perm
;
202 pas
->other
= pa
->e_perm
;
205 pas
->mask
= pa
->e_perm
;
209 /* We'll only care about effective permissions: */
210 pas
->users
&= pas
->mask
;
211 pas
->group
&= pas
->mask
;
212 pas
->groups
&= pas
->mask
;
215 /* We assume the acl has been verified with posix_acl_valid. */
217 _posix_to_nfsv4_one(struct posix_acl
*pacl
, struct nfs4_acl
*acl
,
220 struct posix_acl_entry
*pa
, *group_owner_entry
;
221 struct nfs4_ace
*ace
;
222 struct posix_acl_summary pas
;
224 int eflag
= ((flags
& NFS4_ACL_TYPE_DEFAULT
) ?
225 NFS4_INHERITANCE_FLAGS
| NFS4_ACE_INHERIT_ONLY_ACE
: 0);
227 BUG_ON(pacl
->a_count
< 3);
228 summarize_posix_acl(pacl
, &pas
);
230 pa
= pacl
->a_entries
;
231 ace
= acl
->aces
+ acl
->naces
;
233 /* We could deny everything not granted by the owner: */
236 * but it is equivalent (and simpler) to deny only what is not
237 * granted by later entries:
239 deny
&= pas
.users
| pas
.group
| pas
.groups
| pas
.other
;
241 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
243 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
244 ace
->whotype
= NFS4_ACL_WHO_OWNER
;
249 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
251 ace
->access_mask
= mask_from_posix(pa
->e_perm
, flags
| NFS4_ACL_OWNER
);
252 ace
->whotype
= NFS4_ACL_WHO_OWNER
;
257 while (pa
->e_tag
== ACL_USER
) {
258 deny
= ~(pa
->e_perm
& pas
.mask
);
259 deny
&= pas
.groups
| pas
.group
| pas
.other
;
261 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
263 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
264 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
269 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
271 ace
->access_mask
= mask_from_posix(pa
->e_perm
& pas
.mask
,
273 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
280 /* In the case of groups, we apply allow ACEs first, then deny ACEs,
281 * since a user can be in more than one group. */
285 group_owner_entry
= pa
;
287 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
289 ace
->access_mask
= mask_from_posix(pas
.group
, flags
);
290 ace
->whotype
= NFS4_ACL_WHO_GROUP
;
295 while (pa
->e_tag
== ACL_GROUP
) {
296 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
297 ace
->flag
= eflag
| NFS4_ACE_IDENTIFIER_GROUP
;
298 ace
->access_mask
= mask_from_posix(pa
->e_perm
& pas
.mask
,
300 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
309 pa
= group_owner_entry
;
311 deny
= ~pas
.group
& pas
.other
;
313 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
315 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
316 ace
->whotype
= NFS4_ACL_WHO_GROUP
;
322 while (pa
->e_tag
== ACL_GROUP
) {
323 deny
= ~(pa
->e_perm
& pas
.mask
);
326 ace
->type
= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
;
327 ace
->flag
= eflag
| NFS4_ACE_IDENTIFIER_GROUP
;
328 ace
->access_mask
= deny_mask_from_posix(deny
, flags
);
329 ace
->whotype
= NFS4_ACL_WHO_NAMED
;
337 if (pa
->e_tag
== ACL_MASK
)
339 ace
->type
= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
;
341 ace
->access_mask
= mask_from_posix(pa
->e_perm
, flags
);
342 ace
->whotype
= NFS4_ACL_WHO_EVERYONE
;
347 sort_pacl_range(struct posix_acl
*pacl
, int start
, int end
) {
349 struct posix_acl_entry tmp
;
351 /* We just do a bubble sort; easy to do in place, and we're not
352 * expecting acl's to be long enough to justify anything more. */
355 for (i
= start
; i
< end
; i
++) {
356 if (pacl
->a_entries
[i
].e_id
357 > pacl
->a_entries
[i
+1].e_id
) {
359 tmp
= pacl
->a_entries
[i
];
360 pacl
->a_entries
[i
] = pacl
->a_entries
[i
+1];
361 pacl
->a_entries
[i
+1] = tmp
;
368 sort_pacl(struct posix_acl
*pacl
)
370 /* posix_acl_valid requires that users and groups be in order
374 if (pacl
->a_count
<= 4)
375 return; /* no users or groups */
377 while (pacl
->a_entries
[i
].e_tag
== ACL_USER
)
379 sort_pacl_range(pacl
, 1, i
-1);
381 BUG_ON(pacl
->a_entries
[i
].e_tag
!= ACL_GROUP_OBJ
);
383 while (pacl
->a_entries
[j
].e_tag
== ACL_GROUP
)
385 sort_pacl_range(pacl
, i
, j
-1);
390 * While processing the NFSv4 ACE, this maintains bitmasks representing
391 * which permission bits have been allowed and which denied to a given
393 struct posix_ace_state
{
398 struct posix_user_ace_state
{
400 struct posix_ace_state perms
;
403 struct posix_ace_state_array
{
405 struct posix_user_ace_state aces
[];
409 * While processing the NFSv4 ACE, this maintains the partial permissions
410 * calculated so far: */
412 struct posix_acl_state
{
414 struct posix_ace_state owner
;
415 struct posix_ace_state group
;
416 struct posix_ace_state other
;
417 struct posix_ace_state everyone
;
418 struct posix_ace_state mask
; /* Deny unused in this case */
419 struct posix_ace_state_array
*users
;
420 struct posix_ace_state_array
*groups
;
424 init_state(struct posix_acl_state
*state
, int cnt
)
428 memset(state
, 0, sizeof(struct posix_acl_state
));
431 * In the worst case, each individual acl could be for a distinct
432 * named user or group, but we don't no which, so we allocate
433 * enough space for either:
435 alloc
= sizeof(struct posix_ace_state_array
)
436 + cnt
*sizeof(struct posix_user_ace_state
);
437 state
->users
= kzalloc(alloc
, GFP_KERNEL
);
440 state
->groups
= kzalloc(alloc
, GFP_KERNEL
);
441 if (!state
->groups
) {
449 free_state(struct posix_acl_state
*state
) {
451 kfree(state
->groups
);
454 static inline void add_to_mask(struct posix_acl_state
*state
, struct posix_ace_state
*astate
)
456 state
->mask
.allow
|= astate
->allow
;
460 * Certain bits (SYNCHRONIZE, DELETE, WRITE_OWNER, READ/WRITE_NAMED_ATTRS,
461 * READ_ATTRIBUTES, READ_ACL) are currently unenforceable and don't translate
462 * to traditional read/write/execute permissions.
464 * It's problematic to reject acls that use certain mode bits, because it
465 * places the burden on users to learn the rules about which bits one
466 * particular server sets, without giving the user a lot of help--we return an
467 * error that could mean any number of different things. To make matters
468 * worse, the problematic bits might be introduced by some application that's
469 * automatically mapping from some other acl model.
471 * So wherever possible we accept anything, possibly erring on the side of
472 * denying more permissions than necessary.
474 * However we do reject *explicit* DENY's of a few bits representing
475 * permissions we could never deny:
478 static inline int check_deny(u32 mask
, int isowner
)
480 if (mask
& (NFS4_ACE_READ_ATTRIBUTES
| NFS4_ACE_READ_ACL
))
484 if (mask
& (NFS4_ACE_WRITE_ATTRIBUTES
| NFS4_ACE_WRITE_ACL
))
489 static struct posix_acl
*
490 posix_state_to_acl(struct posix_acl_state
*state
, unsigned int flags
)
492 struct posix_acl_entry
*pace
;
493 struct posix_acl
*pacl
;
498 * ACLs with no ACEs are treated differently in the inheritable
499 * and effective cases: when there are no inheritable ACEs, we
500 * set a zero-length default posix acl:
502 if (state
->empty
&& (flags
& NFS4_ACL_TYPE_DEFAULT
)) {
503 pacl
= posix_acl_alloc(0, GFP_KERNEL
);
504 return pacl
? pacl
: ERR_PTR(-ENOMEM
);
507 * When there are no effective ACEs, the following will end
508 * up setting a 3-element effective posix ACL with all
511 nace
= 4 + state
->users
->n
+ state
->groups
->n
;
512 pacl
= posix_acl_alloc(nace
, GFP_KERNEL
);
514 return ERR_PTR(-ENOMEM
);
516 pace
= pacl
->a_entries
;
517 pace
->e_tag
= ACL_USER_OBJ
;
518 error
= check_deny(state
->owner
.deny
, 1);
521 low_mode_from_nfs4(state
->owner
.allow
, &pace
->e_perm
, flags
);
522 pace
->e_id
= ACL_UNDEFINED_ID
;
524 for (i
=0; i
< state
->users
->n
; i
++) {
526 pace
->e_tag
= ACL_USER
;
527 error
= check_deny(state
->users
->aces
[i
].perms
.deny
, 0);
530 low_mode_from_nfs4(state
->users
->aces
[i
].perms
.allow
,
531 &pace
->e_perm
, flags
);
532 pace
->e_id
= state
->users
->aces
[i
].uid
;
533 add_to_mask(state
, &state
->users
->aces
[i
].perms
);
537 pace
->e_tag
= ACL_GROUP_OBJ
;
538 error
= check_deny(state
->group
.deny
, 0);
541 low_mode_from_nfs4(state
->group
.allow
, &pace
->e_perm
, flags
);
542 pace
->e_id
= ACL_UNDEFINED_ID
;
543 add_to_mask(state
, &state
->group
);
545 for (i
=0; i
< state
->groups
->n
; i
++) {
547 pace
->e_tag
= ACL_GROUP
;
548 error
= check_deny(state
->groups
->aces
[i
].perms
.deny
, 0);
551 low_mode_from_nfs4(state
->groups
->aces
[i
].perms
.allow
,
552 &pace
->e_perm
, flags
);
553 pace
->e_id
= state
->groups
->aces
[i
].uid
;
554 add_to_mask(state
, &state
->groups
->aces
[i
].perms
);
558 pace
->e_tag
= ACL_MASK
;
559 low_mode_from_nfs4(state
->mask
.allow
, &pace
->e_perm
, flags
);
560 pace
->e_id
= ACL_UNDEFINED_ID
;
563 pace
->e_tag
= ACL_OTHER
;
564 error
= check_deny(state
->other
.deny
, 0);
567 low_mode_from_nfs4(state
->other
.allow
, &pace
->e_perm
, flags
);
568 pace
->e_id
= ACL_UNDEFINED_ID
;
572 posix_acl_release(pacl
);
573 return ERR_PTR(error
);
576 static inline void allow_bits(struct posix_ace_state
*astate
, u32 mask
)
578 /* Allow all bits in the mask not already denied: */
579 astate
->allow
|= mask
& ~astate
->deny
;
582 static inline void deny_bits(struct posix_ace_state
*astate
, u32 mask
)
584 /* Deny all bits in the mask not already allowed: */
585 astate
->deny
|= mask
& ~astate
->allow
;
588 static int find_uid(struct posix_acl_state
*state
, struct posix_ace_state_array
*a
, uid_t uid
)
592 for (i
= 0; i
< a
->n
; i
++)
593 if (a
->aces
[i
].uid
== uid
)
597 a
->aces
[i
].uid
= uid
;
598 a
->aces
[i
].perms
.allow
= state
->everyone
.allow
;
599 a
->aces
[i
].perms
.deny
= state
->everyone
.deny
;
604 static void deny_bits_array(struct posix_ace_state_array
*a
, u32 mask
)
608 for (i
=0; i
< a
->n
; i
++)
609 deny_bits(&a
->aces
[i
].perms
, mask
);
612 static void allow_bits_array(struct posix_ace_state_array
*a
, u32 mask
)
616 for (i
=0; i
< a
->n
; i
++)
617 allow_bits(&a
->aces
[i
].perms
, mask
);
620 static void process_one_v4_ace(struct posix_acl_state
*state
,
621 struct nfs4_ace
*ace
)
623 u32 mask
= ace
->access_mask
;
628 switch (ace2type(ace
)) {
630 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
631 allow_bits(&state
->owner
, mask
);
633 deny_bits(&state
->owner
, mask
);
637 i
= find_uid(state
, state
->users
, ace
->who
);
638 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
639 allow_bits(&state
->users
->aces
[i
].perms
, mask
);
641 deny_bits(&state
->users
->aces
[i
].perms
, mask
);
642 mask
= state
->users
->aces
[i
].perms
.deny
;
643 deny_bits(&state
->owner
, mask
);
647 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
648 allow_bits(&state
->group
, mask
);
650 deny_bits(&state
->group
, mask
);
651 mask
= state
->group
.deny
;
652 deny_bits(&state
->owner
, mask
);
653 deny_bits(&state
->everyone
, mask
);
654 deny_bits_array(state
->users
, mask
);
655 deny_bits_array(state
->groups
, mask
);
659 i
= find_uid(state
, state
->groups
, ace
->who
);
660 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
661 allow_bits(&state
->groups
->aces
[i
].perms
, mask
);
663 deny_bits(&state
->groups
->aces
[i
].perms
, mask
);
664 mask
= state
->groups
->aces
[i
].perms
.deny
;
665 deny_bits(&state
->owner
, mask
);
666 deny_bits(&state
->group
, mask
);
667 deny_bits(&state
->everyone
, mask
);
668 deny_bits_array(state
->users
, mask
);
669 deny_bits_array(state
->groups
, mask
);
673 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
674 allow_bits(&state
->owner
, mask
);
675 allow_bits(&state
->group
, mask
);
676 allow_bits(&state
->other
, mask
);
677 allow_bits(&state
->everyone
, mask
);
678 allow_bits_array(state
->users
, mask
);
679 allow_bits_array(state
->groups
, mask
);
681 deny_bits(&state
->owner
, mask
);
682 deny_bits(&state
->group
, mask
);
683 deny_bits(&state
->other
, mask
);
684 deny_bits(&state
->everyone
, mask
);
685 deny_bits_array(state
->users
, mask
);
686 deny_bits_array(state
->groups
, mask
);
691 int nfs4_acl_nfsv4_to_posix(struct nfs4_acl
*acl
, struct posix_acl
**pacl
,
692 struct posix_acl
**dpacl
, unsigned int flags
)
694 struct posix_acl_state effective_acl_state
, default_acl_state
;
695 struct nfs4_ace
*ace
;
698 ret
= init_state(&effective_acl_state
, acl
->naces
);
701 ret
= init_state(&default_acl_state
, acl
->naces
);
705 for (ace
= acl
->aces
; ace
< acl
->aces
+ acl
->naces
; ace
++) {
706 if (ace
->type
!= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
&&
707 ace
->type
!= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
)
709 if (ace
->flag
& ~NFS4_SUPPORTED_FLAGS
)
711 if ((ace
->flag
& NFS4_INHERITANCE_FLAGS
) == 0) {
712 process_one_v4_ace(&effective_acl_state
, ace
);
715 if (!(flags
& NFS4_ACL_DIR
))
718 * Note that when only one of FILE_INHERIT or DIRECTORY_INHERIT
719 * is set, we're effectively turning on the other. That's OK,
720 * according to rfc 3530.
722 process_one_v4_ace(&default_acl_state
, ace
);
724 if (!(ace
->flag
& NFS4_ACE_INHERIT_ONLY_ACE
))
725 process_one_v4_ace(&effective_acl_state
, ace
);
727 *pacl
= posix_state_to_acl(&effective_acl_state
, flags
);
729 ret
= PTR_ERR(*pacl
);
733 *dpacl
= posix_state_to_acl(&default_acl_state
,
734 flags
| NFS4_ACL_TYPE_DEFAULT
);
735 if (IS_ERR(*dpacl
)) {
736 ret
= PTR_ERR(*dpacl
);
738 posix_acl_release(*pacl
);
746 free_state(&default_acl_state
);
748 free_state(&effective_acl_state
);
753 ace2type(struct nfs4_ace
*ace
)
755 switch (ace
->whotype
) {
756 case NFS4_ACL_WHO_NAMED
:
757 return (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
?
758 ACL_GROUP
: ACL_USER
);
759 case NFS4_ACL_WHO_OWNER
:
761 case NFS4_ACL_WHO_GROUP
:
762 return ACL_GROUP_OBJ
;
763 case NFS4_ACL_WHO_EVERYONE
:
770 EXPORT_SYMBOL(nfs4_acl_posix_to_nfsv4
);
771 EXPORT_SYMBOL(nfs4_acl_nfsv4_to_posix
);
776 struct nfs4_acl
*acl
;
778 acl
= kmalloc(sizeof(*acl
) + n
*sizeof(struct nfs4_ace
), GFP_KERNEL
);
792 .stringlen
= sizeof("OWNER@") - 1,
793 .type
= NFS4_ACL_WHO_OWNER
,
797 .stringlen
= sizeof("GROUP@") - 1,
798 .type
= NFS4_ACL_WHO_GROUP
,
801 .string
= "EVERYONE@",
802 .stringlen
= sizeof("EVERYONE@") - 1,
803 .type
= NFS4_ACL_WHO_EVERYONE
,
808 nfs4_acl_get_whotype(char *p
, u32 len
)
812 for (i
= 0; i
< ARRAY_SIZE(s2t_map
); i
++) {
813 if (s2t_map
[i
].stringlen
== len
&&
814 0 == memcmp(s2t_map
[i
].string
, p
, len
))
815 return s2t_map
[i
].type
;
817 return NFS4_ACL_WHO_NAMED
;
821 nfs4_acl_write_who(int who
, char *p
)
825 for (i
= 0; i
< ARRAY_SIZE(s2t_map
); i
++) {
826 if (s2t_map
[i
].type
== who
) {
827 memcpy(p
, s2t_map
[i
].string
, s2t_map
[i
].stringlen
);
828 return s2t_map
[i
].stringlen
;
835 EXPORT_SYMBOL(nfs4_acl_new
);
836 EXPORT_SYMBOL(nfs4_acl_get_whotype
);
837 EXPORT_SYMBOL(nfs4_acl_write_who
);