From: David Mulder Date: Thu, 17 May 2018 21:56:15 +0000 (-0600) Subject: gpo: Create a function for returning applied settings X-Git-Tag: tdb-1.3.17~1411 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc02de6bfa53af09140a59023f63c2d8bf221ff4;p=thirdparty%2Fsamba.git gpo: Create a function for returning applied settings This returns a list of guids for gpos applied plus settings applied and their previous values. Signed-off-by: David Mulder Reviewed-by: Douglas Bagnall Reviewed-by: Aurelien Aptel --- diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py index f312f9f95a9..85fdb88eafa 100644 --- a/python/samba/gpclass.py +++ b/python/samba/gpclass.py @@ -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