* src/usermod.c (update_group, update_gshadow): Reduce complexity
and document checks. Some checks were always true/false within their call context.
This commit is contained in:
parent
8195a2b5d8
commit
c2f5088067
@ -13,6 +13,9 @@
|
|||||||
check if changes are needed.
|
check if changes are needed.
|
||||||
* src/usermod.c: usage() does not return. Add annotations.
|
* src/usermod.c: usage() does not return. Add annotations.
|
||||||
* src/usermod.c (update_gshadow): is_member was computed twice.
|
* src/usermod.c (update_gshadow): is_member was computed twice.
|
||||||
|
* src/usermod.c (update_group, update_gshadow): Reduce complexity
|
||||||
|
and document checks. Some checks were always true/false within
|
||||||
|
their call context.
|
||||||
|
|
||||||
2011-07-08 Nicolas François <nicolas.francois@centraliens.net>
|
2011-07-08 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
120
src/usermod.c
120
src/usermod.c
@ -2,7 +2,7 @@
|
|||||||
* Copyright (c) 1991 - 1994, Julianne Frances Haugh
|
* Copyright (c) 1991 - 1994, Julianne Frances Haugh
|
||||||
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
||||||
* Copyright (c) 2000 - 2006, Tomasz Kłoczko
|
* Copyright (c) 2000 - 2006, Tomasz Kłoczko
|
||||||
* Copyright (c) 2007 - 2010, Nicolas François
|
* Copyright (c) 2007 - 2011, Nicolas François
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -613,35 +613,47 @@ static void update_group (void)
|
|||||||
fail_exit (E_GRP_UPDATE);
|
fail_exit (E_GRP_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (was_member && (!Gflg || is_member)) {
|
if (was_member) {
|
||||||
if (lflg) {
|
if ((!Gflg) || is_member) {
|
||||||
ngrp->gr_mem = del_list (ngrp->gr_mem,
|
/* User was a member and is still a member
|
||||||
user_name);
|
* of this group.
|
||||||
ngrp->gr_mem = add_list (ngrp->gr_mem,
|
* But the user might have been renamed.
|
||||||
user_newname);
|
*/
|
||||||
|
if (lflg) {
|
||||||
|
ngrp->gr_mem = del_list (ngrp->gr_mem,
|
||||||
|
user_name);
|
||||||
|
ngrp->gr_mem = add_list (ngrp->gr_mem,
|
||||||
|
user_newname);
|
||||||
|
changed = true;
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"changing group member",
|
||||||
|
user_newname, AUDIT_NO_ID, 1);
|
||||||
|
#endif
|
||||||
|
SYSLOG ((LOG_INFO,
|
||||||
|
"change '%s' to '%s' in group '%s'",
|
||||||
|
user_name, user_newname,
|
||||||
|
ngrp->gr_name));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* User was a member but is no more a
|
||||||
|
* member of this group.
|
||||||
|
*/
|
||||||
|
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
|
||||||
changed = true;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"changing group member",
|
"removing group member",
|
||||||
user_newname, AUDIT_NO_ID, 1);
|
user_name, AUDIT_NO_ID, 1);
|
||||||
#endif
|
#endif
|
||||||
SYSLOG ((LOG_INFO,
|
SYSLOG ((LOG_INFO,
|
||||||
"change '%s' to '%s' in group '%s'",
|
"delete '%s' from group '%s'",
|
||||||
user_name, user_newname,
|
user_name, ngrp->gr_name));
|
||||||
ngrp->gr_name));
|
|
||||||
}
|
}
|
||||||
} else if (was_member && !aflg && Gflg && !is_member) {
|
} else {
|
||||||
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
|
/* User was not a member but is now a member this
|
||||||
changed = true;
|
* group.
|
||||||
#ifdef WITH_AUDIT
|
*/
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
||||||
"removing group member",
|
|
||||||
user_name, AUDIT_NO_ID, 1);
|
|
||||||
#endif
|
|
||||||
SYSLOG ((LOG_INFO,
|
|
||||||
"delete '%s' from group '%s'",
|
|
||||||
user_name, ngrp->gr_name));
|
|
||||||
} else if (!was_member && Gflg && is_member) {
|
|
||||||
ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname);
|
ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname);
|
||||||
changed = true;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -715,6 +727,9 @@ static void update_gshadow (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (was_admin && lflg) {
|
if (was_admin && lflg) {
|
||||||
|
/* User was an admin of this group but the user
|
||||||
|
* has been renamed.
|
||||||
|
*/
|
||||||
nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name);
|
nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name);
|
||||||
nsgrp->sg_adm = add_list (nsgrp->sg_adm, user_newname);
|
nsgrp->sg_adm = add_list (nsgrp->sg_adm, user_newname);
|
||||||
changed = true;
|
changed = true;
|
||||||
@ -727,35 +742,48 @@ static void update_gshadow (void)
|
|||||||
"change admin '%s' to '%s' in shadow group '%s'",
|
"change admin '%s' to '%s' in shadow group '%s'",
|
||||||
user_name, user_newname, nsgrp->sg_name));
|
user_name, user_newname, nsgrp->sg_name));
|
||||||
}
|
}
|
||||||
if (was_member && (!Gflg || is_member)) {
|
|
||||||
if (lflg) {
|
if (was_member) {
|
||||||
nsgrp->sg_mem = del_list (nsgrp->sg_mem,
|
if ((!Gflg) || is_member) {
|
||||||
user_name);
|
/* User was a member and is still a member
|
||||||
nsgrp->sg_mem = add_list (nsgrp->sg_mem,
|
* of this group.
|
||||||
user_newname);
|
* But the user might have been renamed.
|
||||||
|
*/
|
||||||
|
if (lflg) {
|
||||||
|
nsgrp->sg_mem = del_list (nsgrp->sg_mem,
|
||||||
|
user_name);
|
||||||
|
nsgrp->sg_mem = add_list (nsgrp->sg_mem,
|
||||||
|
user_newname);
|
||||||
|
changed = true;
|
||||||
|
#ifdef WITH_AUDIT
|
||||||
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
|
"changing member in shadow group",
|
||||||
|
user_name, AUDIT_NO_ID, 1);
|
||||||
|
#endif
|
||||||
|
SYSLOG ((LOG_INFO,
|
||||||
|
"change '%s' to '%s' in shadow group '%s'",
|
||||||
|
user_name, user_newname,
|
||||||
|
nsgrp->sg_name));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* User was a member but is no more a
|
||||||
|
* member of this group.
|
||||||
|
*/
|
||||||
|
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
|
||||||
changed = true;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
||||||
"changing member in shadow group",
|
"removing user from shadow group",
|
||||||
user_name, AUDIT_NO_ID, 1);
|
user_name, AUDIT_NO_ID, 1);
|
||||||
#endif
|
#endif
|
||||||
SYSLOG ((LOG_INFO,
|
SYSLOG ((LOG_INFO,
|
||||||
"change '%s' to '%s' in shadow group '%s'",
|
"delete '%s' from shadow group '%s'",
|
||||||
user_name, user_newname,
|
user_name, nsgrp->sg_name));
|
||||||
nsgrp->sg_name));
|
|
||||||
}
|
}
|
||||||
} else if (was_member && !aflg && Gflg && !is_member) {
|
} else if (is_member) {
|
||||||
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
|
/* User was not a member but is now a member this
|
||||||
changed = true;
|
* group.
|
||||||
#ifdef WITH_AUDIT
|
*/
|
||||||
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
||||||
"removing user from shadow group",
|
|
||||||
user_name, AUDIT_NO_ID, 1);
|
|
||||||
#endif
|
|
||||||
SYSLOG ((LOG_INFO,
|
|
||||||
"delete '%s' from shadow group '%s'",
|
|
||||||
user_name, nsgrp->sg_name));
|
|
||||||
} else if (!was_member && Gflg && is_member) {
|
|
||||||
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_newname);
|
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_newname);
|
||||||
changed = true;
|
changed = true;
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user