]> granicus.if.org Git - shadow/commitdiff
* src/chpasswd.c: Added crypt method: NONE.
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 23 Nov 2007 20:09:57 +0000 (20:09 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 23 Nov 2007 20:09:57 +0000 (20:09 +0000)
* src/chpasswd.c: Added --sha-rounds to the usage().
* libmisc/Makefile.am, libmisc/getlong.c, src/chgpasswd.c,
  src/chpasswd.c: New getlong function. Replace chpasswd's and
  chgpasswd's getnumber.

ChangeLog
libmisc/Makefile.am
libmisc/getlong.c [new file with mode: 0644]
src/chgpasswd.c
src/chpasswd.c

index 17dab236b0b5b5bc2d2f537ac01ec62236069dae..d8aa9248a9cb14c90c05ecab7e7cf9ec0a29a850 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-11-23  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * src/chpasswd.c: Added crypt method: NONE.
+       * src/chpasswd.c: Added --sha-rounds to the usage().
+       * libmisc/Makefile.am, libmisc/getlong.c, src/chgpasswd.c,
+       src/chpasswd.c: New getlong function. Replace chpasswd's and
+       chgpasswd's getnumber.
+
 2007-11-23  Nicolas François  <nicolas.francois@centraliens.net>
 
        * lib/groupio.c: Removed unused variable 'member'.
index dd36e755bb609b0ca24997210aa6899c33722f54..95ce28cdb52f201005c5d2dbe8f25b2e1c36919c 100644 (file)
@@ -23,6 +23,7 @@ libmisc_a_SOURCES = \
        fields.c \
        getdate.h \
        getdate.y \
+       getlong.c \
        hushed.c \
        isexpired.c \
        limits.c \
diff --git a/libmisc/getlong.c b/libmisc/getlong.c
new file mode 100644 (file)
index 0000000..076b93e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2007, Nicolas François
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Julianne F. Haugh nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NICOLAS FRANÇOIS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL NICOLAS FRANÇOIS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#ident "$Id:$"
+
+#include "prototypes.h"
+#include "defines.h"
+
+int getlong(const char *numstr, long int *result)
+{
+       long val;
+       char *endptr;
+
+       val = strtol (numstr, &endptr, 10);
+       if (*endptr || errno == ERANGE)
+               return 0;
+
+       *result = val;
+       return 1;
+}
+
index 4edab9f27bdc090f76c1e8c4f11def2d9d88bdd5..39dfe42459eba2719c83956b3d07785f4171355c 100644 (file)
@@ -56,7 +56,7 @@ static int md5flg = 0;
 static int sflg = 0;
 
 static char *crypt_method = NULL;
-static int sha_rounds = 5000;
+static long sha_rounds = 5000;
 
 #ifdef SHADOWGRP
 static int is_shadow_grp;
@@ -70,39 +70,27 @@ static void usage (void);
  */
 static void usage (void)
 {
-       fprintf (stderr, _("Usage: chgpasswd [options]\n"
+       fprintf (stderr, _("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         use MD5 encryption instead DES when the supplied\n"
+                          "  -m, --md5         use MD5 encryption instead of DES when the supplied\n"
                           "                    passwords are not encrypted\n"
+                          "%s"
                           "\n"),
+                        Prog,
 #ifndef ENCRYPTMETHOD_SELECT
-                        "DES MD5"
+                        "NONE DES MD5", ""
 #else
-                        "DES MD5 SHA256 SHA512"
+                        "NONE DES MD5 SHA256 SHA512",
+                        _("  -s, --sha-rounds  number of SHA rounds for the SHA* crypt algorithms\n")
 #endif
                         );
        exit (1);
 }
 
-static long getnumber (const char *numstr)
-{
-       long val;
-       char *errptr;
-
-       val = strtol (numstr, &errptr, 10);
-       if (*errptr || errno == ERANGE) {
-               fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
-                        numstr);
-               exit (1);
-       }
-
-       return val;
-}
-
 int main (int argc, char **argv)
 {
        char buf[BUFSIZ];
@@ -163,7 +151,12 @@ int main (int argc, char **argv)
                                break;
                        case 's':
                                sflg = 1;
-                               sha_rounds = getnumber(optarg);
+                               if (!getlong(optarg, &sha_rounds)) {
+                                       fprintf (stderr,
+                                                _("%s: invalid numeric argument '%s'\n"),
+                                                Prog, optarg);
+                                       usage ();
+                               }
                                break;
                        case 0:
                                /* long option */
@@ -192,14 +185,15 @@ int main (int argc, char **argv)
        if (cflg) {
                if (0 != strcmp (crypt_method, "DES") &&
                    0 != strcmp (crypt_method, "MD5") &&
+                   0 != strcmp (crypt_method, "NONE") &&
 #ifdef ENCRYPTMETHOD_SELECT
                    0 != strcmp (crypt_method, "SHA256") &&
                    0 != strcmp (crypt_method, "SHA512")
 #endif
                    ) {
                        fprintf (stderr,
-                        _("%s: unsupported crypt method: %s\n"),
-                        Prog, crypt_method);
+                                _("%s: unsupported crypt method: %s\n"),
+                                Prog, crypt_method);
                        usage ();
                }
        }
@@ -308,7 +302,9 @@ int main (int argc, char **argv)
                        continue;
                }
                newpwd = cp;
-               if (!eflg) {
+               if (!eflg &&
+                   (NULL == crypt_method ||
+                    0 != strcmp(crypt_method, "NONE"))) {
                        void *arg = NULL;
                        if (md5flg)
                                crypt_method = "MD5";
index 73e76759de266231c2e7bfc95ebfca8e312d09cf..afddb71d6a6691b67e6b7407a46f7938a829ddd2 100644 (file)
@@ -55,7 +55,7 @@ static int md5flg = 0;
 static int sflg = 0;
 
 static char *crypt_method = NULL;
-static int sha_rounds = 5000;
+static long sha_rounds = 5000;
 
 static int is_shadow_pwd;
 
@@ -67,39 +67,27 @@ static void usage (void);
  */
 static void usage (void)
 {
-       fprintf (stderr, _("Usage: chpasswd [options]\n"
+       fprintf (stderr, _("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         use MD5 encryption instead DES when the supplied\n"
+                          "  -m, --md5         use MD5 encryption instead of DES when the supplied\n"
                           "                    passwords are not encrypted\n"
+                          "%s"
                           "\n"),
+                        Prog,
 #ifndef ENCRYPTMETHOD_SELECT
-                        "DES MD5"
+                        "NONE DES MD5", ""
 #else
-                        "DES MD5 SHA256 SHA512"
+                        "NONE DES MD5 SHA256 SHA512",
+                        _("  -s, --sha-rounds  number of SHA rounds for the SHA* crypt algorithms\n")
 #endif
                         );
        exit (E_USAGE);
 }
 
-static long getnumber (const char *numstr)
-{
-       long val;
-       char *errptr;
-
-       val = strtol (numstr, &errptr, 10);
-       if (*errptr || errno == ERANGE) {
-               fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
-                        numstr);
-               exit (1);
-       }
-
-       return val;
-}
-
 int main (int argc, char **argv)
 {
        char buf[BUFSIZ];
@@ -159,7 +147,12 @@ int main (int argc, char **argv)
                                break;
                        case 's':
                                sflg = 1;
-                               sha_rounds = getnumber(optarg);
+                               if (!getlong(optarg, &sha_rounds)) {
+                                       fprintf (stderr,
+                                                _("%s: invalid numeric argument '%s'\n"),
+                                                Prog, optarg);
+                                       usage ();
+                               }
                                break;
                        case 0:
                                /* long option */
@@ -188,14 +181,15 @@ int main (int argc, char **argv)
        if (cflg) {
                if (0 != strcmp (crypt_method, "DES") &&
                    0 != strcmp (crypt_method, "MD5") &&
+                   0 != strcmp (crypt_method, "NONE") &&
 #ifdef ENCRYPTMETHOD_SELECT
                    0 != strcmp (crypt_method, "SHA256") &&
                    0 != strcmp (crypt_method, "SHA512")
 #endif
                    ) {
                        fprintf (stderr,
-                        _("%s: unsupported crypt method: %s\n"),
-                        Prog, crypt_method);
+                                _("%s: unsupported crypt method: %s\n"),
+                                Prog, crypt_method);
                        usage ();
                }
        }
@@ -306,7 +300,9 @@ int main (int argc, char **argv)
                        continue;
                }
                newpwd = cp;
-               if (!eflg) {
+               if (!eflg &&
+                   (NULL == crypt_method ||
+                    0 != strcmp(crypt_method, "NONE"))) {
                        void *arg = NULL;
                        if (md5flg)
                                crypt_method = "MD5";