1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
4 import configparser as ConfigParser
13 from mailer import Message
14 from config import config
17 def __init__(self, p, login):
22 self.change_requester = False
24 if p.has_option(login, "gpg_emails"):
25 self.gpg_emails = p.get(login, "gpg_emails").split()
27 log.panic("acl: [%s] has no gpg_emails" % login)
29 if p.has_option(login, "mailto"):
30 self.mailto = p.get(login, "mailto")
32 if len(self.gpg_emails) > 0:
33 self.mailto = self.gpg_emails[0]
35 if p.has_option(login, "change_requester"):
36 self.change_requester = True
38 if p.has_option(login, "privs"):
39 for p in p.get(login, "privs").split():
43 if len(l) not in (2,3) or l[0] == "" or l[1] == "":
44 log.panic("acl: invalid priv format: '%s' [%s]" % (p, login))
48 log.panic("acl: [%s] has no privs" % login)
50 def can_do(self, what, where, branch=None):
52 action = "%s:%s:%s" % (what, where, branch)
54 action = "%s:%s:N-A" % (what, where)
55 for priv in self.privs:
61 pwhat,pwhere,pbranch=priv.split(":")
62 for pbranch in pbranch.split(","):
63 priv="%s:%s:%s" % (pwhat,pwhere,pbranch)
64 if fnmatch.fnmatch(action, priv):
68 def check_priority(self, prio, where):
69 for priv in self.privs:
70 val,builder=priv.split(":")[0:2]
71 if fnmatch.fnmatch(where, builder):
87 m.set_headers(to = self.mail_to(), cc = config.builder_list)
98 mtime = os.stat(path.acl_conf)[stat.ST_MTIME]
99 if mtime != self.acl_conf_mtime:
100 log.notice("acl.conf has changed, reloading...")
106 self.acl_conf_mtime = os.stat(path.acl_conf)[stat.ST_MTIME]
107 self.current_user = None
108 status.push("reading acl.conf")
109 p = ConfigParser.ConfigParser()
110 p.readfp(open(path.acl_conf))
112 for login in p.sections():
113 if login in self.users:
114 log.panic("acl: duplicate login: %s" % login)
116 user = User(p, login)
117 for e in user.gpg_emails:
119 log.panic("acl: user email colision %s <-> %s" % \
120 (self.users[e].login, login))
123 self.users[login] = user
126 def user_by_email(self, ems):
132 def user_by_login(self, l):
136 if not l in self.users:
137 log.panic("no such user: %s" % l)
140 def set_current_user(self, u):
141 self.current_user = u
143 status.email = u.mail_to()
145 def current_user_login(self):
146 if self.current_user != None:
147 return self.current_user.login