diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-03-06 09:50:13 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2024-03-06 09:50:13 +0000 |
commit | c01130bff03b3a1bf4ec73962fd6a4741d68483e (patch) | |
tree | 59ab5347d2d8e5f1301d8b177d342fb123f3403a | |
parent | c02cc7dd9985f42e807badefe97c005d8e3534f2 (diff) | |
download | tipidee-c01130bff03b3a1bf4ec73962fd6a4741d68483e.tar.gz tipidee-c01130bff03b3a1bf4ec73962fd6a4741d68483e.tar.xz tipidee-c01130bff03b3a1bf4ec73962fd6a4741d68483e.zip |
Fix indexification with infopath for full cgi sites
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | src/libtipidee/tipidee_log_resource.c | 2 | ||||
-rw-r--r-- | src/tipideed/cgi.c | 4 | ||||
-rw-r--r-- | src/tipideed/tipideed.c | 33 |
3 files changed, 23 insertions, 16 deletions
diff --git a/src/libtipidee/tipidee_log_resource.c b/src/libtipidee/tipidee_log_resource.c index efdea69..38c7294 100644 --- a/src/libtipidee/tipidee_log_resource.c +++ b/src/libtipidee/tipidee_log_resource.c @@ -21,7 +21,7 @@ void tipidee_log_resource (uint32_t v, tipidee_rql const *rql, char const *file, a[m++] = file ; a[m++] = " type " ; a[m++] = ra->flags & TIPIDEE_RA_FLAG_CGI ? ra->flags & TIPIDEE_RA_FLAG_NPH ? "nph" : "cgi" : ra->content_type ; - if (ra->flags & TIPIDEE_RA_FLAG_CGI && infopath) + if (ra->flags & TIPIDEE_RA_FLAG_CGI && infopath[0]) { a[m++] = " path_info /" ; a[m++] = infopath ; diff --git a/src/tipideed/cgi.c b/src/tipideed/cgi.c index a2554f5..4a7f9f2 100644 --- a/src/tipideed/cgi.c +++ b/src/tipideed/cgi.c @@ -48,7 +48,7 @@ static void addrequesturi (tipidee_rql const *rql, char const *docroot, char con { if (!stralloc_cats(&g.sa, "REQUEST_URI=") || !stralloc_cats(&g.sa, script)) dienomem(rql, docroot) ; - if (infopath) + if (infopath[0]) { if (!stralloc_catb(&g.sa, "/", 1) || !stralloc_cats(&g.sa, infopath)) dienomem(rql, docroot) ; @@ -73,7 +73,7 @@ static inline void modify_env (tipidee_rql const *rql, char const *docroot, tipi } else delenv(rql, docroot, "CONTENT_LENGTH") ; - if (infopath) addenvslash(rql, docroot, "PATH_INFO", infopath) ; + if (infopath[0]) addenvslash(rql, docroot, "PATH_INFO", infopath) ; else delenv(rql, docroot, "PATH_INFO") ; if (rql->uri.query) addenv(rql, docroot, "QUERY_STRING", rql->uri.query) ; else delenv(rql, docroot, "QUERY_STRING") ; diff --git a/src/tipideed/tipideed.c b/src/tipideed/tipideed.c index 9ed9899..903828e 100644 --- a/src/tipideed/tipideed.c +++ b/src/tipideed/tipideed.c @@ -224,9 +224,11 @@ static inline int serve (tipidee_rql *rql, char const *docroot, char *uribuf, ti tipidee_resattr ra = TIPIDEE_RESATTR_ZERO ; size_t docrootlen = strlen(docroot) ; size_t pathlen = strlen(rql->uri.path) ; - char const *infopath = 0 ; + char const *x = 0 ; struct stat st ; - char fn[docrootlen + pathlen + 2 + g.indexlen] ; + char fn[docrootlen + pathlen + 3 + g.indexlen] ; + char infopath[pathlen + 1] ; + infopath[0] = 0 ; memcpy(fn, docroot, docrootlen) ; memcpy(fn + docrootlen, rql->uri.path, pathlen) ; fn[docrootlen + pathlen] = 0 ; @@ -265,11 +267,16 @@ static inline int serve (tipidee_rql *rql, char const *docroot, char *uribuf, ti default : die500sys(rql, 111, docroot, "stat ", fn) ; } } - infopath = fn + pos + 1 ; + strcpy(infopath, fn + pos + 1) ; + if (infopath[0] && S_ISDIR(st.st_mode)) + { + fn[pos++] = '/' ; + fn[pos] = 0 ; + } } + tipidee_log_debug(g.logv, "found ", fn) ; if (S_ISDIR(st.st_mode)) { - if (infopath) { respond_404(rql, docroot) ; return 0 ; } switch (indexify(rql, docroot, fn, &st)) { case 403 : respond_403(rql, docroot) ; return 0 ; @@ -279,14 +286,14 @@ static inline int serve (tipidee_rql *rql, char const *docroot, char *uribuf, ti case 0 : break ; } } - tipidee_log_debug(g.logv, "serve: docroot ", docroot, " file ", fn, " infopath ", infopath ? infopath : "(none)") ; + tipidee_log_debug(g.logv, "serve: docroot ", docroot, " file ", fn, infopath[0] ? " infopath /" : "", infopath[0] ? infopath : "") ; if (g.xiscgi && st.st_mode & S_IXOTH) ra.flags |= TIPIDEE_RA_FLAG_CGI ; get_resattr(rql, docroot, fn, &ra) ; - if (!ra.flags & TIPIDEE_RA_FLAG_CGI) + if (!(ra.flags & TIPIDEE_RA_FLAG_CGI)) { - if (infopath) { respond_404(rql, docroot) ; return 0 ; } + if (infopath[0]) { respond_404(rql, docroot) ; return 0 ; } if (rql->m == TIPIDEE_METHOD_POST) exit_405(rql, docroot, 0) ; } @@ -298,11 +305,11 @@ static inline int serve (tipidee_rql *rql, char const *docroot, char *uribuf, ti if (ra.flags & TIPIDEE_RA_FLAG_CGI) return respond_cgi(rql, docroot, fn, docrootlen, infopath, uribuf, hdr, &ra, body, bodylen) ; - infopath = tipidee_headers_search(hdr, "If-Modified-Since") ; - if (infopath) + x = tipidee_headers_search(hdr, "If-Modified-Since") ; + if (x) { tain wanted, actual ; - if (tipidee_util_httpdate(infopath, &wanted) + if (tipidee_util_httpdate(x, &wanted) && tain_from_timespec(&actual, &st.st_mtim) && tain_less(&actual, &wanted)) return respond_304(rql, fn, &st) ; @@ -310,11 +317,11 @@ static inline int serve (tipidee_rql *rql, char const *docroot, char *uribuf, ti if (rql->m == TIPIDEE_METHOD_GET) { - infopath = tipidee_headers_search(hdr, "Range") ; - if (infopath) + x = tipidee_headers_search(hdr, "Range") ; + if (x) { uint64_t start, len ; - int r = tipidee_util_parse_range(infopath, st.st_size, &start, &len) ; + int r = tipidee_util_parse_range(x, st.st_size, &start, &len) ; if (r > 0) return respond_partial(rql, docroot, fn, &st, start, len, &ra) ; if (r < 0) { respond_416(rql, docroot, st.st_size) ; return 0 ; } } |