* src/lastlog.c: Use a bool when possible instead of int integers.

* src/lastlog.c: Avoid implicit conversion of pointers / integers
	/ chars to booleans.
	* src/lastlog.c: Add brackets and parenthesis.
	* src/lastlog.c: Ignore return value of setlocale(),
	bindtextdomain(), and textdomain().
This commit is contained in:
nekral-guest 2008-06-09 19:15:27 +00:00
parent 8b98a2e829
commit 5038f6687b
2 changed files with 37 additions and 19 deletions

View File

@ -1,3 +1,12 @@
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* src/lastlog.c: Use a bool when possible instead of int integers.
* src/lastlog.c: Avoid implicit conversion of pointers / integers
/ chars to booleans.
* src/lastlog.c: Add brackets and parenthesis.
* src/lastlog.c: Ignore return value of setlocale(),
bindtextdomain(), and textdomain().
2008-06-09 Nicolas François <nicolas.francois@centraliens.net> 2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* src/userdel.c: Use a bool for the is_shadow_pwd, is_shadow_grp, * src/userdel.c: Use a bool for the is_shadow_pwd, is_shadow_grp,

View File

@ -43,12 +43,14 @@
#include <time.h> #include <time.h>
#include "defines.h" #include "defines.h"
#include "prototypes.h" #include "prototypes.h"
/* /*
* Needed for MkLinux DR1/2/2.1 - J. * Needed for MkLinux DR1/2/2.1 - J.
*/ */
#ifndef LASTLOG_FILE #ifndef LASTLOG_FILE
#define LASTLOG_FILE "/var/log/lastlog" #define LASTLOG_FILE "/var/log/lastlog"
#endif #endif
/* /*
* Global variables * Global variables
*/ */
@ -61,9 +63,9 @@ static int inverse_days; /* number of days to consider for print command */
static time_t inverse_seconds; /* that number of days in seconds */ static time_t inverse_seconds; /* that number of days in seconds */
static int uflg = 0; /* print only an user of range of users */ static bool uflg = false; /* print only an user of range of users */
static int tflg = 0; /* print is restricted to most recent days */ static bool tflg = false; /* print is restricted to most recent days */
static int bflg = 0; /* print excludes most recent days */ static bool bflg = false; /* print excludes most recent days */
static struct lastlog lastlog; /* scratch structure to play with ... */ static struct lastlog lastlog; /* scratch structure to play with ... */
static struct passwd *pwent; static struct passwd *pwent;
@ -84,7 +86,7 @@ static void usage (void)
static void print_one (const struct passwd *pw) static void print_one (const struct passwd *pw)
{ {
static int once; static bool once = false;
char *cp; char *cp;
struct tm *tm; struct tm *tm;
time_t ll_time; time_t ll_time;
@ -93,8 +95,9 @@ static void print_one (const struct passwd *pw)
char ptime[80]; char ptime[80];
#endif #endif
if (!pw) if (NULL == pw) {
return; return;
}
if (!once) { if (!once) {
#ifdef HAVE_LL_HOST #ifdef HAVE_LL_HOST
@ -102,7 +105,7 @@ static void print_one (const struct passwd *pw)
#else #else
puts (_("Username Port Latest")); puts (_("Username Port Latest"));
#endif #endif
once++; once = true;
} }
ll_time = lastlog.ll_time; ll_time = lastlog.ll_time;
tm = localtime (&ll_time); tm = localtime (&ll_time);
@ -114,8 +117,9 @@ static void print_one (const struct passwd *pw)
cp[24] = '\0'; cp[24] = '\0';
#endif #endif
if (lastlog.ll_time == (time_t) 0) if (lastlog.ll_time == (time_t) 0) {
cp = _("**Never logged in**\0"); cp = _("**Never logged in**\0");
}
#ifdef HAVE_LL_HOST #ifdef HAVE_LL_HOST
printf ("%-16s %-8.8s %-16.16s %s\n", pw->pw_name, printf ("%-16s %-8.8s %-16.16s %s\n", pw->pw_name,
@ -133,22 +137,26 @@ static void print (void)
setpwent (); setpwent ();
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) || && ( (umin != -1 && user < (uid_t)umin)
(umax != -1 && user > (uid_t)umax))) || (umax != -1 && user > (uid_t)umax))) {
continue; continue;
}
offset = user * sizeof lastlog; offset = user * sizeof lastlog;
fseeko (lastlogfile, offset, SEEK_SET); fseeko (lastlogfile, offset, SEEK_SET);
if (fread ((char *) &lastlog, sizeof lastlog, 1, if (fread ((char *) &lastlog, sizeof lastlog, 1,
lastlogfile) != 1) lastlogfile) != 1) {
continue; continue;
}
if (tflg && NOW - lastlog.ll_time > seconds) if (tflg && ((NOW - lastlog.ll_time) > seconds)) {
continue; continue;
}
if (bflg && NOW - lastlog.ll_time < inverse_seconds) if (bflg && ((NOW - lastlog.ll_time) < inverse_seconds)) {
continue; continue;
}
print_one (pwent); print_one (pwent);
} }
@ -157,9 +165,9 @@ static void print (void)
int main (int argc, char **argv) int main (int argc, char **argv)
{ {
setlocale (LC_ALL, ""); (void) setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR); (void) bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE); (void) textdomain (PACKAGE);
{ {
int c; int c;
@ -181,12 +189,12 @@ int main (int argc, char **argv)
case 't': case 't':
days = atoi (optarg); days = atoi (optarg);
seconds = days * DAY; seconds = days * DAY;
tflg++; tflg = true;
break; break;
case 'b': case 'b':
inverse_days = atoi (optarg); inverse_days = atoi (optarg);
inverse_seconds = inverse_days * DAY; inverse_seconds = inverse_days * DAY;
bflg++; bflg = true;
break; break;
case 'u': case 'u':
/* /*
@ -196,7 +204,7 @@ int main (int argc, char **argv)
* - a numerical login ID * - a numerical login ID
* - a range (-x, x-, x-y) * - a range (-x, x-, x-y)
*/ */
uflg++; uflg = true;
pwent = xgetpwnam (optarg); pwent = xgetpwnam (optarg);
if (NULL != pwent) { if (NULL != pwent) {
umin = pwent->pw_uid; umin = pwent->pw_uid;
@ -253,3 +261,4 @@ int main (int argc, char **argv)
fclose (lastlogfile); fclose (lastlogfile);
exit (0); exit (0);
} }