From 13a70e7d4eef151b80dcdc2567486209a6bd5312 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Tue, 31 May 2016 09:10:54 -0300 Subject: [PATCH] Copy users config files from skeleton dir Every time user is added or modified, make sure all default config files are copied over from /etc/skel to user's home. It will make sure users will always get the last version of these files --- src/etc/inc/auth.inc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/etc/inc/auth.inc b/src/etc/inc/auth.inc index 5731c84dd6..48d9c2e736 100644 --- a/src/etc/inc/auth.inc +++ b/src/etc/inc/auth.inc @@ -548,9 +548,11 @@ function local_user_set(& $user) { pclose($fd); $userattrs = explode(":", trim($pwread)); + $skel_dir = '/etc/skel'; + /* determine add or mod */ if (($userattrs[0] != $user['name']) || (!strncmp($pwread, "pw:", 3))) { - $user_op = "useradd -m -k /etc/skel -o"; + $user_op = "useradd -m -k {$skel_dir} -o"; } else { $user_op = "usermod"; } @@ -579,6 +581,14 @@ function local_user_set(& $user) { @chown($user_home, $user_name); @chgrp($user_home, $user_group); + /* Make sure all users have last version of config files */ + foreach (glob("{$skel_dir}/dot.*") as $dot_file) { + $target = $user_home . '/' . substr(basename($dot_file), 3); + @copy($dot_file, $target); + @chown($target, $user_name); + @chgrp($target, $user_group); + } + /* write out ssh authorized key file */ if ($user['authorizedkeys']) { if (!is_dir("{$user_home}/.ssh")) {