]> granicus.if.org Git - shadow/commitdiff
* src/chgpasswd.c: Add annotations to indicate that usage() does
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 22 Jul 2011 23:52:08 +0000 (23:52 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 22 Jul 2011 23:52:08 +0000 (23:52 +0000)
not return.
* src/chgpasswd.c: Split usage in smaller parts. Those parts are
already translated for chpasswd. Usage is now closer to
chpasswd's.
* src/chgpasswd.c: Remove dead code. No need to set crypt_method
to NULL when it is already NULL. sflg is only set if crypt_method
is not NULL.

ChangeLog
src/chgpasswd.c

index 7ddd0d718310c6875d3dc17129342591e958f84c..a0a7234b8daf8df0746fa0dc60093b8392a80e46 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-07-23  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * src/chgpasswd.c: Add annotations to indicate that usage() does
+       not return.
+       * src/chgpasswd.c: Split usage in smaller parts. Those parts are
+       already translated for chpasswd. Usage is now closer to
+       chpasswd's.
+       * src/chgpasswd.c: Remove dead code. No need to set crypt_method
+       to NULL when it is already NULL. sflg is only set if crypt_method
+       is not NULL.
+
 2011-07-23  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/expiry.c: Remove dead code.
index 146f6219b66cf5a8a13d58d369436854c00f9148..73fdf3954792f4d15a8fceeb62b6afff0d93a204 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1990 - 1994, Julianne Frances Haugh
  * Copyright (c) 2006       , Tomasz Kłoczko
  * Copyright (c) 2006       , Jonas Meurer
- * Copyright (c) 2007 - 2009, Nicolas François
+ * Copyright (c) 2007 - 2011, Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -78,7 +78,7 @@ static bool gr_locked = false;
 
 /* local function prototypes */
 static void fail_exit (int code);
-static void usage (int status);
+static /*@noreturn@*/void usage (int status);
 static void process_flags (int argc, char **argv);
 static void check_flags (void);
 static void check_perms (void);
@@ -114,28 +114,34 @@ static void fail_exit (int code)
 /*
  * usage - display usage message and exit
  */
-static void usage (int status)
+static /*@noreturn@*/void usage (int status)
 {
-       (void) fprintf ((E_SUCCESS != status) ? stderr : stdout,
-                        _("Usage: %s [options]\n"
-                          "\n"
-                          "Options:\n"
-                          "  -c, --crypt-method            the crypt method (one of %s)\n"
-                          "  -e, --encrypted               supplied passwords are encrypted\n"
-                          "  -h, --help                    display this help message and exit\n"
-                          "  -m, --md5                     encrypt the clear text password using\n"
-                          "                                the MD5 algorithm\n"
-                          "%s"
-                          "\n"),
-                        Prog,
+       FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
+       (void) fprintf (usageout,
+                       _("Usage: %s [options]\n"
+                         "\n"
+                         "Options:\n"),
+                       Prog);
+       void) fprintf (usageout,
+                       _("  -c, --crypt-method <METHOD>   the crypt method (one of %s)\n"),
 #ifndef USE_SHA_CRYPT
-                        "NONE DES MD5", ""
-#else
-                        "NONE DES MD5 SHA256 SHA512",
-                        _("  -s, --sha-rounds              number of SHA rounds for the SHA*\n"
-                          "                                crypt algorithms\n")
-#endif
-                        );
+                       "NONE DES MD5"
+#else                          /* USE_SHA_CRYPT */
+                       "NONE DES MD5 SHA256 SHA512"
+#endif                         /* USE_SHA_CRYPT */
+                      );
+       (void) fputs (_("  -e, --encrypted               supplied passwords are encrypted\n"), usageout);
+       (void) fputs (_("  -h, --help                    display this help message and exit\n"), usageout);
+       (void) fputs (_("  -m, --md5                     encrypt the clear text password using\n"
+                       "                                the MD5 algorithm\n"),
+                     usageout);
+#ifdef USE_SHA_CRYPT
+       (void) fputs (_("  -s, --sha-rounds              number of SHA rounds for the SHA*\n"
+                       "                                crypt algorithms\n"),
+                     usageout);
+#endif                         /* USE_SHA_CRYPT */
+       (void) fputs ("\n", usageout);
+
        exit (status);
 }
 
@@ -176,7 +182,7 @@ static void process_flags (int argc, char **argv)
                        break;
                case 'h':
                        usage (E_SUCCESS);
-                       break;
+                       /*@notreached@*/break;
                case 'm':
                        md5flg = true;
                        break;
@@ -193,7 +199,7 @@ static void process_flags (int argc, char **argv)
 #endif
                default:
                        usage (E_USAGE);
-                       break;
+                       /*@notreached@*/break;
                }
        }
 
@@ -442,21 +448,18 @@ int main (int argc, char **argv)
                        continue;
                }
                newpwd = cp;
-               if (!eflg &&
-                   (NULL == crypt_method ||
-                    0 != strcmp(crypt_method, "NONE"))) {
+               if (   (!eflg)
+                   && (   (NULL == crypt_method)
+                       || (0 != strcmp(crypt_method, "NONE")))) {
                        void *arg = NULL;
                        if (md5flg) {
                                crypt_method = "MD5";
-                       } else if (crypt_method != NULL) {
+                       }
 #ifdef USE_SHA_CRYPT
-                               if (sflg) {
-                                       arg = &sha_rounds;
-                               }
-#endif
-                       } else {
-                               crypt_method = NULL;
+                       if (sflg) {
+                               arg = &sha_rounds;
                        }
+#endif
                        cp = pw_encrypt (newpwd,
                                         crypt_make_salt(crypt_method, arg));
                }