Fix bugs in option processing and add cp/mv/rm support.

This commit is contained in:
Manuel Amador (Rudd-O) 2017-05-14 15:09:31 +00:00
parent 01882f5499
commit b901fc5c0d
3 changed files with 98 additions and 16 deletions

View File

@ -32,7 +32,24 @@ elif [ "$1" == "get-or-generate" ] ; then
nosymbols=$(echo "$3" | base64 -w 0)
echo "$cmd
$key
$autogen" | /usr/lib/qubes/qrexec-client-vm "$QUBES_PASS_DOMAIN" ruddo.PassManage
$autogen
$nosymbols" | /usr/lib/qubes/qrexec-client-vm "$QUBES_PASS_DOMAIN" ruddo.PassManage
elif [ "$1" == "rm" ] ; then
cmd=$(echo "$1" | base64 -w 0)
key=$(echo "$2" | base64 -w 0)
echo "$cmd
$key" | /usr/lib/qubes/qrexec-client-vm "$QUBES_PASS_DOMAIN" ruddo.PassManage
elif [ "$1" == "mv" -o "$1" == "cp" ] ; then
cmd=$(echo "$1" | base64 -w 0)
key=$(echo "$2" | base64 -w 0)
newkey=$(echo "$3" | base64 -w 0)
force=$(echo "$4" | base64 -w 0)
echo "$cmd
$key
$newkey
$force" | /usr/lib/qubes/qrexec-client-vm "$QUBES_PASS_DOMAIN" ruddo.PassManage
elif [ "$1" == "insert" ] ; then

View File

@ -1,11 +1,5 @@
#!/bin/bash
TEMP=`getopt -o ?d:n:mfe -- "$@"`
force=0
multiline=0
echo=0
nosymbols=
eval set -- "$TEMP"
set -e
usage() {
@ -31,11 +25,23 @@ usage() {
echo " during password generation."
echo " insert [--echo,-e | --multiline,-m] [--force,-f] <key>"
echo " Creates a key in the pass store."
exit 0
echo " rm <key>"
echo " Removes a key from the pass store."
echo " cp [-f] <key> <newkey>"
echo " Copies a key to another key in the pass store,"
echo " optionally forcefully."
echo " mv [-f] <key> <newkey>"
echo " Moves a key to another key in the pass store,"
echo " optionally forcefully."
}
while true ; do
case "$1" in
force=0
multiline=0
echo=0
nosymbols=
while getopts :d:n:mfe? opt ; do
case "$opt" in
-d)
case "$2" in
"") shift 2 ;;
@ -49,10 +55,15 @@ while true ; do
force=1 ; shift ;;
-e)
echo=1 ; shift ;;
"-?")
usage ;;
--) shift ; break ;;
*) echo "error processing options; run with -? for more information" ; exit 64 ;;
":")
echo "incorrect usage; run with -? for more information" ; exit 64 ;;
"?")
if [ "$OPTARG" != "?" ] ; then
usage ; exit 64 ;
else
usage ; exit 0 ;
fi
;;
esac
done
@ -78,6 +89,33 @@ case "$1" in
fi
exec qubes-pass-client "$1"
;;
rm)
if [ "$force$multiline$echo$nosymbols" != "000" ] ; then
echo "the $1 subcommand does not accept that option; run with -? for more information" >&2 ; exit 64
fi
if [ -z "$2" ] ; then
echo "the $1 subcommand requires a key; run with -? for more information" >&2 ; exit 64
fi
exec qubes-pass-client "$1" "$2"
;;
mv)
if [ "$multiline$echo$nosymbols" != "000" ] ; then
echo "the $1 subcommand does not accept that option; run with -? for more information" >&2 ; exit 64
fi
if [ -z "$2" -o -z "$3" ] ; then
echo "the $1 subcommand requires two keys; run with -? for more information" >&2 ; exit 64
fi
exec qubes-pass-client "$1" "$2" "$3" "$force"
;;
cp)
if [ "$multiline$echo$nosymbols" != "000" ] ; then
echo "the $1 subcommand does not accept that option; run with -? for more information" >&2 ; exit 64
fi
if [ -z "$2" -o -z "$3" ] ; then
echo "the $1 subcommand requires two keys; run with -? for more information" >&2 ; exit 64
fi
exec qubes-pass-client "$1" "$2" "$3" "$force"
;;
insert)
if [ "$nosymbols" != "" ] ; then
echo "the $1 subcommand does not accept that option; run with -? for more information" >&2 ; exit 64

View File

@ -83,4 +83,31 @@ elif [ "$cmd" == "insert" ] ; then
echo "$contents" | pass insert -e --force -- "$entry"
fi
elif [ "$cmd" == "rm" ] ; then
read -n 4096 entry
entry=$(echo "$entry" | base64 -d)
logger -t ruddo.PassManage "removing password entry $entry"
pass rm -- "$entry"
elif [ "$cmd" == "mv" -o "$cmd" == "cp" ] ; then
read -n 4096 entry
entry=$(echo "$entry" | base64 -d)
read -n 4096 newentry
newentry=$(echo "$newentry" | base64 -d)
read -n 4096 force
force=$(echo "$force" | base64 -d)
if [ "$force" == "1" ] ; then
force=-f
else
force=
fi
logger -t ruddo.PassManage "$cmd password entry $entry to $entry"
pass "$cmd" $f -- "$entry" "$newentry"
fi