From: Zbigniew Jędrzejewski-Szmek Date: Fri, 27 Jun 2025 12:19:29 +0000 (+0200) Subject: shared/bus-unit-util: define helper for RootHash= X-Git-Tag: v258-rc1~183^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d92c1da4595986fd7d5479072d06cf4398862c0;p=thirdparty%2Fsystemd.git shared/bus-unit-util: define helper for RootHash= --- diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 71b141fe991..ba4ba65dfa3 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1600,6 +1600,25 @@ static int bus_append_temporary_file_system(sd_bus_message *m, const char *field return 1; } +static int bus_append_root_hash(sd_bus_message *m, const char *field, const char *eq) { + _cleanup_free_ void *roothash_decoded = NULL; + size_t roothash_decoded_size = 0; + int r; + + /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */ + if (path_is_absolute(eq)) + return bus_append_string(m, "RootHashPath", eq); + + /* We have a roothash to decode, eg: RootHash=012345789abcdef */ + r = unhexmem(eq, &roothash_decoded, &roothash_decoded_size); + if (r < 0) + return log_error_errno(r, "Failed to decode RootHash= '%s': %m", eq); + if (roothash_decoded_size < sizeof(sd_id128_t)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "RootHash= '%s' is too short.", eq); + + return bus_append_byte_array(m, field, roothash_decoded, roothash_decoded_size); +} + static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) { if (STR_IN_SET(field, "DevicePolicy", "Slice", @@ -1946,23 +1965,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con if (streq(field, "TemporaryFileSystem")) return bus_append_temporary_file_system(m, field, eq); - if (streq(field, "RootHash")) { - _cleanup_free_ void *roothash_decoded = NULL; - size_t roothash_decoded_size = 0; - - /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */ - if (path_is_absolute(eq)) - return bus_append_string(m, "RootHashPath", eq); - - /* We have a roothash to decode, eg: RootHash=012345789abcdef */ - r = unhexmem(eq, &roothash_decoded, &roothash_decoded_size); - if (r < 0) - return log_error_errno(r, "Failed to decode RootHash= '%s': %m", eq); - if (roothash_decoded_size < sizeof(sd_id128_t)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "RootHash= '%s' is too short.", eq); - - return bus_append_byte_array(m, field, roothash_decoded, roothash_decoded_size); - } + if (streq(field, "RootHash")) + return bus_append_root_hash(m, field, eq); if (streq(field, "RootHashSignature")) { _cleanup_free_ void *roothash_sig_decoded = NULL;