private static void Check( Parser parser, ParseTreeNode ptn, IEnumerable <string> allowedCommands, bool moduleManifest) { RestrictedLanguageModeChecker languageModeChecker = new RestrictedLanguageModeChecker(parser, allowedCommands, moduleManifest); ptn.Accept((ParseTreeVisitor)languageModeChecker); }
public static void Check( Parser parser, ScriptBlock scriptBlock, IEnumerable <string> allowedCommands, bool moduleManifset) { if (scriptBlock == null) { return; } if (scriptBlock.Begin != null || scriptBlock.Process != null || scriptBlock.ParameterDeclaration != null) { parser.ReportException((object)null, typeof(ParseException), scriptBlock.Token, "InvalidScriptBlockInDataSection"); } if (scriptBlock.End == null) { return; } RestrictedLanguageModeChecker.Check(parser, scriptBlock.End, allowedCommands, moduleManifset); }
internal ScriptCommandProcessor( string script, ExecutionContext context, bool isFilter, bool useLocalScope, bool interactiveCommand, CommandOrigin origin) { this.Context = context; this._interactiveCommand = interactiveCommand; this._dontUseScopeCommandOrigin = false; this._rethrowExitException = this.Context.ScriptCommandProcessorShouldRethrowExit; this.Context.ScriptCommandProcessorShouldRethrowExit = false; if (origin == CommandOrigin.Runspace && this.Context.LanguageMode == PSLanguageMode.NoLanguage) { throw InterpreterError.NewInterpreterException((object)script, typeof(ParseException), (Token)null, "ScriptsNotAllowed"); } this._scriptBlock = this.Context.Engine.ParseScriptBlock(script, interactiveCommand); if (origin == CommandOrigin.Runspace) { switch (this.Context.LanguageMode) { case PSLanguageMode.FullLanguage: break; case PSLanguageMode.RestrictedLanguage: RestrictedLanguageModeChecker.Check(this.Context.Engine.EngineParser, this._scriptBlock, (IEnumerable <string>)null, false); break; default: throw new InvalidOperationException("Invalid langage mode was set when building a ScriptCommandProcessor"); } } this.CommandInfo = (CommandInfo) new ScriptInfo(string.Empty, this._scriptBlock, context); this._fromPipeline = true; this.SetupCommand(); this.Command.CommandOriginInternal = origin; this.UseLocalScope = useLocalScope; }
internal override object Execute(Array input, Pipe outputPipe, ExecutionContext context) { this.CheckForInterrupts(context); object obj = (object)null; IEnumerable <string> commandsAllowed = (IEnumerable <string>) this.GetCommandsAllowed(context); if (this._body != null) { RestrictedLanguageModeChecker.Check(context.Engine.EngineParser, this._body, commandsAllowed); PSLanguageMode languageMode = context.LanguageMode; try { context.LanguageMode = PSLanguageMode.RestrictedLanguage; obj = this._body.Execute(input, (Pipe)null, context); } finally { context.LanguageMode = languageMode; } } if (this._name == null) { return(obj); } string tokenText = this._name.TokenText; PSVariable variableAtScope = context.EngineSessionState.GetVariableAtScope(tokenText, "local"); if (variableAtScope == null) { PSVariable variable = new PSVariable(tokenText, obj, ScopedItemOptions.None); context.EngineSessionState.NewVariableAtScope(variable, "local", true); } else { variableAtScope.Value = obj; } return((object)AutomationNull.Value); }
public static void Check(Parser parser, ParseTreeNode ptn, IEnumerable <string> allowedCommands) => RestrictedLanguageModeChecker.Check(parser, ptn, allowedCommands, false);