Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (4.3 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 1de7afc9 Paolo Bonzini
#include "qemu/xattr.h"
16 0d09e41a Paolo Bonzini
#include "hw/virtio/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 9238c209 Jim Meyering
    /* len includes the trailing NUL */
48 9238c209 Jim Meyering
    memcpy(value, ACL_ACCESS, len);
49 70fc55eb Aneesh Kumar K.V
    return 0;
50 70fc55eb Aneesh Kumar K.V
}
51 70fc55eb Aneesh Kumar K.V
52 70fc55eb Aneesh Kumar K.V
static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
53 70fc55eb Aneesh Kumar K.V
                            void *value, size_t size, int flags)
54 70fc55eb Aneesh Kumar K.V
{
55 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
56 faa44e3d Venkateswararao Jujjuri (JV)
    return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value,
57 faa44e3d Venkateswararao Jujjuri (JV)
            size, flags);
58 70fc55eb Aneesh Kumar K.V
}
59 70fc55eb Aneesh Kumar K.V
60 70fc55eb Aneesh Kumar K.V
static int mp_pacl_removexattr(FsContext *ctx,
61 70fc55eb Aneesh Kumar K.V
                               const char *path, const char *name)
62 70fc55eb Aneesh Kumar K.V
{
63 70fc55eb Aneesh Kumar K.V
    int ret;
64 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
65 faa44e3d Venkateswararao Jujjuri (JV)
    ret  = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS);
66 70fc55eb Aneesh Kumar K.V
    if (ret == -1 && errno == ENODATA) {
67 70fc55eb Aneesh Kumar K.V
        /*
68 a0994761 Aneesh Kumar K.V
         * We don't get ENODATA error when trying to remove a
69 70fc55eb Aneesh Kumar K.V
         * posix acl that is not present. So don't throw the error
70 70fc55eb Aneesh Kumar K.V
         * even in case of mapped security model
71 70fc55eb Aneesh Kumar K.V
         */
72 70fc55eb Aneesh Kumar K.V
        errno = 0;
73 70fc55eb Aneesh Kumar K.V
        ret = 0;
74 70fc55eb Aneesh Kumar K.V
    }
75 70fc55eb Aneesh Kumar K.V
    return ret;
76 70fc55eb Aneesh Kumar K.V
}
77 70fc55eb Aneesh Kumar K.V
78 70fc55eb Aneesh Kumar K.V
static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
79 70fc55eb Aneesh Kumar K.V
                                const char *name, void *value, size_t size)
80 70fc55eb Aneesh Kumar K.V
{
81 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
82 faa44e3d Venkateswararao Jujjuri (JV)
    return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size);
83 70fc55eb Aneesh Kumar K.V
}
84 70fc55eb Aneesh Kumar K.V
85 70fc55eb Aneesh Kumar K.V
static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
86 70fc55eb Aneesh Kumar K.V
                                 char *name, void *value, size_t osize)
87 70fc55eb Aneesh Kumar K.V
{
88 70fc55eb Aneesh Kumar K.V
    ssize_t len = sizeof(ACL_DEFAULT);
89 70fc55eb Aneesh Kumar K.V
90 70fc55eb Aneesh Kumar K.V
    if (!value) {
91 70fc55eb Aneesh Kumar K.V
        return len;
92 70fc55eb Aneesh Kumar K.V
    }
93 70fc55eb Aneesh Kumar K.V
94 70fc55eb Aneesh Kumar K.V
    if (osize < len) {
95 70fc55eb Aneesh Kumar K.V
        errno = ERANGE;
96 70fc55eb Aneesh Kumar K.V
        return -1;
97 70fc55eb Aneesh Kumar K.V
    }
98 70fc55eb Aneesh Kumar K.V
99 9238c209 Jim Meyering
    /* len includes the trailing NUL */
100 9238c209 Jim Meyering
    memcpy(value, ACL_ACCESS, len);
101 70fc55eb Aneesh Kumar K.V
    return 0;
102 70fc55eb Aneesh Kumar K.V
}
103 70fc55eb Aneesh Kumar K.V
104 70fc55eb Aneesh Kumar K.V
static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
105 70fc55eb Aneesh Kumar K.V
                            void *value, size_t size, int flags)
106 70fc55eb Aneesh Kumar K.V
{
107 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
108 faa44e3d Venkateswararao Jujjuri (JV)
    return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value,
109 faa44e3d Venkateswararao Jujjuri (JV)
            size, flags);
