From: David Mulder Date: Wed, 16 May 2018 16:58:29 +0000 (-0600) Subject: gpo: Initialize gp_ext variables in constructor X-Git-Tag: tdb-1.3.17~1418 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4354071b7a862e5e459b1be8bec9ec185e6a784f;p=thirdparty%2Fsamba.git 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 Reviewed-by: Douglas Bagnall Reviewed-by: Aurelien Aptel --- diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py index 048b25b4105..2de11e7730e 100644 --- a/python/samba/gpclass.py +++ b/python/samba/gpclass.py @@ -298,8 +298,11 @@ class GPOStorage: class gp_ext(object): __metaclass__ = ABCMeta - def __init__(self, logger): + def __init__(self, logger, lp, creds, store): self.logger = logger + self.lp = lp + self.creds = creds + self.gp_db = store.get_gplog(creds.get_username()) @abstractmethod def list(self, rootpath): @@ -313,11 +316,7 @@ class gp_ext(object): def read(self, policy): pass - def parse(self, afile, gp_db, lp, creds): - self.gp_db = gp_db - self.lp = lp - self.creds = creds - + def parse(self, afile): local_path = self.lp.cache_path('gpo_cache') data_file = os.path.join(local_path, check_safe_path(afile).upper()) if os.path.exists(data_file): @@ -483,7 +482,7 @@ def apply_gp(lp, creds, logger, store, gp_extensions): store.start() for ext in gp_extensions: try: - ext.parse(ext.list(path), gp_db, lp, creds) + ext.parse(ext.list(path)) except Exception as e: logger.error('Failed to parse gpo %s for extension %s' % (guid, str(ext))) diff --git a/source4/scripting/bin/samba-gpupdate b/source4/scripting/bin/samba-gpupdate index 648d1886cda..e69492dab8e 100755 --- a/source4/scripting/bin/samba-gpupdate +++ b/source4/scripting/bin/samba-gpupdate @@ -77,12 +77,12 @@ if __name__ == "__main__": lp.configfile) gp_extensions = [] 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: - gp_extensions.append(ext(logger)) + gp_extensions.append(ext(logger, lp, creds, store)) elif opts.target == 'User': for ext in user_exts: - gp_extensions.append(ext(logger)) + gp_extensions.append(ext(logger, lp, creds, store)) if not opts.unapply: apply_gp(lp, creds, logger, store, gp_extensions)