]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: Test gpo manage files add command
authorDavid Mulder <dmulder@suse.com>
Tue, 26 Jan 2021 20:43:43 +0000 (13:43 -0700)
committerJeremy Allison <jra@samba.org>
Mon, 8 Feb 2021 22:33:14 +0000 (22:33 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
python/samba/netcmd/gpo.py
python/samba/tests/samba_tool/gpo.py
selftest/knownfail.d/gpo [new file with mode: 0644]

index af0df653948bf9a8fcbb322acb6e026d3614defa..198ffe351efc8bd3c9388a38dbe3bd0fe1debe23 100644 (file)
@@ -2559,10 +2559,39 @@ samba-tool gpo manage files list {31B2F340-016D-11D2-945F-00C04FB984F9}
                     (stat_from_mode(mode), user, group, target, source)
             self.outf.write('%s\n' % p)
 
+class cmd_add_files(Command):
+    """Add VGP Files Group Policy to the sysvol
+
+This command adds files which will be copied from the sysvol and applied to winbind clients.
+
+Example:
+samba-tool gpo manage files add {31B2F340-016D-11D2-945F-00C04FB984F9} ./source.txt /usr/share/doc/target.txt root root 600
+    """
+
+    synopsis = "%prog <gpo> <source> <target> <user> <group> <mode> [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", "source", "target", "user", "group", "mode"]
+
+    def run(self, gpo, source, target, user, group, mode, H=None,
+            sambaopts=None, credopts=None, versionopts=None):
+        pass
+
 class cmd_files(SuperCommand):
     """Manage Files Group Policy Objects"""
     subcommands = {}
     subcommands["list"] = cmd_list_files()
+    subcommands["add"] = cmd_add_files()
 
 class cmd_manage(SuperCommand):
     """Manage Group Policy Objects"""
index af2e45782bdb1b972504a1758541108e6f6d9e8a..c885198c1b2d19c01a14b37be65ce3b08d04ba41 100644 (file)
@@ -923,6 +923,50 @@ class GpoCmdTestCase(SambaToolCmdTest):
         # Unstage the manifest.xml file
         unstage_file(vgp_xml)
 
+    def test_files_add(self):
+        lp = LoadParm()
+        lp.load(os.environ['SERVERCONFFILE'])
+        local_path = lp.get('path', 'sysvol')
+        sysvol_source = os.path.join(local_path, lp.get('realm').lower(),
+                                     'Policies', self.gpo_guid, 'Machine/VGP',
+                                     'VTLA/Unix/Files/test.source')
+        source_file = os.path.join(self.tempdir, 'test.source')
+        source_data = '#!/bin/sh\necho hello world'
+        with open(source_file, 'w') as w:
+            w.write(source_data)
+        target_file = os.path.join(self.tempdir, 'test.target')
+        user = pwd.getpwuid(os.getuid()).pw_name
+        group = grp.getgrgid(os.getgid()).gr_name
+        (result, out, err) = self.runsublevelcmd("gpo", ("manage",
+                                                 "files", "add"),
+                                                 self.gpo_guid,
+                                                 source_file,
+                                                 target_file,
+                                                 user, group,
+                                                 '755', "-H",
+                                                 "ldap://%s" %
+                                                 os.environ["SERVER"],
+                                                 "-U%s%%%s" %
+                                                 (os.environ["USERNAME"],
+                                                 os.environ["PASSWORD"]))
+        self.assertCmdSuccess(result, out, err, 'File add failed')
+        self.assertIn(source_data, open(sysvol_source, 'r').read(),
+                      'Failed to find the source file on the sysvol')
+
+        (result, out, err) = self.runsublevelcmd("gpo", ("manage",
+                                                 "files", "list"),
+                                                 self.gpo_guid, "-H",
+                                                 "ldap://%s" %
+                                                 os.environ["SERVER"],
+                                                 "-U%s%%%s" %
+                                                 (os.environ["USERNAME"],
+                                                 os.environ["PASSWORD"]))
+        self.assertIn(target_file, out, 'The test entry was not found!')
+        self.assertIn('-rwxr-xr-x', out,
+                      'The test entry permissions were not found')
+
+        os.unlink(source_file)
+
     def setUp(self):
         """set up a temporary GPO to work with"""
         super(GpoCmdTestCase, self).setUp()
diff --git a/selftest/knownfail.d/gpo b/selftest/knownfail.d/gpo
new file mode 100644 (file)
index 0000000..960b8e5
--- /dev/null
@@ -0,0 +1 @@
+^samba.tests.samba_tool.gpo.samba.tests.samba_tool.gpo.GpoCmdTestCase.test_files_add