gpo: Create a function for returning applied settings
authorDavid Mulder <dmulder@suse.com>
Thu, 17 May 2018 21:56:15 +0000 (15:56 -0600)
committerAurélien Aptel <aaptel@samba.org>
Mon, 8 Oct 2018 16:17:15 +0000 (18:17 +0200)
This returns a list of guids for gpos applied
plus settings applied and their previous values.

Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
python/samba/gpclass.py

index f312f9f95a905300cbe2c2fca1a498f7882d9b0a..85fdb88eafa6f2b2aaf07c37fc4781541ca5655c 100644 (file)
@@ -235,6 +235,45 @@ class gp_log:
                     ret.append((attr.attrib['name'], attr.text, func))
         return ret
 
+    def get_applied_guids(self):
+        ''' Return a list of applied ext guids
+        return              - List of guids for gpos that have applied settings
+                              to the system.
+        '''
+        guids = []
+        user_obj = self.gpdb.find('user[@name="%s"]' % self.user)
+        if user_obj is not None:
+            apply_log = user_obj.find('applylog')
+            if apply_log is None:
+                return guids
+            for i in reversed(range(0, len(apply_log))):
+                guid_obj = apply_log.find('guid[@count="%d"]' % i)
+                guid = guid_obj.attrib['value']
+                guids.append(guid)
+        return guids
+
+    def get_applied_settings(self, guids):
+        ''' Return a list of applied ext guids
+        return              - List of tuples containing the guid of a gpo, then
+                              a dictionary of policies and their values prior
+                              policy application. These are sorted so that the
+                              most recently applied settings are removed first.
+        '''
+        ret = []
+        user_obj = self.gpdb.find('user[@name="%s"]' % self.user)
+        for guid in guids:
+            guid_settings = user_obj.find('guid[@value="%s"]' % guid)
+            exts = guid_settings.findall('gp_ext')
+            settings = {}
+            for ext in exts:
+                attr_dict = {}
+                attrs = ext.findall('attribute')
+                for attr in attrs:
+                    attr_dict[attr.attrib['name']] = attr.text
+                settings[ext.attrib['name']] = attr_dict
+            ret.append((guid, settings))
+        return ret
+
     def delete(self, gp_ext_name, attribute):
         ''' Remove an attribute from the gp_log
         param gp_ext_name   - name of extension from which to remove the