mirror of
https://github.com/moparisthebest/pacman
synced 2025-03-01 09:51:50 -05:00
Improve exit statuses and error messages in pacman-key
Return codes from gpg commands are currently lost. This adds the functionality of taking non-zero exit statuses from gpg. This includes error reporting for all gpg commands that are run individually, run in a loop, and run through a pipe. Includes the check_keyids_exist function which verifies a key exists locally prior to attempted local manipulation of the key. If a gpg command has a non-zero status, pacman-key will now exit with a non-zero status. It will print a gettext error message of gpg's failure. Signed-off-by: canyonknight <canyonknight@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
24ca6ce1f9
commit
c231c9af97
@ -144,6 +144,20 @@ add_gpg_conf_option() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_keyids_exist() {
|
||||||
|
local ret=0
|
||||||
|
for key in "${KEYIDS[@]}"; do
|
||||||
|
# Verify if the key exists in pacman's keyring
|
||||||
|
if ! "${GPG_PACMAN[@]}" --list-keys "$key" &>/dev/null ; then
|
||||||
|
error "$(gettext "The key identified by %s could not be found locally.")" "$key"
|
||||||
|
ret=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if (( ret )); then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
local conffile keyserv
|
local conffile keyserv
|
||||||
# Check for simple existence rather than for a directory as someone
|
# Check for simple existence rather than for a directory as someone
|
||||||
@ -339,85 +353,143 @@ populate_keyring() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_keys() {
|
add_keys() {
|
||||||
"${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}"
|
if ! "${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}" ; then
|
||||||
|
error "$(gettext "A specified keyfile could not be added to the gpg keychain.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_keys() {
|
delete_keys() {
|
||||||
"${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}"
|
check_keyids_exist
|
||||||
|
if ! "${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}" ; then
|
||||||
|
error "$(gettext "A specified key could not be removed from the gpg keychain.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_keys() {
|
edit_keys() {
|
||||||
local errors=0;
|
check_keyids_exist
|
||||||
|
local ret=0
|
||||||
for key in "${KEYIDS[@]}"; do
|
for key in "${KEYIDS[@]}"; do
|
||||||
# Verify if the key exists in pacman's keyring
|
if ! "${GPG_PACMAN[@]}" --edit-key "$key" ; then
|
||||||
if ! "${GPG_PACMAN[@]}" --list-keys "$key" &>/dev/null; then
|
error "$(gettext "The key identified by %s could not be edited.")" "$key"
|
||||||
error "$(gettext "The key identified by %s does not exist.")" "$key"
|
ret=1
|
||||||
errors=1;
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
(( errors )) && exit 1;
|
if (( ret )); then
|
||||||
|
exit 1
|
||||||
for key in "${KEYIDS[@]}"; do
|
fi
|
||||||
"${GPG_PACMAN[@]}" --edit-key "$key"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export_keys() {
|
export_keys() {
|
||||||
"${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}"
|
check_keyids_exist
|
||||||
|
if ! "${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}" ; then
|
||||||
|
error "$(gettext "A specified key could not be exported from the gpg keychain.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
finger_keys() {
|
finger_keys() {
|
||||||
"${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}"
|
check_keyids_exist
|
||||||
|
if ! "${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}" ; then
|
||||||
|
error "$(gettext "The fingerprint of a specified key could not be determined.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
import_trustdb() {
|
import_trustdb() {
|
||||||
local importdir
|
local importdir
|
||||||
|
local ret=0
|
||||||
for importdir in "${IMPORT_DIRS[@]}"; do
|
for importdir in "${IMPORT_DIRS[@]}"; do
|
||||||
if [[ -f "${importdir}/trustdb.gpg" ]]; then
|
if [[ -f "${importdir}/trustdb.gpg" ]]; then
|
||||||
gpg --homedir "${importdir}" --export-ownertrust | \
|
gpg --homedir "${importdir}" --export-ownertrust | \
|
||||||
"${GPG_PACMAN[@]}" --import-ownertrust -
|
"${GPG_PACMAN[@]}" --import-ownertrust -
|
||||||
|
if (( PIPESTATUS )); then
|
||||||
|
error "$(gettext "%s could not be imported.")" "${importdir}/trustdb.gpg"
|
||||||
|
ret=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "$(gettext "File %s does not exist and could not be imported.")" "${importdir}/trustdb.gpg"
|
||||||
|
ret=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
if (( ret )); then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
import() {
|
import() {
|
||||||
local importdir
|
local importdir
|
||||||
|
local ret=0
|
||||||
for importdir in "${IMPORT_DIRS[@]}"; do
|
for importdir in "${IMPORT_DIRS[@]}"; do
|
||||||
if [[ -f "${importdir}/pubring.gpg" ]]; then
|
if [[ -f "${importdir}/pubring.gpg" ]]; then
|
||||||
"${GPG_PACMAN[@]}" --quiet --batch --import "${importdir}/pubring.gpg"
|
if ! "${GPG_PACMAN[@]}" --quiet --batch --import "${importdir}/pubring.gpg" ; then
|
||||||
|
error "$(gettext "%s could not be imported.")" "${importdir}/pubring.gpg"
|
||||||
|
ret=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "$(gettext "File %s does not exist and could not be imported.")" "${importdir}/pubring.gpg"
|
||||||
|
ret=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
if (( ret )); then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
list_keys() {
|
list_keys() {
|
||||||
"${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}"
|
check_keyids_exist
|
||||||
|
if ! "${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}" ; then
|
||||||
|
error "$(gettext "A specified key could not be listed.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
list_sigs() {
|
list_sigs() {
|
||||||
"${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}"
|
check_keyids_exist
|
||||||
|
if ! "${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}" ; then
|
||||||
|
error "$(gettext "A specified signature could not be listed.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
lsign_keys() {
|
lsign_keys() {
|
||||||
|
check_keyids_exist
|
||||||
printf 'y\ny\n' | LANG=C "${GPG_PACMAN[@]}" --command-fd 0 --quiet --batch --lsign-key "${KEYIDS[@]}" 2>/dev/null
|
printf 'y\ny\n' | LANG=C "${GPG_PACMAN[@]}" --command-fd 0 --quiet --batch --lsign-key "${KEYIDS[@]}" 2>/dev/null
|
||||||
|
if (( PIPESTATUS[1] )); then
|
||||||
|
error "$(gettext "A specified key could not be locally signed.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
receive_keys() {
|
receive_keys() {
|
||||||
"${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}"
|
if ! "${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}" ; then
|
||||||
|
error "$(gettext "Remote key not fetched correctly from keyserver.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh_keys() {
|
refresh_keys() {
|
||||||
"${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}"
|
check_keyids_exist
|
||||||
|
if ! "${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}" ; then
|
||||||
|
error "$(gettext "A specified local key could not be updated from a keyserver.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
verify_sig() {
|
verify_sig() {
|
||||||
"${GPG_PACMAN[@]}" --verify $SIGNATURE
|
if ! "${GPG_PACMAN[@]}" --verify $SIGNATURE ; then
|
||||||
|
error "$(gettext "The signature identified by %s could not be verified.")" "$SIGNATURE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedb() {
|
updatedb() {
|
||||||
msg "$(gettext "Updating trust database...")"
|
msg "$(gettext "Updating trust database...")"
|
||||||
"${GPG_PACMAN[@]}" --batch --check-trustdb
|
if ! "${GPG_PACMAN[@]}" --batch --check-trustdb ; then
|
||||||
|
error "$(gettext "Trust database could not be updated.")"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# PROGRAM START
|
# PROGRAM START
|
||||||
|
Loading…
x
Reference in New Issue
Block a user