2 from afs._acl import READ, WRITE, INSERT, LOOKUP, DELETE, LOCK, ADMINISTER, \
3 USR0, USR1, USR2, USR3, USR4, USR5, USR6, USR7
4 from afs._acl import getCallerAccess
14 _reverseCanonical = dict((y, x) for (x, y) in _canonical.iteritems())
34 _char2bit = dict(_charBitAssoc)
37 def rightsToEnglish(s):
38 """Turns a rlwidwka string into a canonical name if possible"""
39 if s in _reverseCanonical:
40 return _reverseCanonical[s]
45 """Canonicalizes string rights to bitmask"""
46 if s in _canonical: s = _canonical[s]
47 return _parseRights(s)
50 """Takes a bitmask and returns a rwlidka string"""
52 for char,mask in _charBitAssoc:
53 if r & mask == mask: s += char
57 """Parses a rwlid... rights tring to bitmask"""
67 lines = inp.split("\n")
68 npos = int(lines[0].split(" ")[0])
82 def _unparseAcl(pos, neg):
85 acl = "%d\n%d\n" % (npos, nneg)
93 def __init__(self, pos, neg):
96 Dictionary of usernames to positive ACL bitmasks
98 Dictionary of usernames to negative ACL bitmasks
103 def retrieve(dir, follow=True):
104 """Retrieve the ACL for an AFS directory"""
105 pos, neg = _parseAcl(_acl.getAcl(dir, follow))
107 def apply(self, dir, follow=True):
108 """Apply the ACL to a directory"""
110 _acl.setAcl(dir, _unparseAcl(self.pos, self.neg), follow)
112 """Clean an ACL by removing any entries whose bitmask is 0"""
113 for n,a in self.pos.items():
116 for n,a in self.neg.items():
119 def set(self, user, bitmask, negative=False):
120 """Set the bitmask for a given user"""
121 if bitmask < 0 or bitmask > max(_char2bit.values()):
122 raise ValueError, "Invalid bitmask"
124 self.neg[user] = bitmask
126 self.pos[user] = bitmask
127 def remove(self, user, negative=False):
128 """Convenience function to removeSet the bitmask for a given user"""
129 self.set(user, 0, negative)