1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-08 13:49:29 +03:00

samba-tool: Test gpo manage script startup add command

Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
David Mulder
2021-02-12 08:04:30 -07:00
committed by Jeremy Allison
parent d22196117c
commit f6a0bd8b91
3 changed files with 73 additions and 0 deletions

View File

@ -3113,10 +3113,41 @@ samba-tool gpo manage scripts startup list {31B2F340-016D-11D2-945F-00C04FB984F9
self.outf.write('@reboot %s %s %s' % (run_as, script_path,
parameters.text))
class cmd_add_startup(Command):
"""Adds VGP Startup Script Group Policy to the sysvol
This command adds a startup script policy to the sysvol.
Example:
samba-tool gpo manage scripts startup add {31B2F340-016D-11D2-945F-00C04FB984F9} test_script.sh '-n'
"""
synopsis = "%prog <gpo> <script> [args] [run_as] [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"),
Option("--run-once", dest="run_once", default=False, action='store_true',
help="Whether to run the script only once"),
]
takes_args = ["gpo", "script", "args?", "run_as?"]
def run(self, gpo, script, args=None, run_as=None, run_once=None,
H=None, sambaopts=None, credopts=None, versionopts=None):
pass
class cmd_startup(SuperCommand):
"""Manage Startup Scripts Group Policy Objects"""
subcommands = {}
subcommands["list"] = cmd_list_startup()
subcommands["add"] = cmd_add_startup()
class cmd_scripts(SuperCommand):
"""Manage Scripts Group Policy Objects"""

View File

@ -32,6 +32,8 @@ from samba.common import get_string
from configparser import ConfigParser
from io import StringIO
import xml.etree.ElementTree as etree
from tempfile import NamedTemporaryFile
from time import sleep
source_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../.."))
@ -1120,6 +1122,45 @@ class GpoCmdTestCase(SambaToolCmdTest):
os.environ["PASSWORD"]))
self.assertNotIn(openssh, out, 'The test entry was still found!')
def test_startup_script_add(self):
lp = LoadParm()
fname = None
with NamedTemporaryFile() as f:
fname = os.path.basename(f.name)
f.write(b'#!/bin/sh\necho $@ hello world')
f.flush()
(result, out, err) = self.runsublevelcmd("gpo", ("manage",
"scripts", "startup",
"add"), self.gpo_guid,
f.name, "'-n'", "-H",
"ldap://%s" %
os.environ["SERVER"],
"-U%s%%%s" %
(os.environ["USERNAME"],
os.environ["PASSWORD"]))
self.assertCmdSuccess(result, out, err, 'Script add failed')
script_path = '\\'.join(['\\', lp.get('realm').lower(), 'Policies',
self.gpo_guid, 'MACHINE\\VGP\\VTLA\\Unix',
'Scripts\\Startup', fname])
entry = '@reboot root %s -n' % script_path
(result, out, err) = self.runsublevelcmd("gpo", ("manage", "scripts",
"startup", "list"),
self.gpo_guid, "-H",
"ldap://%s" %
os.environ["SERVER"],
"-U%s%%%s" %
(os.environ["USERNAME"],
os.environ["PASSWORD"]))
self.assertIn(entry, out, 'The test entry was not found!')
local_path = lp.get('path', 'sysvol')
local_script_path = os.path.join(local_path, lp.get('realm').lower(),
'Policies', self.gpo_guid,
'Machine/VGP/VTLA/Unix',
'Scripts/Startup', fname)
self.assertTrue(os.path.exists(local_script_path),
'The test script was not uploaded to the sysvol')
def test_startup_script_list(self):
lp = LoadParm()
lp.load(os.environ['SERVERCONFFILE'])

1
selftest/knownfail.d/gpo Normal file
View File

@ -0,0 +1 @@
^samba.tests.samba_tool.gpo.samba.tests.samba_tool.gpo.GpoCmdTestCase.test_startup_script_add