Page MenuHomeFreeBSD

pw userdel: destroy home dataset if empty
ClosedPublic

Authored by karels on May 24 2024, 8:54 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 11, 5:30 PM
Unknown Object (File)
Mon, Nov 11, 4:27 PM
Unknown Object (File)
Mon, Nov 11, 4:24 PM
Unknown Object (File)
Mon, Nov 11, 4:23 PM
Unknown Object (File)
Mon, Nov 11, 4:14 PM
Unknown Object (File)
Fri, Nov 8, 3:45 AM
Unknown Object (File)
Thu, Nov 7, 4:56 AM
Unknown Object (File)
Fri, Oct 18, 10:58 AM
Subscribers
None

Details

Summary

When removing a user's home directory, if the directory is a ZFS
dataset, it cannot be removed. If the directory has been emptied,
use "zfs destroy" to destroy it. This complements the automatic
dataset creation in adduser. Note that datasets within the directory
and snapshots are not handled, as the complete path is not constructed.

While here, add waitpid() calls to rmat() and pw_user_del().

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 57902
Build 54790: arc lint + arc unit

Event Timeline

karels created this revision.

It would be nice to have some tests for this, but I haven't figured out how to do it. It appears that it would be necessary to create a zpool on a memory disk for the purpose, and of course to clean it up after the tests. Suggestions welcome.

des requested changes to this revision.May 25 2024, 7:16 AM
des added inline comments.
usr.sbin/pw/rm_r.c
125

Use kld_isloaded(3).

133

Wouldn't it be simpler to statfs(home, &buf) and check that f_fstypename is "zfs" and f_mntonname is identical to home?

147

That won't work if the filesystem has snapshots.

148

Please use posix_spawn(3) or posix_spawnp(3) instead.

This revision now requires changes to proceed.May 25 2024, 7:16 AM

I'll take care of the other items later today.

usr.sbin/pw/rm_r.c
133

zfs list translates from a file system name to a pool name, e.g. /home -> zroot/home. There may be other ways to do this, but this works.

147

In that case, it seems best not to destroy it. As the man page says. additional cleanup is left to the user. We could use destroy -r, which would also do contained datasets, but that doesn't seem conservative enough.

switch to zfs_unload(), posix_spawn()

usr.sbin/pw/rm_r.c
133

So does statfs(2), the dataset name will be in f_mntfromname.

des requested changes to this revision.May 25 2024, 3:12 PM
des added inline comments.
usr.sbin/pw/rm_r.c
158

You should collect the child before returning.

This revision now requires changes to proceed.May 25 2024, 3:12 PM
usr.sbin/pw/rm_r.c
158

I wondered about that, but rmat() (pw_user.c) does not. Should I add it there too?

usr.sbin/pw/rm_r.c
158

Yes, and in pw_user_del() as well please. I don't think we need to bother checking the status though.

Add waitpid calls for each posix_spawn; use statfs.

usr.sbin/pw/pw_user.c
31 ↗(On Diff #139095)

Redundant, <sys/param.h> includes <sys/types.h>.

48 ↗(On Diff #139095)

These should be sorted in lexicographical order.

50 ↗(On Diff #139095)

Move up to line 31.

usr.sbin/pw/rm_r.c
41

Move these up to line 29.

128

Do you mean “asbolute”?

146

Why not just compare path to f_mntonname?

148

We have basename(3) for this.

karels marked 4 inline comments as done.
karels edited the summary of this revision. (Show Details)

Address review comments.

usr.sbin/pw/pw_user.c
31 ↗(On Diff #139095)

I didn't add these, or even modify this file much. But I'll be adding another include in that spot...

48 ↗(On Diff #139095)

I think that's a bigger change than I should include with my change.

usr.sbin/pw/rm_r.c
146

I was just thinking about the final component, but f_mntonname is better.

This revision is now accepted and ready to land.May 29 2024, 5:04 PM