diff options
Diffstat (limited to 'fs/btrfs/xattr.c')
| -rw-r--r-- | fs/btrfs/xattr.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index b4fa5f4b6ad1..312b9435e9f8 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
| 22 | #include <linux/rwsem.h> | 22 | #include <linux/rwsem.h> |
| 23 | #include <linux/xattr.h> | 23 | #include <linux/xattr.h> |
| 24 | #include <linux/security.h> | ||
| 24 | #include "ctree.h" | 25 | #include "ctree.h" |
| 25 | #include "btrfs_inode.h" | 26 | #include "btrfs_inode.h" |
| 26 | #include "transaction.h" | 27 | #include "transaction.h" |
| @@ -330,3 +331,34 @@ int btrfs_removexattr(struct dentry *dentry, const char *name) | |||
| 330 | return -EOPNOTSUPP; | 331 | return -EOPNOTSUPP; |
| 331 | return __btrfs_setxattr(dentry->d_inode, name, NULL, 0, XATTR_REPLACE); | 332 | return __btrfs_setxattr(dentry->d_inode, name, NULL, 0, XATTR_REPLACE); |
| 332 | } | 333 | } |
| 334 | |||
| 335 | int btrfs_xattr_security_init(struct inode *inode, struct inode *dir) | ||
| 336 | { | ||
| 337 | int err; | ||
| 338 | size_t len; | ||
| 339 | void *value; | ||
| 340 | char *suffix; | ||
| 341 | char *name; | ||
| 342 | |||
| 343 | err = security_inode_init_security(inode, dir, &suffix, &value, &len); | ||
| 344 | if (err) { | ||
| 345 | if (err == -EOPNOTSUPP) | ||
| 346 | return 0; | ||
| 347 | return err; | ||
| 348 | } | ||
| 349 | |||
| 350 | name = kmalloc(XATTR_SECURITY_PREFIX_LEN + strlen(suffix) + 1, | ||
| 351 | GFP_NOFS); | ||
| 352 | if (!name) { | ||
| 353 | err = -ENOMEM; | ||
| 354 | } else { | ||
| 355 | strcpy(name, XATTR_SECURITY_PREFIX); | ||
| 356 | strcpy(name + XATTR_SECURITY_PREFIX_LEN, suffix); | ||
| 357 | err = __btrfs_setxattr(inode, name, value, len, 0); | ||
| 358 | kfree(name); | ||
| 359 | } | ||
| 360 | |||
| 361 | kfree(suffix); | ||
| 362 | kfree(value); | ||
| 363 | return err; | ||
| 364 | } | ||
