-
Notifications
You must be signed in to change notification settings - Fork 768
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
PowerShell Permissions Helpers Are Not Compatible with PSH 2.0 #758
Comments
@DarwinJS Do you see any problem that user download WMF 5.1 on win7 machine? Here is WMF chocolatey package |
@bingbing8 - yes there are a lot of challenges with requiring PSH 5.1 (or any PSH upgrade) for something as small as this. The below (plus more if I had time to think and write) are why I always maintain PowerShell 2.0 compatibility with any of my code that has to run on Win7/Server 2008 R2 RTM. Compatibility:
Logistics:
Putting My Money Where My Mouth Is:
|
@DarwinJS I will update the script work with ps 2.0 |
@DarwinJS the fix is checked in PowerShell/openssh-portable#160 and it works on ps2 on win7. Please let me know if you see any other issue |
@bingbing8 - thank you for this! I have tested and I get some errors and the file permission does not change - please see the screenshot. "ProtectedAdmin" is a custom user who is a regular admin - running elevated when the code runs. |
@DarwinJS what os is this repro? this is due to a bug in default .net (localsystem is not allowed to be file owner, but icacls can set it) on the machine. I saw this on my win7 and workaround it like: |
@DarwinJS based on the screen you provided. the code should set owner to admin groups instead of system. Can you check the OpenSSHUtil.psm1 has the below lines? |
@bingbing8 - yes I have those lines. |
Ok - I got this one figured out. I remembered that chocolatey installs .NET 4.0 and then on PSH 2.0 systems it still uses PSH 2.0, but it changes the CLR to 4.0 when running PowerShell (only under chocolatey - not for the entire system). I forget why but I think it had to do with some serious CLR 2.0 limitations. The below screen show shows output of $psversiontable running under chocolatey. Also I updated the If statements to ($psversiontable.psversion.major -gt 2) which works for chocolatey and should also work for non-chocolatey psh 2. The screen shots also show successful permissions setting and owner setting. The package also cleanly uninstalls. You can test with this exact chocolatey package (with the $psversiontable debug output still being emitted) from a test chocolatey feed detailed in #763 |
@DarwinJS got it. I will include the changes in my next PR |
@bingbing8 - I had not yet tested with authorized_keys files in profiles other than the one running the opensshutils.psm1 code. It looks like we have the same problem with setting permissions on the authorized_keys files of other user profiles on Win7 because this line: https://github.com/PowerShell/openssh-portable/blob/latestw_all/contrib/win32/openssh/OpenSSHUtils.psm1#L104 Does not have an alternative for PSH 2.0 like the other corrections you made earlier. You can see in the screenshot the other fixed lines are working correctly. |
@DarwinJS I don't repro this on my win7 machine. but I found a workaround. I think the commit I added fix the issue.
|
Thanks for the updates. Have you tried deleting and recreating your test authorized_users files in other profiles on Win7 - or were they present during a previous run? I am guessing here - but in the case that an authorized_users file ALREADY has the correct owner (I created my test ones WHILE logged in as the specific user), then doesn't this line: https://github.com/PowerShell/openssh-portable/blob/latestw_all/contrib/win32/openssh/OpenSSHUtils.psm1#L190 read the ENTIRE acl (including the owner), the code in these lines is SKIPPED: https://github.com/PowerShell/openssh-portable/blob/latestw_all/contrib/win32/openssh/OpenSSHUtils.psm1#L196-L224 which might affect the subsequent lines that try to set only DACLs because the entire ACL was read and we are in that weird set-acl lockout condition where we are denied writing the existing owner as a new owner (when we don't care about writing the owner) because we read the entire ACL, but only changed DACLs? When you tested on Win7, did you create the authorized_keys files as the actual users whose profiles they are in? If not, could you give it a run that way? |
@bingbing8 - I guess I didn't have the right branch. Just tested with the recently updated latestw_all and it works fine on Win 7 now! |
I originally commented in #721 under the heading "Installation Code Testing" that all PowerShell code should be tested on the target platforms of openssh, which I believe still includes Windows 7 / Server 2008 R2 RTM.
FYI - the code does appear to work for Nano.
FixHostFilePermissions, FixUserFilePermissions.ps1 and OpenSSHUtils.psm1 all have syntax or assumptions that are not compatible with PowerShell 2.0.
I fixed some, but I realized I don't have time to test if the scripts still actually perform their intended duties. I also noticed that some permissions do not seem to be updating after the below changes.
Here are the ones I know about:
FixHostFilePermissions, FixUserFilePermissions.ps1 = $psscriptroot was introduced in version 3.
Fixup - right under params block:
If (!(Test-Path variable:PSScriptRoot)) {$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition}
OpenSSHUtils.psm1: '-in' operator is not in PSH 2
Untested Fixup: change
$abc -in $xyzarray
to$xyzarray -icontains $abc
(unsure if this is a full emulation of -in)OpenSSHUtils.psm1: '.contains' method is not in PSH 2 (string objects?)
Untested Fixup: change
$abc.contains($somedata)
to$abc -contains $somedata
(unsure if this is working)FYI - I personally avoid testing with "powershell.exe -version 2" for compatibility with Win 7 / Server 2008 R2. There are just too many other differences.
If these scripts can be made compatible with PSH 2.0 and a pull request made - I will grab the code from the pull request and include it in the chocolatey package for 0.0.15.0 as an override of the files in the zip archives.
The text was updated successfully, but these errors were encountered: