2017-07-05 05:32:54 +03:00
# Tests basic behaviour when NTLM is disabled
2017-07-04 04:31:11 +03:00
#
# 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
2017-07-04 08:27:27 +03:00
from samba . credentials import Credentials , DONT_USE_KERBEROS , MUST_USE_KERBEROS
2017-07-04 04:31:11 +03:00
from samba import NTSTATUSError , ntstatus
import ctypes
2017-07-04 08:27:27 +03:00
from samba . dcerpc import srvsvc , samr , lsa
2017-07-04 04:31:11 +03:00
"""
2017-07-05 05:32:54 +03:00
Tests behaviour when NTLM is disabled
2017-07-04 04:31:11 +03:00
"""
2018-07-30 09:20:39 +03:00
2017-07-05 05:32:54 +03:00
class NtlmDisabledTests ( TestCase ) :
2017-07-04 04:31:11 +03:00
def setUp ( self ) :
2023-11-28 06:38:22 +03:00
super ( ) . setUp ( )
2017-07-04 04:31:11 +03:00
self . lp = self . get_loadparm ( )
2017-07-04 08:27:27 +03:00
self . server = os . getenv ( " SERVER " )
2017-07-04 04:31:11 +03:00
2017-07-04 08:27:27 +03:00
self . creds = Credentials ( )
self . creds . guess ( self . lp )
self . creds . set_username ( os . getenv ( " USERNAME " ) )
self . creds . set_domain ( self . server )
self . creds . set_password ( os . getenv ( " PASSWORD " ) )
self . creds . set_kerberos_state ( DONT_USE_KERBEROS )
2017-07-04 04:31:11 +03:00
def test_ntlm_connection ( self ) :
try :
2017-07-04 08:27:27 +03:00
conn = srvsvc . srvsvc ( " ncacn_np: %s [smb2,ntlm] " % self . server , self . lp , self . creds )
2017-07-04 04:31:11 +03:00
self . assertIsNotNone ( conn )
except NTSTATUSError as e :
# NTLM might be blocked on this server
2018-05-09 22:17:30 +03:00
enum = ctypes . c_uint32 ( e . args [ 0 ] ) . value
2017-07-04 04:31:11 +03:00
if enum == ntstatus . NT_STATUS_NTLM_BLOCKED :
self . fail ( " NTLM is disabled on this server " )
else :
raise
2017-07-04 08:27:27 +03:00
def test_samr_change_password ( self ) :
self . creds . set_kerberos_state ( MUST_USE_KERBEROS )
conn = samr . samr ( " ncacn_np: %s [krb5,seal,smb2] " % os . getenv ( " SERVER " ) )
# we want to check whether this gets rejected outright because NTLM is
# disabled, so we don't actually need to encrypt a valid password here
server = lsa . String ( )
server . string = self . server
username = lsa . String ( )
username . string = os . getenv ( " USERNAME " )
try :
conn . ChangePasswordUser2 ( server , username , None , None , True , None , None )
except NTSTATUSError as e :
2017-07-05 05:32:54 +03:00
# changing passwords should be rejected when NTLM is disabled
2018-05-09 22:17:30 +03:00
enum = ctypes . c_uint32 ( e . args [ 0 ] ) . value
2017-07-04 08:27:27 +03:00
if enum == ntstatus . NT_STATUS_NTLM_BLOCKED :
self . fail ( " NTLM is disabled on this server " )
elif enum == ntstatus . NT_STATUS_WRONG_PASSWORD :
# expected error case when NTLM is enabled
pass
else :
raise