diff options
author | Tim Beale <timbeale@catalyst.net.nz> | 2017-07-04 09:31:54 +1200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2017-07-04 06:57:20 +0200 |
commit | e13b21d9644445636a7657c73f501772ac8d96bf (patch) | |
tree | a510ead0b26ab6568fa1ce20e8a209c812818d4d | |
parent | d10e27c350d6e4b389fa15cdbc32dc0689e4fcc6 (diff) | |
download | samba-e13b21d9644445636a7657c73f501772ac8d96bf.tar.gz |
tests: Add simple check whether netlogon server is running
Netlogon only needs to run in DC environment. This is a simple test to
check whether the netlogon service is running. This will allow us to
disable the netlogon service on setups that don't require it.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
-rw-r--r-- | python/samba/tests/netlogonsvc.py | 69 | ||||
-rwxr-xr-x | source4/selftest/tests.py | 5 |
2 files changed, 74 insertions, 0 deletions
diff --git a/python/samba/tests/netlogonsvc.py b/python/samba/tests/netlogonsvc.py new file mode 100644 index 00000000000..87afa3e233e --- /dev/null +++ b/python/samba/tests/netlogonsvc.py @@ -0,0 +1,69 @@ +# Tests to check the netlogon service is only running when it's required +# +# Copyright (C) Catalyst IT Ltd. 2017 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +from samba.tests import TestCase +import os + +import samba +from samba.credentials import Credentials +from samba.dcerpc import netlogon +from samba import NTSTATUSError, ntstatus +import ctypes + +""" +Tests whether the netlogon service is running +""" + +class NetlogonServiceTests(TestCase): + + def setUp(self): + super(NetlogonServiceTests, self).setUp() + + self.server = os.environ["SERVER"] + self.lp = self.get_loadparm() + self.creds = Credentials() + + # prefer the DC user/password in environments that have it + if "DC_USERNAME" in os.environ and "DC_PASSWORD" in os.environ: + self.creds.set_username(os.environ["DC_USERNAME"]) + self.creds.set_password(os.environ["DC_PASSWORD"]) + else: + self.creds.set_username(os.environ["USERNAME"]) + self.creds.set_password(os.environ["PASSWORD"]) + + self.creds.guess(self.lp) + + def tearDown(self): + super(NetlogonServiceTests, self).tearDown() + + def test_have_netlogon_connection(self): + try: + c = self.get_netlogon_connection() + self.assertIsNotNone(c) + except NTSTATUSError as e: + # On non-DC test environments, netlogon should not be running on + # the server, so we expect the test to fail here + enum = ctypes.c_uint32(e[0]).value + if enum == ntstatus.NT_STATUS_OBJECT_NAME_NOT_FOUND: + self.fail("netlogon service is not running") + else: + raise + + # Establish netlogon connection over NP + def get_netlogon_connection(self): + return netlogon.netlogon("ncacn_np:%s[seal]" % self.server, self.lp, + self.creds) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 049009fe125..c74d0fef715 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -893,6 +893,11 @@ for env in [ extra_path=[os.path.join(srcdir(), "samba/python"), ] ) +for env in [ "simpleserver", "fileserver", "nt4_dc", "ad_dc", "ad_dc_ntvfs", "ad_member"]: + planoldpythontestsuite(env, "netlogonsvc", + extra_path=[os.path.join(srcdir(), 'python/samba/tests')], + name="samba.tests.netlogonsvc.python(%s)" % env) + # Demote the vampire DC, it must be the last test each DC, before the dbcheck for env in ['vampire_dc', 'promoted_dc', 'rodc']: plantestsuite("samba4.blackbox.samba_tool_demote(%s)" % env, env, [os.path.join(samba4srcdir, "utils/tests/test_demote.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', '$DOMAIN', '$DC_SERVER', '$PREFIX/%s' % env, smbclient4]) |