aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/xattr_acl.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2013-12-20 08:16:49 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2014-01-25 23:58:21 -0500
commit47f70d08facf288a9faad6e6c36ac2e670be8195 (patch)
tree6c615c020bb9b8faa7c59e05580150449010dfde /fs/reiserfs/xattr_acl.c
parent702e5bc68ad2c02f1b12b53ef7093074af9d2441 (diff)
reiserfs: use generic posix ACL infrastructure
Also don't bother to set up a .get_acl method for symlinks as we do not support access control (ACLs or even mode bits) for symlinks in Linux. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/reiserfs/xattr_acl.c')
-rw-r--r--fs/reiserfs/xattr_acl.c182
1 files changed, 27 insertions, 155 deletions
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index d95c9592327b..a6ce532402dc 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -11,35 +11,19 @@
11#include "acl.h" 11#include "acl.h"
12#include <asm/uaccess.h> 12#include <asm/uaccess.h>
13 13
14static int reiserfs_set_acl(struct reiserfs_transaction_handle *th, 14static int __reiserfs_set_acl(struct reiserfs_transaction_handle *th,
15 struct inode *inode, int type, 15 struct inode *inode, int type,
16 struct posix_acl *acl); 16 struct posix_acl *acl);
17 17
18static int 18
19reiserfs_posix_acl_set(struct dentry *dentry, const char *name, const void *value, 19int
20 size_t size, int flags, int type) 20reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
21{ 21{
22 struct inode *inode = dentry->d_inode;
23 struct posix_acl *acl;
24 int error, error2; 22 int error, error2;
25 struct reiserfs_transaction_handle th; 23 struct reiserfs_transaction_handle th;
26 size_t jcreate_blocks; 24 size_t jcreate_blocks;
27 if (!reiserfs_posixacl(inode->i_sb)) 25 int size = acl ? posix_acl_xattr_size(acl->a_count) : 0;
28 return -EOPNOTSUPP; 26
29 if (!inode_owner_or_capable(inode))
30 return -EPERM;
31
32 if (value) {
33 acl = posix_acl_from_xattr(&init_user_ns, value, size);
34 if (IS_ERR(acl)) {
35 return PTR_ERR(acl);
36 } else if (acl) {
37 error = posix_acl_valid(acl);
38 if (error)
39 goto release_and_out;
40 }
41 } else
42 acl = NULL;
43 27
44 /* Pessimism: We can't assume that anything from the xattr root up 28 /* Pessimism: We can't assume that anything from the xattr root up
45 * has been created. */ 29 * has been created. */
@@ -51,7 +35,7 @@ reiserfs_posix_acl_set(struct dentry *dentry, const char *name, const void *valu
51 error = journal_begin(&th, inode->i_sb, jcreate_blocks); 35 error = journal_begin(&th, inode->i_sb, jcreate_blocks);
52 reiserfs_write_unlock(inode->i_sb); 36 reiserfs_write_unlock(inode->i_sb);
53 if (error == 0) { 37 if (error == 0) {
54 error = reiserfs_set_acl(&th, inode, type, acl); 38 error = __reiserfs_set_acl(&th, inode, type, acl);
55 reiserfs_write_lock(inode->i_sb); 39 reiserfs_write_lock(inode->i_sb);
56 error2 = journal_end(&th, inode->i_sb, jcreate_blocks); 40 error2 = journal_end(&th, inode->i_sb, jcreate_blocks);
57 reiserfs_write_unlock(inode->i_sb); 41 reiserfs_write_unlock(inode->i_sb);
@@ -59,29 +43,6 @@ reiserfs_posix_acl_set(struct dentry *dentry, const char *name, const void *valu
59 error = error2; 43 error = error2;
60 } 44 }
61 45
62 release_and_out:
63 posix_acl_release(acl);
64 return error;
65}
66
67static int
68reiserfs_posix_acl_get(struct dentry *dentry, const char *name, void *buffer,
69 size_t size, int type)
70{
71 struct posix_acl *acl;
72 int error;
73
74 if (!reiserfs_posixacl(dentry->d_sb))
75 return -EOPNOTSUPP;
76
77 acl = reiserfs_get_acl(dentry->d_inode, type);
78 if (IS_ERR(acl))
79 return PTR_ERR(acl);
80 if (acl == NULL)
81 return -ENODATA;
82 error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
83 posix_acl_release(acl);
84
85 return error; 46 return error;
86} 47}
87 48
@@ -221,10 +182,6 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
221 int size; 182 int size;
222 int retval; 183 int retval;
223 184
224 acl = get_cached_acl(inode, type);
225 if (acl != ACL_NOT_CACHED)
226 return acl;
227
228 switch (type) { 185 switch (type) {
229 case ACL_TYPE_ACCESS: 186 case ACL_TYPE_ACCESS:
230 name = POSIX_ACL_XATTR_ACCESS; 187 name = POSIX_ACL_XATTR_ACCESS;
@@ -273,7 +230,7 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
273 * BKL held [before 2.5.x] 230 * BKL held [before 2.5.x]
274 */ 231 */
275static int 232static int
276reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode, 233__reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
277 int type, struct posix_acl *acl) 234 int type, struct posix_acl *acl)
278{ 235{
279 char *name; 236 char *name;
@@ -281,9 +238,6 @@ reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
281 size_t size = 0; 238 size_t size = 0;
282 int error; 239 int error;
283 240
284 if (S_ISLNK(inode->i_mode))
285 return -EOPNOTSUPP;
286
287 switch (type) { 241 switch (type) {
288 case ACL_TYPE_ACCESS: 242 case ACL_TYPE_ACCESS:
289 name = POSIX_ACL_XATTR_ACCESS; 243 name = POSIX_ACL_XATTR_ACCESS;
@@ -343,7 +297,7 @@ reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
343 struct inode *dir, struct dentry *dentry, 297 struct inode *dir, struct dentry *dentry,
344 struct inode *inode) 298 struct inode *inode)
345{ 299{
346 struct posix_acl *acl; 300 struct posix_acl *default_acl, *acl;
347 int err = 0; 301 int err = 0;
348 302
349 /* ACLs only get applied to files and directories */ 303 /* ACLs only get applied to files and directories */
@@ -363,37 +317,28 @@ reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
363 goto apply_umask; 317 goto apply_umask;
364 } 318 }
365 319
366 acl = reiserfs_get_acl(dir, ACL_TYPE_DEFAULT); 320 err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
367 if (IS_ERR(acl)) 321 if (err)
368 return PTR_ERR(acl); 322 return err;
369 323
324 if (default_acl) {
325 err = __reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
326 default_acl);
327 posix_acl_release(default_acl);
328 }
370 if (acl) { 329 if (acl) {
371 /* Copy the default ACL to the default ACL of a new directory */ 330 if (!err)
372 if (S_ISDIR(inode->i_mode)) { 331 err = __reiserfs_set_acl(th, inode, ACL_TYPE_ACCESS,
373 err = reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT, 332 acl);
374 acl);
375 if (err)
376 goto cleanup;
377 }
378
379 /* Now we reconcile the new ACL and the mode,
380 potentially modifying both */
381 err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
382 if (err < 0)
383 return err;
384
385 /* If we need an ACL.. */
386 if (err > 0)
387 err = reiserfs_set_acl(th, inode, ACL_TYPE_ACCESS, acl);
388 cleanup:
389 posix_acl_release(acl); 333 posix_acl_release(acl);
390 } else {
391 apply_umask:
392 /* no ACL, apply umask */
393 inode->i_mode &= ~current_umask();
394 } 334 }
395 335
396 return err; 336 return err;
337
338 apply_umask:
339 /* no ACL, apply umask */
340 inode->i_mode &= ~current_umask();
341 return err;
397} 342}
398 343
399/* This is used to cache the default acl before a new object is created. 344/* This is used to cache the default acl before a new object is created.
@@ -442,84 +387,11 @@ int reiserfs_cache_default_acl(struct inode *inode)
442 */ 387 */
443int reiserfs_acl_chmod(struct inode *inode) 388int reiserfs_acl_chmod(struct inode *inode)
444{ 389{
445 struct reiserfs_transaction_handle th;
446 struct posix_acl *acl;
447 size_t size;
448 int error;
449
450 if (IS_PRIVATE(inode)) 390 if (IS_PRIVATE(inode))
451 return 0; 391 return 0;
452
453 if (S_ISLNK(inode->i_mode))
454 return -EOPNOTSUPP;
455
456 if (get_inode_sd_version(inode) == STAT_DATA_V1 || 392 if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
457 !reiserfs_posixacl(inode->i_sb)) { 393 !reiserfs_posixacl(inode->i_sb))
458 return 0; 394 return 0;
459 }
460 395
461 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); 396 return posix_acl_chmod(inode, inode->i_mode);
462 if (!acl)
463 return 0;
464 if (IS_ERR(acl))
465 return PTR_ERR(acl);
466 error = __posix_acl_chmod(&acl, GFP_NOFS, inode->i_mode);
467 if (error)
468 return error;
469
470 size = reiserfs_xattr_nblocks(inode, reiserfs_acl_size(acl->a_count));
471 reiserfs_write_lock(inode->i_sb);
472 error = journal_begin(&th, inode->i_sb, size * 2);
473 reiserfs_write_unlock(inode->i_sb);
474 if (!error) {
475 int error2;
476 error = reiserfs_set_acl(&th, inode, ACL_TYPE_ACCESS, acl);
477 reiserfs_write_lock(inode->i_sb);
478 error2 = journal_end(&th, inode->i_sb, size * 2);
479 reiserfs_write_unlock(inode->i_sb);
480 if (error2)
481 error = error2;
482 }
483 posix_acl_release(acl);
484 return error;
485}
486
487static size_t posix_acl_access_list(struct dentry *dentry, char *list,
488 size_t list_size, const char *name,
489 size_t name_len, int type)
490{
491 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
492 if (!reiserfs_posixacl(dentry->d_sb))
493 return 0;
494 if (list && size <= list_size)
495 memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
496 return size;
497} 397}
498
499const struct xattr_handler reiserfs_posix_acl_access_handler = {
500 .prefix = POSIX_ACL_XATTR_ACCESS,
501 .flags = ACL_TYPE_ACCESS,
502 .get = reiserfs_posix_acl_get,
503 .set = reiserfs_posix_acl_set,
504 .list = posix_acl_access_list,
505};
506
507static size_t posix_acl_default_list(struct dentry *dentry, char *list,
508 size_t list_size, const char *name,
509 size_t name_len, int type)
510{
511 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
512 if (!reiserfs_posixacl(dentry->d_sb))
513 return 0;
514 if (list && size <= list_size)
515 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
516 return size;
517}
518
519const struct xattr_handler reiserfs_posix_acl_default_handler = {
520 .prefix = POSIX_ACL_XATTR_DEFAULT,
521 .flags = ACL_TYPE_DEFAULT,
522 .get = reiserfs_posix_acl_get,
523 .set = reiserfs_posix_acl_set,
524 .list = posix_acl_default_list,
525};