diff options
Diffstat (limited to 'x11vnc/ssltools.h')
-rw-r--r-- | x11vnc/ssltools.h | 212 |
1 files changed, 166 insertions, 46 deletions
diff --git a/x11vnc/ssltools.h b/x11vnc/ssltools.h index 763597c..013b7a2 100644 --- a/x11vnc/ssltools.h +++ b/x11vnc/ssltools.h @@ -744,12 +744,104 @@ char find_display[] = " exit 1\n" "fi\n" "\n" +"prdpy () {\n" +" d1=$1\n" +" chvt0=\"\"\n" +" if [ \"X$uname\" = \"XLinux\" ]; then\n" +" d2=$d1\n" +" d3=`echo \"$d2\" | sed -e 's/^.*:/:/' -e 's/\\..*$//'`\n" +" d4=\"($d2|$d3)\"\n" +" vt=`ps wwwwwaux | grep X | egrep -v 'startx|xinit' | egrep \" $d4 \" | egrep ' vt([789]|[1-9][0-9][0-9]*) ' | grep -v grep | head -n 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" +" chvt0=\",VT=$vt\"\n" +" fi\n" +" else\n" +" vt=`ps wwwwwaux | grep X | egrep \" $d4 \" | egrep ' tty([789]|[1-9][0-9][0-9]*) ' | grep -v grep | head -n 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" +" chvt0=\",VT=$vt\"\n" +" fi\n" +" else\n" +" pvt=`ps wwwwwaux | grep X | egrep -v 'startx|xinit' | egrep \" $d4 \" | head -n 1 | awk '{print $2}'`\n" +" if [ \"X$pvt\" != \"X\" ]; then\n" +" vt=`lsof -p \"$pvt\" 2>/dev/null | egrep '/dev/tty([789]|[1-9][0-9][0-9]*)$' | grep -v grep | head -n 1 | awk '{print $NF}' | sed -e 's,/dev/tty,,'`\n" +" if echo \"$vt\" | grep '^[0-9][0-9]*$' > /dev/null; then\n" +" chvt0=\",VT=$vt\"\n" +" else\n" +" chvt0=\",XPID=$pvt\"\n" +" fi\n" +" fi\n" +" fi\n" +" fi\n" +" fi\n" +" echo \"$d1$chvt0\"\n" +"}\n" +"\n" +"uname=`uname`\n" +"nsout=`netstat -an`\n" +"if [ \"X$uname\" = \"XDarwin\" ]; then\n" +" psout=`ps aux 2>/dev/null | grep -wv PID | grep -v grep`\n" +" pslist=`echo \"$psout\" | awk '{print $2}'`\n" +"else\n" +" psout=`ps -ef 2>/dev/null | grep -wv PID | grep -v grep`\n" +" pslist=`echo \"$psout\" | awk '{print $2}'`\n" +"fi\n" +"\n" +"if [ \"X$FD_XDM\" != \"X\" ]; then\n" +" list=\"\"\n" +" for pair in `echo \"$psout\" | grep '/X.* :[0-9][0-9]* .*-auth' | egrep -v 'startx|xinit' | sed -e 's,^.*/X.* \\(:[0-9][0-9]*\\) .* -auth \\([^ ][^ ]*\\).*$,\\1\\,\\2,' | sort -u`\n" +" do\n" +" da=`echo \"$pair\" | awk -F, '{print $1}'`\n" +" xa=`echo \"$pair\" | awk -F, '{print $2}'`\n" +" if [ -f $xa -a -r $xa ]; then\n" +" env XAUTHORITY=\"$xa\" xdpyinfo -display \"$da\" >/dev/null 2>&1\n" +" if [ $? = 0 ]; then\n" +" env XAUTHORITY=/dev/null xdpyinfo -display \"$da\" >/dev/null 2>&1\n" +" if [ $? != 0 ]; then\n" +" y=`prdpy $da`\n" +" echo \"DISPLAY=$y\"\n" +" if [ \"X$showxauth\" != \"X\" ]; then\n" +" cook=`xauth -f \"$xa\" list | head -n 1 | awk '{print $NF}'`\n" +" tf=$HOME/.xat.$$\n" +" rm -f $tf\n" +" if [ -f $tf ]; then\n" +" exit 1\n" +" fi\n" +" touch $tf 2>/dev/null\n" +" chmod 600 $tf 2>/dev/null\n" +" if [ ! -f $tf ]; then\n" +" tf=/tmp/.xat.$$\n" +" rm -f $tf\n" +" if [ -f $tf ]; then\n" +" exit 1\n" +" fi\n" +" touch $tf 2>/dev/null\n" +" chmod 600 $tf 2>/dev/null\n" +" if [ ! -f $tf ]; then\n" +" exit 1\n" +" fi\n" +" fi\n" +" xauth -f $tf add \"$da\" . $cook\n" +" xauth -f $tf extract - \"$da\" 2>/dev/null\n" +" rm -f $tf\n" +" fi\n" +" exit 0\n" +" fi\n" +" fi\n" +" fi\n" +" done\n" +" exit 1\n" +"fi\n" +"\n" "# Now try to match X DISPLAY to user:\n" "\n" "# who(1) output column 2:\n" "#gone=`last $user | grep 'gone.*no.logout' | awk '{print $2}' | grep '^:' | sed -e 's,/.*,,' | tr '\\n' '|'`\n" "#gone=\"${gone}__quite_impossible__\"\n" -"#display=`who | grep \"^${user}[ ][ ]*:[0-9]\" | egrep -v \" ($gone)\\>\" | head -1 \\\n" +"#display=`who | grep \"^${user}[ ][ ]*:[0-9]\" | egrep -v \" ($gone)\\>\" | head -n 1 \\\n" "# | awk '{print $2}' | sed -e 's,/.*$,,'`\n" "poss=\"\"\n" "list=`who | grep \"^${user}[ ][ ]*:[0-9]\" | awk '{print $2}' | sed -e 's,/.*$,,'`\n" @@ -759,12 +851,11 @@ char find_display[] = "if [ \"X$X11VNC_FINDDISPLAY_SKIP_XAUTH\" = \"X\" ]; then\n" " list=\"$list \"`xauth list | awk '{print $1}' | grep /unix | grep \"^${host}\" | sed -e 's/^.*:/:/' | sort -n | uniq`\n" "fi\n" -"uname=`uname`\n" -"nsout=`netstat -an`\n" -"psout=`ps -ef`\n" +"\n" "for p in $list\n" "do\n" -" d=`echo \"$p\" | sed -e 's/://' -e 's/\\..*$//'`\n" +" xa=`echo \"$p\" | awk -F, '{print $2}'`\n" +" d=`echo \"$p\" | sed -e 's/,.*$//' -e 's/://' -e 's/\\..*$//'`\n" " ok=\"\"\n" " if [ \"X$X11VNC_SKIP_DISPLAY\" != \"X\" ]; then\n" " mat=\"\"\n" @@ -799,7 +890,7 @@ char find_display[] = " if [ -d \"/proc/$pid\" ]; then\n" " ok=1\n" " fi\n" -" elif echo \"$psout\" | awk '{print $2}' | grep -w \"$pid\" > /dev/null; then\n" +" elif echo \"$pslist\" | grep -w \"$pid\" > /dev/null; then\n" " ok=1\n" " fi\n" " fi\n" @@ -810,14 +901,57 @@ char find_display[] = " fi\n" "done\n" "\n" +"seenvalues=\"\"\n" +"\n" +"seen() {\n" +" v=$1\n" +" if [ \"X$seenvalues\" != \"X\" ]; then\n" +" for v2 in $seenvalues\n" +" do\n" +" if [ \"X$v\" = \"X$v2\" ]; then\n" +" seenret=1\n" +" return\n" +" fi\n" +" done\n" +" fi\n" +" if [ \"X$seenvalues\" = \"X\" ]; then\n" +" seenvalues=\"$v\"\n" +" else\n" +" seenvalues=\"$seenvalues $v\"\n" +" fi\n" +" seenret=0\n" +"}\n" +"\n" "poss=`echo \"$poss\" | sed -e 's/^ *//' -e 's/ *$//'`\n" "\n" "if [ \"X$X11VNC_FINDDISPLAY_SKIP_XAUTH\" != \"X\" ]; then\n" -" display=`echo \"$poss\" | tr ' ' '\\n' | head -1`\n" +" if [ \"X$FIND_DISPLAY_ALL\" != \"X\" ]; then\n" +" for p in $poss\n" +" do\n" +" if [ \"X$p\" = \"X\" ]; then\n" +" continue\n" +" fi\n" +" seen \"$p\"\n" +" if [ \"X$seenret\" = \"X1\" ]; then\n" +" continue\n" +" fi\n" +" y=`prdpy $p`\n" +" echo $y\n" +" done\n" +" exit 0\n" +" fi\n" +" display=`echo \"$poss\" | tr ' ' '\\n' | head -n 1`\n" "else\n" " freebie=\"\"\n" " for p in $poss\n" " do\n" +" if [ \"X$p\" = \"X\" ]; then\n" +" continue\n" +" fi\n" +" seen \"$p\"\n" +" if [ \"X$seenret\" = \"X1\" ]; then\n" +" continue\n" +" fi\n" " xdpyinfo -display \"$p\" >/dev/null 2>&1\n" " if [ $? = 0 ]; then\n" " if [ \"X$FD_TAG\" != \"X\" ]; then\n" @@ -834,8 +968,18 @@ char find_display[] = " if [ $? != 0 ]; then\n" " # keep it\n" " display=\"$p\"\n" +" if [ \"X$FIND_DISPLAY_ALL\" != \"X\" ]; then\n" +" y=`prdpy $p`\n" +" echo \"DISPLAY=$y\"\n" +" continue\n" +" fi\n" " break\n" " else\n" +" if [ \"X$FIND_DISPLAY_ALL\" != \"X\" ]; then\n" +" y=`prdpy $p`\n" +" echo \"$y,NOXAUTH\"\n" +" continue\n" +" fi\n" " if [ \"X$freebie\" = \"X\" ]; then\n" " freebie=\"$p\"\n" " fi\n" @@ -847,44 +991,17 @@ char find_display[] = " fi\n" "fi\n" "\n" +"if [ \"X$FIND_DISPLAY_ALL\" != \"X\" ]; then\n" +" exit\n" +"fi\n" "if [ \"X$display\" = \"X\" ]; then\n" " echo \"\" # failure\n" " exit 1\n" "fi\n" "\n" -"chvt=\"\"\n" -"if [ \"X$uname\" = \"XLinux\" ]; then\n" -" d2=$display\n" -" d3=`echo \"$d2\" | sed -e 's/^.*:/:/' -e 's/\\..*$//'`\n" -" d4=\"($d2|$d3)\"\n" -" vt=`ps wwwwwaux | grep X | egrep -v 'startx|xinit' | egrep \" $d4 \" | 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 | egrep \" $d4 \" | 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" -" else\n" -" pvt=`ps wwwwwaux | grep X | egrep -v 'startx|xinit' | egrep \" $d4 \" | head -1 | awk '{print $2}'`\n" -" if [ \"X$pvt\" != \"X\" ]; then\n" -" vt=`lsof -p \"$pvt\" | egrep '/dev/tty([789]|[1-9][0-9][0-9]*)$' | grep -v grep | head -1 | awk '{print $NF}' | sed -e 's,/dev/tty,,'`\n" -" if echo \"$vt\" | grep '^[0-9][0-9]*$' > /dev/null; then\n" -" chvt=\",VT=$vt\"\n" -" else\n" -" chvt=\",XPID=$pvt\"\n" -" fi\n" -" fi\n" -" fi\n" -" fi\n" -"fi\n" +"dpy2=`prdpy \"$display\"`\n" "\n" -"echo \"DISPLAY=$display$chvt\"\n" +"echo \"DISPLAY=$dpy2\"\n" "if [ \"X$showxauth\" != \"X\" ]; then\n" " xauth extract - \"$display\" 2>/dev/null\n" "fi\n" @@ -959,7 +1076,7 @@ char create_display[] = " if echo \"$r1\" | grep '^[0-9][0-9]*$' > /dev/null; then\n" " echo \"$r1\"\n" " else\n" -" r2=`sh -c 'echo $$; date; ps -elf' 2>/dev/null | sum -r 2>/dev/null | awk '{print $1}'`\n" +" r2=`sh -c 'echo $$; date; ps -elf' 2>&1 | sum -r 2>/dev/null | awk '{print $1}'`\n" " if echo \"$r2\" | grep '^[0-9][0-9]*$' > /dev/null; then\n" " echo \"$r2\"\n" " else\n" @@ -999,6 +1116,9 @@ char create_display[] = " elif [ \"X$have_wmaker\" != \"X\" -a \"X$FD_SESS\" = \"Xwmaker\" ]; then\n" " echo \"$have_wmaker\"\n" " return\n" +" elif [ \"X$have_enlightenment\" != \"X\" -a \"X$FD_SESS\" = \"Xenlightenment\" ]; then\n" +" echo \"$have_enlightenment\"\n" +" return\n" " elif [ \"X$have_Xsession\" != \"X\" -a \"X$FD_SESS\" = \"XXsession\" ]; then\n" " echo \"$have_Xsession\"\n" " return\n" @@ -1046,7 +1166,7 @@ char create_display[] = " return\n" " fi\n" " fi\n" -" for wm in blackbox fvwm icewm wmw openbox twm mwm windowmaker metacity\n" +" for wm in blackbox fvwm icewm wmw openbox twm mwm windowmaker enlightenment metacity\n" " do\n" " eval \"have=\\$have_$wm\"\n" " if [ \"X$have\" = \"X\" ]; then\n" @@ -1106,7 +1226,6 @@ char create_display[] = " dport=`freeport $dport`\n" " FD_CUPS=$dport\n" " redir_daemon=\"$redir_daemon,TS_CUPS_REDIR:$dport:$rport\"\n" -"#echo \"redir_daemon=$redir_daemon\" 1>&2\n" " fi\n" " if echo \"$FD_CUPS\" | grep ':' > /dev/null; then\n" " :\n" @@ -1426,7 +1545,7 @@ char create_display[] = " cookie=`(echo $r; 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" +" cookie=`$have_xauth list | awk '{print $NF}' | tail -n 1`\n" " fi\n" " if [ \"X$cookie\" = \"X\" ]; then\n" " # oh well..\n" @@ -1518,8 +1637,8 @@ char create_display[] = " fi\n" "fi\n" "\n" -"depth=`echo \"$depth\" | head -1`\n" -"geom=`echo \"$geom\" | head -1`\n" +"depth=`echo \"$depth\" | head -n 1`\n" +"geom=`echo \"$geom\" | head -n 1`\n" "\n" "if echo \"$depth\" | grep '^[0-9][0-9]*$' > /dev/null; then\n" " :\n" @@ -1552,7 +1671,7 @@ char create_display[] = " p_ok=1\n" "fi\n" "\n" -"for prog in startx xinit xdm gdm kdm xterm Xdummy Xvfb Xvnc xauth mcookie md5sum xmodmap startkde gnome-session blackbox fvwm2 mwm openbox twm windowmaker wmaker metacity X Xorg XFree86 Xsun Xsession dtwm netstat nohup esddsp konsole gnome-terminal\n" +"for prog in startx xinit xdm gdm kdm xterm Xdummy Xvfb Xvnc xauth mcookie md5sum xmodmap startkde gnome-session blackbox fvwm2 mwm openbox twm windowmaker wmaker enlightenment metacity X Xorg XFree86 Xsun Xsession dtwm netstat nohup esddsp konsole gnome-terminal\n" "do\n" " p2=`echo \"$prog\" | sed -e 's/-/_/g'`\n" " eval \"have_$p2=''\"\n" @@ -1605,6 +1724,7 @@ char create_display[] = " use_xdmcp_query=1\n" " fi\n" " curr_try=`echo \"$curr_try\" | sed -e 's/[+.-]xdmcp//'`\n" +" curr_try=`echo \"$curr_try\" | sed -e 's/[+.-]redirect//'`\n" " \n" " if echo \"$curr_try\" | grep -iw \"^Xdummy\" > /dev/null; then\n" " try_Xdummy\n" |