]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Move sensitive value hiding to own function
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 12 Mar 2018 07:11:14 +0000 (09:11 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 23 Mar 2018 13:01:01 +0000 (13:01 +0000)
Simplifies next change

src/config/doveconf.c

index ba2ccea495d9c006af13bebbf09ee5970e484ad9..a283354784f48e8e55deb77f780a4d2c1094056d 100644 (file)
@@ -168,6 +168,22 @@ static bool value_need_quote(const char *value)
        return FALSE;
 }
 
+static bool
+hide_secrets_from_value(struct ostream *output, const char *key,
+                       const char *value)
+{
+       if (*value != '\0' &&
+           ((value-key > 8 && strncmp(value-9, "_password", 8) == 0) ||
+            (value-key > 7 && strncmp(value-8, "_api_key", 7) == 0) ||
+            strncmp(key, "ssl_key",7) == 0 ||
+            strncmp(key, "ssl_dh",6) == 0)) {
+               o_stream_nsend_str(output, "# hidden, use -P to show it");
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
 static int ATTR_NULL(4)
 config_dump_human_output(struct config_dump_human_context *ctx,
                         struct ostream *output, unsigned int indent,
@@ -306,13 +322,11 @@ config_dump_human_output(struct config_dump_human_context *ctx,
                i_assert(value != NULL);
                o_stream_nsend(output, key, value-key);
                o_stream_nsend_str(output, " = ");
-               if (hide_passwords && value[1] != '\0' &&
-                   ((value-key > 9 && strncmp(value-9, "_password", 9) == 0) ||
-                    (value-key > 8 && strncmp(value-8, "_api_key", 8) == 0) ||
-                    strncmp(key, "ssl_key",7) == 0 ||
-                    strncmp(key, "ssl_dh",6) == 0)) {
-                       o_stream_nsend_str(output, " # hidden, use -P to show it");
-               } else if (!value_need_quote(value+1))
+               if (hide_passwords &&
+                   hide_secrets_from_value(output, key, value+1))
+                       /* sent */
+                       ;
+               else if (!value_need_quote(value+1))
                        o_stream_nsend_str(output, value+1);
                else {
                        o_stream_nsend(output, "\"", 1);