gpo: Apply Group Policy Hourly Scripts
authorDavid Mulder <dmulder@suse.com>
Thu, 25 Jun 2020 20:14:09 +0000 (14:14 -0600)
committerDavid Mulder <dmulder@samba.org>
Thu, 6 Aug 2020 16:38:35 +0000 (16:38 +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_scripts_ext.py
selftest/knownfail.d/gpo [deleted file]

index b5fc50986381de4b6bf722cd54c1343d0f6bcd10..55dae86199dec118314fd668398f888cbde26b68 100755 (executable)
@@ -8,12 +8,17 @@
       <string id="CAT_3338C1DD_8A00_4273_8547_158D8B8C19E9">Samba</string>\r
       <string id="CAT_7D8D7DC8_5A9D_4BE1_8227_F09CDD5AFFC6">Unix Settings</string>\r
       <string id="POL_9320E11F_AC80_4A7D_A5C8_1C0F3F727061">Daily Scripts</string>\r
+      <string id="POL_825D441F_905E_4C7E_9E4B_03013697C6C1">Hourly Scripts</string>\r
       <string id="POL_9320E11F_AC80_4A7D_A5C8_1C0F3F727061_Help">This policy setting allows you to execute commands, either local or on remote storage, daily.</string>\r
+      <string id="POL_825D441F_905E_4C7E_9E4B_03013697C6C1_Help">This policy setting allows you to execute commands, either local or on remote storage, hourly.</string>\r
     </stringTable>\r
     <presentationTable>\r
       <presentation id="POL_9320E11F_AC80_4A7D_A5C8_1C0F3F727061">\r
         <listBox refId="LST_2E9A4684_3C0E_415B_8FD6_D4AF68BC8AC6">Script and arguments</listBox>\r
       </presentation>\r
+      <presentation id="POL_825D441F_905E_4C7E_9E4B_03013697C6C1">\r
+        <listBox refId="LST_1AA93D59_6372_4F1E_90BB_D4CBBBB77238">Script and arguments</listBox>\r
+      </presentation>\r
     </presentationTable>\r
   </resources>\r
 </policyDefinitionResources>\r
index f2921ff188506aa51bd3e6d149aed8c9d75716fb..1a67bddf809882fcecaa12553c8708e5bfe0a202 100755 (executable)
         <list id="LST_2E9A4684_3C0E_415B_8FD6_D4AF68BC8AC6" key="Software\Policies\Samba\Unix Settings\Daily Scripts" valueName="Daily Scripts" />\r
       </elements>\r
     </policy>\r
+    <policy name="POL_825D441F_905E_4C7E_9E4B_03013697C6C1" class="Machine" displayName="$(string.POL_825D441F_905E_4C7E_9E4B_03013697C6C1)" explainText="$(string.POL_825D441F_905E_4C7E_9E4B_03013697C6C1_Help)" presentation="$(presentation.POL_825D441F_905E_4C7E_9E4B_03013697C6C1)" key="Software\Policies\Samba\Unix Settings">\r
+      <parentCategory ref="CAT_7D8D7DC8_5A9D_4BE1_8227_F09CDD5AFFC6" />\r
+      <supportedOn ref="windows:SUPPORTED_WindowsVista" />\r
+      <elements>\r
+        <list id="LST_1AA93D59_6372_4F1E_90BB_D4CBBBB77238" key="Software\Policies\Samba\Unix Settings\Hourly Scripts" valueName="Hourly Scripts" />\r
+      </elements>\r
+    </policy>\r
   </policies>\r
 </policyDefinitions>\r
index f83f367a5d72377c08b4614176046719df26c056..93a5ef778cbd352e9c9e821a0a94f664728ebe9d 100644 (file)
@@ -21,9 +21,9 @@ from tempfile import NamedTemporaryFile
 
 class gp_scripts_ext(gp_pol_ext):
     def __str__(self):
-        return 'Unix Settings/Daily Scripts'
+        return 'Unix Settings/Scripts'
 
-    def process_group_policy(self, deleted_gpo_list, changed_gpo_list, cdir='/etc/cron.daily'):
+    def process_group_policy(self, deleted_gpo_list, changed_gpo_list, cdir=None):
         for gpo in deleted_gpo_list:
             self.gp_db.set_guid(gpo[0])
             if str(self) in gpo[1]:
@@ -34,7 +34,9 @@ class gp_scripts_ext(gp_pol_ext):
 
         for gpo in changed_gpo_list:
             if gpo.file_sys_path:
-                section_name = 'Software\\Policies\\Samba\\Unix Settings\\Daily Scripts'
+                reg_key = 'Software\\Policies\\Samba\\Unix Settings'
+                sections = { '%s\\Daily Scripts' % reg_key : '/etc/cron.daily',
+                             '%s\\Hourly Scripts' % reg_key : '/etc/cron.hourly' }
                 self.gp_db.set_guid(gpo.name)
                 pol_file = 'MACHINE/Registry.pol'
                 path = os.path.join(gpo.file_sys_path, pol_file)
@@ -42,11 +44,14 @@ class gp_scripts_ext(gp_pol_ext):
                 if not pol_conf:
                     continue
                 for e in pol_conf.entries:
-                    if e.keyname == section_name and e.data.strip():
-                        attribute = b64encode(e.data.encode()).decode()
+                    if e.keyname in sections.keys() and e.data.strip():
+                        cron_dir = sections[e.keyname] if not cdir else cdir
+                        attribute = '%s:%s' % (e.keyname,
+                                b64encode(e.data.encode()).decode())
                         old_val = self.gp_db.retrieve(str(self), attribute)
                         if not old_val:
-                            with NamedTemporaryFile(mode="w+", delete=False, dir=cdir) as f:
+                            with NamedTemporaryFile(mode="w+", delete=False,
+                                    dir=cron_dir) as f:
                                 f.write('#!/bin/sh\n%s' % e.data)
                                 os.chmod(f.name, 0o700)
                                 self.gp_db.store(str(self), attribute, f.name)
diff --git a/selftest/knownfail.d/gpo b/selftest/knownfail.d/gpo
deleted file mode 100644 (file)
index 27f3459..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba.tests.gpo.samba.tests.gpo.GPOTests.test_gp_scripts