if unix_home is None:
# obtain nETBIOS Domain Name
- filter = "(&(objectClass=crossRef)(nETBIOSName=*))"
- searchdn = ("CN=Partitions,CN=Configuration," + domaindn)
- try:
- res = samdb.search(searchdn,
- scope=ldb.SCOPE_SUBTREE,
- expression=filter)
- unix_domain = res[0]["nETBIOSName"][0].decode()
- except IndexError:
+ unix_domain = samdb.domain_netbios_name()
+ if unix_domain is None:
raise CommandError('Unable to find Unix domain')
tmpl = lp.get('template homedir')
domain_dn = self.get_default_basedn()
return domain_dn.canonical_str().split('/')[0]
+ def domain_netbios_name(self):
+ """return the NetBIOS name of the domain root"""
+ domain_dn = self.get_default_basedn()
+ dns_name = self.domain_dns_name()
+ filter = "(&(objectClass=crossRef)(nETBIOSName=*)(ncName=%s)(dnsroot=%s))" % (domain_dn, dns_name)
+ partitions_dn = self.get_partitions_dn()
+ res = self.search(partitions_dn,
+ scope=ldb.SCOPE_ONELEVEL,
+ expression=filter)
+ try:
+ netbios_domain = res[0]["nETBIOSName"][0].decode()
+ except IndexError:
+ return None
+ return netbios_domain
+
def forest_dns_name(self):
"""return the DNS name of the forest root"""
forest_dn = self.get_root_basedn()
super(SamDBTestCase, self).setUp()
self.session = system_session()
logger = logging.getLogger("selftest")
- domain = "dsdb"
- realm = "dsdb.samba.example.com"
+ self.domain = "dsdb"
+ self.realm = "dsdb.samba.example.com"
host_name = "test"
server_role = "active directory domain controller"
self.result = provision(logger,
self.session, targetdir=self.tempdir,
- realm=realm, domain=domain,
+ realm=self.realm, domain=self.domain,
hostname=host_name,
use_ntvfs=True,
serverrole=server_role,
shutil.rmtree(os.path.join(self.tempdir, d))
super(SamDBTestCase, self).tearDown()
+
+
+class SamDBTests(SamDBTestCase):
+
+ def test_get_domain(self):
+ self.assertEqual(self.samdb.domain_dns_name(), self.realm.lower())
+ self.assertEqual(self.samdb.domain_netbios_name(), self.domain.upper())
plantestsuite("wafsamba.duplicate_symbols", "none", [os.path.join(srcdir(), "buildtools/wafsamba/test_duplicate_symbol.sh")])
planpythontestsuite("none", "samba.tests.glue")
planpythontestsuite("none", "samba.tests.tdb_util")
+planpythontestsuite("none", "samba.tests.samdb")
planpythontestsuite("none", "samba.tests.samdb_api")
if with_pam: