blob: 5044a3e5ab4b5d2df38247e437757ae9065848d0 [file] [log] [blame]
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +05301/*
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 Weil873c3212011-06-01 12:35:14 +053015#include "hw/virtio.h"
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053016#include "virtio-9p.h"
Aneesh Kumar K.V353ac782011-01-28 18:09:08 +053017#include "fsdev/file-op-9p.h"
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053018#include "virtio-9p-xattr.h"
19
20
21static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
22 const char *name, void *value, size_t size)
23{
Venkateswararao Jujjuri (JV)faa44e32011-06-01 12:35:14 +053024 char buffer[PATH_MAX];
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053025 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)faa44e32011-06-01 12:35:14 +053033 return lgetxattr(rpath(ctx, path, buffer), name, value, size);
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053034}
35
36static 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.V70fc55e2010-10-18 15:28:16 +053041
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.Vfc221182010-10-18 15:28:16 +053054 }
55 if (!value) {
56 return name_size;
57 }
58
59 if (size < name_size) {
60 errno = ERANGE;
61 return -1;
62 }
63
64 strncpy(value, name, name_size);
65 return name_size;
66}
67
68static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
69 void *value, size_t size, int flags)
70{
Venkateswararao Jujjuri (JV)faa44e32011-06-01 12:35:14 +053071 char buffer[PATH_MAX];
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053072 if (strncmp(name, "user.virtfs.", 12) == 0) {
73 /*
74 * Don't allow fetch of user.virtfs namesapce
75 * in case of mapped security
76 */
77 errno = EACCES;
78 return -1;
79 }
Venkateswararao Jujjuri (JV)faa44e32011-06-01 12:35:14 +053080 return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags);
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053081}
82
83static int mp_user_removexattr(FsContext *ctx,
84 const char *path, const char *name)
85{
Venkateswararao Jujjuri (JV)faa44e32011-06-01 12:35:14 +053086 char buffer[PATH_MAX];
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053087 if (strncmp(name, "user.virtfs.", 12) == 0) {
88 /*
89 * Don't allow fetch of user.virtfs namesapce
90 * in case of mapped security
91 */
92 errno = EACCES;
93 return -1;
94 }
Venkateswararao Jujjuri (JV)faa44e32011-06-01 12:35:14 +053095 return lremovexattr(rpath(ctx, path, buffer), name);
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053096}
97
98XattrOperations mapped_user_xattr = {
99 .name = "user.",
100 .getxattr = mp_user_getxattr,
101 .setxattr = mp_user_setxattr,
102 .listxattr = mp_user_listxattr,
103 .removexattr = mp_user_removexattr,
104};
105
106XattrOperations passthrough_user_xattr = {
107 .name = "user.",
108 .getxattr = pt_getxattr,
109 .setxattr = pt_setxattr,
110 .listxattr = pt_listxattr,
111 .removexattr = pt_removexattr,
112};