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
28 changes: 12 additions & 16 deletions src/Microsoft.PowerShell.Security/security/AclCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ internal CmdletProviderContext CmdletProviderContext
{
get
{
CmdletProviderContext coreCommandContext =
new CmdletProviderContext(this);
CmdletProviderContext coreCommandContext = new(this);

Collection<string> includeFilter =
SessionStateUtilities.ConvertArrayToCollection<string>(Include);
Expand Down Expand Up @@ -351,7 +350,7 @@ public static AuthorizationRuleCollection GetAudit(PSObject instance)
/// </returns>
public static SecurityIdentifier GetCentralAccessPolicyId(PSObject instance)
{
SessionState sessionState = new SessionState();
SessionState sessionState = new();
string path = sessionState.Path.GetUnresolvedProviderPathFromPSPath(
GetPath(instance));
IntPtr pSd = IntPtr.Zero;
Expand Down Expand Up @@ -801,7 +800,7 @@ protected override void ProcessRecord()
{
foreach (string p in Path)
{
List<string> pathsToProcess = new List<string>();
List<string> pathsToProcess = new();

string currentPath = null;
try
Expand All @@ -824,7 +823,7 @@ protected override void ProcessRecord()
{
currentPath = rp;

CmdletProviderContext context = new CmdletProviderContext(this.Context);
CmdletProviderContext context = new(this.Context);
context.SuppressWildcardExpansion = true;

if (!InvokeProvider.Item.Exists(rp, false, _isLiteralPath))
Expand Down Expand Up @@ -1264,7 +1263,7 @@ private static IntPtr GetTokenWithEnabledPrivilege(
}

// Get the LUID of the specified privilege.
NativeMethods.LUID luid = new NativeMethods.LUID();
NativeMethods.LUID luid = new();
ret = NativeMethods.LookupPrivilegeValue(
null,
privilege,
Expand All @@ -1275,7 +1274,7 @@ private static IntPtr GetTokenWithEnabledPrivilege(
}

// Enable the privilege.
NativeMethods.TOKEN_PRIVILEGE newState = new NativeMethods.TOKEN_PRIVILEGE();
NativeMethods.TOKEN_PRIVILEGE newState = new();
newState.PrivilegeCount = 1;
newState.Privilege.Attributes = NativeMethods.SE_PRIVILEGE_ENABLED;
newState.Privilege.Luid = luid;
Expand Down Expand Up @@ -1419,16 +1418,15 @@ protected override void ProcessRecord()
}

IntPtr pSacl = IntPtr.Zero;
NativeMethods.TOKEN_PRIVILEGE previousState = new NativeMethods.TOKEN_PRIVILEGE();
NativeMethods.TOKEN_PRIVILEGE previousState = new();
try
{
if (CentralAccessPolicy != null)
{
pSacl = GetSaclWithCapId(CentralAccessPolicy);
if (pSacl == IntPtr.Zero)
{
SystemException e = new SystemException(
UtilsStrings.GetSaclWithCapIdFail);
SystemException e = new(UtilsStrings.GetSaclWithCapIdFail);
WriteError(new ErrorRecord(e,
"SetAcl_CentralAccessPolicy",
ErrorCategory.InvalidResult,
Expand All @@ -1441,8 +1439,7 @@ protected override void ProcessRecord()
pSacl = GetEmptySacl();
if (pSacl == IntPtr.Zero)
{
SystemException e = new SystemException(
UtilsStrings.GetEmptySaclFail);
SystemException e = new(UtilsStrings.GetEmptySaclFail);
WriteError(new ErrorRecord(e,
"SetAcl_ClearCentralAccessPolicy",
ErrorCategory.InvalidResult,
Expand All @@ -1453,7 +1450,7 @@ protected override void ProcessRecord()

foreach (string p in Path)
{
Collection<PathInfo> pathsToProcess = new Collection<PathInfo>();
Collection<PathInfo> pathsToProcess = new();

CmdletProviderContext context = this.CmdletProviderContext;
context.PassThru = Passthru;
Expand Down Expand Up @@ -1496,8 +1493,7 @@ protected override void ProcessRecord()
IntPtr pToken = GetTokenWithEnabledPrivilege("SeSecurityPrivilege", previousState);
if (pToken == IntPtr.Zero)
{
SystemException e = new SystemException(
UtilsStrings.GetTokenWithEnabledPrivilegeFail);
SystemException e = new(UtilsStrings.GetTokenWithEnabledPrivilegeFail);
WriteError(new ErrorRecord(e,
"SetAcl_AdjustTokenPrivileges",
ErrorCategory.InvalidResult,
Expand All @@ -1518,7 +1514,7 @@ protected override void ProcessRecord()
// Restore privileges to the previous state.
if (pToken != IntPtr.Zero)
{
NativeMethods.TOKEN_PRIVILEGE newState = new NativeMethods.TOKEN_PRIVILEGE();
NativeMethods.TOKEN_PRIVILEGE newState = new();
uint newSize = 0;
NativeMethods.AdjustTokenPrivileges(
pToken,
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.PowerShell.Security/security/CatalogCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void ProcessRecord()
Dbg.Assert((CatalogFilePath != null) && (CatalogFilePath.Length > 0),
"CatalogCommands: Param binder did not bind catalogFilePath");

Collection<string> paths = new Collection<string>();
Collection<string> paths = new();

if (Path != null)
{
Expand Down Expand Up @@ -182,7 +182,7 @@ protected override void PerformAction(Collection<string> path, string catalogFil
path.Add(SessionState.Path.CurrentFileSystemLocation.Path);
}

FileInfo catalogFileInfo = new FileInfo(catalogFilePath);
FileInfo catalogFileInfo = new(catalogFilePath);

// If Path points to the expected cat file make sure
// parent Directory exists other wise CryptoAPI fails to create a .cat file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public string[] LiteralPath
//
// list of files that were not found
//
private readonly List<string> _filesNotFound = new List<string>();
private readonly List<string> _filesNotFound = new();

/// <summary>
/// Initializes a new instance of the GetPfxCertificateCommand
Expand Down Expand Up @@ -105,7 +105,7 @@ protected override void ProcessRecord()

foreach (string p in FilePath)
{
List<string> paths = new List<string>();
List<string> paths = new();

// Expand wildcard characters
if (_isLiteralPath)
Expand Down Expand Up @@ -160,11 +160,11 @@ protected override void ProcessRecord()
}
catch (CryptographicException e)
{
ErrorRecord er =
new ErrorRecord(e,
"GetPfxCertificateUnknownCryptoError",
ErrorCategory.NotSpecified,
null);
ErrorRecord er = new(
e,
"GetPfxCertificateUnknownCryptoError",
ErrorCategory.NotSpecified,
targetObject: null);
WriteError(er);
continue;
}
Expand Down
Loading