]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homectl: add a 'dry-run' mode for registering/creating users
authorLennart Poettering <lennart@poettering.net>
Wed, 19 Feb 2025 20:25:34 +0000 (21:25 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 Mar 2025 17:14:14 +0000 (18:14 +0100)
Since this only covers user creation/registration for now, let's hide it
behind an env var. We might reconsider this eventually and make it a
proper switch one day, but who knows, it after all has this "debug tool"
wiff.

docs/ENVIRONMENT.md
src/home/homectl.c

index 4b2289e6466b1a148b67b87ec51dc4803eaa4ff1..c340e01d0168c9ab919ab9d707427613a71c6b80 100644 (file)
@@ -615,6 +615,11 @@ SYSTEMD_HOME_DEBUG_SUFFIX=foo \
   there already exists at least one regular user on the system. If set to "0"
   will make the tool skip any such query.
 
+* `$SYSTEMD_HOME_DRY_RUN` – if set to "1" will make `homectl create` and
+  `homectl update` operate in a "dry-run" mode: the new user record is
+  assembled, and displayed in JSON format, but not actually passed to
+  `systemd-homed` for execution of the operation.
+
 `kernel-install`:
 
 * `$KERNEL_INSTALL_BYPASS` – If set to "1", execution of kernel-install is skipped
index 66f3f773f6460cea6b24a434a8b114bbb7108488..22570819a47c72459c65c2da3b424fd4174b7e27 100644 (file)
@@ -99,6 +99,7 @@ static char *arg_blob_dir = NULL;
 static bool arg_blob_clear = false;
 static Hashmap *arg_blob_files = NULL;
 static char *arg_key_name = NULL;
+static bool arg_dry_run = false;
 
 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra, sd_json_variant_unrefp);
 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_this_machine, sd_json_variant_unrefp);
@@ -1462,6 +1463,11 @@ static int create_home_common(sd_json_variant *input, bool show_enforce_password
                         log_warning_errno(r, "Specified password does not pass quality checks (%s), proceeding anyway.", bus_error_message(&error, r));
         }
 
+        if (arg_dry_run) {
+                sd_json_variant_dump(hr->json, SD_JSON_FORMAT_COLOR_AUTO|SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_NEWLINE, stderr, /* prefix= */ NULL);
+                return 0;
+        }
+
         r = acquire_bus(&bus);
         if (r < 0)
                 return r;
@@ -1760,6 +1766,11 @@ static int update_home(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return r;
 
+        if (arg_dry_run) {
+                sd_json_variant_dump(hr->json, SD_JSON_FORMAT_COLOR_AUTO|SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_NEWLINE, stderr, /* prefix= */ NULL);
+                return 0;
+        }
+
         /* If we do multiple operations, let's output things more verbosely, since otherwise the repeated
          * authentication might be confusing. */
 
@@ -3181,6 +3192,13 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
+        /* Eventually we should probably turn this into a proper --dry-run option, but as long as it is not hooked up everywhere let's make it an environment variable only. */
+        r = getenv_bool("SYSTEMD_HOME_DRY_RUN");
+        if (r >= 0)
+                arg_dry_run = r;
+        else if (r != -ENXIO)
+                log_debug_errno(r, "Unable to parse $SYSTEMD_HOME_DRY_RUN, ignoring: %m");
+
         for (;;) {
                 int c;