| 1 |
/* |
| 2 |
* libpwquality main API code for translation of errors |
| 3 |
* |
| 4 |
* See the end of the file for Copyright and License Information |
| 5 |
*/ |
| 6 |
#include "config.h" |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <string.h> |
| 10 |
#include <stdlib.h> |
| 11 |
|
| 12 |
#include "pwquality.h" |
| 13 |
#include "pwqprivate.h" |
| 14 |
|
| 15 |
/* Create an error message, the auxerror is generated by the library call |
| 16 |
* and so it can be an arbitrary thing - it does not have to be a pointer |
| 17 |
* to string. */ |
| 18 |
const char * |
| 19 |
pwquality_strerror(char *buf, size_t len, int rv, void *auxerror) |
| 20 |
{ |
| 21 |
static char intbuf[PWQ_MAX_ERROR_MESSAGE_LEN]; |
| 22 |
|
| 23 |
if (buf == NULL) { |
| 24 |
buf = intbuf; |
| 25 |
len = sizeof(intbuf); |
| 26 |
} |
| 27 |
|
| 28 |
switch(rv) { |
| 29 |
case PWQ_ERROR_MEM_ALLOC: |
| 30 |
if (auxerror) { |
| 31 |
snprintf(buf, len, "%s - %s", _("Memory allocation error when setting"), (const char *)auxerror); |
| 32 |
free(auxerror); |
| 33 |
return buf; |
| 34 |
} |
| 35 |
return _("Memory allocation error"); |
| 36 |
case PWQ_ERROR_SAME_PASSWORD: |
| 37 |
return _("The password is the same as the old one"); |
| 38 |
case PWQ_ERROR_PALINDROME: |
| 39 |
return _("The password is a palindrome"); |
| 40 |
case PWQ_ERROR_CASE_CHANGES_ONLY: |
| 41 |
return _("The password differs with case changes only"); |
| 42 |
case PWQ_ERROR_TOO_SIMILAR: |
| 43 |
return _("The password is too similar to the old one"); |
| 44 |
case PWQ_ERROR_USER_CHECK: |
| 45 |
return _("The password contains the user name in some form"); |
| 46 |
case PWQ_ERROR_GECOS_CHECK: |
| 47 |
return _("The password contains words from the real name of the user in some form"); |
| 48 |
case PWQ_ERROR_BAD_WORDS: |
| 49 |
return _("The password contains forbidden words in some form"); |
| 50 |
case PWQ_ERROR_MIN_DIGITS: |
| 51 |
if (auxerror) { |
| 52 |
snprintf(buf, len, _("The password contains less than %ld digits"), (long)auxerror); |
| 53 |
return buf; |
| 54 |
} |
| 55 |
return _("The password contains too few digits"); |
| 56 |
case PWQ_ERROR_MIN_UPPERS: |
| 57 |
if (auxerror) { |
| 58 |
snprintf(buf, len, _("The password contains less than %ld uppercase letters"), (long)auxerror); |
| 59 |
return buf; |
| 60 |
} |
| 61 |
return _("The password contains too few uppercase letters"); |
| 62 |
case PWQ_ERROR_MIN_LOWERS: |
| 63 |
if (auxerror) { |
| 64 |
snprintf(buf, len, _("The password contains less than %ld lowercase letters"), (long)auxerror); |
| 65 |
return buf; |
| 66 |
} |
| 67 |
return _("The password contains too few lowercase letters"); |
| 68 |
case PWQ_ERROR_MIN_OTHERS: |
| 69 |
if (auxerror) { |
| 70 |
snprintf(buf, len, _("The password contains less than %ld non-alphanumeric characters"), (long)auxerror); |
| 71 |
return buf; |
| 72 |
} |
| 73 |
return _("The password contains too few non-alphanumeric characters"); |
| 74 |
case PWQ_ERROR_MIN_LENGTH: |
| 75 |
if (auxerror) { |
| 76 |
snprintf(buf, len, _("The password is shorter than %ld characters"), (long)auxerror); |
| 77 |
return buf; |
| 78 |
} |
| 79 |
return _("The password is too short"); |
| 80 |
case PWQ_ERROR_ROTATED: |
| 81 |
return _("The password is just rotated old one"); |
| 82 |
case PWQ_ERROR_MIN_CLASSES: |
| 83 |
if (auxerror) { |
| 84 |
snprintf(buf, len, _("The password contains less than %ld character classes"), (long)auxerror); |
| 85 |
return buf; |
| 86 |
} |
| 87 |
return _("The password does not contain enough character classes"); |
| 88 |
case PWQ_ERROR_MAX_CONSECUTIVE: |
| 89 |
if (auxerror) { |
| 90 |
snprintf(buf, len, _("The password contains more than %ld same characters consecutively"), (long)auxerror); |
| 91 |
return buf; |
| 92 |
} |
| 93 |
return _("The password contains too many same characters consecutively"); |
| 94 |
case PWQ_ERROR_MAX_CLASS_REPEAT: |
| 95 |
if (auxerror) { |
| 96 |
snprintf(buf, len, _("The password contains more than %ld characters of the same class consecutively"), (long)auxerror); |
| 97 |
return buf; |
| 98 |
} |
| 99 |
return _("The password contains too many characters of the same class consecutively"); |
| 100 |
case PWQ_ERROR_MAX_SEQUENCE: |
| 101 |
if (auxerror) { |
| 102 |
snprintf(buf, len, _("The password contains monotonic sequence longer than %ld characters"), (long)auxerror); |
| 103 |
return buf; |
| 104 |
} |
| 105 |
return _("The password contains too long of a monotonic character sequence"); |
| 106 |
case PWQ_ERROR_EMPTY_PASSWORD: |
| 107 |
return _("No password supplied"); |
| 108 |
case PWQ_ERROR_RNG: |
| 109 |
return _("Cannot obtain random numbers from the RNG device"); |
| 110 |
case PWQ_ERROR_GENERATION_FAILED: |
| 111 |
return _("Password generation failed - required entropy too low for settings"); |
| 112 |
case PWQ_ERROR_CRACKLIB_CHECK: |
| 113 |
if (auxerror) { |
| 114 |
snprintf(buf, len, "%s - %s", _("The password fails the dictionary check"), (const char *)auxerror); |
| 115 |
return buf; |
| 116 |
} |
| 117 |
return _("The password fails the dictionary check"); |
| 118 |
case PWQ_ERROR_UNKNOWN_SETTING: |
| 119 |
if (auxerror) { |
| 120 |
snprintf(buf, len, "%s - %s", _("Unknown setting"), (const char *)auxerror); |
| 121 |
free(auxerror); |
| 122 |
return buf; |
| 123 |
} |
| 124 |
return _("Unknown setting"); |
| 125 |
case PWQ_ERROR_INTEGER: |
| 126 |
if (auxerror) { |
| 127 |
snprintf(buf, len, "%s - %s", _("Bad integer value of setting"), (const char *)auxerror); |
| 128 |
free(auxerror); |
| 129 |
return buf; |
| 130 |
} |
| 131 |
return _("Bad integer value"); |
| 132 |
case PWQ_ERROR_NON_INT_SETTING: |
| 133 |
if (auxerror) { |
| 134 |
snprintf(buf, len, _("Setting %s is not of integer type"), (const char *)auxerror); |
| 135 |
free(auxerror); |
| 136 |
return buf; |
| 137 |
} |
| 138 |
return _("Setting is not of integer type"); |
| 139 |
case PWQ_ERROR_NON_STR_SETTING: |
| 140 |
if (auxerror) { |
| 141 |
snprintf(buf, len, _("Setting %s is not of string type"), (const char *)auxerror); |
| 142 |
free(auxerror); |
| 143 |
return buf; |
| 144 |
} |
| 145 |
return _("Setting is not of string type"); |
| 146 |
case PWQ_ERROR_CFGFILE_OPEN: |
| 147 |
return _("Opening the configuration file failed"); |
| 148 |
case PWQ_ERROR_CFGFILE_MALFORMED: |
| 149 |
return _("The configuration file is malformed"); |
| 150 |
case PWQ_ERROR_FATAL_FAILURE: |
| 151 |
return _("Fatal failure"); |
| 152 |
default: |
| 153 |
return _("Unknown error"); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
/* |
| 159 |
* Copyright (c) Red Hat, Inc, 2011 |
| 160 |
* Copyright (c) Tomas Mraz <[email protected]>, 2011 |
| 161 |
* |
| 162 |
* Redistribution and use in source and binary forms, with or without |
| 163 |
* modification, are permitted provided that the following conditions |
| 164 |
* are met: |
| 165 |
* 1. Redistributions of source code must retain the above copyright |
| 166 |
* notice, and the entire permission notice in its entirety, |
| 167 |
* including the disclaimer of warranties. |
| 168 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 169 |
* notice, this list of conditions and the following disclaimer in the |
| 170 |
* documentation and/or other materials provided with the distribution. |
| 171 |
* 3. The name of the author may not be used to endorse or promote |
| 172 |
* products derived from this software without specific prior |
| 173 |
* written permission. |
| 174 |
* |
| 175 |
* ALTERNATIVELY, this product may be distributed under the terms of |
| 176 |
* the GNU General Public License version 2 or later, in which case the |
| 177 |
* provisions of the GPL are required INSTEAD OF the above restrictions. |
| 178 |
* |
| 179 |
* THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED |
| 180 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 181 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 182 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 183 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 184 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 185 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 186 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 187 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 188 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 189 |
* OF THE POSSIBILITY OF SUCH DAMAGE. |
| 190 |
*/ |
| 191 |
|