Bug 1277602 - pass correct number of arguments to format strings draft
authorISHIKAWA, Chiaki <ishikawa@yk.rim.or.jp>
Sat, 09 Nov 2019 11:11:57 +0900
changeset 81095 758f2fd86cc752f32ac6a10643c820d3567e5f1c
parent 81094 b403fb968812671266c382bb549689a0e7b0118c
child 81096 889fb11e4c2d85a52bee737b725633951655b48a
push id9745
push userishikawa@yk.rim.or.jp
push dateSat, 09 Nov 2019 02:12:14 +0000
treeherdertry-comm-central@f62e5475decc [default view] [failures only]
bugs1277602
Bug 1277602 - pass correct number of arguments to format strings
ldap/c-sdk/include/ldaplog.h
ldap/c-sdk/libraries/libldap/abandon.c
ldap/c-sdk/libraries/libldap/add.c
ldap/c-sdk/libraries/libldap/bind.c
ldap/c-sdk/libraries/libldap/cache.c
ldap/c-sdk/libraries/libldap/charset.c
ldap/c-sdk/libraries/libldap/cldap.c
ldap/c-sdk/libraries/libldap/compare.c
ldap/c-sdk/libraries/libldap/control.c
ldap/c-sdk/libraries/libldap/delete.c
ldap/c-sdk/libraries/libldap/error.c
ldap/c-sdk/libraries/libldap/extendop.c
ldap/c-sdk/libraries/libldap/getattr.c
ldap/c-sdk/libraries/libldap/getdn.c
ldap/c-sdk/libraries/libldap/getdxbyname.c
ldap/c-sdk/libraries/libldap/getentry.c
ldap/c-sdk/libraries/libldap/getvalues.c
ldap/c-sdk/libraries/libldap/memcache.c
ldap/c-sdk/libraries/libldap/modify.c
ldap/c-sdk/libraries/libldap/open.c
ldap/c-sdk/libraries/libldap/os-ip.c
ldap/c-sdk/libraries/libldap/rename.c
ldap/c-sdk/libraries/libldap/request.c
ldap/c-sdk/libraries/libldap/result.c
ldap/c-sdk/libraries/libldap/saslbind.c
ldap/c-sdk/libraries/libldap/sbind.c
ldap/c-sdk/libraries/libldap/search.c
ldap/c-sdk/libraries/libldap/tmplout.c
ldap/c-sdk/libraries/libldap/unbind.c
ldap/c-sdk/libraries/libldap/url.c
--- a/ldap/c-sdk/include/ldaplog.h
+++ b/ldap/c-sdk/include/ldaplog.h
@@ -58,49 +58,137 @@ extern "C" {
 #define LDAP_DEBUG_REPL 0x02000
 #define LDAP_DEBUG_ANY 0x04000
 #define LDAP_DEBUG_CACHE 0x08000
 #define LDAP_DEBUG_PLUGIN 0x10000
 
 /* debugging stuff */
 /* Disable by default */
 #define LDAPDebug(level, fmt, arg1, arg2, arg3)
+#define LDAPDebug0(level, fmt, arg1, arg2, arg3) \
+  LDAPDebug(level, fmt, arg1, arg2, arg3)
+#define LDAPDebug1(level, fmt, arg1, arg2, arg3) \
+  LDAPDebug(level, fmt, arg1, arg2, arg3)
+#define LDAPDebug2(level, fmt, arg1, arg2, arg3) \
+  LDAPDebug(level, fmt, arg1, arg2, arg3)
+#define LDAPDebug3(level, fmt, arg1, arg2, arg3) \
+  LDAPDebug(level, fmt, arg1, arg2, arg3)
 
 #ifdef LDAP_DEBUG
 #  undef LDAPDebug
+#  undef LDAPDebug0
+#  undef LDAPDebug1
+#  undef LDAPDebug2
+#  undef LDAPDebug3
 
 /* SLAPD_LOGGING should not be on for WINSOCK (16-bit Windows) */
 #  if defined(SLAPD_LOGGING)
 #    ifdef _WIN32
 extern int *module_ldap_debug;
 #      define LDAPDebug(level, fmt, arg1, arg2, arg3)          \
         {                                                      \
           if (*module_ldap_debug & level) {                    \
             slapd_log_error_proc(NULL, fmt, arg1, arg2, arg3); \
           }                                                    \
         }
+#      define LDAPDebug0(level, fmt, arg1, arg2, arg3) \
+        {                                              \
+          if (*module_ldap_debug & level) {            \
+            slapd_log_error_proc(NULL, fmt);           \
+          }                                            \
+        }
+#      define LDAPDebug1(level, fmt, arg1, arg2, arg3) \
+        {                                              \
+          if (*module_ldap_debug & level) {            \
+            slapd_log_error_proc(NULL, fmt, arg1);     \
+          }                                            \
+        }
+#      define LDAPDebug2(level, fmt, arg1, arg2, arg3)   \
+        {                                                \
+          if (*module_ldap_debug & level) {              \
+            slapd_log_error_proc(NULL, fmt, arg1, arg2); \
+          }                                              \
+        }
+#      define LDAPDebug3(level, fmt, arg1, arg2, arg3)         \
+        {                                                      \
+          if (*module_ldap_debug & level) {                    \
+            slapd_log_error_proc(NULL, fmt, arg1, arg2, arg3); \
+          }                                                    \
+        }
 #    else /* _WIN32 */
 extern int ldap_debug;
 #      define LDAPDebug(level, fmt, arg1, arg2, arg3)          \
         {                                                      \
           if (ldap_debug & level) {                            \
             slapd_log_error_proc(NULL, fmt, arg1, arg2, arg3); \
           }                                                    \
         }
+#      define LDAPDebug0(level, fmt, arg1, arg2, arg3) \
+        {                                              \
+          if (ldap_debug & level) {                    \
+            slapd_log_error_proc(NULL, fmt);           \
+          }                                            \
+        }
+#      define LDAPDebug1(level, fmt, arg1, arg2, arg3) \
+        {                                              \
+          if (ldap_debug & level) {                    \
+            slapd_log_error_proc(NULL, fmt, arg1);     \
+          }                                            \
+        }
+#      define LDAPDebug2(level, fmt, arg1, arg2, arg3)   \
+        {                                                \
+          if (ldap_debug & level) {                      \
+            slapd_log_error_proc(NULL, fmt, arg1, arg2); \
+          }                                              \
+        }
+#      define LDAPDebug3(level, fmt, arg1, arg2, arg3)         \
+        {                                                      \
+          if (ldap_debug & level) {                            \
+            slapd_log_error_proc(NULL, fmt, arg1, arg2, arg3); \
+          }                                                    \
+        }
 #    endif /* Win32 */
 #  else    /* no SLAPD_LOGGING */
 extern void ber_err_print(char*);
 extern int ldap_debug;
 #    define LDAPDebug(level, fmt, arg1, arg2, arg3)        \
       if (ldap_debug & level) {                            \
         char msg[1024];                                    \
         snprintf(msg, sizeof(msg), fmt, arg1, arg2, arg3); \
         msg[sizeof(msg) - 1] = '\0';                       \
         ber_err_print(msg);                                \
       }
+#    define LDAPDebug0(level, fmt, arg1, arg2, arg3) \
+      if (ldap_debug & level) {                      \
+        char msg[1024];                              \
+        snprintf(msg, sizeof(msg), fmt);             \
+        msg[sizeof(msg) - 1] = '\0';                 \
+        ber_err_print(msg);                          \
+      }
+#    define LDAPDebug1(level, fmt, arg1, arg2, arg3) \
+      if (ldap_debug & level) {                      \
+        char msg[1024];                              \
+        snprintf(msg, sizeof(msg), fmt, arg1);       \
+        msg[sizeof(msg) - 1] = '\0';                 \
+        ber_err_print(msg);                          \
+      }
+#    define LDAPDebug2(level, fmt, arg1, arg2, arg3) \
+      if (ldap_debug & level) {                      \
+        char msg[1024];                              \
+        snprintf(msg, sizeof(msg), fmt, arg1, arg2); \
+        msg[sizeof(msg) - 1] = '\0';                 \
+        ber_err_print(msg);                          \
+      }
+#    define LDAPDebug3(level, fmt, arg1, arg2, arg3)       \
+      if (ldap_debug & level) {                            \
+        char msg[1024];                                    \
+        snprintf(msg, sizeof(msg), fmt, arg1, arg2, arg3); \
+        msg[sizeof(msg) - 1] = '\0';                       \
+        ber_err_print(msg);                                \
+      }
 #  endif /* SLAPD_LOGGING */
 #endif   /* LDAP_DEBUG */
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* _LDAP_H */
--- a/ldap/c-sdk/libraries/libldap/abandon.c
+++ b/ldap/c-sdk/libraries/libldap/abandon.c
@@ -63,36 +63,36 @@ static int nsldapi_send_abandon_message(
  * msgid  The message id of the operation to abandon
  *
  * ldap_abandon returns 0 if everything went ok, -1 otherwise.
  *
  * Example:
  * ldap_abandon(ld, msgid);
  */
 int LDAP_CALL ldap_abandon(LDAP *ld, int msgid) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0);
-  LDAPDebug(LDAP_DEBUG_TRACE, "4e65747363617065\n", msgid, 0, 0);
-  LDAPDebug(LDAP_DEBUG_TRACE, "466f726576657221\n", msgid, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "4e65747363617065\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "466f726576657221\n", 0, 0, 0);
 
   if (ldap_abandon_ext(ld, msgid, NULL, NULL) == LDAP_SUCCESS) {
     return (0);
   }
 
   return (-1);
 }
 
 /*
  * LDAPv3 extended abandon.
  * Returns an LDAP error code.
  */
 int LDAP_CALL ldap_abandon_ext(LDAP *ld, int msgid, LDAPControl **serverctrls,
                                LDAPControl **clientctrls) {
   int rc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   LDAP_MUTEX_LOCK(ld, LDAP_CONN_LOCK);
   LDAP_MUTEX_LOCK(ld, LDAP_REQ_LOCK);
   rc = do_abandon(ld, msgid, msgid, serverctrls, clientctrls);
@@ -119,18 +119,18 @@ static int do_abandon(LDAP *ld, int orig
   BerElement *ber;
   int i, bererr, lderr, sendabandon;
   LDAPRequest *lr = NULL;
 
   /*
    * An abandon request looks like this:
    * AbandonRequest ::= MessageID
    */
-  LDAPDebug(LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n", origid, msgid,
-            0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n", origid,
+             msgid, 0);
 
   /* optimistic */
   lderr = LDAP_SUCCESS;
 
   /*
    * Find the request that we are abandoning.  Don't send an
    * abandon message unless there is something to abandon.
    */
--- a/ldap/c-sdk/libraries/libldap/add.c
+++ b/ldap/c-sdk/libraries/libldap/add.c
@@ -67,17 +67,17 @@ static char copyright[] = "@(#) Copyrigh
  *     { 0, "objectClass", { "person", 0 } },
  *     0
  *   }
  * msgid = ldap_add(ld, dn, attrs);
  */
 int LDAP_CALL ldap_add(LDAP *ld, const char *dn, LDAPMod **attrs) {
   int msgid;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_add\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_add\n", 0, 0, 0);
 
   if (ldap_add_ext(ld, dn, attrs, NULL, NULL, &msgid) == LDAP_SUCCESS) {
     return (msgid);
   } else {
     return (-1); /* error is in ld handle */
   }
 }
 
@@ -97,17 +97,17 @@ int LDAP_CALL ldap_add_ext(LDAP *ld, con
    *   entry DistinguishedName,
    *   attrs SEQUENCE OF SEQUENCE {
    *     type AttributeType,
    *     values SET OF AttributeValue
    *   }
    * }
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_add_ext\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_add_ext\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if (!NSLDAPI_VALID_LDAPMESSAGE_POINTER(msgidp)) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (LDAP_PARAM_ERROR);
--- a/ldap/c-sdk/libraries/libldap/bind.c
+++ b/ldap/c-sdk/libraries/libldap/bind.c
@@ -68,17 +68,17 @@ int LDAP_CALL ldap_bind(LDAP *ld, const 
    *   name DistinguishedName,   -- who
    *   authentication CHOICE {
    *     simple [0] OCTET STRING -- passwd
    *   }
    * }
    * all wrapped up in an LDAPMessage sequence.
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_bind\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (-1);
   }
 
   switch (authmethod) {
     case LDAP_AUTH_SIMPLE:
       return (ldap_simple_bind(ld, dn, passwd));
@@ -102,17 +102,17 @@ int LDAP_CALL ldap_bind(LDAP *ld, const 
  *             "secret", LDAP_AUTH_SIMPLE)
  * ldap_bind_s(ld, "cn=manager, o=university of michigan, c=us",
  *             NULL, LDAP_AUTH_KRBV4)
  */
 int LDAP_CALL ldap_bind_s(LDAP *ld, const char *dn, const char *passwd,
                           int authmethod) {
   int err;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_bind_s\n", 0, 0, 0);
 
   switch (authmethod) {
     case LDAP_AUTH_SIMPLE:
       return (ldap_simple_bind_s(ld, dn, passwd));
 
     default:
       err = LDAP_AUTH_UNKNOWN;
       LDAP_SET_LDERRNO(ld, err, NULL, NULL);
--- a/ldap/c-sdk/libraries/libldap/cache.c
+++ b/ldap/c-sdk/libraries/libldap/cache.c
@@ -73,21 +73,21 @@ void nsldapi_add_result_to_cache(LDAP *l
   LDAPMod **mods;
   int i, max, rc;
   char *a;
   BerElement *ber;
   char buf[50];
   struct berval bv;
   struct berval *bvp[2];
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "=> nsldapi_add_result_to_cache id %d type %d\n",
-            m->lm_msgid, m->lm_msgtype, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "=> nsldapi_add_result_to_cache id %d type %d\n",
+             m->lm_msgid, m->lm_msgtype, 0);
   if (m->lm_msgtype != LDAP_RES_SEARCH_ENTRY || ld->ld_cache_add == NULL) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "<= nsldapi_add_result_to_cache not added\n", 0,
-              0, 0);
+    LDAPDebug0(LDAP_DEBUG_TRACE, "<= nsldapi_add_result_to_cache not added\n",
+               0, 0, 0);
     return;
   }
 
 #define GRABSIZE 5
 
   dn = ldap_get_dn(ld, m);
   mods = (LDAPMod **)NSLDAPI_MALLOC(GRABSIZE * sizeof(LDAPMod *));
   max = GRABSIZE;
@@ -102,20 +102,20 @@ void nsldapi_add_result_to_cache(LDAP *l
     mods[i]->mod_op = LDAP_MOD_BVALUES;
     mods[i]->mod_type = a;
     mods[i]->mod_bvalues = ldap_get_values_len(ld, m, a);
   }
   if (ber != NULL) {
     ber_free(ber, 0);
   }
   if ((rc = LDAP_GET_LDERRNO(ld, NULL, NULL)) != LDAP_SUCCESS) {
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "<= nsldapi_add_result_to_cache error: failed to construct mod "
-              "list (%s)\n",
-              ldap_err2string(rc), 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "<= nsldapi_add_result_to_cache error: failed to construct mod "
+               "list (%s)\n",
+               ldap_err2string(rc), 0, 0);
     ldap_mods_free(mods, 1);
     return;
   }
 
   /* update special cachedtime attribute */
   if (i == (max - 1)) {
     max++;
     mods = (LDAPMod **)NSLDAPI_REALLOC(mods, sizeof(LDAPMod *) * max);
@@ -128,11 +128,11 @@ void nsldapi_add_result_to_cache(LDAP *l
   bv.bv_len = strlen(buf);
   bvp[0] = &bv;
   bvp[1] = NULL;
   mods[i]->mod_bvalues = bvp;
   mods[++i] = NULL;
 
   /* msgid of -1 means don't send the result */
   rc = (ld->ld_cache_add)(ld, -1, m->lm_msgtype, dn, mods);
-  LDAPDebug(LDAP_DEBUG_TRACE, "<= nsldapi_add_result_to_cache added (rc %d)\n",
-            rc, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "<= nsldapi_add_result_to_cache added (rc %d)\n",
+             rc, 0, 0);
 }
--- a/ldap/c-sdk/libraries/libldap/charset.c
+++ b/ldap/c-sdk/libraries/libldap/charset.c
@@ -880,18 +880,18 @@ static Byte *c_to_cc(Byte *o, Couple *cc
 
 int ldap_t61_to_8859(char **bufp, unsigned long *buflenp, int free_input) {
   Byte *s, *oo, *o;
   unsigned int n;
   int c;
   unsigned long len;
   Couple *cc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_t61_to_8859 input length: %ld\n", *buflenp,
-            0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_t61_to_8859 input length: %ld\n", *buflenp,
+             0, 0);
 
   len = *buflenp;
   s = (Byte *)*bufp;
 
   if ((o = oo = (Byte *)NSLDAPI_MALLOC(2 * len + 64)) == NULL) {
     return (1);
   }
 
@@ -1735,18 +1735,18 @@ static Byte *cc_to_t61(Byte *o, Byte *s)
 /* --- routine to convert from ISO 8859-n to T.61 --- */
 
 int ldap_8859_to_t61(char **bufp, unsigned long *buflenp, int free_input) {
   Byte *s, *oo, *o, *aux;
   int c;
   unsigned long len;
   Couple *cc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_8859_to_t61 input length: %ld\n", *buflenp,
-            0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_8859_to_t61 input length: %ld\n", *buflenp,
+             0, 0);
 
   len = *buflenp;
   s = (Byte *)*bufp;
 
   if ((o = oo = (Byte *)NSLDAPI_MALLOC(2 * len + 64)) == NULL) {
     return (1);
   }
 
--- a/ldap/c-sdk/libraries/libldap/cldap.c
+++ b/ldap/c-sdk/libraries/libldap/cldap.c
@@ -115,17 +115,17 @@ LDAP *cldap_open(char *host, int port) {
   int s;
   ldap_x_in_addr_t address;
   struct sockaddr_in sock;
   struct hostent *hp;
   LDAP *ld;
   char *p;
   int i;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "cldap_open\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "cldap_open\n", 0, 0, 0);
 
   if (port == 0) {
     port = LDAP_PORT;
   }
 
   if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
     return (NULL);
   }
@@ -214,17 +214,17 @@ LDAP *cldap_open(char *host, int port) {
   }
 
   ld->ld_sbp->sb_useaddr = ld->ld_sbp->sb_addrs[0];
   cldap_setretryinfo(ld, 0, 0);
 
 #  ifdef LDAP_DEBUG
   putchar('\n');
   for (i = 0; i < ld->ld_sbp->sb_naddr; ++i) {
-    LDAPDebug(
+    LDAPDebug2(
         LDAP_DEBUG_TRACE, "end of cldap_open address %d is %s\n", i,
         inet_ntoa(((struct sockaddr_in *)ld->ld_sbp->sb_addrs[i])->sin_addr),
         0);
   }
 #  endif
 
   return (ld);
 }
@@ -252,27 +252,27 @@ int cldap_search_s(LDAP *ld, char *base,
   }
 
   do {
     if (cri.cri_try != 0) {
       --ld->ld_msgid; /* use same id as before */
     }
     ld->ld_sbp->sb_useaddr = ld->ld_sbp->sb_addrs[cri.cri_useaddr];
 
-    LDAPDebug(
+    LDAPDebug2(
         LDAP_DEBUG_TRACE, "cldap_search_s try %d (to %s)\n", cri.cri_try,
         inet_ntoa(((struct sockaddr_in *)ld->ld_sbp->sb_useaddr)->sin_addr), 0);
 
     if ((msgid = ldap_search(ld, base, scope, filter, attrs, attrsonly)) ==
         -1) {
       return (LDAP_GET_LDERRNO(ld, NULL, NULL));
     }
 #  ifndef NO_CACHE
     if (ld->ld_cache != NULL && ld->ld_responses != NULL) {
-      LDAPDebug(LDAP_DEBUG_TRACE, "cldap_search_s res from cache\n", 0, 0, 0);
+      LDAPDebug0(LDAP_DEBUG_TRACE, "cldap_search_s res from cache\n", 0, 0, 0);
       *res = ld->ld_responses;
       ld->ld_responses = ld->ld_responses->lm_next;
       return (ldap_result2error(ld, *res, 0));
     }
 #  endif /* NO_CACHE */
     ret = cldap_result(ld, msgid, res, &cri, base);
   } while (ret == -1);
 
@@ -318,36 +318,36 @@ static int cldap_result(LDAP *ld, int ms
   struct timeval tv;
 
   fromaddr = -1;
 
   if (crip->cri_try == 0) {
     crip->cri_maxtries = ld->ld_cldaptries * sb->sb_naddr;
     crip->cri_timeout = ld->ld_cldaptimeout;
     crip->cri_useaddr = 0;
-    LDAPDebug(LDAP_DEBUG_TRACE, "cldap_result tries %d timeout %d\n",
-              ld->ld_cldaptries, ld->ld_cldaptimeout, 0);
+    LDAPDebug2(LDAP_DEBUG_TRACE, "cldap_result tries %d timeout %d\n",
+               ld->ld_cldaptries, ld->ld_cldaptimeout, 0);
   }
 
   if ((tv.tv_sec = crip->cri_timeout / sb->sb_naddr) < 1) {
     tv.tv_sec = 1;
   }
   tv.tv_usec = 0;
 
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "cldap_result waiting up to %d seconds for a response\n", tv.tv_sec,
-            0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE,
+             "cldap_result waiting up to %d seconds for a response\n",
+             tv.tv_sec, 0, 0);
   ber_init_w_nullchar(&ber, 0);
   nsldapi_set_ber_options(ld, &ber);
 
   if (cldap_getmsg(ld, &tv, &ber) == -1) {
     ret = LDAP_GET_LDERRNO(ld, NULL, NULL);
-    LDAPDebug(LDAP_DEBUG_TRACE, "cldap_getmsg returned -1 (%d)\n", ret, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE, "cldap_getmsg returned -1 (%d)\n", ret, 0, 0);
   } else if (LDAP_GET_LDERRNO(ld, NULL, NULL) == LDAP_TIMEOUT) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "cldap_result timed out\n", 0, 0, 0);
+    LDAPDebug0(LDAP_DEBUG_TRACE, "cldap_result timed out\n", 0, 0, 0);
     /*
      * It timed out; is it time to give up?
      */
     if (++crip->cri_try >= crip->cri_maxtries) {
       ret = LDAP_TIMEOUT;
       --crip->cri_try;
     } else {
       if (++crip->cri_useaddr >= sb->sb_naddr) {
@@ -366,39 +366,39 @@ static int cldap_result(LDAP *ld, int ms
      * Got a response.  It should look like:
      * { msgid, logdn, { searchresponse...}}
      */
     logdn = NULL;
 
     if (ber_scanf(&ber, "ia", &id, &logdn) == LBER_ERROR) {
       NSLDAPI_FREE(ber.ber_buf); /* gack! */
       ret = LDAP_DECODING_ERROR;
-      LDAPDebug(LDAP_DEBUG_TRACE,
-                "cldap_result: ber_scanf returned LBER_ERROR (%d)\n", ret, 0,
-                0);
+      LDAPDebug1(LDAP_DEBUG_TRACE,
+                 "cldap_result: ber_scanf returned LBER_ERROR (%d)\n", ret, 0,
+                 0);
     } else if (id != msgid) {
       NSLDAPI_FREE(ber.ber_buf); /* gack! */
-      LDAPDebug(LDAP_DEBUG_TRACE,
-                "cldap_result: looking for msgid %d; got %ld\n", msgid, id, 0);
+      LDAPDebug2(LDAP_DEBUG_TRACE,
+                 "cldap_result: looking for msgid %d; got %ld\n", msgid, id, 0);
       ret = -1; /* ignore and keep looking */
     } else {
       /*
        * got a result: determine which server it came from
        * decode into ldap message chain
        */
       for (fromaddr = 0; fromaddr < sb->sb_naddr; ++fromaddr) {
         if (memcmp(&((struct sockaddr_in *)sb->sb_addrs[fromaddr])->sin_addr,
                    &((struct sockaddr_in *)sb->sb_fromaddr)->sin_addr,
                    sizeof(struct in_addr)) == 0) {
           break;
         }
       }
       ret = cldap_parsemsg(ld, msgid, &ber, res, base);
       NSLDAPI_FREE(ber.ber_buf); /* gack! */
-      LDAPDebug(LDAP_DEBUG_TRACE, "cldap_result got result (%d)\n", ret, 0, 0);
+      LDAPDebug1(LDAP_DEBUG_TRACE, "cldap_result got result (%d)\n", ret, 0, 0);
     }
 
     if (logdn != NULL) {
       NSLDAPI_FREE(logdn);
     }
   }
 
   /*
@@ -411,19 +411,19 @@ static int cldap_result(LDAP *ld, int ms
       i = sb->sb_naddr - 1;
     }
 
     for (; i >= 0; --i) {
       if (i == fromaddr) {
         continue;
       }
       sb->sb_useaddr = sb->sb_addrs[i];
-      LDAPDebug(LDAP_DEBUG_TRACE, "cldap_result abandoning id %d (to %s)\n",
-                msgid,
-                inet_ntoa(((struct sockaddr_in *)sb->sb_useaddr)->sin_addr), 0);
+      LDAPDebug2(
+          LDAP_DEBUG_TRACE, "cldap_result abandoning id %d (to %s)\n", msgid,
+          inet_ntoa(((struct sockaddr_in *)sb->sb_useaddr)->sin_addr), 0);
       (void)ldap_abandon(ld, msgid);
     }
   }
 
   LDAP_SET_LDERRNO(ld, ret, NULL, NULL);
   return (ret);
 }
 
@@ -450,35 +450,35 @@ static int cldap_parsemsg(LDAP *ld, int 
     } else if ((rc = nsldapi_alloc_ber_with_options(ld, &ldm->lm_ber)) !=
                LDAP_SUCCESS) {
       break; /* return with error*/
     }
     ldm->lm_msgid = msgid;
     ldm->lm_msgtype = tag;
 
     if (tag == LDAP_RES_SEARCH_RESULT) {
-      LDAPDebug(LDAP_DEBUG_TRACE, "cldap_parsemsg got search result\n", 0, 0,
-                0);
+      LDAPDebug0(LDAP_DEBUG_TRACE, "cldap_parsemsg got search result\n", 0, 0,
+                 0);
 
       if (ber_get_stringal(ber, &bv) == LBER_DEFAULT) {
         break; /* return w/error */
       }
 
       if (ber_printf(ldm->lm_ber, "to", tag, bv->bv_val, bv->bv_len) == -1) {
         break; /* return w/error */
       }
       ber_bvfree(bv);
       bv = NULL;
       rc = LDAP_SUCCESS;
 
     } else if (tag == LDAP_RES_SEARCH_ENTRY) {
       if (ber_scanf(ber, "{aO", &dn, &bv) == LBER_ERROR) {
         break; /* return w/error */
       }
-      LDAPDebug(LDAP_DEBUG_TRACE, "cldap_parsemsg entry %s\n", dn, 0, 0);
+      LDAPDebug1(LDAP_DEBUG_TRACE, "cldap_parsemsg entry %s\n", dn, 0, 0);
       if (dn != NULL && *(dn + (slen = strlen(dn)) - 1) == '*' && baselen > 0) {
         /*
          * substitute original searchbase for trailing '*'
          */
         if ((p = (char *)NSLDAPI_MALLOC(slen + baselen)) == NULL) {
           rc = LDAP_NO_MEMORY;
           NSLDAPI_FREE(dn);
           break; /* return w/error */
@@ -493,18 +493,18 @@ static int cldap_parsemsg(LDAP *ld, int 
           -1) {
         break; /* return w/error */
       }
       NSLDAPI_FREE(dn);
       ber_bvfree(bv);
       bv = NULL;
 
     } else {
-      LDAPDebug(LDAP_DEBUG_TRACE, "cldap_parsemsg got unknown tag %d\n", tag, 0,
-                0);
+      LDAPDebug1(LDAP_DEBUG_TRACE, "cldap_parsemsg got unknown tag %d\n", tag,
+                 0, 0);
       rc = LDAP_PROTOCOL_ERROR;
       break; /* return w/error */
     }
 
     /* Reset message ber so we can read from it later.  Gack! */
     ldm->lm_ber->ber_end = ldm->lm_ber->ber_ptr;
     ldm->lm_ber->ber_ptr = ldm->lm_ber->ber_buf;
 
--- a/ldap/c-sdk/libraries/libldap/compare.c
+++ b/ldap/c-sdk/libraries/libldap/compare.c
@@ -58,17 +58,17 @@ static char copyright[] = "@(#) Copyrigh
  * Example:
  * ldap_compare(ld, "c=us@cn=bob", "userPassword", "secret")
  */
 int LDAP_CALL ldap_compare(LDAP *ld, const char *dn, const char *attr,
                            const char *value) {
   int msgid;
   struct berval bv;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_compare\n", 0, 0, 0);
 
   bv.bv_val = (char *)value;
   bv.bv_len = (value == NULL) ? 0 : strlen(value);
 
   if (ldap_compare_ext(ld, dn, attr, &bv, NULL, NULL, &msgid) == LDAP_SUCCESS) {
     return (msgid);
   } else {
     return (-1); /* error is in ld handle */
@@ -88,17 +88,17 @@ int LDAP_CALL ldap_compare_ext(LDAP *ld,
    *   ava SEQUENCE {
    *     type AttributeType,
    *     value AttributeValue
    *   }
    * }
    * and must be wrapped in an LDAPMessage.
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_compare_ext\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_compare_ext\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
   if (attr == NULL || bvalue == NULL || bvalue->bv_len == 0 || msgidp == NULL) {
     lderr = LDAP_PARAM_ERROR;
     LDAP_SET_LDERRNO(ld, lderr, NULL, NULL);
     return (lderr);
--- a/ldap/c-sdk/libraries/libldap/control.c
+++ b/ldap/c-sdk/libraries/libldap/control.c
@@ -152,46 +152,46 @@ int nsldapi_get_controls(BerElement *ber
    * Controls ::= SEQUENCE OF Control
    *
    * Control ::= SEQUENCE {
    *   controlType LDAPOID,
    *   criticality BOOLEAN DEFAULT FALSE,
    *   controlValue OCTET STRING
    * }
    */
-  LDAPDebug(LDAP_DEBUG_TRACE, "=> nsldapi_get_controls\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "=> nsldapi_get_controls\n", 0, 0, 0);
 
   *controlsp = NULL;
 
   /*
    * check to see if controls were included
    */
   if (ber_get_option(ber, LBER_OPT_REMAINING_BYTES, &len) != 0) {
     return (LDAP_DECODING_ERROR); /* unexpected error */
   }
   if (len == 0) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "<= nsldapi_get_controls no controls\n", 0, 0,
-              0);
+    LDAPDebug0(LDAP_DEBUG_TRACE, "<= nsldapi_get_controls no controls\n", 0, 0,
+               0);
     return (LDAP_SUCCESS); /* no controls */
   }
   if ((tag = ber_peek_tag(ber, &len)) != LDAP_TAG_CONTROLS) {
     if (tag == LBER_ERROR) {
-      LDAPDebug(LDAP_DEBUG_TRACE,
-                "<= nsldapi_get_controls LDAP_PROTOCOL_ERROR\n", 0, 0, 0);
+      LDAPDebug0(LDAP_DEBUG_TRACE,
+                 "<= nsldapi_get_controls LDAP_PROTOCOL_ERROR\n", 0, 0, 0);
       return (LDAP_DECODING_ERROR); /* decoding error */
     }
     /*
      * We found something other than controls.  This should never
      * happen in LDAPv3, but we don't treat this is a hard error --
      * we just ignore the extra stuff.
      */
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "<= nsldapi_get_controls ignoring unrecognized data in message "
-              "(tag 0x%x)\n",
-              tag, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "<= nsldapi_get_controls ignoring unrecognized data in message "
+               "(tag 0x%x)\n",
+               tag, 0, 0);
     return (LDAP_SUCCESS);
   }
 
   maxcontrols = curcontrols = 0;
   for (tag = ber_first_element(ber, &len, &last);
        tag != LBER_ERROR && tag != LBER_END_OF_SEQORSET;
        tag = ber_next_element(ber, &len, last)) {
     if (curcontrols >= maxcontrols - 1) {
@@ -244,24 +244,25 @@ int nsldapi_get_controls(BerElement *ber
     }
   }
 
   if (tag == LBER_ERROR) {
     rc = LDAP_DECODING_ERROR;
     goto free_and_return;
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "<= nsldapi_get_controls found %d controls\n",
-            curcontrols, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "<= nsldapi_get_controls found %d controls\n",
+             curcontrols, 0, 0);
   return (LDAP_SUCCESS);
 
 free_and_return:;
   ldap_controls_free(*controlsp);
   *controlsp = NULL;
-  LDAPDebug(LDAP_DEBUG_TRACE, "<= nsldapi_get_controls error 0x%x\n", rc, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "<= nsldapi_get_controls error 0x%x\n", rc, 0,
+             0);
   return (rc);
 }
 
 /*
  * Skips forward in a ber to find a control tag, then calls on
  * nsldapi_get_controls() to parse them into an LDAPControl list.
  * Returns an LDAP error code.
  */
--- a/ldap/c-sdk/libraries/libldap/delete.c
+++ b/ldap/c-sdk/libraries/libldap/delete.c
@@ -53,17 +53,17 @@ static char copyright[] = "@(#) Copyrigh
  * dn    DN of the object to delete
  *
  * Example:
  * msgid = ldap_delete(ld, dn);
  */
 int LDAP_CALL ldap_delete(LDAP *ld, const char *dn) {
   int msgid;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0);
 
   if (ldap_delete_ext(ld, dn, NULL, NULL, &msgid) == LDAP_SUCCESS) {
     return (msgid);
   } else {
     return (-1); /* error is in ld handle */
   }
 }
 
@@ -73,17 +73,17 @@ int LDAP_CALL ldap_delete_ext(LDAP *ld, 
   BerElement *ber;
   int rc, lderr;
 
   /*
    * A delete request looks like this:
    * DelRequet ::= DistinguishedName,
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_delete_ext\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_delete_ext\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if (!NSLDAPI_VALID_LDAPMESSAGE_POINTER(msgidp)) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (LDAP_PARAM_ERROR);
--- a/ldap/c-sdk/libraries/libldap/error.c
+++ b/ldap/c-sdk/libraries/libldap/error.c
@@ -109,17 +109,17 @@ static struct ldaperror ldap_errlist[] =
     {LDAP_MORE_RESULTS_TO_RETURN, "More results to return"},
     {LDAP_CLIENT_LOOP, "Client detected loop"},
     {LDAP_REFERRAL_LIMIT_EXCEEDED, "Referral hop limit exceeded"},
     {-1, 0}};
 
 char *LDAP_CALL ldap_err2string(int err) {
   int i;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_err2string\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_err2string\n", 0, 0, 0);
 
   for (i = 0; ldap_errlist[i].e_code != -1; i++) {
     if (err == ldap_errlist[i].e_code) return (ldap_errlist[i].e_reason);
   }
 
   return ("Unknown error");
 }
 
@@ -135,17 +135,17 @@ static char *nsldapi_safe_strerror(int e
 
 void LDAP_CALL ldap_perror(LDAP *ld, const char *s) {
   int i, err;
   char *matched = NULL;
   char *errmsg = NULL;
   char *separator;
   char msg[1024];
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_perror\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_perror\n", 0, 0, 0);
 
   if (s == NULL) {
     s = separator = "";
   } else {
     separator = ": ";
   }
 
   if (ld == NULL) {
@@ -258,17 +258,17 @@ int LDAP_CALL ldap_parse_result(LDAP *ld
                                 char **matchednp, char **errmsgp,
                                 char ***referralsp, LDAPControl ***serverctrlsp,
                                 int freeit) {
   LDAPMessage *lm;
   int err, errcode;
   char *m, *e;
   m = e = NULL;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_parse_result\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_parse_result\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld) ||
       !NSLDAPI_VALID_LDAPMESSAGE_POINTER(res)) {
     return (LDAP_PARAM_ERROR);
   }
 
   /* skip over entries and references to find next result in this chain */
   for (lm = res; lm != NULL; lm = lm->lm_chain) {
--- a/ldap/c-sdk/libraries/libldap/extendop.c
+++ b/ldap/c-sdk/libraries/libldap/extendop.c
@@ -62,17 +62,17 @@ int LDAP_CALL ldap_extended_operation(LD
    * ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
    *   requestName  LDAPOID,
    *   requestValue  OCTET STRING
    * }
    *
    * all wrapped up in an LDAPMessage sequence.
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_extended_operation\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_extended_operation\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   /* only ldapv3 or higher can do extended operations */
   if (NSLDAPI_LDAP_VERSION(ld) < LDAP_VERSION3) {
     rc = LDAP_NOT_SUPPORTED;
@@ -186,17 +186,17 @@ int LDAP_CALL ldap_parse_extended_result
     struct berval **retdatap,                   /* may be NULL */
     int freeit) {
   struct berelement ber;
   ber_len_t len;
   ber_int_t err;
   char *m, *e, *roid;
   struct berval *rdata;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_parse_extended_result\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_parse_extended_result\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if (!NSLDAPI_VALID_LDAPMESSAGE_EXRESULT_POINTER(res)) {
     return (LDAP_PARAM_ERROR);
   }
--- a/ldap/c-sdk/libraries/libldap/getattr.c
+++ b/ldap/c-sdk/libraries/libldap/getattr.c
@@ -60,17 +60,17 @@ static unsigned long bytes_remaining(Ber
 }
 
 char *LDAP_CALL ldap_first_attribute(LDAP *ld, LDAPMessage *entry,
                                      BerElement **ber) {
   char *attr;
   int err;
   ber_len_t seqlength;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (NULL); /* punt */
   }
 
   if (ber == NULL || !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER(entry)) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (NULL);
@@ -111,17 +111,17 @@ char *LDAP_CALL ldap_first_attribute(LDA
 }
 
 /* ARGSUSED */
 char *LDAP_CALL ldap_next_attribute(LDAP *ld, LDAPMessage *entry,
                                     BerElement *ber) {
   char *attr;
   int err;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (NULL); /* punt */
   }
 
   if (ber == NULL || !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER(entry)) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (NULL);
--- a/ldap/c-sdk/libraries/libldap/getdn.c
+++ b/ldap/c-sdk/libraries/libldap/getdn.c
@@ -49,17 +49,17 @@ static char copyright[] = "@(#) Copyrigh
 #endif
 
 #include "ldap-int.h"
 
 char *LDAP_CALL ldap_get_dn(LDAP *ld, LDAPMessage *entry) {
   char *dn;
   struct berelement tmp;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_get_dn\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_get_dn\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (NULL); /* punt */
   }
 
   if (!NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER(entry)) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (NULL);
@@ -74,17 +74,17 @@ char *LDAP_CALL ldap_get_dn(LDAP *ld, LD
   return (dn);
 }
 
 char *LDAP_CALL ldap_dn2ufn(const char *dn) {
   char *p, *ufn, *r;
   size_t plen;
   int state;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0);
 
   if (dn == NULL) {
     dn = "";
   }
 
   if (ldap_is_dns_dn(dn) || (p = strchr(dn, '=')) == NULL)
     return (nsldapi_strdup((char *)dn));
 
@@ -194,17 +194,17 @@ static char **ldap_explode(const char *d
   size_t plen = 0;
   int state = 0;
   int count = 0;
   int startquote = 0;
   int endquote = 0;
   int len = 0;
   int goteq = 0;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_explode\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_explode\n", 0, 0, 0);
 
   if (dn == NULL) {
     dn = "";
   }
 
 #if 0
   if (ldap_is_dns_dn(dn)) {
     return(ldap_explode_dns(dn));
--- a/ldap/c-sdk/libraries/libldap/getdxbyname.c
+++ b/ldap/c-sdk/libraries/libldap/getdxbyname.c
@@ -94,17 +94,17 @@ extern char *h_errlist[];
  * nsldapi_getdxbyname - lookup DNS DX records for domain and return an ordered
  * array.
  */
 char **nsldapi_getdxbyname(char *domain) {
   unsigned char buf[PACKETSZ];
   char **dxs;
   int rc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_getdxbyname( %s )\n", domain, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "nsldapi_getdxbyname( %s )\n", domain, 0, 0);
 
   memset(buf, 0, sizeof(buf));
 
   /* XXX not MT safe XXX */
   if ((rc = res_search(domain, C_IN, T_TXT, buf, sizeof(buf))) < 0 ||
       (rc > sizeof(buf)) || (dxs = decode_answer(buf, rc)) == NULL) {
     /*
      * punt:  return list consisting of the original domain name only
--- a/ldap/c-sdk/libraries/libldap/getentry.c
+++ b/ldap/c-sdk/libraries/libldap/getentry.c
@@ -92,17 +92,17 @@ int LDAP_CALL ldap_count_entries(LDAP *l
   return (i);
 }
 
 int LDAP_CALL ldap_get_entry_controls(LDAP *ld, LDAPMessage *entry,
                                       LDAPControl ***serverctrlsp) {
   int rc;
   BerElement tmpber;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_get_entry_controls\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_get_entry_controls\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if (!NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER(entry) || serverctrlsp == NULL) {
     rc = LDAP_PARAM_ERROR;
     goto report_error_and_return;
--- a/ldap/c-sdk/libraries/libldap/getvalues.c
+++ b/ldap/c-sdk/libraries/libldap/getvalues.c
@@ -52,17 +52,17 @@ static char copyright[] = "@(#) Copyrigh
 
 static void **internal_ldap_get_values(LDAP *ld, LDAPMessage *entry,
                                        const char *target, int lencall) {
   struct berelement ber;
   char *attr;
   int rc;
   void **vals;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (NULL); /* punt */
   }
   if (target == NULL || !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER(entry)) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (NULL);
   }
@@ -316,17 +316,17 @@ static void **internal_ldap_get_lang_val
   int nsubtypes;
   char *baseTarget = NULL;
   int bestMatch = 0;
   char *lang = NULL;
   int len;
   int firstAttr = 1;
   char *bestType = NULL;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (NULL);
   }
   if ((target == NULL) || !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER(entry)) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (NULL);
   }
--- a/ldap/c-sdk/libraries/libldap/memcache.c
+++ b/ldap/c-sdk/libraries/libldap/memcache.c
@@ -257,17 +257,17 @@ static unsigned long crc32_convert(char 
 
 /* Create a memcache object. */
 int LDAP_CALL ldap_memcache_init(unsigned long ttl, unsigned long size,
                                  char **baseDNs,
                                  struct ldap_thread_fns *thread_fns,
                                  LDAPMemCache **cachep) {
   unsigned long total_size = 0;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_memcache_init\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_memcache_init\n", 0, 0, 0);
 
   if (cachep == NULL) {
     return (LDAP_PARAM_ERROR);
   }
 
   if ((*cachep = (LDAPMemCache *)NSLDAPI_CALLOC(1, sizeof(LDAPMemCache))) ==
       NULL) {
     return (LDAP_NO_MEMORY);
@@ -342,27 +342,27 @@ int LDAP_CALL ldap_memcache_init(unsigne
   /* See if there is enough room so far */
   if (memcache_adj_size(*cachep, total_size, MEMCACHE_SIZE_NON_ENTRIES,
                         MEMCACHE_SIZE_ADD) != LDAP_SUCCESS) {
     ldap_memcache_destroy(*cachep);
     *cachep = NULL;
     return (LDAP_SIZELIMIT_EXCEEDED);
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_memcache_init new cache 0x%p\n", *cachep, 0,
-            0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_memcache_init new cache 0x%p\n", *cachep,
+             0, 0);
 
   return (LDAP_SUCCESS);
 }
 
 /* Associates a ldap handle to a memcache object. */
 int LDAP_CALL ldap_memcache_set(LDAP *ld, LDAPMemCache *cache) {
   int nRes = LDAP_SUCCESS;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_memcache_set\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_memcache_set\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) return (LDAP_PARAM_ERROR);
 
   LDAP_MUTEX_LOCK(ld, LDAP_MEMCACHE_LOCK);
 
   if (ld->ld_memcache != cache) {
     LDAPMemCache *c = ld->ld_memcache;
     ldapmemcacheld *pCur = NULL;
@@ -435,17 +435,17 @@ int LDAP_CALL ldap_memcache_set(LDAP *ld
 
   LDAP_MUTEX_UNLOCK(ld, LDAP_MEMCACHE_LOCK);
 
   return nRes;
 }
 
 /* Retrieves memcache with which the ldap handle has been associated. */
 int LDAP_CALL ldap_memcache_get(LDAP *ld, LDAPMemCache **cachep) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_memcache_get ld: 0x%p\n", ld, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_memcache_get ld: 0x%p\n", ld, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld) || cachep == NULL) {
     return (LDAP_PARAM_ERROR);
   }
 
   LDAP_MUTEX_LOCK(ld, LDAP_MEMCACHE_LOCK);
   *cachep = ld->ld_memcache;
   LDAP_MUTEX_UNLOCK(ld, LDAP_MEMCACHE_LOCK);
@@ -454,54 +454,54 @@ int LDAP_CALL ldap_memcache_get(LDAP *ld
 }
 
 /*
  * Function that stays inside libldap and proactively expires items from
  * the given cache.  This should be called from a newly created thread since
  * it will not return until after ldap_memcache_destroy() is called.
  */
 void LDAP_CALL ldap_memcache_update(LDAPMemCache *cache) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_memcache_update: cache 0x%p\n", cache, 0,
-            0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_memcache_update: cache 0x%p\n", cache, 0,
+             0);
 
   if (!NSLDAPI_VALID_MEMCACHE_POINTER(cache)) {
     return;
   }
 
   LDAP_MEMCACHE_MUTEX_LOCK(cache);
   memcache_access(cache, MEMCACHE_ACCESS_UPDATE, NULL, NULL, NULL);
   LDAP_MEMCACHE_MUTEX_UNLOCK(cache);
 }
 
 /* Removes specified entries from given memcache. Only clears out search
    results that included search entries. */
 void LDAP_CALL ldap_memcache_flush(LDAPMemCache *cache, char *dn, int scope) {
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "ldap_memcache_flush( cache: 0x%p, dn: %s, scope: %d)\n", cache,
-            (dn == NULL) ? "(null)" : dn, scope);
+  LDAPDebug3(LDAP_DEBUG_TRACE,
+             "ldap_memcache_flush( cache: 0x%p, dn: %s, scope: %d)\n", cache,
+             (dn == NULL) ? "(null)" : dn, scope);
   memcache_flush(cache, dn, scope, 0 /* Don't use result flush mode */);
 }
 
 /* Removes specified entries from given memcache, including search
    results that returned no entries. */
 void LDAP_CALL ldap_memcache_flush_results(LDAPMemCache *cache, char *dn,
                                            int scope) {
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "ldap_memcache_flush_results( cache: 0x%p, dn: %s, scope: %d)\n",
-            cache, (dn == NULL) ? "(null)" : dn, scope);
+  LDAPDebug3(LDAP_DEBUG_TRACE,
+             "ldap_memcache_flush_results( cache: 0x%p, dn: %s, scope: %d)\n",
+             cache, (dn == NULL) ? "(null)" : dn, scope);
   memcache_flush(cache, dn, scope, 1 /* Use result flush mode */);
 }
 
 /* Destroys the given memcache. */
 void LDAP_CALL ldap_memcache_destroy(LDAPMemCache *cache) {
   int i = 0;
   unsigned long size = sizeof(LDAPMemCache);
   ldapmemcacheld *pNode = NULL, *pNextNode = NULL;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_memcache_destroy( 0x%p )\n", cache, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_memcache_destroy( 0x%p )\n", cache, 0, 0);
 
   if (!NSLDAPI_VALID_MEMCACHE_POINTER(cache)) {
     return;
   }
 
   /* Dissociate all ldap handes from this cache. */
   LDAP_MEMCACHE_MUTEX_LOCK(cache);
 
@@ -651,19 +651,19 @@ int ldap_memcache_createkey(LDAP *ld, co
 
 /* Searches the cache for the right cached entries, and if found, attaches
    them to the given ldap handle.  This function relies on locking by the
    caller. */
 int ldap_memcache_result(LDAP *ld, int msgid, unsigned long key) {
   int nRes;
   LDAPMessage *pMsg = NULL;
 
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "ldap_memcache_result( ld: 0x%p, msgid: %d, key: 0x%8.8lx)\n", ld,
-            msgid, key);
+  LDAPDebug3(LDAP_DEBUG_TRACE,
+             "ldap_memcache_result( ld: 0x%p, msgid: %d, key: 0x%8.8lx)\n", ld,
+             msgid, key);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld) || (msgid < 0)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if (!memcache_exist(ld)) {
     return (LDAP_LOCAL_ERROR);
   }
@@ -671,22 +671,23 @@ int ldap_memcache_result(LDAP *ld, int m
   LDAP_MUTEX_LOCK(ld, LDAP_MEMCACHE_LOCK);
   LDAP_MEMCACHE_MUTEX_LOCK(ld->ld_memcache);
 
   /* Search the cache and append the results to ld if found */
   ++ld->ld_memcache->ldmemc_stats.ldmemcstat_tries;
   if ((nRes = memcache_search(ld, key, &pMsg)) == LDAP_SUCCESS) {
     nRes = memcache_add_to_ld(ld, msgid, pMsg);
     ++ld->ld_memcache->ldmemc_stats.ldmemcstat_hits;
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "ldap_memcache_result: key 0x%8.8lx found in cache\n", key, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "ldap_memcache_result: key 0x%8.8lx found in cache\n", key, 0,
+               0);
   } else {
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "ldap_memcache_result: key 0x%8.8lx not found in cache\n", key, 0,
-              0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "ldap_memcache_result: key 0x%8.8lx not found in cache\n", key,
+               0, 0);
   }
 
 #ifdef LDAP_DEBUG
   memcache_print_list(ld->ld_memcache, LIST_LRU);
   memcache_report_statistics(ld->ld_memcache);
 #endif /* LDAP_DEBUG */
 
   LDAP_MEMCACHE_MUTEX_UNLOCK(ld->ld_memcache);
@@ -721,19 +722,19 @@ int ldap_memcache_new(LDAP *ld, int msgi
 }
 
 /* Appends a chain of entries to an existing cache header.  Parameter "bLast"
    indicates whether there will be more entries arriving for the search in
    question. */
 int ldap_memcache_append(LDAP *ld, int msgid, int bLast, LDAPMessage *result) {
   int nRes = LDAP_SUCCESS;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_memcache_append( ld: 0x%p, ", ld, 0, 0);
-  LDAPDebug(LDAP_DEBUG_TRACE, "msgid %d, bLast: %d, result: 0x%p)\n", msgid,
-            bLast, result);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_memcache_append( ld: 0x%p, ", ld, 0, 0);
+  LDAPDebug3(LDAP_DEBUG_TRACE, "msgid %d, bLast: %d, result: 0x%p)\n", msgid,
+             bLast, result);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld) || !result) {
     return (LDAP_PARAM_ERROR);
   }
 
   LDAP_MUTEX_LOCK(ld, LDAP_MEMCACHE_LOCK);
 
   if (!memcache_exist(ld)) {
@@ -743,18 +744,18 @@ int ldap_memcache_append(LDAP *ld, int m
 
   LDAP_MEMCACHE_MUTEX_LOCK(ld->ld_memcache);
 
   if (!bLast)
     nRes = memcache_append(ld, msgid, result);
   else
     nRes = memcache_append_last(ld, msgid, result);
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_memcache_append: %s result for msgid %d\n",
-            (nRes == LDAP_SUCCESS) ? "added" : "failed to add", msgid, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "ldap_memcache_append: %s result for msgid %d\n",
+             (nRes == LDAP_SUCCESS) ? "added" : "failed to add", msgid, 0);
 
   LDAP_MEMCACHE_MUTEX_UNLOCK(ld->ld_memcache);
   LDAP_MUTEX_UNLOCK(ld, LDAP_MEMCACHE_LOCK);
 
   return nRes;
 }
 
 /* Removes partially cached results for a search as a result of calling
@@ -877,61 +878,62 @@ static void memcache_append_ctrls(char *
     }
   }
 }
 
 /* Increases or decreases the size (in bytes) the given memcache currently
    uses.  If the size goes over the limit, the function returns an error. */
 static int memcache_adj_size(LDAPMemCache *cache, unsigned long size,
                              int usageFlags, int bAdd) {
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "memcache_adj_size: attempting to %s %ld %s bytes...\n",
-            bAdd ? "add" : "remove", size,
-            (usageFlags & MEMCACHE_SIZE_ENTRIES) ? "entry" : "non-entry");
+  LDAPDebug3(LDAP_DEBUG_TRACE,
+             "memcache_adj_size: attempting to %s %ld %s bytes...\n",
+             bAdd ? "add" : "remove", size,
+             (usageFlags & MEMCACHE_SIZE_ENTRIES) ? "entry" : "non-entry");
 
   if (bAdd) {
     cache->ldmemc_size_used += size;
     if ((cache->ldmemc_size > 0) &&
         (cache->ldmemc_size_used > cache->ldmemc_size)) {
       if (size > cache->ldmemc_size_entries) {
         cache->ldmemc_size_used -= size;
-        LDAPDebug(LDAP_DEBUG_TRACE,
-                  "memcache_adj_size: failed (size > size_entries %ld).\n",
-                  cache->ldmemc_size_entries, 0, 0);
+        LDAPDebug1(LDAP_DEBUG_TRACE,
+                   "memcache_adj_size: failed (size > size_entries %ld).\n",
+                   cache->ldmemc_size_entries, 0, 0);
         return (LDAP_SIZELIMIT_EXCEEDED);
       }
 
       while (cache->ldmemc_size_used > cache->ldmemc_size) {
         if (memcache_access(cache, MEMCACHE_ACCESS_FLUSH_LRU, NULL, NULL,
                             NULL) != LDAP_SUCCESS) {
           cache->ldmemc_size_used -= size;
-          LDAPDebug(LDAP_DEBUG_TRACE,
-                    "memcache_adj_size: failed (LRU flush failed).\n", 0, 0, 0);
+          LDAPDebug0(LDAP_DEBUG_TRACE,
+                     "memcache_adj_size: failed (LRU flush failed).\n", 0, 0,
+                     0);
           return (LDAP_SIZELIMIT_EXCEEDED);
         }
       }
     }
     if (usageFlags & MEMCACHE_SIZE_ENTRIES) cache->ldmemc_size_entries += size;
   } else {
     cache->ldmemc_size_used -= size;
     assert(cache->ldmemc_size_used >= 0);
     if (usageFlags & MEMCACHE_SIZE_ENTRIES) cache->ldmemc_size_entries -= size;
   }
 
 #ifdef LDAP_DEBUG
   if (cache->ldmemc_size == 0) { /* no size limit */
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "memcache_adj_size: succeeded (new size: %ld bytes).\n",
-              cache->ldmemc_size_used, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "memcache_adj_size: succeeded (new size: %ld bytes).\n",
+               cache->ldmemc_size_used, 0, 0);
   } else {
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "memcache_adj_size: succeeded (new size: %ld bytes, "
-              "free space: %ld bytes).\n",
-              cache->ldmemc_size_used,
-              cache->ldmemc_size - cache->ldmemc_size_used, 0);
+    LDAPDebug2(LDAP_DEBUG_TRACE,
+               "memcache_adj_size: succeeded (new size: %ld bytes, "
+               "free space: %ld bytes).\n",
+               cache->ldmemc_size_used,
+               cache->ldmemc_size - cache->ldmemc_size_used, 0);
   }
 #endif /* LDAP_DEBUG */
 
   return (LDAP_SUCCESS);
 }
 
 /* Searches the cache for results for a particular search identified by
    parameter "key", which was generated ldap_memcache_createkey(). */
@@ -1270,25 +1272,25 @@ static void memcache_print_list(LDAPMemC
       break;
     case LIST_TOTAL:
       name = "TOTAL";
       break;
     default:
       name = "unknown";
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "memcache 0x%p %s list:\n", cache, name, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "memcache 0x%p %s list:\n", cache, name, 0);
   for (restmp = cache->ldmemc_resHead[index]; restmp != NULL;
        restmp = restmp->ldmemcr_next[index]) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "    key: 0x%8.8lx, ld: 0x%p, msgid: %d\n",
-              restmp->ldmemcr_crc_key, restmp->ldmemcr_req_id.ldmemcrid_ld,
-              restmp->ldmemcr_req_id.ldmemcrid_msgid);
+    LDAPDebug3(LDAP_DEBUG_TRACE, "    key: 0x%8.8lx, ld: 0x%p, msgid: %d\n",
+               restmp->ldmemcr_crc_key, restmp->ldmemcr_req_id.ldmemcrid_ld,
+               restmp->ldmemcr_req_id.ldmemcrid_msgid);
   }
-  LDAPDebug(LDAP_DEBUG_TRACE, "memcache 0x%p end of %s list.\n", cache, name,
-            0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "memcache 0x%p end of %s list.\n", cache, name,
+             0);
 }
 #endif /* LDAP_DEBUG */
 
 /* Tells whether a cached result has expired. */
 static int memcache_expired(LDAPMemCache *cache, ldapmemcacheRes *pRes,
                             unsigned long curTime) {
   if (!cache->ldmemc_ttl) return 0;
 
@@ -1522,19 +1524,19 @@ static int memcache_access(LDAPMemCache 
     }
   }
   /* Flush least recently used entries from cache */
   else if (mode == MEMCACHE_ACCESS_FLUSH_LRU) {
     ldapmemcacheRes *pRes = cache->ldmemc_resTail[LIST_LRU];
 
     if (pRes == NULL) return LDAP_NO_SUCH_OBJECT;
 
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "memcache_access FLUSH_LRU: removing key 0x%8.8lx\n",
-              pRes->ldmemcr_crc_key, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "memcache_access FLUSH_LRU: removing key 0x%8.8lx\n",
+               pRes->ldmemcr_crc_key, 0, 0);
     nRes = htable_remove(cache->ldmemc_resLookup,
                          (void *)&(pRes->ldmemcr_crc_key), NULL);
     assert(nRes == LDAP_SUCCESS);
     memcache_free_from_list(cache, pRes, LIST_TTL);
     memcache_free_from_list(cache, pRes, LIST_LRU);
     memcache_free_entry(cache, pRes);
   }
   /* Unknown command */
@@ -1573,27 +1575,27 @@ static void memcache_report_statistics(L
   unsigned long hitrate;
 
   if (cache->ldmemc_stats.ldmemcstat_tries == 0) {
     hitrate = 0;
   } else {
     hitrate = (100L * cache->ldmemc_stats.ldmemcstat_hits) /
               cache->ldmemc_stats.ldmemcstat_tries;
   }
-  LDAPDebug(LDAP_DEBUG_STATS, "memcache 0x%p:\n", cache, 0, 0);
-  LDAPDebug(LDAP_DEBUG_STATS, "    tries: %ld  hits: %ld  hitrate: %ld%%\n",
-            cache->ldmemc_stats.ldmemcstat_tries,
-            cache->ldmemc_stats.ldmemcstat_hits, hitrate);
+  LDAPDebug1(LDAP_DEBUG_STATS, "memcache 0x%p:\n", cache, 0, 0);
+  LDAPDebug3(LDAP_DEBUG_STATS, "    tries: %ld  hits: %ld  hitrate: %ld%%\n",
+             cache->ldmemc_stats.ldmemcstat_tries,
+             cache->ldmemc_stats.ldmemcstat_hits, hitrate);
   if (cache->ldmemc_size <= 0) { /* no size limit */
-    LDAPDebug(LDAP_DEBUG_STATS, "    memory bytes used: %ld\n",
-              cache->ldmemc_size_used, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_STATS, "    memory bytes used: %ld\n",
+               cache->ldmemc_size_used, 0, 0);
   } else {
-    LDAPDebug(LDAP_DEBUG_STATS, "    memory bytes used: %ld free: %ld\n",
-              cache->ldmemc_size_used,
-              cache->ldmemc_size - cache->ldmemc_size_used, 0);
+    LDAPDebug2(LDAP_DEBUG_STATS, "    memory bytes used: %ld free: %ld\n",
+               cache->ldmemc_size_used,
+               cache->ldmemc_size - cache->ldmemc_size_used, 0);
   }
 }
 #endif /* LDAP_DEBUG */
 
 /************************ Hash Table Functions *****************************/
 
 /* Calculates size (# of entries) of hash table given the size limit for
    the cache. */
--- a/ldap/c-sdk/libraries/libldap/modify.c
+++ b/ldap/c-sdk/libraries/libldap/modify.c
@@ -65,17 +65,17 @@ static char copyright[] = "@(#) Copyrigh
  *     { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
  *     0
  *   }
  * msgid = ldap_modify(ld, dn, mods);
  */
 int LDAP_CALL ldap_modify(LDAP *ld, const char *dn, LDAPMod **mods) {
   int msgid;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0);
 
   if (ldap_modify_ext(ld, dn, mods, NULL, NULL, &msgid) == LDAP_SUCCESS) {
     return (msgid);
   } else {
     return (-1); /* error is in ld handle */
   }
 }
 
