pvincent 2 weeks ago
parent
commit
0209addad1
  1. 23
      examples/ldapdb.yaml
  2. 25
      examples/server2.rb

23
examples/ldapdb.yaml

@ -2,11 +2,32 @@
dc=pvincent,dc=re:
cn:
- Top object
cn=admin,dc=pvincent,dc=re:
mail=admin@pvincent.re,dc=zourit,dc=re:
cn:
- admin
sn:
- Vincentdmin
mail:
- admin@pvincent.re
mail=test1@pvincent.re,dc=zourit,dc=re:
cn:
- test1
sn:
- Test1
mail:
- test1@pvincent.re
mail=test2@pvincent.re,dc=zourit,dc=re:
cn:
- test2
sn:
- Test2
mail:
- test2@pvincent.re
mail=test3@pvincent.re,dc=zourit,dc=re:
cn:
- test3
sn:
- Test3
mail:
- test3@pvincent.re

25
examples/server2.rb

@ -26,25 +26,16 @@ class HashOperation < LDAP::Server::Operation
version = protocolOp.value[0].value
authentication = protocolOp.value[2]
password = authentication.value
$logger.info("AUTHENTICATION ..version=#{version}, dn=#{dn}, password=#{password}")
super
valid = password == 'toto'
$logger.info("AUTHENTICATION ..version=#{version}, dn=#{dn}, valid=#{valid}")
send_BindResponse(valid ? 0 : 1)
end
# def simple_bind(version, dn, password)
# super.simple_bind(version, dn, password)
# $logger.info("SIMPLE BIND...version=#{version}, dn=#{dn}")
#
# raise LDAP::ResultError::ProtocolError, 'version 3 only' if version != 3
# raise LDAP::ResultError::InvalidCredentials, 'Invalid credentials' if password.nil? || password == ''
#
# $logger.info('authentication SUCCESS')
# end
#
def search(basedn, scope, deref, filter)
$logger.info("SEARCHING...basedn=#{basedn}, scope=#{scope}, deref=#{deref}, filter=#{filter}")
basedn = basedn.downcase
result = nil
nil
case scope
when LDAP::Server::BaseObject
# client asked for single object by DN
@ -52,22 +43,20 @@ class HashOperation < LDAP::Server::Operation
raise LDAP::ResultError::NoSuchObject unless obj
$logger.info('BaseObject')
result = send_SearchResultEntry(basedn, obj) if LDAP::Server::Filter.run(filter, obj)
send_SearchResultEntry(basedn, obj) if LDAP::Server::Filter.run(filter, obj)
when LDAP::Server::WholeSubtree
@hash.each do |dn, av|
next unless dn.index(basedn, -basedn.length) # under basedn?
next unless LDAP::Server::Filter.run(filter, av) # attribute filter?
$logger.info('WholeSubtree')
result = send_SearchResultEntry(dn, av)
$logger.info("WholeSubtree av=#{av}")
send_SearchResultEntry(dn, av)
end
else
raise LDAP::ResultError::UnwillingToPerform, 'OneLevel not implemented'
end
$logger.info "result=#{result}"
# result
end
end

Loading…
Cancel
Save