| 
                Last change
                  on this file since 434 was
                  434,
                  checked in by ecprice, 18 years ago
           | 
        
        
          | 
               
Only autodetect system: when setting the administrator, so new users don't get admin access. 
 
           | 
        
        | 
            File size:
            1.8 KB
           | 
      
      
        
  | Rev | Line |   | 
|---|
| [249] | 1 | #!/usr/bin/python | 
|---|
 | 2 | from sipb_xen_database import * | 
|---|
 | 3 | import sys | 
|---|
 | 4 | import getafsgroups | 
|---|
 | 5 | import subprocess | 
|---|
 | 6 |  | 
|---|
 | 7 | def expandLocker(name): | 
|---|
 | 8 |     groups = getafsgroups.getLockerAcl(name) | 
|---|
 | 9 |     cell = getafsgroups.getCell(name) | 
|---|
 | 10 |     ans = set() | 
|---|
 | 11 |     for group in groups: | 
|---|
 | 12 |         if ':' in group: | 
|---|
 | 13 |             ans.update(getafsgroups.getAfsGroupMembers(group, cell)) | 
|---|
 | 14 |         else: | 
|---|
 | 15 |             ans.add(group) | 
|---|
 | 16 |     return ans | 
|---|
 | 17 |  | 
|---|
 | 18 | def isUser(name): | 
|---|
 | 19 |     p = subprocess.Popen(['vos', 'examine', 'user.'+name], | 
|---|
 | 20 |                          stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 
|---|
 | 21 |     if p.wait(): | 
|---|
 | 22 |         return False | 
|---|
 | 23 |     return True | 
|---|
 | 24 |      | 
|---|
 | 25 |  | 
|---|
 | 26 | def expandName(name): | 
|---|
 | 27 |     if ':' not in name: | 
|---|
 | 28 |         if isUser(name): | 
|---|
 | 29 |             return [name] | 
|---|
| [434] | 30 |         return [] | 
|---|
| [413] | 31 |     try: | 
|---|
 | 32 |         return getafsgroups.getAfsGroupMembers(name, 'athena.mit.edu') | 
|---|
 | 33 |     except getafsgroups.AfsProcessError: | 
|---|
 | 34 |         return [] | 
|---|
| [249] | 35 |  | 
|---|
| [410] | 36 | def accessList(m): | 
|---|
| [263] | 37 |     people = set() | 
|---|
 | 38 |     people.update(expandLocker(m.owner)) | 
|---|
 | 39 |     people.update(expandName(m.administrator)) | 
|---|
| [410] | 40 |     return people | 
|---|
 | 41 |  | 
|---|
 | 42 | def refreshMachine(m): | 
|---|
 | 43 |     people = accessList(m) | 
|---|
| [263] | 44 |     old_people = set(a.user for a in m.acl) | 
|---|
 | 45 |     for removed in old_people - people: | 
|---|
 | 46 |         ma = [x for x in m.acl if x.user == removed][0] | 
|---|
 | 47 |         ctx.current.delete(ma) | 
|---|
 | 48 |     for p in people - old_people: | 
|---|
 | 49 |         ma = MachineAccess(machine_id=m.machine_id, user=p) | 
|---|
 | 50 |         ctx.current.save(ma) | 
|---|
 | 51 |      | 
|---|
| [262] | 52 | def refreshCache(): | 
|---|
| [257] | 53 |     transaction = ctx.current.create_transaction() | 
|---|
 | 54 |  | 
|---|
 | 55 |     try: | 
|---|
 | 56 |         machines = Machine.select() | 
|---|
 | 57 |         for m in machines: | 
|---|
| [263] | 58 |             refreshMachine(m) | 
|---|
 | 59 |         ctx.current.flush() | 
|---|
| [257] | 60 |              | 
|---|
 | 61 |         # Atomically execute our changes | 
|---|
| [249] | 62 |         transaction.commit() | 
|---|
| [257] | 63 |     except: | 
|---|
 | 64 |         # Failed! Rollback all the changes. | 
|---|
 | 65 |         transaction.rollback() | 
|---|
 | 66 |         raise | 
|---|
| [262] | 67 |  | 
|---|
 | 68 | if __name__ == '__main__': | 
|---|
 | 69 |     connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen') | 
|---|
 | 70 |     refreshCache() | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.