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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ dotnet-uninstall-debian-packages.sh
# Visual Studio IDE directory
.vs/

# VSCode directories that are not at the repository root
/**/.vscode/

# Project Rider IDE files
.idea.powershell/

Expand Down
4 changes: 0 additions & 4 deletions assets/files.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,9 +1641,6 @@
<Component Id="cmp2DF9FE0BD560EB7DC8489A259330C2C6" Guid="{1C027D01-228F-4878-8E05-A6EC7602253B}">
<File Id="fil70CD54BF55F5335B82B2BED64BDB246D" KeyPath="yes" Source="$(env.ProductSourcePath)\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1" />
</Component>
<Component Id="cmpA4E56A46B68CE37D7731DB1F96458D10" Guid="{B7F5384B-6F82-4839-ADA2-5C1C2A5FBEAE}">
<File Id="fil2471B9979A48B7FA2E1E46E597EB337A" KeyPath="yes" Source="$(env.ProductSourcePath)\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psm1" />
</Component>
</Directory>
<Directory Id="dirAB5880051B03D55D6C333CF1F67C7F76" Name="PSDesiredStateConfiguration">
<Component Id="cmp9723892C7119DFDFD3A6FAE8027B053F" Guid="{C3A2E60E-7F0F-44D0-B54E-2E4B73CE7602}">
Expand Down Expand Up @@ -2733,7 +2730,6 @@
<ComponentRef Id="cmpB924CBBD7AE45EF70866F140D8E133E9" />
<ComponentRef Id="cmpDC2EF4541FA5A2E63F36A8CD6C5FA51B" />
<ComponentRef Id="cmp2DF9FE0BD560EB7DC8489A259330C2C6" />
<ComponentRef Id="cmpA4E56A46B68CE37D7731DB1F96458D10" />
<ComponentRef Id="cmp9723892C7119DFDFD3A6FAE8027B053F" />
<ComponentRef Id="cmp6DAFD01CAA3A4C67185922F445EDE495" />
<ComponentRef Id="cmp4AF592F1EDC8794BF4A3CCC2DCB717DB" />
Expand Down
1 change: 1 addition & 0 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,7 @@ function Start-CrossGen {
"System.IO.Pipes.dll"
"System.Diagnostics.FileVersionInfo.dll"
"System.Collections.Specialized.dll"
"Microsoft.ApplicationInsights.dll"
)

# Common PowerShell libraries to crossgen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
<PackageReference Include="System.Threading.AccessControl" Version="4.5.0" />
<PackageReference Include="NJsonSchema" Version="9.12.6" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#if !UNIX

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using System.ComponentModel;

namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// Converts a SDDL string into an object-based representation of a security descriptor.
/// </summary>
[Cmdlet(VerbsData.ConvertFrom, "SddlString", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=623636", RemotingCapability = RemotingCapability.None)]
[OutputType(typeof(SecurityDescriptorInfo))]
public sealed class ConvertFromSddlStringCommand : PSCmdlet
{
/// <summary>
/// Gets and sets the string representing the security descriptor in SDDL syntax.
/// </summary>
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public string Sddl { get; set; }

/// <summary>
/// Gets and sets type of rights that this SDDL string represents.
/// </summary>
[Parameter]
public AccessRightTypeNames Type
{
get { return _type; }
set
{
_isTypeSet = true;
_type = value;
}
}
private AccessRightTypeNames _type;
private bool _isTypeSet = false;

private string ConvertToNTAccount(SecurityIdentifier securityIdentifier)
{
try
{
return securityIdentifier?.Translate(typeof(NTAccount)).Value;
}
catch
{
return null;
}
}

private List<string> GetApplicableAccessRights(int accessMask, AccessRightTypeNames? typeName)
{
List<Type> typesToExamine = new List<Type>();
List<string> foundAccessRightNames = new List<string>();
HashSet<int> foundAccessRightValues = new HashSet<int>();

if (typeName != null)
{
typesToExamine.Add(GetRealAccessRightType(typeName.Value));
}
else
{
foreach (AccessRightTypeNames member in Enum.GetValues(typeof(AccessRightTypeNames)))
{
typesToExamine.Add(GetRealAccessRightType(member));
}
}

foreach (Type accessRightType in typesToExamine)
{
foreach (string memberName in Enum.GetNames(accessRightType))
{
int memberValue = (int)Enum.Parse(accessRightType, memberName);
if (!foundAccessRightValues.Contains(memberValue))
{
foundAccessRightValues.Add(memberValue);
if ((accessMask & memberValue) == memberValue)
{
foundAccessRightNames.Add(memberName);
}
}
}
}

foundAccessRightNames.Sort(StringComparer.OrdinalIgnoreCase);
return foundAccessRightNames;
}

private Type GetRealAccessRightType(AccessRightTypeNames typeName)
{
switch (typeName)
{
case AccessRightTypeNames.FileSystemRights:
return typeof(FileSystemRights);
case AccessRightTypeNames.RegistryRights:
return typeof(RegistryRights);
case AccessRightTypeNames.ActiveDirectoryRights:
return typeof(System.DirectoryServices.ActiveDirectoryRights);
case AccessRightTypeNames.MutexRights:
return typeof(MutexRights);
case AccessRightTypeNames.SemaphoreRights:
return typeof(SemaphoreRights);
case AccessRightTypeNames.EventWaitHandleRights:
return typeof(EventWaitHandleRights);
default:
throw new InvalidOperationException();
}
}

private string[] ConvertAccessControlListToStrings(CommonAcl acl, AccessRightTypeNames? typeName)
{
if (acl == null || acl.Count == 0)
{
return Array.Empty<string>();
}

List<string> aceStringList = new List<string>(acl.Count);
foreach (CommonAce ace in acl)
{
StringBuilder aceString = new StringBuilder();
string ntAccount = ConvertToNTAccount(ace.SecurityIdentifier);
aceString.Append($"{ntAccount}: {ace.AceQualifier}");

if (ace.AceFlags != AceFlags.None)
{
aceString.Append($" {ace.AceFlags}");
}

List<string> accessRightList = GetApplicableAccessRights(ace.AccessMask, typeName);
if (accessRightList.Count > 0)
{
string accessRights = String.Join(", ", accessRightList);
aceString.Append($" ({accessRights})");
}
aceStringList.Add(aceString.ToString());
}

return aceStringList.ToArray();
}

/// <summary>
/// ProcessRecord method.
/// </summary>
protected override void ProcessRecord()
{
CommonSecurityDescriptor rawSecurityDescriptor = null;
try
{
rawSecurityDescriptor = new CommonSecurityDescriptor(isContainer: false, isDS: false, Sddl);
}
catch (Exception e)
{
var ioe = PSTraceSource.NewInvalidOperationException(e, UtilityCommonStrings.InvalidSDDL, e.Message);
ThrowTerminatingError(new ErrorRecord(ioe, "InvalidSDDL", ErrorCategory.InvalidArgument, Sddl));
}

string owner = ConvertToNTAccount(rawSecurityDescriptor.Owner);
string group = ConvertToNTAccount(rawSecurityDescriptor.Group);

AccessRightTypeNames? typeToUse = _isTypeSet ? _type : (AccessRightTypeNames?) null;
string[] discretionaryAcl = ConvertAccessControlListToStrings(rawSecurityDescriptor.DiscretionaryAcl, typeToUse);
string[] systemAcl = ConvertAccessControlListToStrings(rawSecurityDescriptor.SystemAcl, typeToUse);

var outObj = new SecurityDescriptorInfo(owner, group, discretionaryAcl, systemAcl, rawSecurityDescriptor);
WriteObject(outObj);
}

/// <summary>
/// AccessRight type names.
/// </summary>
public enum AccessRightTypeNames
{
/// <summary>
/// FileSystemRights.
/// </summary>
FileSystemRights,

/// <summary>
/// RegistryRights.
/// </summary>
RegistryRights,

/// <summary>
/// ActiveDirectoryRights.
/// </summary>
ActiveDirectoryRights,

/// <summary>
/// MutexRights.
/// </summary>
MutexRights,

/// <summary>
/// SemaphoreRights.
/// </summary>
SemaphoreRights,

// We have 'CryptoKeyRights' in the list for Windows PowerShell, but that type is not available in .NET Core.
// CryptoKeyRights,

/// <summary>
/// EventWaitHandleRights.
/// </summary>
EventWaitHandleRights
}
}

/// <summary>
/// Representation of a security descriptor.
/// </summary>
public sealed class SecurityDescriptorInfo
{
internal SecurityDescriptorInfo(
string owner,
string group,
string[] discretionaryAcl,
string[] systemAcl,
CommonSecurityDescriptor rawDescriptor)
{
Owner = owner;
Group = group;
DiscretionaryAcl = discretionaryAcl;
SystemAcl = systemAcl;
RawDescriptor = rawDescriptor;
}

/// <summary>
/// EventWaitHandle rights.
/// </summary>
public readonly string Owner;

/// <summary>
/// EventWaitHandle rights.
/// </summary>
public readonly string Group;

/// <summary>
/// EventWaitHandle rights.
/// </summary>
public readonly string[] DiscretionaryAcl;

/// <summary>
/// EventWaitHandle rights.
/// </summary>
public readonly string[] SystemAcl;

/// <summary>
/// EventWaitHandle rights.
/// </summary>
public readonly CommonSecurityDescriptor RawDescriptor;
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class GetFileHashCommand : HashCmdletBase
{
/// <summary>
/// Path parameter.
/// The paths of the files to calculate a hashs.
/// The paths of the files to calculate hash values.
/// Resolved wildcards.
/// </summary>
/// <value></value>
Expand Down Expand Up @@ -266,7 +266,7 @@ protected void InitHasher(String Algorithm)
catch
{
// Seems it will never throw! Remove?
Exception exc = new NotSupportedException(UtilityResources.AlgorithmTypeNotSupported);
Exception exc = new NotSupportedException(UtilityCommonStrings.AlgorithmTypeNotSupported);
ThrowTerminatingError(new ErrorRecord(exc, "AlgorithmTypeNotSupported", ErrorCategory.NotImplemented, null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void WritePathNotFoundError(string path)
{
var errorId = "PathNotFound";
var errorCategory = ErrorCategory.InvalidArgument;
var errorMessage = string.Format(UtilityResources.PathDoesNotExist, path);
var errorMessage = string.Format(UtilityCommonStrings.PathDoesNotExist, path);
var exception = new ArgumentException(errorMessage);
var errorRecord = new ErrorRecord(exception, errorId, errorCategory, path);
WriteError(errorRecord);
Expand All @@ -88,7 +88,7 @@ private void WritePathNotFoundError(string path)
private void WriteInvalidDataFileError(string resolvedPath, string errorId)
{
var errorCategory = ErrorCategory.InvalidData;
var errorMessage = string.Format(UtilityResources.CouldNotParseAsPowerShellDataFile, resolvedPath);
var errorMessage = string.Format(UtilityCommonStrings.CouldNotParseAsPowerShellDataFile, resolvedPath);
var exception = new InvalidOperationException(errorMessage);
var errorRecord = new ErrorRecord(exception, errorId, errorCategory, resolvedPath);
WriteError(errorRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum TextEncodingType
/// <summary>
/// Utility class to contain resources for the Microsoft.PowerShell.Utility module.
/// </summary>
[Obsolete("This class is obsolete", true)]
public static class UtilityResources
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
<data name="CouldNotParseAsPowerShellDataFile" xml:space="preserve">
<value>The file '{0}' could not be parsed as a PowerShell Data File.</value>
</data>
<data name="TypeNotSupported" xml:space="preserve">
<value>'{0}' is not supported in this system.</value>
<data name="InvalidSDDL" xml:space="preserve">
<value>Cannot construct a security descriptor from the given SDDL due to the following error: {0}</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<PackageReference Include="System.IO.Packaging" Version="4.5.0" />
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="4.5.1" />
<PackageReference Include="System.Text.Encodings.Web" Version="4.5.0" />
<PackageReference Include="System.Threading.AccessControl" Version="4.5.0" />
<!-- the following package(s) are from https://github.com/dotnet/wcf -->
<PackageReference Include="System.ServiceModel.Duplex" Version="4.5.3" />
<PackageReference Include="System.ServiceModel.Http" Version="4.5.3" />
Expand Down
Loading