andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

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

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