Jim Garlick | d9a7385 | 2013-05-29 12:09:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright IBM Corporation, 2010 |
| 3 | * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2.1 of the GNU Lesser General Public License |
| 7 | * as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include "xattr.h" |
| 21 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame^] | 22 | static int v9fs_xattr_security_get(const struct xattr_handler *handler, |
| 23 | struct dentry *dentry, const char *name, |
| 24 | void *buffer, size_t size) |
Jim Garlick | d9a7385 | 2013-05-29 12:09:39 -0700 | [diff] [blame] | 25 | { |
| 26 | int retval; |
| 27 | char *full_name; |
| 28 | size_t name_len; |
| 29 | size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; |
| 30 | |
| 31 | if (name == NULL) |
| 32 | return -EINVAL; |
| 33 | |
| 34 | if (strcmp(name, "") == 0) |
| 35 | return -EINVAL; |
| 36 | |
| 37 | name_len = strlen(name); |
| 38 | full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); |
| 39 | if (!full_name) |
| 40 | return -ENOMEM; |
| 41 | memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len); |
| 42 | memcpy(full_name+prefix_len, name, name_len); |
| 43 | full_name[prefix_len + name_len] = '\0'; |
| 44 | |
| 45 | retval = v9fs_xattr_get(dentry, full_name, buffer, size); |
| 46 | kfree(full_name); |
| 47 | return retval; |
| 48 | } |
| 49 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame^] | 50 | static int v9fs_xattr_security_set(const struct xattr_handler *handler, |
| 51 | struct dentry *dentry, const char *name, |
| 52 | const void *value, size_t size, int flags) |
Jim Garlick | d9a7385 | 2013-05-29 12:09:39 -0700 | [diff] [blame] | 53 | { |
| 54 | int retval; |
| 55 | char *full_name; |
| 56 | size_t name_len; |
| 57 | size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; |
| 58 | |
| 59 | if (name == NULL) |
| 60 | return -EINVAL; |
| 61 | |
| 62 | if (strcmp(name, "") == 0) |
| 63 | return -EINVAL; |
| 64 | |
| 65 | name_len = strlen(name); |
| 66 | full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); |
| 67 | if (!full_name) |
| 68 | return -ENOMEM; |
| 69 | memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len); |
| 70 | memcpy(full_name + prefix_len, name, name_len); |
| 71 | full_name[prefix_len + name_len] = '\0'; |
| 72 | |
| 73 | retval = v9fs_xattr_set(dentry, full_name, value, size, flags); |
| 74 | kfree(full_name); |
| 75 | return retval; |
| 76 | } |
| 77 | |
| 78 | struct xattr_handler v9fs_xattr_security_handler = { |
| 79 | .prefix = XATTR_SECURITY_PREFIX, |
| 80 | .get = v9fs_xattr_security_get, |
| 81 | .set = v9fs_xattr_security_set, |
| 82 | }; |