From: David Mulder Date: Wed, 8 Jul 2020 21:29:42 +0000 (-0600) Subject: gpo: Apply Group Policy Message of the day X-Git-Tag: talloc-2.3.2~692 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4f598fde8cfa564613108397b0a645277cf0ace;p=thirdparty%2Fsamba.git gpo: Apply Group Policy Message of the day Signed-off-by: David Mulder Reviewed-by: Douglas Bagnall --- diff --git a/libgpo/admx/en-US/samba.adml b/libgpo/admx/en-US/samba.adml index 2f612f0658e..fc0ec31c3cc 100755 --- a/libgpo/admx/en-US/samba.adml +++ b/libgpo/admx/en-US/samba.adml @@ -3084,6 +3084,9 @@ Example: 192.9.200.1 192.168.2.61 This is the interval in s till tombstone records are deleted from the WINS database. Defaults to 1 day. wreplsrv:verify_interval This is the interval in s till we verify active replica records with the owning WINS server. Unfortunately not implemented yet. Defaults to 24 days. + Messages + Message of the day + The contents of /etc/motd are displayed after a successful login but just before it executes the login shell. @@ -4591,6 +4594,11 @@ Example: 192.9.200.1 192.168.2.61 2073600 + + + + + diff --git a/libgpo/admx/samba.admx b/libgpo/admx/samba.admx index c5c5586610d..f63c250d1c2 100755 --- a/libgpo/admx/samba.admx +++ b/libgpo/admx/samba.admx @@ -14,6 +14,9 @@ + + + @@ -2511,5 +2514,12 @@ + + + + + + + diff --git a/python/samba/gp_msgs_ext.py b/python/samba/gp_msgs_ext.py index ac6edccdc18..aa03cc35dbc 100644 --- a/python/samba/gp_msgs_ext.py +++ b/python/samba/gp_msgs_ext.py @@ -14,9 +14,51 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os from samba.gpclass import gp_pol_ext class gp_msgs_ext(gp_pol_ext): + def __str__(self): + return 'Unix Settings/Messages' + def process_group_policy(self, deleted_gpo_list, changed_gpo_list, cdir='/etc'): - pass + for guid, settings in deleted_gpo_list: + self.gp_db.set_guid(guid) + if str(self) in settings: + for attribute, msg in settings[str(self)].items(): + if attribute == 'motd': + mfile = os.path.join(cdir, 'motd') + else: + continue + with open(mfile, 'w') as w: + if msg: + w.write(msg) + else: + w.truncate() + self.gp_db.delete(str(self), attribute) + self.gp_db.commit() + + for gpo in changed_gpo_list: + if gpo.file_sys_path: + section_name = 'Software\\Policies\\Samba\\Unix Settings\\Messages' + self.gp_db.set_guid(gpo.name) + pol_file = 'MACHINE/Registry.pol' + path = os.path.join(gpo.file_sys_path, pol_file) + pol_conf = self.parse(path) + if not pol_conf: + continue + for e in pol_conf.entries: + if e.keyname == section_name and e.data.strip(): + if e.valuename == 'motd': + mfile = os.path.join(cdir, 'motd') + else: + continue + if os.path.exists(mfile): + old_val = open(mfile, 'r').read() + else: + old_val = '' + with open(mfile, 'w') as w: + w.write(e.data) + self.gp_db.store(str(self), e.valuename, old_val) + self.gp_db.commit() diff --git a/selftest/knownfail b/selftest/knownfail index 81299f63cd6..6c005d1f4de 100644 --- a/selftest/knownfail +++ b/selftest/knownfail @@ -396,4 +396,3 @@ ^samba.tests.ntlmdisabled.python\(ktest\).python2.ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\) ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).python3.ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\) ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).python2.ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\) -^samba.tests.gpo.samba.tests.gpo.GPOTests.test_gp_motd diff --git a/source4/scripting/bin/samba-gpupdate b/source4/scripting/bin/samba-gpupdate index d14bca4944b..44292ec644f 100755 --- a/source4/scripting/bin/samba-gpupdate +++ b/source4/scripting/bin/samba-gpupdate @@ -35,6 +35,7 @@ from samba.gp_ext_loader import get_gp_client_side_extensions from samba.gp_scripts_ext import gp_scripts_ext from samba.gp_sudoers_ext import gp_sudoers_ext from samba.gp_smb_conf_ext import gp_smb_conf_ext +from samba.gp_msgs_ext import gp_msgs_ext import logging if __name__ == "__main__": @@ -89,6 +90,7 @@ if __name__ == "__main__": gp_extensions.append(gp_scripts_ext) gp_extensions.append(gp_sudoers_ext) gp_extensions.append(gp_smb_conf_ext) + gp_extensions.append(gp_msgs_ext) gp_extensions.extend(machine_exts) elif opts.target == 'User': gp_extensions.extend(user_exts)