]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: make ImportCredentialEx= DBus property support without renaming
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 3 Aug 2024 05:19:35 +0000 (14:19 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 3 Aug 2024 05:20:07 +0000 (14:20 +0900)
Note that the conf parser for ImportCredential= checks in the same way.

Follow-up for 831f208783aeac443e6f2fc2efc3119535a032ef.

src/core/dbus-execute.c
test/units/TEST-54-CREDS.sh

index feafa15e4303a1b2960ba8f164a244846be16f26..c7c43ce7d38f0e19eeefacfa3753e7b6b0f75215 100644 (file)
@@ -2225,7 +2225,7 @@ int bus_exec_context_set_transient_property(
                         if (!credential_glob_valid(glob))
                                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential name or glob is invalid: %s", glob);
 
-                        if (rename && !credential_name_valid(rename))
+                        if (!isempty(rename) && !credential_name_valid(rename))
                                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential name is invalid: %s", rename);
 
                         empty = false;
index 9f7f4b11606f477d4937173b0a0399b65307e2cc..aa0a1329e0e7a46df5dd283334ce244376d1b166 100755 (executable)
@@ -279,6 +279,8 @@ echo -n ignored >/run/credstore/test.creds.second
 mkdir -p /etc/credstore
 echo -n b >/etc/credstore/test.creds.second
 echo -n c >/etc/credstore/test.creds.third
+
+# Check that all valid credentials are imported.
 systemd-run -p "ImportCredential=test.creds.*" \
             --unit=test-54-ImportCredential.service \
             -p DynamicUser=1 \
@@ -289,6 +291,17 @@ systemd-run -p "ImportCredential=test.creds.*" \
                 '${CREDENTIALS_DIRECTORY}/test.creds.third' >/tmp/ts54-concat
 cmp /tmp/ts54-concat <(echo -n abc)
 
+# Check that ImportCredentialEx= works without renaming.
+systemd-run -p "ImportCredentialEx=test.creds.*" \
+            --unit=test-54-ImportCredential.service \
+            -p DynamicUser=1 \
+            --wait \
+            --pipe \
+            cat '${CREDENTIALS_DIRECTORY}/test.creds.first' \
+                '${CREDENTIALS_DIRECTORY}/test.creds.second' \
+                '${CREDENTIALS_DIRECTORY}/test.creds.third' >/tmp/ts54-concat
+cmp /tmp/ts54-concat <(echo -n abc)
+
 # Check that renaming with globs works as expected.
 systemd-run -p "ImportCredentialEx=test.creds.*:renamed.creds." \
             --unit=test-54-ImportCredential.service \