From 228a17006576971337ce248338b2c59f403169c2 Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Mon, 17 Jan 2022 11:50:26 +0000 Subject: [PATCH] Add LDAP v3 protocol support Signed-off-by: Sergey Bogdanov --- diary_env.example.rb | 12 ++++++++++-- ldap_record.rb | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/diary_env.example.rb b/diary_env.example.rb index efffc76..96af3fb 100644 --- a/diary_env.example.rb +++ b/diary_env.example.rb @@ -17,7 +17,11 @@ class DiaryEnv DB_DATABASE = "diary" LDAP_HOST = 'ldap.example.com' + LDAP_PORT = 389 LDAP_ROOT = "ou=People,dc=example,dc=com" + LDAP_VER = 3 + LDAP_BIND_DN = "" + LDAP_BIND_PW = "" HOME_ORGANIZATION = "Example ORG" HOME_OU = "Employees" @@ -31,8 +35,12 @@ class DiaryEnv def initialize @confirmation = Array.new Person.setup(:host => LDAP_HOST, - :root => LDAP_ROOT, - :key => "uid") + :port => LDAP_PORT, + :root => LDAP_ROOT, + :ver => LDAP_VER, + :binddn => LDAP_BIND_DN, + :bindpw => LDAP_BIND_PW, + :key => "uid") Person.set_local(HOME_ORGANIZATION, HOME_OU) DataMapper.setup(:adapter => "Mysql", :database => DB_DATABASE, diff --git a/ldap_record.rb b/ldap_record.rb index d5217ef..a23ab73 100644 --- a/ldap_record.rb +++ b/ldap_record.rb @@ -5,7 +5,7 @@ # Class LdapRecord for Diary Management Application. # -require 'ldap_cache' +require_relative 'ldap_cache' require 'net/smtp' class LdapRecord @@ -17,6 +17,12 @@ class LdapRecord raise "Invalid parameters" unless args.is_a? Hash raise "LDAP server is not specified" unless args[:host] @@ldap = LDAP::Conn.new(args[:host], args[:port] || LDAP::LDAP_PORT) + if args[:ver] == 3 + @@ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) + end + if args[:binddn] != "" + @@ldap.bind(args[:binddn], args[:bindpw]) + end #@@ldap.bind # Bind is optional for LDAPv3 raise "LDAP tree root is not specified" unless args[:root]