Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux_user: when modifying a users' homedir, tries to create it even if it exists #9080

Open
jaymzh opened this issue Nov 8, 2019 · 5 comments

Comments

@jaymzh
Copy link
Member

@jaymzh jaymzh commented Nov 8, 2019

Description

When linux_user modifies a user to set it's homedir, if that homedir exists, it tries to create it, fails, and fails the run.

It looks like this is from passing -m always

Chef Version

14.13.11

Platform Version

Ubuntu 18.04

Replication Case

setup a user. change it's homedir to something that exists.

Client Output

---- Begin output of ["usermod", "-d", "/var/lib/openvpn/chroot", "-m", "nm-openvpn"]
 ----
STDOUT: 
STDERR: usermod: directory /var/lib/openvpn/chroot exists
---- End output of ["usermod", "-d", "/var/lib/openvpn/chroot", "-m", "nm-openvpn"] -
---
Ran ["usermod", "-d", "/var/lib/openvpn/chroot", "-m", "nm-openvpn"] returned 12

Stacktrace

@skippyj

This comment has been minimized.

Copy link

@skippyj skippyj commented Nov 17, 2019

Based on what I know about the "usermod" command, that message is purely informational and should not be evaluating the " directory already exists" message as an error. The manpage of usermod specifically addresses what happens if the passed "-d" directory already exists: https://linux.die.net/man/8/usermod

Chef is not actually attempting to re-create the directory, it is simply reading the resulting message as an error when the directory already exists.

[root@dev ~]# useradd test_user
[root@dev ~]# mkdir /home/test_user
mkdir: cannot create directory ‘/home/test_user’: File exists
[root@dev ~]# mkdir /home/new_test_user_dir
[root@dev ~]# usermod -d /home/new_test_user_dir -m test_user
usermod: directory /home/new_test_user_dir exists
[root@dev ~]# echo $?
12
@jaymzh

This comment has been minimized.

Copy link
Member Author

@jaymzh jaymzh commented Nov 17, 2019

Yeah, it's def usermod. But the question is can we handle this better. The man page doesn't list the exit codes, but if 12 is unique to this, then we could set the allowed exit codes to [0,12].

@skippyj

This comment has been minimized.

Copy link

@skippyj skippyj commented Nov 17, 2019

Yeah I agree. I haven't actively contributed to this project before, but I'll take a crack at it.

@skippyj

This comment has been minimized.

Copy link

@skippyj skippyj commented Nov 17, 2019

For reference, the entry reference in usermod that corresponds to code 12: https://github.com/shadow-maint/shadow/blob/b49712ed328ded0cd8161542ca13cf5d4cf55e5f/src/usermod.c#L92

"/* unable to complete home dir move */"

@skippyj

This comment has been minimized.

Copy link

@skippyj skippyj commented Nov 17, 2019

Created branch on my fork
skippyj@768d0f1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.