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 "ext2.h" 9 #include "xattr.h" 10 11 static size_t 12 ext2_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) 15 { 16 const int prefix_len = XATTR_TRUSTED_PREFIX_LEN; 17 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 30 static int 31 ext2_xattr_trusted_get(const struct xattr_handler *handler, 32 struct dentry *dentry, const char *name, 33 void *buffer, size_t size) 34 { 35 if (strcmp(name, "") == 0) 36 return -EINVAL; 37 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name, 38 buffer, size); 39 } 40 41 static int 42 ext2_xattr_trusted_set(const struct xattr_handler *handler, 43 struct dentry *dentry, const char *name, 44 const void *value, size_t size, int flags) 45 { 46 if (strcmp(name, "") == 0) 47 return -EINVAL; 48 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name, 49 value, size, flags); 50 } 51 52 const struct xattr_handler ext2_xattr_trusted_handler = { 53 .prefix = XATTR_TRUSTED_PREFIX, 54 .list = ext2_xattr_trusted_list, 55 .get = ext2_xattr_trusted_get, 56 .set = ext2_xattr_trusted_set, 57 }; 58