本文整理汇总了Python中ldap.SCOPE_BASE属性的典型用法代码示例。如果您正苦于以下问题:Python ldap.SCOPE_BASE属性的具体用法?Python ldap.SCOPE_BASE怎么用?Python ldap.SCOPE_BASE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ldap
的用法示例。
在下文中一共展示了ldap.SCOPE_BASE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exact
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def exact(self):
try:
results = self.connection.search_s(
self.dn, ldap.SCOPE_BASE, attrlist=[self.name])
except ldap.LDAPError:
e = get_exception()
self.module.fail_json(
msg="Cannot search for attribute %s" % self.name,
details=str(e))
current = results[0][1].get(self.name, [])
modlist = []
if frozenset(self.values) != frozenset(current):
if len(current) == 0:
modlist = [(ldap.MOD_ADD, self.name, self.values)]
elif len(self.values) == 0:
modlist = [(ldap.MOD_DELETE, self.name, None)]
else:
modlist = [(ldap.MOD_REPLACE, self.name, self.values)]
return modlist
示例2: getDefaultNamingContext
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def getDefaultNamingContext(self):
try:
newCon = ldap.initialize('ldap://{}'.format(self.dc_ip))
newCon.simple_bind_s('', '')
res = newCon.search_s("", ldap.SCOPE_BASE, '(objectClass=*)')
rootDSE = res[0][1]
except ldap.LDAPError as e:
print("[!] Error retrieving the root DSE")
print("[!] {}".format(e))
sys.exit(1)
if 'defaultNamingContext' not in rootDSE:
print("[!] No defaultNamingContext found!")
sys.exit(1)
defaultNamingContext = rootDSE['defaultNamingContext'][0].decode()
self.domainBase = defaultNamingContext
newCon.unbind()
return defaultNamingContext
示例3: _ldap_user_search_with_rdn
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _ldap_user_search_with_rdn(self, conn, username_or_email, user_search_dn, suffix=""):
query = "(|({0}={2}{3})({1}={2}{3}))".format(
self._uid_attr, self._email_attr, escape_filter_chars(username_or_email), suffix
)
query = self._add_user_filter(query)
logger.debug("Conducting user search: %s under %s", query, user_search_dn)
try:
return (conn.search_s(user_search_dn, ldap.SCOPE_SUBTREE, query), None)
except ldap.REFERRAL as re:
referral_dn = self._get_ldap_referral_dn(re)
if not referral_dn:
return (None, "Failed to follow referral when looking up username")
try:
subquery = "(%s=%s)" % (self._uid_attr, username_or_email)
subquery = self._add_user_filter(subquery)
return (conn.search_s(referral_dn, ldap.SCOPE_BASE, subquery), None)
except ldap.LDAPError:
logger.debug("LDAP referral search exception")
return (None, "Username not found")
except ldap.LDAPError:
logger.debug("LDAP search exception")
return (None, "Username not found")
示例4: _get_fqdn
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _get_fqdn(self):
self._log.debug('Grabbing FQDN from LDAP')
results = self._search(
'cn=config',
'(objectClass=*)',
['nsslapd-localhost'],
scope=ldap.SCOPE_BASE
)
if not results and type(results) is not list:
r = None
else:
dn, attrs = results[0]
r = attrs['nsslapd-localhost'][0].decode('utf-8')
self._log.debug(r)
return r
示例5: _get_context
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _get_context(self):
self._log.debug('Grabbing default context from LDAP')
results = self._search(
'cn=config',
'(objectClass=*)',
['nsslapd-defaultnamingcontext'],
scope=ldap.SCOPE_BASE
)
if not results and type(results) is not list:
r = None
else:
dn, attrs = results[0]
r = attrs['nsslapd-defaultnamingcontext'][0].decode('utf-8')
self._log.debug(r)
return r
示例6: _count_users
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _count_users(self, user_base):
self._log.debug('Counting %s users...' % user_base)
results = self._search(
getattr(self, '_%s_user_base' % user_base),
'(objectClass=*)',
['numSubordinates'],
scope=ldap.SCOPE_BASE
)
if not results and type(results) is not list:
r = 0
else:
dn, attrs = results[0]
r = attrs['numSubordinates'][0].decode('utf-8')
self._log.debug(r)
return r
示例7: _anon_bind
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _anon_bind(self):
self._log.debug('Checking for anonymous bind...')
results = self._search(
'cn=config',
'(objectClass=*)',
['nsslapd-allow-anonymous-access'],
scope=ldap.SCOPE_BASE
)
dn, attrs = results[0]
state = attrs['nsslapd-allow-anonymous-access'][0].decode('utf-8')
if state in ['on', 'off', 'rootdse']:
r = str(state).upper()
else:
r = 'ERROR'
self._log.debug(r)
return r
示例8: _load_user_attrs
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _load_user_attrs(self):
if self.dn is not None:
search = LDAPSearch(
self.dn, ldap.SCOPE_BASE, attrlist=self.settings.USER_ATTRLIST
)
results = search.execute(self.connection)
if results is not None and len(results) > 0:
self._user_attrs = results[0][1]
示例9: test_populate_with_attrlist
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def test_populate_with_attrlist(self, mock):
self._init_settings(
USER_DN_TEMPLATE="uid=%(user)s,ou=people,o=test",
USER_ATTR_MAP={"first_name": "givenName", "last_name": "sn"},
USER_ATTRLIST=["*", "+"],
)
user = authenticate(username="alice", password="password")
self.assertEqual(user.username, "alice")
# lookup user attrs
mock.assert_called_once_with(
"uid=alice,ou=people,o=test", ldap.SCOPE_BASE, "(objectClass=*)", ["*", "+"]
)
示例10: _scope_to_ldap_option
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _scope_to_ldap_option(self, scope):
"""
Transform scope string into ldap module constant.
"""
if 'base' in scope.lower():
opt = ldap.SCOPE_BASE
elif 'onelevel' in scope.lower():
opt = ldap.SCOPE_ONELEVEL
else:
opt = ldap.SCOPE_SUBTREE
return opt
示例11: get_profile
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def get_profile(self, uid, password):
c = self.connect()
ldap_result = c.search_s(self.get_user_dn(uid), ldap.SCOPE_BASE)[0][1]
profile = {}
profile['uid'] = ldap_result['uid'][0]
profile['name'] = ldap_result['displayName'][0].decode('utf-8')
profile['email'] = ldap_result['mail'][0]
profile['picture'] = ldap_result['jpegPhoto'][0] if ('jpegPhoto' in ldap_result and
ldap_result['jpegPhoto']) else None
c.unbind()
return profile
示例12: getDefaultNamingContext
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def getDefaultNamingContext(self):
try:
newCon = ldap.initialize('ldap://{}'.format(self.dc_ip))
newCon.simple_bind_s('','')
res = newCon.search_s("", ldap.SCOPE_BASE, '(objectClass=*)')
rootDSE = res[0][1]
except ldap.LDAPError, e:
print "[!] Error retrieving the root DSE"
print "[!] {}".format(e)
sys.exit(1)
示例13: getFunctionalityLevel
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def getFunctionalityLevel(self):
objectFilter = '(objectclass=*)'
attrs = ['domainFunctionality', 'forestFunctionality', 'domainControllerFunctionality']
try:
# rawFunctionality = self.do_ldap_query('', ldap.SCOPE_BASE, objectFilter, attrs)
rawData = self.con.search_s('', ldap.SCOPE_BASE, "(objectclass=*)", attrs)
functionalityLevels = rawData[0][1]
except Error, e:
print "[!] Error retrieving functionality level"
print "[!] {}".format(e)
sys.exit(1)
示例14: getFunctionalityLevel
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def getFunctionalityLevel(self):
objectFilter = '(objectclass=*)'
attrs = ['domainFunctionality', 'forestFunctionality', 'domainControllerFunctionality']
try:
# rawFunctionality = self.do_ldap_query('', ldap.SCOPE_BASE, objectFilter, attrs)
rawData = self.con.search_s('', ldap.SCOPE_BASE, "(objectclass=*)", attrs)
functionalityLevels = rawData[0][1]
except Error as e:
print("[!] Error retrieving functionality level")
print("[!] {}".format(e))
sys.exit(1)
return functionalityLevels
示例15: _find_pubkeys
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _find_pubkeys(self, dn):
conf = self.conf
result = self._conn.search_s(
dn, ldap.SCOPE_BASE, attrlist=[conf.pubkey_attr])
return map(_decode, result[0][1].get(conf.pubkey_attr, []))