| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <netinet/in.h> |
| 4 |
#include <sys/sysmacros.h> |
| 5 |
|
| 6 |
#include "alloc-util.h" |
| 7 |
#include "devnum-util.h" |
| 8 |
#include "env-util.h" |
| 9 |
#include "errno-util.h" |
| 10 |
#include "fd-util.h" |
| 11 |
#include "glyph-util.h" |
| 12 |
#include "in-addr-util.h" |
| 13 |
#include "iovec-util.h" |
| 14 |
#include "json-util.h" |
| 15 |
#include "log.h" |
| 16 |
#include "mountpoint-util.h" |
| 17 |
#include "parse-util.h" |
| 18 |
#include "path-util.h" |
| 19 |
#include "pidref.h" |
| 20 |
#include "process-util.h" |
| 21 |
#include "stat-util.h" |
| 22 |
#include "stdio-util.h" |
| 23 |
#include "string-util.h" |
| 24 |
#include "strv.h" |
| 25 |
#include "syslog-util.h" |
| 26 |
#include "unit-name.h" |
| 27 |
#include "user-util.h" |
| 28 |
|
| 29 |
int json_dispatch_unhex_iovec(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 30 |
_cleanup_free_ void *buffer = NULL; |
| 31 |
struct iovec *iov = ASSERT_PTR(userdata); |
| 32 |
size_t sz; |
| 33 |
int r; |
| 34 |
|
| 35 |
if (sd_json_variant_is_null(variant)) { |
| 36 |
iovec_done(iov); |
| 37 |
return 0; |
| 38 |
} |
| 39 |
|
| 40 |
if (!sd_json_variant_is_string(variant)) |
| 41 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); |
| 42 |
|
| 43 |
r = sd_json_variant_unhex(variant, &buffer, &sz); |
| 44 |
if (r < 0) |
| 45 |
return json_log(variant, flags, r, "JSON field '%s' is not valid hex data.", strna(name)); |
| 46 |
|
| 47 |
free_and_replace(iov->iov_base, buffer); |
| 48 |
iov->iov_len = sz; |
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
int json_dispatch_unbase64_iovec(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 53 |
_cleanup_free_ void *buffer = NULL; |
| 54 |
struct iovec *iov = ASSERT_PTR(userdata); |
| 55 |
size_t sz; |
| 56 |
int r; |
| 57 |
|
| 58 |
if (sd_json_variant_is_null(variant)) { |
| 59 |
iovec_done(iov); |
| 60 |
return 0; |
| 61 |
} |
| 62 |
|
| 63 |
if (!sd_json_variant_is_string(variant)) |
| 64 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); |
| 65 |
|
| 66 |
r = sd_json_variant_unbase64(variant, &buffer, &sz); |
| 67 |
if (r < 0) |
| 68 |
return json_log(variant, flags, r, "JSON field '%s' is not valid Base64 data.", strna(name)); |
| 69 |
|
| 70 |
free_and_replace(iov->iov_base, buffer); |
| 71 |
iov->iov_len = sz; |
| 72 |
return 0; |
| 73 |
} |
| 74 |
|
| 75 |
int json_dispatch_byte_array_iovec(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 76 |
_cleanup_free_ uint8_t *buffer = NULL; |
| 77 |
struct iovec *iov = ASSERT_PTR(userdata); |
| 78 |
size_t sz, k = 0; |
| 79 |
|
| 80 |
assert(variant); |
| 81 |
|
| 82 |
if (sd_json_variant_is_null(variant)) { |
| 83 |
iovec_done(iov); |
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
if (!sd_json_variant_is_array(variant)) |
| 88 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array.", strna(name)); |
| 89 |
|
| 90 |
sz = sd_json_variant_elements(variant); |
| 91 |
|
| 92 |
buffer = new(uint8_t, sz + 1); |
| 93 |
if (!buffer) |
| 94 |
return json_log(variant, flags, SYNTHETIC_ERRNO(ENOMEM), "Out of memory."); |
| 95 |
|
| 96 |
sd_json_variant *i; |
| 97 |
JSON_VARIANT_ARRAY_FOREACH(i, variant) { |
| 98 |
uint64_t b; |
| 99 |
|
| 100 |
if (!sd_json_variant_is_unsigned(i)) |
| 101 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Element %zu of JSON field '%s' is not an unsigned integer.", k, strna(name)); |
| 102 |
|
| 103 |
b = sd_json_variant_unsigned(i); |
| 104 |
if (b > 0xff) |
| 105 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), |
| 106 |
"Element %zu of JSON field '%s' is out of range 0%s255.", |
| 107 |
k, strna(name), glyph(GLYPH_ELLIPSIS)); |
| 108 |
|
| 109 |
buffer[k++] = (uint8_t) b; |
| 110 |
} |
| 111 |
assert(k == sz); |
| 112 |
|
| 113 |
/* Append a NUL byte for safety, like we do in memdup_suffix0() and others. */ |
| 114 |
buffer[sz] = 0; |
| 115 |
|
| 116 |
free_and_replace(iov->iov_base, buffer); |
| 117 |
iov->iov_len = sz; |
| 118 |
return 0; |
| 119 |
} |
| 120 |
|
| 121 |
int json_dispatch_user_group_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 122 |
char **s = ASSERT_PTR(userdata); |
| 123 |
const char *n; |
| 124 |
int r; |
| 125 |
|
| 126 |
r = json_dispatch_const_user_group_name(name, variant, flags, &n); |
| 127 |
if (r < 0) |
| 128 |
return r; |
| 129 |
|
| 130 |
r = free_and_strdup(s, n); |
| 131 |
if (r < 0) |
| 132 |
return json_log(variant, flags, r, "Failed to allocate string: %m"); |
| 133 |
|
| 134 |
return 0; |
| 135 |
} |
| 136 |
|
| 137 |
int json_dispatch_const_user_group_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 138 |
const char **s = ASSERT_PTR(userdata), *n; |
| 139 |
|
| 140 |
if (sd_json_variant_is_null(variant)) { |
| 141 |
*s = NULL; |
| 142 |
return 0; |
| 143 |
} |
| 144 |
|
| 145 |
if (!sd_json_variant_is_string(variant)) |
| 146 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); |
| 147 |
|
| 148 |
n = sd_json_variant_string(variant); |
| 149 |
if (!valid_user_group_name(n, FLAGS_SET(flags, SD_JSON_RELAX) ? VALID_USER_RELAX : 0)) |
| 150 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid user/group name.", strna(name)); |
| 151 |
|
| 152 |
*s = n; |
| 153 |
return 0; |
| 154 |
} |
| 155 |
|
| 156 |
int json_dispatch_const_unit_name(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 157 |
const char **s = ASSERT_PTR(userdata), *n; |
| 158 |
UnitNameFlags unitname_flags; |
| 159 |
|
| 160 |
if (sd_json_variant_is_null(variant)) { |
| 161 |
*s = NULL; |
| 162 |
return 0; |
| 163 |
} |
| 164 |
|
| 165 |
if (!sd_json_variant_is_string(variant)) |
| 166 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); |
| 167 |
|
| 168 |
if (FLAGS_SET(flags, SD_JSON_STRICT)) |
| 169 |
unitname_flags = UNIT_NAME_PLAIN; |
| 170 |
else if (FLAGS_SET(flags, SD_JSON_RELAX)) |
| 171 |
unitname_flags = UNIT_NAME_ANY; |
| 172 |
else |
| 173 |
unitname_flags = UNIT_NAME_PLAIN | UNIT_NAME_INSTANCE; |
| 174 |
|
| 175 |
n = sd_json_variant_string(variant); |
| 176 |
if (!unit_name_is_valid(n, unitname_flags)) |
| 177 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid unit name.", strna(name)); |
| 178 |
|
| 179 |
*s = n; |
| 180 |
return 0; |
| 181 |
} |
| 182 |
|
| 183 |
int json_dispatch_in_addr(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 184 |
struct in_addr *address = ASSERT_PTR(userdata); |
| 185 |
_cleanup_(iovec_done) struct iovec iov = {}; |
| 186 |
int r; |
| 187 |
|
| 188 |
if (sd_json_variant_is_null(variant)) { |
| 189 |
*address = (struct in_addr) {}; |
| 190 |
return 0; |
| 191 |
} |
| 192 |
|
| 193 |
/* We support a more human readable string based encoding, and an array based encoding */ |
| 194 |
if (sd_json_variant_is_string(variant)) { |
| 195 |
union in_addr_union a; |
| 196 |
r = in_addr_from_string(AF_INET, sd_json_variant_string(variant), &a); |
| 197 |
if (r < 0) |
| 198 |
return json_log(variant, flags, r, |
| 199 |
"JSON field '%s' is not a valid IPv4 address string: %s", strna(name), sd_json_variant_string(variant)); |
| 200 |
|
| 201 |
*address = a.in; |
| 202 |
return 0; |
| 203 |
} |
| 204 |
|
| 205 |
r = json_dispatch_byte_array_iovec(name, variant, flags, &iov); |
| 206 |
if (r < 0) |
| 207 |
return r; |
| 208 |
|
| 209 |
if (iov.iov_len != sizeof(struct in_addr)) |
| 210 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), |
| 211 |
"Expected JSON field '%s' to be an array of %zu bytes.", strna(name), sizeof(struct in_addr)); |
| 212 |
|
| 213 |
memcpy(address, iov.iov_base, iov.iov_len); |
| 214 |
return 0; |
| 215 |
} |
| 216 |
|
| 217 |
int json_dispatch_in6_addr(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 218 |
struct in6_addr *address = ASSERT_PTR(userdata); |
| 219 |
_cleanup_(iovec_done) struct iovec iov = {}; |
| 220 |
int r; |
| 221 |
|
| 222 |
if (sd_json_variant_is_null(variant)) { |
| 223 |
*address = (struct in6_addr) {}; |
| 224 |
return 0; |
| 225 |
} |
| 226 |
|
| 227 |
/* We support both a more human readable string based encoding and an array based encoding */ |
| 228 |
if (sd_json_variant_is_string(variant)) { |
| 229 |
union in_addr_union a; |
| 230 |
r = in_addr_from_string(AF_INET6, sd_json_variant_string(variant), &a); |
| 231 |
if (r < 0) |
| 232 |
return json_log(variant, flags, r, |
| 233 |
"JSON field '%s' is not a valid IPv6 address string: %s", strna(name), sd_json_variant_string(variant)); |
| 234 |
|
| 235 |
*address = a.in6; |
| 236 |
return 0; |
| 237 |
} |
| 238 |
|
| 239 |
r = json_dispatch_byte_array_iovec(name, variant, flags, &iov); |
| 240 |
if (r < 0) |
| 241 |
return r; |
| 242 |
|
| 243 |
if (iov.iov_len != sizeof(struct in6_addr)) |
| 244 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), |
| 245 |
"Expected JSON field '%s' to be an array of %zu bytes.", strna(name), sizeof(struct in6_addr)); |
| 246 |
|
| 247 |
memcpy(address, iov.iov_base, iov.iov_len); |
| 248 |
return 0; |
| 249 |
} |
| 250 |
|
| 251 |
int json_dispatch_const_path(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 252 |
const char **p = ASSERT_PTR(userdata), *path; |
| 253 |
|
| 254 |
assert(variant); |
| 255 |
|
| 256 |
if (sd_json_variant_is_null(variant)) { |
| 257 |
*p = NULL; |
| 258 |
return 0; |
| 259 |
} |
| 260 |
|
| 261 |
if (!sd_json_variant_is_string(variant)) |
| 262 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); |
| 263 |
|
| 264 |
path = sd_json_variant_string(variant); |
| 265 |
if (!((flags & SD_JSON_STRICT) ? path_is_normalized(path) : path_is_valid(path))) |
| 266 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a normalized file system path.", strna(name)); |
| 267 |
if (!path_is_absolute(path)) |
| 268 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an absolute file system path.", strna(name)); |
| 269 |
|
| 270 |
*p = path; |
| 271 |
return 0; |
| 272 |
} |
| 273 |
|
| 274 |
int json_dispatch_path(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 275 |
char **p = ASSERT_PTR(userdata); |
| 276 |
const char *path; |
| 277 |
int r; |
| 278 |
|
| 279 |
assert(variant); |
| 280 |
|
| 281 |
r = json_dispatch_const_path(name, variant, flags, &path); |
| 282 |
if (r < 0) |
| 283 |
return r; |
| 284 |
|
| 285 |
if (free_and_strdup(p, path) < 0) |
| 286 |
return json_log_oom(variant, flags); |
| 287 |
|
| 288 |
return 0; |
| 289 |
} |
| 290 |
|
| 291 |
int json_dispatch_strv_path(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 292 |
_cleanup_strv_free_ char **n = NULL; |
| 293 |
char ***l = ASSERT_PTR(userdata); |
| 294 |
size_t s = 0; |
| 295 |
int r; |
| 296 |
|
| 297 |
assert(variant); |
| 298 |
|
| 299 |
if (sd_json_variant_is_null(variant)) { |
| 300 |
*l = strv_free(*l); |
| 301 |
return 0; |
| 302 |
} |
| 303 |
|
| 304 |
if (!sd_json_variant_is_array(variant)) |
| 305 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array.", strna(name)); |
| 306 |
|
| 307 |
sd_json_variant *i; |
| 308 |
JSON_VARIANT_ARRAY_FOREACH(i, variant) { |
| 309 |
const char *a; |
| 310 |
r = json_dispatch_const_path(name, i, flags, &a); |
| 311 |
if (r < 0) |
| 312 |
return r; |
| 313 |
|
| 314 |
r = strv_extend_with_size(&n, &s, a); |
| 315 |
if (r < 0) |
| 316 |
return json_log_oom(variant, flags); |
| 317 |
} |
| 318 |
|
| 319 |
return strv_free_and_replace(*l, n); |
| 320 |
} |
| 321 |
|
| 322 |
int json_dispatch_const_filename(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 323 |
const char **n = ASSERT_PTR(userdata); |
| 324 |
|
| 325 |
if (sd_json_variant_is_null(variant)) { |
| 326 |
*n = NULL; |
| 327 |
return 0; |
| 328 |
} |
| 329 |
|
| 330 |
if (!sd_json_variant_is_string(variant)) |
| 331 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); |
| 332 |
|
| 333 |
const char *filename = sd_json_variant_string(variant); |
| 334 |
if (!filename_is_valid(filename)) |
| 335 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid file name.", strna(name)); |
| 336 |
|
| 337 |
*n = filename; |
| 338 |
return 0; |
| 339 |
} |
| 340 |
|
| 341 |
int json_dispatch_filename(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 342 |
char **n = ASSERT_PTR(userdata); |
| 343 |
const char *filename; |
| 344 |
int r; |
| 345 |
|
| 346 |
assert(variant); |
| 347 |
|
| 348 |
r = json_dispatch_const_filename(name, variant, flags, &filename); |
| 349 |
if (r < 0) |
| 350 |
return r; |
| 351 |
|
| 352 |
if (free_and_strdup(n, filename) < 0) |
| 353 |
return json_log_oom(variant, flags); |
| 354 |
|
| 355 |
return 0; |
| 356 |
} |
| 357 |
|
| 358 |
int json_dispatch_const_version(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 359 |
const char **n = ASSERT_PTR(userdata); |
| 360 |
|
| 361 |
assert(variant); |
| 362 |
|
| 363 |
if (sd_json_variant_is_null(variant)) { |
| 364 |
*n = NULL; |
| 365 |
return 0; |
| 366 |
} |
| 367 |
|
| 368 |
if (!sd_json_variant_is_string(variant)) |
| 369 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name)); |
| 370 |
|
| 371 |
const char *version = sd_json_variant_string(variant); |
| 372 |
if (!version_is_valid(version)) |
| 373 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid version string.", strna(name)); |
| 374 |
|
| 375 |
*n = version; |
| 376 |
return 0; |
| 377 |
} |
| 378 |
|
| 379 |
int json_dispatch_version(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 380 |
char **n = ASSERT_PTR(userdata); |
| 381 |
const char *version; |
| 382 |
int r; |
| 383 |
|
| 384 |
assert(variant); |
| 385 |
|
| 386 |
r = json_dispatch_const_version(name, variant, flags, &version); |
| 387 |
if (r < 0) |
| 388 |
return r; |
| 389 |
|
| 390 |
if (free_and_strdup(n, version) < 0) |
| 391 |
return json_log_oom(variant, flags); |
| 392 |
|
| 393 |
return 0; |
| 394 |
} |
| 395 |
|
| 396 |
int json_variant_new_pidref(sd_json_variant **ret, PidRef *pidref) { |
| 397 |
sd_id128_t boot_id = SD_ID128_NULL; |
| 398 |
int r; |
| 399 |
|
| 400 |
/* Turns a PidRef into a triplet of PID, pidfd inode nr, and the boot ID. The triplet should uniquely |
| 401 |
* identify the process globally, and be good enough to turn back into a pidfd + PidRef */ |
| 402 |
|
| 403 |
if (!pidref_is_set(pidref)) |
| 404 |
return sd_json_variant_new_null(ret); |
| 405 |
|
| 406 |
if (!pidref_is_remote(pidref)) { |
| 407 |
r = pidref_acquire_pidfd_id(pidref); |
| 408 |
if (r < 0 && !ERRNO_IS_NEG_NOT_SUPPORTED(r) && r != -ENOMEDIUM) |
| 409 |
return r; |
| 410 |
|
| 411 |
/* If we have the pidfd inode number, also acquire the boot ID, to make things universally unique */ |
| 412 |
if (pidref->fd_id > 0) { |
| 413 |
r = sd_id128_get_boot(&boot_id); |
| 414 |
if (r < 0) |
| 415 |
return r; |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
return sd_json_buildo( |
| 420 |
ret, |
| 421 |
SD_JSON_BUILD_PAIR_INTEGER("pid", pidref->pid), |
| 422 |
SD_JSON_BUILD_PAIR_CONDITION(pidref->fd_id > 0, "pidfdId", SD_JSON_BUILD_INTEGER(pidref->fd_id)), |
| 423 |
SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(boot_id), "bootId", SD_JSON_BUILD_ID128(boot_id))); |
| 424 |
} |
| 425 |
|
| 426 |
int json_dispatch_pidref(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 427 |
PidRef *p = ASSERT_PTR(userdata); |
| 428 |
int r; |
| 429 |
|
| 430 |
assert(variant); |
| 431 |
|
| 432 |
/* Turns a JSON PID triplet back into a PidRef, i.e. the reverse of json_variant_new_pidref() |
| 433 |
* above. If SD_JSON_STRICT is set this will acquire a pidfd for the process, and validate that the |
| 434 |
* auxiliary fields match it. Otherwise, this will just store the pid and the pidfd inode number (the |
| 435 |
* latter not if the provided boot id differs from the local one), and not attempt to get a pidfd for |
| 436 |
* it, or authenticate it. |
| 437 |
* |
| 438 |
* If SD_JSON_RELAX is specified, a specified but zero/empty PID will be mapped to PIDREF_AUTOMATIC, |
| 439 |
* which is supposed to indicate that the PID shall be automatically derived, typically from the |
| 440 |
* connection peer. |
| 441 |
* |
| 442 |
* Note that SD_JSON_RELAX and SD_JSON_STRICT can be combined. */ |
| 443 |
|
| 444 |
if (sd_json_variant_is_null(variant)) { |
| 445 |
pidref_done(p); |
| 446 |
return 0; |
| 447 |
} |
| 448 |
|
| 449 |
struct { |
| 450 |
uint64_t pid, fd_id; |
| 451 |
sd_id128_t boot_id; |
| 452 |
} data = {}; |
| 453 |
|
| 454 |
if (sd_json_variant_is_integer(variant)) |
| 455 |
/* Permit a simple classic integer based format */ |
| 456 |
data.pid = sd_json_variant_integer(variant); |
| 457 |
else if (sd_json_variant_is_string(variant)) { |
| 458 |
/* As usual, allow integers be encoded as strings too */ |
| 459 |
r = safe_atou64(sd_json_variant_string(variant), &data.pid); |
| 460 |
if (r < 0) |
| 461 |
return json_log(variant, flags, r, "JSON field '%s' is not a numeric PID.", strna(name)); |
| 462 |
} else if (sd_json_variant_is_object(variant)) { |
| 463 |
|
| 464 |
static const sd_json_dispatch_field dispatch_table[] = { |
| 465 |
{ "pid", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, voffsetof(data, pid), SD_JSON_MANDATORY }, |
| 466 |
{ "pidfdId", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, voffsetof(data, fd_id), 0 }, |
| 467 |
{ "bootId", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, voffsetof(data, boot_id), 0 }, |
| 468 |
{} |
| 469 |
}; |
| 470 |
|
| 471 |
r = sd_json_dispatch(variant, dispatch_table, flags, &data); |
| 472 |
if (r < 0) |
| 473 |
return r; |
| 474 |
} else |
| 475 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is neither a numeric PID nor a PID object.", strna(name)); |
| 476 |
|
| 477 |
/* If SD_JSON_RELAX is set then we'll take a specified but zero field as request for "automatic" PID derivation */ |
| 478 |
if ((flags & SD_JSON_RELAX) && data.pid == 0 && data.fd_id == 0 && sd_id128_is_null(data.boot_id)) { |
| 479 |
pidref_done(p); |
| 480 |
*p = PIDREF_AUTOMATIC; |
| 481 |
return 0; |
| 482 |
} |
| 483 |
|
| 484 |
/* Before casting the 64bit data.pid field to pid_t, let's ensure it fits the pid_t range. */ |
| 485 |
if (data.pid > PID_T_MAX || !pid_is_valid(data.pid)) |
| 486 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' does not contain a valid PID.", strna(name)); |
| 487 |
|
| 488 |
int local_boot_id = -1; /* tristate */ |
| 489 |
if (!sd_id128_is_null(data.boot_id)) { |
| 490 |
sd_id128_t my_boot_id; |
| 491 |
|
| 492 |
r = sd_id128_get_boot(&my_boot_id); |
| 493 |
if (r < 0) { |
| 494 |
json_log(variant, flags | (FLAGS_SET(flags, SD_JSON_STRICT) ? 0 : SD_JSON_DEBUG), r, "Unable to get local boot ID to validate JSON field '%s': %m", strna(name)); |
| 495 |
if (FLAGS_SET(flags, SD_JSON_STRICT)) |
| 496 |
return r; |
| 497 |
} else { |
| 498 |
local_boot_id = sd_id128_equal(data.boot_id, my_boot_id); |
| 499 |
if (!local_boot_id) { |
| 500 |
json_log(variant, flags | (FLAGS_SET(flags, SD_JSON_STRICT) ? 0 : SD_JSON_DEBUG), 0, "JSON field '%s' refers to non-local PID%s.", strna(name), FLAGS_SET(flags, SD_JSON_STRICT) ? "" : ", proceeding"); |
| 501 |
if (FLAGS_SET(flags, SD_JSON_STRICT)) |
| 502 |
return -ESRCH; |
| 503 |
} |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
_cleanup_(pidref_done) PidRef np = PIDREF_NULL; |
| 508 |
if (local_boot_id == 0) |
| 509 |
/* If this is definitely not the local boot ID, then mark the PidRef as remote in the sense of pidref_is_remote() */ |
| 510 |
np = (PidRef) { |
| 511 |
.pid = data.pid, |
| 512 |
.fd = -EREMOTE, |
| 513 |
.fd_id = data.fd_id, |
| 514 |
}; |
| 515 |
else { |
| 516 |
/* Try to acquire a pidfd if this is or might be a local PID */ |
| 517 |
r = pidref_set_pid(&np, data.pid); |
| 518 |
if (r < 0) { |
| 519 |
json_log(variant, flags | (FLAGS_SET(flags, SD_JSON_STRICT) ? 0 : SD_JSON_DEBUG), r, "Unable to get fd for PID in JSON field '%s': %m", strna(name)); |
| 520 |
if (FLAGS_SET(flags, SD_JSON_STRICT)) |
| 521 |
return r; |
| 522 |
|
| 523 |
/* If the PID is dead or we otherwise can't get a pidfd of it, then store at least the PID number */ |
| 524 |
np = PIDREF_MAKE_FROM_PID(data.pid); |
| 525 |
} |
| 526 |
|
| 527 |
/* If the pidfd inode nr is specified, validate it or at least state */ |
| 528 |
if (data.fd_id > 0) { |
| 529 |
if (np.fd >= 0) { |
| 530 |
r = pidref_acquire_pidfd_id(&np); |
| 531 |
if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r)) |
| 532 |
return json_log(variant, flags, r, "Unable to get pidfd ID to validate JSON field '%s': %m", strna(name)); |
| 533 |
|
| 534 |
if (data.fd_id != np.fd_id) { |
| 535 |
json_log(variant, flags | (FLAGS_SET(flags, SD_JSON_STRICT) ? 0 : SD_JSON_DEBUG), 0, "JSON field '%s' references PID with non-matching inode number.", strna(name)); |
| 536 |
if (FLAGS_SET(flags, SD_JSON_STRICT)) |
| 537 |
return -ESRCH; |
| 538 |
} |
| 539 |
} else { |
| 540 |
json_log(variant, flags|SD_JSON_DEBUG, 0, "Not validating PID inode number on JSON field '%s', because operating without pidfd.", strna(name)); |
| 541 |
np.fd_id = data.fd_id; |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
pidref_done(p); |
| 547 |
*p = TAKE_PIDREF(np); |
| 548 |
|
| 549 |
return 0; |
| 550 |
} |
| 551 |
|
| 552 |
int json_dispatch_ifindex(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 553 |
int *ifi = ASSERT_PTR(userdata), r, t; |
| 554 |
|
| 555 |
if (sd_json_variant_is_null(variant)) { |
| 556 |
*ifi = 0; |
| 557 |
return 0; |
| 558 |
} |
| 559 |
|
| 560 |
r = sd_json_dispatch_int(name, variant, flags, &t); |
| 561 |
if (r < 0) |
| 562 |
return r; |
| 563 |
|
| 564 |
/* If SD_JSON_RELAX is set allow a zero interface index, otherwise refuse. */ |
| 565 |
if (t < (FLAGS_SET(flags, SD_JSON_RELAX) ? 0 : 1)) |
| 566 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is out of bounds for an interface index.", strna(name)); |
| 567 |
|
| 568 |
*ifi = t; |
| 569 |
return 0; |
| 570 |
} |
| 571 |
|
| 572 |
int json_dispatch_log_level(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 573 |
int *log_level = ASSERT_PTR(userdata), r, t; |
| 574 |
|
| 575 |
/* If SD_JSON_STRICT is set, we'll refuse attempts to set the log level to null. If SD_JSON_RELAX is |
| 576 |
* set we'll turn null (and any negative log level) into LOG_NULL (which when used as max log level |
| 577 |
* means: no logging). Otherwise we turn null into LOG_INFO (which is typically our default). */ |
| 578 |
|
| 579 |
if (sd_json_variant_is_null(variant)) { |
| 580 |
if (FLAGS_SET(flags, SD_JSON_STRICT)) |
| 581 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' may not be null.", strna(name)); |
| 582 |
|
| 583 |
*log_level = FLAGS_SET(flags, SD_JSON_RELAX) ? LOG_NULL : LOG_INFO; |
| 584 |
return 0; |
| 585 |
} |
| 586 |
|
| 587 |
r = sd_json_dispatch_int(name, variant, flags, &t); |
| 588 |
if (r < 0) |
| 589 |
return r; |
| 590 |
|
| 591 |
if (FLAGS_SET(flags, SD_JSON_RELAX) && t < 0) |
| 592 |
t = LOG_NULL; |
| 593 |
else if (!log_level_is_valid(t)) |
| 594 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid log level.", strna(name)); |
| 595 |
|
| 596 |
*log_level = t; |
| 597 |
return 0; |
| 598 |
} |
| 599 |
|
| 600 |
int json_variant_new_devnum(sd_json_variant **ret, dev_t devnum) { |
| 601 |
if (devnum == 0) |
| 602 |
return sd_json_variant_new_null(ret); |
| 603 |
|
| 604 |
return sd_json_buildo( |
| 605 |
ret, |
| 606 |
SD_JSON_BUILD_PAIR_UNSIGNED("major", major(devnum)), |
| 607 |
SD_JSON_BUILD_PAIR_UNSIGNED("minor", minor(devnum))); |
| 608 |
} |
| 609 |
|
| 610 |
int json_dispatch_devnum(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 611 |
dev_t *ret = ASSERT_PTR(userdata); |
| 612 |
int r; |
| 613 |
|
| 614 |
assert(variant); |
| 615 |
|
| 616 |
if (sd_json_variant_is_null(variant)) { |
| 617 |
*ret = 0; |
| 618 |
return 0; |
| 619 |
} |
| 620 |
|
| 621 |
struct { |
| 622 |
uint32_t major; |
| 623 |
uint32_t minor; |
| 624 |
} data; |
| 625 |
|
| 626 |
static const sd_json_dispatch_field dispatch_table[] = { |
| 627 |
{ "major", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint32, voffsetof(data, major), SD_JSON_MANDATORY }, |
| 628 |
{ "minor", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint32, voffsetof(data, minor), SD_JSON_MANDATORY }, |
| 629 |
{} |
| 630 |
}; |
| 631 |
|
| 632 |
r = sd_json_dispatch(variant, dispatch_table, flags, &data); |
| 633 |
if (r < 0) |
| 634 |
return r; |
| 635 |
|
| 636 |
if (!DEVICE_MAJOR_VALID(data.major) || !DEVICE_MINOR_VALID(data.minor)) |
| 637 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid device number.", strna(name)); |
| 638 |
|
| 639 |
*ret = makedev(data.major, data.minor); |
| 640 |
return 0; |
| 641 |
} |
| 642 |
|
| 643 |
int json_dispatch_strv_environment(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 644 |
char ***l = ASSERT_PTR(userdata); |
| 645 |
_cleanup_strv_free_ char **n = NULL; |
| 646 |
int r; |
| 647 |
|
| 648 |
if (sd_json_variant_is_null(variant)) { |
| 649 |
*l = strv_free(*l); |
| 650 |
return 0; |
| 651 |
} |
| 652 |
|
| 653 |
if (!sd_json_variant_is_array(variant)) |
| 654 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array.", strna(name)); |
| 655 |
|
| 656 |
if (sd_json_variant_elements(variant) > ENVIRONMENT_ASSIGNMENTS_MAX) |
| 657 |
return json_log(variant, flags, SYNTHETIC_ERRNO(E2BIG), "Too many environment variable assignments."); |
| 658 |
|
| 659 |
sd_json_variant *i; |
| 660 |
JSON_VARIANT_ARRAY_FOREACH(i, variant) { |
| 661 |
const char *e; |
| 662 |
|
| 663 |
if (!sd_json_variant_is_string(i)) |
| 664 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array of strings.", strna(name)); |
| 665 |
|
| 666 |
e = ASSERT_PTR(sd_json_variant_string(i)); |
| 667 |
if (!env_assignment_is_valid(e)) |
| 668 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), |
| 669 |
"JSON field '%s' contains invalid environment variable assignment.", strna(name)); |
| 670 |
|
| 671 |
r = strv_env_replace_strdup(&n, e); |
| 672 |
if (r < 0) |
| 673 |
return json_log_oom(variant, flags); |
| 674 |
} |
| 675 |
|
| 676 |
return strv_free_and_replace(*l, n); |
| 677 |
} |
| 678 |
|
| 679 |
static int json_variant_new_stat(sd_json_variant **ret, const struct stat *st) { |
| 680 |
char mode[STRLEN("0755")+1]; |
| 681 |
|
| 682 |
assert(st); |
| 683 |
|
| 684 |
if (!stat_is_set(st)) |
| 685 |
return sd_json_variant_new_null(ret); |
| 686 |
|
| 687 |
xsprintf(mode, "%04o", st->st_mode & ~S_IFMT); |
| 688 |
|
| 689 |
return sd_json_buildo( |
| 690 |
ret, |
| 691 |
JSON_BUILD_PAIR_DEVNUM("dev", st->st_dev), |
| 692 |
SD_JSON_BUILD_PAIR_UNSIGNED("inode", st->st_ino), |
| 693 |
JSON_BUILD_PAIR_STRING_NON_EMPTY("type", inode_type_to_string(st->st_mode)), |
| 694 |
SD_JSON_BUILD_PAIR_STRING("mode", mode), |
| 695 |
SD_JSON_BUILD_PAIR_UNSIGNED("linkCount", st->st_nlink), |
| 696 |
SD_JSON_BUILD_PAIR_UNSIGNED("uid", st->st_uid), |
| 697 |
SD_JSON_BUILD_PAIR_UNSIGNED("gid", st->st_gid), |
| 698 |
SD_JSON_BUILD_PAIR_CONDITION( |
| 699 |
S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode), |
| 700 |
"rdev", |
| 701 |
JSON_BUILD_DEVNUM(st->st_rdev)), |
| 702 |
SD_JSON_BUILD_PAIR_UNSIGNED("size", st->st_size), |
| 703 |
SD_JSON_BUILD_PAIR_UNSIGNED("blockSize", st->st_blksize), |
| 704 |
SD_JSON_BUILD_PAIR_UNSIGNED("blocks", st->st_blocks)); |
| 705 |
} |
| 706 |
|
| 707 |
static int json_variant_new_file_handle(sd_json_variant **ret, const struct file_handle *fid) { |
| 708 |
assert(ret); |
| 709 |
|
| 710 |
if (!fid) |
| 711 |
return sd_json_variant_new_null(ret); |
| 712 |
|
| 713 |
return sd_json_buildo( |
| 714 |
ret, |
| 715 |
SD_JSON_BUILD_PAIR_INTEGER("type", fid->handle_type), |
| 716 |
SD_JSON_BUILD_PAIR_BASE64("handle", fid->f_handle, fid->handle_bytes)); |
| 717 |
} |
| 718 |
|
| 719 |
int json_variant_new_fd_info(sd_json_variant **ret, int fd) { |
| 720 |
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *w = NULL; |
| 721 |
_cleanup_free_ char *path = NULL; |
| 722 |
_cleanup_free_ struct file_handle *fid = NULL; |
| 723 |
struct stat st; |
| 724 |
int mntid = -1, r; |
| 725 |
|
| 726 |
assert(fd >= 0 || fd == AT_FDCWD); |
| 727 |
|
| 728 |
r = fd_get_path(fd, &path); |
| 729 |
if (r < 0) |
| 730 |
return r; |
| 731 |
|
| 732 |
/* If AT_FDCWD is specified, show information about the current working directory. */ |
| 733 |
if (fstatat(fd, "", &st, AT_EMPTY_PATH) < 0) |
| 734 |
return -errno; |
| 735 |
|
| 736 |
r = json_variant_new_stat(&v, &st); |
| 737 |
if (r < 0) |
| 738 |
return r; |
| 739 |
|
| 740 |
r = name_to_handle_at_try_fid(fd, "", &fid, &mntid, /* ret_unique_mnt_id = */ NULL, AT_EMPTY_PATH); |
| 741 |
if (r < 0 && is_name_to_handle_at_fatal_error(r)) |
| 742 |
return r; |
| 743 |
|
| 744 |
r = json_variant_new_file_handle(&w, fid); |
| 745 |
if (r < 0) |
| 746 |
return r; |
| 747 |
|
| 748 |
return sd_json_buildo( |
| 749 |
ret, |
| 750 |
JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE("fd", fd), |
| 751 |
SD_JSON_BUILD_PAIR_STRING("path", path), |
| 752 |
SD_JSON_BUILD_PAIR_VARIANT("stat", v), |
| 753 |
JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE("mountId", mntid), |
| 754 |
SD_JSON_BUILD_PAIR_VARIANT("fileHandle", w)); |
| 755 |
} |
| 756 |
|
| 757 |
int json_dispatch_access_mode(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 758 |
mode_t *m = ASSERT_PTR(userdata); |
| 759 |
int r; |
| 760 |
|
| 761 |
if (sd_json_variant_is_null(variant)) { |
| 762 |
*m = MODE_INVALID; |
| 763 |
return 0; |
| 764 |
} |
| 765 |
|
| 766 |
/* Let the SD_JSON_STRICT determine if we allow suid/sgid/sticky or not */ |
| 767 |
mode_t limit = FLAGS_SET(flags, SD_JSON_STRICT) ? 0777 : 07777; |
| 768 |
|
| 769 |
if (sd_json_variant_is_string(variant)) { |
| 770 |
/* NB: we parse the mode in the usual octal if a string is specified. */ |
| 771 |
|
| 772 |
mode_t mode; |
| 773 |
r = parse_mode(sd_json_variant_string(variant), &mode); |
| 774 |
if (r < 0) |
| 775 |
return json_log(variant, flags, r, "JSON field '%s' is not a valid access mode string.", strna(name)); |
| 776 |
|
| 777 |
if (mode > limit) |
| 778 |
return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), |
| 779 |
"JSON field '%s' outside of valid range 0%s0%o.", |
| 780 |
strna(name), glyph(GLYPH_ELLIPSIS), limit); |
| 781 |
|
| 782 |
*m = mode; |
| 783 |
|
| 784 |
} else if (sd_json_variant_is_unsigned(variant)) { |
| 785 |
|
| 786 |
uint64_t k = sd_json_variant_unsigned(variant); |
| 787 |
if (k > (uint64_t) limit) |
| 788 |
return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), |
| 789 |
"JSON field '%s' outside of valid range 0%s0%o.", |
| 790 |
strna(name), glyph(GLYPH_ELLIPSIS), limit); |
| 791 |
|
| 792 |
*m = (mode_t) k; |
| 793 |
} else |
| 794 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is neither a number nor a string.", strna(name)); |
| 795 |
|
| 796 |
return 0; |
| 797 |
} |
| 798 |
|
| 799 |
int json_dispatch_job_id(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { |
| 800 |
uint32_t *id = ASSERT_PTR(userdata); |
| 801 |
uint32_t k; |
| 802 |
int r; |
| 803 |
|
| 804 |
if (sd_json_variant_is_null(variant)) { |
| 805 |
*id = 0; |
| 806 |
return 0; |
| 807 |
} |
| 808 |
|
| 809 |
r = sd_json_dispatch_uint32(name, variant, flags, &k); |
| 810 |
if (r < 0) |
| 811 |
return r; |
| 812 |
|
| 813 |
if (k == 0) |
| 814 |
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a valid job ID.", strna(name)); |
| 815 |
|
| 816 |
*id = k; |
| 817 |
return 0; |
| 818 |
} |
| 819 |
|
| 820 |
int json_variant_compare(sd_json_variant *a, sd_json_variant *b) { |
| 821 |
int r; |
| 822 |
|
| 823 |
r = CMP(!!a, !!b); |
| 824 |
if (r != 0) |
| 825 |
return r; |
| 826 |
|
| 827 |
if (sd_json_variant_equal(a, b)) |
| 828 |
return 0; |
| 829 |
|
| 830 |
if (sd_json_variant_is_null(a)) |
| 831 |
return -1; |
| 832 |
if (sd_json_variant_is_null(b)) |
| 833 |
return 1; |
| 834 |
|
| 835 |
if (sd_json_variant_is_string(a) && |
| 836 |
sd_json_variant_is_string(b)) |
| 837 |
return strcmp(sd_json_variant_string(a), sd_json_variant_string(b)); |
| 838 |
|
| 839 |
if (sd_json_variant_is_integer(a) && |
| 840 |
sd_json_variant_is_integer(b)) |
| 841 |
return CMP(sd_json_variant_integer(a), sd_json_variant_integer(b)); |
| 842 |
|
| 843 |
if (sd_json_variant_is_unsigned(a) && |
| 844 |
sd_json_variant_is_unsigned(b)) |
| 845 |
return CMP(sd_json_variant_unsigned(a), sd_json_variant_unsigned(b)); |
| 846 |
|
| 847 |
/* We cannot necessarily compare 64bit signed with unsigned, hence we go via sign checking instead */ |
| 848 |
if (sd_json_variant_is_number(a) && sd_json_variant_is_number(b)) { |
| 849 |
if (sd_json_variant_is_negative(a) && |
| 850 |
!sd_json_variant_is_negative(b)) |
| 851 |
return -1; |
| 852 |
|
| 853 |
if (!sd_json_variant_is_negative(a) && |
| 854 |
sd_json_variant_is_negative(b)) |
| 855 |
return 1; |
| 856 |
} |
| 857 |
|
| 858 |
if (sd_json_variant_is_real(a) && |
| 859 |
sd_json_variant_is_real(b)) |
| 860 |
return CMP(sd_json_variant_real(a), sd_json_variant_real(b)); |
| 861 |
|
| 862 |
if (sd_json_variant_is_boolean(a) && |
| 863 |
sd_json_variant_is_boolean(b)) |
| 864 |
return CMP(sd_json_variant_boolean(a), sd_json_variant_boolean(b)); |
| 865 |
|
| 866 |
if (sd_json_variant_is_array(a) && |
| 867 |
sd_json_variant_is_array(b)) { |
| 868 |
|
| 869 |
size_t n = sd_json_variant_elements(a), |
| 870 |
m = sd_json_variant_elements(b); |
| 871 |
for (size_t i = 0; i < n || i < m; i++) { |
| 872 |
|
| 873 |
if (i >= n) |
| 874 |
return -1; |
| 875 |
if (i >= m) |
| 876 |
return 1; |
| 877 |
|
| 878 |
r = json_variant_compare( |
| 879 |
sd_json_variant_by_index(a, i), |
| 880 |
sd_json_variant_by_index(b, i)); |
| 881 |
if (r != 0) |
| 882 |
return r; |
| 883 |
} |
| 884 |
|
| 885 |
return 0; |
| 886 |
} |
| 887 |
|
| 888 |
if (sd_json_variant_is_object(a) && |
| 889 |
sd_json_variant_is_object(b)) { |
| 890 |
const char *k, *lowest = NULL; |
| 891 |
sd_json_variant *v; |
| 892 |
int result = 0; |
| 893 |
|
| 894 |
JSON_VARIANT_OBJECT_FOREACH(k, v, a) { |
| 895 |
if (lowest && strcmp(k, lowest) >= 0) |
| 896 |
continue; |
| 897 |
|
| 898 |
r = json_variant_compare(v, sd_json_variant_by_key(b, k)); |
| 899 |
if (r != 0) { |
| 900 |
lowest = k; |
| 901 |
result = r; |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
JSON_VARIANT_OBJECT_FOREACH(k, v, b) { |
| 906 |
if (lowest && strcmp(k, lowest) >= 0) |
| 907 |
continue; |
| 908 |
|
| 909 |
r = json_variant_compare(v, sd_json_variant_by_key(a, k)); |
| 910 |
if (r != 0) { |
| 911 |
lowest = k; |
| 912 |
result = -r; |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
return result; |
| 917 |
} |
| 918 |
|
| 919 |
return CMP(sd_json_variant_type(a), sd_json_variant_type(b)); |
| 920 |
} |