Skip to content

Commit af3c70d

Browse files
committed
Get or set context by ID.
1 parent a6fc7fd commit af3c70d

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

NtObjectManager/RpcFunctions.ps1

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,20 +1410,28 @@ This cmdlet sets the current RPC security context for a client.
14101410
Specify the RPC client to set the context to.
14111411
.PARAMETER SecurityContext
14121412
Specify the security context to set.
1413+
.PARAMETER ContextId
1414+
Specify the ID of the security context to set.
14131415
.INPUTS
14141416
None
14151417
.OUTPUTS
14161418
None
14171419
#>
14181420
function Set-RpcClientSecurityContext {
1419-
[CmdletBinding()]
1421+
[CmdletBinding(DefaultParameterSetName="FromContext")]
14201422
Param(
14211423
[parameter(Mandatory, Position = 0)]
14221424
[NtApiDotNet.Win32.Rpc.RpcClientBase]$Client,
1423-
[parameter(Mandatory, Position = 1)]
1424-
[NtApiDotNet.Win32.Rpc.Transport.RpcTransportSecurityContext]$SecurityContext
1425+
[parameter(Mandatory, Position = 1, ParameterSetName="FromContext")]
1426+
[NtApiDotNet.Win32.Rpc.Transport.RpcTransportSecurityContext]$SecurityContext,
1427+
[parameter(Mandatory, Position = 1, ParameterSetName="FromId")]
1428+
[int]$ContextId
14251429
)
14261430

1431+
if ($PSCmdlet.ParameterSetName -eq "FromId") {
1432+
$SecurityContext = Get-RpcClientSecurityContext -Client $Client -ContextId $ContextId
1433+
}
1434+
14271435
$Client.Transport.CurrentSecurityContext = $SecurityContext
14281436
}
14291437

@@ -1436,22 +1444,33 @@ This cmdlet gets the current RPC security context for a client.
14361444
Specify the RPC client to set the context to.
14371445
.PARAMETER Current
14381446
Specify to return the current context only.
1447+
.PARAMETER ContextId
1448+
Specify to return the context with the specified ID.
14391449
.INPUTS
14401450
None
14411451
.OUTPUTS
14421452
NtApiDotNet.Win32.Rpc.Transport.RpcTransportSecurityContext[]
14431453
#>
14441454
function Get-RpcClientSecurityContext {
1445-
[CmdletBinding()]
1455+
[CmdletBinding(DefaultParameterSetName="All")]
14461456
Param(
14471457
[parameter(Mandatory, Position = 0)]
14481458
[NtApiDotNet.Win32.Rpc.RpcClientBase]$Client,
1449-
[switch]$Current
1459+
[parameter(Mandatory, ParameterSetName="FromCurrent")]
1460+
[switch]$Current,
1461+
[parameter(Mandatory, Position = 1, ParameterSetName="FromId")]
1462+
[int]$ContextId
14501463
)
14511464

1452-
if ($Current) {
1453-
$Client.Transport.CurrentSecurityContext
1454-
} else {
1455-
$Client.Transport.SecurityContext | Write-Output
1465+
switch($PSCmdlet.ParameterSetName) {
1466+
"All" {
1467+
$Client.Transport.SecurityContext | Write-Output
1468+
}
1469+
"FromCurrent" {
1470+
$Client.Transport.CurrentSecurityContext
1471+
}
1472+
"FromId" {
1473+
$Client.Transport.SecurityContext | Where-Object ContextId -eq $ContextId
1474+
}
14561475
}
14571476
}

0 commit comments

Comments
 (0)