Commit c38d96d2 authored by bescoto's avatar bescoto

Fix for bug #13576, destination system should not need posix1e


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@604 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 48da48a2
...@@ -37,6 +37,9 @@ Added Keith Edmunds patch adding the --create-full-path option. ...@@ -37,6 +37,9 @@ Added Keith Edmunds patch adding the --create-full-path option.
Fixed selection bug reported by Daniel Richard G. Fixed selection bug reported by Daniel Richard G.
bug#13576: You can now back ACLs to a computer that doesn't have the
posix1e module.
New in v0.13.6 (2005/04/07) New in v0.13.6 (2005/04/07)
--------------------------- ---------------------------
......
...@@ -228,21 +228,19 @@ class AccessControlLists: ...@@ -228,21 +228,19 @@ class AccessControlLists:
def entrytuple_to_text(self, entrytuple): def entrytuple_to_text(self, entrytuple):
"""Return text version of entrytuple, as in getfacl""" """Return text version of entrytuple, as in getfacl"""
type, name_pair, perms = entrytuple tagchar, name_pair, perms = entrytuple
if type == posix1e.ACL_USER_OBJ: if tagchar == "U": text = 'user::'
text = 'user::' elif tagchar == "u":
elif type == posix1e.ACL_USER:
uid, uname = name_pair uid, uname = name_pair
text = 'user:%s:' % (uname or uid) text = 'user:%s:' % (uname or uid)
elif type == posix1e.ACL_GROUP_OBJ: elif tagchar == "G":
text = 'group::' text = 'group::'
elif type == posix1e.ACL_GROUP: elif tagchar == "g":
gid, gname = name_pair gid, gname = name_pair
text = 'group:%s:' % (gname or gid) text = 'group:%s:' % (gname or gid)
elif type == posix1e.ACL_MASK: elif tagchar == "M": text = 'mask::'
text = 'mask::'
else: else:
assert type == posix1e.ACL_OTHER, type assert tagchar == "O", tagchar
text = 'other::' text = 'other::'
permstring = '%s%s%s' % (perms & 4 and 'r' or '-', permstring = '%s%s%s' % (perms & 4 and 'r' or '-',
...@@ -251,32 +249,36 @@ class AccessControlLists: ...@@ -251,32 +249,36 @@ class AccessControlLists:
return text+permstring return text+permstring
def text_to_entrytuple(self, text): def text_to_entrytuple(self, text):
"""Return entrytuple given text like 'user:foo:r--'""" """Return entrytuple given text like 'user:foo:r--'
See the acl_to_list function for entrytuple documentation.
"""
typetext, qualifier, permtext = text.split(':') typetext, qualifier, permtext = text.split(':')
if qualifier: if qualifier:
try: uid = int(qualifier) try: uid = int(qualifier)
except ValueError: namepair = (None, qualifier) except ValueError: namepair = (None, qualifier)
else: namepair = (uid, None) else: namepair = (uid, None)
if typetext == 'user': type = posix1e.ACL_USER if typetext == 'user': typechar = "u"
else: else:
assert typetext == 'group', (typetext, text) assert typetext == 'group', (typetext, text)
type = posix1e.ACL_GROUP typechar = "g"
else: else:
namepair = None namepair = None
if typetext == 'user': type = posix1e.ACL_USER_OBJ if typetext == 'user': typechar = "U"
elif typetext == 'group': type = posix1e.ACL_GROUP_OBJ elif typetext == 'group': typechar = "G"
elif typetext == 'mask': type = posix1e.ACL_MASK elif typetext == 'mask': typechar = "M"
else: else:
assert typetext == 'other', (typetext, text) assert typetext == 'other', (typetext, text)
type = posix1e.ACL_OTHER typechar = "O"
assert len(permtext) == 3, (permtext, text) assert len(permtext) == 3, (permtext, text)
read, write, execute = permtext read, write, execute = permtext
perms = ((read == 'r') << 2 | perms = ((read == 'r') << 2 |
(write == 'w') << 1 | (write == 'w') << 1 |
(execute == 'x')) (execute == 'x'))
return (type, namepair, perms) return (typechar, namepair, perms)
def cmp_entry_list(self, l1, l2): def cmp_entry_list(self, l1, l2):
"""True if the lists have same entries. Assume preordered""" """True if the lists have same entries. Assume preordered"""
...@@ -385,15 +387,33 @@ def acl_to_list(acl): ...@@ -385,15 +387,33 @@ def acl_to_list(acl):
lost when moved to another system. lost when moved to another system.
The result will be a list of tuples. Each tuple will have the The result will be a list of tuples. Each tuple will have the
form (acltype, (uid or gid, uname or gname) or None, form (acltype, (uid or gid, uname or gname) or None, permissions
permissions as an int). as an int). acltype is encoded as a single character:
U - ACL_USER_OBJ
u - ACL_USER
G - ACL_GROUP_OBJ
g - ACL_GROUP
M - ACL_MASK
O - ACL_OTHER
""" """
def acltag_to_char(tag):
if tag == posix1e.ACL_USER_OBJ: return "U"
elif tag == posix1e.ACL_USER: return "u"
elif tag == posix1e.ACL_GROUP_OBJ: return "G"
elif tag == posix1e.ACL_GROUP: return "g"
elif tag == posix1e.ACL_MASK: return "M"
else:
assert tag == posix1e.ACL_OTHER, tag
return "O"
def entry_to_tuple(entry): def entry_to_tuple(entry):
if entry.tag_type == posix1e.ACL_USER: tagchar = acltag_to_char(entry.tag_type)
if tagchar == "u":
uid = entry.qualifier uid = entry.qualifier
owner_pair = (uid, user_group.uid2uname(uid)) owner_pair = (uid, user_group.uid2uname(uid))
elif entry.tag_type == posix1e.ACL_GROUP: elif tagchar == "g":
gid = entry.qualifier gid = entry.qualifier
owner_pair = (gid, user_group.gid2gname(gid)) owner_pair = (gid, user_group.gid2gname(gid))
else: owner_pair = None else: owner_pair = None
...@@ -401,7 +421,7 @@ def acl_to_list(acl): ...@@ -401,7 +421,7 @@ def acl_to_list(acl):
perms = (entry.permset.read << 2 | perms = (entry.permset.read << 2 |
entry.permset.write << 1 | entry.permset.write << 1 |
entry.permset.execute) entry.permset.execute)
return (entry.tag_type, owner_pair, perms) return (tagchar, owner_pair, perms)
return map(entry_to_tuple, acl) return map(entry_to_tuple, acl)
def list_to_acl(entry_list, map_names = 1): def list_to_acl(entry_list, map_names = 1):
...@@ -411,7 +431,20 @@ def list_to_acl(entry_list, map_names = 1): ...@@ -411,7 +431,20 @@ def list_to_acl(entry_list, map_names = 1):
current system, and drop if not available. Otherwise just use the current system, and drop if not available. Otherwise just use the
same id. same id.
See the acl_to_list function for the format of an acllist.
""" """
def char_to_acltag(typechar):
"""Given typechar, query posix1e module for appropriate constant"""
if typechar == "U": return posix1e.ACL_USER_OBJ
elif typechar == "u": return posix1e.ACL_USER
elif typechar == "G": return posix1e.ACL_GROUP_OBJ
elif typechar == "g": return posix1e.ACL_GROUP
elif typechar == "M": return posix1e.ACL_MASK
else:
assert typechar == "O", typechar
return posix1e.ACL_OTHER
def warn_drop(name): def warn_drop(name):
"""Warn about acl with name getting dropped""" """Warn about acl with name getting dropped"""
global dropped_acl_names global dropped_acl_names
...@@ -435,23 +468,23 @@ def list_to_acl(entry_list, map_names = 1): ...@@ -435,23 +468,23 @@ def list_to_acl(entry_list, map_names = 1):
return Map.get_id_from_id(id) return Map.get_id_from_id(id)
acl = posix1e.ACL() acl = posix1e.ACL()
for tag, owner_pair, perms in entry_list: for typechar, owner_pair, perms in entry_list:
id = None id = None
if owner_pair: if owner_pair:
if map_names: if map_names:
if tag == posix1e.ACL_USER: id = map_id_name(owner_pair, 0) if typechar == "u": id = map_id_name(owner_pair, 0)
else: else:
assert tag == posix1e.ACL_GROUP, (tag, owner_pair, perms) assert typechar == "g", (typechar, owner_pair, perms)
id = map_id_name(owner_pair, 1) id = map_id_name(owner_pair, 1)
if id is None: if id is None:
warn_drop(owner_pair[1]) warn_drop(owner_pair[1])
continue continue
else: else:
assert owner_pair[0] is not None, (tag, owner_pair, perms) assert owner_pair[0] is not None, (typechar, owner_pair, perms)
id = owner_pair[0] id = owner_pair[0]
entry = posix1e.Entry(acl) entry = posix1e.Entry(acl)
entry.tag_type = tag entry.tag_type = char_to_acltag(typechar)
if id is not None: entry.qualifier = id if id is not None: entry.qualifier = id
entry.permset.read = perms >> 2 entry.permset.read = perms >> 2
entry.permset.write = perms >> 1 & 1 entry.permset.write = perms >> 1 & 1
......
...@@ -245,6 +245,7 @@ other::---""") ...@@ -245,6 +245,7 @@ other::---""")
new_acl = AccessControlLists(()) new_acl = AccessControlLists(())
tempdir.chmod(0700) tempdir.chmod(0700)
new_acl.read_from_rp(tempdir) new_acl.read_from_rp(tempdir)
print "@", new_acl
assert new_acl.is_basic(), str(new_acl) assert new_acl.is_basic(), str(new_acl)
assert not new_acl == self.sample_acl assert not new_acl == self.sample_acl
assert new_acl != self.sample_acl assert new_acl != self.sample_acl
...@@ -449,8 +450,8 @@ other::---""") ...@@ -449,8 +450,8 @@ other::---""")
def get_perms_of_user(acl, user): def get_perms_of_user(acl, user):
"""Return the permissions of ACL_USER in acl, or None""" """Return the permissions of ACL_USER in acl, or None"""
for type, owner_pair, perms in acl.entry_list: for typechar, owner_pair, perms in acl.entry_list:
if type == posix1e.ACL_USER and owner_pair[1] == user: if typechar == "u" and owner_pair[1] == user:
return perms return perms
return None return None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment