From 22aba9b2fcb5db1b48abb267f12a1420fd15ea4d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 26 Oct 2021 16:41:31 +0200 Subject: [PATCH] homework: actually try all supplied passwords Unfortunately mount.cifs doesn't really let us know much about the reason for the failure. Hence, assume it's caused by a bad password, and retry on any failure with additional passwords that we might have. A loop to do this was always in place, but none of the possible codepaths actually allowed to iterate more than once. Fix that. --- src/home/homework-cifs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/home/homework-cifs.c b/src/home/homework-cifs.c index 55b8c2588d6..6184d7c30e1 100644 --- a/src/home/homework-cifs.c +++ b/src/home/homework-cifs.c @@ -99,16 +99,18 @@ int home_setup_cifs( exit_status = wait_for_terminate_and_check("mount", mount_pid, WAIT_LOG_ABNORMAL|WAIT_LOG_NON_ZERO_EXIT_STATUS); if (exit_status < 0) return exit_status; - if (exit_status != EXIT_SUCCESS) - return -EPROTO; + if (exit_status == EXIT_SUCCESS) { + setup->undo_mount = true; + break; + } - setup->undo_mount = true; - break; + if (pw[1]) + log_info("CIFS mount failed with password #%zu, trying next password.", (size_t) (pw - h->password) + 1); } if (!setup->undo_mount) return log_error_errno(SYNTHETIC_ERRNO(ENOKEY), - "Failed to mount home directory with supplied password."); + "Failed to mount home directory, supplied password(s) possibly wrong."); /* Adjust MS_SUID and similar flags */ r = mount_nofollow_verbose(LOG_ERR, NULL, HOME_RUNTIME_WORK_DIR, NULL, MS_BIND|MS_REMOUNT|user_record_mount_flags(h), NULL);