From abb2d89db389d6636c327343b7e6292a12155bd1 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Thu, 18 Sep 2014 18:37:40 +0200 Subject: [PATCH 01/16] Add cynara external plugins Add interface for creating external cynara plugin to enable custom policy types support. Change-Id: I43bd31a3e48f9667964107dd243f2286e7ffae8a --- packaging/cynara.spec | 14 ++++ pkgconfig/CMakeLists.txt | 1 + pkgconfig/cynara-plugin/CMakeLists.txt | 25 +++++++ pkgconfig/cynara-plugin/cynara-plugin.pc.in | 11 +++ src/common/CMakeLists.txt | 5 ++ src/include/CMakeLists.txt | 1 + src/include/cynara-plugin.h | 107 ++++++++++++++++++++++++++++ 7 files changed, 164 insertions(+) create mode 100644 pkgconfig/cynara-plugin/CMakeLists.txt create mode 100644 pkgconfig/cynara-plugin/cynara-plugin.pc.in create mode 100644 src/include/cynara-plugin.h diff --git a/packaging/cynara.spec b/packaging/cynara.spec index c25347f..6abd205 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -141,6 +141,14 @@ Requires: libcynara-commons = %{version}-%{release} cynara common library (devel) with common functionalities ####################################################### +%package -n libcynara-plugin-devel +Summary: Cynara - cynara plugin library (devel) +Requires: libcynara-commons-devel = %{version}-%{release} + +%description -n libcynara-plugin-devel +cynara plugin library (devel) with plugin definitions + +####################################################### %package -n libcynara-creds-commons Summary: Base library for cynara credentials helpers @@ -451,8 +459,14 @@ fi %{_libdir}/libcynara-commons.so.* %files -n libcynara-commons-devel +%{_includedir}/cynara/types/PolicyResult.h +%{_includedir}/cynara/types/PolicyType.h %{_libdir}/libcynara-commons.so +%files -n libcynara-plugin-devel +%{_includedir}/cynara/cynara-plugin.h +%{_libdir}/pkgconfig/cynara-plugin.pc + %files -n cynara-tests %manifest cynara-tests.manifest %attr(755,root,root) /usr/bin/cynara-tests diff --git a/pkgconfig/CMakeLists.txt b/pkgconfig/CMakeLists.txt index 9d4600f..a93ae55 100644 --- a/pkgconfig/CMakeLists.txt +++ b/pkgconfig/CMakeLists.txt @@ -23,4 +23,5 @@ ADD_SUBDIRECTORY(cynara-admin) ADD_SUBDIRECTORY(cynara-creds-commons) ADD_SUBDIRECTORY(cynara-creds-dbus) ADD_SUBDIRECTORY(cynara-creds-socket) +ADD_SUBDIRECTORY(cynara-plugin) ADD_SUBDIRECTORY(cynara-session) diff --git a/pkgconfig/cynara-plugin/CMakeLists.txt b/pkgconfig/cynara-plugin/CMakeLists.txt new file mode 100644 index 0000000..1ea74a5 --- /dev/null +++ b/pkgconfig/cynara-plugin/CMakeLists.txt @@ -0,0 +1,25 @@ +# 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 CMakeLists.txt +# @author Zofia Abramowska +# + +CONFIGURE_FILE(cynara-plugin.pc.in cynara-plugin.pc @ONLY) + +INSTALL(FILES + ${CMAKE_BINARY_DIR}/pkgconfig/cynara-plugin/cynara-plugin.pc + DESTINATION + ${LIB_INSTALL_DIR}/pkgconfig + ) diff --git a/pkgconfig/cynara-plugin/cynara-plugin.pc.in b/pkgconfig/cynara-plugin/cynara-plugin.pc.in new file mode 100644 index 0000000..c14de16 --- /dev/null +++ b/pkgconfig/cynara-plugin/cynara-plugin.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@LIB_INSTALL_DIR@ +includedir=${prefix}/include + +Name: cynara-plugin +Description: Cynara plugin definition package +Version: @CYNARA_VERSION@ +Requires: +Libs: -L${libdir} -lcynara-commons +Cflags: -I${includedir}/cynara diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 461450a..77c7d56 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -82,3 +82,8 @@ TARGET_LINK_LIBRARIES(${TARGET_CYNARA_COMMON} ) INSTALL(TARGETS ${TARGET_CYNARA_COMMON} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(FILES + ${COMMON_PATH}/types/PolicyResult.h + ${COMMON_PATH}/types/PolicyType.h + DESTINATION ${INCLUDE_INSTALL_DIR}/cynara/types + ) diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index 1be6e10..cb9d00c 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -26,6 +26,7 @@ INSTALL(FILES ${CYNARA_PATH}/include/cynara-creds-commons.h ${CYNARA_PATH}/include/cynara-creds-dbus.h ${CYNARA_PATH}/include/cynara-creds-socket.h + ${CYNARA_PATH}/include/cynara-plugin.h ${CYNARA_PATH}/include/cynara-session.h DESTINATION ${INCLUDE_INSTALL_DIR}/cynara ) diff --git a/src/include/cynara-plugin.h b/src/include/cynara-plugin.h new file mode 100644 index 0000000..83956fe --- /dev/null +++ b/src/include/cynara-plugin.h @@ -0,0 +1,107 @@ +/* + * 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 src/include/cynara-plugin.h + * @author Zofia Abramowska + * @version 1.0 + * @brief This file defines cynara side external plugin interface + */ + +#ifndef CYNARA_PLUGIN_H_ +#define CYNARA_PLUGIN_H_ + +#include +#include +#include + +#include +#include + +namespace Cynara { + +class ExternalPluginInterface; + +extern "C" { +typedef ExternalPluginInterface *(*createPlugin)(void); +} + +//These typedefs will be defined in external headers +typedef std::string PluginData; +typedef std::string AgentType; +typedef std::vector PolicyTypes; + +/** + * A class defining external plugins interface. + * These plugins work inside of cynara and either can produce + * response through check instantly or require communication + * with given type of agent. Agent must be registered through + * cynara-agent API. + */ + +class ExternalPluginInterface { +public: + /** + * Enum indicating status of calling plugin method. + */ + enum class PluginStatus { + SUCCESS, /** < update() finished successfully*/ + ANSWER_READY, /** < check() returns answer immediately through argument*/ + ANSWER_NOTREADY, /** < check() cannot return answer immediately, + < communication with agent is required */ + ERROR /** < either check() or update() fails */ + }; + + /** + * Policy type supported by plugin. + */ + virtual PolicyTypes getSupportedPolicyTypes(void) = 0; + + /** + * Asks plugin, what kind of permission does client, user and privilege has. + * + * @param[in] client + * @param[in] user + * @param[in] privilege + * @param[out] result Immediate response (if available) + * @param[out] requiredAgent When ANSWER_NOTREADY, required AgentType to communicate with + * @param[out] pluginData Additional data, that will be passed to agent + * @return PluginStatus In case of success - either ANSWER_READY or ANSWER_NOTREADY, + * in case of error - ERROR + */ + virtual PluginStatus check(const std::string &client, const std::string &user, + const std::string &privilege, PolicyResult &result, + AgentType &requiredAgent, PluginData &pluginData) noexcept = 0; + + /** + * Updates response returned by agent + * @param[in] client + * @param[in] user + * @param[in] privilege + * @param[in] agentData Additional data, passed from agent + * @param[out] result Response interpreted from agent + * @return PluginStatus In case of success - SUCCESS, in case of error - ERROR + */ + virtual PluginStatus update(const std::string &client, const std::string &user, + const std::string &privilege, const PluginData &agentData, + PolicyResult &result) noexcept = 0; + + virtual ~ExternalPluginInterface() {}; + +}; + +} // namespace Cynara + +#endif /* CYNARA_PLUGIN_H_ */ -- 2.7.4 From fa70d3d34bf759389e67f52401adb334cf21ec2e Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Fri, 19 Sep 2014 16:42:02 +0200 Subject: [PATCH 02/16] Add PluginManager Add cynara service manager for loading and managing dynamic loaded plugins supporting custom policy types. Change-Id: I94c3bfa4842a6a8d0a078ac910aba5e54db7b468 --- src/service/CMakeLists.txt | 3 + src/service/logic/Logic.cpp | 28 ++++++-- src/service/logic/Logic.h | 7 ++ src/service/main/Cynara.cpp | 17 +++++ src/service/main/Cynara.h | 2 + src/service/main/pointers.h | 3 + src/service/plugin/PluginManager.cpp | 123 +++++++++++++++++++++++++++++++++++ src/service/plugin/PluginManager.h | 55 ++++++++++++++++ 8 files changed, 232 insertions(+), 6 deletions(-) create mode 100644 src/service/plugin/PluginManager.cpp create mode 100644 src/service/plugin/PluginManager.h diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt index f1c4c8a..f8d2eb8 100644 --- a/src/service/CMakeLists.txt +++ b/src/service/CMakeLists.txt @@ -22,6 +22,7 @@ SET(CYNARA_SOURCES ${CYNARA_SERVICE_PATH}/logic/Logic.cpp ${CYNARA_SERVICE_PATH}/main/Cynara.cpp ${CYNARA_SERVICE_PATH}/main/main.cpp + ${CYNARA_SERVICE_PATH}/plugin/PluginManager.cpp ${CYNARA_SERVICE_PATH}/sockets/Descriptor.cpp ${CYNARA_SERVICE_PATH}/sockets/SocketManager.cpp ) @@ -29,6 +30,7 @@ SET(CYNARA_SOURCES INCLUDE_DIRECTORIES( ${CYNARA_SERVICE_PATH} ${CYNARA_PATH} + ${CYNARA_PATH}/include ) ADD_EXECUTABLE(${TARGET_CYNARA} ${CYNARA_SOURCES}) @@ -37,6 +39,7 @@ TARGET_LINK_LIBRARIES(${TARGET_CYNARA} ${CYNARA_DEP_LIBRARIES} ${TARGET_CYNARA_COMMON} ${TARGET_LIB_CYNARA_STORAGE} + dl ) INSTALL(TARGETS ${TARGET_CYNARA} DESTINATION ${BIN_INSTALL_DIR}) diff --git a/src/service/logic/Logic.cpp b/src/service/logic/Logic.cpp index d05f512..60a0cce 100644 --- a/src/service/logic/Logic.cpp +++ b/src/service/logic/Logic.cpp @@ -97,13 +97,29 @@ bool Logic::check(RequestContextPtr context UNUSED, const PolicyKey &key, LOGD("check of policy key <%s> returned DENY", key.toString().c_str()); return true; } - //todo pass question to proper plugin that: - // 1) returns false when answer has to be waited for (UI) - // 2) returns true if Response is to be generated - // In case 1) context should be saved in plugin in order to return answer when ready. - //in case no proper plugin is found - throw PluginNotFoundException(result); + ExternalPluginPtr plugin = m_pluginManager->getPlugin(result.policyType()); + if (!plugin) { + throw PluginNotFoundException(result); + } + + AgentType requiredAgent; + PluginData pluginData; + + auto ret = plugin->check(key.client().toString(), key.user().toString(), + key.privilege().toString(), result, requiredAgent, pluginData); + + switch (ret) { + case ExternalPluginInterface::PluginStatus::ANSWER_READY: + return true; + case ExternalPluginInterface::PluginStatus::ANSWER_NOTREADY: + //todo send request to agent + //context should be saved in plugin in order to return answer when ready + return false; + default: + //todo make additional class + throw std::runtime_error("Plugin error"); + } } void Logic::execute(RequestContextPtr context, InsertOrUpdateBucketRequestPtr request) { diff --git a/src/service/logic/Logic.h b/src/service/logic/Logic.h index 28fdeea..3c434a5 100644 --- a/src/service/logic/Logic.h +++ b/src/service/logic/Logic.h @@ -27,6 +27,7 @@ #include #include
+#include #include #include @@ -37,6 +38,10 @@ public: Logic(); virtual ~Logic(); + void bindPluginManager(PluginManagerPtr pluginManager) { + m_pluginManager = pluginManager; + } + void bindStorage(StoragePtr storage) { m_storage = storage; } @@ -46,6 +51,7 @@ public: } void unbindAll(void) { + m_pluginManager.reset(); m_storage.reset(); m_socketManager.reset(); } @@ -59,6 +65,7 @@ public: virtual void execute(RequestContextPtr context, SignalRequestPtr request); private: + PluginManagerPtr m_pluginManager; StoragePtr m_storage; SocketManagerPtr m_socketManager; diff --git a/src/service/main/Cynara.cpp b/src/service/main/Cynara.cpp index 4a4deb4..1a0d45e 100644 --- a/src/service/main/Cynara.cpp +++ b/src/service/main/Cynara.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -58,12 +59,27 @@ const std::string Cynara::storageDir(void) { return dir; } +const std::string Cynara::pluginDir(void) { + std::string dir("/usr/lib/cynara/"); + +#ifdef CYNARA_LIB_PATH + dir = CYNARA_LIB_PATH; +#else + LOGW("Cynara compiled without CYNARA_LIB_PATH flag. Using default plugin directory."); +#endif + dir += "plugin/"; + LOGI("Cynara plugin path <%s>", dir.c_str()); + return dir; +} + void Cynara::init(void) { m_logic = std::make_shared(); + m_pluginManager = std::make_shared(pluginDir()); m_socketManager = std::make_shared(); m_storageBackend = std::make_shared(storageDir()); m_storage = std::make_shared(*m_storageBackend); + m_logic->bindPluginManager(m_pluginManager); m_logic->bindStorage(m_storage); m_logic->bindSocketManager(m_socketManager); @@ -90,6 +106,7 @@ void Cynara::finalize(void) { } m_logic.reset(); + m_pluginManager.reset(); m_socketManager.reset(); m_storageBackend.reset(); m_storage.reset(); diff --git a/src/service/main/Cynara.h b/src/service/main/Cynara.h index ecdde62..e89eda3 100644 --- a/src/service/main/Cynara.h +++ b/src/service/main/Cynara.h @@ -30,10 +30,12 @@ namespace Cynara { class Cynara { private: LogicPtr m_logic; + PluginManagerPtr m_pluginManager; SocketManagerPtr m_socketManager; StoragePtr m_storage; StorageBackendPtr m_storageBackend; + static const std::string pluginDir(void); static const std::string storageDir(void); public: diff --git a/src/service/main/pointers.h b/src/service/main/pointers.h index 652dba3..e31eeb8 100644 --- a/src/service/main/pointers.h +++ b/src/service/main/pointers.h @@ -30,6 +30,9 @@ namespace Cynara { class Logic; typedef std::shared_ptr LogicPtr; +class PluginManager; +typedef std::shared_ptr PluginManagerPtr; + class SocketManager; typedef std::shared_ptr SocketManagerPtr; diff --git a/src/service/plugin/PluginManager.cpp b/src/service/plugin/PluginManager.cpp new file mode 100644 index 0000000..3d21b49 --- /dev/null +++ b/src/service/plugin/PluginManager.cpp @@ -0,0 +1,123 @@ +/* + * 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 src/service/plugin/PluginManager.cpp + * @author Zofia Abramowska + * @version 1.0 + * @brief Definition of PluginManager class + */ + +#define _BSD_SOURCE_ + +#include +#include +#include +#include +#include + +#include + +#include "PluginManager.h" + + +namespace { + int pluginFilter(const struct dirent *ent) { +#ifdef _DIRENT_HAVE_D_TYPE + if (ent->d_type != DT_REG) { + return 0; + } +#endif + if (ent->d_name[0] == '.') { + return 0; + } + return 1; + } +} + +namespace Cynara { + +PluginManager::PluginManager(const std::string &pluginDir) : m_dir(pluginDir) { + loadPlugins(); +} + +ExternalPluginPtr PluginManager::getPlugin(PolicyType pType) { + return m_plugins[pType]; +} + +void PluginManager::loadPlugins(void) { + struct dirent **nameList = NULL; + int fileAmount = scandir(m_dir.c_str(), &nameList, pluginFilter, alphasort); + + if (fileAmount < 0) { + auto error = strerror(errno); + LOGE("Couldn't scan for plugins in <%s> : <%s>", m_dir.c_str(), error); + return; + } + + std::unique_ptr> direntPtr(nameList, + [fileAmount](dirent** dirs) { + for (int i = 0; i < fileAmount; i++) { + free(dirs[i]); + } + free(dirs); + }); + for (int i = 0; i < fileAmount; i++) { + openPlugin(m_dir + nameList[i]->d_name); + } +} + +void PluginManager::openPlugin(const std::string &path) { + void *handle = dlopen(path.c_str(), RTLD_LAZY); + + if (!handle) { + LOGW("File could not be dlopened <%s> : <%s>", path.c_str(), dlerror()); + return; + } + PluginLibPtr handlePtr(handle, std::ptr_fun(dlclose)); + + //Flush any previous errors + dlerror(); + createPlugin func = reinterpret_cast(dlsym(handle, "create")); + + char *error; + if ((error = dlerror()) != NULL) { + LOGE("Couldn't resolve symbol from lib <%s> : <%s>", path.c_str(), error); + return; + } + + ExternalPluginPtr pluginPtr(func()); + + if (!pluginPtr) { + LOGE("Couldn't create plugin for <%s>", path.c_str()); + return; + } + + PolicyTypes policies = pluginPtr->getSupportedPolicyTypes(); + if (policies.empty()) { + LOGE("Plugin <%s> does not support any type!", path.c_str()); + return; + } + for (auto type : policies) { + if (!m_plugins.insert(std::make_pair(type, pluginPtr)).second) { + LOGW("policyType [%" PRIu16 "] was already supported.", type); + } + } + + m_pluginLibs.push_back(std::move(handlePtr)); +} + +} // namespace Cynara + diff --git a/src/service/plugin/PluginManager.h b/src/service/plugin/PluginManager.h new file mode 100644 index 0000000..6338cad --- /dev/null +++ b/src/service/plugin/PluginManager.h @@ -0,0 +1,55 @@ +/* + * 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 src/service/plugin/PluginManager.h + * @author Zofia Abramowska + * @version 1.0 + * @brief Declaration of PluginManager class + */ + +#ifndef SRC_SERVICE_PLUGIN_PLUGINMANAGER_H_ +#define SRC_SERVICE_PLUGIN_PLUGINMANAGER_H_ + +#include +#include +#include +#include + +#include + +namespace Cynara { +typedef std::shared_ptr ExternalPluginPtr; + +class PluginManager { +public: + PluginManager(const std::string &pluginDir); + ExternalPluginPtr getPlugin(PolicyType pType); + ~PluginManager() {} + +private: + typedef std::unique_ptr> PluginLibPtr; + typedef std::list PluginLibs; + + std::string m_dir; + std::map m_plugins; + PluginLibs m_pluginLibs; + + void loadPlugins(void); + void openPlugin(const std::string &path); +}; + +} // namespace Cynara +#endif /* SRC_SERVICE_PLUGIN_PLUGINMANAGER_H_ */ -- 2.7.4 From 401f59efe466d7bc55174666a598d49941bc3ff8 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 7 Oct 2014 14:46:47 +0200 Subject: [PATCH 03/16] Add PluginErrorException Add exception class for plugin processing error. Change-Id: I26090bd3a54bdbc4767fd05735b5b06fae523b2f --- src/common/exceptions/PluginErrorException.h | 48 ++++++++++++++++++++++++++++ src/service/logic/Logic.cpp | 7 ++-- 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/common/exceptions/PluginErrorException.h diff --git a/src/common/exceptions/PluginErrorException.h b/src/common/exceptions/PluginErrorException.h new file mode 100644 index 0000000..a29eab5 --- /dev/null +++ b/src/common/exceptions/PluginErrorException.h @@ -0,0 +1,48 @@ +/* + * 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 src/common/exceptions/PluginErrorException.h + * @author Zofia Abramowska + * @version 1.0 + * @brief Implementation of PluginErrorException + */ +#ifndef SRC_COMMON_EXCEPTIONS_PLUGINERROREXCEPTION_H_ +#define SRC_COMMON_EXCEPTIONS_PLUGINERROREXCEPTION_H_ + +#include +#include + +namespace Cynara { + +class PluginErrorException : public Exception { +public: + PluginErrorException(const PolicyKey &key) { + m_message = "Plugin couldn't get result for user <" + key.user().toString() + ">, " + "client <" + key.client().toString() + ">, " + "privilege <" + key.privilege().toString() + ">"; + } + + const std::string message(void) const { + return m_message; + } + +private: + std::string m_message; +}; + +} // namespace Cynara + +#endif // SRC_COMMON_EXCEPTIONS_PLUGINERROREXCEPTION_H_ diff --git a/src/service/logic/Logic.cpp b/src/service/logic/Logic.cpp index 60a0cce..1787575 100644 --- a/src/service/logic/Logic.cpp +++ b/src/service/logic/Logic.cpp @@ -22,10 +22,12 @@ #include #include -#include #include #include #include +#include +#include + #include #include
@@ -117,8 +119,7 @@ bool Logic::check(RequestContextPtr context UNUSED, const PolicyKey &key, //context should be saved in plugin in order to return answer when ready return false; default: - //todo make additional class - throw std::runtime_error("Plugin error"); + throw PluginErrorException(key); } } -- 2.7.4 From adedddc8dbb050342f883b8966b9fe3fad5207f8 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Tue, 14 Oct 2014 08:47:31 +0200 Subject: [PATCH 04/16] Remove "noexcept" keyword from admin's Logic class We don't want cause application termination. All exceptions should be caught and handled. Change-Id: Ic245fb42a8b8fa7a7d83665ce95c4acb89c5b964 --- src/admin/api/ApiInterface.h | 10 +++++----- src/admin/logic/Logic.cpp | 8 ++++---- src/admin/logic/Logic.h | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/admin/api/ApiInterface.h b/src/admin/api/ApiInterface.h index bbfe98d..62c40e5 100644 --- a/src/admin/api/ApiInterface.h +++ b/src/admin/api/ApiInterface.h @@ -42,13 +42,13 @@ public: virtual ~ApiInterface() {}; virtual int setPolicies(const std::map> &insertOrUpdate, - const std::map> &remove) noexcept = 0; - virtual int insertOrUpdateBucket(const PolicyBucketId &bucket, const PolicyResult &policyResult) - noexcept = 0; - virtual int removeBucket(const PolicyBucketId &bucket) noexcept = 0; + const std::map> &remove) = 0; + virtual int insertOrUpdateBucket(const PolicyBucketId &bucket, + const PolicyResult &policyResult) = 0; + virtual int removeBucket(const PolicyBucketId &bucket) = 0; virtual int adminCheck(const PolicyBucketId &startBucket, bool recursive, - const PolicyKey &key, PolicyResult &result) noexcept = 0; + const PolicyKey &key, PolicyResult &result) = 0; }; diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp index 6906056..3b004d9 100644 --- a/src/admin/logic/Logic.cpp +++ b/src/admin/logic/Logic.cpp @@ -112,21 +112,21 @@ int Logic::askCynaraAndInterpreteCodeResponse(Args... args) { } int Logic::setPolicies(const std::map> &insertOrUpdate, - const std::map> &remove) noexcept { + const std::map> &remove) { return askCynaraAndInterpreteCodeResponse(insertOrUpdate, remove); } int Logic::insertOrUpdateBucket(const PolicyBucketId &bucket, - const PolicyResult &policyResult) noexcept { + const PolicyResult &policyResult) { return askCynaraAndInterpreteCodeResponse(bucket, policyResult); } -int Logic::removeBucket(const PolicyBucketId &bucket) noexcept { +int Logic::removeBucket(const PolicyBucketId &bucket) { return askCynaraAndInterpreteCodeResponse(bucket); } int Logic::adminCheck(const PolicyBucketId &startBucket, bool recursive, const PolicyKey &key, - PolicyResult &result) noexcept { + PolicyResult &result) { try { if (!ensureConnection()) { LOGE("Cannot connect to cynara. Service not available."); diff --git a/src/admin/logic/Logic.h b/src/admin/logic/Logic.h index 527e992..a8688c2 100644 --- a/src/admin/logic/Logic.h +++ b/src/admin/logic/Logic.h @@ -44,13 +44,13 @@ public: virtual ~Logic() {}; virtual int setPolicies(const std::map> &insertOrUpdate, - const std::map> &remove) noexcept; - virtual int insertOrUpdateBucket(const PolicyBucketId &bucket, const PolicyResult &policyResult) - noexcept; - virtual int removeBucket(const PolicyBucketId &bucket) noexcept; + const std::map> &remove); + virtual int insertOrUpdateBucket(const PolicyBucketId &bucket, + const PolicyResult &policyResult); + virtual int removeBucket(const PolicyBucketId &bucket); virtual int adminCheck(const PolicyBucketId &startBucket, bool recursive, - const PolicyKey &key, PolicyResult &result) noexcept; + const PolicyKey &key, PolicyResult &result); }; } // namespace Cynara -- 2.7.4 From 8c151752c38ea5572e4d2efbdc3ae55292ae8820 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Tue, 14 Oct 2014 09:21:41 +0200 Subject: [PATCH 05/16] Clean up exception classes Some minor clean-ups in exceptions classes: * remove "noexcept" keyword from exception classes; * catch exceptions in Exception::what(); * correcting comments; * adding missing virtual keyword; * rearranging public and private sections. Change-Id: I99c382838adb22429a7ea8ac35974c988b3d3f33 --- .../exceptions/BucketDeserializationException.h | 2 +- src/common/exceptions/BucketNotExistsException.h | 11 ++++----- .../exceptions/BucketRecordCorruptedException.h | 27 +++++++++++----------- .../exceptions/BucketSerializationException.h | 2 +- src/common/exceptions/CannotCreateFileException.h | 2 +- src/common/exceptions/DatabaseException.h | 3 ++- .../exceptions/DefaultBucketDeletionException.h | 2 +- .../exceptions/DefaultBucketSetNoneException.h | 2 +- .../exceptions/DescriptorNotExistsException.h | 8 +++---- src/common/exceptions/Exception.h | 8 +++++-- src/common/exceptions/FileNotFoundException.h | 2 +- src/common/exceptions/InitException.h | 2 +- src/common/exceptions/InvalidProtocolException.h | 14 +++++------ src/common/exceptions/NoMemoryException.h | 2 +- src/common/exceptions/NotImplementedException.h | 2 +- src/common/exceptions/NullPointerException.h | 10 ++++---- src/common/exceptions/OutOfDataException.h | 8 +++---- src/common/exceptions/PluginNotFoundException.h | 8 +++---- src/common/exceptions/UnexpectedErrorException.h | 8 +++---- 19 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/common/exceptions/BucketDeserializationException.h b/src/common/exceptions/BucketDeserializationException.h index c6b6f1d..c5670c8 100644 --- a/src/common/exceptions/BucketDeserializationException.h +++ b/src/common/exceptions/BucketDeserializationException.h @@ -30,7 +30,7 @@ namespace Cynara { class BucketDeserializationException : public DatabaseException { public: BucketDeserializationException(const PolicyBucketId &bucketId) : m_bucketId(bucketId) {} - ~BucketDeserializationException() noexcept {}; + virtual ~BucketDeserializationException() {}; const std::string message(void) const { if (m_message.empty()) { diff --git a/src/common/exceptions/BucketNotExistsException.h b/src/common/exceptions/BucketNotExistsException.h index 7802210..9ba9505 100644 --- a/src/common/exceptions/BucketNotExistsException.h +++ b/src/common/exceptions/BucketNotExistsException.h @@ -34,19 +34,18 @@ class BucketNotExistsException : public Exception { public: BucketNotExistsException() = delete; BucketNotExistsException(const PolicyBucketId &bucketId) : m_bucketId(bucketId) {} - virtual ~BucketNotExistsException() noexcept {}; + virtual ~BucketNotExistsException() {}; virtual const std::string message(void) const { return "BucketNotExistsException"; } -private: - PolicyBucketId m_bucketId; - -public: - const PolicyBucketId &bucketId() const { + const PolicyBucketId &bucketId(void) const { return m_bucketId; } + +private: + PolicyBucketId m_bucketId; }; } /* namespace Cynara */ diff --git a/src/common/exceptions/BucketRecordCorruptedException.h b/src/common/exceptions/BucketRecordCorruptedException.h index 4511fb5..92b29f7 100644 --- a/src/common/exceptions/BucketRecordCorruptedException.h +++ b/src/common/exceptions/BucketRecordCorruptedException.h @@ -31,7 +31,7 @@ namespace Cynara { class BucketRecordCorruptedException : public DatabaseException { public: BucketRecordCorruptedException(void) = delete; - virtual ~BucketRecordCorruptedException() noexcept {}; + virtual ~BucketRecordCorruptedException() {}; BucketRecordCorruptedException(const std::string &line) : m_lineNumber(0), m_line(line) {} @@ -60,6 +60,18 @@ public: return m_whatMsg; } + const std::string &filename(void) const { + return m_filename; + } + + const std::string &line(void) const { + return m_line; + } + + size_t lineNumber(void) const { + return m_lineNumber; + } + protected: inline std::string slicedLine(void) const { return m_line.substr(0, 50) + (m_line.size() > 50 ? "..." : ""); @@ -80,19 +92,6 @@ private: std::string m_line; std::string m_filename; mutable std::string m_whatMsg; - -public: - const std::string &filename(void) const { - return m_filename; - } - - const std::string &line(void) const { - return m_line; - } - - size_t lineNumber(void) const { - return m_lineNumber; - } }; } /* namespace Cynara */ diff --git a/src/common/exceptions/BucketSerializationException.h b/src/common/exceptions/BucketSerializationException.h index f6dba4c..1e02823 100644 --- a/src/common/exceptions/BucketSerializationException.h +++ b/src/common/exceptions/BucketSerializationException.h @@ -30,7 +30,7 @@ namespace Cynara { class BucketSerializationException : public DatabaseException { public: BucketSerializationException(const PolicyBucketId &bucketId) : m_bucketId(bucketId) {} - ~BucketSerializationException() noexcept {}; + virtual ~BucketSerializationException() {}; const std::string message(void) const { if (m_message.empty()) { diff --git a/src/common/exceptions/CannotCreateFileException.h b/src/common/exceptions/CannotCreateFileException.h index 4195156..67c1d67 100644 --- a/src/common/exceptions/CannotCreateFileException.h +++ b/src/common/exceptions/CannotCreateFileException.h @@ -32,7 +32,7 @@ namespace Cynara { class CannotCreateFileException : public DatabaseException { public: CannotCreateFileException(const std::string &filename) : m_filename(filename) {}; - virtual ~CannotCreateFileException() noexcept {}; + virtual ~CannotCreateFileException() {}; const std::string message(void) const { if (m_message.empty()) { diff --git a/src/common/exceptions/DatabaseException.h b/src/common/exceptions/DatabaseException.h index 9cbd2b4..834d524 100644 --- a/src/common/exceptions/DatabaseException.h +++ b/src/common/exceptions/DatabaseException.h @@ -27,7 +27,8 @@ namespace Cynara { class DatabaseException : public Exception { - +public: + virtual ~DatabaseException() {}; }; } /* namespace Cynara */ diff --git a/src/common/exceptions/DefaultBucketDeletionException.h b/src/common/exceptions/DefaultBucketDeletionException.h index 9b75a00..a4742be 100644 --- a/src/common/exceptions/DefaultBucketDeletionException.h +++ b/src/common/exceptions/DefaultBucketDeletionException.h @@ -32,7 +32,7 @@ namespace Cynara { class DefaultBucketDeletionException : public Exception { public: DefaultBucketDeletionException() = default; - virtual ~DefaultBucketDeletionException() noexcept {}; + virtual ~DefaultBucketDeletionException() {}; virtual const std::string message(void) const { return "DefaultBucketDeletionException"; diff --git a/src/common/exceptions/DefaultBucketSetNoneException.h b/src/common/exceptions/DefaultBucketSetNoneException.h index b7975cd..243c4d8 100644 --- a/src/common/exceptions/DefaultBucketSetNoneException.h +++ b/src/common/exceptions/DefaultBucketSetNoneException.h @@ -32,7 +32,7 @@ namespace Cynara { class DefaultBucketSetNoneException : public Exception { public: DefaultBucketSetNoneException() = default; - virtual ~DefaultBucketSetNoneException() noexcept {}; + virtual ~DefaultBucketSetNoneException() {}; virtual const std::string message(void) const { return "DefaultBucketSetNoneException"; diff --git a/src/common/exceptions/DescriptorNotExistsException.h b/src/common/exceptions/DescriptorNotExistsException.h index badb64a..3535b91 100644 --- a/src/common/exceptions/DescriptorNotExistsException.h +++ b/src/common/exceptions/DescriptorNotExistsException.h @@ -32,9 +32,6 @@ namespace Cynara { class DescriptorNotExistsException : public Exception { -private: - std::string m_whatMsg; - public: DescriptorNotExistsException() = delete; DescriptorNotExistsException(int desc) { @@ -43,11 +40,14 @@ public: m_whatMsg = stream.str(); } - virtual ~DescriptorNotExistsException() noexcept {}; + virtual ~DescriptorNotExistsException() {}; virtual const std::string message(void) const { return m_whatMsg; } + +private: + std::string m_whatMsg; }; } // namespace Cynara diff --git a/src/common/exceptions/Exception.h b/src/common/exceptions/Exception.h index 4f5f5eb..c5eb709 100644 --- a/src/common/exceptions/Exception.h +++ b/src/common/exceptions/Exception.h @@ -33,11 +33,15 @@ public: m_backtrace = Backtrace::getBacktrace(); } - virtual ~Exception() noexcept {}; + virtual ~Exception() {}; virtual const char *what(void) const noexcept { if(m_whatMessage.empty()) { - m_whatMessage = message() + " From: " + m_backtrace; + try { + m_whatMessage = message() + " From: " + m_backtrace; + } + catch (...) { + } } return m_whatMessage.c_str(); } diff --git a/src/common/exceptions/FileNotFoundException.h b/src/common/exceptions/FileNotFoundException.h index e7aeead..4c446e2 100644 --- a/src/common/exceptions/FileNotFoundException.h +++ b/src/common/exceptions/FileNotFoundException.h @@ -32,7 +32,7 @@ namespace Cynara { class FileNotFoundException : public DatabaseException { public: FileNotFoundException(const std::string &filename) : m_filename(filename) {}; - virtual ~FileNotFoundException() noexcept {}; + virtual ~FileNotFoundException() {}; const std::string message(void) const { if (m_message.empty()) { diff --git a/src/common/exceptions/InitException.h b/src/common/exceptions/InitException.h index c93155c..cdb09a2 100644 --- a/src/common/exceptions/InitException.h +++ b/src/common/exceptions/InitException.h @@ -32,7 +32,7 @@ namespace Cynara { class InitException : public Exception { public: InitException() = default; - virtual ~InitException() noexcept {}; + virtual ~InitException() {}; virtual const std::string message(void) const { return "InitException"; diff --git a/src/common/exceptions/InvalidProtocolException.h b/src/common/exceptions/InvalidProtocolException.h index 89d0e4b..9b6a740 100644 --- a/src/common/exceptions/InvalidProtocolException.h +++ b/src/common/exceptions/InvalidProtocolException.h @@ -38,11 +38,6 @@ public: Other }; -private: - std::string m_whatMessage; - ExceptionType m_exceptionType; - -public: InvalidProtocolException(ExceptionType exceptionType) : m_exceptionType(exceptionType) { switch(m_exceptionType) { @@ -56,18 +51,21 @@ public: m_whatMessage = "Unknown problem"; break; } - } - virtual ~InvalidProtocolException() noexcept {}; + virtual ~InvalidProtocolException() {}; virtual const std::string message(void) const { return m_whatMessage; } - ExceptionType exceptionTyp(void) const { + ExceptionType exceptionType(void) const { return m_exceptionType; } + +private: + std::string m_whatMessage; + ExceptionType m_exceptionType; }; } // namespace Cynara diff --git a/src/common/exceptions/NoMemoryException.h b/src/common/exceptions/NoMemoryException.h index d8a6086..2eca090 100644 --- a/src/common/exceptions/NoMemoryException.h +++ b/src/common/exceptions/NoMemoryException.h @@ -37,7 +37,7 @@ public: m_whatMessage = "NoMemoryException with message <" + errorMsg + ">"; } - virtual ~NoMemoryException() noexcept {}; + virtual ~NoMemoryException() {}; virtual const std::string message(void) const { return m_whatMessage; diff --git a/src/common/exceptions/NotImplementedException.h b/src/common/exceptions/NotImplementedException.h index 1496fd7..8ca3762 100644 --- a/src/common/exceptions/NotImplementedException.h +++ b/src/common/exceptions/NotImplementedException.h @@ -32,7 +32,7 @@ namespace Cynara { class NotImplementedException : public Exception { public: NotImplementedException() = default; - virtual ~NotImplementedException() noexcept {}; + virtual ~NotImplementedException() {}; virtual const std::string message(void) const { return "NotImplementedException"; diff --git a/src/common/exceptions/NullPointerException.h b/src/common/exceptions/NullPointerException.h index 47e4239..e735555 100644 --- a/src/common/exceptions/NullPointerException.h +++ b/src/common/exceptions/NullPointerException.h @@ -17,7 +17,7 @@ * @file src/common/exceptions/NullPointerException.h * @author Lukasz Wojciechowski * @version 1.0 - * @brief Implementation of OutOfDataException + * @brief Implementation of NullPointerException */ #ifndef SRC_COMMON_EXCEPTIONS_NULLPOINTEREXCEPTION_H_ @@ -31,9 +31,6 @@ namespace Cynara { class NullPointerException : public Exception { -private: - std::string m_whatMsg; - public: NullPointerException() = delete; NullPointerException(const char *varName) { @@ -42,11 +39,14 @@ public: + std::string(">"); } - virtual ~NullPointerException() noexcept {}; + virtual ~NullPointerException() {}; virtual const std::string message(void) const { return m_whatMsg; } + +private: + std::string m_whatMsg; }; } // namespace Cynara diff --git a/src/common/exceptions/OutOfDataException.h b/src/common/exceptions/OutOfDataException.h index 716df13..6420819 100644 --- a/src/common/exceptions/OutOfDataException.h +++ b/src/common/exceptions/OutOfDataException.h @@ -32,9 +32,6 @@ namespace Cynara { class OutOfDataException : public Exception { -private: - std::string m_whatMsg; - public: OutOfDataException() = delete; OutOfDataException(size_t dataRange, size_t accessTry) { @@ -44,11 +41,14 @@ public: m_whatMsg = stream.str(); } - virtual ~OutOfDataException() noexcept {}; + virtual ~OutOfDataException() {}; virtual const std::string message(void) const { return m_whatMsg; } + +private: + std::string m_whatMsg; }; } // namespace Cynara diff --git a/src/common/exceptions/PluginNotFoundException.h b/src/common/exceptions/PluginNotFoundException.h index 3604075..4492a53 100644 --- a/src/common/exceptions/PluginNotFoundException.h +++ b/src/common/exceptions/PluginNotFoundException.h @@ -32,9 +32,6 @@ namespace Cynara { class PluginNotFoundException : public Exception { -private: - std::string m_whatMessage; - public: PluginNotFoundException() = delete; PluginNotFoundException(const PolicyResult &result) { @@ -45,11 +42,14 @@ public: m_whatMessage = stream.str(); } - virtual ~PluginNotFoundException() noexcept {}; + virtual ~PluginNotFoundException() {}; virtual const std::string message(void) const { return m_whatMessage; } + +private: + std::string m_whatMessage; }; } // namespace Cynara diff --git a/src/common/exceptions/UnexpectedErrorException.h b/src/common/exceptions/UnexpectedErrorException.h index ed0b72c..3080c0f 100644 --- a/src/common/exceptions/UnexpectedErrorException.h +++ b/src/common/exceptions/UnexpectedErrorException.h @@ -31,9 +31,6 @@ namespace Cynara { class UnexpectedErrorException : public Exception { -private: - std::string m_whatMessage; - public: UnexpectedErrorException() = delete; UnexpectedErrorException(int errorCode, const char *errorMsg) { @@ -49,11 +46,14 @@ public: m_whatMessage = stream.str(); } - virtual ~UnexpectedErrorException() noexcept {}; + virtual ~UnexpectedErrorException() {}; virtual const std::string message(void) const { return m_whatMessage; } + +private: + std::string m_whatMessage; }; } // namespace Cynara -- 2.7.4 From 35c285ba8b553681422b9e996da08e5e721ca38a Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Tue, 14 Oct 2014 11:13:25 +0200 Subject: [PATCH 06/16] Remove "noexcept" keyword from PolicyBucket Change-Id: I0b00841efadb7584e854a04286758caf90e400cc --- src/common/types/PolicyBucket.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/types/PolicyBucket.h b/src/common/types/PolicyBucket.h index 92c5f36..122ece0 100644 --- a/src/common/types/PolicyBucket.h +++ b/src/common/types/PolicyBucket.h @@ -86,11 +86,11 @@ public: return const_policy_iterator(m_policyCollection.end()); } - PolicyMap::size_type size(void) const noexcept { + PolicyMap::size_type size(void) const { return m_policyCollection.size(); } - bool empty(void) const noexcept { + bool empty(void) const { return m_policyCollection.empty(); } -- 2.7.4 From 426deba8e8db72050eeef6044b170015b10260e4 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Tue, 14 Oct 2014 14:09:00 +0200 Subject: [PATCH 07/16] Use client error codes in admin libraries We need to have one unified set of error codes. Client error codes have been adjusted to serve admin errors too. Then client error codes were used in admin libraries keeping following mapping: CYNARA_ADMIN_API_SUCCESS -> CYNARA_API_SUCCESS CYNARA_ADMIN_API_OUT_OF_MEMORY -> CYNARA_API_OUT_OF_MEMORY CYNARA_ADMIN_API_INVALID_PARAM -> CYNARA_API_INVALID_PARAM CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE -> CYNARA_API_SERVICE_NOT_AVAILABLE CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR -> CYNARA_API_UNKNOWN_ERROR CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED -> CYNARA_API_OPERATION_NOT_ALLOWED CYNARA_ADMIN_API_BUCKET_NOT_FOUND -> CYNARA_API_BUCKET_NOT_FOUND Remove not needed anymore old admin error codes file: src/include/cynara-admin-error.h Change-Id: Ice8990a2b354bd489c67c2a004344a5c60fc15ee --- packaging/cynara.spec | 2 +- src/admin/api/admin-api.cpp | 50 +++++++++++++++++----------------- src/admin/logic/Logic.cpp | 34 +++++++++++------------ src/include/CMakeLists.txt | 1 - src/include/cynara-admin-error.h | 56 -------------------------------------- src/include/cynara-admin.h | 12 ++++---- src/include/cynara-client-error.h | 8 +++++- src/include/cynara-offline-admin.h | 12 ++++---- 8 files changed, 62 insertions(+), 113 deletions(-) delete mode 100644 src/include/cynara-admin-error.h diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 6abd205..17746c8 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -106,6 +106,7 @@ admin client library for setting, listing and removing policies %package -n libcynara-admin-devel Summary: Cynara - admin client library (devel) Requires: libcynara-admin = %{version}-%{release} +Requires: libcynara-commons-devel = %{version}-%{release} %description -n libcynara-admin-devel admin client library (devel) for setting, listing and removing policies @@ -440,7 +441,6 @@ fi %files -n libcynara-admin-devel %{_includedir}/cynara/cynara-admin.h -%{_includedir}/cynara/cynara-admin-error.h %{_includedir}/cynara/cynara-admin-types.h %{_libdir}/libcynara-admin.so %{_libdir}/pkgconfig/cynara-admin.pc diff --git a/src/admin/api/admin-api.cpp b/src/admin/api/admin-api.cpp index fe426fb..929b075 100644 --- a/src/admin/api/admin-api.cpp +++ b/src/admin/api/admin-api.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include @@ -55,35 +55,35 @@ struct cynara_admin { CYNARA_API int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) { if (!pp_cynara_admin) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; try { *pp_cynara_admin = new cynara_admin(new Cynara::Logic); } catch (const std::bad_alloc &ex) { - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } init_log(); LOGD("Cynara admin initialized"); - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; } CYNARA_API int cynara_admin_finish(struct cynara_admin *p_cynara_admin) { delete p_cynara_admin; - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; } CYNARA_API int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, const struct cynara_admin_policy *const *policies) { if (!p_cynara_admin || !p_cynara_admin->impl) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!policies) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; std::map> insertOrUpdate; std::map> remove; @@ -106,7 +106,7 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, for (auto i = policies; *i; i++) { const cynara_admin_policy *policy = *i; if(!policy->bucket || !policy->client || !policy->user || !policy->privilege) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; switch (policy->result) { case CYNARA_ADMIN_DELETE: @@ -122,7 +122,7 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, break; case CYNARA_ADMIN_BUCKET: if (!policy->result_extra) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; insertOrUpdate[policy->bucket].push_back(Cynara::Policy(key(policy), Cynara::PolicyResult( Cynara::PredefinedPolicyType::BUCKET, @@ -130,11 +130,11 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, break; case CYNARA_ADMIN_NONE: default: - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; } } } catch (const std::bad_alloc &ex) { - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } return p_cynara_admin->impl->setPolicies(insertOrUpdate, remove); @@ -144,15 +144,15 @@ CYNARA_API int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *bucket, int operation, const char *extra) { if (!p_cynara_admin || !p_cynara_admin->impl) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!bucket) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; std::string extraStr; try { extraStr = extra ? extra : ""; } catch (const std::bad_alloc &ex) { - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } switch (operation) { case CYNARA_ADMIN_DELETE: @@ -168,10 +168,10 @@ int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *buc return p_cynara_admin->impl->insertOrUpdateBucket(bucket, Cynara::PolicyResult(Cynara::PredefinedPolicyType::NONE)); } - return CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED; + return CYNARA_API_OPERATION_NOT_ALLOWED; case CYNARA_ADMIN_BUCKET: default: - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; } } @@ -181,13 +181,13 @@ int cynara_admin_check(struct cynara_admin *p_cynara_admin, const char *client, const char *user, const char *privilege, int *result, char **result_extra) { if (!p_cynara_admin || !p_cynara_admin->impl) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!start_bucket) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!client || !user || !privilege) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!result || !result_extra) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; Cynara::PolicyResult policyResult; @@ -195,22 +195,22 @@ int cynara_admin_check(struct cynara_admin *p_cynara_admin, int ret = p_cynara_admin->impl->adminCheck(start_bucket, recursive != 0, Cynara::PolicyKey(client, user, privilege), policyResult); - if (ret != CYNARA_ADMIN_API_SUCCESS) + if (ret != CYNARA_API_SUCCESS) return ret; } catch (const std::bad_alloc &ex) { - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } catch (const std::length_error &ex) { - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; } char *str = nullptr; if (!policyResult.metadata().empty()) { str = strdup(policyResult.metadata().c_str()); if (!str) - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } *result = static_cast(policyResult.policyType()); *result_extra = str; - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; } diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp index 3b004d9..d36651e 100644 --- a/src/admin/logic/Logic.cpp +++ b/src/admin/logic/Logic.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -65,7 +65,7 @@ int Logic::askCynaraAndInterpreteCodeResponse(Args... args) { try { if (!ensureConnection()) { LOGE("Cannot connect to cynara. Service not available."); - return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE; + return CYNARA_API_SERVICE_NOT_AVAILABLE; } ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); @@ -77,37 +77,37 @@ int Logic::askCynaraAndInterpreteCodeResponse(Args... args) { ResponsePtr response; while (!(response = m_socketClient->askCynaraServer(request))) { if (!m_socketClient->connect()) - return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE; + return CYNARA_API_SERVICE_NOT_AVAILABLE; } codeResponse = std::dynamic_pointer_cast(response); if (!codeResponse) { LOGC("Critical error. Casting Response to CodeResponse failed."); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } LOGD("codeResponse: code [%" PRIu16 "]", codeResponse->m_code); switch (codeResponse->m_code) { case CodeResponse::Code::OK: LOGI("Policies set successfully."); - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; case CodeResponse::Code::NOT_ALLOWED: LOGE("Cynara service answered: Operation not allowed."); - return CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED; + return CYNARA_API_OPERATION_NOT_ALLOWED; case CodeResponse::Code::NO_BUCKET: LOGE("Trying to use unexisting bucket."); - return CYNARA_ADMIN_API_BUCKET_NOT_FOUND; + return CYNARA_API_BUCKET_NOT_FOUND; default: LOGE("Unexpected response code from server: [%d]", static_cast(codeResponse->m_code)); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } } catch (const std::bad_alloc &ex) { LOGE("Cynara admin client out of memory."); - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } catch (const std::exception &ex) { LOGE("Unexpected client error: <%s>", ex.what()); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } } @@ -130,7 +130,7 @@ int Logic::adminCheck(const PolicyBucketId &startBucket, bool recursive, const P try { if (!ensureConnection()) { LOGE("Cannot connect to cynara. Service not available."); - return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE; + return CYNARA_API_SERVICE_NOT_AVAILABLE; } ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); @@ -143,13 +143,13 @@ int Logic::adminCheck(const PolicyBucketId &startBucket, bool recursive, const P ResponsePtr response; while (!(response = m_socketClient->askCynaraServer(request))) { if (!m_socketClient->connect()) - return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE; + return CYNARA_API_SERVICE_NOT_AVAILABLE; } checkResponse = std::dynamic_pointer_cast(response); if (!checkResponse) { LOGC("Casting Response to CheckResponse failed."); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } LOGD("checkResponse: policyType [%" PRIu16 "], metadata <%s>", @@ -157,16 +157,16 @@ int Logic::adminCheck(const PolicyBucketId &startBucket, bool recursive, const P checkResponse->m_resultRef.metadata().c_str()); result = checkResponse->m_resultRef; - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; } catch (const UnexpectedErrorException &ex) { LOGE(ex.what()); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } catch (const std::bad_alloc &ex) { LOGE("Cynara admin client out of memory."); - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } catch (const std::exception &ex) { LOGE("Unexpected client error: <%s>", ex.what()); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } } diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index cb9d00c..a6c1945 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -18,7 +18,6 @@ INSTALL(FILES ${CYNARA_PATH}/include/cynara-admin.h - ${CYNARA_PATH}/include/cynara-admin-error.h ${CYNARA_PATH}/include/cynara-admin-types.h ${CYNARA_PATH}/include/cynara-client.h ${CYNARA_PATH}/include/cynara-client-async.h diff --git a/src/include/cynara-admin-error.h b/src/include/cynara-admin-error.h deleted file mode 100644 index 4b9cad9..0000000 --- a/src/include/cynara-admin-error.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 src/include/cynara-admin-error.h - * @author Lukasz Wojciechowski - * @author Zofia Abramowska - * @version 1.0 - * @brief This file contains error codes of administration APIs of Cynara. - */ - -#ifndef CYNARA_ADMIN_ERROR_H -#define CYNARA_ADMIN_ERROR_H - -/** - * \name Return Codes - * exported by the foundation API. - * result codes begin with the start error code and extend into negative direction. - * @{ -*/ - -/*! \brief indicating the result of the one specific API is successful or access is allowed */ -#define CYNARA_ADMIN_API_SUCCESS 0 - -/*! \brief indicating client process is running out of memory */ -#define CYNARA_ADMIN_API_OUT_OF_MEMORY -1 - -/*! \brief indicating the API's parameter is malformed */ -#define CYNARA_ADMIN_API_INVALID_PARAM -2 - -/*! \brief service not available (cannot connect to cynara service) */ -#define CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE -3 - -/*! \brief unexpected error in client library */ -#define CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR -4 - -/*! \brief cynara service does not allow to perform requested operation */ -#define CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED -5 - -/*! \brief cynara service hasn't found requested bucket */ -#define CYNARA_ADMIN_API_BUCKET_NOT_FOUND -6 -/** @}*/ - -#endif // CYNARA_ADMIN_ERROR_H diff --git a/src/include/cynara-admin.h b/src/include/cynara-admin.h index a31b1c5..6f5bc9e 100644 --- a/src/include/cynara-admin.h +++ b/src/include/cynara-admin.h @@ -23,8 +23,8 @@ #ifndef CYNARA_ADMIN_H #define CYNARA_ADMIN_H -#include #include +#include #ifdef __cplusplus extern "C" { @@ -63,7 +63,7 @@ struct cynara_admin; * * \param[out] pp_cynara_admin address of pointer for created cynara_admin structure. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Initialize cynara-admin library. */ @@ -92,7 +92,7 @@ int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin); * * \param[in] p_cynara_admin cynara_admin structure created in cynara_admin_initialize. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Release cynara-admin library. */ @@ -144,7 +144,7 @@ int cynara_admin_finish(struct cynara_admin *p_cynara_admin); * \param[in] p_cynara_admin cynara admin structure. * \param[in] policies NULL terminated array of pointers to policy structures. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Insert, update or delete policies in cynara database. */ @@ -191,7 +191,7 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, * \param[in] operation type of operation (default policy or CYNARA_ADMIN_DELETE) * \param[in] extra additional data for default policy (will be available with cynara extensions) * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Add, remove or update buckets in cynara database. */ @@ -238,7 +238,7 @@ int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *buc * \param[out] result placeholder for matched policy type. * \param[out] result_extra placeholder for matched policy additional data (see Important Notes!). * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Raw check client and user access for given privilege without using plugins extensions. */ diff --git a/src/include/cynara-client-error.h b/src/include/cynara-client-error.h index 8dd344f..d4d8bcc 100644 --- a/src/include/cynara-client-error.h +++ b/src/include/cynara-client-error.h @@ -58,8 +58,14 @@ /*! \brief indicating that provided method is not supported by library */ #define CYNARA_API_METHOD_NOT_SUPPORTED -6 +/*! \brief cynara service does not allow to perform requested operation */ +#define CYNARA_API_OPERATION_NOT_ALLOWED -7 + +/*! \brief cynara service hasn't found requested bucket */ +#define CYNARA_API_BUCKET_NOT_FOUND -8 + /*! \brief indicating an unknown error */ -#define CYNARA_API_UNKNOWN_ERROR -7 +#define CYNARA_API_UNKNOWN_ERROR -9 /** @}*/ diff --git a/src/include/cynara-offline-admin.h b/src/include/cynara-offline-admin.h index 1b26901..079ebd3 100644 --- a/src/include/cynara-offline-admin.h +++ b/src/include/cynara-offline-admin.h @@ -25,8 +25,8 @@ #ifndef CYNARA_OFFLINE_ADMIN_H #define CYNARA_OFFLINE_ADMIN_H -#include #include +#include #ifdef __cplusplus extern "C" { @@ -66,7 +66,7 @@ struct cynara_offline_admin; * \param[out] pp_cynara_offline_admin address of pointer for created cynara_offline_admin * structure. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise. + * \return CYNARA_API_SUCCESS on success, or negative error code otherwise. * * \brief Initialize cynara-offline-admin library. */ @@ -96,7 +96,7 @@ int cynara_offline_admin_initialize(struct cynara_offline_admin **pp_cynara_offl * \param[in] p_cynara_offline_admin cynara_offline_admin structure created * in cynara_offline_admin_initialize. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise. + * \return CYNARA_API_SUCCESS on success, or negative error code otherwise. * * \brief Release cynara-offline-admin library. */ @@ -146,7 +146,7 @@ int cynara_offline_admin_finish(struct cynara_offline_admin *p_cynara_offline_ad * \param[in] p_cynara_offline_admin cynara offline admin structure. * \param[in] policies NULL terminated array of pointers to policy structures. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise. + * \return CYNARA_API_SUCCESS on success, or negative error code otherwise. * * \brief Insert, update or delete policies in cynara database. */ @@ -193,7 +193,7 @@ int cynara_offline_admin_set_policies(struct cynara_offline_admin *p_cynara_offl * \param[in] operation type of operation (default policy or CYNARA_ADMIN_DELETE) * \param[in] extra additional data for default policy (will be available with cynara extensions) * - * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise. + * \return CYNARA_API_SUCCESS on success, or negative error code otherwise. * * \brief Add, remove or update buckets in cynara database. */ @@ -240,7 +240,7 @@ int cynara_offline_admin_set_bucket(struct cynara_offline_admin *p_cynara_offlin * \param[out] result placeholder for matched policy type * \param[out] result_extra placeholder for matched policy additional data (see Important Notes!) * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Raw check client, user access for given privilege without using plugins extensions. */ -- 2.7.4 From cbdeb6113b5e8b8cfbfea846fe7e7ed5d672926f Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Tue, 14 Oct 2014 14:37:07 +0200 Subject: [PATCH 08/16] Rename cynara-client-error.h to cynara-error.h Apply new name to all files. Change-Id: I9e4590a40e11ba5a33442707207635bb0d75a278 --- packaging/cynara.spec | 2 +- src/admin/api/admin-api.cpp | 2 +- src/admin/logic/Logic.cpp | 2 +- src/client-common/cache/CapacityCache.cpp | 2 +- src/client-common/exceptions/TryCatch.h | 2 +- src/client-common/plugins/NaiveInterpreter.h | 2 +- src/client/api/client-api.cpp | 2 +- src/client/logic/Logic.cpp | 2 +- src/helpers/creds-commons/creds-commons.cpp | 2 +- src/helpers/creds-dbus/creds-dbus-inner.cpp | 2 +- src/helpers/creds-dbus/creds-dbus.cpp | 2 +- src/helpers/creds-socket/creds-socket-inner.cpp | 2 +- src/helpers/creds-socket/creds-socket.cpp | 2 +- src/include/CMakeLists.txt | 2 +- src/include/cynara-admin.h | 2 +- src/include/cynara-client-async.h | 2 +- src/include/cynara-client.h | 2 +- src/include/cynara-creds-commons.h | 2 +- src/include/{cynara-client-error.h => cynara-error.h} | 10 +++++----- src/include/cynara-offline-admin.h | 2 +- 20 files changed, 24 insertions(+), 24 deletions(-) rename src/include/{cynara-client-error.h => cynara-error.h} (90%) diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 17746c8..e8d0bc8 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -431,7 +431,7 @@ fi %{_libdir}/libcynara-client-commons.so.* %files -n libcynara-client-commons-devel -%{_includedir}/cynara/cynara-client-error.h +%{_includedir}/cynara/cynara-error.h %{_libdir}/libcynara-client-commons.so %files -n libcynara-admin diff --git a/src/admin/api/admin-api.cpp b/src/admin/api/admin-api.cpp index 929b075..0df64f3 100644 --- a/src/admin/api/admin-api.cpp +++ b/src/admin/api/admin-api.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp index d36651e..683a2cf 100644 --- a/src/admin/logic/Logic.cpp +++ b/src/admin/logic/Logic.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/client-common/cache/CapacityCache.cpp b/src/client-common/cache/CapacityCache.cpp index c6449bc..d07bb2c 100644 --- a/src/client-common/cache/CapacityCache.cpp +++ b/src/client-common/cache/CapacityCache.cpp @@ -22,7 +22,7 @@ #include -#include +#include #include #include diff --git a/src/client-common/exceptions/TryCatch.h b/src/client-common/exceptions/TryCatch.h index 6dc4d0b..08b93d9 100644 --- a/src/client-common/exceptions/TryCatch.h +++ b/src/client-common/exceptions/TryCatch.h @@ -30,7 +30,7 @@ #include #include -#include +#include namespace Cynara { diff --git a/src/client-common/plugins/NaiveInterpreter.h b/src/client-common/plugins/NaiveInterpreter.h index e306ab7..e9e8ba4 100644 --- a/src/client-common/plugins/NaiveInterpreter.h +++ b/src/client-common/plugins/NaiveInterpreter.h @@ -24,7 +24,7 @@ #include #include -#include +#include namespace Cynara { diff --git a/src/client/api/client-api.cpp b/src/client/api/client-api.cpp index 6ca7def..4eb4625 100644 --- a/src/client/api/client-api.cpp +++ b/src/client/api/client-api.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include diff --git a/src/client/logic/Logic.cpp b/src/client/logic/Logic.cpp index f375e9e..4886b78 100644 --- a/src/client/logic/Logic.cpp +++ b/src/client/logic/Logic.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/helpers/creds-commons/creds-commons.cpp b/src/helpers/creds-commons/creds-commons.cpp index 3fa1c9b..35d2ac7 100644 --- a/src/helpers/creds-commons/creds-commons.cpp +++ b/src/helpers/creds-commons/creds-commons.cpp @@ -24,8 +24,8 @@ #include -#include #include +#include CYNARA_API int cynara_creds_get_default_client_method(enum cynara_client_creds *method) { diff --git a/src/helpers/creds-dbus/creds-dbus-inner.cpp b/src/helpers/creds-dbus/creds-dbus-inner.cpp index 34ad453..fc48217 100644 --- a/src/helpers/creds-dbus/creds-dbus-inner.cpp +++ b/src/helpers/creds-dbus/creds-dbus-inner.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include "creds-dbus-inner.h" diff --git a/src/helpers/creds-dbus/creds-dbus.cpp b/src/helpers/creds-dbus/creds-dbus.cpp index e0b235d..4bca2a5 100644 --- a/src/helpers/creds-dbus/creds-dbus.cpp +++ b/src/helpers/creds-dbus/creds-dbus.cpp @@ -27,9 +27,9 @@ #include -#include #include #include +#include CYNARA_API int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueName, diff --git a/src/helpers/creds-socket/creds-socket-inner.cpp b/src/helpers/creds-socket/creds-socket-inner.cpp index 320fca5..bb4ebcc 100644 --- a/src/helpers/creds-socket/creds-socket-inner.cpp +++ b/src/helpers/creds-socket/creds-socket-inner.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include "creds-socket-inner.h" diff --git a/src/helpers/creds-socket/creds-socket.cpp b/src/helpers/creds-socket/creds-socket.cpp index d60c241..fb5f963 100644 --- a/src/helpers/creds-socket/creds-socket.cpp +++ b/src/helpers/creds-socket/creds-socket.cpp @@ -29,9 +29,9 @@ #include -#include #include #include +#include CYNARA_API int cynara_creds_socket_get_client(int socket_fd, enum cynara_client_creds method, char **client) { diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index a6c1945..245962d 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -21,10 +21,10 @@ INSTALL(FILES ${CYNARA_PATH}/include/cynara-admin-types.h ${CYNARA_PATH}/include/cynara-client.h ${CYNARA_PATH}/include/cynara-client-async.h - ${CYNARA_PATH}/include/cynara-client-error.h ${CYNARA_PATH}/include/cynara-creds-commons.h ${CYNARA_PATH}/include/cynara-creds-dbus.h ${CYNARA_PATH}/include/cynara-creds-socket.h + ${CYNARA_PATH}/include/cynara-error.h ${CYNARA_PATH}/include/cynara-plugin.h ${CYNARA_PATH}/include/cynara-session.h DESTINATION ${INCLUDE_INSTALL_DIR}/cynara diff --git a/src/include/cynara-admin.h b/src/include/cynara-admin.h index 6f5bc9e..0e92b18 100644 --- a/src/include/cynara-admin.h +++ b/src/include/cynara-admin.h @@ -24,7 +24,7 @@ #define CYNARA_ADMIN_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/include/cynara-client-async.h b/src/include/cynara-client-async.h index 1e39d9b..20f5ea4 100644 --- a/src/include/cynara-client-async.h +++ b/src/include/cynara-client-async.h @@ -27,7 +27,7 @@ #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/include/cynara-client.h b/src/include/cynara-client.h index 3f4c938..571bef1 100644 --- a/src/include/cynara-client.h +++ b/src/include/cynara-client.h @@ -23,7 +23,7 @@ #ifndef CYNARA_CLIENT_H #define CYNARA_CLIENT_H -#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/include/cynara-creds-commons.h b/src/include/cynara-creds-commons.h index 0bb3e69..75e4366 100644 --- a/src/include/cynara-creds-commons.h +++ b/src/include/cynara-creds-commons.h @@ -26,7 +26,7 @@ #ifndef CYNARA_CREDS_COMMONS_H #define CYNARA_CREDS_COMMONS_H -#include +#include enum cynara_client_creds { CLIENT_METHOD_SMACK, diff --git a/src/include/cynara-client-error.h b/src/include/cynara-error.h similarity index 90% rename from src/include/cynara-client-error.h rename to src/include/cynara-error.h index d4d8bcc..e8900b8 100644 --- a/src/include/cynara-client-error.h +++ b/src/include/cynara-error.h @@ -14,15 +14,15 @@ * limitations under the License */ /** - * @file src/include/cynara-client-error.h + * @file src/include/cynara-error.h * @author Lukasz Wojciechowski * @author Zofia Abramowska * @version 1.0 - * @brief This file contains error codes returned by client APIs of Cynara. + * @brief This file contains error codes returned by APIs of Cynara. */ -#ifndef CYNARA_CLIENT_ERROR_H -#define CYNARA_CLIENT_ERROR_H +#ifndef CYNARA_ERROR_H +#define CYNARA_ERROR_H /** * \name Return Codes @@ -69,4 +69,4 @@ /** @}*/ -#endif /* CYNARA_CLIENT_ERROR_H */ +#endif /* CYNARA_ERROR_H */ diff --git a/src/include/cynara-offline-admin.h b/src/include/cynara-offline-admin.h index 079ebd3..dbecc78 100644 --- a/src/include/cynara-offline-admin.h +++ b/src/include/cynara-offline-admin.h @@ -26,7 +26,7 @@ #define CYNARA_OFFLINE_ADMIN_H #include -#include +#include #ifdef __cplusplus extern "C" { -- 2.7.4 From 5dca2a965490bd53fa00ac2d8c612b0653eb9fa7 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Tue, 14 Oct 2014 14:45:27 +0200 Subject: [PATCH 09/16] Move TryCatch from client-common to common library TryCatch can be used also in admin libraries, so it belongs to common library now. Change-Id: Ibdd9c1576b9b34195555c2d9b43e72b57a83a201 --- src/{client-common => common}/exceptions/TryCatch.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) rename src/{client-common => common}/exceptions/TryCatch.h (88%) diff --git a/src/client-common/exceptions/TryCatch.h b/src/common/exceptions/TryCatch.h similarity index 88% rename from src/client-common/exceptions/TryCatch.h rename to src/common/exceptions/TryCatch.h index 08b93d9..b1ef172 100644 --- a/src/client-common/exceptions/TryCatch.h +++ b/src/common/exceptions/TryCatch.h @@ -14,14 +14,14 @@ * limitations under the License */ /** - * @file src/client-common/exceptions/TryCatch.h + * @file src/common/exceptions/TryCatch.h * @author Marcin Niesluchowski * @version 1.0 * @brief This file contains functions for catching exceptions */ -#ifndef SRC_CLIENT_COMMON_EXCEPTIONS_TRYCATCH_H_ -#define SRC_CLIENT_COMMON_EXCEPTIONS_TRYCATCH_H_ +#ifndef SRC_COMMON_EXCEPTIONS_TRYCATCH_H_ +#define SRC_COMMON_EXCEPTIONS_TRYCATCH_H_ #include #include @@ -54,5 +54,4 @@ int tryCatch(const std::function &func) { } // namespace Cynara -#endif // SRC_CLIENT_COMMON_EXCEPTIONS_TRYCATCH_H_ - +#endif // SRC_COMMON_EXCEPTIONS_TRYCATCH_H_ -- 2.7.4 From 45c717d1a2f1091ad025fc617dd3af6ab67ef095 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Thu, 16 Oct 2014 08:25:04 +0200 Subject: [PATCH 10/16] Use TryCatch() for exception catching in admin library Change-Id: I01d0b075c7d9cb5d94cadfe2c1dc5da7bd326027 --- src/admin/api/admin-api.cpp | 141 +++++++++++++++++++++++--------------------- src/admin/logic/Logic.cpp | 133 ++++++++++++++++++----------------------- 2 files changed, 130 insertions(+), 144 deletions(-) diff --git a/src/admin/api/admin-api.cpp b/src/admin/api/admin-api.cpp index 0df64f3..e444b7a 100644 --- a/src/admin/api/admin-api.cpp +++ b/src/admin/api/admin-api.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -57,17 +58,15 @@ int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) { if (!pp_cynara_admin) return CYNARA_API_INVALID_PARAM; - try { + return Cynara::tryCatch([&]() { *pp_cynara_admin = new cynara_admin(new Cynara::Logic); - } catch (const std::bad_alloc &ex) { - return CYNARA_API_OUT_OF_MEMORY; - } - init_log(); + init_log(); - LOGD("Cynara admin initialized"); + LOGD("Cynara admin initialized"); - return CYNARA_API_SUCCESS; + return CYNARA_API_SUCCESS; + }); } CYNARA_API @@ -85,24 +84,24 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, if (!policies) return CYNARA_API_INVALID_PARAM; - std::map> insertOrUpdate; - std::map> remove; + return Cynara::tryCatch([&]() { + std::map> insertOrUpdate; + std::map> remove; - auto key = ([](const cynara_admin_policy *policy)->Cynara::PolicyKey { - std::string wildcard(CYNARA_ADMIN_WILDCARD); + auto key = ([](const cynara_admin_policy *policy)->Cynara::PolicyKey { + std::string wildcard(CYNARA_ADMIN_WILDCARD); - auto feature = ([&wildcard] (const char *str)->Cynara::PolicyKeyFeature { - if (wildcard.compare(str)) - return Cynara::PolicyKeyFeature::create(str); - else - return Cynara::PolicyKeyFeature::createWildcard(); - }); + auto feature = ([&wildcard] (const char *str)->Cynara::PolicyKeyFeature { + if (wildcard.compare(str)) + return Cynara::PolicyKeyFeature::create(str); + else + return Cynara::PolicyKeyFeature::createWildcard(); + }); - return Cynara::PolicyKey(feature(policy->client), feature(policy->user), - feature(policy->privilege)); - }); + return Cynara::PolicyKey(feature(policy->client), feature(policy->user), + feature(policy->privilege)); + }); - try { for (auto i = policies; *i; i++) { const cynara_admin_policy *policy = *i; if(!policy->bucket || !policy->client || !policy->user || !policy->privilege) @@ -133,11 +132,9 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, return CYNARA_API_INVALID_PARAM; } } - } catch (const std::bad_alloc &ex) { - return CYNARA_API_OUT_OF_MEMORY; - } - return p_cynara_admin->impl->setPolicies(insertOrUpdate, remove); + return p_cynara_admin->impl->setPolicies(insertOrUpdate, remove); + }); } CYNARA_API @@ -148,31 +145,29 @@ int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *buc if (!bucket) return CYNARA_API_INVALID_PARAM; - std::string extraStr; - try { - extraStr = extra ? extra : ""; - } catch (const std::bad_alloc &ex) { - return CYNARA_API_OUT_OF_MEMORY; - } - switch (operation) { - case CYNARA_ADMIN_DELETE: - return p_cynara_admin->impl->removeBucket(bucket); - case CYNARA_ADMIN_DENY: - return p_cynara_admin->impl->insertOrUpdateBucket(bucket, - Cynara::PolicyResult(Cynara::PredefinedPolicyType::DENY, extraStr)); - case CYNARA_ADMIN_ALLOW: - return p_cynara_admin->impl->insertOrUpdateBucket(bucket, - Cynara::PolicyResult(Cynara::PredefinedPolicyType::ALLOW, extraStr)); - case CYNARA_ADMIN_NONE: - if (bucket != Cynara::defaultPolicyBucketId) { + return Cynara::tryCatch([&]() { + std::string extraStr = extra ? extra : ""; + + switch (operation) { + case CYNARA_ADMIN_DELETE: + return p_cynara_admin->impl->removeBucket(bucket); + case CYNARA_ADMIN_DENY: return p_cynara_admin->impl->insertOrUpdateBucket(bucket, - Cynara::PolicyResult(Cynara::PredefinedPolicyType::NONE)); - } - return CYNARA_API_OPERATION_NOT_ALLOWED; - case CYNARA_ADMIN_BUCKET: - default: - return CYNARA_API_INVALID_PARAM; - } + Cynara::PolicyResult(Cynara::PredefinedPolicyType::DENY, extraStr)); + case CYNARA_ADMIN_ALLOW: + return p_cynara_admin->impl->insertOrUpdateBucket(bucket, + Cynara::PolicyResult(Cynara::PredefinedPolicyType::ALLOW, extraStr)); + case CYNARA_ADMIN_NONE: + if (bucket != Cynara::defaultPolicyBucketId) { + return p_cynara_admin->impl->insertOrUpdateBucket(bucket, + Cynara::PolicyResult(Cynara::PredefinedPolicyType::NONE)); + } + return CYNARA_API_OPERATION_NOT_ALLOWED; + case CYNARA_ADMIN_BUCKET: + default: + return CYNARA_API_INVALID_PARAM; + } + }); } CYNARA_API @@ -189,28 +184,38 @@ int cynara_admin_check(struct cynara_admin *p_cynara_admin, if (!result || !result_extra) return CYNARA_API_INVALID_PARAM; - Cynara::PolicyResult policyResult; + return Cynara::tryCatch([&]() { + Cynara::PolicyResult policyResult; + Cynara::PolicyBucketId startBucket; + std::string clientStr; + std::string userStr; + std::string privilegeStr; + + try { + startBucket = start_bucket; + clientStr = client; + userStr = user; + privilegeStr = privilege; + } catch (const std::length_error &e) { + LOGE(e.what()); + return CYNARA_API_INVALID_PARAM; + } - try { - int ret = p_cynara_admin->impl->adminCheck(start_bucket, recursive != 0, - Cynara::PolicyKey(client, user, privilege), - policyResult); + int ret = p_cynara_admin->impl->adminCheck(startBucket, recursive != 0, + Cynara::PolicyKey(clientStr, userStr, + privilegeStr), policyResult); if (ret != CYNARA_API_SUCCESS) return ret; - } catch (const std::bad_alloc &ex) { - return CYNARA_API_OUT_OF_MEMORY; - } catch (const std::length_error &ex) { - return CYNARA_API_INVALID_PARAM; - } - char *str = nullptr; - if (!policyResult.metadata().empty()) { - str = strdup(policyResult.metadata().c_str()); - if (!str) - return CYNARA_API_OUT_OF_MEMORY; - } - *result = static_cast(policyResult.policyType()); - *result_extra = str; + char *str = nullptr; + if (!policyResult.metadata().empty()) { + str = strdup(policyResult.metadata().c_str()); + if (!str) + return CYNARA_API_OUT_OF_MEMORY; + } + *result = static_cast(policyResult.policyType()); + *result_extra = str; - return CYNARA_API_SUCCESS; + return CYNARA_API_SUCCESS; + }); } diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp index 683a2cf..72c40bf 100644 --- a/src/admin/logic/Logic.cpp +++ b/src/admin/logic/Logic.cpp @@ -62,53 +62,45 @@ bool Logic::ensureConnection(void) { template int Logic::askCynaraAndInterpreteCodeResponse(Args... args) { - try { - if (!ensureConnection()) { - LOGE("Cannot connect to cynara. Service not available."); - return CYNARA_API_SERVICE_NOT_AVAILABLE; - } + if (!ensureConnection()) { + LOGE("Cannot connect to cynara. Service not available."); + return CYNARA_API_SERVICE_NOT_AVAILABLE; + } - ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); + ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); - //Ask cynara service - CodeResponsePtr codeResponse; + //Ask cynara service + CodeResponsePtr codeResponse; - RequestPtr request = std::make_shared(args..., sequenceNumber); - ResponsePtr response; - while (!(response = m_socketClient->askCynaraServer(request))) { - if (!m_socketClient->connect()) - return CYNARA_API_SERVICE_NOT_AVAILABLE; - } + RequestPtr request = std::make_shared(args..., sequenceNumber); + ResponsePtr response; + while (!(response = m_socketClient->askCynaraServer(request))) { + if (!m_socketClient->connect()) + return CYNARA_API_SERVICE_NOT_AVAILABLE; + } - codeResponse = std::dynamic_pointer_cast(response); - if (!codeResponse) { - LOGC("Critical error. Casting Response to CodeResponse failed."); - return CYNARA_API_UNKNOWN_ERROR; - } - - LOGD("codeResponse: code [%" PRIu16 "]", codeResponse->m_code); - switch (codeResponse->m_code) { - case CodeResponse::Code::OK: - LOGI("Policies set successfully."); - return CYNARA_API_SUCCESS; - case CodeResponse::Code::NOT_ALLOWED: - LOGE("Cynara service answered: Operation not allowed."); - return CYNARA_API_OPERATION_NOT_ALLOWED; - case CodeResponse::Code::NO_BUCKET: - LOGE("Trying to use unexisting bucket."); - return CYNARA_API_BUCKET_NOT_FOUND; - default: - LOGE("Unexpected response code from server: [%d]", - static_cast(codeResponse->m_code)); - return CYNARA_API_UNKNOWN_ERROR; - } - } catch (const std::bad_alloc &ex) { - LOGE("Cynara admin client out of memory."); - return CYNARA_API_OUT_OF_MEMORY; - } catch (const std::exception &ex) { - LOGE("Unexpected client error: <%s>", ex.what()); + codeResponse = std::dynamic_pointer_cast(response); + if (!codeResponse) { + LOGC("Critical error. Casting Response to CodeResponse failed."); return CYNARA_API_UNKNOWN_ERROR; } + + LOGD("codeResponse: code [%" PRIu16 "]", codeResponse->m_code); + switch (codeResponse->m_code) { + case CodeResponse::Code::OK: + LOGI("Policies set successfully."); + return CYNARA_API_SUCCESS; + case CodeResponse::Code::NOT_ALLOWED: + LOGE("Cynara service answered: Operation not allowed."); + return CYNARA_API_OPERATION_NOT_ALLOWED; + case CodeResponse::Code::NO_BUCKET: + LOGE("Trying to use unexisting bucket."); + return CYNARA_API_BUCKET_NOT_FOUND; + default: + LOGE("Unexpected response code from server: [%d]", + static_cast(codeResponse->m_code)); + return CYNARA_API_UNKNOWN_ERROR; + } } int Logic::setPolicies(const std::map> &insertOrUpdate, @@ -127,47 +119,36 @@ int Logic::removeBucket(const PolicyBucketId &bucket) { int Logic::adminCheck(const PolicyBucketId &startBucket, bool recursive, const PolicyKey &key, PolicyResult &result) { - try { - if (!ensureConnection()) { - LOGE("Cannot connect to cynara. Service not available."); - return CYNARA_API_SERVICE_NOT_AVAILABLE; - } - - ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); + if (!ensureConnection()) { + LOGE("Cannot connect to cynara. Service not available."); + return CYNARA_API_SERVICE_NOT_AVAILABLE; + } - //Ask cynara service - CheckResponsePtr checkResponse; + ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); - RequestPtr request = std::make_shared(key, startBucket, recursive, - sequenceNumber); - ResponsePtr response; - while (!(response = m_socketClient->askCynaraServer(request))) { - if (!m_socketClient->connect()) - return CYNARA_API_SERVICE_NOT_AVAILABLE; - } + //Ask cynara service + CheckResponsePtr checkResponse; - checkResponse = std::dynamic_pointer_cast(response); - if (!checkResponse) { - LOGC("Casting Response to CheckResponse failed."); - return CYNARA_API_UNKNOWN_ERROR; - } - - LOGD("checkResponse: policyType [%" PRIu16 "], metadata <%s>", - checkResponse->m_resultRef.policyType(), - checkResponse->m_resultRef.metadata().c_str()); + RequestPtr request = std::make_shared(key, startBucket, recursive, + sequenceNumber); + ResponsePtr response; + while (!(response = m_socketClient->askCynaraServer(request))) { + if (!m_socketClient->connect()) + return CYNARA_API_SERVICE_NOT_AVAILABLE; + } - result = checkResponse->m_resultRef; - return CYNARA_API_SUCCESS; - } catch (const UnexpectedErrorException &ex) { - LOGE(ex.what()); - return CYNARA_API_UNKNOWN_ERROR; - } catch (const std::bad_alloc &ex) { - LOGE("Cynara admin client out of memory."); - return CYNARA_API_OUT_OF_MEMORY; - } catch (const std::exception &ex) { - LOGE("Unexpected client error: <%s>", ex.what()); + checkResponse = std::dynamic_pointer_cast(response); + if (!checkResponse) { + LOGC("Casting Response to CheckResponse failed."); return CYNARA_API_UNKNOWN_ERROR; } + + LOGD("checkResponse: policyType [%" PRIu16 "], metadata <%s>", + checkResponse->m_resultRef.policyType(), + checkResponse->m_resultRef.metadata().c_str()); + + result = checkResponse->m_resultRef; + return CYNARA_API_SUCCESS; } } // namespace Cynara -- 2.7.4 From b140c8834b3a514aa6abe0b320bd3e51042a84d5 Mon Sep 17 00:00:00 2001 From: Jacek Bukarewicz Date: Wed, 15 Oct 2014 10:21:00 +0200 Subject: [PATCH 11/16] Set build_type default value in a different way Apparently gbs couldn't parse previous construct properly and installed debug libraries regardless of build_type. Change-Id: I84c6456efc692da9f1bec94b071d8107a540f3d8 Signed-off-by: Jacek Bukarewicz --- packaging/cynara.spec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packaging/cynara.spec b/packaging/cynara.spec index e8d0bc8..7f02901 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -33,7 +33,9 @@ BuildRequires: pkgconfig(libsystemd-journal) %global state_path %{_localstatedir}/%{name}/ %global tests_dir %{_datarootdir}/%{name}/tests -%global build_type %{?build_type:%build_type}%{!?build_type:RELEASE} +%if !%{defined build_type} +%define build_type RELEASE +%endif %if %{?build_type} == "DEBUG" -- 2.7.4 From 38d286c8f23ddf8c18100aca5ebd9e776099d70b Mon Sep 17 00:00:00 2001 From: Marcin Niesluchowski Date: Tue, 14 Oct 2014 13:36:08 +0200 Subject: [PATCH 12/16] Fix comment in cynara-async api header Change-Id: Id195797893866f5aca48b1120c04e2d2ebb69813 --- src/include/cynara-client-async.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/cynara-client-async.h b/src/include/cynara-client-async.h index 20f5ea4..9bed89d 100644 --- a/src/include/cynara-client-async.h +++ b/src/include/cynara-client-async.h @@ -86,7 +86,7 @@ typedef enum { * - probably cynara is unoperational (CYNARA_CALL_CAUSE_SERVICE_NOT_AVAILABLE) * * \param[in] check_id Number identifying check request. Number is generated in - * cynara_async_cancel_request() and returned to user. It can be used to match + * cynara_async_create_request() and returned to user. It can be used to match * response with sent request. * Number is valid since cynara_async_create_request() call till callback call. * After that the number can be reused by cynara to run new request. -- 2.7.4 From 8e4e754b026f3d5b99b99b95ec72ade4e426b740 Mon Sep 17 00:00:00 2001 From: Aleksander Zdyb Date: Tue, 14 Oct 2014 09:59:49 +0200 Subject: [PATCH 13/16] Fix creation of bucket in InMemoryStorageBackend This prevents creation of bucket without properly initialized id. Change-Id: Ib5374e15a0172e48ca5413987df256f19595fe91 --- src/storage/InMemoryStorageBackend.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/storage/InMemoryStorageBackend.cpp b/src/storage/InMemoryStorageBackend.cpp index 7365294..ae9c624 100644 --- a/src/storage/InMemoryStorageBackend.cpp +++ b/src/storage/InMemoryStorageBackend.cpp @@ -122,8 +122,7 @@ void InMemoryStorageBackend::insertPolicy(const PolicyBucketId &bucketId, Policy void InMemoryStorageBackend::createBucket(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy) { - PolicyBucket newBucket; - newBucket.setDefaultPolicy(defaultPolicy); + PolicyBucket newBucket(bucketId, defaultPolicy); buckets().insert({ bucketId, newBucket }); } -- 2.7.4 From 3eb098c59208727fddc20db56f38ef21161e310e Mon Sep 17 00:00:00 2001 From: Pawel Wieczorek Date: Wed, 24 Sep 2014 12:11:12 +0200 Subject: [PATCH 14/16] Add new libcynara-admin return code Added code is: CYNARA_ADMIN_API_OPERATION_FAILED It is used to indicate failures during saving database to storage. This patch also adds handling such situations. Change-Id: I35b7d3334def8e688a180ddec6861c0f3bdd70d6 --- src/admin/logic/Logic.cpp | 3 +++ src/common/response/CodeResponse.h | 3 ++- src/include/cynara-error.h | 7 +++++-- src/service/logic/Logic.cpp | 7 +++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp index 72c40bf..0deccb9 100644 --- a/src/admin/logic/Logic.cpp +++ b/src/admin/logic/Logic.cpp @@ -96,6 +96,9 @@ int Logic::askCynaraAndInterpreteCodeResponse(Args... args) { case CodeResponse::Code::NO_BUCKET: LOGE("Trying to use unexisting bucket."); return CYNARA_API_BUCKET_NOT_FOUND; + case CodeResponse::Code::FAILED: + LOGC("Cynara service answered: Operation failed."); + return CYNARA_API_OPERATION_FAILED; default: LOGE("Unexpected response code from server: [%d]", static_cast(codeResponse->m_code)); diff --git a/src/common/response/CodeResponse.h b/src/common/response/CodeResponse.h index 8544310..7a6020f 100644 --- a/src/common/response/CodeResponse.h +++ b/src/common/response/CodeResponse.h @@ -34,7 +34,8 @@ public: enum Code { OK, NO_BUCKET, - NOT_ALLOWED + NOT_ALLOWED, + FAILED }; const Code m_code; diff --git a/src/include/cynara-error.h b/src/include/cynara-error.h index e8900b8..728fc2a 100644 --- a/src/include/cynara-error.h +++ b/src/include/cynara-error.h @@ -61,11 +61,14 @@ /*! \brief cynara service does not allow to perform requested operation */ #define CYNARA_API_OPERATION_NOT_ALLOWED -7 +/*! \brief cynara service failed to perform requested operation */ +#define CYNARA_API_OPERATION_FAILED -8 + /*! \brief cynara service hasn't found requested bucket */ -#define CYNARA_API_BUCKET_NOT_FOUND -8 +#define CYNARA_API_BUCKET_NOT_FOUND -9 /*! \brief indicating an unknown error */ -#define CYNARA_API_UNKNOWN_ERROR -9 +#define CYNARA_API_UNKNOWN_ERROR -10 /** @}*/ diff --git a/src/service/logic/Logic.cpp b/src/service/logic/Logic.cpp index 1787575..eeed387 100644 --- a/src/service/logic/Logic.cpp +++ b/src/service/logic/Logic.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,8 @@ void Logic::execute(RequestContextPtr context, InsertOrUpdateBucketRequestPtr re try { m_storage->addOrUpdateBucket(request->bucketId(), request->result()); onPoliciesChanged(); + } catch (const DatabaseException &ex) { + code = CodeResponse::Code::FAILED; } catch (const DefaultBucketSetNoneException &ex) { code = CodeResponse::Code::NOT_ALLOWED; } @@ -142,6 +145,8 @@ void Logic::execute(RequestContextPtr context, RemoveBucketRequestPtr request) { try { m_storage->deleteBucket(request->bucketId()); onPoliciesChanged(); + } catch (const DatabaseException &ex) { + code = CodeResponse::Code::FAILED; } catch (const BucketNotExistsException &ex) { code = CodeResponse::Code::NO_BUCKET; } catch (const DefaultBucketDeletionException &ex) { @@ -157,6 +162,8 @@ void Logic::execute(RequestContextPtr context, SetPoliciesRequestPtr request) { m_storage->insertPolicies(request->policiesToBeInsertedOrUpdated()); m_storage->deletePolicies(request->policiesToBeRemoved()); onPoliciesChanged(); + } catch (const DatabaseException &ex) { + code = CodeResponse::Code::FAILED; } catch (const BucketNotExistsException &ex) { code = CodeResponse::Code::NO_BUCKET; } -- 2.7.4 From a40189b7583c531d3113459c23d62f66b0e7f0da Mon Sep 17 00:00:00 2001 From: Jacek Bukarewicz Date: Wed, 22 Oct 2014 11:06:04 +0200 Subject: [PATCH 15/16] Remove unnecessary dependencies to Cynara Change-Id: I02c00332c20083639b862231b507545103613051 --- packaging/cynara.spec | 3 --- 1 file changed, 3 deletions(-) diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 7f02901..8212f7e 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -85,7 +85,6 @@ asynchronous client library (devel) for checking policies ####################################################### %package -n libcynara-client-commons Summary: Cynara - client commons library -Requires: cynara = %{version}-%{release} %description -n libcynara-client-commons client commons library with common functionalities @@ -116,7 +115,6 @@ admin client library (devel) for setting, listing and removing policies ####################################################### %package -n libcynara-storage Summary: Cynara - storage -Requires: cynara = %{version}-%{release} %description -n libcynara-storage cynara common storage library with common storage functionalities @@ -131,7 +129,6 @@ cynara common storage library (devel) with common storage functionalities ####################################################### %package -n libcynara-commons Summary: Cynara - cynara commons library -Requires: cynara = %{version}-%{release} %description -n libcynara-commons cynara common library with common functionalities -- 2.7.4 From eafad37f12ed0f7f89683730b054ba523d7f8d91 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Tue, 23 Sep 2014 17:50:27 +0200 Subject: [PATCH 16/16] Adjust admin API policy type codes External admin API policy types should match inner cynara values used in storage and protocols. That would make plugins work easier and allows correct work of cynara_admin_check function. New header cynara-policy-types.h is provided by libcynara-common. It defines policy type values and is included by external admin API. Predefined policies variables use same values for initialization. Change-Id: If1b158dcd5abbe9ee3af692e706a2d2e886f8631 --- packaging/cynara.spec | 1 + src/common/CMakeLists.txt | 4 ++++ src/common/types/PolicyType.h | 10 ++++---- src/include/CMakeLists.txt | 1 + src/include/cynara-admin-types.h | 23 ------------------ src/include/cynara-admin.h | 1 + src/include/cynara-offline-admin.h | 1 + src/include/cynara-policy-types.h | 49 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 src/include/cynara-policy-types.h diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 8212f7e..4d067c3 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -458,6 +458,7 @@ fi %{_libdir}/libcynara-commons.so.* %files -n libcynara-commons-devel +%{_includedir}/cynara/cynara-policy-types.h %{_includedir}/cynara/types/PolicyResult.h %{_includedir}/cynara/types/PolicyType.h %{_libdir}/libcynara-commons.so diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 77c7d56..6cd0005 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -21,6 +21,10 @@ SET(CYNARA_COMMON_VERSION ${CYNARA_COMMON_VERSION_MAJOR}.3.0) SET(COMMON_PATH ${CYNARA_PATH}/common) +INCLUDE_DIRECTORIES( + ${CYNARA_PATH}/include + ) + SET(COMMON_SOURCES ${COMMON_PATH}/containers/BinaryQueue.cpp ${COMMON_PATH}/log/log.cpp diff --git a/src/common/types/PolicyType.h b/src/common/types/PolicyType.h index 5bef612..36c84e6 100644 --- a/src/common/types/PolicyType.h +++ b/src/common/types/PolicyType.h @@ -27,15 +27,17 @@ #include #include +#include + namespace Cynara { typedef std::uint16_t PolicyType; namespace PredefinedPolicyType { - const PolicyType DENY = 0; - const PolicyType NONE = 1; - const PolicyType BUCKET = 0xFFFE; - const PolicyType ALLOW = 0xFFFF; + const PolicyType DENY = CYNARA_ADMIN_DENY; + const PolicyType NONE = CYNARA_ADMIN_NONE; + const PolicyType BUCKET = CYNARA_ADMIN_BUCKET; + const PolicyType ALLOW = CYNARA_ADMIN_ALLOW; }; class PolicyResult; diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index 245962d..1d672a8 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -26,6 +26,7 @@ INSTALL(FILES ${CYNARA_PATH}/include/cynara-creds-socket.h ${CYNARA_PATH}/include/cynara-error.h ${CYNARA_PATH}/include/cynara-plugin.h + ${CYNARA_PATH}/include/cynara-policy-types.h ${CYNARA_PATH}/include/cynara-session.h DESTINATION ${INCLUDE_INSTALL_DIR}/cynara ) diff --git a/src/include/cynara-admin-types.h b/src/include/cynara-admin-types.h index 073881a..8dd3c66 100644 --- a/src/include/cynara-admin-types.h +++ b/src/include/cynara-admin-types.h @@ -63,29 +63,6 @@ struct cynara_admin_policy { */ #define CYNARA_ADMIN_DEFAULT_BUCKET "" -/** - * \name Operation Codes - * operation codes that define action type to be taken in below defined functions - * they are used mostly to define policy result - * @{ - */ - -/*! \brief a policy or bucket should be removed */ -#define CYNARA_ADMIN_DELETE -1 - -/*! \brief set policy result or bucket's default policy to DENY */ -#define CYNARA_ADMIN_DENY 0 - -/*! \brief set bucket's default policy to NONE */ -#define CYNARA_ADMIN_NONE 1 - -/*! \brief set policy result or bucket's default policy to ALLOW */ -#define CYNARA_ADMIN_ALLOW 2 - -/*! \brief set policy to point into another bucket */ -#define CYNARA_ADMIN_BUCKET 3 -/** @}*/ - #ifdef __cplusplus } #endif diff --git a/src/include/cynara-admin.h b/src/include/cynara-admin.h index 0e92b18..cd51465 100644 --- a/src/include/cynara-admin.h +++ b/src/include/cynara-admin.h @@ -25,6 +25,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/include/cynara-offline-admin.h b/src/include/cynara-offline-admin.h index dbecc78..ce711f7 100644 --- a/src/include/cynara-offline-admin.h +++ b/src/include/cynara-offline-admin.h @@ -27,6 +27,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/include/cynara-policy-types.h b/src/include/cynara-policy-types.h new file mode 100644 index 0000000..398c267 --- /dev/null +++ b/src/include/cynara-policy-types.h @@ -0,0 +1,49 @@ +/* + * 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 src/include/cynara-policy-types.h + * \author Lukasz Wojciechowski + * \version 1.0 + * \brief This file contains policy types / operations definitions. + */ + +#ifndef CYNARA_POLICY_TYPES_H +#define CYNARA_POLICY_TYPES_H + +/** + * \name Operation Codes + * operation codes that define action type to be taken in below defined functions + * they are used mostly to define policy result + * @{ + */ + +/*! \brief a policy or bucket should be removed */ +#define CYNARA_ADMIN_DELETE -1 + +/*! \brief set policy result or bucket's default policy to DENY */ +#define CYNARA_ADMIN_DENY 0 + +/*! \brief set bucket's default policy to NONE */ +#define CYNARA_ADMIN_NONE 1 + +/*! \brief set policy to point into another bucket */ +#define CYNARA_ADMIN_BUCKET 0xFFFE + +/*! \brief set policy result or bucket's default policy to ALLOW */ +#define CYNARA_ADMIN_ALLOW 0xFFFF +/** @}*/ + +#endif /* CYNARA_POLICY_TYPES_H */ -- 2.7.4