add proper error checking for LDAP search
This commit is contained in:
parent
aab83aaf09
commit
68e6b40741
@ -32,6 +32,7 @@ require 'pg_ldap_sync'
|
|||||||
|
|
||||||
module PgLdapSync
|
module PgLdapSync
|
||||||
class Application
|
class Application
|
||||||
|
class LdapError < RuntimeError; end
|
||||||
attr_accessor :config_fname
|
attr_accessor :config_fname
|
||||||
attr_accessor :log
|
attr_accessor :log
|
||||||
attr_accessor :test
|
attr_accessor :test
|
||||||
@ -77,7 +78,7 @@ class Application
|
|||||||
ldap_user_conf = @config[:ldap_users]
|
ldap_user_conf = @config[:ldap_users]
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
@ldap.search(:base => ldap_user_conf[:base], :filter => ldap_user_conf[:filter]) do |entry|
|
res = @ldap.search(:base => ldap_user_conf[:base], :filter => ldap_user_conf[:filter]) do |entry|
|
||||||
name = entry[ldap_user_conf[:name_attribute]].first
|
name = entry[ldap_user_conf[:name_attribute]].first
|
||||||
|
|
||||||
unless name
|
unless name
|
||||||
@ -95,6 +96,7 @@ class Application
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
raise LdapError, "LDAP: #{@ldap.get_operation_result.message}" unless res
|
||||||
return users
|
return users
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -102,7 +104,7 @@ class Application
|
|||||||
ldap_group_conf = @config[:ldap_groups]
|
ldap_group_conf = @config[:ldap_groups]
|
||||||
|
|
||||||
groups = []
|
groups = []
|
||||||
@ldap.search(:base => ldap_group_conf[:base], :filter => ldap_group_conf[:filter]) do |entry|
|
res = @ldap.search(:base => ldap_group_conf[:base], :filter => ldap_group_conf[:filter]) do |entry|
|
||||||
name = entry[ldap_group_conf[:name_attribute]].first
|
name = entry[ldap_group_conf[:name_attribute]].first
|
||||||
|
|
||||||
unless name
|
unless name
|
||||||
@ -120,6 +122,7 @@ class Application
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
raise LdapError, "LDAP: #{@ldap.get_operation_result.message}" unless res
|
||||||
return groups
|
return groups
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user