Statistics
| Branch: | Revision:

root / hw / 9pfs / virtio-9p-posix-acl.c @ 77eec1b3

History | View | Annotate | Download (4.2 kB)

1 70fc55eb Aneesh Kumar K.V
/*
2 70fc55eb Aneesh Kumar K.V
 * Virtio 9p system.posix* xattr callback
3 70fc55eb Aneesh Kumar K.V
 *
4 70fc55eb Aneesh Kumar K.V
 * Copyright IBM, Corp. 2010
5 70fc55eb Aneesh Kumar K.V
 *
6 70fc55eb Aneesh Kumar K.V
 * Authors:
7 70fc55eb Aneesh Kumar K.V
 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
8 70fc55eb Aneesh Kumar K.V
 *
9 70fc55eb Aneesh Kumar K.V
 * This work is licensed under the terms of the GNU GPL, version 2.  See
10 70fc55eb Aneesh Kumar K.V
 * the COPYING file in the top-level directory.
11 70fc55eb Aneesh Kumar K.V
 *
12 70fc55eb Aneesh Kumar K.V
 */
13 70fc55eb Aneesh Kumar K.V
14 70fc55eb Aneesh Kumar K.V
#include <sys/types.h>
15 4f26f2b6 Avi Kivity
#include "qemu-xattr.h"
16 873c3213 Stefan Weil
#include "hw/virtio.h"
17 70fc55eb Aneesh Kumar K.V
#include "virtio-9p.h"
18 353ac78d Aneesh Kumar K.V
#include "fsdev/file-op-9p.h"
19 70fc55eb Aneesh Kumar K.V
#include "virtio-9p-xattr.h"
20 70fc55eb Aneesh Kumar K.V
21 70fc55eb Aneesh Kumar K.V
#define MAP_ACL_ACCESS "user.virtfs.system.posix_acl_access"
22 70fc55eb Aneesh Kumar K.V
#define MAP_ACL_DEFAULT "user.virtfs.system.posix_acl_default"
23 70fc55eb Aneesh Kumar K.V
#define ACL_ACCESS "system.posix_acl_access"
24 70fc55eb Aneesh Kumar K.V
#define ACL_DEFAULT "system.posix_acl_default"
25 70fc55eb Aneesh Kumar K.V
26 70fc55eb Aneesh Kumar K.V
static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
27 70fc55eb Aneesh Kumar K.V
                                const char *name, void *value, size_t size)
28 70fc55eb Aneesh Kumar K.V
{
29 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
30 faa44e3d Venkateswararao Jujjuri (JV)
    return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size);
31 70fc55eb Aneesh Kumar K.V
}
32 70fc55eb Aneesh Kumar K.V
33 70fc55eb Aneesh Kumar K.V
static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
34 70fc55eb Aneesh Kumar K.V
                                 char *name, void *value, size_t osize)
35 70fc55eb Aneesh Kumar K.V
{
36 70fc55eb Aneesh Kumar K.V
    ssize_t len = sizeof(ACL_ACCESS);
37 70fc55eb Aneesh Kumar K.V
38 70fc55eb Aneesh Kumar K.V
    if (!value) {
39 70fc55eb Aneesh Kumar K.V
        return len;
40 70fc55eb Aneesh Kumar K.V
    }
41 70fc55eb Aneesh Kumar K.V
42 70fc55eb Aneesh Kumar K.V
    if (osize < len) {
43 70fc55eb Aneesh Kumar K.V
        errno = ERANGE;
44 70fc55eb Aneesh Kumar K.V
        return -1;
45 70fc55eb Aneesh Kumar K.V
    }
46 70fc55eb Aneesh Kumar K.V
47 70fc55eb Aneesh Kumar K.V
    strncpy(value, ACL_ACCESS, len);
48 70fc55eb Aneesh Kumar K.V
    return 0;
49 70fc55eb Aneesh Kumar K.V
}
50 70fc55eb Aneesh Kumar K.V
51 70fc55eb Aneesh Kumar K.V
static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
52 70fc55eb Aneesh Kumar K.V
                            void *value, size_t size, int flags)
