ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / fs / ext2 / xattr_trusted.c
1 /*
2  * linux/fs/ext2/xattr_trusted.c
3  * Handler for trusted extended attributes.
4  *
5  * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
6  */
7
8 #include <linux/module.h>
9 #include <linux/string.h>
10 #include <linux/fs.h>
11 #include <linux/smp_lock.h>
12 #include <linux/ext2_fs.h>
13 #include "xattr.h"
14
15 #define XATTR_TRUSTED_PREFIX "trusted."
16
17 static size_t
18 ext2_xattr_trusted_list(char *list, struct inode *inode,
19                         const char *name, int name_len)
20 {
21         const int prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1;
22
23         if (!capable(CAP_SYS_ADMIN))
24                 return 0;
25
26         if (list) {
27                 memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
28                 memcpy(list+prefix_len, name, name_len);
29                 list[prefix_len + name_len] = '\0';
30         }
31         return prefix_len + name_len + 1;
32 }
33
34 static int
35 ext2_xattr_trusted_get(struct inode *inode, const char *name,
36                        void *buffer, size_t size)
37 {
38         if (strcmp(name, "") == 0)
39                 return -EINVAL;
40         if (!capable(CAP_SYS_ADMIN))
41                 return -EPERM;
42         return ext2_xattr_get(inode, EXT2_XATTR_INDEX_TRUSTED, name,
43                               buffer, size);
44 }
45
46 static int
47 ext2_xattr_trusted_set(struct inode *inode, const char *name,
48                        const void *value, size_t size, int flags)
49 {
50         if (strcmp(name, "") == 0)
51                 return -EINVAL;
52         if (!capable(CAP_SYS_ADMIN))
53                 return -EPERM;
54         return ext2_xattr_set(inode, EXT2_XATTR_INDEX_TRUSTED, name,
55                               value, size, flags);
56 }
57
58 struct ext2_xattr_handler ext2_xattr_trusted_handler = {
59         .prefix = XATTR_TRUSTED_PREFIX,
60         .list   = ext2_xattr_trusted_list,
61         .get    = ext2_xattr_trusted_get,
62         .set    = ext2_xattr_trusted_set,
63 };