* src/chage.c: Ignore the return value of pam_end() before exiting.

* src/chage.c: Ignore return values of strftime(), snprintf(),
	puts(), printf(), and fputs().
	* src/chage.c: Check the return value of asctime().
This commit is contained in:
nekral-guest 2008-07-11 22:31:43 +00:00
parent 95c78ce92b
commit 7ac0323c7b
2 changed files with 51 additions and 33 deletions

View File

@ -1,3 +1,10 @@
2008-07-12 Nicolas François <nicolas.francois@centraliens.net>
* src/chage.c: Ignore the return value of pam_end() before exiting.
* src/chage.c: Ignore return values of strftime(), snprintf(),
puts(), printf(), and fputs().
* src/chage.c: Check the return value of asctime().
2008-07-12 Nicolas François <nicolas.francois@centraliens.net> 2008-07-12 Nicolas François <nicolas.francois@centraliens.net>
* lib/gshadow.c: Avoid assignments in comparison. * lib/gshadow.c: Avoid assignments in comparison.

View File

@ -130,7 +130,7 @@ static void fail_exit (int code)
* caller. * caller.
* We always end the pam transaction with PAM_SUCCESS here. * We always end the pam transaction with PAM_SUCCESS here.
*/ */
pam_end (pamh, PAM_SUCCESS); (void) pam_end (pamh, PAM_SUCCESS);
} }
#endif #endif
@ -180,10 +180,10 @@ static void date_to_str (char *buf, size_t maxsize, time_t date)
tp = gmtime (&date); tp = gmtime (&date);
#ifdef HAVE_STRFTIME #ifdef HAVE_STRFTIME
strftime (buf, maxsize, "%Y-%m-%d", tp); (void) strftime (buf, maxsize, "%Y-%m-%d", tp);
#else #else
snprintf (buf, maxsize, "%04d-%02d-%02d", (void) snprintf (buf, maxsize, "%04d-%02d-%02d",
tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday); tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday);
#endif /* HAVE_STRFTIME */ #endif /* HAVE_STRFTIME */
} }
@ -201,13 +201,13 @@ static int new_fields (void)
char buf[200]; char buf[200];
char *cp; char *cp;
puts (_("Enter the new value, or press ENTER for the default")); (void) puts (_("Enter the new value, or press ENTER for the default"));
puts (""); (void) puts ("");
snprintf (buf, sizeof buf, "%ld", mindays); snprintf (buf, sizeof buf, "%ld", mindays);
change_field (buf, sizeof buf, _("Minimum Password Age")); change_field (buf, sizeof buf, _("Minimum Password Age"));
mindays = strtol (buf, &cp, 10); mindays = strtol (buf, &cp, 10);
if ( ((mindays == 0) && ('\0' != *cp)) if ( ((0 == mindays) && ('\0' != *cp))
|| (mindays < -1)) { || (mindays < -1)) {
return 0; return 0;
} }
@ -215,7 +215,7 @@ static int new_fields (void)
snprintf (buf, sizeof buf, "%ld", maxdays); snprintf (buf, sizeof buf, "%ld", maxdays);
change_field (buf, sizeof buf, _("Maximum Password Age")); change_field (buf, sizeof buf, _("Maximum Password Age"));
maxdays = strtol (buf, &cp, 10); maxdays = strtol (buf, &cp, 10);
if ( ((maxdays == 0) && ('\0' != *cp)) if ( ((0 == maxdays) && ('\0' != *cp))
|| (maxdays < -1)) { || (maxdays < -1)) {
return 0; return 0;
} }
@ -273,15 +273,25 @@ static void print_date (time_t date)
char buf[80]; char buf[80];
tp = gmtime (&date); tp = gmtime (&date);
strftime (buf, sizeof buf, "%b %d, %Y", tp); if (NULL == tp) {
puts (buf); (void) printf ("time_t: %ul\n", date);
} else {
(void) strftime (buf, sizeof buf, "%b %d, %Y", tp);
(void) puts (buf);
}
#else #else
struct tm *tp; struct tm *tp;
char *cp; char *cp = NULL;
tp = gmtime (&date); tp = gmtime (&date);
cp = asctime (tp); if (NULL != tp) {
printf ("%6.6s, %4.4s\n", cp + 4, cp + 20); cp = asctime (tp);
}
if (NULL != cp) {
(void) printf ("%6.6s, %4.4s\n", cp + 4, cp + 20);
} else {
(void) printf ("time_t: %ul\n", date);
}
#endif #endif
} }
@ -301,11 +311,11 @@ static void list_fields (void)
* The "last change" date is either "never" or the date the password * The "last change" date is either "never" or the date the password
* was last modified. The date is the number of days since 1/1/1970. * was last modified. The date is the number of days since 1/1/1970.
*/ */
fputs (_("Last password change\t\t\t\t\t: "), stdout); (void) fputs (_("Last password change\t\t\t\t\t: "), stdout);
if (lastday < 0) { if (lastday < 0) {
puts (_("never")); (void) puts (_("never"));
} else if (lastday == 0) { } else if (lastday == 0) {
puts (_("password must be changed")); (void) puts (_("password must be changed"));
} else { } else {
changed = lastday * SCALE; changed = lastday * SCALE;
print_date ((time_t) changed); print_date ((time_t) changed);
@ -315,10 +325,10 @@ static void list_fields (void)
* The password expiration date is determined from the last change * The password expiration date is determined from the last change
* date plus the number of days the password is valid for. * date plus the number of days the password is valid for.
*/ */
fputs (_("Password expires\t\t\t\t\t: "), stdout); (void) fputs (_("Password expires\t\t\t\t\t: "), stdout);
if ((lastday <= 0) || (maxdays >= (10000 * (DAY / SCALE))) if ((lastday <= 0) || (maxdays >= (10000 * (DAY / SCALE)))
|| (maxdays < 0)) { || (maxdays < 0)) {
puts (_("never")); (void) puts (_("never"));
} else { } else {
expires = changed + maxdays * SCALE; expires = changed + maxdays * SCALE;
print_date ((time_t) expires); print_date ((time_t) expires);
@ -330,10 +340,10 @@ static void list_fields (void)
* number of inactive days is added. The resulting date is when the * number of inactive days is added. The resulting date is when the
* active will be disabled. * active will be disabled.
*/ */
fputs (_("Password inactive\t\t\t\t\t: "), stdout); (void) fputs (_("Password inactive\t\t\t\t\t: "), stdout);
if ((lastday <= 0) || (inactdays < 0) || if ((lastday <= 0) || (inactdays < 0) ||
(maxdays >= (10000 * (DAY / SCALE))) || (maxdays < 0)) { (maxdays >= (10000 * (DAY / SCALE))) || (maxdays < 0)) {
puts (_("never")); (void) puts (_("never"));
} else { } else {
expires = changed + (maxdays + inactdays) * SCALE; expires = changed + (maxdays + inactdays) * SCALE;
print_date ((time_t) expires); print_date ((time_t) expires);
@ -343,9 +353,9 @@ static void list_fields (void)
* The account will expire on the given date regardless of the * The account will expire on the given date regardless of the
* password expiring or not. * password expiring or not.
*/ */
fputs (_("Account expires\t\t\t\t\t\t: "), stdout); (void) fputs (_("Account expires\t\t\t\t\t\t: "), stdout);
if (expdays < 0) { if (expdays < 0) {
puts (_("never")); (void) puts (_("never"));
} else { } else {
expires = expdays * SCALE; expires = expdays * SCALE;
print_date ((time_t) expires); print_date ((time_t) expires);
@ -500,29 +510,29 @@ static void check_perms (void)
retval = PAM_SUCCESS; retval = PAM_SUCCESS;
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */ pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
if (pampw == NULL) { if (NULL == pampw) {
retval = PAM_USER_UNKNOWN; retval = PAM_USER_UNKNOWN;
} }
if (retval == PAM_SUCCESS) { if (PAM_SUCCESS == retval) {
retval = pam_start ("chage", pampw->pw_name, &conv, &pamh); retval = pam_start ("chage", pampw->pw_name, &conv, &pamh);
} }
if (retval == PAM_SUCCESS) { if (PAM_SUCCESS == retval) {
retval = pam_authenticate (pamh, 0); retval = pam_authenticate (pamh, 0);
if (retval != PAM_SUCCESS) { if (PAM_SUCCESS != retval) {
pam_end (pamh, retval); (void) pam_end (pamh, retval);
} }
} }
if (retval == PAM_SUCCESS) { if (PAM_SUCCESS == retval) {
retval = pam_acct_mgmt (pamh, 0); retval = pam_acct_mgmt (pamh, 0);
if (retval != PAM_SUCCESS) { if (PAM_SUCCESS != retval) {
pam_end (pamh, retval); (void) pam_end (pamh, retval);
} }
} }
if (retval != PAM_SUCCESS) { if (PAM_SUCCESS != retval) {
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog); fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
pamh = NULL; pamh = NULL;
fail_exit (E_NOPERM); fail_exit (E_NOPERM);
@ -789,7 +799,8 @@ int main (int argc, char **argv)
open_files (lflg); open_files (lflg);
/* Drop privileges */ /* Drop privileges */
if (lflg && (setregid (rgid, rgid) || setreuid (ruid, ruid))) { if (lflg && ( (setregid (rgid, rgid) != 0)
|| (setreuid (ruid, ruid) != 0))) {
fprintf (stderr, _("%s: failed to drop privileges (%s)\n"), fprintf (stderr, _("%s: failed to drop privileges (%s)\n"),
Prog, strerror (errno)); Prog, strerror (errno));
fail_exit (E_NOPERM); fail_exit (E_NOPERM);
@ -888,7 +899,7 @@ int main (int argc, char **argv)
SYSLOG ((LOG_INFO, "changed password expiry for %s", user_name)); SYSLOG ((LOG_INFO, "changed password expiry for %s", user_name));
#ifdef USE_PAM #ifdef USE_PAM
pam_end (pamh, PAM_SUCCESS); (void) pam_end (pamh, PAM_SUCCESS);
#endif /* USE_PAM */ #endif /* USE_PAM */
closelog (); closelog ();