37 #define DIM(v) (sizeof (v) / sizeof ((v)[0])) 38 #define DIMof(type, member) DIM (((type *) 0)->member) 45 #define G_LOG_DOMAIN "base plcy" 108 #define PWPOLICY_FILE_NAME GVM_SYSCONF_DIR "/pwpolicy.conf" 122 return g_strdup (
"Password policy checking failed (internal error)");
140 int n = strlen (keyword);
142 if (!strncmp (
string, keyword, n))
144 if (
string[n] ==
':')
146 if (!
string[n] || g_ascii_isspace (
string[n]))
149 while (g_ascii_isspace (*
string))
176 fp = fopen (fname,
"r");
180 while (fgets (line,
DIM (line) - 1, fp))
185 if (!len || line[len - 1] !=
'\n')
189 while ((c = getc (fp)) != EOF && c !=
'\n')
194 if (len && line[len - 1] ==
'\r')
198 if (!g_ascii_strcasecmp (line, password))
206 int save_errno = errno;
233 const char *password,
const char *username)
240 while (g_ascii_isspace (*line))
247 else if (*line ==
'#' && line[1] ==
'+')
254 *descp = g_strdup (p);
270 g_warning (
"error searching '%s' (requested at line %d): %s", p,
271 lineno, g_strerror (errno));
274 else if (sret && *descp)
275 ret = g_strdup_printf (
"Weak password (%s)", *descp);
277 ret = g_strdup_printf (
"Weak password (found in '%s')", p);
289 else if (!g_ascii_strcasecmp (password, username))
290 ret = g_strdup_printf (
"Weak password (%s)",
291 "user name matches password");
292 else if (strstr (password, username))
293 ret = g_strdup_printf (
"Weak password (%s)",
294 "user name is part of the password");
295 else if (strstr (username, password))
296 ret = g_strdup_printf (
"Weak password (%s)",
297 "password is part of the user name");
303 g_warning (
"error reading '%s', line %d: %s", fname, lineno,
304 "unknown processing instruction");
308 else if (*line ==
'#')
312 else if (*line ==
'/' 313 || (*line ==
'!' && line[1] ==
'/'))
315 int rev = (*line ==
'!');
320 if (n && line[n - 1] ==
'/')
322 if (((!g_regex_match_simple (line, password, G_REGEX_CASELESS, 0)) ^ rev))
325 ret = g_strdup_printf (
"Weak password (%s)", *descp);
328 g_strdup_printf (
"Weak password (see '%s' line %d)", fname, lineno);
332 if (g_ascii_strcasecmp (line, password))
335 ret = g_strdup_printf (
"Weak password (%s)", *descp);
338 g_strdup_printf (
"Weak password (see '%s' line %d)", fname, lineno);
367 if (!password || !*password)
368 return g_strdup (
"Empty password");
370 fp = fopen (patternfile,
"r");
373 g_warning (
"error opening '%s': %s", patternfile, g_strerror (errno));
378 while (fgets (line,
DIM (line) - 1, fp))
384 if (!len || line[len - 1] !=
'\n')
386 g_warning (
"error reading '%s', line %d: %s", patternfile, lineno,
387 len ?
"line too long" :
"line without a LF");
392 if (len && line[len - 1] ==
'\r')
399 bzero (line,
sizeof (line));
414 g_warning (
"Password policy checking has been disabled.");
char * gvm_validate_password(const char *password, const char *username)
Validate a password against the pattern file.
#define PWPOLICY_FILE_NAME
The name of the pattern file.
Protos and data structures for pwpolicy checking.
static char * policy_checking_failed(void)
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 * 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.
static gboolean disable_password_policy
Flag indicating that passwords are not checked.
static char * is_keyword(char *string, const char *keyword)
Check whether a string starts with a keyword.