mirror of
https://github.com/samba-team/samba.git
synced 2025-08-03 04:22:09 +03:00
Python: Simplify code in a couple of places. Copy Andrew's changes from g53b5166.
(This used to be commit f056f62495
)
This commit is contained in:
@ -112,15 +112,15 @@ class Ldb(ldb.Ldb):
|
|||||||
for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES",
|
for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES",
|
||||||
"@OPTIONS", "@PARTITION", "@KLUDGEACL"]:
|
"@OPTIONS", "@PARTITION", "@KLUDGEACL"]:
|
||||||
try:
|
try:
|
||||||
self.delete(ldb.Dn(self, attr))
|
self.delete(attr)
|
||||||
except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _):
|
except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _):
|
||||||
# Ignore missing dn errors
|
# Ignore missing dn errors
|
||||||
pass
|
pass
|
||||||
|
|
||||||
basedn = ldb.Dn(self, "")
|
basedn = ""
|
||||||
# and the rest
|
# and the rest
|
||||||
for msg in self.search(basedn, ldb.SCOPE_SUBTREE,
|
for msg in self.search(basedn, ldb.SCOPE_SUBTREE,
|
||||||
"(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))",
|
"(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
|
||||||
["dn"]):
|
["dn"]):
|
||||||
try:
|
try:
|
||||||
self.delete(msg.dn)
|
self.delete(msg.dn)
|
||||||
@ -128,12 +128,12 @@ class Ldb(ldb.Ldb):
|
|||||||
# Ignor eno such object errors
|
# Ignor eno such object errors
|
||||||
pass
|
pass
|
||||||
|
|
||||||
res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"])
|
res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(distinguishedName=*))(!(distinguisedName=@BASEINFO)))", ["dn"])
|
||||||
assert len(res) == 0
|
assert len(res) == 0
|
||||||
|
|
||||||
def erase_partitions(self):
|
def erase_partitions(self):
|
||||||
"""Erase an ldb, removing all records."""
|
"""Erase an ldb, removing all records."""
|
||||||
res = self.search(ldb.Dn(self, ""), ldb.SCOPE_BASE, "(objectClass=*)",
|
res = self.search("", ldb.SCOPE_BASE, "(objectClass=*)",
|
||||||
["namingContexts"])
|
["namingContexts"])
|
||||||
assert len(res) == 1
|
assert len(res) == 1
|
||||||
if not "namingContexts" in res[0]:
|
if not "namingContexts" in res[0]:
|
||||||
@ -145,7 +145,7 @@ class Ldb(ldb.Ldb):
|
|||||||
k = 0
|
k = 0
|
||||||
while ++k < 10 and (previous_remaining != current_remaining):
|
while ++k < 10 and (previous_remaining != current_remaining):
|
||||||
# and the rest
|
# and the rest
|
||||||
res2 = self.search(ldb.Dn(self, basedn), ldb.SCOPE_SUBTREE, "(|(objectclass=*)(dn=*))", ["dn"])
|
res2 = self.search(basedn, ldb.SCOPE_SUBTREE, "(|(objectclass=*)(distinguishedName=*))", ["distinguishedName"])
|
||||||
previous_remaining = current_remaining
|
previous_remaining = current_remaining
|
||||||
current_remaining = len(res2)
|
current_remaining = len(res2)
|
||||||
for msg in res2:
|
for msg in res2:
|
||||||
|
@ -20,7 +20,7 @@ import samba
|
|||||||
from samba import Ldb, substitute_var, valid_netbios_name
|
from samba import Ldb, substitute_var, valid_netbios_name
|
||||||
from samba.samdb import SamDB
|
from samba.samdb import SamDB
|
||||||
import security
|
import security
|
||||||
from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
|
from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
|
||||||
LDB_ERR_NO_SUCH_OBJECT, timestring, CHANGETYPE_MODIFY, CHANGETYPE_NONE
|
LDB_ERR_NO_SUCH_OBJECT, timestring, CHANGETYPE_MODIFY, CHANGETYPE_NONE
|
||||||
|
|
||||||
"""Functions for setting up a Samba configuration."""
|
"""Functions for setting up a Samba configuration."""
|
||||||
@ -64,7 +64,7 @@ def install_ok(lp, session_info, credentials):
|
|||||||
return False
|
return False
|
||||||
ldb = Ldb(lp.get("sam database"), session_info=session_info,
|
ldb = Ldb(lp.get("sam database"), session_info=session_info,
|
||||||
credentials=credentials, lp=lp)
|
credentials=credentials, lp=lp)
|
||||||
if len(ldb.search(ldb.Dn("(cn=Administrator)"))) != 1:
|
if len(ldb.search("(cn=Administrator)")) != 1:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -766,9 +766,9 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
|
|||||||
samdb = SamDB(paths.samdb, session_info=session_info,
|
samdb = SamDB(paths.samdb, session_info=session_info,
|
||||||
credentials=credentials, lp=lp)
|
credentials=credentials, lp=lp)
|
||||||
|
|
||||||
domainguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID")
|
domainguid = samdb.searchone(domaindn, "objectGUID")
|
||||||
assert isinstance(domainguid, str)
|
assert isinstance(domainguid, str)
|
||||||
hostguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID",
|
hostguid = samdb.searchone(domaindn, "objectGUID",
|
||||||
expression="(&(objectClass=computer)(cn=%s))" % hostname,
|
expression="(&(objectClass=computer)(cn=%s))" % hostname,
|
||||||
scope=SCOPE_SUBTREE)
|
scope=SCOPE_SUBTREE)
|
||||||
assert isinstance(hostguid, str)
|
assert isinstance(hostguid, str)
|
||||||
|
@ -60,7 +60,7 @@ description: %s
|
|||||||
:param sid: SID of the NT-side of the mapping.
|
:param sid: SID of the NT-side of the mapping.
|
||||||
:param unixname: Unix name to map to.
|
:param unixname: Unix name to map to.
|
||||||
"""
|
"""
|
||||||
res = self.search(ldb.Dn(self, domaindn), ldb.SCOPE_SUBTREE,
|
res = self.search(domaindn, ldb.SCOPE_SUBTREE,
|
||||||
"objectSid=%s" % sid, ["dn"])
|
"objectSid=%s" % sid, ["dn"])
|
||||||
assert len(res) == 1, "Failed to find record for objectSid %s" % sid
|
assert len(res) == 1, "Failed to find record for objectSid %s" % sid
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ userAccountControl: %u
|
|||||||
res = self.search("", SCOPE_BASE, "defaultNamingContext=*",
|
res = self.search("", SCOPE_BASE, "defaultNamingContext=*",
|
||||||
["defaultNamingContext"])
|
["defaultNamingContext"])
|
||||||
assert(len(res) == 1 and res[0].defaultNamingContext is not None)
|
assert(len(res) == 1 and res[0].defaultNamingContext is not None)
|
||||||
domain_dn = res[0].defaultNamingContext
|
domain_dn = res[0]["defaultNamingContext"][0]
|
||||||
assert(domain_dn is not None)
|
assert(domain_dn is not None)
|
||||||
dom_users = self.searchone(domain_dn, "dn", "name=Domain Users")
|
dom_users = self.searchone(domain_dn, "dn", "name=Domain Users")
|
||||||
assert(dom_users is not None)
|
assert(dom_users is not None)
|
||||||
|
Reference in New Issue
Block a user