[PATCH 18/18] gpo: Properly parse the inf file

David Mulder dmulder at suse.com
Thu Feb 23 20:22:10 UTC 2017


inf file parsing was failing. Modified the parsing code to use ConfigParser. Also, use the backslash in path names when opening smb files, otherwise it fails against a windows server.

Signed-off-by: David Mulder <dmulder at suse.com>
---
 python/samba/gpclass.py | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py
index 4c7b4fb..5ae4479 100755
--- a/python/samba/gpclass.py
+++ b/python/samba/gpclass.py
@@ -28,6 +28,8 @@ import samba.getopt as options
 from samba.samdb import SamDB
 from samba.netcmd import gpo as gpo_user
 import codecs
+from ConfigParser import ConfigParser
+from StringIO import StringIO
 
 class gp_ext(object):
     def list(self, rootpath):
@@ -131,7 +133,7 @@ class gp_sec_ext(gp_ext):
         ret = False
         inftable = self.populate_inf()
 
-        policy = conn.loadfile(path).decode('utf-16')
+        policy = conn.loadfile(path.replace('/', '\\')).decode('utf-16')
         current_section = None
         LOG = open(attr_log, "a")
         LOG.write(str(path.split('/')[2]) + '\n')
@@ -142,18 +144,15 @@ class gp_sec_ext(gp_ext):
         # If at any point in time a GPO was applied,
         # then we return that boolean at the end.
 
-        for line in policy.splitlines():
-            line = line.strip()
-            if line[0] == '[':
-                section = line[1: -1]
-                current_section = inftable.get(section.encode('ascii', 'ignore'))
-
-            else:
-                # We must be in a section
-                if not current_section:
-                    continue
-                (key, value) = line.split("=")
-                key = key.strip()
+        inf_conf = ConfigParser()
+        inf_conf.optionxform=str
+        inf_conf.readfp(StringIO(policy))
+
+        for section in inf_conf.sections():
+            current_section = inftable.get(section)
+            if not current_section:
+                continue
+            for key, value in inf_conf.items(section):
                 if current_section.get(key):
                     (att, setter) = current_section.get(key)
                     value = value.encode('ascii', 'ignore')
-- 
2.10.2




More information about the samba-technical mailing list