Repository: spritelink/nipap
Issue: Logging in with empty username & password causes error

An exception is thrown when a user tries to log in to the web ui with the username & password fields left empty. Seems as the LDAP DN gets invalid when missing password.

```
Error - <class 'ldap.INVALID_DN_SYNTAX'>: {'info': 'invalid DN', 'desc': 'Invalid DN syntax'}
URL: http://nipap.tele2.net/auth/login
File '/usr/lib/pymodules/python2.6/weberror/errormiddleware.py', line 162 in __call__
  app_iter = self.application(environ, sr_checker)
File '/usr/lib/pymodules/python2.6/beaker/middleware.py', line 152 in __call__
  return self.wrap_app(environ, session_start_response)
File '/usr/lib/pymodules/python2.6/routes/middleware.py', line 131 in __call__
  response = self.app(environ, start_response)
File '/usr/lib/python2.6/dist-packages/pylons/wsgiapp.py', line 107 in __call__
  response = self.dispatch(controller, environ, start_response)
File '/usr/lib/python2.6/dist-packages/pylons/wsgiapp.py', line 312 in dispatch
  return controller(environ, start_response)
File '/usr/lib/python2.6/dist-packages/nipapwww/lib/base.py', line 49 in __call__
  return WSGIController.__call__(self, environ, start_response)
File '/usr/lib/python2.6/dist-packages/pylons/controllers/core.py', line 211 in __call__
  response = self._dispatch_call()
File '/usr/lib/python2.6/dist-packages/pylons/controllers/core.py', line 162 in _dispatch_call
  response = self._inspect_call(func)
File '/usr/lib/python2.6/dist-packages/pylons/controllers/core.py', line 105 in _inspect_call
  result = self._perform_call(func, args)
File '/usr/lib/python2.6/dist-packages/pylons/controllers/core.py', line 57 in _perform_call
  return func(**args)
File '/usr/lib/python2.6/dist-packages/nipapwww/controllers/auth.py', line 31 in login
  if not auth.authenticate():
File '/usr/lib/python2.6/dist-packages/nipap/authlib.py', line 308 in authenticate
  self._ldap_conn.simple_bind_s('uid=' + self.username + ',' + self._ldap_basedn, self.password)
File '/usr/lib/python2.6/dist-packages/ldap/ldapobject.py', line 207 in simple_bind_s
  return self.result(msgid,all=1,timeout=self.timeout)
File '/usr/lib/python2.6/dist-packages/ldap/ldapobject.py', line 422 in result
  res_type,res_data,res_msgid = self.result2(msgid,all,timeout)
File '/usr/lib/python2.6/dist-packages/ldap/ldapobject.py', line 426 in result2
  res_type, res_data, res_msgid, srv_ctrls = self.result3(msgid,all,timeout)
File '/usr/lib/python2.6/dist-packages/ldap/ldapobject.py', line 432 in result3
  ldap_result = self._ldap_call(self._l.result3,msgid,all,timeout)
File '/usr/lib/python2.6/dist-packages/ldap/ldapobject.py', line 96 in _ldap_call
  result = func(*args,**kwargs)
INVALID_DN_SYNTAX: {'info': 'invalid DN', 'desc': 'Invalid DN syntax'}
```


Changed files:
nipap/nipap/authlib.py

diff --git a/nipap/nipap/authlib.py b/nipap/nipap/authlib.py
index 4e88be0a..9e68b06a 100644
--- a/nipap/nipap/authlib.py
+++ b/nipap/nipap/authlib.py
@@ -314,7 +314,7 @@ class LdapAuth(BaseAuth):
             self._ldap_conn.simple_bind_s('uid=' + self.username + ',' + self._ldap_basedn, self.password)
         except ldap.SERVER_DOWN, exc:
             raise AuthError('Could not connect to LDAP server')
-        except ldap.INVALID_CREDENTIALS, exc:
+        except (ldap.INVALID_CREDENTIALS, ldap.INVALID_DN_SYNTAX, ldap.UNWILLING_TO_PERFORM), exc:
             # Auth failed
             self._logger.debug('erroneous password for user %s' % self.username)
             self._authenticated = False
@@ -327,7 +327,7 @@ class LdapAuth(BaseAuth):
         self.trusted = False
 
         try:
-            res = self._ldap_conn.search_s(self._ldap_basedn, ldap.SCOPE_SUBTREE, 'uid=' + self.username, ['cn']);
+            res = self._ldap_conn.search_s(self._ldap_basedn, ldap.SCOPE_SUBTREE, 'uid=' + self.username, ['cn'])
             self.full_name = res[0][1]['cn'][0]
         except:
             self.full_name = ''