Skip to content

Commit 47f70d0

Browse files
Christoph HellwigAl Viro
authored andcommitted
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>
1 parent 702e5bc commit 47f70d0

File tree

5 files changed

+35
-161
lines changed

5 files changed

+35
-161
lines changed

fs/reiserfs/acl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ static inline int reiserfs_acl_count(size_t size)
4848

4949
#ifdef CONFIG_REISERFS_FS_POSIX_ACL
5050
struct posix_acl *reiserfs_get_acl(struct inode *inode, int type);
51+
int reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
5152
int reiserfs_acl_chmod(struct inode *inode);
5253
int reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
5354
struct inode *dir, struct dentry *dentry,
5455
struct inode *inode);
5556
int reiserfs_cache_default_acl(struct inode *dir);
56-
extern const struct xattr_handler reiserfs_posix_acl_default_handler;
57-
extern const struct xattr_handler reiserfs_posix_acl_access_handler;
5857

5958
#else
6059

6160
#define reiserfs_cache_default_acl(inode) 0
6261
#define reiserfs_get_acl NULL
62+
#define reiserfs_set_acl NULL
6363

6464
static inline int reiserfs_acl_chmod(struct inode *inode)
6565
{

fs/reiserfs/file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,5 @@ const struct inode_operations reiserfs_file_inode_operations = {
260260
.removexattr = reiserfs_removexattr,
261261
.permission = reiserfs_permission,
262262
.get_acl = reiserfs_get_acl,
263+
.set_acl = reiserfs_set_acl,
263264
};

fs/reiserfs/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ const struct inode_operations reiserfs_dir_inode_operations = {
15221522
.removexattr = reiserfs_removexattr,
15231523
.permission = reiserfs_permission,
15241524
.get_acl = reiserfs_get_acl,
1525+
.set_acl = reiserfs_set_acl,
15251526
};
15261527

15271528
/*
@@ -1538,8 +1539,6 @@ const struct inode_operations reiserfs_symlink_inode_operations = {
15381539
.listxattr = reiserfs_listxattr,
15391540
.removexattr = reiserfs_removexattr,
15401541
.permission = reiserfs_permission,
1541-
.get_acl = reiserfs_get_acl,
1542-
15431542
};
15441543

15451544
/*
@@ -1553,4 +1552,5 @@ const struct inode_operations reiserfs_special_inode_operations = {
15531552
.removexattr = reiserfs_removexattr,
15541553
.permission = reiserfs_permission,
15551554
.get_acl = reiserfs_get_acl,
1555+
.set_acl = reiserfs_set_acl,
15561556
};

fs/reiserfs/xattr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <linux/stat.h>
5151
#include <linux/quotaops.h>
5252
#include <linux/security.h>
53+
#include <linux/posix_acl_xattr.h>
5354

5455
#define PRIVROOT_NAME ".reiserfs_priv"
5556
#define XAROOT_NAME "xattrs"
@@ -904,8 +905,8 @@ static const struct xattr_handler *reiserfs_xattr_handlers[] = {
904905
&reiserfs_xattr_security_handler,
905906
#endif
906907
#ifdef CONFIG_REISERFS_FS_POSIX_ACL
907-
&reiserfs_posix_acl_access_handler,
908-
&reiserfs_posix_acl_default_handler,
908+
&posix_acl_access_xattr_handler,
909+
&posix_acl_default_xattr_handler,
909910
#endif
910911
NULL
911912
};

fs/reiserfs/xattr_acl.c

Lines changed: 27 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,19 @@
1111
#include "acl.h"
1212
#include <asm/uaccess.h>
1313

14-
static int reiserfs_set_acl(struct reiserfs_transaction_handle *th,
14+
static int __reiserfs_set_acl(struct reiserfs_transaction_handle *th,
1515
struct inode *inode, int type,
1616
struct posix_acl *acl);
1717

18-
static int
19-
reiserfs_posix_acl_set(struct dentry *dentry, const char *name, const void *value,
20-
size_t size, int flags, int type)
18+
19+
int
20+
reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
2121
{
22-
struct inode *inode = dentry->d_inode;
23-
struct posix_acl *acl;
2422
int error, error2;
2523
struct reiserfs_transaction_handle th;
2624
size_t jcreate_blocks;
27-
if (!reiserfs_posixacl(inode->i_sb))
28-
return -EOPNOTSUPP;
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;
25+
int size = acl ? posix_acl_xattr_size(acl->a_count) : 0;
26+
4327

4428
/* Pessimism: We can't assume that anything from the xattr root up
4529
* has been created. */
@@ -51,37 +35,14 @@ reiserfs_posix_acl_set(struct dentry *dentry, const char *name, const void *valu
5135
error = journal_begin(&th, inode->i_sb, jcreate_blocks);
5236
reiserfs_write_unlock(inode->i_sb);
5337
if (error == 0) {
54-
error = reiserfs_set_acl(&th, inode, type, acl);
38+
error = __reiserfs_set_acl(&th, inode, type, acl);
5539
reiserfs_write_lock(inode->i_sb);
5640
error2 = journal_end(&th, inode->i_sb, jcreate_blocks);
5741
reiserfs_write_unlock(inode->i_sb);
5842
if (error2)
5943
error = error2;
6044
}
6145

62-
release_and_out:
63-
posix_acl_release(acl);
64-
return error;
65-
}
66-
67-
static int
68-
reiserfs_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-
8546
return error;
8647
}
8748