110 70fc55eb Aneesh Kumar K.V
}
111 70fc55eb Aneesh Kumar K.V
112 70fc55eb Aneesh Kumar K.V
static int mp_dacl_removexattr(FsContext *ctx,
113 70fc55eb Aneesh Kumar K.V
                               const char *path, const char *name)
114 70fc55eb Aneesh Kumar K.V
{
115 a0994761 Aneesh Kumar K.V
    int ret;
116 faa44e3d Venkateswararao Jujjuri (JV)
    char buffer[PATH_MAX];
117 faa44e3d Venkateswararao Jujjuri (JV)
    ret  = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT);
118 a0994761 Aneesh Kumar K.V
    if (ret == -1 && errno == ENODATA) {
119 a0994761 Aneesh Kumar K.V
        /*
120 a0994761 Aneesh Kumar K.V
         * We don't get ENODATA error when trying to remove a
121 a0994761 Aneesh Kumar K.V
         * posix acl that is not present. So don't throw the error
122 a0994761 Aneesh Kumar K.V
         * even in case of mapped security model
123 a0994761 Aneesh Kumar K.V
         */
124 a0994761 Aneesh Kumar K.V
        errno = 0;
125 a0994761 Aneesh Kumar K.V
        ret = 0;
126 a0994761 Aneesh Kumar K.V
    }
127 a0994761 Aneesh Kumar K.V
    return ret;
128 70fc55eb Aneesh Kumar K.V
}
129 70fc55eb Aneesh Kumar K.V
130 70fc55eb Aneesh Kumar K.V
131 70fc55eb Aneesh Kumar K.V
XattrOperations mapped_pacl_xattr = {
132 70fc55eb Aneesh Kumar K.V
    .name = "system.posix_acl_access",
133 70fc55eb Aneesh Kumar K.V
    .getxattr = mp_pacl_getxattr,
134 70fc55eb Aneesh Kumar K.V
    .setxattr = mp_pacl_setxattr,
135 70fc55eb Aneesh Kumar K.V
    .listxattr = mp_pacl_listxattr,
136 70fc55eb Aneesh Kumar K.V
    .removexattr = mp_pacl_removexattr,
137 70fc55eb Aneesh Kumar K.V
};
138 70fc55eb Aneesh Kumar K.V
139 70fc55eb Aneesh Kumar K.V
XattrOperations mapped_dacl_xattr = {
140 70fc55eb Aneesh Kumar K.V
    .name = "system.posix_acl_default",
141 70fc55eb Aneesh Kumar K.V
    .getxattr = mp_dacl_getxattr,
142 70fc55eb Aneesh Kumar K.V
    .setxattr = mp_dacl_setxattr,
143 70fc55eb Aneesh Kumar K.V
    .listxattr = mp_dacl_listxattr,
144 70fc55eb Aneesh Kumar K.V
    .removexattr = mp_dacl_removexattr,
145 70fc55eb Aneesh Kumar K.V
};
146 70fc55eb Aneesh Kumar K.V
147 70fc55eb Aneesh Kumar K.V
XattrOperations passthrough_acl_xattr = {
148 70fc55eb Aneesh Kumar K.V
    .name = "system.posix_acl_",
149 70fc55eb Aneesh Kumar K.V
    .getxattr = pt_getxattr,
150 70fc55eb Aneesh Kumar K.V
    .setxattr = pt_setxattr,
151 70fc55eb Aneesh Kumar K.V
    .listxattr = pt_listxattr,
152 70fc55eb Aneesh Kumar K.V
    .removexattr = pt_removexattr,
153 70fc55eb Aneesh Kumar K.V
};
154 70fc55eb Aneesh Kumar K.V
155 70fc55eb Aneesh Kumar K.V
XattrOperations none_acl_xattr = {
156 70fc55eb Aneesh Kumar K.V
    .name = "system.posix_acl_",
157 70fc55eb Aneesh Kumar K.V
    .getxattr = notsup_getxattr,
158 70fc55eb Aneesh Kumar K.V
    .setxattr = notsup_setxattr,
159 70fc55eb Aneesh Kumar K.V
    .listxattr = notsup_listxattr,
160 70fc55eb Aneesh Kumar K.V
    .removexattr = notsup_removexattr,
161 70fc55eb Aneesh Kumar K.V
};