]> git.hungrycats.org Git - linux/commitdiff
[PATCH] reiserfs: selinux support
authorAndrew Morton <akpm@osdl.org>
Mon, 10 May 2004 06:59:47 +0000 (23:59 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Mon, 10 May 2004 06:59:47 +0000 (23:59 -0700)
From: Chris Mason <mason@suse.com>

From: jeffm@suse.com

reiserfs support for selinux

fs/Kconfig
fs/reiserfs/Makefile
fs/reiserfs/xattr.c
fs/reiserfs/xattr_security.c [new file with mode: 0644]
include/linux/reiserfs_xattr.h

index 1f41463cedf03e93591256aed11f0b59614cf595..bbd098e6d18ecf5c25d9bd441b5da63dcecc3f63 100644 (file)
@@ -266,6 +266,18 @@ config REISERFS_FS_POSIX_ACL
 
          If you don't know what Access Control Lists are, say N
 
+config REISERFS_FS_SECURITY
+       bool "ReiserFS Security Labels"
+       depends on REISERFS_FS_XATTR
+       help
+         Security labels support alternative access control models
+         implemented by security modules like SELinux.  This option
+         enables an extended attribute handler for file security
+         labels in the ReiserFS filesystem.
+
+         If you are not using a security module that requires using
+         extended attributes for file security labels, say N.
+
 config JFS_FS
        tristate "JFS filesystem support"
        select NLS
index 57b6b8c48b005267a49b3ba9cfc97de1eaa63390..3a59309f3ca90d9c0a96a834abb7255ecf92de2c 100644 (file)
@@ -13,6 +13,10 @@ ifeq ($(CONFIG_REISERFS_FS_XATTR),y)
 reiserfs-objs += xattr.o xattr_user.o xattr_trusted.o
 endif
 
+ifeq ($(CONFIG_REISERFS_FS_SECURITY),y)
+reiserfs-objs += xattr_security.o
+endif
+
 ifeq ($(CONFIG_REISERFS_FS_POSIX_ACL),y)
 reiserfs-objs += xattr_acl.o
 endif
index 93d863507a529df5bba15c03363c0549b4b6b846..0c4e2d617d914357c93b6e1d758d005a30920363 100644 (file)
@@ -1177,6 +1177,9 @@ 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_SECURITY
+    list_add_tail (&security_handler.handlers, &xattr_handlers);
+#endif
 #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 --git a/fs/reiserfs/xattr_security.c b/fs/reiserfs/xattr_security.c
new file mode 100644 (file)
index 0000000..eacbdca
--- /dev/null
@@ -0,0 +1,69 @@
+#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_SECURITY_PREFIX "security."
+
+static int
+security_get (struct inode *inode, const char *name, void *buffer, size_t size)
+{
+    if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
+        return -EINVAL;
+
+    if (is_reiserfs_priv_object(inode))
+        return -EPERM;
+
+    return reiserfs_xattr_get (inode, name, buffer, size);
+}
+
+static int
+security_set (struct inode *inode, const char *name, const void *buffer,
+          size_t size, int flags)
+{
+    if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
+        return -EINVAL;
+
+    if (is_reiserfs_priv_object(inode))
+        return -EPERM;
+
+    return reiserfs_xattr_set (inode, name, buffer, size, flags);
+}
+
+static int
+security_del (struct inode *inode, const char *name)
+{
+    if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
+        return -EINVAL;
+
+    if (is_reiserfs_priv_object(inode))
+        return -EPERM;
+
+    return 0;
+}
+
+static int
+security_list (struct inode *inode, const char *name, int namelen, char *out)
+{
+    int len = namelen;
+
+    if (is_reiserfs_priv_object(inode))
+        return 0;
+
+    if (out)
+        memcpy (out, name, len);
+
+    return len;
+}
+
+
+struct reiserfs_xattr_handler security_handler = {
+    prefix: XATTR_SECURITY_PREFIX,
+    get: security_get,
+    set: security_set,
+    del: security_del,
+    list: security_list,
+};
index 64dc1ea564efcba61f3472744e1691623999bafa..3f4480b8a2cdd8ebc74c74b7c93b83fd4b01d93e 100644 (file)
@@ -51,6 +51,9 @@ int reiserfs_xattr_set (struct inode *, const char *, const void *,
 
 extern struct reiserfs_xattr_handler user_handler;
 extern struct reiserfs_xattr_handler trusted_handler;
+#ifdef CONFIG_REISERFS_FS_SECURITY
+extern struct reiserfs_xattr_handler security_handler;
+#endif
 
 int reiserfs_xattr_register_handlers (void) __init;
 void reiserfs_xattr_unregister_handlers (void);