]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
JFS: Implement jfs_init_security
authorDave Kleikamp <shaggy@austin.ibm.com>
Thu, 1 Sep 2005 14:05:39 +0000 (09:05 -0500)
committerDave Kleikamp <shaggy@austin.ibm.com>
Thu, 1 Sep 2005 14:05:39 +0000 (09:05 -0500)
This atomically initializes the security xattr when an object is created

Signed-off-by: Dave Kleikamp <shaggy@austin.ibm.com>
fs/jfs/jfs_xattr.h
fs/jfs/namei.c
fs/jfs/xattr.c

index 116a73ce3076e76be887b3b4b7b5a2e791ae6248..25e9990bccd1be1926a21847d4135544a7dd4e42 100644 (file)
@@ -61,4 +61,14 @@ extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
 extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
 extern int jfs_removexattr(struct dentry *, const char *);
 
+#ifdef CONFIG_JFS_SECURITY
+extern int jfs_init_security(tid_t, struct inode *, struct inode *);
+#else
+static inline int jfs_init_security(tid_t tid, struct inode *inode,
+                                   struct inode *dir)
+{
+       return 0;
+}
+#endif
+
 #endif /* H_JFS_XATTR */
index f23f9c2aa5259b37eae271e87a65e74123f00e6c..1abe7343f920494451b3bb5e5165f31af471eac6 100644 (file)
@@ -111,6 +111,12 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
        if (rc)
                goto out3;
 
+       rc = jfs_init_security(tid, ip, dip);
+       if (rc) {
+               txAbort(tid, 0);
+               goto out3;
+       }
+
        if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) {
                jfs_err("jfs_create: dtSearch returned %d", rc);
                txAbort(tid, 0);
@@ -239,6 +245,12 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
        if (rc)
                goto out3;
 
+       rc = jfs_init_security(tid, ip, dip);
+       if (rc) {
+               txAbort(tid, 0);
+               goto out3;
+       }
+
        if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) {
                jfs_err("jfs_mkdir: dtSearch returned %d", rc);
                txAbort(tid, 0);
@@ -906,6 +918,10 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
        down(&JFS_IP(dip)->commit_sem);
        down(&JFS_IP(ip)->commit_sem);
 
+       rc = jfs_init_security(tid, ip, dip);
+       if (rc)
+               goto out3;
+
        tblk = tid_to_tblock(tid);
        tblk->xflag |= COMMIT_CREATE;
        tblk->ino = ip->i_ino;
@@ -1349,6 +1365,12 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
        if (rc)
                goto out3;
 
+       rc = jfs_init_security(tid, ip, dir);
+       if (rc) {
+               txAbort(tid, 0);
+               goto out3;
+       }
+
        if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) {
                txAbort(tid, 0);
                goto out3;
index 35674b2a0e6c52e091e24429772b757507282dc2..23aa5066b5a438014d84a2d0491c79e49b25e4dd 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/xattr.h>
 #include <linux/posix_acl_xattr.h>
 #include <linux/quotaops.h>
+#include <linux/security.h>
 #include "jfs_incore.h"
 #include "jfs_superblock.h"
 #include "jfs_dmap.h"
@@ -1148,3 +1149,38 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
 
        return rc;
 }
+
+#ifdef CONFIG_JFS_SECURITY
+int jfs_init_security(tid_t tid, struct inode *inode, struct inode *dir)
+{
+       int rc;
+       size_t len;
+       void *value;
+       char *suffix;
+       char *name;
+
+       rc = security_inode_init_security(inode, dir, &suffix, &value, &len);
+       if (rc) {
+               if (rc == -EOPNOTSUPP)
+                       return 0;
+               return rc;
+       }
+       name = kmalloc(XATTR_SECURITY_PREFIX_LEN + 1 + strlen(suffix),
+                      GFP_NOFS);
+       if (!name) {
+               rc = -ENOMEM;
+               goto kmalloc_failed;
+       }
+       strcpy(name, XATTR_SECURITY_PREFIX);
+       strcpy(name + XATTR_SECURITY_PREFIX_LEN, suffix);
+
+       rc = __jfs_setxattr(tid, inode, name, value, len, 0);
+
+       kfree(name);
+kmalloc_failed:
+       kfree(suffix);
+       kfree(value);
+
+       return rc;
+}
+#endif