* src/faillog.c: The fail_max field is a short, use a short also
for the max argument of setmax / setmax_one. * src/faillog.c: Fail with an error message when faillog fails to write to the faillog database.
This commit is contained in:
parent
5762d08f4f
commit
6e2c6ffdf7
@ -1,3 +1,10 @@
|
|||||||
|
2011-11-19 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* src/faillog.c: The fail_max field is a short, use a short also
|
||||||
|
for the max argument of setmax / setmax_one.
|
||||||
|
* src/faillog.c: Fail with an error message when faillog fails to
|
||||||
|
write to the faillog database.
|
||||||
|
|
||||||
2011-11-19 Nicolas François <nicolas.francois@centraliens.net>
|
2011-11-19 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* man/gpasswd.1.xml: Document the difference between the -r and -R
|
* man/gpasswd.1.xml: Document the difference between the -r and -R
|
||||||
|
@ -52,8 +52,8 @@ static /*@noreturn@*/void usage (int status);
|
|||||||
static void print_one (/*@null@*/const struct passwd *pw, bool force);
|
static void print_one (/*@null@*/const struct passwd *pw, bool force);
|
||||||
static void set_locktime (long locktime);
|
static void set_locktime (long locktime);
|
||||||
static bool set_locktime_one (uid_t uid, long locktime);
|
static bool set_locktime_one (uid_t uid, long locktime);
|
||||||
static void setmax (int max);
|
static void setmax (short max);
|
||||||
static bool setmax_one (uid_t uid, int max);
|
static bool setmax_one (uid_t uid, short max);
|
||||||
static void print (void);
|
static void print (void);
|
||||||
static bool reset_one (uid_t uid);
|
static bool reset_one (uid_t uid);
|
||||||
static void reset (void);
|
static void reset (void);
|
||||||
@ -329,7 +329,7 @@ static void reset (void)
|
|||||||
*
|
*
|
||||||
* This returns a boolean indicating if an error occurred.
|
* This returns a boolean indicating if an error occurred.
|
||||||
*/
|
*/
|
||||||
static bool setmax_one (uid_t uid, int max)
|
static bool setmax_one (uid_t uid, short max)
|
||||||
{
|
{
|
||||||
off_t offset;
|
off_t offset;
|
||||||
struct faillog fl;
|
struct faillog fl;
|
||||||
@ -381,7 +381,7 @@ static bool setmax_one (uid_t uid, int max)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setmax (int max)
|
static void setmax (short max)
|
||||||
{
|
{
|
||||||
if (uflg && has_umin && has_umax && (umin==umax)) {
|
if (uflg && has_umin && has_umax && (umin==umax)) {
|
||||||
if (setmax_one ((uid_t)umin, max)) {
|
if (setmax_one ((uid_t)umin, max)) {
|
||||||
@ -476,10 +476,10 @@ static bool set_locktime_one (uid_t uid, long locktime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (locktime == fl.fail_locktime) {
|
if (locktime == fl.fail_locktime) {
|
||||||
/* If the max is already set to the right value, do not
|
/* If the locktime is already set to the right value, do not
|
||||||
* write in the file.
|
* write in the file.
|
||||||
* This avoids writing 0 when no entries were present for
|
* This avoids writing 0 when no entries were present for
|
||||||
* the user and the max argument is 0.
|
* the user and the locktime argument is 0.
|
||||||
*/
|
*/
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -561,7 +561,7 @@ static void set_locktime (long locktime)
|
|||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
long fail_locktime;
|
long fail_locktime;
|
||||||
long fail_max;
|
short fail_max;
|
||||||
long days;
|
long days;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -608,14 +608,19 @@ int main (int argc, char **argv)
|
|||||||
lflg = true;
|
lflg = true;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
if (getlong (optarg, &fail_max) == 0) {
|
{
|
||||||
|
long int lmax;
|
||||||
|
if ( (getlong (optarg, &lmax) == 0)
|
||||||
|
|| ((long int)(short) lmax != lmax)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: invalid numeric argument '%s'\n"),
|
_("%s: invalid numeric argument '%s'\n"),
|
||||||
Prog, optarg);
|
Prog, optarg);
|
||||||
exit (E_BAD_ARG);
|
exit (E_BAD_ARG);
|
||||||
}
|
}
|
||||||
|
fail_max = (short) lmax;
|
||||||
mflg = true;
|
mflg = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'r':
|
case 'r':
|
||||||
rflg = true;
|
rflg = true;
|
||||||
break;
|
break;
|
||||||
@ -716,7 +721,20 @@ int main (int argc, char **argv)
|
|||||||
print ();
|
print ();
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (fail);
|
if (lflg || mflg || rflg) {
|
||||||
|
if ( (ferror (fail) != 0)
|
||||||
|
|| (fflush (fail) != 0)
|
||||||
|
|| (fsync (fileno (fail)) != 0)
|
||||||
|
|| (fclose (fail) != 0)) {
|
||||||
|
fprintf (stderr,
|
||||||
|
_("%s: Failed to write %s: %s\n"),
|
||||||
|
Prog, FAILLOG_FILE, strerror (errno));
|
||||||
|
(void) fclose (fail);
|
||||||
|
errors = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(void) fclose (fail);
|
||||||
|
}
|
||||||
|
|
||||||
exit (errors ? E_NOPERM : E_SUCCESS);
|
exit (errors ? E_NOPERM : E_SUCCESS);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user