gp_ini: Add a fdeploy1 parser for better generalization
authorGarming Sam <garming@catalyst.net.nz>
Thu, 24 May 2018 03:17:35 +0000 (15:17 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 16 Aug 2018 21:42:21 +0000 (23:42 +0200)
We still fail to handle entities in fdeploy.ini (version 0) files. Here we
manage to factor out some of the SIDs, but not all of them. This will be
completed in a later patch. The overall idea is to split the SID values into
individual XML elements and annotate them. We also note down network paths for
the redirection folders.

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

index cfbf02298701e973d24c67ff3088265edf18c917..f0ef0b2358cfa06cc3fc3d43e9e11f209e84f7b6 100644 (file)
@@ -103,3 +103,80 @@ class GPIniParser(GPParser):
 
 class GPTIniParser(GPIniParser):
     encoding = 'utf-8'
+
+
+class GPFDeploy1IniParser(GPIniParser):
+    def build_xml_parameter(self, section_xml, section, key_ini, val_ini):
+        parent_return = super(GPFDeploy1IniParser,
+                              self).build_xml_parameter(section_xml, section,
+                                                        key_ini, val_ini)
+        # Add generalization metadata and parse out SID list
+        if section.lower() == 'folder_redirection':
+            # Process the header section
+            # {GUID} = S-1-1-0;S-1-1-0
+
+            # Remove the un-split SID values
+            key = parent_return.find('Value')
+            parent_return.remove(key)
+
+            sid_list = val_ini.strip().strip(';').split(';')
+
+            for sid in sid_list:
+                value = SubElement(parent_return, 'Value')
+                value.text = sid
+                value.attrib['user_id'] = 'TRUE'
+
+        else:
+            # Process redirection sections
+            # Only FullPath should be a network path
+            if key_ini == 'FullPath':
+                key = parent_return.find('Value')
+                key.attrib['network_path'] = 'TRUE'
+
+        return parent_return
+
+    def load_xml_parameter(self, param_xml, section):
+        # Re-join the SID list before entering ConfigParser
+        if section.lower() == 'folder_redirection':
+            key = param_xml.find('Key').text
+            values = param_xml.findall('Value')
+
+            if len(values) == 1:
+                # There appears to be a convention of a trailing semi-colon
+                # with only one value in the SID list.
+                value = values[0].text + ';'
+            else:
+                value = ';'.join([x.text for x in values])
+
+            self.ini_conf.set(section, key, value)
+
+            return (key, value)
+
+        # Do the normal ini code for other sections
+        return super(GPFDeploy1IniParser,
+                     self).load_xml_parameter(param_xml, section)
+
+    def build_xml_section(self, root_xml, sec_ini):
+        section = SubElement(root_xml, 'Section')
+
+        if (sec_ini.lower() != 'folder_redirection' and
+            sec_ini.lower() != 'version'):
+            guid, sid = sec_ini.split('_')
+            section.attrib['fdeploy_GUID'] = guid
+            section.attrib['fdeploy_SID'] = sid
+        else:
+            section.attrib['name'] = sec_ini
+
+        return section
+
+    def load_xml_section(self, section_xml):
+        # Construct the name from GUID + SID if no name exists
+        if 'name' in section_xml.attrib:
+            section_name = section_xml.attrib['name']
+        else:
+            guid = section_xml.attrib['fdeploy_GUID']
+            sid = section_xml.attrib['fdeploy_SID']
+            section_name = guid + '_' + sid
+
+        self.ini_conf.add_section(section_name)
+        return section_name
index 544c351c31ce888d49cf5670b4ed229ba0598542..c4d1bd9a1f5afcf71a7d74badc22dadb10cd2ffe 100644 (file)
@@ -50,7 +50,7 @@ from samba.dcerpc import nbt
 from samba.net import Net
 from samba.gp_parse import GPParser, GPNoParserException
 from samba.gp_parse.gp_pol import GPPolParser
-from samba.gp_parse.gp_ini import GPIniParser, GPTIniParser
+from samba.gp_parse.gp_ini import GPIniParser, GPTIniParser, GPFDeploy1IniParser
 from samba.gp_parse.gp_csv import GPAuditCsvParser
 from samba.gp_parse.gp_inf import GptTmplInfParser
 from samba.gp_parse.gp_aas import GPAasParser
@@ -243,6 +243,8 @@ def parse_unc(unc):
 
 
 def find_parser(name, flags=re.IGNORECASE):
+    if re.match('fdeploy1\.ini$', name, flags=flags):
+        return GPFDeploy1IniParser()
     if re.match('audit\.csv$', name, flags=flags):
         return GPAuditCsvParser()
     if re.match('GptTmpl\.inf$', name, flags=flags):