simplified hiding secrets from cmdline (fixes #300)
This commit is contained in:
@@ -109,11 +109,13 @@ static const char* g_keypass = nullptr; //!< client key file password for TLS
|
|||||||
|
|
||||||
bool parseTopic(const string& topic, vector<string>* strs, vector<string>* fields);
|
bool parseTopic(const string& topic, vector<string>* strs, vector<string>* fields);
|
||||||
|
|
||||||
static void replaceSecret(char *arg) {
|
static char* replaceSecret(char *arg) {
|
||||||
|
char* ret = strdup(arg);
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
while (*arg) {
|
while (*arg && cnt++<256) {
|
||||||
*arg++ = (cnt++<4 ? '*' : 0);
|
*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");
|
argp_error(state, "invalid mqttpass");
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
g_password = strdup(arg);
|
g_password = replaceSecret(arg);
|
||||||
replaceSecret(arg);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_TOPI: // --mqtttopic=ebusd
|
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");
|
argp_error(state, "invalid mqttkeypass");
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
g_keypass = strdup(arg);
|
g_keypass = replaceSecret(arg);
|
||||||
replaceSecret(arg);
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user