tAdd new flag to change password prompt - safe - password protected secret keeper
 (HTM) git clone git://git.z3bra.org/safe.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit cadbbb3e8554063b5f363c0b395fa7849072dfa5
 (DIR) parent be7b04615cd9bef464bc7541b50d5c27022f80b9
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Fri, 28 Jun 2019 13:51:53 +0200
       
       Add new flag to change password prompt
       
       Diffstat:
         M safe.1                              |      14 ++++++++++----
         M safe.c                              |      26 +++++++++++++++-----------
       
       2 files changed, 25 insertions(+), 15 deletions(-)
       ---
 (DIR) diff --git a/safe.1 b/safe.1
       t@@ -8,7 +8,8 @@
        
        .Sh SYNOPSIS
        .Nm
       -.Op Fl hp
       +.Op Fl hr
       +.Op Fl s Ar prompt
        .Op Fl s Ar safe
        .Op Fl a
        .Ar secret
       t@@ -25,10 +26,15 @@ Decrypt file
        from your safe to stdout.
        .It Fl h
        Print a quick usage text.
       -.It Fl p
       -Push key to the
       +.It Fl r
       +Remember the password. The variable
        .Ev SAFE_SOCK
       -agent socket (see AGENT).
       +must be set and point to the UNIX-domain socket bound by a running agent
       +(see AGENT).
       +.It Fl p Ar prompt
       +Prompt user for password using text
       +.Ar prompt .
       +(default: "password:")
        .It Fl s Ar safe
        Set the path to your safe as
        .Ar safe .
 (DIR) diff --git a/safe.c b/safe.c
       t@@ -42,7 +42,7 @@ char *argv0;
        void
        usage(void)
        {
       -        fprintf(stderr, "usage: %s [-h] [-s safe] [[-a] entry]\n", argv0);
       +        fprintf(stderr, "usage: %s [-hr] [-s safe] [-p prompt] [[-a] entry]\n", argv0);
                exit(1);
        }
        
       t@@ -381,20 +381,24 @@ readsecret(struct safe *s, int in, int out)
        int
        main(int argc, char *argv[])
        {
       -        int fd, haskey = 0, hasmaster = 1, aflag = 0, pflag = 0;
       -        char *secret = NULL, *sockp = NULL, *safe = SAFE;
       +        int fd, haskey = 0, hasmaster = 1, aflag = 0, rflag = 0;
       +        char *prompt, *secret, *sockp, *safe = SAFE;
                struct safe s;
                struct rlimit rlim;
        
       -        safe  = getenv("SAFE_DIR");
       -        sockp = getenv("SAFE_SOCK");
       +        safe   = getenv("SAFE_DIR");
       +        sockp  = getenv("SAFE_SOCK");
       +        prompt = "password:";
        
                ARGBEGIN {
                case 'a':
                        aflag = 1;
                        break;
                case 'p':
       -                pflag = 1;
       +                prompt = EARGF(usage());
       +                break;
       +        case 'r':
       +                rflag = 1;
                        break;
                case 's':
                        safe = EARGF(usage());
       t@@ -403,7 +407,7 @@ main(int argc, char *argv[])
                        usage();
                } ARGEND
        
       -        if (argc != 1 && !pflag)
       +        if (argc != 1 && !rflag)
                        usage();
        
                if (sodium_init() < 0)
       t@@ -431,18 +435,18 @@ main(int argc, char *argv[])
                        hasmaster = 0;
                }
        
       -        if (!pflag && sockp) {
       +        if (!rflag && sockp) {
                        if (!readkey(&s, sockp))
                                haskey = 1;
                }
        
       -        if (pflag && !sockp) {
       +        if (rflag && !sockp) {
                        fprintf(stderr, "SAFE_SOCK variable is not set\n");
                        return -1;
                }
        
                if (!haskey) {
       -                if (readpass("password:", &passphrase, &pplen) < 0)
       +                if (readpass(prompt, &passphrase, &pplen) < 0)
                                return -1;
        
                        sodium_mlock(passphrase, pplen);
       t@@ -491,7 +495,7 @@ main(int argc, char *argv[])
                }
                close(fd);
        
       -        if (pflag)
       +        if (rflag)
                        return pushkey(&s, sockp);
        
                secret = argv[0];