sekrit: remove -f flag for sekrit_add

Not only it parsed the wrong character 2 commits ago, it's also
completely broken: file can't be overwritten, because of `chmod 400`.
This commit is contained in:
Lucas 2020-12-02 03:51:00 +00:00
parent f500903cba
commit 19631627d6
2 changed files with 7 additions and 24 deletions

View File

@ -10,7 +10,7 @@
.\" Dedication along with this software. If not, see
.\" <http://creativecommons.org/publicdomain/zero/1.0/>.
.\"
.Dd August 26, 2020
.Dd December 2, 2020
.Dt SEKRIT 1
.Os
.Sh NAME
@ -19,7 +19,6 @@
.Sh SYNOPSIS
.Nm
.Cm add
.Op Fl f
.Ar key
.Op Ar value ...
.Nm
@ -52,7 +51,7 @@ Because of this,
can be used as an account credentials manager,
or as a general-purpose key-value store of encrypted information.
.Bl -tag -width Ds
.It Nm Cm add Oo Fl f Oc Ar key Op Ar value ...
.It Nm Cm add Ar key Op Ar value ...
Adds a value to
.Ar key .
.Ar value
@ -65,9 +64,7 @@ will read the value from standard input.
.Cm add
will fail if
.Ar key
already has a value, unless
.Fl f
is specified.
already has a value.
.It Nm Cm cp Oo Fl k Oc Ar key
Decrypts the value associated with
.Ar key

View File

@ -29,7 +29,7 @@ usage()
{
cat - <<. >&2
Usage:
${0##*/} add [-f] key [value ...]
${0##*/} add key [value ...]
${0##*/} cp [-k] key
${0##*/} gen [-l length] [chars]
${0##*/} get key
@ -73,34 +73,20 @@ _sekrit_decrypt()
sekrit_add()
{
force=no
OPTIND=1
while getopts f flag; do
case "$flag" in
f) force=yes ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))
[ $# -ge 1 ] && [ -n "$1" ] || usage
key=$1
shift
path=$(make_key_path "$key")
if [ -f "$path" ] && [ $force = no ]; then
err "key $key already exists"
fi
path=$SEKRIT_DIR/$key.gpg
mkdir -p "${path%/*}"
[ ! -f "$path" ] || err "key $key already exists"
if [ $# -gt 0 ]; then
# use all additional parameters as a single string
printf "%s\n" "$*"
else
cat -
fi | gpg2 -qae -r "$SEKRIT_GPG_ID" >|"$path"
fi | gpg2 -qae -r "$SEKRIT_GPG_ID" >"$path"
# make it read-only
chmod -- 400 "$path"
}