summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2014-04-22 19:17:45 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2014-04-22 19:17:45 +0200
commit6c1c551fc6227f6d955eb3884124a7e1d0a38fb8 (patch)
treef6d11998c32963056224f3e709c83c94b6e63ca8 /src
parentf82e9d6cf3bc3a12bdfce89bf319d76f79e66efc (diff)
downloadpass-6c1c551fc6227f6d955eb3884124a7e1d0a38fb8.tar.gz
pass-6c1c551fc6227f6d955eb3884124a7e1d0a38fb8.tar.bz2
pass-6c1c551fc6227f6d955eb3884124a7e1d0a38fb8.zip
reencryption: take into account groups
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rwxr-xr-xsrc/password-store.sh36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/password-store.sh b/src/password-store.sh
index 7ea5d4c..6144cac 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -92,6 +92,14 @@ reencrypt_path() {
local prev_gpg_recipients
local gpg_keys
local current_keys
+ local config
+ local saved_ifs
+ local -A groups
+ while read -r config; do
+ [[ $config =~ cfg:group:* ]] || continue
+ groups[$(cut -d : -f 3 <<<"$config")]="$(cut -d : -f 4 <<<"$config")"
+ done < <($GPG --list-config --with-colons)
+
while read -r -d "" passfile; do
passfile_dir="${passfile%/*}"
passfile_dir="${passfile_dir#$PREFIX}"
@@ -101,8 +109,18 @@ reencrypt_path() {
passfile_temp="${passfile}.tmp.${RANDOM}.${RANDOM}.${RANDOM}.${RANDOM}.--"
set_gpg_recipients "$passfile_dir"
- [[ $prev_gpg_recipients != "${GPG_RECIPIENTS[@]}" ]] &&
- gpg_keys="$($GPG --list-keys --keyid-format long "${GPG_RECIPIENTS[@]}" | sed -n 's/sub *.*\/\([A-F0-9]\{16\}\) .*/\1/p' | sort -u)"
+ if [[ $prev_gpg_recipients != "${GPG_RECIPIENTS[@]}" ]]; then
+ for config in "${!GPG_RECIPIENTS[@]}"; do
+ [[ ${groups[${GPG_RECIPIENTS[$config]}]} ]] || continue
+ saved_ifs="$IFS"
+ IFS=";"
+ GPG_RECIPIENTS+=( ${groups[${GPG_RECIPIENTS[$config]}]} )
+ IFS="$saved_ifs"
+ unset GPG_RECIPIENTS[$config]
+ done
+ gpg_keys="$($GPG --list-keys --keyid-format long "${GPG_RECIPIENTS[@]}" | sed -n 's/sub *.*\/\([A-F0-9]\{16\}\) .*/\1/p' | sort -u)"
+
+ fi
current_keys="$($GPG -v --list-only --keyid-format long "$passfile" 2>&1 | cut -d ' ' -f 5 | sort -u)"
if [[ $gpg_keys != "$current_keys" ]]; then
@@ -110,7 +128,6 @@ reencrypt_path() {
$GPG -d $GPG_OPTS "$passfile" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile_temp" $GPG_OPTS &&
mv "$passfile_temp" "$passfile" || rm -f "$passfile_temp"
fi
-
prev_gpg_recipients="${GPG_RECIPIENTS[@]}"
done < <(find "$PREFIX" -iname '*.gpg' -print0)
}
@@ -285,15 +302,14 @@ cmd_init() {
git_commit "Deinitialized ${gpg_id}."
fi
rmdir -p "${gpg_id%/*}" 2>/dev/null
- exit 0
+ else
+ mkdir -v -p "$PREFIX/$id_path"
+ printf "%s\n" "$@" > "$gpg_id"
+ local id_print="$(printf "%s, " "$@")"
+ echo "Password store initialized for ${id_print%, }"
+ git_add_file "$gpg_id" "Set GPG id to ${id_print%, }."
fi
- mkdir -v -p "$PREFIX/$id_path"
- printf "%s\n" "$@" > "$gpg_id"
- local id_print="$(printf "%s, " "$@")"
- echo "Password store initialized for ${id_print%, }"
- git_add_file "$gpg_id" "Set GPG id to ${id_print%, }."
-
agent_check
reencrypt_path "$PREFIX/$id_path"
git_add_file "$PREFIX/$id_path" "Reencrypted password store using new GPG id ${id_print%, }."
tr>2006-12-13Remove implementation details from READMELars Hjemli1-53/+34 2006-12-13Small layout adjustments to summary and blob viewLars Hjemli3-5/+13 2006-12-13Add display of tree content w/ui-tree.cLars Hjemli9-8/+113 2006-12-12cache_lock: do xstrdup/free on lockfileLars Hjemli1-1/+2 2006-12-11Don't truncate valid cachefilesLars Hjemli3-4/+16 2006-12-11Move global variables + callback functions into shared.cLars Hjemli4-82/+86 2006-12-11Move functions for generic object output into ui-view.cLars Hjemli4-34/+43 2006-12-11Move log-functions into ui-log.cLars Hjemli5-111/+121 2006-12-11Move repo summary functions into ui-summary.cLars Hjemli4-47/+59 2006-12-11Move functions for repolist output into ui-repolist.cLars Hjemli5-70/+90 2006-12-11Move common output-functions into ui-shared.cLars Hjemli4-82/+99 2006-12-11Rename config.c to parsing.c + move cgit_parse_query from cgit.c to parsing.cLars Hjemli4-28/+29 2006-12-11Avoid infinite loops in caching layerLars Hjemli3-14/+31 2006-12-11Let 'make install' clear all cachefilesLars Hjemli1-0/+2 2006-12-11Fix cache algorithm loopholeLars Hjemli3-11/+16 2006-12-10Add version identifier in generated filesLars Hjemli2-9/+14 2006-12-10Add license file and copyright noticesLars Hjemli5-0/+372 2006-12-10Add caching infrastructureLars Hjemli9-28/+353