* src/pwck.c: Added fail_exit().
* src/pwck.c: Report failure to unlock files to stderr and syslog. * src/pwck.c: Report failure to sort to stderr, and exit with E_CANTSORT. * man/pwck.8.xml: Document return code 6 (E_CANTSORT).
This commit is contained in:
parent
10e78fbd8e
commit
b6cc69cd8f
@ -1,3 +1,12 @@
|
|||||||
|
2008-08-07 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* src/pwck.c: Added fail_exit().
|
||||||
|
* src/pwck.c: Report failure to unlock files to stderr and
|
||||||
|
syslog.
|
||||||
|
* src/pwck.c: Report failure to sort to stderr, and exit with
|
||||||
|
E_CANTSORT.
|
||||||
|
* man/pwck.8.xml: Document return code 6 (E_CANTSORT).
|
||||||
|
|
||||||
2008-08-07 Nicolas François <nicolas.francois@centraliens.net>
|
2008-08-07 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/vipw.c: Report failures to remove files to stderr.
|
* src/vipw.c: Report failures to remove files to stderr.
|
||||||
|
@ -245,6 +245,12 @@
|
|||||||
<para>can't update password files</para>
|
<para>can't update password files</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
<varlistentry>
|
||||||
|
<term><replaceable>6</replaceable></term>
|
||||||
|
<listitem>
|
||||||
|
<para>can't sort password files</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
</variablelist>
|
</variablelist>
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
90
src/pwck.c
90
src/pwck.c
@ -58,6 +58,7 @@
|
|||||||
#define E_CANTOPEN 3
|
#define E_CANTOPEN 3
|
||||||
#define E_CANTLOCK 4
|
#define E_CANTLOCK 4
|
||||||
#define E_CANTUPDATE 5
|
#define E_CANTUPDATE 5
|
||||||
|
#define E_CANTSORT 6
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global variables
|
* Global variables
|
||||||
@ -71,12 +72,16 @@ static bool use_system_spw_file = true;
|
|||||||
|
|
||||||
static bool is_shadow = false;
|
static bool is_shadow = false;
|
||||||
|
|
||||||
|
static bool pw_locked = false;
|
||||||
|
static bool spw_locked = false;
|
||||||
|
|
||||||
/* Options */
|
/* Options */
|
||||||
static bool read_only = false;
|
static bool read_only = false;
|
||||||
static bool sort_mode = false;
|
static bool sort_mode = false;
|
||||||
static bool quiet = false; /* don't report warnings, only errors */
|
static bool quiet = false; /* don't report warnings, only errors */
|
||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
|
static void fail_exit (int code);
|
||||||
static void usage (void);
|
static void usage (void);
|
||||||
static void process_flags (int argc, char **argv);
|
static void process_flags (int argc, char **argv);
|
||||||
static void open_files (void);
|
static void open_files (void);
|
||||||
@ -84,6 +89,31 @@ static void close_files (bool changed);
|
|||||||
static void check_pw_file (int *errors, bool *changed);
|
static void check_pw_file (int *errors, bool *changed);
|
||||||
static void check_spw_file (int *errors, bool *changed);
|
static void check_spw_file (int *errors, bool *changed);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fail_exit - do some cleanup and exit with the given error code
|
||||||
|
*/
|
||||||
|
static void fail_exit (int code)
|
||||||
|
{
|
||||||
|
if (spw_locked) {
|
||||||
|
if (spw_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pw_locked) {
|
||||||
|
if (pw_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closelog ();
|
||||||
|
|
||||||
|
exit (code);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* usage - print syntax message and exit
|
* usage - print syntax message and exit
|
||||||
*/
|
*/
|
||||||
@ -172,17 +202,19 @@ static void open_files (void)
|
|||||||
if (use_system_pw_file) {
|
if (use_system_pw_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file));
|
SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file));
|
||||||
}
|
}
|
||||||
closelog ();
|
fail_exit (E_CANTLOCK);
|
||||||
exit (E_CANTLOCK);
|
|
||||||
}
|
}
|
||||||
if (is_shadow && (spw_lock () == 0)) {
|
pw_locked = true;
|
||||||
fprintf (stderr, _("%s: cannot lock %s\n"),
|
if (is_shadow) {
|
||||||
Prog, spw_file);
|
if (spw_lock () == 0) {
|
||||||
if (use_system_spw_file) {
|
fprintf (stderr, _("%s: cannot lock %s\n"),
|
||||||
SYSLOG ((LOG_WARN, "cannot lock %s", spw_file));
|
Prog, spw_file);
|
||||||
|
if (use_system_spw_file) {
|
||||||
|
SYSLOG ((LOG_WARN, "cannot lock %s", spw_file));
|
||||||
|
}
|
||||||
|
fail_exit (E_CANTLOCK);
|
||||||
}
|
}
|
||||||
closelog ();
|
spw_locked = true;
|
||||||
exit (E_CANTLOCK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,8 +228,7 @@ static void open_files (void)
|
|||||||
if (use_system_pw_file) {
|
if (use_system_pw_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
|
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
|
||||||
}
|
}
|
||||||
closelog ();
|
fail_exit (E_CANTOPEN);
|
||||||
exit (E_CANTOPEN);
|
|
||||||
}
|
}
|
||||||
if (is_shadow && (spw_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
|
if (is_shadow && (spw_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
|
||||||
fprintf (stderr, _("%s: cannot open %s\n"),
|
fprintf (stderr, _("%s: cannot open %s\n"),
|
||||||
@ -205,8 +236,7 @@ static void open_files (void)
|
|||||||
if (use_system_spw_file) {
|
if (use_system_spw_file) {
|
||||||
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
|
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
|
||||||
}
|
}
|
||||||
closelog ();
|
fail_exit (E_CANTOPEN);
|
||||||
exit (E_CANTOPEN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,15 +258,13 @@ static void close_files (bool changed)
|
|||||||
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
||||||
Prog, pwd_file);
|
Prog, pwd_file);
|
||||||
SYSLOG ((LOG_WARN, "failure while writing changes to %s", pwd_file));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", pwd_file));
|
||||||
closelog ();
|
fail_exit (E_CANTUPDATE);
|
||||||
exit (E_CANTUPDATE);
|
|
||||||
}
|
}
|
||||||
if (is_shadow && (spw_close () == 0)) {
|
if (is_shadow && (spw_close () == 0)) {
|
||||||
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
||||||
Prog, spw_file);
|
Prog, spw_file);
|
||||||
SYSLOG ((LOG_WARN, "failure while writing changes to %s", spw_file));
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", spw_file));
|
||||||
closelog ();
|
fail_exit (E_CANTUPDATE);
|
||||||
exit (E_CANTUPDATE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,9 +272,19 @@ static void close_files (bool changed)
|
|||||||
* Don't be anti-social - unlock the files when you're done.
|
* Don't be anti-social - unlock the files when you're done.
|
||||||
*/
|
*/
|
||||||
if (is_shadow) {
|
if (is_shadow) {
|
||||||
spw_unlock ();
|
if (spw_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(void) pw_unlock ();
|
spw_locked = false;
|
||||||
|
if (pw_unlock () == 0) {
|
||||||
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
||||||
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
||||||
|
/* continue */
|
||||||
|
}
|
||||||
|
pw_locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -620,9 +658,19 @@ int main (int argc, char **argv)
|
|||||||
open_files ();
|
open_files ();
|
||||||
|
|
||||||
if (sort_mode) {
|
if (sort_mode) {
|
||||||
pw_sort ();
|
if (pw_sort () != 0) {
|
||||||
|
fprintf (stderr,
|
||||||
|
_("%s: cannot sort entries in %s\n"),
|
||||||
|
Prog, pw_dbname ());
|
||||||
|
fail_exit (E_CANTSORT);
|
||||||
|
}
|
||||||
if (is_shadow) {
|
if (is_shadow) {
|
||||||
spw_sort ();
|
if (spw_sort () != 0) {
|
||||||
|
fprintf (stderr,
|
||||||
|
_("%s: cannot sort entries in %s\n"),
|
||||||
|
Prog, spw_dbname ());
|
||||||
|
fail_exit (E_CANTSORT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
changed = true;
|
changed = true;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user