mirror of https://github.com/dirtbags/moth.git
Make points a long
This commit is contained in:
parent
5199cf5cac
commit
df3da9c6d3
|
@ -6,6 +6,7 @@ in.tokend: in.tokend.o xxtea.o
|
|||
|
||||
claim.cgi: claim.cgi.o common.o
|
||||
puzzler.cgi: puzzler.cgi.o common.o
|
||||
puzzles.cgi: puzzles.cgi.o common.o
|
||||
pointscli: common.o pointscli.o
|
||||
|
||||
clean:
|
||||
|
|
35
src/common.c
35
src/common.c
|
@ -100,10 +100,8 @@ cgi_item(char *str, size_t maxlen)
|
|||
}
|
||||
|
||||
void
|
||||
cgi_page(char *title, char *fmt, ...)
|
||||
cgi_head(char *title)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
printf(("Content-type: text/html\r\n"
|
||||
"\r\n"
|
||||
"<!DOCTYPE html>\n"
|
||||
|
@ -115,12 +113,26 @@ cgi_page(char *title, char *fmt, ...)
|
|||
" <body>\n"
|
||||
" <h1>%s</h1>\n"),
|
||||
title, title);
|
||||
va_start(ap, fmt);
|
||||
vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
cgi_foot()
|
||||
{
|
||||
printf("\n"
|
||||
" </body>\n"
|
||||
"</html>\n");
|
||||
}
|
||||
|
||||
void
|
||||
cgi_page(char *title, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
cgi_head(title);
|
||||
va_start(ap, fmt);
|
||||
vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
cgi_foot();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -135,6 +147,7 @@ cgi_error(char *fmt, ...)
|
|||
va_start(ap, fmt);
|
||||
vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
printf("\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -233,7 +246,7 @@ team_exists(char const *teamhash)
|
|||
int
|
||||
award_points(char const *teamhash,
|
||||
char const *category,
|
||||
int points)
|
||||
long points)
|
||||
{
|
||||
char line[100];
|
||||
int linelen;
|
||||
|
@ -248,7 +261,7 @@ award_points(char const *teamhash,
|
|||
}
|
||||
|
||||
linelen = snprintf(line, sizeof(line),
|
||||
"%u %s %s %d\n",
|
||||
"%u %s %s %ld\n",
|
||||
now, teamhash, category, points);
|
||||
if (sizeof(line) <= linelen) {
|
||||
return -1;
|
||||
|
@ -281,7 +294,7 @@ award_points(char const *teamhash,
|
|||
*/
|
||||
|
||||
filenamelen = snprintf(filename, sizeof(filename),
|
||||
"%s/%d.%d.%s.%s.%d",
|
||||
"%s/%d.%d.%s.%s.%ld",
|
||||
pointsdir, now, getpid(),
|
||||
teamhash, category, points);
|
||||
if (sizeof(filename) <= filenamelen) {
|
||||
|
@ -305,11 +318,11 @@ award_points(char const *teamhash,
|
|||
void
|
||||
award_and_log_uniquely(char const *team,
|
||||
char const *category,
|
||||
int points,
|
||||
long points,
|
||||
char const *logfile,
|
||||
char const *fmt, ...)
|
||||
{
|
||||
char line[100];
|
||||
char line[200];
|
||||
int len;
|
||||
int ret;
|
||||
int fd;
|
||||
|
|
|
@ -3,8 +3,13 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
#define TEAM_MAX 40
|
||||
#define CAT_MAX 40
|
||||
|
||||
int cgi_init();
|
||||
size_t cgi_item(char *str, size_t maxlen);
|
||||
void cgi_head(char *title);
|
||||
void cgi_foot();
|
||||
void cgi_page(char *title, char *fmt, ...);
|
||||
void cgi_error(char *fmt, ...);
|
||||
|
||||
|
@ -16,10 +21,10 @@ int fgrepx(char const *needle, char const *filename);
|
|||
int team_exists(char const *teamhash);
|
||||
int award_points(char const *teamhash,
|
||||
char const *category,
|
||||
int point);
|
||||
long point);
|
||||
void award_and_log_uniquely(char const *team,
|
||||
char const *category,
|
||||
int points,
|
||||
long points,
|
||||
char const *logfile,
|
||||
char const *fmt, ...);
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@ char const *logfile = "/var/lib/ctf/puzzler.log";
|
|||
int
|
||||
main(int argc, char *argv)
|
||||
{
|
||||
char team[9];
|
||||
char category[30];
|
||||
char team[TEAM_MAX];
|
||||
char category[CAT_MAX];
|
||||
char points_str[5];
|
||||
char answer[500];
|
||||
int points;
|
||||
long points;
|
||||
|
||||
if (-1 == cgi_init()) {
|
||||
return 0;
|
||||
|
@ -32,7 +32,7 @@ main(int argc, char *argv)
|
|||
break;
|
||||
case 'p':
|
||||
cgi_item(points_str, sizeof(points_str));
|
||||
points = atoi(points_str);
|
||||
points = atol(points_str);
|
||||
break;
|
||||
case 'a':
|
||||
cgi_item(answer, sizeof(answer));
|
||||
|
@ -59,19 +59,19 @@ main(int argc, char *argv)
|
|||
/* Check answer (also assures category exists) */
|
||||
{
|
||||
char filename[100];
|
||||
char needle[100];
|
||||
char needle[400];
|
||||
|
||||
my_snprintf(filename, sizeof(filename),
|
||||
"/srv/%s/answers.txt", category);
|
||||
my_snprintf(needle, sizeof(needle),
|
||||
"%d %s", points, answer);
|
||||
"%ld %s", points, answer);
|
||||
if (! fgrepx(needle, filename)) {
|
||||
cgi_page("Wrong answer", "");
|
||||
}
|
||||
}
|
||||
|
||||
award_and_log_uniquely(team, category, points,
|
||||
logfile, "%s %s %d", team, category, points);
|
||||
logfile, "%s %s %ld", team, category, points);
|
||||
|
||||
cgi_page("Points awarded",
|
||||
"<p>%d points for %s.</p>", points, team);
|
||||
|
|
Loading…
Reference in New Issue