[FreeNX-kNX] Collection of helpful freenx patches

Mario Becroft mb at gem.win.co.nz
Sun Jan 25 12:28:44 UTC 2009


Here is a collection of all the patches I am running on freenx just in
case anyone else might find them useful. Some of them, with some tidying
up, could be incorporated into freenx mainline if there is any interest.


authorization.patch

Authorisation patch. On my system, at least, nxnode fails to set up the
~/.Xauthority file correctly, because by the time it runs the xauth
command, the XAUTHORITY environment variable has already been set to
~/.nx/C-*/authority. Change the first xauth command to explicitly work
on ~/.Xauthority. Ignore the nxhost* lines or replace with your own
hostname(s) if you want to authorize connections from other than localhost.

--- /mnt/devel/mb/src/nx/freenx-server-0.7.3/nxnode     2008-08-22 12:44:43.000000000 +1200
+++ nxnode      2009-01-19 20:49:57.798514922 +1300
@@ -1254,15 +1271,19 @@

        # write xauth script file

-$COMMAND_XAUTH >/dev/null 2>&1 <<EOF
+$COMMAND_XAUTH -f $(eval echo -n ~$user)/.Xauthority >/dev/null 2>&1 <<EOF
 add localhost:$display MIT-MAGIC-COOKIE-1 $cookie
 add :$display MIT-MAGIC-COOKIE-1 $cookie
+add nxhost:$display MIT-MAGIC-COOKIE-1 $cookie
+add nxhost_n12:$display MIT-MAGIC-COOKIE-1 $cookie
 exit
 EOF

 $COMMAND_XAUTH -f "$USER_FAKE_HOME/.nx/C-$sess_id/authority" >/dev/null 2>&1 <<EOF
 add localhost:$display MIT-MAGIC-COOKIE-1 $cookie
 add :$display MIT-MAGIC-COOKIE-1 $cookie
+add nxhost:$display MIT-MAGIC-COOKIE-1 $cookie
+add nxhost_n12:$display MIT-MAGIC-COOKIE-1 $cookie
 exit
 EOF

@@ -1271,6 +1292,8 @@
 cat << EOF >"$USER_FAKE_HOME/.nx/C-$sess_id/scripts/authority"
 remove localhost:$display
 remove :$display
+remove nxhost:$display
+remove nxhost_n12:$display
 exit
 EOF


auth_timeout.patch

If the directory server is extremely highly loaded (unusual)
authentication can take too long. Increase the timeout so that nxserver
does not give up.

--- nxserver.dist       2008-09-24 03:20:08.000000000 +1200
+++ nxserver    2008-09-24 03:38:02.000000000 +1200
@@ -591,7 +591,7 @@
                        NXNODE_SLAVE_STARTED=""

                        # FIXME: Make timeout configurable
-                       while read -t 10 line <&$NX_COMMFD
+                       while read -t 30 line <&$NX_COMMFD
                        do
                                log 6 "$line"
                                case "$line" in



dialog.patch

Using nxclient as nxdialog is extremely slow. Make it use xdialog
instead.

--- nxdialog.dist       2008-09-24 04:21:50.000000000 +1200
+++ nxdialog    2008-09-24 04:22:01.000000000 +1200
@@ -76,9 +76,9 @@
 # This is now fixed in NXClient 3.0.0, but still people sometimes use
 # older clients.

-NXCLIENT="/usr/NX/bin/nxclient"
-[ -x "$NXCLIENT" -a "$DIALOG_TYPE" != "printer" -a "$(file -bi $NXCLIENT)" != 'application/x-shellscript' ] \
-       && exec ${NXCLIENT} "${PARAMS[@]}"
+#NXCLIENT="/usr/NX/bin/nxclient"
+#[ -x "$NXCLIENT" -a "$DIALOG_TYPE" != "printer" -a "$(file -bi $NXCLIENT)" != 'application/x-shellscript' ] \
+#      && exec ${NXCLIENT} "${PARAMS[@]}"

 # FIXME: This should be COMMAND_XDIALOG, ...



nxnode_echo_hang.patch

Fix hang in server_nxnode_echo() when the client dies or loses
connectivity. This resulted in sessions not suspending and resuming
correctly in that case.

--- nxserver.foo	2009-01-25 16:07:46.590977440 +1300
+++ nxserver	2009-01-25 21:34:29.259718601 +1300
@@ -967,8 +967,8 @@
 server_nxnode_echo()
 {
 	log 6 "server_nxnode_echo: $@"
-	[ "$SERVER_CHANNEL" = "1" ] && echo "$@"
-	[ "$SERVER_CHANNEL" = "2" ] && echo "$@" >&2
+	[ "$SERVER_CHANNEL" = "1" ] && /bin/echo "$@"
+	[ "$SERVER_CHANNEL" = "2" ] && /bin/echo "$@" >&2
 }
 
 server_nxnode_exit_func()


proxy_ip.patch

Backport of the proxy ip change to allow connection without encryption.

--- /mnt/devel/mb/src/nx/freenx-server-0.7.3/nxnode     2008-08-22 12:44:43.000000000 +1200
+++ nxnode      2009-01-19 20:49:57.798514922 +1300
@@ -1184,7 +1190,18 @@
                [ -z "$userip" -a "$host" = "127.0.0.1" ] && userip="127.0.0.1"
                [ -z "$userip" ] && userip="*"
        fi
