commit fb12b50d7d0837a11292b8eaf28af79527f7c4b7 parent dac8e4acae1d05263e62ccb0407e960712a23720 Author: hellekin <hellekin@cepheide.org> Date: Sun, 2 Nov 2014 21:55:19 -0300 [cleanup] ask_password Diffstat:
M | tomb | | | 38 | +++++++++++++++++++++----------------- |
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/tomb b/tomb @@ -351,33 +351,37 @@ _check_swap() { } # Ask user for a password +# Wraps around the pinentry command, from the GnuPG project, as it +# provides better security and conveniently use the right toolkit. ask_password() { -# we use pinentry now -# comes from gpg project and is much more secure -# it also conveniently uses the right toolkit - - # pinentry has no custom icon setting - # so we need to temporary modify the gtk theme - if [ -r /usr/local/share/themes/tomb/gtk-2.0-key/gtkrc ]; then - GTK2_RC=/usr/local/share/themes/tomb/gtk-2.0-key/gtkrc - elif [ -r /usr/share/themes/tomb/gtk-2.0-key/gtkrc ]; then - GTK2_RC=/usr/share/themes/tomb/gtk-2.0-key/gtkrc - fi - title="Insert tomb password." - if [ $2 ]; then title="$2"; fi + local description=$1 + local title=${2:-Enter tomb password.} + local gtkrc="share/themes/tomb/gtk-2.0-key/gtkrc" + local output + + # Force pinentry to use a custom icon by overriding the GTK theme + # temporarily. + for prefix in /usr/local /usr; do + [[ -r "$prefix/$gtkrc" ]] && { + GTK2_RC="$prefix/$gtkrc" + break + } + done output=`cat <<EOF | GTK2_RC_FILES=${GTK2_RC} pinentry 2>/dev/null | tail -n +7 OPTION ttyname=$TTY OPTION lc-ctype=$LANG SETTITLE $title -SETDESC $1 +SETDESC $description SETPROMPT Password: GETPIN EOF` - if [[ `tail -n1 <<<$output` =~ ERR ]]; then - return 1 - fi + + # Return 1 on error + [[ `tail -n1 <<<$output` =~ ERR ]] && return 1 + + # Print out the typed password and return 0 head -n1 <<<$output | awk '/^D / { sub(/^D /, ""); print }' return 0 }