本文整理汇总了Python中samba.Ldb类的典型用法代码示例。如果您正苦于以下问题:Python Ldb类的具体用法?Python Ldb怎么用?Python Ldb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ldb类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
class Target:
"""Simple helper class that contains data for a specific SAM
connection."""
def __init__(self, file, basedn, dn):
self.file = os.path.join(tempdir, file)
self.url = "tdb://" + self.file
self.basedn = basedn
self.substvars = {"BASEDN": self.basedn}
self.db = Ldb(lp=cmdline_loadparm)
self._dn = dn
def dn(self, rdn):
return self._dn(self.basedn, rdn)
def connect(self):
return self.db.connect(self.url)
def setup_data(self, path):
self.add_ldif(read_datafile(path))
def subst(self, text):
return substitute_var(text, self.substvars)
def add_ldif(self, ldif):
self.db.add_ldif(self.subst(ldif))
def modify_ldif(self, ldif):
self.db.modify_ldif(self.subst(ldif))
开发者ID:gojdic,项目名称:samba,代码行数:28,代码来源:samba3sam.py
示例2: __init__
class Target:
"""Simple helper class that contains data for a specific SAM
connection."""
def __init__(self, basedn, dn, lp):
self.db = Ldb(lp=lp, session_info=system_session())
self.basedn = basedn
self.basedn_casefold = ldb.Dn(self.db, basedn).get_casefold()
self.substvars = {"BASEDN": self.basedn}
self.file = os.path.join(tempdir, "%s.ldb" % self.basedn_casefold)
self.url = "tdb://" + self.file
self._dn = dn
def dn(self, rdn):
return self._dn(self.basedn, rdn)
def connect(self):
return self.db.connect(self.url)
def setup_data(self, path):
self.add_ldif(read_datafile(path))
def subst(self, text):
return substitute_var(text, self.substvars)
def add_ldif(self, ldif):
self.db.add_ldif(self.subst(ldif))
def modify_ldif(self, ldif):
self.db.modify_ldif(self.subst(ldif))
开发者ID:Alexandr-Galko,项目名称:samba,代码行数:30,代码来源:samba3sam.py
示例3: autenticacion
def autenticacion(creds, lp):
"""
Cumple con la idea de inyección, así que debería ser testeable
"""
try:
ldap_conn = Ldb('ldap://localhost', lp=lp, credentials=creds)
domain_dn = ldap_conn.get_default_basedn()
search_filter='sAMAccountName={0}'.format(creds.get_username())
# NOTA: No intentes usar searchone para este caso específico. Dn resulta ser una clase no iterable
busqueda = ldap_conn.search(base=domain_dn, scope=SCOPE_SUBTREE, expression=search_filter, attrs=['dn', 'memberOf', 'displayName'])
user_dn = busqueda[0].dn
sesion = user_session(ldap_conn, lp_ctx=lp, dn=user_dn, session_info_flags=session_info_flags)
# Este punto podría ser importante para la idea de login
token = sesion.security_token
except LdbError as e:
log.warning("Error LDB: %s" % e)
return False;
except IndexError as e:
log.warning("El usuario %s no existe" % creds.get_username())
return False;
except Exception as e:
log.warning("Error no contemplado %s " % e)
return False;
return busqueda
开发者ID:VTacius,项目名称:justine,代码行数:30,代码来源:conexion.py
示例4: accountcontrol
def accountcontrol(lp, creds, username=None, value=0):
"""enable/disable an OpenChange user account.
:param lp: Loadparm context
:param creds: Credentials context
:param username: Name of user to disable
:param value: the control value
"""
names = guess_names_from_smbconf(lp, None, None)
db = Ldb(url=os.path.join(lp.get("private dir"), lp.samdb_url()),
session_info=system_session(), credentials=creds, lp=lp)
user_dn = "CN=%s,CN=Users,%s" % (username, names.domaindn)
extended_user = """
dn: %s
changetype: modify
replace: msExchUserAccountControl
msExchUserAccountControl: %d
""" % (user_dn, value)
db.modify_ldif(extended_user)
if value == 2:
print "[+] Account %s disabled" % username
else:
print "[+] Account %s enabled" % username
开发者ID:inverse-inc,项目名称:openchange.old,代码行数:26,代码来源:provision.py
示例5: init
def init(self):
# Check to see that this 'existing' LDAP backend in fact exists
ldapi_db = Ldb(self.ldapi_uri)
ldapi_db.search(base="", scope=SCOPE_BASE,
expression="(objectClass=OpenLDAProotDSE)")
# For now, assume existing backends at least emulate OpenLDAP
self.ldap_backend_type = "openldap"
开发者ID:Alexander--,项目名称:samba,代码行数:8,代码来源:backend.py
示例6: init
def init(self):
#Check to see that this 'existing' LDAP backend in fact exists
ldapi_db = Ldb(self.ldapi_uri, credentials=self.credentials)
search_ol_rootdse = ldapi_db.search(base="", scope=SCOPE_BASE,
expression="(objectClass=OpenLDAProotDSE)")
# If we have got here, then we must have a valid connection to the LDAP server, with valid credentials supplied
# This caused them to be set into the long-term database later in the script.
self.secrets_credentials = self.credentials
self.ldap_backend_type = "openldap" #For now, assume existing backends at least emulate OpenLDAP
开发者ID:endisd,项目名称:samba,代码行数:11,代码来源:provisionbackend.py
示例7: run
def run(self, secret, sambaopts=None, credopts=None, versionopts=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
url = lp.get("secrets database")
secretsdb = Ldb(url=url, session_info=system_session(),
credentials=creds, lp=lp)
result = secretsdb.search(attrs=["secret"],
expression="(&(objectclass=primaryDomain)(samaccountname=%s))" % secret)
if len(result) != 1:
raise CommandError("search returned %d records, expected 1" % len(result))
self.outf.write("%s\n" % result[0]["secret"])
开发者ID:Alexandr-Galko,项目名称:samba,代码行数:14,代码来源:machinepw.py
示例8: newuser
def newuser(lp, creds, username=None):
"""extend user record with OpenChange settings.
:param lp: Loadparm context
:param creds: Credentials context
:param username: Name of user to extend
"""
names = guess_names_from_smbconf(lp, None, None)
db = Ldb(url=get_ldb_url(lp, creds, names), session_info=system_session(),
credentials=creds, lp=lp)
user_dn = get_user_dn(db, "CN=Users,%s" % names.domaindn, username)
if user_dn:
extended_user = """
dn: %(user_dn)s
changetype: modify
add: mailNickName
mailNickname: %(username)s
add: homeMDB
homeMDB: CN=Mailbox Store (%(netbiosname)s),CN=First Storage Group,CN=InformationStore,CN=%(netbiosname)s,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=%(firstorg)s,CN=Microsoft Exchange,CN=Services,CN=Configuration,%(domaindn)s
add: homeMTA
homeMTA: CN=Mailbox Store (%(netbiosname)s),CN=First Storage Group,CN=InformationStore,CN=%(netbiosname)s,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=%(firstorg)s,CN=Microsoft Exchange,CN=Services,CN=Configuration,%(domaindn)s
add: legacyExchangeDN
legacyExchangeDN: /o=%(firstorg)s/ou=First Administrative Group/cn=Recipients/cn=%(username)s
add: proxyAddresses
proxyAddresses: =EX:/o=%(firstorg)s/ou=First Administrative Group/cn=Recipients/cn=%(username)s
proxyAddresses: smtp:[email protected]%(dnsdomain)s
proxyAddresses: X400:c=US;a= ;p=First Organizati;o=Exchange;s=%(username)s
proxyAddresses: SMTP:%(username)[email protected]%(dnsdomain)s
replace: msExchUserAccountControl
msExchUserAccountControl: 0
"""
ldif_value = extended_user % {"user_dn": user_dn,
"username": username,
"netbiosname": names.netbiosname,
"firstorg": names.firstorg,
"domaindn": names.domaindn,
"dnsdomain": names.dnsdomain}
db.modify_ldif(ldif_value)
res = db.search(base=user_dn, scope=SCOPE_BASE, attrs=["*"])
if len(res) == 1:
record = res[0]
else:
raise Exception, \
"this should never happen as we just modified the record..."
record_keys = map(lambda x: x.lower(), record.keys())
if "displayname" not in record_keys:
extended_user = "dn: %s\nadd: displayName\ndisplayName: %s\n" % (user_dn, username)
db.modify_ldif(extended_user)
if "mail" not in record_keys:
extended_user = "dn: %s\nadd: mail\nmail: %[email protected]%s\n" % (user_dn, username, names.dnsdomain)
db.modify_ldif(extended_user)
print "[+] User %s extended and enabled" % username
else:
print "[!] User '%s' not found" % username
开发者ID:0x90shell,项目名称:pth-toolkit,代码行数:59,代码来源:provision.py
示例9: start
def start(self):
from samba.provision import ProvisioningError
self.slapd_command_escaped = "\'" + "\' \'".join(
self.slapd_command) + "\'"
ldap_backend_script = os.path.join(self.ldapdir,
"ldap_backend_startup.sh")
f = open(ldap_backend_script, 'w')
try:
f.write("#!/bin/sh\n" + self.slapd_command_escaped + " [email protected]\n")
finally:
f.close()
os.chmod(ldap_backend_script, 0o755)
# Now start the slapd, so we can provision onto it. We keep the
# subprocess context around, to kill this off at the successful
# end of the script
self.slapd = subprocess.Popen(
self.slapd_provision_command, close_fds=True, shell=False)
count = 0
while self.slapd.poll() is None:
# Wait until the socket appears
try:
time.sleep(1)
ldapi_db = Ldb(
self.ldap_uri, lp=self.lp, credentials=self.credentials)
ldapi_db.search(
base="",
scope=SCOPE_BASE,
expression="(objectClass=OpenLDAProotDSE)")
# If we have got here, then we must have a valid connection to
# the LDAP server!
return
except LdbError:
count = count + 1
if count > 15:
self.logger.error(
"Could not connect to slapd started with: %s" % "\'" +
"\' \'".join(self.slapd_provision_command) + "\'")
raise ProvisioningError(
"slapd never accepted a connection within 15 seconds of starting"
)
self.logger.error("Could not start slapd with: %s" % "\'" +
"\' \'".join(self.slapd_provision_command) + "\'")
raise ProvisioningError(
"slapd died before we could make a connection to it")
开发者ID:sYnfo,项目名称:samba,代码行数:49,代码来源:backend.py
示例10: post_setup
def post_setup(self):
ldapi_db = Ldb(self.ldap_uri, credentials=self.credentials)
# configure in-directory access control on Fedora DS via the aci
# attribute (over a direct ldapi:// socket)
aci = """(targetattr = "*") (version 3.0;acl "full access to all by samba-admin";allow (all)(userdn = "ldap:///CN=samba-admin,%s");)""" % self.sambadn
m = ldb.Message()
m["aci"] = ldb.MessageElement([aci], ldb.FLAG_MOD_REPLACE, "aci")
for dnstring in (self.names.domaindn, self.names.configdn,
self.names.schemadn):
m.dn = ldb.Dn(ldapi_db, dnstring)
ldapi_db.modify(m)
return LDAPBackendResult(self.credentials, self.slapd_command_escaped,
self.ldapdir)
开发者ID:Alexander--,项目名称:samba,代码行数:16,代码来源:backend.py
示例11: __init__
def __init__(self, basedn, dn):
self.db = Ldb(lp=cmdline_loadparm, session_info=system_session())
self.basedn = basedn
self.basedn_casefold = ldb.Dn(self.db, basedn).get_casefold()
self.substvars = {"BASEDN": self.basedn}
self.file = os.path.join(tempdir, "%s.ldb" % self.basedn_casefold)
self.url = "tdb://" + self.file
self._dn = dn
开发者ID:endisd,项目名称:samba,代码行数:8,代码来源:samba3sam.py
示例12: setUp
def setUp(self):
super(MapTestCase, self).setUp()
ldb = Ldb(self.ldburl, lp=cmdline_loadparm, session_info=system_session())
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=cmdline_loadparm, session_info=system_session())
开发者ID:endisd,项目名称:samba,代码行数:8,代码来源:samba3sam.py
示例13: __init__
def __init__(
self,
host,
creds,
lp,
two=False,
quiet=False,
descriptor=False,
sort_aces=False,
verbose=False,
view="section",
base="",
scope="SUB",
outf=sys.stdout,
errf=sys.stderr,
skip_missing_dn=True,
):
ldb_options = []
samdb_url = host
if not "://" in host:
if os.path.isfile(host):
samdb_url = "tdb://%s" % host
else:
samdb_url = "ldap://%s" % host
# use 'paged_search' module when connecting remotely
if samdb_url.lower().startswith("ldap://"):
ldb_options = ["modules:paged_searches"]
self.outf = outf
self.errf = errf
self.ldb = Ldb(url=samdb_url, credentials=creds, lp=lp, options=ldb_options)
self.search_base = base
self.search_scope = scope
self.two_domains = two
self.quiet = quiet
self.descriptor = descriptor
self.sort_aces = sort_aces
self.view = view
self.verbose = verbose
self.host = host
self.skip_missing_dn = skip_missing_dn
self.base_dn = str(self.ldb.get_default_basedn())
self.root_dn = str(self.ldb.get_root_basedn())
self.config_dn = str(self.ldb.get_config_basedn())
self.schema_dn = str(self.ldb.get_schema_basedn())
self.domain_netbios = self.find_netbios()
self.server_names = self.find_servers()
self.domain_name = re.sub("[Dd][Cc]=", "", self.base_dn).replace(",", ".")
self.domain_sid = self.find_domain_sid()
self.get_sid_map()
#
# Log some domain controller specific place-holers that are being used
# when compare content of two DCs. Uncomment for DEBUG purposes.
if self.two_domains and not self.quiet:
self.outf.write("\n* Place-holders for %s:\n" % self.host)
self.outf.write(4 * " " + "${DOMAIN_DN} => %s\n" % self.base_dn)
self.outf.write(4 * " " + "${DOMAIN_NETBIOS} => %s\n" % self.domain_netbios)
self.outf.write(4 * " " + "${SERVER_NAME} => %s\n" % self.server_names)
self.outf.write(4 * " " + "${DOMAIN_NAME} => %s\n" % self.domain_name)
开发者ID:nrensen,项目名称:samba,代码行数:58,代码来源:ldapcmp.py
示例14: __init__
def __init__(self, basedn, dn, lp):
self.db = Ldb(lp=lp, session_info=system_session())
self.db.set_opaque("skip_allocate_sids", "true");
self.basedn = basedn
self.basedn_casefold = ldb.Dn(self.db, basedn).get_casefold()
self.substvars = {"BASEDN": self.basedn}
self.file = os.path.join(tempdir, "%s.ldb" % self.basedn_casefold)
self.url = "tdb://" + self.file
self._dn = dn
开发者ID:encukou,项目名称:samba,代码行数:9,代码来源:samba3sam.py
示例15: setUp
def setUp(self):
super(MapTestCase, self).setUp()
ldb = Ldb(self.ldburl, lp=cmdline_loadparm)
self.templates.setup_data("provision_samba3sam_templates.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=cmdline_loadparm)
开发者ID:gojdic,项目名称:samba,代码行数:9,代码来源:samba3sam.py
示例16: setUp
def setUp(self):
super(Samba3SamTestCase, self).setUp()
ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
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())
开发者ID:Alexandr-Galko,项目名称:samba,代码行数:9,代码来源:samba3sam.py
示例17: setUp
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");
开发者ID:encukou,项目名称:samba,代码行数:10,代码来源:samba3sam.py
示例18: OpenchangeDBWithLDB
class OpenchangeDBWithLDB(OpenchangeDB):
def __init__(self, uri):
self.ldb = Ldb(uri)
def get_calendar_uri(self, usercn, email):
base_dn = "CN=%s,%s" % (usercn, config["samba"]["oc_user_basedn"])
ldb_filter = "(&(objectClass=systemfolder)(PidTagContainerClass=IPF.Appointment)(MAPIStoreURI=*))"
res = self.ldb.search(base=base_dn, scope=ldb.SCOPE_SUBTREE,
expression=ldb_filter, attrs=["MAPIStoreURI"])
return [str(res[x]["MAPIStoreURI"][0]) for x in xrange(len(res))]
开发者ID:ThHirsch,项目名称:openchange,代码行数:10,代码来源:openchangedb.py
示例19: start
def start(self):
self.slapd_command_escaped = "\'" + "\' \'".join(self.slapd_command) + "\'"
open(self.paths.ldapdir + "/ldap_backend_startup.sh", 'w').write("#!/bin/sh\n" + self.slapd_command_escaped + "\n")
# Now start the slapd, so we can provision onto it. We keep the
# subprocess context around, to kill this off at the successful
# end of the script
self.slapd = subprocess.Popen(self.slapd_provision_command, close_fds=True, shell=False)
while self.slapd.poll() is None:
# Wait until the socket appears
try:
ldapi_db = Ldb(self.ldapi_uri, lp=self.lp, credentials=self.credentials)
search_ol_rootdse = ldapi_db.search(base="", scope=SCOPE_BASE,
expression="(objectClass=OpenLDAProotDSE)")
# If we have got here, then we must have a valid connection to the LDAP server!
return
except LdbError, e:
time.sleep(1)
pass
开发者ID:endisd,项目名称:samba,代码行数:20,代码来源:provisionbackend.py
示例20: test_tdb_copy
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)
开发者ID:Alexander--,项目名称:samba,代码行数:25,代码来源:tdb_util.py
注:本文中的samba.Ldb类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论