Revision 70fc55eb

b/Makefile.objs
250 250
hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
251 251

  
252 252
hw-obj-$(CONFIG_VIRTFS) += virtio-9p-debug.o virtio-9p-local.o virtio-9p-xattr.o
253
hw-obj-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o
253
hw-obj-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
254 254

  
255 255
######################################################################
256 256
# libdis
b/hw/virtio-9p-posix-acl.c
1
/*
2
 * Virtio 9p system.posix* 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>
15
#include <attr/xattr.h>
16
#include "virtio.h"
17
#include "virtio-9p.h"
18
#include "file-op-9p.h"
19
#include "virtio-9p-xattr.h"
20

  
21
#define MAP_ACL_ACCESS "user.virtfs.system.posix_acl_access"
22
#define MAP_ACL_DEFAULT "user.virtfs.system.posix_acl_default"
23
#define ACL_ACCESS "system.posix_acl_access"
24
#define ACL_DEFAULT "system.posix_acl_default"
25

  
26
static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
27
                                const char *name, void *value, size_t size)
28
{
29
    return lgetxattr(rpath(ctx, path), MAP_ACL_ACCESS, value, size);
30
}
31

  
32
static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
33
                                 char *name, void *value, size_t osize)
34
{
35
    ssize_t len = sizeof(ACL_ACCESS);
36

  
37
    if (!value) {
38
        return len;
39
    }
40

  
41
    if (osize < len) {
42
        errno = ERANGE;
43
        return -1;
44
    }
45

  
46
    strncpy(value, ACL_ACCESS, len);
47
    return 0;
48
}
49

  
50
static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
51
                            void *value, size_t size, int flags)
52
{
53
    return lsetxattr(rpath(ctx, path), MAP_ACL_ACCESS, value, size, flags);
54
}
55

  
56
static int mp_pacl_removexattr(FsContext *ctx,
57
                               const char *path, const char *name)
58
{
59
    int ret;
60
    ret  = lremovexattr(rpath(ctx, path), MAP_ACL_ACCESS);
61
    if (ret == -1 && errno == ENODATA) {
62
        /*
63
         * We don't get ENODATA error when trying to remote a
64
         * posix acl that is not present. So don't throw the error
65
         * even in case of mapped security model
66
         */
67
        errno = 0;
68
        ret = 0;
69
    }
70
    return ret;
71
}
72

  
73
static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
74
                                const char *name, void *value, size_t size)
75
{
76
    return lgetxattr(rpath(ctx, path), MAP_ACL_DEFAULT, value, size);
77
}
78

  
79
static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
80
                                 char *name, void *value, size_t osize)
81
{
82
    ssize_t len = sizeof(ACL_DEFAULT);
83

  
84
    if (!value) {
85
        return len;
86
    }
87

  
88
    if (osize < len) {
89
        errno = ERANGE;
90
        return -1;
91
    }
92

  
93
    strncpy(value, ACL_DEFAULT, len);
94
    return 0;
95
}
96

  
97
static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
98
                            void *value, size_t size, int flags)
99
{
100
    return lsetxattr(rpath(ctx, path), MAP_ACL_DEFAULT, value, size, flags);
101
}
102

  
103
static int mp_dacl_removexattr(FsContext *ctx,
104
                               const char *path, const char *name)
