[pacman-dev] [PATCH 1/3] add specific error for missing gpg support
"wrong or NULL argument passed" is a useless error for end users. Fixes FS#60880. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/alpm.h | 4 +++- lib/libalpm/be_sync.c | 2 +- lib/libalpm/error.c | 3 +++ lib/libalpm/handle.c | 6 +++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 2d3d198a..597e11bd 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -118,7 +118,9 @@ typedef enum _alpm_errno_t { ALPM_ERR_LIBARCHIVE, ALPM_ERR_LIBCURL, ALPM_ERR_EXTERNAL_DOWNLOAD, - ALPM_ERR_GPGME + ALPM_ERR_GPGME, + /* Missing compile-time features */ + ALPM_ERR_MISSING_CAPABILITY_SIGNATURES } alpm_errno_t; /** Returns the current error code from the handle. */ diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 5009a7da..6adf1cd9 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -788,7 +788,7 @@ alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename, #ifndef HAVE_LIBGPGME if(level != ALPM_SIG_USE_DEFAULT) { - RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL); + RET_ERR(handle, ALPM_ERR_MISSING_CAPABILITY_SIGNATURES, NULL); } #endif diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c index b4fc99ae..95be9d7b 100644 --- a/lib/libalpm/error.c +++ b/lib/libalpm/error.c @@ -159,6 +159,9 @@ const char SYMEXPORT *alpm_strerror(alpm_errno_t err) return _("gpgme error"); case ALPM_ERR_EXTERNAL_DOWNLOAD: return _("error invoking external downloader"); + /* Missing compile-time features */ + case ALPM_ERR_MISSING_CAPABILITY_SIGNATURES: + return _("compiled without signature support"); /* Unknown error! */ default: return _("unexpected error"); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 2213ce53..be5666dc 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -807,7 +807,7 @@ int SYMEXPORT alpm_option_set_default_siglevel(alpm_handle_t *handle, handle->siglevel = level; #else if(level != 0 && level != ALPM_SIG_USE_DEFAULT) { - RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1); + RET_ERR(handle, ALPM_ERR_MISSING_CAPABILITY_SIGNATURES, -1); } #endif return 0; @@ -827,7 +827,7 @@ int SYMEXPORT alpm_option_set_local_file_siglevel(alpm_handle_t *handle, handle->localfilesiglevel = level; #else if(level != 0 && level != ALPM_SIG_USE_DEFAULT) { - RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1); + RET_ERR(handle, ALPM_ERR_MISSING_CAPABILITY_SIGNATURES, -1); } #endif return 0; @@ -851,7 +851,7 @@ int SYMEXPORT alpm_option_set_remote_file_siglevel(alpm_handle_t *handle, handle->remotefilesiglevel = level; #else if(level != 0 && level != ALPM_SIG_USE_DEFAULT) { - RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1); + RET_ERR(handle, ALPM_ERR_MISSING_CAPABILITY_SIGNATURES, -1); } #endif return 0; -- 2.19.1
An empty siglevel does not do any signature verification which is exactly what we want when compiled without gpg support. This is already allowed in other parts of the codebase and required for the test suite to pass when compiled without gpg support. Fixes: FS#60880 Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- Signature-related tests still fail without gpg support for obvious reasons, but the rest should pass after this. lib/libalpm/be_sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 6adf1cd9..4a4be548 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -787,7 +787,7 @@ alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename, _alpm_log(handle, ALPM_LOG_DEBUG, "registering sync database '%s'\n", treename); #ifndef HAVE_LIBGPGME - if(level != ALPM_SIG_USE_DEFAULT) { + if(level != 0 && level != ALPM_SIG_USE_DEFAULT) { RET_ERR(handle, ALPM_ERR_MISSING_CAPABILITY_SIGNATURES, NULL); } #endif -- 2.19.1
ALPM_SIG_USE_DEFAULT does not refer to an actual siglevel, rather it indicates that the global default should be used in place of the operation-specific one. Setting this value for the global default itself makes no sense. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/handle.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index be5666dc..f912d2f5 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -803,10 +803,13 @@ int SYMEXPORT alpm_option_set_default_siglevel(alpm_handle_t *handle, int level) { CHECK_HANDLE(handle, return -1); + if(level == ALPM_SIG_USE_DEFAULT) { + RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1); + } #ifdef HAVE_LIBGPGME handle->siglevel = level; #else - if(level != 0 && level != ALPM_SIG_USE_DEFAULT) { + if(level != 0) { RET_ERR(handle, ALPM_ERR_MISSING_CAPABILITY_SIGNATURES, -1); } #endif -- 2.19.1
On 25/11/18 9:56 am, Andrew Gregory wrote:
"wrong or NULL argument passed" is a useless error for end users.
Fixes FS#60880.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> ---
This patch series looks good to me. Allan
participants (2)
-
Allan McRae
-
Andrew Gregory