diff options
author | Frantisek Sumsal <frantisek@sumsal.cz> | 2023-04-25 12:58:15 +0200 |
---|---|---|
committer | Frantisek Sumsal <frantisek@sumsal.cz> | 2023-04-25 18:34:49 +0200 |
commit | c74e13a5c334d6bb4eefc5cac1fa26cb9c5a4dd1 (patch) | |
tree | fea1700d27425fc9073c4ac3d8329dab1fa99de3 /src/creds | |
parent | test: cover missed stuff from securebits-util.h (diff) | |
download | systemd-c74e13a5c334d6bb4eefc5cac1fa26cb9c5a4dd1.tar.xz systemd-c74e13a5c334d6bb4eefc5cac1fa26cb9c5a4dd1.zip |
creds: make --pretty behave in a slightly more expected manner
Diffstat (limited to 'src/creds')
-rw-r--r-- | src/creds/creds.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/creds/creds.c b/src/creds/creds.c index ef32efe1e2..670e719d21 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -506,20 +506,21 @@ static int verb_encrypt(int argc, char **argv, void *userdata) { if (base64_size < 0) return base64_size; - if (arg_pretty) { + /* Pretty print makes sense only if we're printing stuff to stdout + * and if a cred name is provided via --name= (since we can't use + * the output file name as the cred name here) */ + if (arg_pretty && !output_path && name) { _cleanup_free_ char *escaped = NULL, *indented = NULL, *j = NULL; - if (name) { - escaped = cescape(name); - if (!escaped) - return log_oom(); - } + escaped = cescape(name); + if (!escaped) + return log_oom(); indented = strreplace(base64_buf, "\n", " \\\n "); if (!indented) return log_oom(); - j = strjoin("SetCredentialEncrypted=", name, ": \\\n ", indented, "\n"); + j = strjoin("SetCredentialEncrypted=", escaped, ": \\\n ", indented, "\n"); if (!j) return log_oom(); |