Import 2.3.1pre2
[davej-history.git] / fs / ufs / acl.c
blobb002d33987856d4a980de835319a14cea7cf81a6
1 /*
2 * linux/fs/ufs/acl.c
4 * Copyright (C) 1998
5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
8 * from
10 * linux/fs/ext2/acl.c
12 * Copyright (C) 1993, 1994, 1995
13 * Remy Card (card@masi.ibp.fr)
14 * Laboratoire MASI - Institut Blaise Pascal
15 * Universite Pierre et Marie Curie (Paris VI)
19 * This file will contain the Access Control Lists management for UFS
22 #include <linux/errno.h>
23 #include <linux/fs.h>
24 #include <linux/ufs_fs.h>
25 #include <linux/sched.h>
26 #include <linux/stat.h>
29 * ufs_permission ()
31 * Check for access rights
33 int ufs_permission (struct inode * inode, int mask)
35 unsigned short mode = inode->i_mode;
38 * Nobody gets write access to a file on a readonly-fs
40 if ((mask & S_IWOTH) &&
41 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) &&
42 IS_RDONLY(inode))
43 return -EROFS;
45 * Nobody gets write access to an immutable file
47 if ((mask & S_IWOTH) && IS_IMMUTABLE(inode))
48 return -EACCES;
51 * If no ACL, checks using the file mode
53 else if (current->fsuid == inode->i_uid)
54 mode >>= 6;
55 else if (in_group_p (inode->i_gid))
56 mode >>= 3;
58 * Access is always granted for root. We now check last,
59 * though, for BSD process accounting correctness
61 if (((mode & mask & S_IRWXO) == mask) || capable(CAP_DAC_OVERRIDE))
62 return 0;
63 if ((mask == S_IROTH) ||
64 (S_ISDIR(mode) && !(mask & ~(S_IROTH | S_IXOTH))))
65 if (capable(CAP_DAC_READ_SEARCH))
66 return 0;
67 return -EACCES;