USERS_LDAP: use ldap sync function
bzr revid: ced-38b18eb3c304d9e9f63d208cd5345e2d19bf49f9
This commit is contained in:
parent
c281021e3d
commit
ecf679f5ed
|
@ -62,12 +62,12 @@ def ldap_login(oldfnc):
|
||||||
for res_company in cr.dictfetchall():
|
for res_company in cr.dictfetchall():
|
||||||
try:
|
try:
|
||||||
l = ldap.open(res_company['ldap_server'])
|
l = ldap.open(res_company['ldap_server'])
|
||||||
if l.simple_bind(res_company['ldap_binddn'], res_company['ldap_password']):
|
if l.simple_bind_s(res_company['ldap_binddn'], res_company['ldap_password']):
|
||||||
base = res_company['ldap_base']
|
base = res_company['ldap_base']
|
||||||
scope = ldap.SCOPE_SUBTREE
|
scope = ldap.SCOPE_SUBTREE
|
||||||
filter = res_company['ldap_filter']%(login,)
|
filter = res_company['ldap_filter']%(login,)
|
||||||
retrieve_attributes = None
|
retrieve_attributes = None
|
||||||
result_id = l.search(base, scope, filter, retrieve_attributes)
|
result_id = l.search_s(base, scope, filter, retrieve_attributes)
|
||||||
timeout = 60
|
timeout = 60
|
||||||
result_type, result_data = l.result(result_id, timeout)
|
result_type, result_data = l.result(result_id, timeout)
|
||||||
if not result_data:
|
if not result_data:
|
||||||
|
@ -75,7 +75,7 @@ def ldap_login(oldfnc):
|
||||||
if result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1:
|
if result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1:
|
||||||
dn=result_data[0][0]
|
dn=result_data[0][0]
|
||||||
name=result_data[0][1]['cn']
|
name=result_data[0][1]['cn']
|
||||||
if l.bind(dn, passwd):
|
if l.bind_s(dn, passwd):
|
||||||
cr.execute("select id from res_users where login=%s",(login.encode('utf-8'),))
|
cr.execute("select id from res_users where login=%s",(login.encode('utf-8'),))
|
||||||
res = cr.fetchone()
|
res = cr.fetchone()
|
||||||
if res:
|
if res:
|
||||||
|
@ -112,18 +112,18 @@ def ldap_check(oldfnc):
|
||||||
company = user.company_id
|
company = user.company_id
|
||||||
try:
|
try:
|
||||||
l = ldap.open(company.ldap_server)
|
l = ldap.open(company.ldap_server)
|
||||||
if l.simple_bind(company.ldap_binddn, company.ldap_password):
|
if l.simple_bind_s(company.ldap_binddn, company.ldap_password):
|
||||||
base = company['ldap_base']
|
base = company['ldap_base']
|
||||||
scope = ldap.SCOPE_SUBTREE
|
scope = ldap.SCOPE_SUBTREE
|
||||||
filter = company['ldap_filter']%(user.login,)
|
filter = company['ldap_filter']%(user.login,)
|
||||||
retrieve_attributes = None
|
retrieve_attributes = None
|
||||||
result_id = l.search(base, scope, filter, retrieve_attributes)
|
result_id = l.search_s(base, scope, filter, retrieve_attributes)
|
||||||
timeout = 60
|
timeout = 60
|
||||||
result_type, result_data = l.result(result_id, timeout)
|
result_type, result_data = l.result(result_id, timeout)
|
||||||
if result_data and result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1:
|
if result_data and result_type == ldap.RES_SEARCH_RESULT and len(result_data) == 1:
|
||||||
dn=result_data[0][0]
|
dn=result_data[0][0]
|
||||||
name=result_data[0][1]['cn']
|
name=result_data[0][1]['cn']
|
||||||
if l.bind(dn, passwd):
|
if l.bind_s(dn, passwd):
|
||||||
security._uid_cache[uid] = passwd
|
security._uid_cache[uid] = passwd
|
||||||
cr.close()
|
cr.close()
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue