Switch to journal logging by default in all modules except cynara service.
This is to avoid libdlog dependency in client libraries.
Only cynara service may depend on libdlog and use it by providing a logging
callback to libcynara-commons.
Minor fixes and refactoring.
Change-Id: I15cf8dae915bd5863db79d27cad539cd7103ea34
%endif
%endif
+%if %{log_type} == "DLOG"
+BuildRequires: pkgconfig(dlog)
+%endif
+
%if !%{defined build_type}
%define build_type RELEASE
%endif
BuildRequires: pkgconfig(libsmack)
Obsoletes: libcynara-storage
-# alternatives: DLOG, JOURNAL, NONE, (otherwise SYSLOG is used)
+# alternatives: JOURNAL, NONE, (otherwise SYSLOG is used)
%if !%{defined log_type}
%if 0%{tizen_version_major} > 4
-%define log_type "DLOG"
+%define log_type "JOURNAL"
%else
%define log_type "SYSLOG"
%endif
%endif
-
-%if %{log_type} == "DLOG"
-BuildRequires: pkgconfig(dlog)
-%endif
-
%if %{log_type} == "JOURNAL"
BuildRequires: pkgconfig(libsystemd)
%endif
BuildRequires: pkgconfig(libsystemd)
BuildRequires: pkgconfig(dbus-1)
-# alternatives: DLOG, JOURNAL, NONE, (otherwise SYSLOG is used)
+# alternatives: JOURNAL, NONE, (otherwise SYSLOG is used)
%if !%{defined log_type}
%if 0%{tizen_version_major} > 4
-%define log_type "DLOG"
+%define log_type "JOURNAL"
%else
%define log_type "SYSLOG"
%endif
-# Copyright (c) 2014-2018 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
)
ENDIF (BUILD_WITH_SYSTEMD_DAEMON OR LOG_TYPE MATCHES "JOURNAL")
-IF (BUILD_COMMONS AND LOG_TYPE MATCHES "DLOG")
+IF (BUILD_SERVICE AND LOG_TYPE MATCHES "DLOG")
SET(COMMON_DEPS
${COMMON_DEPS}
dlog
)
-ENDIF (BUILD_COMMONS AND LOG_TYPE MATCHES "DLOG")
+ENDIF (BUILD_SERVICE AND LOG_TYPE MATCHES "DLOG")
IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
SET(COMMON_DEPS
-# Copyright (c) 2014-2019 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
)
ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
-IF (LOG_TYPE MATCHES "DLOG")
-SET(COMMON_SOURCES ${COMMON_SOURCES}
- ${COMMON_PATH}/log/DlogLog.cpp
- )
-ENDIF (LOG_TYPE MATCHES "DLOG")
-
ADD_DEFINITIONS("-fvisibility=default")
ADD_LIBRARY(${TARGET_CYNARA_COMMON} SHARED ${COMMON_SOURCES})
/*
- * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @brief This file implements privilege check logging utility.
*/
-#ifdef BUILD_WITH_SYSTEMD_JOURNAL
-#include <systemd/sd-journal.h>
-#elif defined(BUILD_WITH_DLOG)
-#include "DlogLog.h"
-#else
-#include <syslog.h>
-#endif
-
-
#include "AuditLog.h"
+#include "log.h"
+
namespace Cynara {
AuditLog::AuditLog() : m_logLevel(AL_DENY) {
if (m_logLevel == AL_ALL || (m_logLevel == AL_DENY && policyType == PPT::DENY) ||
(m_logLevel == AL_ALLOW && policyType == PPT::ALLOW) ||
- (m_logLevel == AL_OTHER && policyType != PPT::ALLOW && policyType != PPT::DENY)) {
+ (m_logLevel == AL_OTHER && policyType != PPT::ALLOW && policyType != PPT::DENY))
+ {
+ if (__log_callback) {
+ (*__log_callback)(LOG_INFO,
+ "CYNARA AUDIT MESSAGE=%s;%s;%s => %s",
+ policyKey.client().toString().c_str(),
+ policyKey.user().toString().c_str(),
+ policyKey.privilege().toString().c_str(),
+ policyResultToString(policyResult));
+ } else {
#ifdef BUILD_WITH_SYSTEMD_JOURNAL
- sd_journal_send("MESSAGE=%s;%s;%s => %s", policyKey.client().toString().c_str(),
+ sd_journal_send("MESSAGE=%s;%s;%s => %s",
+ policyKey.client().toString().c_str(),
policyKey.user().toString().c_str(),
policyKey.privilege().toString().c_str(),
- policyResultToString(policyResult), "PRIORITY=%i", LOG_INFO,
- "CYNARA_LOG_TYPE=AUDIT", NULL);
-#elif defined(BUILD_WITH_DLOG)
- cynara_dlog_print(LOG_INFO, "CYNARA AUDIT MESSAGE=%s;%s;%s => %s", policyKey.client().toString().c_str(),
- policyKey.user().toString().c_str(),
- policyKey.privilege().toString().c_str(),
- policyResultToString(policyResult));
+ policyResultToString(policyResult),
+ "PRIORITY=%i",
+ LOG_INFO,
+ "CYNARA_LOG_TYPE=AUDIT",
+ NULL);
#else
- syslog(LOG_INFO, "CYNARA AUDIT MESSAGE=%s;%s;%s => %s", policyKey.client().toString().c_str(),
+ syslog(LOG_INFO,
+ "CYNARA AUDIT MESSAGE=%s;%s;%s => %s",
+ policyKey.client().toString().c_str(),
policyKey.user().toString().c_str(),
policyKey.privilege().toString().c_str(),
policyResultToString(policyResult));
#endif
+ }
}
}
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * @file src/common/log/DlogLog.cpp
- * @author Tomasz Swierczek <t.swierczek@samsung.com>
- * @version 1.0
- * @brief This file implements loging functions on top of dlog
- */
-
-#include "DlogLog.h"
-
-#include <dlog.h>
-#include <stdlib.h>
-#include <syslog.h>
-
-#define CYNARA_DLOG_TAG "CYNARA"
-
-void cynara_dlog_print(int priority, char const *fmt, ...)
-{
- log_priority dlog_prio;
-
- switch (priority) {
- case LOG_EMERG:
- dlog_prio = DLOG_FATAL;
- break;
- case LOG_ALERT:
- dlog_prio = DLOG_ERROR;
- break;
- case LOG_CRIT:
- dlog_prio = DLOG_ERROR;
- break;
- case LOG_ERR:
- dlog_prio = DLOG_ERROR;
- break;
- case LOG_WARNING:
- dlog_prio = DLOG_WARN;
- break;
- case LOG_NOTICE:
- dlog_prio = DLOG_INFO;
- break;
- case LOG_INFO:
- dlog_prio = DLOG_INFO;
- break;
- case LOG_DEBUG:
- dlog_prio = DLOG_DEBUG;
- break;
- default:
- dlog_prio = DLOG_DEFAULT;
- }
-
- va_list ap;
- va_start(ap, fmt);
- (void) vprint_system_log(dlog_prio, CYNARA_DLOG_TAG, fmt, ap);
- va_end(ap);
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * @file src/common/log/DlogLog.h
- * @author Tomasz Swierczek <t.swierczek@samsung.com>
- * @version 1.0
- * @brief This file declares loging functions on top of dlog
- */
-
-#ifndef SRC_COMMON_LOG_DLOGLOG_H
-#define SRC_COMMON_LOG_DLOGLOG_H
-
-#include <syslog.h>
-
-void cynara_dlog_print(int priority, char const *fmt, ...);
-
-#endif /* SRC_COMMON_LOG_DLOGLOG_H */
/*
- * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
*
int __log_level = LOG_ERR;
#endif
+LoggingCallback __log_callback = nullptr;
+
static int strlog2intlog(const char *strlog) {
if(!strncmp("LOG_EMERG", strlog, strlen("LOG_EMERG")))
return LOG_EMERG;
return LOG_ERR;
}
-void init_log(void) {
+void init_log(LoggingCallback callback) {
char *env_val = getenv("CYNARA_LOG_LEVEL");
if (env_val) {
__log_level = strlog2intlog(env_val);
}
+ __log_callback = callback;
}
#else
/*
- * Copyright (c) 2014-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
*
#include <sstream>
#ifdef BUILD_WITH_SYSTEMD_JOURNAL
#include <systemd/sd-journal.h>
-#elif defined(BUILD_WITH_DLOG)
-#include "DlogLog.h"
-#else
-#include <syslog.h>
-#endif
+#endif // BUILD_WITH_SYSTEMD_JOURNAL
#endif // CYNARA_NO_LOGS
+#include <syslog.h> // for LOG_* and syslog()
#include <attributes/attributes.h>
extern int __log_level;
+typedef void (*LoggingCallback) (int priority, char const *fmt, ...);
+extern LoggingCallback __log_callback;
+
#ifndef CYNARA_NO_LOGS
namespace {
template <typename ...Args>
void UNUSED __DIRECT_LOG_FUN(int level, Args&&... args) {
+ if (__log_callback) {
+ (*__log_callback)(level, std::forward<Args>(args)...);
+ } else {
#ifdef BUILD_WITH_SYSTEMD_JOURNAL
- sd_journal_print(level, std::forward<Args>(args)...);
-#elif defined(BUILD_WITH_DLOG)
- cynara_dlog_print(level, std::forward<Args>(args)...);
+ sd_journal_print(level, std::forward<Args>(args)...);
#else
- syslog(level, std::forward<Args>(args)...);
+ syslog(level, std::forward<Args>(args)...);
#endif
+ }
}
template <typename ...Args>
#define LOGI_NOTHROW(...) __LOG_NOTHROW(LOG_INFO, __VA_ARGS__) /* informational */
#define LOGD_NOTHROW(...) __LOG_NOTHROW(LOG_DEBUG, __VA_ARGS__) /* debug-level messages */
-void init_log(void);
+void init_log(LoggingCallback callback = nullptr);
#endif /* CYNARA_COMMON_LOG_H */
-# Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
${CYNARA_SERVICE_PATH}/sockets/SocketManager.cpp
)
+IF (LOG_TYPE MATCHES "DLOG")
+ SET(CYNARA_SOURCES ${CYNARA_SOURCES}
+ ${CYNARA_SERVICE_PATH}/main/DlogLog.cpp
+ )
+ENDIF (LOG_TYPE MATCHES "DLOG")
+
INCLUDE_DIRECTORIES(
${CYNARA_SERVICE_PATH}
${CYNARA_PATH}
--- /dev/null
+/*
+ * Copyright (c) 2018-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file src/service/main/DlogLog.cpp
+ * @author Tomasz Swierczek <t.swierczek@samsung.com>
+ * @version 1.0
+ * @brief This file implements loging functions on top of dlog
+ */
+
+#include "DlogLog.h"
+
+#include <dlog.h>
+#include <stdlib.h>
+#include <syslog.h>
+
+#define CYNARA_DLOG_TAG "CYNARA"
+
+void cynara_dlog_print(int priority, char const *fmt, ...)
+{
+ log_priority dlog_prio;
+
+ switch (priority) {
+ case LOG_EMERG:
+ dlog_prio = DLOG_FATAL;
+ break;
+ case LOG_ALERT:
+ dlog_prio = DLOG_ERROR;
+ break;
+ case LOG_CRIT:
+ dlog_prio = DLOG_ERROR;
+ break;
+ case LOG_ERR:
+ dlog_prio = DLOG_ERROR;
+ break;
+ case LOG_WARNING:
+ dlog_prio = DLOG_WARN;
+ break;
+ case LOG_NOTICE:
+ dlog_prio = DLOG_INFO;
+ break;
+ case LOG_INFO:
+ dlog_prio = DLOG_INFO;
+ break;
+ case LOG_DEBUG:
+ dlog_prio = DLOG_DEBUG;
+ break;
+ default:
+ dlog_prio = DLOG_DEFAULT;
+ }
+
+ va_list ap;
+ va_start(ap, fmt);
+ (void) vprint_system_log(dlog_prio, CYNARA_DLOG_TAG, fmt, ap);
+ va_end(ap);
+}
--- /dev/null
+/*
+ * Copyright (c) 2018-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file src/service/main/DlogLog.h
+ * @author Tomasz Swierczek <t.swierczek@samsung.com>
+ * @version 1.0
+ * @brief This file declares loging functions on top of dlog
+ */
+
+#ifndef SRC_SERVICE_MAIN_DLOGLOG_H
+#define SRC_SERVICE_MAIN_DLOGLOG_H
+
+void cynara_dlog_print(int priority, char const *fmt, ...);
+
+#endif /* SRC_SERVICE_MAIN_DLOGLOG_H */
/*
- * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
*
#include <systemd/sd-daemon.h>
#endif
+#if defined(BUILD_WITH_DLOG)
+#include "DlogLog.h"
+#endif
+
+
#include <common.h>
#include <log/log.h>
if (setgid(options.m_gid) == -1)
return EXIT_FAILURE;
+#if defined(BUILD_WITH_DLOG)
+ init_log(cynara_dlog_print);
+#else
init_log();
+#endif
Cynara::Cynara cynara;
LOGI("Cynara service is starting ...");