X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/python-afs.git/blobdiff_plain/dee660f2c4164dbe8862e0158494dbfe966b8c43..4af97584e2401ec114fbbd846a46700613d50a15:/afs/acl.py?ds=sidebyside diff --git a/afs/acl.py b/afs/acl.py index b5da255..713d5b8 100644 --- a/afs/acl.py +++ b/afs/acl.py @@ -4,52 +4,45 @@ from _acl import READ, WRITE, INSERT, LOOKUP, DELETE, LOCK, ADMINISTER, \ from _acl import getCallerAccess _canonical = { - "read": "rl", - "write": "rwlidwk", - "all": "rwlidwka", - "mail": "lik", - "none": "", -} -_char2bit = { - 'r': READ, - 'w': WRITE, - 'i': INSERT, - 'l': LOOKUP, - 'd': DELETE, - 'k': LOCK, - 'a': ADMINISTER, - 'A': USR0, - 'B': USR1, - 'C': USR2, - 'D': USR3, - 'E': USR4, - 'F': USR5, - 'G': USR6, - 'H': USR7, + "read": "rl", + "write": "rwlidwk", + "all": "rwlidwka", + "mail": "lik", + "none": "", } -_bit2char = dict([(v,k) for k,v in _char2bit.items()]) +_charBitAssoc = [ + ('r', READ), + ('w', WRITE), + ('i', INSERT), + ('l', LOOKUP), + ('d', DELETE), + ('k', LOCK), + ('a', ADMINISTER), + ('A', USR0), + ('B', USR1), + ('C', USR2), + ('D', USR3), + ('E', USR4), + ('F', USR5), + ('G', USR6), + ('H', USR7), +] + +_char2bit = dict(_charBitAssoc) -def crights(s): + +def readRights(s): """Canonicalizes string rights to bitmask""" if s in _canonical: s = _canonical[s] return _parseRights(s) -class ACL(object): - def __init__(self, pos, neg): - """ - ``pos`` - Dictionary of usernames to positive ACL bitmasks - ``neg`` - Dictionary of usernames to negative ACL bitmasks - """ - self.pos = pos - self.neg = neg - @staticmethod - def retrieve(dir): - """Retrieve the ACL for an AFS directory""" - pos, neg = _parseAcl(_acl.getAcl(dir)) - return ACL(pos, neg) +def showRights(r): + """Takes a bitmask and returns a rwlidka string""" + s = "" + for char,mask in _charBitAssoc: + if r & mask == mask: s += char + return s def _parseRights(s): """Parses a rwlid... rights tring to bitmask""" @@ -77,3 +70,19 @@ def _parseAcl(inp): neg[name] = int(acl) return (pos, neg) +class ACL(object): + def __init__(self, pos, neg): + """ + ``pos`` + Dictionary of usernames to positive ACL bitmasks + ``neg`` + Dictionary of usernames to negative ACL bitmasks + """ + self.pos = pos + self.neg = neg + @staticmethod + def retrieve(dir, follow=True): + """Retrieve the ACL for an AFS directory""" + pos, neg = _parseAcl(_acl.getAcl(dir, follow)) + return ACL(pos, neg) +