mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
libsystemd: turn json.[ch] into a public API
This is preparation for making our Varlink API a public API. Since our Varlink API is built on top of our JSON API we need to make that public first (it's a nice API, but JSON APIs there are already enough, this is purely about the Varlink angle). I made most of the json.h APIs public, and just placed them in sd-json.h. Sometimes I wasn't so sure however, since the underlying data structures would have to be made public too. If in doubt I didn#t risk it, and moved the relevant API to src/libsystemd/sd-json/json-util.h instead (without any sd_* symbol prefixes). This is mostly a giant search/replace patch.
This commit is contained in:
parent
f2eb7716d0
commit
309a747fa6
@ -2056,6 +2056,7 @@ libsystemd_includes = [basic_includes, include_directories(
|
||||
'src/libsystemd/sd-hwdb',
|
||||
'src/libsystemd/sd-id128',
|
||||
'src/libsystemd/sd-journal',
|
||||
'src/libsystemd/sd-json',
|
||||
'src/libsystemd/sd-netlink',
|
||||
'src/libsystemd/sd-network',
|
||||
'src/libsystemd/sd-resolve')]
|
||||
@ -2104,6 +2105,7 @@ install_libsystemd_static = static_library(
|
||||
libdl,
|
||||
libgcrypt_cflags,
|
||||
liblz4_cflags,
|
||||
libm,
|
||||
libmount,
|
||||
libopenssl,
|
||||
librt,
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -38,9 +38,9 @@ int verb_reboot_to_firmware(int argc, char *argv[], void *userdata) {
|
||||
}
|
||||
}
|
||||
|
||||
int vl_method_set_reboot_to_firmware(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "state", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, 0, 0 },
|
||||
int vl_method_set_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "state", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, 0, 0 },
|
||||
{}
|
||||
};
|
||||
bool b;
|
||||
@ -59,10 +59,10 @@ int vl_method_set_reboot_to_firmware(Varlink *link, JsonVariant *parameters, Var
|
||||
return varlink_reply(link, NULL);
|
||||
}
|
||||
|
||||
int vl_method_get_reboot_to_firmware(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
int vl_method_get_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
int r;
|
||||
|
||||
if (json_variant_elements(parameters) > 0)
|
||||
if (sd_json_variant_elements(parameters) > 0)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
|
||||
r = efi_get_reboot_to_firmware();
|
||||
@ -71,5 +71,5 @@ int vl_method_get_reboot_to_firmware(Varlink *link, JsonVariant *parameters, Var
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return varlink_replyb(link, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BOOLEAN("state", r)));
|
||||
return varlink_replyb(link, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_BOOLEAN("state", r)));
|
||||
}
|
||||
|
@ -4,5 +4,5 @@
|
||||
|
||||
int verb_reboot_to_firmware(int argc, char *argv[], void *userdata);
|
||||
|
||||
int vl_method_set_reboot_to_firmware(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_get_reboot_to_firmware(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_set_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_get_reboot_to_firmware(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
|
@ -808,7 +808,7 @@ int verb_list(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (config.n_entries == 0 && FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
|
||||
if (config.n_entries == 0 && FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
|
||||
log_info("No boot loader entries found.");
|
||||
return 0;
|
||||
}
|
||||
@ -835,14 +835,14 @@ int verb_unlink(int argc, char *argv[], void *userdata) {
|
||||
return verb_list(argc, argv, userdata);
|
||||
}
|
||||
|
||||
int vl_method_list_boot_entries(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
|
||||
dev_t esp_devid = 0, xbootldr_devid = 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);
|
||||
|
||||
r = acquire_esp(/* unprivileged_mode= */ false,
|
||||
@ -870,15 +870,15 @@ int vl_method_list_boot_entries(Varlink *link, JsonVariant *parameters, VarlinkM
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *previous = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *previous = NULL;
|
||||
for (size_t i = 0; i < config.n_entries; i++) {
|
||||
if (previous) {
|
||||
r = varlink_notifyb(link, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_VARIANT("entry", previous)));
|
||||
r = varlink_notifyb(link, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_VARIANT("entry", previous)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
previous = json_variant_unref(previous);
|
||||
previous = sd_json_variant_unref(previous);
|
||||
}
|
||||
|
||||
r = boot_entry_to_json(&config, i, &previous);
|
||||
@ -886,6 +886,6 @@ int vl_method_list_boot_entries(Varlink *link, JsonVariant *parameters, VarlinkM
|
||||
return r;
|
||||
}
|
||||
|
||||
return varlink_replyb(link, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_CONDITION(previous, "entry", JSON_BUILD_VARIANT(previous))));
|
||||
return varlink_replyb(link, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!previous, "entry", SD_JSON_BUILD_VARIANT(previous))));
|
||||
}
|
||||
|
@ -6,4 +6,4 @@ int verb_status(int argc, char *argv[], void *userdata);
|
||||
int verb_list(int argc, char *argv[], void *userdata);
|
||||
int verb_unlink(int argc, char *argv[], void *userdata);
|
||||
|
||||
int vl_method_list_boot_entries(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_list_boot_entries(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
|
@ -47,7 +47,7 @@ sd_id128_t arg_machine_id = SD_ID128_NULL;
|
||||
char *arg_install_layout = NULL;
|
||||
BootEntryTokenType arg_entry_token_type = BOOT_ENTRY_TOKEN_AUTO;
|
||||
char *arg_entry_token = NULL;
|
||||
JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
bool arg_arch_all = false;
|
||||
char *arg_root = NULL;
|
||||
char *arg_image = NULL;
|
||||
|
@ -2,10 +2,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "sd-id128.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "boot-entry.h"
|
||||
#include "image-policy.h"
|
||||
#include "json.h"
|
||||
#include "pager.h"
|
||||
|
||||
typedef enum InstallSource {
|
||||
@ -28,7 +28,7 @@ extern sd_id128_t arg_machine_id;
|
||||
extern char *arg_install_layout;
|
||||
extern BootEntryTokenType arg_entry_token_type;
|
||||
extern char *arg_entry_token;
|
||||
extern JsonFormatFlags arg_json_format_flags;
|
||||
extern sd_json_format_flags_t arg_json_format_flags;
|
||||
extern bool arg_arch_all;
|
||||
extern char *arg_root;
|
||||
extern char *arg_image;
|
||||
|
@ -3,13 +3,14 @@
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "build.h"
|
||||
#include "efi-loader.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "main-func.h"
|
||||
#include "memstream-util.h"
|
||||
#include "openssl-util.h"
|
||||
@ -17,6 +18,7 @@
|
||||
#include "parse-util.h"
|
||||
#include "pretty-print.h"
|
||||
#include "sha256.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "tpm2-pcr.h"
|
||||
#include "tpm2-util.h"
|
||||
@ -34,7 +36,7 @@ static KeySourceType arg_private_key_source_type = OPENSSL_KEY_SOURCE_FILE;
|
||||
static char *arg_private_key_source = NULL;
|
||||
static char *arg_public_key = NULL;
|
||||
static char *arg_certificate = NULL;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO|JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO|SD_JSON_FORMAT_OFF;
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static bool arg_current = false;
|
||||
static char **arg_phase = NULL;
|
||||
@ -276,7 +278,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
case 'j':
|
||||
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
|
||||
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
|
||||
break;
|
||||
|
||||
case ARG_JSON:
|
||||
@ -676,7 +678,7 @@ static void pcr_states_restore(PcrState *pcr_states, size_t n) {
|
||||
}
|
||||
|
||||
static int verb_calculate(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
_cleanup_(pcr_state_free_all) PcrState *pcr_states = NULL;
|
||||
int r;
|
||||
|
||||
@ -713,7 +715,7 @@ static int verb_calculate(int argc, char *argv[], void *userdata) {
|
||||
return r;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (arg_json_format_flags & JSON_FORMAT_OFF) {
|
||||
if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
|
||||
_cleanup_free_ char *hd = NULL;
|
||||
|
||||
if (i == 0) {
|
||||
@ -732,20 +734,20 @@ static int verb_calculate(int argc, char *argv[], void *userdata) {
|
||||
|
||||
printf("%i:%s=%s\n", TPM2_PCR_KERNEL_BOOT, pcr_states[i].bank, hd);
|
||||
} else {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
|
||||
array = json_variant_ref(json_variant_by_key(w, pcr_states[i].bank));
|
||||
array = sd_json_variant_ref(sd_json_variant_by_key(w, pcr_states[i].bank));
|
||||
|
||||
r = json_variant_append_arrayb(
|
||||
r = sd_json_variant_append_arrayb(
|
||||
&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_CONDITION(!isempty(*phase), "phase", JSON_BUILD_STRING(*phase)),
|
||||
JSON_BUILD_PAIR("pcr", JSON_BUILD_INTEGER(TPM2_PCR_KERNEL_BOOT)),
|
||||
JSON_BUILD_PAIR("hash", JSON_BUILD_HEX(pcr_states[i].value, pcr_states[i].value_size))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!isempty(*phase), "phase", SD_JSON_BUILD_STRING(*phase)),
|
||||
SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_INTEGER(TPM2_PCR_KERNEL_BOOT)),
|
||||
SD_JSON_BUILD_PAIR("hash", SD_JSON_BUILD_HEX(pcr_states[i].value, pcr_states[i].value_size))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to append JSON object to array: %m");
|
||||
|
||||
r = json_variant_set_field(&w, pcr_states[i].bank, array);
|
||||
r = sd_json_variant_set_field(&w, pcr_states[i].bank, array);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add bank info to object: %m");
|
||||
}
|
||||
@ -755,19 +757,19 @@ static int verb_calculate(int argc, char *argv[], void *userdata) {
|
||||
pcr_states_restore(pcr_states, n);
|
||||
}
|
||||
|
||||
if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
|
||||
if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
|
||||
|
||||
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(w, arg_json_format_flags, stdout, NULL);
|
||||
sd_json_variant_dump(w, arg_json_format_flags, stdout, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int verb_sign(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(pcr_state_free_all) PcrState *pcr_states = NULL;
|
||||
_cleanup_(EVP_PKEY_freep) EVP_PKEY *privkey = NULL, *pubkey = NULL;
|
||||
_cleanup_(X509_freep) X509 *certificate = NULL;
|
||||
@ -786,17 +788,17 @@ static int verb_sign(int argc, char *argv[], void *userdata) {
|
||||
assert(!strv_isempty(arg_phase));
|
||||
|
||||
if (arg_append) {
|
||||
r = json_parse_file(NULL, arg_append, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse_file(NULL, arg_append, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse '%s': %m", arg_append);
|
||||
|
||||
if (!json_variant_is_object(v))
|
||||
if (!sd_json_variant_is_object(v))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"File '%s' is not a valid JSON object, refusing.", arg_append);
|
||||
}
|
||||
|
||||
/* When signing we only support JSON output */
|
||||
arg_json_format_flags &= ~JSON_FORMAT_OFF;
|
||||
arg_json_format_flags &= ~SD_JSON_FORMAT_OFF;
|
||||
|
||||
/* This must be done before openssl_load_key_from_token() otherwise it will get stuck */
|
||||
if (arg_certificate) {
|
||||
@ -939,28 +941,28 @@ static int verb_sign(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *a = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *a = NULL;
|
||||
r = tpm2_make_pcr_json_array(UINT64_C(1) << TPM2_PCR_KERNEL_BOOT, &a);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build JSON PCR mask array: %m");
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *bv = NULL;
|
||||
r = json_build(&bv, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("pcrs", JSON_BUILD_VARIANT(a)), /* PCR mask */
|
||||
JSON_BUILD_PAIR("pkfp", JSON_BUILD_HEX(pubkey_fp, pubkey_fp_size)), /* SHA256 fingerprint of public key (DER) used for the signature */
|
||||
JSON_BUILD_PAIR("pol", JSON_BUILD_HEX(pcr_policy_digest.buffer, pcr_policy_digest.size)), /* TPM2 policy hash that is signed */
|
||||
JSON_BUILD_PAIR("sig", JSON_BUILD_BASE64(sig, ss)))); /* signature data */
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *bv = NULL;
|
||||
r = sd_json_build(&bv, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("pcrs", SD_JSON_BUILD_VARIANT(a)), /* PCR mask */
|
||||
SD_JSON_BUILD_PAIR("pkfp", SD_JSON_BUILD_HEX(pubkey_fp, pubkey_fp_size)), /* SHA256 fingerprint of public key (DER) used for the signature */
|
||||
SD_JSON_BUILD_PAIR("pol", SD_JSON_BUILD_HEX(pcr_policy_digest.buffer, pcr_policy_digest.size)), /* TPM2 policy hash that is signed */
|
||||
SD_JSON_BUILD_PAIR("sig", SD_JSON_BUILD_BASE64(sig, ss)))); /* signature data */
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build JSON object: %m");
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *av = NULL;
|
||||
av = json_variant_ref(json_variant_by_key(v, p->bank));
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *av = NULL;
|
||||
av = sd_json_variant_ref(sd_json_variant_by_key(v, p->bank));
|
||||
|
||||
r = json_variant_append_array_nodup(&av, bv);
|
||||
r = sd_json_variant_append_array_nodup(&av, bv);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to append JSON object: %m");
|
||||
|
||||
r = json_variant_set_field(&v, p->bank, av);
|
||||
r = sd_json_variant_set_field(&v, p->bank, av);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add JSON field: %m");
|
||||
}
|
||||
@ -969,10 +971,10 @@ static int verb_sign(int argc, char *argv[], void *userdata) {
|
||||
pcr_states_restore(pcr_states, n);
|
||||
}
|
||||
|
||||
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(v, arg_json_format_flags, stdout, NULL);
|
||||
sd_json_variant_dump(v, arg_json_format_flags, stdout, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1057,7 +1059,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
|
||||
TPM2_PCR_SYSEXTS,
|
||||
};
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
int r;
|
||||
|
||||
r = validate_stub();
|
||||
@ -1088,7 +1090,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to decode PCR value '%s': %m", s);
|
||||
|
||||
if (arg_json_format_flags & JSON_FORMAT_OFF) {
|
||||
if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
|
||||
_cleanup_free_ char *f = NULL;
|
||||
|
||||
f = hexmem(h, l);
|
||||
@ -1111,35 +1113,35 @@ static int verb_status(int argc, char *argv[], void *userdata) {
|
||||
printf("%" PRIu32 ":%s=%s\n", relevant_pcrs[i], b, f);
|
||||
|
||||
} else {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *bv = NULL, *a = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *bv = NULL, *a = NULL;
|
||||
|
||||
r = json_build(&bv,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("pcr", JSON_BUILD_INTEGER(relevant_pcrs[i])),
|
||||
JSON_BUILD_PAIR("hash", JSON_BUILD_HEX(h, l))
|
||||
r = sd_json_build(&bv,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("pcr", SD_JSON_BUILD_INTEGER(relevant_pcrs[i])),
|
||||
SD_JSON_BUILD_PAIR("hash", SD_JSON_BUILD_HEX(h, l))
|
||||
)
|
||||
);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build JSON object: %m");
|
||||
|
||||
a = json_variant_ref(json_variant_by_key(v, b));
|
||||
a = sd_json_variant_ref(sd_json_variant_by_key(v, b));
|
||||
|
||||
r = json_variant_append_array(&a, bv);
|
||||
r = sd_json_variant_append_array(&a, bv);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to append PCR entry to JSON array: %m");
|
||||
|
||||
r = json_variant_set_field(&v, b, a);
|
||||
r = sd_json_variant_set_field(&v, b, a);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add bank info to object: %m");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
|
||||
if (arg_json_format_flags & (JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
|
||||
if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
|
||||
if (arg_json_format_flags & (SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
|
||||
pager_open(arg_pager_flags);
|
||||
|
||||
json_variant_dump(v, arg_json_format_flags, stdout, NULL);
|
||||
sd_json_variant_dump(v, arg_json_format_flags, stdout, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "build.h"
|
||||
@ -19,7 +20,6 @@
|
||||
#include "fileio.h"
|
||||
#include "format-table.h"
|
||||
#include "glyph-util.h"
|
||||
#include "json.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "memstream-util.h"
|
||||
@ -38,7 +38,7 @@
|
||||
#include "verbs.h"
|
||||
#include "version.h"
|
||||
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static bool arg_legend = true;
|
||||
static int arg_full = -1;
|
||||
@ -69,7 +69,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_matches, strv_freep);
|
||||
#define NAME_IS_ACQUIRED INT_TO_PTR(1)
|
||||
#define NAME_IS_ACTIVATABLE INT_TO_PTR(2)
|
||||
|
||||
static int json_transform_message(sd_bus_message *m, JsonVariant **ret);
|
||||
static int json_transform_message(sd_bus_message *m, sd_json_variant **ret);
|
||||
|
||||
static int acquire_bus(bool set_monitor, sd_bus **ret) {
|
||||
_cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
|
||||
@ -1198,7 +1198,7 @@ static int message_pcap(sd_bus_message *m, FILE *f) {
|
||||
}
|
||||
|
||||
static int message_json(sd_bus_message *m, FILE *f) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *w = NULL;
|
||||
char e[2];
|
||||
int r;
|
||||
usec_t ts;
|
||||
@ -1214,28 +1214,28 @@ static int message_json(sd_bus_message *m, FILE *f) {
|
||||
if (ts == 0)
|
||||
ts = now(CLOCK_REALTIME);
|
||||
|
||||
r = json_build(&w, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("type", JSON_BUILD_STRING(bus_message_type_to_string(m->header->type))),
|
||||
JSON_BUILD_PAIR("endian", JSON_BUILD_STRING(e)),
|
||||
JSON_BUILD_PAIR("flags", JSON_BUILD_INTEGER(m->header->flags)),
|
||||
JSON_BUILD_PAIR("version", JSON_BUILD_INTEGER(m->header->version)),
|
||||
JSON_BUILD_PAIR("cookie", JSON_BUILD_INTEGER(BUS_MESSAGE_COOKIE(m))),
|
||||
JSON_BUILD_PAIR_CONDITION(m->reply_cookie != 0, "reply_cookie", JSON_BUILD_INTEGER(m->reply_cookie)),
|
||||
JSON_BUILD_PAIR("timestamp-realtime", JSON_BUILD_UNSIGNED(ts)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->sender, "sender", JSON_BUILD_STRING(m->sender)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->destination, "destination", JSON_BUILD_STRING(m->destination)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->path, "path", JSON_BUILD_STRING(m->path)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->interface, "interface", JSON_BUILD_STRING(m->interface)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->member, "member", JSON_BUILD_STRING(m->member)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->monotonic != 0, "monotonic", JSON_BUILD_INTEGER(m->monotonic)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->realtime != 0, "realtime", JSON_BUILD_INTEGER(m->realtime)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->seqnum != 0, "seqnum", JSON_BUILD_INTEGER(m->seqnum)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->error.name, "error_name", JSON_BUILD_STRING(m->error.name)),
|
||||
JSON_BUILD_PAIR("payload", JSON_BUILD_VARIANT(v))));
|
||||
r = sd_json_build(&w, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("type", SD_JSON_BUILD_STRING(bus_message_type_to_string(m->header->type))),
|
||||
SD_JSON_BUILD_PAIR("endian", SD_JSON_BUILD_STRING(e)),
|
||||
SD_JSON_BUILD_PAIR("flags", SD_JSON_BUILD_INTEGER(m->header->flags)),
|
||||
SD_JSON_BUILD_PAIR("version", SD_JSON_BUILD_INTEGER(m->header->version)),
|
||||
SD_JSON_BUILD_PAIR("cookie", SD_JSON_BUILD_INTEGER(BUS_MESSAGE_COOKIE(m))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(m->reply_cookie != 0, "reply_cookie", SD_JSON_BUILD_INTEGER(m->reply_cookie)),
|
||||
SD_JSON_BUILD_PAIR("timestamp-realtime", SD_JSON_BUILD_UNSIGNED(ts)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!m->sender, "sender", SD_JSON_BUILD_STRING(m->sender)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!m->destination, "destination", SD_JSON_BUILD_STRING(m->destination)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!m->path, "path", SD_JSON_BUILD_STRING(m->path)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!m->interface, "interface", SD_JSON_BUILD_STRING(m->interface)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!m->member, "member", SD_JSON_BUILD_STRING(m->member)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(m->monotonic != 0, "monotonic", SD_JSON_BUILD_INTEGER(m->monotonic)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(m->realtime != 0, "realtime", SD_JSON_BUILD_INTEGER(m->realtime)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(m->seqnum != 0, "seqnum", SD_JSON_BUILD_INTEGER(m->seqnum)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!m->error.name, "error_name", SD_JSON_BUILD_STRING(m->error.name)),
|
||||
SD_JSON_BUILD_PAIR("payload", SD_JSON_BUILD_VARIANT(v))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build JSON object: %m");
|
||||
|
||||
json_variant_dump(w, arg_json_format_flags, f, NULL);
|
||||
sd_json_variant_dump(w, arg_json_format_flags, f, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1313,7 +1313,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get unique name: %m");
|
||||
|
||||
if (!arg_quiet && arg_json_format_flags == JSON_FORMAT_OFF)
|
||||
if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
|
||||
log_info("Monitoring bus message stream.");
|
||||
|
||||
(void) sd_notify(/* unset_environment=false */ false, "READY=1");
|
||||
@ -1347,7 +1347,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
|
||||
fflush(stdout);
|
||||
|
||||
if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected") > 0) {
|
||||
if (!arg_quiet && arg_json_format_flags == JSON_FORMAT_OFF)
|
||||
if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF)
|
||||
log_info("Connection terminated, exiting.");
|
||||
return 0;
|
||||
}
|
||||
@ -1365,7 +1365,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f
|
||||
}
|
||||
|
||||
static int verb_monitor(int argc, char **argv, void *userdata) {
|
||||
return monitor(argc, argv, (arg_json_format_flags & JSON_FORMAT_OFF) ? message_dump : message_json);
|
||||
return monitor(argc, argv, (arg_json_format_flags & SD_JSON_FORMAT_OFF) ? message_dump : message_json);
|
||||
}
|
||||
|
||||
static int verb_capture(int argc, char **argv, void *userdata) {
|
||||
@ -1681,10 +1681,10 @@ static int message_append_cmdline(sd_bus_message *m, const char *signature, char
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int json_transform_one(sd_bus_message *m, JsonVariant **ret);
|
||||
static int json_transform_one(sd_bus_message *m, sd_json_variant **ret);
|
||||
|
||||
static int json_transform_and_append(sd_bus_message *m, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *element = NULL;
|
||||
static int json_transform_and_append(sd_bus_message *m, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *element = NULL;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -1694,11 +1694,11 @@ static int json_transform_and_append(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return json_variant_append_array(ret, element);
|
||||
return sd_json_variant_append_array(ret, element);
|
||||
}
|
||||
|
||||
static int json_transform_array_or_struct(sd_bus_message *m, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int json_transform_array_or_struct(sd_bus_message *m, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -1717,14 +1717,14 @@ static int json_transform_array_or_struct(sd_bus_message *m, JsonVariant **ret)
|
||||
}
|
||||
|
||||
if (!array)
|
||||
return json_variant_new_array(ret, NULL, 0);
|
||||
return sd_json_variant_new_array(ret, NULL, 0);
|
||||
|
||||
*ret = TAKE_PTR(array);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int json_transform_variant(sd_bus_message *m, const char *contents, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *value = NULL;
|
||||
static int json_transform_variant(sd_bus_message *m, const char *contents, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *value = NULL;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -1735,23 +1735,23 @@ static int json_transform_variant(sd_bus_message *m, const char *contents, JsonV
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_build(ret, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("type", JSON_BUILD_STRING(contents)),
|
||||
JSON_BUILD_PAIR("data", JSON_BUILD_VARIANT(value))));
|
||||
r = sd_json_build(ret, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("type", SD_JSON_BUILD_STRING(contents)),
|
||||
SD_JSON_BUILD_PAIR("data", SD_JSON_BUILD_VARIANT(value))));
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int json_transform_dict_array(sd_bus_message *m, JsonVariant **ret) {
|
||||
JsonVariant **elements = NULL;
|
||||
static int json_transform_dict_array(sd_bus_message *m, sd_json_variant **ret) {
|
||||
sd_json_variant **elements = NULL;
|
||||
size_t n_elements = 0;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(ret);
|
||||
|
||||
CLEANUP_ARRAY(elements, n_elements, json_variant_unref_many);
|
||||
CLEANUP_ARRAY(elements, n_elements, sd_json_variant_unref_many);
|
||||
|
||||
for (;;) {
|
||||
const char *contents;
|
||||
@ -1793,11 +1793,11 @@ static int json_transform_dict_array(sd_bus_message *m, JsonVariant **ret) {
|
||||
return bus_log_parse_error(r);
|
||||
}
|
||||
|
||||
return json_variant_new_object(ret, elements, n_elements);
|
||||
return sd_json_variant_new_object(ret, elements, n_elements);
|
||||
}
|
||||
|
||||
static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
static int json_transform_one(sd_bus_message *m, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
const char *contents;
|
||||
char type;
|
||||
int r;
|
||||
@ -1818,7 +1818,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_unsigned(&v, b);
|
||||
r = sd_json_variant_new_unsigned(&v, b);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform byte: %m");
|
||||
|
||||
@ -1832,7 +1832,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_boolean(&v, b);
|
||||
r = sd_json_variant_new_boolean(&v, b);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform boolean: %m");
|
||||
|
||||
@ -1846,7 +1846,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_integer(&v, b);
|
||||
r = sd_json_variant_new_integer(&v, b);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform int16: %m");
|
||||
|
||||
@ -1860,7 +1860,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_unsigned(&v, b);
|
||||
r = sd_json_variant_new_unsigned(&v, b);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform uint16: %m");
|
||||
|
||||
@ -1874,7 +1874,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_integer(&v, b);
|
||||
r = sd_json_variant_new_integer(&v, b);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform int32: %m");
|
||||
|
||||
@ -1888,7 +1888,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_unsigned(&v, b);
|
||||
r = sd_json_variant_new_unsigned(&v, b);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform uint32: %m");
|
||||
|
||||
@ -1902,7 +1902,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_integer(&v, b);
|
||||
r = sd_json_variant_new_integer(&v, b);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform int64: %m");
|
||||
|
||||
@ -1916,7 +1916,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_unsigned(&v, b);
|
||||
r = sd_json_variant_new_unsigned(&v, b);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform uint64: %m");
|
||||
|
||||
@ -1930,7 +1930,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_real(&v, d);
|
||||
r = sd_json_variant_new_real(&v, d);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform double: %m");
|
||||
|
||||
@ -1946,7 +1946,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_string(&v, s);
|
||||
r = sd_json_variant_new_string(&v, s);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform double: %m");
|
||||
|
||||
@ -1958,7 +1958,7 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_variant_new_null(&v);
|
||||
r = sd_json_variant_new_null(&v);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to transform fd: %m");
|
||||
|
||||
@ -1994,8 +1994,8 @@ static int json_transform_one(sd_bus_message *m, JsonVariant **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int json_transform_message(sd_bus_message *m, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
static int json_transform_message(sd_bus_message *m, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
const char *type;
|
||||
int r;
|
||||
|
||||
@ -2008,8 +2008,8 @@ static int json_transform_message(sd_bus_message *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_build(ret, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("type", JSON_BUILD_STRING(type)),
|
||||
JSON_BUILD_PAIR("data", JSON_BUILD_VARIANT(v))));
|
||||
r = sd_json_build(ret, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("type", SD_JSON_BUILD_STRING(type)),
|
||||
SD_JSON_BUILD_PAIR("data", SD_JSON_BUILD_VARIANT(v))));
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
@ -2083,17 +2083,17 @@ static int call(int argc, char **argv, void *userdata) {
|
||||
|
||||
if (r == 0 && !arg_quiet) {
|
||||
|
||||
if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
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);
|
||||
|
||||
r = json_transform_message(reply, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
sd_json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
|
||||
} else if (arg_verbose) {
|
||||
pager_open(arg_pager_flags);
|
||||
@ -2191,17 +2191,17 @@ static int get_property(int argc, char **argv, void *userdata) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
if (!FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF)) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
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);
|
||||
|
||||
r = json_transform_variant(reply, contents, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
sd_json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
|
||||
} else if (arg_verbose) {
|
||||
pager_open(arg_pager_flags);
|
||||
@ -2558,7 +2558,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
|
||||
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
|
||||
break;
|
||||
|
||||
case ARG_JSON:
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "core-varlink.h"
|
||||
#include "json-util.h"
|
||||
#include "mkdir-label.h"
|
||||
#include "strv.h"
|
||||
#include "user-util.h"
|
||||
@ -23,22 +24,22 @@ static const char* const managed_oom_mode_properties[] = {
|
||||
"ManagedOOMMemoryPressure",
|
||||
};
|
||||
|
||||
static int build_user_json(const char *user_name, uid_t uid, JsonVariant **ret) {
|
||||
static int build_user_json(const char *user_name, uid_t uid, sd_json_variant **ret) {
|
||||
assert(user_name);
|
||||
assert(uid_is_valid(uid));
|
||||
assert(ret);
|
||||
|
||||
return json_build(ret, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("record", JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(user_name)),
|
||||
JSON_BUILD_PAIR("uid", JSON_BUILD_UNSIGNED(uid)),
|
||||
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(uid)),
|
||||
JSON_BUILD_PAIR("realName", JSON_BUILD_CONST_STRING("Dynamic User")),
|
||||
JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_CONST_STRING("/")),
|
||||
JSON_BUILD_PAIR("shell", JSON_BUILD_CONST_STRING(NOLOGIN)),
|
||||
JSON_BUILD_PAIR("locked", JSON_BUILD_BOOLEAN(true)),
|
||||
JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.DynamicUser")),
|
||||
JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("dynamic"))))));
|
||||
return sd_json_build(ret, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(user_name)),
|
||||
SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(uid)),
|
||||
SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(uid)),
|
||||
SD_JSON_BUILD_PAIR("realName", JSON_BUILD_CONST_STRING("Dynamic User")),
|
||||
SD_JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_CONST_STRING("/")),
|
||||
SD_JSON_BUILD_PAIR("shell", JSON_BUILD_CONST_STRING(NOLOGIN)),
|
||||
SD_JSON_BUILD_PAIR("locked", SD_JSON_BUILD_BOOLEAN(true)),
|
||||
SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.DynamicUser")),
|
||||
SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("dynamic"))))));
|
||||
}
|
||||
|
||||
static bool user_match_lookup_parameters(LookupParameters *p, const char *name, uid_t uid) {
|
||||
@ -53,7 +54,7 @@ static bool user_match_lookup_parameters(LookupParameters *p, const char *name,
|
||||
return true;
|
||||
}
|
||||
|
||||
static int build_managed_oom_json_array_element(Unit *u, const char *property, JsonVariant **ret_v) {
|
||||
static int build_managed_oom_json_array_element(Unit *u, const char *property, sd_json_variant **ret_v) {
|
||||
bool use_limit = false;
|
||||
CGroupContext *c;
|
||||
const char *mode;
|
||||
@ -85,15 +86,15 @@ static int build_managed_oom_json_array_element(Unit *u, const char *property, J
|
||||
} else
|
||||
return -EINVAL;
|
||||
|
||||
return json_build(ret_v, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("mode", JSON_BUILD_STRING(mode)),
|
||||
JSON_BUILD_PAIR("path", JSON_BUILD_STRING(crt->cgroup_path)),
|
||||
JSON_BUILD_PAIR("property", JSON_BUILD_STRING(property)),
|
||||
JSON_BUILD_PAIR_CONDITION(use_limit, "limit", JSON_BUILD_UNSIGNED(c->moom_mem_pressure_limit))));
|
||||
return sd_json_build(ret_v, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("mode", SD_JSON_BUILD_STRING(mode)),
|
||||
SD_JSON_BUILD_PAIR("path", SD_JSON_BUILD_STRING(crt->cgroup_path)),
|
||||
SD_JSON_BUILD_PAIR("property", SD_JSON_BUILD_STRING(property)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(use_limit, "limit", SD_JSON_BUILD_UNSIGNED(c->moom_mem_pressure_limit))));
|
||||
}
|
||||
|
||||
int manager_varlink_send_managed_oom_update(Unit *u) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *arr = NULL, *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *arr = NULL, *v = NULL;
|
||||
CGroupRuntime *crt;
|
||||
CGroupContext *c;
|
||||
int r;
|
||||
@ -124,23 +125,23 @@ int manager_varlink_send_managed_oom_update(Unit *u) {
|
||||
if (!c)
|
||||
return 0;
|
||||
|
||||
r = json_build(&arr, JSON_BUILD_EMPTY_ARRAY);
|
||||
r = sd_json_build(&arr, SD_JSON_BUILD_EMPTY_ARRAY);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
FOREACH_ELEMENT(i, managed_oom_mode_properties) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *e = NULL;
|
||||
|
||||
r = build_managed_oom_json_array_element(u, *i, &e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_append_array(&arr, e);
|
||||
r = sd_json_variant_append_array(&arr, e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = json_build(&v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("cgroups", JSON_BUILD_VARIANT(arr))));
|
||||
r = sd_json_build(&v, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("cgroups", SD_JSON_BUILD_VARIANT(arr))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -156,14 +157,14 @@ int manager_varlink_send_managed_oom_update(Unit *u) {
|
||||
return r;
|
||||
}
|
||||
|
||||
static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *arr = NULL;
|
||||
static int build_managed_oom_cgroups_json(Manager *m, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *arr = NULL;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(ret);
|
||||
|
||||
r = json_build(&arr, JSON_BUILD_EMPTY_ARRAY);
|
||||
r = sd_json_build(&arr, SD_JSON_BUILD_EMPTY_ARRAY);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -183,7 +184,7 @@ static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) {
|
||||
continue;
|
||||
|
||||
FOREACH_ELEMENT(i, managed_oom_mode_properties) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *e = NULL;
|
||||
|
||||
/* For the initial varlink call we only care about units that enabled (i.e. mode is not
|
||||
* set to "auto") oomd properties. */
|
||||
@ -195,14 +196,14 @@ static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_append_array(&arr, e);
|
||||
r = sd_json_variant_append_array(&arr, e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r = json_build(&v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("cgroups", JSON_BUILD_VARIANT(arr))));
|
||||
r = sd_json_build(&v, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("cgroups", SD_JSON_BUILD_VARIANT(arr))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -212,11 +213,11 @@ static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) {
|
||||
|
||||
static int vl_method_subscribe_managed_oom_cgroups(
|
||||
Varlink *link,
|
||||
JsonVariant *parameters,
|
||||
sd_json_variant *parameters,
|
||||
VarlinkMethodFlags flags,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
pid_t pid;
|
||||
Unit *u;
|
||||
@ -237,7 +238,7 @@ static int vl_method_subscribe_managed_oom_cgroups(
|
||||
if (!streq(u->id, "systemd-oomd.service"))
|
||||
return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, NULL);
|
||||
|
||||
if (json_variant_elements(parameters) > 0)
|
||||
if (sd_json_variant_elements(parameters) > 0)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
|
||||
/* We only take one subscriber for this method so return an error if there's already an existing one.
|
||||
@ -258,7 +259,7 @@ static int vl_method_subscribe_managed_oom_cgroups(
|
||||
}
|
||||
|
||||
static int manager_varlink_send_managed_oom_initial(Manager *m) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -275,16 +276,16 @@ static int manager_varlink_send_managed_oom_initial(Manager *m) {
|
||||
return varlink_send(m->managed_oom_varlink, "io.systemd.oom.ReportManagedOOMCGroups", v);
|
||||
}
|
||||
|
||||
static int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "uid", JSON_VARIANT_UNSIGNED, json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 },
|
||||
{ "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 },
|
||||
{ "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
LookupParameters p = {
|
||||
.uid = UID_INVALID,
|
||||
};
|
||||
@ -325,7 +326,7 @@ static int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, Var
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = json_variant_unref(v);
|
||||
v = sd_json_variant_unref(v);
|
||||
}
|
||||
|
||||
r = build_user_json(d->name, uid, &v);
|
||||
@ -356,18 +357,18 @@ static int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, Var
|
||||
return varlink_reply(link, v);
|
||||
}
|
||||
|
||||
static int build_group_json(const char *group_name, gid_t gid, JsonVariant **ret) {
|
||||
static int build_group_json(const char *group_name, gid_t gid, sd_json_variant **ret) {
|
||||
assert(group_name);
|
||||
assert(gid_is_valid(gid));
|
||||
assert(ret);
|
||||
|
||||
return json_build(ret, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("record", JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(group_name)),
|
||||
JSON_BUILD_PAIR("description", JSON_BUILD_CONST_STRING("Dynamic Group")),
|
||||
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(gid)),
|
||||
JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.DynamicUser")),
|
||||
JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("dynamic"))))));
|
||||
return sd_json_build(ret, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(group_name)),
|
||||
SD_JSON_BUILD_PAIR("description", JSON_BUILD_CONST_STRING("Dynamic Group")),
|
||||
SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(gid)),
|
||||
SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.DynamicUser")),
|
||||
SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("dynamic"))))));
|
||||
}
|
||||
|
||||
static bool group_match_lookup_parameters(LookupParameters *p, const char *name, gid_t gid) {
|
||||
@ -382,16 +383,16 @@ static bool group_match_lookup_parameters(LookupParameters *p, const char *name,
|
||||
return true;
|
||||
}
|
||||
|
||||
static int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "gid", JSON_VARIANT_UNSIGNED, json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 },
|
||||
{ "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 },
|
||||
{ "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
LookupParameters p = {
|
||||
.gid = GID_INVALID,
|
||||
};
|
||||
@ -434,7 +435,7 @@ static int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, Va
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = json_variant_unref(v);
|
||||
v = sd_json_variant_unref(v);
|
||||
}
|
||||
|
||||
r = build_group_json(d->name, (gid_t) uid, &v);
|
||||
@ -465,12 +466,12 @@ static int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, Va
|
||||
return varlink_reply(link, v);
|
||||
}
|
||||
|
||||
static int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), JSON_SAFE },
|
||||
{ "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_SAFE },
|
||||
{ "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -581,7 +582,7 @@ static int manager_varlink_init_system(Manager *m) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int vl_reply(Varlink *link, JsonVariant *parameters, const char *error_id, VarlinkReplyFlags flags, void *userdata) {
|
||||
static int vl_reply(Varlink *link, sd_json_variant *parameters, const char *error_id, VarlinkReplyFlags flags, void *userdata) {
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-journal.h"
|
||||
#include "sd-json.h"
|
||||
#include "sd-login.h"
|
||||
#include "sd-messages.h"
|
||||
|
||||
@ -32,6 +33,7 @@
|
||||
#include "iovec-util.h"
|
||||
#include "journal-importer.h"
|
||||
#include "journal-send.h"
|
||||
#include "json-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "main-func.h"
|
||||
@ -773,14 +775,14 @@ static int submit_coredump(
|
||||
struct iovec_wrapper *iovw,
|
||||
int input_fd) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *json_metadata = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *json_metadata = NULL;
|
||||
_cleanup_close_ int coredump_fd = -EBADF, coredump_node_fd = -EBADF;
|
||||
_cleanup_free_ char *filename = NULL, *coredump_data = NULL;
|
||||
_cleanup_free_ char *stacktrace = NULL;
|
||||
const char *module_name;
|
||||
uint64_t coredump_size = UINT64_MAX, coredump_compressed_size = UINT64_MAX;
|
||||
bool truncated = false, written = false;
|
||||
JsonVariant *module_json;
|
||||
sd_json_variant *module_json;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
@ -870,7 +872,7 @@ static int submit_coredump(
|
||||
if (json_metadata) {
|
||||
_cleanup_free_ char *formatted_json = NULL;
|
||||
|
||||
r = json_variant_format(json_metadata, 0, &formatted_json);
|
||||
r = sd_json_variant_format(json_metadata, 0, &formatted_json);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format JSON package metadata: %m");
|
||||
|
||||
@ -881,19 +883,19 @@ static int submit_coredump(
|
||||
* let's avoid guessing the module name and skip the loop. */
|
||||
if (context->meta[META_EXE])
|
||||
JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, json_metadata) {
|
||||
JsonVariant *t;
|
||||
sd_json_variant *t;
|
||||
|
||||
/* We only add structured fields for the 'main' ELF module, and only if we can identify it. */
|
||||
if (!path_equal_filename(module_name, context->meta[META_EXE]))
|
||||
continue;
|
||||
|
||||
t = json_variant_by_key(module_json, "name");
|
||||
t = sd_json_variant_by_key(module_json, "name");
|
||||
if (t)
|
||||
(void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_NAME=", json_variant_string(t));
|
||||
(void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_NAME=", sd_json_variant_string(t));
|
||||
|
||||
t = json_variant_by_key(module_json, "version");
|
||||
t = sd_json_variant_by_key(module_json, "version");
|
||||
if (t)
|
||||
(void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_VERSION=", json_variant_string(t));
|
||||
(void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_VERSION=", sd_json_variant_string(t));
|
||||
}
|
||||
|
||||
/* Optionally store the entire coredump in the journal */
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-journal.h"
|
||||
#include "sd-json.h"
|
||||
#include "sd-messages.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
@ -26,6 +27,7 @@
|
||||
#include "glob-util.h"
|
||||
#include "journal-internal.h"
|
||||
#include "journal-util.h"
|
||||
#include "json-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "main-func.h"
|
||||
@ -56,7 +58,7 @@ static const char *arg_directory = NULL;
|
||||
static char *arg_root = NULL;
|
||||
static char *arg_image = NULL;
|
||||
static char **arg_file = NULL;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static int arg_legend = true;
|
||||
static size_t arg_rows_max = SIZE_MAX;
|
||||
@ -804,26 +806,26 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
/* Print out the build-id of the 'main' ELF module, by matching the JSON key
|
||||
* with the 'exe' field. */
|
||||
if (exe && pkgmeta_json) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
r = json_parse(pkgmeta_json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(pkgmeta_json, 0, &v, NULL, NULL);
|
||||
if (r < 0) {
|
||||
_cleanup_free_ char *esc = cescape(pkgmeta_json);
|
||||
log_warning_errno(r, "json_parse on \"%s\" failed, ignoring: %m", strnull(esc));
|
||||
} else {
|
||||
const char *module_name;
|
||||
JsonVariant *module_json;
|
||||
sd_json_variant *module_json;
|
||||
|
||||
JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, v) {
|
||||
JsonVariant *build_id;
|
||||
sd_json_variant *build_id;
|
||||
|
||||
/* We only print the build-id for the 'main' ELF module */
|
||||
if (!path_equal_filename(module_name, exe))
|
||||
continue;
|
||||
|
||||
build_id = json_variant_by_key(module_json, "buildId");
|
||||
build_id = sd_json_variant_by_key(module_json, "buildId");
|
||||
if (build_id)
|
||||
fprintf(file, " build-id: %s\n", json_variant_string(build_id));
|
||||
fprintf(file, " build-id: %s\n", sd_json_variant_string(build_id));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "build.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "creds-util.h"
|
||||
@ -12,7 +14,7 @@
|
||||
#include "format-table.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "io-util.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "libmount-util.h"
|
||||
#include "main-func.h"
|
||||
#include "memory-util.h"
|
||||
@ -41,7 +43,7 @@ typedef enum TranscodeMode {
|
||||
_TRANSCODE_INVALID = -EINVAL,
|
||||
} TranscodeMode;
|
||||
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static bool arg_legend = true;
|
||||
static bool arg_system = false;
|
||||
@ -271,7 +273,7 @@ static int verb_list(int argc, char **argv, void *userdata) {
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENXIO), "No credentials passed. (i.e. $CREDENTIALS_DIRECTORY not set.)");
|
||||
}
|
||||
|
||||
if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF) && table_isempty(t)) {
|
||||
if (FLAGS_SET(arg_json_format_flags, SD_JSON_FORMAT_OFF) && table_isempty(t)) {
|
||||
log_info("No credentials");
|
||||
return 0;
|
||||
}
|
||||
@ -368,19 +370,19 @@ static int write_blob(FILE *f, const void *data, size_t size) {
|
||||
int r;
|
||||
|
||||
if (arg_transcode == TRANSCODE_OFF &&
|
||||
arg_json_format_flags != JSON_FORMAT_OFF) {
|
||||
arg_json_format_flags != SD_JSON_FORMAT_OFF) {
|
||||
_cleanup_(erase_and_freep) char *suffixed = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
r = make_cstring(data, size, MAKE_CSTRING_REFUSE_TRAILING_NUL, &suffixed);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Unable to convert binary string to C string: %m");
|
||||
|
||||
r = json_parse(suffixed, JSON_PARSE_SENSITIVE, &v, NULL, NULL);
|
||||
r = sd_json_parse(suffixed, SD_JSON_PARSE_SENSITIVE, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse JSON: %m");
|
||||
|
||||
json_variant_dump(v, arg_json_format_flags, f, NULL);
|
||||
sd_json_variant_dump(v, arg_json_format_flags, f, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1167,16 +1169,16 @@ static int settle_scope(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vl_method_encrypt(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_encrypt(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "name", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(MethodEncryptParameters, name), 0 },
|
||||
{ "text", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(MethodEncryptParameters, text), 0 },
|
||||
{ "data", JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, offsetof(MethodEncryptParameters, data), 0 },
|
||||
{ "timestamp", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(MethodEncryptParameters, timestamp), 0 },
|
||||
{ "notAfter", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(MethodEncryptParameters, not_after), 0 },
|
||||
{ "scope", JSON_VARIANT_STRING, dispatch_credential_scope, offsetof(MethodEncryptParameters, scope), 0 },
|
||||
{ "uid", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uid_gid, offsetof(MethodEncryptParameters, uid), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MethodEncryptParameters, name), 0 },
|
||||
{ "text", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MethodEncryptParameters, text), 0 },
|
||||
{ "data", SD_JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, offsetof(MethodEncryptParameters, data), 0 },
|
||||
{ "timestamp", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(MethodEncryptParameters, timestamp), 0 },
|
||||
{ "notAfter", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(MethodEncryptParameters, not_after), 0 },
|
||||
{ "scope", SD_JSON_VARIANT_STRING, dispatch_credential_scope, offsetof(MethodEncryptParameters, scope), 0 },
|
||||
{ "uid", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uid_gid, offsetof(MethodEncryptParameters, uid), 0 },
|
||||
VARLINK_DISPATCH_POLKIT_FIELD,
|
||||
{}
|
||||
};
|
||||
@ -1253,14 +1255,14 @@ static int vl_method_encrypt(Varlink *link, JsonVariant *parameters, VarlinkMeth
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *reply = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *reply = NULL;
|
||||
|
||||
r = json_build(&reply, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_IOVEC_BASE64("blob", &output)));
|
||||
r = sd_json_build(&reply, SD_JSON_BUILD_OBJECT(JSON_BUILD_PAIR_IOVEC_BASE64("blob", &output)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* Let's also mark the (theoretically encrypted) reply as sensitive, in case the NULL encryption scheme was used. */
|
||||
json_variant_sensitive(reply);
|
||||
sd_json_variant_sensitive(reply);
|
||||
|
||||
return varlink_reply(link, reply);
|
||||
}
|
||||
@ -1279,14 +1281,14 @@ static void method_decrypt_parameters_done(MethodDecryptParameters *p) {
|
||||
iovec_done_erase(&p->blob);
|
||||
}
|
||||
|
||||
static int vl_method_decrypt(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_decrypt(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "name", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(MethodDecryptParameters, name), 0 },
|
||||
{ "blob", JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, offsetof(MethodDecryptParameters, blob), JSON_MANDATORY },
|
||||
{ "timestamp", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(MethodDecryptParameters, timestamp), 0 },
|
||||
{ "scope", JSON_VARIANT_STRING, dispatch_credential_scope, offsetof(MethodDecryptParameters, scope), 0 },
|
||||
{ "uid", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uid_gid, offsetof(MethodDecryptParameters, uid), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(MethodDecryptParameters, name), 0 },
|
||||
{ "blob", SD_JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, offsetof(MethodDecryptParameters, blob), SD_JSON_MANDATORY },
|
||||
{ "timestamp", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(MethodDecryptParameters, timestamp), 0 },
|
||||
{ "scope", SD_JSON_VARIANT_STRING, dispatch_credential_scope, offsetof(MethodDecryptParameters, scope), 0 },
|
||||
{ "uid", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uid_gid, offsetof(MethodDecryptParameters, uid), 0 },
|
||||
VARLINK_DISPATCH_POLKIT_FIELD,
|
||||
{}
|
||||
};
|
||||
@ -1373,13 +1375,13 @@ static int vl_method_decrypt(Varlink *link, JsonVariant *parameters, VarlinkMeth
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *reply = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *reply = NULL;
|
||||
|
||||
r = json_build(&reply, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_IOVEC_BASE64("data", &output)));
|
||||
r = sd_json_build(&reply, SD_JSON_BUILD_OBJECT(JSON_BUILD_PAIR_IOVEC_BASE64("data", &output)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_sensitive(reply);
|
||||
sd_json_variant_sensitive(reply);
|
||||
|
||||
return varlink_reply(link, reply);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "cryptenroll-fido2.h"
|
||||
#include "cryptsetup-fido2.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "libfido2-util.h"
|
||||
#include "memory-util.h"
|
||||
#include "random-util.h"
|
||||
@ -71,7 +71,7 @@ int enroll_fido2(
|
||||
|
||||
_cleanup_(erase_and_freep) void *salt = NULL, *secret = NULL;
|
||||
_cleanup_(erase_and_freep) char *base64_encoded = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *keyslot_as_string = NULL;
|
||||
size_t cid_size, salt_size, secret_size;
|
||||
_cleanup_free_ void *cid = NULL;
|
||||
@ -130,16 +130,16 @@ int enroll_fido2(
|
||||
if (asprintf(&keyslot_as_string, "%i", keyslot) < 0)
|
||||
return log_oom();
|
||||
|
||||
r = json_build(&v,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("systemd-fido2")),
|
||||
JSON_BUILD_PAIR("keyslots", JSON_BUILD_ARRAY(JSON_BUILD_STRING(keyslot_as_string))),
|
||||
JSON_BUILD_PAIR("fido2-credential", JSON_BUILD_BASE64(cid, cid_size)),
|
||||
JSON_BUILD_PAIR("fido2-salt", JSON_BUILD_BASE64(salt, salt_size)),
|
||||
JSON_BUILD_PAIR("fido2-rp", JSON_BUILD_CONST_STRING("io.systemd.cryptsetup")),
|
||||
JSON_BUILD_PAIR("fido2-clientPin-required", JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_PIN))),
|
||||
JSON_BUILD_PAIR("fido2-up-required", JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_UP))),
|
||||
JSON_BUILD_PAIR("fido2-uv-required", JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_UV)))));
|
||||
r = sd_json_build(&v,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("systemd-fido2")),
|
||||
SD_JSON_BUILD_PAIR("keyslots", SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_STRING(keyslot_as_string))),
|
||||
SD_JSON_BUILD_PAIR("fido2-credential", SD_JSON_BUILD_BASE64(cid, cid_size)),
|
||||
SD_JSON_BUILD_PAIR("fido2-salt", SD_JSON_BUILD_BASE64(salt, salt_size)),
|
||||
SD_JSON_BUILD_PAIR("fido2-rp", JSON_BUILD_CONST_STRING("io.systemd.cryptsetup")),
|
||||
SD_JSON_BUILD_PAIR("fido2-clientPin-required", SD_JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_PIN))),
|
||||
SD_JSON_BUILD_PAIR("fido2-up-required", SD_JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_UP))),
|
||||
SD_JSON_BUILD_PAIR("fido2-uv-required", SD_JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_UV)))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to prepare FIDO2 JSON token object: %m");
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "cryptenroll-list.h"
|
||||
#include "cryptenroll.h"
|
||||
#include "format-table.h"
|
||||
#include "json-util.h"
|
||||
#include "parse-util.h"
|
||||
|
||||
struct keyslot_metadata {
|
||||
@ -39,9 +42,9 @@ int list_enrolled(struct crypt_device *cd) {
|
||||
/* Second step, enumerate through all tokens, and update the slot table, indicating what kind of
|
||||
* token they are assigned to */
|
||||
for (int token = 0; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
const char *type;
|
||||
JsonVariant *w, *z;
|
||||
sd_json_variant *w, *z;
|
||||
EnrollType et;
|
||||
|
||||
r = cryptsetup_get_token_as_json(cd, token, NULL, &v);
|
||||
@ -52,20 +55,20 @@ int list_enrolled(struct crypt_device *cd) {
|
||||
continue;
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "type");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "type");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
log_warning("Token JSON data lacks type field, ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
et = luks2_token_type_from_string(json_variant_string(w));
|
||||
et = luks2_token_type_from_string(sd_json_variant_string(w));
|
||||
if (et < 0)
|
||||
type = "other";
|
||||
else
|
||||
type = enroll_type_to_string(et);
|
||||
|
||||
w = json_variant_by_key(v, "keyslots");
|
||||
if (!w || !json_variant_is_array(w)) {
|
||||
w = sd_json_variant_by_key(v, "keyslots");
|
||||
if (!w || !sd_json_variant_is_array(w)) {
|
||||
log_warning("Token JSON data lacks keyslots field, ignoring.");
|
||||
continue;
|
||||
}
|
||||
@ -73,12 +76,12 @@ int list_enrolled(struct crypt_device *cd) {
|
||||
JSON_VARIANT_ARRAY_FOREACH(z, w) {
|
||||
unsigned u;
|
||||
|
||||
if (!json_variant_is_string(z)) {
|
||||
if (!sd_json_variant_is_string(z)) {
|
||||
log_warning("Token JSON data's keyslot field is not an array of strings, ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
r = safe_atou(json_variant_string(z), &u);
|
||||
r = safe_atou(sd_json_variant_string(z), &u);
|
||||
if (r < 0) {
|
||||
log_warning_errno(r, "Token JSON data's keyslot field is not an integer formatted as string, ignoring.");
|
||||
continue;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "cryptenroll-pkcs11.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "memory-util.h"
|
||||
#include "openssl-util.h"
|
||||
#include "pkcs11-util.h"
|
||||
@ -39,7 +39,7 @@ int enroll_pkcs11(
|
||||
|
||||
_cleanup_(erase_and_freep) void *decrypted_key = NULL;
|
||||
_cleanup_(erase_and_freep) char *base64_encoded = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *keyslot_as_string = NULL, *private_uri = NULL;
|
||||
size_t decrypted_key_size, saved_key_size;
|
||||
_cleanup_free_ void *saved_key = NULL;
|
||||
@ -100,12 +100,12 @@ int enroll_pkcs11(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_build(&v,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("systemd-pkcs11")),
|
||||
JSON_BUILD_PAIR("keyslots", JSON_BUILD_ARRAY(JSON_BUILD_STRING(keyslot_as_string))),
|
||||
JSON_BUILD_PAIR("pkcs11-uri", JSON_BUILD_STRING(private_uri ?: uri)),
|
||||
JSON_BUILD_PAIR("pkcs11-key", JSON_BUILD_BASE64(saved_key, saved_key_size))));
|
||||
r = sd_json_build(&v,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("systemd-pkcs11")),
|
||||
SD_JSON_BUILD_PAIR("keyslots", SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_STRING(keyslot_as_string))),
|
||||
SD_JSON_BUILD_PAIR("pkcs11-uri", SD_JSON_BUILD_STRING(private_uri ?: uri)),
|
||||
SD_JSON_BUILD_PAIR("pkcs11-key", SD_JSON_BUILD_BASE64(saved_key, saved_key_size))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to prepare PKCS#11 JSON token object: %m");
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "cryptenroll-recovery.h"
|
||||
#include "glyph-util.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "memory-util.h"
|
||||
#include "qrcode-util.h"
|
||||
#include "recovery-key.h"
|
||||
@ -13,7 +13,7 @@ int enroll_recovery(
|
||||
const void *volume_key,
|
||||
size_t volume_key_size) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(erase_and_freep) char *password = NULL;
|
||||
_cleanup_free_ char *keyslot_as_string = NULL;
|
||||
int keyslot, r, q;
|
||||
@ -74,10 +74,10 @@ int enroll_recovery(
|
||||
goto rollback;
|
||||
}
|
||||
|
||||
r = json_build(&v,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("systemd-recovery")),
|
||||
JSON_BUILD_PAIR("keyslots", JSON_BUILD_ARRAY(JSON_BUILD_STRING(keyslot_as_string)))));
|
||||
r = sd_json_build(&v,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("systemd-recovery")),
|
||||
SD_JSON_BUILD_PAIR("keyslots", SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_STRING(keyslot_as_string)))));
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to prepare recovery key JSON token object: %m");
|
||||
goto rollback;
|
||||
|
@ -1,5 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "ask-password-api.h"
|
||||
#include "cryptenroll-tpm2.h"
|
||||
@ -8,7 +10,6 @@
|
||||
#include "errno-util.h"
|
||||
#include "fileio.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "log.h"
|
||||
#include "memory-util.h"
|
||||
#include "random-util.h"
|
||||
@ -29,11 +30,11 @@ static int search_policy_hash(
|
||||
return 0;
|
||||
|
||||
for (int token = 0; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ void *thash = NULL;
|
||||
size_t thash_size = 0;
|
||||
int keyslot;
|
||||
JsonVariant *w;
|
||||
sd_json_variant *w;
|
||||
|
||||
r = cryptsetup_get_token_as_json(cd, token, "systemd-tpm2", &v);
|
||||
if (IN_SET(r, -ENOENT, -EINVAL, -EMEDIUMTYPE))
|
||||
@ -49,12 +50,12 @@ static int search_policy_hash(
|
||||
continue;
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "tpm2-policy-hash");
|
||||
if (!w || !json_variant_is_string(w))
|
||||
w = sd_json_variant_by_key(v, "tpm2-policy-hash");
|
||||
if (!w || !sd_json_variant_is_string(w))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"TPM2 token data lacks 'tpm2-policy-hash' field.");
|
||||
|
||||
r = unhexmem(json_variant_string(w), &thash, &thash_size);
|
||||
r = unhexmem(sd_json_variant_string(w), &thash, &thash_size);
|
||||
if (r < 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Invalid base64 data in 'tpm2-policy-hash' field.");
|
||||
@ -257,7 +258,7 @@ int enroll_tpm2(struct crypt_device *cd,
|
||||
const char *pcrlock_path,
|
||||
int *ret_slot_to_wipe) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *signature_json = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *signature_json = NULL;
|
||||
_cleanup_(erase_and_freep) char *base64_encoded = NULL;
|
||||
_cleanup_(iovec_done) struct iovec srk = {}, blob = {}, pubkey = {};
|
||||
_cleanup_(iovec_done_erase) struct iovec secret = {};
|
||||
|
@ -1,8 +1,10 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "cryptenroll-wipe.h"
|
||||
#include "cryptenroll.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "memory-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "set.h"
|
||||
@ -100,8 +102,8 @@ static int find_slots_by_mask(
|
||||
/* Find all slots that are associated with a token of a type in the specified token type mask */
|
||||
|
||||
for (int token = 0; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
JsonVariant *w, *z;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
sd_json_variant *w, *z;
|
||||
EnrollType t;
|
||||
|
||||
r = cryptsetup_get_token_as_json(cd, token, NULL, &v);
|
||||
@ -112,16 +114,16 @@ static int find_slots_by_mask(
|
||||
continue;
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "type");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "type");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
log_warning("Token JSON data lacks type field, ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
t = luks2_token_type_from_string(json_variant_string(w));
|
||||
t = luks2_token_type_from_string(sd_json_variant_string(w));
|
||||
|
||||
w = json_variant_by_key(v, "keyslots");
|
||||
if (!w || !json_variant_is_array(w)) {
|
||||
w = sd_json_variant_by_key(v, "keyslots");
|
||||
if (!w || !sd_json_variant_is_array(w)) {
|
||||
log_warning("Token JSON data lacks keyslots field, ignoring.");
|
||||
continue;
|
||||
}
|
||||
@ -129,12 +131,12 @@ static int find_slots_by_mask(
|
||||
JSON_VARIANT_ARRAY_FOREACH(z, w) {
|
||||
int slot;
|
||||
|
||||
if (!json_variant_is_string(z)) {
|
||||
if (!sd_json_variant_is_string(z)) {
|
||||
log_warning("Token JSON data's keyslot field is not an array of strings, ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
r = safe_atoi(json_variant_string(z), &slot);
|
||||
r = safe_atoi(sd_json_variant_string(z), &slot);
|
||||
if (r < 0) {
|
||||
log_warning_errno(r, "Token JSON data's keyslot filed is not an integer formatted as string, ignoring.");
|
||||
continue;
|
||||
@ -200,9 +202,9 @@ static int find_slot_tokens(struct crypt_device *cd, Set *wipe_slots, Set *keep_
|
||||
* the slots sets according to the token data: add any other slots listed in the tokens we act on. */
|
||||
|
||||
for (int token = 0; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
bool shall_wipe = false;
|
||||
JsonVariant *w, *z;
|
||||
sd_json_variant *w, *z;
|
||||
|
||||
r = cryptsetup_get_token_as_json(cd, token, NULL, &v);
|
||||
if (IN_SET(r, -ENOENT, -EINVAL))
|
||||
@ -212,8 +214,8 @@ static int find_slot_tokens(struct crypt_device *cd, Set *wipe_slots, Set *keep_
|
||||
continue;
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "keyslots");
|
||||
if (!w || !json_variant_is_array(w)) {
|
||||
w = sd_json_variant_by_key(v, "keyslots");
|
||||
if (!w || !sd_json_variant_is_array(w)) {
|
||||
log_warning("Token JSON data lacks keyslots field, ignoring.");
|
||||
continue;
|
||||
}
|
||||
@ -222,12 +224,12 @@ static int find_slot_tokens(struct crypt_device *cd, Set *wipe_slots, Set *keep_
|
||||
JSON_VARIANT_ARRAY_FOREACH(z, w) {
|
||||
int slot;
|
||||
|
||||
if (!json_variant_is_string(z)) {
|
||||
if (!sd_json_variant_is_string(z)) {
|
||||
log_warning("Token JSON data's keyslot field is not an array of strings, ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
r = safe_atoi(json_variant_string(z), &slot);
|
||||
r = safe_atoi(sd_json_variant_string(z), &slot);
|
||||
if (r < 0) {
|
||||
log_warning_errno(r, "Token JSON data's keyslot filed is not an integer formatted as string, ignoring.");
|
||||
continue;
|
||||
@ -249,9 +251,9 @@ static int find_slot_tokens(struct crypt_device *cd, Set *wipe_slots, Set *keep_
|
||||
JSON_VARIANT_ARRAY_FOREACH(z, w) {
|
||||
int slot;
|
||||
|
||||
if (!json_variant_is_string(z))
|
||||
if (!sd_json_variant_is_string(z))
|
||||
continue;
|
||||
if (safe_atoi(json_variant_string(z), &slot) < 0)
|
||||
if (safe_atoi(sd_json_variant_string(z), &slot) < 0)
|
||||
continue;
|
||||
|
||||
if (set_put(shall_wipe ? wipe_slots : keep_slots, INT_TO_PTR(slot)) < 0)
|
||||
|
@ -3,10 +3,11 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <p11-kit/p11-kit.h>
|
||||
#include <p11-kit/uri.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "ask-password-api.h"
|
||||
#include "cryptsetup-pkcs11.h"
|
||||
@ -15,7 +16,6 @@
|
||||
#include "fileio.h"
|
||||
#include "format-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "macro.h"
|
||||
#include "memory-util.h"
|
||||
#include "parse-util.h"
|
||||
@ -109,8 +109,8 @@ int find_pkcs11_auto_data(
|
||||
/* Loads PKCS#11 metadata from LUKS2 JSON token headers. */
|
||||
|
||||
for (int token = 0; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
JsonVariant *w;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
sd_json_variant *w;
|
||||
int ks;
|
||||
|
||||
r = cryptsetup_get_token_as_json(cd, token, "systemd-pkcs11", &v);
|
||||
@ -134,12 +134,12 @@ int find_pkcs11_auto_data(
|
||||
assert(keyslot < 0);
|
||||
keyslot = ks;
|
||||
|
||||
w = json_variant_by_key(v, "pkcs11-uri");
|
||||
if (!w || !json_variant_is_string(w))
|
||||
w = sd_json_variant_by_key(v, "pkcs11-uri");
|
||||
if (!w || !sd_json_variant_is_string(w))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"PKCS#11 token data lacks 'pkcs11-uri' field.");
|
||||
|
||||
uri = strdup(json_variant_string(w));
|
||||
uri = strdup(sd_json_variant_string(w));
|
||||
if (!uri)
|
||||
return log_oom();
|
||||
|
||||
@ -147,14 +147,14 @@ int find_pkcs11_auto_data(
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"PKCS#11 token data contains invalid PKCS#11 URI.");
|
||||
|
||||
w = json_variant_by_key(v, "pkcs11-key");
|
||||
if (!w || !json_variant_is_string(w))
|
||||
w = sd_json_variant_by_key(v, "pkcs11-key");
|
||||
if (!w || !sd_json_variant_is_string(w))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"PKCS#11 token data lacks 'pkcs11-key' field.");
|
||||
|
||||
assert(!key);
|
||||
assert(key_size == 0);
|
||||
r = unbase64mem(json_variant_string(w), &key, &key_size);
|
||||
r = unbase64mem(sd_json_variant_string(w), &key, &key_size);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to decode base64 encoded key.");
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "cryptsetup-token.h"
|
||||
#include "cryptsetup-token-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "luks2-fido2.h"
|
||||
#include "memory-util.h"
|
||||
#include "version.h"
|
||||
@ -157,59 +157,59 @@ _public_ int cryptsetup_token_validate(
|
||||
const char *json /* contains valid 'type' and 'keyslots' fields. 'type' is 'systemd-fido2' */) {
|
||||
|
||||
int r;
|
||||
JsonVariant *w;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
sd_json_variant *w;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
assert(json);
|
||||
|
||||
r = json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Could not parse " TOKEN_NAME " json object: %m.");
|
||||
|
||||
w = json_variant_by_key(v, "fido2-credential");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "fido2-credential");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "FIDO2 token data lacks 'fido2-credential' field.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
r = unbase64mem(json_variant_string(w), NULL, NULL);
|
||||
r = unbase64mem(sd_json_variant_string(w), NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Invalid base64 data in 'fido2-credential' field: %m");
|
||||
|
||||
w = json_variant_by_key(v, "fido2-salt");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "fido2-salt");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "FIDO2 token data lacks 'fido2-salt' field.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
r = unbase64mem(json_variant_string(w), NULL, NULL);
|
||||
r = unbase64mem(sd_json_variant_string(w), NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Failed to decode base64 encoded salt: %m.");
|
||||
|
||||
/* The "rp" field is optional. */
|
||||
w = json_variant_by_key(v, "fido2-rp");
|
||||
if (w && !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "fido2-rp");
|
||||
if (w && !sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "FIDO2 token data's 'fido2-rp' field is not a string.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The "fido2-clientPin-required" field is optional. */
|
||||
w = json_variant_by_key(v, "fido2-clientPin-required");
|
||||
if (w && !json_variant_is_boolean(w)) {
|
||||
w = sd_json_variant_by_key(v, "fido2-clientPin-required");
|
||||
if (w && !sd_json_variant_is_boolean(w)) {
|
||||
crypt_log_debug(cd, "FIDO2 token data's 'fido2-clientPin-required' field is not a boolean.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The "fido2-up-required" field is optional. */
|
||||
w = json_variant_by_key(v, "fido2-up-required");
|
||||
if (w && !json_variant_is_boolean(w)) {
|
||||
w = sd_json_variant_by_key(v, "fido2-up-required");
|
||||
if (w && !sd_json_variant_is_boolean(w)) {
|
||||
crypt_log_debug(cd, "FIDO2 token data's 'fido2-up-required' field is not a boolean.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The "fido2-uv-required" field is optional. */
|
||||
w = json_variant_by_key(v, "fido2-uv-required");
|
||||
if (w && !json_variant_is_boolean(w)) {
|
||||
w = sd_json_variant_by_key(v, "fido2-uv-required");
|
||||
if (w && !sd_json_variant_is_boolean(w)) {
|
||||
crypt_log_debug(cd, "FIDO2 token data's 'fido2-uv-required' field is not a boolean.");
|
||||
return 1;
|
||||
}
|
||||
|
@ -3,10 +3,11 @@
|
||||
#include <errno.h>
|
||||
#include <libcryptsetup.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "cryptsetup-token.h"
|
||||
#include "cryptsetup-token-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "luks2-pkcs11.h"
|
||||
#include "memory-util.h"
|
||||
#include "pkcs11-util.h"
|
||||
@ -112,31 +113,31 @@ _public_ int cryptsetup_token_validate(
|
||||
const char *json /* contains valid 'type' and 'keyslots' fields. 'type' is 'systemd-pkcs11' */) {
|
||||
|
||||
int r;
|
||||
JsonVariant *w;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
sd_json_variant *w;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
r = json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Could not parse " TOKEN_NAME " json object: %m.");
|
||||
|
||||
w = json_variant_by_key(v, "pkcs11-uri");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "pkcs11-uri");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "PKCS#11 token data lacks 'pkcs11-uri' field.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!pkcs11_uri_valid(json_variant_string(w))) {
|
||||
if (!pkcs11_uri_valid(sd_json_variant_string(w))) {
|
||||
crypt_log_debug(cd, "PKCS#11 token data contains invalid PKCS#11 URI.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "pkcs11-key");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "pkcs11-key");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "PKCS#11 token data lacks 'pkcs11-key' field.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
r = unbase64mem(json_variant_string(w), NULL, NULL);
|
||||
r = unbase64mem(sd_json_variant_string(w), NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Failed to decode base64 encoded key: %m.");
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "cryptsetup-token.h"
|
||||
#include "cryptsetup-token-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "luks2-tpm2.h"
|
||||
#include "memory-util.h"
|
||||
#include "strv.h"
|
||||
@ -44,7 +44,7 @@ _public_ int cryptsetup_token_open_pin(
|
||||
_cleanup_(erase_and_freep) char *base64_encoded = NULL, *pin_string = NULL;
|
||||
_cleanup_(iovec_done) struct iovec blob = {}, pubkey = {}, policy_hash = {}, salt = {}, srk = {}, pcrlock_nv = {};
|
||||
_cleanup_(iovec_done_erase) struct iovec decrypted_key = {};
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
uint32_t hash_pcr_mask, pubkey_pcr_mask;
|
||||
systemd_tpm2_plugin_params params = {
|
||||
.search_pcr_mask = UINT32_MAX
|
||||
@ -72,7 +72,7 @@ _public_ int cryptsetup_token_open_pin(
|
||||
if (usrptr)
|
||||
params = *(systemd_tpm2_plugin_params *)usrptr;
|
||||
|
||||
r = json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Failed to parse token JSON data: %m");
|
||||
|
||||
@ -169,7 +169,7 @@ _public_ void cryptsetup_token_dump(
|
||||
|
||||
_cleanup_free_ char *hash_pcrs_str = NULL, *pubkey_pcrs_str = NULL, *blob_str = NULL, *policy_hash_str = NULL, *pubkey_str = NULL;
|
||||
_cleanup_(iovec_done) struct iovec blob = {}, pubkey = {}, policy_hash = {}, salt = {}, srk = {}, pcrlock_nv = {};
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
uint32_t hash_pcr_mask, pubkey_pcr_mask;
|
||||
uint16_t pcr_bank, primary_alg;
|
||||
TPM2Flags flags = 0;
|
||||
@ -177,7 +177,7 @@ _public_ void cryptsetup_token_dump(
|
||||
|
||||
assert(json);
|
||||
|
||||
r = json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return (void) crypt_log_debug_errno(cd, r, "Failed to parse " TOKEN_NAME " JSON object: %m");
|
||||
|
||||
@ -243,17 +243,17 @@ _public_ int cryptsetup_token_validate(
|
||||
const char *json /* contains valid 'type' and 'keyslots' fields. 'type' is 'systemd-tpm2' */) {
|
||||
|
||||
int r;
|
||||
JsonVariant *w, *e;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
sd_json_variant *w, *e;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
assert(json);
|
||||
|
||||
r = json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Could not parse " TOKEN_NAME " json object: %m");
|
||||
|
||||
w = json_variant_by_key(v, "tpm2-pcrs");
|
||||
if (!w || !json_variant_is_array(w)) {
|
||||
w = sd_json_variant_by_key(v, "tpm2-pcrs");
|
||||
if (!w || !sd_json_variant_is_array(w)) {
|
||||
crypt_log_debug(cd, "TPM2 token data lacks 'tpm2-pcrs' field.");
|
||||
return 1;
|
||||
}
|
||||
@ -261,12 +261,12 @@ _public_ int cryptsetup_token_validate(
|
||||
JSON_VARIANT_ARRAY_FOREACH(e, w) {
|
||||
uint64_t u;
|
||||
|
||||
if (!json_variant_is_number(e)) {
|
||||
if (!sd_json_variant_is_number(e)) {
|
||||
crypt_log_debug(cd, "TPM2 PCR is not a number.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
u = json_variant_unsigned(e);
|
||||
u = sd_json_variant_unsigned(e);
|
||||
if (!TPM2_PCR_INDEX_VALID(u)) {
|
||||
crypt_log_debug(cd, "TPM2 PCR number out of range.");
|
||||
return 1;
|
||||
@ -275,61 +275,61 @@ _public_ int cryptsetup_token_validate(
|
||||
|
||||
/* The bank field is optional, since it was added in systemd 250 only. Before the bank was hardcoded
|
||||
* to SHA256. */
|
||||
w = json_variant_by_key(v, "tpm2-pcr-bank");
|
||||
w = sd_json_variant_by_key(v, "tpm2-pcr-bank");
|
||||
if (w) {
|
||||
/* The PCR bank field is optional */
|
||||
|
||||
if (!json_variant_is_string(w)) {
|
||||
if (!sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "TPM2 PCR bank is not a string.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tpm2_hash_alg_from_string(json_variant_string(w)) < 0) {
|
||||
crypt_log_debug(cd, "TPM2 PCR bank invalid or not supported: %s.", json_variant_string(w));
|
||||
if (tpm2_hash_alg_from_string(sd_json_variant_string(w)) < 0) {
|
||||
crypt_log_debug(cd, "TPM2 PCR bank invalid or not supported: %s.", sd_json_variant_string(w));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* The primary key algorithm field is optional, since it was also added in systemd 250 only. Before
|
||||
* the algorithm was hardcoded to ECC. */
|
||||
w = json_variant_by_key(v, "tpm2-primary-alg");
|
||||
w = sd_json_variant_by_key(v, "tpm2-primary-alg");
|
||||
if (w) {
|
||||
/* The primary key algorithm is optional */
|
||||
|
||||
if (!json_variant_is_string(w)) {
|
||||
if (!sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "TPM2 primary key algorithm is not a string.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tpm2_asym_alg_from_string(json_variant_string(w)) < 0) {
|
||||
crypt_log_debug(cd, "TPM2 primary key algorithm invalid or not supported: %s", json_variant_string(w));
|
||||
if (tpm2_asym_alg_from_string(sd_json_variant_string(w)) < 0) {
|
||||
crypt_log_debug(cd, "TPM2 primary key algorithm invalid or not supported: %s", sd_json_variant_string(w));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "tpm2-blob");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "tpm2-blob");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "TPM2 token data lacks 'tpm2-blob' field.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
r = unbase64mem(json_variant_string(w), NULL, NULL);
|
||||
r = unbase64mem(sd_json_variant_string(w), NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Invalid base64 data in 'tpm2-blob' field: %m");
|
||||
|
||||
w = json_variant_by_key(v, "tpm2-policy-hash");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "tpm2-policy-hash");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
crypt_log_debug(cd, "TPM2 token data lacks 'tpm2-policy-hash' field.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
r = unhexmem(json_variant_string(w), NULL, NULL);
|
||||
r = unhexmem(sd_json_variant_string(w), NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Invalid base64 data in 'tpm2-policy-hash' field: %m");
|
||||
|
||||
w = json_variant_by_key(v, "tpm2-pin");
|
||||
w = sd_json_variant_by_key(v, "tpm2-pin");
|
||||
if (w) {
|
||||
if (!json_variant_is_boolean(w)) {
|
||||
if (!sd_json_variant_is_boolean(w)) {
|
||||
crypt_log_debug(cd, "TPM2 PIN policy is not a boolean.");
|
||||
return 1;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "cryptsetup-token-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "luks2-fido2.h"
|
||||
#include "memory-util.h"
|
||||
#include "strv.h"
|
||||
@ -84,8 +84,8 @@ int parse_luks2_fido2_data(
|
||||
size_t cid_size = 0, salt_size = 0;
|
||||
_cleanup_free_ char *rp = NULL;
|
||||
int r;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
JsonVariant *w;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
sd_json_variant *w;
|
||||
Fido2EnrollFlags required = 0;
|
||||
|
||||
assert(json);
|
||||
@ -96,54 +96,54 @@ int parse_luks2_fido2_data(
|
||||
assert(ret_cid_size);
|
||||
assert(ret_required);
|
||||
|
||||
r = json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_error_errno(cd, r, "Failed to parse JSON token data: %m");
|
||||
|
||||
w = json_variant_by_key(v, "fido2-credential");
|
||||
w = sd_json_variant_by_key(v, "fido2-credential");
|
||||
if (!w)
|
||||
return -EINVAL;
|
||||
|
||||
r = unbase64mem(json_variant_string(w), &cid, &cid_size);
|
||||
r = unbase64mem(sd_json_variant_string(w), &cid, &cid_size);
|
||||
if (r < 0)
|
||||
return crypt_log_error_errno(cd, r, "Failed to parse 'fido2-credentials' field: %m");
|
||||
|
||||
w = json_variant_by_key(v, "fido2-salt");
|
||||
w = sd_json_variant_by_key(v, "fido2-salt");
|
||||
if (!w)
|
||||
return -EINVAL;
|
||||
|
||||
r = unbase64mem(json_variant_string(w), &salt, &salt_size);
|
||||
r = unbase64mem(sd_json_variant_string(w), &salt, &salt_size);
|
||||
if (r < 0)
|
||||
return crypt_log_error_errno(cd, r, "Failed to parse 'fido2-salt' field: %m");
|
||||
|
||||
w = json_variant_by_key(v, "fido2-rp");
|
||||
w = sd_json_variant_by_key(v, "fido2-rp");
|
||||
if (w) {
|
||||
/* The "rp" field is optional. */
|
||||
rp = strdup(json_variant_string(w));
|
||||
rp = strdup(sd_json_variant_string(w));
|
||||
if (!rp) {
|
||||
crypt_log_error(cd, "Not enough memory.");
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "fido2-clientPin-required");
|
||||
w = sd_json_variant_by_key(v, "fido2-clientPin-required");
|
||||
if (w)
|
||||
/* The "fido2-clientPin-required" field is optional. */
|
||||
SET_FLAG(required, FIDO2ENROLL_PIN, json_variant_boolean(w));
|
||||
SET_FLAG(required, FIDO2ENROLL_PIN, sd_json_variant_boolean(w));
|
||||
else
|
||||
required |= FIDO2ENROLL_PIN_IF_NEEDED; /* compat with 248, where the field was unset */
|
||||
|
||||
w = json_variant_by_key(v, "fido2-up-required");
|
||||
w = sd_json_variant_by_key(v, "fido2-up-required");
|
||||
if (w)
|
||||
/* The "fido2-up-required" field is optional. */
|
||||
SET_FLAG(required, FIDO2ENROLL_UP, json_variant_boolean(w));
|
||||
SET_FLAG(required, FIDO2ENROLL_UP, sd_json_variant_boolean(w));
|
||||
else
|
||||
required |= FIDO2ENROLL_UP_IF_NEEDED; /* compat with 248 */
|
||||
|
||||
w = json_variant_by_key(v, "fido2-uv-required");
|
||||
w = sd_json_variant_by_key(v, "fido2-uv-required");
|
||||
if (w)
|
||||
/* The "fido2-uv-required" field is optional. */
|
||||
SET_FLAG(required, FIDO2ENROLL_UV, json_variant_boolean(w));
|
||||
SET_FLAG(required, FIDO2ENROLL_UV, sd_json_variant_boolean(w));
|
||||
else
|
||||
required |= FIDO2ENROLL_UV_OMIT; /* compat with 248 */
|
||||
|
||||
|
@ -3,10 +3,11 @@
|
||||
#include <p11-kit/p11-kit.h>
|
||||
#include <p11-kit/uri.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "cryptsetup-token-util.h"
|
||||
#include "escape.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "luks2-pkcs11.h"
|
||||
#include "memory-util.h"
|
||||
#include "pkcs11-util.h"
|
||||
@ -236,31 +237,31 @@ int parse_luks2_pkcs11_data(
|
||||
size_t key_size;
|
||||
_cleanup_free_ char *uri = NULL;
|
||||
_cleanup_free_ void *key = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
JsonVariant *w;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
sd_json_variant *w;
|
||||
|
||||
assert(json);
|
||||
assert(ret_uri);
|
||||
assert(ret_encrypted_key);
|
||||
assert(ret_encrypted_key_size);
|
||||
|
||||
r = json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
w = json_variant_by_key(v, "pkcs11-uri");
|
||||
w = sd_json_variant_by_key(v, "pkcs11-uri");
|
||||
if (!w)
|
||||
return -EINVAL;
|
||||
|
||||
uri = strdup(json_variant_string(w));
|
||||
uri = strdup(sd_json_variant_string(w));
|
||||
if (!uri)
|
||||
return -ENOMEM;
|
||||
|
||||
w = json_variant_by_key(v, "pkcs11-key");
|
||||
w = sd_json_variant_by_key(v, "pkcs11-key");
|
||||
if (!w)
|
||||
return -EINVAL;
|
||||
|
||||
r = unbase64mem(json_variant_string(w), &key, &key_size);
|
||||
r = unbase64mem(sd_json_variant_string(w), &key, &key_size);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Failed to decode base64 encoded key: %m.");
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "ask-password-api.h"
|
||||
#include "env-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json.h"
|
||||
#include "log.h"
|
||||
#include "luks2-tpm2.h"
|
||||
#include "parse-util.h"
|
||||
@ -31,7 +32,7 @@ int acquire_luks2_key(
|
||||
TPM2Flags flags,
|
||||
struct iovec *ret_decrypted_key) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *signature_json = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *signature_json = NULL;
|
||||
_cleanup_free_ char *auto_device = NULL;
|
||||
_cleanup_(erase_and_freep) char *b64_salted_pin = NULL;
|
||||
int r;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-device.h"
|
||||
#include "sd-json.h"
|
||||
#include "sd-messages.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
@ -28,6 +29,7 @@
|
||||
#include "fs-util.h"
|
||||
#include "fstab-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json-util.h"
|
||||
#include "libfido2-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
@ -720,9 +722,9 @@ static PassphraseType check_registered_passwords(struct crypt_device *cd) {
|
||||
|
||||
/* Iterate all LUKS2 tokens and keep track of all their slots */
|
||||
for (int token = 0; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
const char *type;
|
||||
JsonVariant *w, *z;
|
||||
sd_json_variant *w, *z;
|
||||
int tk;
|
||||
|
||||
tk = cryptsetup_get_token_as_json(cd, token, NULL, &v);
|
||||
@ -733,21 +735,21 @@ static PassphraseType check_registered_passwords(struct crypt_device *cd) {
|
||||
continue;
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "type");
|
||||
if (!w || !json_variant_is_string(w)) {
|
||||
w = sd_json_variant_by_key(v, "type");
|
||||
if (!w || !sd_json_variant_is_string(w)) {
|
||||
log_warning("Token JSON data lacks type field, ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
type = json_variant_string(w);
|
||||
type = sd_json_variant_string(w);
|
||||
if (STR_IN_SET(type, "systemd-recovery", "systemd-pkcs11", "systemd-fido2", "systemd-tpm2")) {
|
||||
|
||||
/* At least exists one recovery key */
|
||||
if (streq(type, "systemd-recovery"))
|
||||
passphrase_type |= PASSPHRASE_RECOVERY_KEY;
|
||||
|
||||
w = json_variant_by_key(v, "keyslots");
|
||||
if (!w || !json_variant_is_array(w)) {
|
||||
w = sd_json_variant_by_key(v, "keyslots");
|
||||
if (!w || !sd_json_variant_is_array(w)) {
|
||||
log_warning("Token JSON data lacks keyslots field, ignoring.");
|
||||
continue;
|
||||
}
|
||||
@ -756,12 +758,12 @@ static PassphraseType check_registered_passwords(struct crypt_device *cd) {
|
||||
unsigned u;
|
||||
int at;
|
||||
|
||||
if (!json_variant_is_string(z)) {
|
||||
if (!sd_json_variant_is_string(z)) {
|
||||
log_warning("Token JSON data's keyslot field is not an array of strings, ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
at = safe_atou(json_variant_string(z), &u);
|
||||
at = safe_atou(sd_json_variant_string(z), &u);
|
||||
if (at < 0) {
|
||||
log_warning_errno(at, "Token JSON data's keyslot field is not an integer formatted as string, ignoring.");
|
||||
continue;
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "json-util.h"
|
||||
#include "libarchive-util.h"
|
||||
#include "log.h"
|
||||
#include "loop-util.h"
|
||||
@ -84,7 +85,7 @@ static DissectImageFlags arg_flags =
|
||||
DISSECT_IMAGE_ADD_PARTITION_DEVICES |
|
||||
DISSECT_IMAGE_ALLOW_USERSPACE_VERITY;
|
||||
static VeritySettings arg_verity_settings = VERITY_SETTINGS_DEFAULT;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static bool arg_legend = true;
|
||||
static bool arg_rmdir = false;
|
||||
@ -861,7 +862,7 @@ static int action_dissect(
|
||||
LoopDevice *d,
|
||||
int userns_fd) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(table_unrefp) Table *t = NULL;
|
||||
_cleanup_free_ char *bn = NULL;
|
||||
uint64_t size = UINT64_MAX;
|
||||
@ -873,10 +874,10 @@ static int action_dissect(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to extract file name from image path '%s': %m", arg_image);
|
||||
|
||||
if (arg_json_format_flags & (JSON_FORMAT_OFF|JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
|
||||
if (arg_json_format_flags & (SD_JSON_FORMAT_OFF|SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_PRETTY_AUTO))
|
||||
pager_open(arg_pager_flags);
|
||||
|
||||
if (arg_json_format_flags & JSON_FORMAT_OFF) {
|
||||
if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
|
||||
printf(" File Name: %s%s%s\n",
|
||||
ansi_highlight(), bn, ansi_normal());
|
||||
|
||||
@ -906,7 +907,7 @@ static int action_dissect(
|
||||
log_warning_errno(r, "OS image is currently in use, proceeding without showing OS image metadata.");
|
||||
else if (r < 0)
|
||||
return log_error_errno(r, "Failed to acquire image metadata: %m");
|
||||
else if (arg_json_format_flags & JSON_FORMAT_OFF) {
|
||||
else if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
|
||||
|
||||
if (m->image_name && !streq(m->image_name, bn))
|
||||
printf("Image Name: %s\n", m->image_name);
|
||||
@ -979,29 +980,29 @@ static int action_dissect(
|
||||
|
||||
Architecture a = dissected_image_architecture(m);
|
||||
|
||||
r = json_build(&v, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("name", JSON_BUILD_STRING(bn)),
|
||||
JSON_BUILD_PAIR_CONDITION(size != UINT64_MAX, "size", JSON_BUILD_INTEGER(size)),
|
||||
JSON_BUILD_PAIR("sectorSize", JSON_BUILD_INTEGER(m->sector_size)),
|
||||
JSON_BUILD_PAIR_CONDITION(a >= 0, "architecture", JSON_BUILD_STRING(architecture_to_string(a))),
|
||||
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(m->image_uuid), "imageUuid", JSON_BUILD_UUID(m->image_uuid)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->hostname, "hostname", JSON_BUILD_STRING(m->hostname)),
|
||||
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(m->machine_id), "machineId", JSON_BUILD_ID128(m->machine_id)),
|
||||
JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->machine_info), "machineInfo", JSON_BUILD_STRV_ENV_PAIR(m->machine_info)),
|
||||
JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->os_release), "osRelease", JSON_BUILD_STRV_ENV_PAIR(m->os_release)),
|
||||
JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->initrd_release), "initrdRelease", JSON_BUILD_STRV_ENV_PAIR(m->initrd_release)),
|
||||
JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->sysext_release), "sysextRelease", JSON_BUILD_STRV_ENV_PAIR(m->sysext_release)),
|
||||
JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->confext_release), "confextRelease", JSON_BUILD_STRV_ENV_PAIR(m->confext_release)),
|
||||
JSON_BUILD_PAIR("useBootableUefi", JSON_BUILD_BOOLEAN(dissected_image_is_bootable_uefi(m))),
|
||||
JSON_BUILD_PAIR("useBootableContainer", JSON_BUILD_BOOLEAN(dissected_image_is_bootable_os(m))),
|
||||
JSON_BUILD_PAIR("useInitrd", JSON_BUILD_BOOLEAN(dissected_image_is_initrd(m))),
|
||||
JSON_BUILD_PAIR("usePortableService", JSON_BUILD_BOOLEAN(dissected_image_is_portable(m))),
|
||||
JSON_BUILD_PAIR("useSystemExtension", JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "system"))),
|
||||
JSON_BUILD_PAIR("useInitRDSystemExtension", JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "initrd"))),
|
||||
JSON_BUILD_PAIR("usePortableSystemExtension", JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "portable"))),
|
||||
JSON_BUILD_PAIR("useConfigurationExtension", JSON_BUILD_BOOLEAN(strv_contains(confext_scopes, "system"))),
|
||||
JSON_BUILD_PAIR("useInitRDConfigurationExtension", JSON_BUILD_BOOLEAN(strv_contains(confext_scopes, "initrd"))),
|
||||
JSON_BUILD_PAIR("usePortableConfigurationExtension", JSON_BUILD_BOOLEAN(strv_contains(confext_scopes, "portable")))));
|
||||
r = sd_json_build(&v, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("name", SD_JSON_BUILD_STRING(bn)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(size != UINT64_MAX, "size", SD_JSON_BUILD_INTEGER(size)),
|
||||
SD_JSON_BUILD_PAIR("sectorSize", SD_JSON_BUILD_INTEGER(m->sector_size)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(a >= 0, "architecture", SD_JSON_BUILD_STRING(architecture_to_string(a))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(m->image_uuid), "imageUuid", SD_JSON_BUILD_UUID(m->image_uuid)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!m->hostname, "hostname", SD_JSON_BUILD_STRING(m->hostname)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(m->machine_id), "machineId", SD_JSON_BUILD_ID128(m->machine_id)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->machine_info), "machineInfo", JSON_BUILD_STRV_ENV_PAIR(m->machine_info)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->os_release), "osRelease", JSON_BUILD_STRV_ENV_PAIR(m->os_release)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->initrd_release), "initrdRelease", JSON_BUILD_STRV_ENV_PAIR(m->initrd_release)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->sysext_release), "sysextRelease", JSON_BUILD_STRV_ENV_PAIR(m->sysext_release)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->confext_release), "confextRelease", JSON_BUILD_STRV_ENV_PAIR(m->confext_release)),
|
||||
SD_JSON_BUILD_PAIR("useBootableUefi", SD_JSON_BUILD_BOOLEAN(dissected_image_is_bootable_uefi(m))),
|
||||
SD_JSON_BUILD_PAIR("useBootableContainer", SD_JSON_BUILD_BOOLEAN(dissected_image_is_bootable_os(m))),
|
||||
SD_JSON_BUILD_PAIR("useInitrd", SD_JSON_BUILD_BOOLEAN(dissected_image_is_initrd(m))),
|
||||
SD_JSON_BUILD_PAIR("usePortableService", SD_JSON_BUILD_BOOLEAN(dissected_image_is_portable(m))),
|
||||
SD_JSON_BUILD_PAIR("useSystemExtension", SD_JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "system"))),
|
||||
SD_JSON_BUILD_PAIR("useInitRDSystemExtension", SD_JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "initrd"))),
|
||||
SD_JSON_BUILD_PAIR("usePortableSystemExtension", SD_JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "portable"))),
|
||||
SD_JSON_BUILD_PAIR("useConfigurationExtension", SD_JSON_BUILD_BOOLEAN(strv_contains(confext_scopes, "system"))),
|
||||
SD_JSON_BUILD_PAIR("useInitRDConfigurationExtension", SD_JSON_BUILD_BOOLEAN(strv_contains(confext_scopes, "initrd"))),
|
||||
SD_JSON_BUILD_PAIR("usePortableConfigurationExtension", SD_JSON_BUILD_BOOLEAN(strv_contains(confext_scopes, "portable")))));
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
@ -1015,7 +1016,7 @@ static int action_dissect(
|
||||
|
||||
/* Hide the device path if this is a loopback device that is not relinquished, since that means the
|
||||
* device node is not going to be useful the instant our command exits */
|
||||
if ((!d || d->created) && (arg_json_format_flags & JSON_FORMAT_OFF))
|
||||
if ((!d || d->created) && (arg_json_format_flags & SD_JSON_FORMAT_OFF))
|
||||
table_hide_column_from_display(t, 8);
|
||||
|
||||
for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
|
||||
@ -1078,24 +1079,24 @@ static int action_dissect(
|
||||
return table_log_add_error(r);
|
||||
}
|
||||
|
||||
if (arg_json_format_flags & JSON_FORMAT_OFF) {
|
||||
if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
|
||||
(void) table_set_header(t, arg_legend);
|
||||
|
||||
r = table_print(t, NULL);
|
||||
if (r < 0)
|
||||
return table_log_print_error(r);
|
||||
} else {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *jt = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *jt = NULL;
|
||||
|
||||
r = table_to_json(t, &jt);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to convert table to JSON: %m");
|
||||
|
||||
r = json_variant_set_field(&v, "mounts", jt);
|
||||
r = sd_json_variant_set_field(&v, "mounts", jt);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
json_variant_dump(v, arg_json_format_flags, stdout, NULL);
|
||||
sd_json_variant_dump(v, arg_json_format_flags, stdout, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1854,7 +1855,7 @@ static int action_discover(void) {
|
||||
return log_error_errno(r, "Failed to discover images: %m");
|
||||
}
|
||||
|
||||
if ((arg_json_format_flags & JSON_FORMAT_OFF) && hashmap_isempty(images)) {
|
||||
if ((arg_json_format_flags & SD_JSON_FORMAT_OFF) && hashmap_isempty(images)) {
|
||||
log_info("No images found.");
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,17 +2,20 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "bootspec.h"
|
||||
#include "env-util.h"
|
||||
#include "escape.h"
|
||||
#include "fuzz.h"
|
||||
#include "fd-util.h"
|
||||
#include "json.h"
|
||||
#include "fuzz.h"
|
||||
#include "json-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
static int json_dispatch_config(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
static int json_dispatch_config(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
BootConfig *config = ASSERT_PTR(userdata);
|
||||
|
||||
const char *s = json_variant_string(variant);
|
||||
const char *s = sd_json_variant_string(variant);
|
||||
if (!s)
|
||||
return -EINVAL;
|
||||
|
||||
@ -23,29 +26,29 @@ static int json_dispatch_config(const char *name, JsonVariant *variant, JsonDisp
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int json_dispatch_entries(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
static int json_dispatch_entries(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
BootConfig *config = ASSERT_PTR(userdata);
|
||||
JsonVariant *entry;
|
||||
sd_json_variant *entry;
|
||||
|
||||
JSON_VARIANT_ARRAY_FOREACH(entry, variant) {
|
||||
if (!json_variant_is_array(entry) ||
|
||||
json_variant_elements(entry) < 1)
|
||||
if (!sd_json_variant_is_array(entry) ||
|
||||
sd_json_variant_elements(entry) < 1)
|
||||
return -EINVAL;
|
||||
|
||||
JsonVariant *v;
|
||||
sd_json_variant *v;
|
||||
const char *id = NULL, *raw = NULL;
|
||||
_cleanup_free_ char *data = NULL;
|
||||
ssize_t len = -ENODATA;
|
||||
|
||||
v = json_variant_by_index(entry, 0);
|
||||
v = sd_json_variant_by_index(entry, 0);
|
||||
if (v)
|
||||
id = json_variant_string(v);
|
||||
id = sd_json_variant_string(v);
|
||||
if (!id)
|
||||
continue;
|
||||
|
||||
v = json_variant_by_index(entry, 1);
|
||||
v = sd_json_variant_by_index(entry, 1);
|
||||
if (v)
|
||||
raw = json_variant_string(v);
|
||||
raw = sd_json_variant_string(v);
|
||||
if (raw)
|
||||
len = cunescape(raw, UNESCAPE_RELAX | UNESCAPE_ACCEPT_NUL, &data);
|
||||
if (len >= 0) {
|
||||
@ -59,12 +62,12 @@ static int json_dispatch_entries(const char *name, JsonVariant *variant, JsonDis
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int json_dispatch_loader(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
static int json_dispatch_loader(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
BootConfig *config = ASSERT_PTR(userdata);
|
||||
_cleanup_strv_free_ char **entries = NULL;
|
||||
int r;
|
||||
|
||||
r = json_dispatch_strv(name, variant, flags, &entries);
|
||||
r = sd_json_dispatch_strv(name, variant, flags, &entries);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -72,10 +75,10 @@ static int json_dispatch_loader(const char *name, JsonVariant *variant, JsonDisp
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const JsonDispatch data_dispatch[] = {
|
||||
{ "config", JSON_VARIANT_STRING, json_dispatch_config, 0, 0 },
|
||||
{ "entries", JSON_VARIANT_ARRAY, json_dispatch_entries, 0, 0 },
|
||||
{ "loader", JSON_VARIANT_ARRAY, json_dispatch_loader, 0, 0 },
|
||||
static const sd_json_dispatch_field data_dispatch[] = {
|
||||
{ "config", SD_JSON_VARIANT_STRING, json_dispatch_config, 0, 0 },
|
||||
{ "entries", SD_JSON_VARIANT_ARRAY, json_dispatch_entries, 0, 0 },
|
||||
{ "loader", SD_JSON_VARIANT_ARRAY, json_dispatch_loader, 0, 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -91,12 +94,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
|
||||
assert_se(datadup = memdup_suffix0(data, size));
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
r = json_parse(datadup, 0, &v, NULL, NULL);
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
r = sd_json_parse(datadup, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
r = json_dispatch(v, data_dispatch, 0, &config);
|
||||
r = sd_json_dispatch(v, data_dispatch, 0, &config);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
@ -113,8 +116,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
assert_se(freopen("/dev/null", "w", stdout));
|
||||
}
|
||||
|
||||
(void) show_boot_entries(&config, JSON_FORMAT_OFF);
|
||||
(void) show_boot_entries(&config, JSON_FORMAT_PRETTY);
|
||||
(void) show_boot_entries(&config, SD_JSON_FORMAT_OFF);
|
||||
(void) show_boot_entries(&config, SD_JSON_FORMAT_PRETTY);
|
||||
|
||||
if (orig_stdout_fd >= 0)
|
||||
assert_se(freopen(FORMAT_PROC_FD_PATH(orig_stdout_fd), "w", stdout));
|
||||
|
@ -1,15 +1,17 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "env-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fuzz.h"
|
||||
#include "json.h"
|
||||
#include "memstream-util.h"
|
||||
#include "string-util.h"
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_(memstream_done) MemStream m = {};
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
FILE *g = NULL;
|
||||
int r;
|
||||
@ -19,7 +21,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
f = data_to_file(data, size);
|
||||
assert_se(f);
|
||||
|
||||
r = json_parse_file(f, NULL, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse_file(f, NULL, 0, &v, NULL, NULL);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "failed to parse input: %m");
|
||||
return 0;
|
||||
@ -28,87 +30,87 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (getenv_bool("SYSTEMD_FUZZ_OUTPUT") <= 0)
|
||||
assert_se(g = memstream_init(&m));
|
||||
|
||||
json_variant_dump(v, 0, g ?: stdout, NULL);
|
||||
json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR|JSON_FORMAT_SOURCE, g ?: stdout, NULL);
|
||||
sd_json_variant_dump(v, 0, g ?: stdout, NULL);
|
||||
sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_COLOR|SD_JSON_FORMAT_SOURCE, g ?: stdout, NULL);
|
||||
|
||||
bool sorted = json_variant_is_sorted(v);
|
||||
log_debug("json_variant_is_sorted: %s", yes_no(sorted));
|
||||
bool sorted = sd_json_variant_is_sorted(v);
|
||||
log_debug("sd_json_variant_is_sorted: %s", yes_no(sorted));
|
||||
|
||||
r = json_variant_sort(&v);
|
||||
log_debug_errno(r, "json_variant_sort: %d/%m", r);
|
||||
r = sd_json_variant_sort(&v);
|
||||
log_debug_errno(r, "sd_json_variant_sort: %d/%m", r);
|
||||
|
||||
sorted = json_variant_is_sorted(v);
|
||||
sorted = sd_json_variant_is_sorted(v);
|
||||
log_debug("json_variant_is_sorted: %s", yes_no(sorted));
|
||||
assert_se(r < 0 || sorted);
|
||||
|
||||
bool normalized = json_variant_is_normalized(v);
|
||||
bool normalized = sd_json_variant_is_normalized(v);
|
||||
log_debug("json_variant_is_normalized: %s", yes_no(normalized));
|
||||
|
||||
r = json_variant_normalize(&v);
|
||||
r = sd_json_variant_normalize(&v);
|
||||
log_debug_errno(r, "json_variant_normalize: %d/%m", r);
|
||||
|
||||
normalized = json_variant_is_normalized(v);
|
||||
normalized = sd_json_variant_is_normalized(v);
|
||||
log_debug("json_variant_is_normalized: %s", yes_no(normalized));
|
||||
assert_se(r < 0 || normalized);
|
||||
|
||||
double real = json_variant_real(v);
|
||||
double real = sd_json_variant_real(v);
|
||||
log_debug("json_variant_real: %lf", real);
|
||||
|
||||
bool negative = json_variant_is_negative(v);
|
||||
bool negative = sd_json_variant_is_negative(v);
|
||||
log_debug("json_variant_is_negative: %s", yes_no(negative));
|
||||
|
||||
bool blank = json_variant_is_blank_object(v);
|
||||
bool blank = sd_json_variant_is_blank_object(v);
|
||||
log_debug("json_variant_is_blank_object: %s", yes_no(blank));
|
||||
|
||||
blank = json_variant_is_blank_array(v);
|
||||
blank = sd_json_variant_is_blank_array(v);
|
||||
log_debug("json_variant_is_blank_array: %s", yes_no(blank));
|
||||
|
||||
size_t elements = json_variant_elements(v);
|
||||
size_t elements = sd_json_variant_elements(v);
|
||||
log_debug("json_variant_elements: %zu", elements);
|
||||
|
||||
for (size_t i = 0; i <= elements + 2; i++)
|
||||
(void) json_variant_by_index(v, i);
|
||||
(void) sd_json_variant_by_index(v, i);
|
||||
|
||||
assert_se(json_variant_equal(v, v));
|
||||
assert_se(!json_variant_equal(v, NULL));
|
||||
assert_se(!json_variant_equal(NULL, v));
|
||||
assert_se(sd_json_variant_equal(v, v));
|
||||
assert_se(!sd_json_variant_equal(v, NULL));
|
||||
assert_se(!sd_json_variant_equal(NULL, v));
|
||||
|
||||
bool sensitive = json_variant_is_sensitive(v);
|
||||
bool sensitive = sd_json_variant_is_sensitive(v);
|
||||
log_debug("json_variant_is_sensitive: %s", yes_no(sensitive));
|
||||
|
||||
json_variant_sensitive(v);
|
||||
sd_json_variant_sensitive(v);
|
||||
|
||||
sensitive = json_variant_is_sensitive(v);
|
||||
sensitive = sd_json_variant_is_sensitive(v);
|
||||
log_debug("json_variant_is_sensitive: %s", yes_no(sensitive));
|
||||
|
||||
const char *source;
|
||||
unsigned line, column;
|
||||
assert_se(json_variant_get_source(v, &source, &line, &column) == 0);
|
||||
assert_se(sd_json_variant_get_source(v, &source, &line, &column) == 0);
|
||||
log_debug("json_variant_get_source: %s:%u:%u", source ?: "-", line, column);
|
||||
|
||||
r = json_variant_set_field_string(&v, "a", "string-a");
|
||||
r = sd_json_variant_set_field_string(&v, "a", "string-a");
|
||||
log_debug_errno(r, "json_set_field_string: %d/%m", r);
|
||||
|
||||
r = json_variant_set_field_integer(&v, "b", -12345);
|
||||
r = sd_json_variant_set_field_integer(&v, "b", -12345);
|
||||
log_debug_errno(r, "json_set_field_integer: %d/%m", r);
|
||||
|
||||
r = json_variant_set_field_unsigned(&v, "c", 12345);
|
||||
r = sd_json_variant_set_field_unsigned(&v, "c", 12345);
|
||||
log_debug_errno(r, "json_set_field_unsigned: %d/%m", r);
|
||||
|
||||
r = json_variant_set_field_boolean(&v, "d", false);
|
||||
r = sd_json_variant_set_field_boolean(&v, "d", false);
|
||||
log_debug_errno(r, "json_set_field_boolean: %d/%m", r);
|
||||
|
||||
r = json_variant_set_field_strv(&v, "e", STRV_MAKE("e-1", "e-2", "e-3"));
|
||||
r = sd_json_variant_set_field_strv(&v, "e", STRV_MAKE("e-1", "e-2", "e-3"));
|
||||
log_debug_errno(r, "json_set_field_strv: %d/%m", r);
|
||||
|
||||
r = json_variant_filter(&v, STRV_MAKE("a", "b", "c", "d", "e"));
|
||||
r = sd_json_variant_filter(&v, STRV_MAKE("a", "b", "c", "d", "e"));
|
||||
log_debug_errno(r, "json_variant_filter: %d/%m", r);
|
||||
|
||||
/* I assume we can merge v with itself… */
|
||||
r = json_variant_merge_object(&v, v);
|
||||
r = sd_json_variant_merge_object(&v, v);
|
||||
log_debug_errno(r, "json_variant_merge: %d/%m", r);
|
||||
|
||||
r = json_variant_append_array(&v, v);
|
||||
r = sd_json_variant_append_array(&v, v);
|
||||
log_debug_errno(r, "json_variant_append_array: %d/%m", r);
|
||||
|
||||
return 0;
|
||||
|
@ -6,8 +6,9 @@
|
||||
#include "fd-util.h"
|
||||
#include "fuzz.h"
|
||||
#include "io-util.h"
|
||||
#include "varlink-idl.h"
|
||||
#include "log.h"
|
||||
#include "string-util.h"
|
||||
#include "varlink-idl.h"
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_(varlink_interface_freep) VarlinkInterface *vi = NULL;
|
||||
|
@ -12,13 +12,13 @@
|
||||
|
||||
static FILE *null = NULL;
|
||||
|
||||
static int method_something(Varlink *v, JsonVariant *p, VarlinkMethodFlags flags, void *userdata) {
|
||||
json_variant_dump(p, JSON_FORMAT_NEWLINE|JSON_FORMAT_PRETTY, null, NULL);
|
||||
static int method_something(Varlink *v, sd_json_variant *p, VarlinkMethodFlags flags, void *userdata) {
|
||||
sd_json_variant_dump(p, SD_JSON_FORMAT_NEWLINE|SD_JSON_FORMAT_PRETTY, null, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int reply_callback(Varlink *v, JsonVariant *p, const char *error_id, VarlinkReplyFlags flags, void *userdata) {
|
||||
json_variant_dump(p, JSON_FORMAT_NEWLINE|JSON_FORMAT_PRETTY, null, NULL);
|
||||
static int reply_callback(Varlink *v, sd_json_variant *p, const char *error_id, VarlinkReplyFlags flags, void *userdata) {
|
||||
sd_json_variant_dump(p, SD_JSON_FORMAT_NEWLINE|SD_JSON_FORMAT_PRETTY, null, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "device-nodes.h"
|
||||
#include "fstab-util.h"
|
||||
#include "hibernate-resume-config.h"
|
||||
#include "json.h"
|
||||
#include "os-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
@ -141,19 +142,19 @@ static bool validate_efi_hibernate_location(EFIHibernateLocation *e) {
|
||||
|
||||
int get_efi_hibernate_location(EFIHibernateLocation **ret) {
|
||||
#if ENABLE_EFI
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "uuid", JSON_VARIANT_STRING, json_dispatch_id128, offsetof(EFIHibernateLocation, uuid), JSON_MANDATORY },
|
||||
{ "offset", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(EFIHibernateLocation, offset), JSON_MANDATORY },
|
||||
{ "kernelVersion", JSON_VARIANT_STRING, json_dispatch_string, offsetof(EFIHibernateLocation, kernel_version), JSON_PERMISSIVE|JSON_DEBUG },
|
||||
{ "osReleaseId", JSON_VARIANT_STRING, json_dispatch_string, offsetof(EFIHibernateLocation, id), JSON_PERMISSIVE|JSON_DEBUG },
|
||||
{ "osReleaseImageId", JSON_VARIANT_STRING, json_dispatch_string, offsetof(EFIHibernateLocation, image_id), JSON_PERMISSIVE|JSON_DEBUG },
|
||||
{ "osReleaseVersionId", JSON_VARIANT_STRING, json_dispatch_string, offsetof(EFIHibernateLocation, version_id), JSON_PERMISSIVE|JSON_DEBUG },
|
||||
{ "osReleaseImageVersion", JSON_VARIANT_STRING, json_dispatch_string, offsetof(EFIHibernateLocation, image_version), JSON_PERMISSIVE|JSON_DEBUG },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "uuid", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(EFIHibernateLocation, uuid), SD_JSON_MANDATORY },
|
||||
{ "offset", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(EFIHibernateLocation, offset), SD_JSON_MANDATORY },
|
||||
{ "kernelVersion", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(EFIHibernateLocation, kernel_version), SD_JSON_PERMISSIVE|SD_JSON_DEBUG },
|
||||
{ "osReleaseId", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(EFIHibernateLocation, id), SD_JSON_PERMISSIVE|SD_JSON_DEBUG },
|
||||
{ "osReleaseImageId", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(EFIHibernateLocation, image_id), SD_JSON_PERMISSIVE|SD_JSON_DEBUG },
|
||||
{ "osReleaseVersionId", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(EFIHibernateLocation, version_id), SD_JSON_PERMISSIVE|SD_JSON_DEBUG },
|
||||
{ "osReleaseImageVersion", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(EFIHibernateLocation, image_version), SD_JSON_PERMISSIVE|SD_JSON_DEBUG },
|
||||
{},
|
||||
};
|
||||
|
||||
_cleanup_(efi_hibernate_location_freep) EFIHibernateLocation *e = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *location_str = NULL;
|
||||
int r;
|
||||
|
||||
@ -168,7 +169,7 @@ int get_efi_hibernate_location(EFIHibernateLocation **ret) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get EFI variable HibernateLocation: %m");
|
||||
|
||||
r = json_parse(location_str, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(location_str, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse HibernateLocation JSON object: %m");
|
||||
|
||||
@ -176,7 +177,7 @@ int get_efi_hibernate_location(EFIHibernateLocation **ret) {
|
||||
if (!e)
|
||||
return log_oom();
|
||||
|
||||
r = json_dispatch(v, dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, e);
|
||||
r = sd_json_dispatch(v, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -115,7 +115,7 @@ int split_user_name_realm(const char *t, char **ret_user_name, char **ret_realm)
|
||||
|
||||
int bus_message_append_secret(sd_bus_message *m, UserRecord *secret) {
|
||||
_cleanup_(erase_and_freep) char *formatted = NULL;
|
||||
JsonVariant *v;
|
||||
sd_json_variant *v;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -124,11 +124,11 @@ int bus_message_append_secret(sd_bus_message *m, UserRecord *secret) {
|
||||
if (!FLAGS_SET(secret->mask, USER_RECORD_SECRET))
|
||||
return sd_bus_message_append(m, "s", "{}");
|
||||
|
||||
v = json_variant_by_key(secret->json, "secret");
|
||||
v = sd_json_variant_by_key(secret->json, "secret");
|
||||
if (!v)
|
||||
return -EINVAL;
|
||||
|
||||
r = json_variant_format(v, 0, &formatted);
|
||||
r = sd_json_variant_format(v, 0, &formatted);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
#if HAVE_LIBFIDO2
|
||||
static int add_fido2_credential_id(
|
||||
JsonVariant **v,
|
||||
sd_json_variant **v,
|
||||
const void *cid,
|
||||
size_t cid_size) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
ssize_t escaped_size;
|
||||
@ -36,9 +36,9 @@ static int add_fido2_credential_id(
|
||||
if (escaped_size < 0)
|
||||
return log_error_errno(escaped_size, "Failed to base64 encode FIDO2 credential ID: %m");
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(*v, "fido2HmacCredential"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(*v, "fido2HmacCredential"));
|
||||
if (w) {
|
||||
r = json_variant_strv(w, &l);
|
||||
r = sd_json_variant_strv(w, &l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse FIDO2 credential ID list: %m");
|
||||
|
||||
@ -50,12 +50,12 @@ static int add_fido2_credential_id(
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
w = json_variant_unref(w);
|
||||
r = json_variant_new_array_strv(&w, l);
|
||||
w = sd_json_variant_unref(w);
|
||||
r = sd_json_variant_new_array_strv(&w, l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create FIDO2 credential ID JSON: %m");
|
||||
|
||||
r = json_variant_set_field(v, "fido2HmacCredential", w);
|
||||
r = sd_json_variant_set_field(v, "fido2HmacCredential", w);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update FIDO2 credential ID: %m");
|
||||
|
||||
@ -63,7 +63,7 @@ static int add_fido2_credential_id(
|
||||
}
|
||||
|
||||
static int add_fido2_salt(
|
||||
JsonVariant **v,
|
||||
sd_json_variant **v,
|
||||
const void *cid,
|
||||
size_t cid_size,
|
||||
const void *fido2_salt,
|
||||
@ -72,7 +72,7 @@ static int add_fido2_salt(
|
||||
size_t secret_size,
|
||||
Fido2EnrollFlags lock_with) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *l = NULL, *w = NULL, *e = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *l = NULL, *w = NULL, *e = NULL;
|
||||
_cleanup_(erase_and_freep) char *base64_encoded = NULL, *hashed = NULL;
|
||||
ssize_t base64_encoded_size;
|
||||
int r;
|
||||
@ -87,29 +87,29 @@ static int add_fido2_salt(
|
||||
if (r < 0)
|
||||
return log_error_errno(errno_or_else(EINVAL), "Failed to UNIX hash secret key: %m");
|
||||
|
||||
r = json_build(&e, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("credential", JSON_BUILD_BASE64(cid, cid_size)),
|
||||
JSON_BUILD_PAIR("salt", JSON_BUILD_BASE64(fido2_salt, fido2_salt_size)),
|
||||
JSON_BUILD_PAIR("hashedPassword", JSON_BUILD_STRING(hashed)),
|
||||
JSON_BUILD_PAIR("up", JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_UP))),
|
||||
JSON_BUILD_PAIR("uv", JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_UV))),
|
||||
JSON_BUILD_PAIR("clientPin", JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_PIN)))));
|
||||
r = sd_json_build(&e, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("credential", SD_JSON_BUILD_BASE64(cid, cid_size)),
|
||||
SD_JSON_BUILD_PAIR("salt", SD_JSON_BUILD_BASE64(fido2_salt, fido2_salt_size)),
|
||||
SD_JSON_BUILD_PAIR("hashedPassword", SD_JSON_BUILD_STRING(hashed)),
|
||||
SD_JSON_BUILD_PAIR("up", SD_JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_UP))),
|
||||
SD_JSON_BUILD_PAIR("uv", SD_JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_UV))),
|
||||
SD_JSON_BUILD_PAIR("clientPin", SD_JSON_BUILD_BOOLEAN(FLAGS_SET(lock_with, FIDO2ENROLL_PIN)))));
|
||||
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build FIDO2 salt JSON key object: %m");
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(*v, "privileged"));
|
||||
l = json_variant_ref(json_variant_by_key(w, "fido2HmacSalt"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(*v, "privileged"));
|
||||
l = sd_json_variant_ref(sd_json_variant_by_key(w, "fido2HmacSalt"));
|
||||
|
||||
r = json_variant_append_array(&l, e);
|
||||
r = sd_json_variant_append_array(&l, e);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed append FIDO2 salt: %m");
|
||||
|
||||
r = json_variant_set_field(&w, "fido2HmacSalt", l);
|
||||
r = sd_json_variant_set_field(&w, "fido2HmacSalt", l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set FDO2 salt: %m");
|
||||
|
||||
r = json_variant_set_field(v, "privileged", w);
|
||||
r = sd_json_variant_set_field(v, "privileged", w);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update privileged field: %m");
|
||||
|
||||
@ -118,13 +118,13 @@ static int add_fido2_salt(
|
||||
#endif
|
||||
|
||||
int identity_add_fido2_parameters(
|
||||
JsonVariant **v,
|
||||
sd_json_variant **v,
|
||||
const char *device,
|
||||
Fido2EnrollFlags lock_with,
|
||||
int cred_alg) {
|
||||
|
||||
#if HAVE_LIBFIDO2
|
||||
JsonVariant *un, *realm, *rn;
|
||||
sd_json_variant *un, *realm, *rn;
|
||||
_cleanup_(erase_and_freep) void *secret = NULL, *salt = NULL;
|
||||
_cleanup_(erase_and_freep) char *used_pin = NULL;
|
||||
size_t cid_size, salt_size, secret_size;
|
||||
@ -135,26 +135,26 @@ int identity_add_fido2_parameters(
|
||||
assert(v);
|
||||
assert(device);
|
||||
|
||||
un = json_variant_by_key(*v, "userName");
|
||||
un = sd_json_variant_by_key(*v, "userName");
|
||||
if (!un)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"userName field of user record is missing");
|
||||
if (!json_variant_is_string(un))
|
||||
if (!sd_json_variant_is_string(un))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"userName field of user record is not a string");
|
||||
|
||||
realm = json_variant_by_key(*v, "realm");
|
||||
realm = sd_json_variant_by_key(*v, "realm");
|
||||
if (realm) {
|
||||
if (!json_variant_is_string(realm))
|
||||
if (!sd_json_variant_is_string(realm))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"realm field of user record is not a string");
|
||||
|
||||
fido_un = strjoina(json_variant_string(un), json_variant_string(realm));
|
||||
fido_un = strjoina(sd_json_variant_string(un), sd_json_variant_string(realm));
|
||||
} else
|
||||
fido_un = json_variant_string(un);
|
||||
fido_un = sd_json_variant_string(un);
|
||||
|
||||
rn = json_variant_by_key(*v, "realName");
|
||||
if (rn && !json_variant_is_string(rn))
|
||||
rn = sd_json_variant_by_key(*v, "realName");
|
||||
if (rn && !sd_json_variant_is_string(rn))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"realName field of user record is not a string");
|
||||
|
||||
@ -164,7 +164,7 @@ int identity_add_fido2_parameters(
|
||||
/* rp_name= */ "Home Directory",
|
||||
/* user_id= */ fido_un, strlen(fido_un), /* We pass the user ID and name as the same */
|
||||
/* user_name= */ fido_un,
|
||||
/* user_display_name= */ rn ? json_variant_string(rn) : NULL,
|
||||
/* user_display_name= */ rn ? sd_json_variant_string(rn) : NULL,
|
||||
/* user_icon_name= */ NULL,
|
||||
/* askpw_icon_name= */ "user-home",
|
||||
/* askpw_credential= */ "home.token-pin",
|
||||
|
@ -1,7 +1,8 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "json.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "libfido2-util.h"
|
||||
|
||||
int identity_add_fido2_parameters(JsonVariant **v, const char *device, Fido2EnrollFlags lock_with, int cred_alg);
|
||||
int identity_add_fido2_parameters(sd_json_variant **v, const char *device, Fido2EnrollFlags lock_with, int cred_alg);
|
||||
|
@ -10,8 +10,8 @@
|
||||
#include "pkcs11-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
int identity_add_token_pin(JsonVariant **v, const char *pin) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL, *l = NULL;
|
||||
int identity_add_token_pin(sd_json_variant **v, const char *pin) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL, *l = NULL;
|
||||
_cleanup_strv_free_erase_ char **pins = NULL;
|
||||
int r;
|
||||
|
||||
@ -20,10 +20,10 @@ int identity_add_token_pin(JsonVariant **v, const char *pin) {
|
||||
if (isempty(pin))
|
||||
return 0;
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(*v, "secret"));
|
||||
l = json_variant_ref(json_variant_by_key(w, "tokenPin"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(*v, "secret"));
|
||||
l = sd_json_variant_ref(sd_json_variant_by_key(w, "tokenPin"));
|
||||
|
||||
r = json_variant_strv(l, &pins);
|
||||
r = sd_json_variant_strv(l, &pins);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to convert PIN array: %m");
|
||||
|
||||
@ -36,19 +36,19 @@ int identity_add_token_pin(JsonVariant **v, const char *pin) {
|
||||
|
||||
strv_uniq(pins);
|
||||
|
||||
l = json_variant_unref(l);
|
||||
l = sd_json_variant_unref(l);
|
||||
|
||||
r = json_variant_new_array_strv(&l, pins);
|
||||
r = sd_json_variant_new_array_strv(&l, pins);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to allocate new PIN array JSON: %m");
|
||||
|
||||
json_variant_sensitive(l);
|
||||
sd_json_variant_sensitive(l);
|
||||
|
||||
r = json_variant_set_field(&w, "tokenPin", l);
|
||||
r = sd_json_variant_set_field(&w, "tokenPin", l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update PIN field: %m");
|
||||
|
||||
r = json_variant_set_field(v, "secret", w);
|
||||
r = sd_json_variant_set_field(v, "secret", w);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update secret object: %m");
|
||||
|
||||
@ -57,17 +57,17 @@ int identity_add_token_pin(JsonVariant **v, const char *pin) {
|
||||
|
||||
#if HAVE_P11KIT
|
||||
|
||||
static int add_pkcs11_token_uri(JsonVariant **v, const char *uri) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
static int add_pkcs11_token_uri(sd_json_variant **v, const char *uri) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
int r;
|
||||
|
||||
assert(v);
|
||||
assert(uri);
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(*v, "pkcs11TokenUri"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(*v, "pkcs11TokenUri"));
|
||||
if (w) {
|
||||
r = json_variant_strv(w, &l);
|
||||
r = sd_json_variant_strv(w, &l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse PKCS#11 token list: %m");
|
||||
|
||||
@ -79,12 +79,12 @@ static int add_pkcs11_token_uri(JsonVariant **v, const char *uri) {
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
w = json_variant_unref(w);
|
||||
r = json_variant_new_array_strv(&w, l);
|
||||
w = sd_json_variant_unref(w);
|
||||
r = sd_json_variant_new_array_strv(&w, l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create PKCS#11 token URI JSON: %m");
|
||||
|
||||
r = json_variant_set_field(v, "pkcs11TokenUri", w);
|
||||
r = sd_json_variant_set_field(v, "pkcs11TokenUri", w);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update PKCS#11 token URI list: %m");
|
||||
|
||||
@ -92,12 +92,12 @@ static int add_pkcs11_token_uri(JsonVariant **v, const char *uri) {
|
||||
}
|
||||
|
||||
static int add_pkcs11_encrypted_key(
|
||||
JsonVariant **v,
|
||||
sd_json_variant **v,
|
||||
const char *uri,
|
||||
const void *encrypted_key, size_t encrypted_key_size,
|
||||
const void *decrypted_key, size_t decrypted_key_size) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *l = NULL, *w = NULL, *e = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *l = NULL, *w = NULL, *e = NULL;
|
||||
_cleanup_(erase_and_freep) char *base64_encoded = NULL, *hashed = NULL;
|
||||
ssize_t base64_encoded_size;
|
||||
int r;
|
||||
@ -119,32 +119,32 @@ static int add_pkcs11_encrypted_key(
|
||||
if (r < 0)
|
||||
return log_error_errno(errno_or_else(EINVAL), "Failed to UNIX hash secret key: %m");
|
||||
|
||||
r = json_build(&e, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("uri", JSON_BUILD_STRING(uri)),
|
||||
JSON_BUILD_PAIR("data", JSON_BUILD_BASE64(encrypted_key, encrypted_key_size)),
|
||||
JSON_BUILD_PAIR("hashedPassword", JSON_BUILD_STRING(hashed))));
|
||||
r = sd_json_build(&e, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("uri", SD_JSON_BUILD_STRING(uri)),
|
||||
SD_JSON_BUILD_PAIR("data", SD_JSON_BUILD_BASE64(encrypted_key, encrypted_key_size)),
|
||||
SD_JSON_BUILD_PAIR("hashedPassword", SD_JSON_BUILD_STRING(hashed))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build encrypted JSON key object: %m");
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(*v, "privileged"));
|
||||
l = json_variant_ref(json_variant_by_key(w, "pkcs11EncryptedKey"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(*v, "privileged"));
|
||||
l = sd_json_variant_ref(sd_json_variant_by_key(w, "pkcs11EncryptedKey"));
|
||||
|
||||
r = json_variant_append_array(&l, e);
|
||||
r = sd_json_variant_append_array(&l, e);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed append PKCS#11 encrypted key: %m");
|
||||
|
||||
r = json_variant_set_field(&w, "pkcs11EncryptedKey", l);
|
||||
r = sd_json_variant_set_field(&w, "pkcs11EncryptedKey", l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set PKCS#11 encrypted key: %m");
|
||||
|
||||
r = json_variant_set_field(v, "privileged", w);
|
||||
r = sd_json_variant_set_field(v, "privileged", w);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update privileged field: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int identity_add_pkcs11_key_data(JsonVariant **v, const char *uri) {
|
||||
int identity_add_pkcs11_key_data(sd_json_variant **v, const char *uri) {
|
||||
_cleanup_(erase_and_freep) void *decrypted_key = NULL, *saved_key = NULL;
|
||||
_cleanup_(erase_and_freep) char *pin = NULL;
|
||||
size_t decrypted_key_size, saved_key_size;
|
||||
|
@ -1,14 +1,14 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "json.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
int identity_add_token_pin(JsonVariant **v, const char *pin);
|
||||
int identity_add_token_pin(sd_json_variant **v, const char *pin);
|
||||
|
||||
#if HAVE_P11KIT
|
||||
int identity_add_pkcs11_key_data(JsonVariant **v, const char *token_uri);
|
||||
int identity_add_pkcs11_key_data(sd_json_variant **v, const char *token_uri);
|
||||
#else
|
||||
static inline int identity_add_pkcs11_key_data(JsonVariant **v, const char *token_uri) {
|
||||
static inline int identity_add_pkcs11_key_data(sd_json_variant **v, const char *token_uri) {
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "PKCS#11 tokens not supported on this build.");
|
||||
}
|
||||
#endif
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "errno-util.h"
|
||||
#include "glyph-util.h"
|
||||
#include "homectl-recovery-key.h"
|
||||
#include "json-util.h"
|
||||
#include "libcrypt-util.h"
|
||||
#include "memory-util.h"
|
||||
#include "qrcode-util.h"
|
||||
@ -11,46 +12,46 @@
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static int add_privileged(JsonVariant **v, const char *hashed) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *e = NULL, *w = NULL, *l = NULL;
|
||||
static int add_privileged(sd_json_variant **v, const char *hashed) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *e = NULL, *w = NULL, *l = NULL;
|
||||
int r;
|
||||
|
||||
assert(v);
|
||||
assert(hashed);
|
||||
|
||||
r = json_build(&e, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("modhex64")),
|
||||
JSON_BUILD_PAIR("hashedPassword", JSON_BUILD_STRING(hashed))));
|
||||
r = sd_json_build(&e, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("modhex64")),
|
||||
SD_JSON_BUILD_PAIR("hashedPassword", SD_JSON_BUILD_STRING(hashed))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build recover key JSON object: %m");
|
||||
|
||||
json_variant_sensitive(e);
|
||||
sd_json_variant_sensitive(e);
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(*v, "privileged"));
|
||||
l = json_variant_ref(json_variant_by_key(w, "recoveryKey"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(*v, "privileged"));
|
||||
l = sd_json_variant_ref(sd_json_variant_by_key(w, "recoveryKey"));
|
||||
|
||||
r = json_variant_append_array(&l, e);
|
||||
r = sd_json_variant_append_array(&l, e);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed append recovery key: %m");
|
||||
|
||||
r = json_variant_set_field(&w, "recoveryKey", l);
|
||||
r = sd_json_variant_set_field(&w, "recoveryKey", l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set recovery key array: %m");
|
||||
|
||||
r = json_variant_set_field(v, "privileged", w);
|
||||
r = sd_json_variant_set_field(v, "privileged", w);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update privileged field: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_public(JsonVariant **v) {
|
||||
static int add_public(sd_json_variant **v) {
|
||||
_cleanup_strv_free_ char **types = NULL;
|
||||
int r;
|
||||
|
||||
assert(v);
|
||||
|
||||
r = json_variant_strv(json_variant_by_key(*v, "recoveryKeyType"), &types);
|
||||
r = sd_json_variant_strv(sd_json_variant_by_key(*v, "recoveryKeyType"), &types);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse recovery key type list: %m");
|
||||
|
||||
@ -58,25 +59,25 @@ static int add_public(JsonVariant **v) {
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
r = json_variant_set_field_strv(v, "recoveryKeyType", types);
|
||||
r = sd_json_variant_set_field_strv(v, "recoveryKeyType", types);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update recovery key types: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_secret(JsonVariant **v, const char *password) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL, *l = NULL;
|
||||
static int add_secret(sd_json_variant **v, const char *password) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL, *l = NULL;
|
||||
_cleanup_strv_free_erase_ char **passwords = NULL;
|
||||
int r;
|
||||
|
||||
assert(v);
|
||||
assert(password);
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(*v, "secret"));
|
||||
l = json_variant_ref(json_variant_by_key(w, "password"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(*v, "secret"));
|
||||
l = sd_json_variant_ref(sd_json_variant_by_key(w, "password"));
|
||||
|
||||
r = json_variant_strv(l, &passwords);
|
||||
r = sd_json_variant_strv(l, &passwords);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to convert password array: %m");
|
||||
|
||||
@ -84,24 +85,24 @@ static int add_secret(JsonVariant **v, const char *password) {
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
r = json_variant_new_array_strv(&l, passwords);
|
||||
r = sd_json_variant_new_array_strv(&l, passwords);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to allocate new password array JSON: %m");
|
||||
|
||||
json_variant_sensitive(l);
|
||||
sd_json_variant_sensitive(l);
|
||||
|
||||
r = json_variant_set_field(&w, "password", l);
|
||||
r = sd_json_variant_set_field(&w, "password", l);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update password field: %m");
|
||||
|
||||
r = json_variant_set_field(v, "secret", w);
|
||||
r = sd_json_variant_set_field(v, "secret", w);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to update secret object: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int identity_add_recovery_key(JsonVariant **v) {
|
||||
int identity_add_recovery_key(sd_json_variant **v) {
|
||||
_cleanup_(erase_and_freep) char *password = NULL, *hashed = NULL;
|
||||
int r;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "json.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
int identity_add_recovery_key(JsonVariant **v);
|
||||
int identity_add_recovery_key(sd_json_variant **v);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,7 @@
|
||||
#include "strv.h"
|
||||
|
||||
int bus_message_read_secret(sd_bus_message *m, UserRecord **ret, sd_bus_error *error) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *full = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *full = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *hr = NULL;
|
||||
unsigned line = 0, column = 0;
|
||||
const char *json;
|
||||
@ -19,11 +19,11 @@ int bus_message_read_secret(sd_bus_message *m, UserRecord **ret, sd_bus_error *e
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_parse(json, JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
if (r < 0)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse JSON secret record at %u:%u: %m", line, column);
|
||||
|
||||
r = json_build(&full, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("secret", JSON_BUILD_VARIANT(v))));
|
||||
r = sd_json_build(&full, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("secret", SD_JSON_BUILD_VARIANT(v))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -40,7 +40,7 @@ int bus_message_read_secret(sd_bus_message *m, UserRecord **ret, sd_bus_error *e
|
||||
}
|
||||
|
||||
int bus_message_read_home_record(sd_bus_message *m, UserRecordLoadFlags flags, UserRecord **ret, sd_bus_error *error) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *hr = NULL;
|
||||
unsigned line = 0, column = 0;
|
||||
const char *json;
|
||||
@ -52,7 +52,7 @@ int bus_message_read_home_record(sd_bus_message *m, UserRecordLoadFlags flags, U
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_parse(json, JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
if (r < 0)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse JSON identity record at %u:%u: %m", line, column);
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "json.h"
|
||||
#include "user-record.h"
|
||||
|
||||
int bus_message_read_secret(sd_bus_message *m, UserRecord **ret, sd_bus_error *error);
|
||||
|
@ -133,7 +133,7 @@ int bus_home_get_record_json(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_format(augmented->json, 0, ret);
|
||||
r = sd_json_variant_format(augmented->json, 0, ret);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -23,8 +23,9 @@
|
||||
#include "fs-util.h"
|
||||
#include "glyph-util.h"
|
||||
#include "home-util.h"
|
||||
#include "homed-home-bus.h"
|
||||
#include "homed-home.h"
|
||||
#include "homed-home-bus.h"
|
||||
#include "json-util.h"
|
||||
#include "memfd-util.h"
|
||||
#include "missing_magic.h"
|
||||
#include "missing_mman.h"
|
||||
@ -266,12 +267,12 @@ int home_set_record(Home *h, UserRecord *hr) {
|
||||
return -EINVAL;
|
||||
|
||||
if (FLAGS_SET(h->record->mask, USER_RECORD_STATUS)) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
/* Hmm, the existing record has status fields? If so, copy them over */
|
||||
|
||||
v = json_variant_ref(hr->json);
|
||||
r = json_variant_set_field(&v, "status", json_variant_by_key(h->record->json, "status"));
|
||||
v = sd_json_variant_ref(hr->json);
|
||||
r = sd_json_variant_set_field(&v, "status", sd_json_variant_by_key(h->record->json, "status"));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -308,19 +309,19 @@ int home_set_record(Home *h, UserRecord *hr) {
|
||||
}
|
||||
|
||||
int home_save_record(Home *h) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *text = NULL;
|
||||
const char *fn;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
|
||||
v = json_variant_ref(h->record->json);
|
||||
r = json_variant_normalize(&v);
|
||||
v = sd_json_variant_ref(h->record->json);
|
||||
r = sd_json_variant_normalize(&v);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "User record could not be normalized.");
|
||||
|
||||
r = json_variant_format(v, JSON_FORMAT_PRETTY|JSON_FORMAT_NEWLINE, &text);
|
||||
r = sd_json_variant_format(v, SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_NEWLINE, &text);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -523,7 +524,7 @@ static void home_set_state(Home *h, HomeState state) {
|
||||
}
|
||||
|
||||
static int home_parse_worker_stdout(int _fd, UserRecord **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_close_ int fd = _fd; /* take possession, even on failure */
|
||||
_cleanup_(user_record_unrefp) UserRecord *hr = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
@ -559,7 +560,7 @@ static int home_parse_worker_stdout(int _fd, UserRecord **ret) {
|
||||
rewind(f);
|
||||
}
|
||||
|
||||
r = json_parse_file(f, "stdout", JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
r = sd_json_parse_file(f, "stdout", SD_JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse identity at %u:%u: %m", line, column);
|
||||
|
||||
@ -1199,7 +1200,7 @@ static int home_start_work(
|
||||
UserRecord *secret,
|
||||
Hashmap *blobs,
|
||||
uint64_t flags) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *fdmap = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *fdmap = NULL;
|
||||
_cleanup_(erase_and_freep) char *formatted = NULL;
|
||||
_cleanup_close_ int stdin_fd = -EBADF, stdout_fd = -EBADF;
|
||||
_cleanup_free_ int *blob_fds = NULL;
|
||||
@ -1216,16 +1217,16 @@ static int home_start_work(
|
||||
assert(h->worker_stdout_fd < 0);
|
||||
assert(!h->worker_event_source);
|
||||
|
||||
v = json_variant_ref(hr->json);
|
||||
v = sd_json_variant_ref(hr->json);
|
||||
|
||||
if (secret) {
|
||||
JsonVariant *sub = NULL;
|
||||
sd_json_variant *sub = NULL;
|
||||
|
||||
sub = json_variant_by_key(secret->json, "secret");
|
||||
sub = sd_json_variant_by_key(secret->json, "secret");
|
||||
if (!sub)
|
||||
return -ENOKEY;
|
||||
|
||||
r = json_variant_set_field(&v, "secret", sub);
|
||||
r = sd_json_variant_set_field(&v, "secret", sub);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -1242,26 +1243,26 @@ static int home_start_work(
|
||||
/* homework needs to be able to tell the difference between blobs being null
|
||||
* (the fdmap field is completely missing) and it being empty (the field is an
|
||||
* empty object) */
|
||||
r = json_variant_new_object(&fdmap, NULL, 0);
|
||||
r = sd_json_variant_new_object(&fdmap, NULL, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
HASHMAP_FOREACH_KEY(fd_ptr, blob_filename, blobs) {
|
||||
blob_fds[i] = PTR_TO_FD(fd_ptr);
|
||||
|
||||
r = json_variant_set_field_integer(&fdmap, blob_filename, i);
|
||||
r = sd_json_variant_set_field_integer(&fdmap, blob_filename, i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
r = json_variant_set_field(&v, HOMEWORK_BLOB_FDMAP_FIELD, fdmap);
|
||||
r = sd_json_variant_set_field(&v, HOMEWORK_BLOB_FDMAP_FIELD, fdmap);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = json_variant_format(v, 0, &formatted);
|
||||
r = sd_json_variant_format(v, 0, &formatted);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -1666,20 +1667,20 @@ int home_remove(Home *h, sd_bus_error *error) {
|
||||
}
|
||||
|
||||
static int user_record_extend_with_binding(UserRecord *hr, UserRecord *with_binding, UserRecordLoadFlags flags, UserRecord **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *nr = NULL;
|
||||
JsonVariant *binding;
|
||||
sd_json_variant *binding;
|
||||
int r;
|
||||
|
||||
assert(hr);
|
||||
assert(with_binding);
|
||||
assert(ret);
|
||||
|
||||
assert_se(v = json_variant_ref(hr->json));
|
||||
assert_se(v = sd_json_variant_ref(hr->json));
|
||||
|
||||
binding = json_variant_by_key(with_binding->json, "binding");
|
||||
binding = sd_json_variant_by_key(with_binding->json, "binding");
|
||||
if (binding) {
|
||||
r = json_variant_set_field(&v, "binding", binding);
|
||||
r = sd_json_variant_set_field(&v, "binding", binding);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -2611,7 +2612,7 @@ int home_augment_status(
|
||||
UserRecord **ret) {
|
||||
|
||||
uint64_t disk_size = UINT64_MAX, disk_usage = UINT64_MAX, disk_free = UINT64_MAX, disk_ceiling = UINT64_MAX, disk_floor = UINT64_MAX;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *j = NULL, *v = NULL, *m = NULL, *status = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL, *v = NULL, *m = NULL, *status = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *ur = NULL;
|
||||
statfs_f_type_t magic;
|
||||
const char *fstype;
|
||||
@ -2653,42 +2654,42 @@ int home_augment_status(
|
||||
if (disk_ceiling == UINT64_MAX || disk_ceiling > USER_DISK_SIZE_MAX)
|
||||
disk_ceiling = USER_DISK_SIZE_MAX;
|
||||
|
||||
r = json_build(&status,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("state", JSON_BUILD_STRING(home_state_to_string(state))),
|
||||
JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Home")),
|
||||
JSON_BUILD_PAIR("useFallback", JSON_BUILD_BOOLEAN(!HOME_STATE_IS_ACTIVE(state))),
|
||||
JSON_BUILD_PAIR("fallbackShell", JSON_BUILD_CONST_STRING(BINDIR "/systemd-home-fallback-shell")),
|
||||
JSON_BUILD_PAIR("fallbackHomeDirectory", JSON_BUILD_CONST_STRING("/")),
|
||||
JSON_BUILD_PAIR_CONDITION(disk_size != UINT64_MAX, "diskSize", JSON_BUILD_UNSIGNED(disk_size)),
|
||||
JSON_BUILD_PAIR_CONDITION(disk_usage != UINT64_MAX, "diskUsage", JSON_BUILD_UNSIGNED(disk_usage)),
|
||||
JSON_BUILD_PAIR_CONDITION(disk_free != UINT64_MAX, "diskFree", JSON_BUILD_UNSIGNED(disk_free)),
|
||||
JSON_BUILD_PAIR_CONDITION(disk_ceiling != UINT64_MAX, "diskCeiling", JSON_BUILD_UNSIGNED(disk_ceiling)),
|
||||
JSON_BUILD_PAIR_CONDITION(disk_floor != UINT64_MAX, "diskFloor", JSON_BUILD_UNSIGNED(disk_floor)),
|
||||
JSON_BUILD_PAIR_CONDITION(h->signed_locally >= 0, "signedLocally", JSON_BUILD_BOOLEAN(h->signed_locally)),
|
||||
JSON_BUILD_PAIR_CONDITION(fstype, "fileSystemType", JSON_BUILD_STRING(fstype)),
|
||||
JSON_BUILD_PAIR_CONDITION(access_mode != MODE_INVALID, "accessMode", JSON_BUILD_UNSIGNED(access_mode))
|
||||
r = sd_json_build(&status,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("state", SD_JSON_BUILD_STRING(home_state_to_string(state))),
|
||||
SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Home")),
|
||||
SD_JSON_BUILD_PAIR("useFallback", SD_JSON_BUILD_BOOLEAN(!HOME_STATE_IS_ACTIVE(state))),
|
||||
SD_JSON_BUILD_PAIR("fallbackShell", JSON_BUILD_CONST_STRING(BINDIR "/systemd-home-fallback-shell")),
|
||||
SD_JSON_BUILD_PAIR("fallbackHomeDirectory", JSON_BUILD_CONST_STRING("/")),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(disk_size != UINT64_MAX, "diskSize", SD_JSON_BUILD_UNSIGNED(disk_size)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(disk_usage != UINT64_MAX, "diskUsage", SD_JSON_BUILD_UNSIGNED(disk_usage)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(disk_free != UINT64_MAX, "diskFree", SD_JSON_BUILD_UNSIGNED(disk_free)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(disk_ceiling != UINT64_MAX, "diskCeiling", SD_JSON_BUILD_UNSIGNED(disk_ceiling)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(disk_floor != UINT64_MAX, "diskFloor", SD_JSON_BUILD_UNSIGNED(disk_floor)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(h->signed_locally >= 0, "signedLocally", SD_JSON_BUILD_BOOLEAN(h->signed_locally)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!fstype, "fileSystemType", SD_JSON_BUILD_STRING(fstype)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(access_mode != MODE_INVALID, "accessMode", SD_JSON_BUILD_UNSIGNED(access_mode))
|
||||
));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
j = json_variant_ref(h->record->json);
|
||||
v = json_variant_ref(json_variant_by_key(j, "status"));
|
||||
m = json_variant_ref(json_variant_by_key(v, SD_ID128_TO_STRING(id)));
|
||||
j = sd_json_variant_ref(h->record->json);
|
||||
v = sd_json_variant_ref(sd_json_variant_by_key(j, "status"));
|
||||
m = sd_json_variant_ref(sd_json_variant_by_key(v, SD_ID128_TO_STRING(id)));
|
||||
|
||||
r = json_variant_filter(&m, STRV_MAKE("diskSize", "diskUsage", "diskFree", "diskCeiling", "diskFloor", "signedLocally"));
|
||||
r = sd_json_variant_filter(&m, STRV_MAKE("diskSize", "diskUsage", "diskFree", "diskCeiling", "diskFloor", "signedLocally"));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_merge_object(&m, status);
|
||||
r = sd_json_variant_merge_object(&m, status);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&v, SD_ID128_TO_STRING(id), m);
|
||||
r = sd_json_variant_set_field(&v, SD_ID128_TO_STRING(id), m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&j, "status", v);
|
||||
r = sd_json_variant_set_field(&j, "status", v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -360,7 +360,7 @@ static int manager_add_home_by_record(
|
||||
int dir_fd,
|
||||
const char *fname) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *hr = NULL;
|
||||
unsigned line, column;
|
||||
int r, is_signed;
|
||||
@ -382,11 +382,11 @@ static int manager_add_home_by_record(
|
||||
if (st.st_size == 0)
|
||||
goto unlink_this_file;
|
||||
|
||||
r = json_parse_file_at(NULL, dir_fd, fname, JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
r = sd_json_parse_file_at(NULL, dir_fd, fname, SD_JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse identity record at %s:%u%u: %m", fname, line, column);
|
||||
|
||||
if (json_variant_is_blank_object(v))
|
||||
if (sd_json_variant_is_blank_object(v))
|
||||
goto unlink_this_file;
|
||||
|
||||
hr = user_record_new();
|
||||
|
@ -34,7 +34,7 @@ static bool client_is_trusted(Varlink *link, Home *h) {
|
||||
return peer_uid == 0 || peer_uid == h->uid;
|
||||
}
|
||||
|
||||
static int build_user_json(Home *h, bool trusted, JsonVariant **ret) {
|
||||
static int build_user_json(Home *h, bool trusted, sd_json_variant **ret) {
|
||||
_cleanup_(user_record_unrefp) UserRecord *augmented = NULL;
|
||||
UserRecordLoadFlags flags;
|
||||
int r;
|
||||
@ -52,9 +52,9 @@ static int build_user_json(Home *h, bool trusted, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return json_build(ret, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("record", JSON_BUILD_VARIANT(augmented->json)),
|
||||
JSON_BUILD_PAIR("incomplete", JSON_BUILD_BOOLEAN(augmented->incomplete))));
|
||||
return sd_json_build(ret, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_VARIANT(augmented->json)),
|
||||
SD_JSON_BUILD_PAIR("incomplete", SD_JSON_BUILD_BOOLEAN(augmented->incomplete))));
|
||||
}
|
||||
|
||||
static bool home_user_match_lookup_parameters(LookupParameters *p, Home *h) {
|
||||
@ -70,16 +70,16 @@ static bool home_user_match_lookup_parameters(LookupParameters *p, Home *h) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "uid", JSON_VARIANT_UNSIGNED, json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 },
|
||||
{ "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 },
|
||||
{ "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
LookupParameters p = {
|
||||
.uid = UID_INVALID,
|
||||
};
|
||||
@ -118,7 +118,7 @@ int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = json_variant_unref(v);
|
||||
v = sd_json_variant_unref(v);
|
||||
}
|
||||
|
||||
trusted = client_is_trusted(link, h);
|
||||
@ -149,7 +149,7 @@ int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
return varlink_reply(link, v);
|
||||
}
|
||||
|
||||
static int build_group_json(Home *h, JsonVariant **ret) {
|
||||
static int build_group_json(Home *h, sd_json_variant **ret) {
|
||||
_cleanup_(group_record_unrefp) GroupRecord *g = NULL;
|
||||
int r;
|
||||
|
||||
@ -167,9 +167,9 @@ static int build_group_json(Home *h, JsonVariant **ret) {
|
||||
assert(!FLAGS_SET(g->mask, USER_RECORD_SECRET));
|
||||
assert(!FLAGS_SET(g->mask, USER_RECORD_PRIVILEGED));
|
||||
|
||||
return json_build(ret,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("record", JSON_BUILD_VARIANT(g->json))));
|
||||
return sd_json_build(ret,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_VARIANT(g->json))));
|
||||
}
|
||||
|
||||
static bool home_group_match_lookup_parameters(LookupParameters *p, Home *h) {
|
||||
@ -185,16 +185,16 @@ static bool home_group_match_lookup_parameters(LookupParameters *p, Home *h) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "gid", JSON_VARIANT_UNSIGNED, json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 },
|
||||
{ "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 },
|
||||
{ "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
LookupParameters p = {
|
||||
.gid = GID_INVALID,
|
||||
};
|
||||
@ -227,7 +227,7 @@ int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, VarlinkMe
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = json_variant_unref(v);
|
||||
v = sd_json_variant_unref(v);
|
||||
}
|
||||
|
||||
r = build_group_json(h, &v);
|
||||
@ -254,12 +254,12 @@ int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, VarlinkMe
|
||||
return varlink_reply(link, v);
|
||||
}
|
||||
|
||||
int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), JSON_SAFE },
|
||||
{ "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_SAFE },
|
||||
{ "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -288,14 +288,14 @@ int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
if (!strv_contains(h->record->member_of, p.group_name))
|
||||
return varlink_error(link, "io.systemd.UserDatabase.NoRecordFound", NULL);
|
||||
|
||||
return varlink_replyb(link, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(h->user_name)),
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(p.group_name))));
|
||||
return varlink_replyb(link, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(h->user_name)),
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(p.group_name))));
|
||||
}
|
||||
|
||||
STRV_FOREACH(i, h->record->member_of) {
|
||||
if (last) {
|
||||
r = varlink_notifyb(link, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(h->user_name)),
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(last))));
|
||||
r = varlink_notifyb(link, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(h->user_name)),
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -304,8 +304,8 @@ int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
}
|
||||
|
||||
if (last)
|
||||
return varlink_replyb(link, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(h->user_name)),
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(last))));
|
||||
return varlink_replyb(link, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(h->user_name)),
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last))));
|
||||
|
||||
} else if (p.group_name) {
|
||||
const char *last = NULL;
|
||||
@ -316,8 +316,8 @@ int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
continue;
|
||||
|
||||
if (last) {
|
||||
r = varlink_notifyb(link, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(last)),
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(p.group_name))));
|
||||
r = varlink_notifyb(link, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last)),
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(p.group_name))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -326,8 +326,8 @@ int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
}
|
||||
|
||||
if (last)
|
||||
return varlink_replyb(link, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(last)),
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(p.group_name))));
|
||||
return varlink_replyb(link, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last)),
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(p.group_name))));
|
||||
} else {
|
||||
const char *last_user_name = NULL, *last_group_name = NULL;
|
||||
|
||||
@ -337,8 +337,8 @@ int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
if (last_user_name) {
|
||||
assert(last_group_name);
|
||||
|
||||
r = varlink_notifyb(link, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(last_user_name)),
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(last_group_name))));
|
||||
r = varlink_notifyb(link, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last_user_name)),
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last_group_name))));
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -350,8 +350,8 @@ int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
|
||||
if (last_user_name) {
|
||||
assert(last_group_name);
|
||||
return varlink_replyb(link, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(last_user_name)),
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(last_group_name))));
|
||||
return varlink_replyb(link, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(last_user_name)),
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(last_group_name))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,6 @@
|
||||
|
||||
#include "homed-manager.h"
|
||||
|
||||
int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "homework-luks.h"
|
||||
#include "homework-mount.h"
|
||||
#include "io-util.h"
|
||||
#include "json-util.h"
|
||||
#include "keyring-util.h"
|
||||
#include "memory-util.h"
|
||||
#include "missing_magic.h"
|
||||
@ -825,7 +826,7 @@ static int luks_validate_home_record(
|
||||
assert(h);
|
||||
|
||||
for (int token = 0; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *rr = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *rr = NULL;
|
||||
_cleanup_(EVP_CIPHER_CTX_freep) EVP_CIPHER_CTX *context = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *lhr = NULL;
|
||||
_cleanup_free_ void *encrypted = NULL, *iv = NULL;
|
||||
@ -834,7 +835,7 @@ static int luks_validate_home_record(
|
||||
_cleanup_free_ char *decrypted = NULL;
|
||||
const char *text, *type;
|
||||
crypt_token_info state;
|
||||
JsonVariant *jr, *jiv;
|
||||
sd_json_variant *jr, *jiv;
|
||||
unsigned line, column;
|
||||
const EVP_CIPHER *cc;
|
||||
|
||||
@ -853,22 +854,22 @@ static int luks_validate_home_record(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to read LUKS token %i: %m", token);
|
||||
|
||||
r = json_parse(text, JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
r = sd_json_parse(text, SD_JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse LUKS token JSON data %u:%u: %m", line, column);
|
||||
|
||||
jr = json_variant_by_key(v, "record");
|
||||
jr = sd_json_variant_by_key(v, "record");
|
||||
if (!jr)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "LUKS token lacks 'record' field.");
|
||||
jiv = json_variant_by_key(v, "iv");
|
||||
jiv = sd_json_variant_by_key(v, "iv");
|
||||
if (!jiv)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "LUKS token lacks 'iv' field.");
|
||||
|
||||
r = json_variant_unbase64(jr, &encrypted, &encrypted_size);
|
||||
r = sd_json_variant_unbase64(jr, &encrypted, &encrypted_size);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to base64 decode record: %m");
|
||||
|
||||
r = json_variant_unbase64(jiv, &iv, &iv_size);
|
||||
r = sd_json_variant_unbase64(jiv, &iv, &iv_size);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to base64 decode IV: %m");
|
||||
|
||||
@ -906,7 +907,7 @@ static int luks_validate_home_record(
|
||||
|
||||
decrypted[decrypted_size] = 0;
|
||||
|
||||
r = json_parse(decrypted, JSON_PARSE_SENSITIVE, &rr, NULL, NULL);
|
||||
r = sd_json_parse(decrypted, SD_JSON_PARSE_SENSITIVE, &rr, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse decrypted JSON record, refusing.");
|
||||
|
||||
@ -941,7 +942,7 @@ static int format_luks_token_text(
|
||||
|
||||
int r, encrypted_size_out1 = 0, encrypted_size_out2 = 0, iv_size, key_size;
|
||||
_cleanup_(EVP_CIPHER_CTX_freep) EVP_CIPHER_CTX *context = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ void *iv = NULL, *encrypted = NULL;
|
||||
size_t text_length, encrypted_size;
|
||||
_cleanup_free_ char *text = NULL;
|
||||
@ -976,7 +977,7 @@ static int format_luks_token_text(
|
||||
if (EVP_EncryptInit_ex(context, cc, NULL, volume_key, iv) != 1)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to initialize encryption context.");
|
||||
|
||||
r = json_variant_format(hr->json, 0, &text);
|
||||
r = sd_json_variant_format(hr->json, 0, &text);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format user record for LUKS: %m");
|
||||
|
||||
@ -997,16 +998,16 @@ static int format_luks_token_text(
|
||||
|
||||
assert((size_t) encrypted_size_out1 + (size_t) encrypted_size_out2 <= encrypted_size);
|
||||
|
||||
r = json_build(&v,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("systemd-homed")),
|
||||
JSON_BUILD_PAIR("keyslots", JSON_BUILD_EMPTY_ARRAY),
|
||||
JSON_BUILD_PAIR("record", JSON_BUILD_BASE64(encrypted, encrypted_size_out1 + encrypted_size_out2)),
|
||||
JSON_BUILD_PAIR("iv", JSON_BUILD_BASE64(iv, iv_size))));
|
||||
r = sd_json_build(&v,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("type", JSON_BUILD_CONST_STRING("systemd-homed")),
|
||||
SD_JSON_BUILD_PAIR("keyslots", SD_JSON_BUILD_EMPTY_ARRAY),
|
||||
SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_BASE64(encrypted, encrypted_size_out1 + encrypted_size_out2)),
|
||||
SD_JSON_BUILD_PAIR("iv", SD_JSON_BUILD_BASE64(iv, iv_size))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to prepare LUKS JSON token object: %m");
|
||||
|
||||
r = json_variant_format(v, 0, ret);
|
||||
r = sd_json_variant_format(v, 0, ret);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format encrypted user record for LUKS: %m");
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "home-util.h"
|
||||
#include "homework.h"
|
||||
#include "homework-blob.h"
|
||||
#include "homework-cifs.h"
|
||||
#include "homework-directory.h"
|
||||
@ -22,7 +23,7 @@
|
||||
#include "homework-luks.h"
|
||||
#include "homework-mount.h"
|
||||
#include "homework-pkcs11.h"
|
||||
#include "homework.h"
|
||||
#include "json-util.h"
|
||||
#include "libcrypt-util.h"
|
||||
#include "main-func.h"
|
||||
#include "memory-util.h"
|
||||
@ -80,7 +81,7 @@ int user_record_authenticate(
|
||||
|
||||
/* First, let's see if we already have a volume key from the keyring */
|
||||
if (cache->volume_key &&
|
||||
json_variant_is_blank_object(json_variant_by_key(secret->json, "secret"))) {
|
||||
sd_json_variant_is_blank_object(sd_json_variant_by_key(secret->json, "secret"))) {
|
||||
log_info("LUKS volume key from keyring unlocks user record.");
|
||||
return 1;
|
||||
}
|
||||
@ -538,7 +539,7 @@ int home_sync_and_statfs(int root_fd, struct statfs *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_identity_file(int root_fd, JsonVariant **ret) {
|
||||
static int read_identity_file(int root_fd, sd_json_variant **ret) {
|
||||
_cleanup_fclose_ FILE *identity_file = NULL;
|
||||
_cleanup_close_ int identity_fd = -EBADF;
|
||||
unsigned line, column;
|
||||
@ -559,7 +560,7 @@ static int read_identity_file(int root_fd, JsonVariant **ret) {
|
||||
if (!identity_file)
|
||||
return log_oom();
|
||||
|
||||
r = json_parse_file(identity_file, ".identity", JSON_PARSE_SENSITIVE, ret, &line, &column);
|
||||
r = sd_json_parse_file(identity_file, ".identity", SD_JSON_PARSE_SENSITIVE, ret, &line, &column);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "[.identity:%u:%u] Failed to parse JSON data: %m", line, column);
|
||||
|
||||
@ -568,8 +569,8 @@ static int read_identity_file(int root_fd, JsonVariant **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_identity_file(int root_fd, JsonVariant *v, uid_t uid) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *normalized = NULL;
|
||||
static int write_identity_file(int root_fd, sd_json_variant *v, uid_t uid) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *normalized = NULL;
|
||||
_cleanup_fclose_ FILE *identity_file = NULL;
|
||||
_cleanup_close_ int identity_fd = -EBADF;
|
||||
_cleanup_free_ char *fn = NULL;
|
||||
@ -578,9 +579,9 @@ static int write_identity_file(int root_fd, JsonVariant *v, uid_t uid) {
|
||||
assert(root_fd >= 0);
|
||||
assert(v);
|
||||
|
||||
normalized = json_variant_ref(v);
|
||||
normalized = sd_json_variant_ref(v);
|
||||
|
||||
r = json_variant_normalize(&normalized);
|
||||
r = sd_json_variant_normalize(&normalized);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to normalize user record, ignoring: %m");
|
||||
|
||||
@ -598,7 +599,7 @@ static int write_identity_file(int root_fd, JsonVariant *v, uid_t uid) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
json_variant_dump(normalized, JSON_FORMAT_PRETTY, identity_file, NULL);
|
||||
sd_json_variant_dump(normalized, SD_JSON_FORMAT_PRETTY, identity_file, NULL);
|
||||
|
||||
r = fflush_and_check(identity_file);
|
||||
if (r < 0) {
|
||||
@ -635,7 +636,7 @@ int home_load_embedded_identity(
|
||||
UserRecord **ret_new_home) {
|
||||
|
||||
_cleanup_(user_record_unrefp) UserRecord *embedded_home = NULL, *intermediate_home = NULL, *new_home = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
@ -1977,14 +1978,14 @@ static int home_unlock(UserRecord *h) {
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_(user_record_unrefp) UserRecord *home = NULL, *new_home = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_fclose_ FILE *opened_file = NULL;
|
||||
_cleanup_hashmap_free_ Hashmap *blobs = NULL;
|
||||
unsigned line = 0, column = 0;
|
||||
const char *json_path = NULL, *blob_filename;
|
||||
FILE *json_file;
|
||||
usec_t start;
|
||||
JsonVariant *fdmap, *blob_fd_variant;
|
||||
sd_json_variant *fdmap, *blob_fd_variant;
|
||||
int r;
|
||||
|
||||
start = now(CLOCK_MONOTONIC);
|
||||
@ -2011,11 +2012,11 @@ static int run(int argc, char *argv[]) {
|
||||
json_file = stdin;
|
||||
}
|
||||
|
||||
r = json_parse_file(json_file, json_path, JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
r = sd_json_parse_file(json_file, json_path, SD_JSON_PARSE_SENSITIVE, &v, &line, &column);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "[%s:%u:%u] Failed to parse JSON data: %m", json_path, line, column);
|
||||
|
||||
fdmap = json_variant_by_key(v, HOMEWORK_BLOB_FDMAP_FIELD);
|
||||
fdmap = sd_json_variant_by_key(v, HOMEWORK_BLOB_FDMAP_FIELD);
|
||||
if (fdmap) {
|
||||
r = hashmap_ensure_allocated(&blobs, &blob_fd_hash_ops);
|
||||
if (r < 0)
|
||||
@ -2025,10 +2026,10 @@ static int run(int argc, char *argv[]) {
|
||||
_cleanup_free_ char *filename = NULL;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
assert(json_variant_is_integer(blob_fd_variant));
|
||||
assert(json_variant_integer(blob_fd_variant) >= 0);
|
||||
assert(json_variant_integer(blob_fd_variant) <= INT_MAX - SD_LISTEN_FDS_START);
|
||||
fd = SD_LISTEN_FDS_START + (int) json_variant_integer(blob_fd_variant);
|
||||
assert(sd_json_variant_is_integer(blob_fd_variant));
|
||||
assert(sd_json_variant_integer(blob_fd_variant) >= 0);
|
||||
assert(sd_json_variant_integer(blob_fd_variant) <= INT_MAX - SD_LISTEN_FDS_START);
|
||||
fd = SD_LISTEN_FDS_START + (int) sd_json_variant_integer(blob_fd_variant);
|
||||
|
||||
if (DEBUG_LOGGING) {
|
||||
_cleanup_free_ char *resolved = NULL;
|
||||
@ -2052,7 +2053,7 @@ static int run(int argc, char *argv[]) {
|
||||
TAKE_FD(fd);
|
||||
}
|
||||
|
||||
r = json_variant_filter(&v, STRV_MAKE(HOMEWORK_BLOB_FDMAP_FIELD));
|
||||
r = sd_json_variant_filter(&v, STRV_MAKE(HOMEWORK_BLOB_FDMAP_FIELD));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to strip internal fdmap from JSON: %m");
|
||||
}
|
||||
@ -2141,7 +2142,7 @@ static int run(int argc, char *argv[]) {
|
||||
* prepare a fresh record, send to us, and only if it works use it without having to keep a local
|
||||
* copy. */
|
||||
if (new_home)
|
||||
json_variant_dump(new_home->json, JSON_FORMAT_NEWLINE, stdout, NULL);
|
||||
sd_json_variant_dump(new_home->json, SD_JSON_FORMAT_NEWLINE, stdout, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ static int acquire_user_record(
|
||||
PamBusData **bus_data) {
|
||||
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *ur = NULL;
|
||||
_cleanup_free_ char *homed_field = NULL;
|
||||
const char *json = NULL;
|
||||
@ -208,7 +208,7 @@ static int acquire_user_record(
|
||||
TAKE_PTR(json_copy);
|
||||
}
|
||||
|
||||
r = json_parse(json, JSON_PARSE_SENSITIVE, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_SENSITIVE, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return pam_syslog_errno(handle, LOG_ERR, r, "Failed to parse JSON user record: %m");
|
||||
|
||||
|
@ -4,13 +4,14 @@
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "json-util.h"
|
||||
#include "memstream-util.h"
|
||||
#include "openssl-util.h"
|
||||
#include "user-record-sign.h"
|
||||
|
||||
static int user_record_signable_json(UserRecord *ur, char **ret) {
|
||||
_cleanup_(user_record_unrefp) UserRecord *reduced = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *j = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
|
||||
int r;
|
||||
|
||||
assert(ur);
|
||||
@ -20,18 +21,18 @@ static int user_record_signable_json(UserRecord *ur, char **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
j = json_variant_ref(reduced->json);
|
||||
j = sd_json_variant_ref(reduced->json);
|
||||
|
||||
r = json_variant_normalize(&j);
|
||||
r = sd_json_variant_normalize(&j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return json_variant_format(j, 0, ret);
|
||||
return sd_json_variant_format(j, 0, ret);
|
||||
}
|
||||
|
||||
int user_record_sign(UserRecord *ur, EVP_PKEY *private_key, UserRecord **ret) {
|
||||
_cleanup_(memstream_done) MemStream m = {};
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *signed_ur = NULL;
|
||||
_cleanup_free_ char *text = NULL, *key = NULL;
|
||||
_cleanup_free_ void *signature = NULL;
|
||||
@ -62,19 +63,19 @@ int user_record_sign(UserRecord *ur, EVP_PKEY *private_key, UserRecord **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = json_variant_ref(ur->json);
|
||||
v = sd_json_variant_ref(ur->json);
|
||||
|
||||
r = json_variant_set_fieldb(
|
||||
r = sd_json_variant_set_fieldb(
|
||||
&v,
|
||||
"signature",
|
||||
JSON_BUILD_ARRAY(
|
||||
JSON_BUILD_OBJECT(JSON_BUILD_PAIR("data", JSON_BUILD_BASE64(signature, signature_size)),
|
||||
JSON_BUILD_PAIR("key", JSON_BUILD_STRING(key)))));
|
||||
SD_JSON_BUILD_ARRAY(
|
||||
SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR("data", SD_JSON_BUILD_BASE64(signature, signature_size)),
|
||||
SD_JSON_BUILD_PAIR("key", SD_JSON_BUILD_STRING(key)))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (DEBUG_LOGGING)
|
||||
json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR_AUTO, NULL, NULL);
|
||||
sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL);
|
||||
|
||||
signed_ur = user_record_new();
|
||||
if (!signed_ur)
|
||||
@ -91,20 +92,20 @@ int user_record_sign(UserRecord *ur, EVP_PKEY *private_key, UserRecord **ret) {
|
||||
int user_record_verify(UserRecord *ur, EVP_PKEY *public_key) {
|
||||
_cleanup_free_ char *text = NULL;
|
||||
unsigned n_good = 0, n_bad = 0;
|
||||
JsonVariant *array, *e;
|
||||
sd_json_variant *array, *e;
|
||||
int r;
|
||||
|
||||
assert(ur);
|
||||
assert(public_key);
|
||||
|
||||
array = json_variant_by_key(ur->json, "signature");
|
||||
array = sd_json_variant_by_key(ur->json, "signature");
|
||||
if (!array)
|
||||
return USER_RECORD_UNSIGNED;
|
||||
|
||||
if (!json_variant_is_array(array))
|
||||
if (!sd_json_variant_is_array(array))
|
||||
return -EINVAL;
|
||||
|
||||
if (json_variant_elements(array) == 0)
|
||||
if (sd_json_variant_elements(array) == 0)
|
||||
return USER_RECORD_UNSIGNED;
|
||||
|
||||
r = user_record_signable_json(ur, &text);
|
||||
@ -115,16 +116,16 @@ int user_record_verify(UserRecord *ur, EVP_PKEY *public_key) {
|
||||
_cleanup_(EVP_MD_CTX_freep) EVP_MD_CTX *md_ctx = NULL;
|
||||
_cleanup_free_ void *signature = NULL;
|
||||
size_t signature_size = 0;
|
||||
JsonVariant *data;
|
||||
sd_json_variant *data;
|
||||
|
||||
if (!json_variant_is_object(e))
|
||||
if (!sd_json_variant_is_object(e))
|
||||
return -EINVAL;
|
||||
|
||||
data = json_variant_by_key(e, "data");
|
||||
data = sd_json_variant_by_key(e, "data");
|
||||
if (!data)
|
||||
return -EINVAL;
|
||||
|
||||
r = json_variant_unbase64(data, &signature, &signature_size);
|
||||
r = sd_json_variant_unbase64(data, &signature, &signature_size);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -148,14 +149,14 @@ int user_record_verify(UserRecord *ur, EVP_PKEY *public_key) {
|
||||
}
|
||||
|
||||
int user_record_has_signature(UserRecord *ur) {
|
||||
JsonVariant *array;
|
||||
sd_json_variant *array;
|
||||
|
||||
array = json_variant_by_key(ur->json, "signature");
|
||||
array = sd_json_variant_by_key(ur->json, "signature");
|
||||
if (!array)
|
||||
return false;
|
||||
|
||||
if (!json_variant_is_array(array))
|
||||
if (!sd_json_variant_is_array(array))
|
||||
return -EINVAL;
|
||||
|
||||
return json_variant_elements(array) > 0;
|
||||
return sd_json_variant_elements(array) > 0;
|
||||
}
|
||||
|
@ -2,15 +2,18 @@
|
||||
|
||||
#include <sys/xattr.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "home-util.h"
|
||||
#include "id128-util.h"
|
||||
#include "json-util.h"
|
||||
#include "libcrypt-util.h"
|
||||
#include "memory-util.h"
|
||||
#include "recovery-key.h"
|
||||
#include "mountpoint-util.h"
|
||||
#include "path-util.h"
|
||||
#include "recovery-key.h"
|
||||
#include "sha256.h"
|
||||
#include "stat-util.h"
|
||||
#include "user-record-util.h"
|
||||
@ -81,18 +84,18 @@ int user_record_synthesize(
|
||||
if (!hd)
|
||||
return -ENOMEM;
|
||||
|
||||
r = json_build(&h->json,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(user_name)),
|
||||
JSON_BUILD_PAIR_CONDITION(!!rr, "realm", JSON_BUILD_STRING(realm)),
|
||||
JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("regular")),
|
||||
JSON_BUILD_PAIR("binding", JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("imagePath", JSON_BUILD_STRING(image_path)),
|
||||
JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_STRING(hd)),
|
||||
JSON_BUILD_PAIR("storage", JSON_BUILD_STRING(user_storage_to_string(storage))),
|
||||
JSON_BUILD_PAIR("uid", JSON_BUILD_UNSIGNED(uid)),
|
||||
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(gid))))))));
|
||||
r = sd_json_build(&h->json,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(user_name)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!rr, "realm", SD_JSON_BUILD_STRING(realm)),
|
||||
SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("regular")),
|
||||
SD_JSON_BUILD_PAIR("binding", SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("imagePath", SD_JSON_BUILD_STRING(image_path)),
|
||||
SD_JSON_BUILD_PAIR("homeDirectory", SD_JSON_BUILD_STRING(hd)),
|
||||
SD_JSON_BUILD_PAIR("storage", SD_JSON_BUILD_STRING(user_storage_to_string(storage))),
|
||||
SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(uid)),
|
||||
SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(gid))))))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -141,18 +144,18 @@ int group_record_synthesize(GroupRecord *g, UserRecord *h) {
|
||||
if (!description)
|
||||
return -ENOMEM;
|
||||
|
||||
r = json_build(&g->json,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(un)),
|
||||
JSON_BUILD_PAIR_CONDITION(!!rr, "realm", JSON_BUILD_STRING(rr)),
|
||||
JSON_BUILD_PAIR("description", JSON_BUILD_STRING(description)),
|
||||
JSON_BUILD_PAIR("binding", JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(user_record_gid(h))))))),
|
||||
JSON_BUILD_PAIR_CONDITION(h->disposition >= 0, "disposition", JSON_BUILD_STRING(user_disposition_to_string(user_record_disposition(h)))),
|
||||
JSON_BUILD_PAIR("status", JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Home"))))))));
|
||||
r = sd_json_build(&g->json,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(un)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!rr, "realm", SD_JSON_BUILD_STRING(rr)),
|
||||
SD_JSON_BUILD_PAIR("description", SD_JSON_BUILD_STRING(description)),
|
||||
SD_JSON_BUILD_PAIR("binding", SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(user_record_gid(h))))))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(h->disposition >= 0, "disposition", SD_JSON_BUILD_STRING(user_disposition_to_string(user_record_disposition(h)))),
|
||||
SD_JSON_BUILD_PAIR("status", SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Home"))))))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -229,9 +232,9 @@ int user_record_reconcile(
|
||||
} else
|
||||
result = USER_RECONCILE_HOST_WON;
|
||||
} else {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *extended = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *extended = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *merged = NULL;
|
||||
JsonVariant *e;
|
||||
sd_json_variant *e;
|
||||
|
||||
/* The embedded version is newer */
|
||||
|
||||
@ -239,11 +242,11 @@ int user_record_reconcile(
|
||||
return -ESTALE;
|
||||
|
||||
/* Copy in the binding data */
|
||||
extended = json_variant_ref(embedded->json);
|
||||
extended = sd_json_variant_ref(embedded->json);
|
||||
|
||||
e = json_variant_by_key(host->json, "binding");
|
||||
e = sd_json_variant_by_key(host->json, "binding");
|
||||
if (e) {
|
||||
r = json_variant_set_field(&extended, "binding", e);
|
||||
r = sd_json_variant_set_field(&extended, "binding", e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -283,7 +286,7 @@ int user_record_add_binding(
|
||||
uid_t uid,
|
||||
gid_t gid) {
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *new_binding_entry = NULL, *binding = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *new_binding_entry = NULL, *binding = NULL;
|
||||
_cleanup_free_ char *blob = NULL, *ip = NULL, *hd = NULL, *ip_auto = NULL, *lc = NULL, *lcm = NULL, *fst = NULL;
|
||||
sd_id128_t mid;
|
||||
int r;
|
||||
@ -335,45 +338,45 @@ int user_record_add_binding(
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
r = json_build(&new_binding_entry,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("blobDirectory", JSON_BUILD_STRING(blob)),
|
||||
JSON_BUILD_PAIR_CONDITION(!!image_path, "imagePath", JSON_BUILD_STRING(image_path)),
|
||||
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(partition_uuid), "partitionUuid", JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(partition_uuid))),
|
||||
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(luks_uuid), "luksUuid", JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(luks_uuid))),
|
||||
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(fs_uuid), "fileSystemUuid", JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(fs_uuid))),
|
||||
JSON_BUILD_PAIR_CONDITION(!!luks_cipher, "luksCipher", JSON_BUILD_STRING(luks_cipher)),
|
||||
JSON_BUILD_PAIR_CONDITION(!!luks_cipher_mode, "luksCipherMode", JSON_BUILD_STRING(luks_cipher_mode)),
|
||||
JSON_BUILD_PAIR_CONDITION(luks_volume_key_size != UINT64_MAX, "luksVolumeKeySize", JSON_BUILD_UNSIGNED(luks_volume_key_size)),
|
||||
JSON_BUILD_PAIR_CONDITION(!!file_system_type, "fileSystemType", JSON_BUILD_STRING(file_system_type)),
|
||||
JSON_BUILD_PAIR_CONDITION(!!home_directory, "homeDirectory", JSON_BUILD_STRING(home_directory)),
|
||||
JSON_BUILD_PAIR_CONDITION(uid_is_valid(uid), "uid", JSON_BUILD_UNSIGNED(uid)),
|
||||
JSON_BUILD_PAIR_CONDITION(gid_is_valid(gid), "gid", JSON_BUILD_UNSIGNED(gid)),
|
||||
JSON_BUILD_PAIR_CONDITION(storage >= 0, "storage", JSON_BUILD_STRING(user_storage_to_string(storage)))));
|
||||
r = sd_json_build(&new_binding_entry,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("blobDirectory", SD_JSON_BUILD_STRING(blob)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!image_path, "imagePath", SD_JSON_BUILD_STRING(image_path)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(partition_uuid), "partitionUuid", SD_JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(partition_uuid))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(luks_uuid), "luksUuid", SD_JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(luks_uuid))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(fs_uuid), "fileSystemUuid", SD_JSON_BUILD_STRING(SD_ID128_TO_UUID_STRING(fs_uuid))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!luks_cipher, "luksCipher", SD_JSON_BUILD_STRING(luks_cipher)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!luks_cipher_mode, "luksCipherMode", SD_JSON_BUILD_STRING(luks_cipher_mode)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(luks_volume_key_size != UINT64_MAX, "luksVolumeKeySize", SD_JSON_BUILD_UNSIGNED(luks_volume_key_size)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!file_system_type, "fileSystemType", SD_JSON_BUILD_STRING(file_system_type)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!home_directory, "homeDirectory", SD_JSON_BUILD_STRING(home_directory)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(uid_is_valid(uid), "uid", SD_JSON_BUILD_UNSIGNED(uid)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(gid_is_valid(gid), "gid", SD_JSON_BUILD_UNSIGNED(gid)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(storage >= 0, "storage", SD_JSON_BUILD_STRING(user_storage_to_string(storage)))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
binding = json_variant_ref(json_variant_by_key(h->json, "binding"));
|
||||
binding = sd_json_variant_ref(sd_json_variant_by_key(h->json, "binding"));
|
||||
if (binding) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *be = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *be = NULL;
|
||||
|
||||
/* Merge the new entry with an old one, if that exists */
|
||||
be = json_variant_ref(json_variant_by_key(binding, SD_ID128_TO_STRING(mid)));
|
||||
be = sd_json_variant_ref(sd_json_variant_by_key(binding, SD_ID128_TO_STRING(mid)));
|
||||
if (be) {
|
||||
r = json_variant_merge_object(&be, new_binding_entry);
|
||||
r = sd_json_variant_merge_object(&be, new_binding_entry);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_unref(new_binding_entry);
|
||||
sd_json_variant_unref(new_binding_entry);
|
||||
new_binding_entry = TAKE_PTR(be);
|
||||
}
|
||||
}
|
||||
|
||||
r = json_variant_set_field(&binding, SD_ID128_TO_STRING(mid), new_binding_entry);
|
||||
r = sd_json_variant_set_field(&binding, SD_ID128_TO_STRING(mid), new_binding_entry);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&h->json, "binding", binding);
|
||||
r = sd_json_variant_set_field(&h->json, "binding", binding);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -634,10 +637,10 @@ int user_record_test_recovery_key(UserRecord *h, UserRecord *secret) {
|
||||
}
|
||||
|
||||
int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *new_per_machine = NULL, *midv = NULL, *midav = NULL, *ne = NULL;
|
||||
_cleanup_free_ JsonVariant **array = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *new_per_machine = NULL, *midv = NULL, *midav = NULL, *ne = NULL;
|
||||
_cleanup_free_ sd_json_variant **array = NULL;
|
||||
size_t idx = SIZE_MAX, n;
|
||||
JsonVariant *per_machine;
|
||||
sd_json_variant *per_machine;
|
||||
sd_id128_t mid;
|
||||
int r;
|
||||
|
||||
@ -650,50 +653,50 @@ int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_new_string(&midv, SD_ID128_TO_STRING(mid));
|
||||
r = sd_json_variant_new_string(&midv, SD_ID128_TO_STRING(mid));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_new_array(&midav, (JsonVariant*[]) { midv }, 1);
|
||||
r = sd_json_variant_new_array(&midav, (sd_json_variant*[]) { midv }, 1);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
per_machine = json_variant_by_key(h->json, "perMachine");
|
||||
per_machine = sd_json_variant_by_key(h->json, "perMachine");
|
||||
if (per_machine) {
|
||||
size_t i;
|
||||
|
||||
if (!json_variant_is_array(per_machine))
|
||||
if (!sd_json_variant_is_array(per_machine))
|
||||
return -EINVAL;
|
||||
|
||||
n = json_variant_elements(per_machine);
|
||||
n = sd_json_variant_elements(per_machine);
|
||||
|
||||
array = new(JsonVariant*, n + 1);
|
||||
array = new(sd_json_variant*, n + 1);
|
||||
if (!array)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
JsonVariant *m;
|
||||
sd_json_variant *m;
|
||||
|
||||
array[i] = json_variant_by_index(per_machine, i);
|
||||
array[i] = sd_json_variant_by_index(per_machine, i);
|
||||
|
||||
if (!json_variant_is_object(array[i]))
|
||||
if (!sd_json_variant_is_object(array[i]))
|
||||
return -EINVAL;
|
||||
|
||||
m = json_variant_by_key(array[i], "matchMachineId");
|
||||
m = sd_json_variant_by_key(array[i], "matchMachineId");
|
||||
if (!m) {
|
||||
/* No machineId field? Let's ignore this, but invalidate what we found so far */
|
||||
idx = SIZE_MAX;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (json_variant_equal(m, midv) ||
|
||||
json_variant_equal(m, midav)) {
|
||||
if (sd_json_variant_equal(m, midv) ||
|
||||
sd_json_variant_equal(m, midav)) {
|
||||
/* Matches exactly what we are looking for. Let's use this */
|
||||
idx = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
r = per_machine_id_match(m, JSON_PERMISSIVE);
|
||||
r = per_machine_id_match(m, SD_JSON_PERMISSIVE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
@ -705,10 +708,10 @@ int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) {
|
||||
if (idx == SIZE_MAX)
|
||||
idx = n++; /* Nothing suitable found, place new entry at end */
|
||||
else
|
||||
ne = json_variant_ref(array[idx]);
|
||||
ne = sd_json_variant_ref(array[idx]);
|
||||
|
||||
} else {
|
||||
array = new(JsonVariant*, 1);
|
||||
array = new(sd_json_variant*, 1);
|
||||
if (!array)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -717,23 +720,23 @@ int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) {
|
||||
}
|
||||
|
||||
if (!ne) {
|
||||
r = json_variant_set_field(&ne, "matchMachineId", midav);
|
||||
r = sd_json_variant_set_field(&ne, "matchMachineId", midav);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = json_variant_set_field_unsigned(&ne, "diskSize", disk_size);
|
||||
r = sd_json_variant_set_field_unsigned(&ne, "diskSize", disk_size);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert(idx < n);
|
||||
array[idx] = ne;
|
||||
|
||||
r = json_variant_new_array(&new_per_machine, array, n);
|
||||
r = sd_json_variant_new_array(&new_per_machine, array, n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&h->json, "perMachine", new_per_machine);
|
||||
r = sd_json_variant_set_field(&h->json, "perMachine", new_per_machine);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -743,7 +746,7 @@ int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) {
|
||||
}
|
||||
|
||||
int user_record_update_last_changed(UserRecord *h, bool with_password) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
usec_t n;
|
||||
int r;
|
||||
|
||||
@ -760,14 +763,14 @@ int user_record_update_last_changed(UserRecord *h, bool with_password) {
|
||||
if (h->last_password_change_usec != UINT64_MAX && h->last_password_change_usec >= n)
|
||||
return -ECHRNG;
|
||||
|
||||
v = json_variant_ref(h->json);
|
||||
v = sd_json_variant_ref(h->json);
|
||||
|
||||
r = json_variant_set_field_unsigned(&v, "lastChangeUSec", n);
|
||||
r = sd_json_variant_set_field_unsigned(&v, "lastChangeUSec", n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (with_password) {
|
||||
r = json_variant_set_field_unsigned(&v, "lastPasswordChangeUSec", n);
|
||||
r = sd_json_variant_set_field_unsigned(&v, "lastPasswordChangeUSec", n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -776,7 +779,7 @@ int user_record_update_last_changed(UserRecord *h, bool with_password) {
|
||||
|
||||
h->last_change_usec = n;
|
||||
|
||||
json_variant_unref(h->json);
|
||||
sd_json_variant_unref(h->json);
|
||||
h->json = TAKE_PTR(v);
|
||||
|
||||
h->mask |= USER_RECORD_REGULAR;
|
||||
@ -784,7 +787,7 @@ int user_record_update_last_changed(UserRecord *h, bool with_password) {
|
||||
}
|
||||
|
||||
int user_record_make_hashed_password(UserRecord *h, char **secret, bool extend) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *priv = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *priv = NULL;
|
||||
_cleanup_strv_free_ char **np = NULL;
|
||||
int r;
|
||||
|
||||
@ -813,45 +816,45 @@ int user_record_make_hashed_password(UserRecord *h, char **secret, bool extend)
|
||||
return r;
|
||||
}
|
||||
|
||||
priv = json_variant_ref(json_variant_by_key(h->json, "privileged"));
|
||||
priv = sd_json_variant_ref(sd_json_variant_by_key(h->json, "privileged"));
|
||||
|
||||
if (strv_isempty(np))
|
||||
r = json_variant_filter(&priv, STRV_MAKE("hashedPassword"));
|
||||
r = sd_json_variant_filter(&priv, STRV_MAKE("hashedPassword"));
|
||||
else {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *new_array = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *new_array = NULL;
|
||||
|
||||
r = json_variant_new_array_strv(&new_array, np);
|
||||
r = sd_json_variant_new_array_strv(&new_array, np);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&priv, "hashedPassword", new_array);
|
||||
if (r < 0)
|
||||
return r;
|
||||
r = sd_json_variant_set_field(&priv, "hashedPassword", new_array);
|
||||
}
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&h->json, "privileged", priv);
|
||||
r = sd_json_variant_set_field(&h->json, "privileged", priv);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
strv_free_and_replace(h->hashed_password, np);
|
||||
|
||||
SET_FLAG(h->mask, USER_RECORD_PRIVILEGED, !json_variant_is_blank_object(priv));
|
||||
SET_FLAG(h->mask, USER_RECORD_PRIVILEGED, !sd_json_variant_is_blank_object(priv));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int user_record_set_hashed_password(UserRecord *h, char **hashed_password) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *priv = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *priv = NULL;
|
||||
_cleanup_strv_free_ char **copy = NULL;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
|
||||
priv = json_variant_ref(json_variant_by_key(h->json, "privileged"));
|
||||
priv = sd_json_variant_ref(sd_json_variant_by_key(h->json, "privileged"));
|
||||
|
||||
if (strv_isempty(hashed_password))
|
||||
r = json_variant_filter(&priv, STRV_MAKE("hashedPassword"));
|
||||
r = sd_json_variant_filter(&priv, STRV_MAKE("hashedPassword"));
|
||||
else {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
|
||||
copy = strv_copy(hashed_password);
|
||||
if (!copy)
|
||||
@ -859,27 +862,27 @@ int user_record_set_hashed_password(UserRecord *h, char **hashed_password) {
|
||||
|
||||
strv_uniq(copy);
|
||||
|
||||
r = json_variant_new_array_strv(&array, copy);
|
||||
r = sd_json_variant_new_array_strv(&array, copy);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&priv, "hashedPassword", array);
|
||||
r = sd_json_variant_set_field(&priv, "hashedPassword", array);
|
||||
}
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&h->json, "privileged", priv);
|
||||
r = sd_json_variant_set_field(&h->json, "privileged", priv);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
strv_free_and_replace(h->hashed_password, copy);
|
||||
|
||||
SET_FLAG(h->mask, USER_RECORD_PRIVILEGED, !json_variant_is_blank_object(priv));
|
||||
SET_FLAG(h->mask, USER_RECORD_PRIVILEGED, !sd_json_variant_is_blank_object(priv));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int user_record_set_password(UserRecord *h, char **password, bool prepend) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
_cleanup_strv_free_erase_ char **e = NULL;
|
||||
int r;
|
||||
|
||||
@ -910,38 +913,38 @@ int user_record_set_password(UserRecord *h, char **password, bool prepend) {
|
||||
strv_uniq(e);
|
||||
}
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(h->json, "secret"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(h->json, "secret"));
|
||||
|
||||
if (strv_isempty(e))
|
||||
r = json_variant_filter(&w, STRV_MAKE("password"));
|
||||
r = sd_json_variant_filter(&w, STRV_MAKE("password"));
|
||||
else {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *l = NULL;
|
||||
|
||||
r = json_variant_new_array_strv(&l, e);
|
||||
r = sd_json_variant_new_array_strv(&l, e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_sensitive(l);
|
||||
sd_json_variant_sensitive(l);
|
||||
|
||||
r = json_variant_set_field(&w, "password", l);
|
||||
r = sd_json_variant_set_field(&w, "password", l);
|
||||
}
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_sensitive(w);
|
||||
sd_json_variant_sensitive(w);
|
||||
|
||||
r = json_variant_set_field(&h->json, "secret", w);
|
||||
r = sd_json_variant_set_field(&h->json, "secret", w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
strv_free_and_replace(h->password, e);
|
||||
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !json_variant_is_blank_object(w));
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !sd_json_variant_is_blank_object(w));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int user_record_set_token_pin(UserRecord *h, char **pin, bool prepend) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
_cleanup_strv_free_erase_ char **e = NULL;
|
||||
int r;
|
||||
|
||||
@ -972,126 +975,126 @@ int user_record_set_token_pin(UserRecord *h, char **pin, bool prepend) {
|
||||
strv_uniq(e);
|
||||
}
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(h->json, "secret"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(h->json, "secret"));
|
||||
|
||||
if (strv_isempty(e))
|
||||
r = json_variant_filter(&w, STRV_MAKE("tokenPin"));
|
||||
r = sd_json_variant_filter(&w, STRV_MAKE("tokenPin"));
|
||||
else {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *l = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *l = NULL;
|
||||
|
||||
r = json_variant_new_array_strv(&l, e);
|
||||
r = sd_json_variant_new_array_strv(&l, e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_sensitive(l);
|
||||
sd_json_variant_sensitive(l);
|
||||
|
||||
r = json_variant_set_field(&w, "tokenPin", l);
|
||||
r = sd_json_variant_set_field(&w, "tokenPin", l);
|
||||
}
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_sensitive(w);
|
||||
sd_json_variant_sensitive(w);
|
||||
|
||||
r = json_variant_set_field(&h->json, "secret", w);
|
||||
r = sd_json_variant_set_field(&h->json, "secret", w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
strv_free_and_replace(h->token_pin, e);
|
||||
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !json_variant_is_blank_object(w));
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !sd_json_variant_is_blank_object(w));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int user_record_set_pkcs11_protected_authentication_path_permitted(UserRecord *h, int b) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(h->json, "secret"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(h->json, "secret"));
|
||||
|
||||
if (b < 0)
|
||||
r = json_variant_filter(&w, STRV_MAKE("pkcs11ProtectedAuthenticationPathPermitted"));
|
||||
r = sd_json_variant_filter(&w, STRV_MAKE("pkcs11ProtectedAuthenticationPathPermitted"));
|
||||
else
|
||||
r = json_variant_set_field_boolean(&w, "pkcs11ProtectedAuthenticationPathPermitted", b);
|
||||
r = sd_json_variant_set_field_boolean(&w, "pkcs11ProtectedAuthenticationPathPermitted", b);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (json_variant_is_blank_object(w))
|
||||
r = json_variant_filter(&h->json, STRV_MAKE("secret"));
|
||||
if (sd_json_variant_is_blank_object(w))
|
||||
r = sd_json_variant_filter(&h->json, STRV_MAKE("secret"));
|
||||
else {
|
||||
json_variant_sensitive(w);
|
||||
sd_json_variant_sensitive(w);
|
||||
|
||||
r = json_variant_set_field(&h->json, "secret", w);
|
||||
r = sd_json_variant_set_field(&h->json, "secret", w);
|
||||
}
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
h->pkcs11_protected_authentication_path_permitted = b;
|
||||
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !json_variant_is_blank_object(w));
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !sd_json_variant_is_blank_object(w));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int user_record_set_fido2_user_presence_permitted(UserRecord *h, int b) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(h->json, "secret"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(h->json, "secret"));
|
||||
|
||||
if (b < 0)
|
||||
r = json_variant_filter(&w, STRV_MAKE("fido2UserPresencePermitted"));
|
||||
r = sd_json_variant_filter(&w, STRV_MAKE("fido2UserPresencePermitted"));
|
||||
else
|
||||
r = json_variant_set_field_boolean(&w, "fido2UserPresencePermitted", b);
|
||||
r = sd_json_variant_set_field_boolean(&w, "fido2UserPresencePermitted", b);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (json_variant_is_blank_object(w))
|
||||
r = json_variant_filter(&h->json, STRV_MAKE("secret"));
|
||||
if (sd_json_variant_is_blank_object(w))
|
||||
r = sd_json_variant_filter(&h->json, STRV_MAKE("secret"));
|
||||
else
|
||||
r = json_variant_set_field(&h->json, "secret", w);
|
||||
r = sd_json_variant_set_field(&h->json, "secret", w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
h->fido2_user_presence_permitted = b;
|
||||
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !json_variant_is_blank_object(w));
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !sd_json_variant_is_blank_object(w));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int user_record_set_fido2_user_verification_permitted(UserRecord *h, int b) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
|
||||
w = json_variant_ref(json_variant_by_key(h->json, "secret"));
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(h->json, "secret"));
|
||||
|
||||
if (b < 0)
|
||||
r = json_variant_filter(&w, STRV_MAKE("fido2UserVerificationPermitted"));
|
||||
r = sd_json_variant_filter(&w, STRV_MAKE("fido2UserVerificationPermitted"));
|
||||
else
|
||||
r = json_variant_set_field_boolean(&w, "fido2UserVerificationPermitted", b);
|
||||
r = sd_json_variant_set_field_boolean(&w, "fido2UserVerificationPermitted", b);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (json_variant_is_blank_object(w))
|
||||
r = json_variant_filter(&h->json, STRV_MAKE("secret"));
|
||||
if (sd_json_variant_is_blank_object(w))
|
||||
r = sd_json_variant_filter(&h->json, STRV_MAKE("secret"));
|
||||
else
|
||||
r = json_variant_set_field(&h->json, "secret", w);
|
||||
r = sd_json_variant_set_field(&h->json, "secret", w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
h->fido2_user_verification_permitted = b;
|
||||
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !json_variant_is_blank_object(w));
|
||||
SET_FLAG(h->mask, USER_RECORD_SECRET, !sd_json_variant_is_blank_object(w));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool per_machine_entry_empty(JsonVariant *v) {
|
||||
static bool per_machine_entry_empty(sd_json_variant *v) {
|
||||
const char *k;
|
||||
_unused_ JsonVariant *e;
|
||||
_unused_ sd_json_variant *e;
|
||||
|
||||
JSON_VARIANT_OBJECT_FOREACH(k, e, v)
|
||||
if (!STR_IN_SET(k, "matchMachineId", "matchHostname"))
|
||||
@ -1101,58 +1104,58 @@ static bool per_machine_entry_empty(JsonVariant *v) {
|
||||
}
|
||||
|
||||
int user_record_set_password_change_now(UserRecord *h, int b) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
JsonVariant *per_machine;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
sd_json_variant *per_machine;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
|
||||
w = json_variant_ref(h->json);
|
||||
w = sd_json_variant_ref(h->json);
|
||||
|
||||
if (b < 0)
|
||||
r = json_variant_filter(&w, STRV_MAKE("passwordChangeNow"));
|
||||
r = sd_json_variant_filter(&w, STRV_MAKE("passwordChangeNow"));
|
||||
else
|
||||
r = json_variant_set_field_boolean(&w, "passwordChangeNow", b);
|
||||
r = sd_json_variant_set_field_boolean(&w, "passwordChangeNow", b);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* Also drop the field from all perMachine entries */
|
||||
per_machine = json_variant_by_key(w, "perMachine");
|
||||
per_machine = sd_json_variant_by_key(w, "perMachine");
|
||||
if (per_machine) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
JsonVariant *e;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
sd_json_variant *e;
|
||||
|
||||
JSON_VARIANT_ARRAY_FOREACH(e, per_machine) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *z = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *z = NULL;
|
||||
|
||||
if (!json_variant_is_object(e))
|
||||
if (!sd_json_variant_is_object(e))
|
||||
return -EINVAL;
|
||||
|
||||
z = json_variant_ref(e);
|
||||
z = sd_json_variant_ref(e);
|
||||
|
||||
r = json_variant_filter(&z, STRV_MAKE("passwordChangeNow"));
|
||||
r = sd_json_variant_filter(&z, STRV_MAKE("passwordChangeNow"));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (per_machine_entry_empty(z))
|
||||
continue;
|
||||
|
||||
r = json_variant_append_array(&array, z);
|
||||
r = sd_json_variant_append_array(&array, z);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (json_variant_is_blank_array(array))
|
||||
r = json_variant_filter(&w, STRV_MAKE("perMachine"));
|
||||
if (sd_json_variant_is_blank_array(array))
|
||||
r = sd_json_variant_filter(&w, STRV_MAKE("perMachine"));
|
||||
else
|
||||
r = json_variant_set_field(&w, "perMachine", array);
|
||||
r = sd_json_variant_set_field(&w, "perMachine", array);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
SET_FLAG(h->mask, USER_RECORD_PER_MACHINE, !json_variant_is_blank_array(array));
|
||||
SET_FLAG(h->mask, USER_RECORD_PER_MACHINE, !sd_json_variant_is_blank_array(array));
|
||||
}
|
||||
|
||||
json_variant_unref(h->json);
|
||||
sd_json_variant_unref(h->json);
|
||||
h->json = TAKE_PTR(w);
|
||||
|
||||
h->password_change_now = b;
|
||||
@ -1204,7 +1207,7 @@ int user_record_merge_secret(UserRecord *h, UserRecord *secret) {
|
||||
}
|
||||
|
||||
int user_record_good_authentication(UserRecord *h) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL, *z = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *w = NULL, *z = NULL;
|
||||
uint64_t counter, usec;
|
||||
sd_id128_t mid;
|
||||
int r;
|
||||
@ -1229,27 +1232,27 @@ int user_record_good_authentication(UserRecord *h) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = json_variant_ref(h->json);
|
||||
w = json_variant_ref(json_variant_by_key(v, "status"));
|
||||
z = json_variant_ref(json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
|
||||
v = sd_json_variant_ref(h->json);
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(v, "status"));
|
||||
z = sd_json_variant_ref(sd_json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
|
||||
|
||||
r = json_variant_set_field_unsigned(&z, "goodAuthenticationCounter", counter);
|
||||
r = sd_json_variant_set_field_unsigned(&z, "goodAuthenticationCounter", counter);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field_unsigned(&z, "lastGoodAuthenticationUSec", usec);
|
||||
r = sd_json_variant_set_field_unsigned(&z, "lastGoodAuthenticationUSec", usec);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
|
||||
r = sd_json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&v, "status", w);
|
||||
r = sd_json_variant_set_field(&v, "status", w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_unref(h->json);
|
||||
sd_json_variant_unref(h->json);
|
||||
h->json = TAKE_PTR(v);
|
||||
|
||||
h->good_authentication_counter = counter;
|
||||
@ -1260,7 +1263,7 @@ int user_record_good_authentication(UserRecord *h) {
|
||||
}
|
||||
|
||||
int user_record_bad_authentication(UserRecord *h) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL, *z = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *w = NULL, *z = NULL;
|
||||
uint64_t counter, usec;
|
||||
sd_id128_t mid;
|
||||
int r;
|
||||
@ -1285,27 +1288,27 @@ int user_record_bad_authentication(UserRecord *h) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = json_variant_ref(h->json);
|
||||
w = json_variant_ref(json_variant_by_key(v, "status"));
|
||||
z = json_variant_ref(json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
|
||||
v = sd_json_variant_ref(h->json);
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(v, "status"));
|
||||
z = sd_json_variant_ref(sd_json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
|
||||
|
||||
r = json_variant_set_field_unsigned(&z, "badAuthenticationCounter", counter);
|
||||
r = sd_json_variant_set_field_unsigned(&z, "badAuthenticationCounter", counter);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field_unsigned(&z, "lastBadAuthenticationUSec", usec);
|
||||
r = sd_json_variant_set_field_unsigned(&z, "lastBadAuthenticationUSec", usec);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
|
||||
r = sd_json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&v, "status", w);
|
||||
r = sd_json_variant_set_field(&v, "status", w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_unref(h->json);
|
||||
sd_json_variant_unref(h->json);
|
||||
h->json = TAKE_PTR(v);
|
||||
|
||||
h->bad_authentication_counter = counter;
|
||||
@ -1316,7 +1319,7 @@ int user_record_bad_authentication(UserRecord *h) {
|
||||
}
|
||||
|
||||
int user_record_ratelimit(UserRecord *h) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL, *z = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *w = NULL, *z = NULL;
|
||||
usec_t usec, new_ratelimit_begin_usec, new_ratelimit_count;
|
||||
sd_id128_t mid;
|
||||
int r;
|
||||
@ -1347,27 +1350,27 @@ int user_record_ratelimit(UserRecord *h) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
v = json_variant_ref(h->json);
|
||||
w = json_variant_ref(json_variant_by_key(v, "status"));
|
||||
z = json_variant_ref(json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
|
||||
v = sd_json_variant_ref(h->json);
|
||||
w = sd_json_variant_ref(sd_json_variant_by_key(v, "status"));
|
||||
z = sd_json_variant_ref(sd_json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
|
||||
|
||||
r = json_variant_set_field_unsigned(&z, "rateLimitBeginUSec", new_ratelimit_begin_usec);
|
||||
r = sd_json_variant_set_field_unsigned(&z, "rateLimitBeginUSec", new_ratelimit_begin_usec);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field_unsigned(&z, "rateLimitCount", new_ratelimit_count);
|
||||
r = sd_json_variant_set_field_unsigned(&z, "rateLimitCount", new_ratelimit_count);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
|
||||
r = sd_json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&v, "status", w);
|
||||
r = sd_json_variant_set_field(&v, "status", w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_unref(h->json);
|
||||
sd_json_variant_unref(h->json);
|
||||
h->json = TAKE_PTR(v);
|
||||
|
||||
h->ratelimit_begin_usec = new_ratelimit_begin_usec;
|
||||
@ -1398,7 +1401,7 @@ int user_record_is_supported(UserRecord *hr, sd_bus_error *error) {
|
||||
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Cannot manage custom blob directories.");
|
||||
}
|
||||
|
||||
if (json_variant_by_key(hr->json, HOMEWORK_BLOB_FDMAP_FIELD))
|
||||
if (sd_json_variant_by_key(hr->json, HOMEWORK_BLOB_FDMAP_FIELD))
|
||||
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "User record contains unsafe internal fields.");
|
||||
|
||||
return 0;
|
||||
@ -1420,11 +1423,11 @@ bool user_record_shall_rebalance(UserRecord *h) {
|
||||
}
|
||||
|
||||
int user_record_set_rebalance_weight(UserRecord *h, uint64_t weight) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *new_per_machine_array = NULL, *machine_id_variant = NULL,
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *new_per_machine_array = NULL, *machine_id_variant = NULL,
|
||||
*machine_id_array = NULL, *per_machine_entry = NULL;
|
||||
_cleanup_free_ JsonVariant **array = NULL;
|
||||
_cleanup_free_ sd_json_variant **array = NULL;
|
||||
size_t idx = SIZE_MAX, n;
|
||||
JsonVariant *per_machine;
|
||||
sd_json_variant *per_machine;
|
||||
sd_id128_t mid;
|
||||
int r;
|
||||
|
||||
@ -1437,48 +1440,48 @@ int user_record_set_rebalance_weight(UserRecord *h, uint64_t weight) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_new_id128(&machine_id_variant, mid);
|
||||
r = sd_json_variant_new_id128(&machine_id_variant, mid);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_new_array(&machine_id_array, (JsonVariant*[]) { machine_id_variant }, 1);
|
||||
r = sd_json_variant_new_array(&machine_id_array, (sd_json_variant*[]) { machine_id_variant }, 1);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
per_machine = json_variant_by_key(h->json, "perMachine");
|
||||
per_machine = sd_json_variant_by_key(h->json, "perMachine");
|
||||
if (per_machine) {
|
||||
if (!json_variant_is_array(per_machine))
|
||||
if (!sd_json_variant_is_array(per_machine))
|
||||
return -EINVAL;
|
||||
|
||||
n = json_variant_elements(per_machine);
|
||||
n = sd_json_variant_elements(per_machine);
|
||||
|
||||
array = new(JsonVariant*, n + 1);
|
||||
array = new(sd_json_variant*, n + 1);
|
||||
if (!array)
|
||||
return -ENOMEM;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
JsonVariant *m;
|
||||
sd_json_variant *m;
|
||||
|
||||
array[i] = json_variant_by_index(per_machine, i);
|
||||
array[i] = sd_json_variant_by_index(per_machine, i);
|
||||
|
||||
if (!json_variant_is_object(array[i]))
|
||||
if (!sd_json_variant_is_object(array[i]))
|
||||
return -EINVAL;
|
||||
|
||||
m = json_variant_by_key(array[i], "matchMachineId");
|
||||
m = sd_json_variant_by_key(array[i], "matchMachineId");
|
||||
if (!m) {
|
||||
/* No machineId field? Let's ignore this, but invalidate what we found so far */
|
||||
idx = SIZE_MAX;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (json_variant_equal(m, machine_id_variant) ||
|
||||
json_variant_equal(m, machine_id_array)) {
|
||||
if (sd_json_variant_equal(m, machine_id_variant) ||
|
||||
sd_json_variant_equal(m, machine_id_array)) {
|
||||
/* Matches exactly what we are looking for. Let's use this */
|
||||
idx = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
r = per_machine_id_match(m, JSON_PERMISSIVE);
|
||||
r = per_machine_id_match(m, SD_JSON_PERMISSIVE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
@ -1490,10 +1493,10 @@ int user_record_set_rebalance_weight(UserRecord *h, uint64_t weight) {
|
||||
if (idx == SIZE_MAX)
|
||||
idx = n++; /* Nothing suitable found, place new entry at end */
|
||||
else
|
||||
per_machine_entry = json_variant_ref(array[idx]);
|
||||
per_machine_entry = sd_json_variant_ref(array[idx]);
|
||||
|
||||
} else {
|
||||
array = new(JsonVariant*, 1);
|
||||
array = new(sd_json_variant*, 1);
|
||||
if (!array)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -1502,26 +1505,26 @@ int user_record_set_rebalance_weight(UserRecord *h, uint64_t weight) {
|
||||
}
|
||||
|
||||
if (!per_machine_entry) {
|
||||
r = json_variant_set_field(&per_machine_entry, "matchMachineId", machine_id_array);
|
||||
r = sd_json_variant_set_field(&per_machine_entry, "matchMachineId", machine_id_array);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (weight == REBALANCE_WEIGHT_UNSET)
|
||||
r = json_variant_set_field(&per_machine_entry, "rebalanceWeight", NULL); /* set explicitly to NULL (so that the perMachine setting we are setting here can override the global setting) */
|
||||
r = sd_json_variant_set_field(&per_machine_entry, "rebalanceWeight", NULL); /* set explicitly to NULL (so that the perMachine setting we are setting here can override the global setting) */
|
||||
else
|
||||
r = json_variant_set_field_unsigned(&per_machine_entry, "rebalanceWeight", weight);
|
||||
r = sd_json_variant_set_field_unsigned(&per_machine_entry, "rebalanceWeight", weight);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert(idx < n);
|
||||
array[idx] = per_machine_entry;
|
||||
|
||||
r = json_variant_new_array(&new_per_machine_array, array, n);
|
||||
r = sd_json_variant_new_array(&new_per_machine_array, array, n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_set_field(&h->json, "perMachine", new_per_machine_array);
|
||||
r = sd_json_variant_set_field(&h->json, "perMachine", new_per_machine_array);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -1531,7 +1534,7 @@ int user_record_set_rebalance_weight(UserRecord *h, uint64_t weight) {
|
||||
}
|
||||
|
||||
int user_record_ensure_blob_manifest(UserRecord *h, Hashmap *blobs, const char **ret_failed) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_hashmap_free_ Hashmap *manifest = NULL;
|
||||
const char *filename;
|
||||
void *key, *value;
|
||||
@ -1569,7 +1572,7 @@ int user_record_ensure_blob_manifest(UserRecord *h, Hashmap *blobs, const char *
|
||||
HASHMAP_FOREACH_KEY(value, filename, blobs) {
|
||||
_cleanup_free_ char *filename_dup = NULL;
|
||||
_cleanup_free_ uint8_t *hash = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *hash_json = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *hash_json = NULL;
|
||||
int fd = PTR_TO_FD(value);
|
||||
off_t initial, size;
|
||||
|
||||
@ -1605,7 +1608,7 @@ int user_record_ensure_blob_manifest(UserRecord *h, Hashmap *blobs, const char *
|
||||
if (lseek(fd, initial, SEEK_SET) < 0)
|
||||
return -errno;
|
||||
|
||||
r = json_variant_new_hex(&hash_json, hash, SHA256_DIGEST_SIZE);
|
||||
r = sd_json_variant_new_hex(&hash_json, hash, SHA256_DIGEST_SIZE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -1615,7 +1618,7 @@ int user_record_ensure_blob_manifest(UserRecord *h, Hashmap *blobs, const char *
|
||||
TAKE_PTR(filename_dup); /* Ownership transfers to hashmap */
|
||||
TAKE_PTR(hash);
|
||||
|
||||
r = json_variant_set_field(&v, filename, hash_json);
|
||||
r = sd_json_variant_set_field(&v, filename, hash_json);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-id128.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "architecture.h"
|
||||
@ -20,7 +21,6 @@
|
||||
#include "format-table.h"
|
||||
#include "hostname-setup.h"
|
||||
#include "hostname-util.h"
|
||||
#include "json.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-argument.h"
|
||||
#include "pretty-print.h"
|
||||
@ -35,7 +35,7 @@ static char *arg_host = NULL;
|
||||
static bool arg_transient = false;
|
||||
static bool arg_pretty = false;
|
||||
static bool arg_static = false;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
|
||||
typedef struct StatusInfo {
|
||||
const char *hostname;
|
||||
@ -491,10 +491,10 @@ static int show_status(int argc, char **argv, void *userdata) {
|
||||
sd_bus *bus = userdata;
|
||||
int r;
|
||||
|
||||
if (arg_json_format_flags != JSON_FORMAT_OFF) {
|
||||
if (arg_json_format_flags != SD_JSON_FORMAT_OFF) {
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
const char *text = NULL;
|
||||
|
||||
r = bus_call_method(bus, bus_hostname, "Describe", &error, &reply, NULL);
|
||||
@ -505,11 +505,11 @@ static int show_status(int argc, char **argv, void *userdata) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_parse(text, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(text, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse JSON: %m");
|
||||
|
||||
json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
sd_json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -766,7 +766,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
|
||||
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-device.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "bus-common-errors.h"
|
||||
@ -23,7 +24,7 @@
|
||||
#include "hostname-setup.h"
|
||||
#include "hostname-util.h"
|
||||
#include "id128-util.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "main-func.h"
|
||||
#include "missing_capability.h"
|
||||
#include "nscd-flush.h"
|
||||
@ -1343,13 +1344,13 @@ static int method_get_hardware_serial(sd_bus_message *m, void *userdata, sd_bus_
|
||||
return sd_bus_reply_method_return(m, "s", serial);
|
||||
}
|
||||
|
||||
static int build_describe_response(Context *c, bool privileged, JsonVariant **ret) {
|
||||
static int build_describe_response(Context *c, bool privileged, sd_json_variant **ret) {
|
||||
_cleanup_free_ char *hn = NULL, *dhn = NULL, *in = NULL,
|
||||
*chassis = NULL, *vendor = NULL, *model = NULL, *serial = NULL, *firmware_version = NULL,
|
||||
*firmware_vendor = NULL;
|
||||
_cleanup_strv_free_ char **os_release_pairs = NULL, **machine_info_pairs = NULL;
|
||||
usec_t firmware_date = USEC_INFINITY, eol = USEC_INFINITY;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
sd_id128_t machine_id, boot_id, product_uuid = SD_ID128_NULL;
|
||||
unsigned local_cid = VMADDR_CID_ANY;
|
||||
struct utsname u;
|
||||
@ -1414,37 +1415,37 @@ static int build_describe_response(Context *c, bool privileged, JsonVariant **re
|
||||
(void) load_os_release_pairs(/* root= */ NULL, &os_release_pairs);
|
||||
(void) load_env_file_pairs(/* f=*/ NULL, "/etc/machine-info", &machine_info_pairs);
|
||||
|
||||
r = json_build(&v, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("Hostname", JSON_BUILD_STRING(hn)),
|
||||
JSON_BUILD_PAIR("StaticHostname", JSON_BUILD_STRING(c->data[PROP_STATIC_HOSTNAME])),
|
||||
JSON_BUILD_PAIR("PrettyHostname", JSON_BUILD_STRING(c->data[PROP_PRETTY_HOSTNAME])),
|
||||
JSON_BUILD_PAIR("DefaultHostname", JSON_BUILD_STRING(dhn)),
|
||||
JSON_BUILD_PAIR("HostnameSource", JSON_BUILD_STRING(hostname_source_to_string(c->hostname_source))),
|
||||
JSON_BUILD_PAIR("IconName", JSON_BUILD_STRING(in ?: c->data[PROP_ICON_NAME])),
|
||||
JSON_BUILD_PAIR("Chassis", JSON_BUILD_STRING(chassis)),
|
||||
JSON_BUILD_PAIR("Deployment", JSON_BUILD_STRING(c->data[PROP_DEPLOYMENT])),
|
||||
JSON_BUILD_PAIR("Location", JSON_BUILD_STRING(c->data[PROP_LOCATION])),
|
||||
JSON_BUILD_PAIR("KernelName", JSON_BUILD_STRING(u.sysname)),
|
||||
JSON_BUILD_PAIR("KernelRelease", JSON_BUILD_STRING(u.release)),
|
||||
JSON_BUILD_PAIR("KernelVersion", JSON_BUILD_STRING(u.version)),
|
||||
JSON_BUILD_PAIR("OperatingSystemPrettyName", JSON_BUILD_STRING(c->data[PROP_OS_PRETTY_NAME])),
|
||||
JSON_BUILD_PAIR("OperatingSystemCPEName", JSON_BUILD_STRING(c->data[PROP_OS_CPE_NAME])),
|
||||
JSON_BUILD_PAIR("OperatingSystemHomeURL", JSON_BUILD_STRING(c->data[PROP_OS_HOME_URL])),
|
||||
r = sd_json_build(&v, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("Hostname", SD_JSON_BUILD_STRING(hn)),
|
||||
SD_JSON_BUILD_PAIR("StaticHostname", SD_JSON_BUILD_STRING(c->data[PROP_STATIC_HOSTNAME])),
|
||||
SD_JSON_BUILD_PAIR("PrettyHostname", SD_JSON_BUILD_STRING(c->data[PROP_PRETTY_HOSTNAME])),
|
||||
SD_JSON_BUILD_PAIR("DefaultHostname", SD_JSON_BUILD_STRING(dhn)),
|
||||
SD_JSON_BUILD_PAIR("HostnameSource", SD_JSON_BUILD_STRING(hostname_source_to_string(c->hostname_source))),
|
||||
SD_JSON_BUILD_PAIR("IconName", SD_JSON_BUILD_STRING(in ?: c->data[PROP_ICON_NAME])),
|
||||
SD_JSON_BUILD_PAIR("Chassis", SD_JSON_BUILD_STRING(chassis)),
|
||||
SD_JSON_BUILD_PAIR("Deployment", SD_JSON_BUILD_STRING(c->data[PROP_DEPLOYMENT])),
|
||||
SD_JSON_BUILD_PAIR("Location", SD_JSON_BUILD_STRING(c->data[PROP_LOCATION])),
|
||||
SD_JSON_BUILD_PAIR("KernelName", SD_JSON_BUILD_STRING(u.sysname)),
|
||||
SD_JSON_BUILD_PAIR("KernelRelease", SD_JSON_BUILD_STRING(u.release)),
|
||||
SD_JSON_BUILD_PAIR("KernelVersion", SD_JSON_BUILD_STRING(u.version)),
|
||||
SD_JSON_BUILD_PAIR("OperatingSystemPrettyName", SD_JSON_BUILD_STRING(c->data[PROP_OS_PRETTY_NAME])),
|
||||
SD_JSON_BUILD_PAIR("OperatingSystemCPEName", SD_JSON_BUILD_STRING(c->data[PROP_OS_CPE_NAME])),
|
||||
SD_JSON_BUILD_PAIR("OperatingSystemHomeURL", SD_JSON_BUILD_STRING(c->data[PROP_OS_HOME_URL])),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("OperatingSystemSupportEnd", eol),
|
||||
JSON_BUILD_PAIR("OperatingSystemReleaseData", JSON_BUILD_STRV_ENV_PAIR(os_release_pairs)),
|
||||
JSON_BUILD_PAIR("MachineInformationData", JSON_BUILD_STRV_ENV_PAIR(machine_info_pairs)),
|
||||
JSON_BUILD_PAIR("HardwareVendor", JSON_BUILD_STRING(vendor ?: c->data[PROP_HARDWARE_VENDOR])),
|
||||
JSON_BUILD_PAIR("HardwareModel", JSON_BUILD_STRING(model ?: c->data[PROP_HARDWARE_MODEL])),
|
||||
JSON_BUILD_PAIR("HardwareSerial", JSON_BUILD_STRING(serial)),
|
||||
JSON_BUILD_PAIR("FirmwareVersion", JSON_BUILD_STRING(firmware_version)),
|
||||
JSON_BUILD_PAIR("FirmwareVendor", JSON_BUILD_STRING(firmware_vendor)),
|
||||
SD_JSON_BUILD_PAIR("OperatingSystemReleaseData", JSON_BUILD_STRV_ENV_PAIR(os_release_pairs)),
|
||||
SD_JSON_BUILD_PAIR("MachineInformationData", JSON_BUILD_STRV_ENV_PAIR(machine_info_pairs)),
|
||||
SD_JSON_BUILD_PAIR("HardwareVendor", SD_JSON_BUILD_STRING(vendor ?: c->data[PROP_HARDWARE_VENDOR])),
|
||||
SD_JSON_BUILD_PAIR("HardwareModel", SD_JSON_BUILD_STRING(model ?: c->data[PROP_HARDWARE_MODEL])),
|
||||
SD_JSON_BUILD_PAIR("HardwareSerial", SD_JSON_BUILD_STRING(serial)),
|
||||
SD_JSON_BUILD_PAIR("FirmwareVersion", SD_JSON_BUILD_STRING(firmware_version)),
|
||||
SD_JSON_BUILD_PAIR("FirmwareVendor", SD_JSON_BUILD_STRING(firmware_vendor)),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("FirmwareDate", firmware_date),
|
||||
JSON_BUILD_PAIR_ID128("MachineID", machine_id),
|
||||
JSON_BUILD_PAIR_ID128("BootID", boot_id),
|
||||
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(product_uuid), "ProductUUID", JSON_BUILD_ID128(product_uuid)),
|
||||
JSON_BUILD_PAIR_CONDITION(sd_id128_is_null(product_uuid), "ProductUUID", JSON_BUILD_NULL),
|
||||
JSON_BUILD_PAIR_CONDITION(local_cid != VMADDR_CID_ANY, "VSockCID", JSON_BUILD_UNSIGNED(local_cid)),
|
||||
JSON_BUILD_PAIR_CONDITION(local_cid == VMADDR_CID_ANY, "VSockCID", JSON_BUILD_NULL)));
|
||||
SD_JSON_BUILD_PAIR_ID128("MachineID", machine_id),
|
||||
SD_JSON_BUILD_PAIR_ID128("BootID", boot_id),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(product_uuid), "ProductUUID", SD_JSON_BUILD_ID128(product_uuid)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(sd_id128_is_null(product_uuid), "ProductUUID", SD_JSON_BUILD_NULL),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(local_cid != VMADDR_CID_ANY, "VSockCID", SD_JSON_BUILD_UNSIGNED(local_cid)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(local_cid == VMADDR_CID_ANY, "VSockCID", SD_JSON_BUILD_NULL)));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build JSON data: %m");
|
||||
|
||||
@ -1453,7 +1454,7 @@ static int build_describe_response(Context *c, bool privileged, JsonVariant **re
|
||||
}
|
||||
|
||||
static int method_describe(sd_bus_message *m, void *userdata, sd_bus_error *error) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
Context *c = ASSERT_PTR(userdata);
|
||||
_cleanup_free_ char *text = NULL;
|
||||
bool privileged;
|
||||
@ -1478,7 +1479,7 @@ static int method_describe(sd_bus_message *m, void *userdata, sd_bus_error *erro
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_format(v, 0, &text);
|
||||
r = sd_json_variant_format(v, 0, &text);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format JSON data: %m");
|
||||
|
||||
@ -1602,8 +1603,8 @@ static int connect_bus(Context *c) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vl_method_describe(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
static int vl_method_describe(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
VARLINK_DISPATCH_POLKIT_FIELD,
|
||||
{}
|
||||
};
|
||||
@ -1632,10 +1633,10 @@ static int vl_method_describe(Varlink *link, JsonVariant *parameters, VarlinkMet
|
||||
* the product ID which we'll check explicitly. */
|
||||
privileged = r > 0;
|
||||
|
||||
if (json_variant_elements(parameters) > 0)
|
||||
if (sd_json_variant_elements(parameters) > 0)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
r = build_describe_response(c, privileged, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -20,7 +20,7 @@ static sd_id128_t arg_app = {};
|
||||
static bool arg_value = false;
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static bool arg_legend = true;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
|
||||
static int verb_new(int argc, char **argv, void *userdata) {
|
||||
return id128_print_new(arg_mode);
|
||||
@ -248,7 +248,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
|
||||
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
|
||||
break;
|
||||
|
||||
case ARG_JSON:
|
||||
|
@ -42,7 +42,7 @@ static bool arg_quiet = false;
|
||||
static bool arg_ask_password = true;
|
||||
static ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
|
||||
static const char* arg_format = NULL;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
static ImageClass arg_image_class = _IMAGE_CLASS_INVALID;
|
||||
|
||||
#define PROGRESS_PREFIX "Total: "
|
||||
@ -932,7 +932,7 @@ static int list_images(int argc, char *argv[], void *userdata) {
|
||||
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))
|
||||
r = table_add_many(
|
||||
t,
|
||||
TABLE_STRING, read_only ? "ro" : "rw",
|
||||
@ -1151,7 +1151,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
|
||||
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
|
||||
arg_legend = false;
|
||||
break;
|
||||
|
||||
|
@ -285,7 +285,7 @@ int action_list_namespaces(void) {
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
if (!arg_quiet)
|
||||
log_notice("No namespaces found.");
|
||||
} else {
|
||||
|
@ -33,7 +33,7 @@ enum {
|
||||
|
||||
JournalctlAction arg_action = ACTION_SHOW;
|
||||
OutputMode arg_output = OUTPUT_SHORT;
|
||||
JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
PagerFlags arg_pager_flags = 0;
|
||||
bool arg_utc = false;
|
||||
bool arg_follow = false;
|
||||
@ -460,9 +460,9 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
arg_quiet = true;
|
||||
|
||||
if (OUTPUT_MODE_IS_JSON(arg_output))
|
||||
arg_json_format_flags = output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO;
|
||||
arg_json_format_flags = output_mode_to_json_format_flags(arg_output) | SD_JSON_FORMAT_COLOR_AUTO;
|
||||
else
|
||||
arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
|
||||
break;
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "json.h"
|
||||
#include "output-mode.h"
|
||||
#include "pager.h"
|
||||
#include "pcre2-util.h"
|
||||
@ -37,7 +37,7 @@ typedef enum JournalctlAction {
|
||||
|
||||
extern JournalctlAction arg_action;
|
||||
extern OutputMode arg_output;
|
||||
extern JsonFormatFlags arg_json_format_flags;
|
||||
extern sd_json_format_flags_t arg_json_format_flags;
|
||||
extern PagerFlags arg_pager_flags;
|
||||
extern bool arg_utc;
|
||||
extern bool arg_follow;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "journald-client.h"
|
||||
#include "nulstr-util.h"
|
||||
#include "pcre2-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
/* This consumes both `allow_list` and `deny_list` arguments. Hence, those arguments are not owned by the
|
||||
* caller anymore and should not be freed. */
|
||||
|
@ -2212,14 +2212,14 @@ static void synchronize_destroy(void *userdata) {
|
||||
varlink_unref(userdata);
|
||||
}
|
||||
|
||||
static int vl_method_synchronize(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_synchronize(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
_cleanup_(sd_event_source_unrefp) sd_event_source *event_source = NULL;
|
||||
Server *s = ASSERT_PTR(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);
|
||||
|
||||
log_info("Received client request to sync journal.");
|
||||
@ -2253,12 +2253,12 @@ static int vl_method_synchronize(Varlink *link, JsonVariant *parameters, Varlink
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vl_method_rotate(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_rotate(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
Server *s = ASSERT_PTR(userdata);
|
||||
|
||||
assert(link);
|
||||
|
||||
if (json_variant_elements(parameters) > 0)
|
||||
if (sd_json_variant_elements(parameters) > 0)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
|
||||
log_info("Received client request to rotate journal, rotating.");
|
||||
@ -2267,12 +2267,12 @@ static int vl_method_rotate(Varlink *link, JsonVariant *parameters, VarlinkMetho
|
||||
return varlink_reply(link, NULL);
|
||||
}
|
||||
|
||||
static int vl_method_flush_to_var(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_flush_to_var(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
Server *s = ASSERT_PTR(userdata);
|
||||
|
||||
assert(link);
|
||||
|
||||
if (json_variant_elements(parameters) > 0)
|
||||
if (sd_json_variant_elements(parameters) > 0)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
if (s->namespace)
|
||||
return varlink_error(link, "io.systemd.Journal.NotSupportedByNamespaces", NULL);
|
||||
@ -2283,12 +2283,12 @@ static int vl_method_flush_to_var(Varlink *link, JsonVariant *parameters, Varlin
|
||||
return varlink_reply(link, NULL);
|
||||
}
|
||||
|
||||
static int vl_method_relinquish_var(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_relinquish_var(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
Server *s = ASSERT_PTR(userdata);
|
||||
|
||||
assert(link);
|
||||
|
||||
if (json_variant_elements(parameters) > 0)
|
||||
if (sd_json_variant_elements(parameters) > 0)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
if (s->namespace)
|
||||
return varlink_error(link, "io.systemd.Journal.NotSupportedByNamespaces", NULL);
|
||||
|
@ -41,7 +41,7 @@ static char *arg_esp_path = NULL;
|
||||
static char *arg_xbootldr_path = NULL;
|
||||
static int arg_make_entry_directory = -1; /* tristate */
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
static char *arg_root = NULL;
|
||||
static char *arg_image = NULL;
|
||||
static ImagePolicy *arg_image_policy = NULL;
|
||||
@ -1371,7 +1371,7 @@ static int verb_inspect(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
|
||||
if (arg_json_format_flags & JSON_FORMAT_OFF) {
|
||||
if (arg_json_format_flags & SD_JSON_FORMAT_OFF) {
|
||||
r = table_add_many(t,
|
||||
TABLE_FIELD, "Plugin Arguments",
|
||||
TABLE_STRV, strv_skip(c->argv, 1));
|
||||
|
@ -2,9 +2,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "sd-dhcp-client-id.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "dhcp-duid-internal.h"
|
||||
#include "json.h"
|
||||
#include "macro.h"
|
||||
#include "siphash24.h"
|
||||
#include "sparse-endian.h"
|
||||
@ -57,4 +57,4 @@ static inline bool client_id_data_size_is_valid(size_t size) {
|
||||
void client_id_hash_func(const sd_dhcp_client_id *client_id, struct siphash *state);
|
||||
int client_id_compare_func(const sd_dhcp_client_id *a, const sd_dhcp_client_id *b);
|
||||
|
||||
int json_dispatch_client_id(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata);
|
||||
int json_dispatch_client_id(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
|
||||
|
@ -2,10 +2,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "sd-dhcp-server-lease.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "dhcp-client-id-internal.h"
|
||||
#include "dhcp-server-internal.h"
|
||||
#include "json.h"
|
||||
#include "time-util.h"
|
||||
|
||||
typedef struct sd_dhcp_server_lease {
|
||||
@ -33,8 +33,8 @@ int dhcp_server_cleanup_expired_leases(sd_dhcp_server *server);
|
||||
|
||||
sd_dhcp_server_lease* dhcp_server_get_static_lease(sd_dhcp_server *server, const DHCPRequest *req);
|
||||
|
||||
int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v);
|
||||
int dhcp_server_static_leases_append_json(sd_dhcp_server *server, JsonVariant **v);
|
||||
int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, sd_json_variant **v);
|
||||
int dhcp_server_static_leases_append_json(sd_dhcp_server *server, sd_json_variant **v);
|
||||
|
||||
int dhcp_server_save_leases(sd_dhcp_server *server);
|
||||
int dhcp_server_load_leases(sd_dhcp_server *server);
|
||||
|
@ -24,7 +24,7 @@ int lldp_network_bind_raw_socket(int ifindex) {
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||
_cleanup_(sd_lldp_rx_unrefp) sd_lldp_rx *lldp_rx = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_(memstream_done) MemStream m = {};
|
||||
FILE *f;
|
||||
|
||||
@ -44,7 +44,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
|
||||
assert_se(lldp_rx_build_neighbors_json(lldp_rx, &v) >= 0);
|
||||
assert_se(f = memstream_init(&m));
|
||||
(void) json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR, f, NULL);
|
||||
(void) sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_COLOR, f, NULL);
|
||||
|
||||
assert_se(sd_lldp_rx_stop(lldp_rx) >= 0);
|
||||
assert_se(sd_lldp_rx_detach_event(lldp_rx) >= 0);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "ether-addr-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "json-util.h"
|
||||
#include "lldp-neighbor.h"
|
||||
#include "memory-util.h"
|
||||
#include "missing_network.h"
|
||||
@ -761,7 +762,7 @@ int sd_lldp_neighbor_get_timestamp(sd_lldp_neighbor *n, clockid_t clock, uint64_
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret) {
|
||||
int lldp_neighbor_build_json(sd_lldp_neighbor *n, sd_json_variant **ret) {
|
||||
const char *chassis_id = NULL, *port_id = NULL, *port_description = NULL,
|
||||
*system_name = NULL, *system_description = NULL;
|
||||
uint16_t cc = 0;
|
||||
@ -778,13 +779,13 @@ int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret) {
|
||||
|
||||
valid_cc = sd_lldp_neighbor_get_enabled_capabilities(n, &cc) >= 0;
|
||||
|
||||
return json_build(ret, JSON_BUILD_OBJECT(
|
||||
return sd_json_build(ret, SD_JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("ChassisID", chassis_id),
|
||||
JSON_BUILD_PAIR_BYTE_ARRAY("RawChassisID", n->id.chassis_id, n->id.chassis_id_size),
|
||||
SD_JSON_BUILD_PAIR_BYTE_ARRAY("RawChassisID", n->id.chassis_id, n->id.chassis_id_size),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("PortID", port_id),
|
||||
JSON_BUILD_PAIR_BYTE_ARRAY("RawPortID", n->id.port_id, n->id.port_id_size),
|
||||
SD_JSON_BUILD_PAIR_BYTE_ARRAY("RawPortID", n->id.port_id, n->id.port_id_size),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("PortDescription", port_description),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("SystemName", system_name),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("SystemDescription", system_description),
|
||||
JSON_BUILD_PAIR_CONDITION(valid_cc, "EnabledCapabilities", JSON_BUILD_UNSIGNED(cc))));
|
||||
SD_JSON_BUILD_PAIR_CONDITION(valid_cc, "EnabledCapabilities", SD_JSON_BUILD_UNSIGNED(cc))));
|
||||
}
|
||||
|
@ -5,10 +5,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
#include "sd-lldp-rx.h"
|
||||
|
||||
#include "hash-funcs.h"
|
||||
#include "json.h"
|
||||
#include "lldp-rx-internal.h"
|
||||
#include "time-util.h"
|
||||
|
||||
@ -91,4 +91,4 @@ sd_lldp_neighbor *lldp_neighbor_new(size_t raw_size);
|
||||
int lldp_neighbor_parse(sd_lldp_neighbor *n);
|
||||
void lldp_neighbor_start_ttl(sd_lldp_neighbor *n);
|
||||
bool lldp_neighbor_equal(const sd_lldp_neighbor *a, const sd_lldp_neighbor *b);
|
||||
int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret);
|
||||
int lldp_neighbor_build_json(sd_lldp_neighbor *n, sd_json_variant **ret);
|
||||
|
@ -2,10 +2,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "sd-event.h"
|
||||
#include "sd-json.h"
|
||||
#include "sd-lldp-rx.h"
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "json.h"
|
||||
#include "network-common.h"
|
||||
#include "prioq.h"
|
||||
|
||||
@ -37,7 +37,7 @@ struct sd_lldp_rx {
|
||||
const char* lldp_rx_event_to_string(sd_lldp_rx_event_t e) _const_;
|
||||
sd_lldp_rx_event_t lldp_rx_event_from_string(const char *s) _pure_;
|
||||
|
||||
int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, JsonVariant **ret);
|
||||
int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, sd_json_variant **ret);
|
||||
|
||||
#define log_lldp_rx_errno(lldp_rx, error, fmt, ...) \
|
||||
log_interface_prefix_full_errno( \
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-client-id-internal.h"
|
||||
#include "iovec-util.h"
|
||||
#include "json-util.h"
|
||||
#include "unaligned.h"
|
||||
#include "utf8.h"
|
||||
|
||||
@ -179,7 +180,7 @@ int client_id_compare_func(const sd_dhcp_client_id *a, const sd_dhcp_client_id *
|
||||
return memcmp_nn(a->raw, a->size, b->raw, b->size);
|
||||
}
|
||||
|
||||
int json_dispatch_client_id(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
int json_dispatch_client_id(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
sd_dhcp_client_id *client_id = ASSERT_PTR(userdata);
|
||||
_cleanup_(iovec_done) struct iovec iov = {};
|
||||
int r;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "dhcp-server-lease-internal.h"
|
||||
#include "fd-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "json-util.h"
|
||||
#include "mkdir.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
@ -209,19 +210,19 @@ int sd_dhcp_server_set_static_lease(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dhcp_server_lease_append_json(sd_dhcp_server_lease *lease, JsonVariant **ret) {
|
||||
static int dhcp_server_lease_append_json(sd_dhcp_server_lease *lease, sd_json_variant **ret) {
|
||||
assert(lease);
|
||||
assert(ret);
|
||||
|
||||
return json_build(ret,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_BYTE_ARRAY("ClientId", lease->client_id.raw, lease->client_id.size),
|
||||
return sd_json_build(ret,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_BYTE_ARRAY("ClientId", lease->client_id.raw, lease->client_id.size),
|
||||
JSON_BUILD_PAIR_IN4_ADDR_NON_NULL("Address", &(struct in_addr) { .s_addr = lease->address }),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("Hostname", lease->hostname)));
|
||||
}
|
||||
|
||||
int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
sd_dhcp_server_lease *lease;
|
||||
usec_t now_b, now_r;
|
||||
int r;
|
||||
@ -238,7 +239,7 @@ int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v
|
||||
return r;
|
||||
|
||||
HASHMAP_FOREACH(lease, server->bound_leases_by_client_id) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
|
||||
r = dhcp_server_lease_append_json(lease, &w);
|
||||
if (r < 0)
|
||||
@ -246,14 +247,14 @@ int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v
|
||||
|
||||
usec_t exp_r = map_clock_usec_raw(lease->expiration, now_b, now_r);
|
||||
|
||||
r = json_variant_merge_objectb(&w,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_UNSIGNED("ExpirationUSec", lease->expiration),
|
||||
JSON_BUILD_PAIR_UNSIGNED("ExpirationRealtimeUSec", exp_r)));
|
||||
r = sd_json_variant_merge_objectb(&w,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("ExpirationUSec", lease->expiration),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("ExpirationRealtimeUSec", exp_r)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_append_array(&array, w);
|
||||
r = sd_json_variant_append_array(&array, w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -261,8 +262,8 @@ int dhcp_server_bound_leases_append_json(sd_dhcp_server *server, JsonVariant **v
|
||||
return json_variant_set_field_non_null(v, "Leases", array);
|
||||
}
|
||||
|
||||
int dhcp_server_static_leases_append_json(sd_dhcp_server *server, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
int dhcp_server_static_leases_append_json(sd_dhcp_server *server, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
sd_dhcp_server_lease *lease;
|
||||
int r;
|
||||
|
||||
@ -270,13 +271,13 @@ int dhcp_server_static_leases_append_json(sd_dhcp_server *server, JsonVariant **
|
||||
assert(v);
|
||||
|
||||
HASHMAP_FOREACH(lease, server->static_leases_by_client_id) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
|
||||
r = dhcp_server_lease_append_json(lease, &w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_append_array(&array, w);
|
||||
r = sd_json_variant_append_array(&array, w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -285,7 +286,7 @@ int dhcp_server_static_leases_append_json(sd_dhcp_server *server, JsonVariant **
|
||||
}
|
||||
|
||||
int dhcp_server_save_leases(sd_dhcp_server *server) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *temp_path = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
sd_id128_t boot_id;
|
||||
@ -307,10 +308,10 @@ int dhcp_server_save_leases(sd_dhcp_server *server) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_build(&v, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_ID128("BootID", boot_id),
|
||||
r = sd_json_build(&v, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_ID128("BootID", boot_id),
|
||||
JSON_BUILD_PAIR_IN4_ADDR("Address", &(struct in_addr) { .s_addr = server->address }),
|
||||
JSON_BUILD_PAIR_UNSIGNED("PrefixLength",
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength",
|
||||
in4_addr_netmask_to_prefixlen(&(struct in_addr) { .s_addr = server->netmask }))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -329,7 +330,7 @@ int dhcp_server_save_leases(sd_dhcp_server *server) {
|
||||
|
||||
(void) fchmod(fileno(f), 0644);
|
||||
|
||||
r = json_variant_dump(v, JSON_FORMAT_NEWLINE | JSON_FORMAT_FLUSH, f, /* prefix = */ NULL);
|
||||
r = sd_json_variant_dump(v, SD_JSON_FORMAT_NEWLINE | SD_JSON_FORMAT_FLUSH, f, /* prefix = */ NULL);
|
||||
if (r < 0)
|
||||
goto failure;
|
||||
|
||||
@ -344,20 +345,20 @@ failure:
|
||||
return r;
|
||||
}
|
||||
|
||||
static int json_dispatch_dhcp_lease(sd_dhcp_server *server, JsonVariant *v, bool use_boottime) {
|
||||
static const JsonDispatch dispatch_table_boottime[] = {
|
||||
{ "ClientId", JSON_VARIANT_ARRAY, json_dispatch_client_id, offsetof(sd_dhcp_server_lease, client_id), JSON_MANDATORY },
|
||||
{ "Address", JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(sd_dhcp_server_lease, address), JSON_MANDATORY },
|
||||
{ "Hostname", JSON_VARIANT_STRING, json_dispatch_string, offsetof(sd_dhcp_server_lease, hostname), 0 },
|
||||
{ "ExpirationUSec", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(sd_dhcp_server_lease, expiration), JSON_MANDATORY },
|
||||
{ "ExpirationRealtimeUSec", _JSON_VARIANT_TYPE_INVALID, NULL, 0, JSON_MANDATORY },
|
||||
static int json_dispatch_dhcp_lease(sd_dhcp_server *server, sd_json_variant *v, bool use_boottime) {
|
||||
static const sd_json_dispatch_field dispatch_table_boottime[] = {
|
||||
{ "ClientId", SD_JSON_VARIANT_ARRAY, json_dispatch_client_id, offsetof(sd_dhcp_server_lease, client_id), SD_JSON_MANDATORY },
|
||||
{ "Address", SD_JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(sd_dhcp_server_lease, address), SD_JSON_MANDATORY },
|
||||
{ "Hostname", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(sd_dhcp_server_lease, hostname), 0 },
|
||||
{ "ExpirationUSec", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(sd_dhcp_server_lease, expiration), SD_JSON_MANDATORY },
|
||||
{ "ExpirationRealtimeUSec", _SD_JSON_VARIANT_TYPE_INVALID, NULL, 0, SD_JSON_MANDATORY },
|
||||
{}
|
||||
}, dispatch_table_realtime[] = {
|
||||
{ "ClientId", JSON_VARIANT_ARRAY, json_dispatch_client_id, offsetof(sd_dhcp_server_lease, client_id), JSON_MANDATORY },
|
||||
{ "Address", JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(sd_dhcp_server_lease, address), JSON_MANDATORY },
|
||||
{ "Hostname", JSON_VARIANT_STRING, json_dispatch_string, offsetof(sd_dhcp_server_lease, hostname), 0 },
|
||||
{ "ExpirationUSec", _JSON_VARIANT_TYPE_INVALID, NULL, 0, JSON_MANDATORY },
|
||||
{ "ExpirationRealtimeUSec", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(sd_dhcp_server_lease, expiration), JSON_MANDATORY },
|
||||
{ "ClientId", SD_JSON_VARIANT_ARRAY, json_dispatch_client_id, offsetof(sd_dhcp_server_lease, client_id), SD_JSON_MANDATORY },
|
||||
{ "Address", SD_JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(sd_dhcp_server_lease, address), SD_JSON_MANDATORY },
|
||||
{ "Hostname", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(sd_dhcp_server_lease, hostname), 0 },
|
||||
{ "ExpirationUSec", _SD_JSON_VARIANT_TYPE_INVALID, NULL, 0, SD_JSON_MANDATORY },
|
||||
{ "ExpirationRealtimeUSec", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(sd_dhcp_server_lease, expiration), SD_JSON_MANDATORY },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -376,7 +377,7 @@ static int json_dispatch_dhcp_lease(sd_dhcp_server *server, JsonVariant *v, bool
|
||||
.n_ref = 1,
|
||||
};
|
||||
|
||||
r = json_dispatch(v, use_boottime ? dispatch_table_boottime : dispatch_table_realtime, JSON_ALLOW_EXTENSIONS, lease);
|
||||
r = sd_json_dispatch(v, use_boottime ? dispatch_table_boottime : dispatch_table_realtime, SD_JSON_ALLOW_EXTENSIONS, lease);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -414,25 +415,25 @@ typedef struct SavedInfo {
|
||||
sd_id128_t boot_id;
|
||||
struct in_addr address;
|
||||
uint8_t prefixlen;
|
||||
JsonVariant *leases;
|
||||
sd_json_variant *leases;
|
||||
} SavedInfo;
|
||||
|
||||
static void saved_info_done(SavedInfo *info) {
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
json_variant_unref(info->leases);
|
||||
sd_json_variant_unref(info->leases);
|
||||
}
|
||||
|
||||
static int load_leases_file(int dir_fd, const char *path, SavedInfo *ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
int r;
|
||||
|
||||
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
|
||||
assert(path);
|
||||
assert(ret);
|
||||
|
||||
r = json_parse_file_at(
|
||||
r = sd_json_parse_file_at(
|
||||
/* f = */ NULL,
|
||||
dir_fd,
|
||||
path,
|
||||
@ -443,15 +444,15 @@ static int load_leases_file(int dir_fd, const char *path, SavedInfo *ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
static const JsonDispatch dispatch_lease_file_table[] = {
|
||||
{ "BootID", JSON_VARIANT_STRING, json_dispatch_id128, offsetof(SavedInfo, boot_id), JSON_MANDATORY },
|
||||
{ "Address", JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(SavedInfo, address), JSON_MANDATORY },
|
||||
{ "PrefixLength", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint8, offsetof(SavedInfo, prefixlen), JSON_MANDATORY },
|
||||
{ "Leases", JSON_VARIANT_ARRAY, json_dispatch_variant, offsetof(SavedInfo, leases), JSON_MANDATORY },
|
||||
static const sd_json_dispatch_field dispatch_lease_file_table[] = {
|
||||
{ "BootID", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(SavedInfo, boot_id), SD_JSON_MANDATORY },
|
||||
{ "Address", SD_JSON_VARIANT_ARRAY, json_dispatch_in_addr, offsetof(SavedInfo, address), SD_JSON_MANDATORY },
|
||||
{ "PrefixLength", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint8, offsetof(SavedInfo, prefixlen), SD_JSON_MANDATORY },
|
||||
{ "Leases", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, offsetof(SavedInfo, leases), SD_JSON_MANDATORY },
|
||||
{}
|
||||
};
|
||||
|
||||
return json_dispatch(v, dispatch_lease_file_table, JSON_ALLOW_EXTENSIONS, ret);
|
||||
return sd_json_dispatch(v, dispatch_lease_file_table, SD_JSON_ALLOW_EXTENSIONS, ret);
|
||||
}
|
||||
|
||||
int dhcp_server_load_leases(sd_dhcp_server *server) {
|
||||
@ -478,7 +479,7 @@ int dhcp_server_load_leases(sd_dhcp_server *server) {
|
||||
|
||||
n = hashmap_size(server->bound_leases_by_client_id);
|
||||
|
||||
JsonVariant *i;
|
||||
sd_json_variant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, info.leases)
|
||||
RET_GATHER(r, json_dispatch_dhcp_lease(server, i, /* use_boottime = */ sd_id128_equal(info.boot_id, boot_id)));
|
||||
|
||||
|
@ -4,13 +4,13 @@
|
||||
#include <linux/sockios.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
#include "sd-lldp-rx.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "event-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "json.h"
|
||||
#include "lldp-neighbor.h"
|
||||
#include "lldp-network.h"
|
||||
#include "lldp-rx-internal.h"
|
||||
@ -491,8 +491,8 @@ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret) {
|
||||
return k;
|
||||
}
|
||||
|
||||
int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
int r;
|
||||
|
||||
assert(lldp_rx);
|
||||
@ -500,13 +500,13 @@ int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, JsonVariant **ret) {
|
||||
|
||||
sd_lldp_neighbor *n;
|
||||
HASHMAP_FOREACH(n, lldp_rx->neighbor_by_id) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
|
||||
r = lldp_neighbor_build_json(n, &w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_append_array(&v, w);
|
||||
r = sd_json_variant_append_array(&v, w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
@ -847,4 +847,104 @@ global:
|
||||
LIBSYSTEMD_257 {
|
||||
global:
|
||||
sd_bus_pending_method_calls;
|
||||
sd_json_build;
|
||||
sd_json_buildv;
|
||||
sd_json_dispatch;
|
||||
sd_json_dispatch_const_string;
|
||||
sd_json_dispatch_full;
|
||||
sd_json_dispatch_id128;
|
||||
sd_json_dispatch_int16;
|
||||
sd_json_dispatch_int32;
|
||||
sd_json_dispatch_int64;
|
||||
sd_json_dispatch_int8;
|
||||
sd_json_dispatch_intbool;
|
||||
sd_json_dispatch_stdbool;
|
||||
sd_json_dispatch_string;
|
||||
sd_json_dispatch_strv;
|
||||
sd_json_dispatch_tristate;
|
||||
sd_json_dispatch_uid_gid;
|
||||
sd_json_dispatch_uint16;
|
||||
sd_json_dispatch_uint32;
|
||||
sd_json_dispatch_uint64;
|
||||
sd_json_dispatch_uint8;
|
||||
sd_json_dispatch_unsupported;
|
||||
sd_json_dispatch_variant;
|
||||
sd_json_dispatch_variant_noref;
|
||||
sd_json_parse;
|
||||
sd_json_parse_continue;
|
||||
sd_json_parse_file;
|
||||
sd_json_parse_file_at;
|
||||
sd_json_parse_with_source;
|
||||
sd_json_parse_with_source_continue;
|
||||
sd_json_variant_append_array;
|
||||
sd_json_variant_append_array_nodup;
|
||||
sd_json_variant_append_arrayb;
|
||||
sd_json_variant_boolean;
|
||||
sd_json_variant_by_index;
|
||||
sd_json_variant_by_key;
|
||||
sd_json_variant_by_key_full;
|
||||
sd_json_variant_dump;
|
||||
sd_json_variant_elements;
|
||||
sd_json_variant_equal;
|
||||
sd_json_variant_filter;
|
||||
sd_json_variant_find;
|
||||
sd_json_variant_format;
|
||||
sd_json_variant_get_source;
|
||||
sd_json_variant_has_type;
|
||||
sd_json_variant_integer;
|
||||
sd_json_variant_is_array;
|
||||
sd_json_variant_is_blank_array;
|
||||
sd_json_variant_is_blank_object;
|
||||
sd_json_variant_is_boolean;
|
||||
sd_json_variant_is_integer;
|
||||
sd_json_variant_is_negative;
|
||||
sd_json_variant_is_normalized;
|
||||
sd_json_variant_is_null;
|
||||
sd_json_variant_is_number;
|
||||
sd_json_variant_is_object;
|
||||
sd_json_variant_is_real;
|
||||
sd_json_variant_is_sensitive;
|
||||
sd_json_variant_is_sensitive_recursive;
|
||||
sd_json_variant_is_sorted;
|
||||
sd_json_variant_is_string;
|
||||
sd_json_variant_is_unsigned;
|
||||
sd_json_variant_merge_object;
|
||||
sd_json_variant_merge_objectb;
|
||||
sd_json_variant_new_array;
|
||||
sd_json_variant_new_array_bytes;
|
||||
sd_json_variant_new_array_strv;
|
||||
sd_json_variant_new_base32hex;
|
||||
sd_json_variant_new_base64;
|
||||
sd_json_variant_new_boolean;
|
||||
sd_json_variant_new_hex;
|
||||
sd_json_variant_new_id128;
|
||||
sd_json_variant_new_integer;
|
||||
sd_json_variant_new_null;
|
||||
sd_json_variant_new_object;
|
||||
sd_json_variant_new_octescape;
|
||||
sd_json_variant_new_real;
|
||||
sd_json_variant_new_string;
|
||||
sd_json_variant_new_stringn;
|
||||
sd_json_variant_new_unsigned;
|
||||
sd_json_variant_new_uuid;
|
||||
sd_json_variant_normalize;
|
||||
sd_json_variant_real;
|
||||
sd_json_variant_ref;
|
||||
sd_json_variant_sensitive;
|
||||
sd_json_variant_set_field;
|
||||
sd_json_variant_set_field_boolean;
|
||||
sd_json_variant_set_field_integer;
|
||||
sd_json_variant_set_field_string;
|
||||
sd_json_variant_set_field_strv;
|
||||
sd_json_variant_set_field_unsigned;
|
||||
sd_json_variant_set_fieldb;
|
||||
sd_json_variant_sort;
|
||||
sd_json_variant_string;
|
||||
sd_json_variant_strv;
|
||||
sd_json_variant_type;
|
||||
sd_json_variant_unbase64;
|
||||
sd_json_variant_unhex;
|
||||
sd_json_variant_unref;
|
||||
sd_json_variant_unref_many;
|
||||
sd_json_variant_unsigned;
|
||||
} LIBSYSTEMD_256;
|
||||
|
@ -66,6 +66,13 @@ sd_login_sources = files('sd-login/sd-login.c')
|
||||
|
||||
############################################################
|
||||
|
||||
sd_json_sources = files(
|
||||
'sd-json/json-util.c',
|
||||
'sd-json/sd-json.c',
|
||||
)
|
||||
|
||||
############################################################
|
||||
|
||||
libsystemd_sources = files(
|
||||
'sd-bus/bus-common-errors.c',
|
||||
'sd-bus/bus-container.c',
|
||||
@ -109,7 +116,7 @@ libsystemd_sources = files(
|
||||
'sd-network/sd-network.c',
|
||||
'sd-path/sd-path.c',
|
||||
'sd-resolve/sd-resolve.c',
|
||||
) + sd_journal_sources + id128_sources + sd_daemon_sources + sd_event_sources + sd_login_sources
|
||||
) + sd_journal_sources + id128_sources + sd_daemon_sources + sd_event_sources + sd_login_sources + sd_json_sources
|
||||
|
||||
libsystemd_c_args = ['-fvisibility=default']
|
||||
|
||||
@ -120,6 +127,7 @@ libsystemd_static = static_library(
|
||||
c_args : libsystemd_c_args,
|
||||
link_with : [libbasic],
|
||||
dependencies : [threads,
|
||||
libm,
|
||||
librt,
|
||||
userspace],
|
||||
build_by_default : false)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "json.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
/* This header should include all prototypes only the JSON parser itself and
|
||||
* its tests need access to. Normal code consuming the JSON parser should not
|
||||
@ -23,31 +23,31 @@ assert_cc(sizeof(JsonValue) == 8U);
|
||||
|
||||
#define JSON_VALUE_NULL ((JsonValue) {})
|
||||
|
||||
/* We use fake JsonVariant objects for some special values, in order to avoid memory allocations for them. Note that
|
||||
/* We use fake sd_json_variant objects for some special values, in order to avoid memory allocations for them. Note that
|
||||
* effectively this means that there are multiple ways to encode the same objects: via these magic values or as
|
||||
* properly allocated JsonVariant. We convert between both on-the-fly as necessary. */
|
||||
* properly allocated sd_json_variant. We convert between both on-the-fly as necessary. */
|
||||
enum
|
||||
{
|
||||
_JSON_VARIANT_MAGIC_TRUE = 1,
|
||||
#define JSON_VARIANT_MAGIC_TRUE ((JsonVariant*) _JSON_VARIANT_MAGIC_TRUE)
|
||||
#define JSON_VARIANT_MAGIC_TRUE ((sd_json_variant*) _JSON_VARIANT_MAGIC_TRUE)
|
||||
_JSON_VARIANT_MAGIC_FALSE,
|
||||
#define JSON_VARIANT_MAGIC_FALSE ((JsonVariant*) _JSON_VARIANT_MAGIC_FALSE)
|
||||
#define JSON_VARIANT_MAGIC_FALSE ((sd_json_variant*) _JSON_VARIANT_MAGIC_FALSE)
|
||||
_JSON_VARIANT_MAGIC_NULL,
|
||||
#define JSON_VARIANT_MAGIC_NULL ((JsonVariant*) _JSON_VARIANT_MAGIC_NULL)
|
||||
#define JSON_VARIANT_MAGIC_NULL ((sd_json_variant*) _JSON_VARIANT_MAGIC_NULL)
|
||||
_JSON_VARIANT_MAGIC_ZERO_INTEGER,
|
||||
#define JSON_VARIANT_MAGIC_ZERO_INTEGER ((JsonVariant*) _JSON_VARIANT_MAGIC_ZERO_INTEGER)
|
||||
#define JSON_VARIANT_MAGIC_ZERO_INTEGER ((sd_json_variant*) _JSON_VARIANT_MAGIC_ZERO_INTEGER)
|
||||
_JSON_VARIANT_MAGIC_ZERO_UNSIGNED,
|
||||
#define JSON_VARIANT_MAGIC_ZERO_UNSIGNED ((JsonVariant*) _JSON_VARIANT_MAGIC_ZERO_UNSIGNED)
|
||||
#define JSON_VARIANT_MAGIC_ZERO_UNSIGNED ((sd_json_variant*) _JSON_VARIANT_MAGIC_ZERO_UNSIGNED)
|
||||
_JSON_VARIANT_MAGIC_ZERO_REAL,
|
||||
#define JSON_VARIANT_MAGIC_ZERO_REAL ((JsonVariant*) _JSON_VARIANT_MAGIC_ZERO_REAL)
|
||||
#define JSON_VARIANT_MAGIC_ZERO_REAL ((sd_json_variant*) _JSON_VARIANT_MAGIC_ZERO_REAL)
|
||||
_JSON_VARIANT_MAGIC_EMPTY_STRING,
|
||||
#define JSON_VARIANT_MAGIC_EMPTY_STRING ((JsonVariant*) _JSON_VARIANT_MAGIC_EMPTY_STRING)
|
||||
#define JSON_VARIANT_MAGIC_EMPTY_STRING ((sd_json_variant*) _JSON_VARIANT_MAGIC_EMPTY_STRING)
|
||||
_JSON_VARIANT_MAGIC_EMPTY_ARRAY,
|
||||
#define JSON_VARIANT_MAGIC_EMPTY_ARRAY ((JsonVariant*) _JSON_VARIANT_MAGIC_EMPTY_ARRAY)
|
||||
#define JSON_VARIANT_MAGIC_EMPTY_ARRAY ((sd_json_variant*) _JSON_VARIANT_MAGIC_EMPTY_ARRAY)
|
||||
_JSON_VARIANT_MAGIC_EMPTY_OBJECT,
|
||||
#define JSON_VARIANT_MAGIC_EMPTY_OBJECT ((JsonVariant*) _JSON_VARIANT_MAGIC_EMPTY_OBJECT)
|
||||
#define JSON_VARIANT_MAGIC_EMPTY_OBJECT ((sd_json_variant*) _JSON_VARIANT_MAGIC_EMPTY_OBJECT)
|
||||
__JSON_VARIANT_MAGIC_MAX
|
||||
#define _JSON_VARIANT_MAGIC_MAX ((JsonVariant*) __JSON_VARIANT_MAGIC_MAX)
|
||||
#define _JSON_VARIANT_MAGIC_MAX ((sd_json_variant*) __JSON_VARIANT_MAGIC_MAX)
|
||||
};
|
||||
|
||||
/* This is only safe as long as we don't define more than 4K magic pointers, i.e. the page size of the simplest
|
135
src/libsystemd/sd-json/json-util.c
Normal file
135
src/libsystemd/sd-json/json-util.c
Normal file
@ -0,0 +1,135 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "glyph-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "iovec-util.h"
|
||||
#include "json-util.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "user-util.h"
|
||||
|
||||
int json_dispatch_unbase64_iovec(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
_cleanup_free_ void *buffer = NULL;
|
||||
struct iovec *iov = ASSERT_PTR(userdata);
|
||||
size_t sz;
|
||||
int r;
|
||||
|
||||
if (!sd_json_variant_is_string(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name));
|
||||
|
||||
r = sd_json_variant_unbase64(variant, &buffer, &sz);
|
||||
if (r < 0)
|
||||
return json_log(variant, flags, r, "JSON field '%s' is not valid Base64 data.", strna(name));
|
||||
|
||||
free_and_replace(iov->iov_base, buffer);
|
||||
iov->iov_len = sz;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int json_dispatch_byte_array_iovec(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
_cleanup_free_ uint8_t *buffer = NULL;
|
||||
struct iovec *iov = ASSERT_PTR(userdata);
|
||||
size_t sz, k = 0;
|
||||
|
||||
assert(variant);
|
||||
|
||||
if (!sd_json_variant_is_array(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array.", strna(name));
|
||||
|
||||
sz = sd_json_variant_elements(variant);
|
||||
|
||||
buffer = new(uint8_t, sz + 1);
|
||||
if (!buffer)
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(ENOMEM), "Out of memory.");
|
||||
|
||||
sd_json_variant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, variant) {
|
||||
uint64_t b;
|
||||
|
||||
if (!sd_json_variant_is_unsigned(i))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Element %zu of JSON field '%s' is not an unsigned integer.", k, strna(name));
|
||||
|
||||
b = sd_json_variant_unsigned(i);
|
||||
if (b > 0xff)
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL),
|
||||
"Element %zu of JSON field '%s' is out of range 0%s255.",
|
||||
k, strna(name), special_glyph(SPECIAL_GLYPH_ELLIPSIS));
|
||||
|
||||
buffer[k++] = (uint8_t) b;
|
||||
}
|
||||
assert(k == sz);
|
||||
|
||||
/* Append a NUL byte for safety, like we do in memdup_suffix0() and others. */
|
||||
buffer[sz] = 0;
|
||||
|
||||
free_and_replace(iov->iov_base, buffer);
|
||||
iov->iov_len = sz;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int json_dispatch_user_group_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
char **s = userdata;
|
||||
const char *n;
|
||||
int r;
|
||||
|
||||
if (sd_json_variant_is_null(variant)) {
|
||||
*s = mfree(*s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!sd_json_variant_is_string(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name));
|
||||
|
||||
n = sd_json_variant_string(variant);
|
||||
if (!valid_user_group_name(n, FLAGS_SET(flags, SD_JSON_RELAX) ? VALID_USER_RELAX : 0))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid user/group name.", strna(name));
|
||||
|
||||
r = free_and_strdup(s, n);
|
||||
if (r < 0)
|
||||
return json_log(variant, flags, r, "Failed to allocate string: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int json_dispatch_in_addr(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
struct in_addr *address = ASSERT_PTR(userdata);
|
||||
_cleanup_(iovec_done) struct iovec iov = {};
|
||||
int r;
|
||||
|
||||
r = json_dispatch_byte_array_iovec(name, variant, flags, &iov);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (iov.iov_len != sizeof(struct in_addr))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is array of unexpected size.", strna(name));
|
||||
|
||||
memcpy(address, iov.iov_base, iov.iov_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int json_dispatch_path(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
char **p = ASSERT_PTR(userdata);
|
||||
const char *path;
|
||||
|
||||
assert(variant);
|
||||
|
||||
if (sd_json_variant_is_null(variant)) {
|
||||
*p = mfree(*p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!sd_json_variant_is_string(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name));
|
||||
|
||||
path = sd_json_variant_string(variant);
|
||||
if (!((flags & SD_JSON_SAFE) ? path_is_normalized(path) : path_is_valid(path)))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a normalized file system path.", strna(name));
|
||||
if (!path_is_absolute(path))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an absolute file system path.", strna(name));
|
||||
|
||||
if (free_and_strdup(p, path) < 0)
|
||||
return json_log_oom(variant, flags);
|
||||
|
||||
return 0;
|
||||
}
|
178
src/libsystemd/sd-json/json-util.h
Normal file
178
src/libsystemd/sd-json/json-util.h
Normal file
@ -0,0 +1,178 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
#define JSON_VARIANT_REPLACE(v, q) \
|
||||
do { \
|
||||
typeof(v)* _v = &(v); \
|
||||
typeof(q) _q = (q); \
|
||||
sd_json_variant_unref(*_v); \
|
||||
*_v = _q; \
|
||||
} while(false)
|
||||
|
||||
static inline int json_variant_set_field_non_null(sd_json_variant **v, const char *field, sd_json_variant *value) {
|
||||
return value && !sd_json_variant_is_null(value) ? sd_json_variant_set_field(v, field, value) : 0;
|
||||
}
|
||||
|
||||
struct json_variant_foreach_state {
|
||||
sd_json_variant *variant;
|
||||
size_t idx;
|
||||
};
|
||||
|
||||
#define _JSON_VARIANT_ARRAY_FOREACH(i, v, state) \
|
||||
for (struct json_variant_foreach_state state = { (v), 0 }; \
|
||||
sd_json_variant_is_array(state.variant) && \
|
||||
state.idx < sd_json_variant_elements(state.variant) && \
|
||||
({ i = sd_json_variant_by_index(state.variant, state.idx); \
|
||||
true; }); \
|
||||
state.idx++)
|
||||
#define JSON_VARIANT_ARRAY_FOREACH(i, v) \
|
||||
_JSON_VARIANT_ARRAY_FOREACH(i, v, UNIQ_T(state, UNIQ))
|
||||
|
||||
#define _JSON_VARIANT_OBJECT_FOREACH(k, e, v, state) \
|
||||
for (struct json_variant_foreach_state state = { (v), 0 }; \
|
||||
sd_json_variant_is_object(state.variant) && \
|
||||
state.idx < sd_json_variant_elements(state.variant) && \
|
||||
({ k = sd_json_variant_string(sd_json_variant_by_index(state.variant, state.idx)); \
|
||||
e = sd_json_variant_by_index(state.variant, state.idx + 1); \
|
||||
true; }); \
|
||||
state.idx += 2)
|
||||
#define JSON_VARIANT_OBJECT_FOREACH(k, e, v) \
|
||||
_JSON_VARIANT_OBJECT_FOREACH(k, e, v, UNIQ_T(state, UNIQ))
|
||||
|
||||
#define JSON_DISPATCH_ENUM_DEFINE(name, type, func) \
|
||||
int name(const char *n, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { \
|
||||
type *c = ASSERT_PTR(userdata); \
|
||||
\
|
||||
assert(variant); \
|
||||
\
|
||||
if (sd_json_variant_is_null(variant)) { \
|
||||
*c = (type) -EINVAL; \
|
||||
return 0; \
|
||||
} \
|
||||
\
|
||||
if (!sd_json_variant_is_string(variant)) \
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(n)); \
|
||||
\
|
||||
type cc = func(sd_json_variant_string(variant)); \
|
||||
if (cc < 0) \
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Value of JSON field '%s' not recognized.", strna(n)); \
|
||||
\
|
||||
*c = cc; \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
static inline int json_dispatch_level(sd_json_dispatch_flags_t flags) {
|
||||
|
||||
/* Did the user request no logging? If so, then never log higher than LOG_DEBUG. Also, if this is marked as
|
||||
* debug message, then also log at debug level. */
|
||||
|
||||
if (!(flags & SD_JSON_LOG) ||
|
||||
(flags & SD_JSON_DEBUG))
|
||||
return LOG_DEBUG;
|
||||
|
||||
/* Are we invoked in permissive mode, or is this explicitly marked as warning message? Then this should be
|
||||
* printed at LOG_WARNING */
|
||||
if (flags & (SD_JSON_PERMISSIVE|SD_JSON_WARNING))
|
||||
return LOG_WARNING;
|
||||
|
||||
/* Otherwise it's an error. */
|
||||
return LOG_ERR;
|
||||
}
|
||||
|
||||
int json_log_internal(sd_json_variant *variant, int level, int error, const char *file, int line, const char *func, const char *format, ...) _printf_(7, 8);
|
||||
|
||||
#define json_log(variant, flags, error, ...) \
|
||||
({ \
|
||||
int _level = json_dispatch_level(flags), _e = (error); \
|
||||
(log_get_max_level() >= LOG_PRI(_level)) \
|
||||
? json_log_internal(variant, _level, _e, PROJECT_FILE, __LINE__, __func__, __VA_ARGS__) \
|
||||
: -ERRNO_VALUE(_e); \
|
||||
})
|
||||
|
||||
#define json_log_oom(variant, flags) \
|
||||
json_log(variant, flags, SYNTHETIC_ERRNO(ENOMEM), "Out of memory.")
|
||||
|
||||
int json_dispatch_unbase64_iovec(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
|
||||
int json_dispatch_byte_array_iovec(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
|
||||
int json_dispatch_user_group_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
|
||||
int json_dispatch_in_addr(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
|
||||
int json_dispatch_path(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
|
||||
|
||||
static inline int json_variant_unbase64_iovec(sd_json_variant *v, struct iovec *ret) {
|
||||
return sd_json_variant_unbase64(v, ret ? &ret->iov_base : NULL, ret ? &ret->iov_len : NULL);
|
||||
}
|
||||
|
||||
static inline int json_variant_unhex_iovec(sd_json_variant *v, struct iovec *ret) {
|
||||
return sd_json_variant_unhex(v, ret ? &ret->iov_base : NULL, ret ? &ret->iov_len : NULL);
|
||||
}
|
||||
|
||||
#define JSON_VARIANT_STRING_CONST(x) _JSON_VARIANT_STRING_CONST(UNIQ, (x))
|
||||
|
||||
#define _JSON_VARIANT_STRING_CONST(xq, x) \
|
||||
({ \
|
||||
_align_(2) static const char UNIQ_T(json_string_const, xq)[] = (x); \
|
||||
assert((((uintptr_t) UNIQ_T(json_string_const, xq)) & 1) == 0); \
|
||||
(sd_json_variant*) ((uintptr_t) UNIQ_T(json_string_const, xq) + 1); \
|
||||
})
|
||||
|
||||
enum {
|
||||
/* This extends the _SD_JSON_BUILD_* enums we define in the public API with some additional values
|
||||
* that we want to keep private for now. (Mostly because the underlying structures are not public, or
|
||||
* because we aren't sure yet they are useful for others). */
|
||||
_JSON_BUILD_STRV_ENV_PAIR = _SD_JSON_BUILD_MAX,
|
||||
_JSON_BUILD_IOVEC_BASE64,
|
||||
_JSON_BUILD_IOVEC_HEX,
|
||||
_JSON_BUILD_HW_ADDR,
|
||||
_JSON_BUILD_STRING_SET,
|
||||
|
||||
_JSON_BUILD_PAIR_UNSIGNED_NON_ZERO,
|
||||
_JSON_BUILD_PAIR_FINITE_USEC,
|
||||
_JSON_BUILD_PAIR_STRING_NON_EMPTY,
|
||||
_JSON_BUILD_PAIR_STRV_NON_EMPTY,
|
||||
_JSON_BUILD_PAIR_VARIANT_NON_NULL,
|
||||
/* _SD_JSON_BUILD_PAIR_VARIANT_ARRAY_NON_EMPTY, */
|
||||
_JSON_BUILD_PAIR_IN4_ADDR_NON_NULL,
|
||||
_JSON_BUILD_PAIR_IN6_ADDR_NON_NULL,
|
||||
_JSON_BUILD_PAIR_IN_ADDR_NON_NULL,
|
||||
_JSON_BUILD_PAIR_ETHER_ADDR_NON_NULL,
|
||||
_JSON_BUILD_PAIR_HW_ADDR_NON_NULL,
|
||||
|
||||
_SD_JSON_BUILD_REALLYMAX,
|
||||
};
|
||||
|
||||
#define JSON_BUILD_STRV_ENV_PAIR(l) _JSON_BUILD_STRV_ENV_PAIR, (char**) { l }
|
||||
#define JSON_BUILD_IOVEC_BASE64(iov) _JSON_BUILD_IOVEC_BASE64, (const struct iovec*) { iov }
|
||||
#define JSON_BUILD_IOVEC_HEX(iov) _JSON_BUILD_IOVEC_HEX, (const struct iovec*) { iov }
|
||||
#define JSON_BUILD_CONST_STRING(s) _SD_JSON_BUILD_VARIANT, JSON_VARIANT_STRING_CONST(s)
|
||||
#define JSON_BUILD_IN4_ADDR(v) SD_JSON_BUILD_BYTE_ARRAY((const struct in_addr*) { v }, sizeof(struct in_addr))
|
||||
#define JSON_BUILD_IN6_ADDR(v) SD_JSON_BUILD_BYTE_ARRAY((const struct in6_addr*) { v }, sizeof(struct in6_addr))
|
||||
#define JSON_BUILD_IN_ADDR(v, f) SD_JSON_BUILD_BYTE_ARRAY(((const union in_addr_union*) { v })->bytes, FAMILY_ADDRESS_SIZE_SAFE(f))
|
||||
#define JSON_BUILD_ETHER_ADDR(v) SD_JSON_BUILD_BYTE_ARRAY(((const struct ether_addr*) { v })->ether_addr_octet, sizeof(struct ether_addr))
|
||||
#define JSON_BUILD_HW_ADDR(v) _JSON_BUILD_HW_ADDR, (const struct hw_addr_data*) { v }
|
||||
#define JSON_BUILD_STRING_SET(s) _JSON_BUILD_STRING_SET, (Set *) { s }
|
||||
|
||||
#define JSON_BUILD_PAIR_UNSIGNED_NON_ZERO(name, u) _JSON_BUILD_PAIR_UNSIGNED_NON_ZERO, (const char*) { name }, (uint64_t) { u }
|
||||
#define JSON_BUILD_PAIR_FINITE_USEC(name, u) _JSON_BUILD_PAIR_FINITE_USEC, (const char*) { name }, (usec_t) { u }
|
||||
#define JSON_BUILD_PAIR_STRING_NON_EMPTY(name, s) _JSON_BUILD_PAIR_STRING_NON_EMPTY, (const char*) { name }, (const char*) { s }
|
||||
#define JSON_BUILD_PAIR_STRV_NON_EMPTY(name, l) _JSON_BUILD_PAIR_STRV_NON_EMPTY, (const char*) { name }, (char**) { l }
|
||||
#define JSON_BUILD_PAIR_VARIANT_NON_NULL(name, v) _JSON_BUILD_PAIR_VARIANT_NON_NULL, (const char*) { name }, (sd_json_variant*) { v }
|
||||
#define JSON_BUILD_PAIR_IN4_ADDR_NON_NULL(name, v) _JSON_BUILD_PAIR_IN4_ADDR_NON_NULL, (const char*) { name }, (const struct in_addr*) { v }
|
||||
#define JSON_BUILD_PAIR_IN6_ADDR_NON_NULL(name, v) _JSON_BUILD_PAIR_IN6_ADDR_NON_NULL, (const char*) { name }, (const struct in6_addr*) { v }
|
||||
#define JSON_BUILD_PAIR_IN_ADDR_NON_NULL(name, v, f) _JSON_BUILD_PAIR_IN_ADDR_NON_NULL, (const char*) { name }, (const union in_addr_union*) { v }, (int) { f }
|
||||
#define JSON_BUILD_PAIR_ETHER_ADDR_NON_NULL(name, v) _JSON_BUILD_PAIR_ETHER_ADDR_NON_NULL, (const char*) { name }, (const struct ether_addr*) { v }
|
||||
#define JSON_BUILD_PAIR_HW_ADDR_NON_NULL(name, v) _JSON_BUILD_PAIR_HW_ADDR_NON_NULL, (const char*) { name }, (const struct hw_addr_data*) { v }
|
||||
|
||||
#define JSON_BUILD_PAIR_IOVEC_BASE64(name, iov) SD_JSON_BUILD_PAIR(name, JSON_BUILD_IOVEC_BASE64(iov))
|
||||
#define JSON_BUILD_PAIR_IOVEC_HEX(name, iov) SD_JSON_BUILD_PAIR(name, JSON_BUILD_IOVEC_HEX(iov))
|
||||
#define JSON_BUILD_PAIR_IN4_ADDR(name, v) SD_JSON_BUILD_PAIR(name, JSON_BUILD_IN4_ADDR(v))
|
||||
#define JSON_BUILD_PAIR_IN6_ADDR(name, v) SD_JSON_BUILD_PAIR(name, JSON_BUILD_IN6_ADDR(v))
|
||||
#define JSON_BUILD_PAIR_IN_ADDR(name, v, f) SD_JSON_BUILD_PAIR(name, JSON_BUILD_IN_ADDR(v, f))
|
||||
#define JSON_BUILD_PAIR_ETHER_ADDR(name, v) SD_JSON_BUILD_PAIR(name, JSON_BUILD_ETHER_ADDR(v))
|
||||
#define JSON_BUILD_PAIR_HW_ADDR(name, v) SD_JSON_BUILD_PAIR(name, JSON_BUILD_HW_ADDR(v))
|
||||
#define JSON_BUILD_PAIR_STRING_SET(name, s) SD_JSON_BUILD_PAIR(name, JSON_BUILD_STRING_SET(s))
|
File diff suppressed because it is too large
Load Diff
@ -44,7 +44,7 @@ static BusPrintPropertyFlags arg_print_flags = 0;
|
||||
static bool arg_full = false;
|
||||
static PagerFlags arg_pager_flags = 0;
|
||||
static bool arg_legend = true;
|
||||
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
static sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
static const char *arg_kill_whom = NULL;
|
||||
static int arg_signal = SIGTERM;
|
||||
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
|
||||
@ -1621,7 +1621,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
|
||||
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
|
||||
arg_legend = false;
|
||||
break;
|
||||
|
||||
@ -1630,7 +1630,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
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))
|
||||
arg_legend = false;
|
||||
|
||||
break;
|
||||
|
@ -196,10 +196,10 @@ static int acquire_user_record(
|
||||
if (!IN_SET(r, PAM_SUCCESS, PAM_NO_MODULE_DATA))
|
||||
return pam_syslog_pam_error(handle, LOG_ERR, r, "Failed to get PAM user record data: @PAMERR@");
|
||||
if (r == PAM_SUCCESS && json) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
/* Parse cached record */
|
||||
r = json_parse(json, JSON_PARSE_SENSITIVE, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_SENSITIVE, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return pam_syslog_errno(handle, LOG_ERR, r, "Failed to parse JSON user record: %m");
|
||||
|
||||
@ -225,7 +225,7 @@ static int acquire_user_record(
|
||||
return PAM_USER_UNKNOWN;
|
||||
}
|
||||
|
||||
r = json_variant_format(ur->json, 0, &formatted);
|
||||
r = sd_json_variant_format(ur->json, 0, &formatted);
|
||||
if (r < 0)
|
||||
return pam_syslog_errno(handle, LOG_ERR, r, "Failed to format user JSON: %m");
|
||||
|
||||
|
@ -3,9 +3,10 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "hostname-util.h"
|
||||
#include "json.h"
|
||||
#include "json-util.h"
|
||||
#include "machine-varlink.h"
|
||||
#include "machine.h"
|
||||
#include "path-util.h"
|
||||
@ -17,17 +18,17 @@
|
||||
|
||||
static JSON_DISPATCH_ENUM_DEFINE(dispatch_machine_class, MachineClass, machine_class_from_string);
|
||||
|
||||
static int machine_name(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
static int machine_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
char **m = ASSERT_PTR(userdata);
|
||||
const char *hostname;
|
||||
int r;
|
||||
|
||||
assert(variant);
|
||||
|
||||
if (!json_variant_is_string(variant))
|
||||
if (!sd_json_variant_is_string(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name));
|
||||
|
||||
hostname = json_variant_string(variant);
|
||||
hostname = sd_json_variant_string(variant);
|
||||
if (!hostname_is_valid(hostname, /* flags= */ 0))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Invalid machine name");
|
||||
|
||||
@ -38,16 +39,16 @@ static int machine_name(const char *name, JsonVariant *variant, JsonDispatchFlag
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int machine_leader(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
static int machine_leader(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
PidRef *leader = ASSERT_PTR(userdata);
|
||||
_cleanup_(pidref_done) PidRef temp = PIDREF_NULL;
|
||||
uint64_t k;
|
||||
int r;
|
||||
|
||||
if (!json_variant_is_unsigned(variant))
|
||||
if (!sd_json_variant_is_unsigned(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name));
|
||||
|
||||
k = json_variant_unsigned(variant);
|
||||
k = sd_json_variant_unsigned(variant);
|
||||
if (k > PID_T_MAX || !pid_is_valid(k))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid PID.", strna(name));
|
||||
|
||||
@ -65,30 +66,30 @@ static int machine_leader(const char *name, JsonVariant *variant, JsonDispatchFl
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int machine_ifindices(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
static int machine_ifindices(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
Machine *m = ASSERT_PTR(userdata);
|
||||
_cleanup_free_ int *netif = NULL;
|
||||
size_t n_netif, k = 0;
|
||||
|
||||
assert(variant);
|
||||
|
||||
if (!json_variant_is_array(variant))
|
||||
if (!sd_json_variant_is_array(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array.", strna(name));
|
||||
|
||||
n_netif = json_variant_elements(variant);
|
||||
n_netif = sd_json_variant_elements(variant);
|
||||
|
||||
netif = new(int, n_netif);
|
||||
if (!netif)
|
||||
return json_log_oom(variant, flags);
|
||||
|
||||
JsonVariant *i;
|
||||
sd_json_variant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, variant) {
|
||||
uint64_t b;
|
||||
|
||||
if (!json_variant_is_unsigned(i))
|
||||
if (!sd_json_variant_is_unsigned(i))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Element %zu of JSON field '%s' is not an unsigned integer.", k, strna(name));
|
||||
|
||||
b = json_variant_unsigned(i);
|
||||
b = sd_json_variant_unsigned(i);
|
||||
if (b > INT_MAX || b <= 0)
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Invalid network interface index %"PRIu64, b);
|
||||
|
||||
@ -102,15 +103,15 @@ static int machine_ifindices(const char *name, JsonVariant *variant, JsonDispatc
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int machine_cid(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
static int machine_cid(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
unsigned cid, *c = ASSERT_PTR(userdata);
|
||||
|
||||
assert(variant);
|
||||
|
||||
if (!json_variant_is_unsigned(variant))
|
||||
if (!sd_json_variant_is_unsigned(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name));
|
||||
|
||||
cid = json_variant_unsigned(variant);
|
||||
cid = sd_json_variant_unsigned(variant);
|
||||
if (!VSOCK_CID_IS_REGULAR(cid))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a regular VSOCK CID.", strna(name));
|
||||
|
||||
@ -119,22 +120,22 @@ static int machine_cid(const char *name, JsonVariant *variant, JsonDispatchFlags
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vl_method_register(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
Manager *manager = ASSERT_PTR(userdata);
|
||||
_cleanup_(machine_freep) Machine *machine = NULL;
|
||||
int r;
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "name", JSON_VARIANT_STRING, machine_name, offsetof(Machine, name), JSON_MANDATORY },
|
||||
{ "id", JSON_VARIANT_STRING, json_dispatch_id128, offsetof(Machine, id), 0 },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_string, offsetof(Machine, service), 0 },
|
||||
{ "class", JSON_VARIANT_STRING, dispatch_machine_class, offsetof(Machine, class), JSON_MANDATORY },
|
||||
{ "leader", JSON_VARIANT_UNSIGNED, machine_leader, offsetof(Machine, leader), 0 },
|
||||
{ "rootDirectory", JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, root_directory), 0 },
|
||||
{ "ifIndices", JSON_VARIANT_ARRAY, machine_ifindices, 0, 0 },
|
||||
{ "vSockCid", JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 },
|
||||
{ "sshAddress", JSON_VARIANT_STRING, json_dispatch_string, offsetof(Machine, ssh_address), JSON_SAFE },
|
||||
{ "sshPrivateKeyPath", JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "name", SD_JSON_VARIANT_STRING, machine_name, offsetof(Machine, name), SD_JSON_MANDATORY },
|
||||
{ "id", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(Machine, id), 0 },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, service), 0 },
|
||||
{ "class", SD_JSON_VARIANT_STRING, dispatch_machine_class, offsetof(Machine, class), SD_JSON_MANDATORY },
|
||||
{ "leader", SD_JSON_VARIANT_UNSIGNED, machine_leader, offsetof(Machine, leader), 0 },
|
||||
{ "rootDirectory", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, root_directory), 0 },
|
||||
{ "ifIndices", SD_JSON_VARIANT_ARRAY, machine_ifindices, 0, 0 },
|
||||
{ "vSockCid", SD_JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 },
|
||||
{ "sshAddress", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, ssh_address), SD_JSON_SAFE },
|
||||
{ "sshPrivateKeyPath", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -3,4 +3,4 @@
|
||||
|
||||
#include "varlink.h"
|
||||
|
||||
int vl_method_register(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "format-table.h"
|
||||
#include "hostname-util.h"
|
||||
#include "import-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "locale-util.h"
|
||||
#include "log.h"
|
||||
#include "logs-show.h"
|
||||
@ -261,7 +262,7 @@ static int show_table(Table *table, const char *word) {
|
||||
table_set_header(table, arg_legend);
|
||||
|
||||
if (OUTPUT_MODE_IS_JSON(arg_output))
|
||||
r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO);
|
||||
r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | SD_JSON_FORMAT_COLOR_AUTO);
|
||||
else
|
||||
r = table_print(table, NULL);
|
||||
if (r < 0)
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "format-util.h"
|
||||
#include "json-util.h"
|
||||
#include "machine-varlink.h"
|
||||
#include "machined-varlink.h"
|
||||
#include "mkdir.h"
|
||||
@ -19,22 +20,22 @@ typedef struct LookupParameters {
|
||||
const char *service;
|
||||
} LookupParameters;
|
||||
|
||||
static int build_user_json(const char *user_name, uid_t uid, const char *real_name, JsonVariant **ret) {
|
||||
static int build_user_json(const char *user_name, uid_t uid, const char *real_name, sd_json_variant **ret) {
|
||||
assert(user_name);
|
||||
assert(uid_is_valid(uid));
|
||||
assert(ret);
|
||||
|
||||
return json_build(ret, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("record", JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(user_name)),
|
||||
JSON_BUILD_PAIR("uid", JSON_BUILD_UNSIGNED(uid)),
|
||||
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(GID_NOBODY)),
|
||||
JSON_BUILD_PAIR_CONDITION(!isempty(real_name), "realName", JSON_BUILD_STRING(real_name)),
|
||||
JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_CONST_STRING("/")),
|
||||
JSON_BUILD_PAIR("shell", JSON_BUILD_STRING(NOLOGIN)),
|
||||
JSON_BUILD_PAIR("locked", JSON_BUILD_BOOLEAN(true)),
|
||||
JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Machine")),
|
||||
JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("container"))))));
|
||||
return sd_json_build(ret, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(user_name)),
|
||||
SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(uid)),
|
||||
SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(GID_NOBODY)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!isempty(real_name), "realName", SD_JSON_BUILD_STRING(real_name)),
|
||||
SD_JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_CONST_STRING("/")),
|
||||
SD_JSON_BUILD_PAIR("shell", JSON_BUILD_CONST_STRING(NOLOGIN)),
|
||||
SD_JSON_BUILD_PAIR("locked", SD_JSON_BUILD_BOOLEAN(true)),
|
||||
SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Machine")),
|
||||
SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("container"))))));
|
||||
}
|
||||
|
||||
static bool user_match_lookup_parameters(LookupParameters *p, const char *name, uid_t uid) {
|
||||
@ -138,16 +139,16 @@ static int user_lookup_name(Manager *m, const char *name, uid_t *ret_uid, char *
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_get_user_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "uid", JSON_VARIANT_UNSIGNED, json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 },
|
||||
{ "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "uid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, uid), 0 },
|
||||
{ "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
LookupParameters p = {
|
||||
.uid = UID_INVALID,
|
||||
};
|
||||
@ -190,18 +191,18 @@ static int vl_method_get_user_record(Varlink *link, JsonVariant *parameters, Var
|
||||
return varlink_reply(link, v);
|
||||
}
|
||||
|
||||
static int build_group_json(const char *group_name, gid_t gid, const char *description, JsonVariant **ret) {
|
||||
static int build_group_json(const char *group_name, gid_t gid, const char *description, sd_json_variant **ret) {
|
||||
assert(group_name);
|
||||
assert(gid_is_valid(gid));
|
||||
assert(ret);
|
||||
|
||||
return json_build(ret, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("record", JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(group_name)),
|
||||
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(gid)),
|
||||
JSON_BUILD_PAIR_CONDITION(!isempty(description), "description", JSON_BUILD_STRING(description)),
|
||||
JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Machine")),
|
||||
JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("container"))))));
|
||||
return sd_json_build(ret, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("record", SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(group_name)),
|
||||
SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(gid)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!isempty(description), "description", SD_JSON_BUILD_STRING(description)),
|
||||
SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.Machine")),
|
||||
SD_JSON_BUILD_PAIR("disposition", JSON_BUILD_CONST_STRING("container"))))));
|
||||
}
|
||||
|
||||
static bool group_match_lookup_parameters(LookupParameters *p, const char *name, gid_t gid) {
|
||||
@ -303,16 +304,16 @@ static int group_lookup_name(Manager *m, const char *name, gid_t *ret_gid, char
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_get_group_record(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "gid", JSON_VARIANT_UNSIGNED, json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 },
|
||||
{ "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "gid", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uid_gid, offsetof(LookupParameters, gid), 0 },
|
||||
{ "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
LookupParameters p = {
|
||||
.gid = GID_INVALID,
|
||||
};
|
||||
@ -355,12 +356,12 @@ static int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, Va
|
||||
return varlink_reply(link, v);
|
||||
}
|
||||
|
||||
static int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_get_memberships(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), JSON_SAFE },
|
||||
{ "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), JSON_SAFE },
|
||||
{ "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "userName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, user_name), SD_JSON_SAFE },
|
||||
{ "groupName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, group_name), SD_JSON_SAFE },
|
||||
{ "service", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LookupParameters, service), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "io-util.h"
|
||||
#include "json-util.h"
|
||||
#include "main-func.h"
|
||||
#include "missing_loop.h"
|
||||
#include "namespace-util.h"
|
||||
@ -37,22 +38,22 @@ static const ImagePolicy image_policy_untrusted = {
|
||||
.default_flags = PARTITION_POLICY_IGNORE,
|
||||
};
|
||||
|
||||
static int json_dispatch_image_policy(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
||||
static int json_dispatch_image_policy(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
_cleanup_(image_policy_freep) ImagePolicy *q = NULL;
|
||||
ImagePolicy **p = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
assert(p);
|
||||
|
||||
if (json_variant_is_null(variant)) {
|
||||
if (sd_json_variant_is_null(variant)) {
|
||||
*p = image_policy_free(*p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!json_variant_is_string(variant))
|
||||
if (!sd_json_variant_is_string(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name));
|
||||
|
||||
r = image_policy_from_string(json_variant_string(variant), &q);
|
||||
r = image_policy_from_string(sd_json_variant_string(variant), &q);
|
||||
if (r < 0)
|
||||
return json_log(variant, flags, r, "JSON field '%s' is not a valid image policy.", strna(name));
|
||||
|
||||
@ -245,17 +246,17 @@ static int validate_userns(Varlink *link, int *userns_fd) {
|
||||
|
||||
static int vl_method_mount_image(
|
||||
Varlink *link,
|
||||
JsonVariant *parameters,
|
||||
sd_json_variant *parameters,
|
||||
VarlinkMethodFlags flags,
|
||||
void *userdata) {
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "imageFileDescriptor", JSON_VARIANT_UNSIGNED, json_dispatch_uint, offsetof(MountImageParameters, image_fd_idx), JSON_MANDATORY },
|
||||
{ "userNamespaceFileDescriptor", JSON_VARIANT_UNSIGNED, json_dispatch_uint, offsetof(MountImageParameters, userns_fd_idx), 0 },
|
||||
{ "readOnly", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(MountImageParameters, read_only), 0 },
|
||||
{ "growFileSystems", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(MountImageParameters, growfs), 0 },
|
||||
{ "password", JSON_VARIANT_STRING, json_dispatch_string, offsetof(MountImageParameters, password), 0 },
|
||||
{ "imagePolicy", JSON_VARIANT_STRING, json_dispatch_image_policy, offsetof(MountImageParameters, image_policy), 0 },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "imageFileDescriptor", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint, offsetof(MountImageParameters, image_fd_idx), SD_JSON_MANDATORY },
|
||||
{ "userNamespaceFileDescriptor", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint, offsetof(MountImageParameters, userns_fd_idx), 0 },
|
||||
{ "readOnly", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_tristate, offsetof(MountImageParameters, read_only), 0 },
|
||||
{ "growFileSystems", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_tristate, offsetof(MountImageParameters, growfs), 0 },
|
||||
{ "password", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(MountImageParameters, password), 0 },
|
||||
{ "imagePolicy", SD_JSON_VARIANT_STRING, json_dispatch_image_policy, offsetof(MountImageParameters, image_policy), 0 },
|
||||
VARLINK_DISPATCH_POLKIT_FIELD,
|
||||
{}
|
||||
};
|
||||
@ -269,7 +270,7 @@ static int vl_method_mount_image(
|
||||
};
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *di = NULL;
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *aj = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *aj = NULL;
|
||||
_cleanup_close_ int image_fd = -EBADF, userns_fd = -EBADF;
|
||||
_cleanup_(image_policy_freep) ImagePolicy *use_policy = NULL;
|
||||
Hashmap **polkit_registry = ASSERT_PTR(userdata);
|
||||
@ -281,7 +282,7 @@ static int vl_method_mount_image(
|
||||
assert(link);
|
||||
assert(parameters);
|
||||
|
||||
json_variant_sensitive(parameters); /* might contain passwords */
|
||||
sd_json_variant_sensitive(parameters); /* might contain passwords */
|
||||
|
||||
r = varlink_get_peer_uid(link, &peer_uid);
|
||||
if (r < 0)
|
||||
@ -486,7 +487,7 @@ static int vl_method_mount_image(
|
||||
return r;
|
||||
|
||||
for (PartitionDesignator d = 0; d < _PARTITION_DESIGNATOR_MAX; d++) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *pj = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *pj = NULL;
|
||||
DissectedPartition *pp = di->partitions + d;
|
||||
int fd_idx;
|
||||
|
||||
@ -508,35 +509,35 @@ static int vl_method_mount_image(
|
||||
|
||||
TAKE_FD(pp->fsmount_fd);
|
||||
|
||||
r = json_build(&pj,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("designator", JSON_BUILD_STRING(partition_designator_to_string(d))),
|
||||
JSON_BUILD_PAIR("writable", JSON_BUILD_BOOLEAN(pp->rw)),
|
||||
JSON_BUILD_PAIR("growFileSystem", JSON_BUILD_BOOLEAN(pp->growfs)),
|
||||
JSON_BUILD_PAIR_CONDITION(pp->partno > 0, "partitionNumber", JSON_BUILD_INTEGER(pp->partno)),
|
||||
JSON_BUILD_PAIR_CONDITION(pp->architecture > 0, "architecture", JSON_BUILD_STRING(architecture_to_string(pp->architecture))),
|
||||
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(pp->uuid), "partitionUuid", JSON_BUILD_UUID(pp->uuid)),
|
||||
JSON_BUILD_PAIR("fileSystemType", JSON_BUILD_STRING(dissected_partition_fstype(pp))),
|
||||
JSON_BUILD_PAIR_CONDITION(pp->label, "partitionLabel", JSON_BUILD_STRING(pp->label)),
|
||||
JSON_BUILD_PAIR("size", JSON_BUILD_INTEGER(pp->size)),
|
||||
JSON_BUILD_PAIR("offset", JSON_BUILD_INTEGER(pp->offset)),
|
||||
JSON_BUILD_PAIR("mountFileDescriptor", JSON_BUILD_INTEGER(fd_idx))));
|
||||
r = sd_json_build(&pj,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("designator", SD_JSON_BUILD_STRING(partition_designator_to_string(d))),
|
||||
SD_JSON_BUILD_PAIR("writable", SD_JSON_BUILD_BOOLEAN(pp->rw)),
|
||||
SD_JSON_BUILD_PAIR("growFileSystem", SD_JSON_BUILD_BOOLEAN(pp->growfs)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(pp->partno > 0, "partitionNumber", SD_JSON_BUILD_INTEGER(pp->partno)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(pp->architecture > 0, "architecture", SD_JSON_BUILD_STRING(architecture_to_string(pp->architecture))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(pp->uuid), "partitionUuid", SD_JSON_BUILD_UUID(pp->uuid)),
|
||||
SD_JSON_BUILD_PAIR("fileSystemType", SD_JSON_BUILD_STRING(dissected_partition_fstype(pp))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!!pp->label, "partitionLabel", SD_JSON_BUILD_STRING(pp->label)),
|
||||
SD_JSON_BUILD_PAIR("size", SD_JSON_BUILD_INTEGER(pp->size)),
|
||||
SD_JSON_BUILD_PAIR("offset", SD_JSON_BUILD_INTEGER(pp->offset)),
|
||||
SD_JSON_BUILD_PAIR("mountFileDescriptor", SD_JSON_BUILD_INTEGER(fd_idx))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_append_array(&aj, pj);
|
||||
r = sd_json_variant_append_array(&aj, pj);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
loop_device_relinquish(loop);
|
||||
|
||||
r = varlink_replyb(link, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("partitions", JSON_BUILD_VARIANT(aj)),
|
||||
JSON_BUILD_PAIR("imagePolicy", JSON_BUILD_STRING(ps)),
|
||||
JSON_BUILD_PAIR("imageSize", JSON_BUILD_INTEGER(di->image_size)),
|
||||
JSON_BUILD_PAIR("sectorSize", JSON_BUILD_INTEGER(di->sector_size)),
|
||||
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(di->image_uuid), "imageUuid", JSON_BUILD_UUID(di->image_uuid))));
|
||||
r = varlink_replyb(link, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("partitions", SD_JSON_BUILD_VARIANT(aj)),
|
||||
SD_JSON_BUILD_PAIR("imagePolicy", SD_JSON_BUILD_STRING(ps)),
|
||||
SD_JSON_BUILD_PAIR("imageSize", SD_JSON_BUILD_INTEGER(di->image_size)),
|
||||
SD_JSON_BUILD_PAIR("sectorSize", SD_JSON_BUILD_INTEGER(di->sector_size)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(di->image_uuid), "imageUuid", SD_JSON_BUILD_UUID(di->image_uuid))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "sd-device.h"
|
||||
#include "sd-dhcp-client.h"
|
||||
#include "sd-hwdb.h"
|
||||
#include "sd-json.h"
|
||||
#include "sd-netlink.h"
|
||||
#include "sd-network.h"
|
||||
|
||||
@ -39,6 +40,7 @@
|
||||
#include "hwdb-util.h"
|
||||
#include "ipvlan-util.h"
|
||||
#include "journal-internal.h"
|
||||
#include "json-util.h"
|
||||
#include "local-addresses.h"
|
||||
#include "locale-util.h"
|
||||
#include "logs-show.h"
|
||||
@ -90,13 +92,13 @@ bool arg_full = false;
|
||||
bool arg_runtime = false;
|
||||
unsigned arg_lines = 10;
|
||||
char *arg_drop_in = NULL;
|
||||
JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
|
||||
sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
|
||||
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_drop_in, freep);
|
||||
|
||||
static int varlink_connect_networkd(Varlink **ret_varlink) {
|
||||
_cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL;
|
||||
JsonVariant *reply;
|
||||
sd_json_variant *reply;
|
||||
uint64_t id;
|
||||
int r;
|
||||
|
||||
@ -114,12 +116,12 @@ static int varlink_connect_networkd(Varlink **ret_varlink) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "NamespaceId", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, 0, JSON_MANDATORY },
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "NamespaceId", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint64, 0, SD_JSON_MANDATORY },
|
||||
{},
|
||||
};
|
||||
|
||||
r = json_dispatch(reply, dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &id);
|
||||
r = sd_json_dispatch(reply, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &id);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -181,7 +183,7 @@ int acquire_bus(sd_bus **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_description(sd_bus *bus, JsonVariant **ret) {
|
||||
static int get_description(sd_bus *bus, sd_json_variant **ret) {
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||
const char *text;
|
||||
@ -198,7 +200,7 @@ static int get_description(sd_bus *bus, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
r = json_parse(text, 0, ret, NULL, NULL);
|
||||
r = sd_json_parse(text, 0, ret, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse JSON: %m");
|
||||
|
||||
@ -206,7 +208,7 @@ static int get_description(sd_bus *bus, JsonVariant **ret) {
|
||||
}
|
||||
|
||||
static int dump_manager_description(sd_bus *bus) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
int r;
|
||||
|
||||
assert(bus);
|
||||
@ -215,14 +217,14 @@ static int dump_manager_description(sd_bus *bus) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
sd_json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dump_link_description(sd_bus *bus, char * const *patterns) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ bool *matched_patterns = NULL;
|
||||
JsonVariant *i;
|
||||
sd_json_variant *i;
|
||||
size_t c = 0;
|
||||
int r;
|
||||
|
||||
@ -237,23 +239,23 @@ static int dump_link_description(sd_bus *bus, char * const *patterns) {
|
||||
if (!matched_patterns)
|
||||
return log_oom();
|
||||
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, json_variant_by_key(v, "Interfaces")) {
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(v, "Interfaces")) {
|
||||
char ifindex_str[DECIMAL_STR_MAX(int64_t)];
|
||||
const char *name;
|
||||
int64_t index;
|
||||
size_t pos;
|
||||
|
||||
name = json_variant_string(json_variant_by_key(i, "Name"));
|
||||
index = json_variant_integer(json_variant_by_key(i, "Index"));
|
||||
name = sd_json_variant_string(sd_json_variant_by_key(i, "Name"));
|
||||
index = sd_json_variant_integer(sd_json_variant_by_key(i, "Index"));
|
||||
xsprintf(ifindex_str, "%" PRIi64, index);
|
||||
|
||||
if (!strv_fnmatch_full(patterns, ifindex_str, 0, &pos) &&
|
||||
!strv_fnmatch_full(patterns, name, 0, &pos)) {
|
||||
bool match = false;
|
||||
JsonVariant *a;
|
||||
sd_json_variant *a;
|
||||
|
||||
JSON_VARIANT_ARRAY_FOREACH(a, json_variant_by_key(i, "AlternativeNames"))
|
||||
if (strv_fnmatch_full(patterns, json_variant_string(a), 0, &pos)) {
|
||||
JSON_VARIANT_ARRAY_FOREACH(a, sd_json_variant_by_key(i, "AlternativeNames"))
|
||||
if (strv_fnmatch_full(patterns, sd_json_variant_string(a), 0, &pos)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
@ -263,7 +265,7 @@ static int dump_link_description(sd_bus *bus, char * const *patterns) {
|
||||
}
|
||||
|
||||
matched_patterns[pos] = true;
|
||||
json_variant_dump(i, arg_json_format_flags, NULL, NULL);
|
||||
sd_json_variant_dump(i, arg_json_format_flags, NULL, NULL);
|
||||
c++;
|
||||
}
|
||||
|
||||
@ -921,7 +923,7 @@ static int list_links(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (arg_json_format_flags != JSON_FORMAT_OFF) {
|
||||
if (arg_json_format_flags != SD_JSON_FORMAT_OFF) {
|
||||
if (arg_all || argc <= 1)
|
||||
return dump_manager_description(bus);
|
||||
else
|
||||
@ -1322,7 +1324,7 @@ typedef struct InterfaceInfo {
|
||||
int ifindex;
|
||||
const char *ifname;
|
||||
char **altnames;
|
||||
JsonVariant *v;
|
||||
sd_json_variant *v;
|
||||
} InterfaceInfo;
|
||||
|
||||
static void interface_info_done(InterfaceInfo *p) {
|
||||
@ -1330,14 +1332,14 @@ static void interface_info_done(InterfaceInfo *p) {
|
||||
return;
|
||||
|
||||
strv_free(p->altnames);
|
||||
json_variant_unref(p->v);
|
||||
sd_json_variant_unref(p->v);
|
||||
}
|
||||
|
||||
static const JsonDispatch interface_info_dispatch_table[] = {
|
||||
{ "InterfaceIndex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(InterfaceInfo, ifindex), JSON_MANDATORY },
|
||||
{ "InterfaceName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(InterfaceInfo, ifname), JSON_MANDATORY },
|
||||
{ "InterfaceAlternativeNames", JSON_VARIANT_ARRAY, json_dispatch_strv, offsetof(InterfaceInfo, altnames), 0 },
|
||||
{ "Neighbors", JSON_VARIANT_ARRAY, json_dispatch_variant, offsetof(InterfaceInfo, v), 0 },
|
||||
static const sd_json_dispatch_field interface_info_dispatch_table[] = {
|
||||
{ "InterfaceIndex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(InterfaceInfo, ifindex), SD_JSON_MANDATORY },
|
||||
{ "InterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(InterfaceInfo, ifname), SD_JSON_MANDATORY },
|
||||
{ "InterfaceAlternativeNames", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_strv, offsetof(InterfaceInfo, altnames), 0 },
|
||||
{ "Neighbors", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, offsetof(InterfaceInfo, v), 0 },
|
||||
{},
|
||||
};
|
||||
|
||||
@ -1350,19 +1352,19 @@ typedef struct LLDPNeighborInfo {
|
||||
uint16_t capabilities;
|
||||
} LLDPNeighborInfo;
|
||||
|
||||
static const JsonDispatch lldp_neighbor_dispatch_table[] = {
|
||||
{ "ChassisID", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, chassis_id), 0 },
|
||||
{ "PortID", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, port_id), 0 },
|
||||
{ "PortDescription", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, port_description), 0 },
|
||||
{ "SystemName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, system_name), 0 },
|
||||
{ "SystemDescription", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, system_description), 0 },
|
||||
{ "EnabledCapabilities", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint16, offsetof(LLDPNeighborInfo, capabilities), 0 },
|
||||
static const sd_json_dispatch_field lldp_neighbor_dispatch_table[] = {
|
||||
{ "ChassisID", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, chassis_id), 0 },
|
||||
{ "PortID", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, port_id), 0 },
|
||||
{ "PortDescription", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, port_description), 0 },
|
||||
{ "SystemName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, system_name), 0 },
|
||||
{ "SystemDescription", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, system_description), 0 },
|
||||
{ "EnabledCapabilities", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(LLDPNeighborInfo, capabilities), 0 },
|
||||
{},
|
||||
};
|
||||
|
||||
static int dump_lldp_neighbors(Varlink *vl, Table *table, int ifindex) {
|
||||
_cleanup_strv_free_ char **buf = NULL;
|
||||
JsonVariant *reply;
|
||||
sd_json_variant *reply;
|
||||
int r;
|
||||
|
||||
assert(vl);
|
||||
@ -1370,26 +1372,26 @@ static int dump_lldp_neighbors(Varlink *vl, Table *table, int ifindex) {
|
||||
assert(ifindex > 0);
|
||||
|
||||
r = varlink_callb_and_log(vl, "io.systemd.Network.GetLLDPNeighbors", &reply,
|
||||
JSON_BUILD_OBJECT(JSON_BUILD_PAIR_INTEGER("InterfaceIndex", ifindex)));
|
||||
SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_INTEGER("InterfaceIndex", ifindex)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
JsonVariant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, json_variant_by_key(reply, "Neighbors")) {
|
||||
sd_json_variant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(reply, "Neighbors")) {
|
||||
_cleanup_(interface_info_done) InterfaceInfo info = {};
|
||||
|
||||
r = json_dispatch(i, interface_info_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &info);
|
||||
r = sd_json_dispatch(i, interface_info_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &info);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (info.ifindex != ifindex)
|
||||
continue;
|
||||
|
||||
JsonVariant *neighbor;
|
||||
sd_json_variant *neighbor;
|
||||
JSON_VARIANT_ARRAY_FOREACH(neighbor, info.v) {
|
||||
LLDPNeighborInfo neighbor_info = {};
|
||||
|
||||
r = json_dispatch(neighbor, lldp_neighbor_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &neighbor_info);
|
||||
r = sd_json_dispatch(neighbor, lldp_neighbor_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &neighbor_info);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -2431,7 +2433,7 @@ static int link_status(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (arg_json_format_flags != JSON_FORMAT_OFF) {
|
||||
if (arg_json_format_flags != SD_JSON_FORMAT_OFF) {
|
||||
if (arg_all || argc <= 1)
|
||||
return dump_manager_description(bus);
|
||||
else
|
||||
@ -2547,47 +2549,47 @@ static bool interface_match_pattern(const InterfaceInfo *info, char * const *pat
|
||||
return false;
|
||||
}
|
||||
|
||||
static int dump_lldp_neighbors_json(JsonVariant *reply, char * const *patterns) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL, *v = NULL;
|
||||
static int dump_lldp_neighbors_json(sd_json_variant *reply, char * const *patterns) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL, *v = NULL;
|
||||
int r;
|
||||
|
||||
assert(reply);
|
||||
|
||||
if (strv_isempty(patterns))
|
||||
return json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
|
||||
return sd_json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
|
||||
|
||||
/* Filter and dump the result. */
|
||||
|
||||
JsonVariant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, json_variant_by_key(reply, "Neighbors")) {
|
||||
sd_json_variant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(reply, "Neighbors")) {
|
||||
_cleanup_(interface_info_done) InterfaceInfo info = {};
|
||||
|
||||
r = json_dispatch(i, interface_info_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &info);
|
||||
r = sd_json_dispatch(i, interface_info_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &info);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!interface_match_pattern(&info, patterns))
|
||||
continue;
|
||||
|
||||
r = json_variant_append_array(&array, i);
|
||||
r = sd_json_variant_append_array(&array, i);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to append json variant to array: %m");
|
||||
}
|
||||
|
||||
r = json_build(&v,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_CONDITION(json_variant_is_blank_array(array), "Neighbors", JSON_BUILD_EMPTY_ARRAY),
|
||||
JSON_BUILD_PAIR_CONDITION(!json_variant_is_blank_array(array), "Neighbors", JSON_BUILD_VARIANT(array))));
|
||||
r = sd_json_build(&v,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_CONDITION(sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_EMPTY_ARRAY),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_VARIANT(array))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build json varinat: %m");
|
||||
|
||||
return json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
return sd_json_variant_dump(v, arg_json_format_flags, NULL, NULL);
|
||||
}
|
||||
|
||||
static int link_lldp_status(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL;
|
||||
_cleanup_(table_unrefp) Table *table = NULL;
|
||||
JsonVariant *reply;
|
||||
sd_json_variant *reply;
|
||||
uint64_t all = 0;
|
||||
TableCell *cell;
|
||||
size_t m = 0;
|
||||
@ -2601,7 +2603,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (arg_json_format_flags != JSON_FORMAT_OFF)
|
||||
if (arg_json_format_flags != SD_JSON_FORMAT_OFF)
|
||||
return dump_lldp_neighbors_json(reply, strv_skip(argv, 1));
|
||||
|
||||
pager_open(arg_pager_flags);
|
||||
@ -2629,22 +2631,22 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
|
||||
assert_se(cell = table_get_cell(table, 0, 7));
|
||||
table_set_minimum_width(table, cell, 11);
|
||||
|
||||
JsonVariant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, json_variant_by_key(reply, "Neighbors")) {
|
||||
sd_json_variant *i;
|
||||
JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(reply, "Neighbors")) {
|
||||
_cleanup_(interface_info_done) InterfaceInfo info = {};
|
||||
|
||||
r = json_dispatch(i, interface_info_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &info);
|
||||
r = sd_json_dispatch(i, interface_info_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &info);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!interface_match_pattern(&info, strv_skip(argv, 1)))
|
||||
continue;
|
||||
|
||||
JsonVariant *neighbor;
|
||||
sd_json_variant *neighbor;
|
||||
JSON_VARIANT_ARRAY_FOREACH(neighbor, info.v) {
|
||||
LLDPNeighborInfo neighbor_info = {};
|
||||
|
||||
r = json_dispatch(neighbor, lldp_neighbor_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &neighbor_info);
|
||||
r = sd_json_dispatch(neighbor, lldp_neighbor_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &neighbor_info);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -2954,7 +2956,7 @@ static int verb_persistent_storage(int argc, char *argv[], void *userdata) {
|
||||
}
|
||||
|
||||
return varlink_callb_and_log(vl, "io.systemd.Network.SetPersistentStorage", /* reply = */ NULL,
|
||||
JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BOOLEAN("Ready", ready)));
|
||||
SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_BOOLEAN("Ready", ready)));
|
||||
}
|
||||
|
||||
static int help(void) {
|
||||
|
@ -17,7 +17,7 @@ extern bool arg_full;
|
||||
extern bool arg_runtime;
|
||||
extern unsigned arg_lines;
|
||||
extern char *arg_drop_in;
|
||||
extern JsonFormatFlags arg_json_format_flags;
|
||||
extern sd_json_format_flags_t arg_json_format_flags;
|
||||
|
||||
bool networkd_is_running(void);
|
||||
int acquire_bus(sd_bus **ret);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "dhcp6-lease-internal.h"
|
||||
#include "dns-domain.h"
|
||||
#include "ip-protocol-list.h"
|
||||
#include "json-util.h"
|
||||
#include "netif-util.h"
|
||||
#include "networkd-address.h"
|
||||
#include "networkd-dhcp-common.h"
|
||||
@ -22,11 +23,12 @@
|
||||
#include "networkd-route.h"
|
||||
#include "networkd-routing-policy-rule.h"
|
||||
#include "sort-util.h"
|
||||
#include "strv.h"
|
||||
#include "udev-util.h"
|
||||
#include "user-util.h"
|
||||
#include "wifi-util.h"
|
||||
|
||||
static int address_append_json(Address *address, JsonVariant **array) {
|
||||
static int address_append_json(Address *address, sd_json_variant **array) {
|
||||
_cleanup_free_ char *scope = NULL, *flags = NULL, *state = NULL;
|
||||
int r;
|
||||
|
||||
@ -45,30 +47,30 @@ static int address_append_json(Address *address, JsonVariant **array) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_INTEGER("Family", address->family),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_INTEGER("Family", address->family),
|
||||
JSON_BUILD_PAIR_IN_ADDR("Address", &address->in_addr, address->family),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Peer", &address->in_addr_peer, address->family),
|
||||
JSON_BUILD_PAIR_IN4_ADDR_NON_NULL("Broadcast", &address->broadcast),
|
||||
JSON_BUILD_PAIR_UNSIGNED("PrefixLength", address->prefixlen),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Scope", address->scope),
|
||||
JSON_BUILD_PAIR_STRING("ScopeString", scope),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Flags", address->flags),
|
||||
JSON_BUILD_PAIR_STRING("FlagsString", flags),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", address->prefixlen),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Scope", address->scope),
|
||||
SD_JSON_BUILD_PAIR_STRING("ScopeString", scope),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Flags", address->flags),
|
||||
SD_JSON_BUILD_PAIR_STRING("FlagsString", flags),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("Label", address->label),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("PreferredLifetimeUSec", address->lifetime_preferred_usec),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("PreferredLifetimeUsec", address->lifetime_preferred_usec), /* for backward compat */
|
||||
JSON_BUILD_PAIR_FINITE_USEC("ValidLifetimeUSec", address->lifetime_valid_usec),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("ValidLifetimeUsec", address->lifetime_valid_usec), /* for backward compat */
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(address->source)),
|
||||
JSON_BUILD_PAIR_STRING("ConfigState", state),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(address->source)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigState", state),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", &address->provider, address->family)));
|
||||
}
|
||||
|
||||
static int addresses_append_json(Set *addresses, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int addresses_append_json(Set *addresses, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
Address *address;
|
||||
int r;
|
||||
|
||||
@ -83,7 +85,7 @@ static int addresses_append_json(Set *addresses, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "Addresses", array);
|
||||
}
|
||||
|
||||
static int neighbor_append_json(Neighbor *n, JsonVariant **array) {
|
||||
static int neighbor_append_json(Neighbor *n, sd_json_variant **array) {
|
||||
_cleanup_free_ char *state = NULL;
|
||||
int r;
|
||||
|
||||
@ -94,18 +96,18 @@ static int neighbor_append_json(Neighbor *n, JsonVariant **array) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_INTEGER("Family", n->family),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_INTEGER("Family", n->family),
|
||||
JSON_BUILD_PAIR_IN_ADDR("Destination", &n->in_addr, n->family),
|
||||
JSON_BUILD_PAIR_HW_ADDR("LinkLayerAddress", &n->ll_addr),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(n->source)),
|
||||
JSON_BUILD_PAIR_STRING("ConfigState", state)));
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(n->source)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigState", state)));
|
||||
}
|
||||
|
||||
static int neighbors_append_json(Set *neighbors, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int neighbors_append_json(Set *neighbors, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
Neighbor *neighbor;
|
||||
int r;
|
||||
|
||||
@ -120,8 +122,8 @@ static int neighbors_append_json(Set *neighbors, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "Neighbors", array);
|
||||
}
|
||||
|
||||
static int nexthop_group_build_json(NextHop *nexthop, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int nexthop_group_build_json(NextHop *nexthop, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
struct nexthop_grp *g;
|
||||
int r;
|
||||
|
||||
@ -129,11 +131,11 @@ static int nexthop_group_build_json(NextHop *nexthop, JsonVariant **ret) {
|
||||
assert(ret);
|
||||
|
||||
HASHMAP_FOREACH(g, nexthop->group) {
|
||||
r = json_variant_append_arrayb(
|
||||
r = sd_json_variant_append_arrayb(
|
||||
&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_UNSIGNED("ID", g->id),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Weight", g->weight+1)));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("ID", g->id),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Weight", g->weight+1)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -142,8 +144,8 @@ static int nexthop_group_build_json(NextHop *nexthop, JsonVariant **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nexthop_append_json(NextHop *n, JsonVariant **array) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *group = NULL;
|
||||
static int nexthop_append_json(NextHop *n, sd_json_variant **array) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *group = NULL;
|
||||
_cleanup_free_ char *flags = NULL, *protocol = NULL, *state = NULL;
|
||||
int r;
|
||||
|
||||
@ -166,23 +168,23 @@ static int nexthop_append_json(NextHop *n, JsonVariant **array) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_UNSIGNED("ID", n->id),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("ID", n->id),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Gateway", &n->gw, n->family),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Flags", n->flags),
|
||||
JSON_BUILD_PAIR_STRING("FlagsString", strempty(flags)),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Protocol", n->protocol),
|
||||
JSON_BUILD_PAIR_STRING("ProtocolString", protocol),
|
||||
JSON_BUILD_PAIR_BOOLEAN("Blackhole", n->blackhole),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Flags", n->flags),
|
||||
SD_JSON_BUILD_PAIR_STRING("FlagsString", strempty(flags)),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Protocol", n->protocol),
|
||||
SD_JSON_BUILD_PAIR_STRING("ProtocolString", protocol),
|
||||
SD_JSON_BUILD_PAIR_BOOLEAN("Blackhole", n->blackhole),
|
||||
JSON_BUILD_PAIR_VARIANT_NON_NULL("Group", group),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(n->source)),
|
||||
JSON_BUILD_PAIR_STRING("ConfigState", state)));
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(n->source)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigState", state)));
|
||||
}
|
||||
|
||||
static int nexthops_append_json(Manager *manager, int ifindex, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int nexthops_append_json(Manager *manager, int ifindex, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
NextHop *nexthop;
|
||||
int r;
|
||||
|
||||
@ -201,7 +203,7 @@ static int nexthops_append_json(Manager *manager, int ifindex, JsonVariant **v)
|
||||
return json_variant_set_field_non_null(v, "NextHops", array);
|
||||
}
|
||||
|
||||
static int route_append_json(Route *route, JsonVariant **array) {
|
||||
static int route_append_json(Route *route, sd_json_variant **array) {
|
||||
_cleanup_free_ char *scope = NULL, *protocol = NULL, *table = NULL, *flags = NULL, *state = NULL;
|
||||
int r;
|
||||
|
||||
@ -228,38 +230,38 @@ static int route_append_json(Route *route, JsonVariant **array) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_INTEGER("Family", route->family),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_INTEGER("Family", route->family),
|
||||
JSON_BUILD_PAIR_IN_ADDR("Destination", &route->dst, route->family),
|
||||
JSON_BUILD_PAIR_UNSIGNED("DestinationPrefixLength", route->dst_prefixlen),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("DestinationPrefixLength", route->dst_prefixlen),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Gateway", &route->nexthop.gw, route->nexthop.family),
|
||||
JSON_BUILD_PAIR_CONDITION(route->src_prefixlen > 0,
|
||||
SD_JSON_BUILD_PAIR_CONDITION(route->src_prefixlen > 0,
|
||||
"Source", JSON_BUILD_IN_ADDR(&route->src, route->family)),
|
||||
JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("SourcePrefixLength", route->src_prefixlen),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("PreferredSource", &route->prefsrc, route->family),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Scope", route->scope),
|
||||
JSON_BUILD_PAIR_STRING("ScopeString", scope),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Protocol", route->protocol),
|
||||
JSON_BUILD_PAIR_STRING("ProtocolString", protocol),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Type", route->type),
|
||||
JSON_BUILD_PAIR_STRING("TypeString", route_type_to_string(route->type)),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Priority", route->priority),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Table", route->table),
|
||||
JSON_BUILD_PAIR_STRING("TableString", table),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Scope", route->scope),
|
||||
SD_JSON_BUILD_PAIR_STRING("ScopeString", scope),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Protocol", route->protocol),
|
||||
SD_JSON_BUILD_PAIR_STRING("ProtocolString", protocol),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Type", route->type),
|
||||
SD_JSON_BUILD_PAIR_STRING("TypeString", route_type_to_string(route->type)),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Priority", route->priority),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Table", route->table),
|
||||
SD_JSON_BUILD_PAIR_STRING("TableString", table),
|
||||
JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("MTU", route_metric_get(&route->metric, RTAX_MTU)),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Preference", route->pref),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Flags", route->flags),
|
||||
JSON_BUILD_PAIR_STRING("FlagsString", strempty(flags)),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Preference", route->pref),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Flags", route->flags),
|
||||
SD_JSON_BUILD_PAIR_STRING("FlagsString", strempty(flags)),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("LifetimeUSec", route->lifetime_usec),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(route->source)),
|
||||
JSON_BUILD_PAIR_STRING("ConfigState", state),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(route->source)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigState", state),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", &route->provider, route->family)));
|
||||
}
|
||||
|
||||
static int routes_append_json(Manager *manager, int ifindex, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int routes_append_json(Manager *manager, int ifindex, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
Route *route;
|
||||
int r;
|
||||
|
||||
@ -278,7 +280,7 @@ static int routes_append_json(Manager *manager, int ifindex, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "Routes", array);
|
||||
}
|
||||
|
||||
static int routing_policy_rule_append_json(RoutingPolicyRule *rule, JsonVariant **array) {
|
||||
static int routing_policy_rule_append_json(RoutingPolicyRule *rule, sd_json_variant **array) {
|
||||
_cleanup_free_ char *table = NULL, *protocol = NULL, *state = NULL;
|
||||
int r;
|
||||
|
||||
@ -298,47 +300,47 @@ static int routing_policy_rule_append_json(RoutingPolicyRule *rule, JsonVariant
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_INTEGER("Family", rule->family),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_INTEGER("Family", rule->family),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("FromPrefix", &rule->from, rule->family),
|
||||
JSON_BUILD_PAIR_CONDITION(in_addr_is_set(rule->family, &rule->from),
|
||||
"FromPrefixLength", JSON_BUILD_UNSIGNED(rule->from_prefixlen)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(in_addr_is_set(rule->family, &rule->from),
|
||||
"FromPrefixLength", SD_JSON_BUILD_UNSIGNED(rule->from_prefixlen)),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ToPrefix", &rule->to, rule->family),
|
||||
JSON_BUILD_PAIR_CONDITION(in_addr_is_set(rule->family, &rule->to),
|
||||
"ToPrefixLength", JSON_BUILD_UNSIGNED(rule->to_prefixlen)),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Protocol", rule->protocol),
|
||||
JSON_BUILD_PAIR_STRING("ProtocolString", protocol),
|
||||
JSON_BUILD_PAIR_UNSIGNED("TOS", rule->tos),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Type", rule->type),
|
||||
JSON_BUILD_PAIR_STRING("TypeString", fr_act_type_full_to_string(rule->type)),
|
||||
JSON_BUILD_PAIR_UNSIGNED("IPProtocol", rule->ipproto),
|
||||
JSON_BUILD_PAIR_STRING("IPProtocolString", ip_protocol_to_name(rule->ipproto)),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Priority", rule->priority),
|
||||
JSON_BUILD_PAIR_UNSIGNED("FirewallMark", rule->fwmark),
|
||||
JSON_BUILD_PAIR_UNSIGNED("FirewallMask", rule->fwmask),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(in_addr_is_set(rule->family, &rule->to),
|
||||
"ToPrefixLength", SD_JSON_BUILD_UNSIGNED(rule->to_prefixlen)),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Protocol", rule->protocol),
|
||||
SD_JSON_BUILD_PAIR_STRING("ProtocolString", protocol),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("TOS", rule->tos),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Type", rule->type),
|
||||
SD_JSON_BUILD_PAIR_STRING("TypeString", fr_act_type_full_to_string(rule->type)),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("IPProtocol", rule->ipproto),
|
||||
SD_JSON_BUILD_PAIR_STRING("IPProtocolString", ip_protocol_to_name(rule->ipproto)),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Priority", rule->priority),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("FirewallMark", rule->fwmark),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("FirewallMask", rule->fwmask),
|
||||
JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("Table", rule->table),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("TableString", table),
|
||||
JSON_BUILD_PAIR_BOOLEAN("Invert", rule->invert_rule),
|
||||
JSON_BUILD_PAIR_CONDITION(rule->suppress_prefixlen >= 0,
|
||||
"SuppressPrefixLength", JSON_BUILD_UNSIGNED(rule->suppress_prefixlen)),
|
||||
JSON_BUILD_PAIR_CONDITION(rule->suppress_ifgroup >= 0,
|
||||
"SuppressInterfaceGroup", JSON_BUILD_UNSIGNED(rule->suppress_ifgroup)),
|
||||
JSON_BUILD_PAIR_CONDITION(rule->sport.start != 0 || rule->sport.end != 0, "SourcePort",
|
||||
JSON_BUILD_ARRAY(JSON_BUILD_UNSIGNED(rule->sport.start), JSON_BUILD_UNSIGNED(rule->sport.end))),
|
||||
JSON_BUILD_PAIR_CONDITION(rule->dport.start != 0 || rule->dport.end != 0, "DestinationPort",
|
||||
JSON_BUILD_ARRAY(JSON_BUILD_UNSIGNED(rule->dport.start), JSON_BUILD_UNSIGNED(rule->dport.end))),
|
||||
JSON_BUILD_PAIR_CONDITION(rule->uid_range.start != UID_INVALID && rule->uid_range.end != UID_INVALID, "User",
|
||||
JSON_BUILD_ARRAY(JSON_BUILD_UNSIGNED(rule->uid_range.start), JSON_BUILD_UNSIGNED(rule->uid_range.end))),
|
||||
SD_JSON_BUILD_PAIR_BOOLEAN("Invert", rule->invert_rule),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(rule->suppress_prefixlen >= 0,
|
||||
"SuppressPrefixLength", SD_JSON_BUILD_UNSIGNED(rule->suppress_prefixlen)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(rule->suppress_ifgroup >= 0,
|
||||
"SuppressInterfaceGroup", SD_JSON_BUILD_UNSIGNED(rule->suppress_ifgroup)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(rule->sport.start != 0 || rule->sport.end != 0, "SourcePort",
|
||||
SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_UNSIGNED(rule->sport.start), SD_JSON_BUILD_UNSIGNED(rule->sport.end))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(rule->dport.start != 0 || rule->dport.end != 0, "DestinationPort",
|
||||
SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_UNSIGNED(rule->dport.start), SD_JSON_BUILD_UNSIGNED(rule->dport.end))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(rule->uid_range.start != UID_INVALID && rule->uid_range.end != UID_INVALID, "User",
|
||||
SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_UNSIGNED(rule->uid_range.start), SD_JSON_BUILD_UNSIGNED(rule->uid_range.end))),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("IncomingInterface", rule->iif),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("OutgoingInterface", rule->oif),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(rule->source)),
|
||||
JSON_BUILD_PAIR_STRING("ConfigState", state)));
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(rule->source)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigState", state)));
|
||||
}
|
||||
|
||||
static int routing_policy_rules_append_json(Set *rules, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int routing_policy_rules_append_json(Set *rules, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
RoutingPolicyRule *rule;
|
||||
int r;
|
||||
|
||||
@ -353,27 +355,27 @@ static int routing_policy_rules_append_json(Set *rules, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "RoutingPolicyRules", array);
|
||||
}
|
||||
|
||||
static int network_append_json(Network *network, JsonVariant **v) {
|
||||
static int network_append_json(Network *network, sd_json_variant **v) {
|
||||
assert(v);
|
||||
|
||||
if (!network)
|
||||
return 0;
|
||||
|
||||
return json_variant_merge_objectb(
|
||||
v, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING("NetworkFile", network->filename),
|
||||
JSON_BUILD_PAIR_STRV("NetworkFileDropins", network->dropins),
|
||||
JSON_BUILD_PAIR_BOOLEAN("RequiredForOnline", network->required_for_online),
|
||||
JSON_BUILD_PAIR("RequiredOperationalStateForOnline",
|
||||
JSON_BUILD_ARRAY(JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.min)),
|
||||
JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.max)))),
|
||||
JSON_BUILD_PAIR_STRING("RequiredFamilyForOnline",
|
||||
return sd_json_variant_merge_objectb(
|
||||
v, SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_STRING("NetworkFile", network->filename),
|
||||
SD_JSON_BUILD_PAIR_STRV("NetworkFileDropins", network->dropins),
|
||||
SD_JSON_BUILD_PAIR_BOOLEAN("RequiredForOnline", network->required_for_online),
|
||||
SD_JSON_BUILD_PAIR("RequiredOperationalStateForOnline",
|
||||
SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.min)),
|
||||
SD_JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.max)))),
|
||||
SD_JSON_BUILD_PAIR_STRING("RequiredFamilyForOnline",
|
||||
link_required_address_family_to_string(network->required_family_for_online)),
|
||||
JSON_BUILD_PAIR_STRING("ActivationPolicy",
|
||||
SD_JSON_BUILD_PAIR_STRING("ActivationPolicy",
|
||||
activation_policy_to_string(network->activation_policy))));
|
||||
}
|
||||
|
||||
static int device_append_json(sd_device *device, JsonVariant **v) {
|
||||
static int device_append_json(sd_device *device, sd_json_variant **v) {
|
||||
_cleanup_strv_free_ char **link_dropins = NULL;
|
||||
const char *link = NULL, *path = NULL, *vendor = NULL, *model = NULL, *joined;
|
||||
int r;
|
||||
@ -396,9 +398,9 @@ static int device_append_json(sd_device *device, JsonVariant **v) {
|
||||
(void) device_get_vendor_string(device, &vendor);
|
||||
(void) device_get_model_string(device, &model);
|
||||
|
||||
return json_variant_merge_objectb(
|
||||
return sd_json_variant_merge_objectb(
|
||||
v,
|
||||
JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("LinkFile", link),
|
||||
JSON_BUILD_PAIR_STRV_NON_EMPTY("LinkFileDropins", link_dropins),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("Path", path),
|
||||
@ -406,7 +408,7 @@ static int device_append_json(sd_device *device, JsonVariant **v) {
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("Model", model)));
|
||||
}
|
||||
|
||||
static int dns_append_json_one(Link *link, const struct in_addr_full *a, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) {
|
||||
static int dns_append_json_one(Link *link, const struct in_addr_full *a, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) {
|
||||
assert(link);
|
||||
assert(a);
|
||||
assert(array);
|
||||
@ -414,20 +416,20 @@ static int dns_append_json_one(Link *link, const struct in_addr_full *a, Network
|
||||
if (a->ifindex != 0 && a->ifindex != link->ifindex)
|
||||
return 0;
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_INTEGER("Family", a->family),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_INTEGER("Family", a->family),
|
||||
JSON_BUILD_PAIR_IN_ADDR("Address", &a->address, a->family),
|
||||
JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("Port", a->port),
|
||||
JSON_BUILD_PAIR_CONDITION(a->ifindex != 0, "InterfaceIndex", JSON_BUILD_INTEGER(a->ifindex)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(a->ifindex != 0, "InterfaceIndex", SD_JSON_BUILD_INTEGER(a->ifindex)),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("ServerName", a->server_name),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, a->family)));
|
||||
}
|
||||
|
||||
static int dns_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int dns_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -509,34 +511,34 @@ static int dns_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "DNS", array);
|
||||
}
|
||||
|
||||
static int server_append_json_one_addr(int family, const union in_addr_union *a, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) {
|
||||
static int server_append_json_one_addr(int family, const union in_addr_union *a, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) {
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(a);
|
||||
assert(array);
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_INTEGER("Family", family),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_INTEGER("Family", family),
|
||||
JSON_BUILD_PAIR_IN_ADDR("Address", a, family),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family)));
|
||||
}
|
||||
|
||||
static int server_append_json_one_fqdn(int family, const char *fqdn, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) {
|
||||
static int server_append_json_one_fqdn(int family, const char *fqdn, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) {
|
||||
assert(IN_SET(family, AF_UNSPEC, AF_INET, AF_INET6));
|
||||
assert(fqdn);
|
||||
assert(array);
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING("Server", fqdn),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_STRING("Server", fqdn),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family)));
|
||||
}
|
||||
|
||||
static int server_append_json_one_string(const char *str, NetworkConfigSource s, JsonVariant **array) {
|
||||
static int server_append_json_one_string(const char *str, NetworkConfigSource s, sd_json_variant **array) {
|
||||
union in_addr_union a;
|
||||
int family;
|
||||
|
||||
@ -548,8 +550,8 @@ static int server_append_json_one_string(const char *str, NetworkConfigSource s,
|
||||
return server_append_json_one_fqdn(AF_UNSPEC, str, s, NULL, array);
|
||||
}
|
||||
|
||||
static int ntp_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int ntp_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -623,8 +625,8 @@ static int ntp_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "NTP", array);
|
||||
}
|
||||
|
||||
static int sip_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int sip_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
const struct in_addr *sip;
|
||||
union in_addr_union s;
|
||||
int n_sip, r;
|
||||
@ -656,21 +658,21 @@ static int sip_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "SIP", array);
|
||||
}
|
||||
|
||||
static int domain_append_json(int family, const char *domain, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) {
|
||||
static int domain_append_json(int family, const char *domain, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) {
|
||||
assert(IN_SET(family, AF_UNSPEC, AF_INET, AF_INET6));
|
||||
assert(domain);
|
||||
assert(array);
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING("Domain", domain),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_STRING("Domain", domain),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
|
||||
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family)));
|
||||
}
|
||||
|
||||
static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int domains_append_json(Link *link, bool is_route, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
OrderedSet *link_domains, *network_domains;
|
||||
UseDomains use_domains;
|
||||
union in_addr_union s;
|
||||
@ -747,19 +749,19 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, is_route ? "RouteDomains" : "SearchDomains", array);
|
||||
}
|
||||
|
||||
static int nta_append_json(const char *nta, NetworkConfigSource s, JsonVariant **array) {
|
||||
static int nta_append_json(const char *nta, NetworkConfigSource s, sd_json_variant **array) {
|
||||
assert(nta);
|
||||
assert(array);
|
||||
|
||||
return json_variant_append_arrayb(
|
||||
return sd_json_variant_append_arrayb(
|
||||
array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING("DNSSECNegativeTrustAnchor", nta),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_STRING("DNSSECNegativeTrustAnchor", nta),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s))));
|
||||
}
|
||||
|
||||
static int ntas_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int ntas_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
const char *nta;
|
||||
int r;
|
||||
|
||||
@ -780,8 +782,8 @@ static int ntas_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "DNSSECNegativeTrustAnchors", array);
|
||||
}
|
||||
|
||||
static int dns_misc_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int dns_misc_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
ResolveSupport resolve_support;
|
||||
NetworkConfigSource source;
|
||||
DnsOverTlsMode mode;
|
||||
@ -797,11 +799,11 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) {
|
||||
if (resolve_support >= 0) {
|
||||
source = link->llmnr >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
|
||||
|
||||
r = json_variant_append_arrayb(
|
||||
r = sd_json_variant_append_arrayb(
|
||||
&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING("LLMNR", resolve_support_to_string(resolve_support)),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_STRING("LLMNR", resolve_support_to_string(resolve_support)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -810,11 +812,11 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) {
|
||||
if (resolve_support >= 0) {
|
||||
source = link->mdns >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
|
||||
|
||||
r = json_variant_append_arrayb(
|
||||
r = sd_json_variant_append_arrayb(
|
||||
&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING("MDNS", resolve_support_to_string(resolve_support)),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_STRING("MDNS", resolve_support_to_string(resolve_support)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -823,11 +825,11 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) {
|
||||
if (t >= 0) {
|
||||
source = link->dns_default_route >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
|
||||
|
||||
r = json_variant_append_arrayb(
|
||||
r = sd_json_variant_append_arrayb(
|
||||
&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_BOOLEAN("DNSDefaultRoute", t),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_BOOLEAN("DNSDefaultRoute", t),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -836,11 +838,11 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) {
|
||||
if (mode >= 0) {
|
||||
source = link->dns_over_tls_mode >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
|
||||
|
||||
r = json_variant_append_arrayb(
|
||||
r = sd_json_variant_append_arrayb(
|
||||
&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING("DNSOverTLS", dns_over_tls_mode_to_string(mode)),
|
||||
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_STRING("DNSOverTLS", dns_over_tls_mode_to_string(mode)),
|
||||
SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -848,7 +850,7 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "DNSSettings", array);
|
||||
}
|
||||
|
||||
static int captive_portal_append_json(Link *link, JsonVariant **v) {
|
||||
static int captive_portal_append_json(Link *link, sd_json_variant **v) {
|
||||
const char *captive_portal;
|
||||
int r;
|
||||
|
||||
@ -859,11 +861,11 @@ static int captive_portal_append_json(Link *link, JsonVariant **v) {
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("CaptivePortal", captive_portal)));
|
||||
return sd_json_variant_merge_objectb(v, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_STRING("CaptivePortal", captive_portal)));
|
||||
}
|
||||
|
||||
static int pref64_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL, *w = NULL;
|
||||
static int pref64_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL, *w = NULL;
|
||||
NDiscPREF64 *i;
|
||||
int r;
|
||||
|
||||
@ -874,10 +876,10 @@ static int pref64_append_json(Link *link, JsonVariant **v) {
|
||||
return 0;
|
||||
|
||||
SET_FOREACH(i, link->ndisc_pref64) {
|
||||
r = json_variant_append_arrayb(&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
r = sd_json_variant_append_arrayb(&array,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_IN6_ADDR_NON_NULL("Prefix", &i->prefix),
|
||||
JSON_BUILD_PAIR_UNSIGNED("PrefixLength", i->prefix_len),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", i->prefix_len),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("LifetimeUSec", i->lifetime_usec),
|
||||
JSON_BUILD_PAIR_IN6_ADDR_NON_NULL("ConfigProvider", &i->router)));
|
||||
if (r < 0)
|
||||
@ -891,8 +893,8 @@ static int pref64_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "NDisc", w);
|
||||
}
|
||||
|
||||
static int dhcp_server_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
static int dhcp_server_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -901,10 +903,10 @@ static int dhcp_server_append_json(Link *link, JsonVariant **v) {
|
||||
if (!link->dhcp_server)
|
||||
return 0;
|
||||
|
||||
r = json_build(&w,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_UNSIGNED("PoolOffset", link->dhcp_server->pool_offset),
|
||||
JSON_BUILD_PAIR_UNSIGNED("PoolSize", link->dhcp_server->pool_size)));
|
||||
r = sd_json_build(&w,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("PoolOffset", link->dhcp_server->pool_offset),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("PoolSize", link->dhcp_server->pool_size)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -919,8 +921,8 @@ static int dhcp_server_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "DHCPServer", w);
|
||||
}
|
||||
|
||||
static int dhcp6_client_vendor_options_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int dhcp6_client_vendor_options_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
sd_dhcp6_option **options = NULL;
|
||||
int r, n_vendor_options;
|
||||
|
||||
@ -933,11 +935,11 @@ static int dhcp6_client_vendor_options_append_json(Link *link, JsonVariant **v)
|
||||
n_vendor_options = sd_dhcp6_lease_get_vendor_options(link->dhcp6_lease, &options);
|
||||
|
||||
FOREACH_ARRAY(option, options, n_vendor_options) {
|
||||
r = json_variant_append_arrayb(&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_UNSIGNED("EnterpriseId", (*option)->enterprise_identifier),
|
||||
JSON_BUILD_PAIR_UNSIGNED("SubOptionCode", (*option)->option),
|
||||
JSON_BUILD_PAIR_HEX("SubOptionData", (*option)->data, (*option)->length)));
|
||||
r = sd_json_variant_append_arrayb(&array,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("EnterpriseId", (*option)->enterprise_identifier),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("SubOptionCode", (*option)->option),
|
||||
SD_JSON_BUILD_PAIR_HEX("SubOptionData", (*option)->data, (*option)->length)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -945,8 +947,8 @@ static int dhcp6_client_vendor_options_append_json(Link *link, JsonVariant **v)
|
||||
return json_variant_set_field_non_null(v, "VendorSpecificOptions", array);
|
||||
}
|
||||
|
||||
static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
static int dhcp6_client_lease_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
usec_t ts = USEC_INFINITY, t1 = USEC_INFINITY, t2 = USEC_INFINITY;
|
||||
int r;
|
||||
|
||||
@ -968,7 +970,7 @@ static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) {
|
||||
if (r < 0 && r != -ENODATA)
|
||||
return r;
|
||||
|
||||
r = json_build(&w, JSON_BUILD_OBJECT(
|
||||
r = sd_json_build(&w, SD_JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_FINITE_USEC("Timeout1USec", t1),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("Timeout2USec", t2),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("LeaseTimestampUSec", ts)));
|
||||
@ -978,8 +980,8 @@ static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "Lease", w);
|
||||
}
|
||||
|
||||
static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int dhcp6_client_pd_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -1004,9 +1006,9 @@ static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_append_arrayb(&array, JSON_BUILD_OBJECT(
|
||||
r = sd_json_variant_append_arrayb(&array, SD_JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_IN6_ADDR("Prefix", &prefix),
|
||||
JSON_BUILD_PAIR_UNSIGNED("PrefixLength", prefix_len),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", prefix_len),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("PreferredLifetimeUSec", lifetime_preferred_usec),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("ValidLifetimeUSec", lifetime_valid_usec)));
|
||||
if (r < 0)
|
||||
@ -1016,7 +1018,7 @@ static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "Prefixes", array);
|
||||
}
|
||||
|
||||
static int dhcp6_client_duid_append_json(Link *link, JsonVariant **v) {
|
||||
static int dhcp6_client_duid_append_json(Link *link, sd_json_variant **v) {
|
||||
const sd_dhcp_duid *duid;
|
||||
const void *data;
|
||||
size_t data_size;
|
||||
@ -1036,11 +1038,11 @@ static int dhcp6_client_duid_append_json(Link *link, JsonVariant **v) {
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BYTE_ARRAY("DUID", data, data_size)));
|
||||
return sd_json_variant_merge_objectb(v, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_BYTE_ARRAY("DUID", data, data_size)));
|
||||
}
|
||||
|
||||
static int dhcp6_client_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
static int dhcp6_client_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -1068,8 +1070,8 @@ static int dhcp6_client_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "DHCPv6Client", w);
|
||||
}
|
||||
|
||||
static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
static int dhcp_client_lease_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
usec_t lease_timestamp_usec = USEC_INFINITY, t1 = USEC_INFINITY, t2 = USEC_INFINITY;
|
||||
int r;
|
||||
|
||||
@ -1091,7 +1093,7 @@ static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) {
|
||||
if (r < 0 && r != -ENODATA)
|
||||
return r;
|
||||
|
||||
r = json_build(&w, JSON_BUILD_OBJECT(
|
||||
r = sd_json_build(&w, SD_JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_FINITE_USEC("LeaseTimestampUSec", lease_timestamp_usec),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("Timeout1USec", t1),
|
||||
JSON_BUILD_PAIR_FINITE_USEC("Timeout2USec", t2)));
|
||||
@ -1101,8 +1103,8 @@ static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "Lease", w);
|
||||
}
|
||||
|
||||
static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *addresses = NULL, *array = NULL;
|
||||
static int dhcp_client_pd_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *addresses = NULL, *array = NULL;
|
||||
uint8_t ipv4masklen, sixrd_prefixlen;
|
||||
struct in6_addr sixrd_prefix;
|
||||
const struct in_addr *br_addresses;
|
||||
@ -1121,15 +1123,15 @@ static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) {
|
||||
return r;
|
||||
|
||||
FOREACH_ARRAY(br_address, br_addresses, n_br_addresses) {
|
||||
r = json_variant_append_arrayb(&addresses, JSON_BUILD_IN4_ADDR(br_address));
|
||||
r = sd_json_variant_append_arrayb(&addresses, JSON_BUILD_IN4_ADDR(br_address));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = json_build(&array, JSON_BUILD_OBJECT(
|
||||
r = sd_json_build(&array, SD_JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_IN6_ADDR("Prefix", &sixrd_prefix),
|
||||
JSON_BUILD_PAIR_UNSIGNED("PrefixLength", sixrd_prefixlen),
|
||||
JSON_BUILD_PAIR_UNSIGNED("IPv4MaskLength", ipv4masklen),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", sixrd_prefixlen),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("IPv4MaskLength", ipv4masklen),
|
||||
JSON_BUILD_PAIR_VARIANT_NON_NULL("BorderRouters", addresses)));
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -1137,8 +1139,8 @@ static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "6rdPrefix", array);
|
||||
}
|
||||
|
||||
static int dhcp_client_private_options_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int dhcp_client_private_options_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -1149,18 +1151,18 @@ static int dhcp_client_private_options_append_json(Link *link, JsonVariant **v)
|
||||
|
||||
LIST_FOREACH(options, option, link->dhcp_lease->private_options) {
|
||||
|
||||
r = json_variant_append_arrayb(
|
||||
r = sd_json_variant_append_arrayb(
|
||||
&array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_UNSIGNED("Option", option->tag),
|
||||
JSON_BUILD_PAIR_HEX("PrivateOptionData", option->data, option->length)));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Option", option->tag),
|
||||
SD_JSON_BUILD_PAIR_HEX("PrivateOptionData", option->data, option->length)));
|
||||
if (r < 0)
|
||||
return 0;
|
||||
}
|
||||
return json_variant_set_field_non_null(v, "PrivateOptions", array);
|
||||
}
|
||||
|
||||
static int dhcp_client_id_append_json(Link *link, JsonVariant **v) {
|
||||
static int dhcp_client_id_append_json(Link *link, sd_json_variant **v) {
|
||||
const sd_dhcp_client_id *client_id;
|
||||
const void *data;
|
||||
size_t l;
|
||||
@ -1180,11 +1182,11 @@ static int dhcp_client_id_append_json(Link *link, JsonVariant **v) {
|
||||
if (r < 0)
|
||||
return 0;
|
||||
|
||||
return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BYTE_ARRAY("ClientIdentifier", data, l)));
|
||||
return sd_json_variant_merge_objectb(v, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_BYTE_ARRAY("ClientIdentifier", data, l)));
|
||||
}
|
||||
|
||||
static int dhcp_client_append_json(Link *link, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
|
||||
static int dhcp_client_append_json(Link *link, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -1212,8 +1214,8 @@ static int dhcp_client_append_json(Link *link, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "DHCPv4Client", w);
|
||||
}
|
||||
|
||||
int link_build_json(Link *link, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
int link_build_json(Link *link, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *type = NULL, *flags = NULL;
|
||||
int r;
|
||||
|
||||
@ -1228,42 +1230,42 @@ int link_build_json(Link *link, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_build(&v, JSON_BUILD_OBJECT(
|
||||
r = sd_json_build(&v, SD_JSON_BUILD_OBJECT(
|
||||
/* basic information */
|
||||
JSON_BUILD_PAIR_INTEGER("Index", link->ifindex),
|
||||
JSON_BUILD_PAIR_STRING("Name", link->ifname),
|
||||
SD_JSON_BUILD_PAIR_INTEGER("Index", link->ifindex),
|
||||
SD_JSON_BUILD_PAIR_STRING("Name", link->ifname),
|
||||
JSON_BUILD_PAIR_STRV_NON_EMPTY("AlternativeNames", link->alternative_names),
|
||||
JSON_BUILD_PAIR_CONDITION(link->master_ifindex > 0,
|
||||
"MasterInterfaceIndex", JSON_BUILD_INTEGER(link->master_ifindex)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(link->master_ifindex > 0,
|
||||
"MasterInterfaceIndex", SD_JSON_BUILD_INTEGER(link->master_ifindex)),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("Kind", link->kind),
|
||||
JSON_BUILD_PAIR_STRING("Type", type),
|
||||
SD_JSON_BUILD_PAIR_STRING("Type", type),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("Driver", link->driver),
|
||||
JSON_BUILD_PAIR_UNSIGNED("Flags", link->flags),
|
||||
JSON_BUILD_PAIR_STRING("FlagsString", flags),
|
||||
JSON_BUILD_PAIR_UNSIGNED("KernelOperationalState", link->kernel_operstate),
|
||||
JSON_BUILD_PAIR_STRING("KernelOperationalStateString", kernel_operstate_to_string(link->kernel_operstate)),
|
||||
JSON_BUILD_PAIR_UNSIGNED("MTU", link->mtu),
|
||||
JSON_BUILD_PAIR_UNSIGNED("MinimumMTU", link->min_mtu),
|
||||
JSON_BUILD_PAIR_UNSIGNED("MaximumMTU", link->max_mtu),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("Flags", link->flags),
|
||||
SD_JSON_BUILD_PAIR_STRING("FlagsString", flags),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("KernelOperationalState", link->kernel_operstate),
|
||||
SD_JSON_BUILD_PAIR_STRING("KernelOperationalStateString", kernel_operstate_to_string(link->kernel_operstate)),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("MTU", link->mtu),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("MinimumMTU", link->min_mtu),
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("MaximumMTU", link->max_mtu),
|
||||
JSON_BUILD_PAIR_HW_ADDR_NON_NULL("HardwareAddress", &link->hw_addr),
|
||||
JSON_BUILD_PAIR_HW_ADDR_NON_NULL("PermanentHardwareAddress", &link->permanent_hw_addr),
|
||||
JSON_BUILD_PAIR_HW_ADDR_NON_NULL("BroadcastAddress", &link->bcast_addr),
|
||||
JSON_BUILD_PAIR_IN6_ADDR_NON_NULL("IPv6LinkLocalAddress", &link->ipv6ll_address),
|
||||
/* wlan information */
|
||||
JSON_BUILD_PAIR_CONDITION(link->wlan_iftype > 0, "WirelessLanInterfaceType",
|
||||
JSON_BUILD_UNSIGNED(link->wlan_iftype)),
|
||||
JSON_BUILD_PAIR_CONDITION(link->wlan_iftype > 0, "WirelessLanInterfaceTypeString",
|
||||
JSON_BUILD_STRING(nl80211_iftype_to_string(link->wlan_iftype))),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(link->wlan_iftype > 0, "WirelessLanInterfaceType",
|
||||
SD_JSON_BUILD_UNSIGNED(link->wlan_iftype)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(link->wlan_iftype > 0, "WirelessLanInterfaceTypeString",
|
||||
SD_JSON_BUILD_STRING(nl80211_iftype_to_string(link->wlan_iftype))),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("SSID", link->ssid),
|
||||
JSON_BUILD_PAIR_ETHER_ADDR_NON_NULL("BSSID", &link->bssid),
|
||||
/* link state */
|
||||
JSON_BUILD_PAIR_STRING("AdministrativeState", link_state_to_string(link->state)),
|
||||
JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(link->operstate)),
|
||||
JSON_BUILD_PAIR_STRING("CarrierState", link_carrier_state_to_string(link->carrier_state)),
|
||||
JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(link->address_state)),
|
||||
JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(link->ipv4_address_state)),
|
||||
JSON_BUILD_PAIR_STRING("IPv6AddressState", link_address_state_to_string(link->ipv6_address_state)),
|
||||
JSON_BUILD_PAIR_STRING("OnlineState", link_online_state_to_string(link->online_state))));
|
||||
SD_JSON_BUILD_PAIR_STRING("AdministrativeState", link_state_to_string(link->state)),
|
||||
SD_JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(link->operstate)),
|
||||
SD_JSON_BUILD_PAIR_STRING("CarrierState", link_carrier_state_to_string(link->carrier_state)),
|
||||
SD_JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(link->address_state)),
|
||||
SD_JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(link->ipv4_address_state)),
|
||||
SD_JSON_BUILD_PAIR_STRING("IPv6AddressState", link_address_state_to_string(link->ipv6_address_state)),
|
||||
SD_JSON_BUILD_PAIR_STRING("OnlineState", link_online_state_to_string(link->online_state))));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -1343,8 +1345,8 @@ int link_build_json(Link *link, JsonVariant **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int links_append_json(Manager *manager, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int links_append_json(Manager *manager, sd_json_variant **v) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
_cleanup_free_ Link **links = NULL;
|
||||
size_t n_links = 0;
|
||||
int r;
|
||||
@ -1357,13 +1359,13 @@ static int links_append_json(Manager *manager, JsonVariant **v) {
|
||||
return r;
|
||||
|
||||
FOREACH_ARRAY(link, links, n_links) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *e = NULL;
|
||||
|
||||
r = link_build_json(*link, &e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = json_variant_append_array(&array, e);
|
||||
r = sd_json_variant_append_array(&array, e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -1371,8 +1373,8 @@ static int links_append_json(Manager *manager, JsonVariant **v) {
|
||||
return json_variant_set_field_non_null(v, "Interfaces", array);
|
||||
}
|
||||
|
||||
int manager_build_json(Manager *manager, JsonVariant **ret) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
int manager_build_json(Manager *manager, sd_json_variant **ret) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
int r;
|
||||
|
||||
assert(manager);
|
||||
|
@ -1,10 +1,10 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "json.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
typedef struct Link Link;
|
||||
typedef struct Manager Manager;
|
||||
|
||||
int link_build_json(Link *link, JsonVariant **ret);
|
||||
int manager_build_json(Manager *manager, JsonVariant **ret);
|
||||
int link_build_json(Link *link, sd_json_variant **ret);
|
||||
int manager_build_json(Manager *manager, sd_json_variant **ret);
|
||||
|
@ -680,7 +680,7 @@ int bus_link_method_reconfigure(sd_bus_message *message, void *userdata, sd_bus_
|
||||
|
||||
int bus_link_method_describe(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *text = NULL;
|
||||
Link *link = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
@ -691,7 +691,7 @@ int bus_link_method_describe(sd_bus_message *message, void *userdata, sd_bus_err
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to build JSON data: %m");
|
||||
|
||||
r = json_variant_format(v, 0, &text);
|
||||
r = sd_json_variant_format(v, 0, &text);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to format JSON data: %m");
|
||||
|
||||
|
@ -231,7 +231,7 @@ static int bus_method_describe_link(sd_bus_message *message, void *userdata, sd_
|
||||
|
||||
static int bus_method_describe(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
_cleanup_free_ char *text = NULL;
|
||||
Manager *manager = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
@ -242,7 +242,7 @@ static int bus_method_describe(sd_bus_message *message, void *userdata, sd_bus_e
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build JSON data: %m");
|
||||
|
||||
r = json_variant_format(v, 0, &text);
|
||||
r = sd_json_variant_format(v, 0, &text);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format JSON data: %m");
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "bus-polkit.h"
|
||||
#include "fd-util.h"
|
||||
#include "json-util.h"
|
||||
#include "lldp-rx-internal.h"
|
||||
#include "networkd-dhcp-server.h"
|
||||
#include "networkd-manager-varlink.h"
|
||||
@ -11,32 +12,32 @@
|
||||
#include "varlink.h"
|
||||
#include "varlink-io.systemd.Network.h"
|
||||
|
||||
static int vl_method_get_states(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_get_states(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
|
||||
assert(link);
|
||||
|
||||
if (json_variant_elements(parameters) > 0)
|
||||
if (sd_json_variant_elements(parameters) > 0)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
|
||||
return varlink_replyb(link,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(m->address_state)),
|
||||
JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(m->ipv4_address_state)),
|
||||
JSON_BUILD_PAIR_STRING("IPv6AddressState", link_address_state_to_string(m->ipv6_address_state)),
|
||||
JSON_BUILD_PAIR_STRING("CarrierState", link_carrier_state_to_string(m->carrier_state)),
|
||||
JSON_BUILD_PAIR_CONDITION(m->online_state >= 0, "OnlineState", JSON_BUILD_STRING(link_online_state_to_string(m->online_state))),
|
||||
JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(m->operational_state))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(m->address_state)),
|
||||
SD_JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(m->ipv4_address_state)),
|
||||
SD_JSON_BUILD_PAIR_STRING("IPv6AddressState", link_address_state_to_string(m->ipv6_address_state)),
|
||||
SD_JSON_BUILD_PAIR_STRING("CarrierState", link_carrier_state_to_string(m->carrier_state)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(m->online_state >= 0, "OnlineState", SD_JSON_BUILD_STRING(link_online_state_to_string(m->online_state))),
|
||||
SD_JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(m->operational_state))));
|
||||
}
|
||||
|
||||
static int vl_method_get_namespace_id(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static int vl_method_get_namespace_id(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
uint64_t inode = 0;
|
||||
uint32_t nsid = UINT32_MAX;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
|
||||
if (json_variant_elements(parameters) > 0)
|
||||
if (sd_json_variant_elements(parameters) > 0)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
|
||||
/* Network namespaces have two identifiers: the inode number (which all namespace types have), and
|
||||
@ -55,10 +56,10 @@ static int vl_method_get_namespace_id(Varlink *link, JsonVariant *parameters, Va
|
||||
log_full_errno(r == -ENODATA ? LOG_DEBUG : LOG_WARNING, r, "Failed to query network nsid, ignoring: %m");
|
||||
|
||||
return varlink_replyb(link,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_UNSIGNED("NamespaceId", inode),
|
||||
JSON_BUILD_PAIR_CONDITION(nsid == UINT32_MAX, "NamespaceNSID", JSON_BUILD_NULL),
|
||||
JSON_BUILD_PAIR_CONDITION(nsid != UINT32_MAX, "NamespaceNSID", JSON_BUILD_UNSIGNED(nsid))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_UNSIGNED("NamespaceId", inode),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(nsid == UINT32_MAX, "NamespaceNSID", SD_JSON_BUILD_NULL),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(nsid != UINT32_MAX, "NamespaceNSID", SD_JSON_BUILD_UNSIGNED(nsid))));
|
||||
}
|
||||
|
||||
typedef struct InterfaceInfo {
|
||||
@ -66,10 +67,10 @@ typedef struct InterfaceInfo {
|
||||
const char *ifname;
|
||||
} InterfaceInfo;
|
||||
|
||||
static int dispatch_interface(Varlink *vlink, JsonVariant *parameters, Manager *manager, Link **ret) {
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "InterfaceIndex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(InterfaceInfo, ifindex), 0 },
|
||||
{ "InterfaceName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(InterfaceInfo, ifname), 0 },
|
||||
static int dispatch_interface(Varlink *vlink, sd_json_variant *parameters, Manager *manager, Link **ret) {
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "InterfaceIndex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(InterfaceInfo, ifindex), 0 },
|
||||
{ "InterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(InterfaceInfo, ifname), 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -106,21 +107,21 @@ static int dispatch_interface(Varlink *vlink, JsonVariant *parameters, Manager *
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int link_append_lldp_neighbors(Link *link, JsonVariant *v, JsonVariant **array) {
|
||||
static int link_append_lldp_neighbors(Link *link, sd_json_variant *v, sd_json_variant **array) {
|
||||
assert(link);
|
||||
assert(array);
|
||||
|
||||
return json_variant_append_arrayb(array,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_INTEGER("InterfaceIndex", link->ifindex),
|
||||
JSON_BUILD_PAIR_STRING("InterfaceName", link->ifname),
|
||||
return sd_json_variant_append_arrayb(array,
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_INTEGER("InterfaceIndex", link->ifindex),
|
||||
SD_JSON_BUILD_PAIR_STRING("InterfaceName", link->ifname),
|
||||
JSON_BUILD_PAIR_STRV_NON_EMPTY("InterfaceAlternativeNames", link->alternative_names),
|
||||
JSON_BUILD_PAIR_CONDITION(json_variant_is_blank_array(v), "Neighbors", JSON_BUILD_EMPTY_ARRAY),
|
||||
JSON_BUILD_PAIR_CONDITION(!json_variant_is_blank_array(v), "Neighbors", JSON_BUILD_VARIANT(v))));
|
||||
SD_JSON_BUILD_PAIR_CONDITION(sd_json_variant_is_blank_array(v), "Neighbors", SD_JSON_BUILD_EMPTY_ARRAY),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_array(v), "Neighbors", SD_JSON_BUILD_VARIANT(v))));
|
||||
}
|
||||
|
||||
static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters, VarlinkMethodFlags flags, Manager *manager) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
static int vl_method_get_lldp_neighbors(Varlink *vlink, sd_json_variant *parameters, VarlinkMethodFlags flags, Manager *manager) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
|
||||
Link *link = NULL;
|
||||
int r;
|
||||
|
||||
@ -132,7 +133,7 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters,
|
||||
return r;
|
||||
|
||||
if (link) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
if (link->lldp_rx) {
|
||||
r = lldp_rx_build_neighbors_json(link->lldp_rx, &v);
|
||||
@ -145,7 +146,7 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters,
|
||||
return r;
|
||||
} else
|
||||
HASHMAP_FOREACH(link, manager->links_by_index) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
if (!link->lldp_rx)
|
||||
continue;
|
||||
@ -154,7 +155,7 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (json_variant_is_blank_array(v))
|
||||
if (sd_json_variant_is_blank_array(v))
|
||||
continue;
|
||||
|
||||
r = link_append_lldp_neighbors(link, v, &array);
|
||||
@ -163,14 +164,14 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters,
|
||||
}
|
||||
|
||||
return varlink_replyb(vlink,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_CONDITION(json_variant_is_blank_array(array), "Neighbors", JSON_BUILD_EMPTY_ARRAY),
|
||||
JSON_BUILD_PAIR_CONDITION(!json_variant_is_blank_array(array), "Neighbors", JSON_BUILD_VARIANT(array))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR_CONDITION(sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_EMPTY_ARRAY),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_VARIANT(array))));
|
||||
}
|
||||
|
||||
static int vl_method_set_persistent_storage(Varlink *vlink, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{ "Ready", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, 0, 0 },
|
||||
static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static const sd_json_dispatch_field dispatch_table[] = {
|
||||
{ "Ready", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, 0, 0 },
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -4,8 +4,9 @@
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "format-util.h"
|
||||
#include "nspawn-bind-user.h"
|
||||
#include "json-util.h"
|
||||
#include "nspawn.h"
|
||||
#include "nspawn-bind-user.h"
|
||||
#include "path-util.h"
|
||||
#include "user-util.h"
|
||||
#include "userdb.h"
|
||||
@ -87,7 +88,7 @@ static int convert_user(
|
||||
_cleanup_(group_record_unrefp) GroupRecord *converted_group = NULL;
|
||||
_cleanup_(user_record_unrefp) UserRecord *converted_user = NULL;
|
||||
_cleanup_free_ char *h = NULL;
|
||||
JsonVariant *p, *hp = NULL;
|
||||
sd_json_variant *p, *hp = NULL;
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
@ -113,31 +114,31 @@ static int convert_user(
|
||||
return log_oom();
|
||||
|
||||
/* Acquire the source hashed password array as-is, so that it retains the JSON_VARIANT_SENSITIVE flag */
|
||||
p = json_variant_by_key(u->json, "privileged");
|
||||
p = sd_json_variant_by_key(u->json, "privileged");
|
||||
if (p)
|
||||
hp = json_variant_by_key(p, "hashedPassword");
|
||||
hp = sd_json_variant_by_key(p, "hashedPassword");
|
||||
|
||||
r = user_record_build(
|
||||
&converted_user,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("userName", JSON_BUILD_STRING(u->user_name)),
|
||||
JSON_BUILD_PAIR("uid", JSON_BUILD_UNSIGNED(allocate_uid)),
|
||||
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(allocate_uid)),
|
||||
JSON_BUILD_PAIR_CONDITION(u->disposition >= 0, "disposition", JSON_BUILD_STRING(user_disposition_to_string(u->disposition))),
|
||||
JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_STRING(h)),
|
||||
JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.NSpawn")),
|
||||
JSON_BUILD_PAIR_CONDITION(!strv_isempty(u->hashed_password), "privileged", JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("hashedPassword", JSON_BUILD_VARIANT(hp))))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("userName", SD_JSON_BUILD_STRING(u->user_name)),
|
||||
SD_JSON_BUILD_PAIR("uid", SD_JSON_BUILD_UNSIGNED(allocate_uid)),
|
||||
SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(allocate_uid)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(u->disposition >= 0, "disposition", SD_JSON_BUILD_STRING(user_disposition_to_string(u->disposition))),
|
||||
SD_JSON_BUILD_PAIR("homeDirectory", SD_JSON_BUILD_STRING(h)),
|
||||
SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.NSpawn")),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(!strv_isempty(u->hashed_password), "privileged", SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("hashedPassword", SD_JSON_BUILD_VARIANT(hp))))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build container user record: %m");
|
||||
|
||||
r = group_record_build(
|
||||
&converted_group,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(g->group_name)),
|
||||
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(allocate_uid)),
|
||||
JSON_BUILD_PAIR_CONDITION(g->disposition >= 0, "disposition", JSON_BUILD_STRING(user_disposition_to_string(g->disposition))),
|
||||
JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.NSpawn"))));
|
||||
SD_JSON_BUILD_OBJECT(
|
||||
SD_JSON_BUILD_PAIR("groupName", SD_JSON_BUILD_STRING(g->group_name)),
|
||||
SD_JSON_BUILD_PAIR("gid", SD_JSON_BUILD_UNSIGNED(allocate_uid)),
|
||||
SD_JSON_BUILD_PAIR_CONDITION(g->disposition >= 0, "disposition", SD_JSON_BUILD_STRING(user_disposition_to_string(g->disposition))),
|
||||
SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.NSpawn"))));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build container group record: %m");
|
||||
|
||||
@ -314,7 +315,7 @@ int bind_user_prepare(
|
||||
|
||||
static int write_and_symlink(
|
||||
const char *root,
|
||||
JsonVariant *v,
|
||||
sd_json_variant *v,
|
||||
const char *name,
|
||||
uid_t uid,
|
||||
const char *suffix,
|
||||
@ -329,7 +330,7 @@ static int write_and_symlink(
|
||||
assert(uid_is_valid(uid));
|
||||
assert(suffix);
|
||||
|
||||
r = json_variant_format(v, JSON_FORMAT_NEWLINE, &j);
|
||||
r = sd_json_variant_format(v, SD_JSON_FORMAT_NEWLINE, &j);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format user record JSON: %m");
|
||||
|
||||
@ -410,7 +411,7 @@ int bind_user_setup(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to extract privileged information from group record: %m");
|
||||
|
||||
if (!json_variant_is_blank_object(shadow_group->json)) {
|
||||
if (!sd_json_variant_is_blank_object(shadow_group->json)) {
|
||||
r = write_and_symlink(
|
||||
root,
|
||||
shadow_group->json,
|
||||
@ -442,7 +443,7 @@ int bind_user_setup(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to extract privileged information from user record: %m");
|
||||
|
||||
if (!json_variant_is_blank_object(shadow_user->json)) {
|
||||
if (!sd_json_variant_is_blank_object(shadow_user->json)) {
|
||||
r = write_and_symlink(
|
||||
root,
|
||||
shadow_user->json,
|
||||
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user