From df7329de190029158c05814bdff8973143808295 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Fri, 30 Oct 2009 18:52:52 +0000
Subject: [PATCH] ITS#6324

---
 CHANGES                 |  1 +
 include/ldap_log.h      |  2 +-
 servers/slapd/bconfig.c | 10 ++++++----
 servers/slapd/main.c    | 13 ++++++++++++-
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/CHANGES b/CHANGES
index f2c4174fe5..ef981c9280 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,7 @@
 OpenLDAP 2.4 Change Log
 
 OpenLDAP 2.4.20 Engineering
+	Fixed slapd debug handling of LDAP_DEBUG_ANY (ITS#6324)
 
 OpenLDAP 2.4.19 Release (2009/10/06)
 	Fixed client tools with null timeouts (ITS#6282)
diff --git a/include/ldap_log.h b/include/ldap_log.h
index fb7a75f7aa..4296a5de25 100644
--- a/include/ldap_log.h
+++ b/include/ldap_log.h
@@ -123,7 +123,7 @@ LDAP_BEGIN_DECL
 #define LDAP_DEBUG_SYNC		0x4000
 
 #define LDAP_DEBUG_NONE		0x8000
-#define LDAP_DEBUG_ANY		-1
+#define LDAP_DEBUG_ANY		(-1)
 
 /* debugging stuff */
 #ifdef LDAP_DEBUG
diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c
index a7f4bd35b7..e02d90e89b 100644
--- a/servers/slapd/bconfig.c
+++ b/servers/slapd/bconfig.c
@@ -3050,7 +3050,7 @@ static int
 loglevel_init( void )
 {
 	slap_verbmasks	lo[] = {
-		{ BER_BVC("Any"),	-1 },
+		{ BER_BVC("Any"),	(slap_mask_t) LDAP_DEBUG_ANY },
 		{ BER_BVC("Trace"),	LDAP_DEBUG_TRACE },
 		{ BER_BVC("Packets"),	LDAP_DEBUG_PACKETS },
 		{ BER_BVC("Args"),	LDAP_DEBUG_ARGS },
@@ -3202,9 +3202,11 @@ loglevel_print( FILE *out )
 
 	fprintf( out, "Installed log subsystems:\n\n" );
 	for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
-		fprintf( out, "\t%-30s (%lu)\n",
-			loglevel_ops[ i ].word.bv_val,
-			loglevel_ops[ i ].mask );
+		unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
+		fprintf( out,
+			(mask == ((slap_mask_t) -1 & 0xffffffffUL)
+			 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
+			loglevel_ops[ i ].word.bv_val, mask, mask );
 	}
 
 	fprintf( out, "\nNOTE: custom log subsystems may be later installed "
diff --git a/servers/slapd/main.c b/servers/slapd/main.c
index 14fadd6b1a..2fc052369b 100644
--- a/servers/slapd/main.c
+++ b/servers/slapd/main.c
@@ -270,7 +270,18 @@ parse_debug_level( const char *arg, int *levelp, char ***unknowns )
 		ldap_charray_free( levels );
 
 	} else {
-		if ( lutil_atoix( &level, arg, 0 ) != 0 ) {
+		int rc;
+
+		if ( arg[0] == '-' ) {
+			rc = lutil_atoix( &level, arg, 0 );
+		} else {
+			unsigned ulevel;
+
+			rc = lutil_atoux( &ulevel, arg, 0 );
+			level = (int)ulevel;
+		}
+
+		if ( rc ) {
 			fprintf( stderr,
 				"unrecognized log level "
 				"\"%s\"\n", arg );
-- 
GitLab