2010-01-08 13:12:11 +03:00
# Unix SMB/CIFS implementation. Tests for ntacls manipulation
# Copyright (C) Matthieu Patou <mat@matws.net> 2009-2010
2012-11-11 14:01:44 +11:00
# Copyright (C) Andrew Bartlett 2012
2010-01-08 13:12:11 +03: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.
#
# 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/>.
#
2010-12-05 16:56:27 +01:00
""" Tests for samba.ntacls. """
2018-06-01 14:28:43 +12:00
import os
2010-01-08 13:12:11 +03:00
from samba . ntacls import setntacl , getntacl , XattrBackendError
from samba . param import LoadParm
2014-12-14 20:03:28 +00:00
from samba . dcerpc import security
from samba . tests import TestCaseInTempDir , SkipTest
2019-12-17 14:49:42 +01:00
from samba . auth_util import system_session_unix
2010-01-08 13:12:11 +03:00
2018-06-01 14:23:54 +12:00
NTACL_SDDL = " O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;OICI;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512) "
DOMAIN_SID = " S-1-5-21-2212615479-2695158682-2101375467 "
2012-11-11 14:01:44 +11:00
class NtaclsTests ( TestCaseInTempDir ) :
2010-01-08 13:12:11 +03:00
2018-06-01 14:28:43 +12:00
def setUp ( self ) :
super ( NtaclsTests , self ) . setUp ( )
self . tempf = os . path . join ( self . tempdir , " test " )
open ( self . tempf , ' w ' ) . write ( " empty " )
2019-12-17 14:49:42 +01:00
self . session_info = system_session_unix ( )
2018-06-01 14:28:43 +12:00
def tearDown ( self ) :
os . unlink ( self . tempf )
super ( NtaclsTests , self ) . tearDown ( )
2010-03-29 15:43:43 +02:00
def test_setntacl ( self ) :
lp = LoadParm ( )
2012-11-11 14:01:44 +11:00
open ( self . tempf , ' w ' ) . write ( " empty " )
2018-06-01 14:28:43 +12:00
lp . set ( " posix:eadb " , os . path . join ( self . tempdir , " eadbtest.tdb " ) )
2019-12-17 14:49:42 +01:00
setntacl ( lp , self . tempf , NTACL_SDDL , DOMAIN_SID , self . session_info )
2018-06-01 14:28:43 +12:00
os . unlink ( os . path . join ( self . tempdir , " eadbtest.tdb " ) )
2010-01-08 13:12:11 +03:00
2010-03-29 15:43:43 +02:00
def test_setntacl_getntacl ( self ) :
lp = LoadParm ( )
2012-11-11 14:01:44 +11:00
open ( self . tempf , ' w ' ) . write ( " empty " )
2018-06-01 14:28:43 +12:00
lp . set ( " posix:eadb " , os . path . join ( self . tempdir , " eadbtest.tdb " ) )
2019-12-17 14:49:42 +01:00
setntacl ( lp , self . tempf , NTACL_SDDL , DOMAIN_SID , self . session_info )
2019-12-17 14:52:49 +01:00
facl = getntacl ( lp , self . tempf , self . session_info )
2010-03-29 15:43:43 +02:00
anysid = security . dom_sid ( security . SID_NT_SELF )
2020-02-07 11:02:38 +13:00
self . assertEqual ( facl . as_sddl ( anysid ) , NTACL_SDDL )
2018-06-01 14:28:43 +12:00
os . unlink ( os . path . join ( self . tempdir , " eadbtest.tdb " ) )
2010-01-08 13:12:11 +03:00
2010-03-29 15:43:43 +02:00
def test_setntacl_getntacl_param ( self ) :
lp = LoadParm ( )
2012-11-11 14:01:44 +11:00
open ( self . tempf , ' w ' ) . write ( " empty " )
2019-12-17 14:49:42 +01:00
setntacl ( lp , self . tempf , NTACL_SDDL , DOMAIN_SID , self . session_info , " tdb " ,
2018-06-01 14:28:43 +12:00
os . path . join ( self . tempdir , " eadbtest.tdb " ) )
2019-12-17 14:52:49 +01:00
facl = getntacl ( lp , self . tempf , self . session_info , " tdb " , os . path . join (
2018-06-01 14:28:43 +12:00
self . tempdir , " eadbtest.tdb " ) )
domsid = security . dom_sid ( security . SID_NT_SELF )
2020-02-07 11:02:38 +13:00
self . assertEqual ( facl . as_sddl ( domsid ) , NTACL_SDDL )
2018-06-01 14:28:43 +12:00
os . unlink ( os . path . join ( self . tempdir , " eadbtest.tdb " ) )
2010-01-08 13:12:11 +03:00
2010-03-29 15:43:43 +02:00
def test_setntacl_invalidbackend ( self ) :
lp = LoadParm ( )
2012-11-11 14:01:44 +11:00
open ( self . tempf , ' w ' ) . write ( " empty " )
2018-06-01 14:28:43 +12:00
self . assertRaises ( XattrBackendError , setntacl , lp , self . tempf ,
2019-12-17 14:49:42 +01:00
NTACL_SDDL , DOMAIN_SID , self . session_info , " ttdb " ,
2018-06-01 14:28:43 +12:00
os . path . join ( self . tempdir , " eadbtest.tdb " ) )
2010-01-08 13:12:11 +03:00
2010-03-29 15:43:43 +02:00
def test_setntacl_forcenative ( self ) :
2010-06-19 17:49:15 +02:00
if os . getuid ( ) == 0 :
2014-12-14 20:03:28 +00:00
raise SkipTest ( " Running test as root, test skipped " )
2010-06-19 17:49:15 +02:00
lp = LoadParm ( )
2012-11-11 14:01:44 +11:00
open ( self . tempf , ' w ' ) . write ( " empty " )
2018-06-01 14:28:43 +12:00
lp . set ( " posix:eadb " , os . path . join ( self . tempdir , " eadbtest.tdb " ) )
2018-06-01 14:23:54 +12:00
self . assertRaises ( Exception , setntacl , lp , self . tempf , NTACL_SDDL ,
2019-12-17 14:49:42 +01:00
DOMAIN_SID , self . session_info , " native " )