fdeploy_ini: Generalize the share name SIDs
authorGarming Sam <garming@catalyst.net.nz>
Tue, 29 May 2018 21:42:45 +0000 (09:42 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 16 Aug 2018 21:42:22 +0000 (23:42 +0200)
This overrides the custom entity handler defined in the top level parser.

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/gp_parse/__init__.py
python/samba/gp_parse/gp_ini.py

index 3b31a451d615b994de6fc696af5143d4a9535ffb..80fbee68ed4bdfa7066b1d7160edc0a734baf777 100644 (file)
@@ -20,6 +20,7 @@
 from xml.dom import minidom
 from io import BytesIO
 from xml.etree.ElementTree import ElementTree, fromstring, tostring
+from hashlib import md5
 
 
 ENTITY_USER_ID = 0
@@ -79,8 +80,8 @@ class GPParser(object):
         minidom_parsed = minidom.parseString(temporary_bytes.getvalue())
         handle.write(minidom_parsed.toprettyxml(encoding=self.output_encoding))
 
-    def new_xml_entity(self, global_entities, ent_type):
-        identifier = str(len(global_entities)).zfill(4)
+    def new_xml_entity(self, name, ent_type):
+        identifier = md5(name).hexdigest()
 
         type_str = entity_type_to_string(ent_type)
 
@@ -109,7 +110,7 @@ class GPParser(object):
                 elem.text = global_entities[old_text]
                 entities.append((elem.text, old_text))
             else:
-                elem.text = self.new_xml_entity(global_entities,
+                elem.text = self.new_xml_entity(old_text,
                                                 ENTITY_USER_ID)
 
                 entities.append((elem.text, old_text))
@@ -128,7 +129,7 @@ class GPParser(object):
                 elem.text = global_entities[old_text]
                 entities.append((elem.text, old_text))
             else:
-                elem.text = self.new_xml_entity(global_entities,
+                elem.text = self.new_xml_entity(old_text,
                                                 ENTITY_SDDL_ACL)
 
                 entities.append((elem.text, old_text))
@@ -156,7 +157,7 @@ class GPParser(object):
                 to_put = global_entities[old_text]
                 entities.append((to_put, old_text))
             else:
-                to_put = self.new_xml_entity(global_entities,
+                to_put = self.new_xml_entity(old_text,
                                              ENTITY_NETWORK_PATH)
                 elem.text = to_put + remaining
 
index 4bd00c8ccf17c7e2e5d026c8ca4e98368b9d4472..6c3d9391d63e1c49279ba917b6b5cf1e24208c26 100644 (file)
@@ -25,7 +25,7 @@ from ConfigParser import ConfigParser
 from xml.etree.ElementTree import Element, SubElement
 from StringIO import StringIO
 
-from samba.gp_parse import GPParser
+from samba.gp_parse import GPParser, ENTITY_USER_ID
 
 # [MS-GPFR] Group Policy Folder Redirection
 # [MS-GPSCR] Scripts Extension
@@ -195,3 +195,23 @@ class GPFDeploy1IniParser(GPIniParser):
 
         self.ini_conf.add_section(section_name)
         return section_name
+
+    def custom_entities(self, root, global_entities):
+        entities = []
+        fdeploy_sids = root.findall('.//Section[@fdeploy_SID]')
+        fdeploy_sids.sort()
+
+        for sid in fdeploy_sids:
+            old_attrib = sid.attrib['fdeploy_SID']
+
+            if old_attrib in global_entities:
+                new_attrib = global_entities[old_attrib]
+            else:
+                new_attrib = self.new_xml_entity(old_attrib, ENTITY_USER_ID)
+                entities.append((new_attrib, old_attrib))
+
+                global_entities.update([(old_attrib, new_attrib)])
+
+            sid.attrib['fdeploy_SID'] = new_attrib
+
+        return entities