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