From aa4ec72ee0b47c7d7694dbfb570f58332cc3b740 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Wed, 18 Jun 2014 17:07:16 +0200 Subject: [PATCH 01/16] Bump version number to 0.1.0 Make sure that new security-manager packages will have higher version than previously built packages, before split from security-server repository. Change-Id: Id7ad7fbbe19ebce514209ad8e8e6cadae77386f7 Signed-off-by: Rafal Krypa --- packaging/security-manager.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/security-manager.spec b/packaging/security-manager.spec index 4487539..302bc23 100644 --- a/packaging/security-manager.spec +++ b/packaging/security-manager.spec @@ -1,6 +1,6 @@ Name: security-manager Summary: Security manager and utilities -Version: 0.0.1 +Version: 0.1.0 Release: 1 Group: Security/Service License: Apache-2.0 -- 2.7.4 From 298da3e024cd5ab29cb79867ec3601a90de15a85 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Wed, 18 Jun 2014 15:09:46 +0200 Subject: [PATCH 02/16] Remove SmackAudit() from logging facility This functionality was needed in security-server to log user space Smack checks consistently with logs generated by kernel. Security-manager will never perform such checks. Change-Id: Ifcc67228b85dedba33330710d1e763dbdfadd996 Signed-off-by: Rafal Krypa --- packaging/security-manager.spec | 3 - security-manager-audit.conf | 1 - src/server/CMakeLists.txt | 1 - .../log/include/dpl/log/abstract_log_provider.h | 4 - .../dpl/log/include/dpl/log/audit-smack-log.h | 114 -------- .../dpl/log/include/dpl/log/dlog_log_provider.h | 4 - src/server/dpl/log/include/dpl/log/log.h | 10 - .../log/include/dpl/log/old_style_log_provider.h | 4 - src/server/dpl/log/src/audit-smack-log.cpp | 310 --------------------- src/server/dpl/log/src/dlog_log_provider.cpp | 7 - src/server/dpl/log/src/log.cpp | 14 - src/server/dpl/log/src/old_style_log_provider.cpp | 11 - src/server/main/server2-main.cpp | 10 - 13 files changed, 493 deletions(-) delete mode 100644 security-manager-audit.conf delete mode 100644 src/server/dpl/log/include/dpl/log/audit-smack-log.h delete mode 100644 src/server/dpl/log/src/audit-smack-log.cpp diff --git a/packaging/security-manager.spec b/packaging/security-manager.spec index 302bc23..b4b44ac 100644 --- a/packaging/security-manager.spec +++ b/packaging/security-manager.spec @@ -62,8 +62,6 @@ rm -rf %{buildroot} mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} cp LICENSE %{buildroot}/usr/share/license/libsecurity-manager-client -mkdir -p %{buildroot}/etc/security/ -cp security-manager-audit.conf %{buildroot}/etc/security/ mkdir -p %{buildroot}/etc/smack/ cp app-rules-template.smack %{buildroot}/etc/smack/ %make_install @@ -114,7 +112,6 @@ fi %attr(-,root,root) /usr/lib/systemd/system/security-manager.target %attr(-,root,root) /usr/lib/systemd/system/sockets.target.wants/security-manager-installer.socket %attr(-,root,root) /usr/lib/systemd/system/security-manager-installer.socket -%attr(-,root,root) /etc/security/security-manager-audit.conf %attr(-,root,root) /etc/smack/app-rules-template.smack %{_datadir}/license/%{name} diff --git a/security-manager-audit.conf b/security-manager-audit.conf deleted file mode 100644 index c977fda..0000000 --- a/security-manager-audit.conf +++ /dev/null @@ -1 +0,0 @@ -10 524288 diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index c52f61b..73e3c00 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -13,7 +13,6 @@ SET(COMMON_SOURCES ${COMMON_PATH}/dpl/log/src/dlog_log_provider.cpp ${COMMON_PATH}/dpl/log/src/log.cpp ${COMMON_PATH}/dpl/log/src/old_style_log_provider.cpp - ${COMMON_PATH}/dpl/log/src/audit-smack-log.cpp ${COMMON_PATH}/dpl/core/src/assert.cpp ${COMMON_PATH}/dpl/core/src/binary_queue.cpp ${COMMON_PATH}/dpl/core/src/colors.cpp diff --git a/src/server/dpl/log/include/dpl/log/abstract_log_provider.h b/src/server/dpl/log/include/dpl/log/abstract_log_provider.h index cfe9679..a3ad299 100644 --- a/src/server/dpl/log/include/dpl/log/abstract_log_provider.h +++ b/src/server/dpl/log/include/dpl/log/abstract_log_provider.h @@ -67,10 +67,6 @@ class AbstractLogProvider const char *fileName, int line, const char *function) = 0; - virtual void SmackAudit(const char *message, - const char *fileName, - int line, - const char *function) = 0; protected: static const char *LocateSourceFileName(const char *filename); diff --git a/src/server/dpl/log/include/dpl/log/audit-smack-log.h b/src/server/dpl/log/include/dpl/log/audit-smack-log.h deleted file mode 100644 index 98fdc15..0000000 --- a/src/server/dpl/log/include/dpl/log/audit-smack-log.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Bumjin Im - * - * 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 audit-smack-log.h - * @author Marek Smolinski (m.smolinski@samsung.com) - * @version 1.0 - * @brief AuditSmackLog loging SMACK access deny sequentially into files - */ - -#ifndef _AUDIT_SMACK_LOG_ -#define _AUDIT_SMACK_LOG_ - -#include - -#include -#include -#include -#include -#include - -namespace SecurityManager { -namespace Log { - -class AuditSmackLog : - public AbstractLogProvider -{ -public: - AuditSmackLog(); - virtual ~AuditSmackLog(); - - bool Fail() const; - - virtual void Debug(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Info(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Warning(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Error(const char *message, - const char *fileName, - int line, - const char *function); - virtual void Pedantic(const char *message, - const char *fileName, - int line, - const char *function); - virtual void SecureDebug(const char *message, - const char *fileName, - int line, - const char *function); - virtual void SecureInfo(const char *message, - const char *fileName, - int line, - const char *function); - virtual void SecureWarning(const char *message, - const char *fileName, - int line, - const char *function); - virtual void SecureError(const char *message, - const char *fileName, - int line, - const char *function); - - virtual void SmackAudit(const char *message, - const char *fileName, - int line, - const char *function); - -private: - void HandleWrite(const char *message, - const char *fileName, - int line, - const char *function); - - int CreateLogFile(); - int RemoveOldestLogFile(); - int ParseConfig(); - int ProcessLogDir(); - bool IsFileFull(std::ofstream &fs) const; - - bool m_state; - unsigned int m_filesCount; - unsigned int m_fileMaxBytesSize; - - std::map m_fileNameMap; - std::ofstream m_outputStream; - - std::mutex m_writeMtx; -}; - -} // namespace Log -} // namespace SecurityManager -#endif // _AUDIT_SMACK_LOG_ diff --git a/src/server/dpl/log/include/dpl/log/dlog_log_provider.h b/src/server/dpl/log/include/dpl/log/dlog_log_provider.h index 6fe0d97..6b19e09 100644 --- a/src/server/dpl/log/include/dpl/log/dlog_log_provider.h +++ b/src/server/dpl/log/include/dpl/log/dlog_log_provider.h @@ -79,10 +79,6 @@ class DLOGLogProvider : const char *fileName, int line, const char *function); - virtual void SmackAudit(const char *message, - const char *fileName, - int line, - const char *function); // Set global Tag according to DLOG void SetTag(const char *tag); diff --git a/src/server/dpl/log/include/dpl/log/log.h b/src/server/dpl/log/include/dpl/log/log.h index 2594ace..74792cc 100644 --- a/src/server/dpl/log/include/dpl/log/log.h +++ b/src/server/dpl/log/include/dpl/log/log.h @@ -123,14 +123,6 @@ class LogSystem : const char *function); /** - * Log SS_SMACK into files - */ - void SmackAudit(const char *message, - const char *fileName, - int line, - const char *function); - - /** * Set default's DLOG provider Tag */ void SetTag(const char *tag); @@ -199,8 +191,6 @@ do \ #define LogError(message) DPL_MACRO_FOR_LOGGING(message, Error) #define LogSecureError(message) DPL_MACRO_FOR_LOGGING(message, SecureError) -#define LogSmackAudit(message) DPL_MACRO_FOR_LOGGING(message, SmackAudit) - #ifdef BUILD_TYPE_DEBUG #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, Debug) #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, Info) diff --git a/src/server/dpl/log/include/dpl/log/old_style_log_provider.h b/src/server/dpl/log/include/dpl/log/old_style_log_provider.h index 8ca2068..da1117a 100644 --- a/src/server/dpl/log/include/dpl/log/old_style_log_provider.h +++ b/src/server/dpl/log/include/dpl/log/old_style_log_provider.h @@ -93,10 +93,6 @@ class OldStyleLogProvider : const char *fileName, int line, const char *function); - virtual void SmackAudit(const char *message, - const char *fileName, - int line, - const char *function); }; } } // namespace SecurityManager diff --git a/src/server/dpl/log/src/audit-smack-log.cpp b/src/server/dpl/log/src/audit-smack-log.cpp deleted file mode 100644 index 1d03b6f..0000000 --- a/src/server/dpl/log/src/audit-smack-log.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Bumjin Im - * - * 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 audit-smack-log.cpp - * @author Marek Smolinski (m.smolinski@samsung.com) - * @version 1.0 - * @brief AuditSmackLog loging SMACK access deny sequentially into files - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#define UNUSED __attribute__((unused)) - -namespace { - -const std::string AUDIT_CONFIG_LOG_PATH = "/etc/security/"; -const std::string AUDIT_CONFIG_FILENAME = "security-manager-audit.conf"; -const std::string AUDIT_LOG_DIRECTORY = "/var/log/audit/"; -const std::string AUDIT_LOG_FILENAME_PREFIX = "audit-smack"; -const std::string AUDIT_LOG_SMACK_LABEL = "security-manager::audit-files"; - -} // namespace anonymous - -namespace SecurityManager { -namespace Log { - -AuditSmackLog::AuditSmackLog() - : m_state(true), m_filesCount(0), m_fileMaxBytesSize(0) -{ - if (ParseConfig() != 0) { - goto error; - } - - if (ProcessLogDir() != 0) { - goto error; - } - - if (m_state) { - - // reduce existing files count in log dir if config file was changed - while (m_fileNameMap.size() > m_filesCount) { - if (RemoveOldestLogFile() != 0) { - goto error; - } - } - - if (m_fileNameMap.size() == 0) { - if (CreateLogFile() != 0) { - goto error; - } - } else { - std::string filename(AUDIT_LOG_DIRECTORY); - filename += m_fileNameMap.rbegin()->second; - m_outputStream.open(filename, std::ios_base::app); - } - } - - return; - -error: - m_state = false; - -} - -AuditSmackLog::~AuditSmackLog(){} - -bool AuditSmackLog::Fail() const -{ - return !m_state; -} - -void AuditSmackLog::SmackAudit(const char *message, - const char *fileName, - int line, - const char *function) -{ - if (m_state) { - HandleWrite(message, fileName, line, function); - } -} - -void AuditSmackLog::HandleWrite(const char *message, - const char *filename, - int line, - const char *function) -{ - std::lock_guard lock(m_writeMtx); - if (IsFileFull(m_outputStream)) { - if (CreateLogFile() != 0) { - m_state = false; - return; - } - - if (m_fileNameMap.size() > m_filesCount) { - if (RemoveOldestLogFile() != 0) { - m_state = false; - return; - } - } - } - - m_outputStream << std::string("[") << - LocateSourceFileName(filename) << std::string(":") << line << - std::string("] ") << function << std::string("(): ") << - message << std::endl; -} - -int AuditSmackLog::CreateLogFile() -{ - time_t sec = time(NULL); - std::string fname(AUDIT_LOG_FILENAME_PREFIX); - std::string pathname(AUDIT_LOG_DIRECTORY); - - fname += std::to_string(sec); - fname += ".log"; - pathname += fname; - - if (m_outputStream.is_open()) - m_outputStream.close(); - - m_outputStream.open(pathname.c_str()); - - if (!m_outputStream) { - return -1; - } - - if (smack_setlabel(pathname.c_str(), - AUDIT_LOG_SMACK_LABEL.c_str(), - SMACK_LABEL_ACCESS) != 0) { - return -1; - } - - m_fileNameMap.insert(std::make_pair(sec, fname)); - return 0; -} - -int AuditSmackLog::RemoveOldestLogFile() -{ - assert(m_fileNameMap.size() > 0); - - auto it = m_fileNameMap.begin(); - std::string filename(AUDIT_LOG_DIRECTORY); - filename += it->second; - - if (unlink(filename.c_str()) == 0) { - m_fileNameMap.erase(it); - return 0; - } - - return -1; -} - -int AuditSmackLog::ParseConfig() -{ - struct stat sb; - if (stat(AUDIT_CONFIG_LOG_PATH.c_str(), &sb) != 0) { - return -1; - } - - std::ifstream in(AUDIT_CONFIG_LOG_PATH + AUDIT_CONFIG_FILENAME, - std::ios_base::in); - if (!in) { - return -1; - } - - in >> m_filesCount >> m_fileMaxBytesSize; - - if (in.fail()) { - return -1; - } - - return (m_filesCount > 0 && m_fileMaxBytesSize > 0) ? 0 : -1; -} - -int AuditSmackLog::ProcessLogDir() -{ - DIR *dir; - dirent *dp; - - if ((dir = opendir(AUDIT_LOG_DIRECTORY.c_str())) == NULL) { - return -1; - } - - while ((dp = readdir(dir)) != NULL) { - if (AUDIT_LOG_FILENAME_PREFIX.compare(0, std::string::npos, - dp->d_name, - AUDIT_LOG_FILENAME_PREFIX.size()) == 0) { - errno = 0; - char *pEnd; - time_t fUnxTime = static_cast( - strtoull(dp->d_name + AUDIT_LOG_FILENAME_PREFIX.size(), - &pEnd, 10)); - - if (errno != 0) { - closedir(dir); - return -1; - } - - m_fileNameMap.insert( - std::make_pair(fUnxTime, std::string(dp->d_name))); - } - } - - closedir(dir); - - return 0; -} - -bool AuditSmackLog::IsFileFull(std::ofstream &fs) const -{ - return fs.tellp() > m_fileMaxBytesSize; -} - -void AuditSmackLog::Debug(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -void AuditSmackLog::Info(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -void AuditSmackLog::Warning(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -void AuditSmackLog::Error(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -void AuditSmackLog::Pedantic(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -void AuditSmackLog::SecureDebug(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -void AuditSmackLog::SecureInfo(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -void AuditSmackLog::SecureWarning(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -void AuditSmackLog::SecureError(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - -} // namespace Log -} // namespace SecurityManager diff --git a/src/server/dpl/log/src/dlog_log_provider.cpp b/src/server/dpl/log/src/dlog_log_provider.cpp index c96dfd0..b2a59f9 100644 --- a/src/server/dpl/log/src/dlog_log_provider.cpp +++ b/src/server/dpl/log/src/dlog_log_provider.cpp @@ -141,12 +141,5 @@ void DLOGLogProvider::SecureError(const char *message UNUSED, FormatMessage(message, filename, line, function).c_str()); } -void DLOGLogProvider::SmackAudit(const char *message UNUSED, - const char *filename UNUSED, - int line UNUSED, - const char *function UNUSED) -{ -} - } // nemespace Log } // namespace SecurityManager diff --git a/src/server/dpl/log/src/log.cpp b/src/server/dpl/log/src/log.cpp index 9ac65c0..a237fdb 100644 --- a/src/server/dpl/log/src/log.cpp +++ b/src/server/dpl/log/src/log.cpp @@ -26,7 +26,6 @@ #include #include #include -#include IMPLEMENT_SINGLETON(SecurityManager::Log::LogSystem) @@ -277,18 +276,5 @@ void LogSystem::SecureWarning(const char *message, } } -void LogSystem::SmackAudit(const char *message, - const char *fileName, - int line, - const char *function) -{ - for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin(); - iterator != m_providers.end(); - ++iterator) - { - (*iterator)->SmackAudit(message, fileName, line, function); - } -} - } } // namespace SecurityManager diff --git a/src/server/dpl/log/src/old_style_log_provider.cpp b/src/server/dpl/log/src/old_style_log_provider.cpp index b3ea65a..0317862 100644 --- a/src/server/dpl/log/src/old_style_log_provider.cpp +++ b/src/server/dpl/log/src/old_style_log_provider.cpp @@ -298,16 +298,5 @@ void OldStyleLogProvider::SecureError(const char *message, #endif } -void OldStyleLogProvider::SmackAudit(const char *message, - const char *fileName, - int line, - const char *function) -{ - (void)message; - (void)fileName; - (void)line; - (void)function; -} - } } // namespace SecurityManager diff --git a/src/server/main/server2-main.cpp b/src/server/main/server2-main.cpp index 213f749..11a3f04 100644 --- a/src/server/main/server2-main.cpp +++ b/src/server/main/server2-main.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -67,15 +66,6 @@ int main(void) { { SecurityManager::Singleton::Instance().SetTag("SECURITY_MANAGER"); - // This provider may be used in security-manager only. - // If we add it inside LogSystem constructor it also - // will be used by security-manager-client library. - SecurityManager::Log::AuditSmackLog *smackLog = new SecurityManager::Log::AuditSmackLog; - if (smackLog->Fail()) - delete smackLog; - else - SecurityManager::Singleton::Instance().AddProvider(smackLog); - sigset_t mask; sigemptyset(&mask); sigaddset(&mask, SIGTERM); -- 2.7.4 From 0ad62e1c27b64dbe9505bb0def2be4f937c71855 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Wed, 18 Jun 2014 16:25:46 +0200 Subject: [PATCH 03/16] Listen on socket passed by systemd This was previously disabled in security-manager code, because it was coupled with security-server, which already did that. Uncommenting the listening code now. Change-Id: I9e7c5a3a5bde2e29fc74b9918af0a36992533a80 Signed-off-by: Rafal Krypa --- src/server/main/socket-manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/server/main/socket-manager.cpp b/src/server/main/socket-manager.cpp index c9f497b..c2eaced 100644 --- a/src/server/main/socket-manager.cpp +++ b/src/server/main/socket-manager.cpp @@ -335,8 +335,7 @@ void SocketManager::ReadyForWrite(int sock) { void SocketManager::MainLoop() { // remove evironment values passed by systemd - // uncomment it after removing old security-server code - // sd_listen_fds(1); + sd_listen_fds(1); // Daemon is ready to work. sd_notify(0, "READY=1"); -- 2.7.4 From ea2951995db2bafa1ffb466914128b04b33656b4 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Fri, 20 Jun 2014 17:53:48 +0200 Subject: [PATCH 04/16] Remove API for setting allowed users for an app Removed function security_manager_app_inst_req_add_allowed_user. It became obsolete when application framework switched to multi-user support by installing apps for each user separately. Change-Id: I2c1d3533982d23b45f3226e5eb07619d60b0530f Signed-off-by: Rafal Krypa --- src/include/security-manager.h | 10 ---------- src/server/client/client-security-manager.cpp | 12 ------------ src/server/common/protocols.h | 1 - src/server/service/installer.cpp | 1 - 4 files changed, 24 deletions(-) diff --git a/src/include/security-manager.h b/src/include/security-manager.h index ddcd599..2de9c3d 100644 --- a/src/include/security-manager.h +++ b/src/include/security-manager.h @@ -163,16 +163,6 @@ int security_manager_app_inst_req_set_app_id(app_inst_req *p_req, const char *ap int security_manager_app_inst_req_set_pkg_id(app_inst_req *p_req, const char *pkg_id); /* - * This function is used to add allowed user to app_inst_req structure, - * it can be called multiple times - * - * \param[in] Pointer handling app_inst_req structure - * \param[in] Privileged user identifier - * \return API return code or error code - */ -int security_manager_app_inst_req_add_allowed_user(app_inst_req *p_req, const uid_t user_id); - -/* * This function is used to add privilege to app_inst_req structure, * it can be called multiple times * diff --git a/src/server/client/client-security-manager.cpp b/src/server/client/client-security-manager.cpp index e83115d..bab0e96 100644 --- a/src/server/client/client-security-manager.cpp +++ b/src/server/client/client-security-manager.cpp @@ -83,17 +83,6 @@ int security_manager_app_inst_req_set_pkg_id(app_inst_req *p_req, const char *pk } SECURITY_MANAGER_API -int security_manager_app_inst_req_add_allowed_user(app_inst_req *p_req, const uid_t user_id) -{ - if (!p_req) - return SECURITY_MANAGER_ERROR_INPUT_PARAM; - - p_req->allowedUsers.push_back(user_id); - - return SECURITY_MANAGER_SUCCESS; -} - -SECURITY_MANAGER_API int security_manager_app_inst_req_add_privilege(app_inst_req *p_req, const char *privilege) { if (!p_req || !privilege) @@ -134,7 +123,6 @@ int security_manager_app_install(const app_inst_req *p_req) Serialization::Serialize(send, (int)SecurityModuleCall::APP_INSTALL); Serialization::Serialize(send, p_req->appId); Serialization::Serialize(send, p_req->pkgId); - Serialization::Serialize(send, p_req->allowedUsers); Serialization::Serialize(send, p_req->privileges); Serialization::Serialize(send, p_req->appPaths); diff --git a/src/server/common/protocols.h b/src/server/common/protocols.h index 85398e8..90e60b2 100644 --- a/src/server/common/protocols.h +++ b/src/server/common/protocols.h @@ -31,7 +31,6 @@ struct app_inst_req { std::string appId; std::string pkgId; - std::vector allowedUsers; std::vector privileges; std::vector> appPaths; }; diff --git a/src/server/service/installer.cpp b/src/server/service/installer.cpp index 15faa2d..574cac8 100644 --- a/src/server/service/installer.cpp +++ b/src/server/service/installer.cpp @@ -371,7 +371,6 @@ bool InstallerService::processAppInstall(MessageBuffer &buffer, MessageBuffer &s app_inst_req req; Deserialization::Deserialize(buffer, req.appId); Deserialization::Deserialize(buffer, req.pkgId); - Deserialization::Deserialize(buffer, req.allowedUsers); Deserialization::Deserialize(buffer, req.privileges); Deserialization::Deserialize(buffer, req.appPaths); -- 2.7.4 From 5e227c17823fdaa0da30ba826b76628a94a4de10 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Fri, 20 Jun 2014 17:58:50 +0200 Subject: [PATCH 05/16] Set myself as contact person for security-manager Update contact e-mail in source files with appropriate address. Change-Id: I51ef49d47d870403720a51857dc5d1384afc4e39 Signed-off-by: Rafal Krypa --- src/include/security-manager.h | 2 +- src/server/client/client-common.cpp | 4 ++-- src/server/client/client-common.h | 4 ++-- src/server/client/client-security-manager.cpp | 2 +- src/server/common/connection-info.h | 4 ++-- src/server/common/message-buffer.cpp | 4 ++-- src/server/common/message-buffer.h | 4 ++-- src/server/common/protocols.cpp | 4 ++-- src/server/common/protocols.h | 4 ++-- src/server/common/smack-check.h | 4 ++-- src/server/dpl/core/include/dpl/fstream_accessors.h | 4 ++-- src/server/main/generic-event.h | 4 ++-- src/server/main/generic-socket-manager.cpp | 4 ++-- src/server/main/generic-socket-manager.h | 4 ++-- src/server/main/security-manager-util.cpp | 4 ++-- src/server/main/security-manager-util.h | 4 ++-- src/server/main/server2-main.cpp | 4 ++-- src/server/main/service-thread.h | 4 ++-- src/server/main/socket-manager.cpp | 4 ++-- src/server/main/socket-manager.h | 4 ++-- src/server/service/installer.cpp | 2 +- src/server/service/installer.h | 2 +- 22 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/include/security-manager.h b/src/include/security-manager.h index 2de9c3d..d9ed47f 100644 --- a/src/include/security-manager.h +++ b/src/include/security-manager.h @@ -1,7 +1,7 @@ /* * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bartlomiej Grzelewski + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/client/client-common.cpp b/src/server/client/client-common.cpp index e245414..549f6b8 100644 --- a/src/server/client/client-common.cpp +++ b/src/server/client/client-common.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/client/client-common.h b/src/server/client/client-common.h index 607e8d3..c7d18a4 100644 --- a/src/server/client/client-common.h +++ b/src/server/client/client-common.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/client/client-security-manager.cpp b/src/server/client/client-security-manager.cpp index bab0e96..282acf2 100644 --- a/src/server/client/client-security-manager.cpp +++ b/src/server/client/client-security-manager.cpp @@ -1,7 +1,7 @@ /* * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bartlomiej Grzelewski + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/common/connection-info.h b/src/server/common/connection-info.h index 734ad69..7147bbe 100644 --- a/src/server/common/connection-info.h +++ b/src/server/common/connection-info.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/common/message-buffer.cpp b/src/server/common/message-buffer.cpp index 66d5b85..59db481 100644 --- a/src/server/common/message-buffer.cpp +++ b/src/server/common/message-buffer.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/common/message-buffer.h b/src/server/common/message-buffer.h index 71c89ed..19e7ee2 100644 --- a/src/server/common/message-buffer.h +++ b/src/server/common/message-buffer.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/common/protocols.cpp b/src/server/common/protocols.cpp index c120327..59bf302 100644 --- a/src/server/common/protocols.cpp +++ b/src/server/common/protocols.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bartlomiej Grzelewski + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/common/protocols.h b/src/server/common/protocols.h index 90e60b2..51c259e 100644 --- a/src/server/common/protocols.h +++ b/src/server/common/protocols.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bartlomiej Grzelewski + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/common/smack-check.h b/src/server/common/smack-check.h index 24578ae..b1cf733 100644 --- a/src/server/common/smack-check.h +++ b/src/server/common/smack-check.h @@ -1,9 +1,9 @@ /* * security-manager * - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/dpl/core/include/dpl/fstream_accessors.h b/src/server/dpl/core/include/dpl/fstream_accessors.h index 141a499..5d6379a 100644 --- a/src/server/dpl/core/include/dpl/fstream_accessors.h +++ b/src/server/dpl/core/include/dpl/fstream_accessors.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/generic-event.h b/src/server/main/generic-event.h index 3486155..43ed2e5 100644 --- a/src/server/main/generic-event.h +++ b/src/server/main/generic-event.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/generic-socket-manager.cpp b/src/server/main/generic-socket-manager.cpp index 1e6bc5e..487b47e 100644 --- a/src/server/main/generic-socket-manager.cpp +++ b/src/server/main/generic-socket-manager.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/generic-socket-manager.h b/src/server/main/generic-socket-manager.h index 2f0ad1d..5234871 100644 --- a/src/server/main/generic-socket-manager.h +++ b/src/server/main/generic-socket-manager.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/security-manager-util.cpp b/src/server/main/security-manager-util.cpp index 4218375..ee85c86 100644 --- a/src/server/main/security-manager-util.cpp +++ b/src/server/main/security-manager-util.cpp @@ -1,9 +1,9 @@ /* * security-manager * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/security-manager-util.h b/src/server/main/security-manager-util.h index 62aa45a..fc95e25 100644 --- a/src/server/main/security-manager-util.h +++ b/src/server/main/security-manager-util.h @@ -1,9 +1,9 @@ /* * security-manager * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/server2-main.cpp b/src/server/main/server2-main.cpp index 11a3f04..aba9373 100644 --- a/src/server/main/server2-main.cpp +++ b/src/server/main/server2-main.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/service-thread.h b/src/server/main/service-thread.h index 8b8286c..964d168 100644 --- a/src/server/main/service-thread.h +++ b/src/server/main/service-thread.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/socket-manager.cpp b/src/server/main/socket-manager.cpp index c2eaced..b4db0db 100644 --- a/src/server/main/socket-manager.cpp +++ b/src/server/main/socket-manager.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/main/socket-manager.h b/src/server/main/socket-manager.h index 58d3db1..6174d6a 100644 --- a/src/server/main/socket-manager.h +++ b/src/server/main/socket-manager.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bumjin Im + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/service/installer.cpp b/src/server/service/installer.cpp index 574cac8..8de407d 100644 --- a/src/server/service/installer.cpp +++ b/src/server/service/installer.cpp @@ -1,7 +1,7 @@ /* * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bartlomiej Grzelewski + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/server/service/installer.h b/src/server/service/installer.h index 656bc1a..ae9a731 100644 --- a/src/server/service/installer.h +++ b/src/server/service/installer.h @@ -1,7 +1,7 @@ /* * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Bartlomiej Grzelewski + * Contact: Rafal Krypa * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- 2.7.4 From 9f60fd4e3f79425c462fb0a33b3428ce3cdcc564 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 2 Jun 2014 18:52:43 +0200 Subject: [PATCH 06/16] DPL: udate dpl/core/include/dpl/assert.h from latest wrt-commons Needed to get AssertMsg macro, used in other DPL modules. Change-Id: Iaca6c09a52e2f6644580d667a6817cfaa777d0a4 Signed-off-by: Rafal Krypa --- src/server/dpl/core/include/dpl/assert.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/server/dpl/core/include/dpl/assert.h b/src/server/dpl/core/include/dpl/assert.h index 34daa4d..9a6779c 100644 --- a/src/server/dpl/core/include/dpl/assert.h +++ b/src/server/dpl/core/include/dpl/assert.h @@ -40,4 +40,13 @@ SECURITYMANAGER_NORETURN void AssertProc(const char *condition, __FUNCTION__); \ } } while (0) +#define AssertMsg(Condition, Msg) \ + do { \ + if (!(Condition)) { \ + SecurityManager::AssertProc( \ + (std::string(std::string(#Condition)+" ") + Msg).c_str(), \ + __FILE__, __LINE__, __FUNCTION__); \ + } \ + } while (0) + #endif // SECURITY_MANAGER_ASSERT_H -- 2.7.4 From 87d33865d2d5c5f1f09963d417792c79bc34b7d2 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 2 Jun 2014 19:00:44 +0200 Subject: [PATCH 07/16] DPL: import DPL::SqlConnection and dependencies Import SQLite wrapper class from wrt-commons 0.2.210. Several dependencies from DPL common imported as needed. Dependency DPL::Thread has been omitted on purpose, because it caused too many other dependencies. It will be substituded in a separate patch. These classes will be used by security-manager. When security-manager gets its own repository, SqlConnection will be removed from security-server. Change-Id: I090f73d6912f4ef6b85b313e7b12d20a7fd758a1 Signed-off-by: Rafal Krypa --- src/server/dpl/core/include/dpl/availability.h | 30 + src/server/dpl/core/include/dpl/char_traits.h | 38 + src/server/dpl/core/include/dpl/errno_string.h | 35 + src/server/dpl/core/include/dpl/free_deleter.h | 33 + src/server/dpl/core/include/dpl/string.h | 157 ++++ src/server/dpl/core/src/errno_string.cpp | 99 +++ src/server/dpl/core/src/string.cpp | 250 ++++++ .../include/dpl/db/naive_synchronization_object.h | 45 ++ src/server/dpl/db/include/dpl/db/sql_connection.h | 513 ++++++++++++ .../dpl/db/src/naive_synchronization_object.cpp | 44 ++ src/server/dpl/db/src/sql_connection.cpp | 866 +++++++++++++++++++++ 11 files changed, 2110 insertions(+) create mode 100644 src/server/dpl/core/include/dpl/availability.h create mode 100644 src/server/dpl/core/include/dpl/char_traits.h create mode 100644 src/server/dpl/core/include/dpl/errno_string.h create mode 100644 src/server/dpl/core/include/dpl/free_deleter.h create mode 100644 src/server/dpl/core/include/dpl/string.h create mode 100644 src/server/dpl/core/src/errno_string.cpp create mode 100644 src/server/dpl/core/src/string.cpp create mode 100644 src/server/dpl/db/include/dpl/db/naive_synchronization_object.h create mode 100644 src/server/dpl/db/include/dpl/db/sql_connection.h create mode 100644 src/server/dpl/db/src/naive_synchronization_object.cpp create mode 100644 src/server/dpl/db/src/sql_connection.cpp diff --git a/src/server/dpl/core/include/dpl/availability.h b/src/server/dpl/core/include/dpl/availability.h new file mode 100644 index 0000000..0813892 --- /dev/null +++ b/src/server/dpl/core/include/dpl/availability.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 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 availability.h + * @author Jihoon Chung (jihoon.chung@samsung.com) + * @version 1.0 + */ +#ifndef DPL_AVAILABILITY_H +#define DPL_AVAILABILITY_H + +#define DPL_DEPRECATED __attribute__((deprecated)) +#define DPL_DEPRECATED_WITH_MESSAGE(msg) __attribute__((deprecated(msg))) + +#define DPL_UNUSED __attribute__((unused)) +#define DPL_UNUSED_PARAM(variable) (void)variable + +#endif // DPL_AVAILABILITY_H diff --git a/src/server/dpl/core/include/dpl/char_traits.h b/src/server/dpl/core/include/dpl/char_traits.h new file mode 100644 index 0000000..eb2988f --- /dev/null +++ b/src/server/dpl/core/include/dpl/char_traits.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011 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 char_traits.h + * @author Piotr Marcinkiewicz (p.marcinkiew@samsung.com) + * @version 1.0 + * @brief Char traits are used to create basic_string extended with + * additional features + * Current char traits could be extended in feature to boost + * performance + */ +#ifndef DPL_CHAR_TRAITS +#define DPL_CHAR_TRAITS + +#include +#include +#include +#include +#include + +namespace DPL { +typedef std::char_traits CharTraits; +} // namespace DPL + +#endif // DPL_CHAR_TRAITS diff --git a/src/server/dpl/core/include/dpl/errno_string.h b/src/server/dpl/core/include/dpl/errno_string.h new file mode 100644 index 0000000..446dbc9 --- /dev/null +++ b/src/server/dpl/core/include/dpl/errno_string.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2011 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 errno_string.h + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + * @brief This file is the implementation file of errno string + */ +#ifndef DPL_ERRNO_STRING_H +#define DPL_ERRNO_STRING_H + +#include +#include +#include + +namespace DPL { +DECLARE_EXCEPTION_TYPE(DPL::Exception, InvalidErrnoValue) + +std::string GetErrnoString(int error = errno); +} // namespace DPL + +#endif // DPL_ERRNO_STRING_H diff --git a/src/server/dpl/core/include/dpl/free_deleter.h b/src/server/dpl/core/include/dpl/free_deleter.h new file mode 100644 index 0000000..4a09904 --- /dev/null +++ b/src/server/dpl/core/include/dpl/free_deleter.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2014 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 free_deleter.h + * @author Pawel Czajkowski (p.czajkowski@samsung.com) + * @version 1.0 + * @brief This file is the implementation file deleter with use std::free() + */ +#ifndef FREE_DELETER_H +#define FREE_DELETER_H + +#include +namespace DPL +{ +struct free_deleter +{ + void operator()(void *p) { std::free(p); } +}; +}// DPL +#endif // FREE_DELETER_H diff --git a/src/server/dpl/core/include/dpl/string.h b/src/server/dpl/core/include/dpl/string.h new file mode 100644 index 0000000..e4dc923 --- /dev/null +++ b/src/server/dpl/core/include/dpl/string.h @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2011 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 string.h + * @author Piotr Marcinkiewicz (p.marcinkiew@samsung.com) + * @version 1.0 + */ +#ifndef DPL_STRING +#define DPL_STRING + +#include +#include +#include +#include +#include + +namespace DPL { +// @brief DPL string +typedef std::basic_string String; + +// @brief String exception class +class StringException +{ + public: + DECLARE_EXCEPTION_TYPE(DPL::Exception, Base) + + // @brief Invalid init for UTF8 to UTF32 converter + DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF8ToUTF32) + + // @brief Invalid taStdContainerinit for UTF32 to UTF32 converter + DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF32ToUTF8) + + // @brief Invalid conversion for UTF8 to UTF32 converter + DECLARE_EXCEPTION_TYPE(Base, IconvConvertErrorUTF8ToUTF32) + + // @brief Invalid conversion for UTF8 to UTF32 converter + DECLARE_EXCEPTION_TYPE(Base, IconvConvertErrorUTF32ToUTF8) + + // @brief Invalid ASCII character detected in FromASCII + DECLARE_EXCEPTION_TYPE(Base, InvalidASCIICharacter) + + // @brief Invalid ASCII character detected in FromASCII + DECLARE_EXCEPTION_TYPE(Base, ICUInvalidCharacterFound) +}; + +//!\brief convert ASCII string to DPL::String +String FromASCIIString(const std::string& aString); + +//!\brief convert UTF32 string to DPL::String +String FromUTF32String(const std::wstring& aString); + +//@brief Returns String object created from UTF8 string +//@param[in] aString input UTF-8 string +String FromUTF8String(const std::string& aString); + +//@brief Returns String content as std::string +std::string ToUTF8String(const String& aString); + +//@brief Compare two unicode strings +int StringCompare(const String &left, + const String &right, + bool caseInsensitive = false); + +//@brief Splits the string into substrings. +//@param[in] str Input string +//@param[in] delimiters array or string containing a sequence of substring +// delimiters. Can be also a single delimiter character. +//@param[in] it InserterIterator that is used to save the generated substrings. +template +void Tokenize(const StringType& str, + const Delimiters& delimiters, + InserterIterator it, + bool ignoreEmpty = false) +{ + typename StringType::size_type nextSearchStart = 0; + typename StringType::size_type pos; + typename StringType::size_type length; + + while (true) { + pos = str.find_first_of(delimiters, nextSearchStart); + length = + ((pos == StringType::npos) ? str.length() : pos) - nextSearchStart; + + if (!ignoreEmpty || length > 0) { + *it = str.substr(nextSearchStart, length); + it++; + } + + if (pos == StringType::npos) { + return; + } + + nextSearchStart = pos + 1; + } +} + +namespace Utils { + +template class ConcatFunc : public std::binary_function +{ +public: + explicit ConcatFunc(const T & val) : m_delim(val) {} + T operator()(const T & arg1, const T & arg2) const + { + return arg1 + m_delim + arg2; + } +private: + T m_delim; +}; + +} + +template +typename ForwardIterator::value_type Join(ForwardIterator begin, ForwardIterator end, typename ForwardIterator::value_type delim) +{ + typedef typename ForwardIterator::value_type value; + if(begin == end) return value(); + Utils::ConcatFunc func(delim); + ForwardIterator init = begin; + return std::accumulate(++begin, end, *init, func); +} + +template void TrimLeft(StringType & obj, typename StringType::const_pointer separators) +{ + obj.erase(0, obj.find_first_not_of(separators)); +} + +template void TrimRight(StringType & obj, typename StringType::const_pointer separators) +{ + obj.erase(obj.find_last_not_of(separators)+1); +} + +template void Trim(StringType & obj, typename StringType::const_pointer separators) +{ + TrimLeft(obj, separators); + TrimRight(obj, separators); +} + + +} //namespace DPL + +std::ostream& operator<<(std::ostream& aStream, const DPL::String& aString); + +#endif // DPL_STRING diff --git a/src/server/dpl/core/src/errno_string.cpp b/src/server/dpl/core/src/errno_string.cpp new file mode 100644 index 0000000..6c59776 --- /dev/null +++ b/src/server/dpl/core/src/errno_string.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2011 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 errno_string.h + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + * @brief This file is the implementation file of errno string + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace DPL { +namespace // anonymous +{ +const size_t DEFAULT_ERRNO_STRING_SIZE = 32; +} // namespace anonymous + +std::string GetErrnoString(int error) +{ + size_t size = DEFAULT_ERRNO_STRING_SIZE; + char *buffer = NULL; + + for (;;) { + // Add one extra characted for end of string null value + char *newBuffer = static_cast(::realloc(buffer, size + 1)); + + if (!newBuffer) { + // Failed to realloc + ::free(buffer); + throw std::bad_alloc(); + } + + // Setup reallocated buffer + buffer = newBuffer; + ::memset(buffer, 0, size + 1); + + // Try to retrieve error string +#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE + // The XSI-compliant version of strerror_r() is provided if: + int result = ::strerror_r(error, buffer, size); + + if (result == 0) { + std::unique_ptr scopedBufferFree(buffer); + return std::string(buffer); + } +#else + errno = 0; + + // Otherwise, the GNU-specific version is provided. + char *result = ::strerror_r(error, buffer, size); + + if (result != NULL) { + std::unique_ptr scopedBufferFree(buffer); + return std::string(result); + } +#endif + + // Interpret errors + switch (errno) { + case EINVAL: + // We got an invalid errno value + ::free(buffer); + ThrowMsg(InvalidErrnoValue, "Invalid errno value: " << error); + + case ERANGE: + // Incease buffer size and retry + size <<= 1; + continue; + + default: + AssertMsg(0, "Invalid errno value after call to strerror_r!"); + } + } +} +} // namespace DPL diff --git a/src/server/dpl/core/src/string.cpp b/src/server/dpl/core/src/string.cpp new file mode 100644 index 0000000..a642eaa --- /dev/null +++ b/src/server/dpl/core/src/string.cpp @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2011 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 string.cpp + * @author Piotr Marcinkiewicz (p.marcinkiew@samsung.com) + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// TODO: Completely move to ICU +namespace DPL { +namespace //anonymous +{ +class ASCIIValidator +{ + const std::string& m_TestedString; + + public: + ASCIIValidator(const std::string& aTestedString); + + void operator()(char aCharacter) const; +}; + +ASCIIValidator::ASCIIValidator(const std::string& aTestedString) : + m_TestedString(aTestedString) +{} + +void ASCIIValidator::operator()(char aCharacter) const +{ + // Check for ASCII data range + if (aCharacter <= 0) { + ThrowMsg( + StringException::InvalidASCIICharacter, + "invalid character code " << static_cast(aCharacter) + << " from string [" << + m_TestedString + << "] passed as ASCII"); + } +} + +const iconv_t gc_IconvOperError = reinterpret_cast(-1); +const size_t gc_IconvConvertError = static_cast(-1); +} // namespace anonymous + +String FromUTF8String(const std::string& aIn) +{ + if (aIn.empty()) { + return String(); + } + + size_t inbytes = aIn.size(); + + // Default iconv UTF-32 module adds BOM (4 bytes) in from of string + // The worst case is when 8bit UTF-8 char converts to 32bit UTF-32 + // newsize = oldsize * 4 + end + bom + // newsize - bytes for UTF-32 string + // oldsize - letters in UTF-8 string + // end - end character for UTF-32 (\0) + // bom - Unicode header in front of string (0xfeff) + size_t outbytes = sizeof(wchar_t) * (inbytes + 2); + std::vector output(inbytes + 2, 0); + + size_t outbytesleft = outbytes; + char* inbuf = const_cast(aIn.c_str()); + + // vector is used to provide buffer for iconv which expects char* buffer + // but during conversion from UTF32 uses internaly wchar_t + char* outbuf = reinterpret_cast(&output[0]); + + iconv_t iconvHandle = iconv_open("UTF-32", "UTF-8"); + + if (gc_IconvOperError == iconvHandle) { + int error = errno; + + ThrowMsg(StringException::IconvInitErrorUTF8ToUTF32, + "iconv_open failed for " << "UTF-32 <- UTF-8" << + "error: " << GetErrnoString(error)); + } + + size_t iconvRet = iconv(iconvHandle, + &inbuf, + &inbytes, + &outbuf, + &outbytesleft); + + iconv_close(iconvHandle); + + if (gc_IconvConvertError == iconvRet) { + ThrowMsg(StringException::IconvConvertErrorUTF8ToUTF32, + "iconv failed for " << "UTF-32 <- UTF-8" << "error: " + << GetErrnoString()); + } + + // Ignore BOM in front of UTF-32 + return &output[1]; +} + +std::string ToUTF8String(const DPL::String& aIn) +{ + if (aIn.empty()) { + return std::string(); + } + + size_t inbytes = aIn.size() * sizeof(wchar_t); + size_t outbytes = inbytes + sizeof(char); + + // wstring returns wchar_t but iconv expects char* + // iconv internally is processing input as wchar_t + char* inbuf = reinterpret_cast(const_cast(aIn.c_str())); + std::vector output(inbytes, 0); + char* outbuf = &output[0]; + + size_t outbytesleft = outbytes; + + iconv_t iconvHandle = iconv_open("UTF-8", "UTF-32"); + + if (gc_IconvOperError == iconvHandle) { + ThrowMsg(StringException::IconvInitErrorUTF32ToUTF8, + "iconv_open failed for " << "UTF-8 <- UTF-32" + << "error: " << GetErrnoString()); + } + + size_t iconvRet = iconv(iconvHandle, + &inbuf, + &inbytes, + &outbuf, + &outbytesleft); + + iconv_close(iconvHandle); + + if (gc_IconvConvertError == iconvRet) { + ThrowMsg(StringException::IconvConvertErrorUTF32ToUTF8, + "iconv failed for " << "UTF-8 <- UTF-32" + << "error: " << GetErrnoString()); + } + + return &output[0]; +} + +String FromASCIIString(const std::string& aString) +{ + String output; + + std::for_each(aString.begin(), aString.end(), ASCIIValidator(aString)); + std::copy(aString.begin(), aString.end(), std::back_inserter(output)); + + return output; +} + +String FromUTF32String(const std::wstring& aString) +{ + return String(&aString[0]); +} + +static UChar *ConvertToICU(const String &inputString) +{ + std::unique_ptr outputString; + int32_t size = 0; + int32_t convertedSize = 0; + UErrorCode error = U_ZERO_ERROR; + + // Calculate size of output string + ::u_strFromWCS(NULL, + 0, + &size, + inputString.c_str(), + -1, + &error); + + if (error == U_ZERO_ERROR || + error == U_BUFFER_OVERFLOW_ERROR) + { + // What buffer size is ok ? + LogPedantic("ICU: Output buffer size: " << size); + } else { + ThrowMsg(StringException::ICUInvalidCharacterFound, + "ICU: Failed to retrieve output string size. Error: " + << error); + } + + // Allocate proper buffer + outputString.reset(new UChar[size + 1]); + ::memset(outputString.get(), 0, sizeof(UChar) * (size + 1)); + + error = U_ZERO_ERROR; + + // Do conversion + ::u_strFromWCS(outputString.get(), + size + 1, + &convertedSize, + inputString.c_str(), + -1, + &error); + + if (!U_SUCCESS(error)) { + ThrowMsg(StringException::ICUInvalidCharacterFound, + "ICU: Failed to convert string. Error: " << error); + } + + // Done + return outputString.release(); +} + +int StringCompare(const String &left, + const String &right, + bool caseInsensitive) +{ + // Convert input strings + std::unique_ptr leftICU(ConvertToICU(left)); + std::unique_ptr rightICU(ConvertToICU(right)); + + if (caseInsensitive) { + return static_cast(u_strcasecmp(leftICU.get(), rightICU.get(), 0)); + } else { + return static_cast(u_strcmp(leftICU.get(), rightICU.get())); + } +} +} //namespace DPL + +std::ostream& operator<<(std::ostream& aStream, const DPL::String& aString) +{ + return aStream << DPL::ToUTF8String(aString); +} diff --git a/src/server/dpl/db/include/dpl/db/naive_synchronization_object.h b/src/server/dpl/db/include/dpl/db/naive_synchronization_object.h new file mode 100644 index 0000000..2f63a0f --- /dev/null +++ b/src/server/dpl/db/include/dpl/db/naive_synchronization_object.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2011 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 naive_synchronization_object.h + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + * @brief This file is the implementation file of SQL naive + * synchronization object + */ +#ifndef DPL_NAIVE_SYNCHRONIZATION_OBJECT_H +#define DPL_NAIVE_SYNCHRONIZATION_OBJECT_H + +#include + +namespace DPL { +namespace DB { +/** + * Naive synchronization object used to synchronize SQL connection + * to the same database across different threads and processes + */ +class NaiveSynchronizationObject : + public SqlConnection::SynchronizationObject +{ + public: + // [SqlConnection::SynchronizationObject] + virtual void Synchronize(); + virtual void NotifyAll(); +}; +} // namespace DB +} // namespace DPL + +#endif // DPL_NAIVE_SYNCHRONIZATION_OBJECT_H diff --git a/src/server/dpl/db/include/dpl/db/sql_connection.h b/src/server/dpl/db/include/dpl/db/sql_connection.h new file mode 100644 index 0000000..18a5d3f --- /dev/null +++ b/src/server/dpl/db/include/dpl/db/sql_connection.h @@ -0,0 +1,513 @@ +/* + * Copyright (c) 2011 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 sql_connection.h + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + * @brief This file is the implementation file of SQL connection + */ +#ifndef DPL_SQL_CONNECTION_H +#define DPL_SQL_CONNECTION_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace DPL { +namespace DB { +/** + * SQL connection class + */ +class SqlConnection +{ + public: + /** + * SQL Exception classes + */ + class Exception + { + public: + DECLARE_EXCEPTION_TYPE(DPL::Exception, Base) + DECLARE_EXCEPTION_TYPE(Base, SyntaxError) + DECLARE_EXCEPTION_TYPE(Base, ConnectionBroken) + DECLARE_EXCEPTION_TYPE(Base, InternalError) + DECLARE_EXCEPTION_TYPE(Base, InvalidColumn) + }; + + typedef int ColumnIndex; + typedef int ArgumentIndex; + + /* + * SQL processed data command + */ + class DataCommand : + private Noncopyable + { + private: + SqlConnection *m_masterConnection; + sqlite3_stmt *m_stmt; + + void CheckBindResult(int result); + void CheckColumnIndex(SqlConnection::ColumnIndex column); + + DataCommand(SqlConnection *connection, const char *buffer); + + friend class SqlConnection; + + public: + virtual ~DataCommand(); + + /** + * Bind null to the prepared statement argument + * + * @param position Index of argument to bind value to + */ + void BindNull(ArgumentIndex position); + + /** + * Bind int to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInteger(ArgumentIndex position, int value); + + /** + * Bind int8_t to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInt8(ArgumentIndex position, int8_t value); + + /** + * Bind int16 to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInt16(ArgumentIndex position, int16_t value); + + /** + * Bind int32 to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInt32(ArgumentIndex position, int32_t value); + + /** + * Bind int64 to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInt64(ArgumentIndex position, int64_t value); + + /** + * Bind float to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindFloat(ArgumentIndex position, float value); + + /** + * Bind double to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindDouble(ArgumentIndex position, double value); + + /** + * Bind string to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindString(ArgumentIndex position, const char *value); + + /** + * Bind string to the prepared statement argument + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindString(ArgumentIndex position, const String& value); + + /** + * Bind optional int to the prepared statement argument. + * If optional is not set null will be bound + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInteger(ArgumentIndex position, const boost::optional &value); + + /** + * Bind optional int8 to the prepared statement argument. + * If optional is not set null will be bound + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInt8(ArgumentIndex position, const boost::optional &value); + + /** + * Bind optional int16 to the prepared statement argument. + * If optional is not set null will be bound + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInt16(ArgumentIndex position, const boost::optional &value); + + /** + * Bind optional int32 to the prepared statement argument. + * If optional is not set null will be bound + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInt32(ArgumentIndex position, const boost::optional &value); + + /** + * Bind optional int64 to the prepared statement argument. + * If optional is not set null will be bound + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindInt64(ArgumentIndex position, const boost::optional &value); + + /** + * Bind optional float to the prepared statement argument. + * If optional is not set null will be bound + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindFloat(ArgumentIndex position, const boost::optional &value); + + /** + * Bind optional double to the prepared statement argument. + * If optional is not set null will be bound + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindDouble(ArgumentIndex position, const boost::optional &value); + + /** + * Bind optional string to the prepared statement argument. + * If optional is not set null will be bound + * + * @param position Index of argument to bind value to + * @param value Value to bind + */ + void BindString(ArgumentIndex position, const boost::optional &value); + + /** + * Execute the prepared statement and/or move + * to the next row of the result + * + * @return True when there was a row returned + */ + bool Step(); + + /** + * Reset prepared statement's arguments + * All parameters will become null + */ + void Reset(); + + /** + * Checks whether column value is null + * + * @throw Exception::InvalidColumn + */ + bool IsColumnNull(ColumnIndex column); + + /** + * Get integer value from column in current row. + * + * @throw Exception::InvalidColumn + */ + int GetColumnInteger(ColumnIndex column); + + /** + * Get int8 value from column in current row. + * + * @throw Exception::InvalidColumn + */ + int8_t GetColumnInt8(ColumnIndex column); + + /** + * Get int16 value from column in current row. + * + * @throw Exception::InvalidColumn + */ + int16_t GetColumnInt16(ColumnIndex column); + /** + * Get int32 value from column in current row. + * + * @throw Exception::InvalidColumn + */ + int32_t GetColumnInt32(ColumnIndex column); + + /** + * Get int64 value from column in current row. + * + * @throw Exception::InvalidColumn + */ + int64_t GetColumnInt64(ColumnIndex column); + + /** + * Get float value from column in current row. + * + * @throw Exception::InvalidColumn + */ + float GetColumnFloat(ColumnIndex column); + + /** + * Get double value from column in current row. + * + * @throw Exception::InvalidColumn + */ + double GetColumnDouble(ColumnIndex column); + + /** + * Get string value from column in current row. + * + * @throw Exception::InvalidColumn + */ + std::string GetColumnString(ColumnIndex column); + + /** + * Get optional integer value from column in current row. + * + * @throw Exception::InvalidColumn + */ + boost::optional GetColumnOptionalInteger(ColumnIndex column); + + /** + * Get optional int8 value from column in current row. + * + * @throw Exception::InvalidColumn + */ + boost::optional GetColumnOptionalInt8(ColumnIndex column); + + /** + * Get optional int16value from column in current row. + * + * @throw Exception::InvalidColumn + */ + boost::optional GetColumnOptionalInt16(ColumnIndex column); + + /** + * Get optional int32 value from column in current row. + * + * @throw Exception::InvalidColumn + */ + boost::optional GetColumnOptionalInt32(ColumnIndex column); + + /** + * Get optional int64 value from column in current row. + * + * @throw Exception::InvalidColumn + */ + boost::optional GetColumnOptionalInt64(ColumnIndex column); + + /** + * Get optional float value from column in current row. + * + * @throw Exception::InvalidColumn + */ + boost::optional GetColumnOptionalFloat(ColumnIndex column); + + /** + * Get optional double value from column in current row. + * + * @throw Exception::InvalidColumn + */ + boost::optional GetColumnOptionalDouble(ColumnIndex column); + + /** + * Get optional string value from column in current row. + * + * @throw Exception::InvalidColumn + */ + boost::optional GetColumnOptionalString(ColumnIndex column); + }; + + // Move on copy semantics + typedef std::auto_ptr DataCommandAutoPtr; + + // Open flags + class Flag + { + public: + enum Type + { + None = 1 << 0, + UseLucene = 1 << 1 + }; + + enum Option + { + RO = SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_READONLY, + /** + * *TODO: please remove CREATE option from RW flag when all places + * that need that switched do CRW + */ + RW = SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_READWRITE | + SQLITE_OPEN_CREATE, + CRW = RW | SQLITE_OPEN_CREATE + }; + }; + + // RowID + typedef sqlite3_int64 RowID; + + /** + * Synchronization object used to synchronize SQL connection + * to the same database across different threads and processes + */ + class SynchronizationObject + { + public: + virtual ~SynchronizationObject() {} + + /** + * Synchronizes SQL connection for multiple clients. + */ + virtual void Synchronize() = 0; + + /** + * Notify all waiting clients that the connection is no longer locked. + */ + virtual void NotifyAll() = 0; + }; + + protected: + sqlite3 *m_connection; + + // Options + bool m_usingLucene; + + // Stored data procedures + int m_dataCommandsCount; + + // Synchronization object + std::unique_ptr m_synchronizationObject; + + virtual void Connect(const std::string &address, + Flag::Type = Flag::None, Flag::Option = Flag::RO); + virtual void Disconnect(); + + void TurnOnForeignKeys(); + + static SynchronizationObject *AllocDefaultSynchronizationObject(); + + public: + /** + * Open SQL connection + * + * Synchronization is archieved by using provided asynchronization object. + * If synchronizationObject is set to NULL, so synchronization is performed. + * Ownership of the synchronization object is transfered to sql connection + * object. + * + * @param address Database file name + * @param flags Open flags + * @param synchronizationObject A synchronization object to use. + */ + explicit SqlConnection(const std::string &address = std::string(), + Flag::Type flags = Flag::None, + Flag::Option options = Flag::RO, + SynchronizationObject *synchronizationObject = + AllocDefaultSynchronizationObject()); + + /** + * Destructor + */ + virtual ~SqlConnection(); + + /** + * Execute SQL command without result + * + * @param format + * @param ... + */ + void ExecCommand(const char *format, ...) DPL_DEPRECATED_WITH_MESSAGE( + "To prevent sql injection do not use this \ + method for direct sql execution"); + + /** + * Execute BEGIN; command to start new transaction + * + */ + void BeginTransaction(); + + /** + * Execute ROLLBACK; command to discard changes made + * + */ + void RollbackTransaction(); + + /** + * Execute COMMIT; command to commit changes in database + * + */ + void CommitTransaction(); + + /** + * Prepare stored procedure + * + * @param format SQL statement + * @return Data command representing stored procedure + */ + DataCommandAutoPtr PrepareDataCommand(const char *format, ...); + + /** + * Check whether given table exists + * + * @param tableName Name of the table to check + * @return True if given table name exists + */ + bool CheckTableExist(const char *tableName); + + /** + * Get last insert operation new row id + * + * @return Row ID + */ + RowID GetLastInsertRowID() const; +}; +} // namespace DB +} // namespace DPL + +#endif // DPL_SQL_CONNECTION_H diff --git a/src/server/dpl/db/src/naive_synchronization_object.cpp b/src/server/dpl/db/src/naive_synchronization_object.cpp new file mode 100644 index 0000000..1ac71ca --- /dev/null +++ b/src/server/dpl/db/src/naive_synchronization_object.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2011 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 naive_synchronization_object.cpp + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + * @brief This file is the implementation file of SQL naive + * synchronization object + */ +#include +#include +#include + +namespace { + unsigned int seed = time(NULL); +} + +namespace DPL { +namespace DB { +void NaiveSynchronizationObject::Synchronize() +{ + // Sleep for about 10ms - 30ms + Thread::MiliSleep(10 + rand_r(&seed) % 20); +} + +void NaiveSynchronizationObject::NotifyAll() +{ + // No need to inform about anything +} +} // namespace DB +} // namespace DPL diff --git a/src/server/dpl/db/src/sql_connection.cpp b/src/server/dpl/db/src/sql_connection.cpp new file mode 100644 index 0000000..57ea9b9 --- /dev/null +++ b/src/server/dpl/db/src/sql_connection.cpp @@ -0,0 +1,866 @@ +/* + * Copyright (c) 2011 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 sql_connection.cpp + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + * @brief This file is the implementation file of SQL connection + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace DPL { +namespace DB { +namespace // anonymous +{ +class ScopedNotifyAll : + public Noncopyable +{ + private: + SqlConnection::SynchronizationObject *m_synchronizationObject; + + public: + explicit ScopedNotifyAll( + SqlConnection::SynchronizationObject *synchronizationObject) : + m_synchronizationObject(synchronizationObject) + {} + + ~ScopedNotifyAll() + { + if (!m_synchronizationObject) { + return; + } + + LogPedantic("Notifying after successful synchronize"); + m_synchronizationObject->NotifyAll(); + } +}; +} // namespace anonymous + +SqlConnection::DataCommand::DataCommand(SqlConnection *connection, + const char *buffer) : + m_masterConnection(connection), + m_stmt(NULL) +{ + Assert(connection != NULL); + + // Notify all after potentially synchronized database connection access + ScopedNotifyAll notifyAll(connection->m_synchronizationObject.get()); + + for (;;) { + int ret = sqlite3_prepare_v2(connection->m_connection, + buffer, strlen(buffer), + &m_stmt, NULL); + + if (ret == SQLITE_OK) { + LogPedantic("Data command prepared successfuly"); + break; + } else if (ret == SQLITE_BUSY) { + LogPedantic("Collision occurred while preparing SQL command"); + + // Synchronize if synchronization object is available + if (connection->m_synchronizationObject) { + LogPedantic("Performing synchronization"); + connection->m_synchronizationObject->Synchronize(); + continue; + } + + // No synchronization object defined. Fail. + } + + // Fatal error + const char *error = sqlite3_errmsg(m_masterConnection->m_connection); + + LogPedantic("SQL prepare data command failed"); + LogPedantic(" Statement: " << buffer); + LogPedantic(" Error: " << error); + + ThrowMsg(Exception::SyntaxError, error); + } + + LogPedantic("Prepared data command: " << buffer); + + // Increment stored data command count + ++m_masterConnection->m_dataCommandsCount; +} + +SqlConnection::DataCommand::~DataCommand() +{ + LogPedantic("SQL data command finalizing"); + + if (sqlite3_finalize(m_stmt) != SQLITE_OK) { + LogPedantic("Failed to finalize data command"); + } + + // Decrement stored data command count + --m_masterConnection->m_dataCommandsCount; +} + +void SqlConnection::DataCommand::CheckBindResult(int result) +{ + if (result != SQLITE_OK) { + const char *error = sqlite3_errmsg( + m_masterConnection->m_connection); + + LogPedantic("Failed to bind SQL statement parameter"); + LogPedantic(" Error: " << error); + + ThrowMsg(Exception::SyntaxError, error); + } +} + +void SqlConnection::DataCommand::BindNull( + SqlConnection::ArgumentIndex position) +{ + CheckBindResult(sqlite3_bind_null(m_stmt, position)); + LogPedantic("SQL data command bind null: [" + << position << "]"); +} + +void SqlConnection::DataCommand::BindInteger( + SqlConnection::ArgumentIndex position, + int value) +{ + CheckBindResult(sqlite3_bind_int(m_stmt, position, value)); + LogPedantic("SQL data command bind integer: [" + << position << "] -> " << value); +} + +void SqlConnection::DataCommand::BindInt8( + SqlConnection::ArgumentIndex position, + int8_t value) +{ + CheckBindResult(sqlite3_bind_int(m_stmt, position, + static_cast(value))); + LogPedantic("SQL data command bind int8: [" + << position << "] -> " << value); +} + +void SqlConnection::DataCommand::BindInt16( + SqlConnection::ArgumentIndex position, + int16_t value) +{ + CheckBindResult(sqlite3_bind_int(m_stmt, position, + static_cast(value))); + LogPedantic("SQL data command bind int16: [" + << position << "] -> " << value); +} + +void SqlConnection::DataCommand::BindInt32( + SqlConnection::ArgumentIndex position, + int32_t value) +{ + CheckBindResult(sqlite3_bind_int(m_stmt, position, + static_cast(value))); + LogPedantic("SQL data command bind int32: [" + << position << "] -> " << value); +} + +void SqlConnection::DataCommand::BindInt64( + SqlConnection::ArgumentIndex position, + int64_t value) +{ + CheckBindResult(sqlite3_bind_int64(m_stmt, position, + static_cast(value))); + LogPedantic("SQL data command bind int64: [" + << position << "] -> " << value); +} + +void SqlConnection::DataCommand::BindFloat( + SqlConnection::ArgumentIndex position, + float value) +{ + CheckBindResult(sqlite3_bind_double(m_stmt, position, + static_cast(value))); + LogPedantic("SQL data command bind float: [" + << position << "] -> " << value); +} + +void SqlConnection::DataCommand::BindDouble( + SqlConnection::ArgumentIndex position, + double value) +{ + CheckBindResult(sqlite3_bind_double(m_stmt, position, value)); + LogPedantic("SQL data command bind double: [" + << position << "] -> " << value); +} + +void SqlConnection::DataCommand::BindString( + SqlConnection::ArgumentIndex position, + const char *value) +{ + if (!value) { + BindNull(position); + return; + } + + // Assume that text may disappear + CheckBindResult(sqlite3_bind_text(m_stmt, position, + value, strlen(value), + SQLITE_TRANSIENT)); + + LogPedantic("SQL data command bind string: [" + << position << "] -> " << value); +} + +void SqlConnection::DataCommand::BindString( + SqlConnection::ArgumentIndex position, + const String &value) +{ + BindString(position, ToUTF8String(value).c_str()); +} + +void SqlConnection::DataCommand::BindInteger( + SqlConnection::ArgumentIndex position, + const boost::optional &value) +{ + if (!value) { + BindNull(position); + } else { + BindInteger(position, *value); + } +} + +void SqlConnection::DataCommand::BindInt8( + SqlConnection::ArgumentIndex position, + const boost::optional &value) +{ + if (!value) { + BindNull(position); + } else { + BindInt8(position, *value); + } +} + +void SqlConnection::DataCommand::BindInt16( + SqlConnection::ArgumentIndex position, + const boost::optional &value) +{ + if (!value) { + BindNull(position); + } else { + BindInt16(position, *value); + } +} + +void SqlConnection::DataCommand::BindInt32( + SqlConnection::ArgumentIndex position, + const boost::optional &value) +{ + if (!value) { + BindNull(position); + } else { + BindInt32(position, *value); + } +} + +void SqlConnection::DataCommand::BindInt64( + SqlConnection::ArgumentIndex position, + const boost::optional &value) +{ + if (!value) { + BindNull(position); + } else { + BindInt64(position, *value); + } +} + +void SqlConnection::DataCommand::BindFloat( + SqlConnection::ArgumentIndex position, + const boost::optional &value) +{ + if (!value) { + BindNull(position); + } else { + BindFloat(position, *value); + } +} + +void SqlConnection::DataCommand::BindDouble( + SqlConnection::ArgumentIndex position, + const boost::optional &value) +{ + if (!value) { + BindNull(position); + } else { + BindDouble(position, *value); + } +} + +void SqlConnection::DataCommand::BindString( + SqlConnection::ArgumentIndex position, + const boost::optional &value) +{ + if (!!value) { + BindString(position, ToUTF8String(*value).c_str()); + } else { + BindNull(position); + } +} + +bool SqlConnection::DataCommand::Step() +{ + // Notify all after potentially synchronized database connection access + ScopedNotifyAll notifyAll( + m_masterConnection->m_synchronizationObject.get()); + + for (;;) { + int ret = sqlite3_step(m_stmt); + + if (ret == SQLITE_ROW) { + LogPedantic("SQL data command step ROW"); + return true; + } else if (ret == SQLITE_DONE) { + LogPedantic("SQL data command step DONE"); + return false; + } else if (ret == SQLITE_BUSY) { + LogPedantic("Collision occurred while executing SQL command"); + + // Synchronize if synchronization object is available + if (m_masterConnection->m_synchronizationObject) { + LogPedantic("Performing synchronization"); + + m_masterConnection-> + m_synchronizationObject->Synchronize(); + + continue; + } + + // No synchronization object defined. Fail. + } + + // Fatal error + const char *error = sqlite3_errmsg(m_masterConnection->m_connection); + + LogPedantic("SQL step data command failed"); + LogPedantic(" Error: " << error); + + ThrowMsg(Exception::InternalError, error); + } +} + +void SqlConnection::DataCommand::Reset() +{ + /* + * According to: + * http://www.sqlite.org/c3ref/stmt.html + * + * if last sqlite3_step command on this stmt returned an error, + * then sqlite3_reset will return that error, althought it is not an error. + * So sqlite3_reset allways succedes. + */ + sqlite3_reset(m_stmt); + + LogPedantic("SQL data command reset"); +} + +void SqlConnection::DataCommand::CheckColumnIndex( + SqlConnection::ColumnIndex column) +{ + if (column < 0 || column >= sqlite3_column_count(m_stmt)) { + ThrowMsg(Exception::InvalidColumn, "Column index is out of bounds"); + } +} + +bool SqlConnection::DataCommand::IsColumnNull( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column type: [" << column << "]"); + CheckColumnIndex(column); + return sqlite3_column_type(m_stmt, column) == SQLITE_NULL; +} + +int SqlConnection::DataCommand::GetColumnInteger( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column integer: [" << column << "]"); + CheckColumnIndex(column); + int value = sqlite3_column_int(m_stmt, column); + LogPedantic(" Value: " << value); + return value; +} + +int8_t SqlConnection::DataCommand::GetColumnInt8( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column int8: [" << column << "]"); + CheckColumnIndex(column); + int8_t value = static_cast(sqlite3_column_int(m_stmt, column)); + LogPedantic(" Value: " << value); + return value; +} + +int16_t SqlConnection::DataCommand::GetColumnInt16( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column int16: [" << column << "]"); + CheckColumnIndex(column); + int16_t value = static_cast(sqlite3_column_int(m_stmt, column)); + LogPedantic(" Value: " << value); + return value; +} + +int32_t SqlConnection::DataCommand::GetColumnInt32( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column int32: [" << column << "]"); + CheckColumnIndex(column); + int32_t value = static_cast(sqlite3_column_int(m_stmt, column)); + LogPedantic(" Value: " << value); + return value; +} + +int64_t SqlConnection::DataCommand::GetColumnInt64( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column int64: [" << column << "]"); + CheckColumnIndex(column); + int64_t value = static_cast(sqlite3_column_int64(m_stmt, column)); + LogPedantic(" Value: " << value); + return value; +} + +float SqlConnection::DataCommand::GetColumnFloat( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column float: [" << column << "]"); + CheckColumnIndex(column); + float value = static_cast(sqlite3_column_double(m_stmt, column)); + LogPedantic(" Value: " << value); + return value; +} + +double SqlConnection::DataCommand::GetColumnDouble( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column double: [" << column << "]"); + CheckColumnIndex(column); + double value = sqlite3_column_double(m_stmt, column); + LogPedantic(" Value: " << value); + return value; +} + +std::string SqlConnection::DataCommand::GetColumnString( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column string: [" << column << "]"); + CheckColumnIndex(column); + + const char *value = reinterpret_cast( + sqlite3_column_text(m_stmt, column)); + + LogPedantic("Value: " << (value ? value : "NULL")); + + if (value == NULL) { + return std::string(); + } + + return std::string(value); +} + +boost::optional SqlConnection::DataCommand::GetColumnOptionalInteger( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column optional integer: [" + << column << "]"); + CheckColumnIndex(column); + if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { + return boost::optional(); + } + int value = sqlite3_column_int(m_stmt, column); + LogPedantic(" Value: " << value); + return boost::optional(value); +} + +boost::optional SqlConnection::DataCommand::GetColumnOptionalInt8( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column optional int8: [" + << column << "]"); + CheckColumnIndex(column); + if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { + return boost::optional(); + } + int8_t value = static_cast(sqlite3_column_int(m_stmt, column)); + LogPedantic(" Value: " << value); + return boost::optional(value); +} + +boost::optional SqlConnection::DataCommand::GetColumnOptionalInt16( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column optional int16: [" + << column << "]"); + CheckColumnIndex(column); + if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { + return boost::optional(); + } + int16_t value = static_cast(sqlite3_column_int(m_stmt, column)); + LogPedantic(" Value: " << value); + return boost::optional(value); +} + +boost::optional SqlConnection::DataCommand::GetColumnOptionalInt32( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column optional int32: [" + << column << "]"); + CheckColumnIndex(column); + if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { + return boost::optional(); + } + int32_t value = static_cast(sqlite3_column_int(m_stmt, column)); + LogPedantic(" Value: " << value); + return boost::optional(value); +} + +boost::optional SqlConnection::DataCommand::GetColumnOptionalInt64( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column optional int64: [" + << column << "]"); + CheckColumnIndex(column); + if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { + return boost::optional(); + } + int64_t value = static_cast(sqlite3_column_int64(m_stmt, column)); + LogPedantic(" Value: " << value); + return boost::optional(value); +} + +boost::optional SqlConnection::DataCommand::GetColumnOptionalFloat( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column optional float: [" + << column << "]"); + CheckColumnIndex(column); + if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { + return boost::optional(); + } + float value = static_cast(sqlite3_column_double(m_stmt, column)); + LogPedantic(" Value: " << value); + return boost::optional(value); +} + +boost::optional SqlConnection::DataCommand::GetColumnOptionalDouble( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column optional double: [" + << column << "]"); + CheckColumnIndex(column); + if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { + return boost::optional(); + } + double value = sqlite3_column_double(m_stmt, column); + LogPedantic(" Value: " << value); + return boost::optional(value); +} + +boost::optional SqlConnection::DataCommand::GetColumnOptionalString( + SqlConnection::ColumnIndex column) +{ + LogPedantic("SQL data command get column optional string: [" + << column << "]"); + CheckColumnIndex(column); + if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) { + return boost::optional(); + } + const char *value = reinterpret_cast( + sqlite3_column_text(m_stmt, column)); + LogPedantic("Value: " << value); + String s = FromUTF8String(value); + return boost::optional(s); +} + +void SqlConnection::Connect(const std::string &address, + Flag::Type type, + Flag::Option flag) +{ + if (m_connection != NULL) { + LogPedantic("Already connected."); + return; + } + LogPedantic("Connecting to DB: " << address << "..."); + + // Connect to database + int result; + if (type & Flag::UseLucene) { + result = db_util_open_with_options( + address.c_str(), + &m_connection, + flag, + NULL); + + m_usingLucene = true; + LogPedantic("Lucene index enabled"); + } else { + result = sqlite3_open_v2( + address.c_str(), + &m_connection, + flag, + NULL); + + m_usingLucene = false; + LogPedantic("Lucene index disabled"); + } + + if (result == SQLITE_OK) { + LogPedantic("Connected to DB"); + } else { + LogPedantic("Failed to connect to DB!"); + ThrowMsg(Exception::ConnectionBroken, address); + } + + // Enable foreign keys + TurnOnForeignKeys(); +} + +void SqlConnection::Disconnect() +{ + if (m_connection == NULL) { + LogPedantic("Already disconnected."); + return; + } + + LogPedantic("Disconnecting from DB..."); + + // All stored data commands must be deleted before disconnect + AssertMsg(m_dataCommandsCount == 0, + "All stored procedures must be deleted" + " before disconnecting SqlConnection"); + + int result; + + if (m_usingLucene) { + result = db_util_close(m_connection); + } else { + result = sqlite3_close(m_connection); + } + + if (result != SQLITE_OK) { + const char *error = sqlite3_errmsg(m_connection); + LogPedantic("SQL close failed"); + LogPedantic(" Error: " << error); + Throw(Exception::InternalError); + } + + m_connection = NULL; + + LogPedantic("Disconnected from DB"); +} + +bool SqlConnection::CheckTableExist(const char *tableName) +{ + if (m_connection == NULL) { + LogPedantic("Cannot execute command. Not connected to DB!"); + return false; + } + + DataCommandAutoPtr command = + PrepareDataCommand("select tbl_name from sqlite_master where name=?;"); + + command->BindString(1, tableName); + + if (!command->Step()) { + LogPedantic("No matching records in table"); + return false; + } + + return command->GetColumnString(0) == tableName; +} + +SqlConnection::SqlConnection(const std::string &address, + Flag::Type flag, + Flag::Option option, + SynchronizationObject *synchronizationObject) : + m_connection(NULL), + m_usingLucene(false), + m_dataCommandsCount(0), + m_synchronizationObject(synchronizationObject) +{ + LogPedantic("Opening database connection to: " << address); + + // Connect to DB + SqlConnection::Connect(address, flag, option); + + if (!m_synchronizationObject) { + LogPedantic("No synchronization object defined"); + } +} + +SqlConnection::~SqlConnection() +{ + LogPedantic("Closing database connection"); + + // Disconnect from DB + Try + { + SqlConnection::Disconnect(); + } + Catch(Exception::Base) + { + LogPedantic("Failed to disconnect from database"); + } +} + +void SqlConnection::ExecCommand(const char *format, ...) +{ + if (m_connection == NULL) { + LogPedantic("Cannot execute command. Not connected to DB!"); + return; + } + + if (format == NULL) { + LogPedantic("Null query!"); + ThrowMsg(Exception::SyntaxError, "Null statement"); + } + + char *rawBuffer; + + va_list args; + va_start(args, format); + + if (vasprintf(&rawBuffer, format, args) == -1) { + rawBuffer = NULL; + } + + va_end(args); + + std::unique_ptr buffer(rawBuffer); + + if (!buffer) { + LogPedantic("Failed to allocate statement string"); + return; + } + + LogPedantic("Executing SQL command: " << buffer.get()); + + // Notify all after potentially synchronized database connection access + ScopedNotifyAll notifyAll(m_synchronizationObject.get()); + + for (;;) { + char *errorBuffer; + + int ret = sqlite3_exec(m_connection, + buffer.get(), + NULL, + NULL, + &errorBuffer); + + std::string errorMsg; + + // Take allocated error buffer + if (errorBuffer != NULL) { + errorMsg = errorBuffer; + sqlite3_free(errorBuffer); + } + + if (ret == SQLITE_OK) { + return; + } + + if (ret == SQLITE_BUSY) { + LogPedantic("Collision occurred while executing SQL command"); + + // Synchronize if synchronization object is available + if (m_synchronizationObject) { + LogPedantic("Performing synchronization"); + m_synchronizationObject->Synchronize(); + continue; + } + + // No synchronization object defined. Fail. + } + + // Fatal error + LogPedantic("Failed to execute SQL command. Error: " << errorMsg); + ThrowMsg(Exception::SyntaxError, errorMsg); + } +} + +SqlConnection::DataCommandAutoPtr SqlConnection::PrepareDataCommand( + const char *format, + ...) +{ + if (m_connection == NULL) { + LogPedantic("Cannot execute data command. Not connected to DB!"); + return DataCommandAutoPtr(); + } + + char *rawBuffer; + + va_list args; + va_start(args, format); + + if (vasprintf(&rawBuffer, format, args) == -1) { + rawBuffer = NULL; + } + + va_end(args); + + std::unique_ptr buffer(rawBuffer); + + if (!buffer) { + LogPedantic("Failed to allocate statement string"); + return DataCommandAutoPtr(); + } + + LogPedantic("Executing SQL data command: " << buffer.get()); + + return DataCommandAutoPtr(new DataCommand(this, buffer.get())); +} + +SqlConnection::RowID SqlConnection::GetLastInsertRowID() const +{ + return static_cast(sqlite3_last_insert_rowid(m_connection)); +} + +void SqlConnection::TurnOnForeignKeys() +{ + ExecCommand("PRAGMA foreign_keys = ON;"); +} + +void SqlConnection::BeginTransaction() +{ + ExecCommand("BEGIN;"); +} + +void SqlConnection::RollbackTransaction() +{ + ExecCommand("ROLLBACK;"); +} + +void SqlConnection::CommitTransaction() +{ + ExecCommand("COMMIT;"); +} + +SqlConnection::SynchronizationObject * +SqlConnection::AllocDefaultSynchronizationObject() +{ + return new NaiveSynchronizationObject(); +} +} // namespace DB +} // namespace DPL -- 2.7.4 From 61c90ed1c4f8a63b323a9b471f27fb08c86aa570 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 2 Jun 2014 19:10:59 +0200 Subject: [PATCH 08/16] DPL: work around for dependency on DPL::Thread Patch based on work by similar work by Zofia Abramowska. Include needed parts from DPL::Thread into code of NaiveSynchronizationObject. Only NanoSleep() and MiliSleep() methods are needed and the original DPL::Thread() triggers a large chain of dependencies, including EFL. Change-Id: Icf8257ca8eeaa5cdbc4d80ceb98d88aceeec7821 Signed-off-by: Rafal Krypa --- .../dpl/db/src/naive_synchronization_object.cpp | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/server/dpl/db/src/naive_synchronization_object.cpp b/src/server/dpl/db/src/naive_synchronization_object.cpp index 1ac71ca..63f1dd7 100644 --- a/src/server/dpl/db/src/naive_synchronization_object.cpp +++ b/src/server/dpl/db/src/naive_synchronization_object.cpp @@ -22,12 +22,53 @@ */ #include #include -#include +#include +#include namespace { unsigned int seed = time(NULL); } +//Taken from Thread class, so we don't have to pull whole definition +//(only this part is needed) +namespace Thread { + +static const size_t NANOSECONDS_PER_SECOND = + static_cast(1000 * 1000 * 1000); + +static const size_t NANOSECONDS_PER_MILISECOND = + static_cast(1000 * 1000); + +void NanoSleep(uint64_t nanoseconds) +{ + timespec requestedTime = { + static_cast( + nanoseconds / NANOSECONDS_PER_SECOND), + + static_cast( + nanoseconds % NANOSECONDS_PER_SECOND) + }; + + timespec remainingTime; + + for (;;) { + if (nanosleep(&requestedTime, &remainingTime) == 0) { + break; + } + + int error = errno; + Assert(error == EINTR); + + requestedTime = remainingTime; + } +} + +void MiliSleep(uint64_t miliseconds) +{ + NanoSleep(miliseconds * NANOSECONDS_PER_MILISECOND); +} +} + namespace DPL { namespace DB { void NaiveSynchronizationObject::Synchronize() -- 2.7.4 From 68215983b9a6a588f5c16bef22f0882234d8a5d5 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Wed, 18 Jun 2014 16:05:25 +0200 Subject: [PATCH 09/16] DPL: work around for build warnings with -Werror DPL::SqlConnection::ExecCommand() is marked as deprecated to warn it's users. It's not deprecated, but could cause SQL Injection. This method is also used internally for transactions. Such combination causes build warnings. But this repository is built with -Werror flags and it breaks the build. Since this method is not needed outside SqlConnection, move it to private methods and remove the warning. Change-Id: I088f4736ecca318613b897ef05b12af4cdc1f664 Signed-off-by: Rafal Krypa --- src/server/dpl/db/include/dpl/db/sql_connection.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/server/dpl/db/include/dpl/db/sql_connection.h b/src/server/dpl/db/include/dpl/db/sql_connection.h index 18a5d3f..6bd6cf9 100644 --- a/src/server/dpl/db/include/dpl/db/sql_connection.h +++ b/src/server/dpl/db/include/dpl/db/sql_connection.h @@ -432,6 +432,14 @@ class SqlConnection static SynchronizationObject *AllocDefaultSynchronizationObject(); + /** + * Execute SQL command without result + * + * @param format + * @param ... + */ + void ExecCommand(const char *format, ...); + public: /** * Open SQL connection @@ -457,16 +465,6 @@ class SqlConnection virtual ~SqlConnection(); /** - * Execute SQL command without result - * - * @param format - * @param ... - */ - void ExecCommand(const char *format, ...) DPL_DEPRECATED_WITH_MESSAGE( - "To prevent sql injection do not use this \ - method for direct sql execution"); - - /** * Execute BEGIN; command to start new transaction * */ -- 2.7.4 From fd64eeaf5680a64b2f5c40d79e206932fe2a3700 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Wed, 18 Jun 2014 16:08:22 +0200 Subject: [PATCH 10/16] DPL: changing namespace of imported classes to SecurityManager DPL code uses DPL namespace, moving it to SecurityManager. Change-Id: I89f1c6c8b965085546064856045145c9c6d0ac3a Signed-off-by: Rafal Krypa --- src/server/dpl/core/include/dpl/availability.h | 14 +++++++------- src/server/dpl/core/include/dpl/char_traits.h | 10 +++++----- src/server/dpl/core/include/dpl/errno_string.h | 12 ++++++------ src/server/dpl/core/include/dpl/free_deleter.h | 4 ++-- src/server/dpl/core/include/dpl/fstream_accessors.h | 4 ++-- src/server/dpl/core/include/dpl/string.h | 18 +++++++++--------- src/server/dpl/core/src/errno_string.cpp | 4 ++-- src/server/dpl/core/src/string.cpp | 10 +++++----- .../db/include/dpl/db/naive_synchronization_object.h | 10 +++++----- src/server/dpl/db/include/dpl/db/sql_connection.h | 12 ++++++------ src/server/dpl/db/src/naive_synchronization_object.cpp | 4 ++-- src/server/dpl/db/src/sql_connection.cpp | 4 ++-- 12 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/server/dpl/core/include/dpl/availability.h b/src/server/dpl/core/include/dpl/availability.h index 0813892..5892953 100644 --- a/src/server/dpl/core/include/dpl/availability.h +++ b/src/server/dpl/core/include/dpl/availability.h @@ -18,13 +18,13 @@ * @author Jihoon Chung (jihoon.chung@samsung.com) * @version 1.0 */ -#ifndef DPL_AVAILABILITY_H -#define DPL_AVAILABILITY_H +#ifndef SECURITY_MANAGER_AVAILABILITY_H +#define SECURITY_MANAGER_AVAILABILITY_H -#define DPL_DEPRECATED __attribute__((deprecated)) -#define DPL_DEPRECATED_WITH_MESSAGE(msg) __attribute__((deprecated(msg))) +#define SECURITY_MANAGER_DEPRECATED __attribute__((deprecated)) +#define SECURITY_MANAGER_DEPRECATED_WITH_MESSAGE(msg) __attribute__((deprecated(msg))) -#define DPL_UNUSED __attribute__((unused)) -#define DPL_UNUSED_PARAM(variable) (void)variable +#define SECURITY_MANAGER_UNUSED __attribute__((unused)) +#define SECURITY_MANAGER_UNUSED_PARAM(variable) (void)variable -#endif // DPL_AVAILABILITY_H +#endif // SECURITY_MANAGER_AVAILABILITY_H diff --git a/src/server/dpl/core/include/dpl/char_traits.h b/src/server/dpl/core/include/dpl/char_traits.h index eb2988f..8c173e8 100644 --- a/src/server/dpl/core/include/dpl/char_traits.h +++ b/src/server/dpl/core/include/dpl/char_traits.h @@ -22,8 +22,8 @@ * Current char traits could be extended in feature to boost * performance */ -#ifndef DPL_CHAR_TRAITS -#define DPL_CHAR_TRAITS +#ifndef SECURITY_MANAGER_CHAR_TRAITS +#define SECURITY_MANAGER_CHAR_TRAITS #include #include @@ -31,8 +31,8 @@ #include #include -namespace DPL { +namespace SecurityManager { typedef std::char_traits CharTraits; -} // namespace DPL +} // namespace SecurityManager -#endif // DPL_CHAR_TRAITS +#endif // SECURITY_MANAGER_CHAR_TRAITS diff --git a/src/server/dpl/core/include/dpl/errno_string.h b/src/server/dpl/core/include/dpl/errno_string.h index 446dbc9..ebf0274 100644 --- a/src/server/dpl/core/include/dpl/errno_string.h +++ b/src/server/dpl/core/include/dpl/errno_string.h @@ -19,17 +19,17 @@ * @version 1.0 * @brief This file is the implementation file of errno string */ -#ifndef DPL_ERRNO_STRING_H -#define DPL_ERRNO_STRING_H +#ifndef SECURITY_MANAGER_ERRNO_STRING_H +#define SECURITY_MANAGER_ERRNO_STRING_H #include #include #include -namespace DPL { -DECLARE_EXCEPTION_TYPE(DPL::Exception, InvalidErrnoValue) +namespace SecurityManager { +DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, InvalidErrnoValue) std::string GetErrnoString(int error = errno); -} // namespace DPL +} // namespace SecurityManager -#endif // DPL_ERRNO_STRING_H +#endif // SECURITY_MANAGER_ERRNO_STRING_H diff --git a/src/server/dpl/core/include/dpl/free_deleter.h b/src/server/dpl/core/include/dpl/free_deleter.h index 4a09904..80b835f 100644 --- a/src/server/dpl/core/include/dpl/free_deleter.h +++ b/src/server/dpl/core/include/dpl/free_deleter.h @@ -23,11 +23,11 @@ #define FREE_DELETER_H #include -namespace DPL +namespace SecurityManager { struct free_deleter { void operator()(void *p) { std::free(p); } }; -}// DPL +}// SecurityManager #endif // FREE_DELETER_H diff --git a/src/server/dpl/core/include/dpl/fstream_accessors.h b/src/server/dpl/core/include/dpl/fstream_accessors.h index 5d6379a..09f2dc2 100644 --- a/src/server/dpl/core/include/dpl/fstream_accessors.h +++ b/src/server/dpl/core/include/dpl/fstream_accessors.h @@ -25,7 +25,7 @@ #ifndef SECURITY_MANAGER_FSTREAM_ACCESSORS_H #define SECURITY_MANAGER_FSTREAM_ACCESSORS_H -namespace DPL { +namespace SecurityManager { /* * Bypass lack of public member function to get file @@ -43,6 +43,6 @@ public: } }; -} // namespace DPL +} // namespace SecurityManager #endif // SECURITY_MANAGER_FSTREAM_ACCESSORS_H diff --git a/src/server/dpl/core/include/dpl/string.h b/src/server/dpl/core/include/dpl/string.h index e4dc923..168c000 100644 --- a/src/server/dpl/core/include/dpl/string.h +++ b/src/server/dpl/core/include/dpl/string.h @@ -18,8 +18,8 @@ * @author Piotr Marcinkiewicz (p.marcinkiew@samsung.com) * @version 1.0 */ -#ifndef DPL_STRING -#define DPL_STRING +#ifndef SECURITY_MANAGER_STRING +#define SECURITY_MANAGER_STRING #include #include @@ -27,7 +27,7 @@ #include #include -namespace DPL { +namespace SecurityManager { // @brief DPL string typedef std::basic_string String; @@ -35,7 +35,7 @@ typedef std::basic_string String; class StringException { public: - DECLARE_EXCEPTION_TYPE(DPL::Exception, Base) + DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base) // @brief Invalid init for UTF8 to UTF32 converter DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF8ToUTF32) @@ -56,10 +56,10 @@ class StringException DECLARE_EXCEPTION_TYPE(Base, ICUInvalidCharacterFound) }; -//!\brief convert ASCII string to DPL::String +//!\brief convert ASCII string to SecurityManager::String String FromASCIIString(const std::string& aString); -//!\brief convert UTF32 string to DPL::String +//!\brief convert UTF32 string to SecurityManager::String String FromUTF32String(const std::wstring& aString); //@brief Returns String object created from UTF8 string @@ -150,8 +150,8 @@ template void Trim(StringType & obj, typename StringType::cons } -} //namespace DPL +} //namespace SecurityManager -std::ostream& operator<<(std::ostream& aStream, const DPL::String& aString); +std::ostream& operator<<(std::ostream& aStream, const SecurityManager::String& aString); -#endif // DPL_STRING +#endif // SECURITY_MANAGER_STRING diff --git a/src/server/dpl/core/src/errno_string.cpp b/src/server/dpl/core/src/errno_string.cpp index 6c59776..b5de431 100644 --- a/src/server/dpl/core/src/errno_string.cpp +++ b/src/server/dpl/core/src/errno_string.cpp @@ -33,7 +33,7 @@ #include #include -namespace DPL { +namespace SecurityManager { namespace // anonymous { const size_t DEFAULT_ERRNO_STRING_SIZE = 32; @@ -96,4 +96,4 @@ std::string GetErrnoString(int error) } } } -} // namespace DPL +} // namespace SecurityManager diff --git a/src/server/dpl/core/src/string.cpp b/src/server/dpl/core/src/string.cpp index a642eaa..718fb06 100644 --- a/src/server/dpl/core/src/string.cpp +++ b/src/server/dpl/core/src/string.cpp @@ -35,7 +35,7 @@ #include // TODO: Completely move to ICU -namespace DPL { +namespace SecurityManager { namespace //anonymous { class ASCIIValidator @@ -122,7 +122,7 @@ String FromUTF8String(const std::string& aIn) return &output[1]; } -std::string ToUTF8String(const DPL::String& aIn) +std::string ToUTF8String(const SecurityManager::String& aIn) { if (aIn.empty()) { return std::string(); @@ -242,9 +242,9 @@ int StringCompare(const String &left, return static_cast(u_strcmp(leftICU.get(), rightICU.get())); } } -} //namespace DPL +} //namespace SecurityManager -std::ostream& operator<<(std::ostream& aStream, const DPL::String& aString) +std::ostream& operator<<(std::ostream& aStream, const SecurityManager::String& aString) { - return aStream << DPL::ToUTF8String(aString); + return aStream << SecurityManager::ToUTF8String(aString); } diff --git a/src/server/dpl/db/include/dpl/db/naive_synchronization_object.h b/src/server/dpl/db/include/dpl/db/naive_synchronization_object.h index 2f63a0f..ad4192f 100644 --- a/src/server/dpl/db/include/dpl/db/naive_synchronization_object.h +++ b/src/server/dpl/db/include/dpl/db/naive_synchronization_object.h @@ -20,12 +20,12 @@ * @brief This file is the implementation file of SQL naive * synchronization object */ -#ifndef DPL_NAIVE_SYNCHRONIZATION_OBJECT_H -#define DPL_NAIVE_SYNCHRONIZATION_OBJECT_H +#ifndef SECURITY_MANAGER_NAIVE_SYNCHRONIZATION_OBJECT_H +#define SECURITY_MANAGER_NAIVE_SYNCHRONIZATION_OBJECT_H #include -namespace DPL { +namespace SecurityManager { namespace DB { /** * Naive synchronization object used to synchronize SQL connection @@ -40,6 +40,6 @@ class NaiveSynchronizationObject : virtual void NotifyAll(); }; } // namespace DB -} // namespace DPL +} // namespace SecurityManager -#endif // DPL_NAIVE_SYNCHRONIZATION_OBJECT_H +#endif // SECURITY_MANAGER_NAIVE_SYNCHRONIZATION_OBJECT_H diff --git a/src/server/dpl/db/include/dpl/db/sql_connection.h b/src/server/dpl/db/include/dpl/db/sql_connection.h index 6bd6cf9..373ad7f 100644 --- a/src/server/dpl/db/include/dpl/db/sql_connection.h +++ b/src/server/dpl/db/include/dpl/db/sql_connection.h @@ -19,8 +19,8 @@ * @version 1.0 * @brief This file is the implementation file of SQL connection */ -#ifndef DPL_SQL_CONNECTION_H -#define DPL_SQL_CONNECTION_H +#ifndef SECURITY_MANAGER_SQL_CONNECTION_H +#define SECURITY_MANAGER_SQL_CONNECTION_H #include #include @@ -35,7 +35,7 @@ #include #include -namespace DPL { +namespace SecurityManager { namespace DB { /** * SQL connection class @@ -49,7 +49,7 @@ class SqlConnection class Exception { public: - DECLARE_EXCEPTION_TYPE(DPL::Exception, Base) + DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base) DECLARE_EXCEPTION_TYPE(Base, SyntaxError) DECLARE_EXCEPTION_TYPE(Base, ConnectionBroken) DECLARE_EXCEPTION_TYPE(Base, InternalError) @@ -506,6 +506,6 @@ class SqlConnection RowID GetLastInsertRowID() const; }; } // namespace DB -} // namespace DPL +} // namespace SecurityManager -#endif // DPL_SQL_CONNECTION_H +#endif // SECURITY_MANAGER_SQL_CONNECTION_H diff --git a/src/server/dpl/db/src/naive_synchronization_object.cpp b/src/server/dpl/db/src/naive_synchronization_object.cpp index 63f1dd7..a96897f 100644 --- a/src/server/dpl/db/src/naive_synchronization_object.cpp +++ b/src/server/dpl/db/src/naive_synchronization_object.cpp @@ -69,7 +69,7 @@ void MiliSleep(uint64_t miliseconds) } } -namespace DPL { +namespace SecurityManager { namespace DB { void NaiveSynchronizationObject::Synchronize() { @@ -82,4 +82,4 @@ void NaiveSynchronizationObject::NotifyAll() // No need to inform about anything } } // namespace DB -} // namespace DPL +} // namespace SecurityManager diff --git a/src/server/dpl/db/src/sql_connection.cpp b/src/server/dpl/db/src/sql_connection.cpp index 57ea9b9..fdb4fe4 100644 --- a/src/server/dpl/db/src/sql_connection.cpp +++ b/src/server/dpl/db/src/sql_connection.cpp @@ -31,7 +31,7 @@ #include #include -namespace DPL { +namespace SecurityManager { namespace DB { namespace // anonymous { @@ -863,4 +863,4 @@ SqlConnection::AllocDefaultSynchronizationObject() return new NaiveSynchronizationObject(); } } // namespace DB -} // namespace DPL +} // namespace SecurityManager -- 2.7.4 From e33cc12dd19d63474b5b43b168f2469397f695b5 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 23 Jun 2014 16:25:23 +0200 Subject: [PATCH 11/16] Use std::stringstream for parsing Smack rules This leads to simpler and more robust implementation of SmackRules class. Change-Id: I806da78fd6b95b9edcbb21b71c13e9bcb10b10df Signed-off-by: Rafal Krypa --- src/server/service/smack-rules.cpp | 46 +++++++++----------------------------- src/server/service/smack-rules.h | 1 - 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/server/service/smack-rules.cpp b/src/server/service/smack-rules.cpp index 687795e..dc57d5c 100644 --- a/src/server/service/smack-rules.cpp +++ b/src/server/service/smack-rules.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -153,16 +154,16 @@ bool SmackRules::addFromTemplateFile(const std::string &pkgId) bool SmackRules::addFromTemplate(const std::vector &templateRules, const std::string &pkgId) { - std::string tokens[3]; - std::string &subject = tokens[0]; - std::string &object = tokens[1]; - std::string &permissions = tokens[2]; - - for (auto rule = templateRules.begin(); rule != templateRules.end(); ++rule) { - if (rule->length() == 0) + for (auto rule : templateRules) { + if (rule.empty()) continue; - if (!tokenizeRule(*rule, tokens, sizeof(tokens) / sizeof(*tokens))) { + std::stringstream stream(rule); + std::string subject, object, permissions; + stream >> subject >> object >> permissions; + + if (stream.fail() || !stream.eof()) { + LogError("Invalid rule template: " << rule); return false; } @@ -170,7 +171,7 @@ bool SmackRules::addFromTemplate(const std::vector &templateRules, bool objectIsTemplate = (object == SMACK_APP_LABEL_TEMPLATE); if (objectIsTemplate == subjectIsTemplate) { - LogError("Invalid rule template. Exactly one app label template expected: " << *rule); + LogError("Invalid rule template. Exactly one app label template expected: " << rule); return false; } @@ -197,33 +198,6 @@ bool SmackRules::addFromTemplate(const std::vector &templateRules, return true; } - -bool SmackRules::tokenizeRule(const std::string &rule, std::string tokens[], int size) -{ - size_t startPos; - size_t endPos = 0; - const char delimiters[] = " \t\n\r"; - - for (int i = 0; i < size; i++) { - startPos = rule.find_first_not_of(delimiters, endPos); - if (startPos == std::string::npos) { - LogError("Unexpected end of rule: " << rule); - return false; - } - - endPos = rule.find_first_of(delimiters, startPos); - tokens[i] = rule.substr(startPos, endPos - startPos); - } - - if (endPos != std::string::npos && - rule.find_first_not_of(delimiters, endPos) != std::string::npos) { - LogError("Too many tokens found in rule: " << rule); - return false; - } - - return true; -} - std::string SmackRules::getPackageRulesFilePath(const std::string &pkgId) { std::string path(APP_RULES_DIRECTORY); diff --git a/src/server/service/smack-rules.h b/src/server/service/smack-rules.h index bf50a4d..b9ab765 100644 --- a/src/server/service/smack-rules.h +++ b/src/server/service/smack-rules.h @@ -70,7 +70,6 @@ public: */ static bool uninstallPackageRules(const std::string &pkgId); private: - static bool tokenizeRule(const std::string &rule, std::string tokens[], int size); static std::string getPackageRulesFilePath(const std::string &pkgId); smack_accesses *m_handle; -- 2.7.4 From 308598640307922d2cbce27768af7fd39390089b Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 23 Jun 2014 17:32:41 +0200 Subject: [PATCH 12/16] Make generateAppLabel() a static funcion of SmackRules class Eliminate security-manager-common.cpp containing a single function, which now logically belongs to SmackRules class. Change-Id: I5e7c063a5980d97b67c7f9640812d9890e24b2c7 Signed-off-by: Rafal Krypa --- src/server/CMakeLists.txt | 1 - src/server/service/installer.cpp | 3 +- src/server/service/security-manager-common.cpp | 40 ----------------------- src/server/service/security-manager-common.h | 45 -------------------------- src/server/service/smack-rules.cpp | 12 +++++-- src/server/service/smack-rules.h | 10 ++++++ 6 files changed, 20 insertions(+), 91 deletions(-) delete mode 100644 src/server/service/security-manager-common.cpp delete mode 100644 src/server/service/security-manager-common.h diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 73e3c00..a53d379 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -20,7 +20,6 @@ SET(COMMON_SOURCES ${COMMON_PATH}/dpl/core/src/noncopyable.cpp ${COMMON_PATH}/dpl/core/src/serialization.cpp ${COMMON_PATH}/dpl/core/src/singleton.cpp - ${COMMON_PATH}/service/security-manager-common.cpp ) INCLUDE_DIRECTORIES(SYSTEM diff --git a/src/server/service/installer.cpp b/src/server/service/installer.cpp index 8de407d..a1ade47 100644 --- a/src/server/service/installer.cpp +++ b/src/server/service/installer.cpp @@ -39,7 +39,6 @@ #include "protocols.h" #include "security-manager.h" #include "smack-rules.h" -#include "security-manager-common.h" namespace SecurityManager { @@ -232,7 +231,7 @@ bool setupPath(const std::string &pkgId, const std::pair &appP switch (pathType) { case SECURITY_MANAGER_PATH_PRIVATE: - if(!generateAppLabel(pkgId,label)) + if (!SmackRules::generateAppLabel(pkgId, label)) return false; label_executables = true; label_transmute = false; diff --git a/src/server/service/security-manager-common.cpp b/src/server/service/security-manager-common.cpp deleted file mode 100644 index 2ae363a..0000000 --- a/src/server/service/security-manager-common.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Rafal Krypa - * - * 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 security-manager-common.cpp - * @author Jan Cybulski - * @version 1.0 - * @brief This file contains implementation of utility functions for security-manager - * - */ - - -#include "security-manager-common.h" - - -namespace SecurityManager { - -bool generateAppLabel(const std::string &appPkgId, std::string &label) -{ - (void) appPkgId; //todo use pkgId to generate label - label = "User"; - return true; -} - -} // namespace SecurityManager - diff --git a/src/server/service/security-manager-common.h b/src/server/service/security-manager-common.h deleted file mode 100644 index 2f1a24b..0000000 --- a/src/server/service/security-manager-common.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Rafal Krypa - * - * 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 security-manager-common.h - * @author Jan Cybulski - * @version 1.0 - * @brief This file is header for utility functions for security-manager - * - */ -#ifndef _SECURITY_MANAGER_COMMON_H_ -#define _SECURITY_MANAGER_COMMON_H_ - -#include - - -namespace SecurityManager { - -/** - * This function generates label for application with package identifier - * read from @ref appPkgId and assigns it to @ref label. - * @param[in] appPkgId application's package identifier. - * @param[out] label string into which application's label will be stored into. - * @return true on success, false on error. - */ -bool generateAppLabel(const std::string &appPkgId, std::string &label); - - -} // namespace SecurityManager - -#endif diff --git a/src/server/service/smack-rules.cpp b/src/server/service/smack-rules.cpp index dc57d5c..21089b7 100644 --- a/src/server/service/smack-rules.cpp +++ b/src/server/service/smack-rules.cpp @@ -35,7 +35,6 @@ #include #include "smack-rules.h" -#include "security-manager-common.h" namespace SecurityManager { @@ -43,6 +42,13 @@ const char *const SMACK_APP_LABEL_TEMPLATE = "~APP~"; const char *const APP_RULES_TEMPLATE_FILE_PATH = "/etc/smack/app-rules-template.smack"; const char *const APP_RULES_DIRECTORY = "/etc/smack/accesses.d/"; +bool SmackRules::generateAppLabel(const std::string &appPkgId, std::string &label) +{ + (void) appPkgId; //todo use pkgId to generate label + label = "User"; + return true; +} + SmackRules::SmackRules() { if (smack_accesses_new(&m_handle) < 0) { @@ -176,14 +182,14 @@ bool SmackRules::addFromTemplate(const std::vector &templateRules, } if (subjectIsTemplate) { - if (!SecurityManager::generateAppLabel(pkgId, subject)) { + if (!generateAppLabel(pkgId, subject)) { LogError("Failed to generate app label from pkgid: " << pkgId); return false; } } if (objectIsTemplate) { - if (!SecurityManager::generateAppLabel(pkgId, object)) { + if (!generateAppLabel(pkgId, object)) { LogError("Failed to generate app label from pkgid: " << pkgId); return false; } diff --git a/src/server/service/smack-rules.h b/src/server/service/smack-rules.h index b9ab765..6aa6775 100644 --- a/src/server/service/smack-rules.h +++ b/src/server/service/smack-rules.h @@ -69,6 +69,16 @@ public: * false otherwise */ static bool uninstallPackageRules(const std::string &pkgId); + + /** + * Generates label for application with package identifier + * read from @ref appPkgId and assigns it to @ref label. + * @param[in] appPkgId application's package identifier. + * @param[out] label string into which application's label will be stored into. + * @return true on success, false on error. + */ + static bool generateAppLabel(const std::string &appPkgId, std::string &label); + private: static std::string getPackageRulesFilePath(const std::string &pkgId); -- 2.7.4 From 509aa4d74877589b0967c275e94547a63517abf8 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 23 Jun 2014 17:52:33 +0200 Subject: [PATCH 13/16] Refactoring of directory structure and CMake files Directory structure inherited from security-server is confusing and doesn't separate components that form the project. New structure consists of the following directories: * src/include - public security-manager interface * src/dpl - sources and includes borrowed from wrt-commons dpl * src/common - sources of libsecurity-manager-common library * src/client - sources of libsecurity-manager-client library * src/server - sources of security-manager binary * pc - template of pkg-config file Additionally common, client and server include files have been moved into "include" subdirectory in each source dir. CMake files are now more hierarchical, with separete file per component. Previously not checked dependency on libcap is now checked in server CMake. Library versioning is aligned with package versioning of security-manager. Version of libsecurity-manager-common is better parametrized. Change-Id: I8db728e53f912db2b15109f5502def7fc105f77f Signed-off-by: Rafal Krypa --- CMakeLists.txt | 9 +- README | 2 +- build/CMakeLists.txt | 19 ---- {build/security-manager => pc}/CMakeLists.txt | 8 +- .../security-manager => pc}/security-manager.pc.in | 0 src/CMakeLists.txt | 106 +++------------------ src/client/CMakeLists.txt | 30 ++++++ src/{server => }/client/client-common.cpp | 0 .../client/client-security-manager.cpp | 0 .../client => client/include}/client-common.h | 0 src/common/CMakeLists.txt | 50 ++++++++++ .../common => common/include}/connection-info.h | 0 .../common => common/include}/message-buffer.h | 0 src/{server/common => common/include}/protocols.h | 0 .../common => common/include}/smack-check.h | 0 src/{server => }/common/message-buffer.cpp | 0 src/{server => }/common/protocols.cpp | 0 src/{server => }/common/smack-check.cpp | 0 src/{server => }/dpl/core/include/dpl/assert.h | 0 .../dpl/core/include/dpl/availability.h | 0 .../dpl/core/include/dpl/binary_queue.h | 0 .../dpl/core/include/dpl/char_traits.h | 0 src/{server => }/dpl/core/include/dpl/colors.h | 0 .../dpl/core/include/dpl/errno_string.h | 0 src/{server => }/dpl/core/include/dpl/exception.h | 0 .../dpl/core/include/dpl/free_deleter.h | 0 .../dpl/core/include/dpl/fstream_accessors.h | 0 .../dpl/core/include/dpl/noncopyable.h | 0 src/{server => }/dpl/core/include/dpl/noreturn.h | 0 .../dpl/core/include/dpl/serialization.h | 0 src/{server => }/dpl/core/include/dpl/singleton.h | 0 .../dpl/core/include/dpl/singleton_impl.h | 0 .../dpl/core/include/dpl/singleton_safe_impl.h | 0 src/{server => }/dpl/core/include/dpl/string.h | 0 src/{server => }/dpl/core/src/assert.cpp | 0 src/{server => }/dpl/core/src/binary_queue.cpp | 0 src/{server => }/dpl/core/src/colors.cpp | 0 src/{server => }/dpl/core/src/errno_string.cpp | 0 src/{server => }/dpl/core/src/exception.cpp | 0 src/{server => }/dpl/core/src/noncopyable.cpp | 0 src/{server => }/dpl/core/src/serialization.cpp | 0 src/{server => }/dpl/core/src/singleton.cpp | 0 src/{server => }/dpl/core/src/string.cpp | 0 .../include/dpl/db/naive_synchronization_object.h | 0 .../dpl/db/include/dpl/db/sql_connection.h | 0 .../dpl/db/src/naive_synchronization_object.cpp | 0 src/{server => }/dpl/db/src/sql_connection.cpp | 0 .../log/include/dpl/log/abstract_log_provider.h | 0 .../dpl/log/include/dpl/log/dlog_log_provider.h | 0 src/{server => }/dpl/log/include/dpl/log/log.h | 0 .../log/include/dpl/log/old_style_log_provider.h | 0 .../dpl/log/src/abstract_log_provider.cpp | 0 src/{server => }/dpl/log/src/dlog_log_provider.cpp | 0 src/{server => }/dpl/log/src/log.cpp | 0 .../dpl/log/src/old_style_log_provider.cpp | 0 src/include/CMakeLists.txt | 4 + src/server/CMakeLists.txt | 67 ++++++------- src/server/main/{ => include}/generic-event.h | 0 .../main/{ => include}/generic-socket-manager.h | 0 .../main/{ => include}/security-manager-util.h | 0 src/server/main/{ => include}/service-thread.h | 0 src/server/main/{ => include}/socket-manager.h | 0 .../main/{server2-main.cpp => server-main.cpp} | 2 +- src/server/service/{ => include}/installer.h | 0 src/server/service/{ => include}/smack-common.h | 0 src/server/service/{ => include}/smack-rules.h | 0 66 files changed, 132 insertions(+), 165 deletions(-) delete mode 100644 build/CMakeLists.txt rename {build/security-manager => pc}/CMakeLists.txt (78%) rename {build/security-manager => pc}/security-manager.pc.in (100%) create mode 100644 src/client/CMakeLists.txt rename src/{server => }/client/client-common.cpp (100%) rename src/{server => }/client/client-security-manager.cpp (100%) rename src/{server/client => client/include}/client-common.h (100%) create mode 100644 src/common/CMakeLists.txt rename src/{server/common => common/include}/connection-info.h (100%) rename src/{server/common => common/include}/message-buffer.h (100%) rename src/{server/common => common/include}/protocols.h (100%) rename src/{server/common => common/include}/smack-check.h (100%) rename src/{server => }/common/message-buffer.cpp (100%) rename src/{server => }/common/protocols.cpp (100%) rename src/{server => }/common/smack-check.cpp (100%) rename src/{server => }/dpl/core/include/dpl/assert.h (100%) rename src/{server => }/dpl/core/include/dpl/availability.h (100%) rename src/{server => }/dpl/core/include/dpl/binary_queue.h (100%) rename src/{server => }/dpl/core/include/dpl/char_traits.h (100%) rename src/{server => }/dpl/core/include/dpl/colors.h (100%) rename src/{server => }/dpl/core/include/dpl/errno_string.h (100%) rename src/{server => }/dpl/core/include/dpl/exception.h (100%) rename src/{server => }/dpl/core/include/dpl/free_deleter.h (100%) rename src/{server => }/dpl/core/include/dpl/fstream_accessors.h (100%) rename src/{server => }/dpl/core/include/dpl/noncopyable.h (100%) rename src/{server => }/dpl/core/include/dpl/noreturn.h (100%) rename src/{server => }/dpl/core/include/dpl/serialization.h (100%) rename src/{server => }/dpl/core/include/dpl/singleton.h (100%) rename src/{server => }/dpl/core/include/dpl/singleton_impl.h (100%) rename src/{server => }/dpl/core/include/dpl/singleton_safe_impl.h (100%) rename src/{server => }/dpl/core/include/dpl/string.h (100%) rename src/{server => }/dpl/core/src/assert.cpp (100%) rename src/{server => }/dpl/core/src/binary_queue.cpp (100%) rename src/{server => }/dpl/core/src/colors.cpp (100%) rename src/{server => }/dpl/core/src/errno_string.cpp (100%) rename src/{server => }/dpl/core/src/exception.cpp (100%) rename src/{server => }/dpl/core/src/noncopyable.cpp (100%) rename src/{server => }/dpl/core/src/serialization.cpp (100%) rename src/{server => }/dpl/core/src/singleton.cpp (100%) rename src/{server => }/dpl/core/src/string.cpp (100%) rename src/{server => }/dpl/db/include/dpl/db/naive_synchronization_object.h (100%) rename src/{server => }/dpl/db/include/dpl/db/sql_connection.h (100%) rename src/{server => }/dpl/db/src/naive_synchronization_object.cpp (100%) rename src/{server => }/dpl/db/src/sql_connection.cpp (100%) rename src/{server => }/dpl/log/include/dpl/log/abstract_log_provider.h (100%) rename src/{server => }/dpl/log/include/dpl/log/dlog_log_provider.h (100%) rename src/{server => }/dpl/log/include/dpl/log/log.h (100%) rename src/{server => }/dpl/log/include/dpl/log/old_style_log_provider.h (100%) rename src/{server => }/dpl/log/src/abstract_log_provider.cpp (100%) rename src/{server => }/dpl/log/src/dlog_log_provider.cpp (100%) rename src/{server => }/dpl/log/src/log.cpp (100%) rename src/{server => }/dpl/log/src/old_style_log_provider.cpp (100%) create mode 100644 src/include/CMakeLists.txt rename src/server/main/{ => include}/generic-event.h (100%) rename src/server/main/{ => include}/generic-socket-manager.h (100%) rename src/server/main/{ => include}/security-manager-util.h (100%) rename src/server/main/{ => include}/service-thread.h (100%) rename src/server/main/{ => include}/socket-manager.h (100%) rename src/server/main/{server2-main.cpp => server-main.cpp} (98%) rename src/server/service/{ => include}/installer.h (100%) rename src/server/service/{ => include}/smack-common.h (100%) rename src/server/service/{ => include}/smack-rules.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 282a76b..50d2589 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2011 - 2014 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. @@ -58,11 +58,6 @@ IF (CMAKE_BUILD_TYPE MATCHES "DEBUG") ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG") ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") - -SET(TARGET_SECURITY_MANAGER "security-manager") -SET(TARGET_SECURITY_MANAGER_CLIENT "security-manager-client") -SET(TARGET_SERVER_COMMON "security-manager-commons") - ADD_SUBDIRECTORY(src) -ADD_SUBDIRECTORY(build) +ADD_SUBDIRECTORY(pc) ADD_SUBDIRECTORY(systemd) diff --git a/README b/README index 106258d..6730c1e 100644 --- a/README +++ b/README @@ -12,7 +12,7 @@ The implementation of daemon part is divided into: a generalization for services that security-server provides. and services part: implemented as classes derived from GenericSocketService - grouped in src/server2/service directory that defines actions done by + grouped in src/server/service directory that defines actions done by security-manager after receiving certain requests from client side. The security-manager's manager part is fully inherited from security-server, diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt deleted file mode 100644 index 77b8c60..0000000 --- a/build/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2011 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 CMakeLists.txt -# @author Tomasz Swierczek (t.swierczek@samsung.com) -# - -ADD_SUBDIRECTORY(security-manager) diff --git a/build/security-manager/CMakeLists.txt b/pc/CMakeLists.txt similarity index 78% rename from build/security-manager/CMakeLists.txt rename to pc/CMakeLists.txt index 31be27b..d54b4db 100644 --- a/build/security-manager/CMakeLists.txt +++ b/pc/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2011-2014 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. @@ -19,8 +19,4 @@ CONFIGURE_FILE(security-manager.pc.in security-manager.pc @ONLY) -INSTALL(FILES - ${CMAKE_BINARY_DIR}/build/security-manager/security-manager.pc - DESTINATION - ${LIB_INSTALL_DIR}/pkgconfig - ) +INSTALL(FILES security-manager.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/build/security-manager/security-manager.pc.in b/pc/security-manager.pc.in similarity index 100% rename from build/security-manager/security-manager.pc.in rename to pc/security-manager.pc.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08fe241..68f107f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,94 +1,14 @@ -PKG_CHECK_MODULES(SECURITY_MANAGER_DEP - dlog - libsmack - libprivilege-control - libsystemd-daemon - REQUIRED - ) - -SET(SECURITY_MANAGER_PATH ${PROJECT_SOURCE_DIR}/src) -SET(SERVER2_PATH ${PROJECT_SOURCE_DIR}/src/server) - -SET(SECURITY_MANAGER_SOURCES - ${SERVER2_PATH}/main/security-manager-util.cpp - ${SERVER2_PATH}/main/generic-socket-manager.cpp - ${SERVER2_PATH}/main/socket-manager.cpp - ${SERVER2_PATH}/main/server2-main.cpp - ${SERVER2_PATH}/service/smack-common.cpp - ${SERVER2_PATH}/service/smack-rules.cpp - ${SERVER2_PATH}/service/installer.cpp - ) - -SET_SOURCE_FILES_PROPERTIES( - ${SECURITY_MANAGER_SOURCES} - PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden") - -INCLUDE_DIRECTORIES(SYSTEM - ${SECURITY_MANAGER_DEP_INCLUDE_DIRS} - ) - -INCLUDE_DIRECTORIES( - ${SECURITY_MANAGER_PATH}/include - ${SERVER2_PATH}/main - ${SERVER2_PATH}/common - ${SERVER2_PATH}/service - ${SERVER2_PATH}/dpl/core/include - ${SERVER2_PATH}/dpl/log/include - ) - -ADD_EXECUTABLE(${TARGET_SECURITY_MANAGER} ${SECURITY_MANAGER_SOURCES}) - -TARGET_LINK_LIBRARIES(${TARGET_SECURITY_MANAGER} - ${SECURITY_MANAGER_DEP_LIBRARIES} - ${TARGET_SERVER_COMMON} - -lcap - ) - - -################################################################################ - -SET(SECURITY_MANAGER_CLIENT_VERSION_MAJOR 1) -SET(SECURITY_MANAGER_CLIENT_VERSION ${SECURITY_MANAGER_CLIENT_VERSION_MAJOR}.0.1) - -INCLUDE_DIRECTORIES( - ${SERVER2_PATH}/client - ${SERVER2_PATH}/common - ${SERVER2_PATH}/dpl/core/include - ${SERVER2_PATH}/dpl/log/include - ) - -SET(SECURITY_MANAGER_CLIENT_SOURCES - ${SERVER2_PATH}/client/client-security-manager.cpp - ${SERVER2_PATH}/client/client-common.cpp - ) - -ADD_LIBRARY(${TARGET_SECURITY_MANAGER_CLIENT} SHARED ${SECURITY_MANAGER_CLIENT_SOURCES}) - -SET_TARGET_PROPERTIES( - ${TARGET_SECURITY_MANAGER_CLIENT} - PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=hidden" - SOVERSION ${SECURITY_MANAGER_CLIENT_VERSION_MAJOR} - VERSION ${SECURITY_MANAGER_CLIENT_VERSION} - ) - -TARGET_LINK_LIBRARIES(${TARGET_SECURITY_MANAGER_CLIENT} - ${SECURITY_MANAGER_DEP_LIBRARIES} - ${TARGET_SERVER_COMMON} - ) - -################################################################################ - -INSTALL(TARGETS ${TARGET_SECURITY_MANAGER_CLIENT} DESTINATION ${LIB_INSTALL_DIR}) - -INSTALL(TARGETS ${TARGET_SECURITY_MANAGER} DESTINATION bin) - -INSTALL(FILES - ${SECURITY_MANAGER_PATH}/include/security-manager.h - DESTINATION ${INCLUDE_INSTALL_DIR}/security-manager - ) - -################################################################################ - +SET(INCLUDE_PATH ${PROJECT_SOURCE_DIR}/src/include) +SET(COMMON_PATH ${PROJECT_SOURCE_DIR}/src/common) +SET(CLIENT_PATH ${PROJECT_SOURCE_DIR}/src/client) +SET(SERVER_PATH ${PROJECT_SOURCE_DIR}/src/server) +SET(DPL_PATH ${PROJECT_SOURCE_DIR}/src/dpl) + +SET(TARGET_SERVER "security-manager") +SET(TARGET_CLIENT "security-manager-client") +SET(TARGET_COMMON "security-manager-commons") + +ADD_SUBDIRECTORY(include) +ADD_SUBDIRECTORY(common) +ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(server) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt new file mode 100644 index 0000000..9e4ad1c --- /dev/null +++ b/src/client/CMakeLists.txt @@ -0,0 +1,30 @@ +SET(CLIENT_VERSION_MAJOR 0) +SET(CLIENT_VERSION ${CLIENT_VERSION_MAJOR}.1.0) + +INCLUDE_DIRECTORIES( + ${INCLUDE_PATH} + ${COMMON_PATH}/include + ${CLIENT_PATH}/include + ${DPL_PATH}/core/include + ${DPL_PATH}/log/include + ) + +SET(CLIENT_SOURCES + ${CLIENT_PATH}/client-security-manager.cpp + ${CLIENT_PATH}/client-common.cpp + ) + +ADD_LIBRARY(${TARGET_CLIENT} SHARED ${CLIENT_SOURCES}) + +SET_TARGET_PROPERTIES(${TARGET_CLIENT} + PROPERTIES + COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=hidden" + SOVERSION ${CLIENT_VERSION_MAJOR} + VERSION ${CLIENT_VERSION} + ) + +TARGET_LINK_LIBRARIES(${TARGET_CLIENT} + ${TARGET_COMMON} + ) + +INSTALL(TARGETS ${TARGET_CLIENT} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/server/client/client-common.cpp b/src/client/client-common.cpp similarity index 100% rename from src/server/client/client-common.cpp rename to src/client/client-common.cpp diff --git a/src/server/client/client-security-manager.cpp b/src/client/client-security-manager.cpp similarity index 100% rename from src/server/client/client-security-manager.cpp rename to src/client/client-security-manager.cpp diff --git a/src/server/client/client-common.h b/src/client/include/client-common.h similarity index 100% rename from src/server/client/client-common.h rename to src/client/include/client-common.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt new file mode 100644 index 0000000..7e9cf2c --- /dev/null +++ b/src/common/CMakeLists.txt @@ -0,0 +1,50 @@ +SET(COMMON_VERSION_MAJOR 0) +SET(COMMON_VERSION ${COMMON_VERSION_MAJOR}.1.0) + +PKG_CHECK_MODULES(COMMON_DEP + REQUIRED + dlog + libsmack + ) + +INCLUDE_DIRECTORIES(SYSTEM + ${COMMON_DEP_INCLUDE_DIRS} + ) + +INCLUDE_DIRECTORIES( + ${COMMON_PATH}/include + ${DPL_PATH}/core/include + ${DPL_PATH}/log/include + ) + +SET(COMMON_SOURCES + ${COMMON_PATH}/protocols.cpp + ${COMMON_PATH}/message-buffer.cpp + ${COMMON_PATH}/smack-check.cpp + ${DPL_PATH}/log/src/abstract_log_provider.cpp + ${DPL_PATH}/log/src/dlog_log_provider.cpp + ${DPL_PATH}/log/src/log.cpp + ${DPL_PATH}/log/src/old_style_log_provider.cpp + ${DPL_PATH}/core/src/assert.cpp + ${DPL_PATH}/core/src/binary_queue.cpp + ${DPL_PATH}/core/src/colors.cpp + ${DPL_PATH}/core/src/exception.cpp + ${DPL_PATH}/core/src/noncopyable.cpp + ${DPL_PATH}/core/src/serialization.cpp + ${DPL_PATH}/core/src/singleton.cpp + ) + +ADD_LIBRARY(${TARGET_COMMON} SHARED ${COMMON_SOURCES}) + +SET_TARGET_PROPERTIES(${TARGET_COMMON} + PROPERTIES + COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=default" + SOVERSION ${COMMON_VERSION_MAJOR} + VERSION ${COMMON_VERSION} + ) + +TARGET_LINK_LIBRARIES(${TARGET_COMMON} + ${COMMON_DEP_LIBRARIES} + ) + +INSTALL(TARGETS ${TARGET_COMMON} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/server/common/connection-info.h b/src/common/include/connection-info.h similarity index 100% rename from src/server/common/connection-info.h rename to src/common/include/connection-info.h diff --git a/src/server/common/message-buffer.h b/src/common/include/message-buffer.h similarity index 100% rename from src/server/common/message-buffer.h rename to src/common/include/message-buffer.h diff --git a/src/server/common/protocols.h b/src/common/include/protocols.h similarity index 100% rename from src/server/common/protocols.h rename to src/common/include/protocols.h diff --git a/src/server/common/smack-check.h b/src/common/include/smack-check.h similarity index 100% rename from src/server/common/smack-check.h rename to src/common/include/smack-check.h diff --git a/src/server/common/message-buffer.cpp b/src/common/message-buffer.cpp similarity index 100% rename from src/server/common/message-buffer.cpp rename to src/common/message-buffer.cpp diff --git a/src/server/common/protocols.cpp b/src/common/protocols.cpp similarity index 100% rename from src/server/common/protocols.cpp rename to src/common/protocols.cpp diff --git a/src/server/common/smack-check.cpp b/src/common/smack-check.cpp similarity index 100% rename from src/server/common/smack-check.cpp rename to src/common/smack-check.cpp diff --git a/src/server/dpl/core/include/dpl/assert.h b/src/dpl/core/include/dpl/assert.h similarity index 100% rename from src/server/dpl/core/include/dpl/assert.h rename to src/dpl/core/include/dpl/assert.h diff --git a/src/server/dpl/core/include/dpl/availability.h b/src/dpl/core/include/dpl/availability.h similarity index 100% rename from src/server/dpl/core/include/dpl/availability.h rename to src/dpl/core/include/dpl/availability.h diff --git a/src/server/dpl/core/include/dpl/binary_queue.h b/src/dpl/core/include/dpl/binary_queue.h similarity index 100% rename from src/server/dpl/core/include/dpl/binary_queue.h rename to src/dpl/core/include/dpl/binary_queue.h diff --git a/src/server/dpl/core/include/dpl/char_traits.h b/src/dpl/core/include/dpl/char_traits.h similarity index 100% rename from src/server/dpl/core/include/dpl/char_traits.h rename to src/dpl/core/include/dpl/char_traits.h diff --git a/src/server/dpl/core/include/dpl/colors.h b/src/dpl/core/include/dpl/colors.h similarity index 100% rename from src/server/dpl/core/include/dpl/colors.h rename to src/dpl/core/include/dpl/colors.h diff --git a/src/server/dpl/core/include/dpl/errno_string.h b/src/dpl/core/include/dpl/errno_string.h similarity index 100% rename from src/server/dpl/core/include/dpl/errno_string.h rename to src/dpl/core/include/dpl/errno_string.h diff --git a/src/server/dpl/core/include/dpl/exception.h b/src/dpl/core/include/dpl/exception.h similarity index 100% rename from src/server/dpl/core/include/dpl/exception.h rename to src/dpl/core/include/dpl/exception.h diff --git a/src/server/dpl/core/include/dpl/free_deleter.h b/src/dpl/core/include/dpl/free_deleter.h similarity index 100% rename from src/server/dpl/core/include/dpl/free_deleter.h rename to src/dpl/core/include/dpl/free_deleter.h diff --git a/src/server/dpl/core/include/dpl/fstream_accessors.h b/src/dpl/core/include/dpl/fstream_accessors.h similarity index 100% rename from src/server/dpl/core/include/dpl/fstream_accessors.h rename to src/dpl/core/include/dpl/fstream_accessors.h diff --git a/src/server/dpl/core/include/dpl/noncopyable.h b/src/dpl/core/include/dpl/noncopyable.h similarity index 100% rename from src/server/dpl/core/include/dpl/noncopyable.h rename to src/dpl/core/include/dpl/noncopyable.h diff --git a/src/server/dpl/core/include/dpl/noreturn.h b/src/dpl/core/include/dpl/noreturn.h similarity index 100% rename from src/server/dpl/core/include/dpl/noreturn.h rename to src/dpl/core/include/dpl/noreturn.h diff --git a/src/server/dpl/core/include/dpl/serialization.h b/src/dpl/core/include/dpl/serialization.h similarity index 100% rename from src/server/dpl/core/include/dpl/serialization.h rename to src/dpl/core/include/dpl/serialization.h diff --git a/src/server/dpl/core/include/dpl/singleton.h b/src/dpl/core/include/dpl/singleton.h similarity index 100% rename from src/server/dpl/core/include/dpl/singleton.h rename to src/dpl/core/include/dpl/singleton.h diff --git a/src/server/dpl/core/include/dpl/singleton_impl.h b/src/dpl/core/include/dpl/singleton_impl.h similarity index 100% rename from src/server/dpl/core/include/dpl/singleton_impl.h rename to src/dpl/core/include/dpl/singleton_impl.h diff --git a/src/server/dpl/core/include/dpl/singleton_safe_impl.h b/src/dpl/core/include/dpl/singleton_safe_impl.h similarity index 100% rename from src/server/dpl/core/include/dpl/singleton_safe_impl.h rename to src/dpl/core/include/dpl/singleton_safe_impl.h diff --git a/src/server/dpl/core/include/dpl/string.h b/src/dpl/core/include/dpl/string.h similarity index 100% rename from src/server/dpl/core/include/dpl/string.h rename to src/dpl/core/include/dpl/string.h diff --git a/src/server/dpl/core/src/assert.cpp b/src/dpl/core/src/assert.cpp similarity index 100% rename from src/server/dpl/core/src/assert.cpp rename to src/dpl/core/src/assert.cpp diff --git a/src/server/dpl/core/src/binary_queue.cpp b/src/dpl/core/src/binary_queue.cpp similarity index 100% rename from src/server/dpl/core/src/binary_queue.cpp rename to src/dpl/core/src/binary_queue.cpp diff --git a/src/server/dpl/core/src/colors.cpp b/src/dpl/core/src/colors.cpp similarity index 100% rename from src/server/dpl/core/src/colors.cpp rename to src/dpl/core/src/colors.cpp diff --git a/src/server/dpl/core/src/errno_string.cpp b/src/dpl/core/src/errno_string.cpp similarity index 100% rename from src/server/dpl/core/src/errno_string.cpp rename to src/dpl/core/src/errno_string.cpp diff --git a/src/server/dpl/core/src/exception.cpp b/src/dpl/core/src/exception.cpp similarity index 100% rename from src/server/dpl/core/src/exception.cpp rename to src/dpl/core/src/exception.cpp diff --git a/src/server/dpl/core/src/noncopyable.cpp b/src/dpl/core/src/noncopyable.cpp similarity index 100% rename from src/server/dpl/core/src/noncopyable.cpp rename to src/dpl/core/src/noncopyable.cpp diff --git a/src/server/dpl/core/src/serialization.cpp b/src/dpl/core/src/serialization.cpp similarity index 100% rename from src/server/dpl/core/src/serialization.cpp rename to src/dpl/core/src/serialization.cpp diff --git a/src/server/dpl/core/src/singleton.cpp b/src/dpl/core/src/singleton.cpp similarity index 100% rename from src/server/dpl/core/src/singleton.cpp rename to src/dpl/core/src/singleton.cpp diff --git a/src/server/dpl/core/src/string.cpp b/src/dpl/core/src/string.cpp similarity index 100% rename from src/server/dpl/core/src/string.cpp rename to src/dpl/core/src/string.cpp diff --git a/src/server/dpl/db/include/dpl/db/naive_synchronization_object.h b/src/dpl/db/include/dpl/db/naive_synchronization_object.h similarity index 100% rename from src/server/dpl/db/include/dpl/db/naive_synchronization_object.h rename to src/dpl/db/include/dpl/db/naive_synchronization_object.h diff --git a/src/server/dpl/db/include/dpl/db/sql_connection.h b/src/dpl/db/include/dpl/db/sql_connection.h similarity index 100% rename from src/server/dpl/db/include/dpl/db/sql_connection.h rename to src/dpl/db/include/dpl/db/sql_connection.h diff --git a/src/server/dpl/db/src/naive_synchronization_object.cpp b/src/dpl/db/src/naive_synchronization_object.cpp similarity index 100% rename from src/server/dpl/db/src/naive_synchronization_object.cpp rename to src/dpl/db/src/naive_synchronization_object.cpp diff --git a/src/server/dpl/db/src/sql_connection.cpp b/src/dpl/db/src/sql_connection.cpp similarity index 100% rename from src/server/dpl/db/src/sql_connection.cpp rename to src/dpl/db/src/sql_connection.cpp diff --git a/src/server/dpl/log/include/dpl/log/abstract_log_provider.h b/src/dpl/log/include/dpl/log/abstract_log_provider.h similarity index 100% rename from src/server/dpl/log/include/dpl/log/abstract_log_provider.h rename to src/dpl/log/include/dpl/log/abstract_log_provider.h diff --git a/src/server/dpl/log/include/dpl/log/dlog_log_provider.h b/src/dpl/log/include/dpl/log/dlog_log_provider.h similarity index 100% rename from src/server/dpl/log/include/dpl/log/dlog_log_provider.h rename to src/dpl/log/include/dpl/log/dlog_log_provider.h diff --git a/src/server/dpl/log/include/dpl/log/log.h b/src/dpl/log/include/dpl/log/log.h similarity index 100% rename from src/server/dpl/log/include/dpl/log/log.h rename to src/dpl/log/include/dpl/log/log.h diff --git a/src/server/dpl/log/include/dpl/log/old_style_log_provider.h b/src/dpl/log/include/dpl/log/old_style_log_provider.h similarity index 100% rename from src/server/dpl/log/include/dpl/log/old_style_log_provider.h rename to src/dpl/log/include/dpl/log/old_style_log_provider.h diff --git a/src/server/dpl/log/src/abstract_log_provider.cpp b/src/dpl/log/src/abstract_log_provider.cpp similarity index 100% rename from src/server/dpl/log/src/abstract_log_provider.cpp rename to src/dpl/log/src/abstract_log_provider.cpp diff --git a/src/server/dpl/log/src/dlog_log_provider.cpp b/src/dpl/log/src/dlog_log_provider.cpp similarity index 100% rename from src/server/dpl/log/src/dlog_log_provider.cpp rename to src/dpl/log/src/dlog_log_provider.cpp diff --git a/src/server/dpl/log/src/log.cpp b/src/dpl/log/src/log.cpp similarity index 100% rename from src/server/dpl/log/src/log.cpp rename to src/dpl/log/src/log.cpp diff --git a/src/server/dpl/log/src/old_style_log_provider.cpp b/src/dpl/log/src/old_style_log_provider.cpp similarity index 100% rename from src/server/dpl/log/src/old_style_log_provider.cpp rename to src/dpl/log/src/old_style_log_provider.cpp diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt new file mode 100644 index 0000000..6f9a45f --- /dev/null +++ b/src/include/CMakeLists.txt @@ -0,0 +1,4 @@ +INSTALL(FILES + ${INCLUDE_PATH}/security-manager.h + DESTINATION ${INCLUDE_INSTALL_DIR}/security-manager + ) diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index a53d379..d4349f6 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -1,52 +1,43 @@ -PKG_CHECK_MODULES(COMMON_DEP - dlog +PKG_CHECK_MODULES(SERVER_DEP REQUIRED - ) - -SET(COMMON_PATH ${PROJECT_SOURCE_DIR}/src/server) - -SET(COMMON_SOURCES - ${COMMON_PATH}/common/protocols.cpp - ${COMMON_PATH}/common/message-buffer.cpp - ${COMMON_PATH}/common/smack-check.cpp - ${COMMON_PATH}/dpl/log/src/abstract_log_provider.cpp - ${COMMON_PATH}/dpl/log/src/dlog_log_provider.cpp - ${COMMON_PATH}/dpl/log/src/log.cpp - ${COMMON_PATH}/dpl/log/src/old_style_log_provider.cpp - ${COMMON_PATH}/dpl/core/src/assert.cpp - ${COMMON_PATH}/dpl/core/src/binary_queue.cpp - ${COMMON_PATH}/dpl/core/src/colors.cpp - ${COMMON_PATH}/dpl/core/src/exception.cpp - ${COMMON_PATH}/dpl/core/src/noncopyable.cpp - ${COMMON_PATH}/dpl/core/src/serialization.cpp - ${COMMON_PATH}/dpl/core/src/singleton.cpp + libcap + libsmack + libprivilege-control + libsystemd-daemon ) INCLUDE_DIRECTORIES(SYSTEM - ${COMMON_DEP_INCLUDE_DIRS} + ${SERVER_DEP_INCLUDE_DIRS} ) INCLUDE_DIRECTORIES( - ${COMMON_PATH}/common - ${COMMON_PATH}/dpl/core/include - ${COMMON_PATH}/dpl/log/include + ${INCLUDE_PATH} + ${COMMON_PATH}/include + ${SERVER_PATH}/main/include + ${SERVER_PATH}/service/include + ${DPL_PATH}/core/include + ${DPL_PATH}/log/include ) -ADD_LIBRARY(${TARGET_SERVER_COMMON} SHARED ${COMMON_SOURCES}) - -SET_TARGET_PROPERTIES( - ${TARGET_SERVER_COMMON} - PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=default" - SOVERSION 1.0.0 - VERSION 1.0.0 +SET(SERVER_SOURCES + ${SERVER_PATH}/main/security-manager-util.cpp + ${SERVER_PATH}/main/generic-socket-manager.cpp + ${SERVER_PATH}/main/socket-manager.cpp + ${SERVER_PATH}/main/server-main.cpp + ${SERVER_PATH}/service/smack-common.cpp + ${SERVER_PATH}/service/smack-rules.cpp + ${SERVER_PATH}/service/installer.cpp ) -TARGET_LINK_LIBRARIES(${TARGET_SERVER_COMMON} - ${COMMON_DEP_LIBRARIES} - ) +ADD_EXECUTABLE(${TARGET_SERVER} ${SERVER_SOURCES}) -################################################################################ +SET_TARGET_PROPERTIES(${TARGET_SERVER} + PROPERTIES + COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden") -INSTALL(TARGETS ${TARGET_SERVER_COMMON} DESTINATION ${LIB_INSTALL_DIR}) +TARGET_LINK_LIBRARIES(${TARGET_SERVER} + ${TARGET_COMMON} + ${SERVER_DEP_LIBRARIES} + ) +INSTALL(TARGETS ${TARGET_SERVER} DESTINATION bin) diff --git a/src/server/main/generic-event.h b/src/server/main/include/generic-event.h similarity index 100% rename from src/server/main/generic-event.h rename to src/server/main/include/generic-event.h diff --git a/src/server/main/generic-socket-manager.h b/src/server/main/include/generic-socket-manager.h similarity index 100% rename from src/server/main/generic-socket-manager.h rename to src/server/main/include/generic-socket-manager.h diff --git a/src/server/main/security-manager-util.h b/src/server/main/include/security-manager-util.h similarity index 100% rename from src/server/main/security-manager-util.h rename to src/server/main/include/security-manager-util.h diff --git a/src/server/main/service-thread.h b/src/server/main/include/service-thread.h similarity index 100% rename from src/server/main/service-thread.h rename to src/server/main/include/service-thread.h diff --git a/src/server/main/socket-manager.h b/src/server/main/include/socket-manager.h similarity index 100% rename from src/server/main/socket-manager.h rename to src/server/main/include/socket-manager.h diff --git a/src/server/main/server2-main.cpp b/src/server/main/server-main.cpp similarity index 98% rename from src/server/main/server2-main.cpp rename to src/server/main/server-main.cpp index aba9373..6f67efa 100644 --- a/src/server/main/server2-main.cpp +++ b/src/server/main/server-main.cpp @@ -16,7 +16,7 @@ * limitations under the License */ /* - * @file sever2-main.cpp + * @file server-main.cpp * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com) * @version 1.0 * @brief Implementation of security-manager on basis of security-server diff --git a/src/server/service/installer.h b/src/server/service/include/installer.h similarity index 100% rename from src/server/service/installer.h rename to src/server/service/include/installer.h diff --git a/src/server/service/smack-common.h b/src/server/service/include/smack-common.h similarity index 100% rename from src/server/service/smack-common.h rename to src/server/service/include/smack-common.h diff --git a/src/server/service/smack-rules.h b/src/server/service/include/smack-rules.h similarity index 100% rename from src/server/service/smack-rules.h rename to src/server/service/include/smack-rules.h -- 2.7.4 From 44933d65d86184e2874cd3c20cd010b410ab4341 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Tue, 24 Jun 2014 13:19:54 +0200 Subject: [PATCH 14/16] Build security-manager-common with SqlConnection Also adding build dependencies on sqlite3, db-util and boost. Change-Id: I65d55bfd30a600aab19bee489ef20b94b69b45a6 Signed-off-by: Rafal Krypa --- packaging/security-manager.spec | 3 +++ src/server/CMakeLists.txt | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packaging/security-manager.spec b/packaging/security-manager.spec index b4b44ac..58738dd 100644 --- a/packaging/security-manager.spec +++ b/packaging/security-manager.spec @@ -15,6 +15,9 @@ BuildRequires: libcap-devel BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(libprivilege-control) BuildRequires: pkgconfig(libsystemd-daemon) +BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(db-util) +BuildRequires: boost-devel %{?systemd_requires} %description diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index d4349f6..11b38b2 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -4,10 +4,18 @@ PKG_CHECK_MODULES(SERVER_DEP libsmack libprivilege-control libsystemd-daemon + sqlite3 + db-util + ) + +FIND_PACKAGE( + Boost + REQUIRED ) INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEP_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} ) INCLUDE_DIRECTORIES( @@ -17,6 +25,7 @@ INCLUDE_DIRECTORIES( ${SERVER_PATH}/service/include ${DPL_PATH}/core/include ${DPL_PATH}/log/include + ${DPL_PATH}/db/include ) SET(SERVER_SOURCES @@ -27,6 +36,10 @@ SET(SERVER_SOURCES ${SERVER_PATH}/service/smack-common.cpp ${SERVER_PATH}/service/smack-rules.cpp ${SERVER_PATH}/service/installer.cpp + ${DPL_PATH}/core/src/errno_string.cpp + ${DPL_PATH}/core/src/string.cpp + ${DPL_PATH}/db/src/naive_synchronization_object.cpp + ${DPL_PATH}/db/src/sql_connection.cpp ) ADD_EXECUTABLE(${TARGET_SERVER} ${SERVER_SOURCES}) -- 2.7.4 From 2d25a3f5b560e6709bd5d69dbbf4c8c2b4a31f3d Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Tue, 24 Jun 2014 13:21:37 +0200 Subject: [PATCH 15/16] Move smack_check from common to server This function is used only in server. By moving it from common it is now possible to not link libsecurity-manager-common with libsmack. Change-Id: If2b8eb8dc252ff21416ab4e075a5471f5647b98a Signed-off-by: Rafal Krypa --- src/common/CMakeLists.txt | 2 -- src/server/CMakeLists.txt | 2 ++ src/{common => server}/include/smack-check.h | 0 src/{common => server}/smack-check.cpp | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename src/{common => server}/include/smack-check.h (100%) rename src/{common => server}/smack-check.cpp (100%) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 7e9cf2c..2cdca69 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -4,7 +4,6 @@ SET(COMMON_VERSION ${COMMON_VERSION_MAJOR}.1.0) PKG_CHECK_MODULES(COMMON_DEP REQUIRED dlog - libsmack ) INCLUDE_DIRECTORIES(SYSTEM @@ -20,7 +19,6 @@ INCLUDE_DIRECTORIES( SET(COMMON_SOURCES ${COMMON_PATH}/protocols.cpp ${COMMON_PATH}/message-buffer.cpp - ${COMMON_PATH}/smack-check.cpp ${DPL_PATH}/log/src/abstract_log_provider.cpp ${DPL_PATH}/log/src/dlog_log_provider.cpp ${DPL_PATH}/log/src/log.cpp diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 11b38b2..cb6ffd2 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES(SYSTEM INCLUDE_DIRECTORIES( ${INCLUDE_PATH} ${COMMON_PATH}/include + ${SERVER_PATH}/include ${SERVER_PATH}/main/include ${SERVER_PATH}/service/include ${DPL_PATH}/core/include @@ -29,6 +30,7 @@ INCLUDE_DIRECTORIES( ) SET(SERVER_SOURCES + ${SERVER_PATH}/smack-check.cpp ${SERVER_PATH}/main/security-manager-util.cpp ${SERVER_PATH}/main/generic-socket-manager.cpp ${SERVER_PATH}/main/socket-manager.cpp diff --git a/src/common/include/smack-check.h b/src/server/include/smack-check.h similarity index 100% rename from src/common/include/smack-check.h rename to src/server/include/smack-check.h diff --git a/src/common/smack-check.cpp b/src/server/smack-check.cpp similarity index 100% rename from src/common/smack-check.cpp rename to src/server/smack-check.cpp -- 2.7.4 From 04f342fc27ab0980702f90224f6ca904f0ec3f1a Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Tue, 24 Jun 2014 17:49:05 +0200 Subject: [PATCH 16/16] Remove fstream_accessors.h from DPL - It is not used in security-manager - In fact it was never a part of DPL, but an addition by security-server Change-Id: Ia9803ea90cfe8f1a20ab072717c6d9895fb1d89a --- src/dpl/core/include/dpl/fstream_accessors.h | 48 ---------------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/dpl/core/include/dpl/fstream_accessors.h diff --git a/src/dpl/core/include/dpl/fstream_accessors.h b/src/dpl/core/include/dpl/fstream_accessors.h deleted file mode 100644 index 09f2dc2..0000000 --- a/src/dpl/core/include/dpl/fstream_accessors.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Rafal Krypa - * - * 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 fstream-helper.h - * @author Marek Smolinski (m.smolinski@samsung.com) - * @version 1.0 - * @brief This file is the implementation file of fstream-helper - * - */ - -#ifndef SECURITY_MANAGER_FSTREAM_ACCESSORS_H -#define SECURITY_MANAGER_FSTREAM_ACCESSORS_H - -namespace SecurityManager { - -/* - * Bypass lack of public member function to get file - * descriptor from fstream objects in std - * This feature is needed for flushing data from kernel space buffer to - * physical device [fsync(int fd) - syscall] on opened fstream object -*/ - -template -class FstreamAccessors : T::__filebuf_type { - typedef FstreamAccessors MyType; -public: - static int GetFd(T &strm) { - return static_cast(strm.rdbuf())->_M_file.fd(); - } -}; - -} // namespace SecurityManager - -#endif // SECURITY_MANAGER_FSTREAM_ACCESSORS_H -- 2.7.4