Completed find action check_md5

master
Thomas Schmitt 13 years ago
parent 3b05800e08
commit 16d84807da
  1. 33
      xorriso/xorriso.1
  2. 71
      xorriso/xorriso.c
  3. 9
      xorriso/xorriso_private.h
  4. 2
      xorriso/xorriso_timestamp.h
  5. 22
      xorriso/xorrisoburn.c

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "Aug 10, 2009"
.TH XORRISO 1 "Aug 12, 2009"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -67,6 +67,8 @@ Can issue commands to mount older sessions on Linux or FreeBSD.
.br
Can check media for damages and copy readable blocks to disk.
.br
Can attach MD5 checksums to each data file and the whole session.
.br
Scans for optical drives, blanks re-useable optical media.
.br
Reads its instructions from command line arguments, dialog, and files.
@ -756,7 +758,8 @@ each single data file. If enabled then MD5 checksums get loaded from the image
if there are any. At image generation time they are computed for each file
which gets its data written into the new session. The checksums of files which
have their data in older sessions get copied into the new session.
For now checksums can be exploited only via find action get_md5.
Checksums can be exploited via options -check_md5, -check_md5_r, and via find
actions get_md5, check_md5.
.TP
\fB\-rom_toc_scan\fR "on"|"off"[:"emul_on"|"emul_off"]
Read-only drives do not tell the actual media type but show any media as
@ -1315,6 +1318,9 @@ Matches files which have ACL or any xattr.
\fB\-has_any_xattr\fR :
Matches files which have any xattr other than ACL.
.br
\fB\-has_md5\fR :
Matches data files which have MD5 checksums.
.br
\fB\-has_filter\fR :
Matches files which are filtered by -set_filter.
.br
@ -1432,6 +1438,11 @@ namespace "isofs".
.br
\fBget_md5\fR prints eventual recorded MD5 sum together with file path.
.br
\fBcheck_md5\fR compares eventual recorded MD5 sum with the file content
and reports if mismatch.
.br
E.g.: -find / -not -pending_data -exec check_md5 FAILURE --
.br
\fBsetfattr\fR sets or deletes xattr name value pairs.
.br
E.g.: -find / -has_xattr -exec setfattr --remove-all '' --
@ -2621,6 +2632,21 @@ have an -indev and a loaded image. ":force" may be appended after the number.
"use=sector_map" does not read any media but loads the file given by option
sector_map= and processes this virtual outcome.
.TP
\fB\-check_md5\fR severity iso_rr_path [***]
Compare the data content of the given files in the loaded image with their
recorded MD5 checksums, if there are any. In case of any mismatch an event of
the given severity is issued. It may then be handled by appropriate settings of
options -abort_on or -return_with which both can cause non-zero exit values
of the program run. Severity ALL suppresses that event.
.br
This option reports match and mismatch of data files to the result channel.
Non-data files cause NOTE events. There will also be UPDATE events from
data reading.
.TP
\fB\-check_md5_r\fR severity iso_rr_path [***]
Like -check_md5 but checking all data files underneath the given paths.
Only mismatching data files will be reported.
.TP
.B osirrox restore options:
.PP
Normally xorriso only writes to disk files which were given as stdio:
@ -3532,6 +3558,9 @@ ACL and xattr
.BR setfacl(1),
.BR getfattr(1),
.BR setfattr(1)
.TP
MD5 checksums
.BR md5sum(1)
.br
.SH AUTHOR
Thomas Schmitt <scdbackup@gmx.net>

