From 2296db3db68a57ce05364d8055e1a452dea85603 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Fri, 13 Jun 2008 18:31:13 +0000 Subject: [PATCH] * libmisc/failure.c: Avoid assignments in comparisons. * libmisc/failure.c: read() returns a ssize_t. * libmisc/failure.c: Add brackets and parenthesis. * libmisc/failure.c: Ignore return value of time() when use with a non NULL argument. --- ChangeLog | 8 ++++++++ libmisc/failure.c | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index e7129ef8..b6257186 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-06-13 Nicolas François + + * libmisc/failure.c: Avoid assignments in comparisons. + * libmisc/failure.c: read() returns a ssize_t. + * libmisc/failure.c: Add brackets and parenthesis. + * libmisc/failure.c: Ignore return value of time() when use with a + non NULL argument. + 2008-06-13 Nicolas François * libmisc/chowntty.c: Avoid assignments in comparisons. diff --git a/libmisc/failure.c b/libmisc/failure.c index 16b89f19..beeb94b0 100644 --- a/libmisc/failure.c +++ b/libmisc/failure.c @@ -55,8 +55,10 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) * Don't do anything if failure logging isn't set up. */ /* TODO: check if the file exists */ - if ((fd = open (FAILLOG_FILE, O_RDWR)) < 0) + fd = open (FAILLOG_FILE, O_RDWR); + if (fd < 0) { return; + } /* * The file is indexed by UID value meaning that shared UID's @@ -65,8 +67,10 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) */ lseek (fd, (off_t) (sizeof *fl) * uid, SEEK_SET); - if (read (fd, (char *) fl, sizeof *fl) != sizeof *fl) + /* TODO: check failures */ + if (read (fd, (char *) fl, sizeof *fl) != (ssize_t) sizeof *fl) { memzero (fl, sizeof *fl); + } /* * Update the record. We increment the failure count to log the @@ -75,11 +79,12 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) * updated as well. */ - if (fl->fail_cnt + 1 > 0) + if (fl->fail_cnt + 1 > 0) { fl->fail_cnt++; + } strncpy (fl->fail_line, tty, sizeof fl->fail_line); - time (&fl->fail_time); + (void) time (&fl->fail_time); /* * Seek back to the correct position in the file and write the @@ -100,15 +105,18 @@ static bool too_many_failures (const struct faillog *fl) { time_t now; - if (fl->fail_max == 0 || fl->fail_cnt < fl->fail_max) + if ((0 == fl->fail_max) || (fl->fail_cnt < fl->fail_max)) { return false; + } - if (fl->fail_locktime == 0) + if (0 == fl->fail_locktime) { return true; /* locked until reset manually */ + } - time (&now); - if (fl->fail_time + fl->fail_locktime < now) + (void) time (&now); + if ((fl->fail_time + fl->fail_locktime) < now) { return false; /* enough time since last failure */ + } return true; } @@ -153,7 +161,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) */ lseek (fd, (off_t) (sizeof *fl) * uid, SEEK_SET); - if (read (fd, (char *) fl, sizeof *fl) != sizeof *fl) { + if (read (fd, (char *) fl, sizeof *fl) != (ssize_t) sizeof *fl) { close (fd); return 1; } @@ -200,11 +208,12 @@ void failprint (const struct faillog *fail) #endif time_t NOW; - if (fail->fail_cnt == 0) + if (0 == fail->fail_cnt) { return; + } tp = localtime (&(fail->fail_time)); - time (&NOW); + (void) time (&NOW); #if HAVE_STRFTIME /* @@ -220,13 +229,16 @@ void failprint (const struct faillog *fail) lasttime = asctime (tp); lasttime[24] = '\0'; - if (NOW - fail->fail_time < YEAR) + if ((NOW - fail->fail_time) < YEAR) { lasttime[19] = '\0'; - if (NOW - fail->fail_time < DAY) + } + if ((NOW - fail->fail_time) < DAY) { lasttime = lasttime + 11; + } - if (*lasttime == ' ') + if (' ' == *lasttime) { lasttime++; + } #endif printf (ngettext ("%d failure since last login.\n" "Last was %s on %s.\n",