diff --git a/TODO b/TODO index 20d81c4ba7..4a258e5014 100644 --- a/TODO +++ b/TODO @@ -310,6 +310,8 @@ Features: aforementioned journald subscription varlink service, to enable activation-by-message id and similar. +* .service with invalid Sockets= starts successfully. + * landlock: lock down RuntimeDirectory= via landlock, so that services lose ability to write anywehere else below /run/. Similar for StateDirectory=. Benefit would be clear delegation via unit files: services diff --git a/man/rules/meson.build b/man/rules/meson.build index eaaf4adb1b..2884cc32b4 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -672,7 +672,8 @@ manpages = [ ''], ['sd_id128_get_machine', '3', - ['sd_id128_get_boot', + ['sd_id128_get_app_specific', + 'sd_id128_get_boot', 'sd_id128_get_boot_app_specific', 'sd_id128_get_invocation', 'sd_id128_get_machine_app_specific'], diff --git a/man/sd_id128_get_machine.xml b/man/sd_id128_get_machine.xml index 40b9b6f582..31e4b02d9b 100644 --- a/man/sd_id128_get_machine.xml +++ b/man/sd_id128_get_machine.xml @@ -17,6 +17,7 @@ sd_id128_get_machine + sd_id128_get_app_specific sd_id128_get_machine_app_specific sd_id128_get_boot sd_id128_get_boot_app_specific @@ -33,6 +34,13 @@ sd_id128_t *ret + + int sd_id128_get_app_specific + sd_id128_t base + sd_id128_t app_id + sd_id128_t *ret + + int sd_id128_get_machine_app_specific sd_id128_t app_id @@ -69,16 +77,25 @@ ID from this machine ID, in an irreversible (cryptographically secure) way. To make this easy sd_id128_get_machine_app_specific() is provided, see below. + sd_id128_get_app_specific() returns a machine ID that is a combination of the + base and app_id parameters. Internally, this function + calculates HMAC-SHA256 of the app_id parameter keyed by the + base parameter, and truncates this result to fit in + sd_id128_t and turns it into a valid Variant 1 Version 4 UUID, in accordance + with RFC 4122. Neither of the two input + parameters can be calculated from the output parameter ret. + sd_id128_get_machine_app_specific() is similar to - sd_id128_get_machine(), but retrieves a machine ID that is specific to the application that is - identified by the indicated application ID. It is recommended to use this function instead of - sd_id128_get_machine() when passing an ID to untrusted environments, in order to make sure - that the original machine ID may not be determined externally. This way, the ID used by the application remains - stable on a given machine, but cannot be easily correlated with IDs used in other applications on the same - machine. The application-specific ID should be generated via a tool like systemd-id128 new, - and may be compiled into the application. This function will return the same application-specific ID for each - combination of machine ID and application ID. Internally, this function calculates HMAC-SHA256 of the application - ID, keyed by the machine ID. + sd_id128_get_machine(), but retrieves a machine ID that is specific to the + application that is identified by the indicated application ID. It is recommended to use this function + instead of sd_id128_get_machine() when passing an ID to untrusted environments, in + order to make sure that the original machine ID may not be determined externally. This way, the ID used + by the application remains stable on a given machine, but cannot be easily correlated with IDs used in + other applications on the same machine. The application-specific ID should be generated via a tool like + systemd-id128 new, and may be compiled into the application. This function will return + the same application-specific ID for each combination of machine ID and application ID. Internally, this + function calls sd_id128_get_app_specific() with the result from + sd_id128_get_machine() and the app_id parameter. sd_id128_get_boot() returns the boot ID of the executing kernel. This reads and parses the /proc/sys/kernel/random/boot_id file exposed by the kernel. It is randomly generated early @@ -89,9 +106,9 @@ derive an application specific ID using sd_id128_get_boot_app_specific(), see below. sd_id128_get_boot_app_specific() is analogous to - sd_id128_get_machine_app_specific() but returns an ID that changes between boots. Some - machines may be used for a long time without rebooting, hence the boot ID may remain constant for a long time, and - has properties similar to the machine ID during that time. + sd_id128_get_machine_app_specific(), but returns an ID that changes between + boots. Some machines may be used for a long time without rebooting, hence the boot ID may remain constant + for a long time, and has properties similar to the machine ID during that time. sd_id128_get_invocation() returns the invocation ID of the currently executed service. In its current implementation, this tries to read and parse the following: @@ -181,7 +198,10 @@ -ENXIO Returned by sd_id128_get_invocation() if no invocation ID is - set. + set. Also returned by sd_id128_get_app_specific(), + sd_id128_get_machine_app_specific(), and + sd_id128_get_boot_app_specific() when the app_id + parameter is all zeros. diff --git a/man/systemd-id128.xml b/man/systemd-id128.xml index 2211550451..32226363cb 100644 --- a/man/systemd-id128.xml +++ b/man/systemd-id128.xml @@ -44,6 +44,13 @@ OPTIONS invocation-id + + + systemd-id128 + OPTIONS + show + NAME|UUID + @@ -63,12 +70,6 @@ With boot-id, the identifier of the current boot will be printed. - Both machine-id and boot-id may be combined - with the switch to - generate application-specific IDs. See - sd_id128_get_machine3 - for the discussion when this is useful. - With invocation-id, the identifier of the current service invocation will be printed. This is available in systemd services. See systemd.exec5. @@ -76,9 +77,17 @@ With show, well-known IDs are printed (for now, only GPT partition type UUIDs), along with brief identifier strings. When no arguments are specified, all known IDs are shown. When - arguments are specified, they must be the identifiers or ID values of one or more known IDs, which are - then printed. Combine with to list the IDs in UUID style, i.e. the way GPT - partition type UUIDs are usually shown. + arguments are specified, they may be the identifiers or ID values of one or more known IDs, which are + then printed with their name, or arbitrary IDs, which are then printed with a placeholder name. Combine + with to list the IDs in UUID style, i.e. the way GPT partition type UUIDs are + usually shown. + + machine-id, boot-id, and show may be + combined with the switch to generate + application-specific IDs. See + sd_id128_get_machine3 + for the discussion when this is useful. Support for show --app-specific= was added in + version 255. @@ -96,14 +105,28 @@ + + + + + Only print the value. May be combined with + /. + + + + - With this option, an identifier that is the result of hashing the - application identifier app-id and the machine identifier will be - printed. The app-id argument must be a valid sd-id128 string - identifying the application. + With this option, identifiers will be printed that are the result of hashing the + application identifier app-id and another ID. The + app-id argument must be a valid sd-id128 string identifying the + application. When used with machine-id, the other ID will be the machine ID as + described in + machine-id5, when + used with boot-id, the other ID will be the boot ID, and when used with + show, the other ID or IDs should be specified via the positional arguments. @@ -129,7 +152,49 @@ Exit status - On success, 0 is returned, a non-zero failure code otherwise. + On success 0 is returned, and a non-zero failure code otherwise. + + + + Examples + + + Show a well-known UUID + +$ systemd-id128 show -P user-home +773f91ef66d449b5bd83d683bf40ad16 + +$ systemd-id128 show -Pu user-home +773f91ef-66d4-49b5-bd83-d683bf40ad16 + +$ systemd-id128 show 773f91ef-66d4-49b5-bd83-d683bf40ad16 +NAME ID +user-home 773f91ef66d449b5bd83d683bf40ad16 + + + + + Generate an application-specific UUID + + +$ systemd-id128 machine-id -u +3a9d668b-4db7-4939-8a4a-5e78a03bffb7 + +$ systemd-id128 new -u +1fb8f24b-02df-458d-9659-cc8ace68e28a + +$ systemd-id128 --app=1fb8f24b-02df-458d-9659-cc8ace68e28a +47b82cb1-5339-43da-b2a6-1c350aef1bd1 + +$ systemd-id128 -Pu show 3a9d668b-4db7-4939-8a4a-5e78a03bffb7 --app=1fb8f24b-02df-458d-9659-cc8ace68e28a +47b82cb1-5339-43da-b2a6-1c350aef1bd1 + + + On a given machine with the ID 3a9d668b-4db7-4939-8a4a-5e78a03bffb7, for the application + 1fb8f24b-02df-458d-9659-cc8ace68e28a, we generate an application-specific machine ID. If we want to + later recreate the same calculation on a different machine, we need to specify both IDs explicitly. + + diff --git a/src/core/main.c b/src/core/main.c index f8b0c69f5a..279f1b16ce 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -242,20 +242,6 @@ static int console_setup(void) { return 0; } -static int set_machine_id(const char *m) { - sd_id128_t t; - assert(m); - - if (sd_id128_from_string(m, &t) < 0) - return -EINVAL; - - if (sd_id128_is_null(t)) - return -EINVAL; - - arg_machine_id = t; - return 0; -} - static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { int r; @@ -392,7 +378,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (proc_cmdline_value_missing(key, value)) return 0; - r = set_machine_id(value); + r = id128_from_string_nonzero(value, &arg_machine_id); if (r < 0) log_warning_errno(r, "MachineID '%s' is not valid, ignoring: %m", value); @@ -1045,7 +1031,7 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_MACHINE_ID: - r = set_machine_id(optarg); + r = id128_from_string_nonzero(optarg, &arg_machine_id); if (r < 0) return log_error_errno(r, "MachineID '%s' is not valid: %m", optarg); break; diff --git a/src/id128/id128.c b/src/id128/id128.c index a8c5c9ac6c..9e0a3488dd 100644 --- a/src/id128/id128.c +++ b/src/id128/id128.c @@ -16,6 +16,7 @@ static Id128PrettyPrintMode arg_mode = ID128_PRINT_ID128; static sd_id128_t arg_app = {}; +static bool arg_value = false; static int verb_new(int argc, char **argv, void *userdata) { return id128_print_new(arg_mode); @@ -67,8 +68,16 @@ static int verb_invocation_id(int argc, char **argv, void *userdata) { } static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first) { + sd_id128_t u; int r; + assert(table); + + if (sd_id128_is_null(arg_app)) + u = uuid; + else + assert_se(sd_id128_get_app_specific(uuid, arg_app, &u) == 0); + if (arg_mode == ID128_PRINT_PRETTY) { _cleanup_free_ char *id = NULL; @@ -78,26 +87,28 @@ static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first ascii_strupper(id); - r = id128_pretty_print_sample(id, uuid); + r = id128_pretty_print_sample(id, u); if (r < 0) return r; if (!first) puts(""); return 0; - - } else { - if (!*table) { - *table = table_new("name", "id"); - if (!*table) - return log_oom(); - table_set_width(*table, 0); - } - - return table_add_many(*table, - TABLE_STRING, name, - arg_mode == ID128_PRINT_ID128 ? TABLE_ID128 : TABLE_UUID, - uuid); } + + if (arg_value) + return id128_pretty_print(u, arg_mode); + + if (!*table) { + *table = table_new("name", "id"); + if (!*table) + return log_oom(); + table_set_width(*table, 0); + } + + return table_add_many(*table, + TABLE_STRING, name, + arg_mode == ID128_PRINT_ID128 ? TABLE_ID128 : TABLE_UUID, + u); } static int verb_show(int argc, char **argv, void *userdata) { @@ -162,7 +173,7 @@ static int help(void) { " machine-id Print the ID of current machine\n" " boot-id Print the ID of current boot\n" " invocation-id Print the ID of current invocation\n" - " show [NAME] Print one or more well-known GPT partition type IDs\n" + " show [NAME|UUID] Print one or more UUIDs\n" " help Show this help\n" "\nOptions:\n" " -h --help Show this help\n" @@ -191,6 +202,7 @@ static int parse_argv(int argc, char *argv[]) { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, { "pretty", no_argument, NULL, 'p' }, + { "value", no_argument, NULL, 'P' }, { "app-specific", required_argument, NULL, 'a' }, { "uuid", no_argument, NULL, 'u' }, {}, @@ -201,7 +213,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "hpa:u", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "hpa:uP", options, NULL)) >= 0) switch (c) { case 'h': @@ -212,10 +224,19 @@ static int parse_argv(int argc, char *argv[]) { case 'p': arg_mode = ID128_PRINT_PRETTY; + arg_value = false; + break; + + case 'P': + arg_value = true; + if (arg_mode == ID128_PRINT_PRETTY) + arg_mode = ID128_PRINT_ID128; break; case 'a': - r = sd_id128_from_string(optarg, &arg_app); + r = id128_from_string_nonzero(optarg, &arg_app); + if (r == -ENXIO) + return log_error_errno(r, "Application ID cannot be all zeros."); if (r < 0) return log_error_errno(r, "Failed to parse \"%s\" as application-ID: %m", optarg); break; diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index ea13e02719..56a8831f0f 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -828,3 +828,8 @@ global: sd_journal_step_one; sd_session_get_leader; } LIBSYSTEMD_253; + +LIBSYSTEMD_255 { +global: + sd_id128_get_app_specific; +} LIBSYSTEMD_254; diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c index ee9e91c58d..9d391de166 100644 --- a/src/libsystemd/sd-id128/id128-util.c +++ b/src/libsystemd/sd-id128/id128-util.c @@ -13,6 +13,23 @@ #include "string-util.h" #include "sync-util.h" +int id128_from_string_nonzero(const char *s, sd_id128_t *ret) { + sd_id128_t t; + int r; + + assert(ret); + + r = sd_id128_from_string(ASSERT_PTR(s), &t); + if (r < 0) + return r; + + if (sd_id128_is_null(t)) + return -ENXIO; + + *ret = t; + return 0; +} + bool id128_is_valid(const char *s) { size_t l; diff --git a/src/libsystemd/sd-id128/id128-util.h b/src/libsystemd/sd-id128/id128-util.h index bd3e201361..80c36e5a7b 100644 --- a/src/libsystemd/sd-id128/id128-util.h +++ b/src/libsystemd/sd-id128/id128-util.h @@ -21,6 +21,8 @@ typedef enum Id128Flag { ID128_REFUSE_NULL = 1 << 3, /* Refuse all zero ID with -ENOMEDIUM. */ } Id128Flag; +int id128_from_string_nonzero(const char *s, sd_id128_t *ret); + int id128_read_fd(int fd, Id128Flag f, sd_id128_t *ret); int id128_read_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t *ret); static inline int id128_read(const char *path, Id128Flag f, sd_id128_t *ret) { diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index 6a82a7f7b8..9fda79ae26 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -338,18 +338,20 @@ _public_ int sd_id128_randomize(sd_id128_t *ret) { return 0; } -static int get_app_specific(sd_id128_t base, sd_id128_t app_id, sd_id128_t *ret) { - uint8_t hmac[SHA256_DIGEST_SIZE]; - sd_id128_t result; +_public_ int sd_id128_get_app_specific(sd_id128_t base, sd_id128_t app_id, sd_id128_t *ret) { + assert_cc(sizeof(sd_id128_t) < SHA256_DIGEST_SIZE); /* Check that we don't need to pad with zeros. */ + union { + uint8_t hmac[SHA256_DIGEST_SIZE]; + sd_id128_t result; + } buf; - assert(ret); + assert_return(ret, -EINVAL); + assert_return(!sd_id128_is_null(app_id), -ENXIO); - hmac_sha256(&base, sizeof(base), &app_id, sizeof(app_id), hmac); + hmac_sha256(&base, sizeof(base), &app_id, sizeof(app_id), buf.hmac); /* Take only the first half. */ - memcpy(&result, hmac, MIN(sizeof(hmac), sizeof(result))); - - *ret = id128_make_v4_uuid(result); + *ret = id128_make_v4_uuid(buf.result); return 0; } @@ -363,7 +365,7 @@ _public_ int sd_id128_get_machine_app_specific(sd_id128_t app_id, sd_id128_t *re if (r < 0) return r; - return get_app_specific(id, app_id, ret); + return sd_id128_get_app_specific(id, app_id, ret); } _public_ int sd_id128_get_boot_app_specific(sd_id128_t app_id, sd_id128_t *ret) { @@ -376,5 +378,5 @@ _public_ int sd_id128_get_boot_app_specific(sd_id128_t app_id, sd_id128_t *ret) if (r < 0) return r; - return get_app_specific(id, app_id, ret); + return sd_id128_get_app_specific(id, app_id, ret); } diff --git a/src/network/networkd-address-generation.c b/src/network/networkd-address-generation.c index 769cccf748..79fde024a3 100644 --- a/src/network/networkd-address-generation.c +++ b/src/network/networkd-address-generation.c @@ -370,16 +370,11 @@ int config_parse_address_generation_type( } if (comma) { - r = sd_id128_from_string(comma + 1, &secret_key); + r = id128_from_string_nonzero(comma + 1, &secret_key); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse secret key in %s=, ignoring assignment: %s", - lvalue, rvalue); - return 0; - } - if (sd_id128_is_null(secret_key)) { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Secret key in %s= cannot be null, ignoring assignment: %s", + r == -ENXIO ? "Secret key in %s= cannot be null, ignoring assignment: %s" + : "Failed to parse secret key in %s=, ignoring assignment: %s", lvalue, rvalue); return 0; } diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index d3ae547746..9e74ead8d5 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -976,13 +976,12 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_UUID: - r = sd_id128_from_string(optarg, &arg_uuid); - if (r < 0) - return log_error_errno(r, "Invalid UUID: %s", optarg); - - if (sd_id128_is_null(arg_uuid)) + r = id128_from_string_nonzero(optarg, &arg_uuid); + if (r == -ENXIO) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Machine UUID may not be all zeroes."); + if (r < 0) + return log_error_errno(r, "Invalid UUID: %s", optarg); arg_settings_mask |= SETTING_MACHINE_ID; break; diff --git a/src/partition/repart.c b/src/partition/repart.c index e403012e92..b6fe9ef79e 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -2438,11 +2438,8 @@ static int context_load_partition_table(Context *context) { if (r < 0) return log_error_errno(r, "Failed to get current GPT disk label UUID: %m"); - r = sd_id128_from_string(disk_uuid_string, &disk_uuid); - if (r < 0) - return log_error_errno(r, "Failed to parse current GPT disk label UUID: %m"); - - if (sd_id128_is_null(disk_uuid)) { + r = id128_from_string_nonzero(disk_uuid_string, &disk_uuid); + if (r == -ENXIO) { r = derive_uuid(context->seed, "disk-uuid", &disk_uuid); if (r < 0) return log_error_errno(r, "Failed to acquire disk GPT uuid: %m"); @@ -2450,7 +2447,8 @@ static int context_load_partition_table(Context *context) { r = fdisk_set_disklabel_id(c); if (r < 0) return log_error_errno(r, "Failed to set GPT disk label: %m"); - } + } else if (r < 0) + return log_error_errno(r, "Failed to parse current GPT disk label UUID: %m"); r = fdisk_get_partitions(c, &t); if (r < 0) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index ec4b53b2e8..68c4b2ca1a 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -19,6 +19,7 @@ #include "fileio.h" #include "fs-util.h" #include "hostname-util.h" +#include "id128-util.h" #include "in-addr-util.h" #include "log.h" #include "macro.h" @@ -944,25 +945,19 @@ int config_parse_id128( void *data, void *userdata) { - sd_id128_t t, *result = data; + sd_id128_t *result = data; int r; assert(filename); assert(lvalue); assert(rvalue); - r = sd_id128_from_string(rvalue, &t); - if (r < 0) { + r = id128_from_string_nonzero(rvalue, result); + if (r == -ENXIO) + log_syntax(unit, LOG_WARNING, filename, line, r, "128-bit ID/UUID is all 0, ignoring: %s", rvalue); + else if (r < 0) log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse 128-bit ID/UUID, ignoring: %s", rvalue); - return 0; - } - if (sd_id128_is_null(t)) { - log_syntax(unit, LOG_WARNING, filename, line, 0, "128-bit ID/UUID is all 0, ignoring: %s", rvalue); - return 0; - } - - *result = t; return 0; } diff --git a/src/shared/id128-print.c b/src/shared/id128-print.c index f232767adf..c9509b28f0 100644 --- a/src/shared/id128-print.c +++ b/src/shared/id128-print.c @@ -11,12 +11,10 @@ #include "terminal-util.h" int id128_pretty_print_sample(const char *name, sd_id128_t id) { - _cleanup_free_ char *man_link = NULL, *mod_link = NULL; - const char *on, *off; - unsigned i; + _cleanup_free_ char *man_link = NULL, *mod_link = NULL; - on = ansi_highlight(); - off = ansi_normal(); + const char *on = ansi_highlight(), + *off = ansi_normal(); if (terminal_urlify("man:systemd-id128(1)", "systemd-id128(1)", &man_link) < 0) return log_oom(); @@ -34,8 +32,8 @@ int id128_pretty_print_sample(const char *name, sd_id128_t id) { on, SD_ID128_FORMAT_VAL(id), off, man_link, on, name); - for (i = 0; i < 16; i++) - printf("%02x%s", id.bytes[i], i != 15 ? "," : ""); + for (size_t i = 0; i < 16; i++) + printf("%02x%s", id.bytes[i], i < 15 ? "," : ""); printf(")%s\n\n", off); printf("As Python constant:\n" diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h index 3303c374ce..a984a9d85e 100644 --- a/src/systemd/sd-id128.h +++ b/src/systemd/sd-id128.h @@ -50,6 +50,7 @@ int sd_id128_get_machine(sd_id128_t *ret); int sd_id128_get_boot(sd_id128_t *ret); int sd_id128_get_invocation(sd_id128_t *ret); +int sd_id128_get_app_specific(sd_id128_t base, sd_id128_t app_id, sd_id128_t *ret); int sd_id128_get_machine_app_specific(sd_id128_t app_id, sd_id128_t *ret); int sd_id128_get_boot_app_specific(sd_id128_t app_id, sd_id128_t *ret); diff --git a/src/test/test-id128.c b/src/test/test-id128.c index 58dc88110e..ae7df27d8f 100644 --- a/src/test/test-id128.c +++ b/src/test/test-id128.c @@ -20,6 +20,7 @@ #define ID128_WALDI SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10) #define STR_WALDI "0102030405060708090a0b0c0d0e0f10" #define UUID_WALDI "01020304-0506-0708-090a-0b0c0d0e0f10" +#define STR_NULL "00000000000000000000000000000000" TEST(id128) { sd_id128_t id, id2; @@ -75,6 +76,13 @@ TEST(id128) { assert_se(sd_id128_from_string("01020304-0506-0708-090a0b0c0d0e0f10", &id) < 0); assert_se(sd_id128_from_string("010203040506-0708-090a-0b0c0d0e0f10", &id) < 0); + assert_se(id128_from_string_nonzero(STR_WALDI, &id) == 0); + assert_se(id128_from_string_nonzero(STR_NULL, &id) == -ENXIO); + assert_se(id128_from_string_nonzero("01020304-0506-0708-090a-0b0c0d0e0f101", &id) < 0); + assert_se(id128_from_string_nonzero("01020304-0506-0708-090a-0b0c0d0e0f10-", &id) < 0); + assert_se(id128_from_string_nonzero("01020304-0506-0708-090a0b0c0d0e0f10", &id) < 0); + assert_se(id128_from_string_nonzero("010203040506-0708-090a-0b0c0d0e0f10", &id) < 0); + assert_se(id128_is_valid(STR_WALDI)); assert_se(id128_is_valid(UUID_WALDI)); assert_se(!id128_is_valid("")); @@ -172,6 +180,11 @@ TEST(id128) { assert_se(lseek(fd, 0, SEEK_SET) == 0); assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, NULL) == -EUCLEAN); + /* build/systemd-id128 -a f03daaeb1c334b43a732172944bf772e show 51df0b4bc3b04c9780e299b98ca373b8 */ + assert_se(sd_id128_get_app_specific(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8), + SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id) >= 0); + assert_se(sd_id128_equal(id, SD_ID128_MAKE(1d,ee,59,54,e7,5c,4d,6f,b9,6c,c6,c0,4c,a1,8a,86))); + if (sd_booted() > 0 && sd_id128_get_machine(NULL) >= 0) { assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id) >= 0); assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id2) >= 0); @@ -179,6 +192,10 @@ TEST(id128) { assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8), &id2) >= 0); assert_se(!sd_id128_equal(id, id2)); } + + /* Check return values */ + assert_se(sd_id128_get_app_specific(SD_ID128_ALLF, SD_ID128_NULL, &id) == -ENXIO); + assert_se(sd_id128_get_app_specific(SD_ID128_NULL, SD_ID128_ALLF, &id) == 0); } TEST(sd_id128_get_invocation) { diff --git a/test/units/testsuite-74.id128.sh b/test/units/testsuite-74.id128.sh index 213333d9d1..c1b80d660e 100755 --- a/test/units/testsuite-74.id128.sh +++ b/test/units/testsuite-74.id128.sh @@ -9,9 +9,18 @@ set -o pipefail systemd-id128 --help systemd-id128 help systemd-id128 show -systemd-id128 show --pretty | tail -n10 +systemd-id128 show --pretty | tail +systemd-id128 show --value | tail systemd-id128 show 4f68bce3e8cd4db196e7fbcaf984b709 # root-x86-64 systemd-id128 show --pretty 4f68bce3e8cd4db196e7fbcaf984b709 +systemd-id128 show root-x86-64 +systemd-id128 show --pretty root-x86-64 +[[ "$(systemd-id128 show 4f68bce3e8cd4db196e7fbcaf984b709)" = "$(systemd-id128 show root-x86-64)" ]] +[[ "$(systemd-id128 show 4f68bce3-e8cd-4db1-96e7-fbcaf984b709)" = "$(systemd-id128 show root-x86-64)" ]] + +systemd-id128 show root-x86-64 --app-specific=4f68bce3e8cd4db196e7fbcaf984b709 +systemd-id128 show --pretty root-x86-64 --app-specific=4f68bce3e8cd4db196e7fbcaf984b709 +[[ "$(systemd-id128 show root-x86-64 --app-specific=4f68bce3e8cd4db196e7fbcaf984b709 -P)" = "8ee5535e7cb14c249e1d28b8dfbb939c" ]] [[ "$(systemd-id128 new | wc -c)" -eq 33 ]] systemd-id128 new -p