I've been running into a very frustrating situation with a seg fault
in Apache when authenticating Django using LDAP.  The problem is
intermittent, probably one out of every 5 logins causes the seg fault.

The code I'm using for LDAP (borrowed from the web, thanks Mick)
authentication is shown below

Here's what I'm running

Django-1.0.2-final
Python 2.5.2
httpd-2.2.9
openldap-2.4.14
python-ldap-2.3.5
CentOS release 4.6 (Final)

I've tried both mod_python-3.3.1 and mod_wsgi-2.3 I get the crash in
both cases.  I've read that there are conflicts with mod_php, but this
is not the issue, PHP has never been installed on this server.

The code below runs perfectly in a standalone program, it only
segfaults in Apache.

Any help would be greatly appreciated.

Thanks,

Pat

import ldap

from django.conf import settings
from django.contrib.auth.models import User, check_password

class LDAPBackend:
    # from http://blogs.translucentcode.org/mick/tags/django/
    def authenticate(self, username=None, password=None):
        username = "%...@example.com" % (username)
        l = ldap.open('ldap.example.com')
        try:
            l.simple_bind_s(username, password)
            valid = True
        except ldap.LDAPError, e:
            valid = False
        if valid:
            try:
                user = User.objects.get(username=username)
            except User.DoesNotExist:
                # Create a new user. Note that we can set password to
anything
                # as it won't be checked, the password from
settings.py will.
                user = User(username=username, password='obtained from
ldap')
                user.is_staff = True
                user.is_superuser = True
                user.save()
            return user
        return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to