diff options
author | Jack Thomasson <jkt@moonlitsw.com> | 2019-04-25 17:37:13 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2019-04-25 17:37:13 +0300 |
commit | 1cbd395d71c0adceb8880091cbe27b38c86a9b82 (patch) | |
tree | 6b79ea9a8492b9bead457ee5505a44768de5613b /utils | |
parent | ba4d68c76e5247c6e011487ef45efcfa93c83861 (diff) |
multiple database with --pw-stdin (#2916)
* Updated utilities to unlock KDBX with OS password manager on macOS and Linux
* Use a static stream on stdin for --pw-stdin otherwise buffer loss eliminates subsequent passwords
* Update INSTALL requirements
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/keepassxc-kdewallet (renamed from utils/keepassx-kwallet) | 16 | ||||
-rwxr-xr-x | utils/keepassxc-keychain | 29 |
2 files changed, 37 insertions, 8 deletions
diff --git a/utils/keepassx-kwallet b/utils/keepassxc-kdewallet index e0cdcda5e..90a3eb73d 100755 --- a/utils/keepassx-kwallet +++ b/utils/keepassxc-kdewallet @@ -1,9 +1,11 @@ -#!/bin/bash +#!/usr/bin/env bash +# fetch KeePass database passwords from kdewallet ### change the path to suit your installation or set KDBX_SEARCH before calling ### : ${KDBX_SEARCH:=~/.KeePass/*.kdbx} -PROG="$(basename $0)" +PROG="${0##*/}" +KEEPASSXC=$(which -a keepassxc | sed -e "\\,$0,d" -e 'q') function daemon_main { # open kdewallet @@ -12,16 +14,14 @@ function daemon_main { sleep 1 done - # fetch KeePass database passwords from kdewallet declare -A DBs - for DBPATH in $KDBX_SEARCH; do - [[ -L "$DBPATH" ]] && DBPATH=$(readlink --canonicalize "$DBPATH") - DBs[$DBPATH]=$(qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.readPassword "$handle" "Passwords" "$DBPATH" "$PROG") + for DBPATH in $(ls -r $KDBX_SEARCH); do + DBs[$(realpath $DBPATH)]=$(qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.readPassword "$handle" "Passwords" "${DBPATH##*/}" "$PROG") done - # launch keepassx + # launch real keepassxc IFS=$'\n\n\n' - keepassx --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" & + "$KEEPASSXC" --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" & # done with kdewallet qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.close "$handle" "false" "$PROG" diff --git a/utils/keepassxc-keychain b/utils/keepassxc-keychain new file mode 100755 index 000000000..625380d37 --- /dev/null +++ b/utils/keepassxc-keychain @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# fetch KeePass database passwords from keychain + +### change the path to suit your installation or set KDBX_SEARCH before calling ### +: ${KDBX_SEARCH:=~/.KeePass/*.kdbx} + +PROG="$(basename $0)" +KeePassXC=$(ls -f {/usr/local,/Applications}/KeePassXC.app/Contents/MacOS/KeePassXC 2>/dev/null | head -1) + +function daemon_main { + declare -A DBs + for DBPATH in $KDBX_SEARCH; do + DBs[$(python -c "import os; print os.path.realpath('$DBPATH')")]=$(security find-generic-password -a $USER -s "${DBPATH##*/}" -w) + done + + # launch keepassxc + IFS=$'\n\n\n' + $KeePassXC --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" & +} + +if [[ '-d' = "$1" ]]; then + exec >&~/tmp/$PROG.log + set -vx + daemon_main +else + cd / + daemon_main </dev/null >&/dev/null & + disown +fi |