metafiles changed; Sandbox has an own repository: Safebox
This commit is contained in:
parent
31cf25c5ab
commit
fc04254b8e
4
Rakefile
4
Rakefile
|
@ -10,8 +10,8 @@ begin
|
|||
gem.email = "Denis.Knauf@gmail.com"
|
||||
gem.homepage = "http://github.com/DenisKnauf/logan"
|
||||
gem.authors = ["Denis Knauf"]
|
||||
gem.files = ["README", "VERSION", "lib/**/*.rb", "test/**/*.rb"]
|
||||
gem.require_paths = ["lib"]
|
||||
gem.files = %w[AUTHORS README.md VERSION lib/**/*.rb test/**/*.rb]
|
||||
gem.require_paths = %w[lib]
|
||||
end
|
||||
Jeweler::GemcutterTasks.new
|
||||
rescue LoadError
|
||||
|
|
87
bin/box2.rb
Executable file
87
bin/box2.rb
Executable file
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'sbdb'
|
||||
|
||||
module Sandbox
|
||||
def self.run *paras, &exe
|
||||
exe = paras.shift unless exe
|
||||
box = paras.shift || Class
|
||||
Thread.new do
|
||||
$SAFE = 4
|
||||
this = box.new *paras
|
||||
begin
|
||||
[:value, this.instance_eval( exe, "Sandbox")]
|
||||
rescue Object
|
||||
[:exception, $!]
|
||||
end
|
||||
end.value
|
||||
end
|
||||
|
||||
def self.create_class *paras, &exe
|
||||
exe = paras.shift unless exe
|
||||
run Class, *paras do
|
||||
eval exe
|
||||
self
|
||||
end
|
||||
end
|
||||
alias new_class create_class
|
||||
end
|
||||
|
||||
class Box
|
||||
attr_reader :_, :db
|
||||
|
||||
def initialize db, _
|
||||
@_, @db = _, db
|
||||
end
|
||||
|
||||
def put( key, val) @db[key] = val end
|
||||
def get( key) @db[key] end
|
||||
end
|
||||
|
||||
class ClassBuilder
|
||||
end
|
||||
|
||||
class Emit
|
||||
def initialize( db) @db = db end
|
||||
def emit( key, val) @db[key] = val end
|
||||
def inspect() "#<%s:0x%016x>" % [ self.class, self.object_id ] end
|
||||
end
|
||||
|
||||
class Persistent < Emit
|
||||
include Enumerable
|
||||
def initialize db, cursor
|
||||
super db
|
||||
@cursor = cursor
|
||||
end
|
||||
alias put emit
|
||||
alias []= emit
|
||||
def get( key) @db[key] end
|
||||
alias [] get
|
||||
alias fetch get
|
||||
def each &exe
|
||||
exe ? @cursor.each( &exe) : Enumerator.new( self, :each)
|
||||
end
|
||||
def to_hash
|
||||
rh = {}
|
||||
each {|key, val| rh[ key] = val }
|
||||
rh
|
||||
end
|
||||
end
|
||||
|
||||
_ = nil
|
||||
Dir.mkdir 'logs' rescue Errno::EEXIST
|
||||
SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs|
|
||||
db = logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE]
|
||||
db = Persistent.new db, db.cursor
|
||||
$stdout.print "(0)$ "
|
||||
STDIN.each_with_index do |line, i|
|
||||
ret = Sandbox.run line, Box, db, _
|
||||
if :value == ret.first
|
||||
_ = ret.last
|
||||
$stdout.puts "=> #{ret.last.inspect}"
|
||||
else
|
||||
$stdout.puts ret.last.inspect
|
||||
end
|
||||
$stdout.print "(#{i+1})$ "
|
||||
end
|
||||
end
|
22
bin/box3.rb
Executable file
22
bin/box3.rb
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'sbdb'
|
||||
require 'safebox'
|
||||
|
||||
_ = nil
|
||||
Dir.mkdir 'logs' rescue Errno::EEXIST
|
||||
SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs|
|
||||
db = logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE]
|
||||
db = Safebox::Persistent.new db, db.cursor
|
||||
$stdout.print "(0)$ "
|
||||
STDIN.each_with_index do |line, i|
|
||||
ret = Safebox.run line, Safebox::Box, db, _
|
||||
if :value == ret.first
|
||||
_ = ret.last
|
||||
$stdout.puts "=> #{ret.last.inspect}"
|
||||
else
|
||||
$stdout.puts ret.last.inspect
|
||||
end
|
||||
$stdout.print "(#{i+1})$ "
|
||||
end
|
||||
end
|
66
bin/loganinc
66
bin/loganinc
|
@ -1,58 +1,22 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'sbdb'
|
||||
require 'safebox'
|
||||
|
||||
# Secure Worker. Unsafe code in a sandbox.
|
||||
class Worker
|
||||
class Box
|
||||
def self.start e, c
|
||||
Thread.new c, &new( e).method( :run)
|
||||
end
|
||||
|
||||
def run
|
||||
this.untaint
|
||||
e.taint
|
||||
$SAFE = 4
|
||||
end
|
||||
|
||||
def initialize e
|
||||
@emit = e
|
||||
end
|
||||
|
||||
def emit f, k, v
|
||||
@emit.emit f, k, v
|
||||
end
|
||||
end
|
||||
|
||||
def emit f, k, v
|
||||
@out.push [f, k, v]
|
||||
end
|
||||
|
||||
def initalize i, o
|
||||
@in, @out, @funcs = i, o, {}
|
||||
super method(:run)
|
||||
end
|
||||
|
||||
def run
|
||||
$SAFE = 3
|
||||
@in.each do |o|
|
||||
@funcs[:]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
SBDB::Env.new 'conf' do |conf|
|
||||
SBDB::Env.new 'logs' do |logs|
|
||||
SBDB::Env.new 'persist' do |persist|
|
||||
test = cache[ 'test']
|
||||
while line = logs[ 'newids'].get( nil, "\0\0\0\0", nil, SBDB::CONSUME_WAIT)
|
||||
type, obj = line.unpack 'Na*'
|
||||
case type
|
||||
when 11
|
||||
sid, log = obj.unpack 'Na*'
|
||||
parser = conf[ 'sids.cnf', 'parser'][sid]
|
||||
end
|
||||
end
|
||||
_ = nil
|
||||
Dir.mkdir 'logs' rescue Errno::EEXIST
|
||||
SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs|
|
||||
db = logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE]
|
||||
db = Safebox::Persistent.new db, db.cursor
|
||||
$stdout.print "(0)$ "
|
||||
STDIN.each_with_index do |line, i|
|
||||
ret = Safebox.run line, Safebox::Box, db, _
|
||||
if :value == ret.first
|
||||
_ = ret.last
|
||||
$stdout.puts "=> #{ret.last.inspect}"
|
||||
else
|
||||
$stdout.puts ret.last.inspect
|
||||
end
|
||||
$stdout.print "(#{i+1})$ "
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue