summaryrefslogtreecommitdiff
path: root/src/firstboot
diff options
context:
space:
mode:
authorXiang Fan <sfanxiang@gmail.com>2018-10-24 18:34:04 +0800
committerLennart Poettering <lennart@poettering.net>2018-10-31 18:26:58 +0100
commitc7b7d74e81bae65ffef38f46dd6abf0b8a9c3d4f (patch)
tree2e99111cfda17bbfcd6f213871cc3a33adfbd81d /src/firstboot
parent45313bd9211d456b8e27486ab9032572ce6743bd (diff)
downloadsystemd-c7b7d74e81bae65ffef38f46dd6abf0b8a9c3d4f.tar.gz
ask-password: check keyring in ask_password_tty and ask_password_agent
A race condition happens when calling ask_password_auto() multiple times to unlock several disks on boot and effectively no password caching is utilized. This patch fixes it by polling the cache when waiting for the password.
Diffstat (limited to 'src/firstboot')
-rw-r--r--src/firstboot/firstboot.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 6a939aec04..c5deb66edf 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -531,13 +531,17 @@ static int prompt_root_password(void) {
msg2 = strjoina(special_glyph(TRIANGULAR_BULLET), " Please enter new root password again: ");
for (;;) {
- _cleanup_string_free_erase_ char *a = NULL, *b = NULL;
+ _cleanup_strv_free_erase_ char **a = NULL, **b = NULL;
r = ask_password_tty(-1, msg1, NULL, 0, 0, NULL, &a);
if (r < 0)
return log_error_errno(r, "Failed to query root password: %m");
+ if (strv_length(a) != 1) {
+ log_warning("Received multiple passwords, where we expected one.");
+ return -EINVAL;
+ }
- if (isempty(a)) {
+ if (isempty(*a)) {
log_warning("No password entered, skipping.");
break;
}
@@ -546,12 +550,12 @@ static int prompt_root_password(void) {
if (r < 0)
return log_error_errno(r, "Failed to query root password: %m");
- if (!streq(a, b)) {
+ if (!streq(*a, *b)) {
log_error("Entered passwords did not match, please try again.");
continue;
}
- arg_root_password = TAKE_PTR(a);
+ arg_root_password = TAKE_PTR(*a);
break;
}