OpenVAS Libraries  9.0.3
pwpolicy.h File Reference

Protos and data structures for pwpolicy checking. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * openvas_validate_password (const char *, const char *)
 Validate a password against the pattern file. More...
 
void openvas_disable_password_policy (void)
 Disable all password policy checking. More...
 

Detailed Description

Protos and data structures for pwpolicy checking.

This file contains the protos for pwpolicy.c

Definition in file pwpolicy.h.

Function Documentation

◆ openvas_disable_password_policy()

void openvas_disable_password_policy ( void  )

Disable all password policy checking.

Definition at line 422 of file pwpolicy.c.

423 {
424  disable_password_policy = TRUE;
425  g_warning ("Password policy checking has been disabled.");
426 }

◆ openvas_validate_password()

char* openvas_validate_password ( const char *  password,
const char *  username 
)

Validate a password against the pattern file.

Parameters
[in]passwordThe password to check
[in]usernameThe user name or NULL. This is used to check the passphrase against the user name.
Returns
NULL on success or a malloced string with an error description.

Definition at line 367 of file pwpolicy.c.

368 {
369  const char *patternfile = PWPOLICY_FILE_NAME;
370  char *ret;
371  FILE *fp;
372  int lineno;
373  size_t len;
374  char line[256];
375  char *desc = NULL;
376 
377  if (disable_password_policy)
378  return NULL;
379 
380  if (!password || !*password)
381  return g_strdup ("Empty password");
382 
383  fp = fopen (patternfile, "r");
384  if (!fp)
385  {
386  g_warning ("error opening '%s': %s", patternfile, g_strerror (errno));
387  return policy_checking_failed ();
388  }
389  lineno = 0;
390  ret = NULL;
391  while (fgets (line, DIM(line)-1, fp))
392  {
393  lineno++;
394  len = strlen (line);
395  if (!len || line[len-1] != '\n')
396  {
397  g_warning ("error reading '%s', line %d: %s",
398  patternfile, lineno,
399  len? "line too long":"line without a LF");
400  ret = policy_checking_failed ();
401  break;
402  }
403  line[--len] = 0; /* Chop the LF. */
404  if (len && line[len-1] == '\r')
405  line[--len] = 0; /* Chop an optional CR. */
406  ret = parse_pattern_line (line, patternfile, lineno, &desc,
407  password, username);
408  if (ret)
409  break;
410  }
411 
412  fclose (fp);
413  g_free (desc);
414  return ret;
415 }
#define PWPOLICY_FILE_NAME
The name of the pattern file.
Definition: pwpolicy.c:115
#define DIM(v)
Definition: pwpolicy.c:44

References PWPOLICY_FILE_NAME.