2 # Copyright Luke Morrison <luc785@.hotmail.com> July 2013
3 # Co-Edited by Matthieu Pattou July 2013 from original August 2013
4 # Edited by Garming Sam Feb. 2014
5 # Edited by Luke Morrison April 2014
6 # Edited by David Mulder May 2017
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 '''This script reads a log file of previous GPO, gets all GPO from sysvol
22 and sorts them by container. Then, it applies the ones that haven't been
23 applied, have changed, or is in the right container'''
28 sys.path.insert(0, "bin/python")
31 from samba import getopt as options
32 from samba.gp.gpclass import apply_gp, unapply_gp, GPOStorage, rsop
33 from samba.gp.gp_sec_ext import gp_krb_ext, gp_access_ext
34 from samba.gp.gp_ext_loader import get_gp_client_side_extensions
35 from samba.gp.gp_scripts_ext import gp_scripts_ext, gp_user_scripts_ext
36 from samba.gp.gp_sudoers_ext import gp_sudoers_ext
37 from samba.gp.vgp_sudoers_ext import vgp_sudoers_ext
38 from samba.gp.gp_smb_conf_ext import gp_smb_conf_ext
39 from samba.gp.gp_msgs_ext import gp_msgs_ext
40 from samba.gp.vgp_symlink_ext import vgp_symlink_ext
41 from samba.gp.vgp_files_ext import vgp_files_ext
42 from samba.gp.vgp_openssh_ext import vgp_openssh_ext
43 from samba.gp.vgp_motd_ext import vgp_motd_ext
44 from samba.gp.vgp_issue_ext import vgp_issue_ext
45 from samba.gp.vgp_startup_scripts_ext import vgp_startup_scripts_ext
46 from samba.gp.vgp_access_ext import vgp_access_ext
47 from samba.gp.gp_gnome_settings_ext import gp_gnome_settings_ext
48 from samba.gp.gp_cert_auto_enroll_ext import gp_cert_auto_enroll_ext
49 from samba.gp.gp_firefox_ext import gp_firefox_ext
50 from samba.gp.gp_chromium_ext import gp_chromium_ext, gp_chrome_ext
51 from samba.gp.gp_firewalld_ext import gp_firewalld_ext
52 from samba.gp.gp_centrify_sudoers_ext import gp_centrify_sudoers_ext
53 from samba.gp.gp_centrify_crontab_ext import gp_centrify_crontab_ext, \
54 gp_user_centrify_crontab_ext
55 from samba.gp.gp_drive_maps_ext import gp_drive_maps_user_ext
56 from samba.credentials import Credentials
57 from samba.gp.util.logging import logger_init
59 if __name__ == "__main__":
60 parser = optparse.OptionParser('samba-gpupdate [options]')
61 sambaopts = options.Samba3Options(parser)
63 # Get the command line options
64 parser.add_option_group(sambaopts)
65 parser.add_option_group(options.VersionOptions(parser))
66 credopts = options.CredentialsOptions(parser)
67 parser.add_option('-X', '--unapply', help='Unapply Group Policy',
69 parser.add_option('--target', default='Computer', help='{Computer | User}',
70 choices=['Computer', 'User'])
71 parser.add_option('--force', help='Reapplies all policy settings',
73 parser.add_option('--rsop', help='Print the Resultant Set of Policy',
75 parser.add_option_group(credopts)
77 # Set the options and the arguments
78 (opts, args) = parser.parse_args()
80 # Set the loadparm context
81 lp = sambaopts.get_loadparm()
83 creds = credopts.get_credentials(lp, fallback_machine=True)
84 # Apply policy to the command line specified user
85 if opts.target == 'Computer':
86 username = creds.get_username()
87 elif opts.target == 'User':
88 username = '%s\\%s' % (creds.get_domain(), creds.get_username())
89 # Always supply the machine creds for fetching the gpo list
92 creds.set_machine_account(lp)
95 logger_init('samba-gpupdate', lp.log_level())
97 cache_dir = lp.get('cache directory')
98 store = GPOStorage(os.path.join(cache_dir, 'gpo.tdb'))
100 machine_exts, user_exts = get_gp_client_side_extensions(lp.configfile)
102 if opts.target == 'Computer':
103 gp_extensions.append(gp_access_ext)
104 gp_extensions.append(gp_krb_ext)
105 gp_extensions.append(gp_scripts_ext)
106 gp_extensions.append(gp_sudoers_ext)
107 gp_extensions.append(vgp_sudoers_ext)
108 gp_extensions.append(gp_centrify_sudoers_ext)
109 gp_extensions.append(gp_centrify_crontab_ext)
110 gp_extensions.append(gp_smb_conf_ext)
111 gp_extensions.append(gp_msgs_ext)
112 gp_extensions.append(vgp_symlink_ext)
113 gp_extensions.append(vgp_files_ext)
114 gp_extensions.append(vgp_openssh_ext)
115 gp_extensions.append(vgp_motd_ext)
116 gp_extensions.append(vgp_issue_ext)
117 gp_extensions.append(vgp_startup_scripts_ext)
118 gp_extensions.append(vgp_access_ext)
119 gp_extensions.append(gp_gnome_settings_ext)
120 gp_extensions.append(gp_cert_auto_enroll_ext)
121 gp_extensions.append(gp_firefox_ext)
122 gp_extensions.append(gp_chromium_ext)
123 gp_extensions.append(gp_chrome_ext)
124 gp_extensions.append(gp_firewalld_ext)
125 gp_extensions.extend(machine_exts)
126 elif opts.target == 'User':
127 gp_extensions.append(gp_user_scripts_ext)
128 gp_extensions.append(gp_user_centrify_crontab_ext)
129 gp_extensions.append(gp_drive_maps_user_ext)
130 gp_extensions.extend(user_exts)
133 rsop(lp, creds, store, gp_extensions, username, opts.target)
134 elif not opts.unapply:
135 apply_gp(lp, creds, store, gp_extensions, username,
136 opts.target, opts.force)
138 unapply_gp(lp, creds, store, gp_extensions, username,