From 0ae91ebe6e50d78f06b27eb6dfaf7648d97b9db4 Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 3 Jun 2022 13:40:46 -0400 Subject: Support all standard `pinentry` options This is a first step to making `anypinentry` into a drop-in replacement for `pinentry-*` The options processing was changed to use `getopt(1)` which adds a dependency but also simplifies the options processing. Version number bumped to '0.1' --- anypinentry | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/anypinentry b/anypinentry index f550be1..beb8df0 100755 --- a/anypinentry +++ b/anypinentry @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="0.0"; +VERSION="0.1"; if [[ -z "$DISPLAY" ]]; then DISPLAY=":1"; @@ -114,20 +114,46 @@ help() { } parse_cliargs() { - [[ $# -le 0 ]] && return 0; - - case "$1" in - -D|--display) export DISPLAY="$2"; shift 1 ;; - --error-command) display_error_action="$2"; shift 1 ;; - --prompt) prompt_action="$2"; shift 1 ;; - --confirm) confirm_action="$2"; shift 1 ;; - -v|--version) echo "anypinentry-$VERSION" && exit 0 ;; - -h|--help) help && exit 0 ;; - *) help && exit 1 ;; - esac; - - shift 1; - parse_cliargs "$@"; + getopt -T + if [ "$?" -ne 4 ]; then + printf "Your version of getopt(1) is out of date\n" >&2 + exit 1 + fi + + TEMP=$(getopt -n "$0" -o dD:T:N:C:M:o:gWc:a:h \ + --long debug,display:,ttyname:,ttytype:,lc-ctype:,lc-messages:,timeout:,no-global-grab,parent-wid,colors:,ttyalert:,prompt:,confirm:,error:,help,version \ + -- "$@") + + if [ $? -ne 0 ]; then + help + exit 1 + fi + + eval set -- "$TEMP" + unset TEMP + + while true; do + case "$1" in + -d | --debug) shift ;; + -D | --display) shift 2 ;; + -T | --ttyname) shift 2 ;; + -N | --ttytype) shift 2 ;; + -C | --lc-ctype) shift 2 ;; + -M | --lc-messages) shift 2 ;; + -o | --timeout) shift 2 ;; + -g | --no-global-grab) shift ;; + -W | --parent-wid) shift ;; + -c | --colors) echo "colors=$2"; shift 2 ;; + -a | --ttyalert) shift 2 ;; + --error-command) display_error_action="$2"; shift 2 ;; + --prompt) prompt_action="$2"; shift 2 ;; + --confirm) confirm_action="$2"; shift 2 ;; + -h | --help) help && exit 0 ;; + --version) echo "anypinentry-$VERSION" && exit 0 ;; + --) shift; break ;; + *) ;; + esac + done } -- cgit v1.3.1 From d56946fce920c738a29ef854708bf9a6632f4ef9 Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 3 Jun 2022 13:43:52 -0400 Subject: Update 'help' output - Includes standard `pinentry` options - Provides basic documentation on custom `anypinentry` options --- anypinentry | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/anypinentry b/anypinentry index beb8df0..d281873 100755 --- a/anypinentry +++ b/anypinentry @@ -111,6 +111,44 @@ interpret_command() { help() { echo "Usage: $0 [-D DISPLAY] [--prompt script] [--confirm script] [-hv]"; + +cat < + +END + +printf "Usage: %s [options] (-h for help)\n" "$0" >&2 + +cat <. +END } parse_cliargs() { -- cgit v1.3.1 From d526b3ce2e69c7ae9f182768202d5fb540d8cb16 Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 3 Jun 2022 15:23:31 -0400 Subject: Implement most (all?) `pinentry` commands Many commands are "implemented" by doing nothing because they don't really apply to the way `anypinentry` works --- anypinentry | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/anypinentry b/anypinentry index d281873..a9608d5 100755 --- a/anypinentry +++ b/anypinentry @@ -40,6 +40,8 @@ show_error() { cancelled_error() { echo "ERR 99 Operation cancelled "; } com_error() { echo "ERR 99 Operation cancelled "; } +not_implemented_error() { echo "ERR 536870981 Not implemented "; } +unknown_error() { echo "ERR 536871187 Unknown IPC command "; } @@ -84,25 +86,75 @@ confirm_prompt() { [[ "$res" == "$AP_YES" ]] && echo "OK" || cancelled_error; } +pinentry_help() { + cat < Date: Fri, 3 Jun 2022 15:26:17 -0400 Subject: Print proper error messages User cancellation and improper 'GETINFO' commands now print the correct error messages --- anypinentry | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/anypinentry b/anypinentry index a9608d5..21b670d 100755 --- a/anypinentry +++ b/anypinentry @@ -38,8 +38,8 @@ show_error() { bash -c "$display_error_action" 2> /dev/null; } -cancelled_error() { echo "ERR 99 Operation cancelled "; } -com_error() { echo "ERR 99 Operation cancelled "; } +cancelled_error() { echo "ERR 83886179 Operation cancelled "; } +com_error() { echo "ERR 83886360 IP parameter error >"; } not_implemented_error() { echo "ERR 536870981 Not implemented "; } unknown_error() { echo "ERR 536871187 Unknown IPC command "; } -- cgit v1.3.1 From dca538f7e7dcd35dd4a421f403f9d572e992d443 Mon Sep 17 00:00:00 2001 From: Jeremy Brubaker Date: Fri, 3 Jun 2022 15:27:05 -0400 Subject: Change default prompt to 'PIN:' This is in line with all the `pinentry` interfaces I have looked at --- anypinentry | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anypinentry b/anypinentry index 21b670d..1199491 100755 --- a/anypinentry +++ b/anypinentry @@ -8,7 +8,7 @@ if [[ -z "$DISPLAY" ]]; then fi title=""; -prompt_string="Password :: "; +prompt_string="PIN: "; description=""; keyinfo=""; repeat=""; -- cgit v1.3.1