From 68e6b4074195ec4f163f4ffb2250a29cb6e4097f Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 7 Jul 2011 15:07:44 +0200 Subject: [PATCH] add proper error checking for LDAP search --- lib/pg_ldap_sync/application.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pg_ldap_sync/application.rb b/lib/pg_ldap_sync/application.rb index f32d8c0..61f679e 100644 --- a/lib/pg_ldap_sync/application.rb +++ b/lib/pg_ldap_sync/application.rb @@ -32,6 +32,7 @@ require 'pg_ldap_sync' module PgLdapSync class Application + class LdapError < RuntimeError; end attr_accessor :config_fname attr_accessor :log attr_accessor :test @@ -77,7 +78,7 @@ class Application ldap_user_conf = @config[:ldap_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 unless name @@ -95,6 +96,7 @@ class Application end end end + raise LdapError, "LDAP: #{@ldap.get_operation_result.message}" unless res return users end @@ -102,7 +104,7 @@ class Application ldap_group_conf = @config[:ldap_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 unless name @@ -120,6 +122,7 @@ class Application end end end + raise LdapError, "LDAP: #{@ldap.get_operation_result.message}" unless res return groups end