]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
gpo: Initialize SamDB in the gp_sec_ext
authorDavid Mulder <dmulder@suse.com>
Fri, 13 Jul 2018 20:45:06 +0000 (14:45 -0600)
committerAurélien Aptel <aaptel@samba.org>
Mon, 8 Oct 2018 16:17:14 +0000 (18:17 +0200)
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 <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
python/samba/gpclass.py

index db388fa9755e99e3c149f8fdb3b24b1f0b0298b1..048b25b410540c831f56d178ac459076dd9fa89d 100644 (file)
@@ -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()