Changeset 3b03cc6


Ignore:
Timestamp:
May 24, 2011, 4:36:12 PM (15 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, client
Children:
4cc9c2c
Parents:
c9047b1
git-author:
Alex Dehnert <adehnert@…> (05/24/11 16:31:37)
git-committer:
Alex Dehnert <adehnert@…> (05/24/11 16:36:12)
Message:

Fix issues with user setup in the scripts backend

In particular:

  • Properly escape usernames before passing them to LDAP
  • Error out if the user can't be found

In theory, neither should be an issue, because this should only get called if
certs are in use, so the username should be sane and present in LDAP.

Thanks to Anders for bringing the first issue to my attention.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • remit/mit/__init__.py

    rc9047b1 r3b03cc6  
    11import subprocess
     2import ldap
     3import ldap.filter
    24
    35from django.contrib.auth.middleware import RemoteUserMiddleware
     
    2729        username = user.username
    2830        user.password = "ScriptsSSLAuth"
    29         import ldap
    3031        con = ldap.open('ldap.mit.edu')
    3132        con.simple_bind_s("", "")
    3233        dn = "dc=mit,dc=edu"
    3334        fields = ['cn', 'sn', 'givenName', 'mail', ]
    34         result = con.search_s('dc=mit,dc=edu', ldap.SCOPE_SUBTREE, 'uid=%s'%username, fields)
     35        userfilter = ldap.filter.filter_format('uid=%s', [username])
     36        result = con.search_s('dc=mit,dc=edu', ldap.SCOPE_SUBTREE, userfilter, fields)
    3537        if len(result) == 1:
    3638            user.first_name = result[0][1]['givenName'][0]
     
    4143            except ObjectDoesNotExist:
    4244                print "Failed to retrieve mit group"
     45        else:
     46            raise ValueError, ("Could not find user with username '%s' (filter '%s')"%(username, userfilter))
    4347        try:
    4448            user.groups.add(auth.models.Group.objects.get(name='autocreated'))
Note: See TracChangeset for help on using the changeset viewer.