mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-26 07:55:01 +00:00
pw: do not move /home/$user to /usr/home
When adding a user, pw will create the path to the home directory if needed. However, if creating a path with just one component, i.e. that appears to be in the root directory, pw would create the directory in /usr, and create a symlink from the root directory. Most commonly, this meant that the default of /home/$user would turn into /usr/home/$user. This was added in a self-described kludge 26 years ago. It made (some) sense when root was generally a small partition, with most of the space in /usr. However, the default is now one large partition. /home really doesn't belong under /usr, and anyone who wants to use /usr/home can specify it explicitly. Remove the kludge to move /home under /usr and create the symlink, and just use the specified path. Note that this operation was done only on the first invocation for a path, and this happened most commonly when adding a user during the install. Modify the test that checked for the creation of the symlink to verify that the symlink is *not* made, but rather a directory. Add a test that intermediate directories are still created. Reviewed by: rgrimes, bapt Differential Revision: https://reviews.freebsd.org/D40085
This commit is contained in:
parent
c0a83fe074
commit
bbb2d2ce42
@ -114,36 +114,20 @@ mkdir_home_parents(int dfd, const char *dir)
|
||||
}
|
||||
tmp[0] = '\0';
|
||||
|
||||
/*
|
||||
* This is a kludge especially for Joerg :)
|
||||
* If the home directory would be created in the root partition, then
|
||||
* we really create it under /usr which is likely to have more space.
|
||||
* But we create a symlink from cnf->home -> "/usr" -> cnf->home
|
||||
*/
|
||||
if (strchr(dirs, '/') == NULL) {
|
||||
asprintf(&tmp, "usr/%s", dirs);
|
||||
if (tmp == NULL)
|
||||
errx(EX_UNAVAILABLE, "out of memory");
|
||||
if (mkdirat(dfd, tmp, _DEF_DIRMODE) != -1 || errno == EEXIST) {
|
||||
fchownat(dfd, tmp, 0, 0, 0);
|
||||
symlinkat(tmp, dfd, dirs);
|
||||
}
|
||||
free(tmp);
|
||||
}
|
||||
tmp = dirs;
|
||||
if (fstatat(dfd, dirs, &st, 0) == -1) {
|
||||
while ((tmp = strchr(tmp + 1, '/')) != NULL) {
|
||||
*tmp = '\0';
|
||||
if (fstatat(dfd, dirs, &st, 0) == -1) {
|
||||
if (mkdirat(dfd, dirs, _DEF_DIRMODE) == -1)
|
||||
err(EX_OSFILE, "'%s' (root home parent) is not a directory", dirs);
|
||||
err(EX_OSFILE, "'%s' (home parent) is not a directory", dirs);
|
||||
}
|
||||
*tmp = '/';
|
||||
}
|
||||
}
|
||||
if (fstatat(dfd, dirs, &st, 0) == -1) {
|
||||
if (mkdirat(dfd, dirs, _DEF_DIRMODE) == -1)
|
||||
err(EX_OSFILE, "'%s' (root home parent) is not a directory", dirs);
|
||||
err(EX_OSFILE, "'%s' (home parent) is not a directory", dirs);
|
||||
fchownat(dfd, dirs, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -295,15 +295,23 @@ user_add_R_body() {
|
||||
[ ! -d ${HOME}/home/bar ] || atf_fail "Directory not removed"
|
||||
}
|
||||
|
||||
atf_test_case user_add_R_symlink
|
||||
user_add_R_symlink_body() {
|
||||
atf_test_case user_add_R_no_symlink
|
||||
user_add_R_no_symlink_body() {
|
||||
populate_root_etc_skel
|
||||
|
||||
mkdir ${HOME}/usr
|
||||
atf_check -s exit:0 ${RPW} useradd foo -m
|
||||
test -d ${HOME}/usr/home || atf_fail "Home parent directory not created"
|
||||
test -h ${HOME}/home || atf_fail "/home directory is not a symlink"
|
||||
atf_check -s exit:0 -o inline:"usr/home\n" readlink ${HOME}/home
|
||||
[ ! -d ${HOME}/usr/home ] || atf_fail "/usr/home created"
|
||||
test -d ${HOME}/home || atf_fail "/home directory not created"
|
||||
}
|
||||
|
||||
atf_test_case user_add_R_intermed
|
||||
user_add_R_intermed_body() {
|
||||
populate_root_etc_skel
|
||||
|
||||
atf_check -s exit:0 ${RPW} useradd foo -m -d /a/b/c/foo
|
||||
test -d ${HOME}/a/b/c || atf_fail "intermediate directories not created"
|
||||
test -d ${HOME}/a/b/c/foo || atf_fail "user directory not created"
|
||||
}
|
||||
|
||||
atf_test_case user_add_skel
|
||||
@ -479,7 +487,8 @@ atf_init_test_cases() {
|
||||
atf_add_test_case user_add_invalid_group_entry
|
||||
atf_add_test_case user_add_password_from_h
|
||||
atf_add_test_case user_add_R
|
||||
atf_add_test_case user_add_R_symlink
|
||||
atf_add_test_case user_add_R_no_symlink
|
||||
atf_add_test_case user_add_R_intermed
|
||||
atf_add_test_case user_add_skel
|
||||
atf_add_test_case user_add_uid0
|
||||
atf_add_test_case user_add_uid_too_large
|
||||
|
Loading…
Reference in New Issue
Block a user