Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use backslash for path displayed on Windows #719

Open
wants to merge 1 commit into
base: latestw_all
Choose a base branch
from

Conversation

akainth015
Copy link

PR Summary

Currently, ssh-keygen outputs the following, where the mixed slashes cause confusion

$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\aanand/.ssh/id_ed25519):
$ ssh-keygen -y
Enter file in which the key is (C:\Users\aanand/.ssh/id_ed25519):
$ ssh-add
Enter passphrase for C:\Users\aanand/.ssh/id_ed25519:

This pull request uses a _PATH_SEPARATOR macro to separate path elements with \ on Windows, and a / on other platforms. The new output is

$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\aanand\.ssh\id_ed25519):
$ ssh-keygen -y
Enter file in which the key is (C:\Users\aanand\.ssh\id_ed25519):
$ ssh-add
Enter passphrase for C:\Users\aanand\.ssh\id_ed25519:

to align with what a Windows user would expect to see.

PR Context

The confusion this issue causes is described in issues like this one.

@akainth015
Copy link
Author

@microsoft-github-policy-service agree

@akainth015
Copy link
Author

I have attempted to be conservative about this adjustment and aimed to correct the paths used in the client, and not in the server.

I have not rigorously tested these changes. Guidance about what scenarios need to be tested would be appreciated.

@@ -64,29 +72,29 @@
* readable by anyone except the user him/herself, though this does not
* contain anything particularly secret.
*/
#define _PATH_SSH_USER_HOSTFILE "~/" _PATH_SSH_USER_DIR "/known_hosts"
#define _PATH_SSH_USER_HOSTFILE "~" _PATH_SEPARATOR _PATH_SSH_USER_DIR _PATH_SEPARATOR "known_hosts"
Copy link
Author

Choose a reason for hiding this comment

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

Previously, a tab character was used here to align the text, but this did not work consistently across the editor and the terminal (the following line did not align in git diff). I replaced it with spaces so that it is consistent across viewing environments.

@tgauth
Copy link
Collaborator

tgauth commented Feb 12, 2024

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tgauth
Copy link
Collaborator

tgauth commented Feb 12, 2024

@akainth015 - looks like these changes break the CI during the E2E test setup, can you look into that?
At a quick glance, it's not clear to me if it's an actual issue or if the test setup just needs updating to work with the changes.

Info on running the tests is at https://github.com/PowerShell/Win32-OpenSSH/wiki/Run-OpenSSH-Pester-Tests

@akainth015
Copy link
Author

Are there more up-to-date instructions? The commands related to testing, on the wiki page related to testing error as follows.

Import-Module: The specified module 'OpenSSHUtils' was not loaded because no valid module file was found in any module directory.

Based upon this unexpected log message, something is going awry near this line. Once I can find a way to run the tests locally then I would be able to look into it further.

@tgauth
Copy link
Collaborator

tgauth commented Feb 21, 2024

Are there more up-to-date instructions? The commands related to testing, on the wiki page related to testing error as follows.

Import-Module: The specified module 'OpenSSHUtils' was not loaded because no valid module file was found in any module directory.

The OpenSSHUtils module is located in the bin with OpenSSH binaries or in the repo under /contrib/win32/openssh - https://github.com/PowerShell/openssh-portable/blob/latestw_all/contrib/win32/openssh/OpenSSHUtils.psm1

Please run Import-Module <path to OpenSSHUtils> then try the commands again.

@akainth015
Copy link
Author

No dice. I have also tried running the pester tests directly and running from within the .\bin\x64\Debug and .\contrib\win32\openssh directories. All fail with the same error.

~
❯ cd D:\openssh-portable\

openssh-portable on  latestw_all [!] via C
❯ Import-Module .\contrib\win32\openssh\OpenSSHUtils.psm1

openssh-portable on  latestw_all [!] via C
❯ Import-Module .\contrib\win32\openssh\OpenSSHBuildHelper.psm1 -Force

