Skip to content

Instantly share code, notes, and snippets.

@tk3
Created January 24, 2012 14:28
Show Gist options
  • Save tk3/1670430 to your computer and use it in GitHub Desktop.
Save tk3/1670430 to your computer and use it in GitHub Desktop.
LDAP server(tentative)
#!/opt/ruby/bin/ruby
require "socket"
require "pp"
gs = TCPServer.open(1500)
addr = gs.addr
addr.shift
printf("server is on %s\n", addr.join(":"))
ss = DATA.read.split("\n")
req_proc = lambda do |s|
print(s, " is accepted\n")
i = 0
while true
puts ">> read"
head = s.read(2).unpack("C*")
# puts ">> length = #{head[1]}"
body = s.read(head[1])
# puts ">> length = #{body.length}"
res = body.unpack("C*")
if 3 < res.length && res[3] == 0x42
puts "request is Unbind"
break
end
idx = 0
if i == 0
idx = 0
else
idx = 1
end
puts ">> write"
s.write(ss[idx].split.collect{|c| c.hex}.pack("C*"))
i = i + 1
end
s.shutdown(Socket::SHUT_RDWR)
s.close
puts ">> finished"
end
while true
Thread.start(gs.accept, &req_proc)
end
__END__
30 0c 02 01 01 61 07 0a 01 00 04 00 04 00
30 81 a3 02 01 02 64 81 9d 04 21 63 6e 3d 75 73 65 72 30 31 2c 6f 75 3d 67 72 6f 75 70 2c 64 63 3d 71 74 6b 6d 7a 2c 64 63 3d 6a 70 30 78 30 0e 04 02 73 6e 31 08 04 06 75 73 65 72 30 31 30 0e 04 02 63 6e 31 08 04 06 75 73 65 72 30 31 30 1c 04 0b 6f 62 6a 65 63 74 43 6c 61 73 73 31 0d 04 03 74 6f 70 04 06 70 65 72 73 6f 6e 30 38 04 0c 75 73 65 72 50 61 73 73 77 6f 72 64 31 28 04 26 7b 53 53 48 41 7d 4a 42 74 57 50 39 43 6a 68 41 61 4e 61 48 61 56 6c 46 44 4e 4d 42 79 48 73 36 4f 41 77 6c 48 4a 30 0c 02 01 02 65 07 0a 01 00 04 00 04 00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment