Blame SOURCES/0011-Ticket-47799-Any-negative-LDAP-error-code-number-rep.patch

a2f18f
From 3c2165deb45571a0ff0547e5c8c2c970095cca04 Mon Sep 17 00:00:00 2001
a2f18f
From: Noriko Hosoi <nhosoi@redhat.com>
a2f18f
Date: Wed, 8 Jul 2015 10:19:15 -0700
a2f18f
Subject: [PATCH 11/20] Ticket #47799 - Any negative LDAP error code number
a2f18f
 reported as Illegal error by ldclt.
a2f18f
a2f18f
Description: ldclt was implemented with mozldap, which did not expect
a2f18f
negative erorr codes, but openldap does.  E.g., LDAP_FILTER_ERROR (-7)
a2f18f
This patch prepares a negativeError array for the negative error codes.
a2f18f
Example:
a2f18f
  $ ldclt [...] -e esearch -e random -b "<basedn>" -f "<bad filter>" -v
a2f18f
  Filter             = "<bad filter>"
a2f18f
   ...
a2f18f
  ldclt[16030]: T000: Cannot ldap_search(), error=-7 (Bad search filter) -- NULL result
a2f18f
   ...
a2f18f
  ldclt[16030]: Global error -7 (Bad search filter) occurs  1001 times
a2f18f
  ldclt[16030]: Exit status 3 - Max errors reached.
a2f18f
a2f18f
https://fedorahosted.org/389/ticket/47799
a2f18f
a2f18f
Reviewed by mreynolds@redhat.com (Thank you, Mark!!)
a2f18f
a2f18f
(cherry picked from commit 71be5faaa478593bb056887410ca8e48e05b2fe4)
a2f18f
(cherry picked from commit 0680a45773ab4b0e92ec26caa3acbb6bab379103)
a2f18f
---
a2f18f
 ldap/servers/slapd/tools/ldclt/ldapfct.c    |  4 +++
a2f18f
 ldap/servers/slapd/tools/ldclt/ldclt.c      | 35 ++++++++++++++++-----
a2f18f
 ldap/servers/slapd/tools/ldclt/ldclt.h      | 11 ++++++-
a2f18f
 ldap/servers/slapd/tools/ldclt/threadMain.c | 48 +++++++++++++++++++----------
a2f18f
 4 files changed, 73 insertions(+), 25 deletions(-)
