static int _pam_parse (pam_handle_t *pamh, struct module_options *opt, int argc, const char **argv) { int ctrl = 0; int rv; pwquality_settings_t *pwq; void *auxerror; char buf[PWQ_MAX_ERROR_MESSAGE_LEN]; pwq = pwquality_default_settings(); if (pwq == NULL) return -1; /* just log error here */ if ((rv=pwquality_read_config(pwq, NULL, &auxerror)) != 0) pam_syslog(pamh, LOG_ERR, "Reading pwquality configuration file failed: %s", pwquality_strerror(buf, sizeof(buf), rv, auxerror)); /* step through arguments */ for (ctrl = 0; argc-- > 0; ++argv) { char *ep = NULL; if (!strcmp(*argv, "debug")) ctrl |= PAM_DEBUG_ARG; else if (!strncmp(*argv, "type=", 5)) pam_set_item (pamh, PAM_AUTHTOK_TYPE, *argv+5); else if (!strncmp(*argv, "retry=", 6)) { opt->retry_times = strtol(*argv+6, &ep, 10); if (!ep || (opt->retry_times < 1)) opt->retry_times = CO_RETRY_TIMES; } else if (!strncmp(*argv, "enforce_for_root", 16)) { opt->enforce_for_root = 1; } else if (!strncmp(*argv, "difignore=", 10)) { /* ignored for compatibility with pam_cracklib */ } else if (!strncmp(*argv, "reject_username", 15)) { /* ignored for compatibility with pam_cracklib */ } else if (!strncmp(*argv, "authtok_type", 12)) { /* for pam_get_authtok, ignore */; } else if (!strncmp(*argv, "use_authtok", 11)) { /* for pam_get_authtok, ignore */; } else if (!strncmp(*argv, "use_first_pass", 14)) { /* for pam_get_authtok, ignore */; } else if (!strncmp(*argv, "try_first_pass", 14)) { /* for pam_get_authtok, ignore */; } else if (pwquality_set_option(pwq, *argv)) { pam_syslog(pamh, LOG_ERR, "pam_parse: unknown or broken option; %s", *argv); } } opt->pwq = pwq; return ctrl; }
static pwquality_settings_t * get_pwq (void) { static pwquality_settings_t *settings; if (settings == NULL) { gchar *err = NULL; settings = pwquality_default_settings (); if (pwquality_read_config (settings, NULL, (gpointer)&err) < 0) { g_error ("failed to read pwquality configuration: %s\n", err); } } return settings; }
static pwquality_settings_t * get_pwq (void) { static pwquality_settings_t *settings = NULL; if (settings == NULL) { char *err = NULL; settings = pwquality_default_settings (); pwquality_set_int_value (settings, PWQ_SETTING_MAX_SEQUENCE, 4); if (pwquality_read_config (settings, NULL,(void **) &err) < 0) { printf ("failed to read pwquality configuration: %s\n", err); } } return settings; }
/* score a password */ int main(int argc, char *argv[]) { pwquality_settings_t *pwq; char *password; int rv; int bits; void *auxerror; setlocale(LC_ALL, ""); bindtextdomain("libpwquality", "/usr/share/locale"); textdomain("libpwquality"); if (argc != 2) { usage(basename(argv[0])); exit(3); } bits = atoi(argv[1]); pwq = pwquality_default_settings(); if (pwq == NULL) { fprintf(stderr, "Error: %s\n", pwquality_strerror(NULL, 0, PWQ_ERROR_MEM_ALLOC, NULL)); exit(2); } if ((rv = pwquality_read_config(pwq, NULL, &auxerror)) != 0) { fprintf(stderr, "Error: %s\n", pwquality_strerror(NULL, 0, rv, auxerror)); exit(3); } rv = pwquality_generate(pwq, bits, &password); if (rv != 0) { fprintf(stderr, "Error: %s\n", pwquality_strerror(NULL, 0, rv, NULL)); exit(1); } printf("%s\n", password); free(password); return 0; }
keystrength::keystrength() { #if BUILD_PWQUALITY m_handle = pwquality_default_settings() ; #endif }
keystrength::keystrength() { m_handle = reinterpret_cast< void * >( pwquality_default_settings() ) ; }