105
{
106
    return lremovexattr(rpath(ctx, path), MAP_ACL_DEFAULT);
107
}
108

  
109

  
110
XattrOperations mapped_pacl_xattr = {
111
    .name = "system.posix_acl_access",
112
    .getxattr = mp_pacl_getxattr,
113
    .setxattr = mp_pacl_setxattr,
114
    .listxattr = mp_pacl_listxattr,
115
    .removexattr = mp_pacl_removexattr,
116
};
117

  
118
XattrOperations mapped_dacl_xattr = {
119
    .name = "system.posix_acl_default",
120
    .getxattr = mp_dacl_getxattr,
121
    .setxattr = mp_dacl_setxattr,
122
    .listxattr = mp_dacl_listxattr,
123
    .removexattr = mp_dacl_removexattr,
124
};
125

  
126
XattrOperations passthrough_acl_xattr = {
127
    .name = "system.posix_acl_",
128
    .getxattr = pt_getxattr,
129
    .setxattr = pt_setxattr,
130
    .listxattr = pt_listxattr,
131
    .removexattr = pt_removexattr,
132
};
133

  
134
XattrOperations none_acl_xattr = {
135
    .name = "system.posix_acl_",
136
    .getxattr = notsup_getxattr,
137
    .setxattr = notsup_setxattr,
138
    .listxattr = notsup_listxattr,
139
    .removexattr = notsup_removexattr,
140
};
b/hw/virtio-9p-xattr-user.c
37 37
{
38 38
    int name_size = strlen(name) + 1;
39 39
    if (strncmp(name, "user.virtfs.", 12) == 0) {
40
        /*
41
         * Don't allow fetch of user.virtfs namesapce
42
         * in case of mapped security
43
         */
44
        return 0;
40

  
41
        /*  check if it is a mapped posix acl */
42
        if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) {
43
            /* adjust the name and size */
44
            name += 12;
45
            name_size -= 12;
46
        } else {
47
            /*
48
             * Don't allow fetch of user.virtfs namesapce
49
             * in case of mapped security
50
             */
51
            return 0;
52
        }
45 53
    }
46 54
    if (!value) {
47 55
        return name_size;
b/hw/virtio-9p-xattr.c
137 137

  
138 138
XattrOperations *mapped_xattr_ops[] = {
139 139
    &mapped_user_xattr,
140
    &mapped_pacl_xattr,
141
    &mapped_dacl_xattr,
140 142
    NULL,
141 143
};
142 144

  
143 145
XattrOperations *passthrough_xattr_ops[] = {
144 146
    &passthrough_user_xattr,
147
    &passthrough_acl_xattr,
145 148
    NULL,
146 149
};
147 150

  
148 151
/* for .user none model should be same as passthrough */
149 152
XattrOperations *none_xattr_ops[] = {
150 153
    &passthrough_user_xattr,
154
    &none_acl_xattr,
151 155
    NULL,
152 156
};
b/hw/virtio-9p-xattr.h
32 32
extern XattrOperations mapped_user_xattr;
33 33
extern XattrOperations passthrough_user_xattr;
34 34

  
35
extern XattrOperations mapped_pacl_xattr;
36
extern XattrOperations mapped_dacl_xattr;
37
extern XattrOperations passthrough_acl_xattr;
38
extern XattrOperations none_acl_xattr;
39

  
35 40
extern XattrOperations *mapped_xattr_ops[];
36 41
extern XattrOperations *passthrough_xattr_ops[];
37 42
extern XattrOperations *none_xattr_ops[];
......
66 71
    return lremovexattr(rpath(ctx, path), name);
67 72
}
68 73

  
74
static inline ssize_t notsup_getxattr(FsContext *ctx, const char *path,
75
                                      const char *name, void *value,
76
                                      size_t size)
77
{
78
    errno = ENOTSUP;
79
    return -1;
80
}
81

  
82
static inline int notsup_setxattr(FsContext *ctx, const char *path,
83
                                  const char *name, void *value,
84
                                  size_t size, int flags)
85
{
86
    errno = ENOTSUP;
87
    return -1;
88
}
89

  
90
static inline ssize_t notsup_listxattr(FsContext *ctx, const char *path,
91
                                       char *name, void *value, size_t size)
92
{
93
    return 0;
94
}
95

  
96
static inline int notsup_removexattr(FsContext *ctx,
97
                                     const char *path, const char *name)
98
{
99
    errno = ENOTSUP;
100
    return -1;
101
}
102

  
69 103
#endif

Also available in: Unified diff