From a6e9f94e27f8a040f7dd6cec53858a7b6d47ffab Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Tue, 3 Aug 2021 00:16:16 +1200 Subject: [PATCH] vncserver: load .kasmpasswd users --- unix/vncserver | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/unix/vncserver b/unix/vncserver index 0c6a046..3732fc2 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -95,6 +95,7 @@ my %config; $kasmAuthEnabled = 1; $kasmPasswdFile = "$ENV{HOME}/.kasmpasswd"; +@kasmPasswdUsers = &LoadKasmPasswdUsers(); if ($kasmAuthEnabled) { &TellUserToSetupUserAndPassword(); @@ -842,15 +843,33 @@ sub DisableVncAuth() { } sub TellUserToSetupUserAndPassword { - if (!(-e $kasmPasswdFile)) { - warn "\nYou will require a password to access your desktops.\n\n"; - system($exedir."kasmvncpasswd $kasmPasswdFile"); - if (($? >> 8) != 0) { - exit 1; - } + if (scalar @kasmPasswdUsers > 0) { + return; + } + + warn "\nYou will require a password to access your desktops.\n\n"; + system($exedir."kasmvncpasswd $kasmPasswdFile"); + if (($? >> 8) != 0) { + exit 1; } } +sub LoadKasmPasswdUsers { + my @result = (); + + open(FH, '<', $kasmPasswdFile) or return @result; + + while(){ + $_ =~ /^([^:]+):/ or die "$kasmPasswdFile is incorrect"; + push(@result, $1); + } + + close(FH); + + return @result; +} + + sub MakeXCookie { # 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.