Statistics
| Branch: | Revision:

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

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