Blame SOURCES/0032-49227-ldapsearch-for-nsslapd-errorlog-level-re.patch

61f723
From e5f78f9f6a8cab7bfbd33e14912508183f9da283 Mon Sep 17 00:00:00 2001
61f723
From: Mark Reynolds <mreynolds@redhat.com>
61f723
Date: Thu, 20 Apr 2017 15:01:33 -0400
61f723
Subject: [PATCH] Issue 49227 - ldapsearch for nsslapd-errorlog-level returns 
61f723
 incorrect values
61f723
61f723
Bug Description:  ldapsearch for the error log level returns the internal
61f723
                  bitmask value and not the value set in cn=config.
61f723
61f723
Fix Description:  When setting the error log level store the initial/untouched
61f723
                  value in the config entry first, then set the bitmasked
61f723
                  global log level variable.
61f723
61f723
https://pagure.io/389-ds-base/issue/49227
61f723
61f723
Reviewed by: nhosoi(Thanks!)
61f723
---
61f723
 dirsrvtests/tests/tickets/ticket49227_test.py | 111 ++++++++++++++++++++++++++
61f723
 ldap/servers/slapd/configdse.c                |   4 +-
61f723
 ldap/servers/slapd/libglobs.c                 |  11 +--
61f723
 ldap/servers/slapd/slap.h                     |   3 +-
61f723
 4 files changed, 121 insertions(+), 8 deletions(-)
61f723
 create mode 100644 dirsrvtests/tests/tickets/ticket49227_test.py
