Wed, 31 Jul 2013 11:35:57 +0200
fixed solaris build
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 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | #include <unistd.h> | |
32 | #include <sys/types.h> | |
33 | ||
34 | #include "../util/pool.h" | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
35 | #include "../ucx/map.h" |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
36 | #include "acl.h" |
54 | 37 | #include "vfs.h" |
38 | ||
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
39 | static UcxMap *vfs_map; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
40 | |
54 | 41 | static VFS_IO sys_file_io = { |
42 | sys_file_read, | |
43 | sys_file_write, | |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
44 | sys_file_seek, |
54 | 45 | sys_file_close |
46 | }; | |
47 | ||
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
48 | static VFS_DIRIO sys_dir_io = { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
49 | sys_dir_read, |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
50 | sys_dir_close |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
51 | }; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
52 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
53 | int vfs_init() { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
54 | vfs_map = ucx_map_new(16); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
55 | if(!vfs_map) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
56 | return -1; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
57 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
58 | return 0; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
59 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
60 | |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
61 | void vfs_add(char *name, VFS *vfs) { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
62 | WS_ASSERT(name); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
63 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
64 | if(!vfs_map) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
65 | vfs_init(); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
66 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
67 | 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
|
68 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
69 | |
54 | 70 | VFSContext* vfs_request_context(Session *sn, Request *rq) { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
71 | WS_ASSERT(sn); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
72 | WS_ASSERT(rq); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
73 | |
54 | 74 | VFSContext *ctx = pool_malloc(sn->pool, sizeof(VFSContext)); |
75 | ctx->sn = sn; | |
76 | ctx->rq = rq; | |
77 | ctx->vfs = rq->vfs; | |
78 | ctx->user = acllist_getuser(sn, rq, rq->acllist); | |
79 | ctx->acllist = rq->acllist; | |
80 | ctx->aclreqaccess = rq->aclreqaccess; | |
81 | ctx->pool = sn->pool; | |
82 | ctx->vfs_errno = 0; | |
83 | return ctx; | |
84 | } | |
85 | ||
86 | SYS_FILE vfs_open(VFSContext *ctx, char *path, int oflags) { | |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
87 | WS_ASSERT(path); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
88 | |
54 | 89 | Session *sn; |
90 | Request *rq; | |
91 | pool_handle_t *pool; | |
92 | uint32_t access_mask; | |
93 | ||
94 | if(ctx) { | |
95 | access_mask = ctx->aclreqaccess; | |
96 | access_mask |= acl_oflag2mask(oflags); | |
97 | if(!ctx->pool) { | |
98 | // TODO: log warning | |
99 | // broken VFSContext | |
100 | } | |
101 | if(ctx->vfs) { | |
102 | // ctx->aclreqaccess should be the complete access mask | |
103 | uint32_t m = ctx->aclreqaccess; // save original access mask | |
104 | ctx->aclreqaccess = access_mask; // set mask for vfs->open call | |
105 | SYS_FILE file = ctx->vfs->open(ctx, path, oflags); | |
106 | ctx->aclreqaccess = m; // restore original access mask | |
107 | return file; | |
108 | } else { | |
109 | pool = ctx->pool; | |
110 | } | |
111 | } else { | |
112 | sn = NULL; | |
113 | rq = NULL; | |
114 | pool = NULL; | |
115 | access_mask = acl_oflag2mask(oflags); | |
116 | } | |
117 | ||
118 | // check ACLs | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
119 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
120 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
54 | 121 | return NULL; |
122 | } | |
123 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
124 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
125 | 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
|
126 | 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
|
127 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
128 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
129 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
130 | |
54 | 131 | // open file |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
132 | 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
|
133 | int fd = open(path, oflags, mode); |
54 | 134 | if(fd == -1) { |
135 | if(ctx) { | |
136 | ctx->vfs_errno = errno; | |
137 | sys_set_error_status(ctx); | |
138 | } | |
139 | return NULL; | |
140 | } | |
141 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
142 | // 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
|
143 | 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
|
144 | 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
|
145 | perror("vfs_open: fchown"); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
146 | close(fd); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
147 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
148 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
149 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
150 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
151 | |
54 | 152 | VFSFile *file = pool ? |
153 | pool_malloc(pool, sizeof(VFSFile)) : malloc(sizeof(VFSFile)); | |
154 | if(!file) { | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
155 | close(fd); |
54 | 156 | return NULL; |
157 | } | |
158 | file->ctx = ctx; | |
159 | file->data = NULL; | |
160 | file->fd = fd; | |
161 | file->io = &sys_file_io; | |
162 | return file; | |
163 | } | |
164 | ||
165 | SYS_FILE vfs_openRO(VFSContext *ctx, char *path) { | |
166 | return vfs_open(ctx, path, O_RDONLY); | |
167 | } | |
168 | ||
169 | SYS_FILE vfs_openWO(VFSContext *ctx, char *path) { | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
170 | return vfs_open(ctx, path, O_WRONLY | O_CREAT); |
54 | 171 | } |
172 | ||
173 | SYS_FILE vfs_openRW(VFSContext *ctx, char *path) { | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
174 | return vfs_open(ctx, path, O_RDONLY | O_WRONLY | O_CREAT); |
54 | 175 | } |
176 | ||
177 | int vfs_stat(VFSContext *ctx, char *path, struct stat *buf) { | |
178 | Session *sn; | |
179 | Request *rq; | |
180 | uint32_t access_mask; | |
181 | ||
182 | if(ctx) { | |
183 | access_mask = ctx->aclreqaccess; | |
184 | access_mask |= ACL_READ_ATTRIBUTES; | |
185 | if(!ctx->pool) { | |
186 | // TODO: log warning | |
187 | // broken VFSContext | |
188 | } | |
189 | if(ctx->vfs) { | |
190 | // ctx->aclreqaccess should be the complete access mask | |
191 | uint32_t m = ctx->aclreqaccess; // save original access mask | |
192 | ctx->aclreqaccess = access_mask; // set mask for vfs->fstat call | |
193 | int ret = ctx->vfs->stat(ctx, path, buf); | |
194 | ctx->aclreqaccess = m; // restore original access mask | |
195 | return ret; | |
196 | } | |
197 | } else { | |
198 | sn = NULL; | |
199 | rq = NULL; | |
200 | access_mask = ACL_READ_ATTRIBUTES; | |
201 | } | |
202 | ||
203 | // check ACLs | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
204 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
205 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
57 | 206 | return -1; |
54 | 207 | } |
208 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
209 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
210 | 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
|
211 | 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
|
212 | return -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
213 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
214 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
215 | |
54 | 216 | // stat |
217 | if(stat(path, buf)) { | |
218 | if(ctx) { | |
219 | ctx->vfs_errno = errno; | |
220 | sys_set_error_status(ctx); | |
221 | } | |
222 | return -1; | |
223 | } | |
224 | ||
225 | return 0; | |
226 | } | |
227 | ||
228 | int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) { | |
229 | if(ctx) { | |
230 | if(!ctx->pool) { | |
231 | // TODO: log warning | |
232 | // broken VFSContext | |
233 | } | |
234 | if(ctx->vfs) { | |
235 | return ctx->vfs->fstat(ctx, fd, buf); | |
236 | } | |
237 | } | |
238 | ||
239 | // stat | |
240 | if(fstat(fd->fd, buf)) { | |
241 | if(ctx) { | |
242 | ctx->vfs_errno = errno; | |
243 | } | |
244 | return -1; | |
245 | } | |
246 | ||
247 | return 0; | |
248 | } | |
249 | ||
250 | void vfs_close(SYS_FILE fd) { | |
251 | fd->io->close(fd); | |
252 | if(fd->ctx) { | |
253 | pool_free(fd->ctx->pool, fd); | |
254 | } else { | |
255 | free(fd); | |
256 | } | |
257 | } | |
258 | ||
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
259 | VFS_DIR vfs_opendir(VFSContext *ctx, char *path) { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
260 | WS_ASSERT(path); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
261 | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
262 | Session *sn; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
263 | Request *rq; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
264 | pool_handle_t *pool; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
265 | uint32_t access_mask; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
266 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
267 | if(ctx) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
268 | access_mask = ctx->aclreqaccess; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
269 | access_mask |= ACL_LIST; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
270 | if(!ctx->pool) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
271 | // TODO: log warning |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
272 | // broken VFSContext |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
273 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
274 | if(ctx->vfs) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
275 | // ctx->aclreqaccess should be the complete access mask |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
276 | uint32_t m = ctx->aclreqaccess; // save original access mask |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
277 | ctx->aclreqaccess = access_mask; // set mask for vfs->opendir call |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
278 | VFS_DIR dir = ctx->vfs->opendir(ctx, path); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
279 | ctx->aclreqaccess = m; // restore original access mask |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
280 | return dir; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
281 | } else { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
282 | pool = ctx->pool; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
283 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
284 | } else { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
285 | sn = NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
286 | rq = NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
287 | pool = NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
288 | access_mask = ACL_LIST; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
289 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
290 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
291 | // check ACLs |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
292 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
293 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
294 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
295 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
296 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
297 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
298 | 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
|
299 | 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
|
300 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
301 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
302 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
303 | |
72 | 304 | // open directory |
305 | #ifdef BSD | |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
306 | DIR *sys_dir = opendir(path); |
72 | 307 | if(sys_dir) { |
308 | int dir_fd = dirfd(sys_dir); | |
309 | } | |
310 | #else | |
311 | int dir_fd = open(path, O_RDONLY); | |
312 | if(dir_fd == -1) { | |
313 | if(ctx) { | |
314 | ctx->vfs_errno = errno; | |
315 | sys_set_error_status(ctx); | |
316 | } | |
317 | return NULL; | |
318 | } | |
319 | DIR *sys_dir = fdopendir(dir_fd); | |
320 | #endif | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
321 | if(!sys_dir) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
322 | if(ctx) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
323 | ctx->vfs_errno = errno; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
324 | sys_set_error_status(ctx); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
325 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
326 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
327 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
328 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
329 | VFSDir *dir = pool ? |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
330 | pool_malloc(pool, sizeof(VFSDir)) : malloc(sizeof(VFSDir)); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
331 | if(!dir) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
332 | closedir(sys_dir); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
333 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
334 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
335 | dir->ctx = ctx; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
336 | dir->data = sys_dir; |
72 | 337 | dir->fd = dir_fd; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
338 | dir->io = &sys_dir_io; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
339 | return dir; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
340 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
341 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
342 | int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
343 | return dir->io->readdir(dir, entry, 0); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
344 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
345 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
346 | int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
347 | return dir->io->readdir(dir, entry, 1); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
348 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
349 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
350 | void vfs_closedir(VFS_DIR dir) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
351 | dir->io->close(dir); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
352 | if(dir->ctx) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
353 | pool_free(dir->ctx->pool, dir); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
354 | } else { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
355 | free(dir); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
356 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
357 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
358 | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
359 | int vfs_mkdir(VFSContext *ctx, char *path) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
360 | if(ctx && ctx->vfs) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
361 | return vfs_path_op(ctx, path, ctx->vfs->mkdir, ACL_ADD_FILE); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
362 | } else { |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
363 | return sys_path_op(ctx, path, sys_mkdir, ACL_ADD_FILE); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
364 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
365 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
366 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
367 | int vfs_unlink(VFSContext *ctx, char *path) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
368 | if(ctx && ctx->vfs) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
369 | return vfs_path_op(ctx, path, ctx->vfs->unlink, ACL_DELETE); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
370 | } else { |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
371 | return sys_path_op(ctx, path, sys_unlink, ACL_DELETE); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
372 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
373 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
374 | |
54 | 375 | |
376 | // private | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
377 | int vfs_path_op(VFSContext *ctx, char *path, vfs_op_f op, uint32_t access) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
378 | Session *sn; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
379 | Request *rq; |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
380 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
381 | uint32_t access_mask = ctx->aclreqaccess; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
382 | access_mask |= access; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
383 | if(!ctx->pool) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
384 | // TODO: log warning |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
385 | // broken VFSContext |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
386 | return -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
387 | } |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
388 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
389 | // ctx->aclreqaccess should be the complete access mask |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
390 | uint32_t m = ctx->aclreqaccess; // save original access mask |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
391 | ctx->aclreqaccess = access_mask; // set mask for vfs function call |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
392 | int ret = op(ctx, path); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
393 | ctx->aclreqaccess = m; // restore original access mask |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
394 | return ret; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
395 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
396 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
397 | int sys_path_op(VFSContext *ctx, char *path, sys_op_f op, uint32_t access) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
398 | if(ctx) { |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
399 | access |= ctx->aclreqaccess; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
400 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
401 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
402 | // check ACLs |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
403 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
404 | if(sys_acl_check(ctx, access, &sysacl)) { |
57 | 405 | return -1; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
406 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
407 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
408 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
409 | if(!fs_acl_check(&sysacl, ctx->user, path, access)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
410 | 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
|
411 | return -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
412 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
413 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
414 | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
415 | // do path operation |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
416 | if(op(ctx, path, &sysacl)) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
417 | // error |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
418 | if(ctx) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
419 | ctx->vfs_errno = errno; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
420 | sys_set_error_status(ctx); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
421 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
422 | return -1; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
423 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
424 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
425 | return 0; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
426 | } |
54 | 427 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
428 | 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
|
429 | if(sysacl) { |
50505dc3f8a6
dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
430 | sysacl->acl = NULL; |
50505dc3f8a6
dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
431 | } |
54 | 432 | if(!ctx) { |
433 | return 0; | |
434 | } | |
435 | ||
436 | ACLListHandle *acllist = ctx->acllist; | |
437 | if(acllist) { | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
438 | ACLList *acl = acl_evallist( |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
439 | acllist, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
440 | ctx->user, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
441 | access_mask, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
442 | &sysacl->acl); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
443 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
444 | if(acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
445 | 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
|
446 | return 1; |
54 | 447 | } |
448 | } | |
449 | ||
450 | return 0; | |
451 | } | |
452 | ||
453 | void sys_set_error_status(VFSContext *ctx) { | |
454 | if(ctx->sn && ctx->rq) { | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
455 | int status = util_errno2status(ctx->vfs_errno); |
54 | 456 | protocol_status(ctx->sn, ctx->rq, status, NULL); |
457 | } | |
458 | } | |
459 | ||
460 | ssize_t sys_file_read(SYS_FILE fd, void *buf, size_t nbyte) { | |
461 | return read(fd->fd, buf, nbyte); | |
462 | } | |
463 | ||
464 | ssize_t sys_file_write(SYS_FILE fd, const void *buf, size_t nbyte) { | |
465 | return write(fd->fd, buf, nbyte); | |
466 | } | |
467 | ||
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
468 | 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
|
469 | return lseek(fd->fd, offset, whence); |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
470 | } |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
471 | |
54 | 472 | void sys_file_close(SYS_FILE fd) { |
473 | close(fd->fd); | |
474 | } | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
475 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
476 | int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
477 | struct dirent *e = readdir(dir->data); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
478 | if(e) { |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
479 | char *name = e->d_name; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
480 | if(!strcmp(name, ".") || !strcmp(name, "..")) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
481 | return sys_dir_read(dir, entry, getstat); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
482 | } else { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
483 | entry->name = name; |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
484 | #ifndef OSX |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
485 | /* TODO: |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
486 | * 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
|
487 | * Unices |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
488 | */ |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
489 | if(getstat) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
490 | // TODO: check ACLs again for new path |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
491 | if(fstatat(dir->fd, e->d_name, &entry->stat, 0)) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
492 | entry->stat_errno = errno; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
493 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
494 | entry->stat_extra = NULL; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
495 | } |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
496 | #endif |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
497 | return 1; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
498 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
499 | } else { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
500 | return 0; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
501 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
502 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
503 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
504 | void sys_dir_close(VFS_DIR dir) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
505 | closedir(dir->data); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
506 | } |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
507 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
508 | 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
|
509 | 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
|
510 | int ret = mkdir(path, mode); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
511 | if(ret == 0) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
512 | if(sysacl->user_uid != -1) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
513 | 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
|
514 | // TODO: error |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
515 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
516 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
517 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
518 | return ret; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
519 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
520 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
521 | 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
|
522 | return unlink(path); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
523 | } |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
524 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
525 | /* public file api */ |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
526 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
527 | 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
|
528 | return fd->io->read(fd, buf, nbyte); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
529 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
530 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
531 | 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
|
532 | return fd->io->write(fd, buf, nbyte); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
533 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
534 | |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
535 | 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
|
536 | return fd->io->seek(fd, offset, whence); |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
537 | } |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
538 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
539 | NSAPI_PUBLIC int system_fclose(SYS_FILE fd) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
540 | vfs_close(fd); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
541 | return 0; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
542 | } |