HEX
Server: Apache/2.4.63 (Unix)
System: Linux Synopilou92 4.4.302+ #72806 SMP Mon Jul 21 23:16:00 CST 2025 x86_64
User: pilou92 (1026)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: //usr/syno/plugin/dirsvs_leave/domain_leave.sh
#!/bin/sh
case $1 in
	--sdk-mod-ver)
	#Print SDK support version
	echo "1.0";
	;;
	--name)
	#Print package name
	echo "domain_leave";
	;;
	--pkg-ver)
	#Print package version
	echo "1.0";
	;;
	--vendor)
	#Print package vendor
	echo "Synology";
	;;
	--pre)
        ;;
	--post)
		# only for domain
		if [ "$TYPE" != "domain" ]; then
			exit 0
		fi

		# check still join Domain
		if [ ! -f "/var/packages/SMBService/conf/systemd/winbindd.sh" ]; then
			# SMB Service not exist or script not exist ? NO SMB no domain...
			exit 0
		fi
		if /var/packages/SMBService/conf/systemd/winbindd.sh is_domain_mode ; then
			# leave domain still in domain ?
			exit 0
		fi

		# unlink domain info file
		rm /usr/syno/etc/private/domain_* \
			/usr/syno/etc/private/trust_domain_info* \
			/usr/syno/etc/private/pdc_ip \
			/usr/syno/etc/private/kdc_ip \
			/usr/syno/etc/private/adsinfo \
			/usr/syno/etc/private/last_join_info \
			/usr/syno/etc/private/workgroup* \
			/run/samba/winbind_domain* \
			/etc/samba/smb.join.conf \
			/etc/samba/synodomain.conf \
			/etc/krb5.conf \
			/tmp/domain_build_status

		# unlink build flag & kill process
		if [ -f "/tmp/domain_user.pid" ]; then
			BUILDDB_PID=$(cat /tmp/domain_user.pid)
			if grep winbindd "/proc/${BUILDDB_PID}/cmdline" > /dev/null 2>&1; then
				kill -9 "${BUILDDB_PID}"
			fi
		fi
		if [ -f "/tmp/domain_group.pid" ]; then
			BUILDDB_PID=$(cat /tmp/domain_group.pid)
			if grep winbindd "/proc/${BUILDDB_PID}/cmdline" > /dev/null 2>&1; then
				kill -9 "${BUILDDB_PID}"
			fi
		fi

		rm /tmp/domain_updating \
			/tmp/domain_user.pid \
			/tmp/domain_group.pid

		# unlink winbind cache
		rm "/var/lib/samba/winbindd_cache.tdb" "/var/cache/samba/winbindd_cache.tdb"
		for FILE in /volume*/winbindd_cache.tdb
		do
			if [ -f "$FILE" ]; then
				rm "$FILE"
			fi
		done

		# unlink db
		rm "/usr/syno/etc/private/.db.domain"*
		for FILE in /volume*/@accountdb/.db.domain* /volume*/@accountdb/full.* /volume*/@accountdb/dirsync.* /volume*/@accountdb/member.*
		do
			if [ -f "$FILE" ]; then
				rm "$FILE"
			fi
		done
	;;
	*)
	echo "Usage: $0 --sdk-mod-ver|--name|--pkg-ver|--vendor|--pre|--post"
	;;
esac