def from_file(self, fd): def parse_ifv(line): fields = line[1:-1].split() if len(fields) < 2 or fields[0] != "InterfaceVector": raise SyntaxError("Syntax error InterfaceVector statement %s" % line) ifv = InterfaceVector() ifv.name = fields[1] if len(fields) == 2: return for field in fields[2:]: p = field.split(":") if len(p) != 2: raise SyntaxError("Invalid param in InterfaceVector statement %s" % line) param = Param() param.name = p[0] param.type = refpolicy.str_to_field[p[1]] ifv.params[param.name] = param return ifv ifv = None for line in fd: line = line[:-1] if line[0] == "[": if ifv: self.add_ifv(ifv) ifv = parse_ifv(line) elif ifv: l = line.split(",") av = access.AccessVector(l) ifv.add_av(av) if ifv: self.add_ifv(ifv) self.index()
def from_file(self, fd): def parse_attr(line): fields = line[1:-1].split() if len(fields) != 2 or fields[0] != "Attribute": raise SyntaxError("Syntax error Attribute statement %s" % line) a = AttributeVector() a.name = fields[1] return a a = None for line in fd: line = line[:-1] if line[0] == "[": if a: self.add_attr(a) a = parse_attr(line) elif a: l = line.split(",") av = access.AccessVector(l) a.add_av(av) if a: self.add_attr(a)
raise ValueError("error parsing file %s: %s" % (f, str(e))) spt = None if support_macros: o("Parsing support macros (%s): " % support_macros) spt = refpolicy.SupportMacros() parse_file(support_macros, spt) headers.children.append(spt) # FIXME: Total hack - add in can_exec rather than parse the insanity # of misc_macros. We are just going to preten that this is an interface # to make the expansion work correctly. can_exec = refpolicy.Interface("can_exec") av = access.AccessVector([ "$1", "$2", "file", "execute_no_trans", "read", "getattr", "lock", "execute", "ioctl" ]) can_exec.children.append(refpolicy.AVRule(av)) headers.children.append(can_exec) o("done.\n") if output and not debug: status = util.ConsoleProgressBar(sys.stdout, steps=len(modules)) status.start("Parsing interface files") failures = [] for x in modules: m = refpolicy.Module() m.name = x[0]