src/server/daemon/vfs.c

Sat, 21 Jan 2017 15:31:17 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 21 Jan 2017 15:31:17 +0100
changeset 151
74d21dd5fd5d
parent 105
63d9051fe35c
child 165
6942a8c3e737
child 171
af7e2d80dee6
permissions
-rw-r--r--

adds more error handling and logging to send_cgi

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

mercurial