2 from _acl import READ, WRITE, INSERT, LOOKUP, DELETE, LOCK, ADMINISTER, \
3 USR0, USR1, USR2, USR3, USR4, USR5, USR6, USR7
4 from _acl import getCallerAccess
32 _char2bit = dict(_charBitAssoc)
36 """Canonicalizes string rights to bitmask"""
37 if s in _canonical: s = _canonical[s]
38 return _parseRights(s)
41 """Takes a bitmask and returns a rwlidka string"""
43 for char,mask in _charBitAssoc:
44 if r & mask == mask: s += char
48 """Parses a rwlid... rights tring to bitmask"""
58 lines = inp.split("\n")
59 npos = int(lines[0].split(" ")[0])
73 def _unparseAcl(pos, neg):
76 acl = "%d\n%d\n" % (npos, nneg)
84 def __init__(self, pos, neg):
87 Dictionary of usernames to positive ACL bitmasks
89 Dictionary of usernames to negative ACL bitmasks
94 def retrieve(dir, follow=True):
95 """Retrieve the ACL for an AFS directory"""
96 pos, neg = _parseAcl(_acl.getAcl(dir, follow))
98 def apply(self, dir, follow=True):
99 """Apply the ACL to a directory"""
101 _acl.setAcl(dir, _unparseAcl(self.pos, self.neg), follow)
103 """Clean an ACL by removing any entries whose bitmask is 0"""
104 for n,a in self.pos.items():
107 for n,a in self.neg.items():
110 def set(self, user, bitmask, negative=False):
111 """Set the bitmask for a given user"""
112 if bitmask < 0 or bitmask > max(_char2bit.values()):
113 raise ValueError, "Invalid bitmask"
115 self.neg[user] = bitmask
117 self.pos[user] = bitmask
118 def remove(self, user, negative=False):
119 """Convenience function to removeSet the bitmask for a given user"""
120 self.set(user, 0, negative)