From 4cfdb4d97ce2874a2d2d2391dc721c2c468ff345 Mon Sep 17 00:00:00 2001 From: john30 Date: Thu, 24 Oct 2019 09:01:05 +0200 Subject: [PATCH] hide secrets from cmdline --- src/ebusd/mqtthandler.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 34df71ab..29b754e2 100644 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -109,6 +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) { + int cnt = 0; + while (*arg) { + *arg++ = (cnt++<4 ? '*' : 0); + } +} + /** * The MQTT argument parsing function. * @param key the key from @a g_mqtt_argp_options. @@ -156,7 +163,8 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) { argp_error(state, "invalid mqttpass"); return EINVAL; } - g_password = arg; + g_password = strdup(arg); + replaceSecret(arg); break; case O_TOPI: // --mqtttopic=ebusd @@ -237,7 +245,8 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) { argp_error(state, "invalid mqttkeypass"); return EINVAL; } - g_keypass = arg; + g_keypass = strdup(arg); + replaceSecret(arg); break; #endif