alphasort autoindex + add proper error code fir cgi
This commit is contained in:
parent
495fa3213f
commit
2cc63136f8
2 changed files with 23 additions and 20 deletions
33
main.c
33
main.c
|
@ -201,31 +201,31 @@ closefd:
|
||||||
void
|
void
|
||||||
autoindex(const char *path)
|
autoindex(const char *path)
|
||||||
{
|
{
|
||||||
struct dirent *dp;
|
int n = 0;
|
||||||
DIR *fd;
|
struct dirent **namelist;
|
||||||
|
|
||||||
|
|
||||||
if (!(fd = opendir(path))) {
|
|
||||||
err(1,"opendir '%s':", path);
|
|
||||||
}
|
|
||||||
|
|
||||||
syslog(LOG_DAEMON, "autoindex: %s", path);
|
syslog(LOG_DAEMON, "autoindex: %s", path);
|
||||||
|
|
||||||
status(20, "text/gemini");
|
status(20, "text/gemini");
|
||||||
|
|
||||||
/* TODO : add ending / in name if directory */
|
if ((n = scandir(path, &namelist, NULL, alphasort)) < 0) {
|
||||||
while ((dp = readdir(fd))) {
|
status(51, "text/gemini");
|
||||||
/* skip self */
|
errlog("Can't scan %s", path);
|
||||||
if (!strcmp(dp->d_name, ".")) {
|
} else {
|
||||||
|
for(int j = 0; j < n; j++) {
|
||||||
|
if (!strcmp(namelist[j]->d_name, ".")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (dp->d_type == DT_DIR) {
|
if (namelist[j]->d_type == DT_DIR) {
|
||||||
printf("=> ./%s/ %s/\n", dp->d_name, dp->d_name);
|
printf("=> ./%s/ %s/\n", namelist[j]->d_name, namelist[j]->d_name);
|
||||||
} else {
|
} else {
|
||||||
printf("=> ./%s %s\n", dp->d_name, dp->d_name);
|
printf("=> ./%s %s\n", namelist[j]->d_name, namelist[j]->d_name);
|
||||||
}
|
}
|
||||||
|
free(namelist[j]);
|
||||||
|
}
|
||||||
|
free(namelist);
|
||||||
}
|
}
|
||||||
closedir(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -236,6 +236,7 @@ cgi(const char *cgicmd)
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (pipe(pipedes) != 0) {
|
if (pipe(pipedes) != 0) {
|
||||||
|
status(42, "text/gemini");
|
||||||
err(1, "pipe failed");
|
err(1, "pipe failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,6 +245,7 @@ cgi(const char *cgicmd)
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
close(pipedes[0]);
|
close(pipedes[0]);
|
||||||
close(pipedes[1]);
|
close(pipedes[1]);
|
||||||
|
status(42, "text/gemini");
|
||||||
err(1, "fork failed");
|
err(1, "fork failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +259,7 @@ cgi(const char *cgicmd)
|
||||||
/* use fread/fwrite because are buffered */
|
/* use fread/fwrite because are buffered */
|
||||||
output = fdopen(pipedes[0], "r");
|
output = fdopen(pipedes[0], "r");
|
||||||
if (output == NULL) {
|
if (output == NULL) {
|
||||||
|
status(42, "text/gemini");
|
||||||
err(1, "fdopen failed");
|
err(1, "fdopen failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +279,7 @@ cgi(const char *cgicmd)
|
||||||
close(pipedes[1]); /* no need this file descriptor : it is now stdout */
|
close(pipedes[1]); /* no need this file descriptor : it is now stdout */
|
||||||
execlp(cgicmd, cgicmd, NULL);
|
execlp(cgicmd, cgicmd, NULL);
|
||||||
/* if execlp is ok, this will never be reached */
|
/* if execlp is ok, this will never be reached */
|
||||||
status(42, "text/plain");
|
status(42, "text/gemini");
|
||||||
errlog("error when trying to execlp %s", cgicmd);
|
errlog("error when trying to execlp %s", cgicmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ if ! [ $OUT = "874f5e1af67eff6b93bedf8ac8033066" ] ; then echo "error" ; exit 1
|
||||||
|
|
||||||
# auto index in directory
|
# auto index in directory
|
||||||
OUT=$(printf "gemini://host.name/autoidx/\r\n" | ../vger -d var/gemini/ -i | tee /dev/stderr | $MD5)
|
OUT=$(printf "gemini://host.name/autoidx/\r\n" | ../vger -d var/gemini/ -i | tee /dev/stderr | $MD5)
|
||||||
if ! [ $OUT = "9cb7ef77cbcd74dadafdbff47d864152" ] ; then echo "error" ; exit 1 ; fi
|
if ! [ $OUT = "770a987b8f5cf7169e6bc3c6563e1570" ] ; then echo "error" ; exit 1 ; fi
|
||||||
|
|
||||||
# cgi simple script
|
# cgi simple script
|
||||||
OUT=$(printf "gemini://host.name/cgi-bin/test.cgi\r\n" | ../vger -d var/gemini/ -c /cgi-bin | tee /dev/stderr | $MD5)
|
OUT=$(printf "gemini://host.name/cgi-bin/test.cgi\r\n" | ../vger -d var/gemini/ -c /cgi-bin | tee /dev/stderr | $MD5)
|
||||||
|
@ -84,7 +84,7 @@ if ! [ $OUT = "fa065a67d1f7c973501d4a9e3ca2ea57" ] ; then echo "error" ; exit 1
|
||||||
|
|
||||||
# cgi with error
|
# cgi with error
|
||||||
OUT=$(printf "gemini://host.name/cgi-bin/nope\r\n" | ../vger -d var/gemini/ -c /cgi-bin | tee /dev/stderr | $MD5)
|
OUT=$(printf "gemini://host.name/cgi-bin/nope\r\n" | ../vger -d var/gemini/ -c /cgi-bin | tee /dev/stderr | $MD5)
|
||||||
if ! [ $OUT = "babaa82d5b2bd4e8d21ab412e060c890" ] ; then echo "error" ; exit 1 ; fi
|
if ! [ $OUT = "2c88347cfac44450035283a8508a29cb" ] ; then echo "error" ; exit 1 ; fi
|
||||||
|
|
||||||
# must fail only on OpenBSD !
|
# must fail only on OpenBSD !
|
||||||
# try to escape from unveil
|
# try to escape from unveil
|
||||||
|
|
Loading…
Reference in a new issue