From afb766d37eaed3409323efe82e957f99455bfb02 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Fri, 1 Aug 2014 15:20:52 +0200 Subject: [PATCH 01/16] Merge cynara and cynara-tests spec files Change-Id: I254584d5ef8a5e546be8bec4eb9e9629199306bc --- CMakeLists.txt | 2 ++ .../cynara-tests.manifest | 0 packaging/cynara.spec | 18 ++++++++++- packaging_tests/cynara-tests.spec | 31 ------------------- test/CMakeLists.txt | 36 +++------------------- 5 files changed, 24 insertions(+), 63 deletions(-) rename {packaging_tests => packaging}/cynara-tests.manifest (100%) delete mode 100644 packaging_tests/cynara-tests.spec diff --git a/CMakeLists.txt b/CMakeLists.txt index 85bcfdb..354d39b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,9 @@ SET(TARGET_CYNARA "cynara") SET(TARGET_LIB_CYNARA "cynara-client") SET(TARGET_LIB_CYNARA_ADMIN "cynara-admin") SET(TARGET_CYNARA_COMMON "cynara-commons") +SET(TARGET_CYNARA_TESTS "cynara-tests") ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(build) ADD_SUBDIRECTORY(systemd) diff --git a/packaging_tests/cynara-tests.manifest b/packaging/cynara-tests.manifest similarity index 100% rename from packaging_tests/cynara-tests.manifest rename to packaging/cynara-tests.manifest diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 8d9c94f..8bb7e14 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -8,6 +8,7 @@ Source0: %{name}-%{version}.tar.gz Source1001: cynara.manifest Source1002: libcynara-client.manifest Source1003: libcynara-admin.manifest +Source1004: cynara-tests.manifest Requires: default-ac-domains BuildRequires: cmake BuildRequires: zip @@ -29,7 +30,8 @@ BuildRequires: pkgconfig(libunwind) %endif %description -service and client libraries (libcynara-client, libcynara-admin) +service, client libraries (libcynara-client, libcynara-admin) +and tests (cynara-tests) ####################################################### %package -n libcynara-client @@ -66,6 +68,15 @@ Requires: libcynara-admin = %{version}-%{release} admin client library (devel) for setting, listing and removing policies ####################################################### +%package -n cynara-tests +Summary: Cynara - cynara test binaries +BuildRequires: pkgconfig(gmock) + +%description -n cynara-tests +Cynara tests + +####################################################### + %package -n cynara-devel Summary: Cynara service (devel) Requires: cynara = %{version}-%{release} @@ -78,6 +89,7 @@ service (devel version) cp -a %{SOURCE1001} . cp -a %{SOURCE1002} . cp -a %{SOURCE1003} . +cp -a %{SOURCE1004} . %build %if 0%{?sec_build_binary_debug_enable} @@ -199,3 +211,7 @@ fi %{_includedir}/cynara/cynara-admin.h %{_libdir}/libcynara-admin.so %{_libdir}/pkgconfig/cynara-admin.pc + +%files -n cynara-tests +%manifest cynara-tests.manifest +%attr(755,root,root) /usr/bin/cynara-tests diff --git a/packaging_tests/cynara-tests.spec b/packaging_tests/cynara-tests.spec deleted file mode 100644 index 8b1de31..0000000 --- a/packaging_tests/cynara-tests.spec +++ /dev/null @@ -1,31 +0,0 @@ -Name: cynara-tests -Summary: Cynara tests -Version: 0.0.1 -Release: 1 -Group: Development/Testing -License: Apache-2.0 -Source0: %{name}-%{version}.tar.gz -Source1001: cynara-tests.manifest -BuildRequires: cmake -BuildRequires: pkgconfig(gmock) - -%description -Cynara tests - -%global build_type %{?build_type:%build_type}%{!?build_type:RELEASE} - -%prep -%setup -q -cp -a %{SOURCE1001} . - -%build -%cmake test -DCMAKE_BUILD_TYPE=%{?build_type} \ - -DCMAKE_VERBOSE_MAKEFILE=ON -make %{?jobs:-j%jobs} - -%install -%make_install - -%files -%manifest cynara-tests.manifest -%attr(755,root,root) /usr/bin/cynara-tests diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b391a4c..820279f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,47 +16,21 @@ # @author Aleksander Zdyb # @brief Cmake for tests # - -############################# Check minimum CMake version ##################### - -CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3) -PROJECT("cynara-tests") - -############################# cmake packages ################################## - -INCLUDE(FindPkgConfig) - -############################# compiler flags ################################## - -SET(CMAKE_C_FLAGS_DEBUG "-g -O0 -ggdb") -SET(CMAKE_CXX_FLAGS_DEBUG "-g -std=c++0x -O0 -ggdb -Wp,-U_FORTIFY_SOURCE") -SET(CMAKE_C_FLAGS_RELEASE "-g -O2") -SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++0x -O2") - -# Set compiler warning flags -ADD_DEFINITIONS("-Werror") # Make all warnings into errors. -ADD_DEFINITIONS("-Wall") # Generate all warnings -ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings -ADD_DEFINITIONS("-DCYNARA_NO_LOGS") # Disable building logs - -MESSAGE(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") - -SET(TARGET_CYNARA_TESTS "cynara-tests") - PKG_CHECK_MODULES(PKGS REQUIRED gmock_main) -SET(CYNARA_SRC ${PROJECT_SOURCE_DIR}/../src) +ADD_DEFINITIONS("-DCYNARA_NO_LOGS") +SET(CYNARA_SRC ${PROJECT_SOURCE_DIR}/src) SET(CYNARA_SOURCES_FOR_TESTS - ${CYNARA_SRC}/service/storage/Storage.cpp ${CYNARA_SRC}/common/types/PolicyBucket.cpp + ${CYNARA_SRC}/common/types/PolicyKey.cpp ${CYNARA_SRC}/common/types/PolicyKeyHelpers.cpp + ${CYNARA_SRC}/common/types/PolicyType.cpp + ${CYNARA_SRC}/service/storage/Storage.cpp ${CYNARA_SRC}/service/storage/InMemoryStorageBackend.cpp ${CYNARA_SRC}/service/storage/BucketDeserializer.cpp ${CYNARA_SRC}/service/storage/StorageDeserializer.cpp ${CYNARA_SRC}/service/storage/StorageSerializer.cpp - ${CYNARA_SRC}/common/types/PolicyKey.cpp - ${CYNARA_SRC}/common/types/PolicyType.cpp ) SET(CYNARA_TESTS_SOURCES -- 2.7.4 From f801eff5a438cb0267aeea84b330037c47144ccc Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Fri, 8 Aug 2014 14:16:54 +0200 Subject: [PATCH 02/16] Release version 0.2.2 Change-Id: I33c53395cb9af581dd1c1ed3ac37c36b4f874435 --- packaging/cynara.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 8bb7e14..5524b9d 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -1,6 +1,6 @@ Name: cynara Summary: Cynara service with client libraries -Version: 0.2.1 +Version: 0.2.2 Release: 1 Group: Security/Access Control License: Apache-2.0 -- 2.7.4 From c1e566ededb9aa086d2c6ab011519fb1df88ee0a Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Fri, 8 Aug 2014 14:22:29 +0200 Subject: [PATCH 03/16] Change Cache to be based on std::unordered_map Change-Id: Iaadc74c426d9d6e7851a55b69556463b53aa31e6 --- src/client/cache/CapacityCache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/cache/CapacityCache.h b/src/client/cache/CapacityCache.h index 39ca928..12101db 100644 --- a/src/client/cache/CapacityCache.h +++ b/src/client/cache/CapacityCache.h @@ -24,7 +24,7 @@ #define SRC_CLIENT_CACHE_CAPACITYCACHE_H_ #include -#include +#include #include @@ -44,7 +44,7 @@ public: private: typedef std::list KeyUsageList; - typedef std::map> KeyValueMap; -- 2.7.4 From ab73c19c44d7f4e6f4a25ba1243ce08af11c84c0 Mon Sep 17 00:00:00 2001 From: Marcin Niesluchowski Date: Thu, 31 Jul 2014 17:55:36 +0200 Subject: [PATCH 04/16] Add asynchronous client api Change-Id: I76f4374a96a09f53dd4154a8049c42683fb39bf7 --- CMakeLists.txt | 1 + build/CMakeLists.txt | 1 + build/cynara-client-async/CMakeLists.txt | 25 ++ .../cynara-client-async/cynara-client-async.pc.in | 11 + packaging/cynara.spec | 45 +++- packaging/libcynara-client-async.manifest | 5 + src/CMakeLists.txt | 1 + src/client-async/CMakeLists.txt | 48 ++++ src/client-async/api/ApiInterface.h | 47 ++++ src/client-async/api/client-async-api.cpp | 118 +++++++++ src/client-async/logic/Logic.cpp | 52 ++++ src/client-async/logic/Logic.h | 47 ++++ src/include/CMakeLists.txt | 5 + src/include/cynara-client-async.h | 294 +++++++++++++++++++++ 14 files changed, 697 insertions(+), 3 deletions(-) create mode 100644 build/cynara-client-async/CMakeLists.txt create mode 100644 build/cynara-client-async/cynara-client-async.pc.in create mode 100644 packaging/libcynara-client-async.manifest create mode 100644 src/client-async/CMakeLists.txt create mode 100644 src/client-async/api/ApiInterface.h create mode 100644 src/client-async/api/client-async-api.cpp create mode 100644 src/client-async/logic/Logic.cpp create mode 100644 src/client-async/logic/Logic.h create mode 100644 src/include/cynara-client-async.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 354d39b..eadba21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") SET(TARGET_CYNARA "cynara") SET(TARGET_LIB_CYNARA "cynara-client") +SET(TARGET_LIB_CYNARA_ASYNC "cynara-client-async") SET(TARGET_LIB_CYNARA_ADMIN "cynara-admin") SET(TARGET_CYNARA_COMMON "cynara-commons") SET(TARGET_CYNARA_TESTS "cynara-tests") diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 269b258..ff93082 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -17,4 +17,5 @@ # ADD_SUBDIRECTORY(cynara-client) +ADD_SUBDIRECTORY(cynara-client-async) ADD_SUBDIRECTORY(cynara-admin) diff --git a/build/cynara-client-async/CMakeLists.txt b/build/cynara-client-async/CMakeLists.txt new file mode 100644 index 0000000..c24b331 --- /dev/null +++ b/build/cynara-client-async/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 Marcin Niesluchowski +# + +CONFIGURE_FILE(cynara-client-async.pc.in cynara-client-async.pc @ONLY) + +INSTALL(FILES + ${CMAKE_BINARY_DIR}/build/cynara-client-async/cynara-client-async.pc + DESTINATION + ${LIB_INSTALL_DIR}/pkgconfig + ) diff --git a/build/cynara-client-async/cynara-client-async.pc.in b/build/cynara-client-async/cynara-client-async.pc.in new file mode 100644 index 0000000..c3f1be5 --- /dev/null +++ b/build/cynara-client-async/cynara-client-async.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@LIB_INSTALL_DIR@ +includedir=${prefix}/include + +Name: cynara-client-async +Description: cynara-client-async package +Version: 0.0.1 +Requires: +Libs: -L${libdir} -lcynara-client-async +Cflags: -I${includedir}/cynara diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 5524b9d..a75ed92 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -7,8 +7,9 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1001: cynara.manifest Source1002: libcynara-client.manifest -Source1003: libcynara-admin.manifest -Source1004: cynara-tests.manifest +Source1003: libcynara-client-async.manifest +Source1004: libcynara-admin.manifest +Source1005: cynara-tests.manifest Requires: default-ac-domains BuildRequires: cmake BuildRequires: zip @@ -30,7 +31,7 @@ BuildRequires: pkgconfig(libunwind) %endif %description -service, client libraries (libcynara-client, libcynara-admin) +service and client libraries (libcynara-client, libcynara-client-async, libcynara-admin) and tests (cynara-tests) ####################################################### @@ -51,6 +52,23 @@ Requires: libcynara-client = %{version}-%{release} client library (devel) for checking policies ####################################################### +%package -n libcynara-client-async +Summary: Cynara - asynchronous client library +Requires: cynara = %{version}-%{release} +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description -n libcynara-client-async +asynchronous client library for checking policies + +%package -n libcynara-client-async-devel +Summary: Cynara - asynchronous client library (devel) +Requires: libcynara-client-async = %{version}-%{release} + +%description -n libcynara-client-async-devel +asynchronous client library (devel) for checking policies + +####################################################### %package -n libcynara-admin Summary: Cynara - admin client library Requires: cynara = %{version}-%{release} @@ -90,6 +108,7 @@ cp -a %{SOURCE1001} . cp -a %{SOURCE1002} . cp -a %{SOURCE1003} . cp -a %{SOURCE1004} . +cp -a %{SOURCE1005} . %build %if 0%{?sec_build_binary_debug_enable} @@ -163,6 +182,10 @@ fi %postun -n libcynara-client -p /sbin/ldconfig +%post -n libcynara-client-async -p /sbin/ldconfig + +%postun -n libcynara-client-async -p /sbin/ldconfig + %post -n libcynara-admin -p /sbin/ldconfig %postun -n libcynara-admin -p /sbin/ldconfig @@ -171,6 +194,10 @@ fi %postun -n libcynara-client-devel -p /sbin/ldconfig +%post -n libcynara-client-async-devel -p /sbin/ldconfig + +%postun -n libcynara-client-async-devel -p /sbin/ldconfig + %post -n libcynara-admin-devel -p /sbin/ldconfig %postun -n libcynara-admin-devel -p /sbin/ldconfig @@ -200,6 +227,18 @@ fi %{_libdir}/pkgconfig/cynara-client.pc %{_libdir}/libcynara-client.so +%files -n libcynara-client-async +%manifest libcynara-client-async.manifest +%license LICENSE +%defattr(-,root,root,-) +%{_libdir}/libcynara-client-async.so.* + +%files -n libcynara-client-async-devel +%defattr(-,root,root,-) +%{_includedir}/cynara/cynara-client-async.h +%{_libdir}/pkgconfig/cynara-client-async.pc +%{_libdir}/libcynara-client-async.so + %files -n libcynara-admin %manifest libcynara-admin.manifest %license LICENSE diff --git a/packaging/libcynara-client-async.manifest b/packaging/libcynara-client-async.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/libcynara-client-async.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 852e0a5..385e440 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,5 +47,6 @@ INCLUDE_DIRECTORIES( ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(client) +ADD_SUBDIRECTORY(client-async) ADD_SUBDIRECTORY(admin) ADD_SUBDIRECTORY(service) diff --git a/src/client-async/CMakeLists.txt b/src/client-async/CMakeLists.txt new file mode 100644 index 0000000..98f5ad6 --- /dev/null +++ b/src/client-async/CMakeLists.txt @@ -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 CMakeLists.txt +# @author Marcin Niesluchowski +# + +SET(LIB_CYNARA_ASYNC_VERSION_MAJOR 0) +SET(LIB_CYNARA_ASYNC_VERSION ${LIB_CYNARA_ASYNC_VERSION_MAJOR}.0.2) + +SET(CYNARA_LIB_CYNARA_ASYNC_PATH ${CYNARA_PATH}/client-async) + +SET(LIB_CYNARA_ASYNC_SOURCES + ${CYNARA_LIB_CYNARA_ASYNC_PATH}/api/client-async-api.cpp + ${CYNARA_LIB_CYNARA_ASYNC_PATH}/logic/Logic.cpp + ) + +INCLUDE_DIRECTORIES( + ${CYNARA_LIB_CYNARA_ASYNC_PATH} + ) + +ADD_LIBRARY(${TARGET_LIB_CYNARA_ASYNC} SHARED ${LIB_CYNARA_ASYNC_SOURCES}) + +SET_TARGET_PROPERTIES( + ${TARGET_LIB_CYNARA_ASYNC} + PROPERTIES + COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=hidden" + SOVERSION ${LIB_CYNARA_ASYNC_VERSION_MAJOR} + VERSION ${LIB_CYNARA_ASYNC_VERSION} + ) + +TARGET_LINK_LIBRARIES(${TARGET_LIB_CYNARA_ASYNC} + ${CYNARA_DEP_LIBRARIES} + ${TARGET_CYNARA_COMMON} + ) + +INSTALL(TARGETS ${TARGET_LIB_CYNARA_ASYNC} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/client-async/api/ApiInterface.h b/src/client-async/api/ApiInterface.h new file mode 100644 index 0000000..216713a --- /dev/null +++ b/src/client-async/api/ApiInterface.h @@ -0,0 +1,47 @@ +/* + * 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 ApiInterface.h + * @author Marcin Niesluchowski + * @version 1.0 + * @brief This file contains libcynara-client-async API interface definition. + */ + +#ifndef SRC_CLIENT_ASYNC_API_APIINTERFACE_H_ +#define SRC_CLIENT_ASYNC_API_APIINTERFACE_H_ + +#include + +#include + +namespace Cynara { + +class ApiInterface { +public: + ApiInterface() = default; + virtual ~ApiInterface() {}; + + virtual int connect(int &sockFd) = 0; + virtual int check(const std::string &client, const std::string &session, + const std::string &user, const std::string &privilege, + cynara_check_id &checkId) = 0; + virtual int receive(cynara_check_id &checkId) = 0; + virtual int cancel(const cynara_check_id checkId) = 0; +}; + +} // namespace Cynara + +#endif /* SRC_CLIENT_ASYNC_API_APIINTERFACE_H_ */ diff --git a/src/client-async/api/client-async-api.cpp b/src/client-async/api/client-async-api.cpp new file mode 100644 index 0000000..34111f6 --- /dev/null +++ b/src/client-async/api/client-async-api.cpp @@ -0,0 +1,118 @@ +/* + * 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 client-async-api.cpp + * @author Marcin Niesluchowski + * @version 1.0 + * @brief Implementation of external libcynara-client-async API + */ + +#include + +#include +#include + +#include +#include +#include + +struct cynara_async { + Cynara::ApiInterface *impl; + + cynara_async(Cynara::ApiInterface *_impl) : impl(_impl) { + } + + ~cynara_async() { + delete impl; + } +}; + +CYNARA_API +int cynara_async_initialize(cynara_async **pp_cynara, + const cynara_async_configuration *p_conf UNUSED) +{ + if (!pp_cynara) + return CYNARA_ASYNC_API_INVALID_PARAM; + + try { + *pp_cynara = new cynara_async(new Cynara::Logic); + } catch (const std::bad_alloc &ex) { + return CYNARA_ASYNC_API_OUT_OF_MEMORY; + } + + init_log(); + + LOGD("Cynara client async initialized"); + + return CYNARA_ASYNC_API_SUCCESS; +} + +CYNARA_API +int cynara_async_finish(cynara_async *p_cynara) +{ + delete p_cynara; + + return CYNARA_ASYNC_API_SUCCESS; +} + +CYNARA_API +int cynara_async_connect(cynara_async *p_cynara, int *p_sock_fd) +{ + if (!p_cynara || !p_cynara->impl) + return CYNARA_ASYNC_API_INVALID_PARAM; + if (!p_sock_fd) + return CYNARA_ASYNC_API_INVALID_PARAM; + + return p_cynara->impl->connect(*p_sock_fd); +} + +CYNARA_API +int cynara_async_check(cynara_async *p_cynara, + const char *client, const char *client_session, + const char *user, const char *privilege, + cynara_check_id *p_check_id) +{ + if (!p_cynara || !p_cynara->impl) + return CYNARA_ASYNC_API_INVALID_PARAM; + if (!client || !client_session || !user || !privilege) + return CYNARA_ASYNC_API_INVALID_PARAM; + if (!p_check_id) + return CYNARA_ASYNC_API_INVALID_PARAM; + + return p_cynara->impl->check(client, client_session, + user, privilege, + *p_check_id); +} + +CYNARA_API +int cynara_async_receive(cynara_async *p_cynara, cynara_check_id *p_check_id) +{ + if (!p_cynara || !p_cynara->impl) + return CYNARA_ASYNC_API_INVALID_PARAM; + if (!p_check_id) + return CYNARA_ASYNC_API_INVALID_PARAM; + + return p_cynara->impl->receive(*p_check_id); +} + +CYNARA_API +int cynara_async_cancel(cynara_async *p_cynara, const cynara_check_id check_id) +{ + if (!p_cynara || !p_cynara->impl) + return CYNARA_ASYNC_API_INVALID_PARAM; + + return p_cynara->impl->cancel(check_id); +} diff --git a/src/client-async/logic/Logic.cpp b/src/client-async/logic/Logic.cpp new file mode 100644 index 0000000..c6e7860 --- /dev/null +++ b/src/client-async/logic/Logic.cpp @@ -0,0 +1,52 @@ +/* + * 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 Logic.cpp + * @author Marcin Niesluchowski + * @version 1.0 + * @brief This file contains implementation of Logic class - main + * libcynara-client-async class + */ + +#include + +#include "Logic.h" + +namespace Cynara { + +int Logic::connect(int &sockFd UNUSED) noexcept +{ + return CYNARA_ASYNC_API_SUCCESS; +} + +int Logic::check(const std::string &client UNUSED, const std::string &session UNUSED, + const std::string &user UNUSED, const std::string &privilege UNUSED, + cynara_check_id &checkId UNUSED) noexcept +{ + return CYNARA_ASYNC_API_SUCCESS; +} + +int Logic::receive(cynara_check_id &checkId UNUSED) noexcept +{ + return CYNARA_ASYNC_API_SUCCESS; +} + +int Logic::cancel(const cynara_check_id checkId UNUSED) noexcept +{ + return CYNARA_ASYNC_API_SUCCESS; +} + +} // namespace Cynara diff --git a/src/client-async/logic/Logic.h b/src/client-async/logic/Logic.h new file mode 100644 index 0000000..e63ce68 --- /dev/null +++ b/src/client-async/logic/Logic.h @@ -0,0 +1,47 @@ +/* + * 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 Logic.h + * @author Marcin Niesluchowski + * @version 1.0 + * @brief This file contains declaration of Logic class - main + * libcynara-client-async class + */ + +#ifndef SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_ +#define SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_ + +#include +#include + +namespace Cynara { + +class Logic : public ApiInterface { +public: + Logic() = default; + virtual ~Logic() {}; + + virtual int connect(int &sockFd) noexcept; + virtual int check(const std::string &client, const std::string &session, + const std::string &user, const std::string &privilege, + cynara_check_id &checkId) noexcept; + virtual int receive(cynara_check_id &checkId) noexcept; + virtual int cancel(const cynara_check_id checkId) noexcept; +}; + +} // namespace Cynara + +#endif /* SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_ */ diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index 5d8ed5a..edf2938 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -22,6 +22,11 @@ INSTALL(FILES ) INSTALL(FILES + ${CYNARA_PATH}/include/cynara-client-async.h + DESTINATION ${INCLUDE_INSTALL_DIR}/cynara + ) + +INSTALL(FILES ${CYNARA_PATH}/include/cynara-admin.h DESTINATION ${INCLUDE_INSTALL_DIR}/cynara ) diff --git a/src/include/cynara-client-async.h b/src/include/cynara-client-async.h new file mode 100644 index 0000000..c04d0b5 --- /dev/null +++ b/src/include/cynara-client-async.h @@ -0,0 +1,294 @@ +/* + * 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 cynara-client-async.h + * @author Marcin Niesluchowski + * @version 1.0 + * @brief This file contains asynchronous client APIs of Cynara available + * with libcynara-client-asynchronous. + */ + + +#ifndef CYNARA_CLIENT_ASYNC_H +#define CYNARA_CLIENT_ASYNC_H + +#include + +/** + * \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_ASYNC_API_SUCCESS 0 + +/*! \brief indicating that access that was checked is denied */ +#define CYNARA_ASYNC_API_ACCESS_DENIED -1 + +/*! \brief indicating that answer was not yet received */ +#define CYNARA_ASYNC_API_ANSWER_NOT_READY -2 + +/*! \brief indicating that client is already connected */ +#define CYNARA_ASYNC_API_ALREADY_CONNECTED -3 + +/*! \brief indicating system is running out of memory state */ +#define CYNARA_ASYNC_API_OUT_OF_MEMORY -4 + +/*! \brief indicating the API's parameter is malformed */ +#define CYNARA_ASYNC_API_INVALID_PARAM -5 + +/*! \brief service not available */ +#define CYNARA_ASYNC_API_SERVICE_NOT_AVAILABLE -6 + +/** @}*/ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct cynara_async cynara_async; +typedef struct cynara_async_configuration cynara_async_configuration; +typedef uint16_t cynara_check_id; + +/** + * \par Description: + * Initialize cynara-async-client library with given configuration. + * Create structure used in following API calls. + * + * \par Purpose: + * This API must be used prior to calling cynara_async_connect function. + * + * \par Typical use case: + * Once before a service can call cynara_async_connect. + * + * \par Method of function operation: + * This API initializes inner library structures and in case of success creates + * and returns cynara_async structure. + * + * \par Sync (or) Async: + * This is a synchronous API. + * + * \par Thread-safety: + * This function is NOT thread-safe. If functions from described API are called by multithreaded + * application from different threads, they must be put into protected critical section. + * + * \par Important notes: + * Structure cynara_async created by cynara_async_initialize call should be released + * with cynara_async_finish. + * + * \param[out] pp_cynara Placeholder for created cynara_async structure. + * \param[in] p_conf Configuration for cynara-async-client library. NULL for default parameters. + * + * \return CYNARA_ASYNC_API_SUCCESS on success, or error code on error. + */ + +int cynara_async_initialize(cynara_async **pp_cynara, + const cynara_async_configuration *p_conf); + +/** + * \par Description: + * Release cynara-async-client library and destroy structure created with cynara_async_initialize. + * + * \par Purpose: + * This API should be used to clean up after usage of cynara-async-client library. + * + * \par Typical use case: + * Once after all checks have been answered. + * + * \par Method of function operation: + * This API releases inner library structure and destroys cynara_async structure. All pending + * requests are cancelled. + * + * \par Sync (or) Async: + * This is a synchronous API. + * + * \par Thread-safety: + * This function is NOT thread-safe. If functions from described API are called by multithreaded + * application from different threads, they must be put into protected critical section. + * + * \par Important notes: + * No other call to cynara-async-client library should be made after call to cynara_async_finish. + * + * \param[in] p_cynara cynara_async structure. + * + * \return CYNARA_ASYNC_API_SUCCESS on success, or error code on error. + */ +int cynara_async_finish(cynara_async *p_cynara); + +/** + * \par Description: + * Connect with cynara server. + * + * \par Purpose: + * This API must be used prior to calling cynara_async_check and cynara_async_receive. + * + * \par Typical use case: + * After initiating cynara_async structure and after connection with cynara server has been lost. + * + * \par Method of function operation: + * This API connects to cynara server and provides socket descriptor of this connection. + * + * \par Sync (or) Async: + * This is a synchronous API. + * + * \par Thread-safety: + * This function is NOT thread-safe. If functions from described API are called by multithreaded + * application from different threads, they must be put into protected critical section. + * + * \par Important notes: + * Call to cynara_async_check needs cynara_async structure to be created first by + * cynara_async_initialize. + * + * \param[in] p_cynara cynara_async structure. + * \param[out] p_sock_fd Placeholder for connection socket descriptor. + * + * \return CYNARA_ASYNC_API_SUCCESS on success, CYNARA_ASYNC_API_ALREADY_CONNECTED when client is + * already connected or error code on error. + */ +int cynara_async_connect(cynara_async *p_cynara, int *p_sock_fd); + +/** + * \par Description: + * Check client, user access for given privilege. + * + * \par Purpose: + * This API should be used to check if a user running application identified as client + * has access to a privilege. + * + * \par Typical use case: + * A service wants to ask Cynara daemon, if a client demanding access to some privilege + * has proper rights. Despite the fact that the final response has been received, if there are + * still some pending checks, cynara_async_receive MUST be called after this call until not ready + * answer is returned. If service does not get answer after this sequence, it may get it + * asynchronously by calling cynara_async_receive. + * + * \par Method of function operation: + * Client (a process / application) demanding access to a privilege is running as some user. + * For such triple an access to a privilege is checked by calling cynara. + * Depending on defined policy, an external application may be launched to ask user a question, + * e.g. if [s]he wants to allow client to use a privilege. Additional parameter client_session + * may be used to distinguish between client session (e.g. for allowing access only for this + * particular application launch). If final answer is not returned, id of current check should + * be received. + * + * \par Sync (or) Async: + * This is an asynchronous API. + * + * \par Thread-safety: + * This function is NOT thread-safe. If functions from described API are called by multithreaded + * application from different threads, they must be put into protected critical section. + * + * \par Important notes: + * An external application may be launched to allow user interaction in granting or denying access. + * Call cynara_async_cancel to cancel pending request. Call to cynara_async_check needs + * cynara_async structure to be created first and connected with cynara daemon. To do that call + * cynara_async_initialize and cynara_async_connect. + * + * \param[in] p_cynara cynara_async structure. + * \param[in] client Application or process identifier. + * \param[in] client_session Session of client (connection, launch). + * \param[in] user User running client. + * \param[in] privilege Privilege that is a subject of a check. + * \param[out] p_check_id Placeholder for check id. + * + * \return CYNARA_ASYNC_API_SUCCESS on success (access granted), CYNARA_API_ACCESS_DENIED + * on access denial, CYNARA_ASYNC_API_ANSWER_NOT_READY on asynchronous request sent + * or other error code on error. + */ +int cynara_async_check(cynara_async *p_cynara, + const char *client, const char *client_session, + const char *user, const char *privilege, + cynara_check_id *p_check_id); + +/** + * \par Description: + * Receive answer of cynara_async_check call from cynara daemon. + * + * \par Purpose: + * This API should be used to receive answer on single check not answered by cynara_async_check. + * + * \par Typical use case: + * After calling cynara_async_check, if there are still pending checks, this function MUST be + * called until not ready answer is returned. After that, answer can be received by this call + * if a read event occurs on socket received by cynara_async_connect. It MUST be called then + * the same way as after cynara_async_check. + * + * \par Method of function operation: + * Receives answer sent by cynara daemon in response to cynara_async_check call. + * + * \par Sync (or) Async: + * This is an asynchronous API. + * + * \par Thread-safety: + * This function is NOT thread-safe. If functions from described API are called by multithreaded + * application from different threads, they must be put into protected critical section. + * + * \par Important notes: + * An external application may be launched to allow user interaction in granting or denying access. + * Call cynara_async_cancel to cancel pending request. Call to cynara_async_receive needs + * cynara_async structure to be created first and connected with cynara daemon. To do that call + * cynara_async_initialize and cynara_async_connect. As multiple answers can be available at once, + * cynara_async_receive MUST be called until not ready answer is returned. + * + * \param[in] p_cynara cynara_async structure. + * \param[out] p_check_id Placeholder for check id. + * + * \return CYNARA_ASYNC_API_SUCCESS on success (access granted), CYNARA_API_ACCESS_DENIED + * on access denial, CYNARA_ASYNC_API_ANSWER_NOT_READY on answer not yet fully received + * or other error code on error. + */ +int cynara_async_receive(cynara_async *p_cynara, cynara_check_id *p_check_id); + +/** + * \par Description: + * Cancel check request created by cynara_async_check. + * + * \par Purpose: + * This API should be used to cancel check request created by cynara_async_check. + * + * \par Typical use case: + * A service did not get final answer in cynara_async_check call and answer did not come yet + * due to check hanging on user decision to allow or deny privilege. + * + * \par Method of function operation: + * Cancels check request created by cynara_async_check call. + * + * \par Sync (or) Async: + * This is an asynchronous API. + * + * \par Thread-safety: + * This function is NOT thread-safe. If functions from described API are called by multithreaded + * application from different threads, they must be put into protected critical section. + * + * \par Important notes: + * Call to cynara_async_cancel needs cynara_async structure to be created first and connected + * with cynara daemon. To do that call cynara_async_initialize and cynara_async_connect. + * + * \param[in] p_cynara cynara_async structure. + * \param[in] check_id Check id to be cancelled + * + * \return CYNARA_ASYNC_API_SUCCESS on success or other error code on error. + */ +int cynara_async_cancel(cynara_async *p_cynara, cynara_check_id check_id); + + +#ifdef __cplusplus +} +#endif + +#endif /* CYNARA_CLIENT_ASYNC_H */ -- 2.7.4 From 1b06a8e259d044ae3f6fe0782e754f125eab4e03 Mon Sep 17 00:00:00 2001 From: Jacek Bukarewicz Date: Tue, 12 Aug 2014 11:10:10 +0200 Subject: [PATCH 05/16] Use instead of in async client header cannot be used since cynara-client-async.h is a C header which can be included by C projects like dbus. Change-Id: Ife9f75ff594457d67831b487d85f8034bd556b05 Signed-off-by: Jacek Bukarewicz --- 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 c04d0b5..b7aa35b 100644 --- a/src/include/cynara-client-async.h +++ b/src/include/cynara-client-async.h @@ -25,7 +25,7 @@ #ifndef CYNARA_CLIENT_ASYNC_H #define CYNARA_CLIENT_ASYNC_H -#include +#include /** * \name Return Codes -- 2.7.4 From fbd9ddae22fc3f2c99733016a80d304d24ec47a5 Mon Sep 17 00:00:00 2001 From: Aleksander Zdyb Date: Thu, 14 Aug 2014 07:13:23 +0200 Subject: [PATCH 06/16] Add custom TestEventListener This is needed to show custom properties of test cases (like for example time elapsed in benchmarks). Change-Id: Id54c709125c07ceb4d3b387f76047706361d05b3 --- test/CMakeLists.txt | 4 +- test/TestEventListenerProxy.cpp | 86 +++++++++++++++++++++++++++++++++++++++++ test/TestEventListenerProxy.h | 63 ++++++++++++++++++++++++++++++ test/tests.cpp | 59 ++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 test/TestEventListenerProxy.cpp create mode 100644 test/TestEventListenerProxy.h create mode 100644 test/tests.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 820279f..0f64ab4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,7 +16,7 @@ # @author Aleksander Zdyb # @brief Cmake for tests # -PKG_CHECK_MODULES(PKGS REQUIRED gmock_main) +PKG_CHECK_MODULES(PKGS REQUIRED gmock) ADD_DEFINITIONS("-DCYNARA_NO_LOGS") SET(CYNARA_SRC ${PROJECT_SOURCE_DIR}/src) @@ -49,6 +49,8 @@ SET(CYNARA_TESTS_SOURCES storage/serializer/serialize.cpp common/types/policybucket.cpp helpers.cpp + TestEventListenerProxy.cpp + tests.cpp ) INCLUDE_DIRECTORIES( diff --git a/test/TestEventListenerProxy.cpp b/test/TestEventListenerProxy.cpp new file mode 100644 index 0000000..f00a00a --- /dev/null +++ b/test/TestEventListenerProxy.cpp @@ -0,0 +1,86 @@ +/* + * 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 TestEventListenerProxy.cpp + * @author Aleksander Zdyb + * @version 1.0 + * @brief Proxy for ::testing::TestEventListener + */ + +#include "TestEventListenerProxy.h" + +namespace Cynara { + +TestEventListenerProxy::TestEventListenerProxy(TestEventListener *originalListener) + : m_originalListener(originalListener) {}; + +TestEventListenerProxy::~TestEventListenerProxy() { + delete m_originalListener; +}; + +void TestEventListenerProxy::OnTestProgramStart(const UnitTest &unit_test) { + m_originalListener->OnTestProgramStart(unit_test); +} + +void TestEventListenerProxy::OnTestIterationStart(const UnitTest &unit_test, int iteration) { + m_originalListener->OnTestIterationStart(unit_test, iteration); +} + +void TestEventListenerProxy::OnEnvironmentsSetUpStart(const UnitTest &unit_test) { + m_originalListener->OnEnvironmentsSetUpStart(unit_test); +} + +void TestEventListenerProxy::OnEnvironmentsSetUpEnd(const UnitTest &unit_test) { + m_originalListener->OnEnvironmentsSetUpEnd(unit_test); +} + +void TestEventListenerProxy::OnTestCaseStart(const TestCase &test_case) { + m_originalListener->OnTestCaseStart(test_case); +} + +void TestEventListenerProxy::OnTestStart(const TestInfo &test_info) { + m_originalListener->OnTestStart(test_info); +} + +void TestEventListenerProxy::OnTestPartResult(const TestPartResult &result) { + m_originalListener->OnTestPartResult(result); +} + +void TestEventListenerProxy::OnTestEnd(const TestInfo &test_info) { + m_originalListener->OnTestEnd(test_info); +} + +void TestEventListenerProxy::OnTestCaseEnd(const TestCase &test_case) { + m_originalListener->OnTestCaseEnd(test_case); +} + +void TestEventListenerProxy::OnEnvironmentsTearDownStart(const UnitTest &unit_test) { + m_originalListener->OnEnvironmentsTearDownStart(unit_test); +} + +void TestEventListenerProxy::OnEnvironmentsTearDownEnd(const UnitTest &unit_test) { + m_originalListener->OnEnvironmentsTearDownEnd(unit_test); +} + +void TestEventListenerProxy::OnTestIterationEnd(const UnitTest &unit_test, int iteration) { + m_originalListener->OnTestIterationEnd(unit_test, iteration); +} + +void TestEventListenerProxy::OnTestProgramEnd(const UnitTest &unit_test) { + m_originalListener->OnTestProgramEnd(unit_test); +} + +} /* namespace Cynara */ diff --git a/test/TestEventListenerProxy.h b/test/TestEventListenerProxy.h new file mode 100644 index 0000000..79097ce --- /dev/null +++ b/test/TestEventListenerProxy.h @@ -0,0 +1,63 @@ +/* + * 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 TestEventListenerProxy.h + * @author Aleksander Zdyb + * @version 1.0 + * @brief Proxy for ::testing::TestEventListener + */ + +#ifndef TEST_TESTEVENTLISTENERPROXY_H_ +#define TEST_TESTEVENTLISTENERPROXY_H_ + +#include + +namespace Cynara { + +using namespace testing; + +class TestEventListenerProxy : public TestEventListener +{ +public: + explicit TestEventListenerProxy(TestEventListener *originalListener); + virtual ~TestEventListenerProxy(); + + virtual void OnTestProgramStart(const UnitTest &unit_test); + virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration); + virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test); + virtual void OnEnvironmentsSetUpEnd(const UnitTest &unit_test); + virtual void OnTestCaseStart(const TestCase &test_case); + virtual void OnTestStart(const TestInfo &test_info); + virtual void OnTestPartResult(const TestPartResult &result); + virtual void OnTestEnd(const TestInfo &test_info); + virtual void OnTestCaseEnd(const TestCase &test_case); + virtual void OnEnvironmentsTearDownStart(const UnitTest &unit_test); + virtual void OnEnvironmentsTearDownEnd(const UnitTest &unit_test); + virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration); + virtual void OnTestProgramEnd(const UnitTest &unit_test); + +protected: + TestEventListener *originalListener() { + return m_originalListener; + } + +private: + TestEventListener *m_originalListener; +}; + +} /* namespace Cynara */ + +#endif /* TEST_TESTEVENTLISTENERPROXY_H_ */ diff --git a/test/tests.cpp b/test/tests.cpp new file mode 100644 index 0000000..1525fa9 --- /dev/null +++ b/test/tests.cpp @@ -0,0 +1,59 @@ +/* + * 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 tests.cpp + * @author Aleksander Zdyb + * @version 1.0 + * @brief Unit-tests setup + */ + +#include +#include + +#include "TestEventListenerProxy.h" + +class PropertyAwarePrettyUnitTestResultPrinter : public Cynara::TestEventListenerProxy { + using Cynara::TestEventListenerProxy::TestEventListenerProxy; + + void OnTestEnd(const ::testing::TestInfo &testInfo) { + auto result = testInfo.result(); + for (int i = 0; i < result->test_property_count(); ++i) { + const auto &property = result->GetTestProperty(i); + std::cout << " - " + << property.key() << " = " << property.value() + << std::endl; + } + originalListener()->OnTestEnd(testInfo); + } +}; + +int main(int argc, char** argv) { + // Disables elapsed time by default. + ::testing::GTEST_FLAG(print_time) = false; + + // This allows the user to override the flag on the command line. + ::testing::InitGoogleTest(&argc, argv); + + // Gets hold of the event listener list. + auto& listeners = ::testing::UnitTest::GetInstance()->listeners(); + + // Remove original listener (PrettyUnitTestResultPrinter) + // and wrap it with our proxy (PropertyAwarePrettyUnitTestResultPrinter) + auto originalListener = listeners.Release(listeners.default_result_printer()); + listeners.Append(new PropertyAwarePrettyUnitTestResultPrinter(originalListener)); + + return RUN_ALL_TESTS(); +} -- 2.7.4 From dcb87304c3e74559386d39a303da5bde34fb8754 Mon Sep 17 00:00:00 2001 From: Aleksander Zdyb Date: Mon, 18 Aug 2014 11:40:46 +0200 Subject: [PATCH 07/16] Add performance tests for PolicyBucket Change-Id: I3b7f88a7964552664f0a1d1b1a56916ac0726249 --- test/Benchmark.h | 50 +++++++++++++++++ test/CMakeLists.txt | 1 + test/storage/performance/bucket.cpp | 106 ++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 test/Benchmark.h create mode 100644 test/storage/performance/bucket.cpp diff --git a/test/Benchmark.h b/test/Benchmark.h new file mode 100644 index 0000000..9902236 --- /dev/null +++ b/test/Benchmark.h @@ -0,0 +1,50 @@ +/* + * 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 Benchmark.h + * @author Aleksander Zdyb + * @version 1.0 + * @brief A generic benchmark + */ + +#ifndef TEST_BENCHMARK_H_ +#define TEST_BENCHMARK_H_ + +#include + +namespace Cynara { + +namespace Benchmark { + +typedef std::function Function; + +template +Precision measure(Function fn) { + using std::chrono::high_resolution_clock; + + high_resolution_clock::time_point t0 = high_resolution_clock::now(); + fn(); + high_resolution_clock::time_point t1 = high_resolution_clock::now(); + + return std::chrono::duration_cast(t1 - t0); +} + +} // namespace Benchmark + +} // namespace Cynara + + +#endif /* TEST_BENCHMARK_H_ */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0f64ab4..c3e3eea 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,6 +36,7 @@ SET(CYNARA_SOURCES_FOR_TESTS SET(CYNARA_TESTS_SOURCES common/exceptions/bucketrecordcorrupted.cpp types/policykey.cpp + storage/performance/bucket.cpp storage/storage/policies.cpp storage/storage/check.cpp storage/storage/buckets.cpp diff --git a/test/storage/performance/bucket.cpp b/test/storage/performance/bucket.cpp new file mode 100644 index 0000000..264482f --- /dev/null +++ b/test/storage/performance/bucket.cpp @@ -0,0 +1,106 @@ +/* + * 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 bucket.cpp + * @author Aleksander Zdyb + * @version 1.0 + * @brief Performance tests for Cynara::PolicyBucket + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "../../Benchmark.h" + +using namespace Cynara; + +class Benchmark { +public: + +}; + +class PolicyKeyGenerator { +public: + typedef std::vector Features; + typedef std::reference_wrapper FeaturesRef; + + PolicyKeyGenerator(size_t featuresCount, size_t featureLength) { + const std::vector toGenerate = { m_clients, m_users, m_privileges }; + for (auto featuresRef : toGenerate) { + auto &features = featuresRef.get(); + features.resize(featuresCount); + std::generate(std::begin(features), std::end(features), + std::bind(&PolicyKeyGenerator::randomKeyFeature, this, featureLength)); + } + } + + PolicyKey randomKey(void) const { + return { m_clients.at(rand() % m_clients.size()), + m_users.at(rand() % m_users.size()), + m_privileges.at(rand() % m_privileges.size()) + }; + } + + char randomChar(void) const { + return (std::rand() % ('z' - 'a')) + 'a'; + } + + std::string randomKeyFeature(size_t length) const { + std::string str(length, 0); + std::generate_n( str.begin(), length, std::bind(&PolicyKeyGenerator::randomChar, this)); + return str; + } + +private: + Features m_clients; + Features m_users; + Features m_privileges; +}; + +TEST(Performance, bucket_filtered_100000) { + using std::chrono::microseconds; + + PolicyBucket bucket; + + PolicyKeyGenerator generator(100, 10); + + const std::size_t policyNumber = 100000; + for (std::size_t i = 0; i < policyNumber; ++i) { + bucket.insertPolicy(std::make_shared(generator.randomKey(), + PredefinedPolicyType::ALLOW)); + } + + const unsigned int measureRepeats = 1000; + auto result = Benchmark::measure([&bucket, &generator, measureRepeats] () { + for (auto i = 0u; i < measureRepeats; ++i) { + bucket.filtered(generator.randomKey()); + } + }); + + auto key = std::string("performance_" + std::to_string(policyNumber)); + auto value = std::to_string(result.count() / measureRepeats) + " [us]"; + RecordProperty(key, value); +} -- 2.7.4 From 5a337803a3a351072b68a4b99019bd83afd0816c Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 19 Aug 2014 06:11:55 -0700 Subject: [PATCH 08/16] Revert "Use instead of in async client header" This reverts commit 1b06a8e259d044ae3f6fe0782e754f125eab4e03. Change-Id: Ib9efb3ad1d3961da72af0d39b98dfd4b3771ca6a --- 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 b7aa35b..c04d0b5 100644 --- a/src/include/cynara-client-async.h +++ b/src/include/cynara-client-async.h @@ -25,7 +25,7 @@ #ifndef CYNARA_CLIENT_ASYNC_H #define CYNARA_CLIENT_ASYNC_H -#include +#include /** * \name Return Codes -- 2.7.4 From 08a43c8ac2f509b80d1a003687bd80abec4fbc27 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 19 Aug 2014 06:09:08 -0700 Subject: [PATCH 09/16] Revert "Add asynchronous client api" This reverts commit ab73c19c44d7f4e6f4a25ba1243ce08af11c84c0. Change-Id: I8e231284f65d306488aa487c7297e53f3a580c5d --- CMakeLists.txt | 1 - build/CMakeLists.txt | 1 - build/cynara-client-async/CMakeLists.txt | 25 -- .../cynara-client-async/cynara-client-async.pc.in | 11 - packaging/cynara.spec | 45 +--- packaging/libcynara-client-async.manifest | 5 - src/CMakeLists.txt | 1 - src/client-async/CMakeLists.txt | 48 ---- src/client-async/api/ApiInterface.h | 47 ---- src/client-async/api/client-async-api.cpp | 118 --------- src/client-async/logic/Logic.cpp | 52 ---- src/client-async/logic/Logic.h | 47 ---- src/include/CMakeLists.txt | 5 - src/include/cynara-client-async.h | 294 --------------------- 14 files changed, 3 insertions(+), 697 deletions(-) delete mode 100644 build/cynara-client-async/CMakeLists.txt delete mode 100644 build/cynara-client-async/cynara-client-async.pc.in delete mode 100644 packaging/libcynara-client-async.manifest delete mode 100644 src/client-async/CMakeLists.txt delete mode 100644 src/client-async/api/ApiInterface.h delete mode 100644 src/client-async/api/client-async-api.cpp delete mode 100644 src/client-async/logic/Logic.cpp delete mode 100644 src/client-async/logic/Logic.h delete mode 100644 src/include/cynara-client-async.h diff --git a/CMakeLists.txt b/CMakeLists.txt index eadba21..354d39b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,6 @@ ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") SET(TARGET_CYNARA "cynara") SET(TARGET_LIB_CYNARA "cynara-client") -SET(TARGET_LIB_CYNARA_ASYNC "cynara-client-async") SET(TARGET_LIB_CYNARA_ADMIN "cynara-admin") SET(TARGET_CYNARA_COMMON "cynara-commons") SET(TARGET_CYNARA_TESTS "cynara-tests") diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index ff93082..269b258 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -17,5 +17,4 @@ # ADD_SUBDIRECTORY(cynara-client) -ADD_SUBDIRECTORY(cynara-client-async) ADD_SUBDIRECTORY(cynara-admin) diff --git a/build/cynara-client-async/CMakeLists.txt b/build/cynara-client-async/CMakeLists.txt deleted file mode 100644 index c24b331..0000000 --- a/build/cynara-client-async/CMakeLists.txt +++ /dev/null @@ -1,25 +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 CMakeLists.txt -# @author Marcin Niesluchowski -# - -CONFIGURE_FILE(cynara-client-async.pc.in cynara-client-async.pc @ONLY) - -INSTALL(FILES - ${CMAKE_BINARY_DIR}/build/cynara-client-async/cynara-client-async.pc - DESTINATION - ${LIB_INSTALL_DIR}/pkgconfig - ) diff --git a/build/cynara-client-async/cynara-client-async.pc.in b/build/cynara-client-async/cynara-client-async.pc.in deleted file mode 100644 index c3f1be5..0000000 --- a/build/cynara-client-async/cynara-client-async.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix} -libdir=@LIB_INSTALL_DIR@ -includedir=${prefix}/include - -Name: cynara-client-async -Description: cynara-client-async package -Version: 0.0.1 -Requires: -Libs: -L${libdir} -lcynara-client-async -Cflags: -I${includedir}/cynara diff --git a/packaging/cynara.spec b/packaging/cynara.spec index a75ed92..5524b9d 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -7,9 +7,8 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1001: cynara.manifest Source1002: libcynara-client.manifest -Source1003: libcynara-client-async.manifest -Source1004: libcynara-admin.manifest -Source1005: cynara-tests.manifest +Source1003: libcynara-admin.manifest +Source1004: cynara-tests.manifest Requires: default-ac-domains BuildRequires: cmake BuildRequires: zip @@ -31,7 +30,7 @@ BuildRequires: pkgconfig(libunwind) %endif %description -service and client libraries (libcynara-client, libcynara-client-async, libcynara-admin) +service, client libraries (libcynara-client, libcynara-admin) and tests (cynara-tests) ####################################################### @@ -52,23 +51,6 @@ Requires: libcynara-client = %{version}-%{release} client library (devel) for checking policies ####################################################### -%package -n libcynara-client-async -Summary: Cynara - asynchronous client library -Requires: cynara = %{version}-%{release} -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig - -%description -n libcynara-client-async -asynchronous client library for checking policies - -%package -n libcynara-client-async-devel -Summary: Cynara - asynchronous client library (devel) -Requires: libcynara-client-async = %{version}-%{release} - -%description -n libcynara-client-async-devel -asynchronous client library (devel) for checking policies - -####################################################### %package -n libcynara-admin Summary: Cynara - admin client library Requires: cynara = %{version}-%{release} @@ -108,7 +90,6 @@ cp -a %{SOURCE1001} . cp -a %{SOURCE1002} . cp -a %{SOURCE1003} . cp -a %{SOURCE1004} . -cp -a %{SOURCE1005} . %build %if 0%{?sec_build_binary_debug_enable} @@ -182,10 +163,6 @@ fi %postun -n libcynara-client -p /sbin/ldconfig -%post -n libcynara-client-async -p /sbin/ldconfig - -%postun -n libcynara-client-async -p /sbin/ldconfig - %post -n libcynara-admin -p /sbin/ldconfig %postun -n libcynara-admin -p /sbin/ldconfig @@ -194,10 +171,6 @@ fi %postun -n libcynara-client-devel -p /sbin/ldconfig -%post -n libcynara-client-async-devel -p /sbin/ldconfig - -%postun -n libcynara-client-async-devel -p /sbin/ldconfig - %post -n libcynara-admin-devel -p /sbin/ldconfig %postun -n libcynara-admin-devel -p /sbin/ldconfig @@ -227,18 +200,6 @@ fi %{_libdir}/pkgconfig/cynara-client.pc %{_libdir}/libcynara-client.so -%files -n libcynara-client-async -%manifest libcynara-client-async.manifest -%license LICENSE -%defattr(-,root,root,-) -%{_libdir}/libcynara-client-async.so.* - -%files -n libcynara-client-async-devel -%defattr(-,root,root,-) -%{_includedir}/cynara/cynara-client-async.h -%{_libdir}/pkgconfig/cynara-client-async.pc -%{_libdir}/libcynara-client-async.so - %files -n libcynara-admin %manifest libcynara-admin.manifest %license LICENSE diff --git a/packaging/libcynara-client-async.manifest b/packaging/libcynara-client-async.manifest deleted file mode 100644 index a76fdba..0000000 --- a/packaging/libcynara-client-async.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 385e440..852e0a5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,6 +47,5 @@ INCLUDE_DIRECTORIES( ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(client) -ADD_SUBDIRECTORY(client-async) ADD_SUBDIRECTORY(admin) ADD_SUBDIRECTORY(service) diff --git a/src/client-async/CMakeLists.txt b/src/client-async/CMakeLists.txt deleted file mode 100644 index 98f5ad6..0000000 --- a/src/client-async/CMakeLists.txt +++ /dev/null @@ -1,48 +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 CMakeLists.txt -# @author Marcin Niesluchowski -# - -SET(LIB_CYNARA_ASYNC_VERSION_MAJOR 0) -SET(LIB_CYNARA_ASYNC_VERSION ${LIB_CYNARA_ASYNC_VERSION_MAJOR}.0.2) - -SET(CYNARA_LIB_CYNARA_ASYNC_PATH ${CYNARA_PATH}/client-async) - -SET(LIB_CYNARA_ASYNC_SOURCES - ${CYNARA_LIB_CYNARA_ASYNC_PATH}/api/client-async-api.cpp - ${CYNARA_LIB_CYNARA_ASYNC_PATH}/logic/Logic.cpp - ) - -INCLUDE_DIRECTORIES( - ${CYNARA_LIB_CYNARA_ASYNC_PATH} - ) - -ADD_LIBRARY(${TARGET_LIB_CYNARA_ASYNC} SHARED ${LIB_CYNARA_ASYNC_SOURCES}) - -SET_TARGET_PROPERTIES( - ${TARGET_LIB_CYNARA_ASYNC} - PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=hidden" - SOVERSION ${LIB_CYNARA_ASYNC_VERSION_MAJOR} - VERSION ${LIB_CYNARA_ASYNC_VERSION} - ) - -TARGET_LINK_LIBRARIES(${TARGET_LIB_CYNARA_ASYNC} - ${CYNARA_DEP_LIBRARIES} - ${TARGET_CYNARA_COMMON} - ) - -INSTALL(TARGETS ${TARGET_LIB_CYNARA_ASYNC} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/client-async/api/ApiInterface.h b/src/client-async/api/ApiInterface.h deleted file mode 100644 index 216713a..0000000 --- a/src/client-async/api/ApiInterface.h +++ /dev/null @@ -1,47 +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 ApiInterface.h - * @author Marcin Niesluchowski - * @version 1.0 - * @brief This file contains libcynara-client-async API interface definition. - */ - -#ifndef SRC_CLIENT_ASYNC_API_APIINTERFACE_H_ -#define SRC_CLIENT_ASYNC_API_APIINTERFACE_H_ - -#include - -#include - -namespace Cynara { - -class ApiInterface { -public: - ApiInterface() = default; - virtual ~ApiInterface() {}; - - virtual int connect(int &sockFd) = 0; - virtual int check(const std::string &client, const std::string &session, - const std::string &user, const std::string &privilege, - cynara_check_id &checkId) = 0; - virtual int receive(cynara_check_id &checkId) = 0; - virtual int cancel(const cynara_check_id checkId) = 0; -}; - -} // namespace Cynara - -#endif /* SRC_CLIENT_ASYNC_API_APIINTERFACE_H_ */ diff --git a/src/client-async/api/client-async-api.cpp b/src/client-async/api/client-async-api.cpp deleted file mode 100644 index 34111f6..0000000 --- a/src/client-async/api/client-async-api.cpp +++ /dev/null @@ -1,118 +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 client-async-api.cpp - * @author Marcin Niesluchowski - * @version 1.0 - * @brief Implementation of external libcynara-client-async API - */ - -#include - -#include -#include - -#include -#include -#include - -struct cynara_async { - Cynara::ApiInterface *impl; - - cynara_async(Cynara::ApiInterface *_impl) : impl(_impl) { - } - - ~cynara_async() { - delete impl; - } -}; - -CYNARA_API -int cynara_async_initialize(cynara_async **pp_cynara, - const cynara_async_configuration *p_conf UNUSED) -{ - if (!pp_cynara) - return CYNARA_ASYNC_API_INVALID_PARAM; - - try { - *pp_cynara = new cynara_async(new Cynara::Logic); - } catch (const std::bad_alloc &ex) { - return CYNARA_ASYNC_API_OUT_OF_MEMORY; - } - - init_log(); - - LOGD("Cynara client async initialized"); - - return CYNARA_ASYNC_API_SUCCESS; -} - -CYNARA_API -int cynara_async_finish(cynara_async *p_cynara) -{ - delete p_cynara; - - return CYNARA_ASYNC_API_SUCCESS; -} - -CYNARA_API -int cynara_async_connect(cynara_async *p_cynara, int *p_sock_fd) -{ - if (!p_cynara || !p_cynara->impl) - return CYNARA_ASYNC_API_INVALID_PARAM; - if (!p_sock_fd) - return CYNARA_ASYNC_API_INVALID_PARAM; - - return p_cynara->impl->connect(*p_sock_fd); -} - -CYNARA_API -int cynara_async_check(cynara_async *p_cynara, - const char *client, const char *client_session, - const char *user, const char *privilege, - cynara_check_id *p_check_id) -{ - if (!p_cynara || !p_cynara->impl) - return CYNARA_ASYNC_API_INVALID_PARAM; - if (!client || !client_session || !user || !privilege) - return CYNARA_ASYNC_API_INVALID_PARAM; - if (!p_check_id) - return CYNARA_ASYNC_API_INVALID_PARAM; - - return p_cynara->impl->check(client, client_session, - user, privilege, - *p_check_id); -} - -CYNARA_API -int cynara_async_receive(cynara_async *p_cynara, cynara_check_id *p_check_id) -{ - if (!p_cynara || !p_cynara->impl) - return CYNARA_ASYNC_API_INVALID_PARAM; - if (!p_check_id) - return CYNARA_ASYNC_API_INVALID_PARAM; - - return p_cynara->impl->receive(*p_check_id); -} - -CYNARA_API -int cynara_async_cancel(cynara_async *p_cynara, const cynara_check_id check_id) -{ - if (!p_cynara || !p_cynara->impl) - return CYNARA_ASYNC_API_INVALID_PARAM; - - return p_cynara->impl->cancel(check_id); -} diff --git a/src/client-async/logic/Logic.cpp b/src/client-async/logic/Logic.cpp deleted file mode 100644 index c6e7860..0000000 --- a/src/client-async/logic/Logic.cpp +++ /dev/null @@ -1,52 +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 Logic.cpp - * @author Marcin Niesluchowski - * @version 1.0 - * @brief This file contains implementation of Logic class - main - * libcynara-client-async class - */ - -#include - -#include "Logic.h" - -namespace Cynara { - -int Logic::connect(int &sockFd UNUSED) noexcept -{ - return CYNARA_ASYNC_API_SUCCESS; -} - -int Logic::check(const std::string &client UNUSED, const std::string &session UNUSED, - const std::string &user UNUSED, const std::string &privilege UNUSED, - cynara_check_id &checkId UNUSED) noexcept -{ - return CYNARA_ASYNC_API_SUCCESS; -} - -int Logic::receive(cynara_check_id &checkId UNUSED) noexcept -{ - return CYNARA_ASYNC_API_SUCCESS; -} - -int Logic::cancel(const cynara_check_id checkId UNUSED) noexcept -{ - return CYNARA_ASYNC_API_SUCCESS; -} - -} // namespace Cynara diff --git a/src/client-async/logic/Logic.h b/src/client-async/logic/Logic.h deleted file mode 100644 index e63ce68..0000000 --- a/src/client-async/logic/Logic.h +++ /dev/null @@ -1,47 +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 Logic.h - * @author Marcin Niesluchowski - * @version 1.0 - * @brief This file contains declaration of Logic class - main - * libcynara-client-async class - */ - -#ifndef SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_ -#define SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_ - -#include -#include - -namespace Cynara { - -class Logic : public ApiInterface { -public: - Logic() = default; - virtual ~Logic() {}; - - virtual int connect(int &sockFd) noexcept; - virtual int check(const std::string &client, const std::string &session, - const std::string &user, const std::string &privilege, - cynara_check_id &checkId) noexcept; - virtual int receive(cynara_check_id &checkId) noexcept; - virtual int cancel(const cynara_check_id checkId) noexcept; -}; - -} // namespace Cynara - -#endif /* SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_ */ diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index edf2938..5d8ed5a 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -22,11 +22,6 @@ INSTALL(FILES ) INSTALL(FILES - ${CYNARA_PATH}/include/cynara-client-async.h - DESTINATION ${INCLUDE_INSTALL_DIR}/cynara - ) - -INSTALL(FILES ${CYNARA_PATH}/include/cynara-admin.h DESTINATION ${INCLUDE_INSTALL_DIR}/cynara ) diff --git a/src/include/cynara-client-async.h b/src/include/cynara-client-async.h deleted file mode 100644 index c04d0b5..0000000 --- a/src/include/cynara-client-async.h +++ /dev/null @@ -1,294 +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 cynara-client-async.h - * @author Marcin Niesluchowski - * @version 1.0 - * @brief This file contains asynchronous client APIs of Cynara available - * with libcynara-client-asynchronous. - */ - - -#ifndef CYNARA_CLIENT_ASYNC_H -#define CYNARA_CLIENT_ASYNC_H - -#include - -/** - * \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_ASYNC_API_SUCCESS 0 - -/*! \brief indicating that access that was checked is denied */ -#define CYNARA_ASYNC_API_ACCESS_DENIED -1 - -/*! \brief indicating that answer was not yet received */ -#define CYNARA_ASYNC_API_ANSWER_NOT_READY -2 - -/*! \brief indicating that client is already connected */ -#define CYNARA_ASYNC_API_ALREADY_CONNECTED -3 - -/*! \brief indicating system is running out of memory state */ -#define CYNARA_ASYNC_API_OUT_OF_MEMORY -4 - -/*! \brief indicating the API's parameter is malformed */ -#define CYNARA_ASYNC_API_INVALID_PARAM -5 - -/*! \brief service not available */ -#define CYNARA_ASYNC_API_SERVICE_NOT_AVAILABLE -6 - -/** @}*/ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct cynara_async cynara_async; -typedef struct cynara_async_configuration cynara_async_configuration; -typedef uint16_t cynara_check_id; - -/** - * \par Description: - * Initialize cynara-async-client library with given configuration. - * Create structure used in following API calls. - * - * \par Purpose: - * This API must be used prior to calling cynara_async_connect function. - * - * \par Typical use case: - * Once before a service can call cynara_async_connect. - * - * \par Method of function operation: - * This API initializes inner library structures and in case of success creates - * and returns cynara_async structure. - * - * \par Sync (or) Async: - * This is a synchronous API. - * - * \par Thread-safety: - * This function is NOT thread-safe. If functions from described API are called by multithreaded - * application from different threads, they must be put into protected critical section. - * - * \par Important notes: - * Structure cynara_async created by cynara_async_initialize call should be released - * with cynara_async_finish. - * - * \param[out] pp_cynara Placeholder for created cynara_async structure. - * \param[in] p_conf Configuration for cynara-async-client library. NULL for default parameters. - * - * \return CYNARA_ASYNC_API_SUCCESS on success, or error code on error. - */ - -int cynara_async_initialize(cynara_async **pp_cynara, - const cynara_async_configuration *p_conf); - -/** - * \par Description: - * Release cynara-async-client library and destroy structure created with cynara_async_initialize. - * - * \par Purpose: - * This API should be used to clean up after usage of cynara-async-client library. - * - * \par Typical use case: - * Once after all checks have been answered. - * - * \par Method of function operation: - * This API releases inner library structure and destroys cynara_async structure. All pending - * requests are cancelled. - * - * \par Sync (or) Async: - * This is a synchronous API. - * - * \par Thread-safety: - * This function is NOT thread-safe. If functions from described API are called by multithreaded - * application from different threads, they must be put into protected critical section. - * - * \par Important notes: - * No other call to cynara-async-client library should be made after call to cynara_async_finish. - * - * \param[in] p_cynara cynara_async structure. - * - * \return CYNARA_ASYNC_API_SUCCESS on success, or error code on error. - */ -int cynara_async_finish(cynara_async *p_cynara); - -/** - * \par Description: - * Connect with cynara server. - * - * \par Purpose: - * This API must be used prior to calling cynara_async_check and cynara_async_receive. - * - * \par Typical use case: - * After initiating cynara_async structure and after connection with cynara server has been lost. - * - * \par Method of function operation: - * This API connects to cynara server and provides socket descriptor of this connection. - * - * \par Sync (or) Async: - * This is a synchronous API. - * - * \par Thread-safety: - * This function is NOT thread-safe. If functions from described API are called by multithreaded - * application from different threads, they must be put into protected critical section. - * - * \par Important notes: - * Call to cynara_async_check needs cynara_async structure to be created first by - * cynara_async_initialize. - * - * \param[in] p_cynara cynara_async structure. - * \param[out] p_sock_fd Placeholder for connection socket descriptor. - * - * \return CYNARA_ASYNC_API_SUCCESS on success, CYNARA_ASYNC_API_ALREADY_CONNECTED when client is - * already connected or error code on error. - */ -int cynara_async_connect(cynara_async *p_cynara, int *p_sock_fd); - -/** - * \par Description: - * Check client, user access for given privilege. - * - * \par Purpose: - * This API should be used to check if a user running application identified as client - * has access to a privilege. - * - * \par Typical use case: - * A service wants to ask Cynara daemon, if a client demanding access to some privilege - * has proper rights. Despite the fact that the final response has been received, if there are - * still some pending checks, cynara_async_receive MUST be called after this call until not ready - * answer is returned. If service does not get answer after this sequence, it may get it - * asynchronously by calling cynara_async_receive. - * - * \par Method of function operation: - * Client (a process / application) demanding access to a privilege is running as some user. - * For such triple an access to a privilege is checked by calling cynara. - * Depending on defined policy, an external application may be launched to ask user a question, - * e.g. if [s]he wants to allow client to use a privilege. Additional parameter client_session - * may be used to distinguish between client session (e.g. for allowing access only for this - * particular application launch). If final answer is not returned, id of current check should - * be received. - * - * \par Sync (or) Async: - * This is an asynchronous API. - * - * \par Thread-safety: - * This function is NOT thread-safe. If functions from described API are called by multithreaded - * application from different threads, they must be put into protected critical section. - * - * \par Important notes: - * An external application may be launched to allow user interaction in granting or denying access. - * Call cynara_async_cancel to cancel pending request. Call to cynara_async_check needs - * cynara_async structure to be created first and connected with cynara daemon. To do that call - * cynara_async_initialize and cynara_async_connect. - * - * \param[in] p_cynara cynara_async structure. - * \param[in] client Application or process identifier. - * \param[in] client_session Session of client (connection, launch). - * \param[in] user User running client. - * \param[in] privilege Privilege that is a subject of a check. - * \param[out] p_check_id Placeholder for check id. - * - * \return CYNARA_ASYNC_API_SUCCESS on success (access granted), CYNARA_API_ACCESS_DENIED - * on access denial, CYNARA_ASYNC_API_ANSWER_NOT_READY on asynchronous request sent - * or other error code on error. - */ -int cynara_async_check(cynara_async *p_cynara, - const char *client, const char *client_session, - const char *user, const char *privilege, - cynara_check_id *p_check_id); - -/** - * \par Description: - * Receive answer of cynara_async_check call from cynara daemon. - * - * \par Purpose: - * This API should be used to receive answer on single check not answered by cynara_async_check. - * - * \par Typical use case: - * After calling cynara_async_check, if there are still pending checks, this function MUST be - * called until not ready answer is returned. After that, answer can be received by this call - * if a read event occurs on socket received by cynara_async_connect. It MUST be called then - * the same way as after cynara_async_check. - * - * \par Method of function operation: - * Receives answer sent by cynara daemon in response to cynara_async_check call. - * - * \par Sync (or) Async: - * This is an asynchronous API. - * - * \par Thread-safety: - * This function is NOT thread-safe. If functions from described API are called by multithreaded - * application from different threads, they must be put into protected critical section. - * - * \par Important notes: - * An external application may be launched to allow user interaction in granting or denying access. - * Call cynara_async_cancel to cancel pending request. Call to cynara_async_receive needs - * cynara_async structure to be created first and connected with cynara daemon. To do that call - * cynara_async_initialize and cynara_async_connect. As multiple answers can be available at once, - * cynara_async_receive MUST be called until not ready answer is returned. - * - * \param[in] p_cynara cynara_async structure. - * \param[out] p_check_id Placeholder for check id. - * - * \return CYNARA_ASYNC_API_SUCCESS on success (access granted), CYNARA_API_ACCESS_DENIED - * on access denial, CYNARA_ASYNC_API_ANSWER_NOT_READY on answer not yet fully received - * or other error code on error. - */ -int cynara_async_receive(cynara_async *p_cynara, cynara_check_id *p_check_id); - -/** - * \par Description: - * Cancel check request created by cynara_async_check. - * - * \par Purpose: - * This API should be used to cancel check request created by cynara_async_check. - * - * \par Typical use case: - * A service did not get final answer in cynara_async_check call and answer did not come yet - * due to check hanging on user decision to allow or deny privilege. - * - * \par Method of function operation: - * Cancels check request created by cynara_async_check call. - * - * \par Sync (or) Async: - * This is an asynchronous API. - * - * \par Thread-safety: - * This function is NOT thread-safe. If functions from described API are called by multithreaded - * application from different threads, they must be put into protected critical section. - * - * \par Important notes: - * Call to cynara_async_cancel needs cynara_async structure to be created first and connected - * with cynara daemon. To do that call cynara_async_initialize and cynara_async_connect. - * - * \param[in] p_cynara cynara_async structure. - * \param[in] check_id Check id to be cancelled - * - * \return CYNARA_ASYNC_API_SUCCESS on success or other error code on error. - */ -int cynara_async_cancel(cynara_async *p_cynara, cynara_check_id check_id); - - -#ifdef __cplusplus -} -#endif - -#endif /* CYNARA_CLIENT_ASYNC_H */ -- 2.7.4 From 441c00c027df1ee0fc2f7395ff4135de72b41ae2 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 26 Aug 2014 11:33:31 +0200 Subject: [PATCH 10/16] Move error codes to different files Change-Id: Ice6a05d3ef76efed19780e3ce785ff7491519a36 --- packaging/cynara.spec | 2 ++ src/admin/api/admin-api.cpp | 1 + src/admin/logic/Logic.cpp | 1 + src/client/api/client-api.cpp | 1 + src/client/cache/CapacityCache.cpp | 1 + src/client/cache/NaiveInterpreter.h | 1 + src/client/cache/PolicyGetter.cpp | 1 + src/include/CMakeLists.txt | 2 ++ src/include/cynara-admin-error.h | 56 +++++++++++++++++++++++++++++++++++++ src/include/cynara-admin.h | 30 -------------------- src/include/cynara-client-error.h | 50 +++++++++++++++++++++++++++++++++ src/include/cynara-client.h | 24 ---------------- 12 files changed, 116 insertions(+), 54 deletions(-) create mode 100644 src/include/cynara-admin-error.h create mode 100644 src/include/cynara-client-error.h diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 5524b9d..a06f5cc 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -197,6 +197,7 @@ fi %files -n libcynara-client-devel %defattr(-,root,root,-) %{_includedir}/cynara/cynara-client.h +%{_includedir}/cynara/cynara-client-error.h %{_libdir}/pkgconfig/cynara-client.pc %{_libdir}/libcynara-client.so @@ -209,6 +210,7 @@ fi %files -n libcynara-admin-devel %defattr(-,root,root,-) %{_includedir}/cynara/cynara-admin.h +%{_includedir}/cynara/cynara-admin-error.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 d6e6a12..417baa3 100644 --- a/src/admin/api/admin-api.cpp +++ b/src/admin/api/admin-api.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp index 641929d..0934729 100644 --- a/src/admin/logic/Logic.cpp +++ b/src/admin/logic/Logic.cpp @@ -22,6 +22,7 @@ #include +#include #include #include #include diff --git a/src/client/api/client-api.cpp b/src/client/api/client-api.cpp index b6f139f..0371853 100644 --- a/src/client/api/client-api.cpp +++ b/src/client/api/client-api.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include diff --git a/src/client/cache/CapacityCache.cpp b/src/client/cache/CapacityCache.cpp index f5a3df5..a0025b2 100644 --- a/src/client/cache/CapacityCache.cpp +++ b/src/client/cache/CapacityCache.cpp @@ -22,6 +22,7 @@ #include +#include #include #include diff --git a/src/client/cache/NaiveInterpreter.h b/src/client/cache/NaiveInterpreter.h index 9ae333f..9574f2c 100644 --- a/src/client/cache/NaiveInterpreter.h +++ b/src/client/cache/NaiveInterpreter.h @@ -24,6 +24,7 @@ #include #include +#include namespace Cynara { diff --git a/src/client/cache/PolicyGetter.cpp b/src/client/cache/PolicyGetter.cpp index 8bf1a39..f1f2e49 100644 --- a/src/client/cache/PolicyGetter.cpp +++ b/src/client/cache/PolicyGetter.cpp @@ -22,6 +22,7 @@ #include +#include #include #include #include diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index 5d8ed5a..486f657 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -18,10 +18,12 @@ INSTALL(FILES ${CYNARA_PATH}/include/cynara-client.h + ${CYNARA_PATH}/include/cynara-client-error.h DESTINATION ${INCLUDE_INSTALL_DIR}/cynara ) INSTALL(FILES ${CYNARA_PATH}/include/cynara-admin.h + ${CYNARA_PATH}/include/cynara-admin-error.h DESTINATION ${INCLUDE_INSTALL_DIR}/cynara ) diff --git a/src/include/cynara-admin-error.h b/src/include/cynara-admin-error.h new file mode 100644 index 0000000..0f5c4d1 --- /dev/null +++ b/src/include/cynara-admin-error.h @@ -0,0 +1,56 @@ +/* + * 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 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 d998eb6..2224140 100644 --- a/src/include/cynara-admin.h +++ b/src/include/cynara-admin.h @@ -20,39 +20,9 @@ * \brief This file contains administration APIs of cynara available with libcynara-admin. */ - #ifndef CYNARA_ADMIN_H #define CYNARA_ADMIN_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 -/** @}*/ - #ifdef __cplusplus extern "C" { #endif diff --git a/src/include/cynara-client-error.h b/src/include/cynara-client-error.h new file mode 100644 index 0000000..b4746b8 --- /dev/null +++ b/src/include/cynara-client-error.h @@ -0,0 +1,50 @@ +/* + * 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 cynara-error.h + * @author Lukasz Wojciechowski + * @author Zofia Abramowska + * @version 1.0 + * @brief This file contains error codes returned by client APIs of Cynara. + */ + +#ifndef CYNARA_ERROR_H +#define CYNARA_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_API_SUCCESS 0 + +/*! \brief indicating that access that was checked is denied */ +#define CYNARA_API_ACCESS_DENIED -1 + +/*! \brief indicating system is running out of memory state */ +#define CYNARA_API_OUT_OF_MEMORY -2 + +/*! \brief indicating the API's parameter is malformed */ +#define CYNARA_API_INVALID_PARAM -3 + +/*! \brief service not available */ +#define CYNARA_API_SERVICE_NOT_AVAILABLE -4 +/** @}*/ + +#endif // CYNARA_ERROR_H diff --git a/src/include/cynara-client.h b/src/include/cynara-client.h index f984966..2827ff2 100644 --- a/src/include/cynara-client.h +++ b/src/include/cynara-client.h @@ -20,33 +20,9 @@ * @brief This file contains client APIs of Cynara available with libcynara-client. */ - #ifndef CYNARA_CLIENT_H #define CYNARA_CLIENT_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_API_SUCCESS 0 - -/*! \brief indicating that access that was checked is denied */ -#define CYNARA_API_ACCESS_DENIED -1 - -/*! \brief indicating system is running out of memory state */ -#define CYNARA_API_OUT_OF_MEMORY -2 - -/*! \brief indicating the API's parameter is malformed */ -#define CYNARA_API_INVALID_PARAM -3 - -/*! \brief service not available */ -#define CYNARA_API_SERVICE_NOT_AVAILABLE -4 -/** @}*/ - #ifdef __cplusplus extern "C" { #endif -- 2.7.4 From 1405e059bac55207021aa796c9ee9cb7b74f107b Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 26 Aug 2014 14:08:18 +0200 Subject: [PATCH 11/16] Add additional error code CYNARA_API_CACHE_MISS Change-Id: I2f128b28b19956409f0251f725a28a0e8ace2e7d --- src/include/cynara-client-error.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/include/cynara-client-error.h b/src/include/cynara-client-error.h index b4746b8..e5539ea 100644 --- a/src/include/cynara-client-error.h +++ b/src/include/cynara-client-error.h @@ -21,8 +21,8 @@ * @brief This file contains error codes returned by client APIs of Cynara. */ -#ifndef CYNARA_ERROR_H -#define CYNARA_ERROR_H +#ifndef CYNARA_CLIENT_ERROR_H +#define CYNARA_CLIENT_ERROR_H /** * \name Return Codes @@ -45,6 +45,9 @@ /*! \brief service not available */ #define CYNARA_API_SERVICE_NOT_AVAILABLE -4 + +/*! \brief indicating that value is not present in cache */ +#define CYNARA_API_CACHE_MISS -5 /** @}*/ -#endif // CYNARA_ERROR_H +#endif // CYNARA_CLIENT_ERROR_H -- 2.7.4 From d6225814636144a5ed9801cdb6aef4b01c2bd8b4 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Mon, 25 Aug 2014 16:52:33 +0200 Subject: [PATCH 12/16] Prepare Cache for async API Change-Id: I4f2eba2db4a0f35efaa6fa00a924e582211a1e45 --- src/client/cache/CacheInterface.h | 6 ++++-- src/client/cache/CapacityCache.cpp | 35 ++++++++++++++++++----------------- src/client/cache/CapacityCache.h | 9 +++++---- src/client/logic/Logic.cpp | 26 +++++++++++++++++++------- src/client/logic/Logic.h | 3 ++- 5 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/client/cache/CacheInterface.h b/src/client/cache/CacheInterface.h index 0279fdb..ec76a2e 100644 --- a/src/client/cache/CacheInterface.h +++ b/src/client/cache/CacheInterface.h @@ -61,8 +61,11 @@ public: class PluginCache { public: - PluginCache(ResultGetterInterfacePtr getter) : m_getter(getter) {} + PluginCache() {} virtual int get(const std::string &session, const PolicyKey &key) = 0; + virtual int update(const std::string &session, + const PolicyKey &key, + const PolicyResult &result) = 0; void registerPlugin(const PolicyType policyType, InterpreterInterfacePtr plugin) { m_plugins[policyType] = plugin; @@ -76,7 +79,6 @@ public: protected: std::map m_plugins; - ResultGetterInterfacePtr m_getter; }; } // namespace Cynara diff --git a/src/client/cache/CapacityCache.cpp b/src/client/cache/CapacityCache.cpp index a0025b2..412d231 100644 --- a/src/client/cache/CapacityCache.cpp +++ b/src/client/cache/CapacityCache.cpp @@ -33,9 +33,9 @@ int CapacityCache::get(const std::string &session, const PolicyKey &key) { //This can be very time heavy. This part is welcomed to be optimized. if (session != m_session) { LOGD("Session changed from %s to %s.", m_session.c_str(), session.c_str()); - m_keyValue.clear(); - m_keyUsage.clear(); + clear(); m_session = session; + return CYNARA_API_CACHE_MISS; } auto resultIt = m_keyValue.find(keyToString(key)); //Do we have entry in cache? @@ -44,7 +44,7 @@ int CapacityCache::get(const std::string &session, const PolicyKey &key) { key.client().toString().c_str(), key.user().toString().c_str(), key.privilege().toString().c_str()); - return update(key); + return CYNARA_API_CACHE_MISS; } else { LOGD("Entry available for client=%s user=%s privilege=%s", key.client().toString().c_str(), @@ -64,14 +64,13 @@ int CapacityCache::get(const std::string &session, const PolicyKey &key) { LOGD("Entry usable."); m_keyUsage.splice(m_keyUsage.begin(), m_keyUsage, resultIt->second.second); return plugin->toResult(resultIt->second.first); - } else { - //remove from list and map and update - LOGD("Entry not usable."); - auto usage_it = resultIt->second.second; - m_keyUsage.erase(usage_it); - m_keyValue.erase(resultIt); - return update(key); } + //Remove unusable entry + LOGD("Entry not usable"); + auto usageIt = resultIt->second.second; + m_keyUsage.erase(usageIt); + m_keyValue.erase(resultIt); + return CYNARA_API_CACHE_MISS; } } @@ -101,14 +100,16 @@ void CapacityCache::evict(void) { m_keyValue.erase(value_it); } -int CapacityCache::update(const PolicyKey &key) { - int ret; - PolicyResult result; - if ((ret = m_getter->requestResult(key, result)) != CYNARA_API_SUCCESS) { - LOGE("Error fetching new entry."); - return ret; +int CapacityCache::update(const std::string &session, + const PolicyKey &key, + const PolicyResult &result) { + //This can be very time heavy. This part is welcomed to be optimized. + if (session != m_session) { + LOGD("Session changed from %s to %s.", m_session.c_str(), session.c_str()); + clear(); + m_session = session; } - LOGD("Fetched new entry."); + auto pluginIt = m_plugins.find(result.policyType()); //No registered plugin for returned type of policy diff --git a/src/client/cache/CapacityCache.h b/src/client/cache/CapacityCache.h index 12101db..921a16b 100644 --- a/src/client/cache/CapacityCache.h +++ b/src/client/cache/CapacityCache.h @@ -34,12 +34,13 @@ class CapacityCache : public PluginCache { public: static const std::size_t CACHE_DEFAULT_CAPACITY = 10000; - CapacityCache(ResultGetterInterfacePtr getter, - std::size_t capacity = CACHE_DEFAULT_CAPACITY) : - PluginCache(getter), + CapacityCache(std::size_t capacity = CACHE_DEFAULT_CAPACITY) : m_capacity(capacity) {} int get(const std::string &session, const PolicyKey &key); + int update(const std::string& session, + const PolicyKey &key, + const PolicyResult &result); void clear(void); private: @@ -50,7 +51,7 @@ private: static std::string keyToString(const PolicyKey &key); void evict(void); - int update(const PolicyKey &key); + std::size_t m_capacity; std::string m_session; diff --git a/src/client/logic/Logic.cpp b/src/client/logic/Logic.cpp index dbdcf36..0c8ffc9 100644 --- a/src/client/logic/Logic.cpp +++ b/src/client/logic/Logic.cpp @@ -39,7 +39,8 @@ const std::string clientSocketPath("/run/cynara/cynara.socket"); Logic::Logic() { m_socket = std::make_shared(clientSocketPath, std::make_shared()); - m_cache = std::make_shared(std::make_shared(m_socket)); + m_resultGetter = std::make_shared(m_socket); + m_cache = std::make_shared(); auto naiveInterpreter = std::make_shared(); m_cache->registerPlugin(PredefinedPolicyType::ALLOW, naiveInterpreter); m_cache->registerPlugin(PredefinedPolicyType::DENY, naiveInterpreter); @@ -49,15 +50,26 @@ Logic::Logic() { int Logic::check(const std::string &client, const std::string &session, const std::string &user, const std::string &privilege) noexcept { - PolicyKey key(client, user, privilege); - - if (!m_socket->isConnected()) + if (!m_socket->isConnected()){ onDisconnected(); + } + PolicyKey key(client, user, privilege); auto ret = m_cache->get(session, key); - if (ret == CYNARA_API_SERVICE_NOT_AVAILABLE) - onDisconnected(); - return ret; + //Any other situation than cache miss + if (ret != CYNARA_API_CACHE_MISS) { + return ret; + } + + //No value in Cache + PolicyResult result; + ret = m_resultGetter->requestResult(key, result); + if (ret != CYNARA_API_SUCCESS) { + LOGE("Error fetching new entry."); + return ret; + } + + return m_cache->update(session, key, result); } void Logic::onDisconnected(void) { diff --git a/src/client/logic/Logic.h b/src/client/logic/Logic.h index ec298da..3d2ee95 100644 --- a/src/client/logic/Logic.h +++ b/src/client/logic/Logic.h @@ -34,8 +34,9 @@ namespace Cynara { class Logic : public ApiInterface { private: - PluginCachePtr m_cache; SocketClientPtr m_socket; + ResultGetterInterfacePtr m_resultGetter; + PluginCachePtr m_cache; void onDisconnected(void); -- 2.7.4 From 4048a09d307ff55977ab8b1e582002e1f571a684 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 26 Aug 2014 13:17:40 +0200 Subject: [PATCH 13/16] Add ClientSession type Change-Id: Ia62dac02a652c2f252708ed05320eb66ea5506b1 --- src/client/api/ApiInterface.h | 4 +++- src/client/cache/CacheInterface.h | 5 +++-- src/client/cache/CapacityCache.cpp | 4 ++-- src/client/cache/CapacityCache.h | 6 +++--- src/client/logic/Logic.cpp | 2 +- src/client/logic/Logic.h | 2 +- src/common/types/ClientSession.h | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/common/types/ClientSession.h diff --git a/src/client/api/ApiInterface.h b/src/client/api/ApiInterface.h index 73bcec5..656cc1d 100644 --- a/src/client/api/ApiInterface.h +++ b/src/client/api/ApiInterface.h @@ -24,7 +24,9 @@ #define SRC_CLIENT_API_APIINTERFACE_H_ #include + #include +#include namespace Cynara { @@ -33,7 +35,7 @@ public: ApiInterface() = default; virtual ~ApiInterface() {}; - virtual int check(const std::string &client, const std::string &session, + virtual int check(const std::string &client, const ClientSession &session, const std::string &user, const std::string &privilege) = 0; }; diff --git a/src/client/cache/CacheInterface.h b/src/client/cache/CacheInterface.h index ec76a2e..ee2b27d 100644 --- a/src/client/cache/CacheInterface.h +++ b/src/client/cache/CacheInterface.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -62,8 +63,8 @@ public: class PluginCache { public: PluginCache() {} - virtual int get(const std::string &session, const PolicyKey &key) = 0; - virtual int update(const std::string &session, + virtual int get(const ClientSession &session, const PolicyKey &key) = 0; + virtual int update(const ClientSession &session, const PolicyKey &key, const PolicyResult &result) = 0; diff --git a/src/client/cache/CapacityCache.cpp b/src/client/cache/CapacityCache.cpp index 412d231..1d2c658 100644 --- a/src/client/cache/CapacityCache.cpp +++ b/src/client/cache/CapacityCache.cpp @@ -29,7 +29,7 @@ namespace Cynara { -int CapacityCache::get(const std::string &session, const PolicyKey &key) { +int CapacityCache::get(const ClientSession &session, const PolicyKey &key) { //This can be very time heavy. This part is welcomed to be optimized. if (session != m_session) { LOGD("Session changed from %s to %s.", m_session.c_str(), session.c_str()); @@ -100,7 +100,7 @@ void CapacityCache::evict(void) { m_keyValue.erase(value_it); } -int CapacityCache::update(const std::string &session, +int CapacityCache::update(const ClientSession &session, const PolicyKey &key, const PolicyResult &result) { //This can be very time heavy. This part is welcomed to be optimized. diff --git a/src/client/cache/CapacityCache.h b/src/client/cache/CapacityCache.h index 921a16b..6fe9c83 100644 --- a/src/client/cache/CapacityCache.h +++ b/src/client/cache/CapacityCache.h @@ -37,8 +37,8 @@ public: CapacityCache(std::size_t capacity = CACHE_DEFAULT_CAPACITY) : m_capacity(capacity) {} - int get(const std::string &session, const PolicyKey &key); - int update(const std::string& session, + int get(const ClientSession &session, const PolicyKey &key); + int update(const ClientSession& session, const PolicyKey &key, const PolicyResult &result); void clear(void); @@ -54,7 +54,7 @@ private: std::size_t m_capacity; - std::string m_session; + ClientSession m_session; KeyUsageList m_keyUsage; KeyValueMap m_keyValue; diff --git a/src/client/logic/Logic.cpp b/src/client/logic/Logic.cpp index 0c8ffc9..a609314 100644 --- a/src/client/logic/Logic.cpp +++ b/src/client/logic/Logic.cpp @@ -47,7 +47,7 @@ Logic::Logic() { m_cache->registerPlugin(PredefinedPolicyType::BUCKET, naiveInterpreter); } -int Logic::check(const std::string &client, const std::string &session, const std::string &user, +int Logic::check(const std::string &client, const ClientSession &session, const std::string &user, const std::string &privilege) noexcept { if (!m_socket->isConnected()){ diff --git a/src/client/logic/Logic.h b/src/client/logic/Logic.h index 3d2ee95..daab6f4 100644 --- a/src/client/logic/Logic.h +++ b/src/client/logic/Logic.h @@ -44,7 +44,7 @@ public: Logic(); virtual ~Logic() {}; - virtual int check(const std::string &client, const std::string &session, + virtual int check(const std::string &client, const ClientSession &session, const std::string &user, const std::string &privilege) noexcept; }; diff --git a/src/common/types/ClientSession.h b/src/common/types/ClientSession.h new file mode 100644 index 0000000..a848137 --- /dev/null +++ b/src/common/types/ClientSession.h @@ -0,0 +1,34 @@ +/* + * 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 ClientSession.h + * @author Zofia Abramowska + * @version 1.0 + * @brief Description of user defined session type + */ + +#ifndef SRC_COMMON_TYPES_CLIENTSESSION_H_ +#define SRC_COMMON_TYPES_CLIENTSESSION_H_ + +#include + +namespace Cynara { + +typedef std::string ClientSession; + +} // namespace Cynara + +#endif /* SRC_COMMON_TYPES_CLIENTSESSION_H_ */ -- 2.7.4 From 8eb9b35471e4e6dc036d06eaac2f7b73abc1c1ab Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 26 Aug 2014 13:27:31 +0200 Subject: [PATCH 14/16] Move Cache to client commons library Change-Id: Ia47e434063b7a1f6d079a29e0076ab0c2392832f --- CMakeLists.txt | 1 + packaging/cynara.spec | 2 + src/CMakeLists.txt | 2 +- src/admin/CMakeLists.txt | 1 + src/client-common/CMakeLists.txt | 47 +++++++++++++++ .../cache/CacheInterface.h | 28 ++------- .../cache/CapacityCache.cpp | 0 .../cache/CapacityCache.h | 6 +- .../plugins}/NaiveInterpreter.h | 6 +- .../plugins/PluginInterface.h} | 41 ++++++------- src/client/CMakeLists.txt | 22 +++---- src/client/cache/PolicyGetter.cpp | 67 ---------------------- src/client/logic/Logic.cpp | 53 ++++++++++++++--- src/client/logic/Logic.h | 5 +- 14 files changed, 139 insertions(+), 142 deletions(-) create mode 100644 src/client-common/CMakeLists.txt rename src/{client => client-common}/cache/CacheInterface.h (69%) rename src/{client => client-common}/cache/CapacityCache.cpp (100%) rename src/{client => client-common}/cache/CapacityCache.h (92%) rename src/{client/cache => client-common/plugins}/NaiveInterpreter.h (89%) rename src/{client/cache/PolicyGetter.h => client-common/plugins/PluginInterface.h} (50%) delete mode 100644 src/client/cache/PolicyGetter.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 354d39b..38c37d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") SET(TARGET_CYNARA "cynara") SET(TARGET_LIB_CYNARA "cynara-client") +SET(TARGET_LIB_CYNARA_COMMON "cynara-client-commons") SET(TARGET_LIB_CYNARA_ADMIN "cynara-admin") SET(TARGET_CYNARA_COMMON "cynara-commons") SET(TARGET_CYNARA_TESTS "cynara-tests") diff --git a/packaging/cynara.spec b/packaging/cynara.spec index a06f5cc..0fcd718 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -193,6 +193,7 @@ fi %license LICENSE %defattr(-,root,root,-) %{_libdir}/libcynara-client.so.* +%{_libdir}/libcynara-client-commons.so.* %files -n libcynara-client-devel %defattr(-,root,root,-) @@ -200,6 +201,7 @@ fi %{_includedir}/cynara/cynara-client-error.h %{_libdir}/pkgconfig/cynara-client.pc %{_libdir}/libcynara-client.so +%{_libdir}/libcynara-client-commons.so %files -n libcynara-admin %manifest libcynara-admin.manifest diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 852e0a5..596e84a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,12 +40,12 @@ INCLUDE_DIRECTORIES(SYSTEM SET(CYNARA_PATH ${PROJECT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES( - ${CYNARA_PATH}/include ${CYNARA_PATH}/common ) ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(client) +ADD_SUBDIRECTORY(client-common) ADD_SUBDIRECTORY(admin) ADD_SUBDIRECTORY(service) diff --git a/src/admin/CMakeLists.txt b/src/admin/CMakeLists.txt index bbf0ebc..9f53d55 100644 --- a/src/admin/CMakeLists.txt +++ b/src/admin/CMakeLists.txt @@ -27,6 +27,7 @@ SET(LIB_CYNARA_ADMIN_SOURCES ) INCLUDE_DIRECTORIES( + ${CYNARA_PATH}/include ${CYNARA_LIB_CYNARA_ADMIN_PATH} ) diff --git a/src/client-common/CMakeLists.txt b/src/client-common/CMakeLists.txt new file mode 100644 index 0000000..fdc41c6 --- /dev/null +++ b/src/client-common/CMakeLists.txt @@ -0,0 +1,47 @@ +# 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 +# + +SET(LIB_CYNARA_CLIENT_COMMON_VERSION_MAJOR 0) +SET(LIB_CYNARA_CLIENT_COMMON_VERSION ${LIB_CYNARA_CLIENT_COMMON_VERSION_MAJOR}.0.2) + +SET(LIB_CYNARA_COMMON_PATH ${CYNARA_PATH}/client-common) + +INCLUDE_DIRECTORIES( + ${LIB_CYNARA_COMMON_PATH} + ${CYNARA_PATH}/include + ) + +SET(LIB_CYNARA_COMMON_SOURCES + ${LIB_CYNARA_COMMON_PATH}/cache/CapacityCache.cpp + ) + +ADD_LIBRARY(${TARGET_LIB_CYNARA_COMMON} SHARED ${LIB_CYNARA_COMMON_SOURCES}) + +SET_TARGET_PROPERTIES( + ${TARGET_LIB_CYNARA_COMMON} + PROPERTIES + COMPILE_FLAGS "-D_GNU_SOURCE" + SOVERSION ${LIB_CYNARA_CLIENT_COMMON_VERSION_MAJOR} + VERSION ${LIB_CYNARA_CLIENT_COMMON_VERSION} + ) + +TARGET_LINK_LIBRARIES(${TARGET_LIB_CYNARA_COMMON} + ${TARGET_CYNARA_COMMON} + ) + +INSTALL(TARGETS ${TARGET_LIB_CYNARA_COMMON} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/client/cache/CacheInterface.h b/src/client-common/cache/CacheInterface.h similarity index 69% rename from src/client/cache/CacheInterface.h rename to src/client-common/cache/CacheInterface.h index ee2b27d..cdf3be7 100644 --- a/src/client/cache/CacheInterface.h +++ b/src/client-common/cache/CacheInterface.h @@ -21,14 +21,15 @@ * @brief This file contains cache interface definitions. */ -#ifndef SRC_CLIENT_CACHE_CACHEINTERFACE_H_ -#define SRC_CLIENT_CACHE_CACHEINTERFACE_H_ +#ifndef SRC_CLIENT_COMMON_CACHE_CACHEINTERFACE_H_ +#define SRC_CLIENT_COMMON_CACHE_CACHEINTERFACE_H_ #include #include #include #include +#include #include #include #include @@ -36,30 +37,9 @@ namespace Cynara { -class InterpreterInterface; -typedef std::shared_ptr InterpreterInterfacePtr; - class PluginCache; typedef std::shared_ptr PluginCachePtr; -class ResultGetterInterface; -typedef std::shared_ptr ResultGetterInterfacePtr; - -class ResultGetterInterface { -public: - virtual int requestResult(const PolicyKey &key, PolicyResult &result) noexcept = 0; - virtual ~ResultGetterInterface() {}; -}; - -class InterpreterInterface { -public: - virtual bool isCacheable(const PolicyResult &result) noexcept = 0; - virtual bool isUsable(const PolicyResult &result) noexcept = 0; - virtual int toResult(const PolicyResult &result) noexcept = 0; - - virtual ~InterpreterInterface() {}; -}; - class PluginCache { public: PluginCache() {} @@ -84,4 +64,4 @@ protected: } // namespace Cynara -#endif // SRC_CLIENT_CACHE_CACHEINTERFACE_H_ +#endif // SRC_CLIENT_COMMON_CACHE_CACHEINTERFACE_H_ diff --git a/src/client/cache/CapacityCache.cpp b/src/client-common/cache/CapacityCache.cpp similarity index 100% rename from src/client/cache/CapacityCache.cpp rename to src/client-common/cache/CapacityCache.cpp diff --git a/src/client/cache/CapacityCache.h b/src/client-common/cache/CapacityCache.h similarity index 92% rename from src/client/cache/CapacityCache.h rename to src/client-common/cache/CapacityCache.h index 6fe9c83..0a607fd 100644 --- a/src/client/cache/CapacityCache.h +++ b/src/client-common/cache/CapacityCache.h @@ -20,8 +20,8 @@ * @brief This file contains capacity cache header. */ -#ifndef SRC_CLIENT_CACHE_CAPACITYCACHE_H_ -#define SRC_CLIENT_CACHE_CAPACITYCACHE_H_ +#ifndef SRC_CLIENT_COMMON_CACHE_CAPACITYCACHE_H_ +#define SRC_CLIENT_COMMON_CACHE_CAPACITYCACHE_H_ #include #include @@ -62,7 +62,7 @@ private: } //namespace Cynara -#endif // SRC_CLIENT_CACHE_CAPACITYCACHE_H_ +#endif // SRC_CLIENT_COMMON_CACHE_CAPACITYCACHE_H_ diff --git a/src/client/cache/NaiveInterpreter.h b/src/client-common/plugins/NaiveInterpreter.h similarity index 89% rename from src/client/cache/NaiveInterpreter.h rename to src/client-common/plugins/NaiveInterpreter.h index 9574f2c..adac014 100644 --- a/src/client/cache/NaiveInterpreter.h +++ b/src/client-common/plugins/NaiveInterpreter.h @@ -19,8 +19,8 @@ * @version 1.0 * @brief This file contains PolicyType naive interpreter implementation. */ -#ifndef SRC_CLIENT_CACHE_NAIVEINTERPRETER_H_ -#define SRC_CLIENT_CACHE_NAIVEINTERPRETER_H_ +#ifndef SRC_CLIENT_COMMON_PLUGINS_NAIVEINTERPRETER_H_ +#define SRC_CLIENT_COMMON_PLUGINS_NAIVEINTERPRETER_H_ #include #include @@ -45,6 +45,6 @@ class NaiveInterpreter : public InterpreterInterface { } // namespace Cynara -#endif // SRC_CLIENT_CACHE_NAIVEINTERPRETER_H_ +#endif // SRC_CLIENT_COMMON_PLUGINS_NAIVEINTERPRETER_H_ diff --git a/src/client/cache/PolicyGetter.h b/src/client-common/plugins/PluginInterface.h similarity index 50% rename from src/client/cache/PolicyGetter.h rename to src/client-common/plugins/PluginInterface.h index c653887..5edec7a 100644 --- a/src/client/cache/PolicyGetter.h +++ b/src/client-common/plugins/PluginInterface.h @@ -1,3 +1,4 @@ + /* * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved * @@ -14,41 +15,33 @@ * limitations under the License */ /* - * @file PolicyGetter.h + * @file PluginInterface.h * @author Zofia Abramowska * @version 1.0 - * @brief This file contains Cynara PolicyResult getter implementation. + * @brief This file contains plugin interface definitions. */ -#ifndef SRC_CLIENT_CACHE_POLICYGETTER_H_ -#define SRC_CLIENT_CACHE_POLICYGETTER_H_ - -#include +#ifndef SRC_CLIENT_COMMON_PLUGINS_PLUGININTERFACE_H_ +#define SRC_CLIENT_COMMON_PLUGINS_PLUGININTERFACE_H_ -#include -#include +#include +#include namespace Cynara { -class PolicyGetter : public ResultGetterInterface { -public: - PolicyGetter(const SocketClientPtr &socketClient) : m_socketClient(socketClient) {} - int requestResult(const PolicyKey &key, PolicyResult &result) noexcept; +class InterpreterInterface; +typedef std::shared_ptr InterpreterInterfacePtr; -private: - ProtocolFrameSequenceNumber generateSequenceNumber(void) { - static ProtocolFrameSequenceNumber sequenceNumber = 0; - return ++sequenceNumber; - } +class InterpreterInterface { +public: + virtual bool isCacheable(const PolicyResult &result) noexcept = 0; + virtual bool isUsable(const PolicyResult &result) noexcept = 0; + virtual int toResult(const PolicyResult &result) noexcept = 0; - SocketClientPtr m_socketClient; + virtual ~InterpreterInterface() {}; }; -} //namespace Cynara - -#endif // SRC_CLIENT_CACHE_POLICYGETTER_H_ - - - +} +#endif // SRC_CLIENT_COMMON_PLUGINS_PLUGININTERFACE_H_ diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 4431556..09a023e 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -14,22 +14,23 @@ # # @file CMakeLists.txt # @author Lukasz Wojciechowski +# @author Zofia Abramowska # SET(LIB_CYNARA_VERSION_MAJOR 0) SET(LIB_CYNARA_VERSION ${LIB_CYNARA_VERSION_MAJOR}.0.2) -SET(CYNARA_LIB_CYNARA_PATH ${CYNARA_PATH}/client) +SET(LIB_CYNARA_PATH ${CYNARA_PATH}/client) -SET(LIB_CYNARA_SOURCES - ${CYNARA_LIB_CYNARA_PATH}/api/client-api.cpp - ${CYNARA_LIB_CYNARA_PATH}/cache/CapacityCache.cpp - ${CYNARA_LIB_CYNARA_PATH}/cache/PolicyGetter.cpp - ${CYNARA_LIB_CYNARA_PATH}/logic/Logic.cpp +INCLUDE_DIRECTORIES( + ${LIB_CYNARA_PATH} + ${CYNARA_PATH}/include + ${CYNARA_PATH}/client-common ) -INCLUDE_DIRECTORIES( - ${CYNARA_LIB_CYNARA_PATH} +SET(LIB_CYNARA_SOURCES + ${LIB_CYNARA_PATH}/api/client-api.cpp + ${LIB_CYNARA_PATH}/logic/Logic.cpp ) ADD_LIBRARY(${TARGET_LIB_CYNARA} SHARED ${LIB_CYNARA_SOURCES}) @@ -37,14 +38,13 @@ ADD_LIBRARY(${TARGET_LIB_CYNARA} SHARED ${LIB_CYNARA_SOURCES}) SET_TARGET_PROPERTIES( ${TARGET_LIB_CYNARA} PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=hidden" + COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden" SOVERSION ${LIB_CYNARA_VERSION_MAJOR} VERSION ${LIB_CYNARA_VERSION} ) TARGET_LINK_LIBRARIES(${TARGET_LIB_CYNARA} - ${CYNARA_DEP_LIBRARIES} - ${TARGET_CYNARA_COMMON} + ${TARGET_LIB_CYNARA_COMMON} ) INSTALL(TARGETS ${TARGET_LIB_CYNARA} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/client/cache/PolicyGetter.cpp b/src/client/cache/PolicyGetter.cpp deleted file mode 100644 index f1f2e49..0000000 --- a/src/client/cache/PolicyGetter.cpp +++ /dev/null @@ -1,67 +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 PolicyGetter.cpp - * @author Zofia Abramowska - * @version 1.0 - * @brief This file contains PolicyResult getter class implementation. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace Cynara { - -int PolicyGetter::requestResult(const PolicyKey &key, PolicyResult &result) noexcept { - ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); - - //Ask cynara service - CheckResponsePtr checkResponse; - try { - RequestPtr request = std::make_shared(key, sequenceNumber); - ResponsePtr response = m_socketClient->askCynaraServer(request); - if (!response) { - LOGW("Disconnected by cynara server."); - return CYNARA_API_SERVICE_NOT_AVAILABLE; - } - checkResponse = std::dynamic_pointer_cast(response); - if (!checkResponse) { - LOGC("Critical error. Casting Response to CheckResponse failed."); - return CYNARA_API_ACCESS_DENIED; - } - - LOGD("checkResponse: policyType = %" PRIu16 ", metadata = %s", - checkResponse->m_resultRef.policyType(), - checkResponse->m_resultRef.metadata().c_str()); - } catch (const ServerConnectionErrorException &ex) { - LOGE("Cynara service not available."); - return CYNARA_API_SERVICE_NOT_AVAILABLE; - } - - result = checkResponse->m_resultRef; - return CYNARA_API_SUCCESS; -} - -} // namespace Cynara diff --git a/src/client/logic/Logic.cpp b/src/client/logic/Logic.cpp index a609314..2444bff 100644 --- a/src/client/logic/Logic.cpp +++ b/src/client/logic/Logic.cpp @@ -22,24 +22,33 @@ #include +#include #include +#include +#include +#include +#include #include #include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include "Logic.h" +#include namespace Cynara { const std::string clientSocketPath("/run/cynara/cynara.socket"); +static ProtocolFrameSequenceNumber generateSequenceNumber(void) { + static ProtocolFrameSequenceNumber sequenceNumber = 0; + return ++sequenceNumber; +} + Logic::Logic() { m_socket = std::make_shared(clientSocketPath, std::make_shared()); - m_resultGetter = std::make_shared(m_socket); m_cache = std::make_shared(); auto naiveInterpreter = std::make_shared(); m_cache->registerPlugin(PredefinedPolicyType::ALLOW, naiveInterpreter); @@ -63,7 +72,7 @@ int Logic::check(const std::string &client, const ClientSession &session, const //No value in Cache PolicyResult result; - ret = m_resultGetter->requestResult(key, result); + ret = requestResult(key, result); if (ret != CYNARA_API_SUCCESS) { LOGE("Error fetching new entry."); return ret; @@ -72,6 +81,36 @@ int Logic::check(const std::string &client, const ClientSession &session, const return m_cache->update(session, key, result); } +int Logic::requestResult(const PolicyKey &key, PolicyResult &result) noexcept { + ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); + + //Ask cynara service + CheckResponsePtr checkResponse; + try { + RequestPtr request = std::make_shared(key, sequenceNumber); + ResponsePtr response = m_socket->askCynaraServer(request); + if (!response) { + LOGW("Disconnected by cynara server."); + return CYNARA_API_SERVICE_NOT_AVAILABLE; + } + checkResponse = std::dynamic_pointer_cast(response); + if (!checkResponse) { + LOGC("Critical error. Casting Response to CheckResponse failed."); + return CYNARA_API_ACCESS_DENIED; + } + + LOGD("checkResponse: policyType = %" PRIu16 ", metadata = %s", + checkResponse->m_resultRef.policyType(), + checkResponse->m_resultRef.metadata().c_str()); + } catch (const ServerConnectionErrorException &ex) { + LOGE("Cynara service not available."); + return CYNARA_API_SERVICE_NOT_AVAILABLE; + } + + result = checkResponse->m_resultRef; + return CYNARA_API_SUCCESS; +} + void Logic::onDisconnected(void) { m_cache->clear(); } diff --git a/src/client/logic/Logic.h b/src/client/logic/Logic.h index daab6f4..16d63ab 100644 --- a/src/client/logic/Logic.h +++ b/src/client/logic/Logic.h @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include @@ -35,11 +37,10 @@ namespace Cynara { class Logic : public ApiInterface { private: SocketClientPtr m_socket; - ResultGetterInterfacePtr m_resultGetter; PluginCachePtr m_cache; void onDisconnected(void); - + int requestResult(const PolicyKey &key, PolicyResult &result) noexcept; public: Logic(); virtual ~Logic() {}; -- 2.7.4 From 1f5a119d8f4ef420b80911013f5862b47d416f34 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Wed, 27 Aug 2014 19:02:55 +0200 Subject: [PATCH 15/16] Create additional packages for commons Change-Id: Idd62a30326e6f238ac885e13a8bc267fc4a8fe24 --- packaging/cynara.spec | 73 +++++++++++++++++++++++++++-- packaging/libcynara-client-commons.manifest | 5 ++ packaging/libcynara-commons.manifest | 5 ++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 packaging/libcynara-client-commons.manifest create mode 100644 packaging/libcynara-commons.manifest diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 0fcd718..4a6a605 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -9,6 +9,8 @@ Source1001: cynara.manifest Source1002: libcynara-client.manifest Source1003: libcynara-admin.manifest Source1004: cynara-tests.manifest +Source1005: libcynara-client-commons.manifest +Source1006: libcynara-commons.manifest Requires: default-ac-domains BuildRequires: cmake BuildRequires: zip @@ -51,6 +53,23 @@ Requires: libcynara-client = %{version}-%{release} client library (devel) for checking policies ####################################################### +%package -n libcynara-client-commons +Summary: Cynara - client commons library +Requires: cynara = %{version}-%{release} +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description -n libcynara-client-commons +client commons library with common functionalities + +%package -n libcynara-client-commons-devel +Summary: Cynara - client commons library (devel) +Requires: libcynara-client-commons = %{version}-%{release} + +%description -n libcynara-client-commons-devel +client commons library (devel) with common functionalities + +####################################################### %package -n libcynara-admin Summary: Cynara - admin client library Requires: cynara = %{version}-%{release} @@ -68,6 +87,23 @@ Requires: libcynara-admin = %{version}-%{release} admin client library (devel) for setting, listing and removing policies ####################################################### +%package -n libcynara-commons +Summary: Cynara - cynara commons library +Requires: cynara = %{version}-%{release} +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description -n libcynara-commons +cynara common library with common functionalities + +%package -n libcynara-commons-devel +Summary: Cynara - cynara commons library (devel) +Requires: libcynara-commons = %{version}-%{release} + +%description -n libcynara-commons-devel +cynara common library (devel) with common functionalities + +####################################################### %package -n cynara-tests Summary: Cynara - cynara test binaries BuildRequires: pkgconfig(gmock) @@ -90,6 +126,8 @@ cp -a %{SOURCE1001} . cp -a %{SOURCE1002} . cp -a %{SOURCE1003} . cp -a %{SOURCE1004} . +cp -a %{SOURCE1005} . +cp -a %{SOURCE1006} . %build %if 0%{?sec_build_binary_debug_enable} @@ -163,23 +201,38 @@ fi %postun -n libcynara-client -p /sbin/ldconfig +%post -n libcynara-client-commons -p /sbin/ldconfig + +%postun -n libcynara-client-commons -p /sbin/ldconfig + %post -n libcynara-admin -p /sbin/ldconfig %postun -n libcynara-admin -p /sbin/ldconfig +%post -n libcynara-commons -p /sbin/ldconfig + +%postun -n libcynara-commons -p /sbin/ldconfig + %post -n libcynara-client-devel -p /sbin/ldconfig %postun -n libcynara-client-devel -p /sbin/ldconfig +%post -n libcynara-client-commons-devel -p /sbin/ldconfig + +%postun -n libcynara-client-commons-devel -p /sbin/ldconfig + %post -n libcynara-admin-devel -p /sbin/ldconfig %postun -n libcynara-admin-devel -p /sbin/ldconfig +%post -n libcynara-commons-devel -p /sbin/ldconfig + +%postun -n libcynara-commons-devel -p /sbin/ldconfig + %files -n cynara %manifest cynara.manifest %license LICENSE %attr(755,root,root) /usr/bin/cynara -%{_libdir}/libcynara-commons.so* %attr(-,root,root) /usr/lib/systemd/system/cynara.service %attr(-,root,root) /usr/lib/systemd/system/cynara.target %attr(-,root,root) /usr/lib/systemd/system/sockets.target.wants/cynara.socket @@ -193,14 +246,20 @@ fi %license LICENSE %defattr(-,root,root,-) %{_libdir}/libcynara-client.so.* -%{_libdir}/libcynara-client-commons.so.* %files -n libcynara-client-devel %defattr(-,root,root,-) %{_includedir}/cynara/cynara-client.h -%{_includedir}/cynara/cynara-client-error.h %{_libdir}/pkgconfig/cynara-client.pc %{_libdir}/libcynara-client.so + +%files -n libcynara-client-commons +%manifest libcynara-client-commons.manifest +%license LICENSE +%{_libdir}/libcynara-client-commons.so.* + +%files -n libcynara-client-commons-devel +%{_includedir}/cynara/cynara-client-error.h %{_libdir}/libcynara-client-commons.so %files -n libcynara-admin @@ -216,6 +275,14 @@ fi %{_libdir}/libcynara-admin.so %{_libdir}/pkgconfig/cynara-admin.pc +%files -n libcynara-commons +%manifest libcynara-commons.manifest +%license LICENSE +%{_libdir}/libcynara-commons.so.* + +%files -n libcynara-commons-devel +%{_libdir}/libcynara-commons.so + %files -n cynara-tests %manifest cynara-tests.manifest %attr(755,root,root) /usr/bin/cynara-tests diff --git a/packaging/libcynara-client-commons.manifest b/packaging/libcynara-client-commons.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/libcynara-client-commons.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/libcynara-commons.manifest b/packaging/libcynara-commons.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/libcynara-commons.manifest @@ -0,0 +1,5 @@ + + + + + -- 2.7.4 From 70e713b09874f575241e417b5fff26a5efa7cbfc Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Mon, 1 Sep 2014 12:03:21 +0200 Subject: [PATCH 16/16] Add error include in API headers Change-Id: Id907a8fc93585b55b1115ae43054639d1a9088fe --- packaging/cynara.spec | 1 + src/include/cynara-admin.h | 2 ++ src/include/cynara-client.h | 2 ++ 3 files changed, 5 insertions(+) diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 4a6a605..ea556ce 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -48,6 +48,7 @@ client library for checking policies %package -n libcynara-client-devel Summary: Cynara - client library (devel) Requires: libcynara-client = %{version}-%{release} +Requires: libcynara-client-commons-devel = %{version}-%{release} %description -n libcynara-client-devel client library (devel) for checking policies diff --git a/src/include/cynara-admin.h b/src/include/cynara-admin.h index 2224140..b8aec4e 100644 --- a/src/include/cynara-admin.h +++ b/src/include/cynara-admin.h @@ -23,6 +23,8 @@ #ifndef CYNARA_ADMIN_H #define CYNARA_ADMIN_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/include/cynara-client.h b/src/include/cynara-client.h index 2827ff2..5ec59e5 100644 --- a/src/include/cynara-client.h +++ b/src/include/cynara-client.h @@ -23,6 +23,8 @@ #ifndef CYNARA_CLIENT_H #define CYNARA_CLIENT_H +#include + #ifdef __cplusplus extern "C" { #endif -- 2.7.4