src/server/safs/nametrans.c

Sun, 08 May 2022 11:52:52 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 08 May 2022 11:52:52 +0200
branch
webdav
changeset 342
ebd1e67c3d5f
parent 325
2d14055c3543
child 366
47bc686fafe4
permissions
-rw-r--r--

fix invalid memory access in event_bsd.c

14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
4 * Copyright 2016 Olaf Wintermann. All rights reserved.
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
b8bf95b39952 New source folder layout
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
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "nametrans.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
31 #include "../daemon/log.h"
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
32 #include "../daemon/request.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../util/pblock.h"
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
34 #include "../util/util.h"
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
35 #include "../public/webdav.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
37 #include "../public/vfs.h"
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
38
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
39 static int nametrans_set_vfs(pblock *pb, Session *sn, Request *rq) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
40 char *vfsclass = pblock_findkeyval(pb_key_vfsclass, pb);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
41 if(!vfsclass) return 0;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
42
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
43 VFS *vfs = vfs_create(sn, rq, vfsclass, pb);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
44 if(!vfs) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
45 return 1;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
46 }
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
47 rq->vfs = vfs;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
48 return 0;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
49 }
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
50
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
51 static int nametrans_set_dav(pblock *pb, Session *sn, Request *rq) {
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
52 char *davclass = pblock_findkeyval(pb_key_davclass, pb);
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
53 if(!davclass) return 0;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
54
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
55 WebdavBackend *dav = webdav_create(sn, rq, davclass, pb);
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
56
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
57 rq->davCollection = dav;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
58 return 0;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
59 }
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
60
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 /*
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 * assign_name
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 * Assigns the name specified by the name parameter if the uri has the
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 * specified prefix.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 * pblock parameter:
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 * name object name
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 * from optional uri prefix
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 */
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 int assign_name(pblock *pb, Session *sn, Request *rq) {
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 /* TODO: expression instead of simple prefix */
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 char *name = pblock_findkeyval(pb_key_name, pb);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 char *from = pblock_findkeyval(pb_key_from, pb);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 if(!name) {
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
78 log_ereport(LOG_MISCONFIG, "assign-name: missing name parameter");
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 protocol_status(sn, rq, 500, NULL);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 return REQ_ABORTED;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 }
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 if(from) {
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 char c;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 int i = 0;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 while((c = from[i]) != 0) {
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 if(c != uri[i]) {
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 return REQ_NOACTION;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 i++;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 }
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
94
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
95 if(nametrans_set_vfs(pb, sn, rq)) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
96 log_ereport(LOG_FAILURE, "assign-name: cannot create VFS: name=%s from=%s", name, from);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
97 return REQ_ABORTED;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
98 }
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
100 // add object to rq->vars
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 return REQ_NOACTION;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 }
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
105
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
106 /*
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
107 * document_root
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
108 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
109 * Specifies the document root directory.
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
110 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
111 * pblock parameter:
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
112 * root path to document root
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
113 */
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
114 int document_root(pblock *pb, Session *sn, Request *rq) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
115 char *root = pblock_findkeyval(pb_key_root, pb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
116 if(!root) {
97
09fbefc0e6a9 added ldap group support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
117 log_ereport(LOG_MISCONFIG, "document-root: missing root parameter");
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
118 protocol_status(sn, rq, 500, NULL);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
119 return REQ_ABORTED;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
120 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
121
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
122 if(nametrans_set_vfs(pb, sn, rq)) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
123 log_ereport(LOG_FAILURE, "document-root: cannot create VFS");
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
124 return REQ_ABORTED;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
125 }
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
126
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
127 sstr_t root_str = sstr(root);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
128 sstr_t uri_str = sstr(pblock_findkeyval(pb_key_uri, rq->reqpb));
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
129
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
130 request_set_path(root_str, uri_str, rq->vars);
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
131
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
132 return REQ_PROCEED;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
133 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
134
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
135 /*
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
136 * pfx2dir
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
137 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
138 * ...
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
139 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
140 * pblock parameter:
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
141 * from prefix
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
142 * dir file system directory
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
143 * name (optional) object name
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
144 * vfsclass (optional) vfs name
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
145 * davclass (optional) dav backend
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
146 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
147 */
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
148 int pfx2dir(pblock *pb, Session *sn, Request *rq) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
149 char *from = pblock_findkeyval(pb_key_from, pb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
150 char *dir = pblock_findkeyval(pb_key_dir, pb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
151 char *name = pblock_findkeyval(pb_key_name, pb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
152
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
153 if(!from || !dir) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
154 if(!from && dir) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
155 log_ereport(LOG_MISCONFIG, "pfx2dir: missing from parameter");
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
156 } else if(!dir && from) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
157 log_ereport(LOG_MISCONFIG, "pfx2dir: missing dir parameter");
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
158 } else {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
159 log_ereport(
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
160 LOG_MISCONFIG,
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
161 "pfx2dir: missing from and dir parameter");
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
162 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
163 protocol_status(sn, rq, 500, NULL);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
164 return REQ_ABORTED;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
165 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
166
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
167 // check prefix
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
168 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
169 char fc;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
170 char uc;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
171 int i = 0;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
172 while((fc = from[i]) != 0) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
173 uc = uri[i];
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
174 if(fc != uc) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
175 return REQ_NOACTION;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
176 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
177 i++;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
178 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
179
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
180 // url has the specified prefix
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
181
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
182 uri = uri + i;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
183 if(uri[0] == '/') {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
184 uri++;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
185 }
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
186
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
187 if(nametrans_set_vfs(pb, sn, rq)) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
188 log_ereport(LOG_FAILURE, "pfx2dir: cannot create VFS: from=%s dir=%s name=%s", from, dir, name);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
189 return REQ_ABORTED;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
190 }
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
191 if(nametrans_set_dav(pb, sn, rq)) {
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
192 log_ereport(LOG_FAILURE, "pfx2dir: cannot create Webdav Backend: from=%s dir=%s name=%s", from, dir, name);
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
193 return REQ_ABORTED;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
194 }
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
195
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
196 request_set_path(sstr(dir), sstr(uri), rq->vars);
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
197
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
198 if(name) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
199 // add object to rq->vars
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
200 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
201 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
202
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
203 return REQ_PROCEED;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
204 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
205
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
206
137
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
207 int redirect(pblock *pb, Session *sn, Request *rq) {
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
208 char *from = pblock_findval("from", pb);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
209 char *url = pblock_findval("url", pb);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
210
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
211 if(!from || !url) {
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
212 log_ereport(LOG_MISCONFIG, "redirect: missing parameter (from, url)");
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
213 return REQ_ABORTED;
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
214 }
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
215
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
216 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
217 if(!strcmp(uri, from)) {
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
218 pblock_nvinsert("location", url, rq->srvhdrs);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
219
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
220 protocol_status(sn, rq, 302, NULL);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
221 return REQ_ABORTED;
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
222 }
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
223
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
224 return REQ_NOACTION;
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
225 }
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
226
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
227 /*
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
228 * provisional rewrite saf
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
229 */
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
230 int simple_rewrite(pblock *pb, Session *sn, Request *rq) {
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
231 char *from = pblock_findval("from", pb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
232 char *root = pblock_findval("root", pb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
233 char *path = pblock_findval("path", pb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
234 char *name = pblock_findval("name", pb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
235
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
236 if(!from || !path || !root) {
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
237 log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)");
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
238 return REQ_ABORTED;
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
239 }
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
240
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
241 if(nametrans_set_vfs(pb, sn, rq)) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
242 log_ereport(LOG_FAILURE, "simple-rewrite: cannot create VFS: from=%s root=%s path=%s name=%s", from, root, path, name);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
243 return REQ_ABORTED;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
244 }
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
245
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
246 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
247 sstr_t u = sstr(uri);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
248 sstr_t f = sstr(from);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
249 if(sstrprefix(u, f)) {
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
250 sstr_t suf = sstrsubs(u, f.length);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
251 sstr_t ppath = sstrcat(2, sstr(path), suf);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
252
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
253 request_set_path(sstr(root), ppath, rq->vars);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
254 free(ppath.ptr);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
255
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
256 if(name) {
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
257 // add object to rq->vars
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
258 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
259 }
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
260 }
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
261
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
262 return REQ_NOACTION;
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
263 }

mercurial