Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (4.2 kB)

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 "hw/virtio.h"
17
#include "virtio-9p.h"
18
#include "fsdev/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
    char buffer[PATH_MAX];
30
    return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size);
31
}
32

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

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

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

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

    
51
static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
52
                            void *value, size_t size, int flags)
53
{
54
    char buffer[PATH_MAX];
55
    return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value,
56
            size, flags);
57
}
58

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

    
77
static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
78
                                const char *name, void *value, size_t size)
79
{
80
    char buffer[PATH_MAX];
81
    return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size);
82
}
83

    
84
static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
85
                                 char *name, void *value, size_t osize)
86
{
87
    ssize_t len = sizeof(ACL_DEFAULT);
88

    
89
    if (!value) {
90
        return len;
91
    }
92

    
93
    if (osize < len) {
94
        errno = ERANGE;
95
        return -1;
96
    }
97

    
98
    strncpy(value, ACL_DEFAULT, len);
99
    return 0;
100
}
101

    
102
static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
103
                            void *value, size_t size, int flags)
104
{
105
    char buffer[PATH_MAX];
106
    return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value,
107
            size, flags);
108
}
109

    
110
static int mp_dacl_removexattr(FsContext *ctx,
111
                               const char *path, const char *name)
112
{
113
    int ret;
114
    char buffer[PATH_MAX];
115
    ret  = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT);
116
    if (ret == -1 && errno == ENODATA) {
117
        /*
118
         * We don't get ENODATA error when trying to remove a
119
         * posix acl that is not present. So don't throw the error
120
         * even in case of mapped security model
121
         */
122
        errno = 0;
123
        ret = 0;
124
    }
125
    return ret;
126
}
127

    
128

    
129
XattrOperations mapped_pacl_xattr = {
130
    .name = "system.posix_acl_access",
131
    .getxattr = mp_pacl_getxattr,
132
    .setxattr = mp_pacl_setxattr,
133
    .listxattr = mp_pacl_listxattr,
134
    .removexattr = mp_pacl_removexattr,
135
};
136

    
137
XattrOperations mapped_dacl_xattr = {
138
    .name = "system.posix_acl_default",
139
    .getxattr = mp_dacl_getxattr,
140
    .setxattr = mp_dacl_setxattr,
141
    .listxattr = mp_dacl_listxattr,
142
    .removexattr = mp_dacl_removexattr,
143
};
144

    
145
XattrOperations passthrough_acl_xattr = {
146
    .name = "system.posix_acl_",
147
    .getxattr = pt_getxattr,
148
    .setxattr = pt_setxattr,
149
    .listxattr = pt_listxattr,
150
    .removexattr = pt_removexattr,
151
};
152

    
153
XattrOperations none_acl_xattr = {
154
    .name = "system.posix_acl_",
155
    .getxattr = notsup_getxattr,
156
    .setxattr = notsup_setxattr,
157
    .listxattr = notsup_listxattr,
158
    .removexattr = notsup_removexattr,
159
};