# Interpreter: sh
########################################################################
#
. $VENUSFUNCTIONS
#
########################################################################
#
# Method ssh-x11-forward
#
# Default to X11 forwarding in system-wide ssh_config.
# Allow X11 forwarding in ssh daemon config.
#
# Methods:	bsl_restart_service
#		  Called unconditionally to restart ssh daemon.
# Contexts:	ssh-x11-forward
# Variables:	confdir
#		  Location of ssh config files. Defaults to /etc/ssh.
#
###########################################################################

confdir=/etc/ssh
venus_import_variable -F confdir

if ! test -d "$confdir"; then
	venus_print_message ERROR \
		"$confdir: not found. Aborting."
	exit 1
fi

if test "$installflag" = "i"; then
	venus_save_file "$confdir"/sshd_config
	venus_replace_in_file "$confdir"/sshd_config \
		'^X11Forwarding.*' 'X11Forwarding yes'

	venus_delete_part ssh-x11-forward "$confdir"/ssh_config
	venus_insert_part "$confdir"/ssh_config unused \
'Host *
	ForwardX11 yes
' \
	ssh-x11-forward end
elif test "$installflag" = "u"; then
	venus_delete_part ssh-x11-forward "$confdir"/ssh_config
	venus_restore_file "$confdir"/sshd_config
fi

venus_run_method bsl_restart_service ssh

exit 0
