97 VFSContext* vfs_request_context(Session *sn, Request *rq) { |
97 VFSContext* vfs_request_context(Session *sn, Request *rq) { |
98 WS_ASSERT(sn); |
98 WS_ASSERT(sn); |
99 WS_ASSERT(rq); |
99 WS_ASSERT(rq); |
100 |
100 |
101 VFSContext *ctx = pool_malloc(sn->pool, sizeof(VFSContext)); |
101 VFSContext *ctx = pool_malloc(sn->pool, sizeof(VFSContext)); |
|
102 if(!ctx) { |
|
103 return NULL; |
|
104 } |
102 ctx->sn = sn; |
105 ctx->sn = sn; |
103 ctx->rq = rq; |
106 ctx->rq = rq; |
104 ctx->vfs = rq->vfs ? rq->vfs : &sys_vfs; |
107 ctx->vfs = rq->vfs ? rq->vfs : &sys_vfs; |
105 ctx->user = acllist_getuser(sn, rq, rq->acllist); |
108 ctx->user = acllist_getuser(sn, rq, rq->acllist); |
106 ctx->acllist = rq->acllist; |
109 ctx->acllist = rq->acllist; |
129 SYS_FILE file = ctx->vfs->open(ctx, path, oflags); |
132 SYS_FILE file = ctx->vfs->open(ctx, path, oflags); |
130 ctx->aclreqaccess = m; // restore original access mask |
133 ctx->aclreqaccess = m; // restore original access mask |
131 return file; |
134 return file; |
132 } |
135 } |
133 |
136 |
134 SYS_FILE vfs_openRO(VFSContext *ctx, char *path) { |
137 SYS_FILE vfs_openRO(VFSContext *ctx, const char *path) { |
135 return vfs_open(ctx, path, O_RDONLY); |
138 return vfs_open(ctx, path, O_RDONLY); |
136 } |
139 } |
137 |
140 |
138 SYS_FILE vfs_openWO(VFSContext *ctx, char *path) { |
141 SYS_FILE vfs_openWO(VFSContext *ctx, const char *path) { |
139 return vfs_open(ctx, path, O_WRONLY | O_CREAT); |
142 return vfs_open(ctx, path, O_WRONLY | O_CREAT); |
140 } |
143 } |
141 |
144 |
142 SYS_FILE vfs_openRW(VFSContext *ctx, char *path) { |
145 SYS_FILE vfs_openRW(VFSContext *ctx, const char *path) { |
143 return vfs_open(ctx, path, O_RDONLY | O_WRONLY | O_CREAT); |
146 return vfs_open(ctx, path, O_RDONLY | O_WRONLY | O_CREAT); |
144 } |
147 } |
145 |
148 |
146 int vfs_stat(VFSContext *ctx, char *path, struct stat *buf) { |
149 int vfs_stat(VFSContext *ctx, const char *path, struct stat *buf) { |
147 WS_ASSERT(ctx); |
150 WS_ASSERT(ctx); |
148 WS_ASSERT(path); |
151 WS_ASSERT(path); |
149 |
152 |
150 uint32_t access_mask = ctx->aclreqaccess | ACL_READ_ATTRIBUTES; |
153 uint32_t access_mask = ctx->aclreqaccess | ACL_READ_ATTRIBUTES; |
151 |
154 |
248 } else { |
251 } else { |
249 free(dir); |
252 free(dir); |
250 } |
253 } |
251 } |
254 } |
252 |
255 |
253 int vfs_mkdir(VFSContext *ctx, char *path) { |
256 int vfs_mkdir(VFSContext *ctx, const char *path) { |
254 WS_ASSERT(ctx); |
257 WS_ASSERT(ctx); |
255 WS_ASSERT(path); |
258 WS_ASSERT(path); |
256 |
259 |
257 return vfs_path_op(ctx, path, ctx->vfs->mkdir, ACL_ADD_FILE); |
260 return vfs_path_op(ctx, path, ctx->vfs->mkdir, ACL_ADD_FILE); |
258 } |
261 } |
259 |
262 |
260 int vfs_unlink(VFSContext *ctx, char *path) { |
263 int vfs_unlink(VFSContext *ctx, const char *path) { |
261 WS_ASSERT(ctx); |
264 WS_ASSERT(ctx); |
262 WS_ASSERT(path); |
265 WS_ASSERT(path); |
263 |
266 |
264 return vfs_path_op(ctx, path, ctx->vfs->unlink, ACL_DELETE); |
267 return vfs_path_op(ctx, path, ctx->vfs->unlink, ACL_DELETE); |
265 } |
268 } |
266 |
269 |
267 |
270 |
268 // private |
271 // private |
269 int vfs_path_op(VFSContext *ctx, char *path, vfs_op_f op, uint32_t access) { |
272 int vfs_path_op(VFSContext *ctx, const char *path, vfs_op_f op, uint32_t access) { |
270 uint32_t access_mask = ctx->aclreqaccess; |
273 uint32_t access_mask = ctx->aclreqaccess; |
271 access_mask |= access; |
274 access_mask |= access; |
272 |
275 |
273 // ctx->aclreqaccess should be the complete access mask |
276 // ctx->aclreqaccess should be the complete access mask |
274 uint32_t m = ctx->aclreqaccess; // save original access mask |
277 uint32_t m = ctx->aclreqaccess; // save original access mask |
285 return ret; |
288 return ret; |
286 } |
289 } |
287 |
290 |
288 /* system vfs implementation */ |
291 /* system vfs implementation */ |
289 |
292 |
290 SYS_FILE sys_vfs_open(VFSContext *ctx, char *path, int oflags) { |
293 SYS_FILE sys_vfs_open(VFSContext *ctx, const char *path, int oflags) { |
291 uint32_t access_mask = ctx->aclreqaccess; |
294 uint32_t access_mask = ctx->aclreqaccess; |
292 pool_handle_t *pool = ctx->pool; |
295 pool_handle_t *pool = ctx->pool; |
293 |
296 |
294 // check ACLs |
297 // check ACLs |
295 SysACL sysacl; |
298 SysACL sysacl; |
334 file->fd = fd; |
337 file->fd = fd; |
335 file->io = &sys_file_io; |
338 file->io = &sys_file_io; |
336 return file; |
339 return file; |
337 } |
340 } |
338 |
341 |
339 int sys_vfs_stat(VFSContext *ctx, char *path, struct stat *buf) { |
342 int sys_vfs_stat(VFSContext *ctx, const char *path, struct stat *buf) { |
340 uint32_t access_mask = ctx->aclreqaccess; |
343 uint32_t access_mask = ctx->aclreqaccess; |
341 |
344 |
342 // check ACLs |
345 // check ACLs |
343 SysACL sysacl; |
346 SysACL sysacl; |
344 if(sys_acl_check(ctx, access_mask, &sysacl)) { |
347 if(sys_acl_check(ctx, access_mask, &sysacl)) { |
499 dir->fd = fd->fd; |
502 dir->fd = fd->fd; |
500 dir->io = &sys_dir_io; |
503 dir->io = &sys_dir_io; |
501 return dir; |
504 return dir; |
502 } |
505 } |
503 |
506 |
504 int sys_vfs_mkdir(VFSContext *ctx, char *path) { |
507 int sys_vfs_mkdir(VFSContext *ctx, const char *path) { |
505 return sys_path_op(ctx, path, sys_mkdir); |
508 return sys_path_op(ctx, path, sys_mkdir); |
506 } |
509 } |
507 |
510 |
508 int sys_vfs_unlink(VFSContext *ctx, char *path) { |
511 int sys_vfs_unlink(VFSContext *ctx, const char *path) { |
509 return sys_path_op(ctx, path, sys_unlink); |
512 return sys_path_op(ctx, path, sys_unlink); |
510 } |
513 } |
511 |
514 |
512 |
515 |
513 int sys_path_op(VFSContext *ctx, char *path, sys_op_f op) { |
516 int sys_path_op(VFSContext *ctx, const char *path, sys_op_f op) { |
514 uint32_t access_mask = ctx->aclreqaccess; |
517 uint32_t access_mask = ctx->aclreqaccess; |
515 |
518 |
516 // check ACLs |
519 // check ACLs |
517 SysACL sysacl; |
520 SysACL sysacl; |
518 if(sys_acl_check(ctx, access_mask, &sysacl)) { |
521 if(sys_acl_check(ctx, access_mask, &sysacl)) { |
645 free(dirdata); |
648 free(dirdata); |
646 free(dir); |
649 free(dir); |
647 } |
650 } |
648 } |
651 } |
649 |
652 |
650 int sys_mkdir(VFSContext *ctx, char *path, SysACL *sysacl) { |
653 int sys_mkdir(VFSContext *ctx, const char *path, SysACL *sysacl) { |
651 mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
654 mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
652 int ret = mkdir(path, mode); |
655 int ret = mkdir(path, mode); |
653 if(ret == 0) { |
656 if(ret == 0) { |
654 if(sysacl->user_uid != -1) { |
657 if(sysacl->user_uid != -1) { |
655 if(chown(path, sysacl->user_uid, sysacl->user_gid)) { |
658 if(chown(path, sysacl->user_uid, sysacl->user_gid)) { |