Bug 1677005 - Clarify the useradd -d parameter behavior in man page in regards to the creating/not creating the home dir
Summary: Clarify the useradd -d parameter behavior in man page in regards to the creat...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: shadow-utils
Version: 31
Hardware: All
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Iker Pedrosa
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard: sync-to-jira
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-02-13 18:33 UTC by Thomas Walker Lynch
Modified: 2020-04-16 07:39 UTC (History)
4 users (show)

Fixed In Version: shadow-utils-4.8.1-2.fc32 shadow-utils-4.6-18.fc31
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-04-01 00:18:49 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Thomas Walker Lynch 2019-02-13 18:33:14 UTC
Description of problem: the '-d' option is for specifying a non default user directory.  As it says in the man page, https://linux.die.net/man/8/useradd :

-d, --home HOME_DIR
The new user will be created using HOME_DIR as the value for the user's login directory. The default is to append the LOGIN name to BASE_DIR and use that as the login directory name. The directory HOME_DIR does not have to exist but will not be created if it is missing.

Note the last sentence:  "The directory HOME_DIR does not have to exist but will not be created if it is missing."




Version-Release number of selected component (if applicable):


How reproducible: very


Steps to Reproduce:

# ls /home/temp2

# useradd tomjones -d /home/temp2/tj

# ls /home/temp2
tj

# 

Actual results:  the -d option directory is created


Expected results:  the -d option directory will not be created


Additional info: 

To setfacls for the directory the home dir is to be put in requires to first create the user (I think this is the case, seems funny to make up a non-existent user.)  So the home dir created by useradd has the wrong permissions as it is created before facls are set on the directory it is in.

Perhaps there is a scenario where a user directory is mounted when it isn't in the file system?  This would mess that up.

The biggest problem here is that by not acting as specified scripts are throwing errors.

A simple fix seems to be to modify the calling script to delete the home dir after the useradd call, then continue as it did before.

Comment 1 Jakub Hrozek 2019-02-13 20:14:35 UTC
Did you mean to file this bug against libuser? useradd comes from shadow-utils..

Comment 2 Thomas Walker Lynch 2019-02-13 21:03:16 UTC
thanks I was initially on the fence about that .. should know better, I've forked shadow locally to look at it ..

Comment 3 Tomas Mraz 2019-02-14 07:30:04 UTC
By default there is CREATE_HOME yes in /etc/login.defs which overrides what is specified in the manpage for -d. Please see the -m and -M options to override it.

Comment 4 Thomas Walker Lynch 2019-02-14 10:05:16 UTC
Hold on a sec.  Options that are effected by the login.defs are explicitly marked as such on the man page.  Note, -g and -U options.  This leaves the reading that The CREATE_HOME variable in login defs affects only the default behavior, not when explicitly specified as it states for the -d option.  Indeed the man page says:

"CREATE HOME ... if a home directory should be created by default ..."

as quoted above, -d option gives explicit no create behavior.

If the man page is incorrect, like how could anyone know that? If that is the case I'll flip it over to those guys.

BTW,  I did bring this up in an issue on the shadow github, but no one commented on it.  So like other people, I'm left with the man page for documentation.

Comment 5 Tomas Mraz 2019-02-14 10:35:33 UTC
The manpage is what should be clarified.

Comment 6 Thomas Walker Lynch 2019-02-20 21:28:55 UTC
Tomas, am I to understand that there is no way to invoke useradd on Fedora without having a user directory created and populated?

Comment 7 Thomas Walker Lynch 2019-02-20 21:57:07 UTC
(In reply to Thomas Walker Lynch from comment #6)
> Tomas, am I to understand that there is no way to invoke useradd on Fedora
> without having a user directory created and populated?

excuse me,  -M works for this and is working in combination with -d.  So the unqualified clause in the -d option, that the directory will not be created,  is what needs clarification

Comment 8 Tomas Mraz 2019-02-21 11:50:31 UTC
Yes.

Comment 9 Ben Cotton 2019-08-13 16:50:08 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to '31'.

Comment 10 Ben Cotton 2019-08-13 19:33:48 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to 31.

Comment 11 Iker Pedrosa 2020-03-23 08:47:35 UTC
* master
    d60b59b156a576293986a4ccf182db09e3386236 - useradd: clarify the useradd -d parameter behavior in man page

Comment 12 Fedora Update System 2020-03-26 14:38:08 UTC
FEDORA-2020-4ece7634c3 has been submitted as an update to Fedora 32. https://bodhi.fedoraproject.org/updates/FEDORA-2020-4ece7634c3

Comment 13 Fedora Update System 2020-03-27 15:58:15 UTC
FEDORA-2020-4ece7634c3 has been pushed to the Fedora 32 testing repository.
In short time you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2020-4ece7634c3`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2020-4ece7634c3

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 14 Fedora Update System 2020-03-31 10:52:39 UTC
FEDORA-2020-fec3968448 has been submitted as an update to Fedora 31. https://bodhi.fedoraproject.org/updates/FEDORA-2020-fec3968448

Comment 15 Fedora Update System 2020-04-01 00:18:49 UTC
FEDORA-2020-4ece7634c3 has been pushed to the Fedora 32 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 16 Fedora Update System 2020-04-01 03:54:37 UTC
FEDORA-2020-fec3968448 has been pushed to the Fedora 31 testing repository.
In short time you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2020-fec3968448`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2020-fec3968448

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 17 Fedora Update System 2020-04-01 16:33:35 UTC
FEDORA-2020-4ece7634c3 has been pushed to the Fedora 32 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 18 Fedora Update System 2020-04-15 20:32:52 UTC
FEDORA-2020-fec3968448 has been pushed to the Fedora 31 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 19 Villy Kruse 2020-04-16 07:39:33 UTC
This is not 100% correct

       -d, --home-dir HOME_DIR
           The new user will be created using HOME_DIR as the value for the user's login directory. The
           default is to append the LOGIN name to BASE_DIR and use that as the login directory name. If the
           directory HOME_DIR does not exist, then it will be created unless the -M option is specified.


The home directory will be created if the -m option is set or CREATE_HOME is set to true in /etc/login.defs.
Using the -M option prevents creating the directory regardless of the value of CREATE_HOME.


Note You need to log in before you can comment on or make changes to this bug.