diff options
author | Koichiro IWAO <meta@vmeta.jp> | 2016-10-04 17:17:06 +0900 |
---|---|---|
committer | Koichiro IWAO <meta@vmeta.jp> | 2016-10-05 16:58:46 +0900 |
commit | 31cad948089ba3f7b848b4f1376db33c4879cc20 (patch) | |
tree | 17adfcd2a00be1fb831673673c518d1f78c673f6 | |
parent | 977fbde28d7fd6b60dacc035161f949c5cdbd662 (diff) | |
download | tigervnc-31cad948089ba3f7b848b4f1376db33c4879cc20.tar.gz tigervnc-31cad948089ba3f7b848b4f1376db33c4879cc20.zip |
Do not depends on mcookie command
for operating systems other than GNU/Linux.
mcookie is a part of util-linux. Usually only GNU/Linux systems have it.
Do not die even if mcookie is not found. Use the previous pure perl code
to generate cookie as fallback.
-rwxr-xr-x | unix/vncserver | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/unix/vncserver b/unix/vncserver index c59106ca..2ef436a7 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -293,8 +293,24 @@ $desktopLog = "$vncUserDir/$host:$displayNumber.log"; unlink($desktopLog); # Make an X server cookie and set up the Xauthority file - +# mcookie is a part of util-linux, usually only GNU/Linux systems have it. $cookie = `mcookie`; +# Fallback for non GNU/Linux OS - use /dev/urandom on systems that have it, +# otherwise use perl's random number generator, seeded with the sum +# of the current time, our PID and part of the encrypted form of the password. +if ($cookie eq "" && open(URANDOM, '<', '/dev/urandom')) { + my $randata; + if (sysread(URANDOM, $randata, 16) == 16) { + $cookie = unpack 'h*', $randata; + } + close(URANDOM); +} +if ($cookie eq "") { + srand(time+$$+unpack("L",`cat $vncUserDir/passwd`)); + for (1..16) { + $cookie .= sprintf("%02x", int(rand(256)) % 256); + } +} open(XAUTH, "|xauth -f $xauthorityFile source -"); print XAUTH "add $host:$displayNumber . $cookie\n"; @@ -818,7 +834,7 @@ sub SanityCheck # cmd: - foreach $cmd ("uname","mcookie","xauth") { + foreach $cmd ("uname","xauth") { for (split(/:/,$ENV{PATH})) { if (-x "$_/$cmd") { next cmd; |