mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
pw: set the user's home directory mode if it existed
The adduser(8) prompt allows one to set the mode of a new home
directory, but pw(8) doesn't honor the -M mode if the home directory
already exists at creation time. It doesn't seem to make sense to
ignore the mode (which may lead to a security issue on the system being
configured) when we'll happily chown an existing directory, so fix the
inconsistency.
PR: 280099
Reviewed by: des, jlduran (previous version)
(cherry picked from commit 6a7238fd7c)
This commit is contained in:
1 parent
7ea2874ead
commit
b50d2127d9
2 files changed
+25
-8
No files matched your search
@@ -27,7 +27,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd April 11, 2024
|
||||
.Dd December 1, 2024
|
||||
.Dt ADDUSER 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@@ -246,7 +246,9 @@ file can reference the internal variables of the
|
||||
script.
|
||||
.It Fl M Ar mode
|
||||
Create the home directory with permissions set to
|
||||
.Ar mode .
|
||||
.Ar mode ,
|
||||
modified by the current
|
||||
.Xr umask 2 .
|
||||
.It Fl N
|
||||
Do not read the default configuration file.
|
||||
.It Fl q
|
||||
|
||||
+21
-6
@@ -49,13 +49,28 @@ copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid,
|
||||
if (*dir == '/')
|
||||
dir++;
|
||||
|
||||
if (mkdirat(rootfd, dir, mode) != 0 && errno != EEXIST) {
|
||||
warn("mkdir(%s)", dir);
|
||||
return;
|
||||
if (mkdirat(rootfd, dir, mode) != 0) {
|
||||
mode_t pumask;
|
||||
|
||||
if (errno != EEXIST) {
|
||||
warn("mkdir(%s)", dir);
|
||||
return;
|
||||
}
|
||||
|
||||
pumask = umask(0);
|
||||
umask(pumask);
|
||||
|
||||
if (fchmodat(rootfd, dir, mode & ~pumask,
|
||||
AT_SYMLINK_NOFOLLOW) == -1)
|
||||
warn("chmod(%s)", dir);
|
||||
}
|
||||
fchownat(rootfd, dir, uid, gid, AT_SYMLINK_NOFOLLOW);
|
||||
if (flags > 0)
|
||||
chflagsat(rootfd, dir, flags, AT_SYMLINK_NOFOLLOW);
|
||||
|
||||
if (fchownat(rootfd, dir, uid, gid, AT_SYMLINK_NOFOLLOW) == -1)
|
||||
warn("chown(%s)", dir);
|
||||
|
||||
if (flags > 0 && chflagsat(rootfd, dir, flags,
|
||||
AT_SYMLINK_NOFOLLOW) == -1)
|
||||
warn("chflags(%s)", dir);
|
||||
|
||||
if (skelfd == -1)
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user