From 739cf6877b9bd84b0aba47f5c4c205a9dd63a93d Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 14 Oct 2009 17:02:47 -0400 Subject: PR10331: improve nss error message handling * stapsslerr.h: New file containing NSS* error number to string mappings. Originally from mozilla NSS documentation, also seen in other GPLv2 software. * nsscommon.c (nssError): Print error number, and text from . * stap-{client,server}-connect.c (errWarn): Standardize on nssError(). * Makefile.am (nss binaries): Also link in nsscommon.c. --- nsscommon.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'nsscommon.c') diff --git a/nsscommon.c b/nsscommon.c index 2e9c748b..b94e3e63 100644 --- a/nsscommon.c +++ b/nsscommon.c @@ -36,6 +36,9 @@ nssError (void) /* See if PR_GetErrorText can tell us what the error is. */ errorNumber = PR_GetError (); + + fprintf(stderr, "(%d) ", errorNumber); + if (errorNumber >= PR_NSPR_ERROR_BASE && errorNumber <= PR_MAX_ERROR) { errorTextLength = PR_GetErrorTextLength (); @@ -50,28 +53,14 @@ nssError (void) } } - /* Otherwise handle common errors ourselves. */ - switch (errorNumber) - { - case PR_CONNECT_RESET_ERROR: - fputs ("Connection reset by peer.\n", stderr); - break; - case SEC_ERROR_BAD_DATABASE: - fputs ("The specified certificate database does not exist or is not valid.\n", stderr); - break; - case SEC_ERROR_BAD_SIGNATURE: - fputs ("Certificate does not match the signature.\n", stderr); - break; - case SEC_ERROR_CA_CERT_INVALID: - fputs ("The issuer's certificate is invalid.\n", stderr); - break; - case SSL_ERROR_BAD_CERT_DOMAIN: - fputs ("The requested domain name does not match the server's certificate.\n", stderr); - break; - default: - fprintf (stderr, "Unknown NSS error: %d.\n", errorNumber); - break; + switch (errorNumber) { + default: errorText = "(unknown)"; break; +#define NSSYERROR(code,msg) case code: errorText = msg; break +#include "stapsslerr.h" +#undef NSSYERROR } + + fprintf (stderr, "%s\n", errorText); } void -- cgit