Project

General

Profile

Bug #7648

useradd/mod commands operate on /home special filesystem

Added by Alexander Pyhalov over 3 years ago. Updated over 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2016-12-05
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

Useradd/usermod have incorrect default home directory (/home instead of /export/home). As /home is auto_home mount point, 'useradd -m user' fails with

UX: useradd: ERROR: Unable to create the home directory: Operation not applicable.

The fix is pretty simple:

--- a/usr/src/head/userdefs.h
+++ b/usr/src/head/userdefs.h
@@ -51,7 +51,7 @@ extern "C" {
 #define        DEFPROJNAME     "default" 
 #define        DEFGROUP        1
 #define        DEFGNAME        "other" 
-#define        DEFPARENT       "/home" 
+#define        DEFPARENT       "/export/home" 
 #define        DEFSKL          "/etc/skel" 
 #define        DEFSHL          "/bin/sh" 
 #define        DEFROLESHL      "/bin/pfsh" 

History

#1

Updated by Gordon Ross over 3 years ago

I'm trying to stimulate some architectural discussion about this issue.
What are some reasonable ways to fix this? Which serves us best?

First some background: userdefs.h is used in:

usr/src/cmd/cmd-inet/usr.sbin/in.routed/
usr/src/cmd/oamuser/group/
usr/src/cmd/oamuser/lib/
usr/src/cmd/oamuser/user/
usr/src/cmd/passwd/
usr/src/cmd/tsol/updatehome/
usr/src/lib/libcmdutils/common/
usr/src/lib/libproject/common/
usr/src/lib/libtsol/common/
usr/src/lib/pam_modules/unix_auth/

#2

Updated by Alexander Pyhalov over 3 years ago

I see 2 options: either have way to fix it in runtime, as in http://buildzone.oi-build.r61.net/webrev-7648/ (this one is a bit incomplete) or at compile time https://www.illumos.org/rb/r/286/ . Having ability to set some defines in compile time seems more appropriate here, as this hides additional knobs from the end user.

#3

Updated by Alexander Pyhalov over 3 years ago

usr/src/cmd/cmd-inet/usr.sbin/in.routed/main.c - seems to avoid using anything from userdefs.h, however, includes this header;
usr/src/cmd/oamuser/group/add_group.c - uses GROUP define to open /etc/group;
usr/src/cmd/oamuser/group/groupadd.c - uses EX_* defines and DEFRID to find auto-generated free group id;
usr/src/cmd/oamuser/group/groupdel.c, del_group.c, group_mod.c, mod_group.c - use EX_* defines to check function return codes;
usr/src/cmd/oamuser/lib/vgid.c - uses DEFGID to check gids < DEFGID - if they are reserved;
usr/src/cmd/oamuser/lib/vuid.c - uses DEFUID to check uids < DEFUID - if they are reserved;
usr/src/cmd/oamuser/lib/vgname.c - uses MAXGLEN to check if group name is valid;
usr/src/cmd/oamuser/lib/vgroup.c, vlogin.c, vproj.c, vprojid.c, vprojname.c - don't use userdefs.h, however, includes it;
usr/src/cmd/oamuser/user/call_pass.c - uses EX_* exit codes;
usr/src/cmd/oamuser/user/funcs.c - uses EX_* exit codes;
usr/src/cmd/oamuser/user/groups.c - uses EX_* exit codes;
usr/src/cmd/oamuser/user/homedir.c - uses EX_* exit codes;
usr/src/cmd/oamuser/user/movedir.c - uses EX_* exit codes;
usr/src/cmd/oamuser/user/proj.c - uses EX_* exit codes;
usr/src/cmd/oamuser/user/userdefs.c - uses DEF* constants to set defaults, EX_* constants for exit codes;
usr/src/cmd/oamuser/user/useradd.c - uses EX_* for exit codes, struct userdefs to get defaults;
usr/src/cmd/oamuser/user/userdel.c - uses EX_* for exit codes;
usr/src/cmd/oamuser/user/val_lgrp.c - uses EX_* for exit codes;
usr/src/cmd/oamuser/user/val_lprj.c - uses EX_* for exit codes;
usr/src/cm/passwd/passwd.c - uses DEFSHL as default choice in passwd -e if user shell is not set explicitly;

Don't see userdefs.h included in usr/src/cmd/tsol/updatehome/*

usr/src/lib/libcmdutils/common/gid.c, uid.c - includes userdefs.h, but doesn't use it actually;

Don't see userdefs.h included in usr/src/lib/libtsol/*

usr/src/lib/libproject/common/getprojent.c - uses MAXGENT to define string size (char groupname[MAXGLEN + 1]);
usr/src/lib/pam_modules/unix_auth/unix_auth.c - includes userdefs.h, but doesn't use it actually.

#4

Updated by Alexander Pyhalov over 3 years ago

After this analysis I think it's safe to change DEF* defines in userdefs.h to custom values (as needed by distribution).

#5

Updated by Alexander Pyhalov over 3 years ago

passwd DEFSHELL usage seems incorrect, as login hardcodes /usr/bin/sh as default shell

#6

Updated by Alexander Pyhalov over 3 years ago

OpenSSH uses /bin/sh as default shell. As we have /bin -> /usr/bin, we can change DEFSHL in passwd.c to own define.

#7

Updated by Alexander Pyhalov over 3 years ago

Current issue with userdefs.h DEF* settings is that they don't suit all distributions and we don't have a decent way to set them.

Currently there is getusrdef() function, defined in usr/src/cmd/oamuser/user/userdefs.c, which extracts user's settings from /usr/sadm/defadduser (or /usr/sadm/defaddrole) file or compiled-in defaults. These defaults can't be easily changed, as they are hard-coded. The function is used by useradd to get default values. /usr/sadm/defadduser is undocumented and seems to be just internal useradd implementation detail. It is used to store user's preferences.

Now, when we want to set custom defaults per distribution, we have two choices: patch the code or ship custom defadduser/defaddrole file. Distributions have to patch man pages anyway.

We have several approaches to improve this situation. One of them is to define these values in runtime and move 'default default', when defadduser file is not present, to another system-wide config (like /etc/default/useradd). Another - add ability to rewrite these values at compilation time. First approach seems to be more flexible, but as it gives user more knobs to use, should be careful about file precedency and seems to be a bit inconsistent (end user gets two places to set things). However, wen we use second approach (redefining constants in compile time), we have less flexibility.

#8

Updated by Alexander Pyhalov over 3 years ago

As simple fix allowing to define userdefs.h constants was not enough for illumos-gate, I've merged local patch https://github.com/OpenIndiana/oi-userland/pull/2661/files in oi-userland and don't longer care much about this issue.

Also available in: Atom PDF