From: Garming Sam Date: Wed, 20 Feb 2019 03:51:04 +0000 (+1300) Subject: gpo: Restore gPCMachineExtensionNames and gPCUserExtensionNames X-Git-Tag: talloc-2.2.0~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f301b20e3752e9316561bb5761962639fda2bf60;p=thirdparty%2Fsamba.git 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 Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index ae06594e719..b082b34302d 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -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()