]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: Test gpo Sudoers remove command
authorDavid Mulder <dmulder@suse.com>
Mon, 9 Nov 2020 23:08:59 +0000 (16:08 -0700)
committerDavid Mulder <dmulder@samba.org>
Wed, 9 Dec 2020 17:38:28 +0000 (17:38 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/netcmd/gpo.py
python/samba/tests/samba_tool/gpo.py
selftest/knownfail.d/gpo [new file with mode: 0644]

index 28887081bdab730c1f761f0de3f1aa574499bfdb..f1cbbc04e1bbc33b486c5d3324aaaff6f9990ea0 100644 (file)
@@ -1802,11 +1802,34 @@ samba-tool gpo manage sudoers list {31B2F340-016D-11D2-945F-00C04FB984F9}
             if get_bytes(entry.keyname) == keyname:
                 self.outf.write('%s\n' % entry.data)
 
+class cmd_remove_sudoers(Command):
+    """Removes a Samba Sudoers Group Policy from the sysvol
+    """
+
+    synopsis = "%prog <gpo> <entry> [options]"
+
+    takes_optiongroups = {
+        "sambaopts": options.SambaOptions,
+        "versionopts": options.VersionOptions,
+        "credopts": options.CredentialsOptions,
+    }
+
+    takes_options = [
+        Option("-H", "--URL", help="LDB URL for database or target server", type=str,
+                metavar="URL", dest="H"),
+    ]
+
+    takes_args = ["gpo", "entry"]
+
+    def run(self, gpo, entry, H=None, sambaopts=None, credopts=None, versionopts=None):
+        pass
+
 class cmd_sudoers(SuperCommand):
     """Manage Sudoers Group Policy Objects"""
     subcommands = {}
     subcommands["add"] = cmd_add_sudoers()
     subcommands["list"] = cmd_list_sudoers()
+    subcommands["remove"] = cmd_remove_sudoers()
 
 class cmd_manage(SuperCommand):
     """Manage Group Policy Objects"""
index ca3f237f76da73eb137aeea4ed5619a7d838dae2..c170602454ab7b8ded328a411a527f015c4cb3a8 100644 (file)
@@ -546,6 +546,35 @@ class GpoCmdTestCase(SambaToolCmdTest):
                         'Filling PolicyDefinitions failed')
         shutil.rmtree(admx_path)
 
+    def test_sudoers_remove(self):
+        lp = LoadParm()
+        lp.load(os.environ['SERVERCONFFILE'])
+        local_path = lp.get('path', 'sysvol')
+        reg_pol = os.path.join(local_path, lp.get('realm').lower(), 'Policies',
+                               self.gpo_guid, 'Machine/Registry.pol')
+
+        # Stage the Registry.pol file with test data
+        stage = preg.file()
+        e = preg.entry()
+        e.keyname = b'Software\\Policies\\Samba\\Unix Settings\\Sudo Rights'
+        e.valuename = b'Software\\Policies\\Samba\\Unix Settings'
+        e.type = 1
+        e.data = b'fakeu  ALL=(ALL) NOPASSWD: ALL'
+        stage.num_entries = 1
+        stage.entries = [e]
+        ret = stage_file(reg_pol, ndr_pack(stage))
+        self.assertTrue(ret, 'Could not create the target %s' % reg_pol)
+
+        (result, out, err) = self.runsublevelcmd("gpo", ("manage", "sudoers",
+                                                 "remove"), self.gpo_guid,
+                                                 get_string(e.data),
+                                                 "-H", "ldap://%s" %
+                                                 os.environ["SERVER"],
+                                                 "-U%s%%%s" %
+                                                 (os.environ["USERNAME"],
+                                                 os.environ["PASSWORD"]))
+        self.assertCmdSuccess(result, out, err, 'Sudoers remove failed')
+
     def test_sudoers_add(self):
         lp = LoadParm()
         lp.load(os.environ['SERVERCONFFILE'])
diff --git a/selftest/knownfail.d/gpo b/selftest/knownfail.d/gpo
new file mode 100644 (file)
index 0000000..d6c5890
--- /dev/null
@@ -0,0 +1 @@
+^samba.tests.samba_tool.gpo.samba.tests.samba_tool.gpo.GpoCmdTestCase.test_sudoers_remove