From 746151718030fff72a441633e5ac97f276245624 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 29 Dec 2015 14:27:07 +0100 Subject: [PATCH] Use mcookie to generate X server cookie --- unix/vncserver | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/unix/vncserver b/unix/vncserver index a4d6ad93..725cbd54 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -238,24 +238,9 @@ $vncPort = 5900 + $displayNumber; $desktopLog = "$vncUserDir/$host:$displayNumber.log"; unlink($desktopLog); -# Make an X server cookie - 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. - -my $cookie = ""; -if (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); - } -} +# Make an X server cookie and set up the Xauthority file + +$cookie = `mcookie`; system("xauth -f $xauthorityFile add $host:$displayNumber . $cookie"); system("xauth -f $xauthorityFile add $host/unix:$displayNumber . $cookie"); @@ -791,7 +776,7 @@ sub SanityCheck # cmd: - foreach $cmd ("uname","xauth") { + foreach $cmd ("uname","mcookie","xauth") { for (split(/:/,$ENV{PATH})) { if (-x "$_/$cmd") { next cmd; -- 2.39.5