@@ -221,10 +182,6 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
221182
int size;
222183
int retval;
223184

224-
acl = get_cached_acl(inode, type);
225-
if (acl != ACL_NOT_CACHED)
226-
return acl;
227-
228185
switch (type) {
229186
case ACL_TYPE_ACCESS:
230187
name = POSIX_ACL_XATTR_ACCESS;
@@ -273,17 +230,14 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
273230
* BKL held [before 2.5.x]
274231
*/
275232
static int
276-
reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
233+
__reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
277234
int type, struct posix_acl *acl)
278235
{
279236
char *name;
280237
void *value = NULL;
281238
size_t size = 0;
282239
int error;
283240

284-
if (S_ISLNK(inode->i_mode))
285-
return -EOPNOTSUPP;
286-
287241
switch (type) {
288242
case ACL_TYPE_ACCESS:
289243
name = POSIX_ACL_XATTR_ACCESS;
@@ -343,7 +297,7 @@ reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
343297
struct inode *dir, struct dentry *dentry,
344298
struct inode *inode)
345299
{
346-
struct posix_acl *acl;
300+
struct posix_acl *default_acl, *acl;
347301
int err = 0;
348302

349303
/* ACLs only get applied to files and directories */
@@ -363,37 +317,28 @@ reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
363317
goto apply_umask;
364318
}
365319

366-
acl = reiserfs_get_acl(dir, ACL_TYPE_DEFAULT);
367-
if (IS_ERR(acl))
368-
return PTR_ERR(acl);
320+
err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
321+
if (err)
322+
return err;
369323

324+
if (default_acl) {
325+
err = __reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
326+
default_acl);
327+
posix_acl_release(default_acl);
328+
}
370329
if (acl) {
371-
/* Copy the default ACL to the default ACL of a new directory */
372-
if (S_ISDIR(inode->i_mode)) {
373-
err = reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
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:
330+
if (!err)
331+
err = __reiserfs_set_acl(th, inode, ACL_TYPE_ACCESS,
332+
acl);
389333
posix_acl_release(acl);
390-
} else {
391-
apply_umask:
392-
/* no ACL, apply umask */
393-
inode->i_mode &= ~current_umask();
394334
}
395335

396336
return err;
337+
338+
apply_umask:
339+
/* no ACL, apply umask */
340+
inode->i_mode &= ~current_umask();
341+
return err;
397342
}
398343

399344
/* 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)
442387
*/
443388
int reiserfs_acl_chmod(struct inode *inode)
444389
{
445-
struct reiserfs_transaction_handle th;
446-
struct posix_acl *acl;
447-
size_t size;
448-
int error;
449-
450390
if (IS_PRIVATE(inode))
451391
return 0;
452-
453-
if (S_ISLNK(inode->i_mode))
454-
return -EOPNOTSUPP;
455-
456392
if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
457-
!reiserfs_posixacl(inode->i_sb)) {
393+
!reiserfs_posixacl(inode->i_sb))
458394
return 0;
459-
}
460395

461-
acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
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-
487-
static 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;
396+
return posix_acl_chmod(inode, inode->i_mode);
497397
}
498-
499-
const 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-
507-
static 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-
519-
const 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-
};

0 commit comments

Comments
 (0)