Refusing to apply -chattr to non-dir, non-regular files

This commit is contained in:
2024-08-07 15:26:09 +02:00
parent 58fb826c1d
commit c142b7b58f
7 changed files with 122 additions and 77 deletions

View File

@ -3033,7 +3033,7 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
} else if(action == 61) { /* chattr */
ret= Xorriso_set_lfa_flags(xorriso, node, show_path, "",
chattr_flags, type, 1);
chattr_flags, type, 1 | 4);
} else { /* includes : 15 in_iso */
Xorriso_esc_filepath(xorriso, show_path, xorriso->result_line, 0);
@ -4717,6 +4717,12 @@ int Xorriso_decode_chattr_arg(struct XorrisO *xorriso, char *chattr_text,
@param operator chattr operation mode 0='=', 1='+', 2='-'
non-chattr modes: 3='.', 4="--remove-lfa-flags"
@param flag bit0= use lfa_flags and operator rather than chattr_text
bit1= do not refuse to set lfa_flags of files which
are neither directory nor regular file
bit2= if not bit1: refuse silently with return 2
bit3= do not change flags but only test if it would be
really attempted without bit3.
return 1 if yes, <= 0 if not (with SORRY event).
*/
int Xorriso_set_lfa_flags(struct XorrisO *xorriso, void *in_node, char *path,
char *chattr_text, uint64_t lfa_flags, int operator,
@ -4739,6 +4745,19 @@ int Xorriso_set_lfa_flags(struct XorrisO *xorriso, void *in_node, char *path,
if(ret <= 0)
return(ret);
}
if(!(flag & 2)) {
if(!(LIBISO_ISREG(node) || LIBISO_ISDIR(node) || operator == 4)) {
if(flag & 4)
return(2);
Xorriso_report_iso_error(xorriso, path, 0,
"File type unsuitable for -chattr",
0, "SORRY", 4);
return(0);
}
}
if(flag & 8)
return(1);
if(operator == 4) {
ret= Xorriso_path_setfattr(xorriso, (void *) node, path,