KEMBAR78
fix askpass named pipe name path prefix by awakecoding · Pull Request #402 · gerardog/gsudo · GitHub
Skip to content

Conversation

awakecoding
Copy link

In my original pull request (#388) adding support for the GSUDO_ASKPASS_NAMED_PIPE environment variable, I made a minor mistake: the named pipe name should not include the \.\pipe\ path prefix.

Here is how to properly test this feature:

Save this to an AskpassNamedPipeServer.ps1 file:

param (
    [string] $PipeName = "MyNamedPipe",
    [string] $Password = "MySecretPassword"
)

$FullPipeName = "\\.\pipe\$PipeName"
$PipeServer = New-Object System.IO.Pipes.NamedPipeServerStream($PipeName, [System.IO.Pipes.PipeDirection]::Out)

Write-Host "Waiting for client to connect to the pipe '$FullPipeName'..."

$PipeServer.WaitForConnection()
$StreamWriter = New-Object System.IO.StreamWriter($PipeServer)
$StreamWriter.WriteLine($Password)
$StreamWriter.Flush()
$StreamWriter.Close()
$PipeServer.Close()

Write-Host "Password sent through the named pipe and connection closed."

Open a PowerShell terminal, and launch the script:

.\AskpassNamedPipeServer.ps1 "MyNamedPipe" "MySecretPassword"

In another terminal, launch gsudo.exe with the -u parameter for a valid user, setting the GSUDO_ASKPASS_NAMED_PIPE environment variable to point to your named pipe:

$Env:GSUDO_ASKPASS_NAMED_PIPE="MyNamedPipe"
.\gsudo.exe -u validuser

If everything worked, you should see the named pipe server printing out that it "served" the password and closed. gsudo checks if the user exists first, so it will only try to read from the named pipe if the user exists.

@awakecoding
Copy link
Author

the CI test failure appears unrelated to the changes I have made

@awakecoding awakecoding force-pushed the askpass-named-pipe-fix branch from ac06afa to ea3b717 Compare May 22, 2025 13:01
@awakecoding
Copy link
Author

@gerardog it looks like there's a permission issue for some of the GitHub Actions? I wonder if it's caused by who triggers the CI
build from a pull request?

image

I really need this fix

@gerardog gerardog merged commit 10725f2 into gerardog:master May 23, 2025
3 checks passed
@gerardog
Copy link
Owner

Hi Marc. I hadn't realized that the builds were failing. I thought you had a signed CI build available already. Sorry for the delay.
I've updated dorny/test-reporter action to v2.1.0... and the build finally passed... but yeah it was me who triggered the build...

You can fetch signed binaries with version v2.6.1+5 from this master branch build.
I will wait to hear back from you if this one worked, before creating a public release.

Thanks for the collaboration!

@gerardog
Copy link
Owner

Sorry, the previous build was unsigned, try this one.
https://github.com/gerardog/gsudo/actions/runs/15211054869

@JDelSignore
Copy link

Hi @gerardog , using the new build I'm getting stuck trying to launch powershell after entering the password. Is there a known issue?

2.6.0 (working):
image

2.6.1 (not working):
image

@gerardog
Copy link
Owner

gerardog commented Jun 7, 2025

Hi @JDelSignore.

2.6.1 is same as 2.6.0 except for @awakecoding fix.
See v2.6.0...v2.6.1-preview.1

2.6.1 is not commonly downloaded, as it is a preview build with no users. So it's possible that your antivirus software treats it differently, for example show a popup.

Are you invoking gsudo from a Windows Powershell instance in both screenshots? I can't tell from the above screenshot if the shell you are calling from is Powershell v5.1 or Pwsh v7.4.

Can you try gsudo --debug -u user -d pwsh.exe ? the --debug will add debug info to the output, and the -d will make gsudo elevate the pwsh.exe directly without using an intermediate pwsh.exe to parse the pwsh.exe part.

@JDelSignore
Copy link

@gerardog Sorry didn't realise I cropped the first screenshot, yes both times I ran Windows Powershell 7.4.

Here are the results for 2.6.0 vs 2.6.1 with debug enabled:

2.6.0
image

2.6.1
image

@JDelSignore
Copy link

And from the gsudo console:

2.6.0
image

2.6.1
image

@JDelSignore
Copy link

@gerardog Turns out that it works fine on a VM, so it must be Sophos that blocks it on my host like you said. Pretty safe to say it's OK to release.

@awakecoding
Copy link
Author

@gerardog don't hold the release for the suspected Sophos issue, but I did spend some time trying to figure out why it hangs, and the plot thickens. Sophos-related DLLs do get loaded into gsudo.exe, but I confirmed with IT and it's not getting blocked - so whatever happens, it's probably not intentional interference.

I built the exact same version locally and it runs just fine - release, unsigned. I removed the signature from your preview build, but it didn't change anything. I've done a bit of procmon to see if I could identify a difference in behavior: I launched gsudo.exe from cmd.exe to more easily filter on pwsh.exe without background noise from unrelated pwsh.exe instances.

Here's a local build that works, launched with --debug. I can see a first gsudo.exe terminal pop for a second to be replaced by a second one, and the original command prompt correctly gets attached to a pwsh.exe process:

image

In procexp, we can see the full chain of processes for the "happy path" scenario:

image

Here's your prebuilt gsudo.exe launched in the same way, it somehow gets stuck on the first gsudo.exe terminal, and I confirmed in procmon that pwsh.exe is never launched (and apparently isn't even attempted to be launched, no file operations on pwsh.exe show up in procmon):

image

Here's the chain of processes for the "sad path" scenario:

image

I get the feeling that this is a one-off weird thing that happened just for that one preview build you did, and I'm crossing fingers a new build would work just like the 2.6.0 release build does. Does this give you a hint about a possible root cause for the problem?

@JDelSignore
Copy link

Hi @gerardog Do you have an ETA for when 2.6.1 will be released with this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants