Exemplo n.º 1
0
        public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst)
        {
            IEnumerable <string>      allowedCommands = dataStatementAst.HasNonConstantAllowedCommand ? null : GetConstantDataStatementAllowedCommands(dataStatementAst);
            RestrictedLanguageChecker visitor         = new RestrictedLanguageChecker(this._parser, allowedCommands, null, false);

            dataStatementAst.Body.InternalVisit(visitor);
            return(AstVisitAction.Continue);
        }
Exemplo n.º 2
0
 internal static void CheckDataStatementAstAtRuntime(DataStatementAst dataStatementAst, string[] allowedCommands)
 {
     Parser parser = new Parser();
     RestrictedLanguageChecker visitor = new RestrictedLanguageChecker(parser, allowedCommands, null, false);
     dataStatementAst.Body.InternalVisit(visitor);
     if (parser.ErrorList.Any<ParseError>())
     {
         throw new ParseException(parser.ErrorList.ToArray());
     }
 }
        internal static void CheckDataStatementAstAtRuntime(DataStatementAst dataStatementAst, string[] allowedCommands)
        {
            Parser parser = new Parser();
            RestrictedLanguageChecker visitor = new RestrictedLanguageChecker(parser, allowedCommands, null, false);

            dataStatementAst.Body.InternalVisit(visitor);
            if (parser.ErrorList.Any <ParseError>())
            {
                throw new ParseException(parser.ErrorList.ToArray());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Check the script block to see if it uses any language constructs not allowed in restricted language mode.
        /// </summary>
        /// <param name="allowedCommands">The commands that are allowed.</param>
        /// <param name="allowedVariables">
        /// The variables allowed in this scriptblock. If this is null, then the default variable set
        /// will be allowed. If it is an empty list, no variables will be allowed. If it is "*" then
        /// any variable will be allowed.
        /// </param>
        /// <param name="allowEnvironmentVariables">The environment variables that are allowed.</param>
        public void CheckRestrictedLanguage(IEnumerable<string> allowedCommands, IEnumerable<string> allowedVariables, bool allowEnvironmentVariables)
        {
            Parser parser = new Parser();

            var ast = AstInternal;
            if (HasBeginBlock || HasProcessBlock || ast.Body.ParamBlock != null)
            {
                Ast errorAst = ast.Body.BeginBlock ?? (Ast)ast.Body.ProcessBlock ?? ast.Body.ParamBlock;
                parser.ReportError(errorAst.Extent, () => ParserStrings.InvalidScriptBlockInDataSection);
            }

            if (HasEndBlock)
            {
                RestrictedLanguageChecker rlc = new RestrictedLanguageChecker(parser, allowedCommands, allowedVariables, allowEnvironmentVariables);
                var endBlock = ast.Body.EndBlock;
                StatementBlockAst.InternalVisit(rlc, endBlock.Traps, endBlock.Statements, AstVisitAction.Continue);
            }

            if (parser.ErrorList.Any())
            {
                throw new ParseException(parser.ErrorList.ToArray());
            }
        }
Exemplo n.º 5
0
 public void CheckRestrictedLanguage(IEnumerable<string> allowedCommands, IEnumerable<string> allowedVariables, bool allowEnvironmentVariables)
 {
     Parser parser = new Parser();
     if (this.HasBeginBlock || this.HasProcessBlock || this._ast.Body.ParamBlock != null)
     {
         NamedBlockAst beginBlock = this._ast.Body.BeginBlock;
         Ast paramBlock = beginBlock;
         if (beginBlock == null)
         {
             NamedBlockAst processBlock = this._ast.Body.ProcessBlock;
             paramBlock = processBlock;
             if (processBlock == null)
             {
                 paramBlock = this._ast.Body.ParamBlock;
             }
         }
         Ast ast = paramBlock;
         parser.ReportError(ast.Extent, ParserStrings.InvalidScriptBlockInDataSection, new object[0]);
     }
     if (this.HasEndBlock)
     {
         RestrictedLanguageChecker restrictedLanguageChecker = new RestrictedLanguageChecker(parser, allowedCommands, allowedVariables, allowEnvironmentVariables);
         NamedBlockAst endBlock = this._ast.Body.EndBlock;
         StatementBlockAst.InternalVisit(restrictedLanguageChecker, endBlock.Traps, endBlock.Statements, AstVisitAction.Continue);
     }
     if (!parser.ErrorList.Any<ParseError>())
     {
         return;
     }
     else
     {
         throw new ParseException(parser.ErrorList.ToArray());
     }
 }
Exemplo n.º 6
0
        public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst)
        {
            IEnumerable<string> allowedCommands =
                dataStatementAst.HasNonConstantAllowedCommand ? null : GetConstantDataStatementAllowedCommands(dataStatementAst);
            RestrictedLanguageChecker checker = new RestrictedLanguageChecker(_parser, allowedCommands, null, false);
            dataStatementAst.Body.InternalVisit(checker);

            return AstVisitAction.Continue;
        }