'Private to bind/Authenticate a user.
If AUTH_LDAP_BIND_USER exists then it will bind first with it,
next will search the LDAP server using the username with UID
and try to bind to it (OpenLDAP).
If AUTH_LDAP_BIND_USER does not exit, will bind with username/password'

def _bind_ldap(self, ldap, con, username, password):

    try:
        indirect_user = self.auth_ldap_bind_user
        if indirect_user:
            indirect_password = self.auth_ldap_bind_password
            log.debug('LDAP    indirect    bind    with:    {0}'.format(indirect_user))
            con.bind_s(indirect_user, indirect_password)
            log.debug('LDAP    BIND    indirect    OK')
            user = self._search_ldap(ldap, con, username)
            if user:
                log.debug('LDAP    got    User    {0}'.format(user))
                username = user[0][0]
            else:
                return False
        log.debug('LDAP    bind    with:    {0}    {1}'.format(username, 'XXXXXX'))
        if self.auth_ldap_username_format:
            username = (self.auth_ldap_username_format % username)
        if self.auth_ldap_append_domain:
            username = ((username + '@') + self.auth_ldap_append_domain)
        con.bind_s(username, password)
        log.debug('LDAP    bind    OK:    {0}'.format(username))
        return True
    except ldap.INVALID_CREDENTIALS:
        return False
