mirror of
https://github.com/samba-team/samba.git
synced 2025-12-20 16:23:51 +03:00
gpo: Restore gPCMachineExtensionNames and gPCUserExtensionNames
After creating a backup and calling 'gpo restore', this makes it so that restoring a GPO will instantly enable it for use. There might be some cases where we might not want to do this, but for now just do it. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13627 Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
committed by
Andrew Bartlett
parent
2e231541b4
commit
f301b20e37
@@ -171,7 +171,9 @@ def get_gpo_info(samdb, gpo=None, displayname=None, dn=None,
|
||||
'flags',
|
||||
'name',
|
||||
'displayName',
|
||||
'gPCFileSysPath'],
|
||||
'gPCFileSysPath',
|
||||
'gPCMachineExtensionNames',
|
||||
'gPCUserExtensionNames'],
|
||||
controls=['sd_flags:1:%d' % sd_flags])
|
||||
except Exception as e:
|
||||
if gpo is not None:
|
||||
@@ -1076,6 +1078,12 @@ class cmd_backup(GPOCommand):
|
||||
self.outf.write('\nEntities:\n')
|
||||
self.outf.write(ents)
|
||||
|
||||
# Backup the enabled GPO extension names
|
||||
for ext in ('gPCMachineExtensionNames', 'gPCUserExtensionNames'):
|
||||
if ext in msg:
|
||||
with open(os.path.join(gpodir, ext + '.SAMBAEXT'), 'wb') as f:
|
||||
f.write(msg[ext][0])
|
||||
|
||||
@staticmethod
|
||||
def generalize_xml_entities(outf, sourcedir, targetdir):
|
||||
entities = {}
|
||||
@@ -1402,6 +1410,22 @@ class cmd_restore(cmd_create):
|
||||
self.sharepath,
|
||||
ignore_existing=True)
|
||||
|
||||
gpo_dn = get_gpo_dn(self.samdb, self.gpo_name)
|
||||
|
||||
# Restore the enabled extensions
|
||||
for ext in ('gPCMachineExtensionNames', 'gPCUserExtensionNames'):
|
||||
ext_file = os.path.join(backup, ext + '.SAMBAEXT')
|
||||
if os.path.exists(ext_file):
|
||||
with open(ext_file, 'rb') as f:
|
||||
data = f.read()
|
||||
|
||||
m = ldb.Message()
|
||||
m.dn = gpo_dn
|
||||
m[ext] = ldb.MessageElement(data, ldb.FLAG_MOD_REPLACE,
|
||||
ext)
|
||||
|
||||
self.samdb.modify(m)
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
Reference in New Issue
Block a user