From 82959c3533aab7b58116c94481d078ea61a0cb2c Mon Sep 17 00:00:00 2001
From: William Brown <firstyear@redhat.com>
Date: Tue, 9 Feb 2016 11:47:17 +1030
Subject: [PATCH] Ticket 47968 - Fix for issues with multiple log backends

Bug Description:

* Did not correctly use str formats in the output to journald_print
* Due to a change strcmp api, the values were not checked properly
* The default template did not have the correct backend value

Fix Description:
* Correctly use string formats to avoid compilation errors
* Fix the check for values of strcmp
* Fix the template to include dirsrv-log
* The rpm spec to include the correct systemd libraries

https://fedorahosted.org/389/ticket/47968

Author: wibrown

Review by: ????

fixes
---
 ldap/ldif/template-dse.ldif.in |  2 +-
 ldap/servers/slapd/log.c       | 28 +++++++++++++---------------
 rpm/389-ds-base.spec.in        |  5 +++++
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/ldap/ldif/template-dse.ldif.in b/ldap/ldif/template-dse.ldif.in
index 6c62aaa..f18c082 100644
--- a/ldap/ldif/template-dse.ldif.in
+++ b/ldap/ldif/template-dse.ldif.in
@@ -62,7 +62,7 @@ nsslapd-ndn-cache-enabled: on
 nsslapd-sasl-mapping-fallback: off
 nsslapd-dynamic-plugins: off
 nsslapd-allow-hashed-passwords: off
-nsslapd-logging-backend: 1
+nsslapd-logging-backend: dirsrv-log
 
 dn: cn=features,cn=config
 objectclass: top
diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c
index 07bc762..8b22297 100644
--- a/ldap/servers/slapd/log.c
+++ b/ldap/servers/slapd/log.c
@@ -393,21 +393,18 @@ log_set_logging(const char *attrname, char *value, int logtype, char *errorbuf,
 int
 log_set_backend(const char *attrname, char *value, int logtype, char *errorbuf, int apply) {
 
-    int retval = LDAP_SUCCESS;
     int backend = 0;
     char *backendstr = NULL; /* The backend we are looking at */
     char *token = NULL; /* String to tokenise, need to dup value */
     char *next = NULL; /* The next value */
 
-
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
 
     /* We don't need to bother checking log type ... */
-    if ( !apply || !value || !*value ) {
-        return retval;
+    if ( !value || !*value ) {
+        return LDAP_OPERATIONS_ERROR;
     }
 
-
     /* We have a comma seperated list. So split it up */
     token = slapi_ch_strdup(value);
     for (backendstr = ldap_utf8strtok_r(token, ",", &next);
@@ -417,12 +414,12 @@ log_set_backend(const char *attrname, char *value, int logtype, char *errorbuf,
         if(strlen(backendstr) == 0) {
             /* Probably means someone did ",,"*/
             continue;
-        } else if (slapi_UTF8NCASECMP(backendstr, "dirsrv-log", 10) ) {
+        } else if (slapi_UTF8NCASECMP(backendstr, "dirsrv-log", 10) == 0 ) {
             backend |= LOGGING_BACKEND_INTERNAL;
-        } else if (slapi_UTF8NCASECMP(backendstr, "syslog", 6) ) {
+        } else if (slapi_UTF8NCASECMP(backendstr, "syslog", 6) == 0) {
             backend |= LOGGING_BACKEND_SYSLOG;
 #ifdef WITH_SYSTEMD
-        } else if (slapi_UTF8NCASECMP(backendstr, "journald", 8) ) {
+        } else if (slapi_UTF8NCASECMP(backendstr, "journald", 8) == 0 ) {
             backend |= LOGGING_BACKEND_JOURNALD;
 #endif
         }
@@ -436,20 +433,21 @@ log_set_backend(const char *attrname, char *value, int logtype, char *errorbuf,
 #endif
        ) {
         /* There is probably a better error here .... */
-        retval = LDAP_OPERATIONS_ERROR;
-    } else {
+        return LDAP_OPERATIONS_ERROR;
+    }
+    if ( apply ) {
         /* We have a valid backend, set it */
         /*
          * We just need to use any lock here, doesn't matter which. 
          */
-		LOG_ACCESS_LOCK_WRITE( );
+        LOG_ACCESS_LOCK_WRITE( );
         loginfo.log_backend = backend;
         slapi_ch_free_string(&(slapdFrontendConfig->logging_backend));
         slapdFrontendConfig->logging_backend = slapi_ch_strdup(value);
-		LOG_ACCESS_UNLOCK_WRITE( );
+        LOG_ACCESS_UNLOCK_WRITE( );
     }
 
-    return retval;
+    return LDAP_SUCCESS;
 }
 /******************************************************************************
 * Tell me  the access log file name inc path
@@ -1985,7 +1983,7 @@ slapd_log_audit (
     }
 #ifdef WITH_SYSTEMD
     if (lbackend & LOGGING_BACKEND_JOURNALD) {
-        retval = sd_journal_print(LOG_NOTICE, buffer);
+        retval = sd_journal_print(LOG_NOTICE, "%s", buffer);
     }
 #endif
     return retval;
@@ -2044,7 +2042,7 @@ slapd_log_auditfail (
     }
 #ifdef WITH_SYSTEMD
     if (lbackend & LOGGING_BACKEND_JOURNALD) {
-        retval = sd_journal_print(LOG_NOTICE, buffer);
+        retval = sd_journal_print(LOG_NOTICE, "%s", buffer);
     }
 #endif
     return retval;
diff --git a/rpm/389-ds-base.spec.in b/rpm/389-ds-base.spec.in
index 163bc33..28845e8 100644
--- a/rpm/389-ds-base.spec.in
+++ b/rpm/389-ds-base.spec.in
@@ -78,6 +78,7 @@ BuildRequires:    tcp_wrappers
 # the following is for the pam passthru auth plug-in
 BuildRequires:    pam-devel
 BuildRequires:    systemd-units
+BuildRequires:    systemd-devel
 
 # this is needed for using semanage from our setup scripts
 Requires:         policycoreutils-python
@@ -122,6 +123,7 @@ Requires:         perl-Socket6
 Requires:         perl-Socket
 %endif
 Requires:         perl-NetAddr-IP
+Requires:         systemd-libs
 
 Source0:          http://port389.org/sources/%{name}-%{version}%{?prerel}.tar.bz2
 # 389-ds-git.sh should be used to generate the source tarball from git
@@ -169,6 +171,7 @@ BuildRequires:    /usr/bin/xsltproc
 BuildRequires:    valgrind-devel
 %endif
 %endif
+BuildRequires:    systemd-devel
 
 %description      libs
 Core libraries for the 389 Directory Server base package.  These libraries
@@ -193,6 +196,8 @@ Requires:         libtalloc
 Requires:         libevent
 Requires:         libtevent
 %endif
+Requires:         systemd-libs
+
 
 %description      devel
 Development Libraries and headers for the 389 Directory Server base package.
-- 
1.8.3.1

