func (s *SandboxDecoder) Init(config interface{}) (err error) { s.sbc = config.(*SandboxConfig) s.sbc.ScriptFilename = pipeline.PrependShareDir(s.sbc.ScriptFilename) s.tz = time.UTC if tz, ok := s.sbc.Config["tz"]; ok { s.tz, err = time.LoadLocation(tz.(string)) if err != nil { return } } data_dir := pipeline.PrependBaseDir(DATA_DIR) if !fileExists(data_dir) { err = os.MkdirAll(data_dir, 0700) if err != nil { return } } switch s.sbc.ScriptType { case "lua": default: return fmt.Errorf("unsupported script type: %s", s.sbc.ScriptType) } s.sample = true return }
// Determines the script type and creates interpreter func (this *SandboxFilter) Init(config interface{}) (err error) { if this.sb != nil { return nil // no-op already initialized } this.sbc = config.(*SandboxConfig) this.sbc.ScriptFilename = pipeline.PrependShareDir(this.sbc.ScriptFilename) data_dir := pipeline.PrependBaseDir(DATA_DIR) if !fileExists(data_dir) { err = os.MkdirAll(data_dir, 0700) if err != nil { return } } switch this.sbc.ScriptType { case "lua": this.sb, err = lua.CreateLuaSandbox(this.sbc) if err != nil { return } default: return fmt.Errorf("unsupported script type: %s", this.sbc.ScriptType) } this.preservationFile = filepath.Join(data_dir, this.name+DATA_EXT) if this.sbc.PreserveData && fileExists(this.preservationFile) { err = this.sb.Init(this.preservationFile, "filter") } else { err = this.sb.Init("", "filter") } return }
func (s *SandboxEncoder) Init(config interface{}) (err error) { conf := config.(*SandboxEncoderConfig) s.sbc = &sandbox.SandboxConfig{ ScriptType: conf.ScriptType, ScriptFilename: conf.ScriptFilename, ModuleDirectory: conf.ModuleDirectory, PreserveData: conf.PreserveData, MemoryLimit: conf.MemoryLimit, InstructionLimit: conf.InstructionLimit, OutputLimit: conf.OutputLimit, Profile: conf.Profile, Config: conf.Config, } s.sbc.ScriptFilename = pipeline.PrependShareDir(s.sbc.ScriptFilename) s.sampleDenominator = pipeline.Globals().SampleDenominator s.tz = time.UTC if tz, ok := s.sbc.Config["tz"]; ok { if s.tz, err = time.LoadLocation(tz.(string)); err != nil { return } } dataDir := pipeline.PrependBaseDir(sandbox.DATA_DIR) if !fileExists(dataDir) { if err = os.MkdirAll(dataDir, 0700); err != nil { return } } switch s.sbc.ScriptType { case "lua": s.sb, err = lua.CreateLuaSandbox(s.sbc) default: return fmt.Errorf("Unsupported script type: %s", s.sbc.ScriptType) } if err != nil { return fmt.Errorf("Sandbox creation failed: '%s'", err) } s.preservationFile = filepath.Join(dataDir, s.name+sandbox.DATA_EXT) if s.sbc.PreserveData && fileExists(s.preservationFile) { err = s.sb.Init(s.preservationFile, "encoder") } else { err = s.sb.Init("", "encoder") } if err != nil { return fmt.Errorf("Sandbox initialization failed: %s", err) } s.sb.InjectMessage(func(payload, payload_type, payload_name string) int { s.injected = true s.output = []byte(payload) return 0 }) s.sample = true s.cEncoder = client.NewProtobufEncoder(nil) return }
func NewSandboxConfig() interface{} { return &SandboxConfig{ ModuleDirectory: pipeline.PrependShareDir("lua_modules"), MemoryLimit: 8 * 1024 * 1024, InstructionLimit: 1e6, OutputLimit: 63 * 1024, } }
func (s *SandboxEncoder) ConfigStruct() interface{} { return &SandboxEncoderConfig{ ModuleDirectory: pipeline.PrependShareDir("lua_modules"), MemoryLimit: 8 * 1024 * 1024, InstructionLimit: 1e6, OutputLimit: 63 * 1024, ScriptType: "lua", } }
// Creates the working directory to store the submitted scripts, // configurations, and data preservation files. func (this *SandboxManagerFilter) Init(config interface{}) (err error) { conf := config.(*SandboxManagerFilterConfig) this.maxFilters = conf.MaxFilters this.workingDirectory = pipeline.PrependBaseDir(conf.WorkingDirectory) this.moduleDirectory = pipeline.PrependShareDir(conf.ModuleDirectory) this.memoryLimit = conf.MemoryLimit this.instructionLimit = conf.InstructionLimit this.outputLimit = conf.OutputLimit err = os.MkdirAll(this.workingDirectory, 0700) return }