]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/ufs/ufs/ufs_acl.c
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / sys / ufs / ufs / ufs_acl.c
1 /*-
2  * Copyright (c) 1999-2003 Robert N. M. Watson
3  * All rights reserved.
4  *
5  * This software was developed by Robert Watson for the TrustedBSD Project.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 /*
30  * Support for POSIX.1e access control lists: UFS-specific support functions.
31  */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #include "opt_ufs.h"
37 #include "opt_quota.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/stat.h>
42 #include <sys/mount.h>
43 #include <sys/vnode.h>
44 #include <sys/types.h>
45 #include <sys/acl.h>
46 #include <sys/event.h>
47 #include <sys/extattr.h>
48
49 #include <ufs/ufs/quota.h>
50 #include <ufs/ufs/inode.h>
51 #include <ufs/ufs/acl.h>
52 #include <ufs/ufs/extattr.h>
53 #include <ufs/ufs/dir.h>
54 #include <ufs/ufs/ufsmount.h>
55 #include <ufs/ufs/ufs_extern.h>
56 #include <ufs/ffs/fs.h>
57
58 #ifdef UFS_ACL
59
60 FEATURE(ufs_acl, "ACL support for UFS");
61
62 /*
63  * Synchronize an ACL and an inode by copying over appropriate inode fields
64  * to the passed ACL.  Assumes an ACL that would satisfy acl_posix1e_check(),
65  * and may panic if not.
66  */
67 void
68 ufs_sync_acl_from_inode(struct inode *ip, struct acl *acl)
69 {
70         struct acl_entry        *acl_mask, *acl_group_obj;
71         int     i;
72
73         /*
74          * Update ACL_USER_OBJ, ACL_OTHER, but simply identify ACL_MASK
75          * and ACL_GROUP_OBJ for use after we know whether ACL_MASK is
76          * present.
77          */
78         acl_mask = NULL;
79         acl_group_obj = NULL;
80         for (i = 0; i < acl->acl_cnt; i++) {
81                 switch (acl->acl_entry[i].ae_tag) {
82                 case ACL_USER_OBJ:
83                         acl->acl_entry[i].ae_perm = acl_posix1e_mode_to_perm(
84                             ACL_USER_OBJ, ip->i_mode);
85                         acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID;
86                         break;
87         
88                 case ACL_GROUP_OBJ:
89                         acl_group_obj = &acl->acl_entry[i];
90                         acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID;
91                         break;
92
93                 case ACL_OTHER:
94                         acl->acl_entry[i].ae_perm = acl_posix1e_mode_to_perm(
95                             ACL_OTHER, ip->i_mode);
96                         acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID;
97                         break;
98
99                 case ACL_MASK:
100                         acl_mask = &acl->acl_entry[i];
101                         acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID;
102                         break;
103
104                 case ACL_USER:
105                 case ACL_GROUP:
106                         break;
107         
108                 default:
109                         panic("ufs_sync_acl_from_inode(): bad ae_tag");
110                 }
111         }
112
113         if (acl_group_obj == NULL)
114                 panic("ufs_sync_acl_from_inode(): no ACL_GROUP_OBJ");
115
116         if (acl_mask == NULL) {
117                 /*
118                  * There is no ACL_MASK, so update ACL_GROUP_OBJ.
119                  */
120                 acl_group_obj->ae_perm = acl_posix1e_mode_to_perm(
121                     ACL_GROUP_OBJ, ip->i_mode);
122         } else {
123                 /*
124                  * Update the ACL_MASK entry instead of ACL_GROUP_OBJ.
125                  */
126                 acl_mask->ae_perm = acl_posix1e_mode_to_perm(ACL_GROUP_OBJ,
127                     ip->i_mode);
128         }
129 }
130
131 /*
132  * Calculate what the inode mode should look like based on an authoritative
133  * ACL for the inode.  Replace only the fields in the inode that the ACL
134  * can represent.
135  */
136 void
137 ufs_sync_inode_from_acl(struct acl *acl, struct inode *ip)
138 {
139
140         ip->i_mode &= ACL_PRESERVE_MASK;
141         ip->i_mode |= acl_posix1e_acl_to_mode(acl);
142         DIP_SET(ip, i_mode, ip->i_mode);
143 }
144
145 /*
146  * Retrieve NFSv4 ACL, skipping access checks.  Must be used in UFS code
147  * instead of VOP_GETACL() when we don't want to be restricted by the user
148  * not having ACL_READ_ACL permission, e.g. when calculating inherited ACL
149  * or in ufs_vnops.c:ufs_accessx().
150  */
151 int
152 ufs_getacl_nfs4_internal(struct vnode *vp, struct acl *aclp, struct thread *td)
153 {
154         int error, len;
155         struct inode *ip = VTOI(vp);
156
157         len = sizeof(*aclp);
158         bzero(aclp, len);
159
160         error = vn_extattr_get(vp, IO_NODELOCKED,
161             NFS4_ACL_EXTATTR_NAMESPACE, NFS4_ACL_EXTATTR_NAME,
162             &len, (char *) aclp, td);
163         aclp->acl_maxcnt = ACL_MAX_ENTRIES;
164         if (error == ENOATTR) {
165                 /*
166                  * Legitimately no ACL set on object, purely
167                  * emulate it through the inode.
168                  */
169                 acl_nfs4_sync_acl_from_mode(aclp, ip->i_mode, ip->i_uid);
170
171                 return (0);
172         }
173
174         if (error)
175                 return (error);
176
177         if (len != sizeof(*aclp)) {
178                 /*
179                  * A short (or long) read, meaning that for
180                  * some reason the ACL is corrupted.  Return
181                  * EPERM since the object DAC protections
182                  * are unsafe.
183                  */
184                 printf("ufs_getacl_nfs4(): Loaded invalid ACL ("
185                     "%d bytes), inumber %d on %s\n", len,
186                     ip->i_number, ip->i_fs->fs_fsmnt);
187
188                 return (EPERM);
189         }
190
191         error = acl_nfs4_check(aclp, vp->v_type == VDIR);
192         if (error) {
193                 printf("ufs_getacl_nfs4(): Loaded invalid ACL "
194                     "(failed acl_nfs4_check), inumber %d on %s\n",
195                     ip->i_number, ip->i_fs->fs_fsmnt);
196
197                 return (EPERM);
198         }
199
200         return (0);
201 }
202
203 static int
204 ufs_getacl_nfs4(struct vop_getacl_args *ap)
205 {
206         int error;
207
208         if ((ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS) == 0)
209                 return (EINVAL);
210
211         error = VOP_ACCESSX(ap->a_vp, VREAD_ACL, ap->a_td->td_ucred, ap->a_td);
212         if (error)
213                 return (error);
214
215         error = ufs_getacl_nfs4_internal(ap->a_vp, ap->a_aclp, ap->a_td);
216
217         return (error);
218 }
219
220 /*
221  * Read POSIX.1e ACL from an EA.  Return error if its not found
222  * or if any other error has occured.
223  */
224 static int
225 ufs_get_oldacl(acl_type_t type, struct oldacl *old, struct vnode *vp,
226     struct thread *td)
227 {
228         int error, len;
229         struct inode *ip = VTOI(vp);
230
231         len = sizeof(*old);
232
233         switch (type) {
234         case ACL_TYPE_ACCESS:
235                 error = vn_extattr_get(vp, IO_NODELOCKED,
236                     POSIX1E_ACL_ACCESS_EXTATTR_NAMESPACE,
237                     POSIX1E_ACL_ACCESS_EXTATTR_NAME, &len, (char *) old,
238                     td);
239                 break;
240         case ACL_TYPE_DEFAULT:
241                 if (vp->v_type != VDIR)
242                         return (EINVAL);
243                 error = vn_extattr_get(vp, IO_NODELOCKED,
244                     POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE,
245                     POSIX1E_ACL_DEFAULT_EXTATTR_NAME, &len, (char *) old,
246                     td);
247                 break;
248         default:
249                 return (EINVAL);
250         }
251
252         if (error != 0)
253                 return (error);
254
255         if (len != sizeof(*old)) {
256                 /*
257                  * A short (or long) read, meaning that for some reason
258                  * the ACL is corrupted.  Return EPERM since the object
259                  * DAC protections are unsafe.
260                  */
261                 printf("ufs_get_oldacl(): Loaded invalid ACL "
262                     "(len = %d), inumber %d on %s\n", len,
263                     ip->i_number, ip->i_fs->fs_fsmnt);
264                 return (EPERM);
265         }
266
267         return (0);
268 }
269
270 /*
271  * Retrieve the ACL on a file.
272  *
273  * As part of the ACL is stored in the inode, and the rest in an EA,
274  * assemble both into a final ACL product.  Right now this is not done
275  * very efficiently.
276  */
277 static int
278 ufs_getacl_posix1e(struct vop_getacl_args *ap)
279 {
280         struct inode *ip = VTOI(ap->a_vp);
281         int error;
282         struct oldacl *old;
283
284         /*
285          * XXX: If ufs_getacl() should work on file systems not supporting
286          * ACLs, remove this check.
287          */
288         if ((ap->a_vp->v_mount->mnt_flag & MNT_ACLS) == 0)
289                 return (EINVAL);
290
291         old = malloc(sizeof(*old), M_ACL, M_WAITOK | M_ZERO);
292
293         /*
294          * Attempt to retrieve the ACL from the extended attributes.
295          */
296         error = ufs_get_oldacl(ap->a_type, old, ap->a_vp, ap->a_td);
297         switch (error) {
298         /*
299          * XXX: If ufs_getacl() should work on filesystems
300          * without the EA configured, add case EOPNOTSUPP here.
301          */
302         case ENOATTR:
303                 switch (ap->a_type) {
304                 case ACL_TYPE_ACCESS:
305                         /*
306                          * Legitimately no ACL set on object, purely
307                          * emulate it through the inode.  These fields will
308                          * be updated when the ACL is synchronized with
309                          * the inode later.
310                          */
311                         old->acl_cnt = 3;
312                         old->acl_entry[0].ae_tag = ACL_USER_OBJ;
313                         old->acl_entry[0].ae_id = ACL_UNDEFINED_ID;
314                         old->acl_entry[0].ae_perm = ACL_PERM_NONE;
315                         old->acl_entry[1].ae_tag = ACL_GROUP_OBJ;
316                         old->acl_entry[1].ae_id = ACL_UNDEFINED_ID;
317                         old->acl_entry[1].ae_perm = ACL_PERM_NONE;
318                         old->acl_entry[2].ae_tag = ACL_OTHER;
319                         old->acl_entry[2].ae_id = ACL_UNDEFINED_ID;
320                         old->acl_entry[2].ae_perm = ACL_PERM_NONE;
321                         break;
322
323                 case ACL_TYPE_DEFAULT:
324                         /*
325                          * Unlike ACL_TYPE_ACCESS, there is no relationship
326                          * between the inode contents and the ACL, and it is
327                          * therefore possible for the request for the ACL
328                          * to fail since the ACL is undefined.  In this
329                          * situation, return success and an empty ACL,
330                          * as required by POSIX.1e.
331                          */
332                         old->acl_cnt = 0;
333                         break;
334                 }
335                 /* FALLTHROUGH */
336         case 0:
337                 error = acl_copy_oldacl_into_acl(old, ap->a_aclp);
338                 if (error != 0)
339                         break;
340
341                 if (ap->a_type == ACL_TYPE_ACCESS)
342                         ufs_sync_acl_from_inode(ip, ap->a_aclp);
343         default:
344                 break;
345         }
346
347         free(old, M_ACL);
348         return (error);
349 }
350
351 int
352 ufs_getacl(ap)
353         struct vop_getacl_args /* {
354                 struct vnode *vp;
355                 acl_type_t type;
356                 struct acl *aclp;
357                 struct ucred *cred;
358                 struct thread *td;
359         } */ *ap;
360 {
361
362         if ((ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) == 0)
363                 return (EOPNOTSUPP);
364
365         if (ap->a_type == ACL_TYPE_NFS4)
366                 return (ufs_getacl_nfs4(ap));
367
368         return (ufs_getacl_posix1e(ap));
369 }
370
371 /*
372  * Set NFSv4 ACL without doing any access checking.  This is required
373  * e.g. by the UFS code that implements ACL inheritance, or from
374  * ufs_vnops.c:ufs_chmod(), as some of the checks have to be skipped
375  * in that case, and others are redundant.
376  */
377 int
378 ufs_setacl_nfs4_internal(struct vnode *vp, struct acl *aclp, struct thread *td)
379 {
380         int error;
381         mode_t mode;
382         struct inode *ip = VTOI(vp);
383
384         KASSERT(acl_nfs4_check(aclp, vp->v_type == VDIR) == 0,
385             ("invalid ACL passed to ufs_setacl_nfs4_internal"));
386
387         if (acl_nfs4_is_trivial(aclp, ip->i_uid)) {
388                 error = vn_extattr_rm(vp, IO_NODELOCKED,
389                     NFS4_ACL_EXTATTR_NAMESPACE, NFS4_ACL_EXTATTR_NAME, td);
390
391                 /*
392                  * An attempt to remove ACL from a file that didn't have
393                  * any extended entries is not an error.
394                  */
395                 if (error == ENOATTR)
396                         error = 0;
397
398         } else {
399                 error = vn_extattr_set(vp, IO_NODELOCKED,
400                     NFS4_ACL_EXTATTR_NAMESPACE, NFS4_ACL_EXTATTR_NAME,
401                     sizeof(*aclp), (char *) aclp, td);
402         }
403
404         /*
405          * Map lack of attribute definition in UFS_EXTATTR into lack of
406          * support for ACLs on the filesystem.
407          */
408         if (error == ENOATTR)
409                 return (EOPNOTSUPP);
410
411         if (error)
412                 return (error);
413
414         mode = ip->i_mode;
415
416         acl_nfs4_sync_mode_from_acl(&mode, aclp);
417
418         ip->i_mode &= ACL_PRESERVE_MASK;
419         ip->i_mode |= mode;
420         DIP_SET(ip, i_mode, ip->i_mode);
421         ip->i_flag |= IN_CHANGE;
422
423         VN_KNOTE_UNLOCKED(vp, NOTE_ATTRIB);
424
425         return (0);
426 }
427
428 static int
429 ufs_setacl_nfs4(struct vop_setacl_args *ap)
430 {
431         int error;
432         struct inode *ip = VTOI(ap->a_vp);
433
434         if ((ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS) == 0)
435                 return (EINVAL);
436
437         if (ap->a_vp->v_mount->mnt_flag & MNT_RDONLY)
438                 return (EROFS);
439
440         if (ap->a_aclp == NULL)
441                 return (EINVAL);
442
443         error = VOP_ACLCHECK(ap->a_vp, ap->a_type, ap->a_aclp, ap->a_cred,
444             ap->a_td);
445         if (error)
446                 return (error);
447
448         /*
449          * Authorize the ACL operation.
450          */
451         if (ip->i_flags & (IMMUTABLE | APPEND))
452                 return (EPERM);
453
454         /*
455          * Must hold VWRITE_ACL or have appropriate privilege.
456          */
457         if ((error = VOP_ACCESSX(ap->a_vp, VWRITE_ACL, ap->a_cred, ap->a_td)))
458                 return (error);
459
460         /*
461          * With NFSv4 ACLs, chmod(2) may need to add additional entries.
462          * Make sure it has enough room for that - splitting every entry
463          * into two and appending "canonical six" entries at the end.
464          */
465         if (ap->a_aclp->acl_cnt > (ACL_MAX_ENTRIES - 6) / 2)
466                 return (ENOSPC);
467
468         error = ufs_setacl_nfs4_internal(ap->a_vp, ap->a_aclp, ap->a_td);
469
470         return (error);
471 }
472
473 /*
474  * Set the ACL on a file.
475  *
476  * As part of the ACL is stored in the inode, and the rest in an EA,
477  * this is necessarily non-atomic, and has complex authorization.
478  * As ufs_setacl() includes elements of ufs_chown() and ufs_chmod(),
479  * a fair number of different access checks may be required to go ahead
480  * with the operation at all.
481  */
482 static int
483 ufs_setacl_posix1e(struct vop_setacl_args *ap)
484 {
485         struct inode *ip = VTOI(ap->a_vp);
486         int error;
487         struct oldacl *old;
488
489         if ((ap->a_vp->v_mount->mnt_flag & MNT_ACLS) == 0)
490                 return (EINVAL);
491
492         /*
493          * If this is a set operation rather than a delete operation,
494          * invoke VOP_ACLCHECK() on the passed ACL to determine if it is
495          * valid for the target.  This will include a check on ap->a_type.
496          */
497         if (ap->a_aclp != NULL) {
498                 /*
499                  * Set operation.
500                  */
501                 error = VOP_ACLCHECK(ap->a_vp, ap->a_type, ap->a_aclp,
502                     ap->a_cred, ap->a_td);
503                 if (error != 0)
504                         return (error);
505         } else {
506                 /*
507                  * Delete operation.
508                  * POSIX.1e allows only deletion of the default ACL on a
509                  * directory (ACL_TYPE_DEFAULT).
510                  */
511                 if (ap->a_type != ACL_TYPE_DEFAULT)
512                         return (EINVAL);
513                 if (ap->a_vp->v_type != VDIR)
514                         return (ENOTDIR);
515         }
516
517         if (ap->a_vp->v_mount->mnt_flag & MNT_RDONLY)
518                 return (EROFS);
519
520         /*
521          * Authorize the ACL operation.
522          */
523         if (ip->i_flags & (IMMUTABLE | APPEND))
524                 return (EPERM);
525
526         /*
527          * Must hold VADMIN (be file owner) or have appropriate privilege.
528          */
529         if ((error = VOP_ACCESS(ap->a_vp, VADMIN, ap->a_cred, ap->a_td)))
530                 return (error);
531
532         switch(ap->a_type) {
533         case ACL_TYPE_ACCESS:
534                 old = malloc(sizeof(*old), M_ACL, M_WAITOK | M_ZERO);
535                 error = acl_copy_acl_into_oldacl(ap->a_aclp, old);
536                 if (error == 0) {
537                         error = vn_extattr_set(ap->a_vp, IO_NODELOCKED,
538                             POSIX1E_ACL_ACCESS_EXTATTR_NAMESPACE,
539                             POSIX1E_ACL_ACCESS_EXTATTR_NAME, sizeof(*old),
540                             (char *) old, ap->a_td);
541                 }
542                 free(old, M_ACL);
543                 break;
544
545         case ACL_TYPE_DEFAULT:
546                 if (ap->a_aclp == NULL) {
547                         error = vn_extattr_rm(ap->a_vp, IO_NODELOCKED,
548                             POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE,
549                             POSIX1E_ACL_DEFAULT_EXTATTR_NAME, ap->a_td);
550                         /*
551                          * Attempting to delete a non-present default ACL
552                          * will return success for portability purposes.
553                          * (TRIX)
554                          *
555                          * XXX: Note that since we can't distinguish
556                          * "that EA is not supported" from "that EA is not
557                          * defined", the success case here overlaps the
558                          * the ENOATTR->EOPNOTSUPP case below.
559                          */
560                         if (error == ENOATTR)
561                                 error = 0;
562                 } else {
563                         old = malloc(sizeof(*old), M_ACL, M_WAITOK | M_ZERO);
564                         error = acl_copy_acl_into_oldacl(ap->a_aclp, old);
565                         if (error == 0) {
566                                 error = vn_extattr_set(ap->a_vp, IO_NODELOCKED,
567                                     POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE,
568                                     POSIX1E_ACL_DEFAULT_EXTATTR_NAME,
569                                     sizeof(*old), (char *) old, ap->a_td);
570                         }
571                         free(old, M_ACL);
572                 }
573                 break;
574
575         default:
576                 error = EINVAL;
577         }
578         /*
579          * Map lack of attribute definition in UFS_EXTATTR into lack of
580          * support for ACLs on the filesystem.
581          */
582         if (error == ENOATTR)
583                 return (EOPNOTSUPP);
584         if (error != 0)
585                 return (error);
586
587         if (ap->a_type == ACL_TYPE_ACCESS) {
588                 /*
589                  * Now that the EA is successfully updated, update the
590                  * inode and mark it as changed.
591                  */
592                 ufs_sync_inode_from_acl(ap->a_aclp, ip);
593                 ip->i_flag |= IN_CHANGE;
594         }
595
596         VN_KNOTE_UNLOCKED(ap->a_vp, NOTE_ATTRIB);
597         return (0);
598 }
599
600 int
601 ufs_setacl(ap)
602         struct vop_setacl_args /* {
603                 struct vnode *vp;
604                 acl_type_t type;
605                 struct acl *aclp;
606                 struct ucred *cred;
607                 struct thread *td;
608         } */ *ap;
609 {
610         if ((ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) == 0)
611                 return (EOPNOTSUPP);
612
613         if (ap->a_type == ACL_TYPE_NFS4)
614                 return (ufs_setacl_nfs4(ap));
615
616         return (ufs_setacl_posix1e(ap));
617 }
618
619 static int
620 ufs_aclcheck_nfs4(struct vop_aclcheck_args *ap)
621 {
622         int is_directory = 0;
623
624         if ((ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS) == 0)
625                 return (EINVAL);
626
627         /*
628          * With NFSv4 ACLs, chmod(2) may need to add additional entries.
629          * Make sure it has enough room for that - splitting every entry
630          * into two and appending "canonical six" entries at the end.
631          */
632         if (ap->a_aclp->acl_cnt > (ACL_MAX_ENTRIES - 6) / 2)
633                 return (ENOSPC);
634
635         if (ap->a_vp->v_type == VDIR)
636                 is_directory = 1;
637
638         return (acl_nfs4_check(ap->a_aclp, is_directory));
639 }
640
641 static int
642 ufs_aclcheck_posix1e(struct vop_aclcheck_args *ap)
643 {
644
645         if ((ap->a_vp->v_mount->mnt_flag & MNT_ACLS) == 0)
646                 return (EINVAL);
647
648         /*
649          * Verify we understand this type of ACL, and that it applies
650          * to this kind of object.
651          * Rely on the acl_posix1e_check() routine to verify the contents.
652          */
653         switch(ap->a_type) {
654         case ACL_TYPE_ACCESS:
655                 break;
656
657         case ACL_TYPE_DEFAULT:
658                 if (ap->a_vp->v_type != VDIR)
659                         return (EINVAL);
660                 break;
661
662         default:
663                 return (EINVAL);
664         }
665
666         if (ap->a_aclp->acl_cnt > OLDACL_MAX_ENTRIES)
667                 return (EINVAL);
668
669         return (acl_posix1e_check(ap->a_aclp));
670 }
671
672 /*
673  * Check the validity of an ACL for a file.
674  */
675 int
676 ufs_aclcheck(ap)
677         struct vop_aclcheck_args /* {
678                 struct vnode *vp;
679                 acl_type_t type;
680                 struct acl *aclp;
681                 struct ucred *cred;
682                 struct thread *td;
683         } */ *ap;
684 {
685
686         if ((ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) == 0)
687                 return (EOPNOTSUPP);
688
689         if (ap->a_type == ACL_TYPE_NFS4)
690                 return (ufs_aclcheck_nfs4(ap));
691
692         return (ufs_aclcheck_posix1e(ap));
693 }
694
695 #endif /* !UFS_ACL */