Skip to content

Don't fail if SaferPolicy API is not available on Win10 IoT or NanoServer - #7075

Merged
Aditya Patwardhan (adityapatwardhan) merged 3 commits into
PowerShell:masterfrom
SteveL-MSFT:safer-api
Jun 20, 2018
Merged

Aditya Patwardhan (adityapatwardhan) merged 3 commits into
PowerShell:masterfrom
SteveL-MSFT:safer-api

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Jun 15, 2018 •

Copy link
Copy Markdown
Member

PR Summary

We P/Invoke to the SaferPolicy APIs which are not available on Win10 IoT or NanoServer.
If the Win32 error indicates that the api is not supported, we default to Allowed.

Updated Install-PowerShellRemoting.ps1 to work correctly on Windows PowerShell Core 5 so that you can install PSCore6 remoting on Win10 IoT.

Fix #6750

PR Checklist

fix install-powershellremoting to work on Windows PowerShell 5.1
int lastError = Marshal.GetLastWin32Error();
if (lastError == NativeConstants.FUNCTION_NOT_SUPPORTED)
{
_saferApiSupported = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The var name "_saferApiSupported" is kind of misleading because it is broad in a sense that there are other native API calls (Cert-related) in this file that neither utilize this 'global flag' nor set it in case of similar error handling (Win32Exception(Marshal.GetLastWin32Error())).
So for consistency either this"_saferApiSupported" flag should be added to them; or simply renamed to something more narrow like "_SaferIdentifyLevelApiSupported".

@TravisEz13 Travis Plunk (TravisEz13) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

other than the issue we discussed offline, looks good to me

/// MAX_PATH -> 260
internal const int MAX_PATH = 260;

/// This function is not supported on this system

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:-) CodeFactor says that we use incorrect documentation header.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll fix this file


#endregion execution policy

private static bool _SaferIdentifyLevelApiSupported = true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

From CodeFactor - Variable names and private field names must start with a lower-case letter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will change

@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit abcdce4 into PowerShell:master Jun 20, 2018
@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the safer-api branch June 20, 2018 02:38
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…rver (PowerShell#7075)

* don't fail if SaferApi is not available
* fix install-powershellremoting to work on Windows PowerShell 5.1
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.

pwsh.exe does not start on Windows 10 IOT (arm32)

7 participants