-O readloops=n: read source repeatedly n times (by default disabled).
authorAndrey Rys <rys@lynxlynx.ru>
Sun, 28 Nov 2021 13:42:32 +0000 (14:42 +0100)
committerAndrey Rys <rys@lynxlynx.ru>
Sun, 28 Nov 2021 13:42:32 +0000 (14:42 +0100)
VERSION
tfc_error.c
tfc_random.c
tfcrypt.c

diff --git a/VERSION b/VERSION
index 82cced27d7be32719d009707139bd949ad6263c9..0691f67b202a873c99bdb9b99e15a667cb916a5b 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-51
+52
index ad14e7d0bc23eca1cf7b97230738f628fa8c75e2..ba36658baa08838904bb5c4619b8d496ff3cb38c 100644 (file)
@@ -329,6 +329,7 @@ void usage(void)
        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.");
index d3f2ee303ff09bcd8a9dfe6d93dc19518fb451be..ccafe5c28dc6e56da5209f7e6790c0f154af56bd 100644 (file)
@@ -181,8 +181,10 @@ _wagain:   lio = xwrite(fd, pblk, lrem);
        }
 
        if (verbose) tfc_esay("done!");
-       if (verbose || status_timer) print_crypt_status(0);
-       if (verbose) tfc_esay("\n");
+       if (verbose || status_timer) {
+               print_crypt_status(0);
+               tfc_esay("\n");
+       }
 
        xclose(fd);
        xexit(0);
index facb5077c9bd864cb592447dff6b3ce429b50296..6b21e960dbe93e6e68188a0df0d17a152bf6b666 100644 (file)
--- a/tfcrypt.c
+++ b/tfcrypt.c
@@ -29,6 +29,7 @@
 #include "tfcrypt.h"
 
 static tfc_byte svctr[TF_BLOCK_SIZE];
+static tfc_fsize rwd, do_read_loops, loopcnt;
 
 static void open_log(const char *logfile)
 {
@@ -129,7 +130,6 @@ int main(int argc, char **argv)
        double td;
        char *s, *d, *t, *stoi;
        size_t x, n;
-       tfc_fsize rwd;
 
        progpid = getpid();
        progname = basename(argv[0]);
@@ -339,6 +339,10 @@ _baddfname:
                                                show_when_done = YES;
                                        else if (!strcmp(s, "pid"))
                                                show_pid = YES;
+                                       else if (!strncmp(s, "readloops", 9) && *(s+9) == '=') {
+                                               do_read_loops = tfc_humanfsize(s+10, &stoi);
+                                               if (!str_empty(stoi)) do_read_loops = NOSIZE;
+                                       }
                                        else if (!strncmp(s, "logfile", 7) && *(s+7) == '=')
                                                open_log(s+8);
                                        else if (!strncmp(s, "iobs", 4) && *(s+4) == '=') {
@@ -1157,6 +1161,7 @@ _decrypt_again_vrfy2:
        }
 
 _nodecrypt_again_vrfy2:
+       loopcnt = 1;
        errno = 0;
        do_stop = NO;
        while (1) {
@@ -1166,7 +1171,15 @@ _nodecrypt_again_vrfy2:
                lrem = lblock = blk_len_adj(maxlen, total_processed_src, blksize);
                if (error_action == TFC_ERRACT_SYNC) rdpos = tfc_fdgetpos(sfd);
 _ragain:       lio = xread(sfd, pblk, lrem);
-               if (lio == 0) do_stop = YES;
+               if (lio == 0) {
+                       if ((do_read_loops != 0 && sfd != 0) && (loopcnt < do_read_loops)) {
+                               lseek(sfd, 0L, SEEK_SET);
+                               loopcnt++;
+                               goto _ragain;
+                       }
+
+                       do_stop = YES;
+               }
                if (lio != NOSIZE) ldone += lio;
                else {
                        if (errno != EIO && catch_all_errors != YES)