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

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Sat Jun 14 21:06:54 UTC 2008


Author: nekral-guest
Date: 2008-06-14 21:06:53 +0000 (Sat, 14 Jun 2008)
New Revision: 2179

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/lastlog.c
Log:
	* src/lastlog.c: Use getrange to parse the range of users.
	* src/lastlog.c: umin and umax do not need to be signed long. Use
	an unsigned long which might be needed to parse a GID or UID. Add
	the has_umin and has_umax to replace the -1 values.
	* src/lastlog.c: Cast dates to time_t.
	* src/lastlog.c: Prefix lastlog errors with "lastlog: ".


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-06-14 21:02:52 UTC (rev 2178)
+++ upstream/trunk/ChangeLog	2008-06-14 21:06:53 UTC (rev 2179)
@@ -1,5 +1,14 @@
 2008-06-14  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/lastlog.c: Use getrange to parse the range of users.
+	* src/lastlog.c: umin and umax do not need to be signed long. Use
+	an unsigned long which might be needed to parse a GID or UID. Add
+	the has_umin and has_umax to replace the -1 values.
+	* src/lastlog.c: Cast dates to time_t.
+	* src/lastlog.c: Prefix lastlog errors with "lastlog: ".
+
+2008-06-14  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* libmisc/getlong.c: Reset errno before calling strtol().
 	Otherwise, errno could be already set to ERANGE.
 

Modified: upstream/trunk/src/lastlog.c
===================================================================
--- upstream/trunk/src/lastlog.c	2008-06-14 21:02:52 UTC (rev 2178)
+++ upstream/trunk/src/lastlog.c	2008-06-14 21:06:53 UTC (rev 2179)
@@ -55,8 +55,10 @@
  * Global variables
  */
 static FILE *lastlogfile;	/* lastlog file stream */
-static long umin;		/* if uflg, only display users with uid >= umin */
-static long umax;		/* if uflg, only display users with uid <= umax */
+static unsigned long umin;	/* if uflg, only display users with uid >= umin */
+static bool has_umin = false;
+static unsigned long umax;	/* if uflg, only display users with uid <= umax */
+static bool has_umax = false;
 static int days;		/* number of days to consider for print command */
 static time_t seconds;		/* that number of days in seconds */
 static int inverse_days;	/* number of days to consider for print command */
@@ -138,8 +140,8 @@
 	while ( (pwent = getpwent ()) != NULL ) {
 		user = pwent->pw_uid;
 		if (   uflg
-		    && (   (umin != -1 && user < (uid_t)umin)
-		        || (umax != -1 && user > (uid_t)umax))) {
+		    && (   (has_umin && user < (uid_t)umin)
+		        || (has_umax && user > (uid_t)umax))) {
 			continue;
 		}
 		offset = user * sizeof lastlog;
@@ -187,13 +189,13 @@
 				usage ();
 				break;
 			case 't':
-				days = atoi (optarg);
-				seconds = days * DAY;
+				days = atoi (optarg); /* FIXME */
+				seconds = (time_t) days * DAY;
 				tflg = true;
 				break;
 			case 'b':
-				inverse_days = atoi (optarg);
-				inverse_seconds = inverse_days * DAY;
+				inverse_days = atoi (optarg); /* FIXME */
+				inverse_seconds = (time_t) inverse_days * DAY;
 				bflg = true;
 				break;
 			case 'u':
@@ -207,34 +209,17 @@
 				uflg = true;
 				pwent = xgetpwnam (optarg);
 				if (NULL != pwent) {
-					umin = pwent->pw_uid;
+					umin = (unsigned long) pwent->pw_uid;
+					has_umin = true;
 					umax = umin;
+					has_umax = true;
 				} else {
-					char *endptr = NULL;
-					long int user;
-					user = strtol(optarg, &endptr, 10);
-					if (*optarg != '\0' && *endptr == '\0') {
-						if (user < 0) {
-							/* -<userid> */
-							umin = -1;
-							umax = -user;
-						} else {
-							/* <userid> */
-							umin = user;
-							umax = user;
-						}
-					} else if (endptr[0] == '-' && endptr[1] == '\0') {
-						/* <userid>- */
-						umin = user;
-						umax = -1;
-					} else if (*endptr == '-') {
-						/* <userid>-<userid> */
-						umin = user;
-						umax = atol(endptr+1);
-					} else {
+					if (getrange (optarg,
+					              &umin, &has_umin,
+					              &umax, &has_umax) == 0) {
 						fprintf (stderr,
-							 _("Unknown user or range: %s\n"),
-							 optarg);
+						         _("lastlog: Unknown user or range: %s\n"),
+						         optarg);
 						exit (1);
 					}
 				}




More information about the Pkg-shadow-commits mailing list