Make userdel to work with -R.
The userdel checks for users with getpwnam() which might not work properly in chroot. Check for the user's presence in local files only.
This commit is contained in:
parent
056f7352ef
commit
2c57c399bf
@ -96,6 +96,7 @@ static char *user_home;
|
|||||||
static bool fflg = false;
|
static bool fflg = false;
|
||||||
static bool rflg = false;
|
static bool rflg = false;
|
||||||
static bool Zflg = false;
|
static bool Zflg = false;
|
||||||
|
static bool Rflg = false;
|
||||||
|
|
||||||
static bool is_shadow_pwd;
|
static bool is_shadow_pwd;
|
||||||
|
|
||||||
@ -1029,6 +1030,7 @@ int main (int argc, char **argv)
|
|||||||
rflg = true;
|
rflg = true;
|
||||||
break;
|
break;
|
||||||
case 'R': /* no-op, handled in process_root_flag () */
|
case 'R': /* no-op, handled in process_root_flag () */
|
||||||
|
Rflg = true;
|
||||||
break;
|
break;
|
||||||
#ifdef WITH_SELINUX
|
#ifdef WITH_SELINUX
|
||||||
case 'Z':
|
case 'Z':
|
||||||
@ -1103,9 +1105,12 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
user_name = argv[argc - 1];
|
user_name = argv[argc - 1];
|
||||||
{
|
{
|
||||||
struct passwd *pwd;
|
const struct passwd *pwd;
|
||||||
pwd = getpwnam (user_name); /* local, no need for xgetpwnam */
|
|
||||||
|
pw_open(O_RDONLY);
|
||||||
|
pwd = pw_locate (user_name); /* we care only about local users */
|
||||||
if (NULL == pwd) {
|
if (NULL == pwd) {
|
||||||
|
pw_close();
|
||||||
fprintf (stderr, _("%s: user '%s' does not exist\n"),
|
fprintf (stderr, _("%s: user '%s' does not exist\n"),
|
||||||
Prog, user_name);
|
Prog, user_name);
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -1119,6 +1124,7 @@ int main (int argc, char **argv)
|
|||||||
user_id = pwd->pw_uid;
|
user_id = pwd->pw_uid;
|
||||||
user_gid = pwd->pw_gid;
|
user_gid = pwd->pw_gid;
|
||||||
user_home = xstrdup (pwd->pw_dir);
|
user_home = xstrdup (pwd->pw_dir);
|
||||||
|
pw_close();
|
||||||
}
|
}
|
||||||
#ifdef WITH_TCB
|
#ifdef WITH_TCB
|
||||||
if (shadowtcb_set_user (user_name) == SHADOWTCB_FAILURE) {
|
if (shadowtcb_set_user (user_name) == SHADOWTCB_FAILURE) {
|
||||||
@ -1150,7 +1156,7 @@ int main (int argc, char **argv)
|
|||||||
* Note: This is a best effort basis. The user may log in between,
|
* Note: This is a best effort basis. The user may log in between,
|
||||||
* a cron job may be started on her behalf, etc.
|
* a cron job may be started on her behalf, etc.
|
||||||
*/
|
*/
|
||||||
if (user_busy (user_name, user_id) != 0) {
|
if (!Rflg && user_busy (user_name, user_id) != 0) {
|
||||||
if (!fflg) {
|
if (!fflg) {
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
audit_logger (AUDIT_DEL_USER, Prog,
|
audit_logger (AUDIT_DEL_USER, Prog,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user