gpo: avoid quadratic behaviour in guid retrieval
[nivanova/samba-autobuild/.git] / python / samba / gp_sec_ext.py
index 2dc34e678633bb89c97d75350b7d12e187343922..55f71b745658e74546624248905d483c2b48c59b 100644 (file)
@@ -135,13 +135,7 @@ class gp_sec_ext(gp_inf_ext):
     def __str__(self):
         return "Security GPO extension"
 
-    def list(self, rootpath):
-        return os.path.join(rootpath,
-                            "MACHINE/Microsoft/Windows NT/SecEdit/GptTmpl.inf")
-
     def apply_map(self):
-        if self.lp.get('server role') != 'active directory domain controller':
-            return {}
         return {"System Access": {"MinimumPasswordAge": ("minPwdAge",
                                                          inf_to_ldb),
                                   "MaximumPasswordAge": ("maxPwdAge",
@@ -170,10 +164,24 @@ class gp_sec_ext(gp_inf_ext):
         if self.lp.get('server role') != 'active directory domain controller':
             return
         inf_file = 'MACHINE/Microsoft/Windows NT/SecEdit/GptTmpl.inf'
+        apply_map = self.apply_map()
 
         for gpo in changed_gpo_list:
             if gpo.file_sys_path:
                 self.gp_db.set_guid(gpo.name)
                 path = os.path.join(gpo.file_sys_path, inf_file)
-                self.parse(path)
+                inf_conf = self.parse(path)
+                if not inf_conf:
+                    continue
+                for section in inf_conf.sections():
+                    current_section = apply_map.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')
+                            setter(self.logger, self.gp_db, self.lp,
+                                   self.creds, att, value).update_samba()
+                            self.gp_db.commit()