2008-02-13 04:18:45 +03:00
#!/usr/bin/python
# Unix SMB/CIFS implementation. Tests for SamDB
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
#
# 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/>.
#
2008-05-29 19:31:16 +04:00
from samba . auth import system_session
from samba . credentials import Credentials
2008-02-13 04:18:45 +03:00
import os
2008-05-30 08:26:47 +04:00
from samba . provision import setup_samdb , guess_names , setup_templatesdb , make_smbconf
2008-02-13 04:18:45 +03:00
from samba . samdb import SamDB
2008-04-15 01:28:14 +04:00
from samba . tests import cmdline_loadparm , TestCaseInTempDir
2008-12-23 13:44:10 +03:00
from samba . dcerpc import security
2008-02-13 04:18:45 +03:00
from unittest import TestCase
import uuid
2008-05-30 16:15:40 +04:00
from samba import param
2008-02-13 04:18:45 +03:00
class SamDBTestCase ( TestCaseInTempDir ) :
2009-02-11 19:54:58 +03:00
2008-02-13 04:18:45 +03:00
def setUp ( self ) :
super ( SamDBTestCase , self ) . setUp ( )
2008-05-11 06:36:37 +04:00
invocationid = str ( uuid . uuid4 ( ) )
2008-02-13 04:18:45 +03:00
domaindn = " DC=COM,DC=EXAMPLE "
self . domaindn = domaindn
configdn = " CN=Configuration, " + domaindn
schemadn = " CN=Schema, " + configdn
2008-05-11 06:36:37 +04:00
domainguid = str ( uuid . uuid4 ( ) )
policyguid = str ( uuid . uuid4 ( ) )
2008-02-13 04:18:45 +03:00
setup_path = lambda x : os . path . join ( " setup " , x )
creds = Credentials ( )
2008-03-28 13:57:15 +03:00
creds . set_anonymous ( )
2008-02-13 04:18:45 +03:00
domainsid = security . random_sid ( )
2008-05-11 06:36:37 +04:00
hostguid = str ( uuid . uuid4 ( ) )
2008-02-13 04:18:45 +03:00
path = os . path . join ( self . tempdir , " samdb.ldb " )
2008-05-29 19:38:12 +04:00
session_info = system_session ( )
2008-05-30 08:26:47 +04:00
hostname = " foo "
domain = " EXAMPLE "
dnsdomain = " example.com "
serverrole = " domain controller "
smbconf = os . path . join ( self . tempdir , " smb.conf " )
make_smbconf ( smbconf , setup_path , hostname , domain , dnsdomain , serverrole ,
self . tempdir )
lp = param . LoadParm ( )
lp . load ( smbconf )
names = guess_names ( lp = lp , hostname = hostname ,
domain = domain , dnsdomain = dnsdomain ,
2008-05-30 16:15:40 +04:00
serverrole = serverrole ,
2008-05-29 19:31:16 +04:00
domaindn = self . domaindn , configdn = configdn ,
schemadn = schemadn )
2008-05-29 19:38:12 +04:00
setup_templatesdb ( os . path . join ( self . tempdir , " templates.ldb " ) ,
setup_path , session_info = session_info ,
credentials = creds , lp = cmdline_loadparm )
self . samdb = setup_samdb ( path , setup_path , session_info , creds ,
2008-05-29 19:31:16 +04:00
cmdline_loadparm , names ,
lambda x : None , domainsid ,
" # no aci " , domainguid ,
policyguid , False , " secret " ,
" secret " , " secret " , invocationid ,
2008-02-13 04:18:45 +03:00
" secret " , " domain controller " )
2008-05-30 08:26:47 +04:00
2008-05-29 19:31:16 +04:00
def tearDown ( self ) :
for f in [ ' templates.ldb ' , ' schema.ldb ' , ' configuration.ldb ' ,
2008-05-30 08:26:47 +04:00
' users.ldb ' , ' samdb.ldb ' , ' smb.conf ' ] :
2008-05-29 19:31:16 +04:00
os . remove ( os . path . join ( self . tempdir , f ) )
super ( SamDBTestCase , self ) . tearDown ( )
2008-02-13 04:18:45 +03:00
def test_add_foreign ( self ) :
self . samdb . add_foreign ( self . domaindn , " S-1-5-7 " , " Somedescription " )