]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: share dissected_image_decrypt_interactively() invocation between actions
authorLennart Poettering <lennart@poettering.net>
Fri, 10 Mar 2023 10:32:20 +0000 (11:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 10 Mar 2023 10:36:34 +0000 (11:36 +0100)
Let's invoke dissected_image_decrypt_interactively() at once place only,
instead of in each function separately.

No actual changes, just some minor refactoring.

src/dissect/dissect.c

index 8b1f1bf20c82b069f81a85db9a06b36ed005252b..d9f7e0e4c696ebf10d248e91201653edf1ed184b 100644 (file)
@@ -951,13 +951,7 @@ static int action_mount(DissectedImage *m, LoopDevice *d) {
 
         assert(m);
         assert(d);
-
-        r = dissected_image_decrypt_interactively(
-                        m, NULL,
-                        &arg_verity_settings,
-                        arg_flags);
-        if (r < 0)
-                return r;
+        assert(arg_action == ACTION_MOUNT);
 
         r = dissected_image_mount_and_warn(m, arg_path, UID_INVALID, UID_INVALID, arg_flags);
         if (r < 0)
@@ -1160,13 +1154,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
 
         assert(m);
         assert(d);
-
-        r = dissected_image_decrypt_interactively(
-                        m, NULL,
-                        &arg_verity_settings,
-                        arg_flags);
-        if (r < 0)
-                return r;
+        assert(IN_SET(arg_action, ACTION_LIST, ACTION_MTREE, ACTION_COPY_FROM, ACTION_COPY_TO));
 
         r = detach_mount_namespace();
         if (r < 0)
@@ -1406,12 +1394,9 @@ static int action_with(DissectedImage *m, LoopDevice *d) {
         _cleanup_free_ char *temp = NULL;
         int r, rcode;
 
-        r = dissected_image_decrypt_interactively(
-                        m, NULL,
-                        &arg_verity_settings,
-                        arg_flags);
-        if (r < 0)
-                return r;
+        assert(m);
+        assert(d);
+        assert(arg_action == ACTION_WITH);
 
         r = tempfn_random_child(NULL, program_invocation_short_name, &temp);
         if (r < 0)
@@ -1715,6 +1700,15 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 return log_error_errno(r, "Failed to load verity signature partition: %m");
 
+        if (arg_action != ACTION_DISSECT) {
+                r = dissected_image_decrypt_interactively(
+                                m, NULL,
+                                &arg_verity_settings,
+                                arg_flags);
+                if (r < 0)
+                        return r;
+        }
+
         switch (arg_action) {
 
         case ACTION_DISSECT: