diff --git a/doc/packages.txt b/doc/packages.txt index 90805dd..dce545c 100644 --- a/doc/packages.txt +++ b/doc/packages.txt @@ -4,15 +4,34 @@ CTF Packages Packages are squashfs files. A hypothetical package named pkgname.sfs will be mounted under -/srv/pkgname. The following top-level files and directories are +/opt/pkgname. The following top-level files and directories are significant: -* /www/ - Will appear as http://host/pkgname/, CGI can be run -* /bin/ - Will be added to $PATH -* /puzzles/ - Will appear as a puzzle category (see "Puzzles" below) +* /setup - Run after package is mounted +* /bin/ - Added to $PATH for login shells +* /puzzles/ - Appears as a puzzle category (see "Puzzles" below) * /answers.txt - Puzzle answers for category pkgname (see "Puzzles" below) +setup script +------------ + +The setup script (if it exists and is executable) will be run from within +the mounted directory. This is mostly so you can copy things out of your +read-only package and into read/write areas. + +Don't start your service here, instead, make a new directory in +/var/service and place a "run" script in it. More information can be found +at . + +Some common actions in setup: + + cp -r service/* /var/service # Install startup services + + # Set up a file with ownership + install -o ctf -m 0644 /var/lib/ctf/whatever.db + + Puzzles ------- diff --git a/mcp/Makefile b/mcp/Makefile index 5f2c1bb..f46402d 100644 --- a/mcp/Makefile +++ b/mcp/Makefile @@ -12,12 +12,14 @@ $(PACKAGE): build cp setup $(PKGDIR) find bin -not -name '*~' | cpio -p $(PKGDIR) - cp src/in.tokend src/tokencli src/pointscli $(PKGDIR)/bin + cp src/in.tokend $(PKGDIR)/bin + cp src/tokencli src/pointscli $(PKGDIR)/bin + cp src/puzzles.cgi $(PKGDIR)/bin find service -not -name '*~' -not -name '#*' | cpio -p $(PKGDIR) find www -not -name '*~' -not -name '#*' | cpio -p $(PKGDIR) - cp src/puzzler.cgi src/puzzles.cgi src/claim.cgi $(PKGDIR)/www + cp src/puzzler.cgi src/claim.cgi $(PKGDIR)/www mksquashfs $(PKGDIR) $(PACKAGE) -all-root -noappend diff --git a/mcp/bin/register b/mcp/bin/register index efdaecc..6be7af6 100755 --- a/mcp/bin/register +++ b/mcp/bin/register @@ -5,10 +5,15 @@ if [ $# -ne 1 ]; then exit 64 fi +escape () { + sed 's/&/\&/g;s//\>/g' +} + # Don't overwrite files set -C base=${CTF_BASE:-/var/lib/ctf} +www=${CTF_BASE:-/var/www} # Assign a color. I spent two days selecting this color pallette for # people with protanopia. Please don't change these colors. @@ -45,3 +50,6 @@ echo "$1" > $base/teams/names/$hash echo "$color" > $base/teams/colors/$hash echo "Registered with hash: $hash" + +# Write teams.html if it's an actual contest +/opt/mcp/bin/teams.sh > $www/teams.html.new && mv $www/teams.html.new $www/teams.html diff --git a/mcp/bin/run-ctf b/mcp/bin/run-ctf index 89c7295..0d7e4ff 100755 --- a/mcp/bin/run-ctf +++ b/mcp/bin/run-ctf @@ -10,17 +10,6 @@ STATE=${CTF_BASE:-/var/lib/ctf} NEWPOINTS=$STATE/points.new POINTS=$STATE/points.log SCOREBOARD=$WWW/scoreboard.html -PUZZLES=$WWW/puzzles.html -TEAMS=$WWW/teams.html - -install -u ctf -m 0644 /dev/null $STATE/tokens.db -install -u ctf -m 0644 /dev/null $STATE/claim.db -install -u root -m 0644 /dev/null $POINTS - -install -u ctf -d $NEWPOINTS -install -u root -d $STATE/teams/names -install -u root -d $STATE/teams/colors -install -u root -d $STATE/token.keys if ! [ -f $SCOREBOARD ]; then $BIN/scoreboard < $POINTS > $SCOREBOARD @@ -42,16 +31,6 @@ while true; do $BIN/scoreboard < $POINTS > $SCOREBOARD.new && mv $SCOREBOARD.new $SCOREBOARD fi - # Render puzzles list - if [ $STATE/puzzler.db -nt $PUZZLES ]; then - $WWW/puzzles.cgi > $PUZZLES.new && mv $PUZZLES.new $PUZZLES - fi - - # Render team names - if [ $STATE/teams/names -nt $TEAMS ]; then - $BIN/teams.sh > $TEAMS.new && mv $TEAMS.new $TEAMS - fi - now=$(date +%s) if [ $now -lt $next ]; then sleep $(expr $next - $now) diff --git a/mcp/bin/scoreboard b/mcp/bin/scoreboard index 4d39475..bacb3cf 100755 --- a/mcp/bin/scoreboard +++ b/mcp/bin/scoreboard @@ -66,7 +66,7 @@ function output( t, c) { BEGIN { base = ENVIRON["CTF_BASE"] if (! base) { - base = "/srv/ctf" + base = "/var/lib/ctf" } # Only display two decimal places @@ -101,13 +101,19 @@ BEGIN { # Get team colors and names for (team in teams) { - fn = base "/teams/colors/" team - getline colors_by_team[team] < fn - close(fn) + # Busybox awk segfaults if you try to close a file that didn't + # exist. We work around it by calling cat. + cmd = sprintf("cat %s/teams/colors/%s", base, team) + cmd | getline color + if (! color) color = "cccccc"; + colors_by_team[team] = color + close(cmd) - fn = base "/teams/names/" team - getline names_by_team[team] < fn - close(fn) + cmd = sprintf("cat %s/teams/names/%s", base, team) + cmd | getline name + if (! name) name = team + names_by_team[team] = name + close(cmd) } # Sort categories diff --git a/mcp/bin/teams.sh b/mcp/bin/teams.sh index 08985e9..cabafe1 100755 --- a/mcp/bin/teams.sh +++ b/mcp/bin/teams.sh @@ -1,6 +1,6 @@ #! /bin/sh -cd /var/lib/ctf/teams/names +cd ${CTF_BASE:-/var/lib/ctf}/teams/names escape () { sed 's/&/\&/g;s//\>/g' @@ -21,7 +21,7 @@ EOF echo "" echo "" -for i in ??????; do +for i in *; do echo "" @@ -32,4 +32,4 @@ cat <Use your team's token to claim points.

