* NEWS, src/groupdel.c: Make sure the group, and gshadow files are
unlocked on exit. Add function fail_exit(). Use fail_exit() instead of exit(). * src/groupdel.c: Fail immediately instead of increasing errors. Better handling of error cases, like locked group or gshadow file.
This commit is contained in:
parent
d1290c0d5d
commit
5af8a5d74d
@ -1,3 +1,11 @@
|
|||||||
|
2008-03-08 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* NEWS, src/groupdel.c: Make sure the group, and gshadow files are
|
||||||
|
unlocked on exit. Add function fail_exit(). Use fail_exit()
|
||||||
|
instead of exit().
|
||||||
|
* src/groupdel.c: Fail immediately instead of increasing errors.
|
||||||
|
Better handling of error cases, like locked group or gshadow file.
|
||||||
|
|
||||||
2008-03-08 Nicolas François <nicolas.francois@centraliens.net>
|
2008-03-08 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* NEWS, src/newusers.c: Make sure the passwd, group, shadow, and
|
* NEWS, src/newusers.c: Make sure the passwd, group, shadow, and
|
||||||
|
1
NEWS
1
NEWS
@ -35,6 +35,7 @@ shadow-4.1.0 -> shadow-4.1.1 UNRELEASED
|
|||||||
- groupdel
|
- groupdel
|
||||||
* Do not fail if the group does not exist in the gshadow file.
|
* Do not fail if the group does not exist in the gshadow file.
|
||||||
* Do not rewrite the group or gshadow file in case of error.
|
* Do not rewrite the group or gshadow file in case of error.
|
||||||
|
* Make sure the group and gshadow files are unlocked on exit.
|
||||||
- groupmems
|
- groupmems
|
||||||
* Fix buffer overflow when adding an user to a group. Thanks to Peter Vrabec.
|
* Fix buffer overflow when adding an user to a group. Thanks to Peter Vrabec.
|
||||||
- groupmod
|
- groupmod
|
||||||
|
@ -70,6 +70,7 @@ static int is_shadow_grp;
|
|||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
static void usage (void);
|
static void usage (void);
|
||||||
|
static void fail_exit (int);
|
||||||
static void grp_update (void);
|
static void grp_update (void);
|
||||||
static void close_files (void);
|
static void close_files (void);
|
||||||
static void open_files (void);
|
static void open_files (void);
|
||||||
@ -84,6 +85,26 @@ static void usage (void)
|
|||||||
exit (E_USAGE);
|
exit (E_USAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fail_exit - exit with a failure code after unlocking the files
|
||||||
|
*/
|
||||||
|
static void fail_exit (int code)
|
||||||
|
{
|
||||||
|
(void) gr_unlock ();
|
||||||
|
#ifdef SHADOWGRP
|
||||||
|
if (is_shadow_grp) {
|
||||||
|
sgr_unlock ();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting group",
|
||||||
|
group_name, -1, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
exit (code);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* grp_update - update group file entries
|
* grp_update - update group file entries
|
||||||
*
|
*
|
||||||
@ -93,7 +114,7 @@ static void grp_update (void)
|
|||||||
{
|
{
|
||||||
if (!gr_remove (group_name)) {
|
if (!gr_remove (group_name)) {
|
||||||
fprintf (stderr, _("%s: error removing group entry\n"), Prog);
|
fprintf (stderr, _("%s: error removing group entry\n"), Prog);
|
||||||
errors++;
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
/*
|
/*
|
||||||
@ -104,7 +125,7 @@ static void grp_update (void)
|
|||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error removing shadow group entry\n"),
|
_("%s: error removing shadow group entry\n"),
|
||||||
Prog);
|
Prog);
|
||||||
errors++;
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* SHADOWGRP */
|
#endif /* SHADOWGRP */
|
||||||
@ -127,14 +148,14 @@ static void close_files (void)
|
|||||||
|
|
||||||
if (!gr_close ()) {
|
if (!gr_close ()) {
|
||||||
fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog);
|
fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog);
|
||||||
errors++;
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
gr_unlock ();
|
gr_unlock ();
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && !sgr_close ()) {
|
if (is_shadow_grp && !sgr_close ()) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: cannot rewrite shadow group file\n"), Prog);
|
_("%s: cannot rewrite shadow group file\n"), Prog);
|
||||||
errors++;
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_grp)
|
if (is_shadow_grp)
|
||||||
sgr_unlock ();
|
sgr_unlock ();
|
||||||
@ -150,22 +171,22 @@ static void open_files (void)
|
|||||||
{
|
{
|
||||||
if (!gr_lock ()) {
|
if (!gr_lock ()) {
|
||||||
fprintf (stderr, _("%s: unable to lock group file\n"), Prog);
|
fprintf (stderr, _("%s: unable to lock group file\n"), Prog);
|
||||||
exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (!gr_open (O_RDWR)) {
|
if (!gr_open (O_RDWR)) {
|
||||||
fprintf (stderr, _("%s: unable to open group file\n"), Prog);
|
fprintf (stderr, _("%s: unable to open group file\n"), Prog);
|
||||||
exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (is_shadow_grp && !sgr_lock ()) {
|
if (is_shadow_grp && !sgr_lock ()) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: unable to lock shadow group file\n"), Prog);
|
_("%s: unable to lock shadow group file\n"), Prog);
|
||||||
exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
if (is_shadow_grp && !sgr_open (O_RDWR)) {
|
if (is_shadow_grp && !sgr_open (O_RDWR)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: unable to open shadow group file\n"), Prog);
|
_("%s: unable to open shadow group file\n"), Prog);
|
||||||
exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
#endif /* SHADOWGRP */
|
#endif /* SHADOWGRP */
|
||||||
}
|
}
|
||||||
@ -202,7 +223,7 @@ static void group_busy (gid_t gid)
|
|||||||
* Can't remove the group.
|
* Can't remove the group.
|
||||||
*/
|
*/
|
||||||
fprintf (stderr, _("%s: cannot remove user's primary group.\n"), Prog);
|
fprintf (stderr, _("%s: cannot remove user's primary group.\n"), Prog);
|
||||||
exit (E_GROUP_BUSY);
|
fail_exit (E_GROUP_BUSY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -340,21 +361,16 @@ int main (int argc, char **argv)
|
|||||||
open_files ();
|
open_files ();
|
||||||
|
|
||||||
grp_update ();
|
grp_update ();
|
||||||
if (errors == 0) {
|
|
||||||
close_files ();
|
close_files ();
|
||||||
nscd_flush_cache ("group");
|
|
||||||
}
|
nscd_flush_cache ("group");
|
||||||
|
|
||||||
#ifdef USE_PAM
|
#ifdef USE_PAM
|
||||||
if (retval == PAM_SUCCESS)
|
if (retval == PAM_SUCCESS)
|
||||||
pam_end (pamh, PAM_SUCCESS);
|
pam_end (pamh, PAM_SUCCESS);
|
||||||
#endif /* USE_PAM */
|
#endif /* USE_PAM */
|
||||||
if (errors != 0)
|
|
||||||
#ifdef WITH_AUDIT
|
return E_SUCCESS;
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting group",
|
|
||||||
group_name, -1, 0);
|
|
||||||
#endif
|
|
||||||
exit (errors == 0 ? E_SUCCESS : E_GRP_UPDATE);
|
|
||||||
/* NOT REACHED */
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user