Bug 1277602 - pass correct number of arguments to format strings draft
authorISHIKAWA, Chiaki <ishikawa@yk.rim.or.jp>
Tue, 07 Feb 2017 12:20:31 +0900
changeset 47559 cb2879fbad281c8ed1d9aad15d5de2f03d6dd5db
parent 47558 96dc223f1017c1ba497b81a5e60121d9050898fc
child 47560 ecc66f308b9888915c21964e2d0792d3e48012a6
push id4207
push userishikawa@yk.rim.or.jp
push dateTue, 07 Feb 2017 03:21:04 +0000
treeherdertry-comm-central@20c2302fd6e8 [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,20 +58,28 @@ 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 ); \
@@ -81,26 +89,59 @@ extern "C" {
        extern int	ldap_debug;
 #      define LDAPDebug( level, fmt, arg1, arg2, arg3 )	\
        { \
 		if ( ldap_debug & level ) { \
 		        slapd_log_error_proc( NULL, fmt, arg1, arg2, arg3 ); \
 	    } \
        }
 #    endif /* Win32 */
+#    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)
 #  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
@@ -66,19 +66,19 @@ static int nsldapi_send_abandon_message(
  *
  * 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 );
 }
 
@@ -89,17 +89,17 @@ ldap_abandon( LDAP *ld, int msgid )
  */
 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 );
@@ -129,17 +129,17 @@ do_abandon( LDAP *ld, int origid, int ms
 	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",
+	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
@@ -70,17 +70,17 @@ static char copyright[] = "@(#) Copyrigh
  *	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 */
 	}
 }
@@ -104,17 +104,17 @@ ldap_add_ext( LDAP *ld, const char *dn, 
 	 *		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 );
--- a/ldap/c-sdk/libraries/libldap/bind.c
+++ b/ldap/c-sdk/libraries/libldap/bind.c
@@ -70,17 +70,17 @@ ldap_bind( LDAP *ld, const char *dn, con
 	 *		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 ) );
@@ -106,17 +106,17 @@ ldap_bind( LDAP *ld, const char *dn, con
  *	    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
@@ -78,21 +78,21 @@ nsldapi_add_result_to_cache( LDAP *ld, 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",
+	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,
+		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 *) );
@@ -109,17 +109,17 @@ nsldapi_add_result_to_cache( LDAP *ld, 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,
+		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) ) {
@@ -135,11 +135,11 @@ nsldapi_add_result_to_cache( LDAP *ld, 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,
+	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
@@ -1064,17 +1064,17 @@ 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",
+  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 );
   }
@@ -1601,17 +1601,17 @@ cc_to_t61( Byte *o, Byte *s )
 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",
+  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
@@ -117,17 +117,17 @@ 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 );
     }
@@ -218,17 +218,17 @@ XXX
     }
 
     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( LDAP_DEBUG_TRACE, "end of cldap_open address %d is %s\n",
+	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 );
 }
 
