New API call iso_util_get_effective_lfa_mask()

This commit is contained in:
Thomas Schmitt 2024-08-11 12:30:50 +02:00
parent d717613c93
commit 443743d2d8
4 changed files with 44 additions and 7 deletions

View File

@ -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)) {

View File

@ -8189,6 +8189,27 @@ 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.
*/
#define Libisofs_default_path_maX 4096

View File

@ -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;

View File

@ -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;
}