Changeset 9c1f0b2 for asadb/mit


Ignore:
Timestamp:
Jun 6, 2011, 3:10:15 AM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
c9d8369
Parents:
9480c7b
git-author:
Alex Dehnert <adehnert@…> (06/06/11 03:10:15)
git-committer:
Alex Dehnert <adehnert@…> (06/06/11 03:10:15)
Message:

Merge "upstream" fixes from SIPB's snippets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/mit/__init__.py

    r1c68fbb r9c1f0b2  
     1import subprocess
     2import ldap
     3import ldap.filter
     4
    15from django.contrib.auth.middleware import RemoteUserMiddleware
    26from django.contrib.auth.backends import RemoteUserBackend
     
    812import settings
    913
    10 def zephyr(msg, clas='remit', instance='log', rcpt='adehnert',):
    11     import os
    12     os.system("zwrite -d -c '%s' -i '%s' '%s' -m '%s'" % (clas, instance, rcpt, msg, ))
     14def zephyr(msg, clas='message', instance='log', rcpt='nobody',):
     15    proc = subprocess.Popen(
     16        ['zwrite', '-d', '-n', '-c', clas, '-i', instance, rcpt, ],
     17        stdin=subprocess.PIPE, stdout=subprocess.PIPE
     18    )
     19    proc.communicate(msg)
    1320
    1421class ScriptsRemoteUserMiddleware(RemoteUserMiddleware):
     
    2532    def configure_user(self, user, ):
    2633        username = user.username
    27         import ldap
     34        user.password = "ScriptsSSLAuth"
    2835        con = ldap.open('ldap.mit.edu')
    2936        con.simple_bind_s("", "")
    3037        dn = "dc=mit,dc=edu"
    3138        fields = ['cn', 'sn', 'givenName', 'mail', ]
    32         result = con.search_s('dc=mit,dc=edu', ldap.SCOPE_SUBTREE, 'uid=%s'%username, fields)
     39        userfilter = ldap.filter.filter_format('uid=%s', [username])
     40        result = con.search_s('dc=mit,dc=edu', ldap.SCOPE_SUBTREE, userfilter, fields)
    3341        if len(result) == 1:
    3442            user.first_name = result[0][1]['givenName'][0]
     
    3947            except ObjectDoesNotExist:
    4048                print "Failed to retrieve mit group"
    41             user.save()
     49        else:
     50            raise ValueError, ("Could not find user with username '%s' (filter '%s')"%(username, userfilter))
    4251        try:
    4352            user.groups.add(auth.models.Group.objects.get(name='autocreated'))
    4453        except ObjectDoesNotExist:
    4554            print "Failed to retrieve autocreated group"
     55        user.save()
    4656        return user
    4757
Note: See TracChangeset for help on using the changeset viewer.