gpo: Apply Group Policy Message of the day
authorDavid Mulder <dmulder@suse.com>
Wed, 8 Jul 2020 21:29:42 +0000 (15:29 -0600)
committerDavid Mulder <dmulder@samba.org>
Thu, 27 Aug 2020 15:59:34 +0000 (15:59 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
libgpo/admx/en-US/samba.adml
libgpo/admx/samba.admx
python/samba/gp_msgs_ext.py
selftest/knownfail
source4/scripting/bin/samba-gpupdate

index 2f612f0658e8248be5ede9fb5cef40a96f04ca74..fc0ec31c3ccdcea9855f609735108b799da9a7b6 100755 (executable)
@@ -3084,6 +3084,9 @@ Example: 192.9.200.1 192.168.2.61</string>
       <string id="POL_F19C445A_AFD5_51B6_B87A_E42499C3C5D8_Help">This is the interval in s till tombstone records are deleted from the WINS database. Defaults to 1 day.</string>\r
       <string id="POL_8CF1FEA3_BD3E_53C0_9F73_34050187A91E">wreplsrv:verify_interval</string>\r
       <string id="POL_8CF1FEA3_BD3E_53C0_9F73_34050187A91E_Help">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.</string>\r
+      <string id="CAT_9DEF582D_447A_47E9_A1F5_363558D03FA9">Messages</string>\r
+      <string id="POL_38DA04F0_3FD6_4425_8924_1CEEA685FD07">Message of the day</string>\r
+      <string id="POL_38DA04F0_3FD6_4425_8924_1CEEA685FD07_Help">       The contents of /etc/motd are displayed after a successful login but just before it executes the login shell.</string>\r
     </stringTable>\r
     <presentationTable>\r
       <presentation id="POL_9320E11F_AC80_4A7D_A5C8_1C0F3F727061">\r
@@ -4591,6 +4594,11 @@ Example: 192.9.200.1 192.168.2.61</string>
           <defaultValue>2073600</defaultValue>\r
         </textBox>\r
       </presentation>\r
+      <presentation id="POL_38DA04F0_3FD6_4425_8924_1CEEA685FD07">\r
+        <textBox refId="TXT_609C208A_3B4D_48F1_8A15_C0DF08EAD4D6">\r
+          <label>Message of the day</label>\r
+        </textBox>\r
+      </presentation>\r
     </presentationTable>\r
   </resources>\r
 </policyDefinitionResources>\r
index c5c5586610dbb9af6a18716af12ca97c2041c867..f63c250d1c236734489355138ccb327419ac52dc 100755 (executable)
@@ -14,6 +14,9 @@
     <category name="CAT_2B6D622C_5721_4C23_A2D6_5C70D6E059BA" displayName="$(string.CAT_2B6D622C_5721_4C23_A2D6_5C70D6E059BA)">\r
       <parentCategory ref="CAT_7D8D7DC8_5A9D_4BE1_8227_F09CDD5AFFC6" />\r
     </category>\r
+    <category name="CAT_9DEF582D_447A_47E9_A1F5_363558D03FA9" displayName="$(string.CAT_9DEF582D_447A_47E9_A1F5_363558D03FA9)">\r
+      <parentCategory ref="CAT_7D8D7DC8_5A9D_4BE1_8227_F09CDD5AFFC6" />\r
+    </category>\r
     <category displayName="$(string.CAT_10827749_64ED_5052_87F7_E81AD421856A)" name="CAT_10827749_64ED_5052_87F7_E81AD421856A">\r
       <parentCategory ref="CAT_3338C1DD_8A00_4273_8547_158D8B8C19E9"/>\r
     </category>\r
         <text id="TXT_F35F7924_DBD3_5F6F_B247_7F4893C63844" key="Software\Policies\Samba\smb_conf\wreplsrv:verify_interval" valueName="wreplsrv:verify_interval"/>\r
       </elements>\r
     </policy>\r
+    <policy name="POL_38DA04F0_3FD6_4425_8924_1CEEA685FD07" class="Machine" displayName="$(string.POL_38DA04F0_3FD6_4425_8924_1CEEA685FD07)" explainText="$(string.POL_38DA04F0_3FD6_4425_8924_1CEEA685FD07_Help)" presentation="$(presentation.POL_38DA04F0_3FD6_4425_8924_1CEEA685FD07)" key="Software\Policies\Samba\Unix Settings\Messages">\r
+      <parentCategory ref="CAT_9DEF582D_447A_47E9_A1F5_363558D03FA9" />\r
+      <supportedOn ref="windows:SUPPORTED_WindowsVista" />\r
+      <elements>\r
+        <text id="TXT_609C208A_3B4D_48F1_8A15_C0DF08EAD4D6" key="Software\Policies\Samba\Unix Settings\Messages" valueName="motd" />\r
+      </elements>\r
+    </policy>\r
   </policies>\r
 </policyDefinitions>\r
index ac6edccdc18db7349cd210932b25699b28777281..aa03cc35dbcad7df8f2f5e2c6f574361fb6c4a37 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+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()
index 81299f63cd628c165b7fc1b17ab8ce274bcc3388..6c005d1f4deb7afc6db6269b44e5d59870d5710a 100644 (file)
 ^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
index d14bca4944b28e9e915154a460042237b974b4a8..44292ec644fc97112c7054103592f32226137f37 100755 (executable)
@@ -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)