Skip to content

Commit f381edb

Browse files
author
damien cavagnini
committed
fix: check configuration management
fix bug where a configuration file was systematicly deleted then recreated if it was a link. Update logic to not systematicaly update the link, only if it is not correct. Because if you run the debian-cis checks with a non root user, this will fail.
1 parent 9ae5aef commit f381edb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/main.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ if ! [ -r "${CIS_CONF_DIR}"/conf.d/"$cfg_file" ]; then
102102
fi
103103

104104
if [ -n "$cfg_link" ]; then
105-
if [ -f "${CIS_CONF_DIR}"/conf.d/"$cfg_link" ]; then
105+
if [ ! -L "${CIS_CONF_DIR}"/conf.d/"$cfg_link" ]; then
106106
rm -f "${CIS_CONF_DIR}"/conf.d/"$cfg_link"
107+
ln -s "${CIS_CONF_DIR}"/conf.d/"$cfg_file" "${CIS_CONF_DIR}"/conf.d/"$cfg_link"
108+
# make sure the existing link points to the correct file
109+
elif [[ $(readlink -f "${CIS_CONF_DIR}"/conf.d/"$cfg_link") != "${CIS_CONF_DIR}"/conf.d/"$cfg_file" ]]; then
110+
ln -fs "${CIS_CONF_DIR}"/conf.d/"$cfg_file" "${CIS_CONF_DIR}"/conf.d/"$cfg_link"
107111
fi
108-
ln -fs "${CIS_CONF_DIR}"/conf.d/"$cfg_file" "${CIS_CONF_DIR}"/conf.d/"$cfg_link"
109112
fi
110113

111114
if [ "$forcedstatus" = "createconfig" ]; then

0 commit comments

Comments
 (0)