diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-05-02 14:26:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-06-12 18:42:22 +0200 |
commit | 309a747fa6cfeac0a0165543f23a924866727c9b (patch) | |
tree | a51242aa3ac87243c0614bf93d27e9083182e485 /src/creds | |
parent | json: merge json_dispatch_path() + json_dispatch_absolute_path() (diff) | |
download | systemd-309a747fa6cfeac0a0165543f23a924866727c9b.tar.xz systemd-309a747fa6cfeac0a0165543f23a924866727c9b.zip |
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.
Diffstat (limited to 'src/creds')
-rw-r--r-- | src/creds/creds.c | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/src/creds/creds.c b/src/creds/creds.c index 0a26429e31..0cff4d8890 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -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); } |