From 7fc113c1d4542e723b5362ca380d7d7e71eda55c Mon Sep 17 00:00:00 2001 From: bescoto Date: Mon, 15 Sep 2003 21:35:32 +0000 Subject: Added acl list <-> posix1e.ACL conversion git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@437 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/rdiff_backup/eas_acls.py | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/rdiff-backup/rdiff_backup/eas_acls.py b/rdiff-backup/rdiff_backup/eas_acls.py index e543597..80aa0c3 100644 --- a/rdiff-backup/rdiff_backup/eas_acls.py +++ b/rdiff-backup/rdiff_backup/eas_acls.py @@ -257,6 +257,52 @@ class AccessControlList: """Write current access control list to RPath rp""" rp.conn.eas_acls.set_rp_acl(rp, self.acl_text, self.def_acl_text) + def acl_to_list(self, acl): + """Return list representation of posix1e.ACL object + + ACL objects cannot be pickled, so this representation keeps + the structure while adding that option. Also we insert the + username along with the id, because that information will be + lost when moved to another system. + + The result will be a list of tuples. Each tuple will have the + form (acltype, (uid or gid, uname or gname) or None, + permissions as an int). + + """ + def entry_to_tuple(entry): + if entry.tag_type == posix1e.ACL_USER: + uid = entry.qualifier + owner_pair = (uid, user_group.uid2uname(uid)) + elif entry.tag_type == posix1e.ACL_GROUP: + gid = entry.qualifier + owner_pair = (gid, user_group.gid2gname(gid)) + else: owner_pair = None + + perms = (entry.permset.read << 2 | + entry.permset.write << 1 | + entry.permset.execute) + return (entry.tag_type, owner_pair, perms) + return map(entry_to_tuple, acl) + + def list_to_acl(self, listacl): + """Return posix1e.ACL object from list representation""" + acl = posix1e.ACL() + for tag, owner_pair, perms in listacl: + entry = posix1e.Entry(acl) + entry.tag_type = tag + if owner_pair: + if tag == posix1e.ACL_USER: + entry.qualifier = user_group.UserMap.get_id(*owner_pair) + else: + assert tag == posix1e.ACL_GROUP + entry.qualifier = user_group.GroupMap.get_id(*owner_pair) + entry.read = perms >> 2 + entry.write = perms >> 1 & 1 + entry.execute = perms & 1 + return acl + + def set_rp_acl(rp, acl_text = None, def_acl_text = None): """Set given rp with ACL that acl_text defines. rp should be local""" assert rp.conn is Globals.local_connection -- cgit v1.2.1