fs/ext3/xattr.c | 12 +++++- fs/ext3/xattr_trusted.c | 86 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/ext3_xattr.h | 6 +++ 3 files changed, 102 insertions(+), 2 deletions(-) Index: linux-2.4.20/fs/ext3/xattr.c =================================================================== --- linux-2.4.20.orig/fs/ext3/xattr.c 2003-10-22 02:29:40.000000000 +0400 +++ linux-2.4.20/fs/ext3/xattr.c 2003-10-24 01:03:22.000000000 +0400 @@ -1771,18 +1771,25 @@ int __init init_ext3_xattr(void) { + int error; + ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL, sizeof(struct mb_cache_entry) + sizeof(struct mb_cache_entry_index), 1, 61); if (!ext3_xattr_cache) return -ENOMEM; - return 0; + error = init_ext3_xattr_trusted(); + if (error) + mb_cache_destroy(ext3_xattr_cache); + + return error; } void exit_ext3_xattr(void) { + exit_ext3_xattr_trusted(); if (ext3_xattr_cache) mb_cache_destroy(ext3_xattr_cache); ext3_xattr_cache = NULL; @@ -1793,12 +1800,13 @@ int __init init_ext3_xattr(void) { - return 0; + return init_ext3_xattr_trusted(); } void exit_ext3_xattr(void) { + exit_ext3_xattr_trusted(); } #endif /* CONFIG_EXT3_FS_XATTR_SHARING */ Index: linux-2.4.20/fs/ext3/xattr_trusted.c =================================================================== --- linux-2.4.20.orig/fs/ext3/xattr_trusted.c 2003-10-24 01:03:22.000000000 +0400 +++ linux-2.4.20/fs/ext3/xattr_trusted.c 2003-10-24 01:03:22.000000000 +0400 @@ -0,0 +1,86 @@ +/* + * linux/fs/ext3/xattr_trusted.c + * Handler for trusted extended attributes. + * + * Copyright (C) 2003 by Andreas Gruenbacher, + */ + +#include +#include +#include +#include +#include +#include + +#define XATTR_TRUSTED_PREFIX "trusted." + +static size_t +ext3_xattr_trusted_list(char *list, struct inode *inode, + const char *name, int name_len) +{ + const int prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1; + + if (!capable(CAP_SYS_ADMIN)) + return 0; + + if (list) { + memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len); + memcpy(list+prefix_len, name, name_len); + list[prefix_len + name_len] = '\0'; + } + return prefix_len + name_len + 1; +} + +static int +ext3_xattr_trusted_get(struct inode *inode, const char *name, + void *buffer, size_t size) +{ + if (strcmp(name, "") == 0) + return -EINVAL; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + return ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED, name, + buffer, size); +} + +static int +ext3_xattr_trusted_set(struct inode *inode, const char *name, + const void *value, size_t size, int flags) +{ + handle_t *handle; + int error; + + if (strcmp(name, "") == 0) + return -EINVAL; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + handle = ext3_journal_start(inode, EXT3_XATTR_TRANS_BLOCKS); + if (IS_ERR(handle)) + return PTR_ERR(handle); + error = ext3_xattr_set(handle, inode, EXT3_XATTR_INDEX_TRUSTED, name, + value, size, flags); + ext3_journal_stop(handle, inode); + + return error; +} + +struct ext3_xattr_handler ext3_xattr_trusted_handler = { + .prefix = XATTR_TRUSTED_PREFIX, + .list = ext3_xattr_trusted_list, + .get = ext3_xattr_trusted_get, + .set = ext3_xattr_trusted_set, +}; + +int __init +init_ext3_xattr_trusted(void) +{ + return ext3_xattr_register(EXT3_XATTR_INDEX_TRUSTED, + &ext3_xattr_trusted_handler); +} + +void +exit_ext3_xattr_trusted(void) +{ + ext3_xattr_unregister(EXT3_XATTR_INDEX_TRUSTED, + &ext3_xattr_trusted_handler); +} Index: linux-2.4.20/include/linux/ext3_xattr.h =================================================================== --- linux-2.4.20.orig/include/linux/ext3_xattr.h 2003-10-22 02:29:39.000000000 +0400 +++ linux-2.4.20/include/linux/ext3_xattr.h 2003-10-24 01:03:22.000000000 +0400 @@ -21,6 +21,9 @@ #define EXT3_XATTR_INDEX_USER 1 #define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS 2 #define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT 3 +#define EXT3_XATTR_INDEX_TRUSTED 4 +#define EXT3_XATTR_INDEX_LUSTRE 5 +#define EXT3_XATTR_INDEX_SECURITY 6 struct ext3_xattr_header { __u32 h_magic; /* magic number for identification */ @@ -84,6 +87,9 @@ extern int init_ext3_xattr(void) __init; extern void exit_ext3_xattr(void); +extern int init_ext3_xattr_trusted(void) __init; +extern void exit_ext3_xattr_trusted(void); + # else /* CONFIG_EXT3_FS_XATTR */ # define ext3_setxattr NULL # define ext3_getxattr NULL Index: linux-2.4.20/fs/ext3/Makefile =================================================================== --- linux-2.4.20.orig/fs/ext3/Makefile 2003-10-22 02:29:40.000000000 +0400 +++ linux-2.4.20/fs/ext3/Makefile 2003-10-24 01:03:47.000000000 +0400 @@ -12,7 +12,8 @@ export-objs := ext3-exports.o obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \ - ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o + ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o \ + xattr_trusted.o obj-m := $(O_TARGET) export-objs += xattr.o