]>
Commit | Line | Data |
---|---|---|
57b6e61d MM |
1 | import email |
2 | import string | |
3 | import time | |
4 | import os | |
5 | import StringIO | |
cc94eb63 | 6 | import sys |
57b6e61d MM |
7 | |
8 | import gpg | |
9 | import request | |
10 | import log | |
11 | import path | |
12 | from acl import acl | |
13 | from lock import lock | |
14 | from bqueue import B_Queue | |
b5a39692 | 15 | from config import config, init_conf |
57b6e61d MM |
16 | |
17 | def check_double_id(id): | |
18 | id_nl = id + "\n" | |
19 | ||
20 | ids = open(path.processed_ids_file) | |
21 | for i in ids.xreadlines(): | |
22 | if i == id_nl: | |
b5a39692 MM |
23 | # FIXME: security email here? |
24 | log.alert("request %s already processed" % id) | |
57b6e61d MM |
25 | return 1 |
26 | ids.close() | |
27 | ||
28 | ids = open(path.processed_ids_file, "a") | |
29 | ids.write(id_nl) | |
30 | ids.close() | |
31 | ||
32 | return 0 | |
33 | ||
34738db3 | 34 | def handle_group(r, user): |
b5a39692 MM |
35 | def fail_mail(msg): |
36 | if len(r.batches) >= 1: | |
37 | spec = r.batches[0].spec | |
38 | else: | |
39 | spec = "None.spec" | |
40 | log.error("%s: %s" % (spec, msg)) | |
41 | m = user.message_to() | |
42 | m.set_headers(subject = "building %s failed" % spec) | |
43 | m.write_line(msg) | |
44 | m.send() | |
45 | ||
57b6e61d | 46 | lock("request") |
57b6e61d MM |
47 | if check_double_id(r.id): |
48 | return | |
49 | ||
b5a39692 MM |
50 | if not user.can_do("src", config.builder): |
51 | fail_mail("user %s is not allowed to src:%s" \ | |
52 | % (user.get_login(), config.builder)) | |
57b6e61d MM |
53 | return |
54 | ||
55 | for batch in r.batches: | |
56 | for bld in batch.builders: | |
57 | if not user.can_do("binary", bld): | |
b5a39692 MM |
58 | fail_mail("user %s is not allowed to binary:%s" \ |
59 | % (user.get_login(), bld)) | |
57b6e61d MM |
60 | return |
61 | ||
34738db3 | 62 | r.requester = user.get_login() |
57b6e61d MM |
63 | r.time = time.time() |
64 | log.notice("queued %s from %s" % (r.id, user.get_login())) | |
65 | q = B_Queue(path.queue_file) | |
66 | q.lock(0) | |
67 | q.read() | |
68 | q.add(r) | |
69 | q.write() | |
70 | q.unlock() | |
71 | ||
72 | def handle_request(f): | |
73 | sio = StringIO.StringIO() | |
74 | sio.write(f.read()) | |
75 | sio.seek(0) | |
76 | (em, body) = gpg.verify_sig(sio) | |
2e33eed1 | 77 | user = acl.user_by_email(em) |
57b6e61d MM |
78 | if user == None: |
79 | # FIXME: security email here | |
80 | log.alert("invalid signature, or not in acl %s" % em) | |
81 | return | |
82 | r = request.parse_request(body) | |
57b6e61d | 83 | if r.kind == 'group': |
34738db3 | 84 | handle_group(r, user) |
57b6e61d MM |
85 | else: |
86 | msg = "%s: don't know how to handle requests of this kind '%s'" \ | |
87 | % (user.get_login(), r.kind) | |
88 | log.alert(msg) | |
b5a39692 MM |
89 | m = user.message_to() |
90 | m.set_headers(subject = "unknown request") | |
91 | m.write_line(msg) | |
92 | m.send() | |
cc94eb63 | 93 | |
1f62bccc | 94 | def main(): |
b5a39692 | 95 | init_conf("src") |
cc94eb63 MM |
96 | handle_request(sys.stdin) |
97 | sys.exit(0) | |
1f62bccc MM |
98 | |
99 | main() |