@ -4829,7 +4829,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->start_time= 0.0;
m->last_update_time= 0.0;
m->find_compare_result= 1;
m->find_check_md5_result= 1;
m->find_check_md5_result= 0;
m->node_counter= 0;
m->node_array_size= 0;
@ -12470,6 +12470,35 @@ ex:;
}
int Xorriso_report_m5_outcome(struct XorrisO *xorriso, char *severity,
int flag)
{
if((xorriso->find_check_md5_result & 3) == 0) {
sprintf(xorriso->result_line,
"File contents and their MD5 checksums match.\n");
} else if(xorriso->find_check_md5_result & 1) {
sprintf(xorriso->result_line,
"Mismatch detected between file contents and MD5 checksums.\n");
}
Xorriso_result(xorriso,0);
if(xorriso->find_check_md5_result & 2) {
sprintf(xorriso->result_line,
"Encountered other errors during MD5 checking.\n");
Xorriso_result(xorriso,0);
}
if(xorriso->find_check_md5_result & 4) {
sprintf(xorriso->result_line,
"There were data files which had no MD5 and thus could not be checked.\n");
Xorriso_result(xorriso,0);
}
if((xorriso->find_check_md5_result & 3) && strcmp(severity, "ALL") != 0) {
sprintf(xorriso->info_text, "Event triggered by MD5 comparison mismatch");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, severity, 0);
}
return(1);
}
/* ---------------------------- Options API ------------------------ */
@ -13352,7 +13381,7 @@ int Xorriso_option_check_md5(struct XorrisO *xorriso,
return(ret);
}
xorriso->find_check_md5_result= 1;
xorriso->find_check_md5_result= 0;
for(i= 0; i < optc; i++) {
if(flag & 8) {
ret= Findjob_new(&job, optv[i], 0);
@ -13360,7 +13389,7 @@ int Xorriso_option_check_md5(struct XorrisO *xorriso,
Xorriso_no_findjob(xorriso, "-check_md5_r", 0);
{ret= -1; goto ex;}
}
Findjob_set_action_target(job, 35, NULL, 0);
Findjob_set_action_target(job, 35, severity, 0);
cpt= optv[i];
ret= Xorriso_findi_sorted(xorriso, job, (off_t) 0, 1, &cpt, 0);
Findjob_destroy(&job, 0);
@ -13368,12 +13397,16 @@ int Xorriso_option_check_md5(struct XorrisO *xorriso,
ret= xorriso->find_compare_result;
else {
ret= -1;
xorriso->find_check_md5_result= -1;
xorriso->find_check_md5_result|= 2;
}
} else {
ret= Xorriso_check_md5(xorriso, NULL, optv[i], 4);
if(ret < xorriso->find_check_md5_result)
xorriso->find_check_md5_result= ret;
if(ret < 0)
xorriso->find_check_md5_result|= 2;
else if(ret == 0)
xorriso->find_check_md5_result|= 1;
else if(ret == 2)
xorriso->find_check_md5_result|= 4;
}
if(ret>0 && !xorriso->request_to_abort)
continue; /* regular bottom of loop */
@ -13389,20 +13422,8 @@ int Xorriso_option_check_md5(struct XorrisO *xorriso,
Xorriso_pacifier_callback(xorriso, "content bytes read",
xorriso->pacifier_count, 0, "", 1);
report_outcome:;
if(xorriso->find_check_md5_result > 0) {
sprintf(xorriso->result_line,
"File contents and their MD5 checksums match.\n");
} else if(xorriso->find_check_md5_result == 0) {
sprintf(xorriso->result_line,
"Differences detected between file contents and MD5 checksums.\n");
} else {
sprintf(xorriso->result_line, "MD5 checking failed due to error.\n");
}
Xorriso_result(xorriso,0);
if(xorriso->find_check_md5_result <= 0 && strcmp(severity, "ALL") != 0) {
sprintf(xorriso->info_text, "Event triggered by MD5 comparison mismatch");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, severity, 0);
}
Xorriso_report_m5_outcome(xorriso, severity, 0);
ex:;
(*idx)= end_idx;
Xorriso_opt_args(xorriso, "-getfacl", argc, argv, *idx, &end_idx,
@ -13410,7 +13431,7 @@ ex:;
Findjob_destroy(&job, 0);
if(ret <= 0)
return(ret);
return(xorriso->find_check_md5_result > 0);
return((xorriso->find_check_md5_result & 3) == 0);
}
@ -14993,6 +15014,12 @@ not_enough_exec_arguments:;
Findjob_set_action_target(job, 33, NULL, 0);
} else if(strcmp(cpt, "get_md5")==0) {
Findjob_set_action_target(job, 34, NULL, 0);
} else if(strcmp(cpt, "check_md5")==0) {
if(i + 1 >= end_idx)
goto not_enough_exec_arguments;
i+= 1;
Findjob_set_action_target(job, 35, argv[i], 0);
flag|= 8;
} else {
sprintf(xorriso->info_text, "-find -exec: unknown action %s",
Text_shellsafe(argv[i], sfe, 0));
@ -15011,7 +15038,7 @@ sorry_ex:;
0);
else if(flag & 8) {
cpt= start_path;
ret= Xorriso_findi_sorted(xorriso, first_job, (off_t) 0, 1, &cpt, 0);
ret= Xorriso_findi_sorted(xorriso, first_job, (off_t) 0, 1, &cpt, 8);
} else
ret= Xorriso_findi(xorriso, first_job, NULL, (off_t) 0, NULL,
start_path, &dir_stbuf, 0, (flag&4)>>1);

@ -395,7 +395,10 @@ struct XorrisO { /* the global context of xorriso */
void *pacifier_fifo;
int find_compare_result; /* 1=everything matches , 0=mismatch , -1=error */
int find_check_md5_result; /* 1=everything matches , 0=mismatch , -1=error */
int find_check_md5_result; /* bit0= seen mismatch
bit1= seen error
bit2= seen data file without MD5
*/
/* Tree node collection and LBA sorting facility */
int node_counter;
@ -672,6 +675,10 @@ int Xorriso_compare_2_files(struct XorrisO *xorriso, char *disk_adr,
char *iso_adr, char *adr_common_tail,
int *result, int flag);
int Xorriso_report_m5_outcome(struct XorrisO *xorriso, char *severity,
int flag);
int Sfile_str(char target[SfileadrL], char *source, int flag);
double Sfile_microtime(int flag);

@ -1 +1 @@
#define Xorriso_timestamP "2009.08.11.194836"
#define Xorriso_timestamP "2009.08.12.130401"

@ -7602,8 +7602,12 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
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)
xorriso->find_check_md5_result|= 1;
else if(ret < 0)
xorriso->find_check_md5_result|= 2;
else if(ret == 2)
xorriso->find_check_md5_result|= 4;
if(ret >= 0)
ret= 1;
} else { /* includes : 15 in_iso */
@ -8158,6 +8162,7 @@ int Xorriso_path_from_lba(struct XorrisO *xorriso, IsoNode *node, int lba,
/* @param flag bit0= do not dive into trees
bit1= do not perform job->action on resulting node array
bit2= do not free node_array after all actions are done
bit3= eventually issue MD5 mismatch event
*/
int Xorriso_findi_sorted(struct XorrisO *xorriso, struct FindjoB *job,
off_t boss_mem, int filec, char **filev, int flag)
@ -8171,6 +8176,8 @@ int Xorriso_findi_sorted(struct XorrisO *xorriso, struct FindjoB *job,
array_job.start_path= NULL;
if((flag & 8) && job->action == 35)
xorriso->find_check_md5_result= 0;
if(job->action>=9 && job->action<=13) { /* actions which have own findjobs */
/* array_job replaces the hindmost job in the chain */
for(hindmost= job; hindmost->subjob != NULL; hindmost= hindmost->subjob)
@ -8275,6 +8282,8 @@ int Xorriso_findi_sorted(struct XorrisO *xorriso, struct FindjoB *job,
ret= 1;
ex:;
if((flag & 8) && job->action == 35)
Xorriso_report_m5_outcome(xorriso, job->target, 0);
if(!(flag & (2 | 4)))
Xorriso_destroy_node_array(xorriso, 0);
if(hmboss != NULL)
@ -12096,7 +12105,8 @@ ex:;
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
@return 3= not a data file
2= no MD5 attached to node
1= ok, MD5 compared and matching
0= not ok, MD5 mismatch
<0= other error
@ -12116,21 +12126,21 @@ int Xorriso_check_md5(struct XorrisO *xorriso, void *in_node, char *path,
if(node == NULL) {
ret= Xorriso_get_node_by_path(xorriso, path, NULL, &node, 0);
if(ret<=0)
goto ex;
{ret= -1; 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;
ret= 3; goto ex;
}
file= (IsoFile *) node;
/* obtain MD5 */
ret= Xorriso_get_volume(xorriso, &image, 0);
if(ret <= 0)
goto ex;
{ret= -1; goto ex;}
ret= iso_file_get_md5(image, file, node_md5, 0);
Xorriso_process_msg_queues(xorriso,0);
if(ret < 0)

Loading…
Cancel
Save