From b55c407f8b83d19a8ac31aacb45c9633fa9bed9e Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Thu, 20 Apr 2017 16:01:50 -0400 Subject: [PATCH] Issue 48978 - Fix the emergency logging functions severity levels Description: We have duplicate CRITICAL messages, and we were not properly setting the emergency log severity level. https://pagure.io/389-ds-base/issue/48978 Reviewed by: ? --- ldap/servers/plugins/addn/addn.c | 36 ++++++++++++++++++------------------ ldap/servers/slapd/log.c | 24 ++++++++++++------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ldap/servers/plugins/addn/addn.c b/ldap/servers/plugins/addn/addn.c index 6ba7833..e4b6ed9 100644 --- a/ldap/servers/plugins/addn/addn.c +++ b/ldap/servers/plugins/addn/addn.c @@ -96,7 +96,7 @@ addn_get_subconfig(Slapi_PBlock *pb, char *identifier) search_pblock = slapi_pblock_new(); if (search_pblock == NULL) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: CRITICAL: Unable to allocate search_pblock!!!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: Unable to allocate search_pblock!!!\n"); goto out; } @@ -108,7 +108,7 @@ addn_get_subconfig(Slapi_PBlock *pb, char *identifier) search_result = slapi_pblock_get(search_pblock, SLAPI_PLUGIN_INTOP_RESULT, &search_result); if (search_result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: CRITICAL: Internal search pblock get failed!!!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: Internal search pblock get failed!!!\n"); goto out; } @@ -119,7 +119,7 @@ addn_get_subconfig(Slapi_PBlock *pb, char *identifier) /* On all other errors, just fail out. */ if (search_result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_PLUGIN, plugin_name, "addn_get_subconfig: CRITICAL: Internal search error occured %d \n", search_result); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: Internal search error occurred %d \n", search_result); goto out; } @@ -127,7 +127,7 @@ addn_get_subconfig(Slapi_PBlock *pb, char *identifier) search_result = slapi_pblock_get(search_pblock, SLAPI_NENTRIES, &entry_count); if (search_result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: CRITICAL: Unable to retrieve number of entries from pblock!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: Unable to retrieve number of entries from pblock!\n"); goto out; } /* If there are multiple results, we should also fail as we cannot */ @@ -135,13 +135,13 @@ addn_get_subconfig(Slapi_PBlock *pb, char *identifier) if (entry_count != 1) { /* Is there a better log level for this? */ - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: WARNING, multiple or no results returned. Failing to auth ...\n"); + slapi_log_err(SLAPI_LOG_WARNING, plugin_name, "addn_get_subconfig: multiple or no results returned. Failing to auth ...\n"); goto out; } search_result = slapi_pblock_get(search_pblock, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries); if (search_result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: CRITICAL: Unable to retrieve entries from pblock!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_get_subconfig: Unable to retrieve entries from pblock!\n"); goto out; } @@ -209,7 +209,7 @@ addn_prebind(Slapi_PBlock *pb) result = slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &config); if (result != LDAP_SUCCESS || config == NULL) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: CRITICAL: Unable to retrieve plugin configuration!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: Unable to retrieve plugin configuration!\n"); result = ADDN_FAILURE; goto out; } @@ -267,7 +267,7 @@ addn_prebind(Slapi_PBlock *pb) /* Validate the filter_template only has one %s */ if (addn_filter_validate(config_filter) != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: CRITICAL: Failed to validate addn_filter %s for domain %s\n", config_filter, dn_domain_escaped); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: Failed to validate addn_filter %s for domain %s\n", config_filter, dn_domain_escaped); result = ADDN_FAILURE; goto out; } @@ -281,7 +281,7 @@ addn_prebind(Slapi_PBlock *pb) search_pblock = slapi_pblock_new(); if (search_pblock == NULL) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: CRITICAL: Unable to allocate search_pblock!!!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: Unable to allocate search_pblock!!!\n"); result = ADDN_FAILURE; goto out; } @@ -294,7 +294,7 @@ addn_prebind(Slapi_PBlock *pb) result = slapi_pblock_get(search_pblock, SLAPI_PLUGIN_INTOP_RESULT, &search_result); if (result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: CRITICAL: Internal search pblock get failed!!!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: Internal search pblock get failed!!!\n"); result = ADDN_FAILURE; goto out; } @@ -314,7 +314,7 @@ addn_prebind(Slapi_PBlock *pb) /* On all other errors, just fail out. */ if (search_result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_PLUGIN, plugin_name, "addn_prebind: CRITICAL: Internal search error occured %d \n", search_result); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: Internal search error occurred %d \n", search_result); result = ADDN_FAILURE; goto out; } @@ -323,7 +323,7 @@ addn_prebind(Slapi_PBlock *pb) result = slapi_pblock_get(search_pblock, SLAPI_NENTRIES, &entry_count); if (result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: CRITICAL: Unable to retrieve number of entries from pblock!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: Unable to retrieve number of entries from pblock!\n"); result = ADDN_FAILURE; goto out; } @@ -332,14 +332,14 @@ addn_prebind(Slapi_PBlock *pb) if (entry_count > 1) { /* Is there a better log level for this? */ - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: WARNING, multiple results returned. Failing to auth ...\n"); + slapi_log_err(SLAPI_LOG_WARNING, plugin_name, "addn_prebind: multiple results returned. Failing to auth ...\n"); result = ADDN_FAILURE; goto out; } result = slapi_pblock_get(search_pblock, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries); if (result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: CRITICAL: Unable to retrieve entries from pblock!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: Unable to retrieve entries from pblock!\n"); result = ADDN_FAILURE; goto out; } @@ -356,7 +356,7 @@ addn_prebind(Slapi_PBlock *pb) /* Free the original SDN */ result = slapi_pblock_set(pb, SLAPI_TARGET_SDN, pb_sdn_mapped); if (result != LDAP_SUCCESS) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: CRITICAL: Unable to set new mapped DN to pblock!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_prebind: Unable to set new mapped DN to pblock!\n"); /* We have to free the mapped SDN here */ slapi_sdn_free(&pb_sdn_mapped); result = ADDN_FAILURE; @@ -404,7 +404,7 @@ addn_start(Slapi_PBlock *pb) /* It looks like we mis-use the SLAPI_ADD_ENTRY space in PB during plugin startup */ result = slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &plugin_entry); if (result != LDAP_SUCCESS || plugin_entry == NULL) { - slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_start: CRITICAL: Failed to retrieve config entry!\n"); + slapi_log_err(SLAPI_LOG_ERR, plugin_name, "addn_start: Failed to retrieve config entry!\n"); return SLAPI_PLUGIN_FAILURE; } @@ -416,7 +416,7 @@ addn_start(Slapi_PBlock *pb) if (domain == NULL) { slapi_log_err(SLAPI_LOG_ERR, plugin_name, - "addn_start: CRITICAL: No default domain in configuration, you must set addn_default_domain!\n"); + "addn_start: No default domain in configuration, you must set addn_default_domain!\n"); slapi_ch_free((void**)&config); return SLAPI_PLUGIN_FAILURE; } @@ -498,7 +498,7 @@ addn_init(Slapi_PBlock *pb) out: if (result == LDAP_SUCCESS) { slapi_log_err(SLAPI_LOG_PLUGIN, plugin_name, "addn_init: Success: plugin loaded.\n"); - slapi_log_err(SLAPI_LOG_WARNING, plugin_name, "addn_init: WARNING: The use of this plugin violates the LDAPv3 specification RFC4511 section 4.2 BindDN specification. You have been warned ...\n"); + slapi_log_err(SLAPI_LOG_WARNING, plugin_name, "addn_init: The use of this plugin violates the LDAPv3 specification RFC4511 section 4.2 BindDN specification. You have been warned ...\n"); } else { slapi_log_err(SLAPI_LOG_PLUGIN, plugin_name, "addn_init: Error: %d. \n", result); } diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c index 7a5d688..199496a 100644 --- a/ldap/servers/slapd/log.c +++ b/ldap/servers/slapd/log.c @@ -2255,11 +2255,11 @@ vslapd_log_emergency_error(LOGFD fp, const char *msg, int locked) if (logging_hr_timestamps_enabled == 1) { struct timespec tsnow; if (clock_gettime(CLOCK_REALTIME, &tsnow) != 0) { - syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to determine system time for message :: %s", msg); + syslog(LOG_EMERG, "vslapd_log_emergency_error, Unable to determine system time for message :: %s", msg); return; } if (format_localTime_hr_log(tsnow.tv_sec, tsnow.tv_nsec, sizeof(tbuf), tbuf, &size) != 0) { - syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to format system time for message :: %s", msg); + syslog(LOG_EMERG, "vslapd_log_emergency_error, Unable to format system time for message :: %s", msg); return; } } else { @@ -2267,14 +2267,14 @@ vslapd_log_emergency_error(LOGFD fp, const char *msg, int locked) time_t tnl; tnl = current_time(); if (format_localTime_log(tnl, sizeof(tbuf), tbuf, &size) != 0) { - syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to format system time for message :: %s", msg); + syslog(LOG_EMERG, "vslapd_log_emergency_error, Unable to format system time for message :: %s", msg); return; } #ifdef HAVE_CLOCK_GETTIME } #endif - PR_snprintf( buffer, sizeof(buffer), "%s - %s", tbuf, msg); + PR_snprintf( buffer, sizeof(buffer), "%s - EMERG - %s", tbuf, msg); size = strlen(buffer); if(!locked) { @@ -2332,7 +2332,7 @@ vslapd_log_error( int err = 0; if (vasprintf(&vbuf, fmt, ap) == -1) { - log__error_emergency("CRITICAL: vslapd_log_error, Unable to format message", 1 , locked); + log__error_emergency("vslapd_log_error, Unable to format message", 1 , locked); return -1; } @@ -2340,13 +2340,13 @@ vslapd_log_error( if (logging_hr_timestamps_enabled == 1) { struct timespec tsnow; if (clock_gettime(CLOCK_REALTIME, &tsnow) != 0) { - PR_snprintf(buffer, sizeof(buffer), "CRITICAL: vslapd_log_error, Unable to determine system time for message :: %s", vbuf); + PR_snprintf(buffer, sizeof(buffer), "vslapd_log_error, Unable to determine system time for message :: %s", vbuf); log__error_emergency(buffer, 1 ,locked); return -1; } if (format_localTime_hr_log(tsnow.tv_sec, tsnow.tv_nsec, sizeof(buffer), buffer, &blen) != 0) { /* MSG may be truncated */ - PR_snprintf(buffer, sizeof(buffer), "CRITICAL: vslapd_log_error, Unable to format system time for message :: %s", vbuf); + PR_snprintf(buffer, sizeof(buffer), "vslapd_log_error, Unable to format system time for message :: %s", vbuf); log__error_emergency(buffer, 1 ,locked); return -1; } @@ -2355,7 +2355,7 @@ vslapd_log_error( time_t tnl; tnl = current_time(); if (format_localTime_log(tnl, sizeof(buffer), buffer, &blen) != 0) { - PR_snprintf(buffer, sizeof(buffer), "CRITICAL: vslapd_log_error, Unable to format system time for message :: %s", vbuf); + PR_snprintf(buffer, sizeof(buffer), "vslapd_log_error, Unable to format system time for message :: %s", vbuf); log__error_emergency(buffer, 1 ,locked); return -1; } @@ -2521,7 +2521,7 @@ static int vslapd_log_access(char *fmt, va_list ap) /* We do this sooner, because that we we can use the message in other calls */ if ((vlen = vsnprintf(vbuf, SLAPI_LOG_BUFSIZ, fmt, ap)) == -1){ - log__error_emergency("CRITICAL: vslapd_log_access, Unable to format message", 1 ,0); + log__error_emergency("vslapd_log_access, Unable to format message", 1 ,0); return -1; } @@ -2530,14 +2530,14 @@ static int vslapd_log_access(char *fmt, va_list ap) struct timespec tsnow; if (clock_gettime(CLOCK_REALTIME, &tsnow) != 0) { /* Make an error */ - PR_snprintf(buffer, sizeof(buffer), "CRITICAL: vslapd_log_access, Unable to determine system time for message :: %s", vbuf); + PR_snprintf(buffer, sizeof(buffer), "vslapd_log_access, Unable to determine system time for message :: %s", vbuf); log__error_emergency(buffer, 1 ,0); return -1; } tnl = tsnow.tv_sec; if (format_localTime_hr_log(tsnow.tv_sec, tsnow.tv_nsec, sizeof(buffer), buffer, &blen) != 0) { /* MSG may be truncated */ - PR_snprintf(buffer, sizeof(buffer), "CRITICAL: vslapd_log_access, Unable to format system time for message :: %s", vbuf); + PR_snprintf(buffer, sizeof(buffer), "vslapd_log_access, Unable to format system time for message :: %s", vbuf); log__error_emergency(buffer, 1 ,0); return -1; } @@ -2546,7 +2546,7 @@ static int vslapd_log_access(char *fmt, va_list ap) tnl = current_time(); if (format_localTime_log(tnl, sizeof(buffer), buffer, &blen) != 0) { /* MSG may be truncated */ - PR_snprintf(buffer, sizeof(buffer), "CRITICAL: vslapd_log_access, Unable to format system time for message :: %s", vbuf); + PR_snprintf(buffer, sizeof(buffer), "vslapd_log_access, Unable to format system time for message :: %s", vbuf); log__error_emergency(buffer, 1 ,0); return -1; } -- 2.9.3