2007-12-23 19:19:41 -06:00
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
2011-09-13 01:10:37 +02:00
#
2007-12-23 19:19:41 -06:00
# 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.
2011-09-13 01:10:37 +02:00
#
2007-12-23 19:19:41 -06:00
# 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.
2011-09-13 01:10:37 +02:00
#
2007-12-23 19:19:41 -06:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
2018-03-21 18:24:18 +00:00
""" Tests for samba.s3passdb """
2010-12-05 16:56:27 +01:00
2011-08-25 17:10:23 +10:00
from samba . samba3 import passdb
from samba . samba3 import param as s3param
2018-10-11 14:33:49 +13:00
from samba . tests import TestCaseInTempDir
2011-08-25 17:10:23 +10:00
from samba . dcerpc . security import dom_sid
2007-12-23 19:19:41 -06:00
import os
2012-09-16 14:18:51 +02:00
2018-07-30 18:17:02 +12:00
for p in [ " ../../../../../testdata/samba3 " , " ../../../../testdata/samba3 " ] :
2011-02-03 17:35:54 +11:00
DATADIR = os . path . join ( os . path . dirname ( __file__ ) , p )
if os . path . exists ( DATADIR ) :
break
2007-12-23 19:19:41 -06:00
2011-08-26 13:19:18 +10:00
class PassdbTestCase ( TestCaseInTempDir ) :
2010-06-19 17:49:46 +02:00
2007-12-23 19:19:41 -06:00
def setUp ( self ) :
2023-11-28 16:38:22 +13:00
super ( ) . setUp ( )
2011-08-26 13:19:18 +10:00
os . system ( " cp -r %s %s " % ( DATADIR , self . tempdir ) )
datadir = os . path . join ( self . tempdir , " samba3 " )
2011-08-25 17:10:23 +10:00
self . lp = s3param . get_context ( )
2011-08-26 13:19:18 +10:00
self . lp . load ( os . path . join ( datadir , " smb.conf " ) )
self . lp . set ( " private dir " , datadir )
self . lp . set ( " state directory " , datadir )
self . lp . set ( " lock directory " , datadir )
2015-01-15 14:31:19 -07:00
self . lp . set ( " cache directory " , datadir )
2011-08-26 13:19:18 +10:00
passdb . set_secrets_dir ( datadir )
2011-08-25 17:10:23 +10:00
self . pdb = passdb . PDB ( " tdbsam " )
2007-12-23 19:19:41 -06:00
2011-08-25 17:10:23 +10:00
def tearDown ( self ) :
self . lp = [ ]
self . pdb = [ ]
2011-08-26 13:19:18 +10:00
os . system ( " rm -rf %s " % os . path . join ( self . tempdir , " samba3 " ) )
2023-11-28 16:38:22 +13:00
super ( ) . tearDown ( )
2007-12-23 19:19:41 -06:00
2011-08-25 17:10:23 +10:00
def test_policy ( self ) :
policy = self . pdb . get_account_policy ( )
2020-02-07 11:02:38 +13:00
self . assertEqual ( 0 , policy [ ' bad lockout attempt ' ] )
self . assertEqual ( - 1 , policy [ ' disconnect time ' ] )
self . assertEqual ( 0 , policy [ ' lockout duration ' ] )
self . assertEqual ( 999999999 , policy [ ' maximum password age ' ] )
self . assertEqual ( 0 , policy [ ' minimum password age ' ] )
self . assertEqual ( 5 , policy [ ' min password length ' ] )
self . assertEqual ( 0 , policy [ ' password history ' ] )
self . assertEqual ( 0 , policy [ ' refuse machine password change ' ] )
self . assertEqual ( 0 , policy [ ' reset count minutes ' ] )
self . assertEqual ( 0 , policy [ ' user must logon to change password ' ] )
2010-06-19 17:49:46 +02:00
2011-08-25 17:10:23 +10:00
def test_get_sid ( self ) :
domain_sid = passdb . get_global_sam_sid ( )
2020-02-07 11:02:38 +13:00
self . assertEqual ( dom_sid ( " S-1-5-21-2470180966-3899876309-2637894779 " ) , domain_sid )
2007-12-23 19:19:41 -06:00
2011-08-25 17:10:23 +10:00
def test_usernames ( self ) :
userlist = self . pdb . search_users ( 0 )
2020-02-07 11:02:38 +13:00
self . assertEqual ( 3 , len ( userlist ) )
2011-08-25 17:10:23 +10:00
def test_getuser ( self ) :
user = self . pdb . getsampwnam ( " root " )
2020-02-07 11:02:38 +13:00
self . assertEqual ( 16 , user . acct_ctrl )
self . assertEqual ( " " , user . acct_desc )
self . assertEqual ( 0 , user . bad_password_count )
self . assertEqual ( 0 , user . bad_password_time )
self . assertEqual ( 0 , user . code_page )
self . assertEqual ( 0 , user . country_code )
self . assertEqual ( " " , user . dir_drive )
self . assertEqual ( " BEDWYR " , user . domain )
self . assertEqual ( " root " , user . full_name )
self . assertEqual ( dom_sid ( ' S-1-5-21-2470180966-3899876309-2637894779-513 ' ) , user . group_sid )
self . assertEqual ( " \\ \\ BEDWYR \\ root " , user . home_dir )
self . assertEqual ( [ - 1 for i in range ( 21 ) ] , user . hours )
self . assertEqual ( 21 , user . hours_len )
self . assertEqual ( 9223372036854775807 , user . kickoff_time )
2024-07-12 19:38:40 +02:00
self . assertEqual ( b ' U) \x02 \x03 \x1b \xed \xe9 \xef \xaa \xd3 \xb4 5 \xb5 \x14 \x04 \xee ' , user . lanman_passwd )
2020-02-07 11:02:38 +13:00
self . assertEqual ( 9223372036854775807 , user . logoff_time )
self . assertEqual ( 0 , user . logon_count )
self . assertEqual ( 168 , user . logon_divs )
self . assertEqual ( " " , user . logon_script )
self . assertEqual ( 0 , user . logon_time )
self . assertEqual ( " " , user . munged_dial )
self . assertEqual ( b ' \x87 \x8d \x80 \x14 `l \xda )gzD \xef \xa1 5? \xc7 ' , user . nt_passwd )
self . assertEqual ( " " , user . nt_username )
self . assertEqual ( 1125418267 , user . pass_can_change_time )
self . assertEqual ( 1125418267 , user . pass_last_set_time )
self . assertEqual ( 2125418266 , user . pass_must_change_time )
self . assertEqual ( None , user . plaintext_passwd )
self . assertEqual ( " \\ \\ BEDWYR \\ root \\ profile " , user . profile_path )
self . assertEqual ( None , user . pw_history )
self . assertEqual ( dom_sid ( " S-1-5-21-2470180966-3899876309-2637894779-1000 " ) , user . user_sid )
self . assertEqual ( " root " , user . username )
self . assertEqual ( " " , user . workstations )
2007-12-24 13:04:33 -06:00
def test_group_length ( self ) :
2011-08-25 17:10:23 +10:00
grouplist = self . pdb . enum_group_mapping ( )
2020-02-07 11:02:38 +13:00
self . assertEqual ( 13 , len ( grouplist ) )
2007-12-24 13:04:33 -06:00
2007-12-27 03:09:49 -06:00
def test_get_group ( self ) :
2011-08-25 17:10:23 +10:00
group = self . pdb . getgrsid ( dom_sid ( " S-1-5-32-544 " ) )
2020-02-07 11:02:38 +13:00
self . assertEqual ( " Administrators " , group . nt_name )
self . assertEqual ( - 1 , group . gid )
self . assertEqual ( 5 , group . sid_name_use )
2007-12-27 03:09:49 -06:00
2007-12-24 13:04:33 -06:00
def test_groupsids ( self ) :
2011-08-25 17:10:23 +10:00
grouplist = self . pdb . enum_group_mapping ( )
sids = [ ]
for g in grouplist :
sids . append ( str ( g . sid ) )
2007-12-24 13:04:33 -06:00
self . assertTrue ( " S-1-5-32-544 " in sids )
2011-08-25 17:10:23 +10:00
self . assertTrue ( " S-1-5-32-545 " in sids )
self . assertTrue ( " S-1-5-32-546 " in sids )
self . assertTrue ( " S-1-5-32-548 " in sids )
self . assertTrue ( " S-1-5-32-549 " in sids )
self . assertTrue ( " S-1-5-32-550 " in sids )
self . assertTrue ( " S-1-5-32-551 " in sids )
2007-12-24 13:04:33 -06:00
def test_alias_length ( self ) :
2011-08-25 17:10:23 +10:00
aliaslist = self . pdb . search_aliases ( )
2020-02-07 11:02:38 +13:00
self . assertEqual ( 1 , len ( aliaslist ) )
self . assertEqual ( " Jelmers NT Group " , aliaslist [ 0 ] [ ' account_name ' ] )