| 1 |
#!/usr/bin/env mksh |
| 2 |
# $MirOS: contrib/hosted/tg/code/kwalletcli/kwalletaskpass,v 1.9 2016/08/30 17:37:56 tg Exp $ |
| 3 |
#- |
| 4 |
# Copyright © 2009, 2010, 2011, 2014 |
| 5 |
# mirabilos <[email protected]> |
| 6 |
# |
| 7 |
# Provided that these terms and disclaimer and all copyright notices |
| 8 |
# are retained or reproduced in an accompanying document, permission |
| 9 |
# is granted to deal in this work without restriction, including un‐ |
| 10 |
# limited rights to use, publicly perform, distribute, sell, modify, |
| 11 |
# merge, give away, or sublicence. |
| 12 |
# |
| 13 |
# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to |
| 14 |
# the utmost extent permitted by applicable law, neither express nor |
| 15 |
# implied; without malicious intent or gross negligence. In no event |
| 16 |
# may a licensor, author or contributor be held liable for indirect, |
| 17 |
# direct, other damage, loss, or other issues arising in any way out |
| 18 |
# of dealing in the work, even if advised of the possibility of such |
| 19 |
# damage or existence of a defect, except proven that it results out |
| 20 |
# of said person’s immediate fault when using the work as intended. |
| 21 |
|
| 22 |
unset LC_ALL LANGUAGE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES \ |
| 23 |
LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION |
| 24 |
export LANG=C LC_CTYPE=en_US.UTF-8 |
| 25 |
set -U |
| 26 |
|
| 27 |
if (( $# != 1 )); then |
| 28 |
print -u2 wrong number of arguments |
| 29 |
exit 127 |
| 30 |
fi |
| 31 |
|
| 32 |
rv=1 |
| 33 |
trywallet=0 |
| 34 |
[[ -n $DISPLAY ]] && [[ $1 = 'Enter passphrase for '* || \ |
| 35 |
$1 = 'Password for '* ]] && trywallet=1 |
| 36 |
if (( trywallet )); then |
| 37 |
blist=$(kwalletcli -q -f kwalletaskpass-blacklist -e "${1#Enter }") |
| 38 |
[[ $blist = yes* ]] && trywallet=0 |
| 39 |
fi |
| 40 |
if (( trywallet )); then |
| 41 |
pw=$(kwalletcli -q -f kwalletaskpass -e "${1#Enter }") |
| 42 |
rv=$? |
| 43 |
fi |
| 44 |
|
| 45 |
# whitelist of known binary queries |
| 46 |
barg= |
| 47 |
[[ $1 = 'Allow shared connection to '* || \ |
| 48 |
$1 = 'Terminate shared connection to '* || \ |
| 49 |
$1 = 'Open '*' on '*'?' || \ |
| 50 |
$1 = 'Something behind the ssh-agent-filter '*'requested use of the key named '* || \ |
| 51 |
$1 = 'Allow forward to '* || \ |
| 52 |
$1 = 'Allow use of key '* ]] && barg=-b |
| 53 |
|
| 54 |
if (( rv )); then |
| 55 |
pw=$(kwalletcli_getpin -q $barg -t "$1") |
| 56 |
rv=$? |
| 57 |
if (( rv == 0 && trywallet )); then |
| 58 |
q=${1#Enter } |
| 59 |
q=${q%%:*([ ])} |
| 60 |
if kwalletcli_getpin -qb -t "Store $q in the KDE Wallet?"; then |
| 61 |
kwalletcli -q -f kwalletaskpass \ |
| 62 |
-e "${1#Enter }" -p "$pw" |
| 63 |
else |
| 64 |
kwalletcli -q -f kwalletaskpass-blacklist \ |
| 65 |
-e "${1#Enter }" -p yes |
| 66 |
fi |
| 67 |
fi |
| 68 |
fi |
| 69 |
|
| 70 |
case $rv { |
| 71 |
(0) print -r -- "$pw" |
| 72 |
exit 0 ;; |
| 73 |
(1) exit 1 ;; |
| 74 |
(*) exit 3 ;; |
| 75 |
} |