53 70fc55eb Aneesh Kumar K.V
{
54 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
55 faa44e3d Venkateswararao Jujjuri (JV)
    return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value,
56 faa44e3d Venkateswararao Jujjuri (JV)
            size, flags);
57 70fc55eb Aneesh Kumar K.V
}
58 70fc55eb Aneesh Kumar K.V
59 70fc55eb Aneesh Kumar K.V
static int mp_pacl_removexattr(FsContext *ctx,
60 70fc55eb Aneesh Kumar K.V
                               const char *path, const char *name)
61 70fc55eb Aneesh Kumar K.V
{
62 70fc55eb Aneesh Kumar K.V
    int ret;
63 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
64 faa44e3d Venkateswararao Jujjuri (JV)
    ret  = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS);
65 70fc55eb Aneesh Kumar K.V
    if (ret == -1 && errno == ENODATA) {
66 70fc55eb Aneesh Kumar K.V
        /*
67 a0994761 Aneesh Kumar K.V
         * We don't get ENODATA error when trying to remove a
68 70fc55eb Aneesh Kumar K.V
         * posix acl that is not present. So don't throw the error
69 70fc55eb Aneesh Kumar K.V
         * even in case of mapped security model
70 70fc55eb Aneesh Kumar K.V
         */
71 70fc55eb Aneesh Kumar K.V
        errno = 0;
72 70fc55eb Aneesh Kumar K.V
        ret = 0;
73 70fc55eb Aneesh Kumar K.V
    }
74 70fc55eb Aneesh Kumar K.V
    return ret;
75 70fc55eb Aneesh Kumar K.V
}
76 70fc55eb Aneesh Kumar K.V
77 70fc55eb Aneesh Kumar K.V
static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
78 70fc55eb Aneesh Kumar K.V
                                const char *name, void *value, size_t size)
79 70fc55eb Aneesh Kumar K.V
{
80 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
81 faa44e3d Venkateswararao Jujjuri (JV)
    return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size);
82 70fc55eb Aneesh Kumar K.V
}
83 70fc55eb Aneesh Kumar K.V
84 70fc55eb Aneesh Kumar K.V
static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
85 70fc55eb Aneesh Kumar K.V
                                 char *name, void *value, size_t osize)
86 70fc55eb Aneesh Kumar K.V
{
87 70fc55eb Aneesh Kumar K.V
    ssize_t len = sizeof(ACL_DEFAULT);
88 70fc55eb Aneesh Kumar K.V
89 70fc55eb Aneesh Kumar K.V
    if (!value) {
90 70fc55eb Aneesh Kumar K.V
        return len;
91 70fc55eb Aneesh Kumar K.V
    }
92 70fc55eb Aneesh Kumar K.V
93 70fc55eb Aneesh Kumar K.V
    if (osize < len) {
94 70fc55eb Aneesh Kumar K.V
        errno = ERANGE;
95 70fc55eb Aneesh Kumar K.V
        return -1;
96 70fc55eb Aneesh Kumar K.V
    }
97 70fc55eb Aneesh Kumar K.V
98 70fc55eb Aneesh Kumar K.V
    strncpy(value, ACL_DEFAULT, len);
99 70fc55eb Aneesh Kumar K.V
    return 0;
100 70fc55eb Aneesh Kumar K.V
}
101 70fc55eb Aneesh Kumar K.V
102 70fc55eb Aneesh Kumar K.V
static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
103 70fc55eb Aneesh Kumar K.V
                            void *value, size_t size, int flags)
104 70fc55eb Aneesh Kumar K.V
{
105 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
106 faa44e3d Venkateswararao Jujjuri (JV)
    return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value,
107 faa44e3d Venkateswararao Jujjuri (JV)
            size, flags);
108 70fc55eb Aneesh Kumar K.V
}
109 70fc55eb Aneesh Kumar K.V
110 70fc55eb Aneesh Kumar K.V
static int mp_dacl_removexattr(FsContext *ctx,
111 70fc55eb Aneesh Kumar K.V
                               const char *path, const char *name)
