-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* The LdapConnection class provides storage for a single LDAP session between the server and client. The operations performed from the connection over its life are aggregated into this connection, along with an id, which should be unique and used to reference an LdapConnection object in a collection or database. * Added parseops3.rb to test LdapConnection class.
- Loading branch information
John Lamb
committed
Feb 15, 2013
1 parent
814eb3b
commit 48c4c6f
Showing
4 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'ldapreplay' | ||
|
||
class LdapReplay::LdapConnection | ||
|
||
attr_accessor :id, :op_ary, :op_hsh, :from_ip, :from_port, :to_ip, :to_port, :ldap_conn | ||
|
||
def initialize from_ip, from_port, to_ip, to_port | ||
@from_ip = from_ip | ||
@from_port = from_port | ||
@to_ip = to_ip | ||
@to_port = to_port | ||
@op_ary = [] | ||
@op_hsh = {} | ||
@ldap_conn = nil | ||
end | ||
|
||
def add_op op_time, op_conn, op_id, op_type, *op_args | ||
unless op_hsh[op_id] | ||
new_op = LdapReplay::LdapOperation.new(op_time, op_conn, op_id, op_type, *op_args) | ||
@op_hsh[op_id] = new_op | ||
@op_ary.push new_op | ||
return new_op | ||
else | ||
@op_hsh[op_id].add_args(*op_args) | ||
return nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/ruby -I ./lib | ||
|
||
require 'ldapreplay/parsers/openldap' | ||
require 'ldapreplay/ldapoperation' | ||
require 'pp' | ||
require 'yaml' | ||
|
||
parser = LdapReplay::Parsers::OpenLDAP.new( *ARGV ) | ||
|
||
conn_hsh = {} | ||
conn_ary = [] | ||
op_hsh = Hash.new { |hh, kk| hh[kk] = [] } | ||
|
||
parser.emit { |args| | ||
begin | ||
op_time, op_conn, op_id, op_type, op_args = *args | ||
# puts "args: #{args.join(' ')}" | ||
unless op_type == 'RESULT' | ||
if conn_hsh.has_key?(op_conn) | ||
connection = conn_hsh[op_conn] | ||
if connection.has_key?(op_id) | ||
connection[op_id].add_args(op_args) | ||
else | ||
new_op = LdapReplay::LdapOperation.new(*args) | ||
connection[op_id] = new_op | ||
unless new_op.op_type == 'ACCEPT' | ||
op_hsh[new_op.op_time].push(new_op) | ||
end | ||
end | ||
else | ||
conn_hsh[op_conn] = {op_id => LdapReplay::LdapOperation.new(*args)} | ||
end | ||
if op_type == 'closed' | ||
conn_ary.push conn_hsh.delete op_conn | ||
# puts "--------------------" | ||
# puts "conn_hsh: %s" % conn_hsh.pretty_inspect | ||
# puts "====================" | ||
# puts "op_hsh: %s" % op_hsh.pretty_inspect | ||
# puts "conn_ary: %s" % conn_ary.pretty_inspect | ||
# # puts "conn_ary: #{conn_ary}" | ||
# puts "^^^^^^^^^^^^^^^^^^^^" | ||
end | ||
end | ||
rescue Errno::EPIPE | ||
break | ||
end | ||
} | ||
|
||
ckeys = conn_hsh.keys | ||
ckeys.each {|kk| conn_ary.push conn_hsh.delete kk} | ||
|
||
# puts "--------------------" | ||
# puts "conn_hsh: %s" % conn_hsh.pretty_inspect | ||
# puts "====================" | ||
# puts "conn_ary: %s" % conn_ary.pretty_inspect | ||
# # puts "conn_ary: #{conn_ary}" | ||
# puts "^^^^^^^^^^^^^^^^^^^^" | ||
|
||
# puts YAML.dump conn_ary | ||
puts "op_hsh: %s" % op_hsh.pretty_inspect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/ruby -I ./lib | ||
|
||
require 'ldapreplay/parsers/openldap' | ||
require 'ldapreplay/ldapoperation' | ||
require 'ldapreplay/ldapconnection' | ||
require 'pp' | ||
require 'yaml' | ||
|
||
parser = LdapReplay::Parsers::OpenLDAP.new( *ARGV ) | ||
|
||
conn_hsh = {} | ||
conn_ary = [] | ||
op_hsh = Hash.new { |hh, kk| hh[kk] = [] } | ||
|
||
parser.emit { |args| | ||
begin | ||
op_time, op_conn, op_id, op_type, op_args = *args | ||
# puts "args: #{args.join(' ')}" | ||
case op_type | ||
when 'ACCEPT' | ||
nc = LdapReplay::LdapConnection.new( op_args[:from_ip], op_args[:from_port], op_args[:to_ip], op_args[:to_port] ) | ||
nc.id = (conn_ary.push(nc).size) - 1 | ||
conn_hsh[op_conn] = nc.id | ||
when 'closed' | ||
conn_hsh.delete op_conn | ||
when 'RESULT' | ||
|
||
else | ||
if conn_hsh[op_conn] and conn = conn_ary[conn_hsh[op_conn]] | ||
if new_op = conn.add_op(*args) | ||
op_hsh[new_op.op_time].push(new_op) | ||
end | ||
end | ||
end | ||
rescue Errno::EPIPE | ||
break | ||
end | ||
} | ||
|
||
|
||
puts "--------------------" | ||
puts "conn_hsh: %s" % conn_hsh.pretty_inspect | ||
puts "====================" | ||
puts "conn_ary: %s" % conn_ary.pretty_inspect | ||
# puts "conn_ary: #{conn_ary}" | ||
puts "^^^^^^^^^^^^^^^^^^^^" | ||
|
||
# puts YAML.dump conn_ary | ||
puts "op_hsh: %s" % op_hsh.pretty_inspect |