本文整理汇总了Python中samba.Ldb.searchone方法的典型用法代码示例。如果您正苦于以下问题:Python Ldb.searchone方法的具体用法?Python Ldb.searchone怎么用?Python Ldb.searchone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类samba.Ldb
的用法示例。
在下文中一共展示了Ldb.searchone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_tdb_copy
# 需要导入模块: from samba import Ldb [as 别名]
# 或者: from samba.Ldb import searchone [as 别名]
def test_tdb_copy(self):
src_ldb_file = os.path.join(self.tempdir, "source.ldb")
dst_ldb_file = os.path.join(self.tempdir, "destination.ldb")
# Create LDB source file with some content
src_ldb = Ldb(src_ldb_file)
src_ldb.add({"dn": "f=dc", "b": "bla"})
# Copy source file to destination file and check return status
self.assertIsNone(tdb_copy(src_ldb_file, dst_ldb_file))
# Load copied file as LDB object
dst_ldb = Ldb(dst_ldb_file)
# Copmare contents of files
self.assertEqual(
src_ldb.searchone(basedn=ldb.Dn(src_ldb, "f=dc"), attribute="b"),
dst_ldb.searchone(basedn=ldb.Dn(dst_ldb, "f=dc"), attribute="b")
)
# Clean up
del src_ldb
del dst_ldb
os.unlink(src_ldb_file)
os.unlink(dst_ldb_file)
示例2: guess_names_from_smbconf
# 需要导入模块: from samba import Ldb [as 别名]
# 或者: from samba.Ldb import searchone [as 别名]
def guess_names_from_smbconf(lp, creds=None, firstorg=None, firstou=None):
"""Guess configuration settings to use from smb.conf.
:param lp: Loadparm context.
:param firstorg: OpenChange Organization Name
:param firstou: OpenChange Administrative Group
"""
netbiosname = lp.get("netbios name")
hostname = netbiosname.lower()
dnsdomain = lp.get("realm")
dnsdomain = dnsdomain.lower()
serverrole = lp.get("server role")
# Note: "server role" can have many forms, even for the same function:
# "member server", "domain controller", "active directory domain
# controller"...
if "domain controller" in serverrole or serverrole == "member server":
domain = lp.get("workgroup")
domaindn = "DC=" + dnsdomain.replace(".", ",DC=")
else:
domain = netbiosname
domaindn = "CN=" + netbiosname
rootdn = domaindn
configdn = "CN=Configuration," + rootdn
schemadn = "CN=Schema," + configdn
sitename = DEFAULTSITE
names = ProvisionNames()
names.serverrole = serverrole
names.rootdn = rootdn
names.domaindn = domaindn
names.configdn = configdn
names.schemadn = schemadn
names.dnsdomain = dnsdomain
names.domain = domain
names.netbiosname = netbiosname
names.hostname = hostname
names.sitename = sitename
db = Ldb(url=get_ldb_url(lp, creds, names), session_info=system_session(),
credentials=creds, lp=lp)
exchangedn = 'CN=Microsoft Exchange,CN=Services,%s' % configdn
if not firstorg:
firstorg = db.searchone(
'name', exchangedn, '(objectclass=msExchOrganizationContainer)',
ldb.SCOPE_SUBTREE)
assert(firstorg)
firstorgdn = "CN=%s,%s" % (firstorg, exchangedn)
if not firstou:
firstou = db.searchone(
'name', firstorgdn,
'(&(objectclass=msExchAdminGroup)(msExchDefaultAdminGroup=TRUE))',
ldb.SCOPE_SUBTREE)
assert(firstou)
names.firstorg = firstorg
names.firstou = firstou
names.firstorgdn = firstorgdn
names.serverdn = "CN=%s,CN=Servers,CN=%s,CN=Sites,%s" % (netbiosname, sitename, configdn)
# OpenChange dispatcher DB names
names.ocserverdn = "CN=%s,%s" % (names.netbiosname, names.domaindn)
names.ocfirstorg = firstorg
names.ocfirstorgdn = "CN=%s,CN=%s,%s" % (firstou, names.ocfirstorg, names.ocserverdn)
return names