61f723
61f723
diff --git a/dirsrvtests/tests/tickets/ticket49227_test.py b/dirsrvtests/tests/tickets/ticket49227_test.py
61f723
new file mode 100644
61f723
index 0000000..86e0b9a
61f723
--- /dev/null
61f723
+++ b/dirsrvtests/tests/tickets/ticket49227_test.py
61f723
@@ -0,0 +1,111 @@
61f723
+import os
61f723
+import time
61f723
+import ldap
61f723
+import logging
61f723
+import pytest
61f723
+from lib389._constants import *
61f723
+from lib389.properties import *
61f723
+from lib389.tasks import *
61f723
+from lib389.utils import *
61f723
+from lib389.topologies import topology_st as topo
61f723
+
61f723
+DEBUGGING = os.getenv("DEBUGGING", default=False)
61f723
+if DEBUGGING:
61f723
+    logging.getLogger(__name__).setLevel(logging.DEBUG)
61f723
+else:
61f723
+    logging.getLogger(__name__).setLevel(logging.INFO)
61f723
+log = logging.getLogger(__name__)
61f723
+DEFAULT_LEVEL = "16384"
61f723
+
61f723
+
61f723
+def set_level(topo, level):
61f723
+    ''' Set the error log level
61f723
+    '''
61f723
+    try:
61f723
+        topo.standalone.modify_s("cn=config", [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', level)])
61f723
+        time.sleep(1)
61f723
+    except ldap.LDAPError as e:
61f723
+        log.fatal('Failed to set loglevel to %s - error: %s' % (level, str(e)))
61f723
+        assert False
61f723
+
61f723
+
61f723
+def get_level(topo):
61f723
+    ''' Set the error log level
61f723
+    '''
61f723
+    try:
61f723
+        config = topo.standalone.search_s("cn=config", ldap.SCOPE_BASE, "objectclass=top")
61f723
+        time.sleep(1)
61f723
+        return config[0].getValue('nsslapd-errorlog-level')
61f723
+    except ldap.LDAPError as e:
61f723
+        log.fatal('Failed to get loglevel - error: %s' % (str(e)))
61f723
+        assert False
61f723
+
61f723
+
61f723
+def get_log_size(topo):
61f723
+    ''' Get the errors log size
61f723
+    '''
61f723
+    statinfo = os.stat(topo.standalone.errlog)
61f723
+    return statinfo.st_size
61f723
+
61f723
+
61f723
+def test_ticket49227(topo):
61f723
+    """Set the error log to varying levels, and make sure a search for that value
61f723
+    reflects the expected value (not the bitmasked value.
61f723
+    """
61f723
+    log_size = get_log_size(topo)
61f723
+
61f723
+    # Check the default level
61f723
+    level = get_level(topo)
61f723
+    if level != DEFAULT_LEVEL:
61f723
+        log.fatal('Incorrect default logging level: %s' % (level))
61f723
+        assert False
61f723
+
61f723
+    # Set connection logging
61f723
+    set_level(topo, '8')
61f723
+    level = get_level(topo)
61f723
+    if level != '8':
61f723
+        log.fatal('Incorrect connection logging level: %s' % (level))
61f723
+        assert False
61f723
+
61f723
+    # Check the actual log
61f723
+    new_size = get_log_size(topo)
61f723
+    if new_size == log_size:
61f723
+        # Size should be different
61f723
+        log.fatal('Connection logging is not working')
61f723
+        assert False
61f723
+
61f723
+    # Set default logging using zero
61f723
+    set_level(topo, '0')
61f723
+    log_size = get_log_size(topo)
61f723
+    level = get_level(topo)
61f723
+    if level != DEFAULT_LEVEL:
61f723
+        log.fatal('Incorrect default logging level: %s' % (level))
61f723
+        assert False
61f723
+
61f723
+    # Check the actual log
61f723
+    new_size = get_log_size(topo)
61f723
+    if new_size != log_size:
61f723
+        # Size should be the size
61f723
+        log.fatal('Connection logging is still on')
61f723
+        assert False
61f723
+
61f723
+    # Set default logging using the default value
61f723
+    set_level(topo, DEFAULT_LEVEL)
61f723
+    level = get_level(topo)
61f723
+    if level != DEFAULT_LEVEL:
61f723
+        log.fatal('Incorrect default logging level: %s' % (level))
61f723
+        assert False
61f723
+
61f723
+    # Check the actual log
61f723
+    new_size = get_log_size(topo)
61f723
+    if new_size != log_size:
61f723
+        # Size should be the size
61f723
+        log.fatal('Connection logging is still on')
61f723
+        assert False
61f723
+
61f723
+if __name__ == '__main__':
61f723
+    # Run isolated
61f723
+    # -s for DEBUG mode
61f723
+    CURRENT_FILE = os.path.realpath(__file__)
61f723
+    pytest.main("-s %s" % CURRENT_FILE)
61f723
+
61f723
diff --git a/ldap/servers/slapd/configdse.c b/ldap/servers/slapd/configdse.c
61f723
index 78162c9..08d1ace 100644
61f723
--- a/ldap/servers/slapd/configdse.c
61f723
+++ b/ldap/servers/slapd/configdse.c
61f723
@@ -404,12 +404,12 @@ modify_config_dse(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, in
61f723
 						config_attr);
61f723
 					rc = LDAP_UNWILLING_TO_PERFORM;
61f723
 			} else if (ignore_attr_type(config_attr)) {
61f723
-					slapi_log_err(SLAPI_LOG_WARNING, "modify_config_dse",
61f723
+					slapi_log_err(SLAPI_LOG_CONFIG, "modify_config_dse",
61f723
 						"Modification of attribute \"%s\" is not allowed, ignoring!\n",
61f723
 						config_attr);
61f723
 			} else if (SLAPI_IS_MOD_ADD(mods[i]->mod_op)) {
61f723
 				if (apply_mods) { /* log warning once */
61f723
-					slapi_log_err(SLAPI_LOG_WARNING, "modify_config_dse", 
61f723
+					slapi_log_err(SLAPI_LOG_CONFIG, "modify_config_dse",
61f723
 						"Adding configuration attribute \"%s\"\n",
61f723
 						config_attr);
61f723
 				}
61f723
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
61f723
index 2fc9fbf..bb51827 100644
61f723
--- a/ldap/servers/slapd/libglobs.c
61f723
+++ b/ldap/servers/slapd/libglobs.c
61f723
@@ -308,7 +308,7 @@ static struct config_get_and_set {
61f723
 	{CONFIG_LOGLEVEL_ATTRIBUTE, config_set_errorlog_level,
61f723
 		NULL, 0,
61f723
 		(void**)&global_slapdFrontendConfig.errorloglevel,
61f723
-		CONFIG_SPECIAL_ERRORLOGLEVEL, NULL, SLAPD_DEFAULT_ERRORLOG_LEVEL_STR},
61f723
+		CONFIG_SPECIAL_ERRORLOGLEVEL, NULL, SLAPD_DEFAULT_FE_ERRORLOG_LEVEL_STR},
61f723
 	{CONFIG_ERRORLOG_LOGGING_ENABLED_ATTRIBUTE, NULL,
61f723
 		log_set_logging, SLAPD_ERROR_LOG,
61f723
 		(void**)&global_slapdFrontendConfig.errorlog_logging_enabled,
61f723
@@ -1597,7 +1597,7 @@ FrontendConfig_init(void) {
61f723
     cfg->errorlog_minfreespace = SLAPD_DEFAULT_LOG_MINFREESPACE;
61f723
     cfg->errorlog_exptime = SLAPD_DEFAULT_LOG_EXPTIME;
61f723
     cfg->errorlog_exptimeunit = slapi_ch_strdup(SLAPD_INIT_LOG_EXPTIMEUNIT);
61f723
-    cfg->errorloglevel = SLAPD_DEFAULT_ERRORLOG_LEVEL;
61f723
+    cfg->errorloglevel = SLAPD_DEFAULT_FE_ERRORLOG_LEVEL;
61f723
 
61f723
     init_auditlog_logging_enabled = cfg->auditlog_logging_enabled = LDAP_OFF;
61f723
     cfg->auditlog_mode = slapi_ch_strdup(SLAPD_INIT_LOG_MODE);
61f723
@@ -4474,9 +4474,10 @@ config_set_errorlog_level( const char *attrname, char *value, char *errorbuf, in
61f723
   
61f723
   if ( apply ) {
61f723
 	CFG_LOCK_WRITE(slapdFrontendConfig);
61f723
-	level |= SLAPD_DEFAULT_ERRORLOG_LEVEL; /* Always apply the new default error levels for now */
61f723
-	slapd_ldap_debug = level;
61f723
 	slapdFrontendConfig->errorloglevel = level;
61f723
+	/* Set the internal value - apply the default error level */
61f723
+	level |= SLAPD_DEFAULT_ERRORLOG_LEVEL;
61f723
+	slapd_ldap_debug = level;
61f723
 	CFG_UNLOCK_WRITE(slapdFrontendConfig);
61f723
   }
61f723
   return retVal;
61f723
@@ -5771,7 +5772,7 @@ config_get_errorlog_level(){
61f723
   retVal = slapdFrontendConfig->errorloglevel;
61f723
   CFG_UNLOCK_READ(slapdFrontendConfig);
61f723
   
61f723
-  return retVal; 
61f723
+  return retVal |= SLAPD_DEFAULT_ERRORLOG_LEVEL;
61f723
 }
61f723
 
61f723
 /*  return integer -- don't worry about locking similar to config_check_referral_mode 
61f723
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
61f723
index 5e44cc8..04c9b79 100644
61f723
--- a/ldap/servers/slapd/slap.h
61f723
+++ b/ldap/servers/slapd/slap.h
61f723
@@ -343,7 +343,8 @@ typedef void	(*VFPV)(); /* takes undefined arguments */
61f723
  *  LDAP_DEBUG_WARNING | LDAP_DEBUG_NOTICE | LDAP_DEBUG_INFO)
61f723
  */
61f723
 #define SLAPD_DEFAULT_ERRORLOG_LEVEL            266354688
61f723
-#define SLAPD_DEFAULT_ERRORLOG_LEVEL_STR        "266354688"
61f723
+#define SLAPD_DEFAULT_FE_ERRORLOG_LEVEL         16384  /* frontend log level */
61f723
+#define SLAPD_DEFAULT_FE_ERRORLOG_LEVEL_STR     "16384"
61f723
 #define SLAPD_DEFAULT_ACCESSLOG_LEVEL           256
61f723
 #define SLAPD_DEFAULT_ACCESSLOG_LEVEL_STR       "256"
61f723
 
61f723
-- 
61f723
2.9.3
61f723