From 687ae4f4a8a8ca70cfe4a507c2aee7e2605a5044 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Sun, 31 Aug 2008 17:29:41 +0000 Subject: [PATCH] Finish the support for shadow groups. --- src/groupmems.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/groupmems.c b/src/groupmems.c index a8e4f7fb..dd114a48 100644 --- a/src/groupmems.c +++ b/src/groupmems.c @@ -467,6 +467,19 @@ static void fail_exit (int code) /* continue */ } } + +#ifdef SHADOWGRP + if (sgr_locked) { + if (sgr_unlock () == 0) { + fprintf (stderr, + _("%s: failed to unlock %s\n"), + Prog, sgr_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ())); + /* continue */ + } + } +#endif + exit (code); } @@ -480,12 +493,33 @@ static void open_files (void) fail_exit (EXIT_GROUP_FILE); } gr_locked = true; + +#ifdef SHADOWGRP + if (is_shadowgrp) { + if (sgr_lock () == 0) { + fprintf (stderr, + _("%s: cannot lock %s; try again later.\n"), + Prog, sgr_dbname ()); + fail_exit (EXIT_GROUP_FILE); + } + sgr_locked = true; + } +#endif } if (gr_open (list ? O_RDONLY : O_RDWR) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (EXIT_GROUP_FILE); } + +#ifdef SHADOWGRP + if (is_shadowgrp) { + if (sgr_open (list ? O_RDONLY : O_RDWR) == 0) { + fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); + fail_exit (EXIT_GROUP_FILE); + } + } +#endif } static void close_files (void) @@ -503,6 +537,24 @@ static void close_files (void) } gr_locked = false; } + +#ifdef SHADOWGRP + if (is_shadowgrp) { + if ((sgr_close () == 0) && !list) { + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ())); + fail_exit (EXIT_GROUP_FILE); + } + if (sgr_locked) { + if (sgr_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ())); + /* continue */ + } + sgr_locked = false; + } + } +#endif } int main (int argc, char **argv) @@ -521,6 +573,10 @@ int main (int argc, char **argv) (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); +#ifdef SHADOWGRP + is_shadowgrp = sgr_file_present (); +#endif + process_flags (argc, argv); if (NULL == thisgroup) {