Page MenuHomeFreeBSD

pw: set the user's home directory mode if it existed
AcceptedPublic

Authored by kevans on Aug 26 2024, 11:10 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Sep 20, 3:47 PM
Unknown Object (File)
Wed, Sep 11, 3:45 PM
Unknown Object (File)
Wed, Sep 11, 8:26 AM
Unknown Object (File)
Tue, Sep 10, 4:25 PM
Unknown Object (File)
Mon, Sep 9, 10:08 AM
Unknown Object (File)
Mon, Sep 9, 8:22 AM
Unknown Object (File)
Sep 1 2024, 10:40 AM
Unknown Object (File)
Aug 30 2024, 7:43 PM

Details

Summary

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

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Note that pw useradd/usermod -M should have a similar fix.
I'll see if adding a test is feasible (over the weekend).
Thank you!

Could you also change the manpage to indicate that:

.It Fl M Ar mode
Create the home directory with permissions set to
.Ar mode ,
modified by the current
.Xr umask 2 .

To match pw(8)'s description. And let users know that if they try -M 0777, and the umask is 022 (default), they'll still get 0755.

This revision is now accepted and ready to land.Aug 26 2024, 11:26 PM

First draft of test.

First draft of test.

JFYI- I can't see what this is referencing. In the "Referenced Files" section on the right, I can see:

Restricted File
Mon, Aug 26, 20:38

which lines up with the timestamp on your comment, so I guess permissions aren't set on it somehow.

First draft of test.

JFYI- I can't see what this is referencing. In the "Referenced Files" section on the right, I can see:

Restricted File
Mon, Aug 26, 20:38

which lines up with the timestamp on your comment, so I guess permissions aren't set on it somehow.

Forgive my ignorance on Phabricator, I believe it is OK now.

Test looks reasonable to me, incorporating it as:

commit 73f91ff94577a61194702b9f5235233aa4aa7d2c
Author: Jose Luis Duran <jlduran@gmail.com>
Date:   Tue Aug 27 10:03:09 2024 -0500

    pw: tests: add a test for -M with a pre-existing home directory
    
    Previous versions of pw(8) wouldn't chmod the home directory if it
    already existed prior to user creation, rendering adduser(8) -M
    ineffective in some cases.  Add a test to cover that situation.
    
    PR:             280099

While we're here, note in the adduser(8) documentation that -M is subject to the process umask.

This revision now requires review to proceed.Aug 27 2024, 3:34 PM

First draft of test.

JFYI- I can't see what this is referencing. In the "Referenced Files" section on the right, I can see:

Restricted File
Mon, Aug 26, 20:38

which lines up with the timestamp on your comment, so I guess permissions aren't set on it somehow.

Forgive my ignorance on Phabricator, I believe it is OK now.

IMO for a review tool, it's weird that the permissions of an attached file didn't default to the permissions of the review object it's being attached to. That's not the kind of thing I'd expect to have to audit as an uploader when I'm trying to participate in a review.

des requested changes to this revision.Aug 27 2024, 4:21 PM
des added inline comments.
usr.sbin/pw/cpdir.c
63

We should warn if this fails, imo.

This revision now requires changes to proceed.Aug 27 2024, 4:21 PM
usr.sbin/pw/cpdir.c
63

I had considered the same, but couldn't reconcile that with also failing to check either of the below fchownat/chflagsat. Probably all three should be checked.

Issue warnings for any permission change failures- they're not fatal, but the admin should know about them in case there's a legitimate issue.

This revision is now accepted and ready to land.Aug 29 2024, 9:54 AM