Skip to content

Commit

Permalink
Linux: improve acl_get / acl_set error handling, see #4049
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Feb 24, 2024
1 parent 629c60d commit 8b0ef42
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/borg/platform/linux.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,13 @@ def acl_get(path, item, st, numeric_ids=False, fd=None):
access_acl = acl_get_fd(fd)
else:
access_acl = acl_get_file(path, ACL_TYPE_ACCESS)
if access_acl == NULL:
raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path))
if stat.S_ISDIR(st.st_mode):
# only directories can have a default ACL. there is no fd-based api to get it.
default_acl = acl_get_file(path, ACL_TYPE_DEFAULT)
if default_acl == NULL:
raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path))
if access_acl:
access_text = acl_to_text(access_acl, NULL)
if access_text:
Expand Down Expand Up @@ -289,9 +293,11 @@ def acl_set(path, item, numeric_ids=False, fd=None):
access_acl = acl_from_text(<bytes>converter(access_text))
if access_acl:
if fd is not None:
acl_set_fd(fd, access_acl)
if acl_set_fd(fd, access_acl) == -1:
raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path))
else:
acl_set_file(path, ACL_TYPE_ACCESS, access_acl)
if acl_set_file(path, ACL_TYPE_ACCESS, access_acl) == -1:
raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path))
finally:
acl_free(access_acl)
default_text = item.get('acl_default')
Expand All @@ -300,7 +306,8 @@ def acl_set(path, item, numeric_ids=False, fd=None):
default_acl = acl_from_text(<bytes>converter(default_text))
if default_acl:
# only directories can get a default ACL. there is no fd-based api to set it.
acl_set_file(path, ACL_TYPE_DEFAULT, default_acl)
if acl_set_file(path, ACL_TYPE_DEFAULT, default_acl) == -1:
raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path))
finally:
acl_free(default_acl)

Expand Down

0 comments on commit 8b0ef42

Please sign in to comment.