summaryrefslogtreecommitdiffstats
path: root/x11vnc/ssltools.h
diff options
context:
space:
mode:
authorrunge <runge>2006-12-10 03:12:02 +0000
committerrunge <runge>2006-12-10 03:12:02 +0000
commit5b198763c597459a27e7e88827dcc748b98b6670 (patch)
tree07111d31dc1932bd6c5bb99bd899916e5efb7129 /x11vnc/ssltools.h
parent726cedb871a70aa6307df74e769605ee89bd52d0 (diff)
downloadlibtdevnc-5b198763c597459a27e7e88827dcc748b98b6670.tar.gz
libtdevnc-5b198763c597459a27e7e88827dcc748b98b6670.zip
x11vnc: FINDCREATEDISPLAY support to create X session if one cannot be found. Fix bug in java viewer.
Diffstat (limited to 'x11vnc/ssltools.h')
-rw-r--r--x11vnc/ssltools.h361
1 files changed, 360 insertions, 1 deletions
diff --git a/x11vnc/ssltools.h b/x11vnc/ssltools.h
index 1984c0d..06520ab 100644
--- a/x11vnc/ssltools.h
+++ b/x11vnc/ssltools.h
@@ -688,6 +688,24 @@ char find_display[] =
"# x11vnc then uses the info to open the display.\n"
"#\n"
"\n"
+"FIND_DISPLAY_OUTPUT=/tmp/fdo.txt\n"
+"if [ \"X$FIND_DISPLAY_OUTPUT\" != \"X\" ]; then\n"
+" if [ \"X$FIND_DISPLAY_EXEC\" = \"X\" ]; then\n"
+" FIND_DISPLAY_EXEC=1\n"
+" export FIND_DISPLAY_EXEC\n"
+" if [ \"X$FIND_DISPLAY_OUTPUT\" != \"X\" ]; then\n"
+" /bin/sh $0 \"$@\" 2> $FIND_DISPLAY_OUTPUT\n"
+" else\n"
+" /bin/sh $0 \"$@\" 2> /dev/null\n"
+" fi\n"
+" exit $?\n"
+" fi\n"
+"fi\n"
+"\n"
+"if [ \"X$FIND_DISPLAY_OUTPUT\" != \"X\" ]; then\n"
+" set -xv\n"
+"fi\n"
+"\n"
"#env; set -xv\n"
"PATH=$PATH:/bin:/usr/bin:/usr/X11R6/bin:/usr/bin/X11:/usr/openwin/bin:/usr/ucb\n"
"export PATH\n"
@@ -743,9 +761,23 @@ char find_display[] =
" fi\n"
" # loop over xauth list items machine ^hostname/unix:N\n"
" host=`hostname | sed -e 's/\\..*$//'`\n"
+" tries1=\"\"\n"
+" tries2=\"\"\n"
" for d in `xauth list | awk '{print $1}' | grep /unix \\\n"
" | grep \"^${host}\" | sed -e 's/^.*://' | sort -n | uniq`\n"
" do\n"
+" if [ -e \"/tmp/.X$d-lock\" -o -e \"/tmp/.X11-unix/X$d\" ]; then\n"
+" tries1=\"$tries1 $d\"\n"
+" else\n"
+" # these are often ssh X redirs so try them last or skip:\n"
+" #tries2=\"$tries2 $d\"\n"
+" :\n"
+" fi\n"
+" done\n"
+" \n"
+"\n"
+" for d in $tries1 $tries2\n"
+" do\n"
" xdpyinfo -display \":$d\" >/dev/null 2>&1\n"
" if [ $? = 0 ]; then\n"
" # try again with no authority:\n"
@@ -766,12 +798,339 @@ char find_display[] =
" fi\n"
"fi\n"
"\n"
-"echo \"DISPLAY=$display\"\n"
+"chvt=\"\"\n"
+"if [ \"X`uname`\" = \"XLinux\" ]; then\n"
+" vt=`ps wwwwwaux | grep X | egrep -v 'startx|xinit' | grep \" $display \" | egrep ' vt([789]|[1-9][0-9][0-9]*) ' | grep -v grep | head -1`\n"
+" if [ \"X$vt\" != \"X\" ]; then\n"
+" vt=`echo \"$vt\" | sed -e 's/^.* vt\\([0-9][0-9]*\\) .*$/\\1/'`\n"
+" if echo \"$vt\" | grep '^[0-9][0-9]*$' > /dev/null; then\n"
+" chvt=\",VT=$vt\"\n"
+" fi\n"
+" else\n"
+" vt=`ps wwwwwaux | grep X | grep \" $display \" | egrep ' tty([789]|[1-9][0-9][0-9]*) ' | grep -v grep | head -1`\n"
+" if [ \"X$vt\" != \"X\" ]; then\n"
+" vt=`echo \"$vt\" | sed -e 's/^.* tty\\([0-9][0-9]*\\) .*$/\\1/'`\n"
+" if echo \"$vt\" | grep '^[0-9][0-9]*$' > /dev/null; then\n"
+" chvt=\",VT=$vt\"\n"
+" fi\n"
+" fi\n"
+" fi\n"
+"fi\n"
+"\n"
+"echo \"DISPLAY=$display$chvt\"\n"
"if [ \"X$showxauth\" != \"X\" ]; then\n"
" xauth extract - \"$display\" 2>/dev/null\n"
"fi\n"
"\n"
+"\n"
"exit 0\n"
;
+char create_display[] =
+"#!/bin/sh\n"
+"\n"
+"CREATE_DISPLAY_OUTPUT=/tmp/cdo.txt\n"
+"if [ \"X$CREATE_DISPLAY_EXEC\" = \"X\" ]; then\n"
+" CREATE_DISPLAY_EXEC=1\n"
+" export CREATE_DISPLAY_EXEC\n"
+" if [ \"X$CREATE_DISPLAY_OUTPUT\" != \"X\" ]; then\n"
+" /bin/sh $0 \"$@\" 2> $CREATE_DISPLAY_OUTPUT\n"
+" else\n"
+" /bin/sh $0 \"$@\" 2> /dev/null\n"
+" fi\n"
+" exit $?\n"
+"fi\n"
+"\n"
+"if [ \"X$CREATE_DISPLAY_OUTPUT\" != \"X\" ]; then\n"
+" set -xv\n"
+"fi\n"
+"\n"
+"findfree() {\n"
+" try=20\n"
+" n=\"\"\n"
+" while [ $try -lt 99 ]\n"
+" do\n"
+" if [ ! -e \"/tmp/.X${try}-lock\" ]; then\n"
+" n=$try\n"
+" break\n"
+" fi\n"
+" try=`expr $try + 1`\n"
+" done\n"
+" echo \"$n\"\n"
+"}\n"
+"\n"
+"findsession() {\n"
+" if [ \"X$session\" != \"X\" ]; then\n"
+" echo \"$session\"\n"
+" return\n"
+" fi\n"
+" home=`csh -f -c \"echo ~$USER\"`\n"
+" if [ \"X$home\" = \"X\" -o ! -d \"$home\" ]; then\n"
+" if [ \"X$have_root\" != \"X\" -a \"X$USER\" != \"Xroot\" ]; then\n"
+" home=`su - $USER -c 'echo $HOME'`\n"
+" fi\n"
+" fi\n"
+" if [ \"X$home\" = \"X\" -o ! -d \"$home\" ]; then\n"
+" if [ -d \"/home/$USER\" ]; then\n"
+" home=\"/home/$USER\"\n"
+" else \n"
+" home=__noplace__\n"
+" fi\n"
+" fi\n"
+" if [ -f \"$home/.xsession\" ]; then\n"
+" echo \"$home/.xsession\"\n"
+" return\n"
+" elif [ -f \"$home/.xinitrc\" ]; then\n"
+" echo \"$home/.xinitrc\"\n"
+" return\n"
+" fi\n"
+" if [ -f \"$home/.dmrc\" ]; then\n"
+" if [ \"X$have_startkde\" != \"X\" ]; then\n"
+" if egrep -i 'Session=(default|kde)' \"$home/.dmrc\" > /dev/null; then\n"
+" echo \"$have_startkde\"\n"
+" return\n"
+" fi\n"
+" fi\n"
+" if [ \"X$have_gnome_session\" != \"X\" ]; then\n"
+" if egrep -i 'Session=gnome' \"$home/.dmrc\" > /dev/null; then\n"
+" echo \"$have_gnome_session\"\n"
+" return\n"
+" fi\n"
+" fi\n"
+" for wm in blackbox fvwm icewm wmw openbox twm windowmaker metacity\n"
+" do\n"
+" eval \"have=\\$have_$wm\"\n"
+" if [ \"X$have\" = \"X\" ]; then\n"
+" continue\n"
+" fi\n"
+" if grep -i \"Session=$wm\" \"$home/.dmrc\" > /dev/null; then\n"
+" echo \"$have\"\n"
+" return\n"
+" fi\n"
+" \n"
+" done\n"
+" fi\n"
+" if [ \"X$have_xterm\" != \"X\" ]; then\n"
+" echo $have_xterm\n"
+" return\n"
+" else\n"
+" echo \".xinitrc\"\n"
+" fi\n"
+"}\n"
+"\n"
+"server() {\n"
+" authfile=`auth`\n"
+" sess=`findsession`\n"
+" DISPLAY=:$N\n"
+" export DISPLAY\n"
+" stmp=\"\"\n"
+" if [ \"X$have_root\" != \"X\" -a \"X$USER\" != \"Xroot\" ]; then\n"
+" sess=\"env DISPLAY=:$N $sess\"\n"
+" fi\n"
+" if echo \"$sess\" | grep '[ ]' > /dev/null; then\n"
+" stmp=/tmp/.cd$$\n"
+" rm -f $stmp\n"
+" touch $stmp\n"
+" chmod 755 $stmp\n"
+" echo \"#!/bin/sh\" > $stmp\n"
+" echo \"$sess\" >> $stmp\n"
+" echo \"sleep 1\" >> $stmp\n"
+" echo \"rm -f $stmp\" >> $stmp\n"
+" sess=$stmp\n"
+" fi\n"
+" if [ \"X$have_root\" != \"X\" -a \"X$USER\" != \"Xroot\" ]; then\n"
+" ctmp=\"/tmp/.xa.$$\"\n"
+" touch $ctmp\n"
+" chmod 644 $ctmp\n"
+" $have_xauth -f $authfile nextract - :$N > $ctmp\n"
+" su - $USER -c \"$have_xauth nmerge - < $ctmp\" 1>&2\n"
+" $have_xauth -f $authfile nextract - `hostname`:$N > $ctmp\n"
+" su - $USER -c \"$have_xauth nmerge - < $ctmp\" 1>&2\n"
+" rm -f $ctmp\n"
+" XAUTHORITY=$authfile\n"
+" export XAUTHORITY\n"
+" sess=\"/bin/su - $USER -c $sess\"\n"
+" else\n"
+" $have_xauth -f $authfile nextract - :$N | $have_xauth nmerge -\n"
+" $have_xauth -f $authfile nextract - `hostname`:$N | $have_xauth nmerge -\n"
+" fi\n"
+" \n"
+" if [ \"X$have_startx\" != \"X\" ]; then\n"
+" echo \"$have_startx $sess -- $* -auth $authfile\" 1>&2\n"
+" $have_startx $sess -- $* -auth $authfile 1>&2 &\n"
+" pid=$!\n"
+" elif [ \"X$have_xinit\" != \"X\" ]; then\n"
+" echo \"$have_xinit $sess -- $* -auth $authfile\" 1>&2\n"
+" $have_xinit $sess -- $* -auth $authfile 1>&2 &\n"
+" pid=$!\n"
+" else\n"
+" echo \"$*\"\n"
+" nohup $* 1>&2 &\n"
+" pid=$!\n"
+" nohup $sess 1>&2 &\n"
+" fi\n"
+" sleep 4\n"
+" if kill -0 $pid; then\n"
+" result=1\n"
+" else\n"
+" result=0\n"
+" fi\n"
+" #(sleep 120; rm -f $authfile) &\n"
+"}\n"
+"\n"
+"try_X() {\n"
+" if [ \"X$have_xinit\" != \"X\" ]; then\n"
+" save_have_startx=$have_startx\n"
+" have_startx=\"\"\n"
+" server :$N\n"
+" have_startx=$save_have_startx\n"
+" fi\n"
+"}\n"
+"\n"
+"try_Xdummy() {\n"
+" if [ \"X$have_Xdummy\" = \"X\" ]; then\n"
+" return\n"
+" fi\n"
+" if [ \"X$have_root\" = \"X\" ]; then\n"
+" return\n"
+" fi\n"
+"\n"
+" #save_have_startx=$have_startx\n"
+" #have_startx=\"\"\n"
+" server $have_Xdummy :$N -geom $geom -depth $depth\n"
+" #have_startx=$save_have_startx\n"
+"}\n"
+"\n"
+"try_Xvfb() {\n"
+" if [ \"X$have_Xvfb\" = \"X\" ]; then\n"
+" return\n"
+" fi\n"
+"\n"
+" #save_have_startx=$have_startx\n"
+" #have_startx=\"\"\n"
+" server $have_Xvfb :$N -screen 0 ${geom}x${depth}\n"
+" #have_startx=$save_have_startx\n"
+"\n"
+" if [ \"X$result\" = \"X1\" -a \"X$have_xmodmap\" != \"X\" ]; then\n"
+" (\n"
+" sleep 1; $have_xmodmap -display :$N -e \"keycode any = Shift_R\" \n"
+" sleep 1; $have_xmodmap -display :$N -e \"add Shift = Shift_L Shift_R\" \n"
+" sleep 1; $have_xmodmap -display :$N -e \"keycode any = Control_R\" \n"
+" sleep 1; $have_xmodmap -display :$N -e \"add Control = Control_L Control_R\" \n"
+" sleep 1; $have_xmodmap -display :$N -e \"keycode any = Alt_L\" \n"
+" sleep 1; $have_xmodmap -display :$N -e \"keycode any = Alt_R\" \n"
+" sleep 1; $have_xmodmap -display :$N -e \"keycode any = Meta_L\" \n"
+" sleep 1; $have_xmodmap -display :$N -e \"clear Mod1\" \n"
+" sleep 1; $have_xmodmap -display :$N -e \"add Mod1 = Alt_L Alt_R Meta_L\" \n"
+" ) 1>&2 &\n"
+" fi\n"
+"}\n"
+"\n"
+"cookie() {\n"
+" cookie=\"\"\n"
+" if [ \"X$have_mcookie\" != \"X\" ]; then\n"
+" cookie=`mcookie`\n"
+" elif [ \"X$have_md5sum\" != \"X\" ]; then\n"
+" if [ -e /dev/urandom ]; then\n"
+" cookie=`dd if=/dev/urandom count=32 2>/dev/null | md5sum | awk '{print $1}'`\n"
+" elif [ -e /dev/random ]; then\n"
+" cookie=`dd if=/dev/random count=32 2>/dev/null | md5sum | awk '{print $1}'`\n"
+" fi\n"
+" if [ \"X$cookie\" = \"X\" ]; then\n"
+" cookie=`(echo $RANDOM; date; uptime; ps -ealf 2>&1) | md5sum | awk '{print $1}'`\n"
+" fi\n"
+" elif [ \"X$have_xauth\" != \"X\" ]; then\n"
+" cookie=`$have_xauth list | awk '{print $NF}' | tail -1`\n"
+" fi\n"
+" if [ \"X$cookie\" = \"X\" ]; then\n"
+" # oh well..\n"
+" cookie=$cookie`printf \"%08x\" \"$RANDOM$$\"`\n"
+" cookie=$cookie`printf \"%08x\" \"$RANDOM$$\"`\n"
+" cookie=$cookie`printf \"%08x\" \"$RANDOM$$\"`\n"
+" cookie=$cookie`printf \"%08x\" \"$RANDOM$$\"`\n"
+" fi\n"
+" echo \"$cookie\"\n"
+"}\n"
+"\n"
+"auth() {\n"
+" if [ \"X$have_xauth\" = \"X\" ]; then\n"
+" exit 1\n"
+" fi\n"
+" tmp=\"/tmp/.xauth$$$RANDOM\"\n"
+" rm -f $tmp\n"
+" touch $tmp\n"
+" chmod 600 $tmp\n"
+" if [ ! -f $tmp ]; then\n"
+" exit 1\n"
+" fi\n"
+" cook=`cookie`\n"
+" $have_xauth -f $tmp add :$N . $cook 1>&2\n"
+" $have_xauth -f $tmp add `hostname`:$N . $cook 1>&2\n"
+" echo \"$tmp\"\n"
+"}\n"
+"\n"
+"\n"
+"depth=${depth:-16}\n"
+"geom=${geom:-1280x1024}\n"
+"\n"
+"N=`findfree`\n"
+"\n"
+"if [ \"X$N\" = \"X\" ]; then\n"
+" exit 1\n"
+"fi\n"
+"echo \"trying N=$N ...\" 1>&2\n"
+"\n"
+"if [ \"X$USER\" = \"X\" ]; then\n"
+" USER=$LOGNAME\n"
+"fi\n"
+"if [ \"X$USER\" = \"X\" ]; then\n"
+" USER=`whoami`\n"
+"fi\n"
+"\n"
+"PATH=$PATH:/usr/X11R6/bin:/usr/bin/X11:/usr/openwin/bin:/usr/dt/bin:/opt/kde3/bin:/opt/gnome/bin:/usr/bin:/bin\n"
+"\n"
+"have_root=\"\"\n"
+"id0=`id`\n"
+"if id | grep -w root > /dev/null; then\n"
+" have_root=\"1\"\n"
+"fi\n"
+"\n"
+"for prog in startx xinit xdm gdm kdm xterm Xdummy Xvfb xauth mcookie md5sum xmodmap startkde gnome-session blackbox fvwm mwm openbox twm windowmaker metacity\n"
+"do\n"
+" p2=`echo \"$prog\" | sed -e 's/-/_/g'`\n"
+" eval \"have_$p2=''\"\n"
+" if type $prog > /dev/null 2>&1; then\n"
+" eval \"have_$p2=`which $prog`\"\n"
+" fi\n"
+"done\n"
+"\n"
+"if [ \"X$CREATE_DISPLAY_OUTPUT\" != \"X\" ]; then\n"
+" set | grep ^have_ 1>&2\n"
+"fi\n"
+"\n"
+"TRY=\"$1\"\n"
+"if [ \"X$TRY\" = \"X\" ]; then\n"
+" TRY=Xdummy,Xvfb\n"
+"fi\n"
+"\n"
+"for curr_try in `echo \"$TRY\" | tr ',' ' '`\n"
+"do\n"
+" result=0\n"
+" if echo \"$curr_try\" | grep -iw \"Xdummy\" > /dev/null; then\n"
+" try_Xdummy\n"
+" elif echo \"$curr_try\" | grep -iw \"Xvfb\" > /dev/null; then\n"
+" try_Xvfb\n"
+" elif echo \"$curr_try\" | grep -iw \"X\" > /dev/null; then\n"
+" try_X\n"
+" fi\n"
+" if [ \"X$result\" = \"X1\" ]; then\n"
+" echo \"DISPLAY=:$N\"\n"
+" $have_xauth -f $authfile extract - :$N\n"
+" exit 0\n"
+" fi\n"
+"done\n"
+"\n"
+"exit 1\n"
+;
+
#endif /* _SSLTOOLS_H */