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. --- stap-client-connect.c | 47 +++++------------------------------------------ 1 file changed, 5 insertions(+), 42 deletions(-) (limited to 'stap-client-connect.c') diff --git a/stap-client-connect.c b/stap-client-connect.c index fd3b950c..8d48225d 100644 --- a/stap-client-connect.c +++ b/stap-client-connect.c @@ -29,6 +29,8 @@ #include #include +#include "nsscommon.h" + #define READ_BUFFER_SIZE (60 * 1024) static char *hostName = NULL; static unsigned short port = 0; @@ -46,50 +48,11 @@ Usage(const char *progName) static void errWarn(char *function) { - PRErrorCode errorNumber; - PRInt32 errorTextLength; - PRInt32 rc; - char *errorText; - - errorNumber = PR_GetError(); - fprintf(stderr, "Error in function %s: %d: ", function, errorNumber); - - /* See if PR_GetErrorText can tell us what the error is. */ - if (errorNumber >= PR_NSPR_ERROR_BASE && errorNumber <= PR_MAX_ERROR) - { - errorTextLength = PR_GetErrorTextLength (); - if (errorTextLength != 0) { - errorText = PORT_Alloc(errorTextLength); - rc = PR_GetErrorText (errorText); - if (rc != 0) - fprintf (stderr, "%s\n", errorText); - PR_Free (errorText); - if (rc != 0) - return; - } - } - - /* Otherwise handle common errors ourselves. */ - switch (errorNumber) - { - case SEC_ERROR_CA_CERT_INVALID: - fputs ("The issuer's certificate is invalid\n", stderr); - break; - case SEC_ERROR_BAD_DATABASE: - fputs ("The specified certificate database does not exist or is not valid\n", stderr); - break; - case SSL_ERROR_BAD_CERT_DOMAIN: - fputs ("The requested domain name does not match the server's certificate\n", stderr); - break; - case PR_CONNECT_RESET_ERROR: - fputs ("Connection reset by peer\n", stderr); - break; - default: - fputs ("Unknown error\n", stderr); - break; - } + fprintf(stderr, "Error in function %s: ", function); + nssError(); } + static void exitErr(char *function) { -- cgit