23#define DIM(v) (sizeof (v) / sizeof ((v)[0]))
24#define DIMof(type, member) DIM (((type *) 0)->member)
31#define G_LOG_DOMAIN "libgvm base"
94#define PWPOLICY_FILE_NAME GVM_SYSCONF_DIR "/pwpolicy.conf"
108 return g_strdup (
"Password policy checking failed (internal error)");
128 idx = strlen (keyword);
129 slen = strlen (
string);
131 if (!strncmp (
string, keyword, idx))
134 if (tmp -
string > slen)
139 if (tmp -
string > slen)
142 for (; tmp -
string < slen && g_ascii_isspace (*tmp); tmp++)
170 fp = fopen (fname,
"r");
174 while (fgets (line,
DIM (line) - 1, fp))
179 if (!len || line[len - 1] !=
'\n')
183 while ((c = getc (fp)) != EOF && c !=
'\n')
188 if (len && line[len - 1] ==
'\r')
192 if (!g_ascii_strcasecmp (line, password))
200 int save_errno = errno;
227 const char *password,
const char *username)
234 while (g_ascii_isspace (*line))
241 else if (*line ==
'#' && line[1] ==
'+')
248 *descp = g_strdup (p);
264 g_warning (
"error searching '%s' (requested at line %d): %s", p,
265 lineno, g_strerror (errno));
268 else if (sret && *descp)
269 ret = g_strdup_printf (
"Weak password (%s)", *descp);
271 ret = g_strdup_printf (
"Weak password (found in '%s')", p);
283 else if (!g_ascii_strcasecmp (password, username))
284 ret = g_strdup_printf (
"Weak password (%s)",
285 "user name matches password");
286 else if (strstr (password, username))
287 ret = g_strdup_printf (
"Weak password (%s)",
288 "user name is part of the password");
289 else if (strstr (username, password))
290 ret = g_strdup_printf (
"Weak password (%s)",
291 "password is part of the user name");
297 g_warning (
"error reading '%s', line %d: %s", fname, lineno,
298 "unknown processing instruction");
302 else if (*line ==
'#')
306 else if (*line ==
'/'
307 || (*line ==
'!' && line[1] ==
'/'))
309 int rev = (*line ==
'!');
314 if (n && line[n - 1] ==
'/')
316 if (((!g_regex_match_simple (line, password, G_REGEX_CASELESS, 0)) ^ rev))
319 ret = g_strdup_printf (
"Weak password (%s)", *descp);
322 g_strdup_printf (
"Weak password (see '%s' line %d)", fname, lineno);
326 if (g_ascii_strcasecmp (line, password))
329 ret = g_strdup_printf (
"Weak password (%s)", *descp);
332 g_strdup_printf (
"Weak password (see '%s' line %d)", fname, lineno);
361 if (!password || !*password)
362 return g_strdup (
"Empty password");
364 fp = fopen (patternfile,
"r");
367 g_warning (
"error opening '%s': %s", patternfile, g_strerror (errno));
372 while (fgets (line,
DIM (line) - 1, fp))
378 if (!len || line[len - 1] !=
'\n')
380 g_warning (
"error reading '%s', line %d: %s", patternfile, lineno,
381 len ?
"line too long" :
"line without a LF");
386 if (len && line[len - 1] ==
'\r')
393 bzero (line,
sizeof (line));
408 g_warning (
"Password policy checking has been disabled.");
static int search_file(const char *fname, const char *password)
Search a file for a matching line.
void gvm_disable_password_policy(void)
Disable all password policy checking.
static char * policy_checking_failed(void)
static gboolean disable_password_policy
Flag indicating that passwords are not checked.
#define PWPOLICY_FILE_NAME
The name of the pattern file.
char * gvm_validate_password(const char *password, const char *username)
Validate a password against the pattern file.
static char * is_keyword(char *string, const char *keyword)
Check whether a string starts with a keyword.
static char * parse_pattern_line(char *line, const char *fname, int lineno, char **descp, const char *password, const char *username)
Parse one line of a pettern file.
Protos and data structures for pwpolicy checking.