summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2020-11-10 13:46:28 +1300
committerGary Lockyer <gary@samba.org>2020-11-11 01:15:39 +0000
commitd79218dbba3d0f26d6a0e22b3c91b0731bf641dd (patch)
treeca2eb9b9fa8fc159835758edf31eb875ed90f039 /python
parentd85e71f449037fa035fa2fae6b64caf695c53cb3 (diff)
downloadsamba-d79218dbba3d0f26d6a0e22b3c91b0731bf641dd.tar.gz
samdb: Add samdb.domain_netbios_name()
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Diffstat (limited to 'python')
-rw-r--r--python/samba/netcmd/user.py10
-rw-r--r--python/samba/samdb.py15
-rw-r--r--python/samba/tests/samdb.py13
3 files changed, 27 insertions, 11 deletions
diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py
index b483dcf5591..7e8204462d1 100644
--- a/python/samba/netcmd/user.py
+++ b/python/samba/netcmd/user.py
@@ -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')
diff --git a/python/samba/samdb.py b/python/samba/samdb.py
index e8aee496352..a0a7dbf1c50 100644
--- a/python/samba/samdb.py
+++ b/python/samba/samdb.py
@@ -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()
diff --git a/python/samba/tests/samdb.py b/python/samba/tests/samdb.py
index a185a1566e3..834c5a204a6 100644
--- a/python/samba/tests/samdb.py
+++ b/python/samba/tests/samdb.py
@@ -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())