Skip to content

Commit

Permalink
51 broke -E logic completely, rewise it
Browse files Browse the repository at this point in the history
  • Loading branch information
strlcat committed Aug 9, 2023
1 parent 522bfd5 commit 370a18a
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 31 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
70
71
2 changes: 0 additions & 2 deletions tfc_base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ void do_edbase64(char **fargv)
struct base64_encodestate estate;
size_t lread = 0;

xexit_no_nl = YES;

sfd = 0; dfd = 1;

if (fargv[0]) {
Expand Down
12 changes: 2 additions & 10 deletions tfc_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#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;
Expand All @@ -39,7 +37,7 @@ void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char *

va_start(ap, fmt);

if (statline_was_shown == YES && do_statline_dynamic == YES) tfc_esay("\n");
if (noexit == YES && (statline_was_shown == YES && do_statline_dynamic == YES)) tfc_esay("\n");

tfc_nfsay(stderr, "%s: ", tfc_format_pid(progname));
tfc_vfsay(stderr, NO, fmt, ap);
Expand All @@ -52,12 +50,9 @@ void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char *
va_end(ap);

if (nostats == NO) {
print_crypt_status(-1);
tfc_esay("\n");
print_crypt_status(TFC_SIGERR);
}

xexit_no_nl = YES;

_do_sil_exit:
if (noexit == YES) {
errno = 0;
Expand Down Expand Up @@ -102,16 +97,13 @@ void xexit(int status)
memset(pwdask, 0, sizeof(pwdask));
memset(pwdagain, 0, sizeof(pwdagain));

if (xexit_no_nl == NO) tfc_esay("\n");
exit(status);
}

void usage(void)
{
tfc_yesno is_embedded_prog = NO;

xexit_no_nl = YES;

if (optopt == 'V') {
tfc_say("tfcrypt toolkit, version %s.", _TFCRYPT_VERSION);
if (do_edcrypt != TFC_DO_PLAIN) {
Expand Down
8 changes: 1 addition & 7 deletions tfc_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@

static void print_crypt_status_genrnd(int signal)
{
if (signal == SIGTERM || signal == SIGINT) {
if (xexit_no_nl == YES) xexit_no_nl = NO;
}
print_crypt_status(signal);
}

static void exit_sigterm_genrnd(int signal)
{
if (xexit_no_nl == YES) xexit_no_nl = NO;
exit_sigterm(signal);
}

Expand Down Expand Up @@ -102,8 +98,6 @@ void gen_write_bytes(const char *foutname, tfc_fsize offset, tfc_fsize nrbytes)
size_t lblock, lio, lrem;
tfc_byte *pblk;

xexit_no_nl = YES;

for (x = 1; x < NSIG; x++) signal(x, SIG_IGN);
memset(&sigact, 0, sizeof(sigact));
sigact.sa_flags = SA_RESTART;
Expand Down Expand Up @@ -195,7 +189,7 @@ _wagain: lio = xwrite(fd, pblk, lrem);

if (verbose) tfc_esay("done!");
if (verbose || status_timer) {
print_crypt_status(0);
print_crypt_status(TFC_SIGSTAT);
tfc_esay("\n");
}

Expand Down
7 changes: 4 additions & 3 deletions tfc_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

void exit_sigterm(int signal)
{
tfc_esay("\n");
xexit(0);
}

Expand All @@ -55,10 +56,9 @@ void print_crypt_status(int signal)
tfc_yesno finished = NO;

if (last == YES) return;
if (signal <= 0) {
if (signal == TFC_SIGLAST) {
last = YES;
finished = YES;
do_stop = YES; /* error path or sksum finished */
if (signal == 0) last = YES;
}

switch (do_edcrypt) {
Expand Down Expand Up @@ -130,6 +130,7 @@ void print_crypt_status(int signal)
}

if (do_stop == NO && do_statline_dynamic == NO) tfc_esay("\n");
else if (signal == TFC_SIGLAST || signal == TFC_SIGERR) tfc_esay("\n");
statline_was_shown = YES;

if ((signal == SIGINT || signal == SIGTERM) && do_stop == YES) exit_sigterm(signal);
Expand Down
5 changes: 1 addition & 4 deletions tfc_skein.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

static void exit_sigterm_skein(int signal)
{
if (xexit_no_nl == YES) xexit_no_nl = NO;
exit_sigterm(signal);
}

Expand Down Expand Up @@ -118,7 +117,7 @@ _again: lio = xread(fd, pblk, lrem);
skein_final(hash, &sk);
if (ctr_mode == TFC_MODE_SKSUM) {
if (verbose || status_timer) {
print_crypt_status(-1);
print_crypt_status(TFC_SIGSTAT);
tfc_esay("\n");
}
total_processed_src = total_processed_dst = delta_processed = 0;
Expand All @@ -141,8 +140,6 @@ void do_sksum(char *spec, char **fargv)
int x = 0, xx;
size_t bits;

xexit_no_nl = YES;

if (macbits < TF_MAX_BITS) {
bits = macbits;
goto _dothat;
Expand Down
3 changes: 1 addition & 2 deletions tfcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ int main(int argc, char **argv)
break;
case 'q':
quiet = YES;
xexit_no_nl = YES;
verbose = NO;
do_full_hexdump = NO;
status_timer = 0;
Expand Down Expand Up @@ -1474,7 +1473,7 @@ _macwagain: lio = xwrite(dfd, pblk, lrem);
}
else if (do_mac == TFC_MAC_DROP2) total_processed_src += SKEIN_DIGEST_SIZE;

if (verbose || status_timer || (do_stop == YES && quiet == NO)) print_crypt_status(0);
if (verbose || status_timer || (do_stop == YES && quiet == NO)) print_crypt_status(TFC_SIGLAST);

xexit(exitcode);
return -1;
Expand Down
3 changes: 1 addition & 2 deletions tfcrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ extern struct getpasswd_state getps;
size_t xread(int fd, void *data, size_t szdata);
size_t xwrite(int fd, const void *data, size_t szdata);

extern tfc_yesno xexit_no_nl;

void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char *fmt, ...);
void xexit(int status);
void usage(void);
Expand Down Expand Up @@ -238,5 +236,6 @@ enum {
};
enum { TFC_CTR_SHOW = 1, TFC_CTR_HEAD, TFC_CTR_RAND, TFC_CTR_ZERO, TFC_CTR_SSET };
enum { TFC_NO_FTRUNC, TFC_DO_FTRUNC, TFC_FTRUNC_TAIL };
enum { TFC_SIGLAST = -2, TFC_SIGERR = -1, TFC_SIGSTAT = 0 };

#endif

0 comments on commit 370a18a

Please sign in to comment.