blob: 45e55d038a5fd2ace481762cb87c6c2acec8e17a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#!/bin/bash
# ////////////////////////////////////////////////////////////////////////////////
# //BOCA Online Contest Administrator
# // Copyright (C) 2003-2012 by BOCA System (bocasystem@gmail.com)
# //
# // This program is free software: you can redistribute it and/or modify
# // it under the terms of the GNU General Public License as published by
# // the Free Software Foundation, either version 3 of the License, or
# // (at your option) any later version.
# //
# // This program is distributed in the hope that it will be useful,
# // but WITHOUT ANY WARRANTY; without even the implied warranty of
# // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# // GNU General Public License for more details.
# // You should have received a copy of the GNU General Public License
# // along with this program. If not, see <http://www.gnu.org/licenses/>.
# ////////////////////////////////////////////////////////////////////////////////
#Last modified: 21/july/2012 by cassio@ime.usp.br
#
# parameters are:
# $1 source_file
# $2 exe_file (default run.jar)
# $3 timelimit (optional, limit to run all the repetitions, by default only one repetition)
# $4 maximum allowed memory (in MBytes)
#
# the output of the submission should be directed to the standard output
#
# the return code show what happened (according to safeexec):
# 0 ok
# 1 compile error
# 2 runtime error
# 3 timelimit exceeded
# 4 internal error
# 5 parameter error
# 6 internal error
# 7 memory limit exceeded
# 8 security threat
# 9 runtime error
# other_codes are unknown to boca: in this case BOCA will present the
# last line of standard output to the judge
umask 0022
if [ "$1" == "" ]; then
echo "parameter problem"
exit 43
fi
name="$1"
if [ ! -r "$1" ]; then
echo "$1 not found or it's not readable"
exit 44
fi
id -u bocajail >/dev/null 2>/dev/null
if [ $? == 0 ]; then
bocau=`id -u bocajail`
bocag=`id -g bocajail`
chown bocajail.nogroup .
else
bocau=`id -u nobody`
bocag=`id -g nobody`
chown nobody.nogroup .
fi
if [ "$bocau" == "" -o "$bocag" == "" ]; then
echo "error finding user to run script"
exit 43
fi
mkdir -p src
if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then
unzip "$name" -d src
if [ "${name##*.}" == "zip" ]; then
name=`basename $name .zip`
else
name=`basename $name .ZIP`
fi
else
cp "$name" src
fi
chown -R $bocau src
chmod -R 700 src
# this script makes use of safeexec to execute the code with less privilegies
# make sure that directories below are correct.
sf=`which safeexec`
[ -x "$sf" ] || sf=/usr/bin/safeexec
if [ ! -x $sf ]; then
echo "$sf not found or it's not executable"
exit 46
fi
# setting up the timelimit according to the problem
if [ "$3" == "" ]; then
time=5
else
time=$3
fi
let "ttime = $time + 30"
maxm=1024
if [ "$4" != "" -a "$4" -gt "1024" ]; then
maxm=$4
fi
maxms=100
if [ "$2" == "" ]; then
jarfile=run.jar
else
jarfile=$2
fi
cdir=`pwd`
echo "Current directory is $cdir" >&2
mainname=`echo $name | cut -d'.' -f1`
if [ "$mainname" == "" ]; then
mainname=Main
fi
cat <<EOF > compileit.sh
#!/bin/bash
kotlinc=/snap/kotlin/24/bin/kotlinc
[ -x "\$kotlinc" ] || kotlinc=/snap/bin/kotlinc
if [ ! -x \$kotlinc ]; then
echo "\$kotlinc not found or it's not executable"
exit 47
fi
cd src
\$kotlinc -J-Xmx${maxm}M -J-Xss${maxms}M -J-Xms${maxm}M -d ../$jarfile -include-runtime $name
echo \$? > ../compileit.retcode
exit 0
EOF
chmod 755 compileit.sh
echo "COMPILATION IS NOT BEING CHROOTED -- THIS IS NOT AN IDEAL SETTING"
#$kotlinc "$name"
$sf -r1 -t20 -T32 -istdin0 -F512 -u512 -U$bocau -G$bocag -n0 -C. -d40000000000 -m40000000000 ./compileit.sh
#./compileit.sh
ret=$?
if [ -f "stdout0" ]; then
cat "stdout0"
fi
if [ -f "stderr0" ]; then
cat "stderr0"
fi
#rm -rf src/
if [ "$ret" != "0" ]; then
echo "Compilation Error: $ret"
exit $ret
fi
ret=`cat compileit.retcode`
if [ "$ret" != "0" ]; then
echo "Compilation Error: $ret"
ret=1
fi
exit $ret
|