* 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: ".
This commit is contained in:
nekral-guest 2008-06-14 21:06:53 +00:00
parent eed5fc7179
commit dbbae8dcd3
2 changed files with 27 additions and 33 deletions

View File

@ -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> 2008-06-14 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/getlong.c: Reset errno before calling strtol(). * libmisc/getlong.c: Reset errno before calling strtol().

View File

@ -55,8 +55,10 @@
* Global variables * Global variables
*/ */
static FILE *lastlogfile; /* lastlog file stream */ static FILE *lastlogfile; /* lastlog file stream */
static long umin; /* if uflg, only display users with uid >= umin */ static unsigned long umin; /* if uflg, only display users with uid >= umin */
static long umax; /* if uflg, only display users with uid <= umax */ 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 int days; /* number of days to consider for print command */
static time_t seconds; /* that number of days in seconds */ static time_t seconds; /* that number of days in seconds */
static int inverse_days; /* number of days to consider for print command */ static int inverse_days; /* number of days to consider for print command */
@ -138,8 +140,8 @@ static void print (void)
while ( (pwent = getpwent ()) != NULL ) { while ( (pwent = getpwent ()) != NULL ) {
user = pwent->pw_uid; user = pwent->pw_uid;
if ( uflg if ( uflg
&& ( (umin != -1 && user < (uid_t)umin) && ( (has_umin && user < (uid_t)umin)
|| (umax != -1 && user > (uid_t)umax))) { || (has_umax && user > (uid_t)umax))) {
continue; continue;
} }
offset = user * sizeof lastlog; offset = user * sizeof lastlog;
@ -187,13 +189,13 @@ int main (int argc, char **argv)
usage (); usage ();
break; break;
case 't': case 't':
days = atoi (optarg); days = atoi (optarg); /* FIXME */
seconds = days * DAY; seconds = (time_t) days * DAY;
tflg = true; tflg = true;
break; break;
case 'b': case 'b':
inverse_days = atoi (optarg); inverse_days = atoi (optarg); /* FIXME */
inverse_seconds = inverse_days * DAY; inverse_seconds = (time_t) inverse_days * DAY;
bflg = true; bflg = true;
break; break;
case 'u': case 'u':
@ -207,33 +209,16 @@ int main (int argc, char **argv)
uflg = true; uflg = true;
pwent = xgetpwnam (optarg); pwent = xgetpwnam (optarg);
if (NULL != pwent) { if (NULL != pwent) {
umin = pwent->pw_uid; umin = (unsigned long) pwent->pw_uid;
has_umin = true;
umax = umin; umax = umin;
has_umax = true;
} else { } else {
char *endptr = NULL; if (getrange (optarg,
long int user; &umin, &has_umin,
user = strtol(optarg, &endptr, 10); &umax, &has_umax) == 0) {
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 {
fprintf (stderr, fprintf (stderr,
_("Unknown user or range: %s\n"), _("lastlog: Unknown user or range: %s\n"),
optarg); optarg);
exit (1); exit (1);
} }