Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/posix_acl.c |
| 3 | * |
| 4 | * Copyright (C) 2002 by Andreas Gruenbacher <a.gruenbacher@computer.org> |
| 5 | * |
| 6 | * Fixes from William Schumacher incorporated on 15 March 2001. |
| 7 | * (Reported by Charles Bertsch, <CBertsch@microtest.com>). |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * This file contains generic functions for manipulating |
| 12 | * POSIX 1003.1e draft standard 17 ACLs. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/slab.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 17 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/fs.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/posix_acl.h> |
Paul Gortmaker | 630d9c4 | 2011-11-16 23:57:37 -0500 | [diff] [blame] | 21 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include <linux/errno.h> |
| 24 | |
Andrew Morton | 0afaa12 | 2014-01-21 15:48:42 -0800 | [diff] [blame] | 25 | struct posix_acl **acl_by_type(struct inode *inode, int type) |
| 26 | { |
| 27 | switch (type) { |
| 28 | case ACL_TYPE_ACCESS: |
| 29 | return &inode->i_acl; |
| 30 | case ACL_TYPE_DEFAULT: |
| 31 | return &inode->i_default_acl; |
| 32 | default: |
| 33 | BUG(); |
| 34 | } |
| 35 | } |
| 36 | EXPORT_SYMBOL(acl_by_type); |
| 37 | |
| 38 | struct posix_acl *get_cached_acl(struct inode *inode, int type) |
| 39 | { |
| 40 | struct posix_acl **p = acl_by_type(inode, type); |
| 41 | struct posix_acl *acl = ACCESS_ONCE(*p); |
| 42 | if (acl) { |
| 43 | spin_lock(&inode->i_lock); |
| 44 | acl = *p; |
| 45 | if (acl != ACL_NOT_CACHED) |
| 46 | acl = posix_acl_dup(acl); |
| 47 | spin_unlock(&inode->i_lock); |
| 48 | } |
| 49 | return acl; |
| 50 | } |
| 51 | EXPORT_SYMBOL(get_cached_acl); |
| 52 | |
| 53 | struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type) |
| 54 | { |
| 55 | return rcu_dereference(*acl_by_type(inode, type)); |
| 56 | } |
| 57 | EXPORT_SYMBOL(get_cached_acl_rcu); |
| 58 | |
| 59 | void set_cached_acl(struct inode *inode, int type, struct posix_acl *acl) |
| 60 | { |
| 61 | struct posix_acl **p = acl_by_type(inode, type); |
| 62 | struct posix_acl *old; |
| 63 | spin_lock(&inode->i_lock); |
| 64 | old = *p; |
| 65 | rcu_assign_pointer(*p, posix_acl_dup(acl)); |
| 66 | spin_unlock(&inode->i_lock); |
| 67 | if (old != ACL_NOT_CACHED) |
| 68 | posix_acl_release(old); |
| 69 | } |
| 70 | EXPORT_SYMBOL(set_cached_acl); |
| 71 | |
| 72 | void forget_cached_acl(struct inode *inode, int type) |
| 73 | { |
| 74 | struct posix_acl **p = acl_by_type(inode, type); |
| 75 | struct posix_acl *old; |
| 76 | spin_lock(&inode->i_lock); |
| 77 | old = *p; |
| 78 | *p = ACL_NOT_CACHED; |
| 79 | spin_unlock(&inode->i_lock); |
| 80 | if (old != ACL_NOT_CACHED) |
| 81 | posix_acl_release(old); |
| 82 | } |
| 83 | EXPORT_SYMBOL(forget_cached_acl); |
| 84 | |
| 85 | void forget_all_cached_acls(struct inode *inode) |
| 86 | { |
| 87 | struct posix_acl *old_access, *old_default; |
| 88 | spin_lock(&inode->i_lock); |
| 89 | old_access = inode->i_acl; |
| 90 | old_default = inode->i_default_acl; |
| 91 | inode->i_acl = inode->i_default_acl = ACL_NOT_CACHED; |
| 92 | spin_unlock(&inode->i_lock); |
| 93 | if (old_access != ACL_NOT_CACHED) |
| 94 | posix_acl_release(old_access); |
| 95 | if (old_default != ACL_NOT_CACHED) |
| 96 | posix_acl_release(old_default); |
| 97 | } |
| 98 | EXPORT_SYMBOL(forget_all_cached_acls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* |
Chuck Lever | f61f6da | 2011-01-21 03:05:38 +0000 | [diff] [blame] | 101 | * Init a fresh posix_acl |
| 102 | */ |
| 103 | void |
| 104 | posix_acl_init(struct posix_acl *acl, int count) |
| 105 | { |
| 106 | atomic_set(&acl->a_refcount, 1); |
| 107 | acl->a_count = count; |
| 108 | } |
Andrew Morton | 0afaa12 | 2014-01-21 15:48:42 -0800 | [diff] [blame] | 109 | EXPORT_SYMBOL(posix_acl_init); |
Chuck Lever | f61f6da | 2011-01-21 03:05:38 +0000 | [diff] [blame] | 110 | |
| 111 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * Allocate a new ACL with the specified number of entries. |
| 113 | */ |
| 114 | struct posix_acl * |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 115 | posix_acl_alloc(int count, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
| 117 | const size_t size = sizeof(struct posix_acl) + |
| 118 | count * sizeof(struct posix_acl_entry); |
| 119 | struct posix_acl *acl = kmalloc(size, flags); |
Chuck Lever | f61f6da | 2011-01-21 03:05:38 +0000 | [diff] [blame] | 120 | if (acl) |
| 121 | posix_acl_init(acl, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return acl; |
| 123 | } |
Andrew Morton | 0afaa12 | 2014-01-21 15:48:42 -0800 | [diff] [blame] | 124 | EXPORT_SYMBOL(posix_acl_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * Clone an ACL. |
| 128 | */ |
Al Viro | edde854 | 2011-07-23 03:27:37 -0400 | [diff] [blame] | 129 | static struct posix_acl * |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 130 | posix_acl_clone(const struct posix_acl *acl, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
| 132 | struct posix_acl *clone = NULL; |
| 133 | |
| 134 | if (acl) { |
| 135 | int size = sizeof(struct posix_acl) + acl->a_count * |
| 136 | sizeof(struct posix_acl_entry); |
Alexey Dobriyan | 52978be | 2006-09-30 23:27:21 -0700 | [diff] [blame] | 137 | clone = kmemdup(acl, size, flags); |
| 138 | if (clone) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | atomic_set(&clone->a_refcount, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | return clone; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Check if an acl is valid. Returns 0 if it is, or -E... otherwise. |
| 146 | */ |
| 147 | int |
| 148 | posix_acl_valid(const struct posix_acl *acl) |
| 149 | { |
| 150 | const struct posix_acl_entry *pa, *pe; |
| 151 | int state = ACL_USER_OBJ; |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 152 | kuid_t prev_uid = INVALID_UID; |
| 153 | kgid_t prev_gid = INVALID_GID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | int needs_mask = 0; |
| 155 | |
| 156 | FOREACH_ACL_ENTRY(pa, acl, pe) { |
| 157 | if (pa->e_perm & ~(ACL_READ|ACL_WRITE|ACL_EXECUTE)) |
| 158 | return -EINVAL; |
| 159 | switch (pa->e_tag) { |
| 160 | case ACL_USER_OBJ: |
| 161 | if (state == ACL_USER_OBJ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | state = ACL_USER; |
| 163 | break; |
| 164 | } |
| 165 | return -EINVAL; |
| 166 | |
| 167 | case ACL_USER: |
| 168 | if (state != ACL_USER) |
| 169 | return -EINVAL; |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 170 | if (!uid_valid(pa->e_uid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | return -EINVAL; |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 172 | if (uid_valid(prev_uid) && |
| 173 | uid_lte(pa->e_uid, prev_uid)) |
| 174 | return -EINVAL; |
| 175 | prev_uid = pa->e_uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | needs_mask = 1; |
| 177 | break; |
| 178 | |
| 179 | case ACL_GROUP_OBJ: |
| 180 | if (state == ACL_USER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | state = ACL_GROUP; |
| 182 | break; |
| 183 | } |
| 184 | return -EINVAL; |
| 185 | |
| 186 | case ACL_GROUP: |
| 187 | if (state != ACL_GROUP) |
| 188 | return -EINVAL; |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 189 | if (!gid_valid(pa->e_gid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return -EINVAL; |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 191 | if (gid_valid(prev_gid) && |
| 192 | gid_lte(pa->e_gid, prev_gid)) |
| 193 | return -EINVAL; |
| 194 | prev_gid = pa->e_gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | needs_mask = 1; |
| 196 | break; |
| 197 | |
| 198 | case ACL_MASK: |
| 199 | if (state != ACL_GROUP) |
| 200 | return -EINVAL; |
| 201 | state = ACL_OTHER; |
| 202 | break; |
| 203 | |
| 204 | case ACL_OTHER: |
| 205 | if (state == ACL_OTHER || |
| 206 | (state == ACL_GROUP && !needs_mask)) { |
| 207 | state = 0; |
| 208 | break; |
| 209 | } |
| 210 | return -EINVAL; |
| 211 | |
| 212 | default: |
| 213 | return -EINVAL; |
| 214 | } |
| 215 | } |
| 216 | if (state == 0) |
| 217 | return 0; |
| 218 | return -EINVAL; |
| 219 | } |
Andrew Morton | 0afaa12 | 2014-01-21 15:48:42 -0800 | [diff] [blame] | 220 | EXPORT_SYMBOL(posix_acl_valid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | /* |
| 223 | * Returns 0 if the acl can be exactly represented in the traditional |
| 224 | * file mode permission bits, or else 1. Returns -E... on error. |
| 225 | */ |
| 226 | int |
Al Viro | d695212 | 2011-07-23 18:56:36 -0400 | [diff] [blame] | 227 | posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
| 229 | const struct posix_acl_entry *pa, *pe; |
Al Viro | d695212 | 2011-07-23 18:56:36 -0400 | [diff] [blame] | 230 | umode_t mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | int not_equiv = 0; |
| 232 | |
| 233 | FOREACH_ACL_ENTRY(pa, acl, pe) { |
| 234 | switch (pa->e_tag) { |
| 235 | case ACL_USER_OBJ: |
| 236 | mode |= (pa->e_perm & S_IRWXO) << 6; |
| 237 | break; |
| 238 | case ACL_GROUP_OBJ: |
| 239 | mode |= (pa->e_perm & S_IRWXO) << 3; |
| 240 | break; |
| 241 | case ACL_OTHER: |
| 242 | mode |= pa->e_perm & S_IRWXO; |
| 243 | break; |
| 244 | case ACL_MASK: |
| 245 | mode = (mode & ~S_IRWXG) | |
| 246 | ((pa->e_perm & S_IRWXO) << 3); |
| 247 | not_equiv = 1; |
| 248 | break; |
| 249 | case ACL_USER: |
| 250 | case ACL_GROUP: |
| 251 | not_equiv = 1; |
| 252 | break; |
| 253 | default: |
| 254 | return -EINVAL; |
| 255 | } |
| 256 | } |
| 257 | if (mode_p) |
| 258 | *mode_p = (*mode_p & ~S_IRWXUGO) | mode; |
| 259 | return not_equiv; |
| 260 | } |
Andrew Morton | 0afaa12 | 2014-01-21 15:48:42 -0800 | [diff] [blame] | 261 | EXPORT_SYMBOL(posix_acl_equiv_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | /* |
| 264 | * Create an ACL representing the file mode permission bits of an inode. |
| 265 | */ |
| 266 | struct posix_acl * |
Al Viro | 3a5fba1 | 2011-07-23 19:01:48 -0400 | [diff] [blame] | 267 | posix_acl_from_mode(umode_t mode, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
| 269 | struct posix_acl *acl = posix_acl_alloc(3, flags); |
| 270 | if (!acl) |
| 271 | return ERR_PTR(-ENOMEM); |
| 272 | |
| 273 | acl->a_entries[0].e_tag = ACL_USER_OBJ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | acl->a_entries[0].e_perm = (mode & S_IRWXU) >> 6; |
| 275 | |
| 276 | acl->a_entries[1].e_tag = ACL_GROUP_OBJ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | acl->a_entries[1].e_perm = (mode & S_IRWXG) >> 3; |
| 278 | |
| 279 | acl->a_entries[2].e_tag = ACL_OTHER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | acl->a_entries[2].e_perm = (mode & S_IRWXO); |
| 281 | return acl; |
| 282 | } |
Andrew Morton | 0afaa12 | 2014-01-21 15:48:42 -0800 | [diff] [blame] | 283 | EXPORT_SYMBOL(posix_acl_from_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * Return 0 if current is granted want access to the inode |
| 287 | * by the acl. Returns -E... otherwise. |
| 288 | */ |
| 289 | int |
| 290 | posix_acl_permission(struct inode *inode, const struct posix_acl *acl, int want) |
| 291 | { |
| 292 | const struct posix_acl_entry *pa, *pe, *mask_obj; |
| 293 | int found = 0; |
| 294 | |
Andreas Gruenbacher | d124b60 | 2011-10-23 23:13:32 +0530 | [diff] [blame] | 295 | want &= MAY_READ | MAY_WRITE | MAY_EXEC | MAY_NOT_BLOCK; |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | FOREACH_ACL_ENTRY(pa, acl, pe) { |
| 298 | switch(pa->e_tag) { |
| 299 | case ACL_USER_OBJ: |
| 300 | /* (May have been checked already) */ |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 301 | if (uid_eq(inode->i_uid, current_fsuid())) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | goto check_perm; |
| 303 | break; |
| 304 | case ACL_USER: |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 305 | if (uid_eq(pa->e_uid, current_fsuid())) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | goto mask; |
| 307 | break; |
| 308 | case ACL_GROUP_OBJ: |
| 309 | if (in_group_p(inode->i_gid)) { |
| 310 | found = 1; |
| 311 | if ((pa->e_perm & want) == want) |
| 312 | goto mask; |
| 313 | } |
| 314 | break; |
| 315 | case ACL_GROUP: |
Eric W. Biederman | 2f6f065 | 2012-02-07 18:52:57 -0800 | [diff] [blame] | 316 | if (in_group_p(pa->e_gid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | found = 1; |
| 318 | if ((pa->e_perm & want) == want) |
| 319 | goto mask; |
| 320 | } |
| 321 | break; |
| 322 | case ACL_MASK: |
| 323 | break; |
| 324 | case ACL_OTHER: |
| 325 | if (found) |
| 326 | return -EACCES; |
| 327 | else |
| 328 | goto check_perm; |
| 329 | default: |
| 330 | return -EIO; |
| 331 | } |
| 332 | } |
| 333 | return -EIO; |
| 334 | |
| 335 | mask: |
| 336 | for (mask_obj = pa+1; mask_obj != pe; mask_obj++) { |
| 337 | if (mask_obj->e_tag == ACL_MASK) { |
| 338 | if ((pa->e_perm & mask_obj->e_perm & want) == want) |
| 339 | return 0; |
| 340 | return -EACCES; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | check_perm: |
| 345 | if ((pa->e_perm & want) == want) |
| 346 | return 0; |
| 347 | return -EACCES; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Modify acl when creating a new inode. The caller must ensure the acl is |
| 352 | * only referenced once. |
| 353 | * |
| 354 | * mode_p initially must contain the mode parameter to the open() / creat() |
| 355 | * system calls. All permissions that are not granted by the acl are removed. |
| 356 | * The permissions in the acl are changed to reflect the mode_p parameter. |
| 357 | */ |
Al Viro | d3fb612 | 2011-07-23 18:37:50 -0400 | [diff] [blame] | 358 | static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
| 360 | struct posix_acl_entry *pa, *pe; |
| 361 | struct posix_acl_entry *group_obj = NULL, *mask_obj = NULL; |
Al Viro | d3fb612 | 2011-07-23 18:37:50 -0400 | [diff] [blame] | 362 | umode_t mode = *mode_p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | int not_equiv = 0; |
| 364 | |
| 365 | /* assert(atomic_read(acl->a_refcount) == 1); */ |
| 366 | |
| 367 | FOREACH_ACL_ENTRY(pa, acl, pe) { |
| 368 | switch(pa->e_tag) { |
| 369 | case ACL_USER_OBJ: |
| 370 | pa->e_perm &= (mode >> 6) | ~S_IRWXO; |
| 371 | mode &= (pa->e_perm << 6) | ~S_IRWXU; |
| 372 | break; |
| 373 | |
| 374 | case ACL_USER: |
| 375 | case ACL_GROUP: |
| 376 | not_equiv = 1; |
| 377 | break; |
| 378 | |
| 379 | case ACL_GROUP_OBJ: |
| 380 | group_obj = pa; |
| 381 | break; |
| 382 | |
| 383 | case ACL_OTHER: |
| 384 | pa->e_perm &= mode | ~S_IRWXO; |
| 385 | mode &= pa->e_perm | ~S_IRWXO; |
| 386 | break; |
| 387 | |
| 388 | case ACL_MASK: |
| 389 | mask_obj = pa; |
| 390 | not_equiv = 1; |
| 391 | break; |
| 392 | |
| 393 | default: |
| 394 | return -EIO; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | if (mask_obj) { |
| 399 | mask_obj->e_perm &= (mode >> 3) | ~S_IRWXO; |
| 400 | mode &= (mask_obj->e_perm << 3) | ~S_IRWXG; |
| 401 | } else { |
| 402 | if (!group_obj) |
| 403 | return -EIO; |
| 404 | group_obj->e_perm &= (mode >> 3) | ~S_IRWXO; |
| 405 | mode &= (group_obj->e_perm << 3) | ~S_IRWXG; |
| 406 | } |
| 407 | |
| 408 | *mode_p = (*mode_p & ~S_IRWXUGO) | mode; |
| 409 | return not_equiv; |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * Modify the ACL for the chmod syscall. |
| 414 | */ |
Al Viro | 86bc704 | 2011-07-23 19:03:11 -0400 | [diff] [blame] | 415 | static int posix_acl_chmod_masq(struct posix_acl *acl, umode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
| 417 | struct posix_acl_entry *group_obj = NULL, *mask_obj = NULL; |
| 418 | struct posix_acl_entry *pa, *pe; |
| 419 | |
| 420 | /* assert(atomic_read(acl->a_refcount) == 1); */ |
| 421 | |
| 422 | FOREACH_ACL_ENTRY(pa, acl, pe) { |
| 423 | switch(pa->e_tag) { |
| 424 | case ACL_USER_OBJ: |
| 425 | pa->e_perm = (mode & S_IRWXU) >> 6; |
| 426 | break; |
| 427 | |
| 428 | case ACL_USER: |
| 429 | case ACL_GROUP: |
| 430 | break; |
| 431 | |
| 432 | case ACL_GROUP_OBJ: |
| 433 | group_obj = pa; |
| 434 | break; |
| 435 | |
| 436 | case ACL_MASK: |
| 437 | mask_obj = pa; |
| 438 | break; |
| 439 | |
| 440 | case ACL_OTHER: |
| 441 | pa->e_perm = (mode & S_IRWXO); |
| 442 | break; |
| 443 | |
| 444 | default: |
| 445 | return -EIO; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | if (mask_obj) { |
| 450 | mask_obj->e_perm = (mode & S_IRWXG) >> 3; |
| 451 | } else { |
| 452 | if (!group_obj) |
| 453 | return -EIO; |
| 454 | group_obj->e_perm = (mode & S_IRWXG) >> 3; |
| 455 | } |
| 456 | |
| 457 | return 0; |
| 458 | } |
Al Viro | bc26ab5 | 2011-07-23 00:18:02 -0400 | [diff] [blame] | 459 | |
| 460 | int |
Al Viro | d3fb612 | 2011-07-23 18:37:50 -0400 | [diff] [blame] | 461 | posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p) |
Al Viro | 826cae2 | 2011-07-23 03:10:32 -0400 | [diff] [blame] | 462 | { |
| 463 | struct posix_acl *clone = posix_acl_clone(*acl, gfp); |
| 464 | int err = -ENOMEM; |
| 465 | if (clone) { |
| 466 | err = posix_acl_create_masq(clone, mode_p); |
| 467 | if (err < 0) { |
| 468 | posix_acl_release(clone); |
| 469 | clone = NULL; |
| 470 | } |
| 471 | } |
| 472 | posix_acl_release(*acl); |
| 473 | *acl = clone; |
| 474 | return err; |
| 475 | } |
| 476 | EXPORT_SYMBOL(posix_acl_create); |
| 477 | |
| 478 | int |
Al Viro | 86bc704 | 2011-07-23 19:03:11 -0400 | [diff] [blame] | 479 | posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, umode_t mode) |
Al Viro | bc26ab5 | 2011-07-23 00:18:02 -0400 | [diff] [blame] | 480 | { |
| 481 | struct posix_acl *clone = posix_acl_clone(*acl, gfp); |
| 482 | int err = -ENOMEM; |
| 483 | if (clone) { |
| 484 | err = posix_acl_chmod_masq(clone, mode); |
| 485 | if (err) { |
| 486 | posix_acl_release(clone); |
| 487 | clone = NULL; |
| 488 | } |
| 489 | } |
| 490 | posix_acl_release(*acl); |
| 491 | *acl = clone; |
| 492 | return err; |
| 493 | } |
| 494 | EXPORT_SYMBOL(posix_acl_chmod); |