URI: 
       tForce checking master password regardless of operation - safe - password protected secret keeper
  HTML git clone git://git.z3bra.org/safe.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 7a35319955c94c158db21a7e368e58f974830d05
   DIR parent 788fd208467d17a169a655453b20510ba6245cfb
  HTML Author: Willy Goiffon <dev@z3bra.org>
       Date:   Wed,  5 Jun 2019 18:13:30 +0200
       
       Force checking master password regardless of operation
       
       Diffstat:
         M safe.c                              |      28 ++++++++++++++--------------
       
       1 file changed, 14 insertions(+), 14 deletions(-)
       ---
   DIR diff --git a/safe.c b/safe.c
       t@@ -400,21 +400,21 @@ main(int argc, char *argv[])
                        close(fd);
                }
        
       -        if (aflag) {
       -                fd = open(MASTER, O_RDONLY);
       -                if (fd < 0)
       -                        err(1, "%s", MASTER);
       -                xread(fd, s.salt, sizeof(s.salt), NULL);
       -                deriv((char *)passphrase, &s);
       -
       -                /* do not store secret if master password mismatch */
       -                if (trydecrypt(&s, fd) < 0) {
       -                        fprintf(stderr, "incorrect master password\n");
       -                        close(fd);
       -                        return -1;
       -                }
       +        fd = open(MASTER, O_RDONLY);
       +        if (fd < 0)
       +                err(1, "%s", MASTER);
       +        xread(fd, s.salt, sizeof(s.salt), NULL);
       +        deriv((char *)passphrase, &s);
       +
       +        /* do not store secret if master password mismatch */
       +        if (trydecrypt(&s, fd) < 0) {
       +                fprintf(stderr, "incorrect master password\n");
                        close(fd);
       +                return -1;
       +        }
       +        close(fd);
        
       +        if (aflag) {
                        mkdir_p(dirname(secret), 0700);
                        fd = open(secret, O_WRONLY | O_CREAT | O_EXCL, 0600);
                        if (fd < 0)
       t@@ -429,7 +429,7 @@ main(int argc, char *argv[])
                                err(1, "%s", secret);
        
                        /* Read salt from the beginning of the file */
       -                xread(fd, s.salt, sizeof(s.salt), NULL);
       +                lseek(fd, sizeof(s.salt), SEEK_SET);
                        deriv((char *)passphrase, &s);
                        readsecret(&s, fd, STDOUT_FILENO);
                        close(fd);