From f9123277a5b4e27d5fea3dbae0889dcb527115fc Mon Sep 17 00:00:00 2001 From: Robbie Harwood Date: Mon, 6 May 2019 13:13:16 -0400 Subject: [PATCH] Improve error messages from kadmin change_password 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] (cherry picked from commit 13ba54002d362ebb09be464b4e7ec75050d1348f) --- src/kadmin/cli/kadmin.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/kadmin/cli/kadmin.c b/src/kadmin/cli/kadmin.c index cc74921bf..fe4cb493c 100644 --- a/src/kadmin/cli/kadmin.c +++ b/src/kadmin/cli/kadmin.c @@ -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) { @@ -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; }