private
This commit is contained in:
+13
-11
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
$LOAD_PATH.unshift('lib')
|
$LOAD_PATH.unshift('lib')
|
||||||
require 'ldap/server'
|
require 'ldap/server'
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
LOGGER = Logger.new($stderr)
|
LOGGER = Logger.new($stderr)
|
||||||
|
|
||||||
@@ -28,14 +29,6 @@ class HashOperation < LDAP::Server::Operation
|
|||||||
send_BindResponse(authenticated ? 0 : 1)
|
send_BindResponse(authenticated ? 0 : 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_mail_from_dn(entry)
|
|
||||||
entry[/mail=(.*?),/, 1] # short for regex first capture
|
|
||||||
end
|
|
||||||
|
|
||||||
def valid?(_email, password)
|
|
||||||
password == 'toto'
|
|
||||||
end
|
|
||||||
|
|
||||||
def search(basedn, scope, deref, filter)
|
def search(basedn, scope, deref, filter)
|
||||||
basedn = basedn.downcase
|
basedn = basedn.downcase
|
||||||
LOGGER.info("SEARCHING...basedn=\"#{basedn}\", scope=#{scope}, deref=#{deref}, filter=#{filter}")
|
LOGGER.info("SEARCHING...basedn=\"#{basedn}\", scope=#{scope}, deref=#{deref}, filter=#{filter}")
|
||||||
@@ -67,15 +60,24 @@ class HashOperation < LDAP::Server::Operation
|
|||||||
end
|
end
|
||||||
send_SearchResultDone(0)
|
send_SearchResultDone(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def extract_mail_from_dn(entry)
|
||||||
|
entry[/mail=(.*?),/, 1] # short for regex first capture
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid?(_email, password)
|
||||||
|
password == 'toto'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is the shared object which carries our actual directory entries.
|
# This is the shared object which carries our actual directory entries.
|
||||||
# It's just a hash of {dn=>entry}, where each entry is {attr=>[val,val,...]}
|
# It's just a hash of {dn=>entry}, where each entry is {attr=>[val,val,...]}
|
||||||
|
|
||||||
directory = {}
|
directory = {}
|
||||||
require 'yaml'
|
File.open('examples/ldapdb.yaml') { |f| directory = YAML.safe_load(f.read) }
|
||||||
File.open('examples/ldapdb.yaml') { |f| directory = YAML.load(f.read) }
|
LOGGER.info("DIRECTORY loaded from Yaml File containing #{directory.size} items")
|
||||||
LOGGER.info("DIRECTORY=#{directory}")
|
|
||||||
|
|
||||||
# Listen for incoming LDAP connections. For each one, create a Connection
|
# Listen for incoming LDAP connections. For each one, create a Connection
|
||||||
# object, which will invoke a HashOperation object for each request.
|
# object, which will invoke a HashOperation object for each request.
|
||||||
|
|||||||
Reference in New Issue
Block a user