Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,14 @@
<EmbeddedResource Remove="resources\ErrorPackageRemoting.resx" />
</ItemGroup>

<ItemGroup Condition=" '$(IsWindows)' != 'true' ">
<Compile Remove="engine\remoting\commands\ReceivePSSession.cs" />
<Compile Remove="engine\remoting\commands\DisconnectPSSession.cs" />
<Compile Remove="engine\remoting\commands\ConnectPSSession.cs" />
<Compile Remove="engine\remoting\commands\EnterPSHostProcessCommand.cs" />
<Compile Remove="engine\remoting\commands\NewPSSessionOptionCommand.cs" />
<Compile Remove="engine\remoting\commands\CustomShellCommands.cs" />
<Compile Remove="engine\remoting\commands\TestPSSessionConfigurationFile.cs" />
</ItemGroup>

</Project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1498,46 +1498,6 @@ internal static Version ConstructVersionFormatForConfigXml(Version psVersion)
return result;
}

/// <summary>
/// Checks if the specified version of PowerShell is installed
/// </summary>
/// <param name="version"></param>
internal static void CheckIfPowerShellVersionIsInstalled(Version version)
{
// Check if PowerShell 2.0 is installed
if (version != null && version.Major == 2)
{
#if CORECLR
// PowerShell 2.0 is not available for CoreCLR
throw new ArgumentException(
PSRemotingErrorInvariants.FormatResourceString(
RemotingErrorIdStrings.PowerShellNotInstalled,
version, "PSVersion"));
#else
// Because of app-compat issues, in Win8, we will have PS 2.0 installed by default but not .NET 2.0
// In such a case, it is not enough if we check just PowerShell registry keys. We also need to check if .NET 2.0 is installed.
try
{
RegistryKey engineKey = PSSnapInReader.GetPSEngineKey(PSVersionInfo.RegistryVersion1Key);
// Also check for .NET 2.0 installation
if (!PsUtils.FrameworkRegistryInstallation.IsFrameworkInstalled(2, 0, 0))
{
throw new ArgumentException(
PSRemotingErrorInvariants.FormatResourceString(
RemotingErrorIdStrings.NetFrameWorkV2NotInstalled));
}
}
catch (PSArgumentException)
{
throw new ArgumentException(
PSRemotingErrorInvariants.FormatResourceString(
RemotingErrorIdStrings.PowerShellNotInstalled,
version, "PSVersion"));
}
#endif
}
}

/// <summary>
/// Takes array of group name string objects and returns a semicolon delimited string.
/// </summary>
Expand Down Expand Up @@ -2018,24 +1978,6 @@ internal static string GetRemoteSddl()
return (Environment.OSVersion.Version >= new Version(6, 2)) ? remoteSDDL_Win8 : remoteSDDL;
}

internal static void CheckPSVersion(Version version)
{
// PSVersion value can only be 2.0, 3.0, 4.0, 5.0, or 5.1
if (version != null)
{
// PSVersion value can only be 2.0, 3.0, 4.0, 5.0, or 5.1
if (!((version.Major >= 2) && (version.Major <= 4) && (version.Minor == 0)) &&
!((version.Major == 5) && (version.Minor <= 1))
)
{
throw new ArgumentException(
PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.PSVersionParameterOutOfRange,
version, "PSVersion")
);
}
}
}

#endregion

