Sat, 04 Feb 2017 16:42:11 +0100
refactors kqueue event handler
54 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
29 | #define _POSIX_PTHREAD_SEMANTIS |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
30 | |
54 | 31 | #include <stdio.h> |
32 | #include <stdlib.h> | |
33 | #include <unistd.h> | |
34 | #include <sys/types.h> | |
35 | ||
92
382bff43c6eb
fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
87
diff
changeset
|
36 | #include <ucx/map.h> |
382bff43c6eb
fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
87
diff
changeset
|
37 | |
54 | 38 | #include "../util/pool.h" |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
39 | #include "acl.h" |
54 | 40 | #include "vfs.h" |
41 | ||
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
42 | #define VFS_MALLOC(pool, size) pool ? pool_malloc(pool, size) : malloc(size) |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
43 | #define VFS_FREE(pool, ptr) pool ? pool_free(pool, ptr) : free(ptr) |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
44 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
45 | static UcxMap *vfs_map; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
46 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
47 | static VFS sys_vfs = { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
48 | sys_vfs_open, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
49 | sys_vfs_stat, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
50 | sys_vfs_fstat, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
51 | sys_vfs_opendir, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
52 | sys_vfs_mkdir, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
53 | sys_vfs_unlink, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
54 | VFS_CHECKS_ACL |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
55 | }; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
56 | |
54 | 57 | static VFS_IO sys_file_io = { |
58 | sys_file_read, | |
59 | sys_file_write, | |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
60 | sys_file_seek, |
54 | 61 | sys_file_close |
62 | }; | |
63 | ||
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
64 | static VFS_DIRIO sys_dir_io = { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
65 | sys_dir_read, |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
66 | sys_dir_close |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
67 | }; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
68 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
69 | int vfs_init() { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
70 | vfs_map = ucx_map_new(16); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
71 | if(!vfs_map) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
72 | return -1; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
73 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
74 | return 0; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
75 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
76 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
77 | void vfs_add(char *name, VFS *vfs) { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
78 | WS_ASSERT(name); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
79 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
80 | if(!vfs_map) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
81 | vfs_init(); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
82 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
83 | ucx_map_cstr_put(vfs_map, name, vfs); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
84 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
85 | |
54 | 86 | VFSContext* vfs_request_context(Session *sn, Request *rq) { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
87 | WS_ASSERT(sn); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
88 | WS_ASSERT(rq); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
89 | |
54 | 90 | VFSContext *ctx = pool_malloc(sn->pool, sizeof(VFSContext)); |
91 | ctx->sn = sn; | |
92 | ctx->rq = rq; | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
93 | ctx->vfs = rq->vfs ? rq->vfs : &sys_vfs; |
54 | 94 | ctx->user = acllist_getuser(sn, rq, rq->acllist); |
95 | ctx->acllist = rq->acllist; | |
96 | ctx->aclreqaccess = rq->aclreqaccess; | |
97 | ctx->pool = sn->pool; | |
98 | ctx->vfs_errno = 0; | |
99 | return ctx; | |
100 | } | |
101 | ||
102 | SYS_FILE vfs_open(VFSContext *ctx, char *path, int oflags) { | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
103 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
104 | WS_ASSERT(path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
105 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
106 | uint32_t access_mask = ctx->aclreqaccess | acl_oflag2mask(oflags); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
107 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
108 | // ctx->aclreqaccess should be the complete access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
109 | uint32_t m = ctx->aclreqaccess; // save original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
110 | ctx->aclreqaccess = access_mask; // set mask for vfs->open call |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
111 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
112 | // VFS does not evaluates the ACL itself, so we have to do it here |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
113 | SysACL sysacl; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
114 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
115 | return NULL; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
116 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
117 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
118 | SYS_FILE file = ctx->vfs->open(ctx, path, oflags); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
119 | ctx->aclreqaccess = m; // restore original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
120 | return file; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
121 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
122 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
123 | SYS_FILE vfs_openRO(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
124 | return vfs_open(ctx, path, O_RDONLY); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
125 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
126 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
127 | SYS_FILE vfs_openWO(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
128 | return vfs_open(ctx, path, O_WRONLY | O_CREAT); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
129 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
130 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
131 | SYS_FILE vfs_openRW(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
132 | return vfs_open(ctx, path, O_RDONLY | O_WRONLY | O_CREAT); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
133 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
134 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
135 | int vfs_stat(VFSContext *ctx, char *path, struct stat *buf) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
136 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
137 | WS_ASSERT(path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
138 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
139 | uint32_t access_mask = ctx->aclreqaccess | ACL_READ_ATTRIBUTES; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
140 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
141 | // ctx->aclreqaccess should be the complete access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
142 | uint32_t m = ctx->aclreqaccess; // save original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
143 | ctx->aclreqaccess = access_mask; // set mask for vfs->open call |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
144 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
145 | // VFS does not evaluates the ACL itself, so we have to do it here |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
146 | SysACL sysacl; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
147 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
148 | return -1; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
149 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
150 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
151 | int ret = ctx->vfs->stat(ctx, path, buf); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
152 | ctx->aclreqaccess = m; // restore original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
153 | return ret; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
154 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
155 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
156 | int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
157 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
158 | WS_ASSERT(fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
159 | WS_ASSERT(buf); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
160 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
161 | return ctx->vfs->fstat(ctx, fd, buf); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
162 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
163 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
164 | void vfs_close(SYS_FILE fd) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
165 | WS_ASSERT(fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
166 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
167 | fd->io->close(fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
168 | if(fd->ctx) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
169 | pool_free(fd->ctx->pool, fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
170 | } else { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
171 | free(fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
172 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
173 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
174 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
175 | VFS_DIR vfs_opendir(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
176 | WS_ASSERT(ctx); |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
177 | WS_ASSERT(path); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
178 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
179 | uint32_t access_mask = ctx->aclreqaccess | ACL_LIST; |
54 | 180 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
181 | // ctx->aclreqaccess should be the complete access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
182 | uint32_t m = ctx->aclreqaccess; // save original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
183 | ctx->aclreqaccess = access_mask; // set mask for vfs->open call |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
184 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
185 | // VFS does not evaluates the ACL itself, so we have to do it here |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
186 | SysACL sysacl; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
187 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
188 | return NULL; |
54 | 189 | } |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
190 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
191 | VFS_DIR dir = ctx->vfs->opendir(ctx, path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
192 | ctx->aclreqaccess = m; // restore original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
193 | return dir; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
194 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
195 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
196 | int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
197 | WS_ASSERT(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
198 | WS_ASSERT(entry); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
199 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
200 | return dir->io->readdir(dir, entry, 0); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
201 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
202 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
203 | int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
204 | WS_ASSERT(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
205 | WS_ASSERT(entry); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
206 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
207 | return dir->io->readdir(dir, entry, 1); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
208 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
209 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
210 | void vfs_closedir(VFS_DIR dir) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
211 | WS_ASSERT(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
212 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
213 | dir->io->close(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
214 | if(dir->ctx) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
215 | VFS_FREE(dir->ctx->pool, dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
216 | } else { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
217 | free(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
218 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
219 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
220 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
221 | int vfs_mkdir(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
222 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
223 | WS_ASSERT(path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
224 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
225 | return vfs_path_op(ctx, path, ctx->vfs->mkdir, ACL_ADD_FILE); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
226 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
227 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
228 | int vfs_unlink(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
229 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
230 | WS_ASSERT(path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
231 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
232 | return vfs_path_op(ctx, path, ctx->vfs->unlink, ACL_DELETE); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
233 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
234 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
235 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
236 | // private |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
237 | int vfs_path_op(VFSContext *ctx, char *path, vfs_op_f op, uint32_t access) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
238 | uint32_t access_mask = ctx->aclreqaccess; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
239 | access_mask |= access; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
240 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
241 | // ctx->aclreqaccess should be the complete access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
242 | uint32_t m = ctx->aclreqaccess; // save original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
243 | ctx->aclreqaccess = access_mask; // set mask for vfs function call |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
244 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
245 | // VFS does not evaluates the ACL itself, so we have to do it here |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
246 | SysACL sysacl; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
247 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
248 | return -1; |
54 | 249 | } |
250 | } | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
251 | int ret = op(ctx, path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
252 | ctx->aclreqaccess = m; // restore original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
253 | return ret; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
254 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
255 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
256 | /* system vfs implementation */ |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
257 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
258 | SYS_FILE sys_vfs_open(VFSContext *ctx, char *path, int oflags) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
259 | uint32_t access_mask = ctx->aclreqaccess; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
260 | pool_handle_t *pool = ctx->pool; |
54 | 261 | |
262 | // check ACLs | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
263 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
264 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
54 | 265 | return NULL; |
266 | } | |
267 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
268 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
269 | if(!fs_acl_check(&sysacl, ctx->user, path, access_mask)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
270 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
271 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
272 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
273 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
274 | |
54 | 275 | // open file |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
276 | mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
277 | int fd = open(path, oflags, mode); |
54 | 278 | if(fd == -1) { |
279 | if(ctx) { | |
280 | ctx->vfs_errno = errno; | |
281 | sys_set_error_status(ctx); | |
282 | } | |
283 | return NULL; | |
284 | } | |
285 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
286 | // if a file system acl is active, we set the owner for newly created files |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
287 | if(((oflags & O_CREAT) == O_CREAT) && sysacl.user_uid != -1) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
288 | if(fchown(fd, sysacl.user_uid, sysacl.user_gid)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
289 | perror("vfs_open: fchown"); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
290 | close(fd); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
291 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
292 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
293 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
294 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
295 | VFSFile *file = VFS_MALLOC(pool, sizeof(VFSFile)); |
54 | 296 | if(!file) { |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
297 | close(fd); |
54 | 298 | return NULL; |
299 | } | |
300 | file->ctx = ctx; | |
301 | file->data = NULL; | |
302 | file->fd = fd; | |
303 | file->io = &sys_file_io; | |
304 | return file; | |
305 | } | |
306 | ||
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
307 | int sys_vfs_stat(VFSContext *ctx, char *path, struct stat *buf) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
308 | uint32_t access_mask = ctx->aclreqaccess; |
54 | 309 | |
310 | // check ACLs | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
311 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
312 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
57 | 313 | return -1; |
54 | 314 | } |
315 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
316 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
317 | if(!fs_acl_check(&sysacl, ctx->user, path, access_mask)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
318 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
319 | return -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
320 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
321 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
322 | |
54 | 323 | // stat |
324 | if(stat(path, buf)) { | |
325 | if(ctx) { | |
326 | ctx->vfs_errno = errno; | |
327 | sys_set_error_status(ctx); | |
328 | } | |
329 | return -1; | |
330 | } | |
331 | ||
332 | return 0; | |
333 | } | |
334 | ||
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
335 | int sys_vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) { |
54 | 336 | // stat |
337 | if(fstat(fd->fd, buf)) { | |
338 | if(ctx) { | |
339 | ctx->vfs_errno = errno; | |
340 | } | |
341 | return -1; | |
342 | } | |
343 | ||
344 | return 0; | |
345 | } | |
346 | ||
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
347 | VFS_DIR sys_vfs_opendir(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
348 | uint32_t access_mask = ctx->aclreqaccess; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
349 | pool_handle_t *pool = ctx->pool; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
350 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
351 | // check ACLs |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
352 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
353 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
354 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
355 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
356 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
357 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
358 | if(!fs_acl_check(&sysacl, ctx->user, path, access_mask)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
359 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
360 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
361 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
362 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
363 | |
72 | 364 | // open directory |
365 | #ifdef BSD | |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
366 | DIR *sys_dir = opendir(path); |
97
09fbefc0e6a9
added ldap group support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
367 | int dir_fd = sys_dir ? dirfd(sys_dir) : 0; |
72 | 368 | #else |
369 | int dir_fd = open(path, O_RDONLY); | |
370 | if(dir_fd == -1) { | |
371 | if(ctx) { | |
372 | ctx->vfs_errno = errno; | |
373 | sys_set_error_status(ctx); | |
374 | } | |
375 | return NULL; | |
376 | } | |
377 | DIR *sys_dir = fdopendir(dir_fd); | |
378 | #endif | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
379 | if(!sys_dir) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
380 | if(ctx) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
381 | ctx->vfs_errno = errno; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
382 | sys_set_error_status(ctx); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
383 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
384 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
385 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
386 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
387 | SysVFSDir *dir_data = VFS_MALLOC(pool, sizeof(SysVFSDir)); |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
388 | if(!dir_data) { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
389 | closedir(sys_dir); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
390 | return NULL; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
391 | } |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
392 | long maxfilelen = fpathconf(dir_fd, _PC_NAME_MAX); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
393 | size_t entry_len = offsetof(struct dirent, d_name) + maxfilelen + 1; |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
394 | dir_data->cur = VFS_MALLOC(pool, entry_len); |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
395 | if(!dir_data->cur) { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
396 | closedir(sys_dir); |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
397 | VFS_FREE(pool, dir_data); |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
398 | return NULL; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
399 | } |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
400 | dir_data->dir = sys_dir; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
401 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
402 | VFSDir *dir = VFS_MALLOC(pool, sizeof(VFSDir)); |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
403 | if(!dir) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
404 | closedir(sys_dir); |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
405 | VFS_FREE(pool, dir_data->cur); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
406 | VFS_FREE(pool, dir_data); |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
407 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
408 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
409 | dir->ctx = ctx; |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
410 | dir->data = dir_data; |
72 | 411 | dir->fd = dir_fd; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
412 | dir->io = &sys_dir_io; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
413 | return dir; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
414 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
415 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
416 | int sys_vfs_mkdir(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
417 | return sys_path_op(ctx, path, sys_mkdir); |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
418 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
419 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
420 | int sys_vfs_unlink(VFSContext *ctx, char *path) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
421 | return sys_path_op(ctx, path, sys_unlink); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
422 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
423 | |
54 | 424 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
425 | int sys_path_op(VFSContext *ctx, char *path, sys_op_f op) { |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
426 | uint32_t access_mask = ctx->aclreqaccess; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
427 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
428 | // check ACLs |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
429 | SysACL sysacl; |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
430 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
57 | 431 | return -1; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
432 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
433 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
434 | if(sysacl.acl) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
435 | if(!fs_acl_check(&sysacl, ctx->user, path, access_mask)) { |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
436 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
437 | return -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
438 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
439 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
440 | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
441 | // do path operation |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
442 | if(op(ctx, path, &sysacl)) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
443 | // error |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
444 | ctx->vfs_errno = errno; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
445 | sys_set_error_status(ctx); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
446 | return -1; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
447 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
448 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
449 | return 0; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
450 | } |
54 | 451 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
452 | int sys_acl_check(VFSContext *ctx, uint32_t access_mask, SysACL *sysacl) { |
67
50505dc3f8a6
dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
453 | if(sysacl) { |
50505dc3f8a6
dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
454 | sysacl->acl = NULL; |
50505dc3f8a6
dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
455 | } |
54 | 456 | if(!ctx) { |
457 | return 0; | |
458 | } | |
459 | ||
460 | ACLListHandle *acllist = ctx->acllist; | |
461 | if(acllist) { | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
462 | ACLList *acl = acl_evallist( |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
463 | acllist, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
464 | ctx->user, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
465 | access_mask, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
466 | &sysacl->acl); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
467 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
468 | if(acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
469 | acl_set_error_status(ctx->sn, ctx->rq, acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
470 | return 1; |
54 | 471 | } |
472 | } | |
473 | ||
474 | return 0; | |
475 | } | |
476 | ||
477 | void sys_set_error_status(VFSContext *ctx) { | |
478 | if(ctx->sn && ctx->rq) { | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
479 | int status = util_errno2status(ctx->vfs_errno); |
54 | 480 | protocol_status(ctx->sn, ctx->rq, status, NULL); |
481 | } | |
482 | } | |
483 | ||
484 | ssize_t sys_file_read(SYS_FILE fd, void *buf, size_t nbyte) { | |
485 | return read(fd->fd, buf, nbyte); | |
486 | } | |
487 | ||
488 | ssize_t sys_file_write(SYS_FILE fd, const void *buf, size_t nbyte) { | |
489 | return write(fd->fd, buf, nbyte); | |
490 | } | |
491 | ||
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
492 | off_t sys_file_seek(SYS_FILE fd, off_t offset, int whence) { |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
493 | return lseek(fd->fd, offset, whence); |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
494 | } |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
495 | |
54 | 496 | void sys_file_close(SYS_FILE fd) { |
497 | close(fd->fd); | |
498 | } | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
499 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
500 | int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) { |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
501 | SysVFSDir *dirdata = dir->data; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
502 | struct dirent *result = NULL; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
503 | int s = readdir_r(dirdata->dir, dirdata->cur, &result); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
504 | if(!s && result) { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
505 | char *name = result->d_name; |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
506 | if(!strcmp(name, ".") || !strcmp(name, "..")) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
507 | return sys_dir_read(dir, entry, getstat); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
508 | } else { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
509 | entry->name = name; |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
510 | #ifndef OSX |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
511 | /* TODO: |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
512 | * implement alternative for fstat for OS X and other crappy |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
513 | * Unices |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
514 | */ |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
515 | if(getstat) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
516 | // TODO: check ACLs again for new path |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
517 | if(fstatat(dir->fd, result->d_name, &entry->stat, 0)) { |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
518 | entry->stat_errno = errno; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
519 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
520 | entry->stat_extra = NULL; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
521 | } |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
522 | #endif |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
523 | return 1; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
524 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
525 | } else { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
526 | return 0; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
527 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
528 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
529 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
530 | void sys_dir_close(VFS_DIR dir) { |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
531 | SysVFSDir *dirdata = dir->data; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
532 | closedir(dirdata->dir); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
533 | |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
534 | pool_handle_t *pool = dir->ctx->pool; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
535 | if(pool) { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
536 | pool_free(pool, dirdata->cur); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
537 | pool_free(pool, dirdata); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
538 | pool_free(pool, dir); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
539 | } else { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
540 | free(dirdata->cur); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
541 | free(dirdata); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
542 | free(dir); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
543 | } |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
544 | } |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
545 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
546 | int sys_mkdir(VFSContext *ctx, char *path, SysACL *sysacl) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
547 | mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
548 | int ret = mkdir(path, mode); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
549 | if(ret == 0) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
550 | if(sysacl->user_uid != -1) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
551 | if(chown(path, sysacl->user_uid, sysacl->user_gid)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
552 | // TODO: error |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
553 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
554 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
555 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
556 | return ret; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
557 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
558 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
559 | int sys_unlink(VFSContext *ctx, char *path, SysACL *sysacl) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
560 | return unlink(path); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
561 | } |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
562 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
563 | /* public file api */ |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
564 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
565 | NSAPI_PUBLIC int system_fread(SYS_FILE fd, void *buf, int nbyte) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
566 | return fd->io->read(fd, buf, nbyte); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
567 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
568 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
569 | NSAPI_PUBLIC int system_fwrite(SYS_FILE fd, const void *buf, int nbyte) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
570 | return fd->io->write(fd, buf, nbyte); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
571 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
572 | |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
573 | NSAPI_PUBLIC off_t system_lseek(SYS_FILE fd, off_t offset, int whence) { |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
574 | return fd->io->seek(fd, offset, whence); |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
575 | } |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
576 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
577 | NSAPI_PUBLIC int system_fclose(SYS_FILE fd) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
578 | vfs_close(fd); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
579 | return 0; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
580 | } |