Enhanced -find testing by operators -not, -or, -and, (, ), -if, -else, -endif
This commit is contained in:
@ -63,7 +63,6 @@
|
||||
|
||||
#endif /* Xorriso_standalonE */
|
||||
|
||||
#define Xorriso_with_aaiP yes
|
||||
|
||||
/* Some private in advance declarations */
|
||||
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
|
||||
@ -121,11 +120,6 @@ int Xorriso_path_from_node(struct XorrisO *xorriso, IsoNode *node, int lba,
|
||||
isoburn_igopt_rrip_version_1_10 | isoburn_igopt_aaip_susp_1_10 )
|
||||
|
||||
|
||||
/* <<< Whether to allow xattr and ACL with the root node.
|
||||
(It is supposed to work since libisofs-ng resision 479)
|
||||
*/
|
||||
#define Xorriso_root_with_aaiP yes
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
@ -1803,35 +1797,6 @@ int Xorriso_get_volume(struct XorrisO *xorriso, IsoImage **volume,
|
||||
return(*volume != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@param flag bit0= do not issue warning
|
||||
*/
|
||||
int Xorriso_aaip_warn_of_root(struct XorrisO *xorriso, IsoNode *node, int flag)
|
||||
{
|
||||
|
||||
#ifndef Xorriso_root_with_aaiP
|
||||
|
||||
int ret;
|
||||
IsoDir *root= NULL;
|
||||
IsoImage *volume;
|
||||
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
root= iso_image_get_root(volume);
|
||||
if(node == (IsoNode *) root) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot attach ACL or xattr to ISO root directory");
|
||||
if(!(flag & 1))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif /* ! Xorriso_root_with_aaiP */
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0=do not complain about non existent node */
|
||||
int Xorriso_node_from_path(struct XorrisO *xorriso, IsoImage *volume,
|
||||
@ -2131,11 +2096,9 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
|
||||
|
||||
mode= stbuf->st_mode;
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
if((!(flag & 2)) && !(xorriso->do_aaip & 1))
|
||||
/* Will drop ACL. Update mode S_IRWXG by eventual group:: ACL entry */
|
||||
iso_local_get_perms_wo_acl(disk_path, &mode, flag & 32);
|
||||
#endif
|
||||
|
||||
if((flag&1) && S_ISDIR(mode)) {
|
||||
if(mode&S_IRUSR)
|
||||
@ -2152,8 +2115,6 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
|
||||
iso_node_set_mtime(node, stbuf->st_mtime);
|
||||
iso_node_set_ctime(node, stbuf->st_ctime);
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
|
||||
if((xorriso->do_aaip & 5) && !(flag & 2)) {
|
||||
ret= iso_local_get_attrs(disk_path, &num_attrs, &names, &value_lengths,
|
||||
&values, ((xorriso->do_aaip & 1) && !(flag & 2))
|
||||
@ -2184,17 +2145,11 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
|
||||
goto ex;
|
||||
}
|
||||
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
|
||||
ret= 1;
|
||||
ex:;
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
iso_local_get_attrs(disk_path, &num_attrs, &names, &value_lengths,
|
||||
&values, 1 << 15); /* free memory */
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@ -3056,8 +3011,6 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
|
||||
|
||||
mode= iso_node_get_permissions(node);
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
|
||||
if(xorriso->do_aaip & (2 | 8 | 16)) {
|
||||
ret= iso_node_get_attrs(node, &num_attrs, &names, &value_lengths, &values,
|
||||
(!!(xorriso->do_aaip & 2)) | (!(xorriso->do_aaip & (8 | 16))) << 2);
|
||||
@ -3083,8 +3036,6 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
|
||||
if(!(xorriso->do_aaip & 2))
|
||||
mode= iso_node_get_perms_wo_acl(node);
|
||||
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
|
||||
if(is_dir && (flag&2)) {
|
||||
ret= Xorriso_fake_stbuf(xorriso, "", &stbuf, &node,
|
||||
1 | ((!!(xorriso->do_aaip & 2)) << 3));
|
||||
@ -5759,18 +5710,10 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd,
|
||||
continue;
|
||||
link_target[0]= 0;
|
||||
if((flag&5)==1) { /* -ls_l */
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
iso_node_get_acl_text(node, &a_text, &d_text, 16);
|
||||
#endif
|
||||
|
||||
ret= Xorriso_format_ls_l(xorriso, &stbuf,
|
||||
1 | ((a_text != NULL || d_text != NULL) << 1));
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
iso_node_get_acl_text(node, &a_text, &d_text, 1 << 15);
|
||||
#endif
|
||||
|
||||
if(ret<=0)
|
||||
continue;
|
||||
if(LIBISO_ISLNK(node)) {
|
||||
@ -6686,6 +6629,215 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
}
|
||||
|
||||
|
||||
#ifdef Xorriso_findjob_on_expR
|
||||
|
||||
int Exprtest_match(struct XorrisO *xorriso, struct ExprtesT *ftest,
|
||||
void *node_pt, char *name,
|
||||
struct stat *boss_stbuf, struct stat *stbuf, int flag)
|
||||
/*
|
||||
return:
|
||||
<0 = error
|
||||
0 = does not match
|
||||
1 = does match
|
||||
2 = immediate decision : does not match
|
||||
3 = immediate decision : does match
|
||||
*/
|
||||
{
|
||||
int value=0, ret, start_lba, end_lba;
|
||||
int lba_count, *file_end_lbas= NULL, *file_start_lbas= NULL, i;
|
||||
void *arg1, *arg2;
|
||||
char ft, *decision;
|
||||
regmatch_t name_match;
|
||||
off_t damage_start, damage_end, size;
|
||||
void *xinfo_dummy;
|
||||
IsoNode *node;
|
||||
IsoStream *stream;
|
||||
|
||||
if(ftest == NULL)
|
||||
return(1);
|
||||
|
||||
node= (IsoNode *) node_pt;
|
||||
arg1= ftest->arg1;
|
||||
arg2= ftest->arg2;
|
||||
|
||||
if(node == NULL) {
|
||||
if(ftest->test_type > 2 && ftest->test_type != 4) {
|
||||
value= 0;
|
||||
goto ex;
|
||||
}
|
||||
}
|
||||
|
||||
switch(ftest->test_type) {
|
||||
case 0: /* -false */
|
||||
value= 0;
|
||||
|
||||
break; case 1: /* -name *arg1 (regex in *arg2) */
|
||||
ret= regexec(arg2, name, 1, &name_match, 0);
|
||||
value= !ret;
|
||||
|
||||
break; case 2: /* -type *arg1 */
|
||||
value= 1;
|
||||
ft= *((char *) arg1);
|
||||
if(ft!=0) {
|
||||
if(S_ISBLK(stbuf->st_mode)) {
|
||||
if(ft!='b')
|
||||
value= 0;
|
||||
} else if(S_ISCHR(stbuf->st_mode)) {
|
||||
if(ft!='c')
|
||||
value= 0;
|
||||
} else if(S_ISDIR(stbuf->st_mode)) {
|
||||
if(ft=='m') {
|
||||
if(node != NULL)
|
||||
value= 0;
|
||||
else if(boss_stbuf==NULL)
|
||||
value= 0;
|
||||
else if(boss_stbuf->st_dev == stbuf->st_dev)
|
||||
value= 0;
|
||||
} else if(ft!='d')
|
||||
value= 0;
|
||||
} else if(S_ISFIFO(stbuf->st_mode)) {
|
||||
if(ft!='p')
|
||||
value= 0;
|
||||
} else if(S_ISREG(stbuf->st_mode)) {
|
||||
if(ft!='f' && ft!='-')
|
||||
value= 0;
|
||||
} else if(((stbuf->st_mode)&S_IFMT)==S_IFLNK) {
|
||||
if(ft!='l')
|
||||
value= 0;
|
||||
} else if(((stbuf->st_mode)&S_IFMT)==S_IFSOCK) {
|
||||
if(ft!='s')
|
||||
value= 0;
|
||||
} else if((flag & 1) && ((stbuf->st_mode) & S_IFMT) == Xorriso_IFBOOT) {
|
||||
if(ft!='e' || node == NULL)
|
||||
value= 0;
|
||||
} else {
|
||||
if(ft!='X')
|
||||
value= 0;
|
||||
}
|
||||
}
|
||||
|
||||
break; case 3: /* -damaged */;
|
||||
value= Xorriso_file_eval_damage(xorriso, node, &damage_start, &damage_end,
|
||||
0);
|
||||
if(value > 0)
|
||||
value= 1;
|
||||
|
||||
break; case 4: /* -lba_range *arg1 *arg2 */
|
||||
if(node == NULL) {
|
||||
value= !(start_lba >= 0);
|
||||
goto ex;
|
||||
}
|
||||
value= 1;
|
||||
start_lba= *((int *) ftest->arg1);
|
||||
end_lba= *((int *) ftest->arg2);
|
||||
ret= Xorriso__start_end_lbas(node, &lba_count,
|
||||
&file_start_lbas, &file_end_lbas, &size, 0);
|
||||
if(ret <= 0) {
|
||||
if(ret < 0)
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
if(start_lba >= 0)
|
||||
value= 0;
|
||||
} else {
|
||||
for(i= 0; i < lba_count; i++) {
|
||||
if(start_lba >= 0) {
|
||||
if(file_end_lbas[i] < start_lba || file_start_lbas[i] > end_lba)
|
||||
value= 0;
|
||||
} else {
|
||||
if(file_end_lbas[i] >= -start_lba && file_start_lbas[i] <= -end_lba)
|
||||
value= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break; case 5: /* -has_acl */
|
||||
ret = Xorriso_getfacl(xorriso, (void *) node, "", NULL, 2);
|
||||
if(ret <= 0) {
|
||||
value= -1;
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
goto ex;
|
||||
}
|
||||
value= (ret == 1);
|
||||
|
||||
break; case 6: /* -has_xattr */
|
||||
ret = Xorriso_getfattr(xorriso, (void *) node, "", NULL, 64);
|
||||
if(ret < 0) {
|
||||
value= -1;
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
goto ex;
|
||||
}
|
||||
value= (ret > 0);
|
||||
|
||||
break; case 7: /* -has_aaip */
|
||||
ret= iso_node_get_xinfo(node, aaip_xinfo_func, &xinfo_dummy);
|
||||
if(ret < 0) {
|
||||
value= -1;
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
goto ex;
|
||||
}
|
||||
value= (ret > 0);
|
||||
|
||||
break; case 8: /* -has_filter */
|
||||
value= 0;
|
||||
if(LIBISO_ISREG(node)) {
|
||||
stream= iso_file_get_stream((IsoFile *) node);
|
||||
if(iso_stream_get_input_stream(stream, 0) != NULL)
|
||||
value= 1;
|
||||
}
|
||||
|
||||
break; case 9: /* -wanted_node arg1 (for internal use) */
|
||||
value= (((IsoNode *) arg1) == node);
|
||||
|
||||
break; case 10: /* -pending_data */
|
||||
value= 1;
|
||||
if(!LIBISO_ISREG(node)) {
|
||||
value= 0;
|
||||
} else {
|
||||
ret= Xorriso__file_start_lba(node, &start_lba, 0);
|
||||
if(ret > 0 && start_lba >= 0)
|
||||
value= 0;
|
||||
}
|
||||
|
||||
break; case 11: /* -decision */
|
||||
value= 3;
|
||||
decision= (char *) arg1;
|
||||
if(strcmp(decision, "no") == 0 || strcmp(decision, "false") == 0 ||
|
||||
strcmp(decision, "0") == 0)
|
||||
value= 2;
|
||||
|
||||
break; default:
|
||||
|
||||
/* >>> complain about unknown test type */;
|
||||
|
||||
value= -1;
|
||||
|
||||
}
|
||||
|
||||
ex:;
|
||||
if(ftest->invert && value<=1 && value>=0)
|
||||
value= !value;
|
||||
if(file_start_lbas != NULL)
|
||||
free((char *) file_start_lbas);
|
||||
if(file_end_lbas != NULL)
|
||||
free((char *) file_end_lbas);
|
||||
return(value);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
IsoNode *node, char *name,
|
||||
struct stat *boss_stbuf, struct stat *stbuf,
|
||||
int depth, int flag)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret= Findjob_test_2(xorriso, job, node, name, boss_stbuf, stbuf, 1);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
return(1);
|
||||
}
|
||||
|
||||
#else /* Xorriso_findjob_on_expR */
|
||||
|
||||
int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
IsoNode *node, char *name,
|
||||
struct stat *boss_stbuf, struct stat *stbuf,
|
||||
@ -6763,13 +6915,9 @@ int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
}
|
||||
Findjob_get_aaip_filter(job, &a_filter, 0);
|
||||
if(a_filter) {
|
||||
#ifdef Xorriso_with_aaiP
|
||||
{ void *xinfo_dummy;
|
||||
ret= iso_node_get_xinfo(node, aaip_xinfo_func, &xinfo_dummy);
|
||||
}
|
||||
#else
|
||||
ret= 0;
|
||||
#endif
|
||||
if(ret < 0) {
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
goto ex;
|
||||
@ -6806,6 +6954,8 @@ ex:;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
#endif /* ! Xorriso_findjob_on_expR */
|
||||
|
||||
|
||||
/* @param flag bit0= recursion
|
||||
bit1= do not count deleted files with rm and rm_r
|
||||
@ -9070,14 +9220,8 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
}
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
ret= iso_node_get_acl_text(node, &text, &d_text, flag & 16);
|
||||
d_ret= (d_text != NULL);
|
||||
#else
|
||||
ret= d_ret= 0;
|
||||
#endif
|
||||
|
||||
if(ret < 0 || d_ret < 0) {
|
||||
if(path != NULL && path[0] != 0) {
|
||||
strcpy(xorriso->info_text, "Error with obtaining ACL of ");
|
||||
@ -9095,13 +9239,8 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
ret= 1 + (ret == 0);
|
||||
goto ex;
|
||||
}
|
||||
#ifdef Xorriso_with_aaiP
|
||||
strcpy(xorriso->info_text, "No ACL associated with ");
|
||||
Text_shellsafe(path, xorriso->info_text, 1);
|
||||
#else
|
||||
strcpy(xorriso->info_text,
|
||||
"ACL not enabled by Libisofs_with_aaiP/Xorriso_with_aaiP");
|
||||
#endif
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
||||
if(ret == 0)
|
||||
{ret= 2; goto ex;}
|
||||
@ -9229,19 +9368,7 @@ int Xorriso_setfacl(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
}
|
||||
|
||||
ret= Xorriso_aaip_warn_of_root(xorriso, node, flag & 1);
|
||||
if (ret < 0)
|
||||
goto ex;
|
||||
if (ret == 0)
|
||||
{ret= 1; goto ex;}
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
ret= iso_node_set_acl_text(node, access_text, default_text, 0);
|
||||
#else
|
||||
ret= 0;
|
||||
#endif
|
||||
|
||||
if(ret <= 0) {
|
||||
if(path != NULL && path[0] != 0) {
|
||||
strcpy(xorriso->info_text, "Error with setting ACL of ");
|
||||
@ -9366,20 +9493,8 @@ int Xorriso_setfattr(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
}
|
||||
|
||||
ret= Xorriso_aaip_warn_of_root(xorriso, node, !!(flag & 16));
|
||||
if (ret < 0)
|
||||
goto ex;
|
||||
if (ret == 0)
|
||||
{ret= 1; goto ex;}
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
ret= iso_node_set_attrs(node, num_attrs, names, value_lengths, values,
|
||||
flag & (1 | 2 | 4 | 8));
|
||||
#else
|
||||
ret= 0;
|
||||
#endif
|
||||
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
if(ret <= 0) {
|
||||
Xorriso_report_iso_error(xorriso, "", ret,
|
||||
@ -9419,8 +9534,6 @@ ex:;
|
||||
int Xorriso_local_getfacl(struct XorrisO *xorriso, char *disk_path,
|
||||
char **text, int flag)
|
||||
{
|
||||
#ifdef Xorriso_with_aaiP
|
||||
|
||||
int ret, skip= 0, colons= 0, countdown= 0;
|
||||
char *acl= NULL, *cpt, *wpt;
|
||||
|
||||
@ -9471,12 +9584,6 @@ int Xorriso_local_getfacl(struct XorrisO *xorriso, char *disk_path,
|
||||
*wpt= 0;
|
||||
|
||||
return(1);
|
||||
#else
|
||||
|
||||
*text= NULL;
|
||||
return(0);
|
||||
|
||||
#endif /* ! Xorriso_with_aaiP */
|
||||
}
|
||||
|
||||
|
||||
@ -9495,7 +9602,6 @@ int Xorriso_get_attrs(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
IsoNode *node;
|
||||
|
||||
if(flag & (1 << 15)) {
|
||||
#ifdef Xorriso_with_aaiP
|
||||
if(flag & 2) {
|
||||
iso_local_get_attrs(NULL, num_attrs, names, value_lengths, values,
|
||||
1 << 15);
|
||||
@ -9503,14 +9609,11 @@ int Xorriso_get_attrs(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
iso_node_get_attrs(NULL, num_attrs, names, value_lengths, values,
|
||||
1 << 15);
|
||||
}
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
return(1);
|
||||
}
|
||||
|
||||
*num_attrs= 0;
|
||||
if(flag & 2) {
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
ret= iso_local_get_attrs(path, num_attrs, names, value_lengths, values,
|
||||
flag & (8 | 32));
|
||||
if(ret < 0) {
|
||||
@ -9518,9 +9621,6 @@ int Xorriso_get_attrs(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
Text_shellsafe(path, xorriso->info_text, 1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
||||
}
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
;
|
||||
|
||||
} else {
|
||||
node= (IsoNode *) in_node;
|
||||
if(node == NULL) {
|
||||
@ -9528,7 +9628,6 @@ int Xorriso_get_attrs(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
}
|
||||
#ifdef Xorriso_with_aaiP
|
||||
ret= iso_node_get_attrs(node, num_attrs, names, value_lengths, values,
|
||||
0);
|
||||
if(ret < 0) {
|
||||
@ -9536,7 +9635,6 @@ int Xorriso_get_attrs(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
"Error when obtaining xattr of ISO node", 0, "FAILURE", 1);
|
||||
goto ex;
|
||||
}
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
|
||||
if(!(flag & 8)) {
|
||||
/* Filter away any non-userspace xattr */;
|
||||
|
Reference in New Issue
Block a user