diff options
author | gasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414> | 2015-10-26 14:38:50 +0000 |
---|---|---|
committer | gasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414> | 2015-10-26 14:38:50 +0000 |
commit | 4a191a4775f01f66bf7610c38f11517ec4c3a547 (patch) | |
tree | 097d2c0363f04739a96cf8f90db2ab6fb0d566f0 /kpov_judge/tasks | |
parent | b35491eb2cd6bff00e0c45c8fad0c5aa85f84c74 (diff) |
Added the first working version of the exam task
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@341 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge/tasks')
-rw-r--r-- | kpov_judge/tasks/mock_entrance_exam/task.py | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/kpov_judge/tasks/mock_entrance_exam/task.py b/kpov_judge/tasks/mock_entrance_exam/task.py index 7080f4c..46fc7da 100644 --- a/kpov_judge/tasks/mock_entrance_exam/task.py +++ b/kpov_judge/tasks/mock_entrance_exam/task.py @@ -12,7 +12,7 @@ Poskrbi, da bosta oba na istem omrežju in da bo imel Student naslov {student_IP simpleArbiter povezan na Internet. Računajte, da se na studentGUI ob zagonu zažene program {net_prog_name}, ki vam spreminja nastavitve mrežne kartice. -V domačem imeniku uporabnika student obstaja program {P_c} v programskem jeziku C. Prevedite ga v program z imenom {P_executable}. Izvorna koda je namenoma pokvarjena tako, da so vanjo vrinjeni nepotrebni znaki. Pred prevajanjem jo morate popraviti. +V domačem imeniku uporabnika student (geslo je "vaje") obstaja datoteka {P_c} v programskem jeziku C. Z uporabo gcc ga prevedite v program z imenom {P_executable}. Izvorna koda je namenoma pokvarjena tako, da so vanjo vrinjeni nepotrebni znaki. Pred prevajanjem jo morate popraviti. Napišite skripto ali program {P_script} v domačem imeniku uporabnika student, ki: - požene {P_c} z argumentom {arg_c} in mu na standardni vhod pripelje vrednost spremenljivke {env_c} @@ -20,7 +20,7 @@ Napišite skripto ali program {P_script} v domačem imeniku uporabnika student, - vse vrstice, ki jih {P_c} izpiše na stdout in vsebujejo zaporedje znakov "ma", zapiše v {out_stdout_c}. -Lastnik vseh ustvarjenih datotek mora biti uporabnik test. Gesla uporabnika test +Lastnik vseh ustvarjenih datotek mora biti uporabnik student. Gesla uporabnika student ne smete spreminjati. """, @@ -44,7 +44,7 @@ computers = { }, 'Student': { 'disks': [ - {'name': 'student-mock_entrance'} + {'name': 'student-entrance'} ], 'flavor': 'm1.tiny', 'network_interfaces': [{'network': 'net1'}], @@ -74,7 +74,7 @@ params_meta = { 'descriptions': { 'si': 'Datoteka s programom v C', 'en': 'Filename of the program in C', }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, - 'P_executable': { 'description': { 'si': 'Ime prevedenega programa v C', 'en': 'Filename of the compiled C program' + 'P_executable': { 'descriptions': { 'si': 'Ime prevedenega programa v C', 'en': 'Filename of the compiled C program' }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, 'arg_c': { @@ -113,9 +113,9 @@ def task(student_IP, net_prog_name, param_gen_seed): import pxssh import random - # ideally, this would be done using a SFTP client instead of pxssh - target = pxssh.pxssh() - # target.login(student_IP, 'test', 'test') + conn = pxssh.pxssh() + conn.login(student_IP, 'student', 'vaje') + results = dict() r = random.Random(param_gen_seed) env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(11)]) @@ -123,37 +123,37 @@ def task(student_IP, net_prog_name, stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(17)]) conn.sendline('ls -l {}'.format(P_script)) conn.prompt() - results['script_ls'] = conn.before() + results['script_ls'] = conn.before conn.sendline('ls -l {}'.format(P_executable)) conn.prompt() - results['executable_ls'] = conn.before() + results['executable_ls'] = conn.before conn.sendline('export {}={}; {}'.format(env_c, env_val, P_script)) conn.prompt() - results['script_run'] = conn.before() - conn.sendline('cat {}', out_stderr_c) + results['script_run'] = conn.before + conn.sendline('cat {}'.format(out_stderr_c)) conn.prompt() - results['script_stderr'] = conn.before() - conn.sendline('cat {}', out_stdout_c) + results['script_stderr'] = conn.before + conn.sendline('cat {}'.format(out_stdout_c)) conn.prompt() - results['script_stdout'] = conn.before() + results['script_stdout'] = conn.before conn.sendline('echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val)) conn.prompt() - results['prog_stdout'] = conn.before() + results['prog_stdout'] = conn.before conn.sendline('echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val)) conn.prompt() - results['prog_stderr'] = conn.before() - target.logout() + results['prog_stderr'] = conn.before + conn.logout() return results def gen_params(user_id, params_meta): import random r = random.Random(user_id) params = kpov_random_helpers.default_gen(user_id, params_meta) - homedir = '/home/student' + homedir = '/home/student/' params['env_c'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in xrange(5)]) params['P_c'] = "".join([r.choice('abcdefghijklmnoprst') for i in xrange(5)]) + ".c" - params['param_gen_seed'] = r.randint(0, 2**24) - params['c_destroy_gen_seed'] = r.randint(0, 2**24) + params['param_gen_seed'] = str(r.randint(0, 2**24)) + params['c_destroy_gen_seed'] = str(r.randint(0, 2**24)) for k in ['P_c', 'P_executable', 'out_stderr_c', 'P_script', 'out_stdout_c']: params[k] = homedir + params[k] return params @@ -170,13 +170,15 @@ def task_check(results, params): s_out += chr(20 + (ord(arg[i % arg_len]) ^ ord(var[i % env_len]) % 64)) r += ord(arg[i % arg_len]) + ord(var[i % env_len]) + i; if (i % 20 == 0): - s_out += "RAUS\n"; + s_out += "RAUS\r\n"; if (i % 31 == 0): s_out += 'ma' s_err += chr(r % 32 + ord('A')); if (i % 23 == 0): - s_err += "PATACIS\n" + s_err += "PATACIS\r\n" retval = r % 16 + s_err += '\r\n' + s_out += '\r\n' return(s_out, s_err, retval) score = 0 @@ -188,24 +190,26 @@ def task_check(results, params): expected_script_stdout, expected_script_stderr, rval = test_out_gen( params['arg_c'], env_val ) - split_stderr = expected_script_stderr.split('\n') - expected_script_stderr = "\n".join([ i for i in split_stderr if i.find('ma') >= 0]) + expected_script_stderr = 'cat {}\r\n'.format(params['out_stderr_c']) + expected_script_stderr if expected_script_stderr != results['script_stderr']: hints += ['wrong script stderr'] else: score += 2 + split_stdout = expected_script_stdout.split('\r\n') + expected_script_stdout = "\r\n".join([ i for i in split_stdout if i.find('ma') >= 0]) + expected_script_stdout = 'cat {}\r\n'.format(params['out_stdout_c']) + expected_script_stdout + "\r\n" if expected_script_stdout != results['script_stdout']: hints += ['wrong script stdout'] else: score += 2 - expected_prog_stdout, expected_prog_stderr, rval = test_out_ge-n( + expected_prog_stdout, expected_prog_stderr, rval = test_out_gen( arg_val, stdin_val ) - if expected_prog_stderr != results['prog_stderr']: + if expected_prog_stderr != results['prog_stderr'][-len(expected_prog_stderr):]: hints += ['wrong program stderr'] else: score += 2 - if expected_prog_stdout != results['prog_stdout']: + if expected_prog_stdout != results['prog_stdout'][-len(expected_prog_stdout):]: hints += ['wrong program stdout'] else: score += 2 @@ -220,7 +224,7 @@ def task_check(results, params): return hints, score def prepare_disks(templates, params): - c_source = """#include<stdio.h> + c_source = '''#include<stdio.h> #include<stdlib.h> #include<string.h> /* Odstranite vse odvecne velike crke Q, W ali X in program se bo prevedel. */ @@ -238,21 +242,21 @@ int main(int argc, char **argv){ printf("%c", 20 + (arg[i % arg_len] ^ var[i % env_len] % 64)); r += (int)arg[i % arg_len] + (int)var[i % env_len] + i; if (i % 20 == 0){ - printf("RAUS\n"); + printf("RAUS\\n"); } if (i % 31 == 0){ printf("ma"); } fprintf(stderr, "%c", r % 32 + 'A'); if (i % 23 == 0){ - fprintf(stderr, "PATACIS\n"); + fprintf(stderr, "PATACIS\\n"); } } - printf("\n"); - fprintf(stderr, "\n"); + printf("\\n"); + fprintf(stderr, "\\n"); return r % 16; } -""" +''' evil_shell_source = """#!/bin/sh while true; do ifconfig eth1 10.0.2.19; @@ -262,10 +266,10 @@ while true; do done """ import random - d = templates['Student'] + d = templates['student-entrance'] r = random.Random(params['c_destroy_gen_seed']) - destroyed_c_source = c_source[:100] - for c in c_source[100:]: + destroyed_c_source = c_source[:110] + for c in c_source[110:]: i = r.randint(0, 5) if i == 1: destroyed_c_source += 'QW' @@ -275,13 +279,14 @@ done destroyed_c_source += 'QX' destroyed_c_source += c d.write(params['P_c'], destroyed_c_source) + print params['P_c'] d.chown(1000, 1000, params['P_c']) - sh_path ='/usr/local/bin' + params['net_prog_name'] + sh_path ='/usr/local/bin/' + params['net_prog_name'] d.write(sh_path, evil_shell_source) d.chmod(0775, sh_path) d.write("/etc/rc.local", """#!/bin/sh -e -{} +{} & exit 0 """.format(sh_path)) |