Skip to content

Commit

Permalink
gpo: Create a function for returning applied settings
Browse files Browse the repository at this point in the history
This returns a list of guids for gpos applied
plus settings applied and their previous values.

Signed-off-by: David Mulder <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
Reviewed-by: Aurelien Aptel <[email protected]>
  • Loading branch information
dmulder authored and Aurélien Aptel committed Oct 8, 2018
1 parent 8a21ae6 commit cc02de6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions python/samba/gpclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,45 @@ def list(self, gp_extensions):
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
Expand Down

0 comments on commit cc02de6

Please sign in to comment.