|
|
|
@ -73,7 +73,9 @@ void print_usage(void)
|
|
|
|
|
{
|
|
|
|
|
printf("mosquitto_passwd is a tool for managing password files for mosquitto.\n\n");
|
|
|
|
|
printf("Usage: mosquitto_passwd [-c | -D] passwordfile username\n");
|
|
|
|
|
printf(" mosquitto_passwd -b passwordfile username password\n");
|
|
|
|
|
printf(" mosquitto_passwd -U passwordfile\n");
|
|
|
|
|
printf(" -b : run in batch mode to allow passing passwords on the command line.\n");
|
|
|
|
|
printf(" -c : create a new password file. This will overwrite existing files.\n");
|
|
|
|
|
printf(" -D : delete the username rather than adding/updating its password.\n");
|
|
|
|
|
printf(" -U : update a plain text password file to use hashed passwords.\n");
|
|
|
|
@ -346,6 +348,8 @@ int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
char *password_file = NULL;
|
|
|
|
|
char *username = NULL;
|
|
|
|
|
char *password_cmd = NULL;
|
|
|
|
|
bool batch_mode = false;
|
|
|
|
|
bool create_new = false;
|
|
|
|
|
bool delete_user = false;
|
|
|
|
|
FILE *fptr, *ftmp;
|
|
|
|
@ -359,11 +363,23 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
OpenSSL_add_all_digests();
|
|
|
|
|
|
|
|
|
|
if(argc == 4){
|
|
|
|
|
if(argc == 5){
|
|
|
|
|
if(!strcmp(argv[1], "-b")){
|
|
|
|
|
batch_mode = true;
|
|
|
|
|
}else{
|
|
|
|
|
fprintf(stderr, "Error: Unknown option '%s'\n", argv[1]);
|
|
|
|
|
}
|
|
|
|
|
password_file = argv[2];
|
|
|
|
|
username = argv[3];
|
|
|
|
|
password_cmd = argv[4];
|
|
|
|
|
}else if(argc == 4){
|
|
|
|
|
if(!strcmp(argv[1], "-c")){
|
|
|
|
|
create_new = true;
|
|
|
|
|
}else if(!strcmp(argv[1], "-D")){
|
|
|
|
|
delete_user = true;
|
|
|
|
|
}else{
|
|
|
|
|
fprintf(stderr, "Error: Unknown option '%s'\n", argv[1]);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
password_file = argv[2];
|
|
|
|
|
username = argv[3];
|
|
|
|
@ -418,6 +434,10 @@ int main(int argc, char *argv[])
|
|
|
|
|
rc = delete_pwuser(fptr, ftmp, username);
|
|
|
|
|
}else if(do_update_file){
|
|
|
|
|
rc = update_file(fptr, ftmp);
|
|
|
|
|
}else{
|
|
|
|
|
if(batch_mode){
|
|
|
|
|
/* Update password for individual user */
|
|
|
|
|
rc = update_pwuser(fptr, ftmp, username, password_cmd);
|
|
|
|
|
}else{
|
|
|
|
|
rc = get_password(password, 1024);
|
|
|
|
|
if(rc){
|
|
|
|
@ -430,6 +450,7 @@ int main(int argc, char *argv[])
|
|
|
|
|
/* Update password for individual user */
|
|
|
|
|
rc = update_pwuser(fptr, ftmp, username, password);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(rc){
|
|
|
|
|
fclose(fptr);
|
|
|
|
|
fclose(ftmp);
|
|
|
|
|