From 71656e3cbafc874007c9416b012900f65ce6cf0c Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Sat, 30 Aug 2008 18:34:43 +0000 Subject: [PATCH] =?utf8?q?=09*=20src/groupmems.c:=20Added=20function=20ope?= =?utf8?q?n=5F=C2=B0files=20and=20close=5Ffiles=20to=20=09ease=20the=20sup?= =?utf8?q?port=20of=20gshadow.=20=09*=20src/groupmems.c:=20Always=20call?= =?utf8?q?=20check=5Fperms().=20This=20function=20now=20=09succeed=20when?= =?utf8?q?=20the=20requested=20action=20is=20to=20list=20the=20members.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ChangeLog | 7 ++++-- src/groupmems.c | 62 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b58a47a..044ae100 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,10 @@ 2008-08-27 Nicolas François - * src/groupmems.c: Added functions add_user(), remove_user(), and - purge_members() to ease the support of gshadow. + * src/groupmems.c: Added functions add_user(), remove_user(), + purge_members(), open_files, and close_files to ease the support + of gshadow. + * src/groupmems.c: Always call check_perms(). This function now + succeed when the requested action is to list the members. 2008-08-27 Nicolas François diff --git a/src/groupmems.c b/src/groupmems.c index 97014771..0969f734 100644 --- a/src/groupmems.c +++ b/src/groupmems.c @@ -242,6 +242,10 @@ static void process_flags (int argc, char **argv) static void check_perms (void) { + if (list) { + return; + } + #ifdef USE_PAM pam_handle_t *pamh = NULL; int retval = PAM_SUCCESS; @@ -285,6 +289,41 @@ static void fail_exit (int code) exit (code); } +static void open_files (void) +{ + if (!list) { + if (gr_lock () == 0) { + fprintf (stderr, + _("%s: cannot lock %s; try again later.\n"), + Prog, gr_dbname ()); + fail_exit (EXIT_GROUP_FILE); + } + gr_locked = true; + } + + if (gr_open (list ? O_RDONLY : O_RDWR) == 0) { + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); + fail_exit (EXIT_GROUP_FILE); + } +} + +static void close_files (void) +{ + if (gr_close () == 0) { + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ())); + fail_exit (EXIT_GROUP_FILE); + } + if (gr_locked) { + if (gr_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ())); + /* continue */ + } + gr_locked = false; + } +} + int main (int argc, char **argv) { char *name; @@ -317,17 +356,9 @@ int main (int argc, char **argv) } } - if (!list) { - check_perms (); + check_perms (); - if (gr_lock () == 0) { - fprintf (stderr, - _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - fail_exit (EXIT_GROUP_FILE); - } - gr_locked = true; - } + open_files (); if (gr_open (list ? O_RDONLY : O_RDWR) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); @@ -352,16 +383,7 @@ int main (int argc, char **argv) purge_members (grp); } - if (gr_close () == 0) { - fprintf (stderr, _("%s: failure while writing changes to %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: failed to unlock %s\n"), Prog, gr_dbname ()); - SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ())); - /* continue */ - } + close_files (); exit (EXIT_SUCCESS); } -- 2.40.0