@@ -10,7 +10,7 @@ Add-Type -TypeDefinition @"
10
10
"@
11
11
12
12
function Set-FilePermission
13
- {
13
+ {
14
14
param (
15
15
[parameter (Mandatory = $true )]
16
16
[string ]$FilePath ,
@@ -20,7 +20,7 @@ function Set-FilePermission
20
20
[System.Security.AccessControl.AccessControlType ] $AccessType = " Allow" ,
21
21
[ValidateSet (" Add" , " Delete" )]
22
22
[string ]$Action = " Add"
23
- )
23
+ )
24
24
25
25
$myACL = Get-ACL $FilePath
26
26
$account = Get-UserAccount - UserSid $UserSid
@@ -30,9 +30,9 @@ function Set-FilePermission
30
30
Enable-Privilege SeRestorePrivilege | out-null
31
31
Set-Acl - Path $FilePath - AclObject $myACL
32
32
$myACL = Get-ACL $FilePath
33
-
34
- if ($myACL.Access )
35
- {
33
+
34
+ if ($myACL.Access )
35
+ {
36
36
$myACL.Access | % {
37
37
if ($_.IdentityReference.Equals ($account ))
38
38
{
@@ -43,18 +43,18 @@ function Set-FilePermission
43
43
Set-Acl - Path $FilePath - AclObject $myACL
44
44
$myACL = Get-ACL $FilePath
45
45
}
46
-
46
+
47
47
if (-not ($myACL.RemoveAccessRule ($_ )))
48
48
{
49
49
throw " failed to remove access of $ ( $_.IdentityReference ) rule in setup "
50
50
}
51
51
}
52
52
}
53
- }
53
+ }
54
54
}
55
55
elseif ($Perms )
56
56
{
57
- $Perms | % {
57
+ $Perms | % {
58
58
$userACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
59
59
($UserSid , $_ , " None" , " None" , $AccessType )
60
60
$myACL.AddAccessRule ($userACE )
@@ -64,7 +64,7 @@ function Set-FilePermission
64
64
Set-Acl - Path $FilePath - AclObject $myACL - confirm:$false
65
65
}
66
66
67
- function Add-PasswordSetting
67
+ function Add-PasswordSetting
68
68
{
69
69
param ([string ] $pass )
70
70
if ($IsWindows ) {
@@ -86,17 +86,17 @@ function Remove-PasswordSetting
86
86
87
87
$Taskfolder = " \OpenSSHTestTasks\"
88
88
$Taskname = " StartTestDaemon"
89
-
89
+
90
90
function Start-SSHDTestDaemon
91
91
{
92
92
param (
93
93
[string ] $Arguments ,
94
94
[string ] $Workdir ,
95
- [string ] $Port )
95
+ [string ] $Port )
96
96
97
97
$Arguments += " -p $Port "
98
98
$ac = New-ScheduledTaskAction - Execute (join-path $workdir " sshd" ) - WorkingDirectory $workdir - Argument $Arguments
99
- $task = Register-ScheduledTask - TaskName $Taskname - User system - Action $ac - TaskPath $Taskfolder - Force
99
+ $task = Register-ScheduledTask - TaskName $Taskname - User system - Action $ac - TaskPath $Taskfolder - Force
100
100
Start-ScheduledTask - TaskPath $Taskfolder - TaskName $Taskname
101
101
# sleep for 1 seconds for process to ready to listener
102
102
$num = 0
@@ -111,25 +111,25 @@ function Start-SSHDTestDaemon
111
111
function Stop-SSHDTestDaemon
112
112
{
113
113
param (
114
- [string ] $Port )
114
+ [string ] $Port )
115
115
116
116
$task = Get-ScheduledTask - TaskPath $Taskfolder - TaskName $Taskname - ErrorAction SilentlyContinue
117
117
if ($task )
118
118
{
119
119
if ($task.State -eq " Running" )
120
120
{
121
121
Stop-ScheduledTask - TaskPath $Taskfolder - TaskName $Taskname
122
- }
122
+ }
123
123
Unregister-ScheduledTask - TaskPath $Taskfolder - TaskName $Taskname - Confirm:$false
124
124
}
125
125
126
126
# kill process listening on $Port
127
127
$p = netstat - anop TCP | select-string - Pattern " 0.0.0.0:$Port "
128
- if (-not ($p -eq $null ))
128
+ if (-not ($p -eq $null ))
129
129
{
130
130
foreach ($ps in $p ) {
131
- $pss = $ps.ToString () -split " \s+" ;
132
- $processid = $pss [$pss.length -1 ]
131
+ $pss = $ps.ToString () -split " \s+" ;
132
+ $processid = $pss [$pss.length -1 ]
133
133
Stop-Process - Id $processid - Force - ErrorAction SilentlyContinue
134
134
}
135
135
# if still running, wait a little while for task to complete
@@ -142,4 +142,22 @@ function Stop-SSHDTestDaemon
142
142
}
143
143
}
144
144
145
- }
145
+ }
146
+
147
+ function ConfigureDefaultShell {
148
+ param
149
+ (
150
+ [string ] $default_shell_path ,
151
+ [string ] $dfltShellRegPath = " HKLM:\Software\OpenSSH" ,
152
+ [string ] $dfltShellRegKeyName = " DefaultShell" ,
153
+ [string ] $dfltShellCmdOptionRegKeyName = " DefaultShellCommandOption" ,
154
+ [string ] $default_shell_cmd_option_val = $null
155
+ )
156
+ if (! (Test-Path $dfltShellRegPath )) {
157
+ New-Item - Path $dfltShellRegPath - Force | Out-Null
158
+ }
159
+ New-ItemProperty - Path $dfltShellRegPath - Name $dfltShellRegKeyName - Value $default_shell_path - PropertyType String - Force
160
+ if ($default_shell_cmd_option_val -ne $null ) {
161
+ New-ItemProperty - Path $dfltShellRegPath - Name $dfltShellCmdOptionRegKeyName - Value $default_shell_cmd_option_val - PropertyType String - Force
162
+ }
163
+ }
0 commit comments