diff options
author | runge <runge> | 2008-09-07 04:17:33 +0000 |
---|---|---|
committer | runge <runge> | 2008-09-07 04:17:33 +0000 |
commit | d5cba7a574a667f5321194cb05d0b4adcb995866 (patch) | |
tree | 2748fd38612cc63256ee864284cd8dab19f4eba1 /x11vnc/ssltools.h | |
parent | dbfa4ad1f78f6133bc5f50e766f7f3bfdb8fa049 (diff) | |
download | libtdevnc-d5cba7a574a667f5321194cb05d0b4adcb995866.tar.gz libtdevnc-d5cba7a574a667f5321194cb05d0b4adcb995866.zip |
x11vnc: kill gui_pid on exit in -connect/-connect_or_exit mode.
-grablocal n experiment (not compiled by default). -macuskbd
option for macosx for orig uskdb code. keycode=N remote contol
cmd. Find dpy look at non-NFS cookies in /tmp. Fix gui tray
insertion on recent gnome dt. Fix connect_file bug. Sync SSVNC
Diffstat (limited to 'x11vnc/ssltools.h')
-rw-r--r-- | x11vnc/ssltools.h | 151 |
1 files changed, 141 insertions, 10 deletions
diff --git a/x11vnc/ssltools.h b/x11vnc/ssltools.h index c261af9..a2d6499 100644 --- a/x11vnc/ssltools.h +++ b/x11vnc/ssltools.h @@ -694,12 +694,16 @@ char find_display[] = "# display + xauth info to caller (x11vnc running as root or nobody).\n" "# x11vnc then uses the info to open the display.\n" "#\n" +"# If not called with -unixpw, root, etc. uses current $USER.\n" "\n" "#FIND_DISPLAY_OUTPUT=/tmp/fdo.$USER.txt\n" +"\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" +" # we rerun ourselves with verbose output to a file:\n" +" #\n" " if [ \"X$FIND_DISPLAY_OUTPUT\" != \"X\" ]; then\n" " /bin/sh $0 \"$@\" 2> $FIND_DISPLAY_OUTPUT\n" " else\n" @@ -710,13 +714,19 @@ char find_display[] = "fi\n" "\n" "if [ \"X$FIND_DISPLAY_OUTPUT\" != \"X\" ]; then\n" +" # turn on verbose output\n" +" set -xv\n" +"fi\n" +"if [ \"X$FIND_DISPLAY_DEBUG\" != \"X\" ]; then\n" +" # print environment and turn on verbose output\n" +" env\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" "\n" +"# This is to try to trick ps(1) into writing wide lines: \n" "COLUMNS=256\n" "export COLUMNS\n" "\n" @@ -726,6 +736,8 @@ char find_display[] = " showxauth=\"\"\n" " shift\n" "fi\n" +"\n" +"# -f means use this xauthority file:\n" "if [ \"X$1\" = \"X-f\" ]; then\n" " shift\n" " if [ ! -r $1 ]; then\n" @@ -736,6 +748,8 @@ char find_display[] = " shift\n" "fi\n" "\n" +"# we need to set user:\n" +"#\n" "user=\"$1\" # cmd line arg takes precedence\n" "if [ \"X$user\" = \"X\" ]; then\n" " user=$X11VNC_USER # then X11VNC_USER\n" @@ -754,20 +768,30 @@ char find_display[] = " exit 1\n" "fi\n" "\n" +"# util to try to match a display with a Linux VT and print\n" +"# disp,VT=... etc. Otherwise just print out display.\n" +"#\n" "prdpy () {\n" " d1=$1\n" " chvt0=\"\"\n" +" # we can only do chvt on Linux:\n" " if [ \"X$uname\" = \"XLinux\" ]; then\n" " d2=$d1\n" " d3=`echo \"$d2\" | sed -e 's/^.*:/:/' -e 's/\\..*$//'`\n" " d4=\"($d2|$d3)\"\n" +"\n" +" # vt is usually in X server line:\n" +" #\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" +"\n" " if [ \"X$vt\" != \"X\" ]; then\n" +" # strip it out and add it.\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" +" # otherwise look for tty:\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" @@ -775,21 +799,27 @@ char find_display[] = " chvt0=\",VT=$vt\"\n" " fi\n" " else\n" +" # otherwise try lsof:\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" +" # if this fails, at least tell them the XPID:\n" " chvt0=\",XPID=$pvt\"\n" " fi\n" " fi\n" " fi\n" " fi\n" " fi\n" +"\n" +" # return the string, possibly with ,VT=... appended:\n" +" #\n" " echo \"$d1$chvt0\"\n" "}\n" "\n" +"# save uname, netstat, and ps output:\n" "uname=`uname`\n" "nsout=`netstat -an`\n" "if [ \"X$uname\" = \"XDarwin\" ]; then\n" @@ -800,6 +830,10 @@ char find_display[] = " pslist=`echo \"$psout\" | awk '{print $2}'`\n" "fi\n" "\n" +"# this mode is to try to grab a display manager (gdm, kdm, xdm...) display\n" +"# when we are run as root (e.g. no one is logged in yet). We look at the\n" +"# -auth line in the X/Xorg commandline.\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" @@ -807,6 +841,8 @@ char find_display[] = " da=`echo \"$pair\" | awk -F, '{print $1}'`\n" " xa=`echo \"$pair\" | awk -F, '{print $2}'`\n" " if [ -f $xa -a -r $xa ]; then\n" +" # if we have an xauth file, we proceed to test it:\n" +" #\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" @@ -814,6 +850,7 @@ char find_display[] = " y=`prdpy $da`\n" " echo \"DISPLAY=$y\"\n" " if [ \"X$showxauth\" != \"X\" ]; then\n" +" # copy the cookie:\n" " cook=`xauth -f \"$xa\" list | head -n 1 | awk '{print $NF}'`\n" " tf=$HOME/.xat.$$\n" " rm -f $tf\n" @@ -838,6 +875,7 @@ char find_display[] = " xauth -f $tf extract - \"$da\" 2>/dev/null\n" " rm -f $tf\n" " fi\n" +" # DONE\n" " exit 0\n" " fi\n" " fi\n" @@ -847,26 +885,54 @@ char find_display[] = " if [ \"X$showxauth\" != \"X\" ]; then\n" " echo \"\"\n" " fi\n" +" # DONE\n" " exit 1\n" "fi\n" "\n" -"# Now try to match X DISPLAY to user:\n" +"# Normal case here (not xdm...).\n" +"\n" +"# 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 2>/dev/null | grep \"^${user}[ ][ ]*:[0-9]\" | egrep -v \" ($gone)\\>\" | head -n 1 \\\n" "# | awk '{print $2}' | sed -e 's,/.*$,,'`\n" +"\n" "poss=\"\"\n" "list=`who 2>/dev/null | grep \"^${user}[ ][ ]*:[0-9]\" | awk '{print $2}' | sed -e 's,/.*$,,'`\n" "list=\"$list \"`w -h \"$user\" 2>/dev/null | grep \"^${user}[ ][ ]*:[0-9]\" | awk '{print $2}' | sed -e 's,/.*$,,'`\n" "list=\"$list \"`who 2>/dev/null | grep \"^${user}[ ]\" | awk '{print $NF}' | grep '(:[0-9]' | sed -e 's/[()]//g'`\n" "host=`hostname 2>/dev/null | sed -e 's/\\..*$//'`\n" +"\n" "if [ \"X$X11VNC_FINDDISPLAY_SKIP_XAUTH\" = \"X\" ]; then\n" +" # do a normal xauth list:\n" " list=\"$list \"`xauth list | awk '{print $1}' | grep /unix | grep \"^${host}\" | sed -e 's/^.*:/:/' | sort -n | uniq`\n" +"\n" +" # check for gdm and kdm non-NFS cookies in /tmp:\n" +" for xa in /tmp/.gdm* /tmp/.Xauth*\n" +" do\n" +" # try to be somewhat careful about the real owner of the file:\n" +" if id | sed -e 's/ gid.*$//' | grep -w root > /dev/null; then\n" +" break\n" +" fi\n" +" if [ -f $xa -a -r $xa ]; then\n" +" if ls -l \"$xa\" | sed -e 's,/tmp.*$,,' | grep -w \"$user\" > /dev/null; then\n" +" # append these too:\n" +" if find \"$xa\" -user \"$user\" -perm 600 > /dev/null; then\n" +" :\n" +" else\n" +" continue\n" +" fi\n" +" # it passes the ownership tests, add it:\n" +" list=\"$list \"`xauth -f \"$xa\" list | awk '{print $1}' | grep /unix | grep \"^${host}\" | sed -e 's/^.*:/:/' | sort -n | uniq | sed -e \"s,\\$,\\,$xa,\"`\n" +" fi\n" +" fi\n" +" done\n" "fi\n" "\n" "if [ \"X$uname\" = \"XDarwin\" ]; then\n" +" # macosx uses \"console\" string (in leopard X11 runs/launched by default)\n" " if who 2>/dev/null | grep -i \"^${user}[ ][ ]*console[ ]\" > /dev/null; then\n" " echo \"DISPLAY=console\"\n" " if [ \"X$FIND_DISPLAY_ALL\" = \"X\" ]; then\n" @@ -878,12 +944,15 @@ char find_display[] = " fi\n" "fi\n" "\n" +"# try the items in the list:\n" +"#\n" "for p in $list\n" "do\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" +" # user supplied skip list:\n" " mat=\"\"\n" " for skip in `echo $X11VNC_SKIP_DISPLAY | tr ',' '\\n'`\n" " do\n" @@ -902,6 +971,8 @@ char find_display[] = " continue\n" " fi\n" " fi\n" +"\n" +" # check for the local X11 files:\n" " xd=\"/tmp/.X11-unix/X$d\"\n" " if [ -r \"$xd\" -o -w \"$xd\" -o -x \"$xd\" ]; then\n" " if echo \"$nsout\" | grep \"/tmp/.X11-unix/X$d[ ]*\\$\" > /dev/null; then\n" @@ -909,6 +980,7 @@ char find_display[] = " fi\n" " fi\n" " if [ \"X$ok\" = \"X\" ]; then\n" +" # instead check for the lock:\n" " if [ -f \"/tmp/.X$d-lock\" ]; then\n" " pid=`cat \"/tmp/.X$d-lock\" | sed -e 's/[ ]//g'`\n" " if echo \"$pid\" | grep '^[0-9][0-9]*$' > /dev/null; then\n" @@ -922,14 +994,21 @@ char find_display[] = " fi\n" " fi\n" " fi\n" +"\n" " if [ \"X$ok\" = \"X1\" ]; then\n" +" # ok, put it on the list\n" " poss=\"$poss $p\"\n" +" if [ \"X$xa\" != \"X\" ]; then\n" +" # xauth file too, if applicable\n" +" poss=\"$poss,$xa\"\n" +" fi\n" " fi\n" "done\n" "\n" "seenvalues=\"\"\n" "\n" "seen() {\n" +" # simple util to skip repeats\n" " v=$1\n" " if [ \"X$seenvalues\" != \"X\" ]; then\n" " for v2 in $seenvalues\n" @@ -948,9 +1027,14 @@ char find_display[] = " seenret=0\n" "}\n" "\n" +"# now get read to try each one in $poss\n" +"#\n" "poss=`echo \"$poss\" | sed -e 's/^ *//' -e 's/ *$//'`\n" +"display=\"\"\n" +"xauth_use=\"\"\n" "\n" "if [ \"X$X11VNC_FINDDISPLAY_SKIP_XAUTH\" != \"X\" ]; then\n" +" # we are not supposed to call xauth(1), simply report\n" " if [ \"X$FIND_DISPLAY_ALL\" != \"X\" ]; then\n" " for p in $poss\n" " do\n" @@ -961,6 +1045,8 @@ char find_display[] = " if [ \"X$seenret\" = \"X1\" ]; then\n" " continue\n" " fi\n" +" # get rid of any ,xauth\n" +" p=`echo \"$p\" | sed -e 's/,.*$//'`\n" " y=`prdpy $p`\n" " echo $y\n" " done\n" @@ -969,6 +1055,7 @@ char find_display[] = " display=`echo \"$poss\" | tr ' ' '\\n' | head -n 1`\n" "else\n" " freebie=\"\"\n" +" xauth_freebie=\"\"\n" " for p in $poss\n" " do\n" " if [ \"X$p\" = \"X\" ]; then\n" @@ -978,22 +1065,47 @@ char find_display[] = " if [ \"X$seenret\" = \"X1\" ]; then\n" " continue\n" " fi\n" -" xdpyinfo -display \"$p\" >/dev/null 2>&1\n" +"\n" +" # extract ,xauth if any.\n" +" xa=\"\"\n" +" xa=`echo \"$p\" | awk -F, '{print $2}'`\n" +" p=`echo \"$p\" | sed -e 's/,.*$//'`\n" +"\n" +" # check xauth for it:\n" +" if [ \"X$xa\" != \"X\" ]; then\n" +" XAUTHORITY=\"$xa\" xdpyinfo -display \"$p\" >/dev/null 2>&1\n" +" else\n" +" xdpyinfo -display \"$p\" >/dev/null 2>&1\n" +" fi\n" +"\n" " if [ $? = 0 ]; then\n" " if [ \"X$FD_TAG\" != \"X\" ]; then\n" -" if xprop -display \"$p\" -root -len 128 FD_TAG | grep -iv no.such.atom \\\n" -" | grep \"=[ ][ ]*\\\"$FD_TAG\\\"\" > /dev/null; then\n" -" :\n" +" # look for x11vnc special FD_TAG property:\n" +" if [ \"X$xa\" = \"X\" ]; then\n" +" if xprop -display \"$p\" -root -len 128 FD_TAG | grep -iv no.such.atom \\\n" +" | grep \"=[ ][ ]*\\\"$FD_TAG\\\"\" > /dev/null; then\n" +" :\n" +" else\n" +" continue\n" +" fi\n" " else\n" -" continue\n" +" if env XAUTHORITY=\"$xa\" xprop -display \"$p\" -root -len 128 FD_TAG | grep -iv no.such.atom \\\n" +" | grep \"=[ ][ ]*\\\"$FD_TAG\\\"\" > /dev/null; then\n" +" :\n" +" else\n" +" continue\n" +" fi\n" " fi\n" " fi\n" -" # try again with no authority:\n" +"\n" +" # Now try again with no authority:\n" " env XAUTHORITY=/dev/null xdpyinfo -display \"$p\" >/dev/null 2>&1\n" -" # 0 means got in for free... skip it.\n" +"\n" +" # 0 means got in for free... skip it unless we don't find anything else.\n" " if [ $? != 0 ]; then\n" " # keep it\n" " display=\"$p\"\n" +" xauth_use=\"$xa\"\n" " if [ \"X$FIND_DISPLAY_ALL\" != \"X\" ]; then\n" " y=`prdpy $p`\n" " echo \"DISPLAY=$y\"\n" @@ -1001,6 +1113,7 @@ char find_display[] = " fi\n" " break\n" " else\n" +" # store in freebie as fallback\n" " if [ \"X$FIND_DISPLAY_ALL\" != \"X\" ]; then\n" " y=`prdpy $p`\n" " echo \"$y,NOXAUTH\"\n" @@ -1008,16 +1121,20 @@ char find_display[] = " fi\n" " if [ \"X$freebie\" = \"X\" ]; then\n" " freebie=\"$p\"\n" +" xauth_freebie=\"$xa\"\n" " fi\n" " fi\n" " fi\n" " done\n" " if [ \"X$display\" = \"X\" -a \"X$freebie\" != \"X\" ]; then\n" +" # fallback to the freebie (if any)\n" " display=\"$freebie\"\n" +" xauth_use=\"$xauth_freebie\"\n" " fi\n" "fi\n" "\n" "if [ \"X$FIND_DISPLAY_ALL\" != \"X\" ]; then\n" +" # we have listed everything, get out.\n" " exit\n" "fi\n" "if [ \"X$display\" = \"X\" ]; then\n" @@ -1030,11 +1147,25 @@ char find_display[] = " exit 1\n" "fi\n" "\n" +"# append ,VT=n if applicable:\n" "dpy2=`prdpy \"$display\"`\n" "\n" "echo \"DISPLAY=$dpy2\"\n" +"if [ \"X$FIND_DISPLAY_XAUTHORITY_PATH\" != \"X\" ]; then\n" +" # caller wants XAUTHORITY printed out too.\n" +" if [ \"X$xauth_use\" != \"X\" -a -f \"$xauth_use\" ]; then\n" +" echo \"XAUTHORITY=$xauth_use\"\n" +" else\n" +" echo \"XAUTHORITY=$XAUTHORITY\"\n" +" fi\n" +"fi\n" "if [ \"X$showxauth\" != \"X\" ]; then\n" -" xauth extract - \"$display\" 2>/dev/null\n" +" # show the (binary) xauth data:\n" +" if [ \"X$xauth_use\" != \"X\" -a -f \"$xauth_use\" ]; then\n" +" xauth -f \"$xauth_use\" extract - \"$display\" 2>/dev/null\n" +" else\n" +" xauth extract - \"$display\" 2>/dev/null\n" +" fi\n" "fi\n" "\n" "exit 0\n" |