self.domain_sid = security.dom_sid(samdb.get_domain_sid())
self.domainupdate_container = self.samdb.get_root_basedn()
- if not self.domainupdate_container.add_child("CN=Operations,CN=DomainUpdates,CN=System"):
+ try:
+ self.domainupdate_container.add_child("CN=Operations,CN=DomainUpdates,CN=System")
+ except ldb.LdbError:
raise DomainUpdateException("Failed to add domain update container child")
self.revision_object = self.samdb.get_root_basedn()
- if not self.revision_object.add_child("CN=ActiveDirectoryUpdate,CN=DomainUpdates,CN=System"):
+ try:
+ self.revision_object.add_child("CN=ActiveDirectoryUpdate,CN=DomainUpdates,CN=System")
+ except ldb.LdbError:
raise DomainUpdateException("Failed to add revision object child")
def check_updates_functional_level(self, functional_level,
self.domain_sid = security.dom_sid(samdb.get_domain_sid())
self.forestupdate_container = self.samdb.get_config_basedn()
- if not self.forestupdate_container.add_child("CN=Operations,CN=ForestUpdates"):
+ try:
+ self.forestupdate_container.add_child("CN=Operations,CN=ForestUpdates")
+ except ldb.LdbError:
raise ForestUpdateException("Failed to add forest update container child")
self.revision_object = self.samdb.get_config_basedn()
- if not self.revision_object.add_child("CN=ActiveDirectoryUpdate,CN=ForestUpdates"):
+ try:
+ self.revision_object.add_child("CN=ActiveDirectoryUpdate,CN=ForestUpdates")
+ except ldb.LdbError:
raise ForestUpdateException("Failed to add revision object child")
# Store the result of parsing the markdown in a dictionary
SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME |
SYSTEM_FLAG_DISALLOW_DELETE)
- if not groupou and not group_dn.add_child('CN=Builtin'):
- raise RuntimeError('Error getting Builtin objects DN')
+ if not groupou:
+ try:
+ group_dn.add_child('CN=Builtin')
+ except ldb.LdbError:
+ raise RuntimeError('Error getting Builtin objects DN')
else:
raise RuntimeError(f'Unknown group type {gtype}')
- if groupou and not group_dn.add_child(groupou):
- raise CommandError(f'Invalid group OU "{groupou}"')
+ if groupou:
+ try:
+ group_dn.add_child(groupou)
+ except ldb.LdbError:
+ raise CommandError(f'Invalid group OU "{groupou}"')
- if not group_dn.add_child(f'CN={groupname}'):
+ try:
+ group_dn.add_child(f'CN={groupname}')
+ except ldb.LdbError:
raise CommandError(f'Invalid group name "{groupname}"')
msg = {
# This is verbose, but it is the safe, escape-proof way
# to add a base and add an arbitrary RDN.
- if dn.add_base(samdb.get_config_basedn()) == False:
+ try:
+ dn.add_base(samdb.get_config_basedn())
+ except ldb.LdbError:
raise DemoteException("Failed constructing DN %s by adding base %s"
% (dn, samdb.get_config_basedn()))
- if dn.add_child("CN=X") == False:
+ try:
+ dn.add_child("CN=X")
+ except ldb.LdbError:
raise DemoteException("Failed constructing DN %s by adding child CN=X"
% (dn))
dn.set_component(0, "CN", dc_name)
# This is verbose, but it is the safe, escape-proof way
# to add a base and add an arbitrary RDN.
dn = ldb.Dn(samdb, s)
- if dn.add_base(samdb.get_default_basedn()) == False:
+ try:
+ dn.add_base(samdb.get_default_basedn())
+ except ldb.LdbError:
raise DemoteException("Failed constructing DN %s by adding base %s"
% (dn, samdb.get_default_basedn()))
- if dn.add_child("CN=X") == False:
+ try:
+ dn.add_child("CN=X")
+ except ldb.LdbError:
raise DemoteException("Failed constructing DN %s by adding child "
"CN=X (soon to be CN=%s)" % (dn, dc_name))
dn.set_component(0, "CN", dc_name)
"""
dnsite = ldb.Dn(samdb, "CN=Sites")
- if dnsite.add_base(configDn) == False:
+ try:
+ dnsite.add_base(configDn)
+ except ldb.LdbError:
raise SiteException("dnsite.add_base() failed")
- if dnsite.add_child("CN=X") == False:
+ try:
+ dnsite.add_child("CN=X")
+ except ldb.LdbError:
raise SiteException("dnsite.add_child() failed")
dnsite.set_component(0, "CN", siteName)
raise SubnetInvalid("%s is not a valid subnet (not a string)" % subnet_name)
dnsubnet = ldb.Dn(samdb, "CN=Subnets,CN=Sites")
- if dnsubnet.add_base(configDn) == False:
+ try:
+ dnsubnet.add_base(configDn)
+ except ldb.LdbError:
raise SubnetException("dnsubnet.add_base() failed")
- if dnsubnet.add_child("CN=X") == False:
+ try:
+ dnsubnet.add_child("CN=X")
+ except ldb.LdbError:
raise SubnetException("dnsubnet.add_child() failed")
dnsubnet.set_component(0, "CN", subnet_name)
:raise SubnetNotFound: if the subnet to be deleted does not exist.
"""
dnsubnet = ldb.Dn(samdb, "CN=Subnets,CN=Sites")
- if dnsubnet.add_base(configDn) == False:
+ try:
+ dnsubnet.add_base(configDn)
+ except ldb.LdbError:
raise SubnetException("dnsubnet.add_base() failed")
- if dnsubnet.add_child("CN=X") == False:
+ try:
+ dnsubnet.add_child("CN=X")
+ except ldb.LdbError:
raise SubnetException("dnsubnet.add_child() failed")
dnsubnet.set_component(0, "CN", subnet_name)
:raise SubnetExists: if the subnet to be created already exists.
"""
dnsubnet = ldb.Dn(samdb, "CN=Subnets,CN=Sites")
- if dnsubnet.add_base(configDn) == False:
+ try:
+ dnsubnet.add_base(configDn)
+ except ldb.LdbError:
raise SubnetException("dnsubnet.add_base() failed")
- if dnsubnet.add_child("CN=X") == False:
+ try:
+ dnsubnet.add_child("CN=X")
+ except ldb.LdbError:
raise SubnetException("dnsubnet.add_child() failed")
dnsubnet.set_component(0, "CN", subnet_name)
"""
dnsubnet = ldb.Dn(samdb, "CN=Subnets,CN=Sites")
- if dnsubnet.add_base(configDn) == False:
+ try:
+ dnsubnet.add_base(configDn)
+ except ldb.LdbError:
raise SubnetException("dnsubnet.add_base() failed")
- if dnsubnet.add_child("CN=X") == False:
+ try:
+ dnsubnet.add_child("CN=X")
+ except ldb.LdbError:
raise SubnetException("dnsubnet.add_child() failed")
dnsubnet.set_component(0, "CN", subnet_name)
raise SubnetNotFound('Subnet %s does not exist' % subnet_name)
dnsite = ldb.Dn(samdb, "CN=Sites")
- if dnsite.add_base(configDn) == False:
+ try:
+ dnsite.add_base(configDn)
+ except ldb.LdbError:
raise SubnetException("dnsite.add_base() failed")
- if dnsite.add_child("CN=X") == False:
+ try:
+ dnsite.add_child("CN=X")
+ except ldb.LdbError:
raise SubnetException("dnsite.add_child() failed")
dnsite.set_component(0, "CN", site_name)
if self._claim_types_dn is None:
claim_config_dn = samdb.get_config_basedn()
- self.assertTrue(claim_config_dn.add_child(
- 'CN=Claims Configuration,CN=Services'))
+ claim_config_dn.add_child('CN=Claims Configuration,CN=Services')
details = {
'dn': claim_config_dn,
'objectClass': 'container',
self.accounts.append(str(claim_config_dn))
claim_types_dn = claim_config_dn
- self.assertTrue(claim_types_dn.add_child('CN=Claim Types'))
+ claim_types_dn.add_child('CN=Claim Types')
details = {
'dn': claim_types_dn,
'objectClass': 'msDS-ClaimTypes',
samdb = self.get_samdb()
claim_dn = self.get_claim_types_dn()
- self.assertTrue(claim_dn.add_child(f'CN={claim_id}'))
+ claim_dn.add_child(f'CN={claim_id}')
details = {
'dn': claim_dn,