|
|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
$LOAD_PATH.unshift('lib') |
|
|
|
require 'ldap/server' |
|
|
|
require 'yaml' |
|
|
|
|
|
|
|
LOGGER = Logger.new($stderr) |
|
|
|
|
|
|
|
@ -28,14 +29,6 @@ class HashOperation < LDAP::Server::Operation |
|
|
|
send_BindResponse(authenticated ? 0 : 1) |
|
|
|
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) |
|
|
|
basedn = basedn.downcase |
|
|
|
LOGGER.info("SEARCHING...basedn=\"#{basedn}\", scope=#{scope}, deref=#{deref}, filter=#{filter}") |
|
|
|
@ -67,15 +60,24 @@ class HashOperation < LDAP::Server::Operation |
|
|
|
end |
|
|
|
send_SearchResultDone(0) |
|
|
|
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 |
|
|
|
|
|
|
|
# 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,...]} |
|
|
|
|
|
|
|
directory = {} |
|
|
|
require 'yaml' |
|
|
|
File.open('examples/ldapdb.yaml') { |f| directory = YAML.load(f.read) } |
|
|
|
LOGGER.info("DIRECTORY=#{directory}") |
|
|
|
File.open('examples/ldapdb.yaml') { |f| directory = YAML.safe_load(f.read) } |
|
|
|
LOGGER.info("DIRECTORY loaded from Yaml File containing #{directory.size} items") |
|
|
|
|
|
|
|
# Listen for incoming LDAP connections. For each one, create a Connection |
|
|
|
# object, which will invoke a HashOperation object for each request. |
|
|
|
|