Skip to content

Commit

Permalink
Improve error messages from kadmin change_password
Browse files Browse the repository at this point in the history
The checks for missing option arguments were dead code, because the
loop condition requires at least two remaining arguments.  Instead
check for at least one argument with a leading "-", and check for too
many or too few arguments after the loop.  Add an initial message for
unrecognized options.

[ghudson@mit.edu: adjusted logic to improve mesages in more cases]
  • Loading branch information
frozencemetery authored and greghudson committed May 10, 2019
1 parent 2103566 commit 13ba540
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/kadmin/cli/kadmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,11 @@ kadmin_cpw(int argc, char *argv[])
char **db_args = NULL;
int db_args_size = 0;

if (argc < 2) {
if (argc < 1) {
cpw_usage(NULL);
return;
}
for (argv++, argc--; argc > 1; argc--, argv++) {
for (argv++, argc--; argc > 0 && **argv == '-'; argc--, argv++) {
if (!strcmp("-x", *argv)) {
argc--;
if (argc < 1) {
Expand Down Expand Up @@ -841,12 +841,16 @@ kadmin_cpw(int argc, char *argv[])
goto cleanup;
}
} else {
com_err("change_password", 0, _("unrecognized option %s"), *argv);
cpw_usage(NULL);
goto cleanup;
}
}
if (*argv == NULL) {
com_err("change_password", 0, _("missing principal name"));
if (argc != 1) {
if (argc < 1)
com_err("change_password", 0, _("missing principal name"));
else
com_err("change_password", 0, _("too many arguments"));
cpw_usage(NULL);
goto cleanup;
}
Expand Down

0 comments on commit 13ba540

Please sign in to comment.