@@ -267,27 +267,27 @@ cldap_search_s( LDAP *ld, char *base, in
     }
 
     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( LDAP_DEBUG_TRACE, "cldap_search_s try %d (to %s)\n",
+	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",
+		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);
@@ -339,37 +339,37 @@ cldap_result( LDAP *ld, int msgid, LDAPM
     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",
+	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,
+    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",
+	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,
+	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 {
@@ -389,22 +389,22 @@ cldap_result( LDAP *ld, int msgid, LDAPM
 	 * 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,
+	    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,
+	    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
 	     */
@@ -413,17 +413,17 @@ cldap_result( LDAP *ld, int msgid, LDAPM
 			    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,
+	    LDAPDebug1( LDAP_DEBUG_TRACE,
 		"cldap_result got result (%d)\n", ret, 0, 0 );
 	}
 
 	if ( logdn != NULL ) {
 		NSLDAPI_FREE( logdn );
 	}
     }
     
@@ -438,17 +438,17 @@ cldap_result( LDAP *ld, int msgid, LDAPM
 	    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",
+	    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 );
@@ -482,17 +482,17 @@ cldap_parsemsg( LDAP *ld, int msgid, Ber
 	} 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",
+	    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 ) {
@@ -501,17 +501,17 @@ cldap_parsemsg( LDAP *ld, int msgid, Ber
 	    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 );
@@ -527,17 +527,17 @@ cldap_parsemsg( LDAP *ld, int msgid, Ber
 		    bv->bv_len ) == -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",
+	    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
@@ -60,17 +60,17 @@ static char copyright[] = "@(#) Copyrigh
  */
 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 {
@@ -93,17 +93,17 @@ ldap_compare_ext( LDAP *ld, const char *
 	 *		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 );
--- a/ldap/c-sdk/libraries/libldap/control.c
+++ b/ldap/c-sdk/libraries/libldap/control.c
@@ -159,44 +159,44 @@ nsldapi_get_controls( BerElement *ber, L
 	 *	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,
+		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,
+			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,
+		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;
@@ -255,24 +255,24 @@ nsldapi_get_controls( BerElement *ber, L
 
 	}
 
 	if ( tag == LBER_ERROR ) {
 		rc = LDAP_DECODING_ERROR;
 		goto free_and_return;
 	}
 
-	LDAPDebug( LDAP_DEBUG_TRACE,
+	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,
+	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
@@ -56,17 +56,17 @@ static char copyright[] = "@(#) Copyrigh
  *	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 */
 	}
 }
 
@@ -78,17 +78,17 @@ ldap_delete_ext( LDAP *ld, const char *d
 	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 );
--- a/ldap/c-sdk/libraries/libldap/error.c
+++ b/ldap/c-sdk/libraries/libldap/error.c
@@ -112,17 +112,17 @@ static struct ldaperror ldap_errlist[] =
 };
 
 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" );
 }
@@ -146,17 +146,17 @@ 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 ) {
@@ -285,17 +285,17 @@ ldap_parse_result( LDAP *ld, LDAPMessage
 	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
@@ -69,17 +69,17 @@ ldap_extended_operation(
 	 *	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 ) {
@@ -212,17 +212,17 @@ ldap_parse_extended_result(
 )
 {
 	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
@@ -66,17 +66,17 @@ bytes_remaining( BerElement *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 );
@@ -120,17 +120,17 @@ ldap_first_attribute( LDAP *ld, LDAPMess
 /* 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
@@ -52,17 +52,17 @@ static char copyright[] = "@(#) Copyrigh
 
 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 );
@@ -80,17 +80,17 @@ ldap_get_dn( LDAP *ld, LDAPMessage *entr
 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 ));
 
@@ -209,17 +209,17 @@ ldap_explode( const char *dn, const int 
 	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
@@ -97,17 +97,17 @@ extern char *h_errlist[];
  */
 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 ) {
 	/*
--- a/ldap/c-sdk/libraries/libldap/getentry.c
+++ b/ldap/c-sdk/libraries/libldap/getentry.c
@@ -107,17 +107,17 @@ ldap_count_entries( LDAP *ld, LDAPMessag
 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;
--- a/ldap/c-sdk/libraries/libldap/getvalues.c
+++ b/ldap/c-sdk/libraries/libldap/getvalues.c
@@ -55,17 +55,17 @@ 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 );
@@ -344,17 +344,17 @@ internal_ldap_get_lang_values( LDAP *ld,
 	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
@@ -260,17 +260,17 @@ static unsigned long crc32_convert(char 
 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 );
@@ -348,30 +348,30 @@ ldap_memcache_init( unsigned long ttl, u
     /* 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",
+    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) {
 
@@ -450,17 +450,17 @@ ldap_memcache_set( LDAP *ld, LDAPMemCach
     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 );
@@ -472,17 +472,17 @@ ldap_memcache_get( LDAP *ld, LDAPMemCach
  * 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",
+    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);
@@ -490,44 +490,44 @@ ldap_memcache_update( LDAPMemCache *cach
 }
 
 /* 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,
+    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,
+    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",
+    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 );
@@ -687,17 +687,17 @@ ldap_memcache_createkey(LDAP *ld, const 
    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,
+    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)) {
@@ -707,21 +707,21 @@ ldap_memcache_result(LDAP *ld, int msgid
     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,
+	LDAPDebug1( LDAP_DEBUG_TRACE,
 		"ldap_memcache_result: key 0x%8.8lx found in cache\n",
 		key, 0, 0 );
     } else {
-	LDAPDebug( LDAP_DEBUG_TRACE,
+	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 */
@@ -761,18 +761,18 @@ ldap_memcache_new(LDAP *ld, int msgid, u
 /* 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",
+    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 );
 
@@ -783,17 +783,17 @@ ldap_memcache_append(LDAP *ld, int msgid
 
     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,
+    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;
 }
@@ -933,39 +933,39 @@ memcache_append_ctrls(char *buf, LDAPCon
 }
 
 /* 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,
+    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,
+		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,
+		    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;
@@ -973,21 +973,21 @@ memcache_adj_size(LDAPMemCache *cache, u
 	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,
+	LDAPDebug1( LDAP_DEBUG_TRACE,
 		"memcache_adj_size: succeeded (new size: %ld bytes).\n",
 		cache->ldmemc_size_used, 0, 0 );
     } else {
-	LDAPDebug( LDAP_DEBUG_TRACE,
+	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 );
 }
@@ -1386,27 +1386,27 @@ memcache_print_list( LDAPMemCache *cache
 	break;
     case LIST_TOTAL:
 	name = "TOTAL";
 	break;
     default:
 	name = "unknown";
     }
 
-    LDAPDebug( LDAP_DEBUG_TRACE, "memcache 0x%p %s list:\n",
+    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,
+	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",
+    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)
@@ -1669,17 +1669,17 @@ memcache_access(LDAPMemCache *cache, int
     /* 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,
+	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);
@@ -1724,25 +1724,25 @@ memcache_report_statistics( LDAPMemCache
     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",
+    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",
+	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",
+	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 *****************************/
 
--- a/ldap/c-sdk/libraries/libldap/modify.c
+++ b/ldap/c-sdk/libraries/libldap/modify.c
@@ -68,17 +68,17 @@ static char copyright[] = "@(#) Copyrigh
  *	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 */
 	}
 }
@@ -104,17 +104,17 @@ ldap_modify_ext( LDAP *ld, const char *d
 	 *			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
@@ -536,31 +536,31 @@ ldap_version( LDAPVersion *ver )
  */
 
 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",
+	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
@@ -581,26 +581,26 @@ ldap_init( const char *defhost, int defp
 {
 	LDAP	*ld;
 
 	if ( !nsldapi_initialized ) {
 		nsldapi_initialize_defaults();
 	}
 
 	if ( defport < 0 || defport > LDAP_PORT_MAX ) {
-	    LDAPDebug( LDAP_DEBUG_ANY,
+	    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
@@ -292,17 +292,17 @@ nsldapi_os_connect_with_to(LBER_SOCKET s
 	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",
+	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);
@@ -337,17 +337,17 @@ nsldapi_os_connect_with_to(LBER_SOCKET s
 	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.."
+		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 );
@@ -484,17 +484,17 @@ nsldapi_connect_to_host( LDAP *ld, Sockb
 /*
  * "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",
+	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;
 
@@ -654,17 +654,17 @@ nsldapi_try_each_host( LDAP *ld, const c
 				return( -1 );
 			}
 
 			if ( ld->ld_options & LDAP_BITOPT_ASYNC ) {
 				int	iostatus = 1;
 
 				err = (*ioctlfn)( s, FIONBIO, &iostatus );
 				if ( err == -1 ) {
-					LDAPDebug( LDAP_DEBUG_ANY,
+					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 );
@@ -716,17 +716,17 @@ nsldapi_try_each_host( LDAP *ld, const c
 			} 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",
+						LDAPDebug0( LDAP_DEBUG_TRACE, "connect would block...\n",
 							   0, 0, 0 );
 						rc = -2;
 						break;
 					}
 				}
 
 #ifdef LDAP_DEBUG
 				if ( ldap_debug & LDAP_DEBUG_TRACE ) {
@@ -746,17 +746,17 @@ nsldapi_try_each_host( LDAP *ld, const c
 
 	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",
+		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
@@ -848,17 +848,17 @@ nsldapi_iostatus_interest_write( LDAP *l
 
 	} 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,
+		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 );
 }
@@ -905,17 +905,17 @@ nsldapi_iostatus_interest_read( LDAP *ld
 #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,
+		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 );
 }
@@ -976,17 +976,17 @@ nsldapi_iostatus_interest_clear( LDAP *l
 		    &iosp->ios_status.ios_cbinfo, 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,
+		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 );
 }
@@ -1029,17 +1029,17 @@ nsldapi_iostatus_is_write_ready( LDAP *l
 #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,
+		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 );
@@ -1083,17 +1083,17 @@ nsldapi_iostatus_is_read_ready( LDAP *ld
 #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,
+		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 );
@@ -1171,17 +1171,17 @@ nsldapi_iostatus_free( LDAP *ld )
 
 		} 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,
+			LDAPDebug1( LDAP_DEBUG_ANY,
 			    "nsldapi_iostatus_free: unknown I/O type %d\n",
 			     iosp->ios_type, 0, 0 );
 		}
 
 		NSLDAPI_FREE( iosp );
 	}
 }
 
@@ -1229,17 +1229,17 @@ nsldapi_tv2ms( struct timeval *tv )
 
 
 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 */
 
@@ -1279,17 +1279,17 @@ nsldapi_iostatus_poll( LDAP *ld, struct 
 		 * 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,
+		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 );
 }
--- a/ldap/c-sdk/libraries/libldap/rename.c
+++ b/ldap/c-sdk/libraries/libldap/rename.c
@@ -90,17 +90,17 @@ ldap_rename(
 	 *	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
@@ -100,17 +100,17 @@ nsldapi_set_ber_options( LDAP *ld, BerEl
 
 /* 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 );
@@ -168,17 +168,17 @@ 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 && ( ld->ld_options
@@ -294,17 +294,17 @@ 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,
+		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 ) {
        /*
@@ -350,33 +350,33 @@ nsldapi_send_server_request(
 										&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, 
+	LDAPDebug0( LDAP_DEBUG_TRACE, 
 			   "nsldapi_send_server_request: Unsolicited response\n", 0, 0, 0 );
 	if ( ext_oid ) {
-		LDAPDebug( LDAP_DEBUG_TRACE, 
+		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( LDAP_DEBUG_TRACE, 
+		LDAPDebug1( LDAP_DEBUG_TRACE, 
 				"nsldapi_send_server_request: Unsolicited response len: %d\n", 
 				   ext_data->bv_len, 0, 0 );
-		LDAPDebug( LDAP_DEBUG_TRACE, 
+		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, 
+		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 ) {
@@ -508,44 +508,44 @@ 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,
+				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,
+				LDAPDebug2( LDAP_DEBUG_TRACE,
 				    "%s: 0x%p WOULD BLOCK\n", logname, lr, 0 );
 				break;
 			} else {			/* fatal error */
-				LDAPDebug( LDAP_DEBUG_TRACE,
+				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;
@@ -553,17 +553,17 @@ nsldapi_send_pending_requests_nolock( LD
 				break;
 			}
 		}
 
 		if (lr->lr_status == LDAP_REQST_INPROGRESS ) {
 			if (lr->lr_expect_resp) {
 				++waiting_for_a_response;
 			} else {
-				LDAPDebug( LDAP_DEBUG_TRACE,
+				LDAPDebug2( LDAP_DEBUG_TRACE,
 				    "%s: 0x%p NO RESPONSE EXPECTED;"
 				    " freeing request \n", logname, lr, 0 );
 				nsldapi_free_request( ld, lr, 0 );
 				lr = NULL;
 			}
 		}
 	}
 
@@ -574,17 +574,17 @@ nsldapi_send_pending_requests_nolock( LD
 		}
 
 		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 )
 {
@@ -790,17 +790,17 @@ find_connection( LDAP *ld, LDAPServer *s
 
 
 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 );
 			}
@@ -840,21 +840,21 @@ nsldapi_free_connection( LDAP *ld, LDAPC
 		}
 #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",
+		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",
+		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 )
@@ -983,17 +983,17 @@ nsldapi_new_request( LDAPConn *lc, BerEl
 }
 
 
 void
 nsldapi_free_request( LDAP *ld, LDAPRequest *lr, int free_conn )
 {
 	LDAPRequest	*tmplr, *nextlr;
 
-	LDAPDebug( LDAP_DEBUG_TRACE,
+	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;
 	}
@@ -1102,17 +1102,17 @@ free_servers( LDAPServer *srvlist )
 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 );
@@ -1125,17 +1125,17 @@ nsldapi_chase_v2_referrals( LDAP *ld, LD
 		}
 	}
 
 	if ( len < LDAP_REF_STR_LEN ) {
 		return( LDAP_SUCCESS );
 	}
 
 	if ( lr->lr_parentcnt >= ld->ld_refhoplimit ) {
-		LDAPDebug( LDAP_DEBUG_TRACE,
+		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 ) {
@@ -1188,17 +1188,17 @@ nsldapi_chase_v3_refs( LDAP *ld, LDAPReq
 
 	if ( v3refs == NULL || v3refs[0] == NULL ) {
 		return( LDAP_SUCCESS );
 	}
 
 	*totalcountp = 1;
 
 	if ( lr->lr_parentcnt >= ld->ld_refhoplimit ) {
-		LDAPDebug( LDAP_DEBUG_TRACE,
+		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 ) {
@@ -1242,35 +1242,35 @@ chase_one_referral( LDAP *ld, LDAPReques
 	LDAPServer	*srv;
 	BerElement	*ber;
 	LDAPURLDesc	*ludp;
 
 	*unknownp = 0;
 	ludp = NULLLDAPURLDESC;
 
 	if ( nsldapi_url_parse( refurl, &ludp, 0 ) != 0 ) {
-		LDAPDebug( LDAP_DEBUG_TRACE,
+		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,
+		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",
+	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 ) {
@@ -1286,63 +1286,63 @@ chase_one_referral( LDAP *ld, LDAPReques
 	}
 
 	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,
+		  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,
+		  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,
+		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,
+		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,
+		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",
+		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 );
@@ -1397,17 +1397,17 @@ re_encode_request( LDAP *ld, BerElement 
 	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,
+	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
@@ -1513,17 +1513,17 @@ re_encode_request( LDAP *ld, BerElement 
 	    tmpber.ber_ptr ), 0 ) != ( 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",
+		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
@@ -95,17 +95,17 @@ ldap_result(
     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);
@@ -117,17 +117,17 @@ ldap_result(
 
 
 int
 nsldapi_result_nolock( LDAP *ld, int msgid, int all, int unlock_permitted,
     struct timeval *timeout, LDAPMessage **result )
 {
 	int		rc;
 
-	LDAPDebug( LDAP_DEBUG_TRACE,
+	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.
 	 */
@@ -170,17 +170,17 @@ nsldapi_result_nolock( LDAP *ld, int msg
  */
 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,
+	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;
 
@@ -209,17 +209,17 @@ check_response_queue( LDAP *ld, int msgi
 
 			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,
+				LDAPDebug0( LDAP_DEBUG_TRACE,
 				    "<= check_response_queue NOT FOUND\n",
 				    0, 0, 0 );
 				return( 0 );	/* no message to return */
 			}
 
 			break;
 		}
 		lastlm = lm;
@@ -228,17 +228,17 @@ check_response_queue( LDAP *ld, int msgi
 	/*
 	 * 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,
+		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 ) {
@@ -265,17 +265,17 @@ check_response_queue( LDAP *ld, int msgi
 
 	if ( all == 0 ) {
 		lm->lm_chain = NULL;
 	}
 	lm->lm_next = NULL;
 	LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
 
 	*result = lm;
-	LDAPDebug( LDAP_DEBUG_TRACE,
+	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.
@@ -293,20 +293,20 @@ wait4msg( LDAP *ld, int msgid, int all, 
 	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",
+		LDAPDebug0( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout)\n",
 		    0, 0, 0 );
 	} else {
-		LDAPDebug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n",
+		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 );
@@ -388,17 +388,17 @@ wait4msg( LDAP *ld, int msgid, int all, 
 			/*
 			 * 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,
+			    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
@@ -445,17 +445,17 @@ wait4msg( LDAP *ld, int msgid, int all, 
 				 * 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,
+					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 ) {
@@ -519,17 +519,17 @@ wait4msg( LDAP *ld, int msgid, int all, 
 			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",
+			LDAPDebug1( LDAP_DEBUG_TRACE, "wait4msg:  %ld secs to go\n",
 				tv.tv_sec, 0, 0 );
 			start_time = tmp_time;
 		}
 	}
 
 	return( rc );
 }
 
@@ -561,17 +561,17 @@ read1msg( LDAP *ld, int msgid, int all, 
 	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 && nsldapi_alloc_ber_with_options( ld,
@@ -618,30 +618,30 @@ read1msg( LDAP *ld, int msgid, int all, 
 	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,
+		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",
+	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;
 	}
@@ -746,19 +746,19 @@ read1msg( LDAP *ld, int msgid, int all, 
 			 *  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,
+				LDAPDebug1( LDAP_DEBUG_TRACE,
 				    "request %d done\n", id, 0, 0 );
-LDAPDebug( LDAP_DEBUG_TRACE,
+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;
 					}
@@ -843,29 +843,29 @@ lr->lr_res_matched ? lr->lr_res_matched 
 			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,
+		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,
+	LDAPDebug3( 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 );
+        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.
@@ -985,17 +985,17 @@ lr->lr_res_matched ? lr->lr_res_matched 
  */
 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;
 	}
@@ -1052,23 +1052,23 @@ check_for_refs( LDAP *ld, LDAPRequest *l
 		/* 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,
+	LDAPDebug2( 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",
+	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 );
-	LDAPDebug( LDAP_DEBUG_TRACE,
+	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 )
@@ -1130,19 +1130,19 @@ merge_error_info( LDAP *ld, LDAPRequest 
 			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:  ",
+	LDAPDebug1( 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",
+	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! */
@@ -1182,18 +1182,19 @@ cldap_select1( LDAP *ld, struct timeval 
 
 		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",
+		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 */
 
 
@@ -1237,17 +1238,17 @@ cldap_select1( LDAP *ld, struct timeval 
 
 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 );
 	}
 
@@ -1260,17 +1261,17 @@ ldap_msgfree( LDAPMessage *lm )
  *	-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 ) {
@@ -1388,17 +1389,17 @@ cldap_getmsg( LDAP *ld, struct timeval *
 }
 #endif /* CLDAP */
 
 int
 nsldapi_post_result( LDAP *ld, int msgid, LDAPMessage *result )
 {
 	LDAPPend	*lp;
 
-	LDAPDebug( LDAP_DEBUG_TRACE,
+	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 )
--- a/ldap/c-sdk/libraries/libldap/saslbind.c
+++ b/ldap/c-sdk/libraries/libldap/saslbind.c
@@ -304,17 +304,17 @@ nsldapi_sasl_bind_s(
     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 );
@@ -377,28 +377,28 @@ nsldapi_sasl_do_bind( LDAP *ld, const ch
 
         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",
+        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",
+                LDAPDebug2(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 );
@@ -423,17 +423,17 @@ nsldapi_sasl_do_bind( LDAP *ld, const ch
                     /* 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",
+                LDAPDebug2(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 ) {
@@ -444,37 +444,37 @@ nsldapi_sasl_do_bind( LDAP *ld, const ch
                         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,
+                                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,
+                                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(LDAP_DEBUG_TRACE, "Doing client step %d of bind step %d for SASL/%s authentication\n",
+                        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 );
@@ -499,23 +499,23 @@ nsldapi_sasl_do_bind( LDAP *ld, const ch
         }
 
         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,
+                        LDAPDebug1(LDAP_DEBUG_TRACE,
                                 "SASL install encryption, for SSF: %lu\n",
                                 (unsigned long) *ssf, 0, 0 );
                         nsldapi_sasl_install( ld, NULL );
                 }
         }
 
         return( rc );
 }
@@ -564,17 +564,17 @@ ldap_sasl_bind(
 	 *	}
 	 *	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 );
@@ -738,17 +738,17 @@ ldap_sasl_interactive_bind_ext_s( LDAP *
         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 );
         }
@@ -810,17 +810,17 @@ ldap_parse_sasl_bind_result(
 )
 {
 	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
@@ -64,17 +64,17 @@ static int simple_bind_nolock( LDAP *ld,
  */
 
 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 );
 	}
@@ -166,17 +166,17 @@ simple_bind_nolock( LDAP *ld, const char
  */
 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 ) );
 
@@ -184,17 +184,17 @@ ldap_simple_bind_s( LDAP *ld, const char
 		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
@@ -98,17 +98,17 @@ ldap_search(
     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 */
 	}
 }
@@ -169,17 +169,17 @@ nsldapi_search(
     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 = "";
 	}
@@ -469,60 +469,60 @@ put_filter( BerElement *ber, char *str )
 	 *                      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",
+				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",
+				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",
+				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,
+				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 == '(' )
@@ -547,30 +547,30 @@ put_filter( BerElement *ber, char *str )
 				*next++ = ')';
 				str = next;
 				parens--;
 				break;
 			}
 			break;
 
 		case ')':
-			LDAPDebug( LDAP_DEBUG_TRACE, "put_filter: end\n", 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,
+			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;
 		}
@@ -585,17 +585,17 @@ put_filter( BerElement *ber, char *str )
  */
 
 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 )
@@ -671,17 +671,17 @@ put_simple_filter( BerElement *ber, char
 {
 	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 ) {
@@ -865,17 +865,17 @@ hexchar2int( char c )
 
 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,
+	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 ) {
--- a/ldap/c-sdk/libraries/libldap/tmplout.c
+++ b/ldap/c-sdk/libraries/libldap/tmplout.c
@@ -98,17 +98,17 @@ ldap_entry2text(
 	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 ));
 
 }
 
 
 
@@ -125,17 +125,17 @@ ldap_entry2html(
 	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 ));
 }
@@ -401,17 +401,17 @@ ldap_entry2text_search(
 	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
@@ -427,17 +427,17 @@ ldap_entry2html_search(
 	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(
@@ -578,17 +578,17 @@ ldap_vals2text(
 	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
@@ -601,17 +601,17 @@ ldap_vals2html(
 	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
@@ -50,17 +50,17 @@ static char copyright[] = "@(#) Copyrigh
 #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 )
@@ -194,17 +194,17 @@ ldap_ld_free( LDAP *ld, LDAPControl **se
 
 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 */
--- a/ldap/c-sdk/libraries/libldap/url.c
+++ b/ldap/c-sdk/libraries/libldap/url.c
@@ -183,17 +183,17 @@ ldap_url_parse( const char *url, LDAPURL
 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 )) {