openssh-portable on  latestw_all [!] via C
❯ Start-OpenSSHBuild -Configuration Debug -NativeHostArch x64
C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
C:\Program Files\Microsoft Visual Studio\2022\Community
C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
Using MSBuild path: C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe
Starting Open SSH build; Build Log: D:\openssh-portable\contrib\win32\openssh\OpenSSHDebugx64.log.
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe D:\openssh-portable\contrib\win32\openssh\Win32-OpenSSH.sln /t:Rebuild /p:Platform=x64 /p:Configuration=Debug /m /nologo /fl /flp:LogFile=D:\openssh-portable\contrib\win32\openssh\OpenSSHDebugx64.log;Append;Verbosity=diagnostic /noconlog
SSH build successful.

openssh-portable on  latestw_all [!] via C took 29s
❯ Import-Module .\contrib\win32\openssh\OpenSSHTestHelper.psm1 -Force

openssh-portable on  latestw_all [!] via C
❯ Set-OpenSSHTestEnvironment -Confirm:$false -OpenSSHBinPath .\bin\x64\Debug\
VERBOSE: Installing Module OpenSSHUtils...
Import-Module: The specified module 'OpensshUtils' was not loaded because no valid module file was found in any module directory.

@tgauth
Copy link
Collaborator

tgauth commented Mar 4, 2024

hmm, are you using Windows PowerShell (5.1) or PowerShell core (7.4)?

Can you try the following, based on https://github.com/PowerShell/openssh-portable/blob/latestw_all/.azdo/ci.yml#L198:
Import-Module -Name "D:\openssh-portable\contrib\win32\openssh\AzDOBuildTools" -Force
Invoke-OpenSSHTests -OpenSSHBinPath "D:\openssh-portable\bin\x64\debug"

@akainth015
Copy link
Author

I am using PowerShell 7.4.1. The Import-Module succeeded, but it did not help with getting the tests to run. The error message did not change.

I have also tried in Windows PowerShell 5.1. Here are the results of that.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\aanand> cd D:\openssh-portable\
PS D:\openssh-portable> Import-Module -Name "D:\openssh-portable\contrib\win32\openssh\AzDOBuildTools" -Force
PS D:\openssh-portable> Import-Module .\contrib\win32\openssh\OpenSSHTestHelper.psm1 -Force
PS D:\openssh-portable> Set-OpenSSHTestEnvironment -Confirm:$false -OpenSSHBinPath .\bin\x64\Debug\
VERBOSE: Installing Module OpenSSHUtils...
Copy-item : Could not find a part of the path 'C:\Program Files\WindowsPowerShell\Modules\OpenSSHUtils\1.0.0.1'.
At D:\openssh-portable\contrib\win32\openssh\OpenSSHTestHelper.psm1:465 char:5
+     Copy-item "$manifestFile" -Destination "$targetDirectory" -Force  ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], DirectoryNotFoundException
    + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand

PS D:\openssh-portable> Import-Module .\contrib\win32\openssh\OpenSSHUtils.psm1
PS D:\openssh-portable> Set-OpenSSHTestEnvironment -Confirm:$false -OpenSSHBinPath .\bin\x64\Debug\
VERBOSE: Installing Module OpenSSHUtils...
Copy-item : Could not find a part of the path 'C:\Program Files\WindowsPowerShell\Modules\OpenSSHUtils\1.0.0.1'.
At D:\openssh-portable\contrib\win32\openssh\OpenSSHTestHelper.psm1:465 char:5
+     Copy-item "$manifestFile" -Destination "$targetDirectory" -Force  ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], DirectoryNotFoundException
    + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand

PS D:\openssh-portable> echo $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.2506
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.2506
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

@tgauth
Copy link
Collaborator

tgauth commented Mar 8, 2024

Can you try manually copying both OpenSSHUtils.psm1 and OpenSSHUtils.psd1 to C:\Program Files\WindowsPowerShell\Modules\OpenSSHUtils\1.0.0.1 and rerunning in Windows PowerShell?

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.

2 participants