From a1dfce0d4c6d09c05ef18ca814bf3e9181c13bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Wed, 16 Sep 2020 21:42:56 +0200 Subject: [PATCH] add tokenforwarding for etoken and x2go --- bashrc_add | 3 ++ myshell_load_x2go_tokenforward | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 myshell_load_x2go_tokenforward diff --git a/bashrc_add b/bashrc_add index 81e954c..4445a18 100755 --- a/bashrc_add +++ b/bashrc_add @@ -127,6 +127,9 @@ EOF # source loading defaults part of myshellconfig . "${MYSHELLCONFIG_BASE}/myshell_load_defaults" + # source loading workaround for x2go to forward local etoken to remote machine with forwardagent + . "${MYSHELLCONFIG_BASE}/myshell_load_x2go_tokenforward" + cat << EOF >> "${MYSHELLCONFIG_LOGFILE}" --8<--- end ---------------- $(date) ---------------8<-- diff --git a/myshell_load_x2go_tokenforward b/myshell_load_x2go_tokenforward new file mode 100644 index 0000000..358277c --- /dev/null +++ b/myshell_load_x2go_tokenforward @@ -0,0 +1,52 @@ +# --- BEGIN X2Go SSH forwarding workaround --- + + +# Part that runs in regular SSH session + +# check we have an agent socket and +# check we have an ~/.x2go directory +echo "SSH_AUTH_SOCK: ${SSH_AUTH_SOCK-x} - ${SSH_AUTH_SOCK+x} - ${SSH_AUTH_SOCK}" +if [ -n "$SSH_AUTH_SOCK" ] && \ + [ -d ~/.x2go ] && \ + [ -z "$X2GO_AGENT_PID" ] ; then + # touch the output file and set permissions + # (as tight as possible) + touch ~/.x2go/agentsocket + chmod 600 ~/.x2go/agentsocket + chown $USER ~/.x2go/agentsocket + # write file name of agent socket into file + echo old agentsock + cat ~/.x2go/agentsocket + echo $SSH_AUTH_SOCK >~/.x2go/agentsocket + echo "write SSH_AUTH_SOCK to ~/.x2go/agentsocket" +fi + +# Part that runs in X2Go session + +# check we're on an X2GoServer (x2golistsessions is in path), +# check we have a DISPLAY set, and +# check our client DISPLAY and SSH client IP correspond to +# a running X2Go session and +# check ~/.x2go/agentsocket is a regular file +if which x2golistsessions >/dev/null && \ + [ -n "$DISPLAY" ] && \ + [ -n "$(x2golistsessions | \ + awk -F '|' '":"$3 == "'$DISPLAY'" && \ + $5 == "R" && \ + $8 == "'$(echo $SSH_CLIENT | \ + awk '{print $1}')'" { print $3 }')" ] && \ + [ -f ~/.x2go/agentsocket ] ; then + # all checks passed, read content of file + # (might still contain stale agent socket or garbage + MIGHTBEOURAGENT=$(cat ~/.x2go/agentsocket) + # check if it corresponds to an existing socket + echo "MIGHTBEOURAGENT: $MIGHTBEOURAGENT" + if [ -S "$MIGHTBEOURAGENT" ]; then + # export path to agent socket + export SSH_AUTH_SOCK=$MIGHTBEOURAGENT + echo export it + fi +fi + + +# ---- END X2Go SSH forwarding workaround ----