|
@@ -37,7 +37,9 @@ cdef extern from "sys/acl.h":
|
|
|
|
|
|
int acl_free(void *obj)
|
|
|
acl_t acl_get_link_np(const char *path, int type)
|
|
|
+ acl_t acl_get_fd_np(int fd, int type)
|
|
|
int acl_set_link_np(const char *path, int type, acl_t acl)
|
|
|
+ int acl_set_fd_np(int fd, acl_t acl, int type)
|
|
|
acl_t acl_from_text(const char *buf)
|
|
|
char *acl_to_text_np(acl_t acl, ssize_t *len, int flags)
|
|
|
int ACL_TEXT_NUMERIC_IDS
|
|
@@ -89,10 +91,13 @@ def setxattr(path, name, value, *, follow_symlinks=True):
|
|
|
_setxattr_inner(func, path, name, value)
|
|
|
|
|
|
|
|
|
-cdef _get_acl(p, type, item, attribute, int flags):
|
|
|
+cdef _get_acl(p, type, item, attribute, flags, fd=None):
|
|
|
cdef acl_t acl
|
|
|
cdef char *text
|
|
|
- acl = acl_get_link_np(p, type)
|
|
|
+ if fd is not None:
|
|
|
+ acl = acl_get_fd_np(fd, type)
|
|
|
+ else:
|
|
|
+ acl = acl_get_link_np(p, type)
|
|
|
if acl:
|
|
|
text = acl_to_text_np(acl, NULL, flags)
|
|
|
if text:
|
|
@@ -101,7 +106,7 @@ cdef _get_acl(p, type, item, attribute, int flags):
|
|
|
acl_free(acl)
|
|
|
|
|
|
|
|
|
-def acl_get(path, item, st, numeric_owner=False):
|
|
|
+def acl_get(path, item, st, numeric_owner=False, fd=None):
|
|
|
"""Saves ACL Entries
|
|
|
|
|
|
If `numeric_owner` is True the user/group field is not preserved only uid/gid
|
|
@@ -114,13 +119,13 @@ def acl_get(path, item, st, numeric_owner=False):
|
|
|
return
|
|
|
flags |= ACL_TEXT_NUMERIC_IDS if numeric_owner else 0
|
|
|
if ret > 0:
|
|
|
- _get_acl(path, ACL_TYPE_NFS4, item, 'acl_nfs4', flags)
|
|
|
+ _get_acl(path, ACL_TYPE_NFS4, item, 'acl_nfs4', flags, fd=fd)
|
|
|
else:
|
|
|
- _get_acl(path, ACL_TYPE_ACCESS, item, 'acl_access', flags)
|
|
|
- _get_acl(path, ACL_TYPE_DEFAULT, item, 'acl_default', flags)
|
|
|
+ _get_acl(path, ACL_TYPE_ACCESS, item, 'acl_access', flags, fd=fd)
|
|
|
+ _get_acl(path, ACL_TYPE_DEFAULT, item, 'acl_default', flags, fd=fd)
|
|
|
|
|
|
|
|
|
-cdef _set_acl(p, type, item, attribute, numeric_owner=False):
|
|
|
+cdef _set_acl(p, type, item, attribute, numeric_owner=False, fd=None):
|
|
|
cdef acl_t acl
|
|
|
text = item.get(attribute)
|
|
|
if text:
|
|
@@ -130,7 +135,10 @@ cdef _set_acl(p, type, item, attribute, numeric_owner=False):
|
|
|
text = posix_acl_use_stored_uid_gid(text)
|
|
|
acl = acl_from_text(<bytes>text)
|
|
|
if acl:
|
|
|
- acl_set_link_np(p, type, acl)
|
|
|
+ if fd is not None:
|
|
|
+ acl_set_fd_np(fd, acl, type)
|
|
|
+ else:
|
|
|
+ acl_set_link_np(p, type, acl)
|
|
|
acl_free(acl)
|
|
|
|
|
|
|
|
@@ -148,7 +156,7 @@ cdef _nfs4_use_stored_uid_gid(acl):
|
|
|
return safe_encode('\n'.join(entries))
|
|
|
|
|
|
|
|
|
-def acl_set(path, item, numeric_owner=False):
|
|
|
+def acl_set(path, item, numeric_owner=False, fd=None):
|
|
|
"""Restore ACL Entries
|
|
|
|
|
|
If `numeric_owner` is True the stored uid/gid is used instead
|
|
@@ -156,6 +164,6 @@ def acl_set(path, item, numeric_owner=False):
|
|
|
"""
|
|
|
if isinstance(path, str):
|
|
|
path = os.fsencode(path)
|
|
|
- _set_acl(path, ACL_TYPE_NFS4, item, 'acl_nfs4', numeric_owner)
|
|
|
- _set_acl(path, ACL_TYPE_ACCESS, item, 'acl_access', numeric_owner)
|
|
|
- _set_acl(path, ACL_TYPE_DEFAULT, item, 'acl_default', numeric_owner)
|
|
|
+ _set_acl(path, ACL_TYPE_NFS4, item, 'acl_nfs4', numeric_owner, fd=fd)
|
|
|
+ _set_acl(path, ACL_TYPE_ACCESS, item, 'acl_access', numeric_owner, fd=fd)
|
|
|
+ _set_acl(path, ACL_TYPE_DEFAULT, item, 'acl_default', numeric_owner, fd=fd)
|