eval/eval.rb
# Public: Performs an actual evaluation.
#
# This is the method that actually performs an evaluation within the Sandbox,
# using the information contained in the Hash that was passwd instance of
# Sandbox was created.
#
# Returns a String containing the result of the evaluation, or any errors that
#   occurred while trying to evaluate.
Performs an actual evaluation.
This is the method that actually performs an evaluation within the Sandbox,
using the information contained in the Hash that was passwd instance of
Sandbox was created.

Returns a String containing the result of the evaluation, or any errors that
occurred while trying to evaluate.
Performs an actual evaluation . This is the method that actually performs an evaluation within the Sandbox using the information contained in the Hash that was passwd instance of Sandbox was created . Returns a String containing the result of the evaluation or any errors that occurred while trying to evaluate .
def evaluate
    nonexistent_binaries = missing_binaries
    if nonexistent_binaries
      needed_binaries = nonexistent_binaries.join(', ')
      return ["[Rublets] Needed binaries were not found: #{needed_binaries}"]
    end
    insert_code_into_file
    copy_audit_script
    cmd_script_filename = @code_from_stdin ? [] : [@script_filename]
    sandbox_type = 'sandbox_t'
    popen_args = [
      'timeout', @timeout.to_s,
      'sandbox', '-H', @home, '-T', "#{@home}/tmp/", '-t', "#{sandbox_type}",
      'timeout', @timeout.to_s, *@evaluate_with
    ]
    popen_args << @script_filename unless @code_from_stdin
    start_time = Time.now
    IO.popen(popen_args + [{:err => [:child, :out]}], 'w+') do |io|
      io.write File.read("#{@home}/#{@script_filename}") if @code_from_stdin
      io.write @stdin unless @stdin.nil?
      io.close_write
      @result = io.read(@size_limit)
      break unless @result
      break if (@no_output = @result.gsub("\n", "") == "")
      @result = @result.split("\n")
      if @result[0].start_with? 'WARNING: Policy would be downgraded'
        @result.shift
      end
      @result[-1].gsub!('Unable to switch to root to clear tmp dir', '')
      @result =
        @result[@skip_preceding_lines..-(@skip_ending_lines + 1)].join("\n")
    end
    end_time = Time.now
    exitcode = $?.exitstatus.to_i
    if @result.nil? || @result.empty? || @no_output
      @result = "No output. (return code was #{exitcode})"
    end
    if "".respond_to?(:force_encoding) && defined?(Encoding)
      @result = @result.force_encoding(Encoding.default_external)
    end
    @result = @alter_result.call(@result) unless @alter_result.nil?
    lines, output = @result.split("\n"), []
    if lines.any? { |l| l.length > 255 }
      output << "<output is long> #{pastebin(@pastebin_credentials)}"
    else
      @output_limit += 1 if lines.size == @output_limit + 1
      lines[0...@output_limit].each do |line|
        output << ANSIRC.to_irc(line)
      end
      if lines.count > @output_limit and @pastebin_after_limit
        output << pastebin(@pastebin_credentials)
      end
    end
    if exitcode == 124 && (end_time - start_time >= @timeout)
      output << "Timeout of #{@timeout} seconds was hit."
    end
    output <<  @unsafe_perform_after.call(exitcode, @home) if @unsafe_perform_after
    output
  end
def evaluate nonexistent_binaries = missing_binaries if nonexistent_binaries needed_binaries = nonexistent_binaries . join ( ', ' ) return [ "[Rublets] Needed binaries were not found: #{needed_binaries}" ] end insert_code_into_file copy_audit_script cmd_script_filename = @code_from_stdin ? [ ] : [ @script_filename ] sandbox_type = 'sandbox_t' popen_args = [ 'timeout' , @timeout . to_s , 'sandbox' , '-H' , @home , '-T' , "#{@home}/tmp/" , '-t' , "#{sandbox_type}" , 'timeout' , @timeout . to_s , * @evaluate_with ] popen_args << @script_filename unless @code_from_stdin start_time = Time . now IO . popen ( popen_args + [ { :err => [ :child , :out ] } ] , 'w+' ) do | io | io . write File . read ( "#{@home}/#{@script_filename}" ) if @code_from_stdin io . write @stdin unless @stdin . nil? io . close_write @result = io . read ( @size_limit ) break unless @result break if ( @no_output = @result . gsub ( "\n" , "" ) == "" ) @result = @result . split ( "\n" ) if @result [ 0 ] . start_with? 'WARNING: Policy would be downgraded' @result . shift end @result [ - 1 ] . gsub! ( 'Unable to switch to root to clear tmp dir' , '' ) @result = @result [ @skip_preceding_lines .. - ( @skip_ending_lines + 1 ) ] . join ( "\n" ) end end_time = Time . now exitcode = $? . exitstatus . to_i if @result . nil? || @result . empty? || @no_output @result = "No output. (return code was #{exitcode})" end if "" . respond_to? ( :force_encoding ) && defined? ( Encoding ) @result = @result . force_encoding ( Encoding . default_external ) end @result = @alter_result . call ( @result ) unless @alter_result . nil? lines , output = @result . split ( "\n" ) , [ ] if lines . any? { | l | l . length > 255 } output << "<output is long> #{pastebin(@pastebin_credentials)}" else @output_limit += 1 if lines . size == @output_limit + 1 lines [ 0 ... @output_limit ] . each do | line | output << ANSIRC . to_irc ( line ) end if lines . count > @output_limit and @pastebin_after_limit output << pastebin ( @pastebin_credentials ) end end if exitcode == 124 && ( end_time - start_time >= @timeout ) output << "Timeout of #{@timeout} seconds was hit." end output << @unsafe_perform_after . call ( exitcode , @home ) if @unsafe_perform_after output end
Public: Performs an actual evaluation.
Public : Performs an actual evaluation .
# Do we need to do anything to the result before we show it?