-EOF \ No newline at end of file +EOF diff --git a/mcp/setup b/mcp/setup index 788ab89..f028202 100755 --- a/mcp/setup +++ b/mcp/setup @@ -1,8 +1,20 @@ #! /bin/sh -## Set up this package +## Set up the MCP (Master Control Program) server hostname mcp -cp -r service/* /var/service -cp -r www /var +cp -r service/* /var/service/ +cp -r www /var/ + +install -o ctf -m 0644 /dev/null /var/lib/ctf/tokens.db +install -o ctf -m 0644 /dev/null /var/lib/ctf/claim.db +install -o ctf -m 0644 /dev/null /var/lib/ctf/puzzles.db +install -o root -m 0644 /dev/null /var/lib/ctf/points.log + +install -o ctf -d /var/lib/ctf/points.new +install -o ctf -d /var/lib/ctf/points.tmp +install -o root -d /var/lib/ctf/teams/names +install -o root -d /var/lib/ctf/teams/colors +install -o root -d /var/lib/ctf/token.keys + diff --git a/mcp/src/common.c b/mcp/src/common.c index d020d93..c33f81b 100644 --- a/mcp/src/common.c +++ b/mcp/src/common.c @@ -442,7 +442,7 @@ award_points(char const *teamhash, token log. */ - filename = state_path("points.new/%d.%d.%s.%s.%ld", + filename = state_path("points.tmp/%d.%d.%s.%s.%ld", now, getpid(), teamhash, category, points); @@ -457,6 +457,18 @@ award_points(char const *teamhash, } close(fd); + + /* Rename into points.new */ + { + char ofn[PATH_MAX]; + + strncpy(ofn, filename, sizeof(ofn)); + filename = state_path("points.new/%d.%d.%s.%s.%ld", + now, getpid(), + teamhash, category, points); + rename(ofn, filename); + } + return 0; } diff --git a/mcp/test.sh b/mcp/test.sh index 0292bcd..c54b5b0 100755 --- a/mcp/test.sh +++ b/mcp/test.sh @@ -11,6 +11,7 @@ mkdir $CTF_BASE # Some skeletal structure mkdir -p $CTF_BASE/points.new +mkdir -p $CTF_BASE/points.tmp # Set up some packages for cat in cat1 cat2 cat3; do diff --git a/mcp/www/index.html b/mcp/www/index.html index 0c29363..5b0faa3 100644 --- a/mcp/www/index.html +++ b/mcp/www/index.html @@ -13,7 +13,7 @@ Scoreboard
  • - Puzzles + Puzzles
  • Teams
  • Team NameToken
    " escape < $i echo "$i