X-Git-Url: http://www.git.stargrave.org/?p=passman.git;a=blobdiff_plain;f=passman;h=547ba5c9da28b1499f208137a48dfb5a358d7ab5;hp=6adaa464e61ce93531d7d5d996547dba2e524ee6;hb=HEAD;hpb=037d2fdbe19fd821aaf95565f04ad426f55c86b1 diff --git a/passman b/passman index 6adaa46..7a0ad40 100755 --- a/passman +++ b/passman @@ -1,11 +1,10 @@ #!/bin/sh -e # passman -- simple password manager -# Copyright (C) 2013-2016 Sergey Matveev (stargrave@stargrave.org) +# Copyright (C) 2013-2024 Sergey Matveev (stargrave@stargrave.org) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. +# the Free Software Foundation; version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -15,19 +14,54 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -DB=~/.passmandb +DB=${PASSMANDB:-$HOME/.passmandb} -generator() -{ - gpg --armor --gen-random 1 16 | tr '+/' '-_' | tr -d = +dec() { + if [ -s $DB ] ; then + age -d $DB | zstd -d + else + cat < $tmp + [ $(recsel -c $tmp) -eq 1 ] || { + recsel -C -P Name $tmp + exit 1 + } +} + +commit() { + enc < $tmp > ${DB}.tmp + fsync ${DB}.tmp + mv ${DB}.tmp $DB +} + case "$1" in +has) + finder "$2" + ;; gen) generator ;; @@ -36,29 +70,23 @@ add) passwd="$3" [ -n "$dst" ] [ -n "$passwd" ] || passwd=$(generator) - echo Adding password for $dst - mkdir -p $DB/$dst - umask 077 - echo "$passwd" > $DB/$dst/passwd + echo ${dst}... + dec | recins -t Credential -f Name -v "$dst" -f Passwd -v "$passwd" > $tmp + commit + ;; +mod) + dec > $tmp + $EDITOR $tmp + commit ;; *) - cd $DB - result=$(find . -type d -path "*$1*" | while read ent; do - [ -e "$ent/passwd" ] || continue - echo "$ent" | sed 's#^\./##' - done) - if [ $(echo "$result" | wc -l) -ne 1 ]; then - echo "$result" - exit - fi - [ -n "$result" ] || exit 1 - echo $result - if [ -e "$result"/data ]; then - echo -n "Associated data: " - cat "$result"/data - fi - perl -ne 'chop and print' "$result"/passwd | cliper clipboard - echo $(basename "$result") | perl -ne 'chop and print' | cliper primary + finder "$1" + name=$(recsel -P Name $tmp) + echo $name >&2 + data=$(recsel -P Data $tmp) + [ -z "$data" ] || echo "Associated data: $data" + echo -n $(recsel -P Passwd $tmp) | cliper clipboard + echo -n ${name##*/} | cliper primary sleep 10 echo -n | cliper clipboard ;;