From: David Mulder Date: Wed, 16 May 2018 16:37:09 +0000 (-0600) Subject: gpo: Offline policy application via cache X-Git-Tag: ldb-1.5.0~313 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2412c70481fe22fb9e266e6ef1a1cd86fb39a1e5;p=thirdparty%2Fsamba.git gpo: Offline policy application via cache Read policy files from the cache, rather than the sysvol. This enables offline policy apply. Signed-off-by: David Mulder Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py index 086656d8785..a14d3ab3d88 100644 --- a/python/samba/gpclass.py +++ b/python/samba/gpclass.py @@ -307,32 +307,16 @@ class gp_ext(object): def read(self, policy): pass - def parse(self, afile, ldb, conn, gp_db, lp): + def parse(self, afile, ldb, gp_db, lp): self.ldb = ldb self.gp_db = gp_db self.lp = lp - # Fixing the bug where only some Linux Boxes capitalize MACHINE - try: - blist = afile.split('/') - idx = afile.lower().split('/').index('machine') - for case in [ - blist[idx].upper(), - blist[idx].capitalize(), - blist[idx].lower() - ]: - bfile = '/'.join(blist[:idx]) + '/' + case + '/' + \ - '/'.join(blist[idx+1:]) - try: - return self.read(conn.loadfile(bfile.replace('/', '\\'))) - except NTSTATUSError: - continue - except ValueError: - try: - return self.read(conn.loadfile(afile.replace('/', '\\'))) - except Exception as e: - self.logger.error(str(e)) - return None + 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): + return self.read(open(data_file, 'r').read()) + return None @abstractmethod def __str__(self): @@ -471,11 +455,6 @@ def gpo_version(lp, path): def apply_gp(lp, creds, test_ldb, logger, store, gp_extensions): gp_db = store.get_gplog(creds.get_username()) dc_hostname = get_dc_hostname(creds, lp) - try: - conn = smb.SMB(dc_hostname, 'sysvol', lp=lp, creds=creds) - except: - logger.error('Error connecting to \'%s\' using SMB' % dc_hostname) - raise gpos = get_gpo_list(dc_hostname, creds, lp) try: check_refresh_gpo_list(dc_hostname, lp, creds, gpos) @@ -499,7 +478,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, conn, gp_db, lp) + ext.parse(ext.list(path), test_ldb, gp_db, lp) except Exception as e: logger.error('Failed to parse gpo %s for extension %s' % \ (guid, str(ext)))