[PATCH] Add option '-m' to generate to add additional multiline data.
Tobias Girstmair
junkgir-passwd at yahoo.de
Thu Jan 10 16:16:52 CET 2019
That's something that has been bugging me for years! Is there any reason
why `generate -m` doesn't expect lines on stdin, like `insert -m` does?
lg
On Thu, Jan 10, 2019 at 03:33:30PM +0100, Calin Iorgulescu wrote:
>Hello,
>
>This patch adds the '-m' flag to 'generate', allowing the user to specify
>one or more multiline entries after the generated password. This is
>particularly useful when generating passwords used for website accounts where
>other pieces of info are added to the password entry. For example, if using
>an extension like browserpass[1], one might wish to add the account name as
>well. But conceivably additional info such as security question answers could
>be added. It is possible to specify multiple '-m' entries.
>
>Currently, achieving this requires an additional call to "pass edit", requiring
>a decryption of the password (which can be mildly annoying if a passphrase or
>smartcard is required). With this patch, it is reduced to:
>
>$ pass generate acme.com 20 -m "login: john.doe at acme.com" -m "pin: 1423"
>
>I hope this can prove useful!
>
>Best,
>Calin
>[1] https://github.com/browserpass/browserpass
>
>---
> src/password-store.sh | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
>diff --git a/src/password-store.sh b/src/password-store.sh
>index d89d455..e3e48b2 100755
>--- a/src/password-store.sh
>+++ b/src/password-store.sh
>@@ -276,7 +276,7 @@ cmd_usage() {
> overwriting existing password unless forced.
> $PROGRAM edit pass-name
> Insert a new password or edit an existing password using ${EDITOR:-vi}.
>- $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] pass-name [pass-length]
>+ $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] pass-name [pass-length] [-m "additional line"]
> Generate a new password of pass-length (or $GENERATED_LENGTH if unspecified) with optionally no symbols.
> Optionally put it on the clipboard and clear board after $CLIP_TIME seconds.
> Prompt before overwriting existing password unless forced.
>@@ -491,8 +491,8 @@ cmd_edit() {
> }
>
> cmd_generate() {
>- local opts qrcode=0 clip=0 force=0 characters="$CHARACTER_SET" inplace=0 pass
>- opts="$($GETOPT -o nqcif -l no-symbols,qrcode,clip,in-place,force -n "$PROGRAM" -- "$@")"
>+ local opts qrcode=0 clip=0 force=0 characters="$CHARACTER_SET" inplace=0 extralines=0 footer="" pass
>+ opts="$($GETOPT -o nqcifm: -l no-symbols,qrcode,clip,in-place,force -n "$PROGRAM" -- "$@")"
> local err=$?
> eval set -- "$opts"
> while true; do case $1 in
>@@ -501,10 +501,11 @@ cmd_generate() {
> -c|--clip) clip=1; shift ;;
> -f|--force) force=1; shift ;;
> -i|--in-place) inplace=1; shift ;;
>+ -m) shift; extralines=1; footer+="$1\n"; shift ;;
> --) shift; break ;;
> esac done
>
>- [[ $err -ne 0 || ( $# -ne 2 && $# -ne 1 ) || ( $force -eq 1 && $inplace -eq 1 ) || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--no-symbols,-n] [--clip,-c] [--qrcode,-q] [--in-place,-i | --force,-f] pass-name [pass-length]"
>+ [[ $err -ne 0 || ( $# -ne 2 && $# -ne 1 ) || ( $force -eq 1 && $inplace -eq 1 ) || ( $qrcode -eq 1 && $clip -eq 1 ) || ( $inplace -eq 1 && $extralines -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--no-symbols,-n] [--clip,-c] [--qrcode,-q] [--in-place,-i | --force,-f] pass-name [pass-length] [-m \"additional line\"]"
> local path="$1"
> local length="${2:-$GENERATED_LENGTH}"
> check_sneaky_paths "$path"
>@@ -520,7 +521,7 @@ cmd_generate() {
> read -r -n $length pass < <(LC_ALL=C tr -dc "$characters" < /dev/urandom)
> [[ ${#pass} -eq $length ]] || die "Could not generate password from /dev/urandom."
> if [[ $inplace -eq 0 ]]; then
>- echo "$pass" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "Password encryption aborted."
>+ { echo "$pass" ; echo -e "$footer" ; } | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "Password encryption aborted."
> else
> local passfile_temp="${passfile}.tmp.${RANDOM}.${RANDOM}.${RANDOM}.${RANDOM}.--"
> if { echo "$pass"; $GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n +2; } | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile_temp" "${GPG_OPTS[@]}"; then
>--
>2.20.1
>
>_______________________________________________
>Password-Store mailing list
>Password-Store at lists.zx2c4.com
>https://lists.zx2c4.com/mailman/listinfo/password-store
More information about the Password-Store
mailing list