control tags -1 patch

thanks

The current useradd since 2019 has --btrfs-subvolume-home option.


$ useradd -h
Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]

Options:
...
      --btrfs-subvolume-home    use BTRFS subvolume for home directory
...
(Yes, its manpage may need to be updated)


All we need is to add it to the adduser wrapper.

Here is my first try to add it.  Please use this as a starting place.

I don't know if this option should be used for --system or not.  Now it
is enabled.  Please consider this point before adding this feature for
bulleseye+1=Bookworm

Regards,

Osamu





diff -Nru adduser-3.118.orig/adduser adduser-3.118/adduser
--- adduser-3.118.orig/adduser	2021-02-21 16:42:37.759786880 +0900
+++ adduser-3.118/adduser	2021-02-21 20:04:33.622833589 +0900
@@ -103,6 +103,7 @@
 our $special_home = undef;
 our $special_shell = undef;
 our $add_extra_groups = 0;
+our $btrfs_subvolume_home = 0;
 
 # Global variables we need later
 my $existing_user = undef;
@@ -141,6 +142,7 @@
 	    "conf=s" => \$configfile,
 	    "no-create-home" => \$no_create_home,
             "add_extra_groups" => \$add_extra_groups,
+	    "btrfs-subvolume-home" => sub { $btrfs_subvolume_home = 1 },
 	    "debug" => sub { $verbose = 2 } ) ) {
     &usage();
     exit RET_INVALID_CALL;
@@ -434,8 +436,13 @@
     $shell = $special_shell || '/usr/sbin/nologin';
     $undouser = $new_name;
     my $useradd = &which('useradd');
-    &systemcall($useradd, '-d', $home_dir, '-g', $ingroup_name, '-s',
-		$shell, '-u', $new_uid, $new_name);
+    if($btrfs_subvolume_home || $config{"btrfs_subvolume_home"}) {
+        &systemcall($useradd, '--btrfs-subvolume-home', '-d', $home_dir, '-g',
+                    $ingroup_name, '-s', $shell, '-u', $new_uid, $new_name);
+    } else {
+        &systemcall($useradd, '-d', $home_dir, '-g', $ingroup_name, '-s',
+                    $shell, '-u', $new_uid, $new_name);
+    }
     if(!$disabled_login) {
         my $usermod = &which('usermod');
         &systemcall($usermod, '-p', '*', $new_name);
@@ -524,8 +531,13 @@
 	$shell = $special_shell || $config{"dshell"};
     $undouser = $new_name;
     my $useradd = &which('useradd');
-    &systemcall($useradd, '-d', $home_dir, '-g', $ingroup_name, '-s',
-		$shell, '-u', $new_uid, $new_name);
+    if($btrfs_subvolume_home || $config{"btrfs_subvolume_home"}) {
+        &systemcall($useradd, '--btrfs-subvolume-home', '-d', $home_dir, '-g',
+                    $ingroup_name, '-s', $shell, '-u', $new_uid, $new_name);
+    } else {
+        &systemcall($useradd, '-d', $home_dir, '-g', $ingroup_name, '-s',
+                    $shell, '-u', $new_uid, $new_name);
+    }
     &invalidate_nscd();
 
     create_homedir (1); # copy skeleton data
diff -Nru adduser-3.118.orig/AdduserCommon.pm adduser-3.118/AdduserCommon.pm
--- adduser-3.118.orig/AdduserCommon.pm	2021-02-21 16:42:37.759786880 +0900
+++ adduser-3.118/AdduserCommon.pm	2021-02-21 17:24:07.189406049 +0900
@@ -212,6 +212,7 @@
   $configref->{"skel_ignore_regex"} = "dpkg-(old|new|dist)\$";
   $configref->{"extra_groups"} = "dialout cdrom floppy audio video plugdev users";
   $configref->{"add_extra_groups"} = 0;
+  $configref->{"btrfs_subvolume_home"} = 0;
 
   foreach( @$conflistref ) {
       read_config($_,$configref);
diff -Nru adduser-3.118.orig/adduser.conf adduser-3.118/adduser.conf
--- adduser-3.118.orig/adduser.conf	2021-02-21 16:42:37.759786880 +0900
+++ adduser-3.118/adduser.conf	2021-02-21 17:12:48.397892674 +0900
@@ -80,6 +80,9 @@
 # option above will be default behavior for adding new, non-system users
 #ADD_EXTRA_GROUPS=1
 
+# Setting this to something other than 0 (the default) will cause adduser
+# to use BTRFS subvolume for home directory
+#BTRFS_SUBVOLUME_HOME=1
 
 # check user and group names also against this regular expression.
 #NAME_REGEX="^[a-z][-a-z0-9_]*\$"
diff -Nru adduser-3.118.orig/doc/adduser.8 adduser-3.118/doc/adduser.8
--- adduser-3.118.orig/doc/adduser.8	2021-02-21 16:42:37.763786931 +0900
+++ adduser-3.118/doc/adduser.8	2021-02-21 17:03:41.383307131 +0900
@@ -285,6 +285,9 @@
 .B \-\-add_extra_groups
 Add new user to extra groups defined in the configuration file.
 .TP
+.B \-\-btrfs-subvolume-home
+Use BTRFS subvolume for home directory.
+.TP
 .B \-\-version
 Display version and copyright information.
 
diff -Nru adduser-3.118.orig/doc/adduser.conf.5 adduser-3.118/doc/adduser.conf.5
--- adduser-3.118.orig/doc/adduser.conf.5	2021-02-21 16:42:37.763786931 +0900
+++ adduser-3.118/doc/adduser.conf.5	2021-02-21 17:19:54.070588588 +0900
@@ -137,6 +137,10 @@
 \fBEXTRA_GROUPS\fB
 This is the list of groups that new non-system users will be added to.
 By default, this list is 'dialout cdrom floppy audio video plugdev users games'.
+.TP
+\fBBTRFS_SUBVOLUME_HOME\fB
+Setting this to something other than 0 (the default) will cause adduser
+to use BTRFS subvolume for home directory
 .SH NOTES
 .TP
 \fBVALID NAMES\fB

Reply via email to