@@ -4,6 +4,7 @@ set -e -o pipefail
44
55RSYNC_PID_FILE=/tmp/rsyncd.pid
66CONTROL_FILE=/tmp/control/complete
7+ CONTROL_FILE_SYMLINK_MUNGING_FILE=/tmp/control/symlink-munging-file
78RSYNCD_CONF=/tmp/rsyncd.conf
89STUNNEL_CONF=/tmp/stunnel.conf
910STUNNEL_PID_FILE=/tmp/stunnel.pid
@@ -110,7 +111,7 @@ log file = $RSYNC_LOG
110111max verbosity = 10
111112use chroot = false
112113numeric ids = true
113- munge symlinks = false
114+ munge symlinks = true
114115open noatime = true
115116reverse lookup = false
116117transfer logging = true
@@ -166,6 +167,7 @@ STUNNEL_CONF
166167 TAIL_PID=" $! "
167168
168169 rm -f " $CONTROL_FILE "
170+ rm -f " $CONTROL_FILE_SYMLINK_MUNGING_FILE "
169171fi
170172
171173if test -b $BLOCK_TARGET ; then
@@ -218,6 +220,29 @@ done
218220
219221sleep 5 # Give time for the rsync connection to finish
220222
223+ # Before shutting down, read the symlink munging file if it exists, and process
224+ if [[ -s $CONTROL_FILE_SYMLINK_MUNGING_FILE ]]; then
225+ echo " Symlink munging file found, processing..."
226+ # while read -r symlink; do
227+ while IFS= read -r symlink; do
228+ symlinkfullpath=" ${TARGET} /${symlink} "
229+ echo " Processing symlink: ${symlinkfullpath} "
230+
231+ symlink_uid_gid=" "
232+ if [[ $PRIVILEGED_MOVER -ne 0 ]]; then
233+ # If privileged mover, save uid/gid of the symlink for later
234+ symlink_uid_gid=$( stat -c ' %u:%g' " ${symlinkfullpath} " )
235+ fi
236+
237+ munge-symlinks --unmunge " ${symlinkfullpath} "
238+
239+ if [[ $PRIVILEGED_MOVER -ne 0 && -n " ${symlink_uid_gid} " ]]; then
240+ # If privileged mover, restore uid/gid of the symlink after unmunging
241+ chown -h " ${symlink_uid_gid} " " ${symlinkfullpath} "
242+ fi
243+ done < " $CONTROL_FILE_SYMLINK_MUNGING_FILE "
244+ fi
245+
221246# #############################
222247# # Terminate stunnel
223248echo " Shutting down..."
0 commit comments