Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/WineTestBot/TestAgent.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/testbot/lib/WineTestBot/TestAgent.pm b/testbot/lib/WineTestBot/TestAgent.pm index 7934070779..6457b4dd7d 100644 --- a/testbot/lib/WineTestBot/TestAgent.pm +++ b/testbot/lib/WineTestBot/TestAgent.pm @@ -1400,16 +1400,17 @@ sub Rm($@) return $self->_RecvErrorList(); }
-sub SetTime($) +sub SetTime($;$) { - my ($self) = @_; - debug("SetTime\n"); + my ($self, $Leeway) = @_; + $Leeway ||= 30; + debug("SetTime $Leeway\n");
# Send the command if (!$self->_StartRPC($RPC_SETTIME) or !$self->_SendListSize('ArgC', 2) or !$self->_SendUInt64('Time', time()) or - !$self->_SendUInt32('Leeway', 30)) + !$self->_SendUInt32('Leeway', $Leeway)) { return undef; }
The SetTime() leeway should be 0 otherwise it may skip actually setting the time and thus not fail if privileges are insufficient.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- The 'high privileges' detection is usually only done once and before the VM's time has been updated. Since this normally happens a lot more than 30 seconds after the live snapshot has been created this is normally not an issue. It would likely fail for powered-off snapshots however since they update their time on boot. --- testbot/bin/LibvirtTool.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index 5e3e7afb6c..ff834efdc7 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -278,7 +278,7 @@ sub GetPrivilegedTA($) my ($TA) = @_;
# Use SetTime() to detect if privileged operations are allowed. - return $TA->SetTime() ? $TA : $VM->GetAgent(1); + return $TA->SetTime(0) ? $TA : $VM->GetAgent(1); }
sub RunAndWait($$) @@ -582,7 +582,7 @@ sub PrepareVM($) # during the build some ccache versions will return a compilation error). my $PTA = GetPrivilegedTA($TA); FatalError("$VMKey has no privileged TestAgent server\n") if (!$PTA); - if (!$PTA->SetTime()) + if (!$PTA->SetTime(0)) { FatalError("Setting the $VMKey system time failed: ". $PTA->GetLastError() ."\n"); }
This adds a task to run TestAgentd without elevated privileges and modifies the original task so it does not interfere. Note that schtasks.exe asks for a password so use the Powershell APIs instead.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- This depends on part 1's 'high privileges' detection fix. --- testbot/bin/LibvirtTool.pl | 19 +++++- testbot/bin/LibvirtTool.ps1 | 119 ++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 testbot/bin/LibvirtTool.ps1
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index ff834efdc7..bd676f03d1 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -610,7 +610,7 @@ sub GetSnapshotConfig($) { $Config->{locale} ||= $1; # take only the last match } - elsif ($Config->{base} =~ s/-(live|off|tsign|u8)$//) + elsif ($Config->{base} =~ s/-(adm|live|off|tsign|u8)$//) { $Config->{$1} = 1; } @@ -693,6 +693,23 @@ sub CreateSnapshot($$$$) } }
+ if ($Config->{adm}) + { + # Takes effect after the next reboot + my $PS1 = "$0.ps1"; + $PS1 =~ s/.pl//; + if (!$TA->SendFile($PS1, "$Name0.ps1", 0)) + { + FatalError("Could not send '$Name0.ps1'\n"); + } + if (RunAndWait($PTA, ["powershell.exe", "-ExecutionPolicy", "ByPass", + "-File", "$Name0.ps1", "admin", $AgentPort])) + { + FatalError("Could not set up the TestAgentd tasks on $VMKey\n"); + } + $PTA->Rm("$Name0.ps1"); + } + $Reboot = 1; }
diff --git a/testbot/bin/LibvirtTool.ps1 b/testbot/bin/LibvirtTool.ps1 new file mode 100644 index 0000000000..e2b2d1281e --- /dev/null +++ b/testbot/bin/LibvirtTool.ps1 @@ -0,0 +1,119 @@ +# Shows or sets up the TestAgentd tasks +# +# Copyright 2022 Francois Gouget +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +$Name0 = (Get-Item $MyInvocation.InvocationName).Basename + + +# +# Show the existing tasks +# + +function ShowTask($Name) +{ + $Task = Get-ScheduledTask -TaskName $Name -ErrorAction SilentlyContinue + if ($Task -ne $null) + { + Write-Output "$Name.User=$($Task.Principal.UserId)" + Write-Output "$Name.RunLevel=$($Task.Principal.RunLevel)" + Write-Output "$Name.Execute=$($Task.Actions.Execute)" + Write-Output "$Name.Arguments=$($Task.Actions.Arguments)" + Write-Output "$Name.WorkingDirectory=$($Task.Actions.WorkingDirectory)" + Write-Output "$Name.NotOnBatteries=$($Task.Settings.DisallowStartIfOnBatteries)" + } + else + { + Write-Output "$Name=<no such task>" + } +} + +function ShowTasks() +{ + ShowTask "TestAgentd" + ShowTask "TestAgentdAdm" + exit 0 +} + + +# +# Sets up split tasks +# + +function SetupAdminTasks($Argv) +{ + $Port = [int]$Argv[1] + $Task = Get-ScheduledTask -TaskName TestAgentd -ErrorAction SilentlyContinue + if ($Task -eq $null) + { + echo "$Name0:error: the TestAgentd task does not exist!" + exit 1 + } + $WorkDir = $Task.Actions.WorkingDirectory + if ($WorkDir -eq $null) + { + $WorkDir = Split-Path $Task.Actions.Execute + } + + # Modify the 'elevated privileges' server to start on the alternate port + $HighPort = $Port + 1 + $Action = New-ScheduledTaskAction -Execute $Task.Actions.Execute -Argument "--detach --set-time-only $HighPort" -WorkingDirectory $WorkDir + Set-ScheduledTask -TaskName TestAgentd -Action $Action + + # Add a 'regular privileges' server on the regular port + $Action = New-ScheduledTaskAction -Execute $Task.Actions.Execute -Argument "--detach --show-restarts $Port" -WorkingDirectory $WorkDir + $AdmTask = Get-ScheduledTask -TaskName TestAgentdAdm -ErrorAction SilentlyContinue + if ($AdmTask -eq $null) + { + Register-ScheduledTask -TaskName TestAgentdAdm -Action $Action -Trigger $Task.Triggers -Settings $Task.Settings + } + else + { + Set-ScheduledTask -TaskName TestAgentdAdm -Action $Action + } + exit 0 +} + + +# +# Main +# + +function ShowUsage() +{ + Write-Output "Usage: $Name0 show" + Write-Output "or $Name0 admin PORT" + Write-Output "" + Write-Output "Shows or modifies the Windows locales." + Write-Output "" + Write-Output "Where:" + Write-Output " show Shows the existing TestAgentd tasks." + Write-Output " admin Sets up a separate not-elevated-privileges task." + Write-Output " PORT Specifies the port TestAgentd should listen on." + Write-Output " -? Shows this help message." +} + +$Action = $args[0] +if ($Action -eq "show") { ShowTasks } +if ($Action -eq "admin") { SetupAdminTasks $args } +$Rc = 0 +if ($Action -and $Action -ne "-?" -and $Action -ne "-h" -and $Action -ne "help") +{ + echo "$Name0:error: unknown action $Action" + $Rc = 2 +} +ShowUsage +exit $Rc