From 443743d2d8fc41604332edf014d876868e6b09fb Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sun, 11 Aug 2024 12:30:50 +0200 Subject: [PATCH] New API call iso_util_get_effective_lfa_mask() --- libisofs/fs_local.c | 9 ++------- libisofs/libisofs.h | 21 +++++++++++++++++++++ libisofs/libisofs.ver | 1 + libisofs/util.c | 20 ++++++++++++++++++++ 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/libisofs/fs_local.c b/libisofs/fs_local.c index aee14a4..e67fcce 100644 --- a/libisofs/fs_local.c +++ b/libisofs/fs_local.c @@ -1003,10 +1003,8 @@ int iso_local_set_lfa_flags(char *disk_path, uint64_t lfa_flags, int max_bit, { int ret, old_max_bit; struct stat stbuf; - uint64_t known_user_mask, known_su_mask, non_settable, unknown, eff_flags; + uint64_t eff_flags; - iso_util_get_lfa_masks(&known_user_mask, &known_su_mask, &non_settable, - &unknown); *os_errno = 0; if (flag & 32) ret = stat(disk_path, &stbuf); @@ -1018,10 +1016,7 @@ int iso_local_set_lfa_flags(char *disk_path, uint64_t lfa_flags, int max_bit, } if ((stbuf.st_mode & S_IFMT) == S_IFLNK && !(flag & 32)) return 3; - if (flag & 1) - change_mask &= ~known_su_mask; - if (flag & 2) - change_mask &= (known_user_mask | known_su_mask); + change_mask= iso_util_get_effective_lfa_mask(change_mask, flag & 3); if (change_mask == 0) { return 1; } else if (change_mask == ~((uint64_t) 0)) { diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 9bcaa58..22ddcad 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -8187,6 +8187,27 @@ int iso_util_decode_lfa_flags(char *flags_text, uint64_t *lfa_flags, int flag); */ void iso_util_get_lfa_masks(uint64_t *user_settable, uint64_t *su_settable, uint64_t *non_settable, uint64_t *unknown); + + +/** + * Return the effective change mask which will be used by + * iso_local_set_lfa_flags() with the same input of parameters change_mask + * and flag bits 0 and 1. + * + * @param change_mask + * Tells which bits of lfa_flags are meant to change attribute flags + * of the file. Submit ~((uint64_t) 0) if all bits may cause changes. + * The set of changeable bits may further be restricted by bit0 and bit1 + * of parameter flag. + * @param flag + * Bitfield for control purposes + * bit0= do not try to change known superuser flags + * bit1= change only known chattr settable flags + * + * @since 1.5.8 + */ +uint64_t iso_util_get_effective_lfa_mask(uint64_t change_mask, int flag); + /* Default in case that the compile environment has no macro PATH_MAX. diff --git a/libisofs/libisofs.ver b/libisofs/libisofs.ver index 7c4dee9..b93d455 100644 --- a/libisofs/libisofs.ver +++ b/libisofs/libisofs.ver @@ -392,6 +392,7 @@ iso_node_get_lfa_flags; iso_node_set_lfa_flags; iso_util_decode_lfa_flags; iso_util_encode_lfa_flags; +iso_util_get_effective_lfa_mask; iso_util_get_lfa_masks; } LIBISOFS6; diff --git a/libisofs/util.c b/libisofs/util.c index 9c6a08b..fc27f5b 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -2642,3 +2642,23 @@ void iso_util_get_lfa_masks(uint64_t *user_settable, uint64_t *su_settable, *unknown = 0xffffffff8d602200; } + +/* + * @param flag Bitfield for control purposes + * bit0= do not try to change known superuser flags + * bit1= change only known chattr settable flags + */ +uint64_t iso_util_get_effective_lfa_mask(uint64_t change_mask, int flag) +{ + uint64_t known_user_mask, known_su_mask, non_settable, unknown; + + iso_util_get_lfa_masks(&known_user_mask, &known_su_mask, &non_settable, + &unknown); + if (flag & 1) + change_mask &= ~known_su_mask; + if (flag & 2) + change_mask &= (known_user_mask | known_su_mask); + return change_mask; +} + +