11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/fs/ext2/xattr_trusted.c 31da177e4SLinus Torvalds * Handler for trusted extended attributes. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org> 61da177e4SLinus Torvalds */ 71da177e4SLinus Torvalds 8*f7699f2bSAl Viro #include "ext2.h" 91da177e4SLinus Torvalds #include "xattr.h" 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds static size_t 12431547b3SChristoph Hellwig ext2_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, 13431547b3SChristoph Hellwig const char *name, size_t name_len, int type) 141da177e4SLinus Torvalds { 15f905f06fSShen Feng const int prefix_len = XATTR_TRUSTED_PREFIX_LEN; 161da177e4SLinus Torvalds const size_t total_len = prefix_len + name_len + 1; 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) 191da177e4SLinus Torvalds return 0; 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds if (list && total_len <= list_size) { 221da177e4SLinus Torvalds memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len); 231da177e4SLinus Torvalds memcpy(list+prefix_len, name, name_len); 241da177e4SLinus Torvalds list[prefix_len + name_len] = '\0'; 251da177e4SLinus Torvalds } 261da177e4SLinus Torvalds return total_len; 271da177e4SLinus Torvalds } 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds static int 30431547b3SChristoph Hellwig ext2_xattr_trusted_get(struct dentry *dentry, const char *name, 31431547b3SChristoph Hellwig void *buffer, size_t size, int type) 321da177e4SLinus Torvalds { 331da177e4SLinus Torvalds if (strcmp(name, "") == 0) 341da177e4SLinus Torvalds return -EINVAL; 35431547b3SChristoph Hellwig return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name, 361da177e4SLinus Torvalds buffer, size); 371da177e4SLinus Torvalds } 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds static int 40431547b3SChristoph Hellwig ext2_xattr_trusted_set(struct dentry *dentry, const char *name, 41431547b3SChristoph Hellwig const void *value, size_t size, int flags, int type) 421da177e4SLinus Torvalds { 431da177e4SLinus Torvalds if (strcmp(name, "") == 0) 441da177e4SLinus Torvalds return -EINVAL; 45431547b3SChristoph Hellwig return ext2_xattr_set(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name, 461da177e4SLinus Torvalds value, size, flags); 471da177e4SLinus Torvalds } 481da177e4SLinus Torvalds 49749c72efSStephen Hemminger const struct xattr_handler ext2_xattr_trusted_handler = { 501da177e4SLinus Torvalds .prefix = XATTR_TRUSTED_PREFIX, 511da177e4SLinus Torvalds .list = ext2_xattr_trusted_list, 521da177e4SLinus Torvalds .get = ext2_xattr_trusted_get, 531da177e4SLinus Torvalds .set = ext2_xattr_trusted_set, 541da177e4SLinus Torvalds }; 55