id128: reject app-specific IDs for new

Reject --app-specific= for the new verb. The option only makes sense
for verbs that derive IDs from an existing base ID.

Reproducer: systemd-id128 new --app-specific=4f68bce3e8cd4db196e7fbcaf984b709

Before: the command printed a random ID and exited successfully.

Follow-up: 0d1d512f7f
This commit is contained in:
dongshengyuan
2026-07-17 11:09:34 +08:00
parent 8009fa4984
commit 8729fa0e4b
2 changed files with 5 additions and 1 deletions
+4
View File
@@ -52,6 +52,10 @@ static int verb_new(int argc, char *argv[], uintptr_t _data, void *userdata) {
sd_id128_t id;
int r;
if (!sd_id128_is_null(arg_app))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Verb \"new\" cannot be combined with --app-specific=.");
r = sd_id128_randomize(&id);
if (r < 0)
return log_error_errno(r, "Failed to generate ID: %m");
+1 -1
View File
@@ -36,7 +36,6 @@ systemd-id128 show root --value --json=short | jq -e '.id | type == "string"'
systemd-id128 --json=short new | jq -e '.id | type == "string"'
systemd-id128 new -p
systemd-id128 new -u
systemd-id128 new -a 4f68bce3e8cd4db196e7fbcaf984b709
systemd-id128 machine-id
assert_eq "$(systemd-id128 --json=short machine-id | jq --raw-output .id)" "$(</etc/machine-id)"
@@ -56,6 +55,7 @@ assert_eq "$(systemd-id128 boot-id --uuid)" "$(</proc/sys/kernel/random/boot_id)
systemd-run --wait --pipe bash -euxc '[[ $INVOCATION_ID == "$(systemd-id128 invocation-id)" ]]'
(! systemd-id128)
(! systemd-id128 new -a 4f68bce3e8cd4db196e7fbcaf984b709)
(! systemd-id128 new -a '')
(! systemd-id128 new -a '0')
(! systemd-id128 invocation-id -a 4f68bce3e8cd4db196e7fbcaf984b709)