This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch release/4.0.1.x
in repository x2goserver.

commit 6d87b749f5fd108498a44a243045186b03fde49f
Author: Mihai Moldovan <[email protected]>
Date:   Wed Nov 1 09:33:28 2017 +0100

    x2goserver/bin/x2goresume-session: backport HOSTNAME changes from 
x2goserver/bin/x2gostartagent.
---
 debian/changelog                  |  2 ++
 x2goserver/bin/x2goresume-session | 39 +++++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d20b570..b707326 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -52,6 +52,8 @@ x2goserver (4.0.1.21-0x2go1) UNRELEASED; urgency=medium
     - x2goserver/bin/x2goruncommand: use dbus-run-session to start a new dbus
       user session if available. Only for full desktop sessions. Backported
       from a Debian patch.
+    - x2goserver/bin/x2goresume-session: backport HOSTNAME changes from
+      x2goserver/bin/x2gostartagent.
   * x2goserver.spec:
     - Add mandatory perl-generators Build-Requires as per
       https://fedoraproject.org/wiki/Changes/Build_Root_Without_Perl
diff --git a/x2goserver/bin/x2goresume-session 
b/x2goserver/bin/x2goresume-session
index a90edc8..8ac0fa6 100755
--- a/x2goserver/bin/x2goresume-session
+++ b/x2goserver/bin/x2goresume-session
@@ -44,6 +44,33 @@ X2GO_ROOT="${HOME}/.x2go"
 X2GO_RESIZE=1
 X2GO_FULLSCREEN=0
 
+# ${HOSTNAME} should be automatically set by bash via gethostname(2), IFF this
+# variable is not already set in the environment.
+#
+# This leads to two problems:
+#   - export HOSTNAME="malbox"; x2gostartagent will override the actual system
+#     host name and lead to authorization failures when connecting to
+#     x2goagent/nxagent later on.
+#   - even if the above is not the case, the value returned by gethostname(2)
+#     could either be a FQDN, the short name or anything in between. glibc
+#     seems to return the short name on Linux, since it calls uname(2), which
+#     typically does not include a domain, but *BSD seems to default to
+#     the FQDN. We explicitly need the short name.
+#
+# Workaround: use hostname -s, which luckily is portable enough to be available
+# on a wide variety of systems.
+typeset current_host_name=""
+current_host_name="$(hostname -s)"
+
+if [[ "${?}" -ne "0" ]]; then
+       typeset msg="Unable to retrieve machine's hostname. This is required. 
Aborting session startup."
+       "${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "${msg}"
+
+       # Make x2goclient fail.
+       echo "${msg}" >&2
+       exit 1
+fi
+
 # refresh up ssh-agent-forwarding socket file symlink
 X2GOSSH_AUTH_SOCK="$X2GO_ROOT/C-$SESSION_NAME/ssh-agent.PID"
 if [ -L "$X2GOSSH_AUTH_SOCK" ]; then
@@ -149,24 +176,24 @@ USED_PORTS=$(
 #check if saved in DB ports free
 if grep -q "|${GR_PORT}|" <<<$SYSTEM_PORTS ; then
        $X2GO_LIB_PATH/x2gosyslog "$0" "debug" "port $GR_PORT is already in use"
-       $X2GO_LIB_PATH/x2gormport "$HOSTNAME" "$SESSION_NAME" "$GR_PORT"
+       "${X2GO_LIB_PATH}/x2gormport" "${current_host_name}" "${SESSION_NAME}" 
"${GR_PORT}"
        GR_PORT=""
 fi
 if grep -q "|${SOUND_PORT}|" <<<$SYSTEM_PORTS ; then
        $X2GO_LIB_PATH/x2gosyslog "$0" "debug" "port $SOUND_PORT is already in 
use"
-       $X2GO_LIB_PATH/x2gormport "$HOSTNAME" "$SESSION_NAME" "$SOUND_PORT"
+       "${X2GO_LIB_PATH}/x2gormport" "${current_host_name}" "${SESSION_NAME}" 
"${SOUND_PORT}"
        SOUND_PORT=""
 fi
 if grep -q "|${FS_PORT}|" <<<$SYSTEM_PORTS ; then
        $X2GO_LIB_PATH/x2gosyslog "$0" "debug" "port "$FS_PORT" is already in 
use"
-       $X2GO_LIB_PATH/x2gormport "$HOSTNAME" "$SESSION_NAME" "$FS_PORT"
+       "${X2GO_LIB_PATH}/x2gormport" "${current_host_name}" "${SESSION_NAME}" 
"${FS_PORT}"
        FS_PORT=""
 fi
 
 SSH_PORT=30000 #First ssh port 30001
 
 #Get all used in system ports from X2Go database and netstat output
-USED_PORTS=`$X2GO_LIB_PATH/x2gogetports "$HOSTNAME"; netstat -nt -all | awk '{ 
n=split($0,lines,"\n"); for(i=1;i<=n;i++){split (lines[i],words," 
");delim=split(words[4],ports,":"); if(delim>1)printf ("|%s|\n",ports[delim])} 
}'`
+USED_PORTS="$("${X2GO_LIB_PATH}/x2gogetports" "${current_host_name}"; netstat 
-nt -all | awk '{ n=split($0,lines,"\n"); for(i=1;i<=n;i++){split 
(lines[i],words," ");delim=split(words[4],ports,":"); if(delim>1)printf 
("|%s|\n",ports[delim])} }')"
 
 while [ "$GR_PORT" == "" ] || [ "$SOUND_PORT" == "" ] || [ "$FS_PORT" == "" ]; 
do
        OUTPUT=""
@@ -179,7 +206,7 @@ while [ "$GR_PORT" == "" ] || [ "$SOUND_PORT" == "" ] || [ 
"$FS_PORT" == "" ]; d
                #check if port in /etc/services
                SERV=`grep $SSH_PORT /etc/services`
                if [ "$SERV" == "" ]; then
-                       OUTPUT=`$X2GO_LIB_PATH/x2goinsertport "$HOSTNAME" 
"$SESSION_NAME" "$SSH_PORT"`
+                       OUTPUT="$("${X2GO_LIB_PATH}/x2goinsertport" 
"${current_host_name}" "$SESSION_NAME" "$SSH_PORT")"
                fi
        done
        if [ "$GR_PORT" == "" ]; then
@@ -245,7 +272,7 @@ fi
 X2GO_CLIENT=`echo "$SSH_CLIENT" | awk '{print $1}'`
 if [ "$X2GO_CLIENT" == "" ]
 then
-       X2GO_CLIENT="$HOSTNAME"
+       X2GO_CLIENT="${current_host_name}"
 fi
 
 echo "$NEWOPTIONS" >"${SESSION_DIR}/options"

--
Alioth's /srv/git/code.x2go.org/x2goserver.git//..//_hooks_/post-receive-email 
on /srv/git/code.x2go.org/x2goserver.git
_______________________________________________
x2go-commits mailing list
[email protected]
https://lists.x2go.org/listinfo/x2go-commits

Reply via email to