From 0680c7e5b4ca1fd35de7641303d8d529da2deda7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 17 Feb 2025 22:20:51 +0100 Subject: [PATCH] homectl: don't show --enforce-password-policy= recommendation in first-boot invocation The hint is not useful, since this is after all invoked as part of the boot process, and not from an interactive shell, where the user could directly retry with the changed switch. Hence let's simply suppress the hint for those cases. --- src/home/homectl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/home/homectl.c b/src/home/homectl.c index 7acaf593018..f53a7be93a9 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -1407,7 +1407,7 @@ static int bus_message_append_blobs(sd_bus_message *m, Hashmap *blobs) { return sd_bus_message_close_container(m); } -static int create_home_common(sd_json_variant *input) { +static int create_home_common(sd_json_variant *input, bool show_enforce_password_policy_hint) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_(user_record_unrefp) UserRecord *hr = NULL; _cleanup_hashmap_free_ Hashmap *blobs = NULL; @@ -1497,7 +1497,8 @@ static int create_home_common(sd_json_variant *input) { _cleanup_(erase_and_freep) char *new_password = NULL; log_error_errno(r, "%s", bus_error_message(&error, r)); - log_info("(Use --enforce-password-policy=no to turn off password quality checks for this account.)"); + if (show_enforce_password_policy_hint) + log_info("(Use --enforce-password-policy=no to turn off password quality checks for this account.)"); r = acquire_new_password(hr->user_name, hr, /* suggest = */ false, &new_password); if (r < 0) @@ -1550,7 +1551,7 @@ static int create_home(int argc, char *argv[], void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "User name required."); } - return create_home_common(/* input= */ NULL); + return create_home_common(/* input= */ NULL, /* show_enforce_password_policy_hint= */ true); } static int remove_home(int argc, char *argv[], void *userdata) { @@ -2392,7 +2393,7 @@ static int create_from_credentials(void) { log_notice("Processing user '%s' from credentials.", e); - r = create_home_common(identity); + r = create_home_common(identity, /* show_enforce_password_policy_hint= */ false); if (r >= 0) n_created++; @@ -2682,7 +2683,7 @@ static int create_interactively(void) { return log_error_errno(r, "Failed to set shell field: %m"); } - return create_home_common(/* input= */ NULL); + return create_home_common(/* input= */ NULL, /* show_enforce_password_policy_hint= */ false); } static int verb_firstboot(int argc, char *argv[], void *userdata) { -- 2.47.3