diff options
Diffstat (limited to 'src/pcrlock')
-rw-r--r-- | src/pcrlock/pcrlock.c | 412 |
1 files changed, 207 insertions, 205 deletions
diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c index 1716fb3219..c07132c135 100644 --- a/src/pcrlock/pcrlock.c +++ b/src/pcrlock/pcrlock.c @@ -6,6 +6,7 @@ #include <sys/file.h> #include "sd-device.h" +#include "sd-json.h" #include "ask-password-api.h" #include "blockdev-util.h" @@ -28,6 +29,7 @@ #include "hash-funcs.h" #include "hexdecoct.h" #include "initrd-util.h" +#include "json-util.h" #include "main-func.h" #include "mkdir-label.h" #include "openssl-util.h" @@ -62,7 +64,7 @@ typedef enum RecoveryPinMode { } RecoveryPinMode; static PagerFlags arg_pager_flags = 0; -static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF|JSON_FORMAT_NEWLINE; +static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF|SD_JSON_FORMAT_NEWLINE; static char **arg_components = NULL; static uint32_t arg_pcr_mask = 0; static char *arg_pcrlock_path = NULL; @@ -157,7 +159,7 @@ struct EventLogRecord { /* Data for userspace events (i.e. those generated by systemd in userspace */ Tpm2UserspaceEventType userspace_event_type; - JsonVariant *userspace_content; + sd_json_variant *userspace_content; /* Validation result for the event payload itself, if the record contains enough information to validate the hash */ EventPayloadValid event_payload_valid; @@ -246,7 +248,7 @@ static EventLogRecord *event_log_record_free(EventLogRecord *record) { free(record->description); free(record->firmware_payload); - json_variant_unref(record->userspace_content); + sd_json_variant_unref(record->userspace_content); while ((bank = LIST_POP(banks, record->banks))) event_log_record_bank_free(bank); @@ -995,58 +997,58 @@ static int event_log_load_firmware(EventLog *el) { return 0; } -static int event_log_record_parse_json(EventLogRecord *record, JsonVariant *j) { +static int event_log_record_parse_json(EventLogRecord *record, sd_json_variant *j) { const char *rectype = NULL; - JsonVariant *x, *k; + sd_json_variant *x, *k; uint64_t u; int r; assert(record); assert(j); - if (!json_variant_is_object(j)) + if (!sd_json_variant_is_object(j)) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "record object is not an object."); - x = json_variant_by_key(j, "pcr"); + x = sd_json_variant_by_key(j, "pcr"); if (!x) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'pcr' field missing from TPM measurement log file entry."); - if (!json_variant_is_unsigned(x)) + if (!sd_json_variant_is_unsigned(x)) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'pcr' field is not an integer."); - u = json_variant_unsigned(x); + u = sd_json_variant_unsigned(x); if (u >= TPM2_PCRS_MAX) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'pcr' field is out of range."); - record->pcr = json_variant_unsigned(x); + record->pcr = sd_json_variant_unsigned(x); - x = json_variant_by_key(j, "digests"); + x = sd_json_variant_by_key(j, "digests"); if (!x) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'digests' field missing from TPM measurement log file entry."); - if (!json_variant_is_array(x)) + if (!sd_json_variant_is_array(x)) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'digests' field is not an array."); JSON_VARIANT_ARRAY_FOREACH(k, x) { _cleanup_free_ void *hash = NULL; size_t hash_size; - JsonVariant *a, *h; + sd_json_variant *a, *h; int na; - a = json_variant_by_key(k, "hashAlg"); + a = sd_json_variant_by_key(k, "hashAlg"); if (!a) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'digests' field element lacks 'hashAlg' field."); - if (!json_variant_is_string(a)) + if (!sd_json_variant_is_string(a)) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'hashAlg' field is not a string."); - na = tpm2_hash_alg_from_string(json_variant_string(a)); + na = tpm2_hash_alg_from_string(sd_json_variant_string(a)); if (na < 0) { - log_debug_errno(na, "Unsupported hash '%s' in userspace event log, ignoring: %m", json_variant_string(a)); + log_debug_errno(na, "Unsupported hash '%s' in userspace event log, ignoring: %m", sd_json_variant_string(a)); continue; } - h = json_variant_by_key(k, "digest"); + h = sd_json_variant_by_key(k, "digest"); if (!h) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'digests' field lacks 'digest' field."); - r = json_variant_unhex(h, &hash, &hash_size); + r = sd_json_variant_unhex(h, &hash, &hash_size); if (r < 0) return log_error_errno(r, "Failed to decode digest: %m"); @@ -1060,47 +1062,47 @@ static int event_log_record_parse_json(EventLogRecord *record, JsonVariant *j) { return log_error_errno(r, "Failed to add bank to event log record: %m"); } - x = json_variant_by_key(j, "content_type"); + x = sd_json_variant_by_key(j, "content_type"); if (!x) log_debug("'content_type' missing from TPM measurement log file entry, ignoring."); else { - if (!json_variant_is_string(x)) + if (!sd_json_variant_is_string(x)) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'content_type' field is not a string."); - rectype = json_variant_string(x); + rectype = sd_json_variant_string(x); } if (streq_ptr(rectype, "systemd")) { - JsonVariant *y; + sd_json_variant *y; - x = json_variant_by_key(j, "content"); + x = sd_json_variant_by_key(j, "content"); if (!x) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'content' field missing from TPM measurement log file entry."); - if (!json_variant_is_object(x)) + if (!sd_json_variant_is_object(x)) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'content' sub-object is not an object."); - y = json_variant_by_key(x, "string"); + y = sd_json_variant_by_key(x, "string"); if (y) { - if (!json_variant_is_string(y)) + if (!sd_json_variant_is_string(y)) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'string' field is not a string."); - r = free_and_strdup_warn(&record->description, json_variant_string(y)); + r = free_and_strdup_warn(&record->description, sd_json_variant_string(y)); if (r < 0) return r; } - y = json_variant_by_key(x, "eventType"); + y = sd_json_variant_by_key(x, "eventType"); if (y) { - if (!json_variant_is_string(y)) + if (!sd_json_variant_is_string(y)) return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "'eventType' field is not a string."); - record->userspace_event_type = tpm2_userspace_event_type_from_string(json_variant_string(y)); + record->userspace_event_type = tpm2_userspace_event_type_from_string(sd_json_variant_string(y)); if (record->userspace_event_type < 0) - log_debug_errno(record->userspace_event_type, "Unknown userspace event type '%s', ignoring.", json_variant_string(y)); + log_debug_errno(record->userspace_event_type, "Unknown userspace event type '%s', ignoring.", sd_json_variant_string(y)); } - json_variant_unref(record->userspace_content); - record->userspace_content = json_variant_ref(x); + sd_json_variant_unref(record->userspace_content); + record->userspace_content = sd_json_variant_ref(x); } return 0; @@ -1130,7 +1132,7 @@ static int event_log_load_userspace(EventLog *el) { return log_error_errno(errno, "Failed to lock userspace TPM measurement log file: %m"); for (;;) { - _cleanup_(json_variant_unrefp) JsonVariant *j = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL; EventLogRecord *record; int ch; @@ -1164,7 +1166,7 @@ static int event_log_load_userspace(EventLog *el) { continue; } - r = json_parse(b, 0, &j, NULL, NULL); + r = sd_json_parse(b, 0, &j, NULL, NULL); if (r < 0) return log_error_errno(r, "Failed to parse local TPM measurement log file: %m"); @@ -1476,7 +1478,7 @@ static int event_log_record_validate_hash_userspace( _cleanup_free_ unsigned char *payload_hash = NULL; unsigned payload_hash_size; - JsonVariant *js; + sd_json_variant *js; const char *s; int mdsz; @@ -1490,12 +1492,12 @@ static int event_log_record_validate_hash_userspace( if (!record->userspace_content) return 0; - js = json_variant_by_key(record->userspace_content, "string"); + js = sd_json_variant_by_key(record->userspace_content, "string"); if (!js) return 0; - assert(json_variant_is_string(js)); - s = json_variant_string(js); + assert(sd_json_variant_is_string(js)); + s = sd_json_variant_string(js); mdsz = EVP_MD_size(md); assert(mdsz > 0); @@ -1634,8 +1636,8 @@ static int event_log_record_equal(const EventLogRecord *a, const EventLogRecord static int event_log_add_component_file(EventLog *el, EventLogComponent *component, const char *path) { _cleanup_(event_log_component_variant_freep) EventLogComponentVariant *variant = NULL; _cleanup_free_ char *fname = NULL, *id = NULL, *path_copy = NULL; - _cleanup_(json_variant_unrefp) JsonVariant *j = NULL; - JsonVariant *records; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL; + sd_json_variant *records; const char *e; int r; @@ -1662,7 +1664,7 @@ static int event_log_add_component_file(EventLog *el, EventLogComponent *compone if (!GREEDY_REALLOC(component->variants, component->n_variants+1)) return log_oom(); - r = json_parse_file( + r = sd_json_parse_file( /* f= */ NULL, path, /* flags= */ 0, @@ -1674,7 +1676,7 @@ static int event_log_add_component_file(EventLog *el, EventLogComponent *compone return 0; } - if (!json_variant_is_object(j)) { + if (!sd_json_variant_is_object(j)) { log_warning_errno(r, "Component file %s does not contain JSON object, ignoring.", path); return 0; } @@ -1693,11 +1695,11 @@ static int event_log_add_component_file(EventLog *el, EventLogComponent *compone .id = TAKE_PTR(id), }; - records = json_variant_by_key(j, "records"); + records = sd_json_variant_by_key(j, "records"); if (records) { - JsonVariant *rj; + sd_json_variant *rj; - if (!json_variant_is_array(records)) { + if (!sd_json_variant_is_array(records)) { log_warning_errno(r, "Component records field of file %s is not an array, ignoring.", path); return 0; } @@ -2017,7 +2019,7 @@ static int add_algorithm_columns( if (r < 0) return table_log_add_error(r); - if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF) && + if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) && el->primary_algorithm != UINT16_MAX && *alg != el->primary_algorithm) (void) table_hide_column_from_display(table, c); @@ -2039,7 +2041,7 @@ static int add_algorithm_columns( return 0; } -static int show_log_table(EventLog *el, JsonVariant **ret_variant) { +static int show_log_table(EventLog *el, sd_json_variant **ret_variant) { _cleanup_(table_unrefp) Table *table = NULL; int r; @@ -2078,7 +2080,7 @@ static int show_log_table(EventLog *el, JsonVariant **ret_variant) { (void) table_hide_column_from_display(table, table_get_columns(table) - 3); /* hide source */ - if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) + if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) (void) table_hide_column_from_display(table, (size_t) 1); /* hide color block column */ (void) table_set_json_field_name(table, phase_column, "phase"); @@ -2177,7 +2179,7 @@ static bool event_log_pcr_checks_out(const EventLog *el, const EventLogRegister return true; } -static int show_pcr_table(EventLog *el, JsonVariant **ret_variant) { +static int show_pcr_table(EventLog *el, sd_json_variant **ret_variant) { _cleanup_(table_unrefp) Table *table = NULL; int r; @@ -2214,7 +2216,7 @@ static int show_pcr_table(EventLog *el, JsonVariant **ret_variant) { if (r < 0) return r; - if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) + if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) (void) table_hide_column_from_display(table, (size_t) 1, (size_t) 2); /* hide color block and emoji column */ else if (!emoji_enabled()) (void) table_hide_column_from_display(table, (size_t) 2); @@ -2319,7 +2321,7 @@ static int show_pcr_table(EventLog *el, JsonVariant **ret_variant) { if (r < 0) return log_error_errno(r, "Failed to output table: %m"); - if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) + if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) printf("\n" "%sLegend: H → PCR hash value matches event log%s\n" "%s R → All event log records for this PCR have a matching component%s\n" @@ -2399,9 +2401,9 @@ static int event_log_load_and_process(EventLog **ret) { } static int verb_show_log(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *log_table = NULL, *pcr_table = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *log_table = NULL, *pcr_table = NULL; _cleanup_(event_log_freep) EventLog *el = NULL; - bool want_json = !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF); + bool want_json = !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF); int r; r = event_log_load_and_process(&el); @@ -2423,15 +2425,15 @@ static int verb_show_log(int argc, char *argv[], void *userdata) { return r; if (want_json) { - _cleanup_(json_variant_unrefp) JsonVariant *object = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *object = NULL; - r = json_build(&object, JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_VARIANT("log", log_table), - JSON_BUILD_PAIR_VARIANT("pcrs", pcr_table))); + r = sd_json_build(&object, SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_VARIANT("log", log_table), + SD_JSON_BUILD_PAIR_VARIANT("pcrs", pcr_table))); if (r < 0) return log_error_errno(r, "Failed to generate combined object: %m"); - r = json_variant_dump(object, arg_json_format_flags, stdout, /* prefix= */ NULL); + r = sd_json_variant_dump(object, arg_json_format_flags, stdout, /* prefix= */ NULL); if (r < 0) return log_error_errno(r, "Failed to dump JSON object: %m"); } @@ -2439,9 +2441,9 @@ static int verb_show_log(int argc, char *argv[], void *userdata) { return 0; } -static int event_log_record_to_cel(EventLogRecord *record, uint64_t *recnum, JsonVariant **ret) { - _cleanup_(json_variant_unrefp) JsonVariant *ja = NULL, *fj = NULL; - JsonVariant *cd = NULL; +static int event_log_record_to_cel(EventLogRecord *record, uint64_t *recnum, sd_json_variant **ret) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *ja = NULL, *fj = NULL; + sd_json_variant *cd = NULL; const char *ct = NULL; int r; @@ -2450,16 +2452,16 @@ static int event_log_record_to_cel(EventLogRecord *record, uint64_t *recnum, Jso assert(ret); LIST_FOREACH(banks, bank, record->banks) { - r = json_variant_append_arrayb( - &ja, JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_STRING("hashAlg", tpm2_hash_alg_to_string(bank->algorithm)), - JSON_BUILD_PAIR_HEX("digest", bank->hash.buffer, bank->hash.size))); + r = sd_json_variant_append_arrayb( + &ja, SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("hashAlg", tpm2_hash_alg_to_string(bank->algorithm)), + SD_JSON_BUILD_PAIR_HEX("digest", bank->hash.buffer, bank->hash.size))); if (r < 0) return log_error_errno(r, "Failed to append CEL digest entry: %m"); } if (!ja) { - r = json_variant_new_array(&ja, NULL, 0); + r = sd_json_variant_new_array(&ja, NULL, 0); if (r < 0) return log_error_errno(r, "Failed to allocate JSON array: %m"); } @@ -2482,9 +2484,9 @@ static int event_log_record_to_cel(EventLogRecord *record, uint64_t *recnum, Jso } else if (asprintf(&et, "%" PRIu32, record->firmware_event_type) < 0) return log_oom(); - r = json_build(&fj, JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_STRING("event_type", et), - JSON_BUILD_PAIR_HEX("event_data", record->firmware_payload, record->firmware_payload_size))); + r = sd_json_build(&fj, SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("event_type", et), + SD_JSON_BUILD_PAIR_HEX("event_data", record->firmware_payload, record->firmware_payload_size))); if (r < 0) return log_error_errno(r, "Failed to build firmware event data: %m"); @@ -2495,13 +2497,13 @@ static int event_log_record_to_cel(EventLogRecord *record, uint64_t *recnum, Jso ct = "systemd"; } - r = json_build(ret, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_UNSIGNED("pcr", record->pcr), - JSON_BUILD_PAIR_UNSIGNED("recnum", ++(*recnum)), - JSON_BUILD_PAIR_VARIANT("digests", ja), - JSON_BUILD_PAIR_CONDITION(ct, "content_type", JSON_BUILD_STRING(ct)), - JSON_BUILD_PAIR_CONDITION(cd, "content", JSON_BUILD_VARIANT(cd)))); + r = sd_json_build(ret, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_UNSIGNED("pcr", record->pcr), + SD_JSON_BUILD_PAIR_UNSIGNED("recnum", ++(*recnum)), + SD_JSON_BUILD_PAIR_VARIANT("digests", ja), + SD_JSON_BUILD_PAIR_CONDITION(!!ct, "content_type", SD_JSON_BUILD_STRING(ct)), + SD_JSON_BUILD_PAIR_CONDITION(!!cd, "content", SD_JSON_BUILD_VARIANT(cd)))); if (r < 0) return log_error_errno(r, "Failed to make CEL record: %m"); @@ -2509,7 +2511,7 @@ static int event_log_record_to_cel(EventLogRecord *record, uint64_t *recnum, Jso } static int verb_show_cel(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; _cleanup_(event_log_freep) EventLog *el = NULL; uint64_t recnum = 0; int r; @@ -2525,21 +2527,21 @@ static int verb_show_cel(int argc, char *argv[], void *userdata) { /* Output the event log in TCG CEL-JSON. */ FOREACH_ARRAY(rr, el->records, el->n_records) { - _cleanup_(json_variant_unrefp) JsonVariant *cel = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *cel = NULL; r = event_log_record_to_cel(*rr, &recnum, &cel); if (r < 0) return r; - r = json_variant_append_array(&array, cel); + r = sd_json_variant_append_array(&array, cel); if (r < 0) return log_error_errno(r, "Failed to append CEL record: %m"); } - if (arg_json_format_flags & (JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO)) + if (arg_json_format_flags & (SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO)) pager_open(arg_pager_flags); - json_variant_dump(array, arg_json_format_flags|JSON_FORMAT_EMPTY_ARRAY, stdout, NULL); + sd_json_variant_dump(array, arg_json_format_flags|SD_JSON_FORMAT_EMPTY_ARRAY, stdout, NULL); return 0; } @@ -2575,7 +2577,7 @@ static int verb_list_components(int argc, char *argv[], void *userdata) { FOREACH_ARRAY(c, el->components, el->n_components) { - if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { + if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) { _cleanup_free_ char *marker = NULL; switch (loc) { @@ -2621,13 +2623,13 @@ static int verb_list_components(int argc, char *argv[], void *userdata) { } } - if (!table_isempty(table) || !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { + if (!table_isempty(table) || !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */ true); if (r < 0) return log_error_errno(r, "Failed to output table: %m"); } - if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { + if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) { if (table_isempty(table)) printf("No components defined.\n"); else @@ -2656,9 +2658,9 @@ static int make_pcrlock_record( uint32_t pcr, const void *data, size_t data_size, - JsonVariant **ret_record) { + sd_json_variant **ret_record) { - _cleanup_(json_variant_unrefp) JsonVariant *digests = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *digests = NULL; int r; assert(data || data_size == 0); @@ -2689,19 +2691,19 @@ static int make_pcrlock_record( if (EVP_Digest(data, data_size, hash, &hash_usize, md, NULL) != 1) return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), "Failed to hash data with algorithm '%s'.", a); - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &digests, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("hashAlg", JSON_BUILD_STRING(a)), - JSON_BUILD_PAIR("digest", JSON_BUILD_HEX(hash, hash_usize)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("hashAlg", SD_JSON_BUILD_STRING(a)), + SD_JSON_BUILD_PAIR("digest", SD_JSON_BUILD_HEX(hash, hash_usize)))); if (r < 0) return log_error_errno(r, "Failed to build JSON digest object: %m"); } - r = json_build(ret_record, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("pcr", JSON_BUILD_UNSIGNED(pcr)), - JSON_BUILD_PAIR("digests", JSON_BUILD_VARIANT(digests)))); + r = sd_json_build(ret_record, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_UNSIGNED(pcr)), + SD_JSON_BUILD_PAIR("digests", SD_JSON_BUILD_VARIANT(digests)))); if (r < 0) return log_error_errno(r, "Failed to build record object: %m"); @@ -2718,9 +2720,9 @@ static void evp_md_ctx_free_all(EVP_MD_CTX *(*md)[TPM2_N_HASH_ALGORITHMS]) { static int make_pcrlock_record_from_stream( uint32_t pcr_mask, FILE *f, - JsonVariant **ret_records) { + sd_json_variant **ret_records) { - _cleanup_(json_variant_unrefp) JsonVariant *digests = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *digests = NULL; _cleanup_(evp_md_ctx_free_all) EVP_MD_CTX *mdctx[TPM2_N_HASH_ALGORITHMS] = {}; int r; @@ -2773,29 +2775,29 @@ static int make_pcrlock_record_from_stream( return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), "Failed to finalize hash context for algorithn '%s'.", a); - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &digests, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("hashAlg", JSON_BUILD_STRING(a)), - JSON_BUILD_PAIR("digest", JSON_BUILD_HEX(hash, hash_usize)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("hashAlg", SD_JSON_BUILD_STRING(a)), + SD_JSON_BUILD_PAIR("digest", SD_JSON_BUILD_HEX(hash, hash_usize)))); if (r < 0) return log_error_errno(r, "Failed to build JSON digest object: %m"); } for (uint32_t i = 0; i < TPM2_PCRS_MAX; i++) { - _cleanup_(json_variant_unrefp) JsonVariant *record = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *record = NULL; if (!FLAGS_SET(pcr_mask, UINT32_C(1) << i)) continue; - r = json_build(&record, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("pcr", JSON_BUILD_UNSIGNED(i)), - JSON_BUILD_PAIR("digests", JSON_BUILD_VARIANT(digests)))); + r = sd_json_build(&record, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_UNSIGNED(i)), + SD_JSON_BUILD_PAIR("digests", SD_JSON_BUILD_VARIANT(digests)))); if (r < 0) return log_error_errno(r, "Failed to build record object: %m"); - r = json_variant_append_array(ret_records, record); + r = sd_json_variant_append_array(ret_records, record); if (r < 0) return log_error_errno(r, "Failed to append to JSON array: %m"); } @@ -2807,22 +2809,22 @@ static const char *pcrlock_path(const char *default_pcrlock_path) { return arg_pcrlock_path ?: arg_pcrlock_auto ? default_pcrlock_path : NULL; } -static int write_pcrlock(JsonVariant *array, const char *default_pcrlock_path) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *a = NULL; +static int write_pcrlock(sd_json_variant *array, const char *default_pcrlock_path) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *a = NULL; _cleanup_fclose_ FILE *f = NULL; const char *p; int r; if (!array) { - r = json_variant_new_array(&a, NULL, 0); + r = sd_json_variant_new_array(&a, NULL, 0); if (r < 0) return log_error_errno(r, "Failed to allocate empty array: %m"); array = a; } - r = json_build(&v, JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("records", JSON_BUILD_VARIANT(array)))); + r = sd_json_build(&v, SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("records", SD_JSON_BUILD_VARIANT(array)))); if (r < 0) return log_error_errno(r, "Failed to build JSON object: %m"); @@ -2835,7 +2837,7 @@ static int write_pcrlock(JsonVariant *array, const char *default_pcrlock_path) { return log_error_errno(errno, "Failed to open %s for writing: %m", p); } - r = json_variant_dump(v, arg_json_format_flags, f ?: stdout, /* prefix= */ NULL); + r = sd_json_variant_dump(v, arg_json_format_flags, f ?: stdout, /* prefix= */ NULL); if (r < 0) return log_error_errno(r, "Failed to output JSON object: %m"); @@ -2866,7 +2868,7 @@ static int unlink_pcrlock(const char *default_pcrlock_path) { } static int verb_lock_raw(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *records = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *records = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -2905,14 +2907,14 @@ static int verb_lock_secureboot_policy(int argc, char *argv[], void *userdata) { { EFI_VENDOR_DATABASE, "dbr", -1 }, }; - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; int r; /* Generates expected records from the current SecureBoot state, as readable in the EFI variables * right now. */ FOREACH_ELEMENT(vv, variables) { - _cleanup_(json_variant_unrefp) JsonVariant *record = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *record = NULL; _cleanup_free_ char *name = NULL; if (asprintf(&name, "%s-" SD_ID128_UUID_FORMAT_STR, vv->name, SD_ID128_FORMAT_VAL(vv->id)) < 0) @@ -2955,7 +2957,7 @@ static int verb_lock_secureboot_policy(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = json_variant_append_array(&array, record); + r = sd_json_variant_append_array(&array, record); if (r < 0) return log_error_errno(r, "Failed to append to JSON array: %m"); } @@ -3085,7 +3087,7 @@ static int event_log_ensure_secureboot_consistency(EventLog *el) { } static int verb_lock_secureboot_authority(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; _cleanup_(event_log_freep) EventLog *el = NULL; int r; @@ -3135,7 +3137,7 @@ static int verb_lock_secureboot_authority(int argc, char *argv[], void *userdata return r; FOREACH_ARRAY(rr, el->records, el->n_records) { - _cleanup_(json_variant_unrefp) JsonVariant *digests = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *digests = NULL; EventLogRecord *rec = *rr; if (!event_log_record_is_secureboot_authority(rec)) @@ -3144,20 +3146,20 @@ static int verb_lock_secureboot_authority(int argc, char *argv[], void *userdata log_debug("Locking down authority '%s'.", strna(rec->description)); LIST_FOREACH(banks, bank, rec->banks) { - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &digests, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("hashAlg", JSON_BUILD_STRING(tpm2_hash_alg_to_string(bank->algorithm))), - JSON_BUILD_PAIR("digest", JSON_BUILD_HEX(bank->hash.buffer, bank->hash.size)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("hashAlg", SD_JSON_BUILD_STRING(tpm2_hash_alg_to_string(bank->algorithm))), + SD_JSON_BUILD_PAIR("digest", SD_JSON_BUILD_HEX(bank->hash.buffer, bank->hash.size)))); if (r < 0) return log_error_errno(r, "Failed to build digests array: %m"); } - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("pcr", JSON_BUILD_UNSIGNED(rec->pcr)), - JSON_BUILD_PAIR("digests", JSON_BUILD_VARIANT(digests)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_UNSIGNED(rec->pcr)), + SD_JSON_BUILD_PAIR("digests", SD_JSON_BUILD_VARIANT(digests)))); if (r < 0) return log_error_errno(r, "Failed to build record array: %m"); } @@ -3170,7 +3172,7 @@ static int verb_unlock_secureboot_authority(int argc, char *argv[], void *userda } static int verb_lock_gpt(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL, *record = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL, *record = NULL; _cleanup_(sd_device_unrefp) sd_device *d = NULL; uint8_t h[2 * 4096]; /* space for at least two 4K sectors. GPT header should definitely be in here */ uint64_t start, n_members, member_size; @@ -3275,7 +3277,7 @@ static int verb_lock_gpt(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = json_variant_new_array(&array, &record, 1); + r = sd_json_variant_new_array(&array, &record, 1); if (r < 0) return log_error_errno(r, "Failed to append to JSON array: %m"); @@ -3334,15 +3336,15 @@ static void enable_json_sse(void) { if (!arg_pcrlock_path && arg_pcrlock_auto) return; - if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_SSE)) + if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_SSE)) return; log_notice("Enabling JSON_SEQ mode, since writing two .pcrlock files to single output."); - arg_json_format_flags |= JSON_FORMAT_SSE; + arg_json_format_flags |= SD_JSON_FORMAT_SSE; } static int verb_lock_firmware(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *array_early = NULL, *array_late = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array_early = NULL, *array_late = NULL; _cleanup_(event_log_freep) EventLog *el = NULL; uint32_t always_mask, separator_mask, separator_seen_mask = 0, action_seen_mask = 0; const char *default_pcrlock_early_path, *default_pcrlock_late_path; @@ -3408,7 +3410,7 @@ static int verb_lock_firmware(int argc, char *argv[], void *userdata) { // and exactly once FOREACH_ARRAY(rr, el->records, el->n_records) { - _cleanup_(json_variant_unrefp) JsonVariant *digests = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *digests = NULL; EventLogRecord *rec = *rr; uint32_t bit = UINT32_C(1) << rec->pcr; @@ -3437,20 +3439,20 @@ static int verb_lock_firmware(int argc, char *argv[], void *userdata) { } LIST_FOREACH(banks, bank, rec->banks) { - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &digests, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("hashAlg", JSON_BUILD_STRING(tpm2_hash_alg_to_string(bank->algorithm))), - JSON_BUILD_PAIR("digest", JSON_BUILD_HEX(bank->hash.buffer, bank->hash.size)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("hashAlg", SD_JSON_BUILD_STRING(tpm2_hash_alg_to_string(bank->algorithm))), + SD_JSON_BUILD_PAIR("digest", SD_JSON_BUILD_HEX(bank->hash.buffer, bank->hash.size)))); if (r < 0) return log_error_errno(r, "Failed to build digests array: %m"); } - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( FLAGS_SET(separator_seen_mask, bit) ? &array_late : &array_early, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("pcr", JSON_BUILD_UNSIGNED(rec->pcr)), - JSON_BUILD_PAIR("digests", JSON_BUILD_VARIANT(digests)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_UNSIGNED(rec->pcr)), + SD_JSON_BUILD_PAIR("digests", SD_JSON_BUILD_VARIANT(digests)))); if (r < 0) return log_error_errno(r, "Failed to build record array: %m"); } @@ -3489,7 +3491,7 @@ static int verb_unlock_firmware(int argc, char *argv[], void *userdata) { } static int verb_lock_machine_id(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *record = NULL, *array = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *record = NULL, *array = NULL; _cleanup_free_ char *word = NULL; int r; @@ -3501,7 +3503,7 @@ static int verb_lock_machine_id(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = json_variant_new_array(&array, &record, 1); + r = sd_json_variant_new_array(&array, &record, 1); if (r < 0) return log_error_errno(r, "Failed to create record array: %m"); @@ -3566,7 +3568,7 @@ static int verb_lock_file_system(int argc, char *argv[], void *userdata) { STRV_FOREACH(p, paths) { _cleanup_free_ char *word = NULL, *normalized_path = NULL, *pcrlock_file = NULL; - _cleanup_(json_variant_unrefp) JsonVariant *record = NULL, *array = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *record = NULL, *array = NULL; r = pcrextend_file_system_word(*p, &word, &normalized_path); if (r < 0) @@ -3580,7 +3582,7 @@ static int verb_lock_file_system(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = json_variant_new_array(&array, &record, 1); + r = sd_json_variant_new_array(&array, &record, 1); if (r < 0) return log_error_errno(r, "Failed to create record array: %m"); @@ -3623,7 +3625,7 @@ static int verb_unlock_file_system(int argc, char *argv[], void *userdata) { } static int verb_lock_pe(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; _cleanup_close_ int fd = -EBADF; int r; @@ -3640,7 +3642,7 @@ static int verb_lock_pe(int argc, char *argv[], void *userdata) { arg_pcr_mask = UINT32_C(1) << TPM2_PCR_BOOT_LOADER_CODE; for (uint32_t i = 0; i < TPM2_PCRS_MAX; i++) { - _cleanup_(json_variant_unrefp) JsonVariant *digests = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *digests = NULL; if (!FLAGS_SET(arg_pcr_mask, UINT32_C(1) << i)) continue; @@ -3658,19 +3660,19 @@ static int verb_lock_pe(int argc, char *argv[], void *userdata) { if (r < 0) return log_error_errno(r, "Failed to hash PE binary: %m"); - r = json_variant_append_arrayb(&digests, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("hashAlg", JSON_BUILD_STRING(a)), - JSON_BUILD_PAIR("digest", JSON_BUILD_HEX(hash, hash_size)))); + r = sd_json_variant_append_arrayb(&digests, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("hashAlg", SD_JSON_BUILD_STRING(a)), + SD_JSON_BUILD_PAIR("digest", SD_JSON_BUILD_HEX(hash, hash_size)))); if (r < 0) return log_error_errno(r, "Failed to build JSON digest object: %m"); } - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("pcr", JSON_BUILD_UNSIGNED(i)), - JSON_BUILD_PAIR("digests", JSON_BUILD_VARIANT(digests)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_UNSIGNED(i)), + SD_JSON_BUILD_PAIR("digests", SD_JSON_BUILD_VARIANT(digests)))); if (r < 0) return log_error_errno(r, "Failed to append record object: %m"); } @@ -3688,7 +3690,7 @@ static void section_hashes_array_done(SectionHashArray *array) { } static int verb_lock_uki(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL, *pe_digests = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL, *pe_digests = NULL; _cleanup_(section_hashes_array_done) SectionHashArray section_hashes = {}; size_t hash_sizes[TPM2_N_HASH_ALGORITHMS]; _cleanup_close_ int fd = -EBADF; @@ -3715,11 +3717,11 @@ static int verb_lock_uki(int argc, char *argv[], void *userdata) { if (r < 0) return log_error_errno(r, "Failed to hash PE binary: %m"); - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &pe_digests, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("hashAlg", JSON_BUILD_STRING(a)), - JSON_BUILD_PAIR("digest", JSON_BUILD_HEX(peh, hash_sizes[i])))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("hashAlg", SD_JSON_BUILD_STRING(a)), + SD_JSON_BUILD_PAIR("digest", SD_JSON_BUILD_HEX(peh, hash_sizes[i])))); if (r < 0) return log_error_errno(r, "Failed to build JSON digest object: %m"); @@ -3728,16 +3730,16 @@ static int verb_lock_uki(int argc, char *argv[], void *userdata) { return log_error_errno(r, "Failed to UKI hash PE binary: %m"); } - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("pcr", JSON_BUILD_UNSIGNED(TPM2_PCR_BOOT_LOADER_CODE)), - JSON_BUILD_PAIR("digests", JSON_BUILD_VARIANT(pe_digests)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_UNSIGNED(TPM2_PCR_BOOT_LOADER_CODE)), + SD_JSON_BUILD_PAIR("digests", SD_JSON_BUILD_VARIANT(pe_digests)))); if (r < 0) return log_error_errno(r, "Failed to append record object: %m"); for (UnifiedSection section = 0; section < _UNIFIED_SECTION_MAX; section++) { - _cleanup_(json_variant_unrefp) JsonVariant *section_digests = NULL, *record = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *section_digests = NULL, *record = NULL; if (!unified_section_measure(section)) continue; @@ -3752,11 +3754,11 @@ static int verb_lock_uki(int argc, char *argv[], void *userdata) { assert_se(a = tpm2_hash_alg_to_string(tpm2_hash_algorithms[i])); - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( §ion_digests, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("hashAlg", JSON_BUILD_STRING(a)), - JSON_BUILD_PAIR("digest", JSON_BUILD_HEX(hash, hash_sizes[i])))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("hashAlg", SD_JSON_BUILD_STRING(a)), + SD_JSON_BUILD_PAIR("digest", SD_JSON_BUILD_HEX(hash, hash_sizes[i])))); if (r < 0) return log_error_errno(r, "Failed to build JSON digest object: %m"); } @@ -3769,16 +3771,16 @@ static int verb_lock_uki(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = json_variant_append_array(&array, record); + r = sd_json_variant_append_array(&array, record); if (r < 0) return log_error_errno(r, "Failed to append JSON record array: %m"); /* And then append a record for the section contents digests as well */ - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR("pcr", JSON_BUILD_UNSIGNED(TPM2_PCR_KERNEL_BOOT /* =11 */)), - JSON_BUILD_PAIR("digests", JSON_BUILD_VARIANT(section_digests)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_UNSIGNED(TPM2_PCR_KERNEL_BOOT /* =11 */)), + SD_JSON_BUILD_PAIR("digests", SD_JSON_BUILD_VARIANT(section_digests)))); if (r < 0) return log_error_errno(r, "Failed to append record object: %m"); } @@ -3850,7 +3852,7 @@ static int event_log_reduce_to_safe_pcrs(EventLog *el, uint32_t *pcrs) { } static int verb_lock_kernel_cmdline(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *record = NULL, *array = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *record = NULL, *array = NULL; _cleanup_free_ char *cmdline = NULL; int r; @@ -3875,7 +3877,7 @@ static int verb_lock_kernel_cmdline(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = json_variant_new_array(&array, &record, 1); + r = sd_json_variant_new_array(&array, &record, 1); if (r < 0) return log_error_errno(r, "Failed to create record array: %m"); @@ -3891,7 +3893,7 @@ static int verb_unlock_kernel_cmdline(int argc, char *argv[], void *userdata) { } static int verb_lock_kernel_initrd(int argc, char *argv[], void *userdata) { - _cleanup_(json_variant_unrefp) JsonVariant *records = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *records = NULL; _cleanup_fclose_ FILE *f = NULL; uint32_t pcr_mask = UINT32_C(1) << TPM2_PCR_KERNEL_INITRD; int r; @@ -4132,11 +4134,11 @@ static int event_log_show_predictions(Tpm2PCRPrediction *context, uint16_t alg) pager_open(arg_pager_flags); - if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { - _cleanup_(json_variant_unrefp) JsonVariant *j = NULL; + if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL; for (size_t i = 0; i < TPM2_N_HASH_ALGORITHMS; i++) { - _cleanup_(json_variant_unrefp) JsonVariant *aj = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *aj = NULL; r = tpm2_pcr_prediction_to_json( context, @@ -4145,10 +4147,10 @@ static int event_log_show_predictions(Tpm2PCRPrediction *context, uint16_t alg) if (r < 0) return r; - if (json_variant_elements(aj) == 0) + if (sd_json_variant_elements(aj) == 0) continue; - r = json_variant_set_field( + r = sd_json_variant_set_field( &j, tpm2_hash_alg_to_string(tpm2_hash_algorithms[i]), aj); @@ -4157,12 +4159,12 @@ static int event_log_show_predictions(Tpm2PCRPrediction *context, uint16_t alg) } if (!j) { - r = json_variant_new_object(&j, NULL, 0); + r = sd_json_variant_new_object(&j, NULL, 0); if (r < 0) return log_error_errno(r, "Failed to allocated empty object: %m"); } - json_variant_dump(j, arg_json_format_flags, /* f= */ NULL, /* prefix= */ NULL); + sd_json_variant_dump(j, arg_json_format_flags, /* f= */ NULL, /* prefix= */ NULL); return 0; } @@ -4453,13 +4455,13 @@ static int make_policy(bool force, RecoveryPinMode recovery_pin_mode) { log_info("Predicted future PCRs in %s.", FORMAT_TIMESPAN(usec_sub_unsigned(now(CLOCK_MONOTONIC), predict_start_usec), 1)); - _cleanup_(json_variant_unrefp) JsonVariant *new_prediction_json = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *new_prediction_json = NULL; r = tpm2_pcr_prediction_to_json(&new_prediction, el->primary_algorithm, &new_prediction_json); if (r < 0) return r; if (DEBUG_LOGGING) - (void) json_variant_dump(new_prediction_json, JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO, stderr, NULL); + (void) sd_json_variant_dump(new_prediction_json, SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO, stderr, NULL); _cleanup_(tpm2_pcrlock_policy_done) Tpm2PCRLockPolicy old_policy = {}; @@ -4783,12 +4785,12 @@ static int make_policy(bool force, RecoveryPinMode recovery_pin_mode) { return log_error_errno(r, "Failed to marshal NV public area: %m"); } - _cleanup_(json_variant_unrefp) JsonVariant *new_configuration_json = NULL; - r = json_build(&new_configuration_json, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_STRING("pcrBank", tpm2_hash_alg_to_string(el->primary_algorithm)), - JSON_BUILD_PAIR_VARIANT("pcrValues", new_prediction_json), - JSON_BUILD_PAIR_INTEGER("nvIndex", nv_index), + _cleanup_(sd_json_variant_unrefp) sd_json_variant *new_configuration_json = NULL; + r = sd_json_build(&new_configuration_json, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("pcrBank", tpm2_hash_alg_to_string(el->primary_algorithm)), + SD_JSON_BUILD_PAIR_VARIANT("pcrValues", new_prediction_json), + SD_JSON_BUILD_PAIR_INTEGER("nvIndex", nv_index), JSON_BUILD_PAIR_IOVEC_BASE64("nvHandle", &nv_blob), JSON_BUILD_PAIR_IOVEC_BASE64("nvPublic", &nv_public_blob), JSON_BUILD_PAIR_IOVEC_BASE64("srkHandle", &srk_blob), @@ -4798,7 +4800,7 @@ static int make_policy(bool force, RecoveryPinMode recovery_pin_mode) { return log_error_errno(r, "Failed to generate JSON: %m"); _cleanup_free_ char *text = NULL; - r = json_variant_format(new_configuration_json, 0, &text); + r = sd_json_variant_format(new_configuration_json, 0, &text); if (r < 0) return log_error_errno(r, "Failed to format new configuration to JSON: %m"); @@ -5247,14 +5249,14 @@ static int pcrlock_main(int argc, char *argv[]) { return dispatch_verb(argc, argv, verbs, NULL); } -static int vl_method_read_event_log(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_read_event_log(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { _cleanup_(event_log_freep) EventLog *el = NULL; uint64_t recnum = 0; int r; assert(link); - if (json_variant_elements(parameters) > 0) + if (sd_json_variant_elements(parameters) > 0) return varlink_error_invalid_parameter(link, parameters); el = event_log_new(); @@ -5265,17 +5267,17 @@ static int vl_method_read_event_log(Varlink *link, JsonVariant *parameters, Varl if (r < 0) return r; - _cleanup_(json_variant_unrefp) JsonVariant *rec_cel = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *rec_cel = NULL; FOREACH_ARRAY(rr, el->records, el->n_records) { if (rec_cel) { r = varlink_notifyb(link, - JSON_BUILD_OBJECT(JSON_BUILD_PAIR_VARIANT("record", rec_cel))); + SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_VARIANT("record", rec_cel))); if (r < 0) return r; - rec_cel = json_variant_unref(rec_cel); + rec_cel = sd_json_variant_unref(rec_cel); } r = event_log_record_to_cel(*rr, &recnum, &rec_cel); @@ -5284,16 +5286,16 @@ static int vl_method_read_event_log(Varlink *link, JsonVariant *parameters, Varl } return varlink_replyb(link, - JSON_BUILD_OBJECT(JSON_BUILD_PAIR_CONDITION(rec_cel, "record", JSON_BUILD_VARIANT(rec_cel)))); + SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_CONDITION(!!rec_cel, "record", SD_JSON_BUILD_VARIANT(rec_cel)))); } typedef struct MethodMakePolicyParameters { bool force; } MethodMakePolicyParameters; -static int vl_method_make_policy(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { - static const JsonDispatch dispatch_table[] = { - { "force", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, offsetof(MethodMakePolicyParameters, force), 0 }, +static int vl_method_make_policy(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { + static const sd_json_dispatch_field dispatch_table[] = { + { "force", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(MethodMakePolicyParameters, force), 0 }, {} }; MethodMakePolicyParameters p = {}; @@ -5314,12 +5316,12 @@ static int vl_method_make_policy(Varlink *link, JsonVariant *parameters, Varlink return varlink_reply(link, NULL); } -static int vl_method_remove_policy(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_remove_policy(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { int r; assert(link); - if (json_variant_elements(parameters) > 0) + if (sd_json_variant_elements(parameters) > 0) return varlink_error_invalid_parameter(link, parameters); r = remove_policy(); |