#region Parameters
Expand Down Expand Up @@ -2356,10 +2298,10 @@ public Version PSVersion
get { return psVersion; }
set
{
CheckPSVersion(value);
RemotingCommandUtils.CheckPSVersion(value);

// Check if specified version of PowerShell is installed
PSSessionConfigurationCommandUtilities.CheckIfPowerShellVersionIsInstalled(value);
RemotingCommandUtils.CheckIfPowerShellVersionIsInstalled(value);

psVersion = value;
isPSVersionSpecified = true;
Expand Down Expand Up @@ -5244,7 +5186,7 @@ protected override void EndProcessing()
SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=144298")]
public sealed class DisablePSRemotingCommand : PSCmdlet
{
# region Private Data
#region Private Data

// To Escape { -- {{
// To Escape } -- }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Microsoft.PowerShell.Commands
{
#if !UNIX
/// <summary>
/// New-PSSessionConfigurationFile command implementation
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe split the file by classes and exclude a new file from compile on Unix?

If we look CodeFactor issues it recommends to use one-class-per-file - if we move code in the PR maybe follow this rule?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm personally in favour of this approach too. I know we've already taken the other path in most places, but there are some good factors:

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once-class-per-file is ridiculous. We have modern editors with all kinds of features for managing large files. I'm much happier navigating within a few files than having to deal with hundreds of tabs. I vote we suppress this rule.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree with @BrucePay in the general case of having multiple classes per file. Sometimes it's overkill to make a class nested, but it makes a lot more sense contextually to have it in the same file as a larger class. Enums are a good motivating example I find. Also, it's nice to feel like I've moved on from this historical holdover of Java and MATLAB...

Copy link
Collaborator

@iSazonov iSazonov Jun 2, 2018

Choose a reason for hiding this comment

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

My question was only about the file. The rule was already disabled in PR #6930.

Copy link
Member Author

Choose a reason for hiding this comment

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

@iSazonov The reason I was using #if !UNIX in this file is because the class SessionConfigurationUtils in this file is heavily used and only used in those two cmdlets (New-PSSessionConfigurationFile and New-PSRoleCapabilityFile), so it makes sense to keep them close to each other in the same file.

///
Expand Down Expand Up @@ -1064,6 +1065,7 @@ private bool ShouldGenerateConfigurationSnippet(string parameterName)

#endregion
}
#endif

/// <summary>
/// New-PSRoleCapabilityFile command implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,253 +8,6 @@
using System.Management.Automation.Remoting;
using System.Management.Automation.Runspaces;

namespace System.Management.Automation.Remoting
{
/// <summary>
/// IMPORTANT: proxy configuration is supported for HTTPS only; for HTTP, the direct
/// connection to the server is used
/// </summary>
[SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags")]
public enum ProxyAccessType
{
/// <summary>
/// ProxyAccessType is not specified. That means Proxy information (ProxyAccessType, ProxyAuthenticationMechanism
/// and ProxyCredential)is not passed to WSMan at all.
/// </summary>
None = 0,
/// <summary>
/// use the Internet Explorer proxy configuration for the current user.
/// Internet Explorer proxy settings for the current active network connection.
/// This option requires the user profile to be loaded, so the option can
/// be directly used when called within a process that is running under
/// an interactive user account identity; if the client application is running
/// under a user context different than the interactive user, the client
/// application has to explicitly load the user profile prior to using this option.
/// </summary>
IEConfig = 1,
/// <summary>
/// proxy settings configured for WinHTTP, using the ProxyCfg.exe utility
/// </summary>
WinHttpConfig = 2,
/// <summary>
/// Force autodetection of proxy
/// </summary>
AutoDetect = 4,
/// <summary>
/// do not use a proxy server - resolves all host names locally
/// </summary>
NoProxyServer = 8
}
/// <summary>
/// Options for a remote PSSession
/// </summary>
public sealed class PSSessionOption
{
/// <summary>
/// Creates a new instance of <see cref="PSSessionOption"/>
/// </summary>
public PSSessionOption()
{
}

/// <summary>
/// The MaximumConnectionRedirectionCount parameter enables the implicit redirection functionality.
/// -1 = no limit
/// 0 = no redirection
/// </summary>
public int MaximumConnectionRedirectionCount { get; set; } = WSManConnectionInfo.defaultMaximumConnectionRedirectionCount;

/// <summary>
/// If false, underlying WSMan infrastructure will compress data sent on the network.
/// If true, data will not be compressed. Compression improves performance by
/// reducing the amount of data sent on the network. Compression my require extra
/// memory consumption and CPU usage. In cases where available memory / CPU is less,
/// set this property to "true".
/// By default the value of this property is "false".
/// </summary>
public bool NoCompression { get; set; } = false;

/// <summary>
/// If <c>true</c> then Operating System won't load the user profile (i.e. registry keys under HKCU) on the remote server
/// which can result in a faster session creation time. This option won't have any effect if the remote machine has
/// already loaded the profile (i.e. in another session).
/// </summary>
public bool NoMachineProfile { get; set; } = false;

/// <summary>
/// By default, ProxyAccessType is None, that means Proxy information (ProxyAccessType,
/// ProxyAuthenticationMechanism and ProxyCredential)is not passed to WSMan at all.
/// </summary>
public ProxyAccessType ProxyAccessType { get; set; } = ProxyAccessType.None;

/// <summary>
/// The following is the definition of the input parameter "ProxyAuthentication".
/// This parameter takes a set of authentication methods the user can select
/// from. The available options should be as follows:
/// - Negotiate: Use the default authentication (as defined by the underlying
/// protocol) for establishing a remote connection.
/// - Basic: Use basic authentication for establishing a remote connection
/// - Digest: Use Digest authentication for establishing a remote connection
///
/// Default is Negotiate.
/// </summary>
public AuthenticationMechanism ProxyAuthentication
{
get { return _proxyAuthentication; }
set
{
switch (value)
{
case AuthenticationMechanism.Basic:
case AuthenticationMechanism.Negotiate:
case AuthenticationMechanism.Digest:
_proxyAuthentication = value;
break;
default:
string message = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.ProxyAmbiguousAuthentication,
value,
AuthenticationMechanism.Basic.ToString(),
AuthenticationMechanism.Negotiate.ToString(),
AuthenticationMechanism.Digest.ToString());
throw new ArgumentException(message);
}
}
}
private AuthenticationMechanism _proxyAuthentication = AuthenticationMechanism.Negotiate;

/// <summary>
/// The following is the definition of the input parameter "ProxyCredential".
/// </summary>
public PSCredential ProxyCredential { get; set; }

/// <summary>
/// When connecting over HTTPS, the client does not validate that the server
/// certificate is signed by a trusted certificate authority (CA). Use only when
/// the remote computer is trusted by other means, for example, if the remote
/// computer is part of a network that is physically secure and isolated or the
/// remote computer is listed as a trusted host in WinRM configuration
/// </summary>
public bool SkipCACheck { get; set; }

/// <summary>
/// Indicates that certificate common name (CN) of the server need not match the
/// hostname of the server. Used only in remote operations using https. This
/// option should only be used for trusted machines.
/// </summary>
public bool SkipCNCheck { get; set; }

/// <summary>
/// Indicates that certificate common name (CN) of the server need not match the
/// hostname of the server. Used only in remote operations using https. This
/// option should only be used for trusted machines
/// </summary>
public bool SkipRevocationCheck { get; set; }

/// <summary>
/// The duration for which PowerShell remoting waits before timing out
/// for any operation. The user would like to tweak this timeout
/// depending on whether he/she is connecting to a machine in the data
/// center or across a slow WAN.
///
/// Default: 3*60*1000 == 3minutes
/// </summary>
public TimeSpan OperationTimeout { get; set; } = TimeSpan.FromMilliseconds(BaseTransportManager.ClientDefaultOperationTimeoutMs);

/// <summary>
/// Specifies that no encryption will be used when doing remote operations over
/// http. Unencrypted traffic is not allowed by default and must be enabled in
/// the local configuration
/// </summary>
public bool NoEncryption { get; set; }

/// <summary>
/// Indicates the request is encoded in UTF16 format rather than UTF8 format;
/// UTF8 is the default.
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "UTF")]
public bool UseUTF16 { get; set; }

/// <summary>
/// Uses Service Principal Name (SPN) along with the Port number during authentication.
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SPN")]
public bool IncludePortInSPN { get; set; }

/// <summary>
/// Determines how server in disconnected state deals with cached output
/// data when the cache becomes filled.
/// Default value is 'block mode' where command execution is blocked after
/// the server side data cache becomes filled.
/// </summary>
public OutputBufferingMode OutputBufferingMode { get; set; } = WSManConnectionInfo.DefaultOutputBufferingMode;

/// <summary>
/// Number of times a connection will be re-attempted when a connection fails due to network
/// issues.
/// </summary>
public int MaxConnectionRetryCount { get; set; } = WSManConnectionInfo.DefaultMaxConnectionRetryCount;

/// <summary>
/// Culture that the remote session should use
/// </summary>
public CultureInfo Culture { get; set; }

/// <summary>
/// UI culture that the remote session should use
/// </summary>
public CultureInfo UICulture { get; set; }

/// <summary>
/// Total data (in bytes) that can be received from a remote machine
/// targeted towards a command. If null, then the size is unlimited.
/// Default is unlimited data.
/// </summary>
public Nullable<int> MaximumReceivedDataSizePerCommand { get; set; }

/// <summary>
/// Maximum size (in bytes) of a deserialized object received from a remote machine.
/// If null, then the size is unlimited. Default is 200MB object size.
/// </summary>
public Nullable<int> MaximumReceivedObjectSize { get; set; } = 200 << 20;

/// <summary>
/// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/>
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSPrimitiveDictionary ApplicationArguments { get; set; }

/// <summary>
/// The duration for which PowerShell remoting waits before timing out on a connection to a remote machine.
/// Simply put, the timeout for a remote runspace creation.
/// The user would like to tweak this timeout depending on whether
/// he/she is connecting to a machine in the data center or across a slow WAN.
///
/// Default: 3 * 60 * 1000 = 3 minutes
/// </summary>
public TimeSpan OpenTimeout { get; set; } = TimeSpan.FromMilliseconds(RunspaceConnectionInfo.DefaultOpenTimeout);

/// <summary>
/// The duration for which PowerShell should wait before it times out on cancel operations
/// (close runspace or stop powershell). For instance, when the user hits ctrl-C,
/// New-PSSession cmdlet tries to call a stop on all remote runspaces which are in the Opening state.
/// The user wouldn't mind waiting for 15 seconds, but this should be time bound and of a shorter duration.
/// A high timeout here like 3 minutes will give the user a feeling that the PowerShell client is not responding.
///
/// Default: 60 * 1000 = 1 minute
/// </summary>
public TimeSpan CancelTimeout { get; set; } = TimeSpan.FromMilliseconds(RunspaceConnectionInfo.defaultCancelTimeout);

/// <summary>
/// The duration for which a Runspace on server needs to wait before it declares the client dead and closes itself down.
/// This is especially important as these values may have to be configured differently for enterprise administration
/// and exchange scenarios.
///
/// Default: -1 -> Use current server value for IdleTimeout.
/// </summary>
public TimeSpan IdleTimeout { get; set; } = TimeSpan.FromMilliseconds(RunspaceConnectionInfo.DefaultIdleTimeout);
}
}

namespace Microsoft.PowerShell.Commands
{
/// <summary>
Expand Down
Loading