本文整理匯總了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))