Skip to content

Commit

Permalink
Clean up code, add sensible deref option default
Browse files Browse the repository at this point in the history
* Removed debugging puts and commented code

* Fixed 'deref' connection option parsing, set default 'deref' value
  to '0'
  • Loading branch information
John Lamb committed Mar 1, 2013
1 parent 1782424 commit 39808a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
8 changes: 5 additions & 3 deletions lib/ldapreplay/ldapconnection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize from_ip, from_port, to_ip, to_port
@op_ary = []
@op_hsh = {}
@ldap_conn = nil
@deref = nil
@deref = '0'
end

def add_op op_time, op_conn, op_id, op_type, *op_args
Expand All @@ -25,8 +25,10 @@ def add_op op_time, op_conn, op_id, op_type, *op_args
else
@op_hsh[op_id].add_args(*op_args)
end
puts op_time, op_conn, op_id, op_type, op_args
@deref = @op_hsh[op_id].op_args.fetch( :deref, @deref )
# puts op_time, op_conn, op_id, op_type, op_args
if @op_hsh[op_id].op_args
@deref = @op_hsh[op_id].op_args.fetch( :deref, @deref )
end
return new_op
end
end
3 changes: 0 additions & 3 deletions lib/ldapreplay/ldapoperation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ def initialize *args
end

def add_args op_args
# puts "1, #{op_args}, #{@op_args}"
if op_args
# puts 2
@op_args.merge! op_args
# puts "3, #{op_args}, #{@op_args}"
end
end

Expand Down
32 changes: 16 additions & 16 deletions lib/ldapreplay/parsers/openldap.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require 'ldapreplay/parsers'

class LdapReplay::Parsers::OpenLDAP
require 'ldapreplay/monkey_patches'
require 'time'

CONN = 'conn='

def initialize path, offset = 0
raise ArgumentError unless File.exists?( path )

Expand All @@ -14,17 +11,9 @@ def initialize path, offset = 0

end

# def parse_arg oparg
# oparg.split('=', 2).inject{|ii,jj| [ii.to_sym, jj.dchomp('"')]}
# end

def parse_arg oparg
# oparg.split('=', 2).inject{|ii,jj| [ii.to_sym, jj.dchomp('"')]}
# puts "oparg: #{oparg}"
mm = /([^=]+)="?([^"]*)"?$/.match(oparg)
# puts "mm: #{mm}"
if mm
# puts "mm.length: #{mm.length}"
mm[1..2].inject{|ii,jj| [ii.to_sym, jj]}
end
end
Expand All @@ -34,11 +23,24 @@ def parse_operation_args(o_args)
end

def parse_accept_args(a_args)
# Hash[[:from_ip, :from_port].zip(a_args[1][3..-1].split(':')).concat([:to_ip, :to_port].zip(a_args[2][4..-2].split(':')))]
# Hash[[:from_ip, :from_port, :to_ip, :to_port].zip(a_args[1][3..-1].split(':').concat a_args[2][4..-2].split(':'))]
(a_args[1][3..-1].split(':').concat a_args[2][4..-2].split(':'))
end

# For "ACCEPT" lines, generates an array containing the connection
# details; this signifies a new connection
#
# For "closed" and "UNBIND" lines, no additional parameters are
# returned; this signifies that a connection is being closed, and
# thus should have no more operations associated with it
#
# For "SRCH" lines, the arguments are parsed differently than for
# other operations, to account for the presence of the "attr="
# argument, which takes multiple parameters
#
# For other operation lines, arguments are parsed into a hash, with
# the argument type expressed as a :symbol, and the parameter as a
# string

def parse_line(op_time, op_conn, op_id, op_type, *op_args)
op_signature = [op_time, op_conn, op_id, op_type]
case op_type
Expand All @@ -59,9 +61,7 @@ def parse_line(op_time, op_conn, op_id, op_type, *op_args)

def emit &block
@log.each_line do |line|
next unless line.include?(CONN)
# Skip "RESULT" lines - include operation results in future?
# next if line.include?('RESULT')
next unless line.include?('conn=')

current_time = DateTime.parse( line[0,15] ).strftime('%s').to_i

Expand Down

0 comments on commit 39808a1

Please sign in to comment.