From: Chris Mason <mason@suse.com>

From: jeffm@suse.com

reiserfs support for trusted xattrs


---

 25-akpm/fs/reiserfs/Makefile           |    2 
 25-akpm/fs/reiserfs/xattr.c            |    1 
 25-akpm/fs/reiserfs/xattr_trusted.c    |   81 +++++++++++++++++++++++++++++++++
 25-akpm/include/linux/reiserfs_xattr.h |    1 
 4 files changed, 84 insertions(+), 1 deletion(-)

diff -puN fs/reiserfs/Makefile~reiserfs-trusted-02 fs/reiserfs/Makefile
--- 25/fs/reiserfs/Makefile~reiserfs-trusted-02	Fri Apr 23 14:36:50 2004
+++ 25-akpm/fs/reiserfs/Makefile	Fri Apr 23 14:36:50 2004
@@ -10,7 +10,7 @@ reiserfs-objs := bitmap.o do_balan.o nam
 		 item_ops.o ioctl.o procfs.o
 
 ifeq ($(CONFIG_REISERFS_FS_XATTR),y)
-reiserfs-objs += xattr.o xattr_user.o
+reiserfs-objs += xattr.o xattr_user.o xattr_trusted.o
 endif
 
 ifeq ($(CONFIG_REISERFS_FS_POSIX_ACL),y)
diff -puN fs/reiserfs/xattr.c~reiserfs-trusted-02 fs/reiserfs/xattr.c
--- 25/fs/reiserfs/xattr.c~reiserfs-trusted-02	Fri Apr 23 14:36:50 2004
+++ 25-akpm/fs/reiserfs/xattr.c	Fri Apr 23 14:36:50 2004
@@ -1176,6 +1176,7 @@ reiserfs_xattr_register_handlers (void)
 
     /* Add the handlers */
     list_add_tail (&user_handler.handlers, &xattr_handlers);
+    list_add_tail (&trusted_handler.handlers, &xattr_handlers);
 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
     list_add_tail (&posix_acl_access_handler.handlers, &xattr_handlers);
     list_add_tail (&posix_acl_default_handler.handlers, &xattr_handlers);
diff -puN /dev/null fs/reiserfs/xattr_trusted.c
--- /dev/null	Thu Apr 11 07:25:15 2002
+++ 25-akpm/fs/reiserfs/xattr_trusted.c	Fri Apr 23 14:36:50 2004
@@ -0,0 +1,81 @@
+#include <linux/reiserfs_fs.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/pagemap.h>
+#include <linux/xattr.h>
+#include <linux/reiserfs_xattr.h>
+#include <asm/uaccess.h>
+
+#define XATTR_TRUSTED_PREFIX "trusted."
+
+static int
+trusted_get (struct inode *inode, const char *name, void *buffer, size_t size)
+{
+    if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
+        return -EINVAL;
+
+    if (!reiserfs_xattrs (inode->i_sb))
+        return -EOPNOTSUPP;
+
+    if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
+        return -EPERM;
+
+    return reiserfs_xattr_get (inode, name, buffer, size);
+}
+
+static int
+trusted_set (struct inode *inode, const char *name, const void *buffer,
+          size_t size, int flags)
+{
+    if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
+        return -EINVAL;
+
+    if (!reiserfs_xattrs (inode->i_sb))
+        return -EOPNOTSUPP;
+
+    if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
+        return -EPERM;
+
+    return reiserfs_xattr_set (inode, name, buffer, size, flags);
+}
+
+static int
+trusted_del (struct inode *inode, const char *name)
+{
+    if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
+        return -EINVAL;
+
+    if (!reiserfs_xattrs (inode->i_sb))
+        return -EOPNOTSUPP;
+
+    if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
+        return -EPERM;
+
+    return 0;
+}
+
+static int
+trusted_list (struct inode *inode, const char *name, int namelen, char *out)
+{
+    int len = namelen;
+
+    if (!reiserfs_xattrs (inode->i_sb))
+        return 0;
+
+    if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
+        return 0;
+
+    if (out)
+        memcpy (out, name, len);
+
+    return len;
+}
+
+
+struct reiserfs_xattr_handler trusted_handler = {
+    prefix: XATTR_TRUSTED_PREFIX,
+    get: trusted_get,
+    set: trusted_set,
+    del: trusted_del,
+    list: trusted_list,
+};
diff -puN include/linux/reiserfs_xattr.h~reiserfs-trusted-02 include/linux/reiserfs_xattr.h
--- 25/include/linux/reiserfs_xattr.h~reiserfs-trusted-02	Fri Apr 23 14:36:50 2004
+++ 25-akpm/include/linux/reiserfs_xattr.h	Fri Apr 23 14:36:50 2004
@@ -50,6 +50,7 @@ int reiserfs_xattr_set (struct inode *, 
                                size_t, int);
 
 extern struct reiserfs_xattr_handler user_handler;
+extern struct reiserfs_xattr_handler trusted_handler;
 
 int reiserfs_xattr_register_handlers (void) __init;
 void reiserfs_xattr_unregister_handlers (void);

_