blob: 5e90a95ad60b5208d22cac6c0722fd1494af3e8a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/reiserfs_fs.h>
2#include <linux/errno.h>
3#include <linux/fs.h>
4#include <linux/pagemap.h>
5#include <linux/xattr.h>
6#include <linux/reiserfs_xattr.h>
7#include <asm/uaccess.h>
8
9#define XATTR_SECURITY_PREFIX "security."
10
11static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070012security_get(struct inode *inode, const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070013{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070014 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
15 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070017 if (is_reiserfs_priv_object(inode))
18 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070020 return reiserfs_xattr_get(inode, name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021}
22
23static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070024security_set(struct inode *inode, const char *name, const void *buffer,
25 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070027 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
28 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070030 if (is_reiserfs_priv_object(inode))
31 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070033 return reiserfs_xattr_set(inode, name, buffer, size, flags);
34}
35
36static int security_del(struct inode *inode, const char *name)
37{
38 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
39 return -EINVAL;
40
41 if (is_reiserfs_priv_object(inode))
42 return -EPERM;
43
44 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
47static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070048security_list(struct inode *inode, const char *name, int namelen, char *out)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070050 int len = namelen;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070052 if (is_reiserfs_priv_object(inode))
53 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070055 if (out)
56 memcpy(out, name, len);
57
58 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061struct reiserfs_xattr_handler security_handler = {
62 .prefix = XATTR_SECURITY_PREFIX,
63 .get = security_get,
64 .set = security_set,
65 .del = security_del,
66 .list = security_list,
67};