Skip to content

Commit

Permalink
Merge branch 'feature/cswin32' of https://github.com/gerardog/gsudo i…
Browse files Browse the repository at this point in the history
…nto feature/cswin32
  • Loading branch information
gerardog committed Mar 6, 2024
2 parents cf5b4f9 + 7b78ac8 commit ea8d7b6
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/gsudo/ProcessHosts/AttachedConsoleHost.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Security.Principal;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using gsudo.Helpers;
using gsudo.Rpc;
using Windows.Win32;
using Windows.Win32;
using static gsudo.Native.ConsoleApi;

namespace gsudo.ProcessHosts
Expand All @@ -16,7 +16,7 @@ namespace gsudo.ProcessHosts
// This mode is not enabled unless you use --attached.
class AttachedConsoleHost : IProcessHost
{
public bool SupportsSimultaneousElevations { get; } = true;
public bool SupportsSimultaneousElevations { get; } = false;

public async Task Start(Connection connection, ElevationRequest elevationRequest)
{
Expand All @@ -35,19 +35,16 @@ public async Task Start(Connection connection, ElevationRequest elevationRequest

try
{
try
{
System.Environment.CurrentDirectory = elevationRequest.StartFolder;
try
{
System.Environment.CurrentDirectory = elevationRequest.StartFolder;
}
catch (UnauthorizedAccessException ex)

Check warning on line 42 in src/gsudo/ProcessHosts/AttachedConsoleHost.cs

View workflow job for this annotation

GitHub Actions / Test

The variable 'ex' is declared but never used

Check warning on line 42 in src/gsudo/ProcessHosts/AttachedConsoleHost.cs

View workflow job for this annotation

GitHub Actions / Test

The variable 'ex' is declared but never used
{
{
throw new ApplicationException($"User \"{WindowsIdentity.GetCurrent().Name}\" can not access current directory \"{elevationRequest.StartFolder}\"");
}

var process = Helpers.ProcessFactory.StartAttached(elevationRequest.FileName, elevationRequest.Arguments);
}

PInvoke.FreeConsole();
PInvoke.AllocConsole();
var process = Helpers.ProcessFactory.StartAttached(elevationRequest.FileName, elevationRequest.Arguments);

WaitHandle.WaitAny(new WaitHandle[] { process.GetProcessWaitHandle(), connection.DisconnectedWaitHandle });
if (process.HasExited)
Expand Down Expand Up @@ -84,7 +81,7 @@ public async Task Start(Connection connection, ElevationRequest elevationRequest
finally
{
PInvoke.SetConsoleCtrlHandler(ConsoleHelper.IgnoreConsoleCancelKeyPress, false);
//PInvoke.FreeConsole();
PInvoke.FreeConsole();
await connection.FlushAndCloseAll().ConfigureAwait(false);
}
}
Expand Down

0 comments on commit ea8d7b6

Please sign in to comment.