mirror of https://github.com/dirtbags/moth.git
make a stab at detecting fs layout
This commit is contained in:
parent
05b747620c
commit
45a3c84144
|
@ -11,6 +11,7 @@ main(int argc, char *argv[])
|
||||||
if (-1 == cgi_init(argv)) {
|
if (-1 == cgi_init(argv)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
ctf_chdir();
|
||||||
|
|
||||||
/* Read in team and token */
|
/* Read in team and token */
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
|
@ -363,6 +363,33 @@ my_snprintf(char *buf, size_t buflen, char *fmt, ...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ctf_chdir()
|
||||||
|
{
|
||||||
|
char const *ctf_base = getenv("CTF_BASE");
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (ctf_base) {
|
||||||
|
/* chdir to CTF_BASE */
|
||||||
|
chdir(ctf_base);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keep going up one directory until there's a packages directory */
|
||||||
|
for (i = 0; i < 5; i += 1) {
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if ((0 == stat("packages", &st)) &&
|
||||||
|
S_ISDIR(st.st_mode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chdir("..");
|
||||||
|
}
|
||||||
|
fprintf(stderr, "Can not determine CTF_BASE directory: exiting.\n");
|
||||||
|
exit(66);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
mkpath(char const *type, char const *fmt, va_list ap)
|
mkpath(char const *type, char const *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,7 @@ void cgi_page(char *title, char *fmt, ...);
|
||||||
void cgi_error(char *text);
|
void cgi_error(char *text);
|
||||||
|
|
||||||
|
|
||||||
|
void ctf_chdir();
|
||||||
int anchored_search(char const *filename, char const *needle, const char anchor);
|
int anchored_search(char const *filename, char const *needle, const char anchor);
|
||||||
void urandom(char *buf, size_t buflen);
|
void urandom(char *buf, size_t buflen);
|
||||||
int my_snprintf(char *buf, size_t buflen, char *fmt, ...);
|
int my_snprintf(char *buf, size_t buflen, char *fmt, ...);
|
||||||
|
|
|
@ -16,6 +16,7 @@ main(int argc, char *argv[])
|
||||||
"Usage: pointscli TEAM CATEGORY POINTS 'COMMENT'\n");
|
"Usage: pointscli TEAM CATEGORY POINTS 'COMMENT'\n");
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
|
ctf_chdir();
|
||||||
|
|
||||||
points = atoi(argv[3]);
|
points = atoi(argv[3]);
|
||||||
if (0 == points) {
|
if (0 == points) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ main(int argc, char *argv[])
|
||||||
if (-1 == cgi_init(argv)) {
|
if (-1 == cgi_init(argv)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
ctf_chdir();
|
||||||
|
|
||||||
/* Read in team and answer */
|
/* Read in team and answer */
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ main(int argc, char *argv[])
|
||||||
if (-1 == cgi_init(argv)) {
|
if (-1 == cgi_init(argv)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
ctf_chdir();
|
||||||
|
|
||||||
{
|
{
|
||||||
FILE *f = fopen(state_path("points.log"), "r");
|
FILE *f = fopen(state_path("points.log"), "r");
|
||||||
|
|
Loading…
Reference in New Issue