From d8e7c5226081aea4a31733f31359aed21d3ce11e Mon Sep 17 00:00:00 2001 From: Martin van Es Date: Fri, 1 Jul 2022 13:09:36 +0200 Subject: [PATCH] Better server error output --- src/pam_weblogin.c | 24 +++++------------------- src/pam_weblogin.h | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/pam_weblogin.c b/src/pam_weblogin.c index 4ec7552..55674ef 100644 --- a/src/pam_weblogin.c +++ b/src/pam_weblogin.c @@ -18,20 +18,6 @@ #include "pam_weblogin.h" -/* see https://stackoverflow.com/questions/2410976/how-to-define-a-string-literal-in-gcc-command-line - * and note that # is the CPP "stringizing" operator */ -#define STR(x) #x -#define TOSTR(X) STR(x) - -#ifndef GIT_COMMIT -#DEFINE GIT_COMMIT 0000 -#endif - -#ifndef JSONPARSER_GIT_COMMIT -#DEFINE JSONPARSER_GIT_COMMIT 0000 -#endif - - PAM_EXTERN int pam_sm_setcred(UNUSED pam_handle_t *pamh, UNUSED int flags, UNUSED int argc, UNUSED const char *argv[]) { return PAM_SUCCESS; @@ -99,8 +85,8 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, UNUSED int flags, int arg free(data); if (challenge_response == NULL) { - log_message(LOG_ERR, "Error making request"); - tty_output(pamh, "Could not contact auth server"); + log_message(LOG_ERR, SERVER_ERROR); + tty_output(pamh, SERVER_ERROR); pam_result = PAM_SYSTEM_ERR; goto finalize; } @@ -129,7 +115,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, UNUSED int flags, int arg /* Now we need to have a session_id and a challenge ! */ if (!session_id || !challenge) { - tty_output(pamh, "Server error!"); + tty_output(pamh, SERVER_ERROR); goto finalize; } @@ -165,8 +151,8 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, UNUSED int flags, int arg free(data); if (verify_response == NULL) { - log_message(LOG_ERR, "Error making request"); - tty_output(pamh, "Could not contact auth server"); + log_message(LOG_ERR, SERVER_ERROR); + tty_output(pamh, SERVER_ERROR); pam_result = PAM_SYSTEM_ERR; break; } diff --git a/src/pam_weblogin.h b/src/pam_weblogin.h index 866b2cc..5e019dd 100644 --- a/src/pam_weblogin.h +++ b/src/pam_weblogin.h @@ -1,3 +1,8 @@ +/* see https://stackoverflow.com/questions/2410976/how-to-define-a-string-literal-in-gcc-command-line + * and note that # is the CPP "stringizing" operator */ +#define STR(x) #x +#define TOSTR(X) STR(x) + #define API_START_PATH "start" #define API_START_RESPONSE_CODE 201 @@ -8,3 +13,13 @@ #define PROMPT_USERNAME "Username: " #define PROMPT_PIN "Pin: " + +#define SERVER_ERROR "Server error!" + +#ifndef GIT_COMMIT +#DEFINE GIT_COMMIT 0000 +#endif + +#ifndef JSONPARSER_GIT_COMMIT +#DEFINE JSONPARSER_GIT_COMMIT 0000 +#endif