Skip to content

Commit

Permalink
config: Move sensitive value hiding to own function
Browse files Browse the repository at this point in the history
Simplifies next change
  • Loading branch information
cmouse committed Aug 21, 2018
1 parent b27489c commit 0225967
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/config/doveconf.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0225967

Please sign in to comment.