Greenbone Vulnerability Management Libraries  22.8.0
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 * gvm_validate_password (const char *, const char *)
 Validate a password against the pattern file. More...
 
void gvm_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

◆ gvm_disable_password_policy()

void gvm_disable_password_policy ( void  )

Disable all password policy checking.

Definition at line 405 of file pwpolicy.c.

406 {
408  g_warning ("Password policy checking has been disabled.");
409 }

References disable_password_policy.

◆ gvm_validate_password()

char* gvm_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 349 of file pwpolicy.c.

350 {
351  const char *patternfile = PWPOLICY_FILE_NAME;
352  char *ret;
353  FILE *fp;
354  int lineno;
355  char line[256];
356  char *desc = NULL;
357 
359  return NULL;
360 
361  if (!password || !*password)
362  return g_strdup ("Empty password");
363 
364  fp = fopen (patternfile, "r");
365  if (!fp)
366  {
367  g_warning ("error opening '%s': %s", patternfile, g_strerror (errno));
368  return policy_checking_failed ();
369  }
370  lineno = 0;
371  ret = NULL;
372  while (fgets (line, DIM (line) - 1, fp))
373  {
374  size_t len;
375 
376  lineno++;
377  len = strlen (line);
378  if (!len || line[len - 1] != '\n')
379  {
380  g_warning ("error reading '%s', line %d: %s", patternfile, lineno,
381  len ? "line too long" : "line without a LF");
382  ret = policy_checking_failed ();
383  break;
384  }
385  line[--len] = 0; /* Chop the LF. */
386  if (len && line[len - 1] == '\r')
387  line[--len] = 0; /* Chop an optional CR. */
388  ret = parse_pattern_line (line, patternfile, lineno, &desc, password,
389  username);
390  if (ret)
391  break;
392 
393  bzero (line, sizeof (line));
394  }
395 
396  fclose (fp);
397  g_free (desc);
398  return ret;
399 }

References DIM, disable_password_policy, parse_pattern_line(), policy_checking_failed(), and PWPOLICY_FILE_NAME.

Here is the call graph for this function:
parse_pattern_line
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.
Definition: pwpolicy.c:226
PWPOLICY_FILE_NAME
#define PWPOLICY_FILE_NAME
The name of the pattern file.
Definition: pwpolicy.c:94
DIM
#define DIM(v)
Definition: pwpolicy.c:23
policy_checking_failed
static char * policy_checking_failed(void)
Definition: pwpolicy.c:106
disable_password_policy
static gboolean disable_password_policy
Flag indicating that passwords are not checked.
Definition: pwpolicy.c:99