From e3e99974f82e1d9553643133d98b454412702245 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Sat, 9 Aug 2008 23:28:30 +0000 Subject: [PATCH] * NEWS, src/groupmems.c: Added syslog support. * src/groupmems.c: members() renamed display_members() to avoid name clash with its members argument. * src/groupmems.c: Report failure to unlock to syslog. * src/groupmems.c: Harmonize error messages. * src/groupmems.c: Report failures to write the new group file to syslog (gr_close() failure). * src/groupmems.c: Don't use fail_exit for non-failure exit. --- ChangeLog | 11 +++++++++++ NEWS | 1 + src/groupmems.c | 35 +++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b0c21e7..0d4858c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-08-07 Nicolas François + + * NEWS, src/groupmems.c: Added syslog support. + * src/groupmems.c: members() renamed display_members() to + avoid name clash with its members argument. + * src/groupmems.c: Report failure to unlock to syslog. + * src/groupmems.c: Harmonize error messages. + * src/groupmems.c: Report failures to write the new group file to + syslog (gr_close() failure). + * src/groupmems.c: Don't use fail_exit for non-failure exit. + 2008-08-07 Nicolas François * src/chsh.c: Added fail_exit(). diff --git a/NEWS b/NEWS index 18d466ab..c6122187 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ shadow-4.1.2.1 -> shadow-4.1.3 UNRELEASED * Everybody is allowed to list the users of a group. * /etc/group is open readonly when one just wants to list the users of a group. + * Added syslog support. shadow-4.1.2 -> shadow-4.1.2.1 26-06-2008 diff --git a/src/groupmems.c b/src/groupmems.c index 3e9d2261..fd735d5f 100644 --- a/src/groupmems.c +++ b/src/groupmems.c @@ -71,7 +71,7 @@ static char *Prog; static bool group_locked = false; static char *whoami (void); -static void members (char **members); +static void display_members (char **members); static void usage (void); static void process_flags (int argc, char **argv); static void check_perms (void); @@ -94,7 +94,7 @@ static char *whoami (void) } } -static void members (char **members) +static void display_members (char **members) { int i; @@ -208,14 +208,16 @@ static void fail_exit (int code) if (group_locked) { if (gr_unlock () == 0) { fprintf (stderr, - _("%s: unable to unlock group file\n"), - Prog); + _("%s: cannot unlock %s\n"), + Prog, gr_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ())); + /* continue */ } } exit (code); } -void main (int argc, char **argv) +int main (int argc, char **argv) { char *name; struct group *grp; @@ -225,6 +227,8 @@ void main (int argc, char **argv) */ Prog = Basename (argv[0]); + OPENLOG ("groupmems"); + (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); @@ -250,27 +254,28 @@ void main (int argc, char **argv) if (gr_lock () == 0) { fprintf (stderr, - _("%s: unable to lock group file\n"), Prog); + _("%s: cannot lock %s\n"), + Prog, gr_dbname ()); fail_exit (EXIT_GROUP_FILE); } group_locked = true; } if (gr_open (list ? O_RDONLY : O_RDWR) == 0) { - fprintf (stderr, _("%s: unable to open group file\n"), Prog); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (EXIT_GROUP_FILE); } grp = (struct group *) gr_locate (name); if (NULL == grp) { - fprintf (stderr, _("%s: '%s' not found in /etc/group\n"), - Prog, name); + fprintf (stderr, _("%s: group '%s' does not exist in %s\n"), + Prog, name, gr_dbname ()); fail_exit (EXIT_INVALID_GROUP); } if (list) { - members (grp->gr_mem); + display_members (grp->gr_mem); } else if (NULL != adduser) { if (is_on_list (grp->gr_mem, adduser)) { fprintf (stderr, @@ -295,10 +300,16 @@ void main (int argc, char **argv) } if (gr_close () == 0) { - fprintf (stderr, _("%s: unable to close group file\n"), Prog); + fprintf (stderr, _("%s: failure while writing %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_ERR, "failure while writing %s", gr_dbname ())); fail_exit (EXIT_GROUP_FILE); } + if (gr_unlock () == 0) { + fprintf (stderr, _("%s: cannot unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ())); + /* continue */ + } - fail_exit (EXIT_SUCCESS); + exit (EXIT_SUCCESS); }