本文整理汇总了Python中samba.Ldb.add方法的典型用法代码示例。如果您正苦于以下问题:Python Ldb.add方法的具体用法?Python Ldb.add怎么用?Python Ldb.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类samba.Ldb
的用法示例。
在下文中一共展示了Ldb.add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_tdb_copy
# 需要导入模块: from samba import Ldb [as 别名]
# 或者: from samba.Ldb import add [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: delta_update_basesamdb
# 需要导入模块: from samba import Ldb [as 别名]
# 或者: from samba.Ldb import add [as 别名]
def delta_update_basesamdb(refsampath, sampath, creds, session, lp, message):
"""Update the provision container db: sam.ldb
This function is aimed for alpha9 and newer;
:param refsampath: Path to the samdb in the reference provision
:param sampath: Path to the samdb in the upgraded provision
:param creds: Credential used for openning LDB files
:param session: Session to use for openning LDB files
:param lp: A loadparam object
:return: A msg_diff object with the difference between the @ATTRIBUTES
of the current provision and the reference provision
"""
message(SIMPLE,
"Update base samdb by searching difference with reference one")
refsam = Ldb(refsampath, session_info=session, credentials=creds,
lp=lp, options=["modules:"])
sam = Ldb(sampath, session_info=session, credentials=creds, lp=lp,
options=["modules:"])
empty = ldb.Message()
deltaattr = None
reference = refsam.search(expression="")
for refentry in reference:
entry = sam.search(expression="distinguishedName=%s" % refentry["dn"],
scope=SCOPE_SUBTREE)
if not len(entry):
delta = sam.msg_diff(empty, refentry)
message(CHANGE, "Adding %s to sam db" % str(refentry.dn))
if str(refentry.dn) == "@PROVISION" and\
delta.get(samba.provision.LAST_PROVISION_USN_ATTRIBUTE):
delta.remove(samba.provision.LAST_PROVISION_USN_ATTRIBUTE)
delta.dn = refentry.dn
sam.add(delta)
else:
delta = sam.msg_diff(entry[0], refentry)
if str(refentry.dn) == "@ATTRIBUTES":
deltaattr = sam.msg_diff(refentry, entry[0])
if str(refentry.dn) == "@PROVISION" and\
delta.get(samba.provision.LAST_PROVISION_USN_ATTRIBUTE):
delta.remove(samba.provision.LAST_PROVISION_USN_ATTRIBUTE)
if len(delta.items()) > 1:
delta.dn = refentry.dn
sam.modify(delta)
return deltaattr
示例3: MapTestCase
# 需要导入模块: from samba import Ldb [as 别名]
# 或者: from samba.Ldb import add [as 别名]
class MapTestCase(MapBaseTestCase):
def setUp(self):
super(MapTestCase, self).setUp()
ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
ldb.set_opaque("skip_allocate_sids", "true");
ldif = read_datafile("provision_samba3sam.ldif")
ldb.add_ldif(self.samba4.subst(ldif))
self.setup_modules(ldb, self.samba3, self.samba4)
del ldb
self.ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
self.ldb.set_opaque("skip_allocate_sids", "true");
def test_map_search(self):
"""Running search tests on mapped data."""
self.samba3.db.add({
"dn": "sambaDomainName=TESTS," + self.samba3.basedn,
"objectclass": ["sambaDomain", "top"],
"sambaSID": "S-1-5-21-4231626423-2410014848-2360679739",
"sambaNextRid": "2000",
"sambaDomainName": "TESTS"
})
# Add a set of split records
self.ldb.add_ldif("""
dn: """+ self.samba4.dn("cn=Domain Users") + """
objectClass: group
cn: Domain Users
objectSid: S-1-5-21-4231626423-2410014848-2360679739-513
""")
# Add a set of split records
self.ldb.add_ldif("""
dn: """+ self.samba4.dn("cn=X") + """
objectClass: user
cn: X
codePage: x
revision: x
dnsHostName: x
nextRid: y
lastLogon: x
description: x
objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
""")
self.ldb.add({
"dn": self.samba4.dn("cn=Y"),
"objectClass": "top",
"cn": "Y",
"codePage": "x",
"revision": "x",
"dnsHostName": "y",
"nextRid": "y",
"lastLogon": "y",
"description": "x"})
self.ldb.add({
"dn": self.samba4.dn("cn=Z"),
"objectClass": "top",
"cn": "Z",
"codePage": "x",
"revision": "y",
"dnsHostName": "z",
"nextRid": "y",
"lastLogon": "z",
"description": "y"})
# Add a set of remote records
self.samba3.db.add({
"dn": self.samba3.dn("cn=A"),
"objectClass": "posixAccount",
"cn": "A",
"sambaNextRid": "x",
"sambaBadPasswordCount": "x",
"sambaLogonTime": "x",
"description": "x",
"sambaSID": "S-1-5-21-4231626423-2410014848-2360679739-1052",
"sambaPrimaryGroupSID": "S-1-5-21-4231626423-2410014848-2360679739-512"})
self.samba3.db.add({
"dn": self.samba3.dn("cn=B"),
"objectClass": "top",
"cn": "B",
"sambaNextRid": "x",
"sambaBadPasswordCount": "x",
"sambaLogonTime": "y",
"description": "x"})
self.samba3.db.add({
"dn": self.samba3.dn("cn=C"),
"objectClass": "top",
"cn": "C",
"sambaNextRid": "x",
"sambaBadPasswordCount": "y",
"sambaLogonTime": "z",
"description": "y"})
# Testing search by DN
#.........这里部分代码省略.........
示例4: Samba3SamTestCase
# 需要导入模块: from samba import Ldb [as 别名]
# 或者: from samba.Ldb import add [as 别名]
class Samba3SamTestCase(MapBaseTestCase):
def setUp(self):
super(Samba3SamTestCase, self).setUp()
ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
ldb.set_opaque("skip_allocate_sids", "true");
self.samba3.setup_data("samba3.ldif")
ldif = read_datafile("provision_samba3sam.ldif")
ldb.add_ldif(self.samba4.subst(ldif))
self.setup_modules(ldb, self.samba3, self.samba4)
del ldb
self.ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
self.ldb.set_opaque("skip_allocate_sids", "true");
def test_search_non_mapped(self):
"""Looking up by non-mapped attribute"""
msg = self.ldb.search(expression="(cn=Administrator)")
self.assertEquals(len(msg), 1)
self.assertEquals(msg[0]["cn"], "Administrator")
def test_search_non_mapped(self):
"""Looking up by mapped attribute"""
msg = self.ldb.search(expression="(name=Backup Operators)")
self.assertEquals(len(msg), 1)
self.assertEquals(str(msg[0]["name"]), "Backup Operators")
def test_old_name_of_renamed(self):
"""Looking up by old name of renamed attribute"""
msg = self.ldb.search(expression="(displayName=Backup Operators)")
self.assertEquals(len(msg), 0)
def test_mapped_containing_sid(self):
"""Looking up mapped entry containing SID"""
msg = self.ldb.search(expression="(cn=Replicator)")
self.assertEquals(len(msg), 1)
self.assertEquals(str(msg[0].dn),
"cn=Replicator,ou=Groups,dc=vernstok,dc=nl")
self.assertTrue("objectSid" in msg[0])
self.assertSidEquals("S-1-5-21-4231626423-2410014848-2360679739-1052",
msg[0]["objectSid"])
oc = set(msg[0]["objectClass"])
self.assertEquals(oc, set(["group"]))
def test_search_by_objclass(self):
"""Looking up by objectClass"""
msg = self.ldb.search(expression="(|(objectClass=user)(cn=Administrator))")
self.assertEquals(set([str(m.dn) for m in msg]),
set(["unixName=Administrator,ou=Users,dc=vernstok,dc=nl",
"unixName=nobody,ou=Users,dc=vernstok,dc=nl"]))
def test_s3sam_modify(self):
# Adding a record that will be fallbacked
self.ldb.add({
"dn": "cn=Foo",
"foo": "bar",
"blah": "Blie",
"cn": "Foo",
"showInAdvancedViewOnly": "TRUE"})
# Checking for existence of record (local)
# TODO: This record must be searched in the local database, which is
# currently only supported for base searches
# msg = ldb.search(expression="(cn=Foo)", ['foo','blah','cn','showInAdvancedViewOnly')]
# TODO: Actually, this version should work as well but doesn't...
#
#
msg = self.ldb.search(expression="(cn=Foo)", base="cn=Foo",
scope=SCOPE_BASE,
attrs=['foo','blah','cn','showInAdvancedViewOnly'])
self.assertEquals(len(msg), 1)
self.assertEquals(str(msg[0]["showInAdvancedViewOnly"]), "TRUE")
self.assertEquals(str(msg[0]["foo"]), "bar")
self.assertEquals(str(msg[0]["blah"]), "Blie")
# Adding record that will be mapped
self.ldb.add({"dn": "cn=Niemand,cn=Users,dc=vernstok,dc=nl",
"objectClass": "user",
"unixName": "bin",
"sambaUnicodePwd": "geheim",
"cn": "Niemand"})
# Checking for existence of record (remote)
msg = self.ldb.search(expression="(unixName=bin)",
attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
self.assertEquals(len(msg), 1)
self.assertEquals(str(msg[0]["cn"]), "Niemand")
self.assertEquals(str(msg[0]["sambaUnicodePwd"]), "geheim")
# Checking for existence of record (local && remote)
msg = self.ldb.search(expression="(&(unixName=bin)(sambaUnicodePwd=geheim))",
attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
self.assertEquals(len(msg), 1) # TODO: should check with more records
self.assertEquals(str(msg[0]["cn"]), "Niemand")
self.assertEquals(str(msg[0]["unixName"]), "bin")
self.assertEquals(str(msg[0]["sambaUnicodePwd"]), "geheim")
# Checking for existence of record (local || remote)
msg = self.ldb.search(expression="(|(unixName=bin)(sambaUnicodePwd=geheim))",
attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
#print "got %d replies" % len(msg)
#.........这里部分代码省略.........
示例5: OpenChangeDBWithLdbBackend
# 需要导入模块: from samba import Ldb [as 别名]
# 或者: from samba.Ldb import add [as 别名]
class OpenChangeDBWithLdbBackend(object):
"""The OpenChange database."""
def __init__(self, url):
self.url = url
self.ldb = Ldb(self.url)
self.nttime = samba.unix2nttime(int(time.time()))
def reopen(self):
self.ldb = Ldb(self.url)
def remove(self):
"""Remove an existing OpenChangeDB file."""
if os.path.exists(self.url):
os.remove(self.url)
self.reopen()
def setup(self, names=None):
self.ldb.add_ldif("""
dn: @OPTIONS
checkBaseOnSearch: TRUE
dn: @INDEXLIST
@IDXATTR: cn
dn: @ATTRIBUTES
cn: CASE_INSENSITIVE
dn: CASE_INSENSITIVE
""")
self.reopen()
if names:
self.add_rootDSE(names.ocserverdn, names.firstorg, names.firstou)
def add_rootDSE(self, ocserverdn, firstorg, firstou):
self.ldb.add({"dn": "@ROOTDSE",
"defaultNamingContext": "CN=%s,CN=%s,%s" % (firstou, firstorg, ocserverdn),
"rootDomainNamingContext": ocserverdn,
"vendorName": "OpenChange Team (http://www.openchange.org)"})
def add_server(self, names):
self.ldb.add({"dn": names.ocserverdn,
"objectClass": ["top", "server"],
"cn": names.netbiosname,
"GlobalCount": "1",
"ChangeNumber": "1",
"ReplicaID": "1"})
self.ldb.add({"dn": "CN=%s,%s" % (names.firstorg, names.ocserverdn),
"objectClass": ["top", "org"],
"cn": names.firstorg})
self.ldb.add({"dn": "CN=%s,CN=%s,%s" % (names.firstou, names.firstorg, names.ocserverdn),
"objectClass": ["top", "ou"],
"cn": names.firstou})
def add_root_public_folder(self, dn, fid, change_num, SystemIdx, childcount):
self.ldb.add({"dn": dn,
"objectClass": ["publicfolder"],
"cn": fid,
"PidTagFolderId": fid,
"PidTagChangeNumber": change_num,
"PidTagDisplayName": "Public Folder Root",
"PidTagCreationTime": "%d" % self.nttime,
"PidTagLastModificationTime": "%d" % self.nttime,
"PidTagSubFolders": str(childcount != 0).upper(),
"PidTagFolderChildCount": str(childcount),
"SystemIdx": str(SystemIdx)})
def add_sub_public_folder(self, dn, parentfid, fid, change_num, name, SystemIndex, childcount):
self.ldb.add({"dn": dn,
"objectClass": ["publicfolder"],
"cn": fid,
"PidTagFolderId": fid,
"PidTagParentFolderId": parentfid,
"PidTagChangeNumber": change_num,
"PidTagDisplayName": name,
"PidTagCreationTime": "%d" % self.nttime,
"PidTagLastModificationTime": "%d" % self.nttime,
"PidTagAttributeHidden": str(0),
"PidTagAttributeReadOnly": str(0),
"PidTagAttributeSystem": str(0),
"PidTagContainerClass": "IPF.Note (check this)",
"PidTagSubFolders": str(childcount != 0).upper(),
"PidTagFolderChildCount": str(childcount),
"FolderType": str(1),
"SystemIdx": str(SystemIndex)})
def add_one_public_folder(self, parent_fid, path, children, SystemIndex, names, dn_prefix = None):
name = path[-1]
GlobalCount = self.get_message_GlobalCount(names.netbiosname)
ChangeNumber = self.get_message_ChangeNumber(names.netbiosname)
ReplicaID = self.get_message_ReplicaID(names.netbiosname)
if dn_prefix is None:
dn_prefix = "CN=publicfolders,CN=%s,CN=%s,%s" % (names.firstou, names.firstorg, names.ocserverdn)
fid = gen_mailbox_folder_fid(GlobalCount, ReplicaID)
dn = "CN=%s,%s" % (fid, dn_prefix)
change_num = gen_mailbox_folder_fid(ChangeNumber, ReplicaID)
childcount = len(children)
print "\t* %-40s: 0x%.16x (%s)" % (name, int(fid, 10), fid)
if parent_fid == 0:
#.........这里部分代码省略.........
示例6: system_session
# 需要导入模块: from samba import Ldb [as 别名]
# 或者: from samba.Ldb import add [as 别名]
opts = parser.parse_args()[0]
lp = sambaopts.get_loadparm()
smbconf = lp.configfile
if not opts.database:
print "Parameter database is mandatory"
sys.exit(1)
creds = credopts.get_credentials(lp)
creds.set_kerberos_state(DONT_USE_KERBEROS)
session = system_session()
empty = ldb.Message()
newname="%s.new"%(opts.database)
if os.path.exists(newname):
os.remove(newname)
old_ldb = Ldb(opts.database, session_info=session, credentials=creds,lp=lp)
new_ldb = Ldb(newname,session_info=session, credentials=creds,lp=lp)
new_ldb.transaction_start()
res = old_ldb.search(expression="(dn=*)",base="", scope=SCOPE_SUBTREE)
for i in range(0,len(res)):
if str(res[i].dn) == "@BASEINFO":
continue
if str(res[i].dn).startswith("@INDEX:"):
continue
delta = new_ldb.msg_diff(empty,res[i])
delta.dn = res[i].dn
delta.remove("distinguishedName")
new_ldb.add(delta)
new_ldb.transaction_commit()