]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
creds: fix cat with encrypted credentials
authorSimon Pilkington <simonp.git@mailbox.org>
Wed, 25 Sep 2024 09:25:48 +0000 (11:25 +0200)
committerSimon Pilkington <simonp.git@mailbox.org>
Wed, 25 Sep 2024 09:25:48 +0000 (11:25 +0200)
Fixes: https://github.com/systemd/systemd/issues/34547
src/creds/creds.c
test/units/TEST-54-CREDS.sh

index b55c60775c146b7d8457aafe64871bb625cad42b..bb59db37fc9bd6522bdcb4de96869f9330169d25 100644 (file)
@@ -434,10 +434,14 @@ static int verb_cat(int argc, char **argv, void *userdata) {
                         if (!d) /* Not set */
                                 continue;
 
+                        ReadFullFileFlags flags = READ_FULL_FILE_SECURE|READ_FULL_FILE_WARN_WORLD_READABLE;
+                        if (encrypted)
+                                flags |= READ_FULL_FILE_UNBASE64;
+
                         r = read_full_file_full(
                                         dirfd(d), *cn,
                                         UINT64_MAX, SIZE_MAX,
-                                        READ_FULL_FILE_SECURE|READ_FULL_FILE_WARN_WORLD_READABLE,
+                                        flags,
                                         NULL,
                                         (char**) &data, &size);
                         if (r == -ENOENT) /* Not found */
index 29b789d36166de0b4d50470061f239b40d0e9b65..3a4fa654e9494e222f7a351058bd9d72fdcf3b87 100755 (executable)
@@ -43,8 +43,8 @@ CRED_DIR="$(mktemp -d)"
 ENC_CRED_DIR="$(mktemp -d)"
 echo foo >"$CRED_DIR/secure-or-weak"
 echo foo >"$CRED_DIR/insecure"
-echo foo | systemd-creds --name="encrypted" encrypt - - | base64 -d >"$ENC_CRED_DIR/encrypted"
-echo foo | systemd-creds encrypt - - | base64 -d >"$ENC_CRED_DIR/encrypted-unnamed"
+echo foo | systemd-creds --name="encrypted" encrypt - "$ENC_CRED_DIR/encrypted"
+echo foo | systemd-creds encrypt - "$ENC_CRED_DIR/encrypted-unnamed"
 chmod -R 0400 "$CRED_DIR" "$ENC_CRED_DIR"
 chmod -R 0444 "$CRED_DIR/insecure"
 mkdir /tmp/empty/