blob: 3150dd3a78595084d0a6bfd5916f86272e68303a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Al Virof7699f22012-03-23 16:45:51 -04008#include "ext2.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include "xattr.h"
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011static size_t
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020012ext2_xattr_trusted_list(const struct xattr_handler *handler,
13 struct dentry *dentry, char *list, size_t list_size,
14 const char *name, size_t name_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070015{
Shen Fengf905f062008-07-25 01:46:15 -070016 const int prefix_len = XATTR_TRUSTED_PREFIX_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 const size_t total_len = prefix_len + name_len + 1;
18
19 if (!capable(CAP_SYS_ADMIN))
20 return 0;
21
22 if (list && total_len <= list_size) {
23 memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
24 memcpy(list+prefix_len, name, name_len);
25 list[prefix_len + name_len] = '\0';
26 }
27 return total_len;
28}
29
30static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020031ext2_xattr_trusted_get(const struct xattr_handler *handler,
32 struct dentry *dentry, const char *name,
33 void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
35 if (strcmp(name, "") == 0)
36 return -EINVAL;
David Howells2b0143b2015-03-17 22:25:59 +000037 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 buffer, size);
39}
40
41static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020042ext2_xattr_trusted_set(const struct xattr_handler *handler,
43 struct dentry *dentry, const char *name,
44 const void *value, size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 if (strcmp(name, "") == 0)
47 return -EINVAL;
David Howells2b0143b2015-03-17 22:25:59 +000048 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 value, size, flags);
50}
51
Stephen Hemminger749c72ef2010-05-13 17:53:16 -070052const struct xattr_handler ext2_xattr_trusted_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 .prefix = XATTR_TRUSTED_PREFIX,
54 .list = ext2_xattr_trusted_list,
55 .get = ext2_xattr_trusted_get,
56 .set = ext2_xattr_trusted_set,
57};