1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-22 16:59:09 +03:00

samdb: Add samdb.domain_netbios_name()

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
This commit is contained in:
Andrew Bartlett
2020-11-10 13:46:28 +13:00
committed by Gary Lockyer
parent d85e71f449
commit d79218dbba
4 changed files with 28 additions and 11 deletions

View File

@ -3210,14 +3210,8 @@ The users gecos field will be set to 'User4 test'
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')

View File

@ -998,6 +998,21 @@ accountExpires: %u
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()

View File

@ -38,13 +38,13 @@ class SamDBTestCase(TestCaseInTempDir):
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,
@ -61,3 +61,10 @@ class SamDBTestCase(TestCaseInTempDir):
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())