From efaab52265faff0f50581cc95bbacce2eb62760e Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 27 Aug 2024 10:51:36 +0200 Subject: [PATCH] New flag bit5 for iso_file_source_get_aa_string() and iso_image_set_ignore_aclea(), new flag bit7 for iso_local_get_lfa_flags() --- libisofs/aaip-os-linux.c | 18 +++++++++++++++++- libisofs/builder.c | 3 ++- libisofs/fs_local.c | 5 +++-- libisofs/image.c | 5 ++++- libisofs/image.h | 8 ++++++++ libisofs/libisofs.h | 18 ++++++++++++++++++ 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/libisofs/aaip-os-linux.c b/libisofs/aaip-os-linux.c index bf2310f..dc0582e 100644 --- a/libisofs/aaip-os-linux.c +++ b/libisofs/aaip-os-linux.c @@ -281,6 +281,8 @@ static int get_single_attr(char *path, char *name, size_t *value_length, bit5= in case of symbolic link: inquire link target bit6= do not obtain Linux style file attribute flags (chattr) + bit7= With bit6: Ignore non-settable flags and do + not record "isofs.fa" if all flags are zero bit15= free memory of names, value_lengths, values @return 1 ok (reserved for FreeBSD: 2 ok, no permission to inspect @@ -454,7 +456,12 @@ try_lfa_flags:; if(!(flag & 64)) { /* ( aaip_get_lfa_flags() does not gracefully handle dead symbolic links) */ - ret= iso_local_get_lfa_flags(path, &lfa_flags, &max_bit, &os_errno, 0); + ret= iso_local_get_lfa_flags(path, &lfa_flags, &max_bit, &os_errno, + flag & (1 << 7)); + if((flag & (1 << 7)) && lfa_flags == (uint64_t) 0) { + /* virtually no lfa_flags because no settable ones */ + ret= 4; + } if(ret == 1 || ret == 2) { ret= aaip_encode_lfa_flags(lfa_flags, lfa_value, &lfa_length, 0); if(ret > 0) { @@ -528,6 +535,7 @@ ex:; (else return 4 on ENOTTY) bit2= do not issue own error messages with operating system errors + bit7= Ignore non-settable flags @return 1= ok, all local attribute flags are in lfa_flags 2= ok, but some local flags could not be mapped to the FS_*_FL bits @@ -539,6 +547,7 @@ int aaip_get_lfa_flags(char *path, uint64_t *lfa_flags, int *max_bit, int *os_errno, int flag) { int ret= 0; + static uint64_t user_settable= 0, su_settable= 0, non_settable= 0, unknown= 0; #ifdef Libisofs_with_aaip_lfa_flagS int fd; @@ -549,6 +558,10 @@ int aaip_get_lfa_flags(char *path, uint64_t *lfa_flags, int *max_bit, *max_bit= -1; *os_errno= 0; + if(non_settable == (uint64_t) 0) + iso_util_get_lfa_masks(&user_settable, &su_settable, &non_settable, + &unknown); + #ifdef Libisofs_with_aaip_lfa_flagS #ifdef FS_IOC_GETFLAGS fd= open(path, O_RDONLY | O_NDELAY); @@ -579,6 +592,9 @@ int aaip_get_lfa_flags(char *path, uint64_t *lfa_flags, int *max_bit, else *max_bit= sizeof(long) * 8 - 1; + if(flag & (1 << 7)) + *lfa_flags&= ~non_settable; + ret= 1; #endif /* FS_IOC_GETFLAGS */ diff --git a/libisofs/builder.c b/libisofs/builder.c index a74ff7b..bad1bc2 100644 --- a/libisofs/builder.c +++ b/libisofs/builder.c @@ -254,7 +254,8 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image, 1 | (image->builder_ignore_acl << 1) | (image->builder_ignore_ea << 2) | (image->builder_take_all_ea << 3) | - ((!image->builder_ignore_lfa_flags) << 4)); + ((!image->builder_ignore_lfa_flags) << 4) | + (image->builder_ignore_ro_lfa_flags << 5) ); if(ret == 2) image->blind_on_local_get_attrs = 1; if (ret > 0 && aa_string != NULL) { diff --git a/libisofs/fs_local.c b/libisofs/fs_local.c index 192c6b3..d3c569c 100644 --- a/libisofs/fs_local.c +++ b/libisofs/fs_local.c @@ -524,7 +524,7 @@ int lfs_get_aa_string(IsoFileSource *src, unsigned char **aa_string, int flag) ret = aaip_get_attr_list(path, &num_attrs, &names, &value_lengths, &values, (!(flag & 2)) | 2 | (flag & 4) | (flag & 8) | 16 | - ((!(flag & 16)) << 6)); + ((!(flag & 16)) << 6) | ((!!(flag & 32)) << 7)); if (ret <= 0) { if (ret == -2) ret = ISO_AAIP_NO_GET_LOCAL; @@ -950,6 +950,7 @@ int iso_local_get_perms_wo_acl(char *disk_path, mode_t *st_mode, int flag) * Bitfield for control purposes * bit2= do not issue own error messages with operating system errors * bit5= in case of symbolic link: inquire link target + * bit7= Ignore non-settable Linux-like file attribute flags * @return * 1= ok, lfa_flags is valid * 2= ok, but some local flags could not be mapped to the FS_*_FL bits @@ -980,7 +981,7 @@ int iso_local_get_lfa_flags(char *disk_path, uint64_t *lfa_flags, int *max_bit, if ((stbuf.st_mode & S_IFMT) == S_IFLNK && !(flag & 32)) return 3; ret = aaip_get_lfa_flags(disk_path, lfa_flags, max_bit, os_errno, - flag & 4); + flag & (4 | (1 << 7))); if(ret == 0) return ISO_LFA_NOT_ENABLED; if(ret < 0) diff --git a/libisofs/image.c b/libisofs/image.c index dec591d..da1f64b 100644 --- a/libisofs/image.c +++ b/libisofs/image.c @@ -201,6 +201,7 @@ int iso_image_new(const char *name, IsoImage **image) img->builder_ignore_acl = 1; img->builder_ignore_ea = 1; img->builder_ignore_lfa_flags = 1; + img->builder_ignore_ro_lfa_flags = 0; img->truncate_mode = 1; img->truncate_length = LIBISOFS_NODE_NAME_MAX; img->truncate_buffer[0] = 0; @@ -632,6 +633,7 @@ void iso_image_set_ignore_aclea(IsoImage *image, int what) image->builder_ignore_ea = !!(what & 2); image->builder_ignore_lfa_flags= !(what & 4); image->builder_take_all_ea = !!(what & 8); + image->builder_ignore_ro_lfa_flags = !!(what & 32); } @@ -640,7 +642,8 @@ int iso_image_get_ignore_aclea(IsoImage *image) return image->builder_ignore_acl | (image->builder_ignore_ea << 1) | ((!image->builder_ignore_lfa_flags) << 2) | - (image->builder_take_all_ea << 3); + (image->builder_take_all_ea << 3) | + (image->builder_ignore_ro_lfa_flags << 5); } diff --git a/libisofs/image.h b/libisofs/image.h index 8bb102b..8d0bd12 100644 --- a/libisofs/image.h +++ b/libisofs/image.h @@ -152,6 +152,14 @@ struct Iso_Image */ unsigned int builder_ignore_lfa_flags : 1; + /** + * Whether to ignore Linux style file attribute flags (chattr) which are + * only readable but non-settable ("ZEIheVN"). + * Not in effect with loading a complete ISO image but only with image + * manipulation. + */ + unsigned int builder_ignore_ro_lfa_flags : 1; + /** * If not builder_ignore_ea : import all xattr namespaces from local * filesystem, not only "user. diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index da58738..f229751 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -862,6 +862,15 @@ struct IsoFileSource_Iface * not be able to produce it again. * bit1= No need to get ACL (no guarantee of exclusion) * bit2= No need to get xattr (no guarantee of exclusion) + * bit3= if not bit2: import all xattr namespaces from + * local filesystem, not only "user." + * bit4= Try to get Linux-like file attribute flags + * (chattr) as "isofs.fa" + * @since 1.5.8 + * bit5= With bit4: Ignore non-settable Linux-like file + * attribute flags and do not record "isofs.fa" + * if the other flags are all zero + * @since 1.5.8 * @param aa_string Returns a pointer to the AAIP string data. If no AAIP * string is available, *aa_string becomes NULL. * (See doc/susp_aaip_*_*.txt for the meaning of AAIP and @@ -1313,6 +1322,9 @@ int iso_image_new(const char *name, IsoImage **image); * @since 1.5.8 * bit3= if not bit1: import all xattr namespaces, not only "user." * @since 1.5.0 + * bit5= with bit2: Ignore non-settable Linux-like file attribute flags + * and do not record "isofs.fa" if the other flags are all zero + * @since 1.5.8 * all other bits are reserved * * @since 0.6.14 @@ -7270,6 +7282,10 @@ int iso_file_source_readlink(IsoFileSource *src, char *buf, size_t bufsiz); * bit4= Try to get Linux-like file attribute flags (chattr) * as "isofs.fa" * @since 1.5.8 + * bit5= With bit4: Ignore non-settable Linux-like file + * attribute flags and do not record "isofs.fa" + * if the other flags are all zero + * @since 1.5.8 * @return 1 means success (*aa_string == NULL is possible) * <0 means failure and must b a valid libisofs error code * (e.g. ISO_FILE_ERROR if no better one can be found). @@ -8059,6 +8075,8 @@ int iso_local_set_attrs(char *disk_path, size_t num_attrs, char **names, * Bitfield for control purposes * bit2= do not issue own error messages with system call errors * bit5= in case of symbolic link: inquire link target + * bit7= Ignore non-settable Linux-like file attribute flags + * @since 1.5.8 * @return * 1 = ok, lfa_flags is valid * 2 = ok, but some local flags could not be mapped to the FS_*_FL bits