]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
id128: reject app-specific IDs for new
authordongshengyuan <545258830@qq.com>
Thu, 16 Jul 2026 06:18:01 +0000 (14:18 +0800)
committerdongshengyuan <545258830@qq.com>
Fri, 17 Jul 2026 03:09:34 +0000 (11:09 +0800)
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: 0d1d512f7f42071595f0c950f911f3557fda09ea

src/id128/id128.c
test/units/TEST-74-AUX-UTILS.id128.sh

index a4452f1cc502e8a796d128e825a5eb061c27061d..5326ef1f51d8d7ad705d4ae278716ebe1916db01 100644 (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");
index 5da2323461bc56065189a6e476964ba69a4b877e..518642442df1a4e708307395a9dc3763974eeefc 100755 (executable)
@@ -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)