From 5d77bfcca9e40438d84eaab7a0c23e3f540ba7fa Mon Sep 17 00:00:00 2001 From: Igor Chudov Date: Thu, 28 Nov 2019 16:33:35 +0400 Subject: [PATCH] Parse Samba XML PolFile as well as PReg .pol files --- gpoa/util/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gpoa/util/__init__.py b/gpoa/util/__init__.py index 1ce75d2..1c4d6f9 100644 --- a/gpoa/util/__init__.py +++ b/gpoa/util/__init__.py @@ -107,6 +107,11 @@ def get_cache(cache_file, default_cache_obj): return data +def load_preg(file_path): + if file_path.endswith('.xml'): + return load_xml_preg(file_path) + return load_pol_preg(file_path) + def load_xml_preg(xml_path): ''' Parse PReg file and return its preg object @@ -116,5 +121,21 @@ def load_xml_preg(xml_path): xml_root = ElementTree.parse(xml_path).getroot() gpparser.load_xml(xml_root) gpparser.pol_file.__ndr_print__() + + return gpparser.pol_file + +def load_pol_preg(polfile): + ''' + Parse PReg file and return its preg object + ''' + logging.debug('Loading PReg from .pol file: {}'.format(polfile)) + gpparser = GPPolParser() + data = None + + with open(polfile, 'rb') as f: + data = f.read() + gpparser.parse(data) + + #print(gpparser.pol_file.__ndr_print__()) return gpparser.pol_file