def parse(self): try: self.buf = self.data # Cut out comments: self.eatignorable() # attempt to find 'foo {' or 'foo =' while len(self.buf) > 0: word = None print "l: %d" % len(self.buf) if not self.Word.match(self.buf): debuglib.fatal("Unknown: %s" % self.buf) word, self.buf = self.Word.consume(self.buf) self.eatignorable() print "Word: %s" % word if word in self.blocktypes: if not word in self.config: self.config[word] = {} self.config[word].update(self.blocktypes[word]()) else: keyname = 'globals' if not keyname in self.config: self.config[keyname] = {} self.config[keyname].update(self.parseAssignment(key=word)) self.eatignorable() print "Config: " pprint(self.config) except ExpectedTokenMissing, e: debuglib.fatal("config line %d: %s" % (self.lineno, e)) raise SystemExit
def parseBlock(self): ignored, self.buf = self.OpenBlock.consume(self.buf) data = {} self.eatignorable() try: while not self.CloseBlock.match(self.buf): data.update(self.parseAssignment()) ignored, self.buf = self.CloseBlock.consume(self.buf) except ExpectedTokenMissing, e: debuglib.fatal("config line %d: %s" % (self.lineno, e))
def __init__(self, pattern, options={}): try: self.patternMap = options['pattern map'] except KeyError, e: debuglib.fatal("No pattern map specified when creating Pattern") raise SystemExit
Rule( reaction= "echo 'authfail: %(_HITS): %(HOST)/%(PROG): login failure for %(USER) (src %(HOST_SRC))'", patterns=[ '%(HOST) %(PROG)\[\d+\]: error: PAM: authentication error for %(USER) from %(HOST_SRC)', '%(HOST) %(PROG)\[\d+\]: Invalid user %(USER) from %(HOST_SRC)', ], options={ 'pattern map': GLOBALPM, }, ), Rule( reaction= "echo 'noidstring: %(_HITS): %(HOST)/%(PROG): src %(HOST_SRC)'", patterns=[ '%(HOST) %(PROG)\[\d+\]: Did not receive identification string from %(HOST_SRC)', ], options={ 'pattern map': GLOBALPM, }, ), ] while 1: l = sys.stdin.readline() if not l: debuglib.fatal("stdin closed") raise SystemExit for rule in rules: rule.evaluate(l)
rules = [ Rule( reaction = "echo 'authfail: %(_HITS): %(HOST)/%(PROG): login failure for %(USER) (src %(HOST_SRC))'", patterns = [ '%(HOST) %(PROG)\[\d+\]: error: PAM: authentication error for %(USER) from %(HOST_SRC)', '%(HOST) %(PROG)\[\d+\]: Invalid user %(USER) from %(HOST_SRC)', ], options = { 'pattern map': GLOBALPM, }, ), Rule( reaction = "echo 'noidstring: %(_HITS): %(HOST)/%(PROG): src %(HOST_SRC)'", patterns = [ '%(HOST) %(PROG)\[\d+\]: Did not receive identification string from %(HOST_SRC)', ], options = { 'pattern map': GLOBALPM, }, ), ] while 1: l = sys.stdin.readline() if not l: debuglib.fatal("stdin closed") raise SystemExit for rule in rules: rule.evaluate(l)