]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
creds: make --pretty behave in a slightly more expected manner
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 25 Apr 2023 10:58:15 +0000 (12:58 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 25 Apr 2023 16:34:49 +0000 (18:34 +0200)
man/systemd-creds.xml
src/creds/creds.c

index b16ee09ceec6b227b2dec9bc47988b18c56b6aa8..fbe62262af08555b950c27570ec7c8c46eed47ed 100644 (file)
 
         <listitem><para>When specified with <command>encrypt</command> controls whether to show the encrypted
         credential as <varname>SetCredentialEncrypted=</varname> setting that may be pasted directly into a
-        unit file.</para></listitem>
+        unit file. Has effect only when used together with <option>--name=</option> and <literal>-</literal>
+        as the output file.</para></listitem>
       </varlistentry>
 
       <varlistentry>
index ef32efe1e2e8d97212c4808d3b4e55b4e3011978..670e719d21f36c19a6cee6fd00ffe158a26c89cf 100644 (file)
@@ -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();