From ae91be0874852259f47904da309d3a95359334a9 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 27 Oct 2019 08:17:22 +0100 Subject: [PATCH] simplified hiding secrets from cmdline (fixes #300) --- src/ebusd/mqtthandler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 29b754e2..3f44c24f 100644 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -109,11 +109,13 @@ static const char* g_keypass = nullptr; //!< client key file password for TLS bool parseTopic(const string& topic, vector* strs, vector* fields); -static void replaceSecret(char *arg) { +static char* replaceSecret(char *arg) { + char* ret = strdup(arg); int cnt = 0; - while (*arg) { - *arg++ = (cnt++<4 ? '*' : 0); + while (*arg && cnt++<256) { + *arg++ = ' '; } + return ret; } /** @@ -163,8 +165,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) { argp_error(state, "invalid mqttpass"); return EINVAL; } - g_password = strdup(arg); - replaceSecret(arg); + g_password = replaceSecret(arg); break; case O_TOPI: // --mqtttopic=ebusd @@ -245,8 +246,7 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) { argp_error(state, "invalid mqttkeypass"); return EINVAL; } - g_keypass = strdup(arg); - replaceSecret(arg); + g_keypass = replaceSecret(arg); break; #endif