| Server IP : 193.86.120.172 / Your IP : 216.73.216.67 Web Server : Apache/2.4.63 (Unix) System : Linux JServices 3.10.108 #86003 SMP Wed Oct 22 13:20:46 CST 2025 x86_64 User : kubec ( 1026) PHP Version : 8.2.28 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /lib/sssd/sssd/ |
Upload File : |
#!/bin/bash
# Copyright (c) 2000-2020 Synology Inc. All rights reserved.
BIN_SYNOSYSTEMCTL="/usr/syno/bin/synosystemctl"
SERVICE_NAME="sssd"
sssd_db_cache_path="/var/lib/sss/db"
sssd_vol_cache_folder="@sssd_cache"
sssd_force_use_root_partition="/tmp/sssd_cache_force_use_root_partition"
SUPPORT_SOFS=`/usr/syno/bin/synogetkeyvalue /etc/synoinfo.conf support_hyper_converged`
logger_err()
{
logger -s -p user.warn -t "sssd.sh" "$@"
}
create_dir() {
mkdir -p "${1}"
chmod 700 "${1}"
}
get_first_volume() {
if [ -f "${sssd_force_use_root_partition}" ] || [ "yes" = "$SUPPORT_SOFS" ]; then
echo "${sssd_db_cache_path}"
return
fi
local vol_path
vol_path="$(/usr/syno/bin/servicetool --get-available-volume)"
if [ "$?" == "0" ]; then
vol_path="${sssd_db_cache_path}"
fi
echo ${vol_path}
}
get_sssd_vol_path() {
if [ ! -e ${sssd_db_cache_path} ]; then
return
fi
local -r cache_path="$(/bin/realpath ${sssd_db_cache_path})"
local -r vol_name="$(echo "${cache_path}" | awk -F'/' '{print $2}')"
echo "/${vol_name}"
}
is_systemd_service_enabled() {
local -r is_enable=$(/usr/syno/bin/synosystemctl get-enable-status "${1}")
if [ "${is_enable}" == "enabled" ]; then
return 0
fi
return 1
}
is_vol_avail_size_enough () {
local -r vol_avail_size="$(df -BM "${1}" | tail -1 | awk '{print $4}' | awk -F'M' '{print $1}')"
if [ "${vol_avail_size}" -ge "10" ]; then
return 0
fi
return 1
}
is_sssd_vol_cache_path_valid() {
local -r vol_path="$(get_sssd_vol_path)"
if [[ -z "${vol_path}" ]]; then
return 1
fi
# check volume path valid
if [ ! -e "${vol_path}" ] || [ "x${vol_path:0:7}" != "x/volume" ] \
|| ! /bin/grep -q "${vol_path}" "/proc/mounts"; then
return 1
fi
# check volume size is enough
if is_vol_avail_size_enough "${vol_path}"; then
return 0
fi
return 1
}
sssd_cache_path_setup() {
/bin/rm -rf ${sssd_db_cache_path}
local vol_path
if [ -e "${1}" ]; then ## hook script will source this file and use this function
vol_path="${1}"
else
vol_path="$(get_first_volume)"
fi
if [ "x${vol_path}" == "x${sssd_db_cache_path}" ]; then
logger_err "Can't find valid volume for db cache, use root partition."
create_dir "${sssd_db_cache_path}"
else
logger_err "Found valid volume for db cache. [${vol_path}]"
local -r sssd_vol_cache_path="${vol_path}/${sssd_vol_cache_folder}"
rm -rf "${sssd_vol_cache_path}"
create_dir "${sssd_vol_cache_path}"
ln -s "${sssd_vol_cache_path}" ${sssd_db_cache_path}
fi
}
sss_volume_dependency() {
local -r action=${1}
local -r vol_path="$(get_sssd_vol_path)"
if [ "x${vol_path:0:7}" = "x/volume" ]; then
${BIN_SYNOSYSTEMCTL} ${action} ${SERVICE_NAME} ${vol_path}
fi
}
sss_prestart_sssd() {
/bin/chmod 644 "/etc/sssd/sssd.conf"
/bin/find "/etc/sssd/conf.d" -type f -exec /usr/bin/chmod 644 {} \;
# Drop cache when booting up
if /usr/syno/bin/synobootseq --is-booting-up > /dev/null 2>&1 ; then
/bin/rm -rf "${sssd_db_cache_path}"
fi
if ! is_sssd_vol_cache_path_valid ; then
sssd_cache_path_setup
fi
sss_volume_dependency "register-volume"
}
sss_poststart_sssd() {
/bin/rm -f "${sssd_force_use_root_partition}"
}
sss_poststop_sssd() {
# If db cache in root partition, it should be clear when sssd stop.
if is_sssd_vol_cache_path_valid ; then
sss_volume_dependency "unregister-volume"
return
fi
/bin/rm -rf ${sssd_db_cache_path}
}
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
if [ $# -eq 0 ]; then
exit 1
else
action="$1"; shift
fi
case ${action} in
prestart)
sss_prestart_sssd
;;
poststart)
sss_poststart_sssd
;;
poststop)
sss_poststop_sssd
;;
*)
echo "Wrong argument"
exit 1
;;
esac
fi
# vim: noet: ts=4: sw=4: