[X2Go-Commits] [x2goserver] 12/27: x2goserver/bin/x2gostartagent: start using x2gogetrandomport, delete now-duplicate code.

git-admin at x2go.org git-admin at x2go.org
Wed Jan 10 00:17:57 CET 2018


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 56dd4b6b3534453f05ce0edd37195733247146cf
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Thu Jan 4 05:49:17 2018 +0100

    x2goserver/bin/x2gostartagent: start using x2gogetrandomport, delete now-duplicate code.
    
    Also adjust return values accordingly.
---
 debian/changelog              |  2 +
 x2goserver/bin/x2gostartagent | 91 +++++++------------------------------------
 2 files changed, 17 insertions(+), 76 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 9e3e16e..f315edc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -43,6 +43,8 @@ x2goserver (4.0.1.23-0x2go1) UNRELEASED; urgency=medium
       x2gostartagent, but need to be accessible by other scripts as well.
     - x2goserver/bin/x2gostartagent: remove spurious semicolon and add quotes
       on the lib path line.
+    - x2goserver/bin/x2gostartagent: start using x2gogetrandomport, delete
+      now-duplicate code. Also adjust return values accordingly.
   * x2goserver.spec:
     - RPMify x2goserver-xsession description.
     - Remove qt4 stuff, we're not using the framework here.
diff --git a/x2goserver/bin/x2gostartagent b/x2goserver/bin/x2gostartagent
index 89eb0c1..1dd5e65 100755
--- a/x2goserver/bin/x2gostartagent
+++ b/x2goserver/bin/x2gostartagent
@@ -20,78 +20,17 @@
 # Copyright (C) 2007-2017 Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
 # Copyright (C) 2007-2017 Heinz-Markus Graesing <heinz-m.graesing at obviously-nice.de>
 
-# rnowotny, <rnowotny at rotek.at>
-# Patch for SSH_PORT, to not use the same SSH port on each server, which is a
-# problem if you want to connect to different servers at the same time with
-# the windows client.
-# Original problem report: https://www.mail-archive.com/x2go-user@lists.berlios.de/msg00547.html
-# Currently implementation is based on the submitted patch, but differs heavily.
-
-# Get server IP address.
-get_server_ip_address() {
-	# The provided IP address should be outside of any local network.
-	# We are only interested in how the kernel would try to reach the
-	# non-local IP address specified here. It is not actually contacted
-	# in any way.
-	typeset ip_output="$(ip route get 8.8.8.8)"
-
-	# Remove newlines.
-	ip_output="${ip_output//$'\n'}"
-
-	# Fetch source address.
-	typeset src_address="$(grep -oe 'src[[:space:]]\{1,\}\(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}\)' <<< "${ip_output}" | sed -e 's/src[[:space:]]\{1,\}//')"
-
-	if [ -n "${src_address}" ]; then
-		printf '%s' "${src_address}"
-		return "0"
-	fi
-
-	return "1"
-}
-
-# Get some random port.
-get_random_port() {
-	typeset -i unix_timestamp="$(date "+%s")"
-
-	# Seed ${RANDOM}. This should probably be changed some time before 2106.
-	# Or maybe not.
-	RANDOM="${unix_timestamp}"
-
-	typeset -i random_port="$((30000 + RANDOM))"
-	printf '%s' "${random_port}"
-
-	return "0"
-}
-
 X2GO_LIB_PATH="$(x2gopath "libexec")"
 
 "${X2GO_LIB_PATH}/x2gosyslog" "${0}" "info" "$(basename "${0}") called with options: ${*}"
 
+if ! SSH_PORT="$("${X2GO_LIB_PATH}/x2gogetrandomport")"; then
+	typeset msg="Unable to get (pseudo-)randomized starting port value."
+	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "${msg}"
 
-# Refer to x2goserver.conf.
-typeset -i randomize_ssh_port="1"
-typeset randomize_ssh_port_config_value=''
-
-randomize_ssh_port_config_value="$("${X2GO_LIB_PATH}/x2goqueryconfig" "x2goagent" "port_randomization")"
-
-# Failures or incorrect values are implicitly caught by the default value.
-[[ "${randomize_ssh_port_config_value}" = "host-based" ]] && randomize_ssh_port='0'
-
-if [ "${randomize_ssh_port}" = "1" ]; then
-	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "debug" "Full SSH port randomization requested."
-	SSH_PORT="$(get_random_port)"
-else
-	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "debug" "host-based SSH port initialization requested."
-	typeset ip_address=''
-
-	if ip_address="$(get_server_ip_address)"; then
-		typeset -i ip_address_last_octet="${ip_address##*.}"
-		SSH_PORT="$((30000 + (ip_address_last_octet * 128)))"
-	else
-		"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "warning" "IP-based SSH port initialization requested, but failed to fetch primary address."
-		"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "warning" "Falling back to randomization."
-		SSH_PORT="$(get_random_port)"
-	fi
+	# Make x2goclient fail.
+	echo "${msg}" >&2
+	exit "1"
 fi
 
 X2GO_PORT="49" #First port for X2GO=50
@@ -101,22 +40,22 @@ if grep -E "^backend[ ]*=[ ]*postgres" "/etc/x2go/x2gosql/sql" 1>"/dev/null" 2>"
 	msg="The super-user \"root\" is not allowed to launch X2Go sessions."
 	echo "${msg}" >&2
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "${msg}"
-	exit "1"
+	exit "2"
 elif [ -z "${USER}" ]; then
 	msg="The \$USER environment variable is not set. Aborting session startup."
 	echo "${msg}" >&2
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "${msg}"
-	exit "2"
+	exit "3"
 elif [ -z "${HOME}" ]; then
 	msg="The \$HOME environment variable is not set. Aborting session startup."
 	echo "${msg}" >&2
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "${msg}"
-	exit "3"
+	exit "4"
 elif ! iconv -f ASCII -t ASCII &>"/dev/null" <<< "${HOME}"; then
 	msg="Your home directory path contains non-ASCII characters. Aborting session startup."
 	echo "${msg}" >&2
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "${msg}"
-	exit "4"
+	exit "5"
 fi
 
 # ${HOSTNAME} should be automatically set by bash via gethostname(2), IFF this
@@ -138,7 +77,7 @@ if current_host_name="$(hostname)"; then
 
 	# Make x2goclient fail.
 	echo "${msg}" >&2
-	exit "5"
+	exit "6"
 fi
 
 X2GO_ROOT="${HOME}/.x2go"
@@ -167,7 +106,7 @@ if [ -z "${X2GO_CLIENT}" ]; then
 	msg="The \$X2GO_CLIENT environment variable is not set. Possible reasons: \$SSH_CLIENT not set or \$SSH_CONNECTION not set. Or \$X2GO_CLIENT not set by ,,X2Go Desktop Sharing'' applet. Aborting session startup."
 	echo "${msg}" >&2
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "${msg}"
-	exit "6"
+	exit "7"
 fi
 
 "${X2GO_LIB_PATH}/x2gosyslog" "${0}" "debug" "client announced itself as ,,${X2GO_CLIENT}''"
@@ -220,7 +159,7 @@ if [ "${X2GO_STYPE}" == "S" ]; then
 			fi
 			"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "ERROR: user ${SHADOW_USER} denied desktop sharing session"
 			"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "ERROR: reason: for desktop sharing denial ${DENIAL_REASON}"
-			exit "7"
+			exit "8"
 		fi
 		X2GO_COOKIE="$(awk '{print $2}' <<< "${OUTPUT}")"
 		X2GO_PORT="$(awk '{print $1}' <<< "${OUTPUT}")"
@@ -236,7 +175,7 @@ if [ "${X2GO_STYPE}" == "S" ]; then
 		awk '{print $5}' <<< "${OUTPUT}"
 		awk '{print $6}' <<< "${OUTPUT}"
 		awk '{print $7}' <<< "${OUTPUT}"
-		exit "8"
+		exit "9"
 	else
 		X2GO_CLIPBOARD="${1}"; shift
 	fi
@@ -248,7 +187,7 @@ LWORD="$(awk '{print $1}' <<< "${LIMIT}")"
 if [ "${LWORD}" == "LIMIT" ]; then
 	echo "${LIMIT}" >&2
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "session limit has been reached for user ,,${USER}'', cannot start new session"
-	exit "9"
+	exit "10"
 fi
 
 export NX_CLIENT="${X2GO_LIB_PATH}/x2gosuspend-agent"

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git


More information about the x2go-commits mailing list