diff --git a/src/basic/chattr-util.c b/src/basic/chattr-util.c index 8e15b56ea3..9a4e97327e 100644 --- a/src/basic/chattr-util.c +++ b/src/basic/chattr-util.c @@ -41,7 +41,7 @@ int chattr_full( * drivers, where the ioctl might have different effects. Notably, DRM is using the same * ioctl() number. */ - if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) + if (!inode_type_can_chattr(st.st_mode)) return -ENOTTY; if (mask == 0 && !ret_previous && !ret_final) @@ -140,7 +140,7 @@ int read_attr_fd(int fd, unsigned *ret) { if (fstat(fd, &st) < 0) return -errno; - if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) + if (!inode_type_can_chattr(st.st_mode)) return -ENOTTY; _cleanup_close_ int fd_close = -EBADF; @@ -248,3 +248,7 @@ int set_proj_id_recursive(int fd, uint32_t proj_id) { set_proj_id_cb, UINT32_TO_PTR(proj_id)); } + +bool inode_type_can_chattr(mode_t mode) { + return IN_SET(mode & S_IFMT, S_IFREG, S_IFDIR); +} diff --git a/src/basic/chattr-util.h b/src/basic/chattr-util.h index 50f97971f9..543843db2c 100644 --- a/src/basic/chattr-util.h +++ b/src/basic/chattr-util.h @@ -63,3 +63,5 @@ int set_proj_id_recursive(int fd, uint32_t proj_id); static inline int chattr_secret(int fd, ChattrApplyFlags flags) { return chattr_full(fd, NULL, CHATTR_SECRET_FLAGS, CHATTR_SECRET_FLAGS, NULL, NULL, flags|CHATTR_FALLBACK_BITWISE); } + +bool inode_type_can_chattr(mode_t mode); diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c index a057e8028c..03bfcca9b6 100644 --- a/src/shared/acl-util.c +++ b/src/shared/acl-util.c @@ -648,3 +648,7 @@ int fd_acl_make_writable_fallback(int fd) { return 1; } + +int inode_type_can_acl(mode_t mode) { + return IN_SET(mode & S_IFMT, S_IFSOCK, S_IFREG, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO); +} diff --git a/src/shared/acl-util.h b/src/shared/acl-util.h index 2164017de3..5e28f7167f 100644 --- a/src/shared/acl-util.h +++ b/src/shared/acl-util.h @@ -53,3 +53,5 @@ static inline int fd_acl_make_writable(int fd) { } #endif + +int inode_type_can_acl(mode_t mode); diff --git a/src/shared/shift-uid.c b/src/shared/shift-uid.c index 9c7e875dff..2f34908fff 100644 --- a/src/shared/shift-uid.c +++ b/src/shared/shift-uid.c @@ -161,7 +161,7 @@ static int patch_acls(int fd, const char *name, const struct stat *st, uid_t shi assert(st); /* ACLs are not supported on symlinks, there's no point in trying */ - if (S_ISLNK(st->st_mode)) + if (!inode_type_can_acl(st->st_mode)) return 0; r = get_acl(fd, name, ACL_TYPE_ACCESS, &acl); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 4342ed70ab..42d67deebf 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1459,8 +1459,8 @@ static int fd_set_acls( "Refusing to set ACLs on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path); - if (S_ISLNK(st->st_mode)) { - log_debug("Skipping ACL fix for symlink %s.", path); + if (!inode_type_can_acl(st->st_mode)) { + log_debug("Skipping ACL fix for '%s' (inode type does not support ACLs).", path); return 0; }