From: David Mulder Date: Wed, 16 May 2018 15:54:38 +0000 (-0600) Subject: gpupdate: Add the --force option X-Git-Tag: tdb-1.3.17~1405 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e98d18bea527cc6314469d438fe9e44e2a47765;p=thirdparty%2Fsamba.git gpupdate: Add the --force option This option forces the reapplication of policy, and works the same as MS 'gpupdate /force' 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 95938044c17..c3941cf703a 100644 --- a/python/samba/gpclass.py +++ b/python/samba/gpclass.py @@ -427,7 +427,7 @@ def gpo_version(lp, path): return int(gpo.gpo_get_sysvol_gpt_version(gpt_path)[1]) -def apply_gp(lp, creds, logger, store, gp_extensions): +def apply_gp(lp, creds, logger, store, gp_extensions, force=False): gp_db = store.get_gplog(creds.get_username()) dc_hostname = get_dc_hostname(creds, lp) gpos = get_gpo_list(dc_hostname, creds, lp) @@ -439,16 +439,21 @@ def apply_gp(lp, creds, logger, store, gp_extensions): % dc_hostname) return - changed_gpos = [] - for gpo_obj in gpos: - if not gpo_obj.file_sys_path: - continue - guid = gpo_obj.name - path = check_safe_path(gpo_obj.file_sys_path).upper() - version = gpo_version(lp, path) - if version != store.get_int(guid): - logger.info('GPO %s has changed' % guid) - changed_gpos.append(gpo_obj) + if force: + changed_gpos = gpos + gp_db.state(GPOSTATE.ENFORCE) + else: + changed_gpos = [] + for gpo_obj in gpos: + if not gpo_obj.file_sys_path: + continue + guid = gpo_obj.name + path = check_safe_path(gpo_obj.file_sys_path).upper() + version = gpo_version(lp, path) + if version != store.get_int(guid): + logger.info('GPO %s has changed' % guid) + changed_gpos.append(gpo_obj) + gp_db.state(GPOSTATE.APPLY) store.start() for ext in gp_extensions: diff --git a/source4/scripting/bin/samba-gpupdate b/source4/scripting/bin/samba-gpupdate index e69492dab8e..bc350c47c69 100755 --- a/source4/scripting/bin/samba-gpupdate +++ b/source4/scripting/bin/samba-gpupdate @@ -46,6 +46,8 @@ if __name__ == "__main__": action='store_true') parser.add_option('--target', default='Computer', help='{Computer | User}', choices=['Computer', 'User']) + parser.add_option('--force', help='Reapplies all policy settings', + action='store_true') parser.add_option_group(credopts) # Set the options and the arguments @@ -85,7 +87,7 @@ if __name__ == "__main__": gp_extensions.append(ext(logger, lp, creds, store)) if not opts.unapply: - apply_gp(lp, creds, logger, store, gp_extensions) + apply_gp(lp, creds, logger, store, gp_extensions, opts.force) else: unapply_gp(lp, creds, logger, store, gp_extensions)