@@ -98,17 +98,17 @@ int LDAP_CALL ldap_modify_ext(LDAP *ld, 
    *     modification  SEQUENCE {
    *       type AttributeType,
    *       values SET OF AttributeValue
    *     }
    *   }
    * }
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
   if (!NSLDAPI_VALID_LDAPMESSAGE_POINTER(msgidp)) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (LDAP_PARAM_ERROR);
   }
--- a/ldap/c-sdk/libraries/libldap/open.c
+++ b/ldap/c-sdk/libraries/libldap/open.c
@@ -468,32 +468,32 @@ int LDAP_CALL ldap_version(LDAPVersion *
  * Example:
  * LDAP  *ld;
  * ld = ldap_open(hostname, port);
  */
 
 LDAP *LDAP_CALL ldap_open(const char *host, int port) {
   LDAP *ld;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_open\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_open\n", 0, 0, 0);
 
   if ((ld = ldap_init(host, port)) == NULL) {
     return (NULL);
   }
 
   LDAP_MUTEX_LOCK(ld, LDAP_CONN_LOCK);
   if (nsldapi_open_ldap_defconn(ld) < 0) {
     LDAP_MUTEX_UNLOCK(ld, LDAP_CONN_LOCK);
     ldap_ld_free(ld, NULL, NULL, 0);
     return (NULL);
   }
 
   LDAP_MUTEX_UNLOCK(ld, LDAP_CONN_LOCK);
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_open successful, ld_host is %s\n",
-            (ld->ld_host == NULL) ? "(null)" : ld->ld_host, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "ldap_open successful, ld_host is %s\n",
+             (ld->ld_host == NULL) ? "(null)" : ld->ld_host, 0, 0);
 
   return (ld);
 }
 
 /*
  * ldap_init - initialize the LDAP library.  A magic cookie to be used for
  * future communication is returned on success, NULL on failure.
  * "defhost" may be a space-separated list of hosts or IP addresses
@@ -509,27 +509,27 @@ LDAP *LDAP_CALL ldap_open(const char *ho
 LDAP *LDAP_CALL ldap_init(const char *defhost, int defport) {
   LDAP *ld;
 
   if (!nsldapi_initialized) {
     nsldapi_initialize_defaults();
   }
 
   if (defport < 0 || defport > LDAP_PORT_MAX) {
-    LDAPDebug(LDAP_DEBUG_ANY,
-              "ldap_init: port %d is invalid (port numbers must range from 1 "
-              "to %d)\n",
-              defport, LDAP_PORT_MAX, 0);
+    LDAPDebug2(LDAP_DEBUG_ANY,
+               "ldap_init: port %d is invalid (port numbers must range from 1 "
+               "to %d)\n",
+               defport, LDAP_PORT_MAX, 0);
 #if !defined(macintosh) && !defined(DOS) && !defined(BEOS)
     errno = EINVAL;
 #endif
     return (NULL);
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0);
 
   if ((ld = (LDAP *)NSLDAPI_MALLOC(sizeof(struct ldap))) == NULL) {
     return (NULL);
   }
 
   /* copy defaults */
   SAFEMEMCPY(ld, &nsldapi_ld_defaults, sizeof(struct ldap));
   if (nsldapi_ld_defaults.ld_io_fns_ptr != NULL) {
--- a/ldap/c-sdk/libraries/libldap/os-ip.c
+++ b/ldap/c-sdk/libraries/libldap/os-ip.c
@@ -283,18 +283,18 @@ static int nsldapi_os_connect_with_to(LB
 #  else
   struct timeval tval;
   fd_set rset, wset;
 #    ifdef _WINDOWS
   fd_set eset;
 #    endif
 #  endif /* NSLDAPI_HAVE_POLL */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_connect_nonblock timeout: %d (msec)\n",
-            msec, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "nsldapi_connect_nonblock timeout: %d (msec)\n",
+             msec, 0, 0);
 
 #  ifdef _WINDOWS
   ioctlsocket(sockfd, FIONBIO, &nonblock);
 #  elif defined(XP_OS2)
   ioctl(sockfd, FIONBIO, &nonblock, sizeof(nonblock));
 #  else
   flags = fcntl(sockfd, F_GETFL, 0);
   fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
@@ -327,21 +327,21 @@ static int nsldapi_os_connect_with_to(LB
   wset = rset;
 
 #    ifdef _WINDOWS
   eset = rset;
 #    endif /* _WINDOWS */
 #  endif   /* NSLDAPI_HAVE_POLL */
 
   if (msec < 0 && msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) {
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "Invalid timeout value detected.."
-              "resetting connect timeout to default value "
-              "(LDAP_X_IO_TIMEOUT_NO_TIMEOUT\n",
-              0, 0, 0);
+    LDAPDebug0(LDAP_DEBUG_TRACE,
+               "Invalid timeout value detected.."
+               "resetting connect timeout to default value "
+               "(LDAP_X_IO_TIMEOUT_NO_TIMEOUT\n",
+               0, 0, 0);
     msec = LDAP_X_IO_TIMEOUT_NO_TIMEOUT;
 #  ifndef NSLDAPI_HAVE_POLL
   } else {
     if (msec != 0) {
       tval.tv_sec = msec / 1000;
       tval.tv_usec = 1000 * (msec % 1000);
     } else {
       tval.tv_sec = 0;
@@ -470,18 +470,18 @@ int nsldapi_connect_to_host(LDAP *ld, So
 /*
  * "defport" must be in host byte order
  * zero is returned upon success, -1 if fatal error, -2 EINPROGRESS
  * if -1 is returned, ld_errno is set
  */
 {
   int s;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_connect_to_host: %s, port: %d\n",
-            NULL == hostlist ? "NULL" : hostlist, defport, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "nsldapi_connect_to_host: %s, port: %d\n",
+             NULL == hostlist ? "NULL" : hostlist, defport, 0);
 
   /*
    * If an extended I/O connect callback has been defined, just use it.
    */
   if (NULL != ld->ld_extconnect_fn) {
     unsigned long connect_opts = 0;
 
     if (ld->ld_options & LDAP_BITOPT_ASYNC) {
@@ -629,17 +629,17 @@ static int nsldapi_try_each_host(LDAP *l
         return (-1);
       }
 
       if (ld->ld_options & LDAP_BITOPT_ASYNC) {
         int iostatus = 1;
 
         err = (*ioctlfn)(s, FIONBIO, &iostatus);
         if (err == -1) {
-          LDAPDebug(LDAP_DEBUG_ANY, "FIONBIO ioctl failed on %d\n", s, 0, 0);
+          LDAPDebug1(LDAP_DEBUG_ANY, "FIONBIO ioctl failed on %d\n", s, 0, 0);
         }
       }
 
       (void)memset((char *)&sin, 0, sizeof(struct sockaddr_in));
       sin.sin_family = AF_INET;
       sin.sin_port = htons((unsigned short)port);
 
       SAFEMEMCPY((char *)&sin.sin_addr.s_addr,
@@ -686,17 +686,17 @@ static int nsldapi_try_each_host(LDAP *l
       } else {
         if (ld->ld_options & LDAP_BITOPT_ASYNC) {
 #  ifdef _WINDOWS
           if (err == -1 && WSAGetLastError() == WSAEWOULDBLOCK)
             LDAP_SET_ERRNO(ld, EWOULDBLOCK);
 #  endif /* _WINDOWS */
           err = LDAP_GET_ERRNO(ld);
           if (NSLDAPI_ERRNO_IO_INPROGRESS(err)) {
-            LDAPDebug(LDAP_DEBUG_TRACE, "connect would block...\n", 0, 0, 0);
+            LDAPDebug0(LDAP_DEBUG_TRACE, "connect would block...\n", 0, 0, 0);
             rc = -2;
             break;
           }
         }
 
 #  ifdef LDAP_DEBUG
         if (ldap_debug & LDAP_DEBUG_TRACE) {
           perror((char *)inet_ntoa(sin.sin_addr));
@@ -715,18 +715,18 @@ static int nsldapi_try_each_host(LDAP *l
 
   if (ldhpbuf_allocd != NULL) {
     NSLDAPI_FREE(ldhpbuf_allocd);
   }
   ldap_memfree(host);
   ldap_x_hostlist_statusfree(status);
 
   if (connected) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "sd %d connected to: %s\n", s,
-              inet_ntoa(sin.sin_addr), 0);
+    LDAPDebug2(LDAP_DEBUG_TRACE, "sd %d connected to: %s\n", s,
+               inet_ntoa(sin.sin_addr), 0);
   }
 
   return (rc == 0 ? s : -1);
 #endif /* NSLDAPI_AVOID_OS_SOCKETS */
 }
 
 void nsldapi_close_connection(LDAP *ld, Sockbuf *sb) {
   if (ld->ld_extclose_fn == NULL) {
@@ -805,19 +805,19 @@ int nsldapi_iostatus_interest_write(LDAP
 
   } else if (iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK) {
     if (nsldapi_add_to_cb_pollfds(sb, &iosp->ios_status.ios_cbinfo,
                                   LDAP_X_POLLOUT)) {
       ++iosp->ios_write_count;
     }
 
   } else {
-    LDAPDebug(LDAP_DEBUG_ANY,
-              "nsldapi_iostatus_interest_write: unknown I/O type %d\n",
-              iosp->ios_type, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_ANY,
+               "nsldapi_iostatus_interest_write: unknown I/O type %d\n",
+               iosp->ios_type, 0, 0);
   }
 
 unlock_and_return:
   LDAP_MUTEX_UNLOCK(ld, LDAP_IOSTATUS_LOCK);
   return (rc);
 }
 
 /*
@@ -856,19 +856,19 @@ int nsldapi_iostatus_interest_read(LDAP 
 #endif   /* NSLDAPI_AVOID_OS_SOCKETS */
 
   } else if (iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK) {
     if (nsldapi_add_to_cb_pollfds(sb, &iosp->ios_status.ios_cbinfo,
                                   LDAP_X_POLLIN)) {
       ++iosp->ios_read_count;
     }
   } else {
-    LDAPDebug(LDAP_DEBUG_ANY,
-              "nsldapi_iostatus_interest_read: unknown I/O type %d\n",
-              iosp->ios_type, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_ANY,
+               "nsldapi_iostatus_interest_read: unknown I/O type %d\n",
+               iosp->ios_type, 0, 0);
   }
 
 unlock_and_return:
   LDAP_MUTEX_UNLOCK(ld, LDAP_IOSTATUS_LOCK);
   return (rc);
 }
 
 /*
@@ -919,19 +919,19 @@ int nsldapi_iostatus_interest_clear(LDAP
                                       LDAP_X_POLLOUT)) {
       --iosp->ios_write_count;
     }
     if (nsldapi_clear_from_cb_pollfds(sb, &iosp->ios_status.ios_cbinfo,
                                       LDAP_X_POLLIN)) {
       --iosp->ios_read_count;
     }
   } else {
-    LDAPDebug(LDAP_DEBUG_ANY,
-              "nsldapi_iostatus_interest_clear: unknown I/O type %d\n",
-              iosp->ios_type, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_ANY,
+               "nsldapi_iostatus_interest_clear: unknown I/O type %d\n",
+               iosp->ios_type, 0, 0);
   }
 
 unlock_and_return:
   LDAP_MUTEX_UNLOCK(ld, LDAP_IOSTATUS_LOCK);
   return (rc);
 }
 
 /*
@@ -968,19 +968,19 @@ int nsldapi_iostatus_is_write_ready(LDAP
 #  endif /* else NSLDAPI_HAVE_POLL */
 #endif   /* NSLDAPI_AVOID_OS_SOCKETS */
 
   } else if (iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK) {
     rc = nsldapi_find_in_cb_pollfds(sb, &iosp->ios_status.ios_cbinfo,
                                     ~LDAP_X_POLLIN);
 
   } else {
-    LDAPDebug(LDAP_DEBUG_ANY,
-              "nsldapi_iostatus_is_write_ready: unknown I/O type %d\n",
-              iosp->ios_type, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_ANY,
+               "nsldapi_iostatus_is_write_ready: unknown I/O type %d\n",
+               iosp->ios_type, 0, 0);
     rc = 0;
   }
 
 unlock_and_return:
   LDAP_MUTEX_UNLOCK(ld, LDAP_IOSTATUS_LOCK);
   return (rc);
 }
 
@@ -1018,19 +1018,19 @@ int nsldapi_iostatus_is_read_ready(LDAP 
 #  endif /* else NSLDAPI_HAVE_POLL */
 #endif   /* NSLDAPI_AVOID_OS_SOCKETS */
 
   } else if (iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK) {
     rc = nsldapi_find_in_cb_pollfds(sb, &iosp->ios_status.ios_cbinfo,
                                     ~LDAP_X_POLLOUT);
 
   } else {
-    LDAPDebug(LDAP_DEBUG_ANY,
-              "nsldapi_iostatus_is_read_ready: unknown I/O type %d\n",
-              iosp->ios_type, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_ANY,
+               "nsldapi_iostatus_is_read_ready: unknown I/O type %d\n",
+               iosp->ios_type, 0, 0);
     rc = 0;
   }
 
 unlock_and_return:
   LDAP_MUTEX_UNLOCK(ld, LDAP_IOSTATUS_LOCK);
   return (rc);
 }
 
@@ -1095,18 +1095,18 @@ void nsldapi_iostatus_free(LDAP *ld) {
       }
 #endif /* NSLDAPI_HAVE_POLL */
 
     } else if (iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK) {
       if (iosp->ios_status.ios_cbinfo.cbsi_pollfds != NULL) {
         NSLDAPI_FREE(iosp->ios_status.ios_cbinfo.cbsi_pollfds);
       }
     } else {
-      LDAPDebug(LDAP_DEBUG_ANY, "nsldapi_iostatus_free: unknown I/O type %d\n",
-                iosp->ios_type, 0, 0);
+      LDAPDebug1(LDAP_DEBUG_ANY, "nsldapi_iostatus_free: unknown I/O type %d\n",
+                 iosp->ios_type, 0, 0);
     }
 
     NSLDAPI_FREE(iosp);
   }
 }
 
 #if !defined(NSLDAPI_HAVE_POLL) && !defined(NSLDAPI_AVOID_OS_SOCKETS)
 static int nsldapi_get_select_table_size(void) {
@@ -1142,17 +1142,17 @@ static int nsldapi_tv2ms(struct timeval 
 
   return (tv->tv_sec * 1000 + tv->tv_usec / 1000);
 }
 
 int nsldapi_iostatus_poll(LDAP *ld, struct timeval *timeout) {
   int rc;
   NSLDAPIIOStatus *iosp;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_iostatus_poll\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_iostatus_poll\n", 0, 0, 0);
 
   LDAP_MUTEX_LOCK(ld, LDAP_IOSTATUS_LOCK);
   iosp = ld->ld_iostatus;
 
   if (iosp == NULL ||
       (iosp->ios_read_count <= 0 && iosp->ios_write_count <= 0)) {
     rc = 0; /* simulate a timeout */
 
@@ -1192,18 +1192,18 @@ int nsldapi_iostatus_poll(LDAP *ld, stru
      * We always pass the session extended I/O argument to
      * the extended poll() callback.
      */
     rc = ld->ld_extpoll_fn(iosp->ios_status.ios_cbinfo.cbsi_pollfds,
                            iosp->ios_status.ios_cbinfo.cbsi_pollfds_size,
                            nsldapi_tv2ms(timeout), ld->ld_ext_session_arg);
 
   } else {
-    LDAPDebug(LDAP_DEBUG_ANY, "nsldapi_iostatus_poll: unknown I/O type %d\n",
-              iosp->ios_type, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_ANY, "nsldapi_iostatus_poll: unknown I/O type %d\n",
+               iosp->ios_type, 0, 0);
     rc = 0; /* simulate a timeout (what else to do?) */
   }
 
   LDAP_MUTEX_UNLOCK(ld, LDAP_IOSTATUS_LOCK);
   return (rc);
 }
 
 #if defined(NSLDAPI_HAVE_POLL) && !defined(NSLDAPI_AVOID_OS_SOCKETS)
--- a/ldap/c-sdk/libraries/libldap/rename.c
+++ b/ldap/c-sdk/libraries/libldap/rename.c
@@ -83,17 +83,17 @@ ldap_rename(LDAP *ld, const char *dn, co
    * ModifyDNRequest ::= SEQUENCE {
    *   entry  LDAPDN,
    *   newrdn  RelativeLDAPDN,
    *   newparent [0] LDAPDN OPTIONAL,
    *   deleteoldrdn  BOOLEAN
    * }
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_rename\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_rename\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
   if (NULL == newrdn) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (LDAP_PARAM_ERROR);
   }
--- a/ldap/c-sdk/libraries/libldap/request.c
+++ b/ldap/c-sdk/libraries/libldap/request.c
@@ -92,17 +92,17 @@ void nsldapi_set_ber_options(LDAP *ld, B
 #endif /* STR_TRANSLATION */
 }
 
 /* returns the message id of the request or -1 if an error occurs */
 int nsldapi_send_initial_request(LDAP *ld, int msgid, unsigned long msgtype,
                                  char *dn, BerElement *ber) {
   LDAPServer *servers;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_send_initial_request\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_send_initial_request\n", 0, 0, 0);
 
 #ifdef LDAP_DNS
   LDAP_MUTEX_LOCK(ld, LDAP_OPTION_LOCK);
   if ((ld->ld_options & LDAP_BITOPT_DNS) != 0 && ldap_is_dns_dn(dn)) {
     if ((servers = dn2servers(ld, dn)) == NULL) {
       ber_free(ber, 1);
       LDAP_MUTEX_UNLOCK(ld, LDAP_OPTION_LOCK);
       return (-1);
@@ -155,17 +155,17 @@ int nsldapi_send_server_request(
   /* EPIPE and Unsolicited Response handling variables */
   int res_rc = 0;
   int epipe_err = 0;
   int ext_res_rc = 0;
   char *ext_oid = NULL;
   struct berval *ext_data = NULL;
   LDAPMessage *ext_res = NULL;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_send_server_request\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_send_server_request\n", 0, 0, 0);
 
   incparent = 0;
   LDAP_MUTEX_LOCK(ld, LDAP_CONN_LOCK);
   if (lc == NULL) {
     if (srvlist == NULL) {
       if (ld->ld_defconn == NULL) {
         LDAP_MUTEX_LOCK(ld, LDAP_OPTION_LOCK);
         if (bindreqdn == NULL &&
@@ -274,20 +274,20 @@ int nsldapi_send_server_request(
 
   /*
    * If the connect is pending, check to see if it has now completed.
    */
   if (lc->lconn_status == LDAP_CONNST_CONNECTING &&
       nsldapi_iostatus_is_write_ready(ld, lc->lconn_sb)) {
     lc->lconn_status = LDAP_CONNST_CONNECTED;
 
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "nsldapi_send_server_request: connection 0x%p -"
-              " LDAP_CONNST_CONNECTING -> LDAP_CONNST_CONNECTED\n",
-              lc, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "nsldapi_send_server_request: connection 0x%p -"
+               " LDAP_CONNST_CONNECTING -> LDAP_CONNST_CONNECTED\n",
+               lc, 0, 0);
   }
 
   if (lc->lconn_status == LDAP_CONNST_CONNECTING ||
       lc->lconn_pending_requests > 0) {
     /*
      * The connect is not yet complete, or there are existing
      * requests that have not yet been sent to the server.
      * Delay sending this request.
@@ -328,40 +328,40 @@ int nsldapi_send_server_request(
               ldap_parse_extended_result(ld, ext_res, &ext_oid, &ext_data, 0);
           if (ext_res_rc != LDAP_SUCCESS) {
             if (ext_res) {
               ldap_msgfree(ext_res);
             }
             nsldapi_connection_lost_nolock(ld, lc->lconn_sb);
           } else {
 #ifdef LDAP_DEBUG
-            LDAPDebug(LDAP_DEBUG_TRACE,
-                      "nsldapi_send_server_request: Unsolicited response\n", 0,
-                      0, 0);
+            LDAPDebug0(LDAP_DEBUG_TRACE,
+                       "nsldapi_send_server_request: Unsolicited response\n", 0,
+                       0, 0);
             if (ext_oid) {
-              LDAPDebug(
+              LDAPDebug1(
                   LDAP_DEBUG_TRACE,
                   "nsldapi_send_server_request: Unsolicited response oid: %s\n",
                   ext_oid, 0, 0);
             }
             if (ext_data && ext_data->bv_len && ext_data->bv_val) {
-              LDAPDebug(
+              LDAPDebug1(
                   LDAP_DEBUG_TRACE,
                   "nsldapi_send_server_request: Unsolicited response len: %d\n",
                   ext_data->bv_len, 0, 0);
-              LDAPDebug(
+              LDAPDebug1(
                   LDAP_DEBUG_TRACE,
                   "nsldapi_send_server_request: Unsolicited response val: %s\n",
                   ext_data->bv_val, 0, 0);
             }
             if (!ext_oid && !ext_data) {
-              LDAPDebug(LDAP_DEBUG_TRACE,
-                        "nsldapi_send_server_request: Unsolicited response is "
-                        "empty\n",
-                        0, 0, 0);
+              LDAPDebug0(LDAP_DEBUG_TRACE,
+                         "nsldapi_send_server_request: Unsolicited response is "
+                         "empty\n",
+                         0, 0, 0);
             }
 #endif /* LDAP_DEBUG */
             if (ext_oid) {
               if (strcmp(ext_oid, LDAP_NOTICE_OF_DISCONNECTION) == 0) {
                 if (ext_data) {
                   ber_bvfree(ext_data);
                 }
                 if (ext_oid) {
@@ -482,59 +482,59 @@ int nsldapi_send_ber_message(LDAP *ld, S
  */
 int nsldapi_send_pending_requests_nolock(LDAP *ld, LDAPConn *lc) {
   int err;
   int waiting_for_a_response = 0;
   int rc = 0;
   LDAPRequest *lr;
   char *logname = "nsldapi_send_pending_requests_nolock";
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "%s\n", logname, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "%s\n", logname, 0, 0);
 
   for (lr = ld->ld_requests; lr != NULL; lr = lr->lr_next) {
     /*
      * This code relies on the fact that the ld_requests list
      * is in order from oldest to newest request (the oldest
      * requests that have not yet been sent to the server are
      * sent first).
      */
     if (lr->lr_status == LDAP_REQST_WRITING && lr->lr_conn == lc) {
       err = nsldapi_send_ber_message(ld, lc->lconn_sb, lr->lr_ber,
                                      0 /* do not free ber */,
                                      0 /* will not handle EPIPE */);
       if (err == 0) { /* send succeeded */
-        LDAPDebug(LDAP_DEBUG_TRACE, "%s: 0x%p SENT\n", logname, lr, 0);
+        LDAPDebug2(LDAP_DEBUG_TRACE, "%s: 0x%p SENT\n", logname, lr, 0);
         lr->lr_ber->ber_end = lr->lr_ber->ber_ptr;
         lr->lr_ber->ber_ptr = lr->lr_ber->ber_buf;
         lr->lr_status = LDAP_REQST_INPROGRESS;
         --lc->lconn_pending_requests;
       } else if (err == -2) { /* would block */
         rc = 0;               /* not an error */
-        LDAPDebug(LDAP_DEBUG_TRACE, "%s: 0x%p WOULD BLOCK\n", logname, lr, 0);
+        LDAPDebug2(LDAP_DEBUG_TRACE, "%s: 0x%p WOULD BLOCK\n", logname, lr, 0);
         break;
       } else { /* fatal error */
-        LDAPDebug(LDAP_DEBUG_TRACE, "%s: 0x%p FATAL ERROR\n", logname, lr, 0);
+        LDAPDebug2(LDAP_DEBUG_TRACE, "%s: 0x%p FATAL ERROR\n", logname, lr, 0);
         LDAP_SET_LDERRNO(ld, LDAP_SERVER_DOWN, NULL, NULL);
         nsldapi_free_request(ld, lr, 0);
         lr = NULL;
         nsldapi_free_connection(ld, lc, NULL, NULL, 0, 0);
         lc = NULL;
         rc = -1;
         break;
       }
     }
 
     if (lr->lr_status == LDAP_REQST_INPROGRESS) {
       if (lr->lr_expect_resp) {
         ++waiting_for_a_response;
       } else {
-        LDAPDebug(LDAP_DEBUG_TRACE,
-                  "%s: 0x%p NO RESPONSE EXPECTED;"
-                  " freeing request \n",
-                  logname, lr, 0);
+        LDAPDebug2(LDAP_DEBUG_TRACE,
+                   "%s: 0x%p NO RESPONSE EXPECTED;"
+                   " freeing request \n",
+                   logname, lr, 0);
         nsldapi_free_request(ld, lr, 0);
         lr = NULL;
       }
     }
   }
 
   if (lc != NULL) {
     if (lc->lconn_pending_requests < 1) {
@@ -543,17 +543,17 @@ int nsldapi_send_pending_requests_nolock
     }
 
     if (waiting_for_a_response) {
       /* need to poll for "read ready" */
       nsldapi_iostatus_interest_read(ld, lc->lconn_sb);
     }
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "%s <- %d\n", logname, rc, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "%s <- %d\n", logname, rc, 0);
   return (rc);
 }
 
 LDAPConn *nsldapi_new_connection(LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
                                  int connect, int bind) {
   int rc = -1;
   LDAPConn *lc;
   LDAPServer *prevsrv, *srv;
@@ -744,17 +744,17 @@ static LDAPConn *find_connection(LDAP *l
 
   return (NULL);
 }
 
 void nsldapi_free_connection(LDAP *ld, LDAPConn *lc, LDAPControl **serverctrls,
                              LDAPControl **clientctrls, int force, int unbind) {
   LDAPConn *tmplc, *prevlc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_free_connection\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_free_connection\n", 0, 0, 0);
 
   if (force || --lc->lconn_refcnt <= 0) {
     nsldapi_iostatus_interest_clear(ld, lc->lconn_sb);
     if (lc->lconn_status == LDAP_CONNST_CONNECTED) {
       if (unbind) {
         nsldapi_send_unbind(ld, lc->lconn_sb, serverctrls, clientctrls);
       }
     }
@@ -792,22 +792,22 @@ void nsldapi_free_connection(LDAP *ld, L
     }
 #ifdef LDAP_SASLIO_HOOKS
     if (lc->lconn_sasl_ctx) { /* the sasl connection context */
       sasl_dispose(&lc->lconn_sasl_ctx);
       lc->lconn_sasl_ctx = NULL;
     }
 #endif /* LDAP_SASLIO_HOOKS */
     NSLDAPI_FREE(lc);
-    LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_free_connection: actually freed\n", 0,
-              0, 0);
+    LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_free_connection: actually freed\n", 0,
+               0, 0);
   } else {
     lc->lconn_lastused = time(0);
-    LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_free_connection: refcnt %d\n",
-              lc->lconn_refcnt, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE, "nsldapi_free_connection: refcnt %d\n",
+               lc->lconn_refcnt, 0, 0);
   }
 }
 
 #ifdef LDAP_DEBUG
 void nsldapi_dump_connection(LDAP *ld, LDAPConn *lconns, int all) {
   LDAPConn *lc;
   char msg[256];
 /* CTIME for this platform doesn't use this. */
@@ -924,19 +924,19 @@ LDAPRequest *nsldapi_new_request(LDAPCon
   }
 
   return (lr);
 }
 
 void nsldapi_free_request(LDAP *ld, LDAPRequest *lr, int free_conn) {
   LDAPRequest *tmplr, *nextlr;
 
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "nsldapi_free_request 0x%p (origid %d, msgid %d)\n", lr,
-            lr->lr_origid, lr->lr_msgid);
+  LDAPDebug3(LDAP_DEBUG_TRACE,
+             "nsldapi_free_request 0x%p (origid %d, msgid %d)\n", lr,
+             lr->lr_origid, lr->lr_msgid);
 
   if (lr->lr_parent != NULL) {
     /* unlink child from parent */
     lr->lr_parent->lr_child = NULL;
     --lr->lr_parent->lr_outrefcnt;
   }
 
   if (lr->lr_status == LDAP_REQST_WRITING) {
@@ -1034,17 +1034,17 @@ static void free_servers(LDAPServer *srv
  * XXX merging of errors in this routine needs to be improved.
  */
 int nsldapi_chase_v2_referrals(LDAP *ld, LDAPRequest *lr, char **errstrp,
                                int *totalcountp, int *chasingcountp) {
   char *p, *ref, *unfollowed;
   LDAPRequest *origreq;
   int rc, tmprc, len, unknown;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_chase_v2_referrals\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_chase_v2_referrals\n", 0, 0, 0);
 
   *totalcountp = *chasingcountp = 0;
 
   if (*errstrp == NULL) {
     return (LDAP_SUCCESS);
   }
 
   len = strlen(*errstrp);
@@ -1057,18 +1057,18 @@ int nsldapi_chase_v2_referrals(LDAP *ld,
     }
   }
 
   if (len < LDAP_REF_STR_LEN) {
     return (LDAP_SUCCESS);
   }
 
   if (lr->lr_parentcnt >= ld->ld_refhoplimit) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "more than %d referral hops (dropping)\n",
-              ld->ld_refhoplimit, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE, "more than %d referral hops (dropping)\n",
+               ld->ld_refhoplimit, 0, 0);
     return (LDAP_REFERRAL_LIMIT_EXCEEDED);
   }
 
   /* find original request */
   for (origreq = lr; origreq->lr_parent != NULL; origreq = origreq->lr_parent) {
     ;
   }
 
@@ -1116,18 +1116,18 @@ int nsldapi_chase_v3_refs(LDAP *ld, LDAP
 
   if (v3refs == NULL || v3refs[0] == NULL) {
     return (LDAP_SUCCESS);
   }
 
   *totalcountp = 1;
 
   if (lr->lr_parentcnt >= ld->ld_refhoplimit) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "more than %d referral hops (dropping)\n",
-              ld->ld_refhoplimit, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE, "more than %d referral hops (dropping)\n",
+               ld->ld_refhoplimit, 0, 0);
     return (LDAP_REFERRAL_LIMIT_EXCEEDED);
   }
 
   /* find original request */
   for (origreq = lr; origreq->lr_parent != NULL; origreq = origreq->lr_parent) {
     ;
   }
 
@@ -1166,34 +1166,34 @@ static int chase_one_referral(LDAP *ld, 
   LDAPServer *srv;
   BerElement *ber;
   LDAPURLDesc *ludp;
 
   *unknownp = 0;
   ludp = NULLLDAPURLDESC;
 
   if (nsldapi_url_parse(refurl, &ludp, 0) != 0) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "ignoring unknown %s <%s>\n", desc, refurl, 0);
+    LDAPDebug2(LDAP_DEBUG_TRACE, "ignoring unknown %s <%s>\n", desc, refurl, 0);
     *unknownp = 1;
     rc = LDAP_SUCCESS;
     goto cleanup_and_return;
   }
 
   secure = ((ludp->lud_options & LDAP_URL_OPT_SECURE) != 0);
 
   /* XXXmcs: can't tell if secure is supported by connect callback */
   if (secure && ld->ld_extconnect_fn == NULL) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "ignoring LDAPS %s <%s>\n", desc, refurl, 0);
+    LDAPDebug2(LDAP_DEBUG_TRACE, "ignoring LDAPS %s <%s>\n", desc, refurl, 0);
     *unknownp = 1;
     rc = LDAP_SUCCESS;
     goto cleanup_and_return;
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "chasing LDAP%s %s: <%s>\n", secure ? "S" : "",
-            desc, refurl);
+  LDAPDebug3(LDAP_DEBUG_TRACE, "chasing LDAP%s %s: <%s>\n", secure ? "S" : "",
+             desc, refurl);
 
   LDAP_MUTEX_LOCK(ld, LDAP_MSGID_LOCK);
   msgid = ++ld->ld_msgid;
   LDAP_MUTEX_UNLOCK(ld, LDAP_MSGID_LOCK);
 
   if ((tmprc = re_encode_request(ld, origreq->lr_ber, msgid, ludp, &ber,
                                  is_reference)) != LDAP_SUCCESS) {
     rc = tmprc;
@@ -1207,62 +1207,63 @@ static int chase_one_referral(LDAP *ld, 
   }
 
   if (ludp->lud_host == NULL && ld->ld_defhost == NULL) {
     srv->lsrv_host = NULL;
   } else {
     if (ludp->lud_host == NULL) {
       srv->lsrv_host =
           nsldapi_strdup(origreq->lr_conn->lconn_server->lsrv_host);
-      LDAPDebug(LDAP_DEBUG_TRACE,
-                "chase_one_referral: using hostname '%s' from original "
-                "request on new request\n",
-                srv->lsrv_host, 0, 0);
+      LDAPDebug1(LDAP_DEBUG_TRACE,
+                 "chase_one_referral: using hostname '%s' from original "
+                 "request on new request\n",
+                 srv->lsrv_host, 0, 0);
     } else {
       srv->lsrv_host = nsldapi_strdup(ludp->lud_host);
-      LDAPDebug(LDAP_DEBUG_TRACE,
-                "chase_one_referral: using hostname '%s' as specified "
-                "on new request\n",
-                srv->lsrv_host, 0, 0);
+      LDAPDebug1(LDAP_DEBUG_TRACE,
+                 "chase_one_referral: using hostname '%s' as specified "
+                 "on new request\n",
+                 srv->lsrv_host, 0, 0);
     }
 
     if (srv->lsrv_host == NULL) {
       NSLDAPI_FREE((char *)srv);
       ber_free(ber, 1);
       rc = LDAP_NO_MEMORY;
       goto cleanup_and_return;
     }
   }
 
   if (ludp->lud_port == 0 && ludp->lud_host == NULL) {
     srv->lsrv_port = origreq->lr_conn->lconn_server->lsrv_port;
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "chase_one_referral: using port (%d) from original "
-              "request on new request\n",
-              srv->lsrv_port, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "chase_one_referral: using port (%d) from original "
+               "request on new request\n",
+               srv->lsrv_port, 0, 0);
   } else if (ludp->lud_port != 0) {
     srv->lsrv_port = ludp->lud_port;
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "chase_one_referral: using port (%d) as specified on "
-              "new request\n",
-              srv->lsrv_port, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "chase_one_referral: using port (%d) as specified on "
+               "new request\n",
+               srv->lsrv_port, 0, 0);
   } else {
     srv->lsrv_port = secure ? LDAPS_PORT : LDAP_PORT;
-    LDAPDebug(LDAP_DEBUG_TRACE, "chase_one_referral: using default port (%d)\n",
-              srv->lsrv_port, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "chase_one_referral: using default port (%d)\n", srv->lsrv_port,
+               0, 0);
   }
 
   if (secure) {
     srv->lsrv_options |= LDAP_SRV_OPT_SECURE;
   }
 
   if (nsldapi_send_server_request(ld, ber, msgid, lr, srv, NULL, NULL, 1) < 0) {
     rc = LDAP_GET_LDERRNO(ld, NULL, NULL);
-    LDAPDebug(LDAP_DEBUG_ANY, "Unable to chase %s %s (%s)\n", desc, refurl,
-              ldap_err2string(rc));
+    LDAPDebug3(LDAP_DEBUG_ANY, "Unable to chase %s %s (%s)\n", desc, refurl,
+               ldap_err2string(rc));
   } else {
     rc = LDAP_SUCCESS;
   }
 
 cleanup_and_return:
   if (ludp != NULLLDAPURLDESC) {
     ldap_free_urldesc(ludp);
   }
@@ -1309,18 +1310,18 @@ static int re_encode_request(LDAP *ld, B
   ber_int_t ver;
   int rc;
   BerElement *ber;
   struct berelement tmpber;
   char *dn, *orig_dn;
   /* extra stuff for search request */
   ber_int_t scope = -1;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "re_encode_request: new msgid %d, new dn <%s>\n",
-            msgid, (ludp->lud_dn == NULL) ? "NONE" : ludp->lud_dn, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "re_encode_request: new msgid %d, new dn <%s>\n",
+             msgid, (ludp->lud_dn == NULL) ? "NONE" : ludp->lud_dn, 0);
 
   tmpber = *origber;
 
   /*
    * All LDAP requests are sequences that start with a message id.  For
    * everything except delete requests, this is followed by a sequence
    * that is tagged with the operation code.  For deletes, there is just
    * a DN that is tagged with the operation code.
@@ -1423,17 +1424,17 @@ static int re_encode_request(LDAP *ld, B
            (tmpber.ber_end - tmpber.ber_ptr) ||
        ber_printf(ber, "}}") == -1)) {
     ber_free(ber, 1);
     return (LDAP_ENCODING_ERROR);
   }
 
 #ifdef LDAP_DEBUG
   if (ldap_debug & LDAP_DEBUG_PACKETS) {
-    LDAPDebug(LDAP_DEBUG_ANY, "re_encode_request new request is:\n", 0, 0, 0);
+    LDAPDebug0(LDAP_DEBUG_ANY, "re_encode_request new request is:\n", 0, 0, 0);
     ber_dump(ber, 0);
   }
 #endif /* LDAP_DEBUG */
 
   *berp = ber;
   return (LDAP_SUCCESS);
 }
 
--- a/ldap/c-sdk/libraries/libldap/result.c
+++ b/ldap/c-sdk/libraries/libldap/result.c
@@ -88,17 +88,17 @@ static void link_pend(LDAP *ld, LDAPPend
  *
  * Example:
  * ldap_result(s, msgid, all, timeout, result)
  */
 int LDAP_CALL ldap_result(LDAP *ld, int msgid, int all, struct timeval *timeout,
                           LDAPMessage **result) {
   int rc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_result\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_result\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (-1); /* punt */
   }
 
   LDAP_MUTEX_LOCK(ld, LDAP_RESULT_LOCK);
 
   rc = nsldapi_result_nolock(ld, msgid, all, 1, timeout, result);
@@ -107,18 +107,18 @@ int LDAP_CALL ldap_result(LDAP *ld, int 
 
   return (rc);
 }
 
 int nsldapi_result_nolock(LDAP *ld, int msgid, int all, int unlock_permitted,
                           struct timeval *timeout, LDAPMessage **result) {
   int rc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_result_nolock (msgid=%d, all=%d)\n",
-            msgid, all, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "nsldapi_result_nolock (msgid=%d, all=%d)\n",
+             msgid, all, 0);
 
   /*
    * First, look through the list of responses we have received on
    * this association and see if the response we're interested in
    * is there. If it is, return it. If not, call wait4msg() to
    * wait until it arrives or timeout occurs.
    */
 
@@ -156,18 +156,18 @@ int nsldapi_result_nolock(LDAP *ld, int 
  *
  * If not, *result is set to NULL and this function returns 0.
  */
 static int check_response_queue(LDAP *ld, int msgid, int all,
                                 int do_abandon_check, LDAPMessage **result) {
   LDAPMessage *lm, *lastlm, *nextlm;
   LDAPRequest *lr;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "=> check_response_queue (msgid=%d, all=%d)\n",
-            msgid, all, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "=> check_response_queue (msgid=%d, all=%d)\n",
+             msgid, all, 0);
 
   *result = NULL;
   lastlm = NULL;
   LDAP_MUTEX_LOCK(ld, LDAP_RESP_LOCK);
   for (lm = ld->ld_responses; lm != NULL; lm = nextlm) {
     nextlm = lm->lm_next;
 
     if (do_abandon_check && ldap_abandoned(ld, lm->lm_msgid)) {
@@ -193,35 +193,36 @@ static int check_response_queue(LDAP *ld
         break;
 
       for (tmp = lm; tmp != NULL; tmp = tmp->lm_chain) {
         if (tmp->lm_msgtype == LDAP_RES_SEARCH_RESULT) break;
       }
 
       if (tmp == NULL) {
         LDAP_MUTEX_UNLOCK(ld, LDAP_RESP_LOCK);
-        LDAPDebug(LDAP_DEBUG_TRACE, "<= check_response_queue NOT FOUND\n", 0, 0,
-                  0);
+        LDAPDebug0(LDAP_DEBUG_TRACE, "<= check_response_queue NOT FOUND\n", 0,
+                   0, 0);
         return (0); /* no message to return */
       }
 
       break;
     }
     lastlm = lm;
   }
 
   /*
    * if we did not find a message OR if the one we found is a result for
    * a request that is still pending, return failure.
    */
   if (lm == NULL ||
       ((lr = nsldapi_find_request_by_msgid(ld, lm->lm_msgid)) != NULL &&
        lr->lr_outrefcnt > 0)) {
     LDAP_MUTEX_UNLOCK(ld, LDAP_RESP_LOCK);
-    LDAPDebug(LDAP_DEBUG_TRACE, "<= check_response_queue NOT FOUND\n", 0, 0, 0);
+    LDAPDebug0(LDAP_DEBUG_TRACE, "<= check_response_queue NOT FOUND\n", 0, 0,
+               0);
     return (0); /* no message to return */
   }
 
   if (all == 0) {
     if (lm->lm_chain == NULL) {
       if (lastlm == NULL) {
         ld->ld_responses = lm->lm_next;
       } else {
@@ -246,19 +247,19 @@ static int check_response_queue(LDAP *ld
 
   if (all == 0) {
     lm->lm_chain = NULL;
   }
   lm->lm_next = NULL;
   LDAP_MUTEX_UNLOCK(ld, LDAP_RESP_LOCK);
 
   *result = lm;
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "<= check_response_queue returning msgid %d type %d\n",
-            lm->lm_msgid, lm->lm_msgtype, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE,
+             "<= check_response_queue returning msgid %d type %d\n",
+             lm->lm_msgid, lm->lm_msgtype, 0);
   return (1); /* a message was found and returned in *result */
 }
 
 /*
  * wait4msg(): Poll for incoming LDAP messages, respecting the timeout.
  *
  * Return values:
  *  > 0:                      message received; value is the tag of the message.
@@ -271,20 +272,20 @@ static int wait4msg(LDAP *ld, int msgid,
   struct timeval tv, *tvp;
   long start_time = 0, tmp_time;
   LDAPConn *lc, *nextlc;
   /* lr points to the specific request we are waiting for, if any */
   LDAPRequest *lr = NULL;
 
 #ifdef LDAP_DEBUG
   if (timeout == NULL) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "wait4msg (infinite timeout)\n", 0, 0, 0);
+    LDAPDebug0(LDAP_DEBUG_TRACE, "wait4msg (infinite timeout)\n", 0, 0, 0);
   } else {
-    LDAPDebug(LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n",
-              timeout->tv_sec, (long)timeout->tv_usec, 0);
+    LDAPDebug2(LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n",
+               timeout->tv_sec, (long)timeout->tv_usec, 0);
   }
 #endif /* LDAP_DEBUG */
 
   /* check the cache */
   if (ld->ld_cache_on && ld->ld_cache_result != NULL) {
     /* if (unlock_permitted) LDAP_MUTEX_UNLOCK(ld); */
     LDAP_MUTEX_LOCK(ld, LDAP_CACHE_LOCK);
     rc = (ld->ld_cache_result)(ld, msgid, all, timeout, result);
@@ -361,19 +362,19 @@ static int wait4msg(LDAP *ld, int msgid,
       /*
        * There was no buffered data. Poll to check connection
        * status (read/write readiness).
        */
       err = nsldapi_iostatus_poll(ld, tvp);
 
 #if defined(LDAP_DEBUG) && !defined(macintosh) && !defined(DOS)
       if (err == -1) {
-        LDAPDebug(LDAP_DEBUG_TRACE,
-                  "nsldapi_iostatus_poll returned -1: errno %d\n",
-                  LDAP_GET_ERRNO(ld), 0, 0);
+        LDAPDebug1(LDAP_DEBUG_TRACE,
+                   "nsldapi_iostatus_poll returned -1: errno %d\n",
+                   LDAP_GET_ERRNO(ld), 0, 0);
       }
 #endif
 
 #if !defined(macintosh) && !defined(DOS)
       /*
        * If the restart option is enabled and the error
        * was EINTR, try again.
        */
@@ -413,21 +414,21 @@ static int wait4msg(LDAP *ld, int msgid,
          * For connections that are in the CONNECTING
          * state, check for write ready (which
          * indicates that the connection completed) and
          * transition to the CONNECTED state.
          */
         if (lc->lconn_status == LDAP_CONNST_CONNECTING &&
             nsldapi_iostatus_is_write_ready(ld, lc->lconn_sb)) {
           lc->lconn_status = LDAP_CONNST_CONNECTED;
-          LDAPDebug(LDAP_DEBUG_TRACE,
-                    "wait4msg: connection 0x%p -"
-                    " LDAP_CONNST_CONNECTING ->"
-                    " LDAP_CONNST_CONNECTED\n",
-                    lc, 0, 0);
+          LDAPDebug1(LDAP_DEBUG_TRACE,
+                     "wait4msg: connection 0x%p -"
+                     " LDAP_CONNST_CONNECTING ->"
+                     " LDAP_CONNST_CONNECTED\n",
+                     lc, 0, 0);
         }
 
         if (lc->lconn_status != LDAP_CONNST_CONNECTED) {
           continue;
         }
 
         /*
          * For connections that are CONNECTED, check
@@ -479,18 +480,18 @@ static int wait4msg(LDAP *ld, int msgid,
     if (rc == NSLDAPI_RESULT_NOT_FOUND && tvp != NULL) {
       tmp_time = (long)time(NULL);
       if ((tv.tv_sec -= (tmp_time - start_time)) <= 0) {
         rc = NSLDAPI_RESULT_TIMEOUT;
         LDAP_SET_LDERRNO(ld, LDAP_TIMEOUT, NULL, NULL);
         break;
       }
 
-      LDAPDebug(LDAP_DEBUG_TRACE, "wait4msg:  %ld secs to go\n", tv.tv_sec, 0,
-                0);
+      LDAPDebug1(LDAP_DEBUG_TRACE, "wait4msg:  %ld secs to go\n", tv.tv_sec, 0,
+                 0);
       start_time = tmp_time;
     }
   }
 
   return (rc);
 }
 
 #define NSLDAPI_REQUEST_COMPLETE(lr)                                           \
@@ -517,17 +518,17 @@ static int read1msg(LDAP *ld, int msgid,
   ber_tag_t tag;
   ber_len_t len;
   int terrno, lderr, foundit = 0;
   LDAPRequest *lr;
   int rc, has_parent, message_can_be_returned;
   int manufactured_result = 0;
   LDAPConn *lc = *lcp;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0);
 
   message_can_be_returned = 1; /* the usual case... */
 
   /*
    * if we are not already in the midst of reading a message, allocate
    * a ber that is associated with this connection
    */
   if (lc->lconn_ber == NULLBER &&
@@ -574,33 +575,33 @@ static int read1msg(LDAP *ld, int msgid,
   if (ldap_abandoned(ld, (int)id)) {
     ber_free(ber, 1);
     return (NSLDAPI_RESULT_NOT_FOUND); /* continue looking */
   }
 
   if (id == LDAP_RES_UNSOLICITED) {
     lr = NULL;
   } else if ((lr = nsldapi_find_request_by_msgid(ld, id)) == NULL) {
-    LDAPDebug(LDAP_DEBUG_ANY,
-              "no request for response with msgid %d (tossing)\n", id, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_ANY,
+               "no request for response with msgid %d (tossing)\n", id, 0, 0);
     ber_free(ber, 1);
     return (NSLDAPI_RESULT_NOT_FOUND); /* continue looking */
   }
 
   /* the message type */
   if ((tag = ber_peek_tag(ber, &len)) == LBER_ERROR) {
     ber_free(ber, 1);
     LDAP_SET_LDERRNO(ld, LDAP_DECODING_ERROR, NULL, NULL);
     return (NSLDAPI_RESULT_ERROR);
   }
-  LDAPDebug(LDAP_DEBUG_TRACE, "got %s msgid %d, original id %d\n",
-            (tag == LDAP_RES_SEARCH_ENTRY)
-                ? "ENTRY"
-                : (tag == LDAP_RES_SEARCH_REFERENCE) ? "REFERENCE" : "RESULT",
-            id, (lr == NULL) ? id : lr->lr_origid);
+  LDAPDebug3(LDAP_DEBUG_TRACE, "got %s msgid %d, original id %d\n",
+             (tag == LDAP_RES_SEARCH_ENTRY)
+                 ? "ENTRY"
+                 : (tag == LDAP_RES_SEARCH_REFERENCE) ? "REFERENCE" : "RESULT",
+             id, (lr == NULL) ? id : lr->lr_origid);
 
   if (lr != NULL) {
     id = lr->lr_origid;
     lr->lr_res_msgtype = tag;
   }
   rc = NSLDAPI_RESULT_NOT_FOUND; /* default is to keep looking (no response
                                     found) */
 
@@ -698,21 +699,21 @@ static int read1msg(LDAP *ld, int msgid,
        *  1) it is not a child request (NULL parent)
        *  2) it has no outstanding referrals
        *  3) we have received a result for the request (i.e.,
        *     something other than an entry or a reference).
        */
       if (lr->lr_parent == NULL && NSLDAPI_REQUEST_COMPLETE(lr)) {
         id = lr->lr_msgid;
         tag = lr->lr_res_msgtype;
-        LDAPDebug(LDAP_DEBUG_TRACE, "request %d done\n", id, 0, 0);
-        LDAPDebug(LDAP_DEBUG_TRACE,
-                  "res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
-                  lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
-                  lr->lr_res_matched ? lr->lr_res_matched : "");
+        LDAPDebug1(LDAP_DEBUG_TRACE, "request %d done\n", id, 0, 0);
+        LDAPDebug3(LDAP_DEBUG_TRACE,
+                   "res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
+                   lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
+                   lr->lr_res_matched ? lr->lr_res_matched : "");
         if (!simple_request) {
           if (ber != NULLBER) {
             ber_free(ber, 1);
             ber = NULLBER;
           }
           if (build_result_ber(ld, &ber, lr) != LDAP_SUCCESS) {
             rc = NSLDAPI_RESULT_ERROR;
           } else {
@@ -790,27 +791,27 @@ static int read1msg(LDAP *ld, int msgid,
       LDAP_MUTEX_UNLOCK(ld, LDAP_RESP_LOCK);
       *result = new;
       LDAP_SET_LDERRNO(ld, LDAP_SUCCESS, NULL, NULL);
       return (tag);
     }
 
     new->lm_next = ld->ld_responses;
     ld->ld_responses = new;
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "adding new response id %d type %d (looking for id %d)\n",
-              new->lm_msgid, new->lm_msgtype, msgid);
+    LDAPDebug3(LDAP_DEBUG_TRACE,
+               "adding new response id %d type %d (looking for id %d)\n",
+               new->lm_msgid, new->lm_msgtype, msgid);
     LDAP_MUTEX_UNLOCK(ld, LDAP_RESP_LOCK);
     if (message_can_be_returned) POST(ld, new->lm_msgid, new);
     return (NSLDAPI_RESULT_NOT_FOUND); /* continue looking */
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "adding response 0x%p - id %d type %d", new,
-            new->lm_msgid, new->lm_msgtype);
-  LDAPDebug(LDAP_DEBUG_TRACE, " (looking for id %d)\n", msgid, 0, 0);
+  LDAPDebug3(LDAP_DEBUG_TRACE, "adding response 0x%p - id %d type %d", new,
+             new->lm_msgid, new->lm_msgtype);
+  LDAPDebug1(LDAP_DEBUG_TRACE, " (looking for id %d)\n", msgid, 0, 0);
 
   /*
    * part of a search response - add to end of list of entries
    *
    * the first step is to find the end of the list of entries and
    * references.  after the following loop is executed, tmp points to
    * the last entry or reference in the chain.  If there are none,
    * tmp points to the search result.
@@ -927,17 +928,17 @@ static int read1msg(LDAP *ld, int msgid,
  * errors are merged in "lr".
  */
 static void check_for_refs(LDAP *ld, LDAPRequest *lr, BerElement *ber,
                            int ldapversion, int *totalcountp,
                            int *chasingcountp) {
   int err, origerr;
   char *errstr, *matcheddn, **v3refs;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "check_for_refs\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "check_for_refs\n", 0, 0, 0);
 
   *chasingcountp = *totalcountp = 0;
 
   if (ldapversion < LDAP_VERSION2 ||
       (lr->lr_parent == NULL &&
        (ld->ld_options & LDAP_BITOPT_REFERRALS) == 0)) {
     /* referrals are not supported or are disabled */
     return;
@@ -994,25 +995,25 @@ static void check_for_refs(LDAP *ld, LDA
     /* error occurred while trying to chase referrals */
     lr->lr_res_errno = err;
   } else {
     /* some referrals were not recognized */
     lr->lr_res_errno =
         (ldapversion == LDAP_VERSION2) ? LDAP_PARTIAL_RESULTS : LDAP_REFERRAL;
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "check_for_refs: new result: msgid %d, res_errno %d, ",
-            lr->lr_msgid, lr->lr_res_errno, 0);
-  LDAPDebug(LDAP_DEBUG_TRACE, " res_error <%s>, res_matched <%s>\n",
-            lr->lr_res_error ? lr->lr_res_error : "",
-            lr->lr_res_matched ? lr->lr_res_matched : "", 0);
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "check_for_refs: %d new refs(s); chasing %d of them\n",
-            *totalcountp, *chasingcountp, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE,
+             "check_for_refs: new result: msgid %d, res_errno %d, ",
+             lr->lr_msgid, lr->lr_res_errno, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, " res_error <%s>, res_matched <%s>\n",
+             lr->lr_res_error ? lr->lr_res_error : "",
+             lr->lr_res_matched ? lr->lr_res_matched : "", 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE,
+             "check_for_refs: %d new refs(s); chasing %d of them\n",
+             *totalcountp, *chasingcountp, 0);
 }
 
 /* returns an LDAP error code and also sets it in LDAP * */
 static int build_result_ber(LDAP *ld, BerElement **berp, LDAPRequest *lr) {
   ber_len_t len;
   ber_int_t along;
   BerElement *ber;
   int err;
@@ -1066,22 +1067,22 @@ static void merge_error_info(LDAP *ld, L
       if (parentr->lr_res_matched != NULL) {
         NSLDAPI_FREE(parentr->lr_res_matched);
       }
       parentr->lr_res_matched = lr->lr_res_matched;
       lr->lr_res_matched = NULL;
     }
   }
 
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "merged parent (id %d) error info:  ", parentr->lr_msgid, 0, 0);
-  LDAPDebug(LDAP_DEBUG_TRACE, "result lderrno %d, error <%s>, matched <%s>\n",
-            parentr->lr_res_errno,
-            parentr->lr_res_error ? parentr->lr_res_error : "",
-            parentr->lr_res_matched ? parentr->lr_res_matched : "");
+  LDAPDebug1(LDAP_DEBUG_TRACE,
+             "merged parent (id %d) error info:  ", parentr->lr_msgid, 0, 0);
+  LDAPDebug3(LDAP_DEBUG_TRACE, "result lderrno %d, error <%s>, matched <%s>\n",
+             parentr->lr_res_errno,
+             parentr->lr_res_error ? parentr->lr_res_error : "",
+             parentr->lr_res_matched ? parentr->lr_res_matched : "");
 }
 
 #if defined(CLDAP)
 #  if !defined(macintosh) && !defined(DOS) && !defined(_WINDOWS) && \
       !defined(XP_OS2)
 /* XXXmcs: was revised to support extended I/O callbacks but never compiled! */
 static int cldap_select1(LDAP *ld, struct timeval *timeout) {
   int rc;
@@ -1117,19 +1118,19 @@ static int cldap_select1(LDAP *ld, struc
 
     pollfds[0].lpoll_fd = ld->ld_sbp->sb_sd;
     pollfds[0].lpoll_arg = ld->ld_sbp->sb_arg;
     pollfds[0].lpoll_events = LDAP_X_POLLIN;
     pollfds[0].lpoll_revents = 0;
     rc = ld->ld_extpoll_fn(pollfds, 1, nsldapi_tv2ms(timeout),
                            ld->ld_ext_session_arg);
   } else {
-    LDAPDebug(LDAP_DEBUG_ANY,
-        "nsldapi_iostatus_poll: unknown I/O type %d\n",
-     rc = 0; /* simulate a timeout (what else to do?) */
+    LDAPDebug1(LDAP_DEBUG_ANY, "nsldapi_iostatus_poll: unknown I/O type %d\n",
+               iosp->ios_type, 0, 0);
+    rc = 0; /* simulate a timeout (what else to do?) */
   }
 
   return (rc);
 }
 #  endif /* !macintosh */
 
 #  ifdef macintosh
 static int cldap_select1(LDAP *ld, struct timeval *timeout) {
@@ -1162,17 +1163,17 @@ static int cldap_select1(LDAP *ld, struc
 }
 #  endif /* WINSOCK || _WINDOWS */
 #endif   /* CLDAP */
 
 int LDAP_CALL ldap_msgfree(LDAPMessage *lm) {
   LDAPMessage *next;
   int type = 0;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0);
 
   for (; lm != NULL; lm = next) {
     next = lm->lm_chain;
     type = lm->lm_msgtype;
     ber_free(lm->lm_ber, 1);
     NSLDAPI_FREE((char *)lm);
   }
 
@@ -1183,17 +1184,17 @@ int LDAP_CALL ldap_msgfree(LDAPMessage *
  * ldap_msgdelete - delete a message.  It returns:
  *   0  if the entire message was deleted
  *  -1  if the message was not found, or only part of it was found
  */
 int ldap_msgdelete(LDAP *ld, int msgid) {
   LDAPMessage *lm, *prev;
   int msgtype;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (-1); /* punt */
   }
 
   prev = NULL;
   LDAP_MUTEX_LOCK(ld, LDAP_RESP_LOCK);
   for (lm = ld->ld_responses; lm != NULL; lm = lm->lm_next) {
@@ -1293,19 +1294,19 @@ int cldap_getmsg(LDAP *ld, struct timeva
 
   return (tag);
 }
 #endif /* CLDAP */
 
 int nsldapi_post_result(LDAP *ld, int msgid, LDAPMessage *result) {
   LDAPPend *lp;
 
-  LDAPDebug(LDAP_DEBUG_TRACE,
-            "nsldapi_post_result(ld=0x%p, msgid=%d, result=0x%p)\n", ld, msgid,
-            result);
+  LDAPDebug3(LDAP_DEBUG_TRACE,
+             "nsldapi_post_result(ld=0x%p, msgid=%d, result=0x%p)\n", ld, msgid,
+             result);
   LDAP_MUTEX_LOCK(ld, LDAP_PEND_LOCK);
   if (msgid == LDAP_RES_ANY) {
     /*
      * Look for any pending request for which someone is waiting.
      */
     for (lp = ld->ld_pend; lp != NULL; lp = lp->lp_next) {
       if (lp->lp_sema != NULL) {
         break;
--- a/ldap/c-sdk/libraries/libldap/saslbind.c
+++ b/ldap/c-sdk/libraries/libldap/saslbind.c
@@ -282,17 +282,17 @@ static int nsldapi_sasl_bind_s(LDAP *ld,
                                const struct berval *cred,
                                LDAPControl **serverctrls,
                                LDAPControl **clientctrls,
                                struct berval **servercredp,
                                LDAPControl ***responsectrls) {
   int err, msgid;
   LDAPMessage *result;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_sasl_bind_s\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_sasl_bind_s\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if (NSLDAPI_LDAP_VERSION(ld) < LDAP_VERSION3) {
     LDAP_SET_LDERRNO(ld, LDAP_NOT_SUPPORTED, NULL, NULL);
     return (LDAP_NOT_SUPPORTED);
@@ -354,26 +354,26 @@ static int nsldapi_sasl_do_bind(LDAP *ld
 
   if ((rc = nsldapi_sasl_open(ld, NULL, &ctx, 0)) != LDAP_SUCCESS) {
     return (rc);
   }
 
   ccred.bv_val = NULL;
   ccred.bv_len = 0;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "Starting SASL/%s authentication\n",
-            (mechs ? mechs : ""), 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "Starting SASL/%s authentication\n",
+             (mechs ? mechs : ""), 0, 0);
 
   do {
     saslrc = sasl_client_start(ctx, mechs, &prompts,
                                (const char **)&ccred.bv_val, &credlen, &mech);
 
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "Doing step %d of client start for SASL/%s authentication\n",
-              stepnum, (mech ? mech : ""), 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "Doing step %d of client start for SASL/%s authentication\n",
+               stepnum, (mech ? mech : ""), 0);
     stepnum++;
 
     if (saslrc == SASL_INTERACT &&
         (callback)(ld, flags, defaults, prompts) != LDAP_SUCCESS) {
       break;
     }
   } while (saslrc == SASL_INTERACT);
 
@@ -398,19 +398,19 @@ static int nsldapi_sasl_do_bind(LDAP *ld
       /* NOTE that this assumes we only care about the controls
          returned by the last call to nsldapi_sasl_bind_s - if
          we care about _all_ controls, we will have to figure out
          some way to append them each loop go round */
       ldap_controls_free(*rctrl);
       *rctrl = NULL;
     }
 
-    LDAPDebug(LDAP_DEBUG_TRACE,
-              "Doing step %d of bind for SASL/%s authentication\n", stepnum,
-              (mech ? mech : ""), 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE,
+               "Doing step %d of bind for SASL/%s authentication\n", stepnum,
+               (mech ? mech : ""), 0);
     stepnum++;
 
     /* notify server of a sasl bind step */
     rc = nsldapi_sasl_bind_s(ld, dn, mech, &ccred, sctrl, cctrl, &scred, rctrl);
 
     if (ccred.bv_val != NULL) {
       ccred.bv_val = NULL;
     }
@@ -419,39 +419,40 @@ static int nsldapi_sasl_do_bind(LDAP *ld
       ber_bvfree(scred);
       return (rc);
     }
 
     if (rc == LDAP_SUCCESS && saslrc == SASL_OK) {
       /* we're done, no need to step */
       if (scred) {
         if (scred->bv_len == 0) { /* MS AD sends back empty screds */
-          LDAPDebug(LDAP_DEBUG_ANY,
-                    "SASL BIND complete - ignoring empty credential response\n",
-                    0, 0, 0);
+          LDAPDebug0(
+              LDAP_DEBUG_ANY,
+              "SASL BIND complete - ignoring empty credential response\n", 0, 0,
+              0);
           ber_bvfree(scred);
         } else {
           /* but server provided us with data! */
-          LDAPDebug(LDAP_DEBUG_TRACE,
-                    "SASL BIND complete but invalid because server responded "
-                    "with credentials - length [%u]\n",
-                    scred->bv_len, 0, 0);
+          LDAPDebug1(LDAP_DEBUG_TRACE,
+                     "SASL BIND complete but invalid because server responded "
+                     "with credentials - length [%u]\n",
+                     scred->bv_len, 0, 0);
           ber_bvfree(scred);
           LDAP_SET_LDERRNO(ld, LDAP_LOCAL_ERROR, NULL,
                            "Error during SASL handshake - invalid server "
                            "credential response");
           return (LDAP_LOCAL_ERROR);
         }
       }
       break;
     }
 
     /* perform the next step of the sasl bind */
     do {
-      LDAPDebug(
+      LDAPDebug3(
           LDAP_DEBUG_TRACE,
           "Doing client step %d of bind step %d for SASL/%s authentication\n",
           clientstepnum, stepnum, (mech ? mech : ""));
       clientstepnum++;
       saslrc = sasl_client_step(ctx, (scred == NULL) ? NULL : scred->bv_val,
                                 (scred == NULL) ? 0 : scred->bv_len, &prompts,
                                 (const char **)&ccred.bv_val, &credlen);
 
@@ -476,24 +477,24 @@ static int nsldapi_sasl_do_bind(LDAP *ld
 
   if (saslrc != SASL_OK) {
     return (
         nsldapi_sasl_cvterrno(ld, saslrc, nsldapi_strdup(sasl_errdetail(ctx))));
   }
 
   saslrc = sasl_getprop(ctx, SASL_USERNAME, (const void **)&sasl_username);
   if ((saslrc == SASL_OK) && sasl_username) {
-    LDAPDebug(LDAP_DEBUG_TRACE, "SASL identity: %s\n", sasl_username, 0, 0);
+    LDAPDebug1(LDAP_DEBUG_TRACE, "SASL identity: %s\n", sasl_username, 0, 0);
   }
 
   saslrc = sasl_getprop(ctx, SASL_SSF, (const void **)&ssf);
   if (saslrc == SASL_OK) {
     if (ssf && *ssf) {
-      LDAPDebug(LDAP_DEBUG_TRACE, "SASL install encryption, for SSF: %lu\n",
-                (unsigned long)*ssf, 0, 0);
+      LDAPDebug1(LDAP_DEBUG_TRACE, "SASL install encryption, for SSF: %lu\n",
+                 (unsigned long)*ssf, 0, 0);
       nsldapi_sasl_install(ld, NULL);
     }
   }
 
   return (rc);
 }
 #endif /* LDAP_SASLIO_HOOKS */
 
@@ -531,17 +532,17 @@ int LDAP_CALL ldap_sasl_bind(LDAP *ld, c
    * }
    * SaslCredentials ::= SEQUENCE {
    *   mechanism  LDAPString,
    *   credentials  OCTET STRING
    * }
    * all wrapped up in an LDAPMessage sequence.
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_sasl_bind\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_sasl_bind\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if (msgidp == NULL) {
     LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
     return (LDAP_PARAM_ERROR);
@@ -686,17 +687,17 @@ int LDAP_CALL ldap_sasl_interactive_bind
     LDAP *ld, const char *dn, const char *saslMechanism, LDAPControl **sctrl,
     LDAPControl **cctrl, unsigned flags, LDAP_SASL_INTERACT_PROC *callback,
     void *defaults, LDAPControl ***rctrl) {
 #  ifdef LDAP_SASLIO_GET_MECHS_FROM_SERVER
   char *smechs;
 #  endif
   int rc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_sasl_interactive_bind_s\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_sasl_interactive_bind_s\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if ((flags == LDAP_SASL_INTERACTIVE) && (callback == NULL)) {
     return (LDAP_PARAM_ERROR);
   }
@@ -747,17 +748,17 @@ int LDAP_CALL ldap_parse_sasl_bind_resul
                                           struct berval **servercredp,
                                           int freeit) {
   BerElement ber;
   int rc, err;
   ber_int_t along;
   ber_len_t len;
   char *m, *e;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_parse_sasl_bind_result\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_parse_sasl_bind_result\n", 0, 0, 0);
 
   /*
    * the ldapv3 SASL bind response looks like this:
    *
    * BindResponse ::= [APPLICATION 1] SEQUENCE {
    *   COMPONENTS OF LDAPResult,
    *   serverSaslCreds [7] OCTET STRING OPTIONAL
    * }
--- a/ldap/c-sdk/libraries/libldap/sbind.c
+++ b/ldap/c-sdk/libraries/libldap/sbind.c
@@ -61,17 +61,17 @@ static int simple_bind_nolock(LDAP *ld, 
  * Example:
  * ldap_simple_bind(ld, "cn=manager, o=university of michigan, c=us",
  *                  "secret")
  */
 
 int LDAP_CALL ldap_simple_bind(LDAP *ld, const char *dn, const char *passwd) {
   int rc;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_simple_bind\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_simple_bind\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if ((ld->ld_options & LDAP_BITOPT_RECONNECT) != 0) {
     nsldapi_handle_reconnect(ld);
   }
@@ -154,33 +154,33 @@ static int simple_bind_nolock(LDAP *ld, 
  * Example:
  * ldap_simple_bind_s(ld, "cn=manager, o=university of michigan, c=us",
  *                    "secret")
  */
 int LDAP_CALL ldap_simple_bind_s(LDAP *ld, const char *dn, const char *passwd) {
   int msgid;
   LDAPMessage *result;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_simple_bind_s\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_simple_bind_s\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if ((msgid = ldap_simple_bind(ld, dn, passwd)) == -1)
     return (LDAP_GET_LDERRNO(ld, NULL, NULL));
 
   if (ldap_result(ld, msgid, 1, (struct timeval *)0, &result) == -1)
     return (LDAP_GET_LDERRNO(ld, NULL, NULL));
 
   return (ldap_result2error(ld, result, 1));
 }
 
 void nsldapi_handle_reconnect(LDAP *ld) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_handle_reconnect\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_handle_reconnect\n", 0, 0, 0);
 
   /*
    * if the default connection has been lost and is now marked dead,
    * dispose of the default connection so it will get re-established.
    *
    * if not, clear the bind DN and status to ensure that we don't
    * report the wrong bind DN to a different thread while waiting
    * for our bind result to return from the server.
--- a/ldap/c-sdk/libraries/libldap/search.c
+++ b/ldap/c-sdk/libraries/libldap/search.c
@@ -89,17 +89,17 @@ static int nsldapi_search_s(LDAP *ld, co
  * char  *attrs[] = { "mail", "title", 0 };
  * msgid = ldap_search(ld, "c=us@o=UM", LDAP_SCOPE_SUBTREE, "cn~=bob",
  *                     attrs, attrsonly);
  */
 int LDAP_CALL ldap_search(LDAP *ld, const char *base, int scope,
                           const char *filter, char **attrs, int attrsonly) {
   int msgid;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_search\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_search\n", 0, 0, 0);
 
   if (ldap_search_ext(ld, base, scope, filter, attrs, attrsonly, NULL, NULL,
                       NULL, -1, &msgid) == LDAP_SUCCESS) {
     return (msgid);
   } else {
     return (-1); /* error is in ld handle */
   }
 }
@@ -137,17 +137,17 @@ static int nsldapi_search(LDAP *ld, cons
                           LDAPControl **serverctrls, LDAPControl **clientctrls,
                           int timelimit, /* -1 means use ld->ld_timelimit */
                           int sizelimit, /* -1 means use ld->ld_sizelimit */
                           int *msgidp) {
   BerElement *ber;
   int rc, rc_key;
   unsigned long key; /* XXXmcs: memcache */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_search_ext\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_search_ext\n", 0, 0, 0);
 
   if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
     return (LDAP_PARAM_ERROR);
   }
 
   if (base == NULL) {
     base = "";
   }
@@ -409,56 +409,56 @@ static int put_filter(BerElement *ber, c
    *                      initial          [0] IA5String,
    *                      any              [1] IA5String,
    *                      final            [2] IA5String
    *              }
    *      }
    * Note: tags in a choice are always explicit
    */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "put_filter \"%s\"\n", str, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "put_filter \"%s\"\n", str, 0, 0);
 
   parens = 0;
   while (*str) {
     switch (*str) {
       case '(':
         str++;
         parens++;
         switch (*str) {
           case '&':
-            LDAPDebug(LDAP_DEBUG_TRACE, "put_filter: AND\n", 0, 0, 0);
+            LDAPDebug0(LDAP_DEBUG_TRACE, "put_filter: AND\n", 0, 0, 0);
 
             if ((str = put_complex_filter(ber, str, LDAP_FILTER_AND, 0)) ==
                 NULL)
               return (-1);
 
             parens--;
             break;
 
           case '|':
-            LDAPDebug(LDAP_DEBUG_TRACE, "put_filter: OR\n", 0, 0, 0);
+            LDAPDebug0(LDAP_DEBUG_TRACE, "put_filter: OR\n", 0, 0, 0);
 
             if ((str = put_complex_filter(ber, str, LDAP_FILTER_OR, 0)) == NULL)
               return (-1);
 
             parens--;
             break;
 
           case '!':
-            LDAPDebug(LDAP_DEBUG_TRACE, "put_filter: NOT\n", 0, 0, 0);
+            LDAPDebug0(LDAP_DEBUG_TRACE, "put_filter: NOT\n", 0, 0, 0);
 
             if ((str = put_complex_filter(ber, str, LDAP_FILTER_NOT, 1)) ==
                 NULL)
               return (-1);
 
             parens--;
             break;
 
           default:
-            LDAPDebug(LDAP_DEBUG_TRACE, "put_filter: simple\n", 0, 0, 0);
+            LDAPDebug0(LDAP_DEBUG_TRACE, "put_filter: simple\n", 0, 0, 0);
 
             balance = 1;
             escape = 0;
             next = str;
             while (*next && balance) {
               if (escape == 0) {
                 if (*next == '(')
                   balance++;
@@ -480,28 +480,28 @@ static int put_filter(BerElement *ber, c
             *next++ = ')';
             str = next;
             parens--;
             break;
         }
         break;
 
       case ')':
-        LDAPDebug(LDAP_DEBUG_TRACE, "put_filter: end\n", 0, 0, 0);
+        LDAPDebug0(LDAP_DEBUG_TRACE, "put_filter: end\n", 0, 0, 0);
         if (ber_printf(ber, "]") == -1) return (-1);
         str++;
         parens--;
         break;
 
       case ' ':
         str++;
         break;
 
       default: /* assume it's a simple type=value filter */
-        LDAPDebug(LDAP_DEBUG_TRACE, "put_filter: default\n", 0, 0, 0);
+        LDAPDebug0(LDAP_DEBUG_TRACE, "put_filter: default\n", 0, 0, 0);
         next = strchr(str, '\0');
         if (put_simple_filter(ber, str) == -1) {
           return (-1);
         }
         str = next;
         break;
     }
   }
@@ -512,17 +512,17 @@ static int put_filter(BerElement *ber, c
 /*
  * Put a list of filters like this "(filter1)(filter2)..."
  */
 
 static int put_filter_list(BerElement *ber, char *str) {
   char *next;
   char save;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "put_filter_list \"%s\"\n", str, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "put_filter_list \"%s\"\n", str, 0, 0);
 
   while (*str) {
     while (*str && isspace(*str)) str++;
     if (*str == '\0') break;
 
     if ((next = find_right_paren(str + 1)) == NULL) return (-1);
     save = *++next;
 
@@ -589,17 +589,17 @@ static char *find_star(char *s) {
 static int put_simple_filter(BerElement *ber, char *str) {
   char *s, *s2, *s3, filterop;
   char *value;
   unsigned long ftype;
   int rc, len;
   char *oid;  /* for v3 extended filter */
   int dnattr; /* for v3 extended filter */
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "put_simple_filter \"%s\"\n", str, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "put_simple_filter \"%s\"\n", str, 0, 0);
 
   rc = -1; /* pessimistic */
 
   if ((str = nsldapi_strdup(str)) == NULL) {
     return (rc);
   }
 
   if ((s = strchr(str, '=')) == NULL) {
@@ -773,17 +773,18 @@ static int hexchar2int(char c) {
   return (-1);
 }
 
 static int put_substring_filter(BerElement *ber, char *type, char *val) {
   char *nextstar, gotstar = 0;
   unsigned long ftype;
   int len;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "put_substring_filter \"%s=%s\"\n", type, val, 0);
+  LDAPDebug2(LDAP_DEBUG_TRACE, "put_substring_filter \"%s=%s\"\n", type, val,
+             0);
 
   if (ber_printf(ber, "t{s{", LDAP_FILTER_SUBSTRINGS, type) == -1) {
     return (-1);
   }
 
   for (; val != NULL; val = nextstar) {
     if ((nextstar = find_star(val)) != NULL) {
       *nextstar++ = '\0';
--- a/ldap/c-sdk/libraries/libldap/tmplout.c
+++ b/ldap/c-sdk/libraries/libldap/tmplout.c
@@ -92,29 +92,29 @@ static int searchaction(LDAP *ld, char *
 
 #define DEF_LDAP_URL_PREFIX "ldap:///"
 
 int LDAP_CALL ldap_entry2text(LDAP *ld, char *buf, /* NULL for "use internal" */
                               LDAPMessage *entry, struct ldap_disptmpl *tmpl,
                               char **defattrs, char ***defvals,
                               writeptype writeproc, void *writeparm, char *eol,
                               int rdncount, unsigned long opts) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_entry2text\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_entry2text\n", 0, 0, 0);
 
   return (do_entry2text(ld, buf, NULL, entry, tmpl, defattrs, defvals,
                         writeproc, writeparm, eol, rdncount, opts, NULL));
 }
 
 int LDAP_CALL ldap_entry2html(LDAP *ld, char *buf, /* NULL for "use internal" */
                               LDAPMessage *entry, struct ldap_disptmpl *tmpl,
                               char **defattrs, char ***defvals,
                               writeptype writeproc, void *writeparm, char *eol,
                               int rdncount, unsigned long opts, char *base,
                               char *urlprefix) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_entry2html\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_entry2html\n", 0, 0, 0);
 
   if (urlprefix == NULL) {
     urlprefix = DEF_LDAP_URL_PREFIX;
   }
 
   return (do_entry2text(ld, buf, base, entry, tmpl, defattrs, defvals,
                         writeproc, writeparm, eol, rdncount, opts, urlprefix));
 }
@@ -357,32 +357,32 @@ static int do_entry2text(LDAP *ld, char 
 int LDAP_CALL ldap_entry2text_search(
     LDAP *ld, char *dn,             /* if NULL, use entry */
     char *base,                     /* if NULL, no search actions */
     LDAPMessage *entry,             /* if NULL, use dn */
     struct ldap_disptmpl *tmpllist, /* if NULL, load default file */
     char **defattrs, char ***defvals, writeptype writeproc, void *writeparm,
     char *eol, int rdncount, /* if 0, display full DN */
     unsigned long opts) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_entry2text_search\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_entry2text_search\n", 0, 0, 0);
 
   return (do_entry2text_search(ld, dn, base, entry, tmpllist, defattrs, defvals,
                                writeproc, writeparm, eol, rdncount, opts,
                                NULL));
 }
 
 int LDAP_CALL ldap_entry2html_search(
     LDAP *ld, char *dn,             /* if NULL, use entry */
     char *base,                     /* if NULL, no search actions */
     LDAPMessage *entry,             /* if NULL, use dn */
     struct ldap_disptmpl *tmpllist, /* if NULL, load default file */
     char **defattrs, char ***defvals, writeptype writeproc, void *writeparm,
     char *eol, int rdncount, /* if 0, display full DN */
     unsigned long opts, char *urlprefix) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_entry2html_search\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_entry2html_search\n", 0, 0, 0);
 
   return (do_entry2text_search(ld, dn, base, entry, tmpllist, defattrs, defvals,
                                writeproc, writeparm, eol, rdncount, opts,
                                urlprefix));
 }
 
 static int do_entry2text_search(
     LDAP *ld, char *dn,             /* if NULL, use entry */
@@ -501,29 +501,29 @@ static int do_entry2text_search(
   return (err);
 }
 
 int LDAP_CALL ldap_vals2text(LDAP *ld, char *buf, /* NULL for "use internal" */
                              char **vals, char *label,
                              int labelwidth, /* 0 means use default */
                              unsigned long syntaxid, writeptype writeproc,
                              void *writeparm, char *eol, int rdncount) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_vals2text\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_vals2text\n", 0, 0, 0);
 
   return (do_vals2text(ld, buf, vals, label, labelwidth, syntaxid, writeproc,
                        writeparm, eol, rdncount, NULL));
 }
 
 int LDAP_CALL ldap_vals2html(LDAP *ld, char *buf, /* NULL for "use internal" */
                              char **vals, char *label,
                              int labelwidth, /* 0 means use default */
                              unsigned long syntaxid, writeptype writeproc,
                              void *writeparm, char *eol, int rdncount,
                              char *urlprefix) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_vals2html\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_vals2html\n", 0, 0, 0);
 
   if (urlprefix == NULL) {
     urlprefix = DEF_LDAP_URL_PREFIX;
   }
 
   return (do_vals2text(ld, buf, vals, label, labelwidth, syntaxid, writeproc,
                        writeparm, eol, rdncount, urlprefix));
 }
--- a/ldap/c-sdk/libraries/libldap/unbind.c
+++ b/ldap/c-sdk/libraries/libldap/unbind.c
@@ -47,17 +47,17 @@
 #  ifndef lint 
 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
 #  endif
 #endif
 
 #include "ldap-int.h"
 
 int LDAP_CALL ldap_unbind(LDAP *ld) {
-  LDAPDebug(LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0);
 
   return (ldap_ld_free(ld, NULL, NULL, 1));
 }
 
 int LDAP_CALL ldap_unbind_s(LDAP *ld) {
   return (ldap_ld_free(ld, NULL, NULL, 1));
 }
 
@@ -166,17 +166,17 @@ int ldap_ld_free(LDAP *ld, LDAPControl *
   return (err);
 }
 
 int nsldapi_send_unbind(LDAP *ld, Sockbuf *sb, LDAPControl **serverctrls,
                         LDAPControl **clientctrls) {
   BerElement *ber;
   int err, msgid;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_send_unbind\n", 0, 0, 0);
+  LDAPDebug0(LDAP_DEBUG_TRACE, "nsldapi_send_unbind\n", 0, 0, 0);
 
   /* create a message to send */
   if ((err = nsldapi_alloc_ber_with_options(ld, &ber)) != LDAP_SUCCESS) {
     return (err);
   }
 
   /* fill it in */
   LDAP_MUTEX_LOCK(ld, LDAP_MSGID_LOCK);
--- a/ldap/c-sdk/libraries/libldap/url.c
+++ b/ldap/c-sdk/libraries/libldap/url.c
@@ -163,17 +163,17 @@ int LDAP_CALL ldap_url_parse(const char 
  * critical, in which case an LDAP_URL_UNRECOGNIZED_CRITICAL_EXTENSION error
  * is returned.
  */
 int nsldapi_url_parse(const char *url, LDAPURLDesc **ludpp, int dn_required) {
   LDAPURLDesc *ludp;
   char *urlcopy, *attrs, *scope, *extensions = NULL, *p, *q;
   int enclosed, secure, i, nattrs, at_start;
 
-  LDAPDebug(LDAP_DEBUG_TRACE, "nsldapi_url_parse(%s)\n", url, 0, 0);
+  LDAPDebug1(LDAP_DEBUG_TRACE, "nsldapi_url_parse(%s)\n", url, 0, 0);
 
   if (url == NULL || ludpp == NULL) {
     return (LDAP_URL_ERR_PARAM);
   }
 
   *ludpp = NULL; /* pessimistic */
 
   if (!skip_url_prefix(&url, &enclosed, &secure)) {