2010-09-03 17:05:42 -06:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "cgi.h"
|
2010-09-07 14:24:37 -06:00
|
|
|
#include "common.h"
|
2010-09-03 17:05:42 -06:00
|
|
|
|
|
|
|
char const *tokenlog = "/var/lib/ctf/tokend/tokens.log";
|
|
|
|
char const *claimlog = "/var/lib/ctf/tokend/claim.log";
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char team[9];
|
|
|
|
char token[100];
|
|
|
|
|
2010-09-07 14:24:37 -06:00
|
|
|
/* XXX: This code needs to be tested */
|
2010-09-11 22:57:46 -06:00
|
|
|
return 1;
|
2010-09-07 14:24:37 -06:00
|
|
|
|
2010-09-03 17:05:42 -06:00
|
|
|
if (-1 == cgi_init()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in team and token */
|
|
|
|
while (1) {
|
|
|
|
size_t len;
|
|
|
|
char key[20];
|
|
|
|
|
|
|
|
len = cgi_item(key, sizeof(key));
|
|
|
|
if (0 == len) break;
|
2010-09-11 22:57:46 -06:00
|
|
|
switch (key[0]) {
|
|
|
|
case 't':
|
|
|
|
cgi_item(team, sizeof(team));
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
cgi_item(token, sizeof(token));
|
|
|
|
break;
|
2010-09-03 17:05:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-07 14:24:37 -06:00
|
|
|
if (! team_exists(team)) {
|
2010-09-03 17:05:42 -06:00
|
|
|
cgi_page("No such team", "");
|
|
|
|
}
|
|
|
|
|
2010-09-11 22:57:46 -06:00
|
|
|
/* Any weird characters in token name? */
|
2010-09-03 17:05:42 -06:00
|
|
|
{
|
2010-09-11 22:57:46 -06:00
|
|
|
char *p;
|
2010-09-03 17:05:42 -06:00
|
|
|
|
2010-09-11 22:57:46 -06:00
|
|
|
for (p = token; *p; p += 1) {
|
|
|
|
if ((! isalnum(*p)) &&
|
|
|
|
(*p != '-') &&
|
|
|
|
(*p != ':')) {
|
|
|
|
cgi_page("Invalid token", "");
|
2010-09-03 17:05:42 -06:00
|
|
|
}
|
|
|
|
}
|
2010-09-11 22:57:46 -06:00
|
|
|
}
|
2010-09-03 17:05:42 -06:00
|
|
|
|
|
|
|
|
2010-09-11 22:57:46 -06:00
|
|
|
/* Does the token exist? */
|
|
|
|
if (! fgrepx(token, tokenlog)) {
|
|
|
|
cgi_page("Token does not exist", "");
|
|
|
|
}
|
2010-09-03 17:05:42 -06:00
|
|
|
|
2010-09-11 22:57:46 -06:00
|
|
|
/* Award points */
|
|
|
|
{
|
|
|
|
char category[40];
|
|
|
|
int i;
|
2010-09-03 17:05:42 -06:00
|
|
|
|
2010-09-11 22:57:46 -06:00
|
|
|
/* Pull category name out of the token */
|
|
|
|
for (i = 0; token[i] != ':'; i += 1) {
|
|
|
|
category[i] = token[i];
|
2010-09-03 17:05:42 -06:00
|
|
|
}
|
2010-09-11 22:57:46 -06:00
|
|
|
category[i] = '\0';
|
2010-09-03 17:05:42 -06:00
|
|
|
|
2010-09-11 22:57:46 -06:00
|
|
|
award_and_log_uniquely(team, category, 1,
|
|
|
|
claimlog, "%s %s", team, token);
|
2010-09-03 17:05:42 -06:00
|
|
|
}
|
|
|
|
|
2010-09-11 22:57:46 -06:00
|
|
|
|
|
|
|
cgi_page("Point awarded", "<!-- success -->");
|
2010-09-03 17:05:42 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|