| 1 | /* |
| 2 | * Copyright (c) 2019-2022 Joris Vink <[email protected]> |
| 3 | * |
| 4 | * Permission to use, copy, modify, and distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <sys/param.h> |
| 18 | #include <sys/stat.h> |
| 19 | #include <sys/types.h> |
| 20 | |
| 21 | #include <fcntl.h> |
| 22 | #include <dirent.h> |
| 23 | #include <unistd.h> |
| 24 | |
| 25 | #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/ |
| 26 | |
| 27 | #if !defined(KORE_NO_HTTP) |
| 28 | |
| 29 | #include "http.h"cxx . . $ `<file>/include/kore/http.h`/ |
| 30 | |
| 31 | struct filemap_entrycxx . . $ filemap_entry# { |
| 32 | char *rootcxx . . $ filemap_entry#root.; |
| 33 | size_t root_lencxx . . $ filemap_entry#root_len.; |
| 34 | struct kore_domaincxx . . $ kore_domain# *domaincxx . . $ filemap_entry#domain.; |
| 35 | char *ondiskcxx . . $ filemap_entry#ondisk.; |
| 36 | size_t ondisk_lencxx . . $ filemap_entry#ondisk_len.; |
| 37 | TAILQ_ENTRYcxx . . $ `<external>/2546723208511035544/queue.h:382:9`!(filemap_entry) listcxx . . $ filemap_entry#list.; |
| 38 | }; |
| 39 | |
| 40 | int filemap_resolvecxx . . $ filemap_resolve(1f5f2973e69f937).(struct http_requestcxx . . $ http_request# *); |
| 41 | |
| 42 | static void filemap_servecxx . . $ filemap_serve(a1de0a4360abf085).(struct http_requestcxx . . $ http_request# *, const struct filemap_entrycxx . . $ filemap_entry# *); |
| 43 | |
| 44 | static TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(, filemap_entry) mapscxx . . $ maps.; |
| 45 | |
| 46 | char *kore_filemap_extcxx . . $ kore_filemap_ext. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 47 | char *kore_filemap_indexcxx . . $ kore_filemap_index. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 48 | |
| 49 | void |
| 50 | kore_filemap_initcxx . . $ kore_filemap_init(49f6e7a06ebc5aa8).(void) |
| 51 | { |
| 52 | TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&maps); |
| 53 | } |
| 54 | |
| 55 | struct kore_routecxx . . $ kore_route# * |
| 56 | kore_filemap_createcxx . . $ kore_filemap_create(666ea3a8eccbf726).(struct kore_domaincxx . . $ kore_domain# *dom, const char *path, |
| 57 | const char *root, const char *auth) |
| 58 | { |
| 59 | size_t sz; |
| 60 | struct statcxx . . $ stat# st; |
| 61 | int len; |
| 62 | struct kore_routecxx . . $ kore_route# *rt; |
| 63 | struct filemap_entrycxx . . $ filemap_entry# *entry; |
| 64 | char regex[1024], fpath[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 65 | |
| 66 | sz = strlencxx . . $ strlen(751346f8406fd082).(root); |
| 67 | if (sz == 0) |
| 68 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 69 | |
| 70 | if (root[0] != '/' || root[sz - 1] != '/') |
| 71 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 72 | |
| 73 | if (worker_privsepcxx . . $ worker_privsep..rootcxx . . $ kore_privsep#root. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 74 | len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(fpath, sizeof(fpath), "%s/%s", |
| 75 | worker_privsepcxx . . $ worker_privsep..rootcxx . . $ kore_privsep#root., path); |
| 76 | if (len == -1 || (size_t)len >= sizeof(fpath)) |
| 77 | fatalcxx . . $ fatal(f6bc48f0426f26ee).("kore_filemap_create: failed to concat paths"); |
| 78 | } else { |
| 79 | if (kore_strlcpycxx . . $ kore_strlcpy(55abe9014c6d0e39).(fpath, path, sizeof(fpath)) >= sizeof(fpath)) |
| 80 | fatalcxx . . $ fatal(f6bc48f0426f26ee).("kore_filemap_create: failed to copy path"); |
| 81 | } |
| 82 | |
| 83 | if (statcxx . . $ stat(a9cd1e23e96f423c).(fpath, &st) == -1) { |
| 84 | kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "%s: failed to stat '%s': %s", __func__, |
| 85 | fpath, errno_scxx . . $ `include/kore/kore.h:100:9`!); |
| 86 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 87 | } |
| 88 | |
| 89 | len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(regex, sizeof(regex), "^%s.*$", root); |
| 90 | if (len == -1 || (size_t)len >= sizeof(regex)) |
| 91 | fatalcxx . . $ fatal(f6bc48f0426f26ee).("kore_filemap_create: buffer too small"); |
| 92 | |
| 93 | if ((rt = kore_route_createcxx . . $ kore_route_create(8c09fc083371aa6a).(dom, regex, HANDLER_TYPE_DYNAMICcxx . . $ `include/kore/kore.h:407:9`!)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 94 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 95 | |
| 96 | if (auth != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 97 | rt->authcxx . . $ kore_route#auth. = kore_auth_lookupcxx . . $ kore_auth_lookup(89b26d483e8790fd).(auth); |
| 98 | if (rt->authcxx . . $ kore_route#auth. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 99 | fatalcxx . . $ fatal(f6bc48f0426f26ee).("filemap for '%s' has unknown auth '%s'", |
| 100 | path, auth); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | kore_route_callbackcxx . . $ kore_route_callback(20c3529eac994d0e).(rt, "filemap_resolve"); |
| 105 | rt->methodscxx . . $ kore_route#methods. = HTTP_METHOD_GETcxx . . $ `include/kore/http.h:229:9`! | HTTP_METHOD_HEADcxx . . $ `include/kore/http.h:233:9`!; |
| 106 | |
| 107 | entry = kore_calloccxx . . $ kore_calloc(63a7bf2941bfcd7a).(1, sizeof(*entry)); |
| 108 | entry->domaincxx . . $ filemap_entry#domain. = dom; |
| 109 | entry->root_lencxx . . $ filemap_entry#root_len. = sz; |
| 110 | entry->rootcxx . . $ filemap_entry#root. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(root); |
| 111 | |
| 112 | /* |
| 113 | * Resolve the ondisk component inside the workers to make sure |
| 114 | * realpath() resolves the correct path (they maybe chrooted). |
| 115 | */ |
| 116 | entry->ondisk_lencxx . . $ filemap_entry#ondisk_len. = strlencxx . . $ strlen(751346f8406fd082).(path); |
| 117 | entry->ondiskcxx . . $ filemap_entry#ondisk. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(path); |
| 118 | |
| 119 | TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&maps, entry, list); |
| 120 | |
| 121 | return (rt); |
| 122 | } |
| 123 | |
| 124 | void |
| 125 | kore_filemap_resolve_pathscxx . . $ kore_filemap_resolve_paths(49f6e7a06ebc5aa8).(void) |
| 126 | { |
| 127 | struct filemap_entrycxx . . $ filemap_entry# *entry; |
| 128 | char rpath[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 129 | |
| 130 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(entry, &maps, list) { |
| 131 | if (realpathcxx . . $ realpath(ed8193f262e4eda).(entry->ondiskcxx . . $ filemap_entry#ondisk., rpath) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 132 | fatalcxx . . $ fatal(f6bc48f0426f26ee).("realpath(%s): %s", entry->ondiskcxx . . $ filemap_entry#ondisk., errno_scxx . . $ `include/kore/kore.h:100:9`!); |
| 133 | |
| 134 | kore_freecxx . . $ kore_free(5d22bdacc48458e8).(entry->ondiskcxx . . $ filemap_entry#ondisk.); |
| 135 | entry->ondisk_lencxx . . $ filemap_entry#ondisk_len. = strlencxx . . $ strlen(751346f8406fd082).(rpath); |
| 136 | entry->ondiskcxx . . $ filemap_entry#ondisk. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(rpath); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | int |
| 141 | filemap_resolvecxx . . $ filemap_resolve(1f5f2973e69f937).(struct http_requestcxx . . $ http_request# *req) |
| 142 | { |
| 143 | size_t best_len; |
| 144 | struct filemap_entrycxx . . $ filemap_entry# *entry, *best; |
| 145 | |
| 146 | if (req->methodcxx . . $ http_request#method. != HTTP_METHOD_GETcxx . . $ `include/kore/http.h:229:9`! && |
| 147 | req->methodcxx . . $ http_request#method. != HTTP_METHOD_HEADcxx . . $ `include/kore/http.h:233:9`!) { |
| 148 | http_response_headercxx . . $ http_response_header(84119343264ef6a5).(req, "allow", "get, head"); |
| 149 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_BAD_REQUESTcxx . . $ HTTP_STATUS_BAD_REQUEST., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 150 | return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!); |
| 151 | } |
| 152 | |
| 153 | best = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 154 | best_len = 0; |
| 155 | |
| 156 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(entry, &maps, list) { |
| 157 | if (entry->domaincxx . . $ filemap_entry#domain. != req->rtcxx . . $ http_request#rt.->domcxx . . $ kore_route#dom.) |
| 158 | continue; |
| 159 | |
| 160 | if (!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(entry->rootcxx . . $ filemap_entry#root., req->pathcxx . . $ http_request#path., entry->root_lencxx . . $ filemap_entry#root_len.)) { |
| 161 | if (best == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || entry->root_lencxx . . $ filemap_entry#root_len. > best_len) { |
| 162 | best = entry; |
| 163 | best_len = entry->root_lencxx . . $ filemap_entry#root_len.; |
| 164 | continue; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | if (best == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 170 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_NOT_FOUNDcxx . . $ HTTP_STATUS_NOT_FOUND., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 171 | return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!); |
| 172 | } |
| 173 | |
| 174 | filemap_servecxx . . $ filemap_serve(a1de0a4360abf085).(req, best); |
| 175 | |
| 176 | return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!); |
| 177 | } |
| 178 | |
| 179 | static void |
| 180 | filemap_servecxx . . $ filemap_serve(a1de0a4360abf085).(struct http_requestcxx . . $ http_request# *req, const struct filemap_entrycxx . . $ filemap_entry# *map) |
| 181 | { |
| 182 | struct statcxx . . $ stat# st; |
| 183 | struct connectioncxx . . $ connection# *c; |
| 184 | struct kore_filerefcxx . . $ kore_fileref# *ref; |
| 185 | struct kore_servercxx . . $ kore_server# *srv; |
| 186 | const char *path; |
| 187 | int len, fd, index; |
| 188 | char fpath[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!], rpath[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 189 | |
| 190 | path = req->pathcxx . . $ http_request#path. + map->root_lencxx . . $ filemap_entry#root_len.; |
| 191 | |
| 192 | len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(fpath, sizeof(fpath), "%s/%s", map->ondiskcxx . . $ filemap_entry#ondisk., path); |
| 193 | if (len == -1 || (size_t)len >= sizeof(fpath)) { |
| 194 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_INTERNAL_ERRORcxx . . $ HTTP_STATUS_INTERNAL_ERROR., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | if (!http_argument_urldecodecxx . . $ http_argument_urldecode(1ef8e6ec083aabb9).(fpath)) { |
| 199 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_BAD_REQUESTcxx . . $ HTTP_STATUS_BAD_REQUEST., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | index = 0; |
| 204 | |
| 205 | lookup: |
| 206 | if (realpathcxx . . $ realpath(ed8193f262e4eda).(fpath, rpath) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 207 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 208 | if (index == 0 && kore_filemap_extcxx . . $ kore_filemap_ext. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 209 | len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(fpath, sizeof(fpath), |
| 210 | "%s/%s%s", map->ondiskcxx . . $ filemap_entry#ondisk., path, |
| 211 | kore_filemap_extcxx . . $ kore_filemap_ext.); |
| 212 | if (len == -1 || |
| 213 | (size_t)len >= sizeof(fpath)) { |
| 214 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, |
| 215 | HTTP_STATUS_INTERNAL_ERRORcxx . . $ HTTP_STATUS_INTERNAL_ERROR., |
| 216 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 217 | return; |
| 218 | } |
| 219 | index++; |
| 220 | goto lookup; |
| 221 | } |
| 222 | } |
| 223 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_NOT_FOUNDcxx . . $ HTTP_STATUS_NOT_FOUND., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(rpath, fpath, map->ondisk_lencxx . . $ filemap_entry#ondisk_len.)) { |
| 228 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_NOT_FOUNDcxx . . $ HTTP_STATUS_NOT_FOUND., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | c = req->ownercxx . . $ http_request#owner.; |
| 233 | srv = c->ownercxx . . $ connection#owner.->servercxx . . $ listener#server.; |
| 234 | |
| 235 | if ((ref = kore_fileref_getcxx . . $ kore_fileref_get(2e3c4ee0a90b8886).(rpath, srv->tlscxx . . $ kore_server#tls.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 236 | if ((fd = opencxx . . $ open(cb7559238bb26814).(fpath, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`! | O_NOFOLLOWcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:141:10`!)) == -1) { |
| 237 | switch (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) { |
| 238 | case ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!: |
| 239 | if (index || kore_filemap_extcxx . . $ kore_filemap_ext. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 240 | req->statuscxx . . $ http_request#status. = HTTP_STATUS_NOT_FOUNDcxx . . $ HTTP_STATUS_NOT_FOUND.; |
| 241 | } else { |
| 242 | len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(fpath, sizeof(fpath), |
| 243 | "%s/%s%s", map->ondiskcxx . . $ filemap_entry#ondisk., path, |
| 244 | kore_filemap_extcxx . . $ kore_filemap_ext.); |
| 245 | if (len == -1 || |
| 246 | (size_t)len >= sizeof(fpath)) { |
| 247 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, |
| 248 | HTTP_STATUS_INTERNAL_ERRORcxx . . $ HTTP_STATUS_INTERNAL_ERROR., |
| 249 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 250 | return; |
| 251 | } |
| 252 | index++; |
| 253 | goto lookup; |
| 254 | } |
| 255 | break; |
| 256 | case EPERMcxx . . $ `<external>/8987895939074593727/errno-base.h:5:9`!: |
| 257 | case EACCEScxx . . $ `<external>/8987895939074593727/errno-base.h:17:9`!: |
| 258 | req->statuscxx . . $ http_request#status. = HTTP_STATUS_FORBIDDENcxx . . $ HTTP_STATUS_FORBIDDEN.; |
| 259 | break; |
| 260 | default: |
| 261 | req->statuscxx . . $ http_request#status. = HTTP_STATUS_INTERNAL_ERRORcxx . . $ HTTP_STATUS_INTERNAL_ERROR.; |
| 262 | break; |
| 263 | } |
| 264 | |
| 265 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, req->statuscxx . . $ http_request#status., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | if (fstatcxx . . $ fstat(a43660ce2f600cb5).(fd, &st) == -1) { |
| 270 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_INTERNAL_ERRORcxx . . $ HTTP_STATUS_INTERNAL_ERROR., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 271 | goto cleanup; |
| 272 | } |
| 273 | |
| 274 | if (S_ISREGcxx . . $ `<external>/531885356569766532/stat.h:128:9`!(st.st_mode)) { |
| 275 | if (st.st_sizecxx . . $ stat#st_size. <= 0) { |
| 276 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, |
| 277 | HTTP_STATUS_NOT_FOUNDcxx . . $ HTTP_STATUS_NOT_FOUND., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 278 | goto cleanup; |
| 279 | } |
| 280 | |
| 281 | /* kore_fileref_create() takes ownership of the fd. */ |
| 282 | ref = kore_fileref_createcxx . . $ kore_fileref_create(14957474d19f132d).(srv, fpath, fd, |
| 283 | st.st_sizecxx . . $ stat#st_size., &st.st_mtimcxx . . $ stat#st_mtim.); |
| 284 | if (ref == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 285 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, |
| 286 | HTTP_STATUS_INTERNAL_ERRORcxx . . $ HTTP_STATUS_INTERNAL_ERROR., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 287 | } else { |
| 288 | fd = -1; |
| 289 | } |
| 290 | } else if (S_ISDIRcxx . . $ `<external>/531885356569766532/stat.h:125:9`!(st.st_mode) && index == 0) { |
| 291 | closecxx . . $ close(7864480464b09eea).(fd); |
| 292 | if (req->pathcxx . . $ http_request#path.[strlencxx . . $ strlen(751346f8406fd082).(req->pathcxx . . $ http_request#path.) - 1] != '/') { |
| 293 | (void)snprintfcxx . . $ snprintf(ea502d73e74c754c).(fpath, |
| 294 | sizeof(fpath), "%s/", req->pathcxx . . $ http_request#path.); |
| 295 | http_response_headercxx . . $ http_response_header(84119343264ef6a5).(req, "location", fpath); |
| 296 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_FOUNDcxx . . $ HTTP_STATUS_FOUND., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(fpath, sizeof(fpath), |
| 301 | "%s/%s%s", map->ondiskcxx . . $ filemap_entry#ondisk., path, |
| 302 | kore_filemap_indexcxx . . $ kore_filemap_index. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ? |
| 303 | kore_filemap_indexcxx . . $ kore_filemap_index. : "index.html"); |
| 304 | if (len == -1 || (size_t)len >= sizeof(fpath)) { |
| 305 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, |
| 306 | HTTP_STATUS_INTERNAL_ERRORcxx . . $ HTTP_STATUS_INTERNAL_ERROR., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 307 | return; |
| 308 | } |
| 309 | index++; |
| 310 | goto lookup; |
| 311 | } else { |
| 312 | http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_NOT_FOUNDcxx . . $ HTTP_STATUS_NOT_FOUND., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | if (ref != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 317 | http_response_filerefcxx . . $ http_response_fileref(9cb985659cc45a4c).(req, HTTP_STATUS_OKcxx . . $ HTTP_STATUS_OK., ref); |
| 318 | fd = -1; |
| 319 | } |
| 320 | |
| 321 | cleanup: |
| 322 | if (fd != -1) |
| 323 | closecxx . . $ close(7864480464b09eea).(fd); |
| 324 | } |
| 325 | |
| 326 | #endif |