@@ -1132,12 +1132,16 @@ private Breakpoint AddCommandBreakpoint(CommandBreakpoint breakpoint) |
1132 | 1132 | internal Breakpoint NewCommandBreakpoint(string path, string command, ScriptBlock action) |
1133 | 1133 | { |
1134 | 1134 | WildcardPattern pattern = WildcardPattern.Get(command, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); |
| 1135 | + |
| 1136 | + CheckForBreakpointSupport(); |
1135 | 1137 | return AddCommandBreakpoint(new CommandBreakpoint(path, pattern, command, action)); |
1136 | 1138 | } |
1137 | 1139 |
|
1138 | 1140 | internal Breakpoint NewCommandBreakpoint(string command, ScriptBlock action) |
1139 | 1141 | { |
1140 | 1142 | WildcardPattern pattern = WildcardPattern.Get(command, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); |
| 1143 | + |
| 1144 | + CheckForBreakpointSupport(); |
1141 | 1145 | return AddCommandBreakpoint(new CommandBreakpoint(null, pattern, command, action)); |
1142 | 1146 | } |
1143 | 1147 |
|
@@ -1175,13 +1179,15 @@ internal Breakpoint NewLineBreakpoint(string path, int line, ScriptBlock action) |
1175 | 1179 | { |
1176 | 1180 | Diagnostics.Assert(path != null, "caller to verify path is not null"); |
1177 | 1181 |
|
| 1182 | + CheckForBreakpointSupport(); |
1178 | 1183 | return AddLineBreakpoint(new LineBreakpoint(path, line, action)); |
1179 | 1184 | } |
1180 | 1185 |
|
1181 | 1186 | internal Breakpoint NewStatementBreakpoint(string path, int line, int column, ScriptBlock action) |
1182 | 1187 | { |
1183 | 1188 | Diagnostics.Assert(path != null, "caller to verify path is not null"); |
1184 | 1189 |
|
| 1190 | + CheckForBreakpointSupport(); |
1185 | 1191 | return AddLineBreakpoint(new LineBreakpoint(path, line, column, action)); |
1186 | 1192 | } |
1187 | 1193 |
|
@@ -1201,11 +1207,13 @@ internal VariableBreakpoint AddVariableBreakpoint(VariableBreakpoint breakpoint) |
1201 | 1207 |
|
1202 | 1208 | internal Breakpoint NewVariableBreakpoint(string path, string variableName, VariableAccessMode accessMode, ScriptBlock action) |
1203 | 1209 | { |
| 1210 | + CheckForBreakpointSupport(); |
1204 | 1211 | return AddVariableBreakpoint(new VariableBreakpoint(path, variableName, accessMode, action)); |
1205 | 1212 | } |
1206 | 1213 |
|
1207 | 1214 | internal Breakpoint NewVariableBreakpoint(string variableName, VariableAccessMode accessMode, ScriptBlock action) |
1208 | 1215 | { |
| 1216 | + CheckForBreakpointSupport(); |
1209 | 1217 | return AddVariableBreakpoint(new VariableBreakpoint(null, variableName, accessMode, action)); |
1210 | 1218 | } |
1211 | 1219 |
|
@@ -1761,12 +1769,6 @@ private void OnDebuggerStop(InvocationInfo invocationInfo, List<Breakpoint> brea |
1761 | 1769 | originalLanguageMode = _context.LanguageMode; |
1762 | 1770 | _context.LanguageMode = PSLanguageMode.FullLanguage; |
1763 | 1771 | } |
1764 | | - else if (System.Management.Automation.Security.SystemPolicy.GetSystemLockdownPolicy() == |
1765 | | - System.Management.Automation.Security.SystemEnforcementMode.Enforce) |
1766 | | - { |
1767 | | - // If there is a system lockdown in place, enforce it |
1768 | | - originalLanguageMode = Utils.EnforceSystemLockDownLanguageMode(this._context); |
1769 | | - } |
1770 | 1772 |
|
1771 | 1773 | // Update the prompt to the debug prompt |
1772 | 1774 | if (hadDefaultPrompt) |
@@ -2060,6 +2062,17 @@ private void SetInternalDebugMode(InternalDebugMode mode) |
2060 | 2062 | { |
2061 | 2063 | lock (_syncObject) |
2062 | 2064 | { |
| 2065 | + // Disable script debugger when in system lock down mode |
| 2066 | + if (IsSystemLockedDown) |
| 2067 | + { |
| 2068 | + if (_context._debuggingMode != (int)InternalDebugMode.Disabled) |
| 2069 | + { |
| 2070 | + _context._debuggingMode = (int)InternalDebugMode.Disabled; |
| 2071 | + } |
| 2072 | + |
| 2073 | + return; |
| 2074 | + } |
| 2075 | + |
2063 | 2076 | switch (mode) |
2064 | 2077 | { |
2065 | 2078 | case InternalDebugMode.InPushedStop: |
@@ -2086,6 +2099,24 @@ private bool CanEnableDebugger |
2086 | 2099 | } |
2087 | 2100 | } |
2088 | 2101 |
|
| 2102 | + private static bool IsSystemLockedDown |
| 2103 | + { |
| 2104 | + get |
| 2105 | + { |
| 2106 | + return (System.Management.Automation.Security.SystemPolicy.GetSystemLockdownPolicy() == |
| 2107 | + System.Management.Automation.Security.SystemEnforcementMode.Enforce); |
| 2108 | + } |
| 2109 | + } |
| 2110 | + |
| 2111 | + private static void CheckForBreakpointSupport() |
| 2112 | + { |
| 2113 | + if (IsSystemLockedDown) |
| 2114 | + { |
| 2115 | + // Local script debugging is not supported in locked down mode |
| 2116 | + throw new PSNotSupportedException(); |
| 2117 | + } |
| 2118 | + } |
| 2119 | + |
2089 | 2120 | #region Enable debug stepping |
2090 | 2121 |
|
2091 | 2122 | [Flags] |
@@ -2323,6 +2354,15 @@ public override void SetDebugMode(DebugModes mode) |
2323 | 2354 | { |
2324 | 2355 | lock (_syncObject) |
2325 | 2356 | { |
| 2357 | + // Restrict local script debugger mode when in system lock down. |
| 2358 | + // DebugModes enum flags provide a combination of values. To disable local script debugging |
| 2359 | + // we have to disallow 'LocalScript' and 'Default' flags and only allow 'None' or 'RemoteScript' |
| 2360 | + // flags exclusively. This allows only no debugging 'None' or remote debugging 'RemoteScript'. |
| 2361 | + if (IsSystemLockedDown && (mode != DebugModes.None) && (mode != DebugModes.RemoteScript)) |
| 2362 | + { |
| 2363 | + mode = DebugModes.RemoteScript; |
| 2364 | + } |
| 2365 | + |
2326 | 2366 | base.SetDebugMode(mode); |
2327 | 2367 |
|
2328 | 2368 | if (!CanEnableDebugger) |
|