本文整理汇总了Python中ldap.RES_SEARCH_ENTRY属性的典型用法代码示例。如果您正苦于以下问题:Python ldap.RES_SEARCH_ENTRY属性的具体用法?Python ldap.RES_SEARCH_ENTRY怎么用?Python ldap.RES_SEARCH_ENTRY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ldap
的用法示例。
在下文中一共展示了ldap.RES_SEARCH_ENTRY属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __ldap_getgid
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def __ldap_getgid(self, cn="员工"):
"""
查询 组cn对应的gid
:param cn: 组cn
:return: 对应cn的gidNumber
"""
obj = self.ldapconn
obj.protocal_version = ldap.VERSION3
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
searchFilter = "cn=" + cn
try:
ldap_result_id = obj.search(
base="%s" % self.base_dn,
scope=searchScope,
filterstr=searchFilter,
attrlist=retrieveAttributes
)
result_type, result_data = obj.result(ldap_result_id, 0)
if result_type == ldap.RES_SEARCH_ENTRY:
return result_data[0][1].get('gidNumber')[0]
else:
return None
except ldap.LDAPError as e:
logger.error('获取gid失败,原因为: %s' % str(e))
示例2: ldap_search_dn
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def ldap_search_dn(self,uid=None):
obj = self.ldapconn
obj.protocal_version = ldap.VERSION3
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
searchFilter = "cn=" + uid
try:
ldap_result_id = obj.search(self.base_dn, searchScope, searchFilter, retrieveAttributes)
result_type, result_data = obj.result(ldap_result_id, 0)
#返回数据格式
#('cn=django,ou=users,dc=gccmx,dc=cn',
# { 'objectClass': ['inetOrgPerson', 'top'],
# 'userPassword': ['{MD5}lueSGJZetyySpUndWjMBEg=='],
# 'cn': ['django'], 'sn': ['django'] } )
#
if result_type == ldap.RES_SEARCH_ENTRY:
#dn = result[0][0]
return result_data[0][0]
else:
return None
except ldap.LDAPError, e:
print e
#查询用户记录,返回需要的信息
示例3: ldap_get_user
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def ldap_get_user(self,uid=None):
obj = self.ldapconn
obj.protocal_version = ldap.VERSION3
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
searchFilter = "cn=" + uid
try:
ldap_result_id = obj.search(self.base_dn, searchScope, searchFilter, retrieveAttributes)
result_type, result_data = obj.result(ldap_result_id, 0)
if result_type == ldap.RES_SEARCH_ENTRY:
username = result_data[0][1]['cn'][0]
email = result_data[0][1]['mail'][0]
nick = result_data[0][1]['sn'][0]
result = {'username':username,'email':email,'nick':nick}
return result
else:
return None
except ldap.LDAPError, e:
print e
#用户验证,根据传递来的用户名和密码,搜索LDAP,返回boolean值
示例4: _results
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def _results(self, connection, msgid):
"""
Returns the result of a previous asynchronous query.
"""
try:
kind, results = connection.result(msgid)
if kind not in (ldap.RES_SEARCH_ENTRY, ldap.RES_SEARCH_RESULT):
results = []
except ldap.LDAPError as e:
results = []
logger.error("result({}) raised {}".format(msgid, pprint.pformat(e)))
return self._process_results(results)
示例5: _get_ldap_search_results
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def _get_ldap_search_results(self, connection, username, criteria, result_id, current_ref_hop):
"""
The '_get_ldap_search_results()' returns the result of parsing a LDAP tree.
Internally, this calls 'result' method of the LDAPObject.
That method returns a tuple which has following two parameters.
* r_type: This value can be one of the following three values
- RES_SEARCH_ENTRY : describes that the 'r_type' has a LDAP entry
- RES_SEARCH_REFERENCE : describes that the 'r_type' has a referral information
- RES_SEARCH_RESULT : describes the end of this search
* r_data: A contents of search response
There is a similar metho to parse LDAP tree that is 'search()'.
But that method can't get the type information which is described 'r_type' in here.
Therefore, this method parses LDAP tree by calling 'result()' method recursively.
"""
results = []
r_type = None
while r_type != ldap.RES_SEARCH_RESULT:
r_type, r_data = connection.result(result_id, all=0)
if r_type == ldap.RES_SEARCH_ENTRY:
results.append(self._get_ldap_search_entry(r_data))
elif self._chase_referrals and r_type == ldap.RES_SEARCH_REFERENCE:
_results = self._get_ldap_search_referral(r_data,
username,
criteria,
current_ref_hop)
if _results:
results.append(_results)
return results
示例6: get_ldap_search_resultset
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def get_ldap_search_resultset(base_dn, group_query, ldapobject, scope=ldap.SCOPE_SUBTREE):
"""This function will return a query result set."""
result_set = []
result_id = ldapobject.search(base_dn, scope, group_query)
while 1:
result_type, result_data = ldapobject.result(result_id, 0)
if (result_type == ldap.RES_SEARCH_ENTRY):
result_set.append(result_data)
elif (result_type == ldap.RES_SEARCH_RESULT):
break
return result_set
# get_ldap_search_resultset()
示例7: ldap_search
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def ldap_search(self, searchFilter, baseDN):
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
try:
conn = self.ldap_init_conn()
if Setting().get('ldap_type') == 'ad':
conn.simple_bind_s(
"{0}@{1}".format(self.username,
Setting().get('ldap_domain')),
self.password)
else:
conn.simple_bind_s(Setting().get('ldap_admin_username'),
Setting().get('ldap_admin_password'))
ldap_result_id = conn.search(baseDN, searchScope, searchFilter,
retrieveAttributes)
result_set = []
while 1:
result_type, result_data = conn.result(ldap_result_id, 0)
if (result_data == []):
break
else:
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
return result_set
except ldap.LDAPError as e:
current_app.logger.error(e)
current_app.logger.debug('baseDN: {0}'.format(baseDN))
current_app.logger.debug(traceback.format_exc())
示例8: ldap_search_dn
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def ldap_search_dn(self, value=None, value_type='uid'):
"""
# 根据表单提交的用户名,检索该用户的dn,一条dn就相当于数据库里的一条记录。
# 在ldap里类似cn=username,ou=users,dc=gccmx,dc=cn,验证用户密码,必须先检索出该DN
:param value: 用户 uid或 组cn
:param value_type: 用户 uid|cn
:return: search result
"""
obj = self.ldapconn
obj.protocal_version = ldap.VERSION3
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
if value_type == 'cn':
searchFilter = "cn=" + value
else:
searchFilter = "uid=" + value
try:
ldap_result_id = obj.search(
base=self.base_dn,
scope=searchScope,
filterstr=searchFilter,
attrlist=retrieveAttributes
)
result_type, result_data = obj.result(ldap_result_id, 0)
if result_type == ldap.RES_SEARCH_ENTRY:
return result_data
else:
return None
except ldap.LDAPError as e:
logger.error('ldap search %s 失败,原因为: %s' % (value, str(e)))
示例9: __get_max_uidNumber
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import RES_SEARCH_ENTRY [as 别名]
def __get_max_uidNumber(self):
"""
查询 当前最大的uid,这个是在添加用户时,用于自增uid
:param: None
:return: max uidNumber
"""
obj = self.ldapconn
obj.protocal_version = ldap.VERSION3
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = ['uidNumber']
searchFilter = "uid=*"
try:
ldap_result = obj.search(
base="%s" % self.base_dn,
scope=searchScope,
filterstr=searchFilter,
attrlist=retrieveAttributes
)
print(ldap_result)
result_set = []
while True:
result_type, result_data = obj.result(ldap_result, 0)
if not result_data:
break
else:
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(int(result_data[0][1].get('uidNumber')[0]))
return max(result_set) + 1
except ldap.LDAPError as e:
logger.error('获取最大uid失败,原因为: %s' % str(e))