]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homectl: don't show --enforce-password-policy= recommendation in first-boot invocation
authorLennart Poettering <lennart@poettering.net>
Mon, 17 Feb 2025 21:20:51 +0000 (22:20 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 18 Feb 2025 08:19:03 +0000 (09:19 +0100)
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

index 7acaf593018bec786eac22f8d91686a51676e598..f53a7be93a9885c1fca51a89bbf003739279531d 100644 (file)
@@ -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) {