mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
python/sites: Rework site DN construction
This new routine is safe against escape characters and works against Windows 2012R2. The dn= filter in the old code was samba-specific. Andrew Bartlett Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
This commit is contained in:
parent
dbcb13cb05
commit
12813ea555
@ -18,7 +18,7 @@
|
|||||||
"""Manipulating sites."""
|
"""Manipulating sites."""
|
||||||
|
|
||||||
import ldb
|
import ldb
|
||||||
from ldb import FLAG_MOD_ADD
|
from ldb import FLAG_MOD_ADD, LdbError
|
||||||
|
|
||||||
|
|
||||||
class SiteException(Exception):
|
class SiteException(Exception):
|
||||||
@ -92,17 +92,27 @@ def delete_site(samdb, configDn, siteName):
|
|||||||
:raise SiteServerNotEmpty: if the site has still servers in it.
|
:raise SiteServerNotEmpty: if the site has still servers in it.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
dnsites = ldb.Dn(samdb, "CN=Sites,%s" % (str(configDn)))
|
dnsite = ldb.Dn(samdb, "CN=Sites")
|
||||||
dnsite = ldb.Dn(samdb, "Cn=%s,CN=Sites,%s" % (siteName, str(configDn)))
|
if dnsite.add_base(configDn) == False:
|
||||||
dnserver = ldb.Dn(samdb, "Cn=Servers,%s" % str(dnsite))
|
raise SiteException("dnsites.add_base() failed")
|
||||||
|
if dnsite.add_child("CN=X") == False:
|
||||||
|
raise SiteException("dnsites.add_child() failed")
|
||||||
|
dnsite.set_component(0, "CN", siteName)
|
||||||
|
|
||||||
ret = samdb.search(base=dnsites, scope=ldb.SCOPE_ONELEVEL,
|
dnservers = ldb.Dn(samdb, "CN=Servers")
|
||||||
expression='(dn=%s)' % str(dnsite))
|
dnservers.add_base(dnsite)
|
||||||
if len(ret) != 1:
|
|
||||||
raise SiteNotFoundException('Site %s does not exist' % siteName)
|
|
||||||
|
|
||||||
ret = samdb.search(base=dnserver, scope=ldb.SCOPE_ONELEVEL,
|
try:
|
||||||
expression='(objectclass=server)')
|
ret = samdb.search(base=dnsite, scope=ldb.SCOPE_BASE,
|
||||||
|
expression="objectClass=site")
|
||||||
|
if len(ret) != 1:
|
||||||
|
raise SiteNotFoundException('Site %s does not exist' % siteName)
|
||||||
|
except LdbError as (enum, estr):
|
||||||
|
if enum == ldb.ERR_NO_SUCH_OBJECT:
|
||||||
|
raise SiteNotFoundException('Site %s does not exist' % siteName)
|
||||||
|
|
||||||
|
ret = samdb.search(base=dnservers, scope=ldb.SCOPE_ONELEVEL,
|
||||||
|
expression='(objectclass=server)')
|
||||||
if len(ret) != 0:
|
if len(ret) != 0:
|
||||||
raise SiteServerNotEmptyException('Site %s still has servers in it, move them before removal' % siteName)
|
raise SiteServerNotEmptyException('Site %s still has servers in it, move them before removal' % siteName)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user