-
+
+       # We need our own external IP
+       proxyip="$EXTERNAL_PROXY_IP"
+
+       if [ -z "$proxyip" -a -n "$host" ]
+       then
+               [ "$host" = "127.0.0.1" ] && host=$(hostname)
+               proxyip=$(ping -c1 "$host" | grep 'PING' | cut -d'(' -f2 | cut -d')' -f1)
+       fi
+
+       [ -z "$proxyip" ] && proxyip="127.0.0.1"
+
        # ok, lets make the session dir first:

        sess_id="$SERVER_NAME-$display-$uniqueid"
@@ -1316,7 +1339,7 @@
 NX> 705 Session display: $display
 NX> 703 Session type: $type
 NX> 701 Proxy cookie: $proxy_cookie
-NX> 702 Proxy IP: $userip
+NX> 702 Proxy IP: $proxyip
 NX> 706 Agent cookie: $cookie
 NX> 704 Session cache: $type
 NX> 707 SSL tunneling: $ssl_tunnel


shadow_list_username.patch

In the list of sessions available for shadowing, show the username
(helpful if you have several different users with the same session name,
or session names that do not identify the user).

--- nxserver.foo	2009-01-25 21:44:57.566626637 +1300
+++ nxserver	2009-01-25 21:56:32.517375794 +1300
@@ -334,7 +334,7 @@
 			elif [ "$4" = "shadow" ]
 			then
 				available=$(getparam status)
-				printf "%-7s %-16s %32s %8s %5s %-14s %-11s %s\n" "$(getparam display)" "$(getparam type)" "$(getparam sessionId)" "$options" "$depth" "$geom" "$available" "$(getparam sessionName) (Shadowed)" >> $TMPFILE
+				printf "%-7s %-16s %32s %8s %5s %-14s %-11s %s\n" "$(getparam display)" "$(getparam type)" "$(getparam sessionId)" "$options" "$depth" "$geom" "$available" "$(getparam sessionName) ($(getparam userName)) (Shadowed)" >> $TMPFILE
 			else
 				# only unix-* sessions can be resumed, but other session types can still be terminated
 				stringinstring "unix-" "$4" || available="N/A"



shadow_suspended_sessions.patch

Make suspended sessions available for shadowing, instead of only running
sessions.

--- nxserver.foo	2009-01-26 00:50:03.956970327 +1300
+++ nxserver	2009-01-26 00:53:02.332307685 +1300
@@ -1663,7 +1663,8 @@
 				session_list_user_suspended "$USER" "$status" "$(getparam geometry)" "$(getparam type)"
 			elif [ "$(getparam type)" = "shadow" ]
 			then
-				session_list_user_suspended ".*" "Running" "" "shadow"
+				status=$(echo "suspended,running" | sed 's/,/$|^status=/g; s/suspended/Suspended/g; s/running/Running/g')
+				session_list_user_suspended ".*" "$status" "" "shadow"
 			else
 				session_list_user "$USER" | log_tee
 			fi



superuser_session_limit.patch

Enable certain users to bypass the per-user session limit. Invokes
/usr/NX/bin/superuser with the username, which should return 0 if user
is allowed to bypass limit, otherwise 1. Useful if your user session
limit is 1, but for special users you want to allow more sessions.

--- nxserver.foo	2009-01-25 16:07:46.590977440 +1300
+++ nxserver	2009-01-25 21:34:29.259718601 +1300
@@ -1173,6 +1173,9 @@
 	
 	if [ "$SESSION_COUNT_USER" -ge "$SESSION_USER_LIMIT" ]
 	then
+	        if /usr/NX/bin/superuser $USER ; then
+		        return 0
+		fi
 		echo_x "NX> 599 Server capacity: reached for user: $USER"
 		echo_x "NX> 500 ERROR: Last operation failed."
 		return 1


valgrind.patch

Run nxagent in memcheck for a specific user, for debugging use. Apply
patch, then change username and swap the commented and uncommented lines
to enable memcheck usage.

--- /mnt/devel/mb/src/nx/freenx-server-0.7.3/nxnode     2008-08-22 12:44:43.000000000 +1200
+++ nxnode      2009-01-19 20:49:57.798514922 +1300
@@ -540,7 +540,13 @@

                # Start the agent

+if [ "$user" = "mb" ] ; then
+               # run valgrind for mario to test with
+               #PATH="$PATH_BIN:$PATH" /usr/bin/valgrind --log-file=/tmp/valgrind $PATH_BIN/nxagent $P $R -name "NX - $user@$SERVER_NAME:$display - $session (GPL Edition)" -option "$USER_FAKE_HOME/.nx/C-$sess_id/options" $K $G $B $FP $AGENT_EXTRA_OPTIONS_X :$display 2>&3 &
                PATH="$PATH_BIN:$PATH" $PATH_BIN/nxagent $P $R -name "NX - $user@$SERVER_NAME:$display - $session (GPL Edition)" -option "$USER_FAKE_HOME/.nx/C-$sess_id/options" $K $G $B $FP $AGENT_EXTRA_OPTIONS_X :$display 2>&3 &
+else
+               PATH="$PATH_BIN:$PATH" $PATH_BIN/nxagent $P $R -name "NX - $user@$SERVER_NAME:$display - $session (GPL Edition)" -option "$USER_FAKE_HOME/.nx/C-$sess_id/options" $K $G $B $FP $AGENT_EXTRA_OPTIONS_X :$display 2>&3 &
+fi
        fi

        #


-- 
Mario Becroft <mb at gem.win.co.nz>



More information about the FreeNX-kNX mailing list