diff options
Diffstat (limited to 'src/analyze')
-rw-r--r-- | src/analyze/analyze-fdstore.c | 2 | ||||
-rw-r--r-- | src/analyze/analyze-inspect-elf.c | 22 | ||||
-rw-r--r-- | src/analyze/analyze-plot.c | 6 | ||||
-rw-r--r-- | src/analyze/analyze-security.c | 82 | ||||
-rw-r--r-- | src/analyze/analyze.c | 8 | ||||
-rw-r--r-- | src/analyze/analyze.h | 5 |
6 files changed, 64 insertions, 61 deletions
diff --git a/src/analyze/analyze-fdstore.c b/src/analyze/analyze-fdstore.c index 8ada6d4e73..dc3d979d84 100644 --- a/src/analyze/analyze-fdstore.c +++ b/src/analyze/analyze-fdstore.c @@ -81,7 +81,7 @@ static int dump_fdstore(sd_bus *bus, const char *arg) { if (r < 0) return r; - if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF) && table_isempty(table)) + if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) && table_isempty(table)) log_info("No file descriptors in fdstore of '%s'.", unit); else { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */true); diff --git a/src/analyze/analyze-inspect-elf.c b/src/analyze/analyze-inspect-elf.c index 70226a842b..e949c9049a 100644 --- a/src/analyze/analyze-inspect-elf.c +++ b/src/analyze/analyze-inspect-elf.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-json.h" + #include "analyze.h" #include "analyze-inspect-elf.h" #include "elf-util.h" @@ -7,15 +9,15 @@ #include "fd-util.h" #include "format-table.h" #include "format-util.h" -#include "json.h" +#include "json-util.h" #include "path-util.h" #include "strv.h" -static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { +static int analyze_elf(char **filenames, sd_json_format_flags_t json_flags) { int r; STRV_FOREACH(filename, filenames) { - _cleanup_(json_variant_unrefp) JsonVariant *package_metadata = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *package_metadata = NULL; _cleanup_(table_unrefp) Table *t = NULL; _cleanup_free_ char *abspath = NULL; _cleanup_close_ int fd = -EBADF; @@ -46,12 +48,12 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { return table_log_add_error(r); if (package_metadata) { - JsonVariant *module_json; + sd_json_variant *module_json; const char *module_name; JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, package_metadata) { const char *field_name; - JsonVariant *field; + sd_json_variant *field; /* The ELF type and architecture are added as top-level objects, * since they are only parsed for the file itself, but the packaging @@ -61,7 +63,7 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { r = table_add_many( t, TABLE_FIELD, module_name, - TABLE_STRING, json_variant_string(module_json)); + TABLE_STRING, sd_json_variant_string(module_json)); if (r < 0) return table_log_add_error(r); @@ -88,22 +90,22 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { } JSON_VARIANT_OBJECT_FOREACH(field_name, field, module_json) - if (json_variant_is_string(field)) { + if (sd_json_variant_is_string(field)) { r = table_add_many( t, TABLE_FIELD, field_name, - TABLE_STRING, json_variant_string(field)); + TABLE_STRING, sd_json_variant_string(field)); if (r < 0) return table_log_add_error(r); } } } - if (json_flags & JSON_FORMAT_OFF) { + if (json_flags & SD_JSON_FORMAT_OFF) { r = table_print(t, NULL); if (r < 0) return table_log_print_error(r); } else - json_variant_dump(package_metadata, json_flags, stdout, NULL); + sd_json_variant_dump(package_metadata, json_flags, stdout, NULL); } return 0; diff --git a/src/analyze/analyze-plot.c b/src/analyze/analyze-plot.c index e271296b68..0b4725e017 100644 --- a/src/analyze/analyze-plot.c +++ b/src/analyze/analyze-plot.c @@ -413,8 +413,8 @@ static int show_table(Table *table, const char *word) { if (!table_isempty(table)) { table_set_header(table, arg_legend); - if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) - r = table_print_json(table, NULL, arg_json_format_flags | JSON_FORMAT_COLOR_AUTO); + if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) + r = table_print_json(table, NULL, arg_json_format_flags | SD_JSON_FORMAT_COLOR_AUTO); else r = table_print(table, NULL); if (r < 0) @@ -490,7 +490,7 @@ int verb_plot(int argc, char *argv[], void *userdata) { typesafe_qsort(times, n, compare_unit_start); - if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF) || arg_table) + if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) || arg_table) r = produce_plot_as_text(times, boot); else r = produce_plot_as_svg(times, host, boot, pretty_times); diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c index 75508f4d39..6aa67a9339 100644 --- a/src/analyze/analyze-security.c +++ b/src/analyze/analyze-security.c @@ -1615,97 +1615,97 @@ static const struct security_assessor security_assessor_table[] = { }, }; -static JsonVariant* security_assessor_find_in_policy(const struct security_assessor *a, JsonVariant *policy, const char *name) { - JsonVariant *item; +static sd_json_variant* security_assessor_find_in_policy(const struct security_assessor *a, sd_json_variant *policy, const char *name) { + sd_json_variant *item; assert(a); if (!policy) return NULL; - if (!json_variant_is_object(policy)) { + if (!sd_json_variant_is_object(policy)) { log_debug("Specified policy is not a JSON object, ignoring."); return NULL; } - item = json_variant_by_key(policy, a->json_field); + item = sd_json_variant_by_key(policy, a->json_field); if (!item) return NULL; - if (!json_variant_is_object(item)) { + if (!sd_json_variant_is_object(item)) { log_debug("Item for '%s' in policy JSON object is not an object, ignoring.", a->id); return NULL; } - return name ? json_variant_by_key(item, name) : item; + return name ? sd_json_variant_by_key(item, name) : item; } -static uint64_t access_weight(const struct security_assessor *a, JsonVariant *policy) { - JsonVariant *val; +static uint64_t access_weight(const struct security_assessor *a, sd_json_variant *policy) { + sd_json_variant *val; assert(a); val = security_assessor_find_in_policy(a, policy, "weight"); if (val) { - if (json_variant_is_unsigned(val)) - return json_variant_unsigned(val); + if (sd_json_variant_is_unsigned(val)) + return sd_json_variant_unsigned(val); log_debug("JSON field 'weight' of policy for %s is not an unsigned integer, ignoring.", a->id); } return a->weight; } -static uint64_t access_range(const struct security_assessor *a, JsonVariant *policy) { - JsonVariant *val; +static uint64_t access_range(const struct security_assessor *a, sd_json_variant *policy) { + sd_json_variant *val; assert(a); val = security_assessor_find_in_policy(a, policy, "range"); if (val) { - if (json_variant_is_unsigned(val)) - return json_variant_unsigned(val); + if (sd_json_variant_is_unsigned(val)) + return sd_json_variant_unsigned(val); log_debug("JSON field 'range' of policy for %s is not an unsigned integer, ignoring.", a->id); } return a->range; } -static const char *access_description_na(const struct security_assessor *a, JsonVariant *policy) { - JsonVariant *val; +static const char *access_description_na(const struct security_assessor *a, sd_json_variant *policy) { + sd_json_variant *val; assert(a); val = security_assessor_find_in_policy(a, policy, "description_na"); if (val) { - if (json_variant_is_string(val)) - return json_variant_string(val); + if (sd_json_variant_is_string(val)) + return sd_json_variant_string(val); log_debug("JSON field 'description_na' of policy for %s is not a string, ignoring.", a->id); } return a->description_na; } -static const char *access_description_good(const struct security_assessor *a, JsonVariant *policy) { - JsonVariant *val; +static const char *access_description_good(const struct security_assessor *a, sd_json_variant *policy) { + sd_json_variant *val; assert(a); val = security_assessor_find_in_policy(a, policy, "description_good"); if (val) { - if (json_variant_is_string(val)) - return json_variant_string(val); + if (sd_json_variant_is_string(val)) + return sd_json_variant_string(val); log_debug("JSON field 'description_good' of policy for %s is not a string, ignoring.", a->id); } return a->description_good; } -static const char *access_description_bad(const struct security_assessor *a, JsonVariant *policy) { - JsonVariant *val; +static const char *access_description_bad(const struct security_assessor *a, sd_json_variant *policy) { + sd_json_variant *val; assert(a); val = security_assessor_find_in_policy(a, policy, "description_bad"); if (val) { - if (json_variant_is_string(val)) - return json_variant_string(val); + if (sd_json_variant_is_string(val)) + return sd_json_variant_string(val); log_debug("JSON field 'description_bad' of policy for %s is not a string, ignoring.", a->id); } @@ -1716,9 +1716,9 @@ static int assess(const SecurityInfo *info, Table *overview_table, AnalyzeSecurityFlags flags, unsigned threshold, - JsonVariant *policy, + sd_json_variant *policy, PagerFlags pager_flags, - JsonFormatFlags json_format_flags) { + sd_json_format_flags_t json_format_flags) { static const struct { uint64_t exposure; @@ -1871,7 +1871,7 @@ static int assess(const SecurityInfo *info, return log_error_errno(r, "Failed to update cell in table: %m"); } - if (json_format_flags & JSON_FORMAT_OFF) { + if (json_format_flags & SD_JSON_FORMAT_OFF) { r = table_hide_column_from_display(details_table, (size_t) 2); if (r < 0) return log_error_errno(r, "Failed to set columns to display: %m"); @@ -1890,7 +1890,7 @@ static int assess(const SecurityInfo *info, assert(i < ELEMENTSOF(badness_table)); - if (details_table && (json_format_flags & JSON_FORMAT_OFF)) { + if (details_table && (json_format_flags & SD_JSON_FORMAT_OFF)) { _cleanup_free_ char *clickable = NULL; const char *name; @@ -2412,9 +2412,9 @@ static int analyze_security_one(sd_bus *bus, Table *overview_table, AnalyzeSecurityFlags flags, unsigned threshold, - JsonVariant *policy, + sd_json_variant *policy, PagerFlags pager_flags, - JsonFormatFlags json_format_flags) { + sd_json_format_flags_t json_format_flags) { _cleanup_(security_info_freep) SecurityInfo *info = security_info_new(); if (!info) @@ -2644,9 +2644,9 @@ static int get_security_info(Unit *u, ExecContext *c, CGroupContext *g, Security static int offline_security_check(Unit *u, unsigned threshold, - JsonVariant *policy, + sd_json_variant *policy, PagerFlags pager_flags, - JsonFormatFlags json_format_flags) { + sd_json_format_flags_t json_format_flags) { _cleanup_(table_unrefp) Table *overview_table = NULL; AnalyzeSecurityFlags flags = 0; @@ -2667,7 +2667,7 @@ static int offline_security_check(Unit *u, static int offline_security_checks( char **filenames, - JsonVariant *policy, + sd_json_variant *policy, RuntimeScope scope, bool check_man, bool run_generators, @@ -2675,7 +2675,7 @@ static int offline_security_checks( const char *root, const char *profile, PagerFlags pager_flags, - JsonFormatFlags json_format_flags) { + sd_json_format_flags_t json_format_flags) { const ManagerTestRunFlags flags = MANAGER_TEST_RUN_MINIMAL | @@ -2771,7 +2771,7 @@ static int offline_security_checks( static int analyze_security(sd_bus *bus, char **units, - JsonVariant *policy, + sd_json_variant *policy, RuntimeScope scope, bool check_man, bool run_generators, @@ -2779,7 +2779,7 @@ static int analyze_security(sd_bus *bus, unsigned threshold, const char *root, const char *profile, - JsonFormatFlags json_format_flags, + sd_json_format_flags_t json_format_flags, PagerFlags pager_flags, AnalyzeSecurityFlags flags) { @@ -2897,7 +2897,7 @@ static int analyze_security(sd_bus *bus, int verb_security(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; - _cleanup_(json_variant_unrefp) JsonVariant *policy = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *policy = NULL; int r; unsigned line, column; @@ -2910,7 +2910,7 @@ int verb_security(int argc, char *argv[], void *userdata) { pager_open(arg_pager_flags); if (arg_security_policy) { - r = json_parse_file(/*f=*/ NULL, arg_security_policy, /*flags=*/ 0, &policy, &line, &column); + r = sd_json_parse_file(/*f=*/ NULL, arg_security_policy, /*flags=*/ 0, &policy, &line, &column); if (r < 0) return log_error_errno(r, "Failed to parse '%s' at %u:%u: %m", arg_security_policy, line, column); } else { @@ -2922,7 +2922,7 @@ int verb_security(int argc, char *argv[], void *userdata) { return r; if (f) { - r = json_parse_file(f, pp, /*flags=*/ 0, &policy, &line, &column); + r = sd_json_parse_file(f, pp, /*flags=*/ 0, &policy, &line, &column); if (r < 0) return log_error_errno(r, "[%s:%u:%u] Failed to parse JSON policy: %m", pp, line, column); } diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index db3996faea..2b4babc5c9 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -109,7 +109,7 @@ unsigned arg_threshold = 100; unsigned arg_iterations = 1; usec_t arg_base_time = USEC_INFINITY; char *arg_unit = NULL; -JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF; +sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF; bool arg_quiet = false; char *arg_profile = NULL; bool arg_legend = true; @@ -566,7 +566,7 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --offline= requires one or more units to perform a security review."); - if (arg_json_format_flags != JSON_FORMAT_OFF && !STRPTR_IN_SET(argv[optind], "security", "inspect-elf", "plot", "fdstore", "pcrs", "architectures", "capability", "exit-status")) + if (arg_json_format_flags != SD_JSON_FORMAT_OFF && !STRPTR_IN_SET(argv[optind], "security", "inspect-elf", "plot", "fdstore", "pcrs", "architectures", "capability", "exit-status")) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --json= is only supported for security, inspect-elf, plot, fdstore, pcrs, architectures, capability, exit-status right now."); @@ -605,13 +605,13 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No conditions can be passed if --unit= is used."); if ((!arg_legend && !STRPTR_IN_SET(argv[optind], "plot", "architectures")) || - (streq_ptr(argv[optind], "plot") && !arg_legend && !arg_table && FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))) + (streq_ptr(argv[optind], "plot") && !arg_legend && !arg_table && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF))) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --no-legend is only supported for plot with either --table or --json=."); if (arg_table && !streq_ptr(argv[optind], "plot")) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --table is only supported for plot right now."); - if (arg_table && !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) + if (arg_table && !FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--table and --json= are mutually exclusive."); return 1; /* work to do */ diff --git a/src/analyze/analyze.h b/src/analyze/analyze.h index 8a9528c0d3..a6920b7653 100644 --- a/src/analyze/analyze.h +++ b/src/analyze/analyze.h @@ -3,9 +3,10 @@ #include <stdbool.h> +#include "sd-json.h" + #include "analyze-verify-util.h" #include "bus-util.h" -#include "json.h" #include "pager.h" #include "pretty-print.h" #include "time-util.h" @@ -35,7 +36,7 @@ extern unsigned arg_threshold; extern unsigned arg_iterations; extern usec_t arg_base_time; extern char *arg_unit; -extern JsonFormatFlags arg_json_format_flags; +extern sd_json_format_flags_t arg_json_format_flags; extern bool arg_quiet; extern char *arg_profile; extern bool arg_legend; |