Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 1 | /* |
Wei Liu | 267ae09 | 2015-11-18 18:31:52 +0000 | [diff] [blame] | 2 | * 9p user. xattr callback |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 3 | * |
| 4 | * Copyright IBM, Corp. 2010 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 10 | * the COPYING file in the top-level directory. |
| 11 | * |
| 12 | */ |
| 13 | |
Peter Maydell | fbc0412 | 2016-01-26 18:17:10 +0000 | [diff] [blame] | 14 | #include "qemu/osdep.h" |
Wei Liu | ebe74f8 | 2016-01-07 18:18:02 +0000 | [diff] [blame] | 15 | #include "9p.h" |
Aneesh Kumar K.V | 353ac78 | 2011-01-28 18:09:08 +0530 | [diff] [blame] | 16 | #include "fsdev/file-op-9p.h" |
Wei Liu | 267ae09 | 2015-11-18 18:31:52 +0000 | [diff] [blame] | 17 | #include "9p-xattr.h" |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 18 | |
| 19 | |
| 20 | static ssize_t mp_user_getxattr(FsContext *ctx, const char *path, |
| 21 | const char *name, void *value, size_t size) |
| 22 | { |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 23 | char *buffer; |
| 24 | ssize_t ret; |
| 25 | |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 26 | if (strncmp(name, "user.virtfs.", 12) == 0) { |
| 27 | /* |
| 28 | * Don't allow fetch of user.virtfs namesapce |
| 29 | * in case of mapped security |
| 30 | */ |
| 31 | errno = ENOATTR; |
| 32 | return -1; |
| 33 | } |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 34 | buffer = rpath(ctx, path); |
| 35 | ret = lgetxattr(buffer, name, value, size); |
| 36 | g_free(buffer); |
| 37 | return ret; |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static ssize_t mp_user_listxattr(FsContext *ctx, const char *path, |
| 41 | char *name, void *value, size_t size) |
| 42 | { |
| 43 | int name_size = strlen(name) + 1; |
| 44 | if (strncmp(name, "user.virtfs.", 12) == 0) { |
Aneesh Kumar K.V | 70fc55e | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 45 | |
| 46 | /* check if it is a mapped posix acl */ |
| 47 | if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) { |
| 48 | /* adjust the name and size */ |
| 49 | name += 12; |
| 50 | name_size -= 12; |
| 51 | } else { |
| 52 | /* |
| 53 | * Don't allow fetch of user.virtfs namesapce |
| 54 | * in case of mapped security |
| 55 | */ |
| 56 | return 0; |
| 57 | } |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 58 | } |
| 59 | if (!value) { |
| 60 | return name_size; |
| 61 | } |
| 62 | |
| 63 | if (size < name_size) { |
| 64 | errno = ERANGE; |
| 65 | return -1; |
| 66 | } |
| 67 | |
Jim Meyering | 9238c20 | 2012-10-04 13:09:56 +0200 | [diff] [blame] | 68 | /* name_size includes the trailing NUL. */ |
| 69 | memcpy(value, name, name_size); |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 70 | return name_size; |
| 71 | } |
| 72 | |
| 73 | static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name, |
| 74 | void *value, size_t size, int flags) |
| 75 | { |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 76 | char *buffer; |
| 77 | int ret; |
| 78 | |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 79 | if (strncmp(name, "user.virtfs.", 12) == 0) { |
| 80 | /* |
| 81 | * Don't allow fetch of user.virtfs namesapce |
| 82 | * in case of mapped security |
| 83 | */ |
| 84 | errno = EACCES; |
| 85 | return -1; |
| 86 | } |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 87 | buffer = rpath(ctx, path); |
| 88 | ret = lsetxattr(buffer, name, value, size, flags); |
| 89 | g_free(buffer); |
| 90 | return ret; |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static int mp_user_removexattr(FsContext *ctx, |
| 94 | const char *path, const char *name) |
| 95 | { |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 96 | char *buffer; |
| 97 | int ret; |
| 98 | |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 99 | if (strncmp(name, "user.virtfs.", 12) == 0) { |
| 100 | /* |
| 101 | * Don't allow fetch of user.virtfs namesapce |
| 102 | * in case of mapped security |
| 103 | */ |
| 104 | errno = EACCES; |
| 105 | return -1; |
| 106 | } |
Chen Gang | 4fa4ce7 | 2014-03-02 01:36:19 +0800 | [diff] [blame] | 107 | buffer = rpath(ctx, path); |
| 108 | ret = lremovexattr(buffer, name); |
| 109 | g_free(buffer); |
| 110 | return ret; |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | XattrOperations mapped_user_xattr = { |
| 114 | .name = "user.", |
| 115 | .getxattr = mp_user_getxattr, |
| 116 | .setxattr = mp_user_setxattr, |
| 117 | .listxattr = mp_user_listxattr, |
| 118 | .removexattr = mp_user_removexattr, |
| 119 | }; |
| 120 | |
| 121 | XattrOperations passthrough_user_xattr = { |
| 122 | .name = "user.", |
| 123 | .getxattr = pt_getxattr, |
| 124 | .setxattr = pt_setxattr, |
| 125 | .listxattr = pt_listxattr, |
| 126 | .removexattr = pt_removexattr, |
| 127 | }; |