#!/usr/bin/env mksh # $MirOS: contrib/hosted/tg/code/kwalletcli/kwalletaskpass,v 1.9 2016/08/30 17:37:56 tg Exp $ #- # Copyright © 2009, 2010, 2011, 2014 # mirabilos # # 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 if (( $# != 1 )); then print -u2 wrong number of arguments exit 127 fi rv=1 trywallet=0 [[ -n $DISPLAY ]] && [[ $1 = 'Enter passphrase for '* || \ $1 = 'Password for '* ]] && trywallet=1 if (( trywallet )); then blist=$(kwalletcli -q -f kwalletaskpass-blacklist -e "${1#Enter }") [[ $blist = yes* ]] && trywallet=0 fi if (( trywallet )); then pw=$(kwalletcli -q -f kwalletaskpass -e "${1#Enter }") rv=$? fi # whitelist of known binary queries barg= [[ $1 = 'Allow shared connection to '* || \ $1 = 'Terminate shared connection to '* || \ $1 = 'Open '*' on '*'?' || \ $1 = 'Something behind the ssh-agent-filter '*'requested use of the key named '* || \ $1 = 'Allow forward to '* || \ $1 = 'Allow use of key '* ]] && barg=-b if (( rv )); then pw=$(kwalletcli_getpin -q $barg -t "$1") rv=$? if (( rv == 0 && trywallet )); then q=${1#Enter } q=${q%%:*([ ])} if kwalletcli_getpin -qb -t "Store $q in the KDE Wallet?"; then kwalletcli -q -f kwalletaskpass \ -e "${1#Enter }" -p "$pw" else kwalletcli -q -f kwalletaskpass-blacklist \ -e "${1#Enter }" -p yes fi fi fi case $rv { (0) print -r -- "$pw" exit 0 ;; (1) exit 1 ;; (*) exit 3 ;; }