From db0e267cce18f4b3a2602794dc2511578a772940 Mon Sep 17 00:00:00 2001 From: Matthew Maddern Date: Wed, 11 Sep 2019 13:27:35 +0930 Subject: [PATCH 1/6] check for quotaguard url --- lib/net/ldap.rb | 1 + lib/net/ldap/connection.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index f7a98ef5..2d2a6e8a 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -16,6 +16,7 @@ class LDAP end end require 'socket' +require 'socksify' require 'net/ber' require 'net/ldap/pdu' diff --git a/lib/net/ldap/connection.rb b/lib/net/ldap/connection.rb index b01984f4..a49b7dfa 100644 --- a/lib/net/ldap/connection.rb +++ b/lib/net/ldap/connection.rb @@ -710,7 +710,16 @@ def socket # Wrap around Socket.tcp to normalize with other Socket initializers class DefaultSocket def self.new(host, port, socket_opts = {}) - Socket.tcp(host, port, socket_opts) + if ENV["QUOTAGUARDSTATIC_URL"] != nil + # puts 'quotaguard url is present' + socks = URI.parse(ENV["QUOTAGUARDSTATIC_URL"].to_s) + puts socks + # http://dl2bwsbvp46amx:6wXLQMKgHC2axiff_wTNT0Phtw@us-east-static-02.quotaguard.com:9293 + # Scoket.tcp() + else + puts 'quotaguard url is NOT present' + Socket.tcp(host, port, socket_opts) + end end end end # class Connection From ebc50a9abe965da35b6f054044f55f21dc70af9b Mon Sep 17 00:00:00 2001 From: Matthew Maddern Date: Thu, 12 Sep 2019 10:40:20 +0930 Subject: [PATCH 2/6] route ldap queries through socks proxy if quotaguard url present --- lib/net/ldap/connection.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/net/ldap/connection.rb b/lib/net/ldap/connection.rb index a49b7dfa..a612e161 100644 --- a/lib/net/ldap/connection.rb +++ b/lib/net/ldap/connection.rb @@ -707,17 +707,28 @@ def socket private + # Wrap around Socket.tcp to normalize with other Socket initializers # Wrap around Socket.tcp to normalize with other Socket initializers class DefaultSocket def self.new(host, port, socket_opts = {}) - if ENV["QUOTAGUARDSTATIC_URL"] != nil - # puts 'quotaguard url is present' - socks = URI.parse(ENV["QUOTAGUARDSTATIC_URL"].to_s) - puts socks - # http://dl2bwsbvp46amx:6wXLQMKgHC2axiff_wTNT0Phtw@us-east-static-02.quotaguard.com:9293 - # Scoket.tcp() + + # see: https://github.com/quotaguard/ruby-net-ldap/commit/66b436c8322de05e999d36c3a9edaf26c26d167c + # for the reference to how this was implemented + + if ENV["QUOTAGUARDSTATIC_URL"].present? + + # our quotaguard url + socks = URI.parse ENV["QUOTAGUARDSTATIC_URL"] + + # socks socket config + TCPSOCKSSocket::socks_port = 1080 + TCPSOCKSSocket::socks_server = socks.host + TCPSOCKSSocket::socks_username = socks.user + TCPSOCKSSocket::socks_password = socks.password + + # create and return the socks socket, for ldap queries to be routed through + TCPSOCKSSocket.new(host, port, socket_opts) else - puts 'quotaguard url is NOT present' Socket.tcp(host, port, socket_opts) end end From 05afd7c9c80ddc19d60eae3bfdd767272d90cbc9 Mon Sep 17 00:00:00 2001 From: matthewmaddern Date: Thu, 12 Sep 2019 10:50:45 +0930 Subject: [PATCH 3/6] fix formatting --- lib/net/ldap/connection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/ldap/connection.rb b/lib/net/ldap/connection.rb index a612e161..64e429e0 100644 --- a/lib/net/ldap/connection.rb +++ b/lib/net/ldap/connection.rb @@ -723,7 +723,7 @@ def self.new(host, port, socket_opts = {}) # socks socket config TCPSOCKSSocket::socks_port = 1080 TCPSOCKSSocket::socks_server = socks.host - TCPSOCKSSocket::socks_username = socks.user + TCPSOCKSSocket::socks_username = socks.user TCPSOCKSSocket::socks_password = socks.password # create and return the socks socket, for ldap queries to be routed through From c1f6410536df77f182acc127ebed0337058cdb93 Mon Sep 17 00:00:00 2001 From: matthewmaddern <46211129+matthewmaddern@users.noreply.github.com> Date: Thu, 12 Sep 2019 12:39:09 +0930 Subject: [PATCH 4/6] Update README.rdoc --- README.rdoc | 73 +++-------------------------------------------------- 1 file changed, 3 insertions(+), 70 deletions(-) diff --git a/README.rdoc b/README.rdoc index f1b1ea36..b175f994 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,72 +1,5 @@ -= Net::LDAP for Ruby {}[https://travis-ci.org/ruby-ldap/ruby-net-ldap] +**The latest version of ruby-net-ldap (as of 12th Sep, 2019), Forked to work with QuotaGuard Static** -== Description +To use, add `gem 'net-ldap', github: "matthewmaddern/ruby-net-ldap", branch: "master"` to your Gemfile. -Net::LDAP for Ruby (also called net-ldap) implements client access for the -Lightweight Directory Access Protocol (LDAP), an IETF standard protocol for -accessing distributed directory services. Net::LDAP is written completely in -Ruby with no external dependencies. It supports most LDAP client features and a -subset of server features as well. - -Net::LDAP has been tested against modern popular LDAP servers including -OpenLDAP and Active Directory. The current release is mostly compliant with -earlier versions of the IETF LDAP RFCs (2251–2256, 2829–2830, 3377, and 3771). -Our roadmap for Net::LDAP 1.0 is to gain full client compliance with -the most recent LDAP RFCs (4510–4519, plus portions of 4520–4532). - -== Where - -* {GitHub}[https://github.com/ruby-ldap/ruby-net-ldap] -* {ruby-ldap@googlegroups.com}[http://groups.google.com/group/ruby-ldap] - -== Synopsis - -See Net::LDAP for documentation and usage samples. - -== Requirements - -Net::LDAP requires a Ruby 2.0.0 compatible interpreter or better. - -== Install - -Net::LDAP is a pure Ruby library. It does not require any external libraries. -You can install the RubyGems version of Net::LDAP available from the usual -sources. - - gem install net-ldap - -Simply require either 'net-ldap' or 'net/ldap'. - -== Extensions - -This library focuses on the core LDAP RFCs referenced in the description. -However, we recognize there are commonly used extensions to the spec that are -useful. If there is another library which handles it, we list it here. - -* {resolv-srv}[https://rubygems.org/gems/resolv-srv]: Support RFC2782 SRV record lookup and failover - -== Develop - -This task will run the test suite and the -{RuboCop}[https://github.com/bbatsov/rubocop] static code analyzer. - - rake rubotest - -CI takes too long? If your local box supports -{Vagrant}[https://www.vagrantup.com/], you can run most of the tests -in a VM on your local box. For more details and setup instructions, see -{test/support/vm/openldap/README.md}[https://github.com/ruby-ldap/ruby-net-ldap/tree/master/test/support/vm/openldap/README.md] - -== Release - -This section is for gem maintainers to cut a new version of the gem. - -* Check out a new branch `release-VERSION` -* Update lib/net/ldap/version.rb to next version number X.X.X following {semver}(http://semver.org/). -* Update `History.rdoc`. Get latest changes with `script/changelog` -* Open a pull request with these changes for review -* After merging, on the master branch, run `script/release` - -:include: Contributors.rdoc - -:include: License.rdoc +For more informaiton, view the original version of net-ldap here: https://github.com/ruby-ldap/ruby-net-ldap From 672af07a95eb4bb7703d91008b6cbd70bc945c57 Mon Sep 17 00:00:00 2001 From: matthewmaddern <46211129+matthewmaddern@users.noreply.github.com> Date: Thu, 12 Sep 2019 12:39:23 +0930 Subject: [PATCH 5/6] Rename README.rdoc to README.md --- README.rdoc => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.rdoc => README.md (100%) diff --git a/README.rdoc b/README.md similarity index 100% rename from README.rdoc rename to README.md From da0ccb9895a936c245a97ec7cd7a2e0b1805a7a4 Mon Sep 17 00:00:00 2001 From: matthewmaddern <46211129+matthewmaddern@users.noreply.github.com> Date: Thu, 12 Sep 2019 12:40:52 +0930 Subject: [PATCH 6/6] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b175f994..22a4f1aa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -**The latest version of ruby-net-ldap (as of 12th Sep, 2019), Forked to work with QuotaGuard Static** +**The latest version of ruby-net-ldap (as of 12th Sep, 2019), forked to work with QuotaGuard Static** -To use, add `gem 'net-ldap', github: "matthewmaddern/ruby-net-ldap", branch: "master"` to your Gemfile. +To use this gem, add `gem 'net-ldap', github: "matthewmaddern/ruby-net-ldap", branch: "master"` to your Gemfile. -For more informaiton, view the original version of net-ldap here: https://github.com/ruby-ldap/ruby-net-ldap +For more information, view the original version of net-ldap here: https://github.com/ruby-ldap/ruby-net-ldap