Bug 973647 - missing error message when useradd cannot create user with homedir in location without default selinux context
Summary: missing error message when useradd cannot create user with homedir in locatio...
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: shadow-utils
Version: 7.0
Hardware: All
OS: Linux
Target Milestone: rc
: ---
Assignee: Tomas Mraz
QA Contact: Michal Trunecka
Depends On:
TreeView+ depends on / blocked
Reported: 2013-06-12 12:32 UTC by Michal Trunecka
Modified: 2014-09-30 23:35 UTC (History)
4 users (show)

Fixed In Version: shadow-utils-
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2014-06-13 13:27:33 UTC
Target Upstream Version:

Attachments (Terms of Use)

Description Michal Trunecka 2013-06-12 12:32:15 UTC
Description of problem:
For example /mnt/qa/scratch has not a default selinux context:

# matchpathcon /mnt/qa/scratch
/mnt/qa/scratch	<<none>>

Creating user with homedir in there fails:

# useradd -m -d /mnt/qa/scratch/user19376 user19376
# echo $?

The returned 12 means the homedir couldn't be created. It works fine in permissive, no AVCs related to this issue. (even with disabled dontaudit rules)

In useradd.c, there is the following code in create_home function:

> 1762 if (set_selinux_file_context (user_home, NULL) != 0) {
> 1763     fail_exit (E_HOMEDIR);
> 1764 }

And because no orig.context is passed in the second argument and at the same time matchpathcon returns no default context, the set_selinux_file_context function failes.
From lib/selinux.c (in shadow-utils srcrpm):

> 53 int set_selinux_file_context (const char *dst_name, const char *orig_name)
> 62         if (selinux_enabled) {
> 63                 /* Get the default security context for this file */
> 64                 if (matchpathcon (dst_name, 0, &scontext) < 0) {
> 65                         /* We could not get the default, copy the original */
> 66                         if (orig_name == NULL)
> 67                                 goto error;

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

Comment 1 Tomas Mraz 2013-06-12 12:39:01 UTC
I don't think this is a bug. Just specify some default context adequate for the home directory parent with semanage fcontext -a ...

Or disable selinux if you do not want to work with it properly - but I strictly do not recommend that.

Comment 2 Michal Trunecka 2013-06-12 12:51:43 UTC
If not anything else, I definitely think that not logging any message about the reason of not creating home dir is a bug.

Comment 6 Ludek Smid 2014-06-13 13:27:33 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.

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