summaryrefslogtreecommitdiffstats
path: root/src/shared/json.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: use UINT64_MAX or friendsYu Watanabe2021-03-041-12/+12
|
* json: rename json_dispatch_{integer,unsigned} -> json_dispatch_{intmax,uintmax}Anita Zhang2021-02-261-2/+2
| | | | | | Prompted by https://bugzilla.redhat.com/show_bug.cgi?id=1930875 in which I had previously used json_dispatch_unsigned and passed a return variable of type unsigned when json_dispatch_unsigned writes a uintmax_t.
* Move and rename parse_json_argument() functionZbigniew Jędrzejewski-Szmek2021-02-151-21/+0
| | | | | json.[ch] is a very generic implementation, and cmdline argument parsing doesn't fit there.
* shared/json: make JsonVariant.type field widerZbigniew Jędrzejewski-Szmek2021-02-101-4/+4
| | | | | pahole shows that this doesn't make a difference, but we can fit -EINVAL into .type without warnings.
* log: drop unused LogRealmYu Watanabe2021-01-251-3/+3
| | | | | Already no binary is built with LOG_REALM= argument. Hence, we can safely drop LogRealm now.
* json: add generic cmdline parser for --json= switchLennart Poettering2021-01-091-0/+21
|
* json: add new json format flag for disabling JSON outputLennart Poettering2021-01-091-0/+3
| | | | | | | | | | | | | | This adds a new flag JSON_FORMAT_OFF that is a marker for "no JSON output please!". Of course, this flag sounds pointless in a JSON implementation, however this is useful in code that can generate JSON output, but also more human friendly output (for example our table formatters). With this in place various tools that so far maintained one boolean field "arg_json" that controlled whether JSON output was requested at all and another field "arg_json_format_flags" for selecing the precise json output flags may merge them into one, simplifying code a bit.
* json: add APIs for quickly inserting hex blobs into as JSON stringsLennart Poettering2020-12-171-0/+51
| | | | | | This is similar to the base64 support, but fixed-size hash values are typically preferably presented as series of hex values, hence store them here like that too.
* Merge pull request #17702 from rnhmjoj/masterLennart Poettering2020-12-161-4/+4
|\ | | | | Extend $SYSTEMD_COLORS to switch colors mode
| * tree-wide: avoid direct use of color macrosrnhmjoj2020-12-151-4/+4
| |
* | json: log location also when there is no fileZbigniew Jędrzejewski-Szmek2020-12-101-0/+10
|/ | | | | | | | | E.g. in nss-resolve it is still useful to print the location of the error: src/test/test-nss.c:231: dlsym(0x0x1dc6fb0, _nss_resolve_gethostbyname2_r) → 0x0x7fdbfc53f626 (string):1:40: JSON field ifindex is out of bounds for an interface index. I opted to use a partially duplicated if condition to avoid nesting. It's nice to have the log calls vertically aligned. The compiler will optimize this nicely.
* fileio: teach read_full_file_full() to read from offset/with maximum sizeLennart Poettering2020-12-011-1/+1
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* fileio: beef up READ_FULL_FILE_CONNECT_SOCKET to allow setting sender socket ↵Lennart Poettering2020-11-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | name This beefs up the READ_FULL_FILE_CONNECT_SOCKET logic of read_full_file_full() a bit: when used a sender socket name may be specified. If specified as NULL behaviour is as before: the client socket name is picked by the kernel. But if specified as non-NULL the client can pick a socket name to use when connecting. This is useful to communicate a minimal amount of metainformation from client to server, outside of the transport payload. Specifically, these beefs up the service credential logic to pass an abstract AF_UNIX socket name as client socket name when connecting via READ_FULL_FILE_CONNECT_SOCKET, that includes the requesting unit name and the eventual credential name. This allows servers implementing the trivial credential socket logic to distinguish clients: via a simple getpeername() it can be determined which unit is requesting a credential, and which credential specifically. Example: with this patch in place, in a unit file "waldo.service" a configuration line like the following: LoadCredential=foo:/run/quux/creds.sock will result in a connection to the AF_UNIX socket /run/quux/creds.sock, originating from an abstract namespace AF_UNIX socket: @$RANDOM/unit/waldo.service/foo (The $RANDOM is replaced by some randomized string. This is included in the socket name order to avoid namespace squatting issues: the abstract socket namespace is open to unprivileged users after all, and care needs to be taken not to use guessable names) The services listening on the /run/quux/creds.sock socket may thus easily retrieve the name of the unit the credential is requested for plus the credential name, via a simpler getpeername(), discarding the random preifx and the /unit/ string. This logic uses "/" as separator between the fields, since both unit names and credential names appear in the file system, and thus are designed to use "/" as outer separators. Given that it's a good safe choice to use as separators here, too avoid any conflicts. This is a minimal patch only: the new logic is used only for the unit file credential logic. For other places where we use READ_FULL_FILE_CONNECT_SOCKET it is probably a good idea to use this scheme too, but this should be done carefully in later patches, since the socket names become API that way, and we should determine the right amount of info to pass over.
* macro: introduce POINTER_MAX as define for (void*) -1Lennart Poettering2020-10-221-1/+1
| | | | | Just add a safer, prettier way to write (void*) -1, that doesn't rely on two's complement, but uses the correct underlying C constructs.
* shared/json: reject non-utf-8 stringsZbigniew Jędrzejewski-Szmek2020-09-011-1/+8
| | | | | | | | | | | | | JSON strings must be utf-8-clean. We also verify this in json_parse_string() so we would reject a message with invalid utf-8 anyway. It would probably be slightly cheaper to detect non-conformaning strings in serialization, but then we'd have to fail serialization. By doing this early, we give the caller a chance to handle the error nicely. The test is adjusted to contain a valid utf-8 string after decoding of the utf-32 encoding in json ("विवेकख्यातिरविप्लवा हानोपायः।", something about the cessation of ignorance).
* json: split out string formatting to a separate functionZbigniew Jędrzejewski-Szmek2020-09-011-54/+54
| | | | | | It's complicated enough to deserve it's own function. No functional change.
* json: add support for byte arrays to json builderLennart Poettering2020-08-261-0/+30
|
* json: add helpers for dealing with id128 + strvLennart Poettering2020-08-121-0/+45
|
* json: turn off ubsan for json_variant_has_type()Lennart Poettering2020-05-261-1/+4
| | | | Fixes: #15907
* macro: introduce DISABLE_WARNING_TYPE_LIMITS and make use of it everywhereLennart Poettering2020-05-251-3/+2
|
* json: use our regular way to turn off compiler warningsLennart Poettering2020-05-251-18/+14
|
* json: when making a copy of a json variant, propagate the sensitive bitLennart Poettering2020-04-291-1/+30
| | | | | Let's make sure we never lose the bit when copying a variant, after all the data contained is still going to be sensitive after the copy.
* tree-wide: spellcheck using codespellZbigniew Jędrzejewski-Szmek2020-04-161-1/+1
| | | | Fixes #15436.
* user-util: rework how we validate user namesLennart Poettering2020-04-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This reworks the user validation infrastructure. There are now two modes. In regular mode we are strict and test against a strict set of valid chars. And in "relaxed" mode we just filter out some really obvious, dangerous stuff. i.e. strict is whitelisting what is OK, but "relaxed" is blacklisting what is really not OK. The idea is that we use strict mode whenver we allocate a new user (i.e. in sysusers.d or homed), while "relaxed" mode is when we process users registered elsewhere, (i.e. userdb, logind, …) The requirements on user name validity vary wildly. SSSD thinks its fine to embedd "@" for example, while the suggested NAME_REGEX field on Debian does not even allow uppercase chars… This effectively liberaralizes a lot what we expect from usernames. The code that warns about questionnable user names is now optional and only used at places such as unit file parsing, so that it doesn't show up on every userdb query, but only when processing configuration files that know better. Fixes: #15149 #15090
* userdb: allow dots in usernameMike Gilbert2020-02-271-1/+1
| | | | | | | | | This prevents an error in pam_systemd when logging in. sshd[2623165]: pam_unix(sshd:session): session opened for user tony.stark(uid=10001) by (uid=0) sshd[2623165]: pam_systemd(sshd:session): Failed to get user record: Invalid argument Bug: https://bugs.gentoo.org/708824
* json: lower maximum allowed recursion to 2KLennart Poettering2020-01-211-3/+9
| | | | | | Apparently 4K is too high still, let's halve it. Fixes: #14396
* json: add new output flag JSON_PRETTY_AUTOLennart Poettering2019-12-021-0/+3
| | | | | This takes inspiration from JSON_COLOR_AUTO: it will automatically map to JSON_PRETTY if connected to a TTY and JSON_NEWLINE otherwise.
* json: add const string dispatcherLennart Poettering2019-12-021-0/+21
| | | | | | | | | This adds json_dispatch_const_string() which is similar to json_dispatch_string() but doesn't store a strdup()'ed copy of the string, but a pointer directly into the JSON record. This should simplify cases where the json variant sticks around long enough anyway.
* json: teach json_build() to build arrays from C arrays of JsonVariantLennart Poettering2019-12-021-0/+30
|
* json: add more dispatch helpersLennart Poettering2019-12-021-0/+76
|
* json: add json_variant_set_field_integer() and ↵Lennart Poettering2019-12-021-0/+22
| | | | json_variant_set_field_boolean() helpers
* json: add json_variant_unbase64() helperLennart Poettering2019-12-021-0/+8
|
* json: add new flag for forcing a flush after dumping json data to fileLennart Poettering2019-12-021-0/+3
| | | | | This is particularly useful when no trailing \n is generated, i.e. stdio doesn't flush the output on its own.
* json: permit 'null' as a way to reset tri-states to defaultLennart Poettering2019-12-021-0/+5
|
* json: allow putting together base64 fields with json_build()Lennart Poettering2019-12-021-0/+30
|
* json: add new helper json_variant_append_array()Lennart Poettering2019-12-021-0/+43
|
* json: add new helper json_variant_new_base64()Lennart Poettering2019-12-021-0/+14
|
* json: add concept of normalizationLennart Poettering2019-12-021-18/+219
| | | | | | | | | | | | | | | | | | | Let's add a concept of normalization: as preparation for signing json records let's add a mechanism to bring JSON records into a well-defined order so that we can safely validate JSON records. This adds two booleans to each JsonVariant object: "sorted" and "normalized". The latter indicates whether a variant is fully sorted (i.e. all keys of objects listed in alphabetical order) recursively down the tree. The former is a weaker property: it only checks whether the keys of the object itself are sorted. All variants which are "normalized" are also "sorted", but not vice versa. The knowledge of the "sorted" property is then used to optimize searching for keys in the variant by using bisection. Both properties are determined at the moment the variants are allocated. Since our objects are immutable this is safe.
* json: add json_variant_merge() helperLennart Poettering2019-12-021-0/+63
|
* json: add json_variant_set_field_string() and json_variant_set_field_unsigned()Lennart Poettering2019-12-021-0/+22
|
* json: add json_variant_strv() helper that converts a json variant to an strvLennart Poettering2019-12-021-0/+60
| | | | Only works for arrays of strings, of course.
* json: optionally, make string checks stricter when dispatching stringsLennart Poettering2019-12-021-0/+9
|
* json: add flags parameter to json_parse_file(), for parsing "sensitive" dataLennart Poettering2019-12-021-7/+14
| | | | | | | This will call json_variant_sensitive() internally while parsing for each allocated sub-variant. This is better than calling it a posteriori at the end, because partially parsed variants will always be properly erased from memory this way.
* json: add json_parse_file_at() helperLennart Poettering2019-12-021-2/+2
| | | | This is an "at" function, similar to json_parse_file().
* json: add a new "sensitive" flags for JsonVariant objectsLennart Poettering2019-12-021-3/+73
| | | | | | An object marked with this flag will be erased from memory when it is freed. This is useful for dealing with sensitive data (key material, passphrases) encoded in JSON objects.
* json: add new json_variant_set_field() helperLennart Poettering2019-12-021-0/+69
|
* json: add new API json_variant_filter() for dropping fields from objectsLennart Poettering2019-12-021-0/+53
|
* json: add new json_variant_is_blank_{object,array}() helpersLennart Poettering2019-12-021-0/+13
|
* json: beef up strv parser to also accept a single string instead of an array ↵Lennart Poettering2019-12-021-0/+10
| | | | | | | of strings Let's be permissive in what we accept and take a single string instead of an array of strings, when a string is requested, too.