2 * Password quality check wrapper
4 * Copyright (C) 2012, Red Hat, Inc. All rights reserved.
5 * Copyright (C) 2012, Milan Broz
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "cryptsetup.h"
24 int opt_force_password = 0;
27 #include <pwquality.h>
29 static int tools_check_pwquality(const char *password)
33 pwquality_settings_t *pwq;
35 log_dbg("Checking new password using default pwquality settings.");
36 pwq = pwquality_default_settings();
40 r = pwquality_read_config(pwq, NULL, &auxerror);
42 log_err(_("Cannot check passsword quality: %s\n"),
43 pwquality_strerror(NULL, 0, r, auxerror));
44 pwquality_free_settings(pwq);
48 r = pwquality_check(pwq, password, NULL, NULL, &auxerror);
50 log_err(_("Password quality check failed:\n %s\n"),
51 pwquality_strerror(NULL, 0, r, auxerror));
54 log_dbg("New password libpwquality score is %d.", r);
58 pwquality_free_settings(pwq);
61 #else /* ENABLE_PWQUALITY */
62 static int tools_check_pwquality(const char *password)
66 #endif /* ENABLE_PWQUALITY */
68 int tools_get_key(const char *prompt,
69 char **key, size_t *key_size,
70 size_t keyfile_offset, size_t keyfile_size_max,
72 int timeout, int verify, int pwquality,
73 struct crypt_device *cd)
77 block = tools_signals_blocked();
81 r = crypt_get_key(prompt, key, key_size, keyfile_offset,
82 keyfile_size_max, key_file, timeout, verify, cd);
86 /* Check pwquality for password (not keyfile) */
87 if (pwquality && !opt_force_password && !key_file && !r)
88 r = tools_check_pwquality(*key);