diff options
Diffstat (limited to 'src/error.c')
-rw-r--r-- | src/error.c | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/src/error.c b/src/error.c index c1f6e26..790dbed 100644 --- a/src/error.c +++ b/src/error.c @@ -7,16 +7,16 @@ #include <stdio.h> #include <string.h> +#include <stdlib.h> #include "pwquality.h" #include "pwqprivate.h" /* Create an error message, the auxerror is generated by the library call * and so it can be an arbitrary thing - it does not have to be a pointer - * to string. Also in future it might be a string that will have to be - * deallocated inside this function. */ -char * -pwquality_strerror(char *buf, size_t len, int rv, char *auxerror) + * to string. */ +const char * +pwquality_strerror(char *buf, size_t len, int rv, void *auxerror) { static char intbuf[PWQ_MAX_ERROR_MESSAGE_LEN]; @@ -27,6 +27,11 @@ pwquality_strerror(char *buf, size_t len, int rv, char *auxerror) switch(rv) { case PWQ_ERROR_MEM_ALLOC: + if (auxerror) { + snprintf(buf, len, "%s - %s", _("Memory allocation error when setting"), (const char *)auxerror); + free(auxerror); + return buf; + } return _("Memory allocation error"); case PWQ_ERROR_SAME_PASSWORD: return _("The password is the same as the old one"); @@ -38,31 +43,31 @@ pwquality_strerror(char *buf, size_t len, int rv, char *auxerror) return _("The password is too similar to the old one"); case PWQ_ERROR_MIN_DIGITS: if (auxerror) { - snprintf(buf, len, _("The password contains less than %d digits"), (int)auxerror); + snprintf(buf, len, _("The password contains less than %ld digits"), (long)auxerror); return buf; } return _("The password contains too few digits"); case PWQ_ERROR_MIN_UPPERS: if (auxerror) { - snprintf(buf, len, _("The password contains less than %d uppercase letters"), (int)auxerror); + snprintf(buf, len, _("The password contains less than %ld uppercase letters"), (long)auxerror); return buf; } return _("The password contains too few uppercase letters"); case PWQ_ERROR_MIN_LOWERS: if (auxerror) { - snprintf(buf, len, _("The password contains less than %d lowercase letters"), (int)auxerror); + snprintf(buf, len, _("The password contains less than %ld lowercase letters"), (long)auxerror); return buf; } return _("The password contains too few lowercase letters"); case PWQ_ERROR_MIN_OTHERS: if (auxerror) { - snprintf(buf, len, _("The password contains less than %d non-alphanumeric characters"), (int)auxerror); + snprintf(buf, len, _("The password contains less than %ld non-alphanumeric characters"), (long)auxerror); return buf; } return _("The password contains too few non-alphanumeric characters"); case PWQ_ERROR_MIN_LENGTH: if (auxerror) { - snprintf(buf, len, _("The password is shorter than %d characters"), (int)auxerror); + snprintf(buf, len, _("The password is shorter than %ld characters"), (long)auxerror); return buf; } return _("The password is too short"); @@ -70,13 +75,13 @@ pwquality_strerror(char *buf, size_t len, int rv, char *auxerror) return _("The password is just rotated old one"); case PWQ_ERROR_MIN_CLASSES: if (auxerror) { - snprintf(buf, len, _("The password contains less than %d character classes"), (int)auxerror); + snprintf(buf, len, _("The password contains less than %ld character classes"), (long)auxerror); return buf; } return _("The password does not contain enough character classes"); case PWQ_ERROR_MAX_CONSECUTIVE: if (auxerror) { - snprintf(buf, len, _("The password contains more than %d same characters consecutively"), (int)auxerror); + snprintf(buf, len, _("The password contains more than %ld same characters consecutively"), (long)auxerror); return buf; } return _("The password contains too many same characters consecutively"); @@ -88,10 +93,44 @@ pwquality_strerror(char *buf, size_t len, int rv, char *auxerror) return _("Password generation failed - required entropy too low for settings"); case PWQ_ERROR_CRACKLIB_CHECK: if (auxerror) { - snprintf(buf, len, "%s - %s", _("The password fails the dictionary check"), auxerror); + snprintf(buf, len, "%s - %s", _("The password fails the dictionary check"), (const char *)auxerror); return buf; } return _("The password fails the dictionary check"); + case PWQ_ERROR_UNKNOWN_SETTING: + if (auxerror) { + snprintf(buf, len, "%s - %s", _("Unknown setting"), (const char *)auxerror); + free(auxerror); + return buf; + } + return _("Unknown setting"); + case PWQ_ERROR_INTEGER: + if (auxerror) { + snprintf(buf, len, "%s - %s", _("Bad integer value of setting"), (const char *)auxerror); + free(auxerror); + return buf; + } + return _("Bad integer value"); + case PWQ_ERROR_NON_INT_SETTING: + if (auxerror) { + snprintf(buf, len, _("Setting %s is not of integer type"), (const char *)auxerror); + free(auxerror); + return buf; + } + return _("Setting is not of integer type"); + case PWQ_ERROR_NON_STR_SETTING: + if (auxerror) { + snprintf(buf, len, _("Setting %s is not of string type"), (const char *)auxerror); + free(auxerror); + return buf; + } + return _("Setting is not of string type"); + case PWQ_ERROR_CFGFILE_OPEN: + return _("Opening the configuration file failed"); + case PWQ_ERROR_CFGFILE_MALFORMED: + return _("The configuration file is malformed"); + case PWQ_ERROR_FATAL_FAILURE: + return _("Fatal failure"); default: return _("Unknown error"); } |