New options -check_md5, -check_md5_r, find action check_md5, test -has_md5

This commit is contained in:
2009-08-11 19:55:08 +00:00
parent 2069245137
commit 797a16be81
5 changed files with 269 additions and 753 deletions

View File

@@ -7594,12 +7594,18 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
iso_prefix, target, 0);
if(ret==2)
deleted= 1;
} else if(action == 33) {
} else if(action == 33) { /* get_any_xattr */
ret= Xorriso_getfattr(xorriso, (void *) node, show_path, NULL, 8);
} else if(action == 34) {
} else if(action == 34) { /* get_md5 */
ret= Xorriso_get_md5(xorriso, (void *) node, show_path, md5, 0);
if(ret >= 0)
ret= 1;
} else if(action == 35) { /* check_md5 */
ret= Xorriso_check_md5(xorriso, (void *) node, show_path, 2);
if(ret < xorriso->find_check_md5_result)
xorriso->find_check_md5_result= ret;
if(ret >= 0)
ret= 1;
} else { /* includes : 15 in_iso */
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
@@ -7615,8 +7621,6 @@ 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, char *path,
struct stat *boss_stbuf, struct stat *stbuf, int flag)
@@ -7632,7 +7636,7 @@ return:
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;
char ft, *decision, md5[16];
regmatch_t name_match;
off_t damage_start, damage_end, size;
void *xinfo_dummy;
@@ -7799,6 +7803,10 @@ return:
ret= regexec(arg2, path, 1, &name_match, 0);
value= !ret;
break; case 15: /* -has_md5 */
ret= Xorriso_get_md5(xorriso, node, path, md5, 1);
value= (ret > 0);
break; default:
/* >>> complain about unknown test type */;
@@ -7833,126 +7841,6 @@ int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
return(1);
}
#else /* Xorriso_findjob_on_expR */
int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
IsoNode *node, char *name, char *path,
struct stat *boss_stbuf, struct stat *stbuf,
int depth, int flag)
{
int ret, start_lba, end_lba, damage_filter, commit_filter, lba, a_filter;
int is_filtered= 0;
off_t damage_start, damage_end, size;
int lba_count, *file_end_lbas= NULL, *file_start_lbas= NULL, i;
void *wanted_node;
IsoStream *stream;
ret= Findjob_test(job, name, boss_stbuf, stbuf, depth, 1);
if(ret<=0)
return(ret);
Findjob_get_lba_damage_filter(job, &start_lba, &end_lba, &damage_filter, 0);
if(damage_filter != 0) {
ret= Xorriso_file_eval_damage(xorriso, node, &damage_start, &damage_end, 0);
if(ret < 0)
return(ret);
if((damage_filter > 0) != (ret > 0))
return(0);
}
if(start_lba != 0) {
ret= Xorriso__start_end_lbas(node, &lba_count,
&file_start_lbas, &file_end_lbas, &size, 0);
if(ret <= 0) {
Xorriso_process_msg_queues(xorriso, 0);
if(start_lba > 0)
goto ex;
} 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)
{ret= 0; goto ex;}
} else {
if(file_end_lbas[i] >= -start_lba && file_start_lbas[i] <= -end_lba)
{ret= 0; goto ex;}
}
}
}
}
Findjob_get_commit_filter(job, &commit_filter, 0);
if(commit_filter & 1) { /* -pending_data */
if(!LIBISO_ISREG(node))
{ret= 0; goto ex;}
ret= Xorriso__file_start_lba(node, &lba, 0);
if(ret > 0 && lba >= 0)
{ret= 0; goto ex;}
}
Findjob_get_acl_filter(job, &a_filter, 0);
if(a_filter) {
ret = Xorriso_getfacl(xorriso, (void *) node, "", NULL, 2);
if(ret <= 0) {
Xorriso_process_msg_queues(xorriso, 0);
goto ex;
}
if(a_filter < 0 && ret != 2)
{ret= 0; goto ex;}
if(a_filter > 0 && ret == 2)
{ret= 0; goto ex;}
}
Findjob_get_xattr_filter(job, &a_filter, 0);
if(a_filter) {
ret = Xorriso_getfattr(xorriso, (void *) node, "", NULL, 64);
if(ret < 0) {
Xorriso_process_msg_queues(xorriso, 0);
goto ex;
}
if(a_filter < 0 && ret > 0)
{ret= 0; goto ex;}
if(a_filter > 0 && ret == 0)
{ret= 0; goto ex;}
}
Findjob_get_aaip_filter(job, &a_filter, 0);
if(a_filter) {
{ void *xinfo_dummy;
ret= iso_node_get_xinfo(node, aaip_xinfo_func, &xinfo_dummy);
}
if(ret < 0) {
Xorriso_process_msg_queues(xorriso, 0);
goto ex;
}
if(a_filter < 0 && ret == 1)
{ret= 0; goto ex;}
if(a_filter > 0 && ret != 1)
{ret= 0; goto ex;}
}
Findjob_get_filter_filter(job, &a_filter, 0);
if(a_filter) {
is_filtered= 0;
if(LIBISO_ISREG(node)) {
stream= iso_file_get_stream((IsoFile *) node);
if(iso_stream_get_input_stream(stream, 0) != NULL)
is_filtered= 1;;
}
if(a_filter < 0 && is_filtered)
{ret= 0; goto ex;}
if(a_filter > 0 && !is_filtered)
{ret= 0; goto ex;}
}
Findjob_get_wanted_node(job, &wanted_node, 0);
if(wanted_node != NULL && ((IsoNode *) wanted_node) != node)
{ret= 0; goto ex;}
ret= 1;
ex:;
if(file_start_lbas != NULL)
free((char *) file_start_lbas);
if(file_end_lbas != NULL)
free((char *) file_end_lbas);
return(ret);
}
#endif /* ! Xorriso_findjob_on_expR */
/* @param flag bit0= recursion
bit1= do not count deleted files with rm and rm_r
@@ -12160,7 +12048,7 @@ ex:;
/*
@param flag bit0= do not report to result but only retrieve md5 text
bit6= check for existence of md5, return 0 or 1
@return 1= ok, 0= no md5 available, <0= other error
*/
int Xorriso_get_md5(struct XorrisO *xorriso, void *in_node, char *path,
char md5[16], int flag)
@@ -12185,7 +12073,6 @@ int Xorriso_get_md5(struct XorrisO *xorriso, void *in_node, char *path,
Xorriso_process_msg_queues(xorriso,0);
if(ret <= 0)
goto ex;
if(flag & 1)
{ret= 1; goto ex;}
@@ -12203,3 +12090,111 @@ ex:;
}
/* @param node Opaque handle to IsoNode which is to be inquired instead of path if it is not NULL.
@param path is used as address if node is NULL.
@param flag bit0= do not report to result but only indicate outcome
by return value
bit1= silently ignore nodes without MD5
bit2= do not only report mismatches but also matches
@return 2= no MD5 attached to node
1= ok, MD5 compared and matching
0= not ok, MD5 mismatch
<0= other error
*/
int Xorriso_check_md5(struct XorrisO *xorriso, void *in_node, char *path,
int flag)
{
int i, ret, wanted, rret;
IsoImage *image;
IsoNode *node;
IsoFile *file;
char node_md5[16], data_md5[16], buffer[64 * 1024];
void *stream= NULL, *ctx= NULL;
off_t todo;
node= (IsoNode *) in_node;
if(node == NULL) {
ret= Xorriso_get_node_by_path(xorriso, path, NULL, &node, 0);
if(ret<=0)
goto ex;
}
if(!LIBISO_ISREG(node)) {
strcpy(xorriso->info_text, "-check_md5: Not a data file: ");
Text_shellsafe(path, xorriso->info_text, 1);
if(!(flag & 2))
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
ret= 2; goto ex;
}
file= (IsoFile *) node;
/* obtain MD5 */
ret= Xorriso_get_volume(xorriso, &image, 0);
if(ret <= 0)
goto ex;
ret= iso_file_get_md5(image, file, node_md5, 0);
Xorriso_process_msg_queues(xorriso,0);
if(ret < 0)
{ret= -1; goto ex;}
if(ret == 0) {
strcpy(xorriso->info_text, "-check_md5: No MD5 recorded with file: ");
Text_shellsafe(path, xorriso->info_text, 1);
if(!(flag & 2))
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
ret= 2; goto ex;
}
/* Read file and compute MD5 */;
ret= Xorriso_iso_file_open(xorriso, path, (void *) node, &stream, 1);
if(ret <= 0)
{ret= -1; goto ex;}
ret= iso_md5_start(&ctx);
if(ret < 0)
goto ex;
todo= iso_file_get_size(file);
while(todo > 0) {
if(todo < sizeof(buffer))
wanted= todo;
else
wanted= sizeof(buffer);
rret = Xorriso_iso_file_read(xorriso, stream, buffer, wanted, 0);
if(rret <= 0)
{ret= -1; goto ex;}
todo-= rret;
ret = iso_md5_compute(ctx, buffer, rret);
if(ret < 0)
goto ex;
xorriso->pacifier_count+= rret;
xorriso->pacifier_byte_count+= rret;
Xorriso_pacifier_callback(xorriso, "content bytes read",
xorriso->pacifier_count, 0, "", 0);
}
ret= iso_md5_end(&ctx, data_md5);
if(ret < 0)
goto ex;
/* Report outcome */
for(i= 0; i < 16; i++)
if(node_md5[i] != data_md5[i])
break;
if(i < 16 ) {
sprintf(xorriso->result_line, "MD5 MISMATCH: ");
Text_shellsafe(path, xorriso->result_line, 1);
strcat(xorriso->result_line, "\n");
if(!(flag & 1))
Xorriso_result(xorriso,0);
ret= 0;
} else {
sprintf(xorriso->result_line, "md5 match : ");
Text_shellsafe(path, xorriso->result_line, 1);
strcat(xorriso->result_line, "\n");
if(flag & 4)
Xorriso_result(xorriso,0);
ret= 1;
}
ex:;
Xorriso_iso_file_close(xorriso, &stream, 0);
if(ctx != NULL)
iso_md5_end(&ctx, data_md5);
return(ret);
}