gpo: Implement process_group_policy() gp_ext func
[nivanova/samba-autobuild/.git] / python / samba / gpclass.py
index 2de11e7730ed661a2f17547cc95f2b1e8cc3894b..07b8b217084c777388fe15999ded834e6899129a 100644 (file)
@@ -308,6 +308,10 @@ class gp_ext(object):
     def list(self, rootpath):
         pass
 
+    @abstractmethod
+    def process_group_policy(self, deleted_gpo_list, changed_gpo_list):
+        pass
+
     @abstractmethod
     def apply_map(self):
         pass
@@ -467,30 +471,33 @@ def apply_gp(lp, creds, logger, store, gp_extensions):
                      % dc_hostname)
         return
 
+    changed_gpos = []
     for gpo_obj in gpos:
-        guid = gpo_obj.name
-        if guid == 'Local Policy':
+        if not gpo_obj.file_sys_path:
             continue
-        path = os.path.join(lp.get('realm'), 'Policies', guid).upper()
+        guid = gpo_obj.name
+        path = check_safe_path(gpo_obj.file_sys_path).upper()
         version = gpo_version(lp, path)
         if version != store.get_int(guid):
             logger.info('GPO %s has changed' % guid)
-            gp_db.state(GPOSTATE.APPLY)
-        else:
-            gp_db.state(GPOSTATE.ENFORCE)
-        gp_db.set_guid(guid)
-        store.start()
-        for ext in gp_extensions:
-            try:
-                ext.parse(ext.list(path))
-            except Exception as e:
-                logger.error('Failed to parse gpo %s for extension %s' %
-                             (guid, str(ext)))
-                logger.error('Message was: ' + str(e))
-                store.cancel()
-                continue
+            changed_gpos.append(gpo_obj)
+
+    store.start()
+    for ext in gp_extensions:
+        try:
+            ext.process_group_policy([], changed_gpos)
+        except Exception as e:
+            logger.error('Failed to apply extension  %s' % str(ext))
+            logger.error('Message was: ' + str(e))
+            continue
+    for gpo_obj in gpos:
+        if not gpo_obj.file_sys_path:
+            continue
+        guid = gpo_obj.name
+        path = check_safe_path(gpo_obj.file_sys_path).upper()
+        version = gpo_version(lp, path)
         store.store(guid, '%i' % version)
-        store.commit()
+    store.commit()
 
 
 def unapply_log(gp_db):