Skip to content

Commit 32951fe

Browse files
creds: fix cat with encrypted credentials
Fixes: systemd#34547
1 parent 20d00d1 commit 32951fe

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/creds/creds.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,14 @@ static int verb_cat(int argc, char **argv, void *userdata) {
434434
if (!d) /* Not set */
435435
continue;
436436

437+
ReadFullFileFlags flags = READ_FULL_FILE_SECURE|READ_FULL_FILE_WARN_WORLD_READABLE;
438+
if (encrypted)
439+
flags |= READ_FULL_FILE_UNBASE64;
440+
437441
r = read_full_file_full(
438442
dirfd(d), *cn,
439443
UINT64_MAX, SIZE_MAX,
440-
READ_FULL_FILE_SECURE|READ_FULL_FILE_WARN_WORLD_READABLE,
444+
flags,
441445
NULL,
442446
(char**) &data, &size);
443447
if (r == -ENOENT) /* Not found */

test/units/TEST-54-CREDS.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ CRED_DIR="$(mktemp -d)"
4343
ENC_CRED_DIR="$(mktemp -d)"
4444
echo foo >"$CRED_DIR/secure-or-weak"
4545
echo foo >"$CRED_DIR/insecure"
46-
echo foo | systemd-creds --name="encrypted" encrypt - - | base64 -d >"$ENC_CRED_DIR/encrypted"
47-
echo foo | systemd-creds encrypt - - | base64 -d >"$ENC_CRED_DIR/encrypted-unnamed"
46+
echo foo | systemd-creds --name="encrypted" encrypt - "$ENC_CRED_DIR/encrypted"
47+
echo foo | systemd-creds encrypt - "$ENC_CRED_DIR/encrypted-unnamed"
4848
chmod -R 0400 "$CRED_DIR" "$ENC_CRED_DIR"
4949
chmod -R 0444 "$CRED_DIR/insecure"
5050
mkdir /tmp/empty/

0 commit comments

Comments
 (0)