From: David Mulder Date: Fri, 13 Jul 2018 20:45:06 +0000 (-0600) Subject: gpo: Initialize SamDB in the gp_sec_ext X-Git-Tag: tdb-1.3.17~1421 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5dddb784f8214e2b6753b7544cf4cb9eb3829a90;p=thirdparty%2Fsamba.git gpo: Initialize SamDB in the gp_sec_ext The SamDB is only used by the gp_sec_ext, and isn't needed elsewhere, so initialize it where we need it and avoid passing it around everywhere. It makes the most sense to put this in the setter class that uses it, so pass our creds down so we have access to it, then initialize it there. 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 db388fa9755..048b25b4105 100644 --- a/python/samba/gpclass.py +++ b/python/samba/gpclass.py @@ -313,10 +313,10 @@ class gp_ext(object): def read(self, policy): pass - def parse(self, afile, ldb, gp_db, lp): - self.ldb = ldb + def parse(self, afile, gp_db, lp, creds): self.gp_db = gp_db self.lp = lp + self.creds = creds local_path = self.lp.cache_path('gpo_cache') data_file = os.path.join(local_path, check_safe_path(afile).upper()) @@ -329,15 +329,15 @@ class gp_ext(object): pass -class gp_ext_setter(): +class gp_ext_setter(object): __metaclass__ = ABCMeta - def __init__(self, logger, ldb, gp_db, lp, attribute, val): + def __init__(self, logger, gp_db, lp, creds, attribute, val): self.logger = logger - self.ldb = ldb self.attribute = attribute self.val = val self.lp = lp + self.creds = creds self.gp_db = gp_db def explicit(self): @@ -385,8 +385,8 @@ class gp_inf_ext(gp_ext): (att, setter) = current_section.get(key) value = value.encode('ascii', 'ignore') ret = True - setter(self.logger, self.ldb, self.gp_db, self.lp, att, - value).update_samba() + setter(self.logger, self.gp_db, self.lp, + self.creds, att, value).update_samba() self.gp_db.commit() return ret @@ -457,7 +457,7 @@ def gpo_version(lp, path): return int(gpo.gpo_get_sysvol_gpt_version(gpt_path)[1]) -def apply_gp(lp, creds, test_ldb, logger, store, gp_extensions): +def apply_gp(lp, creds, logger, store, gp_extensions): gp_db = store.get_gplog(creds.get_username()) dc_hostname = get_dc_hostname(creds, lp) gpos = get_gpo_list(dc_hostname, creds, lp) @@ -483,7 +483,7 @@ def apply_gp(lp, creds, test_ldb, logger, store, gp_extensions): store.start() for ext in gp_extensions: try: - ext.parse(ext.list(path), test_ldb, gp_db, lp) + ext.parse(ext.list(path), gp_db, lp, creds) except Exception as e: logger.error('Failed to parse gpo %s for extension %s' % (guid, str(ext))) @@ -503,14 +503,14 @@ def unapply_log(gp_db): break -def unapply_gp(lp, creds, test_ldb, logger, store, gp_extensions): +def unapply_gp(lp, creds, logger, store, gp_extensions): gp_db = store.get_gplog(creds.get_username()) gp_db.state(GPOSTATE.UNAPPLY) for gpo_guid in unapply_log(gp_db): gp_db.set_guid(gpo_guid) unapply_attributes = gp_db.list(gp_extensions) for attr in unapply_attributes: - attr_obj = attr[-1](logger, test_ldb, gp_db, lp, attr[0], attr[1]) + attr_obj = attr[-1](logger, gp_db, lp, attr[0], attr[1]) attr_obj.mapper()[attr[0]][0](attr[1]) # Set the old value gp_db.delete(str(attr_obj), attr[0]) gp_db.commit()