Skip to content

Commit

Permalink
ctrl: Error if new passwords don't match.
Browse files Browse the repository at this point in the history
Produce an error when requesting a new password if both
attempts do not match.

Closes #2011. Thanks to Willem Eradus.
  • Loading branch information
ralight committed Jan 15, 2021
1 parent 26fbd0e commit 9c4b9a0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -10,6 +10,8 @@ Broker:
Apps:
- Allow command line arguments to override config file options in
mosquitto_ctrl. Closes #2010.
- mosquitto_ctrl: produce an error when requesting a new password if both
attempts do not match. Closes #2011.

2.0.5 - 2021-01-11
==================
Expand Down
3 changes: 1 addition & 2 deletions apps/mosquitto_ctrl/dynsec.c
Expand Up @@ -720,9 +720,8 @@ int dynsec_init(int argc, char *argv[])
snprintf(verify_prompt, sizeof(verify_prompt), "Reenter password for %s: ", admin_user);
rc = get_password(prompt, verify_prompt, false, password, sizeof(password));
if(rc){
fprintf(stderr, "Error getting password.\n");
mosquitto_lib_cleanup();
return 1;
return -1;
}
admin_password = password;
}
Expand Down
5 changes: 4 additions & 1 deletion apps/mosquitto_ctrl/dynsec_client.c
Expand Up @@ -65,6 +65,9 @@ int dynsec_client__create(int argc, char *argv[], cJSON *j_command)
rc = get_password(prompt, verify_prompt, true, password_buf, sizeof(password_buf));
if(rc == 0){
password = password_buf;
}else if(rc == 2){
fprintf(stderr, "Error: Passwords do not match.\n");
return -1;
}else{
password = NULL;
printf("\n");
Expand Down Expand Up @@ -163,7 +166,7 @@ int dynsec_client__set_password(int argc, char *argv[], cJSON *j_command)
snprintf(verify_prompt, sizeof(verify_prompt), "Reenter password for %s: ", username);
rc = get_password(prompt, verify_prompt, false, password_buf, sizeof(password_buf));
if(rc){
return MOSQ_ERR_INVAL;
return -1;
}
password = password_buf;
}else{
Expand Down
2 changes: 1 addition & 1 deletion apps/mosquitto_passwd/get_password.c
Expand Up @@ -135,7 +135,7 @@ int get_password(const char *prompt, const char *verify_prompt, bool quiet, char
if(!quiet){
fprintf(stderr, "Error: Passwords do not match.\n");
}
return 1;
return 2;
}
}

Expand Down

0 comments on commit 9c4b9a0

Please sign in to comment.