mirror of
https://github.com/borgbackup/borg.git
synced 2026-03-23 02:44:36 -04:00
Linux ACL support improvements
This commit is contained in:
parent
4bcc1b8ff9
commit
1b779c896d
3 changed files with 19 additions and 11 deletions
|
|
@ -65,9 +65,11 @@ cdef acl_numeric_ids(acl):
|
|||
if entry:
|
||||
type, name, permission = entry.split(':')
|
||||
if name and type == 'user':
|
||||
entries.append(':'.join([type, str(user2uid(name, name)), permission]))
|
||||
uid = str(user2uid(name, name))
|
||||
entries.append(':'.join([type, uid, permission, uid]))
|
||||
elif name and type == 'group':
|
||||
entries.append(':'.join([type, str(group2gid(name, name)), permission]))
|
||||
gid = str(group2gid(name, name))
|
||||
entries.append(':'.join([type, gid, permission, gid]))
|
||||
else:
|
||||
entries.append(entry)
|
||||
return ('\n'.join(entries)).encode('ascii')
|
||||
|
|
@ -94,12 +96,12 @@ def acl_get(path, item, numeric_owner=False):
|
|||
if access_acl:
|
||||
access_text = acl_to_text(access_acl, NULL)
|
||||
if access_text:
|
||||
item[b'acl_access'] = acl_append_numeric_ids(access_text)
|
||||
item[b'acl_access'] = converter(access_text)
|
||||
default_acl = acl_get_file(<bytes>os.fsencode(path), ACL_TYPE_DEFAULT)
|
||||
if default_acl:
|
||||
default_text = acl_to_text(default_acl, NULL)
|
||||
if default_text:
|
||||
item[b'acl_default'] = acl_append_numeric_ids(default_text)
|
||||
item[b'acl_default'] = converter(default_text)
|
||||
finally:
|
||||
acl_free(default_text)
|
||||
acl_free(default_acl)
|
||||
|
|
|
|||
|
|
@ -44,20 +44,26 @@ class PlatformLinuxTestCase(AtticTestCase):
|
|||
def tearDown(self):
|
||||
shutil.rmtree(self.tmpdir)
|
||||
|
||||
def get_acl(self, path):
|
||||
def get_acl(self, path, numeric_owner=False):
|
||||
item = {}
|
||||
acl_get(path, item)
|
||||
acl_get(path, item, numeric_owner=numeric_owner)
|
||||
return item
|
||||
|
||||
def set_acl(self, path, access=None, default=None):
|
||||
def set_acl(self, path, access=None, default=None, numeric_owner=False):
|
||||
item = {b'acl_access': access, b'acl_default': default}
|
||||
acl_set(path, item)
|
||||
acl_set(path, item, numeric_owner=numeric_owner)
|
||||
|
||||
def test_access_acl(self):
|
||||
file = tempfile.NamedTemporaryFile()
|
||||
self.assert_equal(self.get_acl(file.name), {})
|
||||
self.set_acl(file.name, access=ACCESS_ACL)
|
||||
self.assert_equal(self.get_acl(file.name)[b'acl_access'], ACCESS_ACL)
|
||||
self.set_acl(file.name, access=b'user::rw-\ngroup::r--\nmask::rw-\nother::---\nuser:root:rw-:9999\ngroup:root:rw-:9999\n', numeric_owner=False)
|
||||
self.assert_in(b'user:root:rw-:0', self.get_acl(file.name)[b'acl_access'])
|
||||
self.assert_in(b'group:root:rw-:0', self.get_acl(file.name)[b'acl_access'])
|
||||
self.assert_in(b'user:0:rw-:0', self.get_acl(file.name, numeric_owner=True)[b'acl_access'])
|
||||
file2 = tempfile.NamedTemporaryFile()
|
||||
self.set_acl(file2.name, access=b'user::rw-\ngroup::r--\nmask::rw-\nother::---\nuser:root:rw-:9999\ngroup:root:rw-:9999\n', numeric_owner=True)
|
||||
self.assert_in(b'user:9999:rw-:9999', self.get_acl(file2.name)[b'acl_access'])
|
||||
self.assert_in(b'group:9999:rw-:9999', self.get_acl(file2.name)[b'acl_access'])
|
||||
|
||||
def test_default_acl(self):
|
||||
self.assert_equal(self.get_acl(self.tmpdir), {})
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ if sys.platform.startswith('linux'):
|
|||
n2 = _check(func(path, namebuf, n), path)
|
||||
if n2 != n:
|
||||
raise Exception('listxattr failed')
|
||||
return [os.fsdecode(name) for name in namebuf.raw.split(b'\0')[:-1]]
|
||||
return [os.fsdecode(name) for name in namebuf.raw.split(b'\0')[:-1] if not n.startswith(b'system.posix_acl_')]
|
||||
|
||||
def getxattr(path, name, *, follow_symlinks=True):
|
||||
name = os.fsencode(name)
|
||||
|
|
|
|||
Loading…
Reference in a new issue