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 | NFS4_ACE_INHERIT_ONLY_ACE)
66 #define MASK_EQUAL(mask1, mask2) \
67 ( ((mask1) & NFS4_ACE_MASK_ALL) == ((mask2) & NFS4_ACE_MASK_ALL) )
70 mask_from_posix(unsigned short perm
, unsigned int flags
)
72 int mask
= NFS4_ANYONE_MODE
;
74 if (flags
& NFS4_ACL_OWNER
)
75 mask
|= NFS4_OWNER_MODE
;
77 mask
|= NFS4_READ_MODE
;
79 mask
|= NFS4_WRITE_MODE
;
80 if ((perm
& ACL_WRITE
) && (flags
& NFS4_ACL_DIR
))
81 mask
|= NFS4_ACE_DELETE_CHILD
;
82 if (perm
& ACL_EXECUTE
)
83 mask
|= NFS4_EXECUTE_MODE
;
88 deny_mask(u32 allow_mask
, unsigned int flags
)
90 u32 ret
= ~allow_mask
& ~NFS4_MASK_UNSUPP
;
91 if (!(flags
& NFS4_ACL_DIR
))
92 ret
&= ~NFS4_ACE_DELETE_CHILD
;
96 /* XXX: modify functions to return NFS errors; they're only ever
97 * used by nfs code, after all.... */
99 /* We only map from NFSv4 to POSIX ACLs when setting ACLs, when we err on the
100 * side of being more restrictive, so the mode bit mapping below is
101 * pessimistic. An optimistic version would be needed to handle DENY's,
102 * but we espect to coalesce all ALLOWs and DENYs before mapping to mode
106 low_mode_from_nfs4(u32 perm
, unsigned short *mode
, unsigned int flags
)
108 u32 write_mode
= NFS4_WRITE_MODE
;
110 if (flags
& NFS4_ACL_DIR
)
111 write_mode
|= NFS4_ACE_DELETE_CHILD
;
113 if ((perm
& NFS4_READ_MODE
) == NFS4_READ_MODE
)
115 if ((perm
& write_mode
) == write_mode
)
117 if ((perm
& NFS4_EXECUTE_MODE
) == NFS4_EXECUTE_MODE
)
118 *mode
|= ACL_EXECUTE
;
121 struct ace_container
{
122 struct nfs4_ace
*ace
;
123 struct list_head ace_l
;
126 static short ace2type(struct nfs4_ace
*);
127 static int _posix_to_nfsv4_one(struct posix_acl
*, struct nfs4_acl
*, unsigned int);
128 static struct posix_acl
*_nfsv4_to_posix_one(struct nfs4_acl
*, unsigned int);
129 int nfs4_acl_add_ace(struct nfs4_acl
*, u32
, u32
, u32
, int, uid_t
);
130 static int nfs4_acl_split(struct nfs4_acl
*, struct nfs4_acl
*);
133 nfs4_acl_posix_to_nfsv4(struct posix_acl
*pacl
, struct posix_acl
*dpacl
,
136 struct nfs4_acl
*acl
;
140 (posix_acl_valid(pacl
) < 0 || pacl
->a_count
== 0)) ||
142 (posix_acl_valid(dpacl
) < 0 || dpacl
->a_count
== 0)))
145 acl
= nfs4_acl_new();
152 error
= _posix_to_nfsv4_one(pacl
, acl
,
153 flags
& ~NFS4_ACL_TYPE_DEFAULT
);
159 error
= _posix_to_nfsv4_one(dpacl
, acl
,
160 flags
| NFS4_ACL_TYPE_DEFAULT
);
170 acl
= ERR_PTR(error
);
176 nfs4_acl_add_pair(struct nfs4_acl
*acl
, int eflag
, u32 mask
, int whotype
,
177 uid_t owner
, unsigned int flags
)
181 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
,
182 eflag
, mask
, whotype
, owner
);
185 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_DENIED_ACE_TYPE
,
186 eflag
, deny_mask(mask
, flags
), whotype
, owner
);
190 /* We assume the acl has been verified with posix_acl_valid. */
192 _posix_to_nfsv4_one(struct posix_acl
*pacl
, struct nfs4_acl
*acl
,
195 struct posix_acl_entry
*pa
, *pe
, *group_owner_entry
;
198 int eflag
= ((flags
& NFS4_ACL_TYPE_DEFAULT
) ?
199 NFS4_INHERITANCE_FLAGS
: 0);
201 BUG_ON(pacl
->a_count
< 3);
202 pe
= pacl
->a_entries
+ pacl
->a_count
;
203 pa
= pe
- 2; /* if mask entry exists, it's second from the last. */
204 if (pa
->e_tag
== ACL_MASK
)
205 mask_mask
= deny_mask(mask_from_posix(pa
->e_perm
, flags
), flags
);
209 pa
= pacl
->a_entries
;
210 BUG_ON(pa
->e_tag
!= ACL_USER_OBJ
);
211 mask
= mask_from_posix(pa
->e_perm
, flags
| NFS4_ACL_OWNER
);
212 error
= nfs4_acl_add_pair(acl
, eflag
, mask
, NFS4_ACL_WHO_OWNER
, 0, flags
);
217 while (pa
->e_tag
== ACL_USER
) {
218 mask
= mask_from_posix(pa
->e_perm
, flags
);
219 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_DENIED_ACE_TYPE
,
220 eflag
, mask_mask
, NFS4_ACL_WHO_NAMED
, pa
->e_id
);
225 error
= nfs4_acl_add_pair(acl
, eflag
, mask
,
226 NFS4_ACL_WHO_NAMED
, pa
->e_id
, flags
);
232 /* In the case of groups, we apply allow ACEs first, then deny ACEs,
233 * since a user can be in more than one group. */
237 if (pacl
->a_count
> 3) {
238 BUG_ON(pa
->e_tag
!= ACL_GROUP_OBJ
);
239 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_DENIED_ACE_TYPE
,
240 NFS4_ACE_IDENTIFIER_GROUP
| eflag
, mask_mask
,
241 NFS4_ACL_WHO_GROUP
, 0);
245 group_owner_entry
= pa
;
246 mask
= mask_from_posix(pa
->e_perm
, flags
);
247 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
,
248 NFS4_ACE_IDENTIFIER_GROUP
| eflag
, mask
,
249 NFS4_ACL_WHO_GROUP
, 0);
254 while (pa
->e_tag
== ACL_GROUP
) {
255 mask
= mask_from_posix(pa
->e_perm
, flags
);
256 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_DENIED_ACE_TYPE
,
257 NFS4_ACE_IDENTIFIER_GROUP
| eflag
, mask_mask
,
258 NFS4_ACL_WHO_NAMED
, pa
->e_id
);
262 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
,
263 NFS4_ACE_IDENTIFIER_GROUP
| eflag
, mask
,
264 NFS4_ACL_WHO_NAMED
, pa
->e_id
);
272 pa
= group_owner_entry
;
273 mask
= mask_from_posix(pa
->e_perm
, flags
);
274 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_DENIED_ACE_TYPE
,
275 NFS4_ACE_IDENTIFIER_GROUP
| eflag
,
276 deny_mask(mask
, flags
), NFS4_ACL_WHO_GROUP
, 0);
280 while (pa
->e_tag
== ACL_GROUP
) {
281 mask
= mask_from_posix(pa
->e_perm
, flags
);
282 error
= nfs4_acl_add_ace(acl
, NFS4_ACE_ACCESS_DENIED_ACE_TYPE
,
283 NFS4_ACE_IDENTIFIER_GROUP
| eflag
,
284 deny_mask(mask
, flags
), NFS4_ACL_WHO_NAMED
, pa
->e_id
);
290 if (pa
->e_tag
== ACL_MASK
)
292 BUG_ON(pa
->e_tag
!= ACL_OTHER
);
293 mask
= mask_from_posix(pa
->e_perm
, flags
);
294 error
= nfs4_acl_add_pair(acl
, eflag
, mask
, NFS4_ACL_WHO_EVERYONE
, 0, flags
);
301 sort_pacl_range(struct posix_acl
*pacl
, int start
, int end
) {
303 struct posix_acl_entry tmp
;
305 /* We just do a bubble sort; easy to do in place, and we're not
306 * expecting acl's to be long enough to justify anything more. */
309 for (i
= start
; i
< end
; i
++) {
310 if (pacl
->a_entries
[i
].e_id
311 > pacl
->a_entries
[i
+1].e_id
) {
313 tmp
= pacl
->a_entries
[i
];
314 pacl
->a_entries
[i
] = pacl
->a_entries
[i
+1];
315 pacl
->a_entries
[i
+1] = tmp
;
322 sort_pacl(struct posix_acl
*pacl
)
324 /* posix_acl_valid requires that users and groups be in order
328 if (pacl
->a_count
<= 4)
329 return; /* no users or groups */
331 while (pacl
->a_entries
[i
].e_tag
== ACL_USER
)
333 sort_pacl_range(pacl
, 1, i
-1);
335 BUG_ON(pacl
->a_entries
[i
].e_tag
!= ACL_GROUP_OBJ
);
337 while (pacl
->a_entries
[j
].e_tag
== ACL_GROUP
)
339 sort_pacl_range(pacl
, i
, j
-1);
344 nfs4_acl_nfsv4_to_posix(struct nfs4_acl
*acl
, struct posix_acl
**pacl
,
345 struct posix_acl
**dpacl
, unsigned int flags
)
347 struct nfs4_acl
*dacl
;
353 dacl
= nfs4_acl_new();
357 error
= nfs4_acl_split(acl
, dacl
);
362 if (acl
->naces
== 0) {
367 *pacl
= _nfsv4_to_posix_one(acl
, flags
);
369 error
= PTR_ERR(*pacl
);
377 if (dacl
->naces
== 0) {
378 if (pacl
== NULL
|| *pacl
== NULL
)
384 *dpacl
= _nfsv4_to_posix_one(dacl
, flags
);
385 if (IS_ERR(*dpacl
)) {
386 error
= PTR_ERR(*dpacl
);
394 posix_acl_release(*pacl
);
403 * While processing the NFSv4 ACE, this maintains bitmasks representing
404 * which permission bits have been allowed and which denied to a given
406 struct posix_ace_state
{
411 struct posix_user_ace_state
{
413 struct posix_ace_state perms
;
416 struct posix_ace_state_array
{
418 struct posix_user_ace_state aces
[];
422 * While processing the NFSv4 ACE, this maintains the partial permissions
423 * calculated so far: */
425 struct posix_acl_state
{
426 struct posix_ace_state owner
;
427 struct posix_ace_state group
;
428 struct posix_ace_state other
;
429 struct posix_ace_state everyone
;
430 struct posix_ace_state mask
; /* Deny unused in this case */
431 struct posix_ace_state_array
*users
;
432 struct posix_ace_state_array
*groups
;
436 init_state(struct posix_acl_state
*state
, int cnt
)
440 memset(state
, 0, sizeof(struct posix_acl_state
));
442 * In the worst case, each individual acl could be for a distinct
443 * named user or group, but we don't no which, so we allocate
444 * enough space for either:
446 alloc
= sizeof(struct posix_ace_state_array
)
447 + cnt
*sizeof(struct posix_ace_state
);
448 state
->users
= kzalloc(alloc
, GFP_KERNEL
);
451 state
->groups
= kzalloc(alloc
, GFP_KERNEL
);
452 if (!state
->groups
) {
460 free_state(struct posix_acl_state
*state
) {
462 kfree(state
->groups
);
465 static inline void add_to_mask(struct posix_acl_state
*state
, struct posix_ace_state
*astate
)
467 state
->mask
.allow
|= astate
->allow
;
471 * Certain bits (SYNCHRONIZE, DELETE, WRITE_OWNER, READ/WRITE_NAMED_ATTRS,
472 * READ_ATTRIBUTES, READ_ACL) are currently unenforceable and don't translate
473 * to traditional read/write/execute permissions.
475 * It's problematic to reject acls that use certain mode bits, because it
476 * places the burden on users to learn the rules about which bits one
477 * particular server sets, without giving the user a lot of help--we return an
478 * error that could mean any number of different things. To make matters
479 * worse, the problematic bits might be introduced by some application that's
480 * automatically mapping from some other acl model.
482 * So wherever possible we accept anything, possibly erring on the side of
483 * denying more permissions than necessary.
485 * However we do reject *explicit* DENY's of a few bits representing
486 * permissions we could never deny:
489 static inline int check_deny(u32 mask
, int isowner
)
491 if (mask
& (NFS4_ACE_READ_ATTRIBUTES
| NFS4_ACE_READ_ACL
))
495 if (mask
& (NFS4_ACE_WRITE_ATTRIBUTES
| NFS4_ACE_WRITE_ACL
))
500 static struct posix_acl
*
501 posix_state_to_acl(struct posix_acl_state
*state
, unsigned int flags
)
503 struct posix_acl_entry
*pace
;
504 struct posix_acl
*pacl
;
508 nace
= 4 + state
->users
->n
+ state
->groups
->n
;
509 pacl
= posix_acl_alloc(nace
, GFP_KERNEL
);
511 return ERR_PTR(-ENOMEM
);
513 pace
= pacl
->a_entries
;
514 pace
->e_tag
= ACL_USER_OBJ
;
515 error
= check_deny(state
->owner
.deny
, 1);
518 low_mode_from_nfs4(state
->owner
.allow
, &pace
->e_perm
, flags
);
519 pace
->e_id
= ACL_UNDEFINED_ID
;
521 for (i
=0; i
< state
->users
->n
; i
++) {
523 pace
->e_tag
= ACL_USER
;
524 error
= check_deny(state
->users
->aces
[i
].perms
.deny
, 0);
527 low_mode_from_nfs4(state
->users
->aces
[i
].perms
.allow
,
528 &pace
->e_perm
, flags
);
529 pace
->e_id
= state
->users
->aces
[i
].uid
;
530 add_to_mask(state
, &state
->users
->aces
[i
].perms
);
534 pace
->e_tag
= ACL_GROUP_OBJ
;
535 error
= check_deny(state
->group
.deny
, 0);
538 low_mode_from_nfs4(state
->group
.allow
, &pace
->e_perm
, flags
);
539 pace
->e_id
= ACL_UNDEFINED_ID
;
540 add_to_mask(state
, &state
->group
);
542 for (i
=0; i
< state
->groups
->n
; i
++) {
544 pace
->e_tag
= ACL_GROUP
;
545 error
= check_deny(state
->groups
->aces
[i
].perms
.deny
, 0);
548 low_mode_from_nfs4(state
->groups
->aces
[i
].perms
.allow
,
549 &pace
->e_perm
, flags
);
550 pace
->e_id
= state
->groups
->aces
[i
].uid
;
551 add_to_mask(state
, &state
->groups
->aces
[i
].perms
);
555 pace
->e_tag
= ACL_MASK
;
556 low_mode_from_nfs4(state
->mask
.allow
, &pace
->e_perm
, flags
);
557 pace
->e_id
= ACL_UNDEFINED_ID
;
560 pace
->e_tag
= ACL_OTHER
;
561 error
= check_deny(state
->other
.deny
, 0);
564 low_mode_from_nfs4(state
->other
.allow
, &pace
->e_perm
, flags
);
565 pace
->e_id
= ACL_UNDEFINED_ID
;
569 posix_acl_release(pacl
);
570 return ERR_PTR(error
);
573 static inline void allow_bits(struct posix_ace_state
*astate
, u32 mask
)
575 /* Allow all bits in the mask not already denied: */
576 astate
->allow
|= mask
& ~astate
->deny
;
579 static inline void deny_bits(struct posix_ace_state
*astate
, u32 mask
)
581 /* Deny all bits in the mask not already allowed: */
582 astate
->deny
|= mask
& ~astate
->allow
;
585 static int find_uid(struct posix_acl_state
*state
, struct posix_ace_state_array
*a
, uid_t uid
)
589 for (i
= 0; i
< a
->n
; i
++)
590 if (a
->aces
[i
].uid
== uid
)
594 a
->aces
[i
].uid
= uid
;
595 a
->aces
[i
].perms
.allow
= state
->everyone
.allow
;
596 a
->aces
[i
].perms
.deny
= state
->everyone
.deny
;
601 static void deny_bits_array(struct posix_ace_state_array
*a
, u32 mask
)
605 for (i
=0; i
< a
->n
; i
++)
606 deny_bits(&a
->aces
[i
].perms
, mask
);
609 static void allow_bits_array(struct posix_ace_state_array
*a
, u32 mask
)
613 for (i
=0; i
< a
->n
; i
++)
614 allow_bits(&a
->aces
[i
].perms
, mask
);
617 static void process_one_v4_ace(struct posix_acl_state
*state
,
618 struct nfs4_ace
*ace
)
620 u32 mask
= ace
->access_mask
;
623 switch (ace2type(ace
)) {
625 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
626 allow_bits(&state
->owner
, mask
);
628 deny_bits(&state
->owner
, mask
);
632 i
= find_uid(state
, state
->users
, ace
->who
);
633 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
634 allow_bits(&state
->users
->aces
[i
].perms
, mask
);
636 deny_bits(&state
->users
->aces
[i
].perms
, mask
);
637 mask
= state
->users
->aces
[i
].perms
.deny
;
638 deny_bits(&state
->owner
, mask
);
642 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
643 allow_bits(&state
->group
, mask
);
645 deny_bits(&state
->group
, mask
);
646 mask
= state
->group
.deny
;
647 deny_bits(&state
->owner
, mask
);
648 deny_bits(&state
->everyone
, mask
);
649 deny_bits_array(state
->users
, mask
);
650 deny_bits_array(state
->groups
, mask
);
654 i
= find_uid(state
, state
->groups
, ace
->who
);
655 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
656 allow_bits(&state
->groups
->aces
[i
].perms
, mask
);
658 deny_bits(&state
->groups
->aces
[i
].perms
, mask
);
659 mask
= state
->groups
->aces
[i
].perms
.deny
;
660 deny_bits(&state
->owner
, mask
);
661 deny_bits(&state
->group
, mask
);
662 deny_bits(&state
->everyone
, mask
);
663 deny_bits_array(state
->users
, mask
);
664 deny_bits_array(state
->groups
, mask
);
668 if (ace
->type
== NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
) {
669 allow_bits(&state
->owner
, mask
);
670 allow_bits(&state
->group
, mask
);
671 allow_bits(&state
->other
, mask
);
672 allow_bits(&state
->everyone
, mask
);
673 allow_bits_array(state
->users
, mask
);
674 allow_bits_array(state
->groups
, mask
);
676 deny_bits(&state
->owner
, mask
);
677 deny_bits(&state
->group
, mask
);
678 deny_bits(&state
->other
, mask
);
679 deny_bits(&state
->everyone
, mask
);
680 deny_bits_array(state
->users
, mask
);
681 deny_bits_array(state
->groups
, mask
);
686 static struct posix_acl
*
687 _nfsv4_to_posix_one(struct nfs4_acl
*n4acl
, unsigned int flags
)
689 struct posix_acl_state state
;
690 struct posix_acl
*pacl
;
691 struct nfs4_ace
*ace
;
694 ret
= init_state(&state
, n4acl
->naces
);
698 list_for_each_entry(ace
, &n4acl
->ace_head
, l_ace
)
699 process_one_v4_ace(&state
, ace
);
701 pacl
= posix_state_to_acl(&state
, flags
);
711 nfs4_acl_split(struct nfs4_acl
*acl
, struct nfs4_acl
*dacl
)
713 struct list_head
*h
, *n
;
714 struct nfs4_ace
*ace
;
717 list_for_each_safe(h
, n
, &acl
->ace_head
) {
718 ace
= list_entry(h
, struct nfs4_ace
, l_ace
);
720 if (ace
->type
!= NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
&&
721 ace
->type
!= NFS4_ACE_ACCESS_DENIED_ACE_TYPE
)
724 if ((ace
->flag
& NFS4_INHERITANCE_FLAGS
)
725 != NFS4_INHERITANCE_FLAGS
)
728 error
= nfs4_acl_add_ace(dacl
, ace
->type
, ace
->flag
,
729 ace
->access_mask
, ace
->whotype
, ace
->who
);
743 ace2type(struct nfs4_ace
*ace
)
745 switch (ace
->whotype
) {
746 case NFS4_ACL_WHO_NAMED
:
747 return (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
?
748 ACL_GROUP
: ACL_USER
);
749 case NFS4_ACL_WHO_OWNER
:
751 case NFS4_ACL_WHO_GROUP
:
752 return ACL_GROUP_OBJ
;
753 case NFS4_ACL_WHO_EVERYONE
:
760 EXPORT_SYMBOL(nfs4_acl_posix_to_nfsv4
);
761 EXPORT_SYMBOL(nfs4_acl_nfsv4_to_posix
);
766 struct nfs4_acl
*acl
;
768 if ((acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
)) == NULL
)
772 INIT_LIST_HEAD(&acl
->ace_head
);
778 nfs4_acl_free(struct nfs4_acl
*acl
)
781 struct nfs4_ace
*ace
;
786 while (!list_empty(&acl
->ace_head
)) {
787 h
= acl
->ace_head
.next
;
789 ace
= list_entry(h
, struct nfs4_ace
, l_ace
);
799 nfs4_acl_add_ace(struct nfs4_acl
*acl
, u32 type
, u32 flag
, u32 access_mask
,
800 int whotype
, uid_t who
)
802 struct nfs4_ace
*ace
;
804 if ((ace
= kmalloc(sizeof(*ace
), GFP_KERNEL
)) == NULL
)
809 ace
->access_mask
= access_mask
;
810 ace
->whotype
= whotype
;
813 list_add_tail(&ace
->l_ace
, &acl
->ace_head
);
826 .stringlen
= sizeof("OWNER@") - 1,
827 .type
= NFS4_ACL_WHO_OWNER
,
831 .stringlen
= sizeof("GROUP@") - 1,
832 .type
= NFS4_ACL_WHO_GROUP
,
835 .string
= "EVERYONE@",
836 .stringlen
= sizeof("EVERYONE@") - 1,
837 .type
= NFS4_ACL_WHO_EVERYONE
,
842 nfs4_acl_get_whotype(char *p
, u32 len
)
846 for (i
= 0; i
< ARRAY_SIZE(s2t_map
); i
++) {
847 if (s2t_map
[i
].stringlen
== len
&&
848 0 == memcmp(s2t_map
[i
].string
, p
, len
))
849 return s2t_map
[i
].type
;
851 return NFS4_ACL_WHO_NAMED
;
855 nfs4_acl_write_who(int who
, char *p
)
859 for (i
= 0; i
< ARRAY_SIZE(s2t_map
); i
++) {
860 if (s2t_map
[i
].type
== who
) {
861 memcpy(p
, s2t_map
[i
].string
, s2t_map
[i
].stringlen
);
862 return s2t_map
[i
].stringlen
;
869 EXPORT_SYMBOL(nfs4_acl_new
);
870 EXPORT_SYMBOL(nfs4_acl_free
);
871 EXPORT_SYMBOL(nfs4_acl_add_ace
);
872 EXPORT_SYMBOL(nfs4_acl_get_whotype
);
873 EXPORT_SYMBOL(nfs4_acl_write_who
);