Ldap does not work with non-latin symbols

Issue #435 resolved
VilenT created an issue

I've entered this filter into ldap settings {{{ (&(objectCategory=User)(CN=Отдел развития информационных технологий)) }}}

now I recieve this during auth

{{{

2012-05-04 13:24:11.298 ERROR [rhodecode.lib.auth] Traceback (most recent call last): File "c:\Python27\lib\site-packages\rhodecode-1.3.5beta-py2.7.egg\rhodecode\lib\auth.py", line 218, in authenticate password) File "c:\Python27\lib\site-packages\rhodecode-1.3.5beta-py2.7.egg\rhodecode\lib\auth_ldap.py", line 124, in authenticate_ldap filter_) File "c:\Python27\lib\site-packages\ldap\ldapobject.py", line 545, in search_ext_s msgid = self.search_ext(base,scope,filterstr,attrlist,attrsonly,serverctrls,clientctrls,timeout,sizelimit) File "c:\Python27\lib\site-packages\ldap\ldapobject.py", line 541, in search_ext timeout,sizelimit, File "c:\Python27\lib\site-packages\ldap\ldapobject.py", line 99, in _ldap_call result = func(args,*kwargs) UnicodeEncodeError: 'ascii' codec can't encode characters in position 29-33: ordinal not in range(128) }}}

Comments (6)

  1. VilenT reporter

    It is utf-8 definetely :) Same here after patch

    2012-05-12 17:21:46.180 ERROR [rhodecode.lib.auth] Traceback (most recent call last):
      File "c:\Python27\lib\site-packages\rhodecode-1.3.5beta-py2.7.egg\rhodecode\lib\auth.py", line 218, in authenticate
        password)
      File "c:\Python27\lib\site-packages\rhodecode-1.3.5beta-py2.7.egg\rhodecode\lib\auth_ldap.py", line 124, in authenticate_ldap
        filter_)
      File "c:\Python27\lib\site-packages\ldap\ldapobject.py", line 545, in search_ext_s
        msgid = self.search_ext(base,scope,filterstr,attrlist,attrsonly,serverctrls,clientctrls,timeout,sizelimit)
      File "c:\Python27\lib\site-packages\ldap\ldapobject.py", line 541, in search_ext
        timeout,sizelimit,
      File "c:\Python27\lib\site-packages\ldap\ldapobject.py", line 99, in _ldap_call
        result = func(*args,**kwargs)
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 29-33: ordinal not in range(128)
    
  2. Michal Toth

    Hello! Same problem here on 1.3.6 version. BUT we don't use other then ascii chars! Failed to login via LDAP.

    2012-08-02 11:17:05.517 WARNI [rhodecode.model.forms] user xxxxxx failed to authenticate
    2012-08-02 11:17:05.531 INFO  [rhodecode.lib.base] Request to /_admin/login time: 0.038s
    2012-08-02 11:17:07.221 INFO  [rhodecode.lib.base] User: <AuthUser('id:1:default|True')> accessed /_admin/login
    2012-08-02 11:17:07.227 ERROR [rhodecode.lib.auth] Traceback (most recent call last):
      File "/data/rhodecode2-venv/local/lib/python2.7/site-packages/rhodecode/lib/auth.py", line 218, in authenticate
        password)
      File "/data/rhodecode2-venv/local/lib/python2.7/site-packages/rhodecode/lib/auth_ldap.py", line 117, in authenticate_ldap
        server.simple_bind_s(self.LDAP_BIND_DN, self.LDAP_BIND_PASS)
      File "/data/rhodecode2-venv/local/lib/python2.7/site-packages/python_ldap-2.4.10-py2.7-linux-x86_64.egg/ldap/ldapobject.py", line 207, in simple_bind_s
        msgid = self.simple_bind(who,cred,serverctrls,clientctrls)
      File "/data/rhodecode2-venv/local/lib/python2.7/site-packages/python_ldap-2.4.10-py2.7-linux-x86_64.egg/ldap/ldapobject.py", line 201, in simple_bind
        return self._ldap_call(self._l.simple_bind,who,cred,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
      File "/data/rhodecode2-venv/local/lib/python2.7/site-packages/python_ldap-2.4.10-py2.7-linux-x86_64.egg/ldap/ldapobject.py", line 99, in _ldap_call
    
        result = func(*args,**kwargs)
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-6: ordinal not in range(128)
    

    If you need more info, just let me know. Thank you, Mich

    EDIT: Fixed in adding these lines into: 
    PATH-TO-YOUR-VIRTUAL-ENV/local/lib/python2.7/site-packages/rhodecode/lib/auth_ldap.py
    added `from rhodecode.lib.utils2 import safe_str` into top of auth_ldap
    and around line 63 wrap bind_dn, bind_pass into safe_str() function: 
    # USE FOR READ ONLY BIND TO LDAP SERVER
    self.LDAP_BIND_DN = safe_str(bind_dn)
    self.LDAP_BIND_PASS = safe_str(bind_pass)
    

    Thank you Marcin

  3. Log in to comment