@@ -114,6 +114,7 @@ static const char *def_shell = "/bin/bash";
114114static const char * def_template = SKEL_DIR ;
115115static const char * def_usrtemplate = USRSKELDIR ;
116116static const char * def_create_mail_spool = "yes" ;
117+ static const char * def_btrfs_subvolume_home = "no" ;
117118static const char * def_log_init = "yes" ;
118119
119120static long def_inactive = -1 ;
@@ -222,6 +223,7 @@ static bool home_added = false;
222223#define DSKEL "SKEL"
223224#define DUSRSKEL "USRSKEL"
224225#define DCREATE_MAIL_SPOOL "CREATE_MAIL_SPOOL"
226+ #define DBTRFS_SUBVOLUME_HOME "BTRFS_SUBVOLUME_HOME"
225227#define DLOG_INIT "LOG_INIT"
226228
227229/* local function prototypes */
@@ -456,6 +458,7 @@ get_defaults(const struct option_flags *flags)
456458 def_usrtemplate = xstrdup (ccp );
457459 }
458460 }
461+
459462 /*
460463 * Create by default user mail spool or not ?
461464 */
@@ -466,6 +469,15 @@ get_defaults(const struct option_flags *flags)
466469 def_create_mail_spool = xstrdup (ccp );
467470 }
468471
472+ /*
473+ * Create home directories as Btrfs subvolumes by default?
474+ */
475+ else if (streq (buf , DBTRFS_SUBVOLUME_HOME )) {
476+ if (streq (ccp , "" ))
477+ ccp = "no" ;
478+ def_btrfs_subvolume_home = xstrdup (ccp );
479+ }
480+
469481 /*
470482 * By default do we add the user to the lastlog and faillog databases ?
471483 */
@@ -500,6 +512,7 @@ static void show_defaults (void)
500512 printf ("SKEL=%s\n" , def_template );
501513 printf ("USRSKEL=%s\n" , def_usrtemplate );
502514 printf ("CREATE_MAIL_SPOOL=%s\n" , def_create_mail_spool );
515+ printf ("BTRFS_SUBVOLUME_HOME=%s\n" , def_btrfs_subvolume_home );
503516 printf ("LOG_INIT=%s\n" , def_log_init );
504517}
505518
@@ -523,6 +536,7 @@ set_defaults(void)
523536 bool out_skel = false;
524537 bool out_usrskel = false;
525538 bool out_create_mail_spool = false;
539+ bool out_btrfs_subvolume_home = false;
526540 bool out_log_init = false;
527541 char buf [1024 ];
528542 char * new_file = NULL ;
@@ -639,6 +653,11 @@ set_defaults(void)
639653 DCREATE_MAIL_SPOOL "=%s\n" ,
640654 def_create_mail_spool );
641655 out_create_mail_spool = true;
656+ } else if (!out_btrfs_subvolume_home && streq (buf , DBTRFS_SUBVOLUME_HOME )) {
657+ fprintf (ofp ,
658+ DBTRFS_SUBVOLUME_HOME "=%s\n" ,
659+ def_btrfs_subvolume_home );
660+ out_btrfs_subvolume_home = true;
642661 } else if (!out_log_init && streq (buf , DLOG_INIT )) {
643662 fprintf (ofp , DLOG_INIT "=%s\n" , def_log_init );
644663 out_log_init = true;
@@ -673,6 +692,8 @@ set_defaults(void)
673692
674693 if (!out_create_mail_spool )
675694 fprintf (ofp , DCREATE_MAIL_SPOOL "=%s\n" , def_create_mail_spool );
695+ if (!out_btrfs_subvolume_home )
696+ fprintf (ofp , DBTRFS_SUBVOLUME_HOME "=%s\n" , def_btrfs_subvolume_home );
676697 if (!out_log_init )
677698 fprintf (ofp , DLOG_INIT "=%s\n" , def_log_init );
678699 /*
@@ -1431,6 +1452,9 @@ static void process_flags (int argc, char **argv, struct option_flags *flags)
14311452 }
14321453 }
14331454
1455+ if (!subvolflg && strcaseeq (def_btrfs_subvolume_home , "yes" ))
1456+ subvolflg = true;
1457+
14341458 if (!gflg && !Nflg && !Uflg ) {
14351459 /* Get the settings from login.defs */
14361460 Uflg = getdef_bool ("USERGROUPS_ENAB" );
0 commit comments