Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bucket/openssh.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@
}
}
},
"post_install": [
"$real = (Get-Item $dir -Force).Target; if (!$real) { $real = $dir }",
"$q = [char]34",
"Set-Content \"$dir\\fix.ps1\" @(\"sc.exe config sshd binPath= ${q}${real}\\sshd.exe${q}\", \"sc.exe config ssh-agent binPath= ${q}${real}\\ssh-agent.exe${q}\") -Encoding UTF8",
Comment on lines +46 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Generated fix.ps1 drops the binPath quotes, breaking paths with spaces.

The post-install command writes sc.exe config sshd binPath= "…\sshd.exe" into fix.ps1. When PowerShell 5.1 later executes that line it treats the outer "…" as a string literal, strips the delimiters, and hands sc.exe the bare path. For paths without spaces the stored registry ImagePath is correct; but for a Scoop root that contains spaces (e.g. C:\Users\My User\scoop\…), sc.exe stores an unquoted path and the SCM tokenises at the first space on service start — exactly the failure mode this PR is trying to fix.

The registry ImagePath must contain the path wrapped in double-quote characters for SCM to handle spaces correctly.

Replace the $q auxiliary line and both sc.exe strings with a parenthesised single-quoted expression — ('"…"') — which produces a PS string value that includes the literal double-quote chars and forwards them untouched to sc.exe:

🐛 Proposed fix for sc.exe binPath quoting
-        "$q = [char]34",
-        "Set-Content \"$dir\\fix.ps1\" @(\"sc.exe config sshd binPath= ${q}${real}\\sshd.exe${q}\", \"sc.exe config ssh-agent binPath= ${q}${real}\\ssh-agent.exe${q}\") -Encoding UTF8",
+        "Set-Content \"$dir\\fix.ps1\" @(\"sc.exe config sshd binPath= ('`\"${real}\\sshd.exe`\"')\", \"sc.exe config ssh-agent binPath= ('`\"${real}\\ssh-agent.exe`\"')\") -Encoding UTF8",

The generated fix.ps1 will then contain lines such as:

sc.exe config sshd binPath= ('"C:\actual\path\sshd.exe"')
sc.exe config ssh-agent binPath= ('"C:\actual\path\ssh-agent.exe"')

The single-quoted expression '"…"' evaluates to a string value that carries the double-quote characters, so sc.exe receives and stores "C:\actual\path\sshd.exe" (with quotes) in ImagePath. This is safe for both spaced and space-free paths.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bucket/openssh.json` around lines 46 - 47, The generated fix.ps1 currently
uses a $q helper and writes sc.exe config lines that lose their surrounding
double-quotes when PowerShell evaluates them; remove the "$q = [char]34" helper
and change the two sc.exe strings written by Set-Content (the sc.exe config sshd
binPath= ... and sc.exe config ssh-agent binPath= ... entries) to use a
parenthesised single-quoted expression that includes literal double-quote
characters around the real path (e.g. use ('"'+ <real path> + '"' ) style so the
resulting ImagePath in the registry includes the quote characters and preserves
paths with spaces).

"Set-Content \"$dir\\autostart-sshd.ps1\" @('Set-Service sshd -StartupType Automatic', 'Set-Service ssh-agent -StartupType Automatic') -Encoding UTF8"
],
"notes": [
"Windows 10 or higher includes this build of OpenSSH in the system itself, hence it is recommended to use the system OpenSSH there.",
"Run 'sudo $dir\\install-sshd.ps1' to install sshd and ssh-agent as a service.",
"Run 'sudo $dir\\uninstall-sshd.ps1' to uninstall the services."
"Run 'sudo $dir\\uninstall-sshd.ps1' to uninstall the services.",
"Run 'sudo $dir\\fix.ps1' to fix service binPath to absolute path.",
"Run 'sudo $dir\\autostart-sshd.ps1' to set sshd and ssh-agent to start automatically."
]
}