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)
Thu, Jun 27, 4:01 PM
Unknown Object (File)
Sun, Jun 23, 8:36 AM
Unknown Object (File)
Mon, Jun 3, 7:08 PM
Unknown Object (File)
Mon, Jun 3, 4:26 PM
Unknown Object (File)
Mon, Jun 3, 2:55 PM
Unknown Object (File)
May 29 2024, 11:55 PM
Unknown Object (File)
May 27 2024, 6:15 PM
Unknown Object (File)
May 26 2024, 1:35 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 Not Applicable
Unit
Tests Not Applicable

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
132

Use kld_isloaded(3).

140

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

154

That won't work if the filesystem has snapshots.

155

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
140

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.

154

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
140

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
165

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
165

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

usr.sbin/pw/rm_r.c
165

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

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

48

These should be sorted in lexicographical order.

50

Move up to line 31.

usr.sbin/pw/rm_r.c
47

Move these up to line 29.

135

Do you mean “asbolute”?

153

Why not just compare path to f_mntonname?

155

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

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

48

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

usr.sbin/pw/rm_r.c
153

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