]> granicus.if.org Git - shadow/commitdiff
* src/lastlog.c: Use getrange to parse the range of users.
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 14 Jun 2008 21:06:53 +0000 (21:06 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 14 Jun 2008 21:06:53 +0000 (21:06 +0000)
* 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: ".

ChangeLog
src/lastlog.c

index fcde3dfbfc8f15d1250f529b664fc1cc39b919b7..a01eec8b40f2ce72b6ee40760b94f97330b6b7c8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-06-14  Nicolas François  <nicolas.francois@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@centraliens.net>
 
        * libmisc/getlong.c: Reset errno before calling strtol().
index 9e22402fb3986fdf1940c02d917d81bc5b915df5..97c42648e991043072d4979062116b256b39425b 100644 (file)
  * 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 @@ static void print (void)
        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 @@ int main (int argc, char **argv)
                                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 @@ int main (int argc, char **argv)
                                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);
                                        }
                                }