krb5 commit: Improve error messages from kadmin change_password

Greg Hudson <[email protected]>
Newsgroups gmane.comp.encryption.kerberos.cvs
Message-ID <[email protected]>
https://github.com/krb5/krb5/commit/13ba54002d362ebb09be464b4e7ec75050d1348f
commit 13ba54002d362ebb09be464b4e7ec75050d1348f
Author: Robbie Harwood <[email protected]>
Date:   Mon May 6 13:13:16 2019 -0400

    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.
    
    [[email protected]: adjusted logic to improve mesages in more cases]

 src/kadmin/cli/kadmin.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/kadmin/cli/kadmin.c b/src/kadmin/cli/kadmin.c
index cc74921..fe4cb49 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;
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.