|
|
|
@ -222,10 +222,10 @@ do_cgi(const char *chroot_dir, const char *cgi_dir, const char *path, const char
|
|
|
|
|
* cgi_dir + strlen(chrootdir) (skip chrootdir)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
estrlcpy(cgirp, cgi_dir + strlen(chroot_dir), sizeof(cgirp));
|
|
|
|
|
esnprintf(cgirp, sizeof(cgirp), "%s", cgi_dir + strlen(chroot_dir));
|
|
|
|
|
/* ensure there is no leading / if user didn't end chrootdir with */
|
|
|
|
|
while (*cgirp == '/')
|
|
|
|
|
estrlcpy(cgirp, cgirp+1, sizeof(cgirp));
|
|
|
|
|
memmove(cgirp, cgirp+1, strlen(cgirp+1)+1);
|
|
|
|
|
|
|
|
|
|
if (strncmp(cgirp, path, strlen(cgirp)) != 0)
|
|
|
|
|
return 1; /* not in cgi_dir, go to display_file */
|
|
|
|
@ -252,7 +252,7 @@ do_cgi(const char *chroot_dir, const char *cgi_dir, const char *path, const char
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* cgi file to execute */
|
|
|
|
|
estrlcpy(cgifp, path + strlen(cgirp) + 1, sizeof(cgifp));
|
|
|
|
|
esnprintf(cgifp, sizeof(cgifp), "%s", path + strlen(cgirp) + 1);
|
|
|
|
|
if (!(*cgifp)) /* problem with cgi file, abort */
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
@ -357,7 +357,7 @@ read_request(char *request)
|
|
|
|
|
request[strcspn(request, "\r\n")] = '\0';
|
|
|
|
|
|
|
|
|
|
/* save request for logs */
|
|
|
|
|
estrlcpy(_request, request, sizeof(_request));
|
|
|
|
|
esnprintf(_request, sizeof(_request), "%s", request);
|
|
|
|
|
|
|
|
|
|
/* remove all "/.." for safety reasons */
|
|
|
|
|
while ((pos = strstr(request, "/..")) != NULL)
|
|
|
|
@ -369,19 +369,17 @@ read_request(char *request)
|
|
|
|
|
char *
|
|
|
|
|
set_path(char *path, size_t pathsiz, int virtualhost, const char *hostname)
|
|
|
|
|
{
|
|
|
|
|
char tmp[GEMINI_REQUEST_MAX] = {'\0'};
|
|
|
|
|
|
|
|
|
|
if (strlen(path) == 0) /* this is root dir */
|
|
|
|
|
estrlcpy(path, "./", pathsiz);
|
|
|
|
|
|
|
|
|
|
/* path is in a subdir named hostname */
|
|
|
|
|
if (virtualhost) {
|
|
|
|
|
estrlcpy(tmp, hostname, sizeof(tmp));
|
|
|
|
|
estrlcat(tmp, "/", sizeof(tmp));
|
|
|
|
|
estrlcat(tmp, path, sizeof(tmp));
|
|
|
|
|
estrlcpy(path, tmp, pathsiz);
|
|
|
|
|
char tmp[GEMINI_REQUEST_MAX] = {'\0'};
|
|
|
|
|
esnprintf(tmp, sizeof(tmp), "%s/%s", hostname, path);
|
|
|
|
|
esnprintf(path, pathsiz, "%s", tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strlen(path) == 0) /* this is root dir */
|
|
|
|
|
esnprintf(path, pathsiz, "./");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -406,21 +404,17 @@ check_path(char *path, size_t pathsiz, int virtualhost, size_t hstnm_o)
|
|
|
|
|
/* check if dir path end with "/" */
|
|
|
|
|
if (path[strlen(path) - 1] != '/') {
|
|
|
|
|
/* redirect to the dir with appropriate ending '/' */
|
|
|
|
|
estrlcpy(tmp, "/", sizeof(tmp));
|
|
|
|
|
if (virtualhost) /* skip hostname */
|
|
|
|
|
estrlcat(tmp, path+hstnm_o+1, sizeof(tmp));
|
|
|
|
|
esnprintf(tmp, sizeof(tmp), "/%s/", path+hstnm_o+1);
|
|
|
|
|
else
|
|
|
|
|
estrlcat(tmp, path, sizeof(tmp));
|
|
|
|
|
estrlcat(tmp, "/", sizeof(tmp));
|
|
|
|
|
esnprintf(tmp, sizeof(tmp), "/%s/", path);
|
|
|
|
|
status(31, "%s", tmp);
|
|
|
|
|
stop(EXIT_SUCCESS, NULL);
|
|
|
|
|
}
|
|
|
|
|
/* check if DEFAULT_INDEX exists in directory */
|
|
|
|
|
estrlcpy(tmp, path, sizeof(tmp));
|
|
|
|
|
estrlcat(tmp, "/", sizeof(tmp));
|
|
|
|
|
estrlcat(tmp, DEFAULT_INDEX, sizeof(tmp));
|
|
|
|
|
esnprintf(tmp, sizeof(tmp), "%s/%s", path, DEFAULT_INDEX);
|
|
|
|
|
if (stat(tmp, &sb) == 0)
|
|
|
|
|
estrlcpy(path, tmp, pathsiz);
|
|
|
|
|
esnprintf(path, pathsiz, "%s", tmp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|