* libmisc/age.c: fork() and wait return a pid_t, not an int.

* libmisc/age.c: Avoid implicit conversion of pointers to
	booleans.
	* libmisc/age.c: Avoid assignments in comparisons.
	* libmisc/age.c: Ignore the return value of printf(), puts(),
	fputs() and fflush().
	* libmisc/age.c: Add brackets and parenthesis.
	* libmisc/age.c: Cast the return value of time() to long and
	converted to a date.
This commit is contained in:
nekral-guest 2008-06-13 19:24:27 +00:00
parent 71dda8b648
commit 0a6ce91369
2 changed files with 53 additions and 29 deletions

View File

@ -1,3 +1,15 @@
2008-06-13 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/age.c: fork() and wait return a pid_t, not an int.
* libmisc/age.c: Avoid implicit conversion of pointers to
booleans.
* libmisc/age.c: Avoid assignments in comparisons.
* libmisc/age.c: Ignore the return value of printf(), puts(),
fputs() and fflush().
* libmisc/age.c: Add brackets and parenthesis.
* libmisc/age.c: Cast the return value of time() to long and
converted to a date.
2008-06-13 Nicolas François <nicolas.francois@centraliens.net> 2008-06-13 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/rlogin.c: The size argument of read() is a size_t. * libmisc/rlogin.c: The size argument of read() is a size_t.

View File

@ -56,28 +56,30 @@
int expire (const struct passwd *pw, const struct spwd *sp) int expire (const struct passwd *pw, const struct spwd *sp)
{ {
int status; int status;
int child; pid_t child;
int pid; pid_t pid;
if (!sp) if (NULL == sp) {
sp = pwd_to_spwd (pw); sp = pwd_to_spwd (pw);
}
/* /*
* See if the user's password has expired, and if so * See if the user's password has expired, and if so
* force them to change their password. * force them to change their password.
*/ */
switch (status = isexpired (pw, sp)) { status = isexpired (pw, sp);
switch (status) {
case 0: case 0:
return 0; return 0;
case 1: case 1:
fputs (_("Your password has expired."), stdout); (void) fputs (_("Your password has expired."), stdout);
break; break;
case 2: case 2:
fputs (_("Your password is inactive."), stdout); (void) fputs (_("Your password is inactive."), stdout);
break; break;
case 3: case 3:
fputs (_("Your login has expired."), stdout); (void) fputs (_("Your login has expired."), stdout);
break; break;
} }
@ -88,12 +90,12 @@ int expire (const struct passwd *pw, const struct spwd *sp)
* change that password. * change that password.
*/ */
if (status > 1 || sp->sp_max < sp->sp_min) { if ((status > 1) || (sp->sp_max < sp->sp_min)) {
puts (_(" Contact the system administrator.")); (void) puts (_(" Contact the system administrator."));
exit (1); exit (1);
} }
puts (_(" Choose a new password.")); (void) puts (_(" Choose a new password."));
fflush (stdout); (void) fflush (stdout);
/* /*
* Close all the files so that unauthorized access won't * Close all the files so that unauthorized access won't
@ -115,7 +117,8 @@ int expire (const struct passwd *pw, const struct spwd *sp)
* change their password before being able to use the account. * change their password before being able to use the account.
*/ */
if ((pid = fork ()) == 0) { pid = fork ();
if (0 == pid) {
int err; int err;
/* /*
@ -123,21 +126,24 @@ int expire (const struct passwd *pw, const struct spwd *sp)
* passwd to work just like it would had they executed * passwd to work just like it would had they executed
* it from the command line while logged in. * it from the command line while logged in.
*/ */
if (setup_uid_gid (pw, 0) != 0) if (setup_uid_gid (pw, 0) != 0) {
_exit (126); _exit (126);
}
execl (PASSWD_PROGRAM, PASSWD_PROGRAM, pw->pw_name, (char *) 0); execl (PASSWD_PROGRAM, PASSWD_PROGRAM, pw->pw_name, (char *) 0);
err = errno; err = errno;
perror ("Can't execute " PASSWD_PROGRAM); perror ("Can't execute " PASSWD_PROGRAM);
_exit (err == ENOENT ? E_CMD_NOTFOUND : E_CMD_NOEXEC); _exit ((ENOENT == err) ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
} else if (pid == -1) { } else if ((pid_t) -1 == pid) {
perror ("fork"); perror ("fork");
exit (1); exit (1);
} }
while ((child = wait (&status)) != pid && child != -1);
if (child == pid && status == 0) while (((child = wait (&status)) != pid) && (child != (pid_t)-1));
if ((child == pid) && (0 == status)) {
return 1; return 1;
}
exit (1); exit (1);
/*NOTREACHED*/} /*NOTREACHED*/}
@ -151,28 +157,34 @@ int expire (const struct passwd *pw, const struct spwd *sp)
void agecheck (const struct passwd *pw, const struct spwd *sp) void agecheck (const struct passwd *pw, const struct spwd *sp)
{ {
long now = time ((long *) 0) / SCALE; long now = (long) time ((time_t *) 0) / SCALE;
long remain; long remain;
if (!sp) if (NULL == sp) {
sp = pwd_to_spwd (pw); sp = pwd_to_spwd (pw);
}
/* /*
* The last, max, and warn fields must be supported or the * The last, max, and warn fields must be supported or the
* warning period cannot be calculated. * warning period cannot be calculated.
*/ */
if (sp->sp_lstchg == -1 || sp->sp_max == -1 || sp->sp_warn == -1) if ( (-1 == sp->sp_lstchg)
|| (-1 == sp->sp_max)
|| (-1 == sp->sp_warn)) {
return; return;
if ((remain = (sp->sp_lstchg + sp->sp_max) - now) <= sp->sp_warn) { }
remain = sp->sp_lstchg + sp->sp_max - now;
if (remain <= sp->sp_warn) {
remain /= DAY / SCALE; remain /= DAY / SCALE;
if (remain > 1) if (remain > 1) {
printf (_ (void) printf (_("Your password will expire in %ld days.\n"),
("Your password will expire in %ld days.\n"), remain);
remain); } else if (1 == remain) {
else if (remain == 1) (void) puts (_("Your password will expire tomorrow."));
puts (_("Your password will expire tomorrow.")); } else if (remain == 0) {
else if (remain == 0) (void) puts (_("Your password will expire today."));
puts (_("Your password will expire today.")); }
} }
} }