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

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