[Pkg-shadow-commits] r1447 - in upstream/trunk: . libmisc src

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Fri Nov 23 20:09:58 UTC 2007


Author: nekral-guest
Date: 2007-11-23 20:09:57 +0000 (Fri, 23 Nov 2007)
New Revision: 1447

Added:
   upstream/trunk/libmisc/getlong.c
Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/libmisc/Makefile.am
   upstream/trunk/src/chgpasswd.c
   upstream/trunk/src/chpasswd.c
Log:
* 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.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2007-11-23 20:00:03 UTC (rev 1446)
+++ upstream/trunk/ChangeLog	2007-11-23 20:09:57 UTC (rev 1447)
@@ -1,5 +1,13 @@
 2007-11-23  Nicolas François  <nicolas.francois at 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 at centraliens.net>
+
 	* lib/groupio.c: Removed unused variable 'member'.
 
 2007-11-23  Nicolas François  <nicolas.francois at centraliens.net>

Modified: upstream/trunk/libmisc/Makefile.am
===================================================================
--- upstream/trunk/libmisc/Makefile.am	2007-11-23 20:00:03 UTC (rev 1446)
+++ upstream/trunk/libmisc/Makefile.am	2007-11-23 20:09:57 UTC (rev 1447)
@@ -23,6 +23,7 @@
 	fields.c \
 	getdate.h \
 	getdate.y \
+	getlong.c \
 	hushed.c \
 	isexpired.c \
 	limits.c \

Added: upstream/trunk/libmisc/getlong.c
===================================================================
--- upstream/trunk/libmisc/getlong.c	                        (rev 0)
+++ upstream/trunk/libmisc/getlong.c	2007-11-23 20:09:57 UTC (rev 1447)
@@ -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;
+}
+


Property changes on: upstream/trunk/libmisc/getlong.c
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: upstream/trunk/src/chgpasswd.c
===================================================================
--- upstream/trunk/src/chgpasswd.c	2007-11-23 20:00:03 UTC (rev 1446)
+++ upstream/trunk/src/chgpasswd.c	2007-11-23 20:09:57 UTC (rev 1447)
@@ -56,7 +56,7 @@
 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)
 {
-	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 @@
 				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 @@
 	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 @@
 			continue;
 		}
 		newpwd = cp;
-		if (!eflg) {
+		if (!eflg &&
+		    (NULL == crypt_method ||
+		     0 != strcmp(crypt_method, "NONE"))) {
 			void *arg = NULL;
 			if (md5flg)
 				crypt_method = "MD5";

Modified: upstream/trunk/src/chpasswd.c
===================================================================
--- upstream/trunk/src/chpasswd.c	2007-11-23 20:00:03 UTC (rev 1446)
+++ upstream/trunk/src/chpasswd.c	2007-11-23 20:09:57 UTC (rev 1447)
@@ -55,7 +55,7 @@
 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)
 {
-	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 @@
 				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 @@
 	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 @@
 			continue;
 		}
 		newpwd = cp;
-		if (!eflg) {
+		if (!eflg &&
+		    (NULL == crypt_method ||
+		     0 != strcmp(crypt_method, "NONE"))) {
 			void *arg = NULL;
 			if (md5flg)
 				crypt_method = "MD5";




More information about the Pkg-shadow-commits mailing list