|
@ -1,6 +1,8 @@ |
|
|
# !/usr/bin/env python -tt |
|
|
# !/usr/bin/env python -tt |
|
|
# -*- encoding: utf-8 -*- |
|
|
# -*- encoding: utf-8 -*- |
|
|
|
|
|
|
|
|
|
|
|
from __future__ import with_statement |
|
|
|
|
|
# this is already implemented in Python 2.6.x |
|
|
auth_methods = ( |
|
|
auth_methods = ( |
|
|
u'trust', |
|
|
u'trust', |
|
|
u'reject', |
|
|
u'reject', |
|
@ -67,3 +69,27 @@ class Rule(object): |
|
|
self.comment = comment |
|
|
self.comment = comment |
|
|
self.line = None |
|
|
self.line = None |
|
|
|
|
|
|
|
|
|
|
|
def get_hba(path): |
|
|
|
|
|
all_lines = {} |
|
|
|
|
|
laws = {} |
|
|
|
|
|
with open(path, 'r') as f: |
|
|
|
|
|
read_data = f.readlines() |
|
|
|
|
|
lineno = 1 |
|
|
|
|
|
for line in read_data: |
|
|
|
|
|
all_lines[lineno] = line |
|
|
|
|
|
if line.startswith(u'#') or len(line.strip())==0: |
|
|
|
|
|
pass |
|
|
|
|
|
else: |
|
|
|
|
|
laws[lineno] = line |
|
|
|
|
|
lineno = lineno +1 |
|
|
|
|
|
return all_lines, laws |
|
|
|
|
|
|
|
|
|
|
|
def test(t): |
|
|
|
|
|
get_hba(u'/etc/postgresql/8.4/main/pg_hba.conf') |
|
|
|
|
|
if t == u'error': |
|
|
|
|
|
error = Rule(u'local',u'trust',u'all',u'all','192.168.1.1/32') |
|
|
|
|
|
else: |
|
|
|
|
|
good = Rule(u'local',u'trust',u'all',u'all') |
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
|
test(u'aa') |
|
|
|
|
|
|