INCLUDE(FindPkgConfig)
INCLUDE(CheckCXXCompilerFlag)
+########################## search for packages ################################
+
+PKG_CHECK_MODULES(SYSTEMD_DEP
+ QUIET
+ libsystemd-daemon
+ libsystemd-journal
+ )
+
+IF (SYSTEMD_DEP_FOUND)
+ SET(BUILD_WITH_SYSTEMD ON)
+ENDIF (SYSTEMD_DEP_FOUND)
+
############################# install dirs ##################################
SET(LIB_INSTALL_DIR
ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
+IF (BUILD_WITH_SYSTEMD)
+ ADD_DEFINITIONS("-DBUILD_WITH_SYSTEMD")
+ENDIF (BUILD_WITH_SYSTEMD)
+
SET(TARGET_CYNARA "cynara")
SET(TARGET_LIB_CYNARA "cynara-client")
SET(TARGET_LIB_CYNARA_ASYNC "cynara-client-async")
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(pkgconfig)
-ADD_SUBDIRECTORY(systemd)
+
+IF (BUILD_WITH_SYSTEMD)
+ ADD_SUBDIRECTORY(systemd)
+ENDIF (BUILD_WITH_SYSTEMD)
+
ADD_SUBDIRECTORY(migration)
IF (BUILD_TESTS)
-ADD_SUBDIRECTORY(test)
-ENDIF()
+ ADD_SUBDIRECTORY(test)
+ENDIF (BUILD_TESTS)
%cmake . \
-DBUILD_TESTS=ON \
- -DBUILD_WITH_SYSTEMD=ON \
-DCMAKE_BUILD_TYPE=%{?build_type} \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DDB_FILES_SMACK_LABEL="System"
# @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
#
+
+SET(COMMON_DEPS)
+
+IF (BUILD_WITH_SYSTEMD)
SET(COMMON_DEPS
+ ${COMMON_DEPS}
libsystemd-daemon
libsystemd-journal
)
+ENDIF (BUILD_WITH_SYSTEMD)
IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
SET(COMMON_DEPS
/**
* @file src/common/log/AuditLog.cpp
* @author Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
* @version 1.0
* @brief This file implements privilege check logging utility.
*/
+#ifdef BUILD_WITH_SYSTEMD
#include <systemd/sd-journal.h>
+#else
+#include <syslog.h>
+#endif
#include "AuditLog.h"
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)) {
+#ifdef BUILD_WITH_SYSTEMD
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);
+#else // BUILD_WITH_SYSTEMD
+ 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 // BUILD_WITH_SYSTEMD
}
}
#ifndef CYNARA_NO_LOGS
#include <sstream>
+#ifdef BUILD_WITH_SYSTEMD
#include <systemd/sd-journal.h>
-#endif
+#else // BUILD_WITH_SYSTEMD
+#include <syslog.h>
+#endif // BUILD_WITH_SYSTEMD
+#endif // CYNARA_NO_LOGS
#include <attributes/attributes.h>
namespace {
template <typename ...Args>
void UNUSED __LOG_FUN(int level, const std::stringstream &format, Args&&... args) {
+#ifdef BUILD_WITH_SYSTEMD
sd_journal_print(level, format.str().c_str(), std::forward<Args>(args)...);
+#else // BUILD_WITH_SYSTEMD
+ syslog(level, format.str().c_str(), std::forward<Args>(args)...);
+#endif // BUILD_WITH_SYSTEMD
}
template <>
void UNUSED __LOG_FUN(int level, const std::stringstream &format) {
+#ifdef BUILD_WITH_SYSTEMD
sd_journal_print(level, "%s", format.str().c_str());
+#else // BUILD_WITH_SYSTEMD
+ syslog(level, "%s", format.str().c_str());
+#endif // BUILD_WITH_SYSTEMD
}
} // namespace anonymous
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
*
#include <iostream>
#include <stdlib.h>
-#include <systemd/sd-journal.h>
+#ifdef BUILD_WITH_SYSTEMD
#include <systemd/sd-daemon.h>
+#endif
#include <common.h>
#include <log/log.h>
cynara.init();
LOGI("Cynara service is started");
+#ifdef BUILD_WITH_SYSTEMD
int ret = sd_notify(0, "READY=1");
if (ret == 0) {
LOGW("Cynara was not configured to notify its status");
} else if (ret < 0) {
LOGE("sd_notify failed [%d]", ret);
}
+#endif
LOGD("Starting the real job");
cynara.run();
#include <sys/un.h>
#include <unistd.h>
+#ifdef BUILD_WITH_SYSTEMD
#include <systemd/sd-daemon.h>
+#endif
#include <log/log.h>
#include <common.h>
void SocketManager::createDomainSocket(ProtocolPtr protocol, const std::string &path, mode_t mask,
bool client) {
- int fd = getSocketFromSystemD(path);
+ int fd;
+#ifdef BUILD_WITH_SYSTEMD
+ fd = getSocketFromSystemD(path);
if (fd == -1)
+#endif
fd = createDomainSocketHelp(path, mask);
auto &desc = createDescriptor(fd, client);
return fd;
}
+#ifdef BUILD_WITH_SYSTEMD
int SocketManager::getSocketFromSystemD(const std::string &path) {
int n = sd_listen_fds(0);
LOGI("sd_listen_fds returns: [%d]", n);
LOGI("No useable sockets were passed by systemd.");
return -1;
}
+#endif // BUILD_WITH_SYSTEMD
void SocketManager::createSignalSocket(ProtocolPtr protocol) {
sigset_t mask;
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 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.
void createDomainSocket(ProtocolPtr protocol, const std::string &path, mode_t mask,
bool client);
static int createDomainSocketHelp(const std::string &path, mode_t mask);
+#ifdef BUILD_WITH_SYSTEMD
static int getSocketFromSystemD(const std::string &path);
+#endif
void createSignalSocket(ProtocolPtr protocol);
Descriptor &createDescriptor(int fd, bool client);