112 70fc55eb Aneesh Kumar K.V
{
113 a0994761 Aneesh Kumar K.V
    int ret;
114 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
115 faa44e3d Venkateswararao Jujjuri (JV)
    ret  = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT);
116 a0994761 Aneesh Kumar K.V
    if (ret == -1 && errno == ENODATA) {
117 a0994761 Aneesh Kumar K.V
        /*
118 a0994761 Aneesh Kumar K.V
         * We don't get ENODATA error when trying to remove a
119 a0994761 Aneesh Kumar K.V
         * posix acl that is not present. So don't throw the error
120 a0994761 Aneesh Kumar K.V
         * even in case of mapped security model
121 a0994761 Aneesh Kumar K.V
         */
122 a0994761 Aneesh Kumar K.V
        errno = 0;
123 a0994761 Aneesh Kumar K.V
        ret = 0;
124 a0994761 Aneesh Kumar K.V
    }
125 a0994761 Aneesh Kumar K.V
    return ret;
126 70fc55eb Aneesh Kumar K.V
}
127 70fc55eb Aneesh Kumar K.V
128 70fc55eb Aneesh Kumar K.V
129 70fc55eb Aneesh Kumar K.V
XattrOperations mapped_pacl_xattr = {
130 70fc55eb Aneesh Kumar K.V
    .name = "system.posix_acl_access",
131 70fc55eb Aneesh Kumar K.V
    .getxattr = mp_pacl_getxattr,
132 70fc55eb Aneesh Kumar K.V
    .setxattr = mp_pacl_setxattr,
133 70fc55eb Aneesh Kumar K.V
    .listxattr = mp_pacl_listxattr,
134 70fc55eb Aneesh Kumar K.V
    .removexattr = mp_pacl_removexattr,
135 70fc55eb Aneesh Kumar K.V
};
136 70fc55eb Aneesh Kumar K.V
137 70fc55eb Aneesh Kumar K.V
XattrOperations mapped_dacl_xattr = {
138 70fc55eb Aneesh Kumar K.V
    .name = "system.posix_acl_default",
139 70fc55eb Aneesh Kumar K.V
    .getxattr = mp_dacl_getxattr,
140 70fc55eb Aneesh Kumar K.V
    .setxattr = mp_dacl_setxattr,
141 70fc55eb Aneesh Kumar K.V
    .listxattr = mp_dacl_listxattr,
142 70fc55eb Aneesh Kumar K.V
    .removexattr = mp_dacl_removexattr,
143 70fc55eb Aneesh Kumar K.V
};
144 70fc55eb Aneesh Kumar K.V
145 70fc55eb Aneesh Kumar K.V
XattrOperations passthrough_acl_xattr = {
146 70fc55eb Aneesh Kumar K.V
    .name = "system.posix_acl_",
147 70fc55eb Aneesh Kumar K.V
    .getxattr = pt_getxattr,
148 70fc55eb Aneesh Kumar K.V
    .setxattr = pt_setxattr,
149 70fc55eb Aneesh Kumar K.V
    .listxattr = pt_listxattr,
150 70fc55eb Aneesh Kumar K.V
    .removexattr = pt_removexattr,
151 70fc55eb Aneesh Kumar K.V
};
152 70fc55eb Aneesh Kumar K.V
153 70fc55eb Aneesh Kumar K.V
XattrOperations none_acl_xattr = {
154 70fc55eb Aneesh Kumar K.V
    .name = "system.posix_acl_",
155 70fc55eb Aneesh Kumar K.V
    .getxattr = notsup_getxattr,
156 70fc55eb Aneesh Kumar K.V
    .setxattr = notsup_setxattr,
157 70fc55eb Aneesh Kumar K.V
    .listxattr = notsup_listxattr,
158 70fc55eb Aneesh Kumar K.V
    .removexattr = notsup_removexattr,
159 70fc55eb Aneesh Kumar K.V
};