Update for previous commit

Update functionality, man page, changelog, and add test.
This commit is contained in:
Roger A. Light
2025-08-07 23:35:12 +01:00
parent 5a79f23510
commit 6967e5b890
5 changed files with 50 additions and 6 deletions
+2
View File
@@ -231,6 +231,8 @@
## mosquitto_passwd
- Print messages in mosquitto_passwd when adding/updating passwords.
Closes #2544.
- When creating a new file with `-c`, setting the output filename to a dash `-`
will output the result to stdout.
## mosquitto_db_dump
- Add `--json` output mode do mosquitto_db_dump.
+9 -3
View File
@@ -511,7 +511,11 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error: -c argument given but password file, username, or password missing.\n");
return 1;
}else{
password_file_tmp = argv[idx];
if(!strcmp(argv[idx], "-")){
use_stdout = true;
}else{
password_file_tmp = argv[idx];
}
username = argv[idx+1];
password_cmd = argv[idx+2];
}
@@ -520,7 +524,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error: -c argument given but password file or username missing.\n");
return 1;
}else{
if (!strcmp(argv[idx], "-")){
if(!strcmp(argv[idx], "-")){
use_stdout = true;
}else{
password_file_tmp = argv[idx];
@@ -607,7 +611,9 @@ int main(int argc, char *argv[])
}
free(password_file);
}
printf("Adding password for user %s\n", username);
if(!use_stdout){
printf("Adding password for user %s\n", username);
}
rc = output_new_password(fptr, username, password_cmd, iterations);
fclose(fptr);
return rc;
+7 -2
View File
@@ -69,8 +69,13 @@
<varlistentry>
<term><option>-c</option></term>
<listitem>
<para>Create a new password file. If the file already
exists, it will be overwritten.</para>
<para>
Create a new password file. If the file already
exists, it will be overwritten. If the filename
is specified as a dash <option>-</option>
then the output will be to stdout. This only really
makes sense with <option>-b</option>.
</para>
</listitem>
</varlistentry>
<varlistentry>
+2 -1
View File
@@ -8,9 +8,10 @@ all :
check : test
test :
test :
./passwd-args.py
./passwd-changes.py
./passwd-stdout.py
ptest :
./test.py
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
# Test parsing of command line args and errors. Does not test arg functionality.
from mosq_test_helper import *
def do_test(args, rc_expected, response=None, input=None):
proc = subprocess.run([mosq_test.get_build_root()+"/apps/mosquitto_passwd/mosquitto_passwd"]
+ args,
capture_output=True, encoding='utf-8', timeout=2, input=input)
if response is not None:
if proc.stdout[0:len(response)] != response:
print(len(proc.stdout))
print(len(response))
print(proc.stdout[0:len(response)])
print(response)
raise ValueError(proc.stdout)
if proc.returncode != rc_expected:
print(proc.returncode)
raise ValueError(args)
resp = "Password: \nReenter password: \nstdout:$7$1000$"
do_test(["-c", "-", "stdout"], 0, response=resp, input="pw\npw\n")
resp = "stdout:$7$1000$"
do_test(["-b", "-c", "-", "stdout", "pw"], 0, response=resp)
exit(0)