X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfc_error.c;h=ba36658baa08838904bb5c4619b8d496ff3cb38c;hb=92b6bb91a5be9fc1b4d300f99b239cb8e3a6398d;hp=16e4cd0352010ced823d281de6fb6e3d7ac987f5;hpb=1a8928c3ab5bd19851a3d2d03451b2f8a25c62e9;p=tfcrypt.git diff --git a/tfc_error.c b/tfc_error.c index 16e4cd0..ba36658 100644 --- a/tfc_error.c +++ b/tfc_error.c @@ -28,18 +28,20 @@ #include "tfcrypt.h" +tfc_yesno xexit_no_nl; + void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char *fmt, ...) { va_list ap; char *s; - if (quiet) goto _ex; + if (quiet) goto _do_sil_exit; va_start(ap, fmt); if (statline_was_shown == YES && do_statline_dynamic == YES) tfc_esay("\n"); - tfc_nfsay(stderr, "%s: ", progname); + tfc_nfsay(stderr, "%s: ", tfc_format_pid(progname)); tfc_vfsay(stderr, NO, fmt, ap); if (errno && noerrno == NO) { s = strerror(errno); @@ -49,9 +51,14 @@ void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char * va_end(ap); - if (nostats == NO) print_crypt_status(-1); + if (nostats == NO) { + print_crypt_status(-1); + tfc_esay("\n"); + } + + xexit_no_nl = YES; -_ex: +_do_sil_exit: if (noexit == YES) { errno = 0; return; @@ -62,6 +69,18 @@ _ex: void xexit(int status) { + if (status > 1) goto _do_clean_and_exit; + + if (do_ftrunc > TFC_NO_FTRUNC) { + if (do_ftrunc == TFC_FTRUNC_TAIL) ftrunc_dfd = total_processed_dst; + if (ftruncate(dfd, (off_t)ftrunc_dfd) == -1) xerror(YES, NO, YES, "ftruncate(%d)", dfd); + } + if (do_preserve_time) fcopy_matime(dfd, &s_stat); + +_do_clean_and_exit: + xclose(sfd); + xclose(dfd); + memset(srcblk, 0, sizeof(srcblk)); memset(dstblk, 0, sizeof(dstblk)); @@ -83,6 +102,7 @@ void xexit(int status) memset(pwdask, 0, sizeof(pwdask)); memset(pwdagain, 0, sizeof(pwdagain)); + if (xexit_no_nl == NO) tfc_esay("\n"); exit(status); } @@ -90,12 +110,17 @@ void usage(void) { tfc_yesno is_embedded_prog = NO; + xexit_no_nl = YES; + if (optopt == 'V') { - char shash[64]; tfc_say("tfcrypt toolkit, version %s.", _TFCRYPT_VERSION); - hash_defaults(shash, sizeof(shash)); - tfc_say("Defaults hash: %s", shash); - memset(shash, 0, sizeof(shash)); + if (ctr_mode != TFC_MODE_PLAIN) { + char shash[64]; + + hash_defaults(shash, sizeof(shash)); + tfc_say("Defaults hash: %s", shash); + memset(shash, 0, sizeof(shash)); + } xexit(0); } @@ -266,7 +291,11 @@ void usage(void) tfc_say(" -: read a detached MAC signature from stdin,"); tfc_say(" drop: do not verify attached MAC, if any, and drop it from output."); tfc_say(" -m: just verify MAC provided with -M. Do not write output file."); - tfc_say(" This option must be specified after -M."); + tfc_say(" -u: almost same as -m, but turns on MAC pre-test mode, when verified"); + tfc_say(" signature enables writing output file. It is useful when decrypting small texts."); + tfc_say(" The source must be a seekable file, otherwise this mode will be disabled."); + tfc_say(" In this mode, decryption is done twice and verification done once."); + tfc_say(" Both -m and -u options must be specified after -M."); tfc_say(" -E how: how to behave on I/O errors (both src or dst):"); tfc_say(" exit: print error if not quiet, then exit,"); tfc_say(" cont: print error if not quiet, then continue,"); @@ -283,6 +312,7 @@ void usage(void) tfc_say(" -E xall: turn on error actions above for all errors, not just EIO errors."); tfc_say(" -E xseek: ignore positioning and other seek related errors."); tfc_say(" Multiple -E specifiers may be given in separate options."); + tfc_say(" -o logfile: redirect all messages to logfile instead of stderr."); tfc_say(" -O opts: set options (comma separated list):"); tfc_say(" sync: request a synchronous I/O for a output,"); tfc_say(" fsync: on each write() call a corresponding fsync(fd),"); @@ -297,9 +327,13 @@ void usage(void) tfc_say(" statless: emit less information in status line (only processed data)."); tfc_say(" norepeat: do not ask for any possible password confirmations."); tfc_say(" showsecrets: show passwords in plaintext instead of masking them."); + tfc_say(" finished: add \"finished\" word before status line when work is finished."); + tfc_say(" pid: show %s's process id near it's name in error messages, logs etc.", progname); + tfc_say(" readloops=val: when seekable source ends, reading continues from it's beginning again."); tfc_say(" prompt=str: set main password prompts to this string."); tfc_say(" macprompt=str: set MAC password prompts to this string."); tfc_say(" shorthex: with -H, do not print printable characters, dump only hex string."); + tfc_say(" logfile: (same as -o) redirect all messages to logfile instead of stderr."); tfc_say(" iobs=val: set IO block size value. Must not exceed %u bytes.", TFC_U(TFC_BLKSIZE)); tfc_say(" xtsblocks=val: use these nr of TF blocks per XTS block. Default is %u.", TFC_U(TFC_XTSBLOCKS)); tfc_say(" iseek=val: seek source file/device by these val bytes.");