3 # Unix SMB/CIFS implementation. Tests for SamDB
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """Tests for samba.samdb."""
26 from samba.auth import system_session
27 from samba.provision import (setup_samdb, guess_names, make_smbconf,
28 provision_paths_from_lp)
29 from samba.provision import DEFAULT_POLICY_GUID, DEFAULT_DC_POLICY_GUID
30 from samba.provision.backend import ProvisionBackend
31 from samba.tests import TestCaseInTempDir
32 from samba.dcerpc import security
33 from samba.schema import Schema
34 from samba import param
37 class SamDBTestCase(TestCaseInTempDir):
38 """Base-class for tests with a Sam Database.
40 This is used by the Samba SamDB-tests, but e.g. also by the OpenChange
41 provisioning tests (which need a Sam).
45 super(SamDBTestCase, self).setUp()
46 invocationid = str(uuid.uuid4())
47 domaindn = "DC=COM,DC=EXAMPLE"
48 self.domaindn = domaindn
49 configdn = "CN=Configuration," + domaindn
50 schemadn = "CN=Schema," + configdn
51 domainguid = str(uuid.uuid4())
52 policyguid = DEFAULT_POLICY_GUID
53 domainsid = security.random_sid()
54 path = os.path.join(self.tempdir, "samdb.ldb")
55 session_info = system_session()
59 dnsdomain="example.com"
60 serverrole="domain controller"
61 policyguid_dc = DEFAULT_DC_POLICY_GUID
63 smbconf = os.path.join(self.tempdir, "smb.conf")
64 make_smbconf(smbconf, hostname, domain, dnsdomain,
65 serverrole, self.tempdir)
67 self.lp = param.LoadParm()
70 names = guess_names(lp=self.lp, hostname=hostname,
71 domain=domain, dnsdomain=dnsdomain,
72 serverrole=serverrole,
73 domaindn=self.domaindn, configdn=configdn,
76 paths = provision_paths_from_lp(self.lp, names.dnsdomain)
78 logger = logging.getLogger("provision")
80 provision_backend = ProvisionBackend("ldb", paths=paths,
81 lp=self.lp, credentials=None,
82 names=names, logger=logger)
84 schema = Schema(domainsid, invocationid=invocationid,
85 schemadn=names.schemadn, serverdn=names.serverdn,
88 self.samdb = setup_samdb(path, session_info,
89 provision_backend, self.lp, names, logger,
90 domainsid, domainguid, policyguid, policyguid_dc, False,
91 "secret", "secret", "secret", invocationid, "secret",
92 None, "domain controller", schema=schema)
95 for f in ['schema.ldb', 'configuration.ldb',
96 'users.ldb', 'samdb.ldb', 'smb.conf']:
97 os.remove(os.path.join(self.tempdir, f))
98 super(SamDBTestCase, self).tearDown()