Add batch mode to mosquitto_passwd.

pull/211/merge
Roger A. Light 11 years ago
parent 9a9dba6cd5
commit bd2aa2f426

@ -33,6 +33,8 @@ Broker:
v3.1.1 client connects with a zero length client id.
- Anonymous clients are no longer accidently disconnected from the broker
after a SIGHUP.
- mosquitto_passwd now supports -b (batch mode) to allow the password to be
provided at the command line.
Clients:
- Both clients can now load default configuration options from a file.

@ -24,6 +24,13 @@
<arg choice='plain'><replaceable>passwordfile</replaceable></arg>
<arg choice='plain'><replaceable>username</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>mosquitto_passwd</command>
<arg choice='plain'><option>-b</option></arg>
<arg choice='plain'><replaceable>passwordfile</replaceable></arg>
<arg choice='plain'><replaceable>username</replaceable></arg>
<arg choice='plain'><replaceable>password</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>mosquitto_passwd</command>
<arg choice='plain'><option>-U</option></arg>
@ -43,6 +50,16 @@
<refsect1>
<title>Options</title>
<variablelist>
<varlistentry>
<term><option>-b</option></term>
<listitem>
<para>Run in batch mode. This allows the password to be
provided at the command line which can be convenient
but should be used with care because the password will
be visible on the command line and in command
history.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-c</option></term>
<listitem>
@ -82,6 +99,12 @@
<para>The username to add/update/delete.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>password</option></term>
<listitem>
<para>The password to use when in batch mode.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

@ -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];
@ -419,16 +435,21 @@ int main(int argc, char *argv[])
}else if(do_update_file){
rc = update_file(fptr, ftmp);
}else{
rc = get_password(password, 1024);
if(rc){
fclose(fptr);
fclose(ftmp);
unlink(backup_file);
free(backup_file);
return rc;
if(batch_mode){
/* Update password for individual user */
rc = update_pwuser(fptr, ftmp, username, password_cmd);
}else{
rc = get_password(password, 1024);
if(rc){
fclose(fptr);
fclose(ftmp);
unlink(backup_file);
free(backup_file);
return rc;
}
/* Update password for individual user */
rc = update_pwuser(fptr, ftmp, username, password);
}
/* Update password for individual user */
rc = update_pwuser(fptr, ftmp, username, password);
}
if(rc){
fclose(fptr);

Loading…
Cancel
Save