def text(e): res = "" for n in e.childNodes: if n.nodeType != Element.TEXT_NODE: log.panic("xml: text expected in <%s>, got %d" % (e.nodeName, n.nodeType)) res += n.nodeValue return res
def get(o, d = None): if p.has_option(builder, o): return string.strip(p.get(builder, o)) elif p.has_option("all", o): return string.strip(p.get("all", o)) elif d != None: return d else: log.panic("cannot find %s::%s" % (builder, o))
def build_request(e): if e.nodeType != Element.ELEMENT_NODE: log.panic("xml: evil request element") if e.nodeName == "group": return Group(e) elif e.nodeName == "notification": return Notification(e) elif e.nodeName == "command": # FIXME return Command(e) else: log.panic("xml: evil request [%s]" % e.nodeName)
def read(self): self._open() self.signers = [] body = self.fd.read() if string.strip(body) == "": # empty file, don't choke self.requests = [] return try: self.requests = request.parse_requests(body) except Exception, e: log.panic("error parsing %s: %s" % (self.name, e)) pass
def parse_xml(self, e): for c in e.childNodes: if is_blank(c): continue if c.nodeType != Element.ELEMENT_NODE: log.panic("xml: evil batch child %d" % c.nodeType) if c.nodeName == "src-rpm": self.src_rpm = text(c) elif c.nodeName == "spec": # normalize specname, specname is used as buildlog and we don't # want to be exposed to directory traversal attacks self.spec = text(c).split('/')[-1] elif c.nodeName == "command": self.spec = "COMMAND" self.command = text(c).strip() self.command_flags = string.split(attr(c, "flags", "")) elif c.nodeName == "info": self.info = text(c) elif c.nodeName == "kernel": self.kernel = text(c) elif c.nodeName == "define": define = attr(c, "name") self.defines[define] = text(c) elif c.nodeName == "target": self.target.append(text(c)) elif c.nodeName == "skip": self.skip.append(text(c)) elif c.nodeName == "branch": self.branch = text(c) elif c.nodeName == "builder": key = text(c) self.builders.append(key) self.builders_status[key] = attr(c, "status", "?") self.builders_status_time[key] = attr(c, "time", "0") self.builders_status_buildtime[ key] = "0" #attr(c, "buildtime", "0") elif c.nodeName == "with": self.bconds_with.append(text(c)) elif c.nodeName == "without": self.bconds_without.append(text(c)) else: log.panic("xml: evil batch child (%s)" % c.nodeName)
def reload(self): self.acl_conf_mtime = os.stat(path.acl_conf)[stat.ST_MTIME] self.current_user = None status.push("reading acl.conf") p = ConfigParser.ConfigParser() p.readfp(open(path.acl_conf)) self.users = {} for login in p.sections(): if self.users.has_key(login): log.panic("acl: duplicate login: %s" % login) continue user = User(p, login) for e in user.gpg_emails: if self.users.has_key(e): log.panic("acl: user email colision %s <-> %s" % \ (self.users[e].login, login)) else: self.users[e] = user self.users[login] = user status.pop()
def parse_xml(self, e): for c in e.childNodes: if is_blank(c): continue if c.nodeType != Element.ELEMENT_NODE: log.panic("xml: evil batch child %d" % c.nodeType) if c.nodeName == "src-rpm": self.src_rpm = text(c) elif c.nodeName == "spec": # normalize specname, specname is used as buildlog and we don't # want to be exposed to directory traversal attacks self.spec = text(c).split('/')[-1] elif c.nodeName == "command": self.spec = "COMMAND" self.command = text(c).strip() self.command_flags = string.split(attr(c, "flags", "")) elif c.nodeName == "info": self.info = text(c) elif c.nodeName == "kernel": self.kernel = text(c) elif c.nodeName == "define": define = attr(c, "name") self.defines[define] = text(c) elif c.nodeName == "target": self.target.append(text(c)) elif c.nodeName == "skip": self.skip.append(text(c)) elif c.nodeName == "branch": self.branch = text(c) elif c.nodeName == "builder": key = text(c) self.builders.append(key) self.builders_status[key] = attr(c, "status", "?") self.builders_status_time[key] = attr(c, "time", "0") self.builders_status_buildtime[key] = "0" #attr(c, "buildtime", "0") elif c.nodeName == "with": self.bconds_with.append(text(c)) elif c.nodeName == "without": self.bconds_without.append(text(c)) else: log.panic("xml: evil batch child (%s)" % c.nodeName)
def __init__(self, p, login): self.login = login self.privs = [] self.gpg_emails = [] self.mailto = "" self.change_requester = False if p.has_option(login, "gpg_emails"): self.gpg_emails = string.split(p.get(login, "gpg_emails")) else: log.panic("acl: [%s] has no gpg_emails" % login) if p.has_option(login, "mailto"): self.mailto = p.get(login, "mailto") else: if len(self.gpg_emails) > 0: self.mailto = self.gpg_emails[0] if p.has_option(login, "change_requester"): self.change_requester = True if p.has_option(login, "privs"): for p in string.split(p.get(login, "privs")): l = string.split(p, ":") if len(l) == 2: p+=":*" if len(l) not in (2,3) or l[0] == "" or l[1] == "": log.panic("acl: invalid priv format: '%s' [%s]" % (p, login)) else: self.privs.append(p) else: log.panic("acl: [%s] has no privs" % login)
def __init__(self, e): self.batches = [] self.kind = 'group' self.id = attr(e, "id") self.no = int(attr(e, "no")) self.priority = 2 self.time = time.time() self.requester = "" self.max_jobs = 0 self.requester_email = "" self.flags = string.split(attr(e, "flags", "")) for c in e.childNodes: if is_blank(c): continue if c.nodeType != Element.ELEMENT_NODE: log.panic("xml: evil group child %d" % c.nodeType) if c.nodeName == "batch": self.batches.append(Batch(c)) elif c.nodeName == "requester": self.requester = text(c) self.requester_email = attr(c, "email", "") elif c.nodeName == "priority": self.priority = int(text(c)) elif c.nodeName == "time": self.time = int(text(c)) elif c.nodeName == "maxjobs": self.max_jobs = int(text(c)) else: log.panic("xml: evil group child (%s)" % c.nodeName) # note that we also check that group is sorted WRT deps m = {} for b in self.batches: deps = [] m[b.b_id] = b for dep in b.depends_on: if m.has_key(dep): # avoid self-deps if id(m[dep]) != id(b): deps.append(m[dep]) else: log.panic("xml: dependency not found in group") b.depends_on = deps if self.requester_email == "" and self.requester != "": self.requester_email = acl.user(self.requester).mail_to()
def __init__(self, e): self.batches = [] self.kind = 'notification' self.group_id = attr(e, "group-id") self.builder = attr(e, "builder") self.batches = {} self.batches_buildtime = {} for c in e.childNodes: if is_blank(c): continue if c.nodeType != Element.ELEMENT_NODE: log.panic("xml: evil notification child %d" % c.nodeType) if c.nodeName == "batch": id = attr(c, "id") status = attr(c, "status") buildtime = attr(c, "buildtime", "0") if not status.startswith("OK") and not status.startswith("SKIP") and not status.startswith("UNSUPP") and not status.startswith("FAIL"): log.panic("xml notification: bad status: %s" % status) self.batches[id] = status self.batches_buildtime[id] = buildtime else: log.panic("xml: evil notification child (%s)" % c.nodeName)
def __init__(self, e): self.batches = [] self.kind = 'notification' self.group_id = attr(e, "group-id") self.builder = attr(e, "builder") self.batches = {} self.batches_buildtime = {} for c in e.childNodes: if is_blank(c): continue if c.nodeType != Element.ELEMENT_NODE: log.panic("xml: evil notification child %d" % c.nodeType) if c.nodeName == "batch": id = attr(c, "id") status = attr(c, "status") buildtime = attr(c, "buildtime", "0") if not status.startswith("OK") and not status.startswith( "SKIP") and not status.startswith( "UNSUPP") and not status.startswith("FAIL"): log.panic("xml notification: bad status: %s" % status) self.batches[id] = status self.batches_buildtime[id] = buildtime else: log.panic("xml: evil notification child (%s)" % c.nodeName)
def read(self, builder): p = ConfigParser.ConfigParser() def get(o, d=None, sec=None): if p.has_option(sec, o): return string.strip(p.get(sec, o)) elif p.has_option(builder, o): return string.strip(p.get(builder, o)) elif p.has_option("all", o): return string.strip(p.get("all", o)) elif d != None: return d else: log.panic("cannot find %s::%s" % (builder, o)) p.readfp(open(path.builder_conf)) self.admin_email = get("admin_email") self.email = self.admin_email if p.has_option("all", "syslog"): f = p.get("all", "syslog") if f != "": if syslog_facilities.has_key(f): log.open_syslog("builder", syslog_facilities[f]) else: log.panic("no such syslog facility: %s" % f) if builder == "src": builder = get("src_builder", builder) self.builder = builder self.binary_builders = string.split(get("binary_builders")) self.src_builder = string.strip(get("src_builder", "")) self.tag_prefixes = string.split(get("tag_prefixes", "")) self.max_keep_time = int(get("max_keep_time", 168)) * 60 * 60 self.bot_email = get("bot_email", "") self.control_url = get("control_url") self.request_handler_server_port = int( get("port", d=1234, sec="request-server")) self.request_handler_server_ssl = get("ssl", d="False", sec="request-server") if self.request_handler_server_ssl: self.request_handler_server_ssl_port = int( get("port", d=1235, sec="request-server")) self.request_handler_server_ssl_key = get("ssl_key", d="", sec="request-server") self.request_handler_server_ssl_cert = get("ssl_cert", d="", sec="request-server") self.builder_list = get("builder_list", "") self.gen_upinfo = get("gen_upinfo", "yes") if self.gen_upinfo == 'no': self.gen_upinfo = False else: self.gen_upinfo = True status.admin = self.admin_email status.builder_list = self.builder_list self.max_jobs = int(get("max_jobs")) if builder == "all": return self.email = get("email") if builder not in p.sections(): log.panic("builder %s not in config file" % builder) self.arch = get("arch") self.chroot = get("chroot") self.buildlogs_url = get("buildlogs_url", "/dev/null") self.buildlogs = get("buildlogs", "http://buildlogs.pld-linux.org/") self.ftp_url = get("ftp_url") self.notify_url = get("notify_url") self.test_ftp_url = get("test_ftp_url", "/dev/null") self.rpmqa_url = get("rpmqa_url", "/dev/null") self.rpmqa_filename = get("rpmqa_filename") self.job_slots = int(get("job_slots")) self.max_load = float(get("max_load")) self.rpm_cache_dir = get("rpm_cache_dir", "/spools/ready") self.builder_user = get("builder_user", "builder") self.sudo_chroot_wrapper = get("sudo_chroot_wrapper", "") self.nice = get("nice", "0") f = get("syslog", "") if f != "": if syslog_facilities.has_key(f): log.open_syslog(self.builder, syslog_facilities[f]) else: log.panic("no such syslog facility: %s" % f) self.done = 1
def read(self, builder): p = ConfigParser.ConfigParser() def get(o, d = None): if p.has_option(builder, o): return string.strip(p.get(builder, o)) elif p.has_option("all", o): return string.strip(p.get("all", o)) elif d != None: return d else: log.panic("cannot find %s::%s" % (builder, o)) p.readfp(open(path.builder_conf)) self.admin_email = get("admin_email") self.email = self.admin_email if p.has_option("all", "syslog"): f = p.get("all", "syslog") if f != "": if syslog_facilities.has_key(f): log.open_syslog("builder", syslog_facilities[f]) else: log.panic("no such syslog facility: %s" % f) if builder == "src": builder = get("src_builder", builder) self.builder = builder self.binary_builders = string.split(get("binary_builders")) self.src_builder = string.strip(get("src_builder", "")) self.tag_prefixes = string.split(get("tag_prefixes", "")) self.max_keep_time = int(get("max_keep_time", 168))*60*60 self.bot_email = get("bot_email", "") self.control_url = get("control_url") self.request_handler_server_port = int(get("request_handler_server_port", 1234)) self.builder_list = get("builder_list", "") self.gen_upinfo = get("gen_upinfo", "yes") if self.gen_upinfo == 'no': self.gen_upinfo = False else: self.gen_upinfo = True status.admin = self.admin_email status.builder_list = self.builder_list self.max_jobs = int(get("max_jobs")) if builder == "all": return self.email = get("email") if builder not in p.sections(): log.panic("builder %s not in config file" % builder) self.arch = get("arch") self.chroot = get("chroot") self.buildlogs_url = get("buildlogs_url", "/dev/null") self.buildlogs = get("buildlogs", "http://buildlogs.pld-linux.org/") self.ftp_url = get("ftp_url") self.notify_url = get("notify_url") self.test_ftp_url = get("test_ftp_url", "/dev/null") self.rpmqa_url = get("rpmqa_url", "/dev/null") self.rpmqa_filename = get("rpmqa_filename") self.job_slots = int(get("job_slots")) self.max_load = float(get("max_load")) self.rpm_cache_dir = get("rpm_cache_dir", "/spools/ready") self.builder_user = get("builder_user", "builder") self.sudo_chroot_wrapper = get("sudo_chroot_wrapper", "") self.nice = get("nice", "0") f = get("syslog", "") if f != "": if syslog_facilities.has_key(f): log.open_syslog(self.builder, syslog_facilities[f]) else: log.panic("no such syslog facility: %s" % f) self.done = 1
def user(self, l): if not self.users.has_key(l): log.panic("no such user: %s" % l) return self.users[l]