Skip to content

Instantly share code, notes, and snippets.

@ThomasLocke
Created January 22, 2012 14:46
Show Gist options
  • Save ThomasLocke/1657269 to your computer and use it in GitHub Desktop.
Save ThomasLocke/1657269 to your computer and use it in GitHub Desktop.
Patch for AWS.LDAP that fixes bug where CONSTRAINT_ERROR is raised instead of LDAP_ERROR.
From a3a1d6c6c6b00c4386710f59a2939b84a40455f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20L=C3=B8cke?= <thomas@12boo.net>
Date: Sun, 22 Jan 2012 15:34:29 +0100
Subject: [PATCH] Fix constraint error when bind fails due to bad server.
Instead of getting a useless CONSTRAINT_ERROR exception, we now get a proper
LDAP_ERROR exception with the message "Can't contact LDAP server".
---
src/ldap/aws-ldap-client.adb | 21 ++++++++++++++++++---
src/ldap/aws-ldap-thin.ads | 4 +++-
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/ldap/aws-ldap-client.adb b/src/ldap/aws-ldap-client.adb
index 6c8de3d..ccf268a 100644
--- a/src/ldap/aws-ldap-client.adb
+++ b/src/ldap/aws-ldap-client.adb
@@ -40,7 +40,6 @@ package body AWS.LDAP.Client is
use Interfaces.C.Strings;
package IC renames Interfaces.C;
-
use type IC.int;
C_Scope : constant array (Scope_Type) of IC.int
@@ -59,6 +58,9 @@ package body AWS.LDAP.Client is
C_Bool : constant array (Boolean) of IC.int := (False => 0, True => 1);
-- Map Boolean with the corrsponding C values
+ function Err_Code_Image (Code : Thin.Return_Code) return String;
+ -- Returns image of Code without the leading blank.
+
function To_C (Mods : LDAP_Mods.Vector) return Thin.LDAPMods;
-- Create C-Style LDAPMod ** structure used to store all
-- modification operations to perform on a LDAP-entry.
@@ -341,6 +343,20 @@ package body AWS.LDAP.Client is
return Result;
end DN2UFN;
+ ----------------------
+ -- Err_Code_Image --
+ ----------------------
+
+ function Err_Code_Image (Code : Thin.Return_Code) return String is
+ S : constant String := Thin.Return_Code'Image (Code);
+ begin
+ if S (S'First) = ' ' then
+ return S (S'First + 1 .. S'Last);
+ else
+ return S;
+ end if;
+ end Err_Code_Image;
+
----------------
-- Explode_DN --
----------------
@@ -739,8 +755,7 @@ package body AWS.LDAP.Client is
Err_Message : constant String := Value (Thin.ldap_err2string (Code));
begin
raise LDAP_Error
- with Message & " - ["
- & AWS.Utils.Image (Integer (Code)) & "] " & Err_Message;
+ with Message & " - [" & Err_Code_Image (Code) & "] " & Err_Message;
end Raise_Error;
------------
diff --git a/src/ldap/aws-ldap-thin.ads b/src/ldap/aws-ldap-thin.ads
index 9284487..68b75d2 100644
--- a/src/ldap/aws-ldap-thin.ads
+++ b/src/ldap/aws-ldap-thin.ads
@@ -38,6 +38,8 @@ package AWS.LDAP.Thin is
package C renames Interfaces.C;
+ use type Interfaces.C.int;
+
subtype chars_ptr is C.Strings.chars_ptr;
function NS (S : String) return chars_ptr renames C.Strings.New_String;
@@ -360,7 +362,7 @@ package AWS.LDAP.Thin is
-- Possible error codes we can return
- subtype Return_Code is C.int range 16#00# .. 16#61#;
+ subtype Return_Code is C.int range -16#01# .. 16#61#;
LDAP_SUCCESS : constant := 16#00#;
LDAP_OPERATIONS_ERROR : constant := 16#01#;
--
1.7.4.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment