Commit | Line | Data |
---|---|---|
b11be056 | 1 | /* vfs_vnops.c 6.1 83/07/29 */ |
961945a8 SL |
2 | |
3 | #include "../machine/reg.h" | |
fc96c615 BJ |
4 | |
5 | #include "../h/param.h" | |
6 | #include "../h/systm.h" | |
7 | #include "../h/dir.h" | |
8 | #include "../h/user.h" | |
6459ebe0 | 9 | #include "../h/fs.h" |
fc96c615 BJ |
10 | #include "../h/file.h" |
11 | #include "../h/conf.h" | |
12 | #include "../h/inode.h" | |
fc96c615 | 13 | #include "../h/acct.h" |
f5b8937b | 14 | #include "../h/mount.h" |
ae921915 BJ |
15 | #include "../h/socket.h" |
16 | #include "../h/socketvar.h" | |
f3156a73 | 17 | #include "../h/proc.h" |
4f083fd7 | 18 | #include "../h/nami.h" |
fc96c615 | 19 | |
fc96c615 BJ |
20 | /* |
21 | * Check mode permission on inode pointer. | |
22 | * Mode is READ, WRITE or EXEC. | |
23 | * In the case of WRITE, the | |
24 | * read-only status of the file | |
25 | * system is checked. | |
26 | * Also in WRITE, prototype text | |
27 | * segments cannot be written. | |
28 | * The mode is shifted to select | |
29 | * the owner/group/other fields. | |
30 | * The super user is granted all | |
31 | * permissions. | |
32 | */ | |
33 | access(ip, mode) | |
fdd90ee3 BJ |
34 | register struct inode *ip; |
35 | int mode; | |
fc96c615 BJ |
36 | { |
37 | register m; | |
197da11b | 38 | register int *gp; |
fc96c615 BJ |
39 | |
40 | m = mode; | |
fdd90ee3 | 41 | if (m == IWRITE) { |
40123f2c SL |
42 | /* |
43 | * Disallow write attempts on read-only | |
44 | * file systems; unless the file is a block | |
45 | * or character device resident on the | |
46 | * file system. | |
47 | */ | |
6459ebe0 | 48 | if (ip->i_fs->fs_ronly != 0) { |
77cc8249 BJ |
49 | if ((ip->i_mode & IFMT) != IFCHR && |
50 | (ip->i_mode & IFMT) != IFBLK) { | |
51 | u.u_error = EROFS; | |
52 | return (1); | |
53 | } | |
fc96c615 | 54 | } |
40123f2c SL |
55 | /* |
56 | * If there's shared text associated with | |
57 | * the inode, try to free it up once. If | |
58 | * we fail, we can't allow writing. | |
59 | */ | |
60 | if (ip->i_flag&ITEXT) | |
fc96c615 | 61 | xrele(ip); |
fdd90ee3 | 62 | if (ip->i_flag & ITEXT) { |
fc96c615 | 63 | u.u_error = ETXTBSY; |
fdd90ee3 | 64 | return (1); |
fc96c615 BJ |
65 | } |
66 | } | |
40123f2c SL |
67 | /* |
68 | * If you're the super-user, | |
69 | * you always get access. | |
70 | */ | |
fdd90ee3 BJ |
71 | if (u.u_uid == 0) |
72 | return (0); | |
40123f2c SL |
73 | /* |
74 | * Access check is based on only | |
75 | * one of owner, group, public. | |
76 | * If not owner, then check group. | |
77 | * If not a member of the group, then | |
78 | * check public access. | |
79 | */ | |
fdd90ee3 | 80 | if (u.u_uid != ip->i_uid) { |
fc96c615 | 81 | m >>= 3; |
40123f2c SL |
82 | if (u.u_gid == ip->i_gid) |
83 | goto found; | |
8f3338c3 SL |
84 | gp = u.u_groups; |
85 | for (; gp < &u.u_groups[NGROUPS] && *gp != NOGROUP; gp++) | |
4060c051 | 86 | if (ip->i_gid == *gp) |
197da11b BJ |
87 | goto found; |
88 | m >>= 3; | |
89 | found: | |
90 | ; | |
fc96c615 | 91 | } |
fdd90ee3 BJ |
92 | if ((ip->i_mode&m) != 0) |
93 | return (0); | |
fc96c615 | 94 | u.u_error = EACCES; |
fdd90ee3 | 95 | return (1); |
fc96c615 BJ |
96 | } |
97 | ||
98 | /* | |
99 | * Look up a pathname and test if | |
100 | * the resultant inode is owned by the | |
101 | * current user. | |
102 | * If not, try for super-user. | |
103 | * If permission is granted, | |
104 | * return inode pointer. | |
105 | */ | |
106 | struct inode * | |
5485e062 BJ |
107 | owner(follow) |
108 | int follow; | |
fc96c615 BJ |
109 | { |
110 | register struct inode *ip; | |
111 | ||
4f083fd7 | 112 | ip = namei(uchar, LOOKUP, follow); |
fdd90ee3 BJ |
113 | if (ip == NULL) |
114 | return (NULL); | |
115 | if (u.u_uid == ip->i_uid) | |
116 | return (ip); | |
117 | if (suser()) | |
118 | return (ip); | |
fc96c615 | 119 | iput(ip); |
fdd90ee3 | 120 | return (NULL); |
fc96c615 BJ |
121 | } |
122 | ||
123 | /* | |
124 | * Test if the current user is the | |
125 | * super user. | |
126 | */ | |
127 | suser() | |
128 | { | |
129 | ||
fdd90ee3 | 130 | if (u.u_uid == 0) { |
fc96c615 | 131 | u.u_acflag |= ASU; |
fdd90ee3 | 132 | return (1); |
fc96c615 BJ |
133 | } |
134 | u.u_error = EPERM; | |
fdd90ee3 | 135 | return (0); |
fc96c615 | 136 | } |