1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

gpo: Initialize gp_ext variables in constructor

Initialize variables for the gp_ext in the
constructor instead of passing them via the parse
function.
This is a dependency of the "gpo: Implement
process_group_policy() gp_ext func" patch, since
the parse() function is now called by the ext,
instead of by gpupdate within apply_gp(). The
parse() function should only take the path
variable, to simplify writing Client Side
Extensions.

Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
This commit is contained in:
David Mulder 2018-05-16 10:58:29 -06:00 committed by Aurélien Aptel
parent f702ad943e
commit 4354071b7a
2 changed files with 9 additions and 10 deletions

View File

@ -298,8 +298,11 @@ class GPOStorage:
class gp_ext(object): class gp_ext(object):
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
def __init__(self, logger): def __init__(self, logger, lp, creds, store):
self.logger = logger self.logger = logger
self.lp = lp
self.creds = creds
self.gp_db = store.get_gplog(creds.get_username())
@abstractmethod @abstractmethod
def list(self, rootpath): def list(self, rootpath):
@ -313,11 +316,7 @@ class gp_ext(object):
def read(self, policy): def read(self, policy):
pass pass
def parse(self, afile, gp_db, lp, creds): def parse(self, afile):
self.gp_db = gp_db
self.lp = lp
self.creds = creds
local_path = self.lp.cache_path('gpo_cache') local_path = self.lp.cache_path('gpo_cache')
data_file = os.path.join(local_path, check_safe_path(afile).upper()) data_file = os.path.join(local_path, check_safe_path(afile).upper())
if os.path.exists(data_file): if os.path.exists(data_file):
@ -483,7 +482,7 @@ def apply_gp(lp, creds, logger, store, gp_extensions):
store.start() store.start()
for ext in gp_extensions: for ext in gp_extensions:
try: try:
ext.parse(ext.list(path), gp_db, lp, creds) ext.parse(ext.list(path))
except Exception as e: except Exception as e:
logger.error('Failed to parse gpo %s for extension %s' % logger.error('Failed to parse gpo %s for extension %s' %
(guid, str(ext))) (guid, str(ext)))

View File

@ -77,12 +77,12 @@ if __name__ == "__main__":
lp.configfile) lp.configfile)
gp_extensions = [] gp_extensions = []
if opts.target == 'Computer': if opts.target == 'Computer':
gp_extensions.append(gp_sec_ext(logger)) gp_extensions.append(gp_sec_ext(logger, lp, creds, store))
for ext in machine_exts: for ext in machine_exts:
gp_extensions.append(ext(logger)) gp_extensions.append(ext(logger, lp, creds, store))
elif opts.target == 'User': elif opts.target == 'User':
for ext in user_exts: for ext in user_exts:
gp_extensions.append(ext(logger)) gp_extensions.append(ext(logger, lp, creds, store))
if not opts.unapply: if not opts.unapply:
apply_gp(lp, creds, logger, store, gp_extensions) apply_gp(lp, creds, logger, store, gp_extensions)