Skip to content

Commit ebc50a9

Browse files
route ldap queries through socks proxy if quotaguard url present
1 parent db0e267 commit ebc50a9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/net/ldap/connection.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,17 +707,28 @@ def socket
707707

708708
private
709709

710+
# Wrap around Socket.tcp to normalize with other Socket initializers
710711
# Wrap around Socket.tcp to normalize with other Socket initializers
711712
class DefaultSocket
712713
def self.new(host, port, socket_opts = {})
713-
if ENV["QUOTAGUARDSTATIC_URL"] != nil
714-
# puts 'quotaguard url is present'
715-
socks = URI.parse(ENV["QUOTAGUARDSTATIC_URL"].to_s)
716-
puts socks
717-
# http://dl2bwsbvp46amx:[email protected]:9293
718-
# Scoket.tcp()
714+
715+
# see: https://github.com/quotaguard/ruby-net-ldap/commit/66b436c8322de05e999d36c3a9edaf26c26d167c
716+
# for the reference to how this was implemented
717+
718+
if ENV["QUOTAGUARDSTATIC_URL"].present?
719+
720+
# our quotaguard url
721+
socks = URI.parse ENV["QUOTAGUARDSTATIC_URL"]
722+
723+
# socks socket config
724+
TCPSOCKSSocket::socks_port = 1080
725+
TCPSOCKSSocket::socks_server = socks.host
726+
TCPSOCKSSocket::socks_username = socks.user
727+
TCPSOCKSSocket::socks_password = socks.password
728+
729+
# create and return the socks socket, for ldap queries to be routed through
730+
TCPSOCKSSocket.new(host, port, socket_opts)
719731
else
720-
puts 'quotaguard url is NOT present'
721732
Socket.tcp(host, port, socket_opts)
722733
end
723734
end

0 commit comments

Comments
 (0)