Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Virtio 9p user. xattr callback |
| 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 | |
| 14 | #include <sys/types.h> |
Stefan Weil | 873c321 | 2011-06-01 12:35:14 +0530 | [diff] [blame] | 15 | #include "hw/virtio.h" |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 16 | #include "virtio-9p.h" |
Aneesh Kumar K.V | 353ac78 | 2011-01-28 18:09:08 +0530 | [diff] [blame] | 17 | #include "fsdev/file-op-9p.h" |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 18 | #include "virtio-9p-xattr.h" |
| 19 | |
| 20 | |
| 21 | static ssize_t mp_user_getxattr(FsContext *ctx, const char *path, |
| 22 | const char *name, void *value, size_t size) |
| 23 | { |
Venkateswararao Jujjuri (JV) | faa44e3 | 2011-06-01 12:35:14 +0530 | [diff] [blame] | 24 | char buffer[PATH_MAX]; |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 25 | if (strncmp(name, "user.virtfs.", 12) == 0) { |
| 26 | /* |
| 27 | * Don't allow fetch of user.virtfs namesapce |
| 28 | * in case of mapped security |
| 29 | */ |
| 30 | errno = ENOATTR; |
| 31 | return -1; |
| 32 | } |
Venkateswararao Jujjuri (JV) | faa44e3 | 2011-06-01 12:35:14 +0530 | [diff] [blame] | 33 | return lgetxattr(rpath(ctx, path, buffer), name, value, size); |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static ssize_t mp_user_listxattr(FsContext *ctx, const char *path, |
| 37 | char *name, void *value, size_t size) |
| 38 | { |
| 39 | int name_size = strlen(name) + 1; |
| 40 | if (strncmp(name, "user.virtfs.", 12) == 0) { |
Aneesh Kumar K.V | 70fc55e | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 41 | |
| 42 | /* check if it is a mapped posix acl */ |
| 43 | if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) { |
| 44 | /* adjust the name and size */ |
| 45 | name += 12; |
| 46 | name_size -= 12; |
| 47 | } else { |
| 48 | /* |
| 49 | * Don't allow fetch of user.virtfs namesapce |
| 50 | * in case of mapped security |
| 51 | */ |
| 52 | return 0; |
| 53 | } |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 54 | } |
| 55 | if (!value) { |
| 56 | return name_size; |
| 57 | } |
| 58 | |
| 59 | if (size < name_size) { |
| 60 | errno = ERANGE; |
| 61 | return -1; |
| 62 | } |
| 63 | |
Jim Meyering | 9238c20 | 2012-10-04 13:09:56 +0200 | [diff] [blame^] | 64 | /* name_size includes the trailing NUL. */ |
| 65 | memcpy(value, name, name_size); |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 66 | return name_size; |
| 67 | } |
| 68 | |
| 69 | static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name, |
| 70 | void *value, size_t size, int flags) |
| 71 | { |
Venkateswararao Jujjuri (JV) | faa44e3 | 2011-06-01 12:35:14 +0530 | [diff] [blame] | 72 | char buffer[PATH_MAX]; |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 73 | if (strncmp(name, "user.virtfs.", 12) == 0) { |
| 74 | /* |
| 75 | * Don't allow fetch of user.virtfs namesapce |
| 76 | * in case of mapped security |
| 77 | */ |
| 78 | errno = EACCES; |
| 79 | return -1; |
| 80 | } |
Venkateswararao Jujjuri (JV) | faa44e3 | 2011-06-01 12:35:14 +0530 | [diff] [blame] | 81 | return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags); |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static int mp_user_removexattr(FsContext *ctx, |
| 85 | const char *path, const char *name) |
| 86 | { |
Venkateswararao Jujjuri (JV) | faa44e3 | 2011-06-01 12:35:14 +0530 | [diff] [blame] | 87 | char buffer[PATH_MAX]; |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 88 | if (strncmp(name, "user.virtfs.", 12) == 0) { |
| 89 | /* |
| 90 | * Don't allow fetch of user.virtfs namesapce |
| 91 | * in case of mapped security |
| 92 | */ |
| 93 | errno = EACCES; |
| 94 | return -1; |
| 95 | } |
Venkateswararao Jujjuri (JV) | faa44e3 | 2011-06-01 12:35:14 +0530 | [diff] [blame] | 96 | return lremovexattr(rpath(ctx, path, buffer), name); |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | XattrOperations mapped_user_xattr = { |
| 100 | .name = "user.", |
| 101 | .getxattr = mp_user_getxattr, |
| 102 | .setxattr = mp_user_setxattr, |
| 103 | .listxattr = mp_user_listxattr, |
| 104 | .removexattr = mp_user_removexattr, |
| 105 | }; |
| 106 | |
| 107 | XattrOperations passthrough_user_xattr = { |
| 108 | .name = "user.", |
| 109 | .getxattr = pt_getxattr, |
| 110 | .setxattr = pt_setxattr, |
| 111 | .listxattr = pt_listxattr, |
| 112 | .removexattr = pt_removexattr, |
| 113 | }; |