a2f18f
a2f18f
diff --git a/ldap/servers/slapd/tools/ldclt/ldapfct.c b/ldap/servers/slapd/tools/ldclt/ldapfct.c
a2f18f
index f906c5a..13e66b8 100644
a2f18f
--- a/ldap/servers/slapd/tools/ldclt/ldapfct.c
a2f18f
+++ b/ldap/servers/slapd/tools/ldclt/ldapfct.c
a2f18f
@@ -1382,6 +1382,10 @@ printErrorFromLdap (
a2f18f
   printf ("ldclt[%d]: T%03d: %s, error=%d (%s",
a2f18f
 		mctx.pid, tttctx->thrdNum, errmsg,
a2f18f
 		errcode, my_ldap_err2string (errcode));
a2f18f
+  if (!res) {
a2f18f
+    printf (") -- NULL result\n");
a2f18f
+    return -1;
a2f18f
+  }
a2f18f
 
a2f18f
   /*
a2f18f
    * See if there is an additional error message...
a2f18f
diff --git a/ldap/servers/slapd/tools/ldclt/ldclt.c b/ldap/servers/slapd/tools/ldclt/ldclt.c
a2f18f
index edb687f..9e573a5 100644
a2f18f
--- a/ldap/servers/slapd/tools/ldclt/ldclt.c
a2f18f
+++ b/ldap/servers/slapd/tools/ldclt/ldclt.c
a2f18f
@@ -716,19 +716,35 @@ printGlobalStatistics (void)
a2f18f
    * Note:	Maybe implement a way to stop the running threads ?
a2f18f
    */
a2f18f
   found = 0;
a2f18f
-  for (i=0 ; i
a2f18f
-    if (mctx.errors[i] > 0)
a2f18f
-    {
a2f18f
+  for (i = 0; i < MAX_ERROR_NB; i++) {
a2f18f
+    if (mctx.errors[i] > 0) {
a2f18f
       found = 1;
a2f18f
       sprintf (buf, "(%s)", my_ldap_err2string (i));
a2f18f
       printf ("ldclt[%d]: Global error %2d %s occurs %5d times\n",
a2f18f
           mctx.pid, i, buf, mctx.errors[i]);
a2f18f
     }
a2f18f
+  }
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+  for (i = 0; i < ABS(NEGATIVE_MAX_ERROR_NB); i++) {
a2f18f
+    if (mctx.negativeErrors[i] > 0) {
a2f18f
+      found = 1;
a2f18f
+      sprintf (buf, "(%s)", my_ldap_err2string (-i));
a2f18f
+      printf ("ldclt[%d]: Global error %2d %s occurs %5d times\n",
a2f18f
+          mctx.pid, -i, buf, mctx.negativeErrors[i]);
a2f18f
+    }
a2f18f
+  }
a2f18f
+#endif
a2f18f
   if (mctx.errorsBad > 0)
a2f18f
   {
a2f18f
     found = 1;
a2f18f
-    printf ("ldclt[%d]: Global illegal errors (codes not in [0, %d]) occurs %5d times\n",
a2f18f
-	mctx.pid, MAX_ERROR_NB-1, mctx.errorsBad);
a2f18f
+    printf("ldclt[%d]: Global illegal errors (codes not in [%d, %d]) occurs %5d times\n",
a2f18f
+            mctx.pid, 
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+			NEGATIVE_MAX_ERROR_NB, 
a2f18f
+#else
a2f18f
+			0,
a2f18f
+#endif
a2f18f
+			MAX_ERROR_NB-1, mctx.errorsBad);
a2f18f
   }
a2f18f
   if (!found)
a2f18f
     printf ("ldclt[%d]: Global no error occurs during this session.\n", mctx.pid);
a2f18f
@@ -1293,9 +1309,14 @@ basicInit (void)
a2f18f
   mctx.totNbOpers   = 0;
a2f18f
   mctx.totNbSamples = 0;
a2f18f
   mctx.errorsBad    = 0;
a2f18f
-  for (i=0 ; i
a2f18f
+  for (i = 0; i < MAX_ERROR_NB; i++) {
a2f18f
     mctx.errors[i] = 0;
a2f18f
-
a2f18f
+  }
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+  for (i = 0; i < ABS(NEGATIVE_MAX_ERROR_NB); i++) {
a2f18f
+    mctx.negativeErrors[i] = 0;
a2f18f
+  }
a2f18f
+#endif
a2f18f
   /*
a2f18f
    * Initiate the mutex that protect the errors statistics
a2f18f
    */
a2f18f
diff --git a/ldap/servers/slapd/tools/ldclt/ldclt.h b/ldap/servers/slapd/tools/ldclt/ldclt.h
a2f18f
index a48ab79..4f8f485 100644
a2f18f
--- a/ldap/servers/slapd/tools/ldclt/ldclt.h
a2f18f
+++ b/ldap/servers/slapd/tools/ldclt/ldclt.h
a2f18f
@@ -169,6 +169,9 @@ dd/mm/yy | Author	| Comments
a2f18f
 #ifndef LDCLT_H
a2f18f
 #define LDCLT_H
a2f18f
 
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+#define ABS(x) ((x > 0) ? (x) : (-x))
a2f18f
+#endif
a2f18f
 /*
a2f18f
  * Misc constant definitions
a2f18f
  */
a2f18f
@@ -183,7 +186,10 @@ dd/mm/yy | Author	| Comments
a2f18f
 #define DEF_PORT_CHECK	  16000 /* Port used for check processing */
a2f18f
 #define MAX_ATTRIBS	     40 /* Max number of attributes */	/*JLS 28-03-01*/
a2f18f
 #define MAX_DN_LENGTH	   1024 /* Max length for a DN */
a2f18f
-#define MAX_ERROR_NB	   0x62 /* Max ldap err number + 1 */
a2f18f
+#define MAX_ERROR_NB	   0x7b /* Max ldap err number + 1 */
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+#define NEGATIVE_MAX_ERROR_NB	   (LDAP_X_CONNECTING - 1) /* Mininum ldap err number */
a2f18f
+#endif
a2f18f
 #define MAX_IGN_ERRORS	     20 /* Max errors ignored */
a2f18f
 #define MAX_FILTER	    512 /* Max filters length */
a2f18f
 #define MAX_THREADS	   1000 /* Max number of threads */	/*JLS 21-11-00*/
a2f18f
@@ -504,6 +510,9 @@ typedef struct main_context {
a2f18f
         char            *certfile;      /* certificate file */ /* BK 11-10-00 */
a2f18f
         char            *cltcertname;   /* client cert name */ /* BK 23 11-00 */
a2f18f
 	data_list_file	*dlf;		/* Data list files */	/*JLS 23-03-01*/
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+	int		 negativeErrors[ABS(NEGATIVE_MAX_ERROR_NB)]; /* Err stats */
a2f18f
+#endif
a2f18f
 	int		 errors[MAX_ERROR_NB]; /* Err stats */
a2f18f
 	int		 errorsBad;	/* Bad errors */
a2f18f
 	ldclt_mutex_t	 errors_mutex;	/* Protect errors */	/*JLS 28-11-00*/
a2f18f
diff --git a/ldap/servers/slapd/tools/ldclt/threadMain.c b/ldap/servers/slapd/tools/ldclt/threadMain.c
a2f18f
index be41186..5d915fd 100644
a2f18f
--- a/ldap/servers/slapd/tools/ldclt/threadMain.c
a2f18f
+++ b/ldap/servers/slapd/tools/ldclt/threadMain.c
a2f18f
@@ -430,14 +430,26 @@ addErrorStat (
a2f18f
   /*
a2f18f
    * Update the counters
a2f18f
    */
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+  if ((err <= NEGATIVE_MAX_ERROR_NB) || (err >= MAX_ERROR_NB))
a2f18f
+#else
a2f18f
   if ((err <= 0) || (err >= MAX_ERROR_NB))
a2f18f
+#endif
a2f18f
   {
a2f18f
     fprintf (stderr, "ldclt[%d]: Illegal error number %d\n", mctx.pid, err);
a2f18f
     fflush (stderr);
a2f18f
     mctx.errorsBad++;
a2f18f
   }
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+  else if (err < 0)
a2f18f
+  {
a2f18f
+    mctx.negativeErrors[abs(err)]++;
a2f18f
+  }
a2f18f
+#endif
a2f18f
   else
a2f18f
+  {
a2f18f
     mctx.errors[err]++;
a2f18f
+  }
a2f18f
 
a2f18f
   /*
a2f18f
    * Release the mutex
a2f18f
@@ -460,26 +472,28 @@ addErrorStat (
a2f18f
      * Ok, we should not ignore this error...
a2f18f
      * Maybe the limit is reached ?
a2f18f
      */
a2f18f
+#if defined(USE_OPENLDAP)
a2f18f
+    if ((err <= NEGATIVE_MAX_ERROR_NB) || (err >= MAX_ERROR_NB))
a2f18f
+#else
a2f18f
     if ((err <= 0) || (err >= MAX_ERROR_NB))
a2f18f
-    {
a2f18f
-      if (mctx.errorsBad > mctx.maxErrors)
a2f18f
-      {
a2f18f
-	printf ("ldclt[%d]: Max error limit reached - exiting.\n", mctx.pid);
a2f18f
-	(void) printGlobalStatistics();				/*JLS 25-08-00*/
a2f18f
-	fflush (stdout);
a2f18f
-	ldclt_sleep (5);
a2f18f
-	ldcltExit (EXIT_MAX_ERRORS);				/*JLS 25-08-00*/
a2f18f
+#endif
a2f18f
+	{
a2f18f
+      if (mctx.errorsBad > mctx.maxErrors) {
a2f18f
+        printf ("ldclt[%d]: Max error limit reached - exiting.\n", mctx.pid);
a2f18f
+        (void) printGlobalStatistics();				/*JLS 25-08-00*/
a2f18f
+        fflush (stdout);
a2f18f
+        ldclt_sleep (5);
a2f18f
+        ldcltExit (EXIT_MAX_ERRORS);				/*JLS 25-08-00*/
a2f18f
       }
a2f18f
-    }
a2f18f
-    else
a2f18f
-      if (mctx.errors[err] > mctx.maxErrors)
a2f18f
-      {
a2f18f
-	printf ("ldclt[%d]: Max error limit reached - exiting.\n", mctx.pid);
a2f18f
-	(void) printGlobalStatistics();				/*JLS 25-08-00*/
a2f18f
-	fflush (stdout);
a2f18f
-	ldclt_sleep (5);
a2f18f
-	ldcltExit (EXIT_MAX_ERRORS);				/*JLS 25-08-00*/
a2f18f
+    } else {
a2f18f
+      if (mctx.errors[err] + mctx.negativeErrors[abs(err)] > mctx.maxErrors) {
a2f18f
+        printf ("ldclt[%d]: Max error limit reached - exiting.\n", mctx.pid);
a2f18f
+        (void) printGlobalStatistics();				/*JLS 25-08-00*/
a2f18f
+        fflush (stdout);
a2f18f
+        ldclt_sleep (5);
a2f18f
+        ldcltExit (EXIT_MAX_ERRORS);				/*JLS 25-08-00*/
a2f18f
       }
a2f18f
+    }
a2f18f
   }
a2f18f
 
a2f18f
   /*
a2f18f
-- 
a2f18f
1.9.3
a2f18f