From: Lennart Poettering Date: Fri, 10 Mar 2023 10:32:20 +0000 (+0100) Subject: dissect: share dissected_image_decrypt_interactively() invocation between actions X-Git-Tag: v254-rc1~1068^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94abea2abff055da7fc4abbb927168c68c3c79d2;p=thirdparty%2Fsystemd.git dissect: share dissected_image_decrypt_interactively() invocation between actions Let's invoke dissected_image_decrypt_interactively() at once place only, instead of in each function separately. No actual changes, just some minor refactoring. --- diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index 8b1f1bf20c8..d9f7e0e4c69 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -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: