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
2010-06-13 17:05:50 +04:00
import logging
2008-02-13 04:18:45 +03:00
import os
2009-09-26 20:37:56 +04:00
from samba . provision import setup_samdb , guess_names , make_smbconf , find_setup_dir
2009-02-12 17:58:11 +03:00
from samba . tests import TestCaseInTempDir
2008-12-23 13:44:10 +03:00
from samba . dcerpc import security
2008-02-13 04:18:45 +03:00
import uuid
2008-05-30 16:15:40 +04:00
from samba import param
2008-02-13 04:18:45 +03:00
2009-02-12 18:00:11 +03:00
2008-02-13 04:18:45 +03:00
class SamDBTestCase ( TestCaseInTempDir ) :
2009-02-12 18:00:11 +03:00
""" Base-class for tests with a Sam Database.
This is used by the Samba SamDB - tests , but e . g . also by the OpenChange
provisioning tests ( which need a Sam ) .
"""
2009-02-11 19:54:58 +03:00
2009-02-11 20:17:00 +03:00
def setup_path ( self , relpath ) :
2009-02-11 20:45:51 +03:00
return os . path . join ( find_setup_dir ( ) , relpath )
2009-02-11 20:17:00 +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
domainsid = security . random_sid ( )
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 " )
2009-02-11 20:17:00 +03:00
make_smbconf ( smbconf , self . setup_path , hostname , domain , dnsdomain ,
serverrole , self . tempdir )
2008-05-30 08:26:47 +04:00
2009-02-11 20:17:00 +03:00
self . lp = param . LoadParm ( )
self . lp . load ( smbconf )
2008-05-30 08:26:47 +04:00
2009-02-11 20:17:00 +03:00
names = guess_names ( lp = self . lp , hostname = hostname ,
2008-05-30 08:26:47 +04:00
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 )
2009-10-30 06:51:57 +03:00
paths = provision_paths_from_lp ( self . lp , names . dnsdomain )
provision_backend = ProvisionBackend ( " ldb " , backend_type ,
paths = paths , setup_path = self . setup_path ,
lp = self . lp , credentials = None ,
names = names ,
message = message , hostname = hostname ,
root = root , schema = schema ,
domainsid = domainsid )
self . samdb = setup_samdb ( path , self . setup_path , session_info , provision_backend ,
2009-02-12 17:58:11 +03:00
self . lp , names ,
2010-06-13 17:05:50 +04:00
logging . getLogger ( " samdb " ) , domainsid ,
2009-08-17 07:28:57 +04:00
domainguid ,
2008-05-29 19:31:16 +04:00
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 ) :
2009-09-26 20:37:56 +04:00
for f in [ ' 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
2009-02-12 18:00:11 +03:00
2009-08-17 11:48:27 +04:00
# disable this test till andrew works it out ...
2009-02-12 18:00:11 +03:00
class SamDBTests ( SamDBTestCase ) :
""" Tests for the SamDB implementation. """
2009-08-17 11:48:27 +04:00
print " samdb add_foreign disabled for now "
# def test_add_foreign(self):