2017-03-14 06:43:06 +03:00
# Unix SMB/CIFS implementation.
# Copyright (C) Andrew Bartlett <abartlet@samba.org> 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/>.
#
""" Tests for the Auth and AuthZ logging.
"""
import samba . tests
2018-04-30 01:35:25 +03:00
from samba . credentials import DONT_USE_KERBEROS
2017-07-24 01:59:18 +03:00
from samba . dcerpc . dcerpc import AS_SYSTEM_MAGIC_PATH_TOKEN
2017-03-14 06:43:06 +03:00
from samba . dcerpc import samr
import samba . tests . auth_log_base
2018-12-13 04:46:31 +03:00
from samba . dcerpc . windows_event_ids import (
EVT_ID_SUCCESSFUL_LOGON ,
EVT_LOGON_NETWORK
)
2018-04-30 01:35:25 +03:00
2017-03-14 06:43:06 +03:00
class AuthLogTestsNcalrpc ( samba . tests . auth_log_base . AuthLogTestBase ) :
def setUp ( self ) :
super ( AuthLogTestsNcalrpc , self ) . setUp ( )
2017-07-24 01:59:18 +03:00
self . remoteAddress = AS_SYSTEM_MAGIC_PATH_TOKEN
2017-03-14 06:43:06 +03:00
def tearDown ( self ) :
2018-04-30 01:35:25 +03:00
super ( AuthLogTestsNcalrpc , self ) . tearDown ( )
2017-03-14 06:43:06 +03:00
def _test_rpc_ncaclrpc ( self , authTypes , binding , creds ,
protection , checkFunction ) :
2018-04-30 01:35:25 +03:00
def isLastExpectedMessage ( msg ) :
2017-03-14 06:43:06 +03:00
return (
msg [ " type " ] == " Authorization " and
2018-12-17 00:04:42 +03:00
msg [ " Authorization " ] [ " serviceDescription " ] == " DCE/RPC " and
msg [ " Authorization " ] [ " authType " ] == authTypes [ 0 ] and
2018-04-30 01:35:25 +03:00
msg [ " Authorization " ] [ " transportProtection " ] == protection )
2017-03-14 06:43:06 +03:00
if binding :
binding = " [ %s ] " % binding
samr . samr ( " ncalrpc: %s " % binding , self . get_loadparm ( ) , creds )
2018-04-30 01:35:25 +03:00
messages = self . waitForMessages ( isLastExpectedMessage )
2017-03-14 06:43:06 +03:00
checkFunction ( messages , authTypes , protection )
def rpc_ncacn_np_ntlm_check ( self , messages , authTypes , protection ) :
expected_messages = len ( authTypes )
2020-02-07 01:02:38 +03:00
self . assertEqual ( expected_messages ,
2017-03-14 06:43:06 +03:00
len ( messages ) ,
" Did not receive the expected number of messages " )
# Check the first message it should be an Authorization
msg = messages [ 0 ]
2020-02-07 01:02:38 +03:00
self . assertEqual ( " Authorization " , msg [ " type " ] )
self . assertEqual ( " DCE/RPC " ,
2017-03-14 06:43:06 +03:00
msg [ " Authorization " ] [ " serviceDescription " ] )
2020-02-07 01:02:38 +03:00
self . assertEqual ( authTypes [ 1 ] , msg [ " Authorization " ] [ " authType " ] )
self . assertEqual ( " NONE " , msg [ " Authorization " ] [ " transportProtection " ] )
2018-04-30 00:13:58 +03:00
self . assertTrue ( self . is_guid ( msg [ " Authorization " ] [ " sessionId " ] ) )
2017-03-14 06:43:06 +03:00
# Check the second message it should be an Authentication
msg = messages [ 1 ]
2020-02-07 01:02:38 +03:00
self . assertEqual ( " Authentication " , msg [ " type " ] )
self . assertEqual ( " NT_STATUS_OK " , msg [ " Authentication " ] [ " status " ] )
self . assertEqual ( " DCE/RPC " ,
2018-04-30 01:35:25 +03:00
msg [ " Authentication " ] [ " serviceDescription " ] )
2020-02-07 01:02:38 +03:00
self . assertEqual ( authTypes [ 2 ] ,
2018-04-30 01:35:25 +03:00
msg [ " Authentication " ] [ " authDescription " ] )
2020-02-07 01:02:38 +03:00
self . assertEqual ( EVT_ID_SUCCESSFUL_LOGON ,
2018-12-13 00:20:28 +03:00
msg [ " Authentication " ] [ " eventId " ] )
2020-02-07 01:02:38 +03:00
self . assertEqual ( EVT_LOGON_NETWORK ,
2018-12-13 04:46:31 +03:00
msg [ " Authentication " ] [ " logonType " ] )
2017-03-14 06:43:06 +03:00
def test_ncalrpc_ntlm_dns_sign ( self ) :
creds = self . insta_creds ( template = self . get_credentials ( ) ,
kerberos_state = DONT_USE_KERBEROS )
self . _test_rpc_ncaclrpc ( [ " NTLMSSP " ,
" ncalrpc " ,
" NTLMSSP " ] ,
" " , creds , " SIGN " ,
self . rpc_ncacn_np_ntlm_check )
def test_ncalrpc_ntlm_dns_seal ( self ) :
creds = self . insta_creds ( template = self . get_credentials ( ) ,
kerberos_state = DONT_USE_KERBEROS )
self . _test_rpc_ncaclrpc ( [ " NTLMSSP " ,
" ncalrpc " ,
" NTLMSSP " ] ,
" seal " , creds , " SEAL " ,
self . rpc_ncacn_np_ntlm_check )