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

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