Resul Cetin dixit:
>+ kwalletcli -q -f pinentry-kwallet -e pass-v-〈〉
>+ pw=asd
>+ rv=0
>+ print -r D asd
>D asd
>+ print OK
>OK
WTF then. Hrm. Care to try this one?
It writes two log files /tmp/pkw-* (you should edit out the
password with a fake one).
I'm making this up on the fly (protocol debugging) as I can't
think of a reason to fail here...
bye,
//mirabilos
--
FWIW, I'm quite impressed with mksh interactively. I thought it was much
*much* more bare bones. But it turns out it beats the living hell out of
ksh93 in that respect. I'd even consider it for my daily use if I hadn't
wasted half my life on my zsh setup. :-) -- Frank Terbeck in #!/bin/mksh
#!/usr/bin/env mksh
rcsid='$MirOS: contrib/hosted/tg/code/kwalletcli/pinentry-kwallet,v 1.5
2009/07/12 17:57:33 tg Exp $'
#-
# Copyright © 2009
# Thorsten Glaser <t...@mirbsd.org>
#
# Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission
# is granted to deal in this work without restriction, including un‐
# limited rights to use, publicly perform, distribute, sell, modify,
# merge, give away, or sublicence.
#
# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
# the utmost extent permitted by applicable law, neither express nor
# implied; without malicious intent or gross negligence. In no event
# may a licensor, author or contributor be held liable for indirect,
# direct, other damage, loss, or other issues arising in any way out
# of dealing in the work, even if advised of the possibility of such
# damage or existence of a defect, except proven that it results out
# of said person’s immediate fault when using the work as intended.
unset LC_ALL LANGUAGE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES \
LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION
export LANG=C LC_CTYPE=en_US.UTF-8
set -U
lp=/tmp/pkw-parent.log
ls=/tmp/pkw-sub.log
print "\n=== new $(date)\n" >>$lp
print "\n=== new $(date)\n" >>$ls
function outp {
local x
x=$(cat)
print -r -- "> $x" >>$lp
print -r -- "$x"
}
function outs {
local x="$*"
print -r -- "> $x" >>$ls
print -pr -- "$x"
}
function inp {
print -r -- "< $*" >>$lp
}
function ins {
print -r -- "< $*" >>$ls
}
if [[ -n $PINENTRY_KWALLET ]]; then
print ERR 7 trying to call me recursively
while read line; do
print ERR 7 trying to call me recursively
done
print "ERR 7" >>$lp
print "ERR 7" >>$ls
exit 1
fi
quiet=0
set -A args
last=
for arg in "$@"; do
if [[ $last = --display ]]; then
v=DISPLAY
last=specvar
elif [[ $last = --ttyname ]]; then
v=GPG_TTY
last=specvar
elif [[ $last = --ttytype ]]; then
v=GPG_TERM
last=specvar
elif [[ $last = --lc-type ]]; then
v=LC_CTYPE
last=specvar
elif [[ $last = --lc-messages ]]; then
v=LC_MESSAGES
last=specvar
fi
if [[ $last = specvar ]]; then
echo "var '$v'='$arg'" >>$lp
eval $v=\$arg
eval export $v
last=addone
fi
if [[ $last = addone ]]; then
args[${#args[*]}]=$arg
last=
continue
fi
last=
if [[ $arg = -V ]]; then
(( quiet )) || print -ru2 -- "$rcsid"
exit 0
elif [[ $arg = --version ]]; then
print -r -- "$rcsid"
exit 0
elif [[ $arg = @(-h|--help) ]]; then
print "Usage: pinentry-kwallet [options]"
exit 0
elif [[ $arg = -q ]]; then
quiet=1
elif [[ $arg = \
@(-@(d|e|g)|--@(debug|enhanced|no-global-grab)) ]]; then
args[${#args[*]}]=$arg
elif [[ $arg = \
--@(display|ttyname|ttytype|lc-type|lc-messages) ]]; then
args[${#args[*]}]=$arg
last=$arg
elif [[ $arg = --parent-wid ]]; then
args[${#args[*]}]=$arg
last=addone
else
(( quiet )) || print -u2 "warning: unknown argument '$arg'"
args[${#args[*]}]=$arg
fi
done
(print -n "subargs:"
for i in "${ar...@]}"; do
print -n " <$i>"
done
print) >>$ls
PINENTRY_KWALLET=set "${PINENTRY:-pinentry}" "${ar...@]}" |&
IFS= read -pr resp || resp='ERR 14 no coprocess'
print "< $resp" >>$ls
if [[ $resp = OK@(| *) ]]; then
have_sub=1
else
have_sub=0
exec 3>&p; exec 3>&-
fi
print OK ready to listen to your demands | outp
x_dsctxt=
x_prompt=
x_errtxt=
function getit {
local type=$1 key=〈${x_prompt}〉$x_dsctxt pw rv tw=0 d errcnt
copyline=0
# the errcnt handling is a little tricky, because GnuPG v2 does
# not reuse the pinentry session (suckers, unable to... *rant*)
if pw=$(kwalletcli -q -f pinentry-kwallet -e "$type-e-$key"); then
print "from e: $pw" >>$ls
set -A errcnt -- $pw
d=$(date -u +'%s')
(( errcnt[0] < (d - 15) )) && errcnt[1]=0
fi
[[ -z $x_errtxt ]] || (( errcnt[1]++ ))
if (( errcnt[1] )); then
errcnt[0]=${d:-$(date -u +'%s')}
kwalletcli -q -f pinentry-kwallet -e "$type-e-$key" \
-p "${errcnt[*]}"
print "to errcnt: ${errcnt[*]}" >>$ls
fi
if (( errcnt[1] < 2 )); then
pw=$(kwalletcli -q -f pinentry-kwallet -e "$type-v-$key")
rv=$?
print "from passwd: rv=$rv pw=$pw" >>$ls
case $type:$rv {
(bool:0)
if [[ $pw = \
@(1|-1|[Tt][Rr][Uu][Ee]|[Yy][Ee][Ss]) ]]; then
print OK | outp
return
elif [[ $pw = \
@(0|[Ff][Aa][Ll][Ss][Ee]|[Nn][Oo]) ]]; then
print ERR 128 not confirmed | outp
return
fi
;;
(pass:0)
[[ -n $pw ]] && print -r "D $pw" | outp
print OK | outp
return
;;
}
fi
if (( !have_sub )); then
print ERR 14 no coprocess | outp
return
fi
if [[ $type = bool ]]; then
outs CONFIRM
IFS= read -pr resp
ins "$resp"
case $resp {
(OK@(| *))
pw=1
tw=1
;;
(ERR\ 128@(| *))
pw=0
tw=1
;;
}
else
outs GETPIN
IFS= read -pr resp
ins "$resp"
pw=
if [[ $resp = @(D )* ]]; then
pw=${resp#D }
IFS= read -pr resp
ins "$resp"
fi
[[ $resp = OK@(| *) ]] && tw=1
fi
if (( tw )); then
kwalletcli_getpin -qbt "Do you want to store your response for
description
'$x_dsctxt',
prompt '$x_prompt' in the KDE Wallet?"
sresp=$?
print "getpin store=$sresp" >>$ls
if (( sresp == 0 )); then
kwalletcli -q -f pinentry-kwallet -e "$type-v-$key" -p
"$pw"
print "to pw: '$pw'" >>$ls
fi
fi
[[ $type = pass ]] && [[ -n $pw ]] && print -r "D $pw" | outp
print -r -- "$resp" | outp
}
while IFS= read -r line; do
inp "$line"
copyline=1
case $line {
(SETDESC)
x_dsctxt=
;;
(SETDESC\ *)
x_dsctxt=${line#SETDESC }
;;
(SETPROMPT)
x_prompt=
;;
(SETPROMPT\ *)
x_prompt=${line#SETPROMPT }
;;
(SETOK*|SETCANCEL*)
;;
(SETERROR)
x_errtxt=
;;
(SETERROR\ *)
x_errtxt=${line#SETERROR }
;;
(SETQUALITYBAR*)
;;
(GETPIN)
getit pass
;;
(CONFIRM)
getit bool
;;
(MESSAGE|CONFIRM\ --one-button)
;;
(OPTION\ ttyname=*)
GPG_TTY=${line#*=}
export GPG_TTY
;;
(OPTION\ ttytype=*)
GPG_TERM=${line#*=}
export GPG_TERM
;;
(OPTION\ lc-ctype=*)
LC_CTYPE=${line#*=}
export LC_CTYPE
;;
(OPTION\ lc-messages=*)
LC_MESSAGES=${line#*=}
export LC_MESSAGES
;;
(OPTION*)
;;
(CONFIRM\ *)
(( quiet )) || print -ru2 "warning: unknown CONFIRM" \
"option ${line#CONFIRM }"
;;
(BYE@(| *))
# undocumented, but used by GnuPG v2
print OK | outp
break
;;
(*)
(( quiet )) || print -ru2 "warning: unknown line '$line'"
;;
}
(( copyline )) && if (( have_sub )); then
outs "$line"
IFS= read -pr resp
ins "$resp"
print -r -- "$resp" | outp
else
print OK | outp
fi
done
print "=== ending $(date)" >>$ls
exec 3>&p; exec 3>&-
print "=== ending $(date)" >>$lp
exit 0