Merge branch 'for-3.3-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj...
[linux-2.6-block.git] / fs / ext2 / xattr_trusted.c
CommitLineData
1da177e4
LT
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
1da177e4 8#include <linux/string.h>
16f7e0fe 9#include <linux/capability.h>
1da177e4 10#include <linux/fs.h>
1da177e4
LT
11#include <linux/ext2_fs.h>
12#include "xattr.h"
13
1da177e4 14static size_t
431547b3
CH
15ext2_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size,
16 const char *name, size_t name_len, int type)
1da177e4 17{
f905f06f 18 const int prefix_len = XATTR_TRUSTED_PREFIX_LEN;
1da177e4
LT
19 const size_t total_len = prefix_len + name_len + 1;
20
21 if (!capable(CAP_SYS_ADMIN))
22 return 0;
23
24 if (list && total_len <= list_size) {
25 memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
26 memcpy(list+prefix_len, name, name_len);
27 list[prefix_len + name_len] = '\0';
28 }
29 return total_len;
30}
31
32static int
431547b3
CH
33ext2_xattr_trusted_get(struct dentry *dentry, const char *name,
34 void *buffer, size_t size, int type)
1da177e4
LT
35{
36 if (strcmp(name, "") == 0)
37 return -EINVAL;
431547b3 38 return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name,
1da177e4
LT
39 buffer, size);
40}
41
42static int
431547b3
CH
43ext2_xattr_trusted_set(struct dentry *dentry, const char *name,
44 const void *value, size_t size, int flags, int type)
1da177e4
LT
45{
46 if (strcmp(name, "") == 0)
47 return -EINVAL;
431547b3 48 return ext2_xattr_set(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name,
1da177e4
LT
49 value, size, flags);
50}
51
749c72ef 52const struct xattr_handler ext2_xattr_trusted_handler = {
1da177e4
LT
53 .prefix = XATTR_TRUSTED_PREFIX,
54 .list = ext2_xattr_trusted_list,
55 .get = ext2_xattr_trusted_get,
56 .set = ext2_xattr_trusted_set,
57};